From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DBF5C433ED for ; Wed, 14 Apr 2021 02:42:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E45616113D for ; Wed, 14 Apr 2021 02:42:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E45616113D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 78DAC6B0074; Tue, 13 Apr 2021 22:42:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73CB06B0075; Tue, 13 Apr 2021 22:42:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 603E36B0078; Tue, 13 Apr 2021 22:42:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 43CF66B0074 for ; Tue, 13 Apr 2021 22:42:57 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 044C843647B3 for ; Wed, 14 Apr 2021 02:42:57 +0000 (UTC) X-FDA: 78029425194.32.B7D7934 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf15.hostedemail.com (Postfix) with ESMTP id 885C6A0000FF for ; Wed, 14 Apr 2021 02:42:54 +0000 (UTC) Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FKmsH20DhzNvtd; Wed, 14 Apr 2021 10:39:47 +0800 (CST) Received: from [10.174.176.162] (10.174.176.162) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Wed, 14 Apr 2021 10:42:38 +0800 Subject: Re: [PATCH 3/5] mm/swap_state: fix get_shadow_from_swap_cache() race with swapoff To: "Huang, Ying" CC: , , , , , , , , , , , , References: <20210408130820.48233-1-linmiaohe@huawei.com> <20210408130820.48233-4-linmiaohe@huawei.com> <87im4rufwq.fsf@yhuang6-desk1.ccr.corp.intel.com> From: Miaohe Lin Message-ID: <4ebc0a78-6fde-9d43-7562-8ef7679b5460@huawei.com> Date: Wed, 14 Apr 2021 10:42:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <87im4rufwq.fsf@yhuang6-desk1.ccr.corp.intel.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.162] X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 885C6A0000FF X-Stat-Signature: 66zsfq9bkbn6xfqbtd84ahqm3gde944o X-Rspamd-Server: rspam02 Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=szxga05-in.huawei.com; client-ip=45.249.212.191 X-HE-DKIM-Result: none/none X-HE-Tag: 1618368174-980965 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2021/4/13 9:33, Huang, Ying wrote: > Miaohe Lin writes: > >> The function get_shadow_from_swap_cache() can race with swapoff, though >> it's only called by do_swap_page() now. >> >> Fixes: aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU") >> Signed-off-by: Miaohe Lin > > This is unnecessary. The only caller has guaranteed the swap device > from swapoff Ok. This patch is just in case get_shadow_from_swap_cache() would be called from elsewhere someday. It's unnecessary and can be dropped now . > > Best Regards, > Huang, Ying > >> --- >> mm/swap_state.c | 9 ++++++--- >> 1 file changed, 6 insertions(+), 3 deletions(-) >> >> diff --git a/mm/swap_state.c b/mm/swap_state.c >> index 272ea2108c9d..709c260d644a 100644 >> --- a/mm/swap_state.c >> +++ b/mm/swap_state.c >> @@ -83,11 +83,14 @@ void show_swap_cache_info(void) >> >> void *get_shadow_from_swap_cache(swp_entry_t entry) >> { >> - struct address_space *address_space = swap_address_space(entry); >> - pgoff_t idx = swp_offset(entry); >> + struct swap_info_struct *si; >> struct page *page; >> >> - page = xa_load(&address_space->i_pages, idx); >> + si = get_swap_device(entry); >> + if (!si) >> + return NULL; >> + page = xa_load(&swap_address_space(entry)->i_pages, swp_offset(entry)); >> + put_swap_device(si); >> if (xa_is_value(page)) >> return page; >> return NULL; > > . >