From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C02343002A9 for ; Fri, 26 Jun 2026 04:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782446947; cv=none; b=KCfuu9flrDyG95blb/Kq+rVDtpE1TCH1IilKK4g6aetTUzBCAsYKUWVC54rNjkxYaxt5xehBep/BxcOCeJqawrRjbPF/OXPLTJCfj7dRRlFLKQ4ZqTckMGNvjTWzOEX7Bb1F5hL2rDYSfGu4T3yab1mOlzGmIOd4QF3tpjNH7PQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782446947; c=relaxed/simple; bh=HTppeoW4NUFkZpfSV8jrwpujTK0jbxEnDx0YkxariVc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UwpGyYP/I+t0x9s9KpW5g8MfCPQW7Zz2ZO7nvu8lA3CvLP0KqB3r2N5tAGGlzbbuoCgkyJ+KWEBd/jBJ7lPsWuc0Skd9ErHrlSwhR81uqnTinBfLbKW+5PZ2auE8wR5PO9x0W0QFQZtpgAtu71h/uEoyBfDHbFZWAyoz7N3aVys= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=BCyLB4Cr; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="BCyLB4Cr" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 768F727B5; Thu, 25 Jun 2026 21:09:00 -0700 (PDT) Received: from [10.164.148.34] (MacBook-Pro.blr.arm.com [10.164.148.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 85BA93F905; Thu, 25 Jun 2026 21:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1782446945; bh=HTppeoW4NUFkZpfSV8jrwpujTK0jbxEnDx0YkxariVc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=BCyLB4CrsL2+cJ/CqAZnk5YVodeXEj2yrFVUItVBDQXbvlWz5we0Lahkc57HaKdFW Zm+txWK8ClKRkpS3Io3gCn7upJoo7X89fOszid/dSI78uOEwl0EzJ/f7g7F1ahkane leEH1DS+Aheq/ePrcsecZKe2olK2W65eoghQMYlE= Message-ID: Date: Fri, 26 Jun 2026 09:38:52 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 5/5] mm/mprotect: use huge_ptep_get() for hugetlb To: Muchun Song Cc: riel@surriel.com, vbabka@kernel.org, harry@kernel.org, jannh@google.com, lance.yang@linux.dev, kas@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, rcampbell@nvidia.com, apopple@nvidia.com, ziy@nvidia.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, mel@csn.ul.ie, nao.horiguchi@gmail.com, ak@linux.intel.com, j-nomura@ce.jp.nec.com, pfalcato@suse.de, dave.hansen@intel.com, tglx@kernel.org, jpoimboe@kernel.org, ryan.roberts@arm.com, anshuman.khandual@arm.com, osalvador@suse.de, akpm@linux-foundation.org, ljs@kernel.org, david@kernel.org, liam@infradead.org References: <20260625112955.3254283-1-dev.jain@arm.com> <20260625112955.3254283-6-dev.jain@arm.com> <28f75d0d-de54-43a1-b46a-fe3dd1188929@linux.dev> Content-Language: en-US From: Dev Jain In-Reply-To: <28f75d0d-de54-43a1-b46a-fe3dd1188929@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 26/06/26 9:10 am, Muchun Song wrote: > > > On 2026/6/25 19:29, Dev Jain wrote: >> prot_none_hugetlb_entry() is the hugetlb callback for the early >> mprotect(PROT_NONE) PFN permission walk on x86. >> >> The callback passes the decoded PFN to pfn_modify_allowed(). For a >> hugetlb callback, the pte pointer refers to a hugetlb entry. On >> architectures where hugetlb entries need huge_ptep_get(), reading that >> entry with ptep_get() can make the permission check use the wrong PFN. >> >> Use huge_ptep_get() before decoding the hugetlb PFN. >> >> Currently there is no path which can trigger a bug: huge_ptep_get() is a >> simple ptep_get() for x86, and the prot_none walk occurs only for x86. >> But use the correct helper anyways. >> >> Fixes: 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings") >> Signed-off-by: Dev Jain >> --- >>   mm/mprotect.c | 8 +++++++- >>   1 file changed, 7 insertions(+), 1 deletion(-) >> >> diff --git a/mm/mprotect.c b/mm/mprotect.c >> index 9cbf932b028cf..23779632d18bf 100644 >> --- a/mm/mprotect.c >> +++ b/mm/mprotect.c >> @@ -699,14 +699,20 @@ static int prot_none_pte_entry(pte_t *pte, unsigned long addr, >>           0 : -EACCES; >>   } >>   +#ifdef CONFIG_HUGETLB_PAGE >>   static int prot_none_hugetlb_entry(pte_t *pte, unsigned long hmask, >>                      unsigned long addr, unsigned long next, >>                      struct mm_walk *walk) >>   { >> -    return pfn_modify_allowed(pte_pfn(ptep_get(pte)), >> +    pte_t entry = huge_ptep_get(walk->mm, addr, pte); >> + >> +    return pfn_modify_allowed(pte_pfn(entry), >>                     *(pgprot_t *)(walk->private)) ? >>           0 : -EACCES; >>   } >> +#else >> +#define prot_none_hugetlb_entry    NULL > > This is very strange, because we defined a stub as NULL for a helper I was following pattern elsewhere, search for ".hugetlb_entry" in the codebase and you will find others doing the same. > function. How about  the following diff? > > diff --git a/mm/mprotect.c b/mm/mprotect.c > index 9cbf932b028c..4d8c1551fbce 100644 > --- a/mm/mprotect.c > +++ b/mm/mprotect.c > @@ -716,7 +716,9 @@ static int prot_none_test(unsigned long addr, unsigned long next, > >  static const struct mm_walk_ops prot_none_walk_ops = { >         .pte_entry              = prot_none_pte_entry, > +#ifdef CONFIG_HUGETLB_PAGE >         .hugetlb_entry          = prot_none_hugetlb_entry, > +#endif >         .test_walk              = prot_none_test, >         .walk_lock              = PGWALK_WRLOCK, >  }; > > Thanks, > Muchun > >> +#endif >>     static int prot_none_test(unsigned long addr, unsigned long next, >>                 struct mm_walk *walk) >