Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp432418pxf; Thu, 8 Apr 2021 06:13:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4oz598rXWPxZxRf2HK6odAbepmhpBD+ciohOT0EiaOjDtlwbYnDfaJzkxO0Gljfo/kNyh X-Received: by 2002:a17:907:6289:: with SMTP id nd9mr10200726ejc.384.1617887622366; Thu, 08 Apr 2021 06:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617887622; cv=none; d=google.com; s=arc-20160816; b=hG32V4ZUfChmhAOIy+sGnHDAtXeOXhWRui7FsqwvmdI/PH3tky6BhBQQzLIsDGxLUW j78h/Wa+IyUeg/d4BVZyI3/2dsWwi1ZdxcVcEnQ43lMyWrfdfc+3wc5h8YAd7KJCvXSA 6pYbHFufqvxAJmasNwWisTRfrc4Z26I0XLzjQvDHXX2h6p2ZqfCpJORXN+RFoKuXtKne QjrFEEjrLtZMcc8ifO6XyuPbaF+d94u3itUWnsm6T13jjukj59mVAt/kHT0YbxxKCjc7 BkdILsmmpR+0WNAI7CKyUMxkO6JPeOdXSXPP2vET17rl72hF+QdjU1nzGcnvmGy+bSqr Gh1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dcYtjnac16e7Cyf/92RgJiPInrkP4i+mSwaF4R1h16I=; b=HY+UuM/VBQ2el4IQam2GHr7XAry4zE4pICCQUqyjeDt9eW1RhF20PEwbqc279hFzDX qXHVStH3kW1Mo0//nzBGECVeWmrtpfaAAyTjsq2iuhxUrKV29olKdumlKc9uxxPDywPC fqYl6kRGr3E0VYFnv+78tdkRSf4EWw45jEHdmgSHKaubMt8CBCx3hnW9cnAhNlRr357u 3Po5bcYJyUg5vcMlQ9Q0mUM1RSwKWy6NozLJmw446UjLgtn5faapkcmW4As9iWHSgoO0 18xp+y9OPtUowkxSh1x8qiIeiMe57PFvcEh/FY85qsWl3Yy0Qc1PUvn7SvZet3PK3aWM TDiw== 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 m13si22970769edd.35.2021.04.08.06.13.19; Thu, 08 Apr 2021 06:13:42 -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 S231667AbhDHNJh (ORCPT + 99 others); Thu, 8 Apr 2021 09:09:37 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:16418 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231610AbhDHNJb (ORCPT ); Thu, 8 Apr 2021 09:09:31 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FGM4L1YkKzkjgH; Thu, 8 Apr 2021 21:07:30 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Thu, 8 Apr 2021 21:09:09 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , Subject: [PATCH 3/5] mm/swap_state: fix get_shadow_from_swap_cache() race with swapoff Date: Thu, 8 Apr 2021 09:08:18 -0400 Message-ID: <20210408130820.48233-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20210408130820.48233-1-linmiaohe@huawei.com> References: <20210408130820.48233-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 2.19.1