linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/1] mm: Allow detection of wrong arch_enter_lazy_mmu_mode() context
@ 2025-04-08 16:48 Alexander Gordeev
  2025-04-08 16:48 ` [PATCH v2 1/1] " Alexander Gordeev
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Gordeev @ 2025-04-08 16:48 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-mm, linux-s390

Hi All,

This patch is aimed at 6.16-rc1 and should be applied not before [1].

Changes since v1:
- this patch is split into a separate series;

1. https://lore.kernel.org/stable/ef8f6538b83b7fc3372602f90375348f9b4f3596.1744128123.git.agordeev@linux.ibm.com/

Thanks!

Alexander Gordeev (1):
  mm: Allow detection of wrong arch_enter_lazy_mmu_mode() context

 include/linux/pgtable.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

-- 
2.45.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/1] mm: Allow detection of wrong arch_enter_lazy_mmu_mode() context
  2025-04-08 16:48 [PATCH v2 0/1] mm: Allow detection of wrong arch_enter_lazy_mmu_mode() context Alexander Gordeev
@ 2025-04-08 16:48 ` Alexander Gordeev
  2025-04-10 15:24   ` Alexander Gordeev
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Gordeev @ 2025-04-08 16:48 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-mm, linux-s390

The lazy MMU batching may be only be entered and left under the
protection of the page table locks for all page tables which may
be modified. Yet, there were cases arch_enter_lazy_mmu_mode()
was called without the locks taken, e.g. commit b9ef323ea168
("powerpc/64s: Disable preemption in hash lazy mmu mode").

Make default arch_enter|leave|flush_lazy_mmu_mode() callbacks
complain at least in case the preemption is enabled to detect
wrong contexts.

Most platforms do not implement the callbacks, so to aovid a
performance impact allow the complaint when CONFIG_DEBUG_VM
option is enabled only.

Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
---
 include/linux/pgtable.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index e2b705c14945..959590bb66da 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -232,9 +232,18 @@ static inline int pmd_dirty(pmd_t pmd)
  * and the mode cannot be used in interrupt context.
  */
 #ifndef __HAVE_ARCH_ENTER_LAZY_MMU_MODE
-#define arch_enter_lazy_mmu_mode()	do {} while (0)
-#define arch_leave_lazy_mmu_mode()	do {} while (0)
-#define arch_flush_lazy_mmu_mode()	do {} while (0)
+static inline void arch_enter_lazy_mmu_mode(void)
+{
+	VM_WARN_ON(preemptible());
+}
+static inline void arch_leave_lazy_mmu_mode(void)
+{
+	VM_WARN_ON(preemptible());
+}
+static inline void arch_flush_lazy_mmu_mode(void)
+{
+	VM_WARN_ON(preemptible());
+}
 #endif
 
 #ifndef pte_batch_hint
-- 
2.45.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/1] mm: Allow detection of wrong arch_enter_lazy_mmu_mode() context
  2025-04-08 16:48 ` [PATCH v2 1/1] " Alexander Gordeev
@ 2025-04-10 15:24   ` Alexander Gordeev
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Gordeev @ 2025-04-10 15:24 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-mm, linux-s390

On Tue, Apr 08, 2025 at 06:48:31PM +0200, Alexander Gordeev wrote:
> The lazy MMU batching may be only be entered and left under the
> protection of the page table locks for all page tables which may
> be modified. Yet, there were cases arch_enter_lazy_mmu_mode()
> was called without the locks taken, e.g. commit b9ef323ea168
> ("powerpc/64s: Disable preemption in hash lazy mmu mode").
> 
> Make default arch_enter|leave|flush_lazy_mmu_mode() callbacks
> complain at least in case the preemption is enabled to detect
> wrong contexts.
> 
> Most platforms do not implement the callbacks, so to aovid a
> performance impact allow the complaint when CONFIG_DEBUG_VM
> option is enabled only.
> 
> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
> ---
>  include/linux/pgtable.h | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)

Andrew,

Following [1] comment to "[PATCH v2 3/3] mm: Protect kernel pgtables in
apply_to_pte_range()" I think this patch should also be dropped.

1. https://lore.kernel.org/all/Z%2FfauW5hDSt+ciwr@li-008a6a4c-3549-11b2-a85c-c5cc2836eea2.ibm.com/

Thanks!


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-10 15:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-08 16:48 [PATCH v2 0/1] mm: Allow detection of wrong arch_enter_lazy_mmu_mode() context Alexander Gordeev
2025-04-08 16:48 ` [PATCH v2 1/1] " Alexander Gordeev
2025-04-10 15:24   ` Alexander Gordeev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox