Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp443233pxb; Fri, 16 Apr 2021 09:16:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZkJsUBK+gfw1BD2WkPavm1cSYK9DVBuf0JhHOS/n+C/flAseD/uU9ZxwQchYlNY27KqnS X-Received: by 2002:a17:906:1dd3:: with SMTP id v19mr9099799ejh.4.1618589781553; Fri, 16 Apr 2021 09:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618589781; cv=none; d=google.com; s=arc-20160816; b=Q2mMNLSI9YeWsjYGkecEOFddhefJDDmV/ry23RxEu8XU0qfkWASiHgadQTl/F1ax+X hWZcrPvKpZymB97IjppkCYF8PhEulVYbeg3W9q483gaiIrxjczsc188+MDht7n51SVFR 2uvI7BaF0It1Kyfqrt1HaHMpZRnZhGUm9UIzA+YMW/BJ9CPNihxHO68mXIdTj+Onehik pbZ3W/WHoRtCfWgUs3QX9UvGghPggTjc+h9AlaJbewFuYyFiasHdCXBEu5FVjuDb7F5m kz9qa1TPgemlwD4u5g9tjJtFBeazNFVaqc7t1cELhii1sUTwskUeATlNnk1eYHOurk3n 4+Vg== 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 :ironport-sdr:ironport-sdr; bh=0iq+R1o8dlSCIpJuY0ogGOBIaraGSCDK1YDCPPBML7E=; b=cIKuNysPqnkeq7PsJ5C95/ZlflQaseZoJsazTScK0/djQrgdQegmM8+UqQoxwV+auh 5ojUhQpPTMjzYmXLWSt9wYvI7fGsqCJc19DRveCyu6roJcTm7KHmfTWJFfE1179CFB/O ufQqb7J3HYRujjFluehTYKZxjZj+zFRZW762FdJrm8UBXXDq4cYDcr+rUgeQyD0+y4HM 9jdY+rnjkU6N5HInH/4yllcwAJYvaCcHk4g0jmeEFV0Q1dgDACrEpuCX4dW+IwZDPDP6 JRgdBcLsDHoBBmBXccmkxYRLkvsobdjumrw6cpVMTLtkW9wTjNnfYBhXfiZYhWqmp2B+ UbUw== 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 f27si5743094edj.425.2021.04.16.09.15.58; Fri, 16 Apr 2021 09:16:21 -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 S1344022AbhDPPmN (ORCPT + 99 others); Fri, 16 Apr 2021 11:42:13 -0400 Received: from mga09.intel.com ([134.134.136.24]:4092 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343943AbhDPPmH (ORCPT ); Fri, 16 Apr 2021 11:42:07 -0400 IronPort-SDR: UnfIaZTA1WTwaplTy6pGqT4QKIXSSwzVUf6K5A1MPONKw6BU73gyEc5XP1G6rrGUCsC+nJqgMS M69UNntXbv/A== X-IronPort-AV: E=McAfee;i="6200,9189,9956"; a="195169144" X-IronPort-AV: E=Sophos;i="5.82,226,1613462400"; d="scan'208";a="195169144" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2021 08:41:41 -0700 IronPort-SDR: ar7dDxzt2Oi7GIhsG5qtuISAhRHVX9LRp+f1DQ8gtF04+3xB3T4x0fabS8zuRBBAEv60tGGXg6 I/rj8v9izkvQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,226,1613462400"; d="scan'208";a="383087500" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 16 Apr 2021 08:41:37 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 1DDE82CF; Fri, 16 Apr 2021 18:41:50 +0300 (EEST) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Sean Christopherson , Jim Mattson Cc: David Rientjes , "Edgecombe, Rick P" , "Kleen, Andi" , "Yamahata, Isaku" , Erdem Aktas , Steve Rutherford , Peter Gonda , David Hildenbrand , x86@kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [RFCv2 08/13] mm/gup: Add FOLL_ALLOW_POISONED Date: Fri, 16 Apr 2021 18:41:01 +0300 Message-Id: <20210416154106.23721-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210416154106.23721-1-kirill.shutemov@linux.intel.com> References: <20210416154106.23721-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The new flag allows to bypass check if the page is poisoned and get reference on it. Signed-off-by: Kirill A. Shutemov --- include/linux/mm.h | 1 + mm/gup.c | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index ecdf8a8cd6ae..378a94481fd1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2802,6 +2802,7 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address, #define FOLL_SPLIT_PMD 0x20000 /* split huge pmd before returning */ #define FOLL_PIN 0x40000 /* pages must be released via unpin_user_page */ #define FOLL_FAST_ONLY 0x80000 /* gup_fast: prevent fall-back to slow gup */ +#define FOLL_ALLOW_POISONED 0x100000 /* bypass poison check */ /* * FOLL_PIN and FOLL_LONGTERM may be used in various combinations with each diff --git a/mm/gup.c b/mm/gup.c index e4c224cd9661..dd3b79b03eb5 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -384,22 +384,29 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, ptep = pte_offset_map_lock(mm, pmd, address, &ptl); pte = *ptep; if (!pte_present(pte)) { - swp_entry_t entry; + swp_entry_t entry = pte_to_swp_entry(pte); + + if (pte_none(pte)) + goto no_page; + /* * KSM's break_ksm() relies upon recognizing a ksm page * even while it is being migrated, so for that case we * need migration_entry_wait(). */ - if (likely(!(flags & FOLL_MIGRATION))) - goto no_page; - if (pte_none(pte)) - goto no_page; - entry = pte_to_swp_entry(pte); - if (!is_migration_entry(entry)) - goto no_page; - pte_unmap_unlock(ptep, ptl); - migration_entry_wait(mm, pmd, address); - goto retry; + if (is_migration_entry(entry) && (flags & FOLL_MIGRATION)) { + pte_unmap_unlock(ptep, ptl); + migration_entry_wait(mm, pmd, address); + goto retry; + } + + if (is_hwpoison_entry(entry) && (flags & FOLL_ALLOW_POISONED)) { + page = hwpoison_entry_to_page(entry); + get_page(page); + goto out; + } + + goto no_page; } if ((flags & FOLL_NUMA) && pte_protnone(pte)) goto no_page; -- 2.26.3