From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-it0-f71.google.com (mail-it0-f71.google.com [209.85.214.71]) by kanga.kvack.org (Postfix) with ESMTP id D39196B038C for ; Sat, 18 Mar 2017 12:57:19 -0400 (EDT) Received: by mail-it0-f71.google.com with SMTP id r141so72732737ita.6 for ; Sat, 18 Mar 2017 09:57:19 -0700 (PDT) Received: from mail-it0-x241.google.com (mail-it0-x241.google.com. [2607:f8b0:4001:c0b::241]) by mx.google.com with ESMTPS id k129si12647334iok.32.2017.03.18.09.57.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Mar 2017 09:57:19 -0700 (PDT) Received: by mail-it0-x241.google.com with SMTP id y18so9624625itc.2 for ; Sat, 18 Mar 2017 09:57:19 -0700 (PDT) MIME-Version: 1.0 From: Linus Torvalds Date: Sat, 18 Mar 2017 09:57:18 -0700 Message-ID: Subject: kernel BUG at mm/swap_slots.c:270 Content-Type: text/plain; charset=UTF-8 Sender: owner-linux-mm@kvack.org List-ID: To: Tim Chen , "Huang, Ying" , Michal Hocko , Andrew Morton Cc: linux-mm , Linux Kernel Mailing List Tim at al, I got this on my desktop at shutdown: ------------[ 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 ]--- so there seems to be something screwy in the new swap_slots code. Any ideas? I'm not finding other reports of this, but I'm also not seeing why it should BUG_ON(). The "use_swap_slot_cache" thing very much checks whether swap_slot_cache_initialized has been set, so the BUG_ON() just seems like garbage. But please take a look. Linus -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f198.google.com (mail-wr0-f198.google.com [209.85.128.198]) by kanga.kvack.org (Postfix) with ESMTP id 52F5C6B0389 for ; Sun, 19 Mar 2017 10:04:55 -0400 (EDT) Received: by mail-wr0-f198.google.com with SMTP id u48so22104901wrc.0 for ; Sun, 19 Mar 2017 07:04:55 -0700 (PDT) Received: from mx2.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id n69si11136194wmd.101.2017.03.19.07.04.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 Mar 2017 07:04:53 -0700 (PDT) Date: Sun, 19 Mar 2017 10:04:47 -0400 From: Michal Hocko Subject: Re: kernel BUG at mm/swap_slots.c:270 Message-ID: <20170319140447.GA12414@dhcp22.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: owner-linux-mm@kvack.org List-ID: To: Linus Torvalds Cc: Tim Chen , "Huang, Ying" , Andrew Morton , linux-mm , Linux Kernel Mailing List On Sat 18-03-17 09:57:18, Linus Torvalds wrote: > Tim at al, > I got this on my desktop at shutdown: > > ------------[ 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 ]--- > > so there seems to be something screwy in the new swap_slots code. I am travelling (LSFMM) so I didn't get to look at this more thoroughly but it seems like a race because enable_swap_slots_cache is called at the very end of the swapon and we could have already created a swap entry for a page by that time I guess. > Any ideas? I'm not finding other reports of this, but I'm also not > seeing why it should BUG_ON(). The "use_swap_slot_cache" thing very > much checks whether swap_slot_cache_initialized has been set, so the > BUG_ON() just seems like garbage. But please take a look. I guess you are right. I cannot speak of the original intention but it seems Tim wanted to be careful to not see unexpected swap entry when the swap wasn't initialized yet. I would just drop the BUG_ON and bail out when the slot cache hasn't been initialized yet. -- Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f71.google.com (mail-pg0-f71.google.com [74.125.83.71]) by kanga.kvack.org (Postfix) with ESMTP id A06266B0038 for ; Sun, 19 Mar 2017 21:25:53 -0400 (EDT) Received: by mail-pg0-f71.google.com with SMTP id 79so144205921pgf.2 for ; Sun, 19 Mar 2017 18:25:53 -0700 (PDT) Received: from mga04.intel.com (mga04.intel.com. [192.55.52.120]) by mx.google.com with ESMTPS id 3si15717798pls.17.2017.03.19.18.25.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Mar 2017 18:25:52 -0700 (PDT) From: "Huang\, Ying" Subject: Re: kernel BUG at mm/swap_slots.c:270 References: <20170319140447.GA12414@dhcp22.suse.cz> Date: Mon, 20 Mar 2017 09:25:50 +0800 In-Reply-To: <20170319140447.GA12414@dhcp22.suse.cz> (Michal Hocko's message of "Sun, 19 Mar 2017 10:04:47 -0400") Message-ID: <87d1dcd9i9.fsf@yhuang-dev.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: owner-linux-mm@kvack.org List-ID: To: Michal Hocko , Linus Torvalds Cc: Tim Chen , "Huang, Ying" , Andrew Morton , linux-mm , Linux Kernel Mailing List Hi, Michal Hocko writes: > On Sat 18-03-17 09:57:18, Linus Torvalds wrote: >> Tim at al, >> I got this on my desktop at shutdown: >> >> ------------[ 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 ]--- >> >> so there seems to be something screwy in the new swap_slots code. > > I am travelling (LSFMM) so I didn't get to look at this more thoroughly > but it seems like a race because enable_swap_slots_cache is called at > the very end of the swapon and we could have already created a swap > entry for a page by that time I guess. > >> Any ideas? I'm not finding other reports of this, but I'm also not >> seeing why it should BUG_ON(). The "use_swap_slot_cache" thing very >> much checks whether swap_slot_cache_initialized has been set, so the >> BUG_ON() just seems like garbage. But please take a look. > > I guess you are right. I cannot speak of the original intention but it > seems Tim wanted to be careful to not see unexpected swap entry when > the swap wasn't initialized yet. I would just drop the BUG_ON and bail > out when the slot cache hasn't been initialized yet. Yes. The BUG_ON() is problematic. The initialization of swap slot cache may fail too, if so, we should still allow using swap without slot cache. Will send out a fixing patch ASAP. Best Regards, Huang, Ying -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id D8B1B6B0038 for ; Mon, 20 Mar 2017 10:15:33 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id e126so7416614pfg.3 for ; Mon, 20 Mar 2017 07:15:33 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id x11si5287289pgx.284.2017.03.20.07.15.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Mar 2017 07:15:32 -0700 (PDT) Date: Mon, 20 Mar 2017 10:15:30 -0400 From: Tim Chen Subject: Re: kernel BUG at mm/swap_slots.c:270 Message-ID: <20170320141529.GA6417@linux.intel.com> Reply-To: tim.c.chen@linux.intel.com References: <20170319140447.GA12414@dhcp22.suse.cz> <87d1dcd9i9.fsf@yhuang-dev.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87d1dcd9i9.fsf@yhuang-dev.intel.com> Sender: owner-linux-mm@kvack.org List-ID: To: "Huang, Ying" Cc: Michal Hocko , Linus Torvalds , Andrew Morton , linux-mm , Linux Kernel Mailing List On Mon, Mar 20, 2017 at 09:25:50AM +0800, Huang, Ying wrote: > Hi, > > Michal Hocko writes: > > > On Sat 18-03-17 09:57:18, Linus Torvalds wrote: > >> Tim at al, > >> I got this on my desktop at shutdown: > >> > >> ------------[ 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 ]--- > >> > >> so there seems to be something screwy in the new swap_slots code. > > > > I am travelling (LSFMM) so I didn't get to look at this more thoroughly > > but it seems like a race because enable_swap_slots_cache is called at > > the very end of the swapon and we could have already created a swap > > entry for a page by that time I guess. > > > >> Any ideas? I'm not finding other reports of this, but I'm also not > >> seeing why it should BUG_ON(). The "use_swap_slot_cache" thing very > >> much checks whether swap_slot_cache_initialized has been set, so the > >> BUG_ON() just seems like garbage. But please take a look. > > > > I guess you are right. I cannot speak of the original intention but it > > seems Tim wanted to be careful to not see unexpected swap entry when > > the swap wasn't initialized yet. I would just drop the BUG_ON and bail > > out when the slot cache hasn't been initialized yet. > > Yes. The BUG_ON() is problematic. The initialization of swap slot > cache may fail too, if so, we should still allow using swap without slot > cache. Will send out a fixing patch ASAP. > I kind of suspect that the swap slot cache initialization failed for some reason. But swap should still work when we try to free a swap slot without the slots cache. A proposed patch to fix this problem: --->8--- From: Tim Chen Date: Mon, 20 Mar 2017 10:00:03 -0400 Subject: [PATCH] mm/swap: Fix inappropriate BUG_ON in swap_slots.c It is possible that we don't have swap_slots cache configured and running when swap is in use and swap slot is freed. So the BUG_ON is in appropriate when swap_slots cache is not initizliaed when a swap slot is released. Signed-off-by: Tim Chen --- mm/swap_slots.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/swap_slots.c b/mm/swap_slots.c index 9b5bc86..a17ecbf 100644 --- a/mm/swap_slots.c +++ b/mm/swap_slots.c @@ -267,10 +267,11 @@ int free_swap_slot(swp_entry_t entry) { struct swap_slots_cache *cache; - BUG_ON(!swap_slot_cache_initialized); + if (unlikely(!use_swap_slot_cache)) + swapcache_free_entries(&entry, 1); cache = &get_cpu_var(swp_slots); - if (use_swap_slot_cache && cache->slots_ret) { + if (cache->slots_ret) { spin_lock_irq(&cache->free_lock); /* Swap slots cache may be deactivated before acquiring lock */ if (!use_swap_slot_cache) { -- 2.5.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751835AbdCRR7Z (ORCPT ); Sat, 18 Mar 2017 13:59:25 -0400 Received: from mail-it0-f54.google.com ([209.85.214.54]:38282 "EHLO mail-it0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751780AbdCRR7W (ORCPT ); Sat, 18 Mar 2017 13:59:22 -0400 MIME-Version: 1.0 From: Linus Torvalds Date: Sat, 18 Mar 2017 09:57:18 -0700 X-Google-Sender-Auth: gPaJphq7-UYwz_ds899eSb9VtwM Message-ID: Subject: kernel BUG at mm/swap_slots.c:270 To: Tim Chen , "Huang, Ying" , Michal Hocko , Andrew Morton Cc: linux-mm , Linux Kernel Mailing List Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tim at al, I got this on my desktop at shutdown: ------------[ 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 ]--- so there seems to be something screwy in the new swap_slots code. Any ideas? I'm not finding other reports of this, but I'm also not seeing why it should BUG_ON(). The "use_swap_slot_cache" thing very much checks whether swap_slot_cache_initialized has been set, so the BUG_ON() just seems like garbage. But please take a look. Linus From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751983AbdCSOFG (ORCPT ); Sun, 19 Mar 2017 10:05:06 -0400 Received: from mx2.suse.de ([195.135.220.15]:43139 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751877AbdCSOEz (ORCPT ); Sun, 19 Mar 2017 10:04:55 -0400 Date: Sun, 19 Mar 2017 10:04:47 -0400 From: Michal Hocko To: Linus Torvalds Cc: Tim Chen , "Huang, Ying" , Andrew Morton , linux-mm , Linux Kernel Mailing List Subject: Re: kernel BUG at mm/swap_slots.c:270 Message-ID: <20170319140447.GA12414@dhcp22.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat 18-03-17 09:57:18, Linus Torvalds wrote: > Tim at al, > I got this on my desktop at shutdown: > > ------------[ 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 ]--- > > so there seems to be something screwy in the new swap_slots code. I am travelling (LSFMM) so I didn't get to look at this more thoroughly but it seems like a race because enable_swap_slots_cache is called at the very end of the swapon and we could have already created a swap entry for a page by that time I guess. > Any ideas? I'm not finding other reports of this, but I'm also not > seeing why it should BUG_ON(). The "use_swap_slot_cache" thing very > much checks whether swap_slot_cache_initialized has been set, so the > BUG_ON() just seems like garbage. But please take a look. I guess you are right. I cannot speak of the original intention but it seems Tim wanted to be careful to not see unexpected swap entry when the swap wasn't initialized yet. I would just drop the BUG_ON and bail out when the slot cache hasn't been initialized yet. -- Michal Hocko SUSE Labs From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752803AbdCTBZ5 (ORCPT ); Sun, 19 Mar 2017 21:25:57 -0400 Received: from mga05.intel.com ([192.55.52.43]:53119 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752756AbdCTBZz (ORCPT ); Sun, 19 Mar 2017 21:25:55 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,191,1486454400"; d="scan'208";a="78812225" From: "Huang\, Ying" To: Michal Hocko , Linus Torvalds Cc: Tim Chen , "Huang\, Ying" , Andrew Morton , linux-mm , Linux Kernel Mailing List Subject: Re: kernel BUG at mm/swap_slots.c:270 References: <20170319140447.GA12414@dhcp22.suse.cz> Date: Mon, 20 Mar 2017 09:25:50 +0800 In-Reply-To: <20170319140447.GA12414@dhcp22.suse.cz> (Michal Hocko's message of "Sun, 19 Mar 2017 10:04:47 -0400") Message-ID: <87d1dcd9i9.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Michal Hocko writes: > On Sat 18-03-17 09:57:18, Linus Torvalds wrote: >> Tim at al, >> I got this on my desktop at shutdown: >> >> ------------[ 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 ]--- >> >> so there seems to be something screwy in the new swap_slots code. > > I am travelling (LSFMM) so I didn't get to look at this more thoroughly > but it seems like a race because enable_swap_slots_cache is called at > the very end of the swapon and we could have already created a swap > entry for a page by that time I guess. > >> Any ideas? I'm not finding other reports of this, but I'm also not >> seeing why it should BUG_ON(). The "use_swap_slot_cache" thing very >> much checks whether swap_slot_cache_initialized has been set, so the >> BUG_ON() just seems like garbage. But please take a look. > > I guess you are right. I cannot speak of the original intention but it > seems Tim wanted to be careful to not see unexpected swap entry when > the swap wasn't initialized yet. I would just drop the BUG_ON and bail > out when the slot cache hasn't been initialized yet. Yes. The BUG_ON() is problematic. The initialization of swap slot cache may fail too, if so, we should still allow using swap without slot cache. Will send out a fixing patch ASAP. Best Regards, Huang, Ying From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755279AbdCTOUf (ORCPT ); Mon, 20 Mar 2017 10:20:35 -0400 Received: from mga01.intel.com ([192.55.52.88]:35356 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755077AbdCTOUc (ORCPT ); Mon, 20 Mar 2017 10:20:32 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,194,1486454400"; d="scan'208";a="238280743" Date: Mon, 20 Mar 2017 10:15:30 -0400 From: Tim Chen To: "Huang, Ying" Cc: Michal Hocko , Linus Torvalds , Andrew Morton , linux-mm , Linux Kernel Mailing List Subject: Re: kernel BUG at mm/swap_slots.c:270 Message-ID: <20170320141529.GA6417@linux.intel.com> Reply-To: tim.c.chen@linux.intel.com References: <20170319140447.GA12414@dhcp22.suse.cz> <87d1dcd9i9.fsf@yhuang-dev.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87d1dcd9i9.fsf@yhuang-dev.intel.com> User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 20, 2017 at 09:25:50AM +0800, Huang, Ying wrote: > Hi, > > Michal Hocko writes: > > > On Sat 18-03-17 09:57:18, Linus Torvalds wrote: > >> Tim at al, > >> I got this on my desktop at shutdown: > >> > >> ------------[ 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 ]--- > >> > >> so there seems to be something screwy in the new swap_slots code. > > > > I am travelling (LSFMM) so I didn't get to look at this more thoroughly > > but it seems like a race because enable_swap_slots_cache is called at > > the very end of the swapon and we could have already created a swap > > entry for a page by that time I guess. > > > >> Any ideas? I'm not finding other reports of this, but I'm also not > >> seeing why it should BUG_ON(). The "use_swap_slot_cache" thing very > >> much checks whether swap_slot_cache_initialized has been set, so the > >> BUG_ON() just seems like garbage. But please take a look. > > > > I guess you are right. I cannot speak of the original intention but it > > seems Tim wanted to be careful to not see unexpected swap entry when > > the swap wasn't initialized yet. I would just drop the BUG_ON and bail > > out when the slot cache hasn't been initialized yet. > > Yes. The BUG_ON() is problematic. The initialization of swap slot > cache may fail too, if so, we should still allow using swap without slot > cache. Will send out a fixing patch ASAP. > I kind of suspect that the swap slot cache initialization failed for some reason. But swap should still work when we try to free a swap slot without the slots cache. A proposed patch to fix this problem: --->8--- From: Tim Chen Date: Mon, 20 Mar 2017 10:00:03 -0400 Subject: [PATCH] mm/swap: Fix inappropriate BUG_ON in swap_slots.c It is possible that we don't have swap_slots cache configured and running when swap is in use and swap slot is freed. So the BUG_ON is in appropriate when swap_slots cache is not initizliaed when a swap slot is released. Signed-off-by: Tim Chen --- mm/swap_slots.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/swap_slots.c b/mm/swap_slots.c index 9b5bc86..a17ecbf 100644 --- a/mm/swap_slots.c +++ b/mm/swap_slots.c @@ -267,10 +267,11 @@ int free_swap_slot(swp_entry_t entry) { struct swap_slots_cache *cache; - BUG_ON(!swap_slot_cache_initialized); + if (unlikely(!use_swap_slot_cache)) + swapcache_free_entries(&entry, 1); cache = &get_cpu_var(swp_slots); - if (use_swap_slot_cache && cache->slots_ret) { + if (cache->slots_ret) { spin_lock_irq(&cache->free_lock); /* Swap slots cache may be deactivated before acquiring lock */ if (!use_swap_slot_cache) { -- 2.5.5