Subject: [merged] swap-fix-set_blocksize-race-during-swapon-swapoff.patch removed from -mm tree To: k.kozlowski@xxxxxxxxxxx,bob.liu@xxxxxxxxxx,hughd@xxxxxxxxxx,konrad.wilk@xxxxxxxxxx,minchan@xxxxxxxxxx,shli@xxxxxxxxxxxx,weijie.yang.kh@xxxxxxxxx,mm-commits@xxxxxxxxxxxxxxx From: akpm@xxxxxxxxxxxxxxxxxxxx Date: Thu, 17 Oct 2013 11:13:29 -0700 The patch titled Subject: swap: fix set_blocksize race during swapon/swapoff has been removed from the -mm tree. Its filename was swap-fix-set_blocksize-race-during-swapon-swapoff.patch This patch was dropped because it was merged into mainline or a subsystem tree ------------------------------------------------------ From: Krzysztof Kozlowski <k.kozlowski@xxxxxxxxxxx> Subject: swap: fix set_blocksize race during swapon/swapoff Fix race between swapoff and swapon. Swapoff used old_block_size from swap_info outside of swapon_mutex so it could be overwritten by concurrent swapon. The race has visible effect only if more than one swap block device exists with different block sizes (e.g. /dev/sda1 with block size 4096 and /dev/sdb1 with 512). In such case it leads to setting the blocksize of swapped off device with wrong blocksize. The bug can be triggered with multiple concurrent swapoff and swapon: 0. Swap for some device is on. 1. swapoff: First the swapoff is called on this device and "struct swap_info_struct *p" is assigned. This is done under swap_lock however this lock is released for the call try_to_unuse(). 2. swapon: After the assignment above (and before acquiring swapon_mutex & swap_lock by swapoff) the swapon is called on the same device. The p->old_block_size is assigned to the value of block_size the device. This block size should be the same as previous but sometimes it is not. The swapon ends successfully. 3. swapoff: Swapoff resumes, grabs the locks and mutex and continues to disable this swap device. Now it sets the block size to value taken from swap_info which was overwritten by swapon in 2. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@xxxxxxxxxxx> Reported-by: Weijie Yang <weijie.yang.kh@xxxxxxxxx> Cc: Bob Liu <bob.liu@xxxxxxxxxx> Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> Cc: Shaohua Li <shli@xxxxxxxxxxxx> Cc: Minchan Kim <minchan@xxxxxxxxxx> Acked-by: Hugh Dickins <hughd@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/swapfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff -puN mm/swapfile.c~swap-fix-set_blocksize-race-during-swapon-swapoff mm/swapfile.c --- a/mm/swapfile.c~swap-fix-set_blocksize-race-during-swapon-swapoff +++ a/mm/swapfile.c @@ -1824,6 +1824,7 @@ SYSCALL_DEFINE1(swapoff, const char __us struct filename *pathname; int i, type, prev; int err; + unsigned int old_block_size; if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -1914,6 +1915,7 @@ SYSCALL_DEFINE1(swapoff, const char __us } swap_file = p->swap_file; + old_block_size = p->old_block_size; p->swap_file = NULL; p->max = 0; swap_map = p->swap_map; @@ -1938,7 +1940,7 @@ SYSCALL_DEFINE1(swapoff, const char __us inode = mapping->host; if (S_ISBLK(inode->i_mode)) { struct block_device *bdev = I_BDEV(inode); - set_blocksize(bdev, p->old_block_size); + set_blocksize(bdev, old_block_size); blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); } else { mutex_lock(&inode->i_mutex); _ Patches currently in -mm which might be from k.kozlowski@xxxxxxxxxxx are origin.patch frontswap-enable-call-to-invalidate-area-on-swapoff.patch swap-fix-setting-page_size-blocksize-during-swapoff-swapon-race.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html