<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/drivers/block/loop.c, branch v2.6.32</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v2.6.32</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v2.6.32'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2009-10-29T14:39:27Z</updated>
<entry>
<title>loop: fix NULL dereference if mount fails</title>
<updated>2009-10-29T14:39:27Z</updated>
<author>
<name>Alexey Dobriyan</name>
<email>adobriyan@gmail.com</email>
</author>
<published>2009-10-26T23:49:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=cf6e693212263d33c5882e4653df89a2fca4c0c4'/>
<id>urn:sha1:cf6e693212263d33c5882e4653df89a2fca4c0c4</id>
<content type='text'>
Commit bb21488482bd36eae6b30b014d93619063773fd4 ("[PATCH] switch loop")
started to pass NULL bdev to ioctl hook.

Steps to reproduce:

	[boot with loop.max_part=1]
	[mount -o loop something so mount fails]

BUG: unable to handle kernel NULL pointer dereference at 00000000000000b8
IP: [&lt;ffffffff811486ee&gt;] blkdev_ioctl+0x2e/0xa30
PGD 0
Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
last sysfs file: /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:35/ACPI0003:00/power_supply/ACAD/online
CPU 0
Modules linked in: zfs nvidia(P) [last unloaded: zfs]
Pid: 15177, comm: mount Tainted: P           2.6.32-rc4-zfs #2 Satellite X200
RIP: 0010:[&lt;ffffffff811486ee&gt;]  [&lt;ffffffff811486ee&gt;] blkdev_ioctl+0x2e/0xa30
RSP: 0018:ffff88003b3d5bb8  EFLAGS: 00010286
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: 000000000000125f RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffff88003b3d5ce8 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 00007ffffffff000
R13: 0000000000000000 R14: ffff880071cef280 R15: 00000000000200da
FS:  00007fd77cfe7740(0000) GS:ffff880001600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 00000000000000b8 CR3: 0000000001001000 CR4: 00000000000026f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process mount (pid: 15177, threadinfo ffff88003b3d4000, task ffff88007572f920)
Stack:
 ffff88003b3d5c38 ffffffff812f95f5 ffff88007eeb6600 0000000000000000
&lt;0&gt; 0000000000000000 ffff88003b3d5c18 ffffffff811547d9 ffff88001bf11ef0
&lt;0&gt; 7fffffffffffffff ffff88001bf11ee8 ffff88001bf11ef0 0000000000000000
Call Trace:
 [&lt;ffffffff812f95f5&gt;] ? schedule_timeout+0x1f5/0x250
 [&lt;ffffffff811547d9&gt;] ? rb_insert_color+0x109/0x140
 [&lt;ffffffff812fb754&gt;] ? _spin_unlock_irq+0x14/0x40
 [&lt;ffffffff812f84c6&gt;] ? wait_for_common+0x66/0x170
 [&lt;ffffffff8105a280&gt;] ? default_wake_function+0x0/0x10
 [&lt;ffffffff810f8258&gt;] ioctl_by_bdev+0x38/0x50
 [&lt;ffffffff811d2481&gt;] loop_clr_fd+0x1e1/0x210
 [&lt;ffffffff811d2522&gt;] lo_release+0x72/0x80
 [&lt;ffffffff810f934c&gt;] __blkdev_put+0x1ac/0x1d0
 [&lt;ffffffff810f937b&gt;] blkdev_put+0xb/0x10
 [&lt;ffffffff810f93b9&gt;] blkdev_close+0x39/0x60
 [&lt;ffffffff810ccef3&gt;] __fput+0xd3/0x230
 [&lt;ffffffff810cd06d&gt;] fput+0x1d/0x30
 [&lt;ffffffff810c9680&gt;] filp_close+0x50/0x80
 [&lt;ffffffff81061f11&gt;] put_files_struct+0x81/0x100
 [&lt;ffffffff81061fde&gt;] exit_files+0x4e/0x60
 [&lt;ffffffff81063ec5&gt;] do_exit+0x6b5/0x730
 [&lt;ffffffff8107b279&gt;] ? up_read+0x9/0x10
 [&lt;ffffffff8104c86e&gt;] ? do_page_fault+0x18e/0x2a0
 [&lt;ffffffff81063f81&gt;] do_group_exit+0x41/0xc0
 [&lt;ffffffff81064012&gt;] sys_exit_group+0x12/0x20
 [&lt;ffffffff81030deb&gt;] system_call_fastpath+0x16/0x1b
Code: f8 48 89 e5 48 81 ec 30 01 00 00 48 89 5d d8 4c 89 6d e8 4c 89 65 e0 4c 89 75 f0 4c 89 7d f8 48 89 bd e8 fe ff ff 49 89 cd 89 f3 &lt;49&gt; 8b 88 b8 00 00 00 81 fa 68 12 00 00 0f 84 57 05 00 00 0f 86
RIP  [&lt;ffffffff811486ee&gt;] blkdev_ioctl+0x2e/0xa30
 RSP &lt;ffff88003b3d5bb8&gt;
CR2: 00000000000000b8
---[ end trace c0b4d3c3118d1427 ]---
Fixing recursive fault but reboot is needed!

Signed-off-by: Alexey Dobriyan &lt;adobriyan@gmail.com&gt;
Cc: Jens Axboe &lt;jens.axboe@oracle.com&gt;
Cc: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>const: make block_device_operations const</title>
<updated>2009-09-22T14:17:25Z</updated>
<author>
<name>Alexey Dobriyan</name>
<email>adobriyan@gmail.com</email>
</author>
<published>2009-09-22T00:01:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=83d5cde47dedf01b6a4a4331882cbc0a7eea3c2e'/>
<id>urn:sha1:83d5cde47dedf01b6a4a4331882cbc0a7eea3c2e</id>
<content type='text'>
Signed-off-by: Alexey Dobriyan &lt;adobriyan@gmail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>bio: first step in sanitizing the bio-&gt;bi_rw flag testing</title>
<updated>2009-09-11T12:33:31Z</updated>
<author>
<name>Jens Axboe</name>
<email>jens.axboe@oracle.com</email>
</author>
<published>2009-09-11T12:32:04Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1f98a13f623e0ef666690a18c1250335fc6d7ef1'/>
<id>urn:sha1:1f98a13f623e0ef666690a18c1250335fc6d7ef1</id>
<content type='text'>
Get rid of any functions that test for these bits and make callers
use bio_rw_flagged() directly. Then it is at least directly apparent
what variable and flag they check.

Signed-off-by: Jens Axboe &lt;jens.axboe@oracle.com&gt;
</content>
</entry>
<entry>
<title>headers: smp_lock.h redux</title>
<updated>2009-07-12T19:22:34Z</updated>
<author>
<name>Alexey Dobriyan</name>
<email>adobriyan@gmail.com</email>
</author>
<published>2009-07-11T18:08:37Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=405f55712dfe464b3240d7816cc4fe4174831be2'/>
<id>urn:sha1:405f55712dfe464b3240d7816cc4fe4174831be2</id>
<content type='text'>
* Remove smp_lock.h from files which don't need it (including some headers!)
* Add smp_lock.h to files which do need it
* Make smp_lock.h include conditional in hardirq.h
  It's needed only for one kernel_locked() usage which is under CONFIG_PREEMPT

  This will make hardirq.h inclusion cheaper for every PREEMPT=n config
  (which includes allmodconfig/allyesconfig, BTW)

Signed-off-by: Alexey Dobriyan &lt;adobriyan@gmail.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>splice: implement default splice_read method</title>
<updated>2009-05-11T12:13:10Z</updated>
<author>
<name>Miklos Szeredi</name>
<email>miklos@szeredi.hu</email>
</author>
<published>2009-05-07T13:37:36Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=6818173bd658439b83896a2a7586f64ab51bf29c'/>
<id>urn:sha1:6818173bd658439b83896a2a7586f64ab51bf29c</id>
<content type='text'>
If f_op-&gt;splice_read() is not implemented, fall back to a plain read.
Use vfs_readv() to read into previously allocated pages.

This will allow splice and functions using splice, such as the loop
device, to work on all filesystems.  This includes "direct_io" files
in fuse which bypass the page cache.

Signed-off-by: Miklos Szeredi &lt;mszeredi@suse.cz&gt;
Signed-off-by: Jens Axboe &lt;jens.axboe@oracle.com&gt;
</content>
</entry>
<entry>
<title>loop: use BIO list management functions</title>
<updated>2009-04-28T05:37:28Z</updated>
<author>
<name>Akinobu Mita</name>
<email>akinobu.mita@gmail.com</email>
</author>
<published>2009-04-17T06:41:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e686307fdc84f249490e6c9da92fcb2424491f14'/>
<id>urn:sha1:e686307fdc84f249490e6c9da92fcb2424491f14</id>
<content type='text'>
Now that the bio list management stuff is generic, convert loop to use
bio lists instead of its own private bio list implementation.

Cc:  Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: Christoph Hellwig &lt;hch@infradead.org&gt;
Signed-off-by: Akinobu Mita &lt;akinobu.mita@gmail.com&gt;
Signed-off-by: Jens Axboe &lt;jens.axboe@oracle.com&gt;
</content>
</entry>
<entry>
<title>loop: mutex already unlocked in loop_clr_fd()</title>
<updated>2009-04-07T11:48:21Z</updated>
<author>
<name>Alexander Beregalov</name>
<email>a.beregalov@gmail.com</email>
</author>
<published>2009-04-07T11:48:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ffcd7dca3ab78f9f425971756e5e90024157f6be'/>
<id>urn:sha1:ffcd7dca3ab78f9f425971756e5e90024157f6be</id>
<content type='text'>
mount/1865 is trying to release lock (&amp;lo-&gt;lo_ctl_mutex) at:
but there are no more locks to release!

mutex is already unlocked in loop_clr_fd(), we should not
try to unlock it in lo_release() again.

Signed-off-by: Alexander Beregalov &lt;a.beregalov@gmail.com&gt;
Signed-off-by: Jens Axboe &lt;jens.axboe@oracle.com&gt;
</content>
</entry>
<entry>
<title>loop: add ioctl to resize a loop device</title>
<updated>2009-04-01T15:59:17Z</updated>
<author>
<name>J. R. Okajima</name>
<email>hooanon05@yahoo.co.jp</email>
</author>
<published>2009-03-31T22:23:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=53d6660836f233df66490707365ab177e5fb2bb4'/>
<id>urn:sha1:53d6660836f233df66490707365ab177e5fb2bb4</id>
<content type='text'>
Add the ability to 'resize' the loop device on the fly.

One practical application is a loop file with XFS filesystem, already
mounted: You can easily enlarge the file (append some bytes) and then call
ioctl(fd, LOOP_SET_CAPACITY, new); The loop driver will learn about the
new size and you can use xfs_growfs later on, which will allow you to use
full capacity of the loop file without the need to unmount.

Test app:

#include &lt;linux/fs.h&gt;
#include &lt;linux/loop.h&gt;
#include &lt;sys/ioctl.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;assert.h&gt;
#include &lt;errno.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;

#define _GNU_SOURCE
#include &lt;getopt.h&gt;

char *me;

void usage(FILE *f)
{
	fprintf(f, "%s [options] loop_dev [backend_file]\n"
		"-s, --set new_size_in_bytes\n"
		"\twhen backend_file is given, "
		"it will be expanded too while keeping the original contents\n",
		me);
}

struct option opts[] = {
	{
		.name		= "set",
		.has_arg	= 1,
		.flag		= NULL,
		.val		= 's'
	},
	{
		.name		= "help",
		.has_arg	= 0,
		.flag		= NULL,
		.val		= 'h'
	}
};

void err_size(char *name, __u64 old)
{
	fprintf(stderr, "size must be larger than current %s (%llu)\n",
		name, old);
}

int main(int argc, char *argv[])
{
	int fd, err, c, i, bfd;
	ssize_t ssz;
	size_t sz;
	__u64 old, new, append;
	char a[BUFSIZ];
	struct stat st;
	FILE *out;
	char *backend, *dev;

	err = EINVAL;
	out = stderr;
	me = argv[0];
	new = 0;
	while ((c = getopt_long(argc, argv, "s:h", opts, &amp;i)) != -1) {
		switch (c) {
		case 's':
			errno = 0;
			new = strtoull(optarg, NULL, 0);
			if (errno) {
				err = errno;
				perror(argv[i]);
				goto out;
			}
			break;

		case 'h':
			err = 0;
			out = stdout;
			goto err;

		default:
			perror(argv[i]);
			goto err;
		}
	}

	if (optind &lt; argc)
		dev = argv[optind++];
	else
		goto err;

	fd = open(dev, O_RDONLY);
	if (fd &lt; 0) {
		err = errno;
		perror(dev);
		goto out;
	}

	err = ioctl(fd, BLKGETSIZE64, &amp;old);
	if (err) {
		err = errno;
		perror("ioctl BLKGETSIZE64");
		goto out;
	}

	if (!new) {
		printf("%llu\n", old);
		goto out;
	}

	if (new &lt; old) {
		err = EINVAL;
		err_size(dev, old);
		goto out;
	}

	if (optind &lt; argc) {
		backend = argv[optind++];
		bfd = open(backend, O_WRONLY|O_APPEND);
		if (bfd &lt; 0) {
			err = errno;
			perror(backend);
			goto out;
		}
		err = fstat(bfd, &amp;st);
		if (err) {
			err = errno;
			perror(backend);
			goto out;
		}
		if (new &lt; st.st_size) {
			err = EINVAL;
			err_size(backend, st.st_size);
			goto out;
		}
		append = new - st.st_size;
		sz = sizeof(a);
		while (append &gt; 0) {
			if (append &lt; sz)
				sz = append;
			ssz = write(bfd, a, sz);
			if (ssz != sz) {
				err = errno;
				perror(backend);
				goto out;
			}
			append -= sz;
		}
		err = fsync(bfd);
		if (err) {
			err = errno;
			perror(backend);
			goto out;
		}
	}

	err = ioctl(fd, LOOP_SET_CAPACITY, new);
	if (err) {
		err = errno;
		perror("ioctl LOOP_SET_CAPACITY");
	}
	goto out;

 err:
	usage(out);
 out:
	return err;
}

Signed-off-by: J. R. Okajima &lt;hooanon05@yahoo.co.jp&gt;
Signed-off-by: Tomas Matejicek &lt;tomas@slax.org&gt;
Cc: &lt;util-linux-ng@vger.kernel.org&gt;
Cc: Karel Zak &lt;kzak@redhat.com&gt;
Cc: Jens Axboe &lt;jens.axboe@oracle.com&gt;
Cc: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Cc: Christoph Hellwig &lt;hch@lst.de&gt;
Cc: Akinobu Mita &lt;akinobu.mita@gmail.com&gt;
Cc: &lt;linux-api@vger.kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>loop: fix circular locking in loop_clr_fd()</title>
<updated>2009-03-26T10:01:19Z</updated>
<author>
<name>Nikanth Karthikesan</name>
<email>knikanth@suse.de</email>
</author>
<published>2009-03-24T11:33:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=f028f3b2f987ebc61cef382ab7a5c449917b728e'/>
<id>urn:sha1:f028f3b2f987ebc61cef382ab7a5c449917b728e</id>
<content type='text'>
With CONFIG_PROVE_LOCKING enabled

$ losetup /dev/loop0 file
$ losetup -o 32256 /dev/loop1 /dev/loop0

$ losetup -d /dev/loop1
$ losetup -d /dev/loop0

triggers a [ INFO: possible circular locking dependency detected ]

I think this warning is a false positive.

Open/close on a loop device acquires bd_mutex of the device before
acquiring lo_ctl_mutex of the same device. For ioctl(LOOP_CLR_FD) after
acquiring lo_ctl_mutex, fput on the backing_file might acquire the bd_mutex of
a device, if backing file is a device and this is the last reference to the
file being dropped . But it is guaranteed that it is impossible to have a
circular list of backing devices.(say loop2-&gt;loop1-&gt;loop0-&gt;loop2 is not
possible), which guarantees that this can never deadlock.

So this warning should be suppressed. It is very difficult to annotate lockdep
not to warn here in the correct way. A simple way to silence lockdep could be
to mark the lo_ctl_mutex in ioctl to be a sub class, but this might mask some
other real bugs.

@@ -1164,7 +1164,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
 	struct loop_device *lo = bdev-&gt;bd_disk-&gt;private_data;
 	int err;

-	mutex_lock(&amp;lo-&gt;lo_ctl_mutex);
+	mutex_lock_nested(&amp;lo-&gt;lo_ctl_mutex, 1);
 	switch (cmd) {
 	case LOOP_SET_FD:
 		err = loop_set_fd(lo, mode, bdev, arg);

Or actually marking the bd_mutex after lo_ctl_mutex as a sub class could be
a better solution.

Luckily it is easy to avoid calling fput on backing file with lo_ctl_mutex
held, so no lockdep annotation is required.

If you do not like the special handling of the lo_ctl_mutex just for the
LOOP_CLR_FD ioctl in lo_ioctl(), the mutex handling could be moved inside
each of the individual ioctl handlers and I could send you another patch.

Signed-off-by: Jens Axboe &lt;jens.axboe@oracle.com&gt;
</content>
</entry>
<entry>
<title>loop: support barrier writes</title>
<updated>2009-03-24T11:35:18Z</updated>
<author>
<name>Nikanth Karthikesan</name>
<email>knikanth@suse.de</email>
</author>
<published>2009-03-24T11:29:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=68db1961bbf4e16c220ccec4a780e966bc1fece3'/>
<id>urn:sha1:68db1961bbf4e16c220ccec4a780e966bc1fece3</id>
<content type='text'>
Honour barrier requests in the loop back block device driver.
In case of barrier bios, flush the backing file once before processing the
barrier and once after to guarantee ordering. In case of filesystems that
does not support fsync, barrier bios would be failed with -EOPNOTSUPP.

Signed-off-by: Nikanth Karthikesan &lt;knikanth@suse.de&gt;
Signed-off-by: Jens Axboe &lt;jens.axboe@oracle.com&gt;
</content>
</entry>
</feed>
