From: Muhammad Usama Anjum <usama.anjum@arm.com>
To: Ryan Roberts <ryan.roberts@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Ard Biesheuvel <ardb@kernel.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>
Cc: usama.anjum@arm.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org,
kasan-dev@googlegroups.com, linux-mm@kvack.org
Subject: Re: [PATCH 3/6] arm64: convert between HW PTEs and SW PTE values
Date: Mon, 21 Sep 2026 10:50:47 +0100 [thread overview]
Message-ID: <e044fdbc-a648-417d-9949-6e4e51040aa4@arm.com> (raw)
In-Reply-To: <86d4aea6-4272-427e-9229-295489e068d7@arm.com>
On 21/09/2026 9:26 am, Ryan Roberts wrote:
> On 14/09/2026 14:51, Muhammad Usama Anjum wrote:
>> __ptep_get() returns a SW PTE value, and __set_pte_nosync() accepts one.
>> When HW PTEs use a distinct hw_pte_t, directly reading or writing *ptep
>> as a SW PTE value no longer satisfies those interfaces.
>>
>> Use __pte_from_hw after READ_ONCE() to obtain a SW PTE value and add
>> __hw_pte before WRITE_ONCE() to form an HW PTE.
>>
>> Define __hw_pte for both the wrapper and alias configurations so the
>> same accessor code works in either case.
>>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@arm.com>
>> ---
>> arch/arm64/include/asm/pgtable.h | 4 ++--
>> include/linux/pgtable_types.h | 2 ++
>> 2 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
>> index 4768ec59de555..67c4a6179e154 100644
>> --- a/arch/arm64/include/asm/pgtable.h
>> +++ b/arch/arm64/include/asm/pgtable.h
>> @@ -360,7 +360,7 @@ static inline pte_t pte_clear_uffd(pte_t pte)
>>
>> static inline void __set_pte_nosync(hw_pte_t *ptep, pte_t pte)
>> {
>> - WRITE_ONCE(*ptep, pte);
>> + WRITE_ONCE(*ptep, __hw_pte(pte));
>
> Would this work as an alternative? It removes the need for the new __hw_pte()
> helper. In future, converting a pte_t to a hw_pte_t won't be trivial so having a
> generic helper for it doesn't feel like a good fit.
>
> WRITE_ONCE(hw_pte_val(*ptep), pte_val(pte));
Yeah, this would work. It removes the need for the generic conversion
helpers which is even better.
>
> In general, I wonder if we should avoid defining both the __hw_pte() and
> __pte_from_hw() generic helpers. Conversion between sw and hw representations
> will become arch-specific in future and for arm64 that conversion will need
> extra information so it's can't just specialize these interfaces as they are.
Agreed.
>
>> }
>>
>> static inline void __set_pte_complete(pte_t pte)
>> @@ -381,7 +381,7 @@ static inline void __set_pte(hw_pte_t *ptep, pte_t pte)
>>
>> static inline pte_t __ptep_get(hw_pte_t *ptep)
>> {
>> - return READ_ONCE(*ptep);
>> + return __pte_from_hw(READ_ONCE(*ptep));
>
>
> ...Corresponds with:
>
> return __pte(READ_ONCE(hw_pte_val(*ptep)));
I'll update.
>
> Thanks,
> Ryan
>
>> }
>>
>> extern void __sync_icache_dcache(pte_t pteval);
>> diff --git a/include/linux/pgtable_types.h b/include/linux/pgtable_types.h
>> index ee4eace5c3e1c..b5862a16aa497 100644
>> --- a/include/linux/pgtable_types.h
>> +++ b/include/linux/pgtable_types.h
>> @@ -9,11 +9,13 @@
>> #ifdef CONFIG_ARCH_HAS_HW_PTE_T
>> typedef struct __hw_pte_t { pte_t __pte; } hw_pte_t;
>> #define __pte_from_hw(pte) ((pte).__pte)
>> +#define __hw_pte(pte) ((hw_pte_t) { (pte) })
>>
>> #define hw_pte_val(x) pte_val((x).__pte)
>> #else
>> #define hw_pte_t pte_t
>> #define __pte_from_hw(pte) (pte)
>> +#define __hw_pte(pte) (pte)
>>
>> #define hw_pte_val(x) pte_val(x)
>> #endif
>>
>
--
Thanks,
Usama
next prev parent reply other threads:[~2026-09-21 9:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 13:51 [PATCH 0/6] arm64: distinguish HW PTE pointers from SW PTE value pointers Muhammad Usama Anjum
2026-09-14 13:51 ` [PATCH 1/6] arm64: use hw_pte_t for HW PTE pointers Muhammad Usama Anjum
2026-09-21 7:59 ` Ryan Roberts
2026-09-21 8:20 ` Muhammad Usama Anjum
2026-09-14 13:51 ` [PATCH 2/6] arm64: use hw_pte_val for HW PTE atomics Muhammad Usama Anjum
2026-09-18 15:55 ` Ryan Roberts
2026-09-21 8:49 ` Muhammad Usama Anjum
2026-09-14 13:51 ` [PATCH 3/6] arm64: convert between HW PTEs and SW PTE values Muhammad Usama Anjum
2026-09-18 15:56 ` Ryan Roberts
2026-09-21 8:26 ` Ryan Roberts
2026-09-21 9:50 ` Muhammad Usama Anjum [this message]
2026-09-14 13:51 ` [PATCH 4/6] arm64: use hw_pte_t for fixmap HW PTEs Muhammad Usama Anjum
2026-09-18 16:03 ` Ryan Roberts
2026-09-18 20:00 ` David Hildenbrand (Arm)
2026-09-21 7:37 ` Ryan Roberts
2026-09-21 8:29 ` Ryan Roberts
2026-09-14 13:51 ` [PATCH 5/6] arm64: use HW PTE accessors in early map_range() Muhammad Usama Anjum
2026-09-21 9:44 ` Ryan Roberts
2026-09-14 13:51 ` [PATCH 6/6] arm64: enable a distinct type for HW PTEs Muhammad Usama Anjum
2026-09-21 9:44 ` Ryan Roberts
2026-09-21 9:51 ` [PATCH 0/6] arm64: distinguish HW PTE pointers from SW PTE value pointers Ryan Roberts
2026-09-21 10:10 ` Muhammad Usama Anjum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e044fdbc-a648-417d-9949-6e4e51040aa4@arm.com \
--to=usama.anjum@arm.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=david@kernel.org \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=ilias.apalodimas@linaro.org \
--cc=kasan-dev@googlegroups.com \
--cc=liam@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=vincenzo.frascino@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®