* [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions
@ 2025-11-20 4:18 Paul Walmsley
2025-11-20 4:18 ` [PATCH 1/3] riscv: mm: pmdp_huge_get_and_clear(): avoid atomic ops when !CONFIG_SMP Paul Walmsley
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Paul Walmsley @ 2025-11-20 4:18 UTC (permalink / raw)
To: linux-riscv
This series implements some minor cleanups on the RISC-V page table
get-and-clear functions. We continue the work from commit
546e42c8c6d94 ("riscv: Use an atomic xchg in
pudp_huge_get_and_clear()"). The two themes are:
- avoid atomic operations on non-SMP kernels
- use xchg() rather than atomic_long_xchg() on variables that aren't
atomic_long_t
Tested on QEMU 10.0.6 on RV32 and RV64, SMP and !SMP, running kselftests.
- Paul
Paul Walmsley (3):
riscv: mm: pmdp_huge_get_and_clear(): avoid atomic ops when
!CONFIG_SMP
riscv: mm: ptep_get_and_clear(): avoid atomic ops when !CONFIG_SMP
riscv: mm: use xchg() on non-atomic_long_t variables, not
atomic_long_xchg()
arch/riscv/include/asm/pgtable.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
base-commit: dcb6fa37fd7bc9c3d2b066329b0d27dedf8becaa
--
2.48.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] riscv: mm: pmdp_huge_get_and_clear(): avoid atomic ops when !CONFIG_SMP
2025-11-20 4:18 [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions Paul Walmsley
@ 2025-11-20 4:18 ` Paul Walmsley
2025-11-20 4:18 ` [PATCH 2/3] riscv: mm: ptep_get_and_clear(): " Paul Walmsley
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Paul Walmsley @ 2025-11-20 4:18 UTC (permalink / raw)
To: linux-riscv
When !CONFIG_SMP, there's no need for atomic operations in
pmdp_huge_get_and_clear(), so, similar to what x86 does, let's not use
atomics in this case. See also commit 546e42c8c6d94 ("riscv: Use an
atomic xchg in pudp_huge_get_and_clear()").
Cc: Alexandre Ghiti <alex@ghiti.fr>
Signed-off-by: Paul Walmsley <pjw@kernel.org>
---
arch/riscv/include/asm/pgtable.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 5a08eb5fe99f..64a2197e6d97 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -861,7 +861,13 @@ static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
unsigned long address, pmd_t *pmdp)
{
+#ifdef CONFIG_SMP
pmd_t pmd = __pmd(atomic_long_xchg((atomic_long_t *)pmdp, 0));
+#else
+ pmd_t pmd = *pmdp;
+
+ pmd_clear(pmdp);
+#endif
page_table_check_pmd_clear(mm, pmd);
--
2.48.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] riscv: mm: ptep_get_and_clear(): avoid atomic ops when !CONFIG_SMP
2025-11-20 4:18 [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions Paul Walmsley
2025-11-20 4:18 ` [PATCH 1/3] riscv: mm: pmdp_huge_get_and_clear(): avoid atomic ops when !CONFIG_SMP Paul Walmsley
@ 2025-11-20 4:18 ` Paul Walmsley
2025-11-20 4:18 ` [PATCH 3/3] riscv: mm: use xchg() on non-atomic_long_t variables, not atomic_long_xchg() Paul Walmsley
2025-11-20 4:30 ` [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions patchwork-bot+linux-riscv
3 siblings, 0 replies; 5+ messages in thread
From: Paul Walmsley @ 2025-11-20 4:18 UTC (permalink / raw)
To: linux-riscv
When !CONFIG_SMP, there's no need for atomic operations in
ptep_get_and_clear(), so, similar to x86, let's not use atomics in
this case.
Cc: Alexandre Ghiti <alex@ghiti.fr>
Signed-off-by: Paul Walmsley <pjw@kernel.org>
---
arch/riscv/include/asm/pgtable.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 64a2197e6d97..e1610d031199 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -590,7 +590,13 @@ extern int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long a
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
unsigned long address, pte_t *ptep)
{
+#ifdef CONFIG_SMP
pte_t pte = __pte(atomic_long_xchg((atomic_long_t *)ptep, 0));
+#else
+ pte_t pte = *ptep;
+
+ set_pte(ptep, __pte(0));
+#endif
page_table_check_pte_clear(mm, pte);
--
2.48.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] riscv: mm: use xchg() on non-atomic_long_t variables, not atomic_long_xchg()
2025-11-20 4:18 [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions Paul Walmsley
2025-11-20 4:18 ` [PATCH 1/3] riscv: mm: pmdp_huge_get_and_clear(): avoid atomic ops when !CONFIG_SMP Paul Walmsley
2025-11-20 4:18 ` [PATCH 2/3] riscv: mm: ptep_get_and_clear(): " Paul Walmsley
@ 2025-11-20 4:18 ` Paul Walmsley
2025-11-20 4:30 ` [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions patchwork-bot+linux-riscv
3 siblings, 0 replies; 5+ messages in thread
From: Paul Walmsley @ 2025-11-20 4:18 UTC (permalink / raw)
To: linux-riscv
Let's not call atomic_long_xchg() on something that's not an
atomic_long_t, and just use xchg() instead. Continues the cleanup
from commit 546e42c8c6d94 ("riscv: Use an atomic xchg in
pudp_huge_get_and_clear()"),
Cc: Alexandre Ghiti <alex@ghiti.fr>
Signed-off-by: Paul Walmsley <pjw@kernel.org>
---
arch/riscv/include/asm/pgtable.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index e1610d031199..a1ffa502739b 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -591,7 +591,7 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
unsigned long address, pte_t *ptep)
{
#ifdef CONFIG_SMP
- pte_t pte = __pte(atomic_long_xchg((atomic_long_t *)ptep, 0));
+ pte_t pte = __pte(xchg(&ptep->pte, 0));
#else
pte_t pte = *ptep;
@@ -868,7 +868,7 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
unsigned long address, pmd_t *pmdp)
{
#ifdef CONFIG_SMP
- pmd_t pmd = __pmd(atomic_long_xchg((atomic_long_t *)pmdp, 0));
+ pmd_t pmd = __pmd(xchg(&pmdp->pmd, 0));
#else
pmd_t pmd = *pmdp;
--
2.48.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions
2025-11-20 4:18 [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions Paul Walmsley
` (2 preceding siblings ...)
2025-11-20 4:18 ` [PATCH 3/3] riscv: mm: use xchg() on non-atomic_long_t variables, not atomic_long_xchg() Paul Walmsley
@ 2025-11-20 4:30 ` patchwork-bot+linux-riscv
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-11-20 4:30 UTC (permalink / raw)
To: Paul Walmsley; +Cc: linux-riscv
Hello:
This series was applied to riscv/linux.git (for-next)
by Paul Walmsley <pjw@kernel.org>:
On Wed, 19 Nov 2025 21:18:27 -0700 you wrote:
> This series implements some minor cleanups on the RISC-V page table
> get-and-clear functions. We continue the work from commit
> 546e42c8c6d94 ("riscv: Use an atomic xchg in
> pudp_huge_get_and_clear()"). The two themes are:
>
> - avoid atomic operations on non-SMP kernels
>
> [...]
Here is the summary with links:
- [1/3] riscv: mm: pmdp_huge_get_and_clear(): avoid atomic ops when !CONFIG_SMP
https://git.kernel.org/riscv/c/44d98d7575d0
- [2/3] riscv: mm: ptep_get_and_clear(): avoid atomic ops when !CONFIG_SMP
https://git.kernel.org/riscv/c/ad6a7d4bcee7
- [3/3] riscv: mm: use xchg() on non-atomic_long_t variables, not atomic_long_xchg()
https://git.kernel.org/riscv/c/36313cea1273
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-20 4:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20 4:18 [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions Paul Walmsley
2025-11-20 4:18 ` [PATCH 1/3] riscv: mm: pmdp_huge_get_and_clear(): avoid atomic ops when !CONFIG_SMP Paul Walmsley
2025-11-20 4:18 ` [PATCH 2/3] riscv: mm: ptep_get_and_clear(): " Paul Walmsley
2025-11-20 4:18 ` [PATCH 3/3] riscv: mm: use xchg() on non-atomic_long_t variables, not atomic_long_xchg() Paul Walmsley
2025-11-20 4:30 ` [PATCH 0/3] riscv: mm: clean up and optimize some page table get-and-clear functions patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox