Re: [PATCH] mm, swap: Remove WARN_ON_ONCE() in free_swap_slot()

From: Tim Chen
Date: Tue Mar 21 2017 - 16:42:38 EST


On Mon, 2017-03-20 at 14:26 +0800, Huang, Ying wrote:
> From: Huang Ying <ying.huang@xxxxxxxxx>
>
> Before commit 452b94b8c8c7 ("mm/swap: don't BUG_ON() due to
> uninitialized swap slot cache"), the following bug is reported,
>
> Â ------------[ cut here ]------------
> Â kernel BUG at mm/swap_slots.c:270!
> Â invalid opcode: 0000 [#1] SMP
> Â CPU: 5 PID: 1745 Comm: (sd-pam) Not tainted 4.11.0-rc1-00243-g24c534bb161b #1
> Â Hardware name: System manufacturer System Product Name/Z170-K, BIOS
> 1803 05/06/2016
> Â RIP: 0010:free_swap_slot+0xba/0xd0
> Â Call Trace:
> ÂÂÂswap_free+0x36/0x40
> ÂÂÂdo_swap_page+0x360/0x6d0
> ÂÂÂ__handle_mm_fault+0x880/0x1080
> ÂÂÂhandle_mm_fault+0xd0/0x240
> ÂÂÂ__do_page_fault+0x232/0x4d0
> ÂÂÂdo_page_fault+0x20/0x70
> ÂÂÂpage_fault+0x22/0x30
> Â ---[ end trace aefc9ede53e0ab21 ]---
>
> This is raised by the BUG_ON(!swap_slot_cache_initialized) in
> free_swap_slot().ÂÂThis is incorrect, because even if the swap slots
> cache fails to be initialized, the swap should operate properly
> without the swap slots cache.ÂÂAnd the use_swap_slot_cache check later
> in the function will protect the uninitialized swap slots cache case.
>
> In commit 452b94b8c8c7, the BUG_ON() is replaced by WARN_ON_ONCE().
> In the patch, the WARN_ON_ONCE() is removed too.
>

This replaces my previous patch to replace the BUG_ON.

Acked-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>

> Reported-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Cc: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
> Cc: Michal Hocko <mhocko@xxxxxxxx>
> Signed-off-by: "Huang, Ying" <ying.huang@xxxxxxxxx>
> ---
> Âmm/swap_slots.c | 2 --
> Â1 file changed, 2 deletions(-)
>
> diff --git a/mm/swap_slots.c b/mm/swap_slots.c
> index 7ebb23836f68..b1ccb58ad397 100644
> --- a/mm/swap_slots.c
> +++ b/mm/swap_slots.c
> @@ -267,8 +267,6 @@ int free_swap_slot(swp_entry_t entry)
> Â{
> Â struct swap_slots_cache *cache;
> Â
> - WARN_ON_ONCE(!swap_slot_cache_initialized);
> -
> Â cache = &get_cpu_var(swp_slots);
> Â if (use_swap_slot_cache && cache->slots_ret) {
> Â spin_lock_irq(&cache->free_lock);