From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk, Hugh Dickins <hughd@google.com>,
Jens Axboe <axboe@kernel.dk>
Subject: [ 78/95] block: replace __getblk_slow misfix by grow_dev_page fix
Date: Sun, 09 Sep 2012 23:43:08 +0100 [thread overview]
Message-ID: <20120909224201.319503363@decadent.org.uk> (raw)
In-Reply-To: <20120909224150.641491654@decadent.org.uk>
3.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hugh Dickins <hughd@google.com>
commit 676ce6d5ca3098339c028d44fe0427d1566a4d2d upstream.
Commit 91f68c89d8f3 ("block: fix infinite loop in __getblk_slow")
is not good: a successful call to grow_buffers() cannot guarantee
that the page won't be reclaimed before the immediate next call to
__find_get_block(), which is why there was always a loop there.
Yesterday I got "EXT4-fs error (device loop0): __ext4_get_inode_loc:3595:
inode #19278: block 664: comm cc1: unable to read itable block" on console,
which pointed to this commit.
I've been trying to bisect for weeks, why kbuild-on-ext4-on-loop-on-tmpfs
sometimes fails from a missing header file, under memory pressure on
ppc G5. I've never seen this on x86, and I've never seen it on 3.5-rc7
itself, despite that commit being in there: bisection pointed to an
irrelevant pinctrl merge, but hard to tell when failure takes between
18 minutes and 38 hours (but so far it's happened quicker on 3.6-rc2).
(I've since found such __ext4_get_inode_loc errors in /var/log/messages
from previous weeks: why the message never appeared on console until
yesterday morning is a mystery for another day.)
Revert 91f68c89d8f3, restoring __getblk_slow() to how it was (plus
a checkpatch nitfix). Simplify the interface between grow_buffers()
and grow_dev_page(), and avoid the infinite loop beyond end of device
by instead checking init_page_buffers()'s end_block there (I presume
that's more efficient than a repeated call to blkdev_max_block()),
returning -ENXIO to __getblk_slow() in that case.
And remove akpm's ten-year-old "__getblk() cannot fail ... weird"
comment, but that is worrying: are all users of __getblk() really
now prepared for a NULL bh beyond end of device, or will some oops??
Signed-off-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
fs/buffer.c | 66 +++++++++++++++++++++++++++--------------------------------
1 file changed, 30 insertions(+), 36 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index 9f6d2e4..58e2e7b 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -914,7 +914,7 @@ link_dev_buffers(struct page *page, struct buffer_head *head)
/*
* Initialise the state of a blockdev page's buffers.
*/
-static void
+static sector_t
init_page_buffers(struct page *page, struct block_device *bdev,
sector_t block, int size)
{
@@ -936,33 +936,41 @@ init_page_buffers(struct page *page, struct block_device *bdev,
block++;
bh = bh->b_this_page;
} while (bh != head);
+
+ /*
+ * Caller needs to validate requested block against end of device.
+ */
+ return end_block;
}
/*
* Create the page-cache page that contains the requested block.
*
- * This is user purely for blockdev mappings.
+ * This is used purely for blockdev mappings.
*/
-static struct page *
+static int
grow_dev_page(struct block_device *bdev, sector_t block,
- pgoff_t index, int size)
+ pgoff_t index, int size, int sizebits)
{
struct inode *inode = bdev->bd_inode;
struct page *page;
struct buffer_head *bh;
+ sector_t end_block;
+ int ret = 0; /* Will call free_more_memory() */
page = find_or_create_page(inode->i_mapping, index,
(mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS)|__GFP_MOVABLE);
if (!page)
- return NULL;
+ return ret;
BUG_ON(!PageLocked(page));
if (page_has_buffers(page)) {
bh = page_buffers(page);
if (bh->b_size == size) {
- init_page_buffers(page, bdev, block, size);
- return page;
+ end_block = init_page_buffers(page, bdev,
+ index << sizebits, size);
+ goto done;
}
if (!try_to_free_buffers(page))
goto failed;
@@ -982,14 +990,14 @@ grow_dev_page(struct block_device *bdev, sector_t block,
*/
spin_lock(&inode->i_mapping->private_lock);
link_dev_buffers(page, bh);
- init_page_buffers(page, bdev, block, size);
+ end_block = init_page_buffers(page, bdev, index << sizebits, size);
spin_unlock(&inode->i_mapping->private_lock);
- return page;
-
+done:
+ ret = (block < end_block) ? 1 : -ENXIO;
failed:
unlock_page(page);
page_cache_release(page);
- return NULL;
+ return ret;
}
/*
@@ -999,7 +1007,6 @@ failed:
static int
grow_buffers(struct block_device *bdev, sector_t block, int size)
{
- struct page *page;
pgoff_t index;
int sizebits;
@@ -1023,22 +1030,14 @@ grow_buffers(struct block_device *bdev, sector_t block, int size)
bdevname(bdev, b));
return -EIO;
}
- block = index << sizebits;
+
/* Create a page with the proper size buffers.. */
- page = grow_dev_page(bdev, block, index, size);
- if (!page)
- return 0;
- unlock_page(page);
- page_cache_release(page);
- return 1;
+ return grow_dev_page(bdev, block, index, size, sizebits);
}
static struct buffer_head *
__getblk_slow(struct block_device *bdev, sector_t block, int size)
{
- int ret;
- struct buffer_head *bh;
-
/* Size must be multiple of hard sectorsize */
if (unlikely(size & (bdev_logical_block_size(bdev)-1) ||
(size < 512 || size > PAGE_SIZE))) {
@@ -1051,21 +1050,20 @@ __getblk_slow(struct block_device *bdev, sector_t block, int size)
return NULL;
}
-retry:
- bh = __find_get_block(bdev, block, size);
- if (bh)
- return bh;
+ for (;;) {
+ struct buffer_head *bh;
+ int ret;
- ret = grow_buffers(bdev, block, size);
- if (ret == 0) {
- free_more_memory();
- goto retry;
- } else if (ret > 0) {
bh = __find_get_block(bdev, block, size);
if (bh)
return bh;
+
+ ret = grow_buffers(bdev, block, size);
+ if (ret < 0)
+ return NULL;
+ if (ret == 0)
+ free_more_memory();
}
- return NULL;
}
/*
@@ -1321,10 +1319,6 @@ EXPORT_SYMBOL(__find_get_block);
* which corresponds to the passed block_device, block and size. The
* returned buffer has its reference count incremented.
*
- * __getblk() cannot fail - it just keeps trying. If you pass it an
- * illegal block number, __getblk() will happily return a buffer_head
- * which represents the non-existent block. Very weird.
- *
* __getblk() will lock up the machine if grow_dev_page's try_to_free_buffers()
* attempt is failing. FIXME, perhaps?
*/
next prev parent reply other threads:[~2012-09-09 23:16 UTC|newest]
Thread overview: 112+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-09 22:41 [ 00/95] 3.2.29-stable review Ben Hutchings
2012-09-09 22:41 ` [ 01/95] HID: add ASUS AIO keyboard model AK1D Ben Hutchings
2012-09-09 22:41 ` [ 02/95] nfs: tear down caches in nfs_init_writepagecache when allocation fails Ben Hutchings
2012-09-09 22:41 ` [ 03/95] NFS: Use kcalloc() when allocating arrays Ben Hutchings
2012-09-09 22:41 ` [ 04/95] NFSv4.1 fix page number calculation bug for filelayout decode buffers Ben Hutchings
2012-09-09 22:41 ` [ 05/95] fix page number calculation bug for block layout decode buffer Ben Hutchings
2012-09-09 22:41 ` [ 06/95] pnfs: defer release of pages in layoutget Ben Hutchings
2012-09-09 22:41 ` [ 07/95] ext4: avoid kmemcheck complaint from reading uninitialized memory Ben Hutchings
2012-09-09 22:41 ` [ 08/95] fuse: verify all ioctl retry iov elements Ben Hutchings
2012-09-09 22:41 ` [ 09/95] Bluetooth: Fix legacy pairing with some devices Ben Hutchings
2012-09-09 22:42 ` [ 10/95] xhci: Increase reset timeout for Renesas 720201 host Ben Hutchings
2012-09-09 22:42 ` [ 11/95] xhci: Add Etron XHCI_TRUST_TX_LENGTH quirk Ben Hutchings
2012-09-09 22:42 ` [ 12/95] xhci: Switch PPT ports to EHCI on shutdown Ben Hutchings
2012-09-10 11:09 ` Denis Turischev
2012-09-10 15:18 ` Ben Hutchings
2012-09-09 22:42 ` [ 13/95] USB: ftdi_sio: Add VID/PID for Kondo Serial USB Ben Hutchings
2012-09-09 22:42 ` [ 14/95] USB: option: Add Vodafone/Huawei K5005 support Ben Hutchings
2012-09-09 22:42 ` [ 15/95] USB: add USB_VENDOR_AND_INTERFACE_INFO() macro Ben Hutchings
2012-09-09 22:42 ` [ 16/95] USB: support the new interfaces of Huawei Data Card devices in option driver Ben Hutchings
2012-09-09 22:42 ` [ 17/95] usb: serial: mos7840: Fixup mos7840_chars_in_buffer() Ben Hutchings
2012-09-09 22:42 ` [ 18/95] usb: gadget: u_ether: fix kworker 100% CPU issue with still used interfaces in eth_stop Ben Hutchings
2012-09-09 22:42 ` [ 19/95] ARM: 7483/1: vfp: only advertise VFPv4 in hwcaps if CONFIG_VFPv3 is enabled Ben Hutchings
2012-09-09 22:42 ` [ 20/95] ARM: 7488/1: mm: use 5 bits for swapfile type encoding Ben Hutchings
2012-09-09 22:42 ` [ 21/95] ARM: 7489/1: errata: fix workaround for erratum #720789 on UP systems Ben Hutchings
2012-09-09 22:42 ` [ 22/95] drm/i915: ignore eDP bpc settings from vbt Ben Hutchings
2012-09-09 22:42 ` [ 23/95] ALSA: hda - fix Copyright debug message Ben Hutchings
2012-09-09 22:42 ` [ 24/95] sched: fix divide by zero at {thread_group,task}_times Ben Hutchings
2012-09-09 22:42 ` [ 25/95] mutex: Place lock in contended state after fastpath_lock failure Ben Hutchings
2012-09-09 23:34 ` Nicolas Pitre
2012-09-09 23:42 ` Ben Hutchings
2012-09-09 22:42 ` [ 26/95] ath9k: fix decrypt_error initialization in ath_rx_tasklet() Ben Hutchings
2012-09-09 22:42 ` [ 27/95] drm/nvd0/disp: mask off high 16 bit of negative cursor x-coordinate Ben Hutchings
2012-09-09 22:42 ` [ 28/95] drm/i915: reorder edp disabling to fix ivb MacBook Air Ben Hutchings
2012-09-09 22:42 ` [ 29/95] audit: dont free_chunk() after fsnotify_add_mark() Ben Hutchings
2012-09-09 22:42 ` [ 30/95] audit: fix refcounting in audit-tree Ben Hutchings
2012-09-09 22:42 ` [ 31/95] vfs: canonicalize create mode in build_open_flags() Ben Hutchings
2012-09-09 22:42 ` [ 32/95] PCI: EHCI: Fix crash during hibernation on ASUS computers Ben Hutchings
2012-09-09 22:42 ` [ 33/95] IB/srp: Fix a race condition Ben Hutchings
2012-09-09 22:42 ` [ 34/95] USB: option: add ZTE K5006-Z Ben Hutchings
2012-09-10 17:11 ` Thomas Schäfer
2012-09-11 7:43 ` Bjørn Mork
2012-09-12 2:29 ` Ben Hutchings
2012-09-13 15:22 ` Thomas Schäfer
2012-09-16 16:44 ` Ben Hutchings
2012-09-09 22:42 ` [ 35/95] dccp: check ccid before dereferencing Ben Hutchings
2012-09-10 6:17 ` Mathias Krause
2012-09-10 6:47 ` David Miller
2012-09-10 7:10 ` Mathias Krause
2012-09-09 22:42 ` [ 36/95] md: Dont truncate size at 4TB for RAID0 and Linear Ben Hutchings
2012-09-09 22:42 ` [ 37/95] NFS: Alias the nfs module to nfs4 Ben Hutchings
2012-09-09 22:42 ` [ 38/95] target: fix NULL pointer dereference bug alloc_page() fails to get memory Ben Hutchings
2012-09-09 22:42 ` [ 39/95] ext4: fix long mount times on very big file systems Ben Hutchings
2012-09-09 22:42 ` [ 40/95] PM / Runtime: Fix rpm_resume() return value for power.no_callbacks set Ben Hutchings
2012-09-09 22:42 ` [ 41/95] PM / Runtime: Clear power.deferred_resume on success in rpm_suspend() Ben Hutchings
2012-09-09 22:42 ` [ 42/95] ASoC: wm9712: Fix microphone source selection Ben Hutchings
2012-09-09 22:42 ` [ 43/95] USB: smsusb: remove __devinit* from the struct usb_device_id table Ben Hutchings
2012-09-09 22:42 ` [ 44/95] USB: spca506: " Ben Hutchings
2012-09-09 22:42 ` [ 45/95] USB: p54usb: " Ben Hutchings
2012-09-09 22:42 ` [ 46/95] USB: rtl8187: " Ben Hutchings
2012-09-09 22:42 ` [ 47/95] USB: vt6656: " Ben Hutchings
2012-09-09 22:42 ` [ 48/95] USB: winbond: " Ben Hutchings
2012-09-09 22:42 ` [ 49/95] USB: emi62: " Ben Hutchings
2012-09-09 22:42 ` [ 50/95] USB: CDC ACM: Fix NULL pointer dereference Ben Hutchings
2012-09-09 22:42 ` [ 51/95] alpha: Dont export SOCK_NONBLOCK to user space Ben Hutchings
2012-09-09 22:42 ` [ 52/95] Redefine ATOMIC_INIT and ATOMIC64_INIT to drop the casts Ben Hutchings
2012-09-09 22:42 ` [ 53/95] ALSA: hda - dont create dysfunctional mixer controls for ca0132 Ben Hutchings
2012-09-09 22:42 ` [ 54/95] netconsole: remove a redundant netconsole_target_put() Ben Hutchings
2012-09-09 22:42 ` [ 55/95] drm/radeon/kms: upstream atombios.h updates Ben Hutchings
2012-09-09 22:42 ` [ 56/95] drm/radeon/kms: extend the Fujitsu D3003-S2 board connector quirk to cover later silicon stepping Ben Hutchings
2012-09-09 22:42 ` [ 57/95] drm/radeon: implement ACPI VFCT vbios fetch (v3) Ben Hutchings
2012-09-09 22:42 ` [ 58/95] ACPI: export symbol acpi_get_table_with_size Ben Hutchings
2012-09-09 22:42 ` [ 59/95] drm/radeon: convert radeon vfct code to use acpi_get_table_with_size Ben Hutchings
2012-09-09 22:42 ` [ 60/95] drm/radeon: fix invalid memory access in radeon_atrm_get_bios() Ben Hutchings
2012-09-09 22:42 ` [ 61/95] drm/radeon: finish getting bios earlier Ben Hutchings
2012-09-09 22:42 ` [ 62/95] drm/radeon: fix use after free in ATRM bios reading code Ben Hutchings
2012-09-09 22:42 ` [ 63/95] drm/radeon: split ATRM support out from the ATPX handler (v3) Ben Hutchings
2012-09-09 22:42 ` [ 64/95] NFSv3: Ensure that do_proc_get_root() reports errors correctly Ben Hutchings
2012-09-09 22:42 ` [ 65/95] vfs: missed source of ->f_pos races Ben Hutchings
2012-09-09 22:42 ` [ 66/95] svcrpc: fix BUG() in svc_tcp_clear_pages Ben Hutchings
2012-09-09 22:42 ` [ 67/95] svcrpc: sends on closed socket should stop immediately Ben Hutchings
2012-09-09 22:42 ` [ 68/95] svcrpc: fix svc_xprt_enqueue/svc_recv busy-looping Ben Hutchings
2012-09-09 22:42 ` [ 69/95] Revert "drm/radeon: fix bo creation retry path" Ben Hutchings
2012-09-09 22:43 ` [ 70/95] fbcon: fix race condition between console lock and cursor timer (v1.1) Ben Hutchings
2012-09-09 22:43 ` [ 71/95] cciss: fix incorrect scsi status reporting Ben Hutchings
2012-09-09 22:43 ` [ 72/95] mm: hugetlbfs: correctly populate shared pmd Ben Hutchings
2012-09-09 22:43 ` [ 73/95] drivers/misc/sgi-xp/xpc_uv.c: SGI XPC fails to load when cpu 0 is out of IRQ resources Ben Hutchings
2012-09-09 22:43 ` [ 74/95] drivers/rtc/rtc-rs5c348.c: fix hour decoding in 12-hour mode Ben Hutchings
2012-09-09 22:43 ` [ 75/95] rapidio/tsi721: fix inbound doorbell interrupt handling Ben Hutchings
2012-09-09 22:43 ` [ 76/95] rapidio/tsi721: fix unused variable compiler warning Ben Hutchings
2012-09-09 22:43 ` [ 77/95] fs/buffer.c: remove BUG() in possible but rare condition Ben Hutchings
2012-09-09 22:43 ` Ben Hutchings [this message]
2012-09-09 22:43 ` [ 79/95] Bluetooth: Fix using uninitialized option in RFCMode Ben Hutchings
2012-09-09 22:43 ` [ 80/95] drivers/char/random.c: fix boot id uniqueness race Ben Hutchings
2012-09-09 22:43 ` [ 81/95] MAINTAINERS: Theodore Tso is taking over the random driver Ben Hutchings
2012-09-09 22:43 ` [ 82/95] random: Add comment to random_initialize() Ben Hutchings
2012-09-09 22:43 ` [ 83/95] dmi: Feed DMI table to /dev/random driver Ben Hutchings
2012-09-09 22:43 ` [ 84/95] virtio_blk: fix config handler race Ben Hutchings
2012-09-10 2:26 ` Rusty Russell
2012-09-10 2:45 ` Asias He
2012-09-10 15:25 ` Ben Hutchings
2012-09-09 22:43 ` [ 85/95] virtio_blk: Drop unused request tracking list Ben Hutchings
2012-09-09 22:43 ` [ 86/95] virtio-blk: Fix hot-unplug race in remove method Ben Hutchings
2012-09-09 22:43 ` [ 87/95] virtio-blk: Call del_gendisk() before disable guest kick Ben Hutchings
2012-09-09 22:43 ` [ 88/95] virtio-blk: Reset device after blk_cleanup_queue() Ben Hutchings
2012-09-09 22:43 ` [ 89/95] HID: add support for Cypress barcode scanner 04B4:ED81 Ben Hutchings
2012-09-09 22:43 ` [ 90/95] pmac_zilog,kdb: Fix console poll hook to return instead of loop Ben Hutchings
2012-09-09 22:43 ` [ 91/95] Staging: speakup: fix an improperly-declared variable Ben Hutchings
2012-09-09 22:43 ` [ 92/95] NFS: Fix Oopses in nfs_lookup_revalidate and nfs4_lookup_revalidate Ben Hutchings
2012-09-12 6:45 ` Suresh Jayaraman
2012-09-09 22:43 ` [ 93/95] asus-nb-wmi: add some video toggle keys Ben Hutchings
2012-09-09 22:43 ` [ 94/95] Squashfs: fix mount time sanity check for corrupted superblock Ben Hutchings
2012-09-09 22:43 ` [ 95/95] mm: avoid swapping out with swappiness==0 Ben Hutchings
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120909224201.319503363@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=axboe@kernel.dk \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome