Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1387293pxb; Sun, 11 Apr 2021 18:10:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2HqbcbPQazCccYREyTu7snVNoDHpjm0PLaiyC8r94X4oRVket9Qu9I3yfox+KMhK4Ps8o X-Received: by 2002:aa7:d84b:: with SMTP id f11mr26922482eds.149.1618189803064; Sun, 11 Apr 2021 18:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618189803; cv=none; d=google.com; s=arc-20160816; b=uyheETBjh5980JIm/TI9Wgap9KlUceMKnXxfWJwlmRypZ61C+2s+4D/dgKwBGz8Wxy turBOyfYovm/W7oEISSvcTLAmyttrJEjChGLy20jmITzIU3JqokpWih44XJphokuANr9 QR1pvHXq00cUNdy+qTfcVWOLA3E7yOY7YSdl09yyUQiuW5yDs3+KL4umzlSNQdYXXoRS neVmgzjrp6En/0ZCWA32xOGslr5FVSJ/4ToHbiRfn7nAlUmZtnC2deWUg6xcnTVmVkYy ochGyryyayAl/Eos539EYv3Kcn0yOA0vC5CSM0lcYSLrsWDrhrsDk+N/vxJChJ1q6pLH OCpw== 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=oqXSI06SJ9PoeBbxEnQ8Lq7evQmEz8KQ2990/2Hf0RQ=; b=ubq8QBGf8lrhjeNzfmdKEvVJLIqOCh2OQFKguq3fDrMZIG23U08Y9KHMUZ9Mx0g7RK +FfSyOqhL8pH6CfXMEt6c9P/V34/mY7dNfW5hMLnutUKh7lsWLPKZ9sgh+sVCwBVaxlQ n5QFUwWYC5AJQrkrYqQoieUONBa+a5/vFiDcYUDN0lCqc+jBHxlgEMREzXZK4N9tzv6v 52tQvBN48Y50ID4i7puXSy/ZVjT/HCI441lyOVgrRVtaIYvn5d0KqK03lVstKKSm9sA8 zjcPDT86X/FGo7Jhhu2bPrMLvcFkoGMfFwQh+HKxKMvooZbQX20y1HnLeefZT9Oeq6Ph bL5w== 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 i2si6171319ejj.554.2021.04.11.18.09.39; Sun, 11 Apr 2021 18:10:03 -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 S235844AbhDLAz0 (ORCPT + 99 others); Sun, 11 Apr 2021 20:55:26 -0400 Received: from mga09.intel.com ([134.134.136.24]:12362 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235388AbhDLAzZ (ORCPT ); Sun, 11 Apr 2021 20:55:25 -0400 IronPort-SDR: 6nh6IxeGRSHOzk95MTlgjvllmI9QROPNINfWv5EPoZwpL4yx+3pvqKBlK6ZpcHu60ew8Fd2X8R iSy9u56Gyz7Q== X-IronPort-AV: E=McAfee;i="6000,8403,9951"; a="194198797" X-IronPort-AV: E=Sophos;i="5.82,214,1613462400"; d="scan'208";a="194198797" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2021 17:55:07 -0700 IronPort-SDR: T0w+1dSLSNJceumKgMBiMnlQebHoIE4I9Fv+9sQrumPYKc3AGx5lqaQAKY713tP7MbcVtqlLzc 5H30oT+UFXUg== X-IronPort-AV: E=Sophos;i="5.82,214,1613462400"; d="scan'208";a="459960660" 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; 11 Apr 2021 17:55:03 -0700 From: "Huang, Ying" To: Miaohe Lin Cc: , , , , , , , , , , , , Subject: Re: [PATCH 4/5] mm/swap_state: fix potential faulted in race in swap_ra_info() References: <20210408130820.48233-1-linmiaohe@huawei.com> <20210408130820.48233-5-linmiaohe@huawei.com> <874kgfyh85.fsf@yhuang6-desk1.ccr.corp.intel.com> Date: Mon, 12 Apr 2021 08:55:01 +0800 In-Reply-To: (Miaohe Lin's message of "Fri, 9 Apr 2021 17:00:02 +0800") Message-ID: <87v98swcd6.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: > On 2021/4/9 16:50, Huang, Ying wrote: >> Miaohe Lin writes: >> >>> While we released the pte lock, somebody else might faulted in this pte. >>> So we should check whether it's swap pte first to guard against such race >>> or swp_type would be unexpected. And we can also avoid some unnecessary >>> readahead cpu cycles possibly. >>> >>> Fixes: ec560175c0b6 ("mm, swap: VMA based swap readahead") >>> Signed-off-by: Miaohe Lin >>> --- >>> mm/swap_state.c | 13 +++++++++---- >>> 1 file changed, 9 insertions(+), 4 deletions(-) >>> >>> diff --git a/mm/swap_state.c b/mm/swap_state.c >>> index 709c260d644a..3bf0d0c297bc 100644 >>> --- a/mm/swap_state.c >>> +++ b/mm/swap_state.c >>> @@ -724,10 +724,10 @@ static void swap_ra_info(struct vm_fault *vmf, >>> { >>> struct vm_area_struct *vma = vmf->vma; >>> unsigned long ra_val; >>> - swp_entry_t entry; >>> + swp_entry_t swap_entry; >>> unsigned long faddr, pfn, fpfn; >>> unsigned long start, end; >>> - pte_t *pte, *orig_pte; >>> + pte_t *pte, *orig_pte, entry; >>> unsigned int max_win, hits, prev_win, win, left; >>> #ifndef CONFIG_64BIT >>> pte_t *tpte; >>> @@ -742,8 +742,13 @@ static void swap_ra_info(struct vm_fault *vmf, >>> >>> faddr = vmf->address; >>> orig_pte = pte = pte_offset_map(vmf->pmd, faddr); >>> - entry = pte_to_swp_entry(*pte); >>> - if ((unlikely(non_swap_entry(entry)))) { >>> + entry = *pte; >>> + if (unlikely(!is_swap_pte(entry))) { >>> + pte_unmap(orig_pte); >>> + return; >>> + } >>> + swap_entry = pte_to_swp_entry(entry); >>> + if ((unlikely(non_swap_entry(swap_entry)))) { >>> pte_unmap(orig_pte); >>> return; >>> } >> >> This isn't a real issue. entry or swap_entry isn't used in this > > Agree. It seems the entry or swap_entry here is just used for check whether > pte is still valid swap_entry. If you check the git history, you will find that the check has been necessary before. Because the function is used earlier in do_swap_page() at that time. Best Regards, Huang, Ying