The patch titled Subject: mm, swap: fix race between swapoff and some swap operations has been added to the -mm tree. Its filename is mm-swap-fix-race-between-swapoff-and-some-swap-operations-v6.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-swap-fix-race-between-swapoff-and-some-swap-operations-v6.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-swap-fix-race-between-swapoff-and-some-swap-operations-v6.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Huang Ying <ying.huang@xxxxxxxxx> Subject: mm, swap: fix race between swapoff and some swap operations - Add more comments to get_swap_device() to make it more clear about possible swapoff or swapoff+swapon. Link: http://lkml.kernel.org/r/20180223060010.954-1-ying.huang@xxxxxxxxx Signed-off-by: "Huang, Ying" <ying.huang@xxxxxxxxx> Cc: Hugh Dickins <hughd@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/memory.c | 2 +- mm/swapfile.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff -puN mm/memory.c~mm-swap-fix-race-between-swapoff-and-some-swap-operations-v6 mm/memory.c --- a/mm/memory.c~mm-swap-fix-race-between-swapoff-and-some-swap-operations-v6 +++ a/mm/memory.c @@ -2925,7 +2925,7 @@ int do_swap_page(struct vm_fault *vmf) struct swap_info_struct *si = swp_swap_info(entry); if (si->flags & SWP_SYNCHRONOUS_IO && - __swap_count(entry) == 1) { + __swap_count(entry) == 1) { /* skip swapcache */ page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address); diff -puN mm/swapfile.c~mm-swap-fix-race-between-swapoff-and-some-swap-operations-v6 mm/swapfile.c --- a/mm/swapfile.c~mm-swap-fix-race-between-swapoff-and-some-swap-operations-v6 +++ a/mm/swapfile.c @@ -1113,6 +1113,29 @@ static struct swap_info_struct *swap_inf * return pointer to swap_info_struct, and keep the swap entry valid * via preventing the swap device from being swapoff, until * put_swap_device() is called. Otherwise return NULL. + * + * Notice that swapoff or swapoff+swapon can still happen before the + * preempt_disable() in get_swap_device() or after the + * preempt_enable() in put_swap_device() if there isn't any other way + * to prevent swapoff, such as page lock, page table lock, etc. The + * caller must be prepared for that. For example, the following + * situation is possible. + * + * CPU1 CPU2 + * do_swap_page() + * ... swapoff+swapon + * __read_swap_cache_async() + * swapcache_prepare() + * __swap_duplicate() + * // check swap_map + * // verify PTE not changed + * + * In __swap_duplicate(), the swap_map need to be checked before + * changing partly because the specified swap entry may be for another + * swap device which has been swapoff. And in do_swap_page(), after + * the page is read from the swap device, the PTE is verified not + * changed with the page table locked to check whether the swap device + * has been swapoff or swapoff+swapon. */ struct swap_info_struct *get_swap_device(swp_entry_t entry) { _ Patches currently in -mm which might be from ying.huang@xxxxxxxxx are mm-fix-races-between-address_space-dereference-and-free-in-page_evicatable.patch mm-fix-races-between-swapoff-and-flush-dcache.patch mm-swap-fix-race-between-swapoff-and-some-swap-operations.patch mm-swap-fix-race-between-swapoff-and-some-swap-operations-v6.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