linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Vlastimil Babka <vbabka@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Tejun Heo <tj@kernel.org>, Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	Alexei Starovoitov <ast@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	bpf@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Meta kernel team <kernel-team@meta.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	npiggin@gmail.com
Subject: Re: [PATCH 0/4] memcg: nmi-safe kmem charging
Date: Wed, 14 May 2025 09:11:44 +0200	[thread overview]
Message-ID: <20250514071144.GB24938@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <ct2h2eyuepa2g2ltl5fucfegwyuqspvz6d4uugcs4szxwnggdc@6m4ks3hp3tjj>

On Tue, May 13, 2025 at 03:17:00PM -0700, Shakeel Butt wrote:

> > IIRC Power64 has issues here, 'funnily' their local_t is NMI safe.
> > Perhaps we could do the same for their this_cpu_*(), but ideally someone
> > with actual power hardware should do this ;-)
> > 
> 
> Is CONFIG_ARCH_HAS_NMI_SAFE_THIS_CPU_OPS the right config to
> differentiate between such archs? I see Power64 does not have that
> enabled.

> > There is no config symbol for this presently.
> 
> Hmm what about CONFIG_ARCH_HAS_NMI_SAFE_THIS_CPU_OPS?

Hmm, I didn't know about that one, and it escaped my grep yesterday.

Anyway, PPC is fixable, just not sure its worth it for them.

> > 
> > > - (if the above leaves any 64bit arch) its 64bit atomics implementation is safe
> > 
> > True, only because HPPA does not in fact have NMIs.
> 
> What is HPPA?

arch/parisc the worst 64bit arch ever.

They saw sparc32-smp and thought that was a great idea, or something
along those lines. Both are quite terrible. Sparc64 realized the mistake
and fixed it -- it has cmpxchg.


Nick, is this something that's useful for you guys?

---
diff --git a/arch/powerpc/include/asm/percpu.h b/arch/powerpc/include/asm/percpu.h
index ecf5ac70cfae..aa188db68ef5 100644
--- a/arch/powerpc/include/asm/percpu.h
+++ b/arch/powerpc/include/asm/percpu.h
@@ -25,6 +25,11 @@ DECLARE_STATIC_KEY_FALSE(__percpu_first_chunk_is_paged);
 #define percpu_first_chunk_is_paged	false
 #endif
 
+#ifdef CONFIG_PPC_BOOK3S_64
+#define __pcpu_local_irq_save(f) powerpc_local_irq_pmu_save(f)
+#define __pcpu_local_irq_restore(s) powerpc_local_irq_pmu_restore(f)
+#endif
+
 #include <asm-generic/percpu.h>
 
 #include <asm/paca.h>
diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h
index 02aeca21479a..5c8376588dfb 100644
--- a/include/asm-generic/percpu.h
+++ b/include/asm-generic/percpu.h
@@ -75,6 +75,11 @@ extern void setup_per_cpu_areas(void);
 #define PER_CPU_ATTRIBUTES
 #endif
 
+#ifndef __pcpu_local_irq_save
+#define __pcpu_local_irq_save(x) raw_local_irq_save(x)
+#define __pcpu_local_irq_restore(x) raw_local_irq_restore(x)
+#endif
+
 #define raw_cpu_generic_read(pcp)					\
 ({									\
 	*raw_cpu_ptr(&(pcp));						\
@@ -146,9 +151,9 @@ do {									\
 ({									\
 	TYPEOF_UNQUAL(pcp) ___ret;					\
 	unsigned long ___flags;						\
-	raw_local_irq_save(___flags);					\
+	__pcpu_local_irq_save(___flags);					\
 	___ret = raw_cpu_generic_read(pcp);				\
-	raw_local_irq_restore(___flags);				\
+	__pcpu_local_irq_restore(___flags);				\
 	___ret;								\
 })
 
@@ -165,9 +170,9 @@ do {									\
 #define this_cpu_generic_to_op(pcp, val, op)				\
 do {									\
 	unsigned long __flags;						\
-	raw_local_irq_save(__flags);					\
+	__pcpu_local_irq_save(__flags);					\
 	raw_cpu_generic_to_op(pcp, val, op);				\
-	raw_local_irq_restore(__flags);					\
+	__pcpu_local_irq_restore(__flags);					\
 } while (0)
 
 
@@ -175,9 +180,9 @@ do {									\
 ({									\
 	TYPEOF_UNQUAL(pcp) __ret;					\
 	unsigned long __flags;						\
-	raw_local_irq_save(__flags);					\
+	__pcpu_local_irq_save(__flags);					\
 	__ret = raw_cpu_generic_add_return(pcp, val);			\
-	raw_local_irq_restore(__flags);					\
+	__pcpu_local_irq_restore(__flags);					\
 	__ret;								\
 })
 
@@ -185,9 +190,9 @@ do {									\
 ({									\
 	TYPEOF_UNQUAL(pcp) __ret;					\
 	unsigned long __flags;						\
-	raw_local_irq_save(__flags);					\
+	__pcpu_local_irq_save(__flags);					\
 	__ret = raw_cpu_generic_xchg(pcp, nval);			\
-	raw_local_irq_restore(__flags);					\
+	__pcpu_local_irq_restore(__flags);					\
 	__ret;								\
 })
 
@@ -195,9 +200,9 @@ do {									\
 ({									\
 	bool __ret;							\
 	unsigned long __flags;						\
-	raw_local_irq_save(__flags);					\
+	__pcpu_local_irq_save(__flags);					\
 	__ret = raw_cpu_generic_try_cmpxchg(pcp, ovalp, nval);		\
-	raw_local_irq_restore(__flags);					\
+	__pcpu_local_irq_restore(__flags);					\
 	__ret;								\
 })
 
@@ -205,9 +210,9 @@ do {									\
 ({									\
 	TYPEOF_UNQUAL(pcp) __ret;					\
 	unsigned long __flags;						\
-	raw_local_irq_save(__flags);					\
+	__pcpu_local_irq_save(__flags);					\
 	__ret = raw_cpu_generic_cmpxchg(pcp, oval, nval);		\
-	raw_local_irq_restore(__flags);					\
+	__pcpu_local_irq_restore(__flags);					\
 	__ret;								\
 })
 


  reply	other threads:[~2025-05-14  7:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-09 23:28 Shakeel Butt
2025-05-09 23:28 ` [PATCH 1/4] memcg: add infra for nmi safe memcg stats Shakeel Butt
2025-05-09 23:28 ` [PATCH 2/4] memcg: add nmi-safe update for MEMCG_KMEM Shakeel Butt
2025-05-09 23:28 ` [PATCH 3/4] memcg: nmi-safe slab stats updates Shakeel Butt
2025-05-09 23:28 ` [PATCH 4/4] memcg: make objcg charging nmi safe Shakeel Butt
2025-05-13 22:25   ` Alexei Starovoitov
2025-05-14 16:46     ` Shakeel Butt
2025-05-10  1:26 ` [PATCH 0/4] memcg: nmi-safe kmem charging Andrew Morton
2025-05-10  3:11   ` Shakeel Butt
2025-05-10  7:00     ` Harry Yoo
2025-05-12 14:52     ` Vlastimil Babka
2025-05-12 15:56 ` Vlastimil Babka
2025-05-12 19:12   ` Shakeel Butt
2025-05-13  7:15     ` Vlastimil Babka
2025-05-13 11:41       ` Peter Zijlstra
2025-05-13 22:17         ` Shakeel Butt
2025-05-14  7:11           ` Peter Zijlstra [this message]
2025-05-15  1:49           ` Shakeel Butt

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=20250514071144.GB24938@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=ast@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=bpf@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=npiggin@gmail.com \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=tj@kernel.org \
    --cc=vbabka@suse.cz \
    /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