From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
Hugh Dickins <hughd@google.com>,
Konstantin Khlebnikov <khlebnikov@openvz.org>
Subject: [49/71] tmpfs: fix spurious ENOSPC when racing with unswap
Date: Thu, 19 May 2011 11:05:17 -0700 [thread overview]
Message-ID: <20110519180559.000998675@clark.kroah.org> (raw)
In-Reply-To: <20110519180626.GA16555@kroah.com>
2.6.38-stable review patch. If anyone has any objections, please let us know.
------------------
From: Hugh Dickins <hughd@google.com>
commit 59a16ead572330deb38e5848151d30ed1af754bc upstream.
Testing the shmem_swaplist replacements for igrab() revealed another bug:
writes to /dev/loop0 on a tmpfs file which fills its filesystem were
sometimes failing with "Buffer I/O error"s.
These came from ENOSPC failures of shmem_getpage(), when racing with
swapoff: the same could happen when racing with another shmem_getpage(),
pulling the page in from swap in between our find_lock_page() and our
taking the info->lock (though not in the single-threaded loop case).
This is unacceptable, and surprising that I've not noticed it before:
it dates back many years, but (presumably) was made a lot easier to
reproduce in 2.6.36, which sited a page preallocation in the race window.
Fix it by rechecking the page cache before settling on an ENOSPC error.
Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: Konstantin Khlebnikov <khlebnikov@openvz.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
mm/shmem.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1407,20 +1407,14 @@ repeat:
if (sbinfo->max_blocks) {
if (percpu_counter_compare(&sbinfo->used_blocks,
sbinfo->max_blocks) >= 0 ||
- shmem_acct_block(info->flags)) {
- spin_unlock(&info->lock);
- error = -ENOSPC;
- goto failed;
- }
+ shmem_acct_block(info->flags))
+ goto nospace;
percpu_counter_inc(&sbinfo->used_blocks);
spin_lock(&inode->i_lock);
inode->i_blocks += BLOCKS_PER_PAGE;
spin_unlock(&inode->i_lock);
- } else if (shmem_acct_block(info->flags)) {
- spin_unlock(&info->lock);
- error = -ENOSPC;
- goto failed;
- }
+ } else if (shmem_acct_block(info->flags))
+ goto nospace;
if (!filepage) {
int ret;
@@ -1500,6 +1494,24 @@ done:
error = 0;
goto out;
+nospace:
+ /*
+ * Perhaps the page was brought in from swap between find_lock_page
+ * and taking info->lock? We allow for that at add_to_page_cache_lru,
+ * but must also avoid reporting a spurious ENOSPC while working on a
+ * full tmpfs. (When filepage has been passed in to shmem_getpage, it
+ * is already in page cache, which prevents this race from occurring.)
+ */
+ if (!filepage) {
+ struct page *page = find_get_page(mapping, idx);
+ if (page) {
+ spin_unlock(&info->lock);
+ page_cache_release(page);
+ goto repeat;
+ }
+ }
+ spin_unlock(&info->lock);
+ error = -ENOSPC;
failed:
if (*pagep != filepage) {
unlock_page(filepage);
next prev parent reply other threads:[~2011-05-19 18:09 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-19 18:06 [00/71] 2.6.38.7-stable review Greg KH
2011-05-19 18:04 ` [01/71] cifs: change bleft in decode_unicode_ssetup back to signed type Greg KH
2011-05-19 18:04 ` [02/71] cifs: check for bytes_remaining going to zero in CIFS_SessSetup Greg KH
2011-05-19 18:04 ` [03/71] cifs: sanitize length checking in coalesce_t2 (try #3) Greg KH
2011-05-19 18:04 ` [04/71] cifs: refactor mid finding loop in cifs_demultiplex_thread Greg KH
2011-05-19 18:04 ` [05/71] cifs: handle errors from coalesce_t2 Greg KH
2011-05-19 18:04 ` [06/71] Validate size of EFI GUID partition entries Greg KH
2011-05-19 18:04 ` [07/71] drm/radeon/kms: add pci id to acer travelmate quirk for 5730 Greg KH
2011-05-19 18:04 ` [08/71] thinkpad-acpi: module autoloading for newer Lenovo ThinkPads Greg KH
2011-05-20 0:58 ` Henrique de Moraes Holschuh
2011-05-19 18:04 ` [09/71] x86, hw_breakpoints: Fix racy access to ptrace breakpoints Greg KH
2011-05-19 18:04 ` [10/71] ptrace: Prepare to fix racy accesses on task breakpoints Greg KH
2011-05-19 18:04 ` [11/71] hw_breakpoints, powerpc: Fix CONFIG_HAVE_HW_BREAKPOINT off-case in ptrace_set_debugreg() Greg KH
2011-05-19 18:04 ` [12/71] iwlwifi: add {ack, plpc}_check module parameters Greg KH
2011-05-19 18:04 ` [13/71] [stable] [PATCH] drm/radeon/kms: fix gart setup on fusion parts (v2) backport Greg KH
2011-05-19 18:04 ` [14/71] vm: fix vm_pgoff wrap in upward expansion Greg KH
2011-05-19 18:04 ` [15/71] Dont lock guardpage if the stack is growing up Greg KH
2011-05-19 18:04 ` [16/71] drm/i915/dp: Be paranoid in case we disable a DP before it is attached Greg KH
2011-05-19 18:04 ` [17/71] drm/i915/lvds: Only act on lid notify when the device is on Greg KH
2011-05-19 18:04 ` [18/71] drm/i915: Release object along create user fb error path Greg KH
2011-05-19 18:04 ` [19/71] dccp: handle invalid feature options length Greg KH
2011-05-19 18:04 ` [20/71] CIFS: Fix memory over bound bug in cifs_parse_mount_options Greg KH
2011-05-19 18:04 ` [21/71] drivers/rtc/rtc-s3c.c: fixup wake support for rtc Greg KH
2011-05-19 18:04 ` [22/71] mm: use alloc_bootmem_node_nopanic() on really needed path Greg KH
2011-05-19 18:04 ` [23/71] tmpfs: fix race between umount and swapoff Greg KH
2011-05-21 4:48 ` Hugh Dickins
2011-05-21 21:43 ` Greg KH
2011-05-19 18:04 ` [24/71] ARM: zImage: make sure the stack is 64-bit aligned Greg KH
2011-05-19 18:04 ` [25/71] PM: Fix warning in pm_restrict_gfp_mask() during SNAPSHOT_S2RAM ioctl Greg KH
2011-05-19 18:04 ` [26/71] PM / Hibernate: Make snapshot_release() restore GFP mask Greg KH
2011-05-19 18:04 ` [27/71] PM / Hibernate: Fix ioctl SNAPSHOT_S2RAM Greg KH
2011-05-19 18:04 ` [28/71] net: ip_expire() must revalidate route Greg KH
2011-05-19 18:04 ` [29/71] can: fix SJA1000 dlc for RTR packets Greg KH
2011-05-19 20:17 ` Kurt Van Dijck
2011-05-19 18:04 ` [30/71] ipheth: Properly distinguish length and alignment in URBs and skbs Greg KH
2011-05-19 18:04 ` [31/71] vmxnet3: Consistently disable irqs when taking adapter->cmd_lock Greg KH
2011-05-19 18:05 ` [32/71] ehea: fix wrongly reported speed and port Greg KH
2011-05-19 18:05 ` [33/71] NET: slip, fix ldisc->open retval Greg KH
2011-05-19 18:05 ` [34/71] PCH_GbE : Fixed the issue of collision detection Greg KH
2011-05-19 18:05 ` [35/71] PCH_GbE : Fixed the issue of checksum judgment Greg KH
2011-05-19 18:05 ` [36/71] pch_gbe: support ML7223 IOH Greg KH
2011-05-19 18:05 ` [37/71] net: dev_close() should check IFF_UP Greg KH
2011-05-19 18:05 ` [38/71] slcan: fix ldisc->open retval Greg KH
2011-05-19 18:05 ` [39/71] ASoC: UDA134x: Remove POWER_OFF_ON_STANDBY define Greg KH
2011-05-19 18:05 ` [40/71] ASoC: SSM2602: Fix Mic Boost2 control Greg KH
2011-05-19 18:05 ` [41/71] ne-h8300: Fix regression caused during net_device_ops conversion Greg KH
2011-05-19 18:05 ` [42/71] hydra: " Greg KH
2011-05-19 18:05 ` [43/71] ehea: Fix memory hotplug oops Greg KH
2011-05-19 18:05 ` [44/71] libertas: fix cmdpendingq locking Greg KH
2011-05-19 18:05 ` [45/71] zorro8390: Fix regression caused during net_device_ops conversion Greg KH
2011-05-19 18:05 ` [46/71] tmpfs: fix race between umount and writepage Greg KH
2011-05-19 18:05 ` [47/71] tmpfs: fix race between swapoff " Greg KH
2011-05-19 18:05 ` [48/71] tmpfs: fix off-by-one in max_blocks checks Greg KH
2011-05-19 18:05 ` Greg KH [this message]
2011-05-19 18:05 ` [50/71] libata: fix oops when LPM is used with PMP Greg KH
2011-05-19 18:05 ` [51/71] drm/radeon/kms: fix extended lvds info parsing Greg KH
2011-05-19 18:05 ` [52/71] Revert "mmc: fix a race between card-detect rescan and clock-gate work instances" Greg KH
2011-05-19 18:05 ` [53/71] cifs: add fallback in is_path_accessible for old servers Greg KH
2011-05-19 18:05 ` [54/71] rapidio: fix default routing initialization Greg KH
2011-05-19 18:05 ` [55/71] Revert "x86, AMD: Fix APIC timer erratum 400 affecting K8 Rev.A-E processors" Greg KH
2011-05-19 18:05 ` [56/71] x86, AMD: Fix ARAT feature setting again Greg KH
2011-05-19 18:05 ` [57/71] block: rescan partitions on invalidated devices on -ENOMEDIA too Greg KH
2011-05-19 18:12 ` Tejun Heo
2011-05-19 18:18 ` Greg KH
2011-05-25 9:09 ` Tejun Heo
2011-05-30 0:01 ` [stable] " Greg KH
2011-05-19 18:05 ` [58/71] clocksource: Install completely before selecting Greg KH
2011-05-19 18:05 ` [59/71] tick: Clear broadcast active bit when switching to oneshot Greg KH
2011-05-19 18:05 ` [60/71] x86, apic: Fix spurious error interrupts triggering on all non-boot APs Greg KH
2011-05-19 18:05 ` [61/71] [media] Fix cx88 remote control input Greg KH
2011-05-19 18:05 ` [62/71] [media] v4l: Release module if subdev registration fails Greg KH
2011-05-19 18:05 ` [63/71] x86: Fix UV BAU for non-consecutive nasids Greg KH
2011-05-19 18:05 ` [64/71] x86, mce, AMD: Fix leaving freed data in a list Greg KH
2011-05-19 18:05 ` [65/71] [SCSI] megaraid_sas: Sanity check user supplied length before passing it to dma_alloc_coherent() Greg KH
2011-05-19 18:05 ` [66/71] cdrom: always check_disk_change() on open Greg KH
2011-05-19 18:05 ` [67/71] vmxnet3: Fix inconsistent LRO state after initialization Greg KH
2011-05-19 18:05 ` [68/71] [SCSI] Revert "[SCSI] Retrieve the Caching mode page" Greg KH
2011-05-19 18:05 ` [69/71] cifs: clean up various nits in unicode routines (try #2) Greg KH
2011-05-19 18:05 ` [70/71] cifs: fix cifsConvertToUCS() for the mapchars case Greg KH
2011-05-19 18:05 ` [71/71] iwlegacy: fix IBSS mode crashes Greg KH
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=20110519180559.000998675@clark.kroah.org \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=hughd@google.com \
--cc=khlebnikov@openvz.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable-review@kernel.org \
--cc=stable@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
all inboxes | Powered by JetHome®