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 0ACFD313E31 for ; Fri, 26 Jun 2026 04:42:46 +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=1782448968; cv=none; b=Aw86VKpuPrSBpCmrSiw2zqN4ATxRn9EwUSc2TuTo9tIgXgZ5rI3SPdQh03CNDW/p0QaJrv134k2WD0ubH818ae42Um4Ewg86+OJoKx8XIsISkK4uXN3j7cpeg8CjAAGSEtkW/ZFMVgq8zEBUEsa+sYb1RLLbRw2xFxPTUtCvsRA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782448968; c=relaxed/simple; bh=jm0W1HK2v0EV8GOom2wsH9OJKWlaesJ9dgMzcyqKEhw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=DNdwgW+ywugmxoKh4ctIfbdeVTLwMepytCoUsQdB/MCV70BczTObb77Sv3GXswkhQBxviCQimSsZmvAYCupsYaaDsY++isiTL/7g+NQMc6NSN73X/0HVSMYCg5fG12k0E00KUGhYCbNVC6aLCnn2aOZzWRcq1yOm1BYk5PbLg/w= 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=Omt1UEns; 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="Omt1UEns" 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 C7FB82BCB; Thu, 25 Jun 2026 21:42:41 -0700 (PDT) Received: from [10.164.19.14] (unknown [10.164.19.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 32E823F905; Thu, 25 Jun 2026 21:42:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1782448966; bh=jm0W1HK2v0EV8GOom2wsH9OJKWlaesJ9dgMzcyqKEhw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Omt1UEnsa3O5EvFoZTeggyk3IRsLZKvm39+Eue4aqJ688x9dxZQxFhgZP2iqXBRdu Tut8EOm7Ii0Hh7/X8+sGBUI9N3GlJPjexaQMMvkOFgR24mPipoVbKBJYImtyINRVJ4 J7rt0tcmQ8vm0K7Fsxz0+HGMUfd8yHUcse9/Rzh0= Message-ID: <3875df90-760e-49c5-ac18-c43fc7ede133@arm.com> Date: Fri, 26 Jun 2026 10:12:35 +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: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 26/06/26 9:51 am, Muchun Song wrote: > > >> On Jun 26, 2026, at 12:08, Dev Jain wrote: >> >> >> >> 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. > > Okay, I understand why you want to do it that way, but I would still > recommend not following that format. Okay then I'll update v2 with the below diff. > > Thanks. > >> >> >>> 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) > > >