[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 6/9] mm: convert PTE table entry to pte
- To: Alexander Gordeev <agordeev@xxxxxxxxxxxxx>
- From: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
- Date: Mon, 10 Aug 2026 12:06:39 +0100
- Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=linux.ibm.com smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
- Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BnQqdXX1ZyOUKKU4li9Bc+RBJzrUk6RyawcfqsSj/Eo=; b=G+FkAECJjVw0S0GHsHYBzilgEhx+mh3nMjHEmm3/QIsdHJuFaqOpe7EWTpH/cIUsAcDUJe5YGHTq9H0Mv6vxDe4cUXZ/lxFnlfuCyYwf14o1x20iWGXYw8co5Qtoa7sTdmQfm+dg0efhWdP8B/tltGRDVog1K04qF7Ba2EewOo/Oqezxs9Jss462e6DuhRO1JjRFbNeISoIdqmM6wO8n/tWoMivh28F7lDgxxSGQfgLXNBPImvDgGR/zOB3tPl2CRDbR8juQv3PiO0bH0xi4lMtTwizYvC6VGayanrxr+pVY+Y8Dz2UgpZOnoQeDPdv1LMgmNGjqO+C9rdorbSqtIQ==
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BnQqdXX1ZyOUKKU4li9Bc+RBJzrUk6RyawcfqsSj/Eo=; b=GdzwAUCegwRfCxVii+ZLGkAHtO3xXp4tzYPyF0iDSnfrKkoUNGEAMGhyDAQb39r1zcUcsMnxah9Xs/c0/bOPAN64IsYrxlHANrH0uiSvjthio3zxLLdIAClSLHTCk/a2+wLIy/0MPUkjKdt2o8mrBSwHvXehtjU2VwCbcamMxE5XsWs9w1H5IV6kNrcPdqkbq5Q6QOTzInJZbqCCym37I5EOnc2q7D/bPp1USuGxXPCX3As3bQ2IIjG6tgAGC81jJJmeoYrKOCrspJs2VC20PJ0vlwKKSWXEZu3j4/LNx5lQiLcRbzue4l6uOentjCiBOvApUlYxv4u6XBCNs2j9Kg==
- Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=NpfveSg/8h0SZbLFOQkd9a23PTo9LDt9y+bWfMh9J2+KQ80xwXGIx2B+WmDxkOTlFdPMn9r3AUQrASz7wbWOVso69P75Ftpp2ZuW0uadEWi3ULKuuNCXT3UDo/MlPmBHD6+nR7vThRvrHpmX+XfcH+okPBXjn2EiHm3DLtJnSfZL2kRK5ebWvkwJi6y0+oXilnoS04k+uqH5AqQkrBGxKTXh1lN22oU0gb8TQWEFHM6utJA105mYrmHpMHos1igY/vRJWkOSMz7+fibMeeAWrhjRc178ZFOCB5MVEONnWquzfdhZi8u9jPDAQg+YggpyzOJUC0oGgLg509lWVZrHZw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ziuome5/djtyBQzLEzz0klmAysoiBI5ZAwdG5vnb3nMr09jdV9VGv97x/PZogNuexDHgr5Xo5nw3XjHMCCjfiOoa3inGpsNMEfFzlW8yKZg8LiwfBlpVURriB1zGsB2mAyZBoQUt4prjIke7q/FWySr+Ygo8QBVmuE6d+O/0OjpAKTIxOIjcOkraqFpDsBHE4rCU647hc4e0D6FVP0Kv4noUVajpvIWXLH9litFTkeZXuLKIJYC12llbrMGJ4d2Dt8a8LFKPaUChAGM6/FefuJTy4GvU/zRGIvq3uWLhj4xlGe29JKudC2FebNsOezbu0guaNOMNCGQI/DuWebZESA==
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
- Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
- Cc: usama.anjum@xxxxxxx, Jani Nikula <jani.nikula@xxxxxxxxxxxxxxx>, Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>, Rodrigo Vivi <rodrigo.vivi@xxxxxxxxx>, Tvrtko Ursulin <tursulin@xxxxxxxxxxx>, David Airlie <airlied@xxxxxxxxx>, Simona Vetter <simona@xxxxxxxx>, Dimitri Sivanich <dimitri.sivanich@xxxxxxx>, Arnd Bergmann <arnd@xxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, "James E.J. Bottomley" <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>, Helge Deller <deller@xxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Muchun Song <muchun.song@xxxxxxxxx>, Oscar Salvador <osalvador@xxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, "Liam R. Howlett" <liam@xxxxxxxxxxxxx>, Lorenzo Stoakes <ljs@xxxxxxxxxx>, Will Deacon <will@xxxxxxxxxx>, "Aneesh Kumar K.V" <aneesh.kumar@xxxxxxxxxx>, Nick Piggin <npiggin@xxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, Andrey Ryabinin <ryabinin.a.a@xxxxxxxxx>, David Hildenbrand <david@xxxxxxxxxx>, Pasha Tatashin <pasha.tatashin@xxxxxxxxxx>, Chris Li <chrisl@xxxxxxxxxx>, Kairui Song <kasong@xxxxxxxxxxx>, Uladzislau Rezki <urezki@xxxxxxxxx>, Steven Rostedt <rostedt@xxxxxxxxxxx>, Masami Hiramatsu <mhiramat@xxxxxxxxxx>, Alexei Starovoitov <ast@xxxxxxxxxx>, Daniel Borkmann <daniel@xxxxxxxxxxxxx>, Andrii Nakryiko <andrii@xxxxxxxxxx>, Eduard Zingerman <eddyz87@xxxxxxxxx>, Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>, Namhyung Kim <namhyung@xxxxxxxxxx>, SJ Park <sj@xxxxxxxxxx>, "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx>, Jan Kara <jack@xxxxxxx>, Jason Gunthorpe <jgg@xxxxxxxx>, Leon Romanovsky <leon@xxxxxxxxxx>, Miaohe Lin <linmiaohe@xxxxxxxxxx>, Dennis Zhou <dennis@xxxxxxxxxx>, Tejun Heo <tj@xxxxxxxxxx>, Christoph Lameter <cl@xxxxxxxxxx>, Mike Rapoport <rppt@xxxxxxxxxx>, Johannes Weiner <hannes@xxxxxxxxxxx>, ziy@xxxxxxxxxx, pfalcato@xxxxxxx, ryan.roberts@xxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, intel-gfx@xxxxxxxxxxxxxxxxxxxxx, dri-devel@xxxxxxxxxxxxxxxxxxxxx, linux-parisc@xxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-mm@xxxxxxxxx, linux-fsdevel@xxxxxxxxxxxxxxx, linux-arch@xxxxxxxxxxxxxxx, kasan-dev@xxxxxxxxxxxxxxxx, linux-trace-kernel@xxxxxxxxxxxxxxx, bpf@xxxxxxxxxxxxxxx, linux-perf-users@xxxxxxxxxxxxxxx, damon@xxxxxxxxxxxxxxx
- Delivery-date: Mon, 10 Aug 2026 11:07:58 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Nodisclaimer: true
On 10/08/2026 7:44 am, Alexander Gordeev wrote:
> On Fri, Aug 07, 2026 at 05:26:04PM +0100, Muhammad Usama Anjum wrote:
>> On 07/08/2026 7:58 am, Alexander Gordeev wrote:
>>> On Thu, Aug 06, 2026 at 09:38:44AM +0100, Muhammad Usama Anjum wrote:
>>>> The non-MMU stub receives hw_pte_t but returns a logical pte_t
>>>> value. Convert the stored entry through __pte_from_hw() before
>>>> returning.
>>>>
>>>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
>>>> ---
>>>> include/linux/hugetlb.h | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
>>>> index bc0b9c65aa1d0..9e8b391aa4bc9 100644
>>>> --- a/include/linux/hugetlb.h
>>>> +++ b/include/linux/hugetlb.h
>>>> @@ -1283,7 +1283,7 @@ static inline pte_t huge_ptep_clear_flush(struct
>>>> vm_area_struct *vma,
>>>> #ifdef CONFIG_MMU
>>>> return ptep_get(ptep);
>>>> #else
>>>> - return *ptep;
>>>> + return __pte_from_hw(*ptep);
>>>
>>> But this is a direct dereferencing, which breaks the whole point, isn't it?
>> Yes, this is particular line is for non MMU. In this case,
>> CONIFG_ARCH_HAS_HW_PTE
>> would never be defined. Hence hw_pte_t is just pte_t and direct dereference
>> is
>> allowed. I'd thought a lot about it; is better to leave direct dereference
>> here
>> or use some helper. Then used __pte_from_hw() was already being used in
>> generic
>> ptep_get().
>
> But in case CONIFG_ARCH_HAS_HW_PTE=n __pte_from_hw() is still gets called.
> That looks inconsistent to me. Why not just call ptep_deref() (see below)?
Agreed. Calling __pte_from_hw() directly exposes the representation
conversion at the call site. I will introduce ptep_deref() and use it
here.
>
>> There are only two users of __pte_from_hw() at this time.
>>
>>>
>>> What about introducing something like pte_t ptep_get_sw(hw_pte_t *ptep)
>>> to be used in exactly situations like this? With that the semantics of
>>> hw_pte_t pointers becomes straightforward and closes the still ongoing
>>> "storage vs lifetime" discussion:
>>>
>>> hw_pte_t* points to HW-formatted page table entries
>>>
>>> ptep_get() is used to obtain HW-linked/attached entries, and may wire
>>> extra code like [1] or [2]
>>>
>>> ptep_get_sw() is used to obtain HW-unlinked/unattached entries and in
>>> most cases is just a direct dereference
>> ptep_get_sw() or ptep_get_deref() is better name here?
>
> ptep_deref() would be it.
>
> Do you agree to the suggested API requirements?
Yes. hw_pte_t * identifies storage containing hardware-formatted PTEs,
regardless of whether it is attached. ptep_get() is used for attached
entries and may provide additional architecture-specific handling.
ptep_deref() is used for unattached entries and performs only the raw
storage-to-value conversion.
For review, this patch would become:
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index bc0b9c65aa1d0..ce900d2652d91 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -1283,7 +1283,7 @@ static inline pte_t huge_ptep_clear_flush(struct
vm_area_struct *vma,
#ifdef CONFIG_MMU
return ptep_get(ptep);
#else
- return *ptep;
+ return ptep_deref(ptep);
#endif
}
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 1768421755a9c..08613593f3320 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -490,6 +490,13 @@ static inline int pudp_set_access_flags(struct
vm_area_struct *vma,
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
#endif
+#ifndef ptep_deref
+static inline pte_t ptep_deref(hw_pte_t *ptep)
+{
+ return __pte_from_hw(*ptep);
+}
+#endif
+
#ifndef ptep_get
static inline pte_t ptep_get(hw_pte_t *ptep)
{
--
Thanks,
Usama
|