Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3415836pxb; Wed, 14 Apr 2021 05:13:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMRBzicvIisn/SKveJx9kGj13CkidP1awXEqxH9j4S8TBYPATwlw8Q1s9qxyq/jls23RgC X-Received: by 2002:a17:906:17ca:: with SMTP id u10mr5625419eje.124.1618402395473; Wed, 14 Apr 2021 05:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618402395; cv=none; d=google.com; s=arc-20160816; b=hByPBM3AHU7Wc0/25a60MU8OfdW0ukPtqjXjWBGMiRd7hZEAVq8Qeh51HeWPyrZvs0 JamPzAf4M/JxfkQklFot5+zRWVl0IaTn/F8z+OnpLAAv7Pxdqh9cW9QwuasOnVQBt1cH p8A5WZdrPUMBEruh73J8yinoJtWr8SRmkjMQYkLHWbjEwyklqC2nCtsoRG3HAnUIoaZC wBUBXSSDK4N+Or4DPrWLPVwFCc/Z6526HvxGuMe4PeSicwSXvYv/cNsXH1EO1cmTBeSs Jlfdv1Km/48VThuy4JJmJ39iS4Y7tca41RzblsZwW+d3nzn/K6kEYEVfUWiCwX4GUvJq 9Daw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=I25vQqr+z6OgZQxOfVt3AzkU74Dxi7iEIfWho+PPrZ0=; b=k+W6zm0G4bxaRhBoUjnznqpnU2/hcFQcjxRF2rbDfWg4ARrHLcNEd1aYt+ccLp08Af /o/l2q1cHWxm7dVfDc8Y2H3OeQ81ztW5D4+ZNylWCQuhNSaCGnvW3leI13xe1YxensGu ztWE78u7If+76cNecPho0u56tlTetkX38qeLKFSAeOSZ/vC7Uu2TklDtKDRKDsoYIi2p NS+ou3y5giSCPclOmANcYlsmydsMrSmQVVV0j22wSMHHE92xL+TKZtDFJrAxkQr4dZWU uolkNYGzTLMjWgsc4J5+J2dGGJFv5rFy88rdEwY31lOQOTc6TIuJDK2QmrJEw4Calgvs Ltyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h24si8102284ejf.662.2021.04.14.05.12.46; Wed, 14 Apr 2021 05:13:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232904AbhDNCnD (ORCPT + 99 others); Tue, 13 Apr 2021 22:43:03 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:16990 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232274AbhDNCnC (ORCPT ); Tue, 13 Apr 2021 22:43:02 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > > . >