Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2571606pxb; Tue, 13 Apr 2021 05:20:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAo8JRcRc2+zGhcIbHX2Fps5yY9YTJ0151U36yefYO7DenXHA0tQCiqsP7cbeRfvOfRCQ4 X-Received: by 2002:a05:6402:68a:: with SMTP id f10mr34484510edy.26.1618316423255; Tue, 13 Apr 2021 05:20:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618316423; cv=none; d=google.com; s=arc-20160816; b=qPJYXzFL58UNubpIwsFZUSveNorn1LgWn/KkhHHH5nAC96ZudUqo+DrLyN8HXjGct2 8M42XGNTN2q/P7HzuKEYCpXArUPSwABiDH8DPcvfD4+6wOES6KOzy1OmUEtxvurSicdR WFk7X6csf1eUGShoiKqjbb8qD3hBdF1628XQivD1MvXxnc1irwnChE8kj3rxBz141AbK oUNZHkx2iZeJGTlAcoIPycdqdCmacBP8yLdZ6Q6IARpf9T5G9CmaoCvx4LZrFpXSpNnn 35fOZO2LHwxYSDMWCu2HfhJFRIm3lBVzbTuHj6tMpwIVbcALlNnvwpDSz2zloSs/7Fvd h07A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=dBmbZXUfJ+rKr5bqcqyRXKsude0DWNCY36dKiR0Awvo=; b=lkGJ+p3qoY8ZE3tKHmyzWzKsTVm8ZOIgavy7MgeunfdZMEA+p7Il53TPNVHDfzQ3yu WrIIcifD4pf1qMZsyU6nKBipieTFBflhZ95vxr7l1tkPbNioOw9PzkZmkE7l1E2JNcok c5mhwndkCJCHj4OrJA7GEPmMZyxzDGh9frd2QrOAQFD763DwpSoonSSD9nPTZAemXHap UhXbFwShHvjmo4ykDMTO7sjx8R1uLqcdtu+XDYzVupPzIPnW5FxkNMm2W6bMOpyTG3ar MhhZjUWl+KNFSpvTPK8rp7HI3SBqWUDonzzopRyGxTNXqOrWaAwFq6lFRyDB9VbVCsYI ERhw== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c97si11168784edf.404.2021.04.13.05.19.58; Tue, 13 Apr 2021 05:20:23 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240213AbhDMBg2 (ORCPT + 99 others); Mon, 12 Apr 2021 21:36:28 -0400 Received: from mga14.intel.com ([192.55.52.115]:31488 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239217AbhDMBg2 (ORCPT ); Mon, 12 Apr 2021 21:36:28 -0400 IronPort-SDR: Ks0mNFRqGQZmpFyxEOl2Z5y1JGtX5HLC+GQEeVxxYk/QpbdjfqDHx6kK6o7lq0iUEFNy3WffUi rSRjbpmeacuQ== X-IronPort-AV: E=McAfee;i="6200,9189,9952"; a="193875059" X-IronPort-AV: E=Sophos;i="5.82,216,1613462400"; d="scan'208";a="193875059" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2021 18:36:08 -0700 IronPort-SDR: zRlTi4pzNrHKsmZ1fcfAtAzWVA3jCcJG8g9hFVnAJVpg7onB/ZJS3Ep7RWTCBa6g8uZXCUGAey ojf9Jh8O6dpA== X-IronPort-AV: E=Sophos;i="5.82,216,1613462400"; d="scan'208";a="460397719" Received: from yhuang6-desk1.sh.intel.com (HELO yhuang6-desk1.ccr.corp.intel.com) ([10.239.13.1]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2021 18:36:04 -0700 From: "Huang, Ying" To: Miaohe Lin Cc: , , , , , , , , , , , , Subject: Re: [PATCH 5/5] mm/swap_state: fix swap_cluster_readahead() race with swapoff References: <20210408130820.48233-1-linmiaohe@huawei.com> <20210408130820.48233-6-linmiaohe@huawei.com> Date: Tue, 13 Apr 2021 09:36:02 +0800 In-Reply-To: <20210408130820.48233-6-linmiaohe@huawei.com> (Miaohe Lin's message of "Thu, 8 Apr 2021 09:08:20 -0400") Message-ID: <87eeffufst.fsf@yhuang6-desk1.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Miaohe Lin writes: > swap_cluster_readahead() could race with swapoff and might dereference > si->swap_file after it's released by swapoff. Close this race window by > using get/put_swap_device() pair. I think we should fix the callers instead to reduce the overhead. Now, do_swap_page() has been fixed. We need to fix shmem_swapin(). Best Regards, Huang, Ying > Signed-off-by: Miaohe Lin > --- > mm/swap_state.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/mm/swap_state.c b/mm/swap_state.c > index 3bf0d0c297bc..eba6b0cf6cf9 100644 > --- a/mm/swap_state.c > +++ b/mm/swap_state.c > @@ -626,12 +626,17 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, > unsigned long offset = entry_offset; > unsigned long start_offset, end_offset; > unsigned long mask; > - struct swap_info_struct *si = swp_swap_info(entry); > + struct swap_info_struct *si; > struct blk_plug plug; > bool do_poll = true, page_allocated; > struct vm_area_struct *vma = vmf->vma; > unsigned long addr = vmf->address; > > + si = get_swap_device(entry); > + /* In case we raced with swapoff. */ > + if (!si) > + return NULL; > + > mask = swapin_nr_pages(offset) - 1; > if (!mask) > goto skip; > @@ -673,7 +678,9 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, > > lru_add_drain(); /* Push any new pages onto the LRU now */ > skip: > - return read_swap_cache_async(entry, gfp_mask, vma, addr, do_poll); > + page = read_swap_cache_async(entry, gfp_mask, vma, addr, do_poll); > + put_swap_device(si); > + return page; > } > > int init_swap_address_space(unsigned int type, unsigned long nr_pages)