Skip to contentSkip to conversation

powerpc/pseries: Move VPHN constants into vphn.h

PATCH Applied Michael Ellerman 2 participants 6 messages Aug 23, 2023 – Aug 31, 2023

Subsystems (5)
lore
Share & tools
lore

Michael Ellerman

author reviewer
#0 lore raw

PATCH 1/4 powerpc/pseries: Move VPHN constants into vphn.h

These don't have any particularly good reason to belong in lppaca.h, move them into their own header.

---
 arch/powerpc/include/asm/lppaca.h             | 22 -------------------
 arch/powerpc/include/asm/vphn.h               | 22 +++++++++++++++++++
 arch/powerpc/mm/numa.c                        |  1 +
 arch/powerpc/platforms/pseries/lpar.c         |  1 +
 arch/powerpc/platforms/pseries/vas.c          |  1 +
 arch/powerpc/platforms/pseries/vphn.c         |  2 +-
 .../selftests/powerpc/vphn/asm/lppaca.h       |  1 -
 .../testing/selftests/powerpc/vphn/asm/vphn.h |  1 +
 8 files changed, 27 insertions(+), 24 deletions(-)
 create mode 100644 arch/powerpc/include/asm/vphn.h
 delete mode 120000 tools/testing/selftests/powerpc/vphn/asm/lppaca.h
 create mode 120000 tools/testing/selftests/powerpc/vphn/asm/vphn.h
arch/powerpc/include/asm/lppaca.h +0 -22
index 34d44cb17c87..12159e5b6888 100644
@@ -6,28 +6,6 @@
 #ifndef _ASM_POWERPC_LPPACA_H
 #define _ASM_POWERPC_LPPACA_H
 
-/*
- * The below VPHN macros are outside the __KERNEL__ check since these are
- * used for compiling the vphn selftest in userspace
- */
-
-/* The H_HOME_NODE_ASSOCIATIVITY h_call returns 6 64-bit registers. */
-#define VPHN_REGISTER_COUNT 6
-
-/*
- * 6 64-bit registers unpacked into up to 24 be32 associativity values. To
- * form the complete property we have to add the length in the first cell.
- */
-#define VPHN_ASSOC_BUFSIZE (VPHN_REGISTER_COUNT*sizeof(u64)/sizeof(u16) + 1)
-
-/*
- * The H_HOME_NODE_ASSOCIATIVITY hcall takes two values for flags:
- * 1 for retrieving associativity information for a guest cpu
- * 2 for retrieving associativity information for a host/hypervisor cpu
- */
-#define VPHN_FLAG_VCPU	1
-#define VPHN_FLAG_PCPU	2
-
 #ifdef __KERNEL__
 
 /*
arch/powerpc/include/asm/vphn.h new file +22 -0
new file mode 100644
index 000000000000..e0970603fce2
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _ASM_POWERPC_VPHN_H
+#define _ASM_POWERPC_VPHN_H
+
+/* The H_HOME_NODE_ASSOCIATIVITY h_call returns 6 64-bit registers. */
+#define VPHN_REGISTER_COUNT 6
+
+/*
+ * 6 64-bit registers unpacked into up to 24 be32 associativity values. To
+ * form the complete property we have to add the length in the first cell.
+ */
+#define VPHN_ASSOC_BUFSIZE (VPHN_REGISTER_COUNT*sizeof(u64)/sizeof(u16) + 1)
+
+/*
+ * The H_HOME_NODE_ASSOCIATIVITY hcall takes two values for flags:
+ * 1 for retrieving associativity information for a guest cpu
+ * 2 for retrieving associativity information for a host/hypervisor cpu
+ */
+#define VPHN_FLAG_VCPU	1
+#define VPHN_FLAG_PCPU	2
+
+#endif // _ASM_POWERPC_VPHN_H
arch/powerpc/mm/numa.c +1 -0
index 9f73d089eac1..f6c4ace3b221 100644
@@ -34,6 +34,7 @@
 #include <asm/hvcall.h>
 #include <asm/setup.h>
 #include <asm/vdso.h>
+#include <asm/vphn.h>
 #include <asm/drmem.h>
 
 static int numa_enabled = 1;
arch/powerpc/platforms/pseries/lpar.c +1 -0
index 2eab323f6970..27fb656bd6ba 100644
@@ -41,6 +41,7 @@
 #include <asm/kexec.h>
 #include <asm/fadump.h>
 #include <asm/dtl.h>
+#include <asm/vphn.h>
 
 #include "pseries.h"
 
arch/powerpc/platforms/pseries/vas.c +1 -0
index 3fbc2a6aa319..e25ac52acf50 100644
@@ -17,6 +17,7 @@
 #include <asm/hvcall.h>
 #include <asm/plpar_wrappers.h>
 #include <asm/firmware.h>
+#include <asm/vphn.h>
 #include <asm/vas.h>
 #include "vas.h"
 
arch/powerpc/platforms/pseries/vphn.c +1 -1
index cca474a2c396..3f85ece3c872 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <asm/byteorder.h>
-#include <asm/lppaca.h>
+#include <asm/vphn.h>
 
 /*
  * The associativity domain numbers are returned from the hypervisor as a
tools/testing/selftests/powerpc/vphn/asm/lppaca.h deleted +0 -1
deleted file mode 120000
index 942b1d00999c..000000000000
@@ -1 +0,0 @@
-../../../../../../arch/powerpc/include/asm/lppaca.h
\ No newline at end of file
tools/testing/selftests/powerpc/vphn/asm/vphn.h new file +1 -0
new file mode 120000
index 000000000000..3a0b2a00171c
@@ -0,0 +1 @@
+../../../../../../arch/powerpc/include/asm/vphn.h
\ No newline at end of file
Signature · 1 line
2.41.0
author reviewer
#1 lore raw

PATCH 2/4 powerpc/pseries: Move hcall_vphn() prototype into vphn.h

Consolidate the two prototypes for hcall_vphn() into vphn.h.

---
 arch/powerpc/include/asm/dtl.h    | 1 -
 arch/powerpc/include/asm/lppaca.h | 2 --
 arch/powerpc/include/asm/vphn.h   | 2 ++
 3 files changed, 2 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/dtl.h +0 -1
index 4bcb9f9ac764..d6f43d149f8d 100644
@@ -39,6 +39,5 @@ extern rwlock_t dtl_access_lock;
 
 extern void register_dtl_buffer(int cpu);
 extern void alloc_dtl_buffers(unsigned long *time_limit);
-extern long hcall_vphn(unsigned long cpu, u64 flags, __be32 *associativity);
 
 #endif /* _ASM_POWERPC_DTL_H */
arch/powerpc/include/asm/lppaca.h +0 -2
index 12159e5b6888..27f0421188ec 100644
@@ -127,8 +127,6 @@ struct slb_shadow {
 	} save_area[SLB_NUM_BOLTED];
 } ____cacheline_aligned;
 
-extern long hcall_vphn(unsigned long cpu, u64 flags, __be32 *associativity);
-
 #endif /* CONFIG_PPC_BOOK3S */
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_LPPACA_H */
arch/powerpc/include/asm/vphn.h +2 -0
index e0970603fce2..8c2f795eea68 100644
@@ -19,4 +19,6 @@
 #define VPHN_FLAG_VCPU	1
 #define VPHN_FLAG_PCPU	2
 
+long hcall_vphn(unsigned long cpu, u64 flags, __be32 *associativity);
+
 #endif // _ASM_POWERPC_VPHN_H
Signature · 1 line
2.41.0
author reviewer
#2 lore raw

PATCH v2 4/4 powerpc/pseries: Rework lppaca_shared_proc() to avoid DEBUG_PREEMPT

In reply to Michael Ellerman

From: Russell Currey <[email protected]>

lppaca_shared_proc() takes a pointer to the lppaca which is typically accessed through get_lppaca(). With DEBUG_PREEMPT enabled, this leads to checking if preemption is enabled, for example:

  BUG: using smp_processor_id() in preemptible [00000000] code: grep/10693
  caller is lparcfg_data+0x408/0x19a0
  CPU: 4 PID: 10693 Comm: grep Not tainted 6.5.0-rc3 #2
  Call Trace:
    dump_stack_lvl+0x154/0x200 (unreliable)
    check_preemption_disabled+0x214/0x220
    lparcfg_data+0x408/0x19a0
    ...

This isn't actually a problem however, as it does not matter which lppaca is accessed, the shared proc state will be the same. vcpudispatch_stats_procfs_init() already works around this by disabling preemption, but the lparcfg code does not, erroring any time /proc/powerpc/lparcfg is accessed with DEBUG_PREEMPT enabled.

Instead of disabling preemption on the caller side, rework lppaca_shared_proc() to not take a pointer and instead directly access the lppaca, bypassing any potential preemption checks.

Fixes f13c13a00512 ("powerpc: Stop using non-architected shared_proc field in lppaca")
[mpe: Rework to avoid needing a definition in paca.h and lppaca.h]
---
 arch/powerpc/include/asm/lppaca.h        | 11 +++++++++--
 arch/powerpc/platforms/pseries/lpar.c    | 10 +---------
 arch/powerpc/platforms/pseries/lparcfg.c |  4 ++--
 arch/powerpc/platforms/pseries/setup.c   |  2 +-
 drivers/cpuidle/cpuidle-pseries.c        |  8 +-------
 5 files changed, 14 insertions(+), 21 deletions(-)

v2: mpe, rework based on the preceeding header untangling patches.

arch/powerpc/include/asm/lppaca.h +9 -2
index b6a63fa0965f..61ec2447dabf 100644
@@ -23,6 +23,7 @@
 #include <asm/types.h>
 #include <asm/mmu.h>
 #include <asm/firmware.h>
+#include <asm/paca.h>
 
 /*
  * The lppaca is the "virtual processor area" registered with the hypervisor,
@@ -105,14 +106,20 @@ struct lppaca {
  */
 #define LPPACA_OLD_SHARED_PROC		2
 
-static inline bool lppaca_shared_proc(struct lppaca *l)
+#ifdef CONFIG_PPC_PSERIES
+/*
+ * All CPUs should have the same shared proc value, so directly access the PACA
+ * to avoid false positives from DEBUG_PREEMPT.
+ */
+static inline bool lppaca_shared_proc(void)
 {
+	struct lppaca *l = local_paca->lppaca_ptr;
+
 	if (!firmware_has_feature(FW_FEATURE_SPLPAR))
 		return false;
 	return !!(l->__old_status & LPPACA_OLD_SHARED_PROC);
 }
 
-#ifdef CONFIG_PPC_PSERIES
 #define get_lppaca()	(get_paca()->lppaca_ptr)
 #endif
 
arch/powerpc/platforms/pseries/lpar.c +1 -9
index 27fb656bd6ba..f2cb62148f36 100644
@@ -640,16 +640,8 @@ static const struct proc_ops vcpudispatch_stats_freq_proc_ops = {
 
 static int __init vcpudispatch_stats_procfs_init(void)
 {
-	/*
-	 * Avoid smp_processor_id while preemptible. All CPUs should have
-	 * the same value for lppaca_shared_proc.
-	 */
-	preempt_disable();
-	if (!lppaca_shared_proc(get_lppaca())) {
-		preempt_enable();
+	if (!lppaca_shared_proc())
 		return 0;
-	}
-	preempt_enable();
 
 	if (!proc_create("powerpc/vcpudispatch_stats", 0600, NULL,
 					&vcpudispatch_stats_proc_ops))
arch/powerpc/platforms/pseries/lparcfg.c +2 -2
index 8acc70509520..1c151d77e74b 100644
@@ -206,7 +206,7 @@ static void parse_ppp_data(struct seq_file *m)
 	           ppp_data.active_system_procs);
 
 	/* pool related entries are appropriate for shared configs */
-	if (lppaca_shared_proc(get_lppaca())) {
+	if (lppaca_shared_proc()) {
 		unsigned long pool_idle_time, pool_procs;
 
 		seq_printf(m, "pool=%d\n", ppp_data.pool_num);
@@ -560,7 +560,7 @@ static int pseries_lparcfg_data(struct seq_file *m, void *v)
 		   partition_potential_processors);
 
 	seq_printf(m, "shared_processor_mode=%d\n",
-		   lppaca_shared_proc(get_lppaca()));
+		   lppaca_shared_proc());
 
 #ifdef CONFIG_PPC_64S_HASH_MMU
 	if (!radix_enabled())
arch/powerpc/platforms/pseries/setup.c +1 -1
index bb0a9aeb50f9..ecea85c74c43 100644
@@ -849,7 +849,7 @@ static void __init pSeries_setup_arch(void)
 	if (firmware_has_feature(FW_FEATURE_LPAR)) {
 		vpa_init(boot_cpuid);
 
-		if (lppaca_shared_proc(get_lppaca())) {
+		if (lppaca_shared_proc()) {
 			static_branch_enable(&shared_processor);
 			pv_spinlocks_init();
 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
drivers/cpuidle/cpuidle-pseries.c +1 -7
index a7d33f3ee01e..14db9b7d985d 100644
@@ -414,13 +414,7 @@ static int __init pseries_idle_probe(void)
 		return -ENODEV;
 
 	if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
-		/*
-		 * Use local_paca instead of get_lppaca() since
-		 * preemption is not disabled, and it is not required in
-		 * fact, since lppaca_ptr does not need to be the value
-		 * associated to the current CPU, it can be from any CPU.
-		 */
-		if (lppaca_shared_proc(local_paca->lppaca_ptr)) {
+		if (lppaca_shared_proc()) {
 			cpuidle_state_table = shared_states;
 			max_idle_state = ARRAY_SIZE(shared_states);
 		} else {
Signature · 1 line
2.41.0
#3 lore raw

Re: (subset) [PATCH v2 4/4] powerpc/pseries: Rework lppaca_shared_proc() to avoid DEBUG_PREEMPT

Quoted 13 lines · Michael Ellerman

lppaca_shared_proc() takes a pointer to the lppaca which is typically accessed through get_lppaca(). With DEBUG_PREEMPT enabled, this leads to checking if preemption is enabled, for example:

  BUG: using smp_processor_id() in preemptible [00000000] code: grep/10693
  caller is lparcfg_data+0x408/0x19a0
  CPU: 4 PID: 10693 Comm: grep Not tainted 6.5.0-rc3 #2
  Call Trace:
    dump_stack_lvl+0x154/0x200 (unreliable)
    check_preemption_disabled+0x214/0x220
    lparcfg_data+0x408/0x19a0
    ...
Quoted 1 line

[...]

Applied to powerpc/next.

[4/4] powerpc/pseries: Rework lppaca_shared_proc() to avoid DEBUG_PREEMPT

      https://git.kernel.org/powerpc/c/eac030b22ea12cdfcbb2e941c21c03964403c63f

cheers

author reviewer
#4 lore raw

PATCH 3/4 powerpc: Don't include lppaca.h in paca.h

In reply to Michael Ellerman

By adding a forward declaration for struct lppaca we can untangle paca.h and lppaca.h. Also move get_lppaca() into lppaca.h for consistency.

Add includes of lppaca.h to some files that need it.

---
 arch/powerpc/include/asm/lppaca.h         | 4 ++++
 arch/powerpc/include/asm/paca.h           | 6 +-----
 arch/powerpc/include/asm/paravirt.h       | 1 +
 arch/powerpc/include/asm/plpar_wrappers.h | 1 +
 arch/powerpc/kvm/book3s_hv_ras.c          | 1 +
 arch/powerpc/mm/book3s64/slb.c            | 1 +
 arch/powerpc/xmon/xmon.c                  | 1 +
 7 files changed, 10 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/lppaca.h +4 -0
index 27f0421188ec..b6a63fa0965f 100644
@@ -112,6 +112,10 @@ static inline bool lppaca_shared_proc(struct lppaca *l)
 	return !!(l->__old_status & LPPACA_OLD_SHARED_PROC);
 }
 
+#ifdef CONFIG_PPC_PSERIES
+#define get_lppaca()	(get_paca()->lppaca_ptr)
+#endif
+
 /*
  * SLB shadow buffer structure as defined in the PAPR.  The save_area
  * contains adjacent ESID and VSID pairs for each shadowed SLB.  The
arch/powerpc/include/asm/paca.h +1 -5
index cb325938766a..e667d455ecb4 100644
@@ -15,7 +15,6 @@
 #include <linux/cache.h>
 #include <linux/string.h>
 #include <asm/types.h>
-#include <asm/lppaca.h>
 #include <asm/mmu.h>
 #include <asm/page.h>
 #ifdef CONFIG_PPC_BOOK3E_64
@@ -47,14 +46,11 @@ extern unsigned int debug_smp_processor_id(void); /* from linux/smp.h */
 #define get_paca()	local_paca
 #endif
 
-#ifdef CONFIG_PPC_PSERIES
-#define get_lppaca()	(get_paca()->lppaca_ptr)
-#endif
-
 #define get_slb_shadow()	(get_paca()->slb_shadow_ptr)
 
 struct task_struct;
 struct rtas_args;
+struct lppaca;
 
 /*
  * Defines the layout of the paca.
arch/powerpc/include/asm/paravirt.h +1 -0
index f5ba1a3c41f8..e08513d73119 100644
@@ -6,6 +6,7 @@
 #include <asm/smp.h>
 #ifdef CONFIG_PPC64
 #include <asm/paca.h>
+#include <asm/lppaca.h>
 #include <asm/hvcall.h>
 #endif
 
arch/powerpc/include/asm/plpar_wrappers.h +1 -0
index 8239c0af5eb2..fe3d0ea0058a 100644
@@ -9,6 +9,7 @@
 
 #include <asm/hvcall.h>
 #include <asm/paca.h>
+#include <asm/lppaca.h>
 #include <asm/page.h>
 
 static inline long poll_pending(void)
arch/powerpc/kvm/book3s_hv_ras.c +1 -0
index ccfd96965630..82be6d87514b 100644
@@ -9,6 +9,7 @@
 #include <linux/kvm.h>
 #include <linux/kvm_host.h>
 #include <linux/kernel.h>
+#include <asm/lppaca.h>
 #include <asm/opal.h>
 #include <asm/mce.h>
 #include <asm/machdep.h>
arch/powerpc/mm/book3s64/slb.c +1 -0
index 6956f637a38c..f2708c8629a5 100644
@@ -13,6 +13,7 @@
 #include <asm/mmu.h>
 #include <asm/mmu_context.h>
 #include <asm/paca.h>
+#include <asm/lppaca.h>
 #include <asm/ppc-opcode.h>
 #include <asm/cputable.h>
 #include <asm/cacheflush.h>
arch/powerpc/xmon/xmon.c +1 -0
index 78453b9b1ba0..6c6f90f1da94 100644
@@ -58,6 +58,7 @@
 #ifdef CONFIG_PPC64
 #include <asm/hvcall.h>
 #include <asm/paca.h>
+#include <asm/lppaca.h>
 #endif
 
 #include "nonstdio.h"
Signature · 1 line
2.41.0
#5 lore raw
In reply to Michael Ellerman
Quoted 4 lines · Michael Ellerman

These don't have any particularly good reason to belong in lppaca.h, move them into their own header.

Applied to powerpc/next.

[1/4] powerpc/pseries: Move VPHN constants into vphn.h

      https://git.kernel.org/powerpc/c/c040c7488b6a89c98dd0f6dd5f001101413779e2
[2/4] powerpc/pseries: Move hcall_vphn() prototype into vphn.h
      https://git.kernel.org/powerpc/c/9a6c05fe9a998386a61b5e70ce07d31ec47a01a0
[3/4] powerpc: Don't include lppaca.h in paca.h
      https://git.kernel.org/powerpc/c/1aa000667669fa855853decbb1c69e974d8ff716

cheers