Skip to contentSkip to conversation

pseries/kexec: skip resetting CPUs added by firmware but not started by the kernel

PATCH In review Shivang Upadhyay 5 participants 11 messages Mar 30 – Apr 27 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pseries/kexec: skip resetting CPUs added by firmware but not started by the kernel

During DLPAR operations, the newly added CPUs start in halted mode. The kernel then takes some time to initialize those CPUs internally and start them using the "start-cpu" RTAS call. However, if a kexec crash occurs in this window (before the new CPU has been initialized), the kexec NMI will try to reset all other CPUs from the crashing CPU. This leads to firmware starting the uninitialized CPUs as well.

This can cause the kdump kernel to hang during bring-up.

Sample Log:

  [175993.028231][ T1502] NIP [00007fffb953f394] 0x7fffb953f394
  [175993.028314][ T1502] LR [00007fffb953f394] 0x7fffb953f394
  [175993.028390][ T1502] --- interrupt: 3000
  [    5.519483][    T1] Processor 0 is stuck.
  [   11.089481][    T1] Processor 1 is stuck.

To fix this, only issue the system-reset hcall to CPUs that have actually been started by the kernel.

Cc Madhavan Srinivasan <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Shrikanth Hegde <[email protected]>
Cc Nysal Jan K.A. <[email protected]>
Cc Vishal Chourasia <[email protected]>
Cc Ritesh Harjani <[email protected]>
Cc Sourabh Jain <[email protected]>

---
Changelog:

V2:
* added set_crash_nmi_ipi to saperate crash's case from other nmi_ipi users

V1:
* https://lore.kernel.org/all/[email protected]/

---
 arch/powerpc/include/asm/smp.h       |  1 +
 arch/powerpc/kernel/smp.c            |  1 +
 arch/powerpc/platforms/pseries/smp.c | 29 +++++++++++++++++++++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/smp.h +1 -0
index e41b9ea42122..cb74201f5674 100644
@@ -47,6 +47,7 @@ struct smp_ops_t {
 	void  (*cause_ipi)(int cpu);
 #endif
 	int   (*cause_nmi_ipi)(int cpu);
+	void  (*set_crash_nmi_ipi)(void);
 	void  (*probe)(void);
 	int   (*kick_cpu)(int nr);
 	int   (*prepare_cpu)(int nr);
arch/powerpc/kernel/smp.c +1 -0
index 3467f86fd78f..3390ee8adf79 100644
@@ -594,6 +594,7 @@ void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
 {
 	int cpu;
 
+	smp_ops->set_crash_nmi_ipi();
 	smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, crash_ipi_callback, 1000000);
 	if (kdump_in_progress() && crash_wake_offline) {
 		for_each_present_cpu(cpu) {
arch/powerpc/platforms/pseries/smp.c +28 -1
index db99725e752b..c6c2baacca9a 100644
@@ -51,6 +51,9 @@
  */
 static cpumask_var_t of_spin_mask;
 
+
+static int crash_nmi_ipi;
+
 /* Query where a cpu is now.  Return codes #defined in plpar_wrappers.h */
 int smp_query_cpu_stopped(unsigned int pcpu)
 {
@@ -171,12 +174,35 @@ static void dbell_or_ic_cause_ipi(int cpu)
 	ic_cause_ipi(cpu);
 }
 
+static void pseries_set_crash_nmi_ipi(void)
+{
+	crash_nmi_ipi = 1;
+}
+
 static int pseries_cause_nmi_ipi(int cpu)
 {
 	int hwcpu;
+	int k, curcpu;
 
+	curcpu = smp_processor_id();
 	if (cpu == NMI_IPI_ALL_OTHERS) {
-		hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
+		if (crash_nmi_ipi) {
+			for_each_present_cpu(k) {
+				if (k != curcpu) {
+					hwcpu = get_hard_smp_processor_id(k);
+
+					/* it is possible that cpu is present,
+					 * but not started yet.
+					 */
+
+					if (paca_ptrs[hwcpu]->cpu_start == 1) {
+						plpar_signal_sys_reset(hwcpu);
+					}
+				}
+			}
+			return 1;
+		} else
+			hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
 	} else {
 		if (cpu < 0) {
 			WARN_ONCE(true, "incorrect cpu parameter %d", cpu);
@@ -243,6 +269,7 @@ static struct smp_ops_t pseries_smp_ops = {
 	.message_pass	= NULL,	/* Use smp_muxed_ipi_message_pass */
 	.cause_ipi	= NULL,	/* Filled at runtime by pSeries_smp_probe() */
 	.cause_nmi_ipi	= pseries_cause_nmi_ipi,
+	.set_crash_nmi_ipi = pseries_set_crash_nmi_ipi,
 	.probe		= pSeries_smp_probe,
 	.prepare_cpu	= pseries_smp_prepare_cpu,
 	.kick_cpu	= smp_pSeries_kick_cpu,
Signature · 1 line
2.53.0
#1 lore raw

Hi Shivang.

Few nitpicks.

Quoted 87 lines · Shivang Upadhyay

During DLPAR operations, the newly added CPUs start in halted mode. The kernel then takes some time to initialize those CPUs internally and start them using the "start-cpu" RTAS call. However, if a kexec crash occurs in this window (before the new CPU has been initialized), the kexec NMI will try to reset all other CPUs from the crashing CPU. This leads to firmware starting the uninitialized CPUs as well.

This can cause the kdump kernel to hang during bring-up.

Sample Log:

   [175993.028231][ T1502] NIP [00007fffb953f394] 0x7fffb953f394
   [175993.028314][ T1502] LR [00007fffb953f394] 0x7fffb953f394
   [175993.028390][ T1502] --- interrupt: 3000
   [    5.519483][    T1] Processor 0 is stuck.
   [   11.089481][    T1] Processor 1 is stuck.

To fix this, only issue the system-reset hcall to CPUs that have actually been started by the kernel.

Cc Madhavan Srinivasan <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Shrikanth Hegde <[email protected]>
Cc Nysal Jan K.A. <[email protected]>
Cc Vishal Chourasia <[email protected]>
Cc Ritesh Harjani <[email protected]>
Cc Sourabh Jain <[email protected]>

---
Changelog:

V2:
* added set_crash_nmi_ipi to saperate crash's case from other nmi_ipi users

V1:
* https://lore.kernel.org/all/[email protected]/

---
  arch/powerpc/include/asm/smp.h       |  1 +
  arch/powerpc/kernel/smp.c            |  1 +
  arch/powerpc/platforms/pseries/smp.c | 29 +++++++++++++++++++++++++++-
  3 files changed, 30 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/smp.h +1 -0
index e41b9ea42122..cb74201f5674 100644
@@ -47,6 +47,7 @@ struct smp_ops_t {
  	void  (*cause_ipi)(int cpu);
  #endif
  	int   (*cause_nmi_ipi)(int cpu);
+	void  (*set_crash_nmi_ipi)(void);
  	void  (*probe)(void);
  	int   (*kick_cpu)(int nr);
  	int   (*prepare_cpu)(int nr);
arch/powerpc/kernel/smp.c +1 -0
index 3467f86fd78f..3390ee8adf79 100644
@@ -594,6 +594,7 @@ void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
  {
  	int cpu;
 
+	smp_ops->set_crash_nmi_ipi();
  	smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, crash_ipi_callback, 1000000);
  	if (kdump_in_progress() && crash_wake_offline) {
  		for_each_present_cpu(cpu) {
arch/powerpc/platforms/pseries/smp.c +3 -0
index db99725e752b..c6c2baacca9a 100644
@@ -51,6 +51,9 @@
   */
  static cpumask_var_t of_spin_mask;
 
+
+static int crash_nmi_ipi;
+
  /* Query where a cpu is now.  Return codes #defined in plpar_wrappers.h */
  int smp_query_cpu_stopped(unsigned int pcpu)
  {
@@ -171,12 +174,35 @@ static void dbell_or_ic_cause_ipi(int cpu)
  	ic_cause_ipi(cpu);
  }

arch/powerpc/platforms/pseries/smp.c static void dbell_or_ic_cause_ipi(int cpu) · line 185

Quoted 10 lines
arch/powerpc/platforms/pseries/smp.c +6 -0
 
+static void pseries_set_crash_nmi_ipi(void)
+{
+	crash_nmi_ipi = 1;
+}
+
  static int pseries_cause_nmi_ipi(int cpu)
  {
  	int hwcpu;
+	int k, curcpu;

Please follow inverted christmas tree for variables.

Can the below block be re-written with less indentations? One level indentation removal could be.

if (cpu == NMI_IPI_ALL_OTHERS && crash_nmi_ipi)

	hwcpu = <>
else if (cpu == NMI_IPI_ALL_OTHERS)
	hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;

else
<existing remaining logic>

arch/powerpc/platforms/pseries/smp.c static void dbell_or_ic_cause_ipi(int cpu) · line 191

Quoted 7 lines
arch/powerpc/platforms/pseries/smp.c +4 -1
+	curcpu = smp_processor_id();
  	if (cpu == NMI_IPI_ALL_OTHERS) {
-		hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
+		if (crash_nmi_ipi) {
+			for_each_present_cpu(k) {
+				if (k != curcpu) {

Maybe below to reduce one more indentation level.

if ( k == curcpu)

	continue;

arch/powerpc/platforms/pseries/smp.c static void dbell_or_ic_cause_ipi(int cpu) · line 198

Quoted 7 lines
arch/powerpc/platforms/pseries/smp.c +7 -0
+					hwcpu = get_hard_smp_processor_id(k);
+
+					/* it is possible that cpu is present,
+					 * but not started yet.
+					 */
+
+					if (paca_ptrs[hwcpu]->cpu_start == 1) {

It either 1 or 0. So if(paca_ptrs[hwcpu]->cpu_start) is enough.

Quoted 18 lines
arch/powerpc/platforms/pseries/smp.c +8 -0
+						plpar_signal_sys_reset(hwcpu);
+					}
+				}
+			}
+			return 1;
+		} else
+			hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
  	} else {
  		if (cpu < 0) {
  			WARN_ONCE(true, "incorrect cpu parameter %d", cpu);
@@ -243,6 +269,7 @@ static struct smp_ops_t pseries_smp_ops = {
  	.message_pass	= NULL,	/* Use smp_muxed_ipi_message_pass */
  	.cause_ipi	= NULL,	/* Filled at runtime by pSeries_smp_probe() */
  	.cause_nmi_ipi	= pseries_cause_nmi_ipi,
+	.set_crash_nmi_ipi = pseries_set_crash_nmi_ipi,
  	.probe		= pSeries_smp_probe,
  	.prepare_cpu	= pseries_smp_prepare_cpu,
  	.kick_cpu	= smp_pSeries_kick_cpu,
#2 lore raw

Hi Shrikanth, Thanks for your review.

Quoted 107 lines · Shrikanth Hegde

Hi Shivang.

Few nitpicks.

Quoted 102 lines · Shivang Upadhyay

During DLPAR operations, the newly added CPUs start in halted mode. The kernel then takes some time to initialize those CPUs internally and
start them using the "start-cpu" RTAS call. However, if a kexec crash
occurs in this window (before the new CPU has been initialized), the kexec NMI will try to reset all other CPUs from the crashing CPU.
This leads to firmware starting the uninitialized CPUs as well.

This can cause the kdump kernel to hang during bring-up.

Sample Log:

   [175993.028231][ T1502] NIP [00007fffb953f394] 0x7fffb953f394
   [175993.028314][ T1502] LR [00007fffb953f394] 0x7fffb953f394
   [175993.028390][ T1502] --- interrupt: 3000

   [    5.519483][    T1] Processor 0 is stuck.
   [   11.089481][    T1] Processor 1 is stuck.

To fix this, only issue the system-reset hcall to CPUs that have actually been started by the kernel.

Cc Madhavan Srinivasan <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Shrikanth Hegde <[email protected]>
Cc Nysal Jan K.A. <[email protected]>
Cc Vishal Chourasia <[email protected]>
Cc Ritesh Harjani <[email protected]>
Cc Sourabh Jain <[email protected]>

---
Changelog:

V2:
   * added set_crash_nmi_ipi to saperate crash's case from other nmi_ipi
     users

V1:
   *
https://lore.kernel.org/all/[email protected]/
---
  arch/powerpc/include/asm/smp.h       |  1 +
  arch/powerpc/kernel/smp.c            |  1 +
  arch/powerpc/platforms/pseries/smp.c | 29
+++++++++++++++++++++++++++-

  3 files changed, 30 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/smp.h +1 -0
index e41b9ea42122..cb74201f5674 100644
@@ -47,6 +47,7 @@ struct smp_ops_t {
   	void  (*cause_ipi)(int cpu);
   #endif
   	int   (*cause_nmi_ipi)(int cpu);
+	void  (*set_crash_nmi_ipi)(void);
   	void  (*probe)(void);
   	int   (*kick_cpu)(int nr);
   	int   (*prepare_cpu)(int nr);
arch/powerpc/kernel/smp.c +0 -0
index 3467f86fd78f..3390ee8adf79 100644
@@ -594,6 +594,7 @@ void crash_send_ipi(void
 (*crash_ipi_callback)(struct pt_regs *))
   {
   	int cpu;

arch/powerpc/kernel/smp.c +1 -0
+	smp_ops->set_crash_nmi_ipi();

   smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, crash_ipi_callback, 1000000);
   if (kdump_in_progress() && crash_wake_offline) { for_each_present_cpu(cpu) {

arch/powerpc/platforms/pseries/smp.c +0 -0
index db99725e752b..c6c2baacca9a 100644
@@ -51,6 +51,9 @@
    */
   static cpumask_var_t of_spin_mask;

arch/powerpc/platforms/pseries/smp.c +3 -0
+
+static int crash_nmi_ipi;
+

  /* Query where a cpu is now.  Return codes #defined in plpar_wrappers.h */
  int smp_query_cpu_stopped(unsigned int pcpu) {

arch/powerpc/platforms/pseries/smp.c +0 -0
@@ -171,12 +174,35 @@ static void dbell_or_ic_cause_ipi(int cpu)
   	ic_cause_ipi(cpu);
   }

arch/powerpc/platforms/pseries/smp.c +3 -0
+static void pseries_set_crash_nmi_ipi(void)
+{
+	crash_nmi_ipi = 1;
Quoted 8 lines

arch/powerpc/platforms/pseries/smp.c static void dbell_or_ic_cause_ipi(int cpu) · line 185

Quoted 6 lines
arch/powerpc/platforms/pseries/smp.c +2 -0
+}
+

  static int pseries_cause_nmi_ipi(int cpu)
  {
   int hwcpu;

arch/powerpc/platforms/pseries/smp.c +1 -0
+	int k, curcpu;

Please follow inverted christmas tree for variables.

Ack.

Quoted 22 lines

Can the below block be re-written with less indentations? One level indentation removal could be.

if (cpu == NMI_IPI_ALL_OTHERS && crash_nmi_ipi)

	hwcpu = <>
else if (cpu == NMI_IPI_ALL_OTHERS)
	hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;

else
<existing remaining logic>

arch/powerpc/platforms/pseries/smp.c static void dbell_or_ic_cause_ipi(int cpu) · line 191

Quoted 7 lines

arch/powerpc/platforms/pseries/smp.c +1 -0
+	curcpu = smp_processor_id();

   if (cpu == NMI_IPI_ALL_OTHERS) {

arch/powerpc/platforms/pseries/smp.c +3 -1
-		hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
+		if (crash_nmi_ipi) {
+			for_each_present_cpu(k) {
+				if (k != curcpu) {

Maybe below to reduce one more indentation level.

Quoted 3 lines

if ( k == curcpu)

	continue;

Sure, i can rewrite it that way.

Quoted 10 lines
Quoted 10 lines
arch/powerpc/platforms/pseries/smp.c +1 -0
+					hwcpu =

get_hard_smp_processor_id(k);

arch/powerpc/platforms/pseries/smp.c +2 -0
+
+					/* it is possible that cpu

is present,

arch/powerpc/platforms/pseries/smp.c +4 -0
+					 * but not started yet.
+					 */
+
+					if (paca_ptrs[hwcpu]-
Quoted 3 lines
Quoted 1 line
Quoted 1 line

cpu_start == 1) {

It either 1 or 0. So if(paca_ptrs[hwcpu]->cpu_start) is enough.

Ack.

~Shivang.

#3 lore raw
In reply to Shivang Upadhyay
Quoted 6 lines · Shivang Upadhyay

During DLPAR operations, the newly added CPUs start in halted mode. The kernel then takes some time to initialize those CPUs internally and start them using the "start-cpu" RTAS call. However, if a kexec crash occurs in this window (before the new CPU has been initialized), the kexec NMI will try to reset all other CPUs from the crashing CPU. This leads to firmware starting the uninitialized CPUs as well.

What would happen if an non kexec crash nmi was delivered when we did a DLPAR operation and before the CPUs are initialized?

Quoted 57 lines

This can cause the kdump kernel to hang during bring-up.

Sample Log:

  [175993.028231][ T1502] NIP [00007fffb953f394] 0x7fffb953f394
  [175993.028314][ T1502] LR [00007fffb953f394] 0x7fffb953f394
  [175993.028390][ T1502] --- interrupt: 3000
  [    5.519483][    T1] Processor 0 is stuck.
  [   11.089481][    T1] Processor 1 is stuck.

To fix this, only issue the system-reset hcall to CPUs that have actually been started by the kernel.

Cc Madhavan Srinivasan <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Shrikanth Hegde <[email protected]>
Cc Nysal Jan K.A. <[email protected]>
Cc Vishal Chourasia <[email protected]>
Cc Ritesh Harjani <[email protected]>
Cc Sourabh Jain <[email protected]>

---
Changelog:

V2:
* added set_crash_nmi_ipi to saperate crash's case from other nmi_ipi users

V1:
* https://lore.kernel.org/all/[email protected]/

---
 arch/powerpc/include/asm/smp.h       |  1 +
 arch/powerpc/kernel/smp.c            |  1 +
 arch/powerpc/platforms/pseries/smp.c | 29 +++++++++++++++++++++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/smp.h +1 -0
index e41b9ea42122..cb74201f5674 100644
@@ -47,6 +47,7 @@ struct smp_ops_t {
 	void  (*cause_ipi)(int cpu);
 #endif
 	int   (*cause_nmi_ipi)(int cpu);
+	void  (*set_crash_nmi_ipi)(void);
 	void  (*probe)(void);
 	int   (*kick_cpu)(int nr);
 	int   (*prepare_cpu)(int nr);
arch/powerpc/kernel/smp.c +0 -0
index 3467f86fd78f..3390ee8adf79 100644

arch/powerpc/kernel/smp.c void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *)) · line 597

Quoted 4 lines
arch/powerpc/kernel/smp.c +1 -0
@@ -594,6 +594,7 @@ void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
 {
 	int cpu;
 
+	smp_ops->set_crash_nmi_ipi();

Shouldn't we be checking got smp_ops->set_crash_nmi_ipi being non-NULL before calling. Dont we expect set_crash_nmi_ipi() to be NULL in PowerNV after this patch? Or what would happen if set_crash_nmi_ipi() was called in PowerNV code?

arch/powerpc/platforms/pseries/smp.c line 54

Quoted 12 lines
arch/powerpc/kernel/smp.c +0 -0
 	smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, crash_ipi_callback, 1000000);
 	if (kdump_in_progress() && crash_wake_offline) {
 		for_each_present_cpu(cpu) {
arch/powerpc/platforms/pseries/smp.c +1 -0
index db99725e752b..c6c2baacca9a 100644
@@ -51,6 +51,9 @@
  */
 static cpumask_var_t of_spin_mask;
 
+

Nit: Are we adding an unnecessary newline?

Quoted 53 lines
arch/powerpc/platforms/pseries/smp.c +27 -1
+static int crash_nmi_ipi;
+
 /* Query where a cpu is now.  Return codes #defined in plpar_wrappers.h */
 int smp_query_cpu_stopped(unsigned int pcpu)
 {
@@ -171,12 +174,35 @@ static void dbell_or_ic_cause_ipi(int cpu)
 	ic_cause_ipi(cpu);
 }
 
+static void pseries_set_crash_nmi_ipi(void)
+{
+	crash_nmi_ipi = 1;
+}
+
 static int pseries_cause_nmi_ipi(int cpu)
 {
 	int hwcpu;
+	int k, curcpu;
 
+	curcpu = smp_processor_id();
 	if (cpu == NMI_IPI_ALL_OTHERS) {
-		hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
+		if (crash_nmi_ipi) {
+			for_each_present_cpu(k) {
+				if (k != curcpu) {
+					hwcpu = get_hard_smp_processor_id(k);
+
+					/* it is possible that cpu is present,
+					 * but not started yet.
+					 */
+
+					if (paca_ptrs[hwcpu]->cpu_start == 1) {
+						plpar_signal_sys_reset(hwcpu);
+					}
+				}
+			}
+			return 1;
+		} else
+			hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
 	} else {
 		if (cpu < 0) {
 			WARN_ONCE(true, "incorrect cpu parameter %d", cpu);
@@ -243,6 +269,7 @@ static struct smp_ops_t pseries_smp_ops = {
 	.message_pass	= NULL,	/* Use smp_muxed_ipi_message_pass */
 	.cause_ipi	= NULL,	/* Filled at runtime by pSeries_smp_probe() */
 	.cause_nmi_ipi	= pseries_cause_nmi_ipi,
+	.set_crash_nmi_ipi = pseries_set_crash_nmi_ipi,
 	.probe		= pSeries_smp_probe,
 	.prepare_cpu	= pseries_smp_prepare_cpu,
 	.kick_cpu	= smp_pSeries_kick_cpu,
Signature · 1 line
2.53.0
Signature · 2 lines
Thanks and Regards
Srikar Dronamraju
#4 lore raw

Hi Srikar,

Thanks for reviewing.

Quoted 12 lines · Srikar Dronamraju
Quoted 9 lines · Shivang Upadhyay

During DLPAR operations, the newly added CPUs start in halted mode. The kernel then takes some time to initialize those CPUs internally and
start them using the "start-cpu" RTAS call. However, if a kexec crash
occurs in this window (before the new CPU has been initialized), the kexec NMI will try to reset all other CPUs from the crashing CPU.
This leads to firmware starting the uninitialized CPUs as well.

Quoted 3 lines

What would happen if an non kexec crash nmi was delivered when we did a
DLPAR operation and before the CPUs are initialized?

As per my understanding, similar hang like situation should happen there also. But I think this case would be highly unlikely. Crash's case is little special, because this is called for offline cpus also.

Quoted 68 lines
Quoted 66 lines

This can cause the kdump kernel to hang during bring-up.

Sample Log:

  [175993.028231][ T1502] NIP [00007fffb953f394] 0x7fffb953f394
  [175993.028314][ T1502] LR [00007fffb953f394] 0x7fffb953f394
  [175993.028390][ T1502] --- interrupt: 3000

  [    5.519483][    T1] Processor 0 is stuck.
  [   11.089481][    T1] Processor 1 is stuck.

To fix this, only issue the system-reset hcall to CPUs that have actually been started by the kernel.

Cc Madhavan Srinivasan <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Shrikanth Hegde <[email protected]>
Cc Nysal Jan K.A. <[email protected]>
Cc Vishal Chourasia <[email protected]>
Cc Ritesh Harjani <[email protected]>
Cc Sourabh Jain <[email protected]>

---
Changelog:

V2:
  * added set_crash_nmi_ipi to saperate crash's case from other nmi_ipi
    users

V1:
  *
https://lore.kernel.org/all/[email protected]/
---
 arch/powerpc/include/asm/smp.h       |  1 +
 arch/powerpc/kernel/smp.c            |  1 +
 arch/powerpc/platforms/pseries/smp.c | 29
+++++++++++++++++++++++++++-

 3 files changed, 30 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/smp.h +1 -0
index e41b9ea42122..cb74201f5674 100644
@@ -47,6 +47,7 @@ struct smp_ops_t {
  	void  (*cause_ipi)(int cpu);
  #endif
  	int   (*cause_nmi_ipi)(int cpu);
+	void  (*set_crash_nmi_ipi)(void);
  	void  (*probe)(void);
  	int   (*kick_cpu)(int nr);
  	int   (*prepare_cpu)(int nr);
arch/powerpc/kernel/smp.c +0 -0
index 3467f86fd78f..3390ee8adf79 100644
@@ -594,6 +594,7 @@ void crash_send_ipi(void
 (*crash_ipi_callback)(struct pt_regs *))
  {
  	int cpu;

arch/powerpc/kernel/smp.c void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *)) · line 597

Quoted 1 line
arch/powerpc/kernel/smp.c +1 -0
+	smp_ops->set_crash_nmi_ipi();
Quoted 8 lines

Shouldn't we be checking got smp_ops->set_crash_nmi_ipi being non- NULL
before calling. Dont we expect set_crash_nmi_ipi() to be NULL in PowerNV
after this patch? Or what would happen if set_crash_nmi_ipi() was called in
PowerNV code?

Yeah, that should be a Bug, Ill fix this in new patch. Thanks for catching this.

Quoted 8 lines
Quoted 8 lines

  smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, crash_ipi_callback, 1000000);
  if (kdump_in_progress() && crash_wake_offline) { for_each_present_cpu(cpu) {

arch/powerpc/platforms/pseries/smp.c +0 -1
index db99725e752b..c6c2baacca9a 100644
--- a/arch/powerpc/platforms/pseries/smp.c
Quoted 8 lines
Quoted 6 lines

+++ b/arch/powerpc/platforms/pseries/smp.c

arch/powerpc/platforms/pseries/smp.c +0 -0
@@ -51,6 +51,9 @@
   */
  static cpumask_var_t of_spin_mask;


+

Nit: Are we adding an unnecessary newline?

Ack.

Quoted 54 lines
Quoted 54 lines
arch/powerpc/platforms/pseries/smp.c +2 -0
+static int crash_nmi_ipi;
+

 /* Query where a cpu is now.  Return codes #defined in plpar_wrappers.h */
 int smp_query_cpu_stopped(unsigned int pcpu) {

arch/powerpc/platforms/pseries/smp.c +0 -0
@@ -171,12 +174,35 @@ static void dbell_or_ic_cause_ipi(int cpu)
  	ic_cause_ipi(cpu);
  }

arch/powerpc/platforms/pseries/smp.c +5 -0
+static void pseries_set_crash_nmi_ipi(void)
+{
+	crash_nmi_ipi = 1;
+}
+

 static int pseries_cause_nmi_ipi(int cpu)
 {
  int hwcpu;

arch/powerpc/platforms/pseries/smp.c +1 -0
+	int k, curcpu;

arch/powerpc/platforms/pseries/smp.c +1 -0
+	curcpu = smp_processor_id();

  if (cpu == NMI_IPI_ALL_OTHERS) {

arch/powerpc/platforms/pseries/smp.c +4 -1
-		hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
+		if (crash_nmi_ipi) {
+			for_each_present_cpu(k) {
+				if (k != curcpu) {
+					hwcpu =

get_hard_smp_processor_id(k);

arch/powerpc/platforms/pseries/smp.c +2 -0
+
+					/* it is possible that cpu

is present,

arch/powerpc/platforms/pseries/smp.c +4 -0
+					 * but not started yet.
+					 */
+
+					if (paca_ptrs[hwcpu]-
Quoted 1 line

cpu_start == 1) {

arch/powerpc/platforms/pseries/smp.c +1 -0
+						plpar_signal_sys_r

eset(hwcpu);

arch/powerpc/platforms/pseries/smp.c +6 -0
+					}
+				}
+			}
+			return 1;
+		} else
+			hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;

  } else {
  if (cpu < 0) {
  WARN_ONCE(true, "incorrect cpu parameter %d", cpu);

arch/powerpc/platforms/pseries/smp.c +0 -0
@@ -243,6 +269,7 @@ static struct smp_ops_t pseries_smp_ops = {

  .message_pass = NULL, /* Use
smp_muxed_ipi_message_pass */
  .cause_ipi = NULL, /* Filled at runtime by
pSeries_smp_probe() */

Quoted 8 lines
Quoted 8 lines

  .cause_nmi_ipi = pseries_cause_nmi_ipi,

arch/powerpc/platforms/pseries/smp.c +1 -0
+	.set_crash_nmi_ipi = pseries_set_crash_nmi_ipi,

  .probe = pSeries_smp_probe,
  .prepare_cpu = pseries_smp_prepare_cpu,
  .kick_cpu = smp_pSeries_kick_cpu,

Signature · 1 line
2.53.0

Thanks

~Shivang.

#5 lore raw
In reply to Shivang Upadhyay

Hi Shivang,

Thanks for working on this issue.
A few questions and concerns about the approach:

1. Was this issue only observed with QEMU-based virtualization, or does it also reproduce on PowerVM/phyp? The commit message and sample logs don't clarify this. If this is QEMU-specific, I think we should fix this in QEMU rather than working around it in the kernel.
2. The approach taken here moves away from the PAPR interface. The kernel currently uses H_SIGNAL_SYS_RESET_ALL_OTHERS, which is the architecturally defined hcall for this purpose. Replacing it with a per-CPU loop that checks internal kernel state (paca cpu_start) breaks the clean abstraction between guest and hypervisor.

QEMU's sPAPR implementation should behave the same way. The hypervisor (QEMU) should maintain a list of CPUs that have been activated/online/started and given to the guest. When H_SIGNAL_SYS_RESET_ALL_OTHERS is called, QEMU should only reset those CPUs that the guest has actually started. Unless the guest makes the RTAS start-cpu call for a CPU, QEMU should not include that CPU in the set of CPUs to be reset.

I think discussing this would help determine the right fix location.

Can you refer to the following commit in QEMU to see if help in this case.

commit fb802acdc8b162084e9e60d42aeba79097d14d2b
Author: Nicholas Piggin <[email protected]>
Date:   Tue Mar 18 15:03:48 2025 +1000

    ppc/spapr: Fix RTAS stopped state

Thanks and Regards,
Vishal

Quoted 129 lines · Shivang Upadhyay

During DLPAR operations, the newly added CPUs start in halted mode. The kernel then takes some time to initialize those CPUs internally and start them using the "start-cpu" RTAS call. However, if a kexec crash occurs in this window (before the new CPU has been initialized), the kexec NMI will try to reset all other CPUs from the crashing CPU. This leads to firmware starting the uninitialized CPUs as well.

This can cause the kdump kernel to hang during bring-up.

Sample Log:

   [175993.028231][ T1502] NIP [00007fffb953f394] 0x7fffb953f394
   [175993.028314][ T1502] LR [00007fffb953f394] 0x7fffb953f394
   [175993.028390][ T1502] --- interrupt: 3000
   [    5.519483][    T1] Processor 0 is stuck.
   [   11.089481][    T1] Processor 1 is stuck.

To fix this, only issue the system-reset hcall to CPUs that have actually been started by the kernel.

Cc Madhavan Srinivasan <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Shrikanth Hegde <[email protected]>
Cc Nysal Jan K.A. <[email protected]>
Cc Vishal Chourasia <[email protected]>
Cc Ritesh Harjani <[email protected]>
Cc Sourabh Jain <[email protected]>

---
Changelog:

V2:
* added set_crash_nmi_ipi to saperate crash's case from other nmi_ipi users

V1:
* https://lore.kernel.org/all/[email protected]/

---
  arch/powerpc/include/asm/smp.h       |  1 +
  arch/powerpc/kernel/smp.c            |  1 +
  arch/powerpc/platforms/pseries/smp.c | 29 +++++++++++++++++++++++++++-
  3 files changed, 30 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/smp.h +1 -0
index e41b9ea42122..cb74201f5674 100644
@@ -47,6 +47,7 @@ struct smp_ops_t {
  	void  (*cause_ipi)(int cpu);
  #endif
  	int   (*cause_nmi_ipi)(int cpu);
+	void  (*set_crash_nmi_ipi)(void);
  	void  (*probe)(void);
  	int   (*kick_cpu)(int nr);
  	int   (*prepare_cpu)(int nr);
arch/powerpc/kernel/smp.c +1 -0
index 3467f86fd78f..3390ee8adf79 100644
@@ -594,6 +594,7 @@ void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
  {
  	int cpu;
 
+	smp_ops->set_crash_nmi_ipi();
  	smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, crash_ipi_callback, 1000000);
  	if (kdump_in_progress() && crash_wake_offline) {
  		for_each_present_cpu(cpu) {
arch/powerpc/platforms/pseries/smp.c +28 -1
index db99725e752b..c6c2baacca9a 100644
@@ -51,6 +51,9 @@
   */
  static cpumask_var_t of_spin_mask;
 
+
+static int crash_nmi_ipi;
+
  /* Query where a cpu is now.  Return codes #defined in plpar_wrappers.h */
  int smp_query_cpu_stopped(unsigned int pcpu)
  {
@@ -171,12 +174,35 @@ static void dbell_or_ic_cause_ipi(int cpu)
  	ic_cause_ipi(cpu);
  }
 
+static void pseries_set_crash_nmi_ipi(void)
+{
+	crash_nmi_ipi = 1;
+}
+
  static int pseries_cause_nmi_ipi(int cpu)
  {
  	int hwcpu;
+	int k, curcpu;
 
+	curcpu = smp_processor_id();
  	if (cpu == NMI_IPI_ALL_OTHERS) {
-		hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
+		if (crash_nmi_ipi) {
+			for_each_present_cpu(k) {
+				if (k != curcpu) {
+					hwcpu = get_hard_smp_processor_id(k);
+
+					/* it is possible that cpu is present,
+					 * but not started yet.
+					 */
+
+					if (paca_ptrs[hwcpu]->cpu_start == 1) {
+						plpar_signal_sys_reset(hwcpu);
+					}
+				}
+			}
+			return 1;
+		} else
+			hwcpu = H_SIGNAL_SYS_RESET_ALL_OTHERS;
  	} else {
  		if (cpu < 0) {
  			WARN_ONCE(true, "incorrect cpu parameter %d", cpu);
@@ -243,6 +269,7 @@ static struct smp_ops_t pseries_smp_ops = {
  	.message_pass	= NULL,	/* Use smp_muxed_ipi_message_pass */
  	.cause_ipi	= NULL,	/* Filled at runtime by pSeries_smp_probe() */
  	.cause_nmi_ipi	= pseries_cause_nmi_ipi,
+	.set_crash_nmi_ipi = pseries_set_crash_nmi_ipi,
  	.probe		= pSeries_smp_probe,
  	.prepare_cpu	= pseries_smp_prepare_cpu,
  	.kick_cpu	= smp_pSeries_kick_cpu,
#6 lore raw

Hi,
Thanks for your review.

Quoted 11 lines · Vishal Chourasia

Hi Shivang,

Thanks for working on this issue.
A few questions and concerns about the approach:

1. Was this issue only observed with QEMU-based virtualization, or does
it also reproduce on PowerVM/phyp? The commit message and sample logs don't clarify this. If this is QEMU-specific, I think we should fix this
in QEMU rather than working around it in the kernel.

Currently this is only happening in Qemu (both tcg and kvm mode). But I think this should be reproducible on phyp also. Ill confirm wheather it is really the case or not.

Quoted 8 lines

2. The approach taken here moves away from the PAPR interface. The kernel currently uses H_SIGNAL_SYS_RESET_ALL_OTHERS, which is the architecturally defined hcall for this purpose. Replacing it with a per-CPU loop that checks internal kernel state (paca cpu_start) breaks
the clean abstraction between guest and
QEMU's sPAPR implementation should behave the same way. The hypervisor

Yeah it is a valid concern about ownership for this resets. Ill try to see if this fix is possible in qemu itself.

Quoted 10 lines

(QEMU) should maintain a list of CPUs that have been activated/online/started and given to the guest. When H_SIGNAL_SYS_RESET_ALL_OTHERS is called, QEMU should only reset those CPUs that the guest has actually started. Unless the guest makes the RTAS start-cpu call for a CPU, QEMU should not include that CPU in the
set of CPUs to be reset.

I think discussing this would help determine the right fix location.

Quoted 9 lines

Can you refer to the following commit in QEMU to see if help in this case.

commit fb802acdc8b162084e9e60d42aeba79097d14d2b
Author: Nicholas Piggin <[email protected]>
Date:   Tue Mar 18 15:03:48 2025 +1000

     ppc/spapr: Fix RTAS stopped state

Thanks for this reference. cpu->quiesced state was introduced in this patch, for modelling "RTAS stopped" state.

as per the commit message:
A KVM spapr guest boots with all secondary CPUs defined to be in the RTAS stopped" state. In this state, the CPU is only responsive to the start-cpu RTAS call.

So, we should be able to use this to check wheather cpu is started or not. Only other concern here would be about phyp's implementation for this.

Thanks.
~Shivang.

#7 lore raw
Quoted 52 lines · Shivang Upadhyay

Hi,
Thanks for your review.

Quoted 11 lines · Vishal Chourasia

Hi Shivang,

Thanks for working on this issue.
A few questions and concerns about the approach:

1. Was this issue only observed with QEMU-based virtualization, or does
it also reproduce on PowerVM/phyp? The commit message and sample logs don't clarify this. If this is QEMU-specific, I think we should fix this
in QEMU rather than working around it in the kernel.

Currently this is only happening in Qemu (both tcg and kvm mode). But I think this should be reproducible on phyp also. Ill confirm wheather it is really the case or not.

Quoted 8 lines

2. The approach taken here moves away from the PAPR interface. The kernel currently uses H_SIGNAL_SYS_RESET_ALL_OTHERS, which is the architecturally defined hcall for this purpose. Replacing it with a per-CPU loop that checks internal kernel state (paca cpu_start) breaks
the clean abstraction between guest and
QEMU's sPAPR implementation should behave the same way. The hypervisor

Yeah it is a valid concern about ownership for this resets. Ill try to see if this fix is possible in qemu itself.

Quoted 10 lines

(QEMU) should maintain a list of CPUs that have been activated/online/started and given to the guest. When H_SIGNAL_SYS_RESET_ALL_OTHERS is called, QEMU should only reset those CPUs that the guest has actually started. Unless the guest makes the RTAS start-cpu call for a CPU, QEMU should not include that CPU in the
set of CPUs to be reset.

I think discussing this would help determine the right fix location.

Quoted 9 lines

Can you refer to the following commit in QEMU to see if help in this case.

commit fb802acdc8b162084e9e60d42aeba79097d14d2b
Author: Nicholas Piggin <[email protected]>
Date:   Tue Mar 18 15:03:48 2025 +1000

     ppc/spapr: Fix RTAS stopped state

Thanks for this reference. cpu->quiesced state was introduced in this patch, for modelling "RTAS stopped" state.

Quoted 8 lines

as per the commit message:
A KVM spapr guest boots with all secondary CPUs defined to be in the RTAS stopped" state. In this state, the CPU is only responsive to the start-cpu RTAS call.

So, we should be able to use this to check wheather cpu is started or not. Only other concern here would be about phyp's implementation for this.

Yes, something like this.

hw/ppc/spapr_hcall.c +0 -0

index 032805a8d0..8c51372cf8 100644

hw/ppc/spapr_hcall.c +0 -0
@@ -1105,6 +1105,9 @@ static target_ulong h_signal_sys_reset(PowerPCCPU *cpu,

                     continue;
                 }
             }
+
+            if (c->env.quiesced) continue;
+
             run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL); }
         return H_SUCCESS;

Quoted 6 lines

Thanks.
~Shivang.

#8 lore raw
Quoted 96 lines · Vishal Chourasia
Quoted 73 lines · Shivang Upadhyay

Hi,
Thanks for your review.

Quoted 5 lines · Vishal Chourasia

Hi Shivang,

Thanks for working on this issue.
A few questions and concerns about the approach:

Quoted 9 lines

1. Was this issue only observed with QEMU-based virtualization, or
does
it also reproduce on PowerVM/phyp? The commit message and sample logs
don't clarify this. If this is QEMU-specific, I think we should fix
this
in QEMU rather than working around it in the kernel.

Currently this is only happening in Qemu (both tcg and kvm mode). But I
think this should be reproducible on phyp also. Ill confirm wheather it
is really the case or not.

Quoted 10 lines

2. The approach taken here moves away from the PAPR interface. The
kernel currently uses H_SIGNAL_SYS_RESET_ALL_OTHERS, which is the architecturally defined hcall for this purpose. Replacing it with a
per-CPU loop that checks internal kernel state (paca cpu_start) breaks
the clean abstraction between guest and
QEMU's sPAPR implementation should behave the same way. The hypervisor

Yeah it is a valid concern about ownership for this resets. Ill try to
see if this fix is possible in qemu itself.

Quoted 18 lines

(QEMU) should maintain a list of CPUs that have been activated/online/started and given to the guest. When H_SIGNAL_SYS_RESET_ALL_OTHERS is called, QEMU should only reset those
CPUs that the guest has actually started. Unless the guest makes the
RTAS start-cpu call for a CPU, QEMU should not include that CPU in
the
set of CPUs to be reset.

I think discussing this would help determine the right fix location.

Can you refer to the following commit in QEMU to see if help in this
case.

Quoted 6 lines

commit fb802acdc8b162084e9e60d42aeba79097d14d2b
Author: Nicholas Piggin <[email protected]>
Date:   Tue Mar 18 15:03:48 2025 +1000

      ppc/spapr: Fix RTAS stopped state

Thanks for this reference. cpu->quiesced state was introduced in this
patch, for modelling "RTAS stopped" state.

as per the commit message:
A KVM spapr guest boots with all secondary CPUs defined to be in the
RTAS stopped" state. In this state, the CPU is only responsive to the
start-cpu RTAS call.

Quoted 5 lines

So, we should be able to use this to check wheather cpu is started or
not. Only other concern here would be about phyp's implementation for
this.

Yes, something like this.

hw/ppc/spapr_hcall.c +0 -0

index 032805a8d0..8c51372cf8 100644

hw/ppc/spapr_hcall.c +0 -0
@@ -1105,6 +1105,9 @@ static target_ulong

h_signal_sys_reset(PowerPCCPU
*cpu,
                      continue;
                  }
              }

hw/ppc/spapr_hcall.c +3 -0
+
+            if (c->env.quiesced) continue;
+
Quoted 5 lines

              run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL);
          }
          return H_SUCCESS;

Hi Vishal,

The changes mentioned above are also able to solve this bug in my
local testing. Which means "env.quiesced" state is enough to track the kernel's cpu bringup state.

So if phyp is able to independently handle this case then we will not require this as kernel modification. I am Yet to do that test.

Thanks.
~Shivang

Quoted 1 line
#9 lore raw
In reply to Vishal Chourasia
Quoted 92 lines · Vishal Chourasia
Quoted 52 lines · Shivang Upadhyay

Hi,
Thanks for your review.

Quoted 11 lines · Vishal Chourasia

Hi Shivang,

Thanks for working on this issue.
A few questions and concerns about the approach:

1. Was this issue only observed with QEMU-based virtualization, or does
it also reproduce on PowerVM/phyp? The commit message and sample logs don't clarify this. If this is QEMU-specific, I think we should fix this
in QEMU rather than working around it in the kernel.

Currently this is only happening in Qemu (both tcg and kvm mode). But I think this should be reproducible on phyp also. Ill confirm wheather it is really the case or not.

Quoted 8 lines

2. The approach taken here moves away from the PAPR interface. The kernel currently uses H_SIGNAL_SYS_RESET_ALL_OTHERS, which is the architecturally defined hcall for this purpose. Replacing it with a per-CPU loop that checks internal kernel state (paca cpu_start) breaks
the clean abstraction between guest and
QEMU's sPAPR implementation should behave the same way. The hypervisor

Yeah it is a valid concern about ownership for this resets. Ill try to see if this fix is possible in qemu itself.

Quoted 10 lines

(QEMU) should maintain a list of CPUs that have been activated/online/started and given to the guest. When H_SIGNAL_SYS_RESET_ALL_OTHERS is called, QEMU should only reset those CPUs that the guest has actually started. Unless the guest makes the RTAS start-cpu call for a CPU, QEMU should not include that CPU in the
set of CPUs to be reset.

I think discussing this would help determine the right fix location.

Quoted 9 lines

Can you refer to the following commit in QEMU to see if help in this case.

commit fb802acdc8b162084e9e60d42aeba79097d14d2b
Author: Nicholas Piggin <[email protected]>
Date:   Tue Mar 18 15:03:48 2025 +1000

      ppc/spapr: Fix RTAS stopped state

Thanks for this reference. cpu->quiesced state was introduced in this patch, for modelling "RTAS stopped" state.

Quoted 8 lines

as per the commit message:
A KVM spapr guest boots with all secondary CPUs defined to be in the RTAS stopped" state. In this state, the CPU is only responsive to the start-cpu RTAS call.

So, we should be able to use this to check wheather cpu is started or not. Only other concern here would be about phyp's implementation for this.

Yes, something like this.

hw/ppc/spapr_hcall.c +0 -0

index 032805a8d0..8c51372cf8 100644

hw/ppc/spapr_hcall.c +3 -0
@@ -1105,6 +1105,9 @@ static target_ulong 
 h_signal_sys_reset(PowerPCCPU *cpu,
                      continue;
                  }
              }
+
+            if (c->env.quiesced) continue;
+
              run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL);
          }

         return H_SUCCESS;

Quoted 11 lines

Thanks.
~Shivang.

Hi Vishal/Shivang,

I have tested this qemu patch mentioned here, after applying this the issue is getting fixed.

Thank you!
Anushree Mathur

#10 lore raw
In reply to Vishal Chourasia
Quoted 79 lines · Vishal Chourasia
Quoted 52 lines · Shivang Upadhyay

Hi,
Thanks for your review.

Quoted 11 lines · Vishal Chourasia

Hi Shivang,

Thanks for working on this issue.
A few questions and concerns about the approach:

1. Was this issue only observed with QEMU-based virtualization, or does
it also reproduce on PowerVM/phyp? The commit message and sample logs don't clarify this. If this is QEMU-specific, I think we should fix this
in QEMU rather than working around it in the kernel.

Currently this is only happening in Qemu (both tcg and kvm mode). But I think this should be reproducible on phyp also. Ill confirm wheather it is really the case or not.

Quoted 8 lines

2. The approach taken here moves away from the PAPR interface. The kernel currently uses H_SIGNAL_SYS_RESET_ALL_OTHERS, which is the architecturally defined hcall for this purpose. Replacing it with a per-CPU loop that checks internal kernel state (paca cpu_start) breaks
the clean abstraction between guest and
QEMU's sPAPR implementation should behave the same way. The hypervisor

Yeah it is a valid concern about ownership for this resets. Ill try to see if this fix is possible in qemu itself.

Quoted 10 lines

(QEMU) should maintain a list of CPUs that have been activated/online/started and given to the guest. When H_SIGNAL_SYS_RESET_ALL_OTHERS is called, QEMU should only reset those CPUs that the guest has actually started. Unless the guest makes the RTAS start-cpu call for a CPU, QEMU should not include that CPU in the
set of CPUs to be reset.

I think discussing this would help determine the right fix location.

Quoted 9 lines

Can you refer to the following commit in QEMU to see if help in this case.

commit fb802acdc8b162084e9e60d42aeba79097d14d2b
Author: Nicholas Piggin <[email protected]>
Date:   Tue Mar 18 15:03:48 2025 +1000

      ppc/spapr: Fix RTAS stopped state

Thanks for this reference. cpu->quiesced state was introduced in this patch, for modelling "RTAS stopped" state.

Quoted 8 lines

as per the commit message:
A KVM spapr guest boots with all secondary CPUs defined to be in the RTAS stopped" state. In this state, the CPU is only responsive to the start-cpu RTAS call.

So, we should be able to use this to check wheather cpu is started or not. Only other concern here would be about phyp's implementation for this.

Yes, something like this.

hw/ppc/spapr_hcall.c +0 -0

index 032805a8d0..8c51372cf8 100644

hw/ppc/spapr_hcall.c +3 -0
@@ -1105,6 +1105,9 @@ static target_ulong 
 h_signal_sys_reset(PowerPCCPU *cpu,
                      continue;
                  }
              }
+
+            if (c->env.quiesced) continue;
+
              run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL);
          }
Quoted 8 lines

         return H_SUCCESS;

Quoted 6 lines

Thanks.
~Shivang.

Hi Vishal/Shivang,

I have tested this qemu patch mentioned here, after applying this the issue is getting fixed. Will update all the logs once the new patch is sent out to qemu mailing list!

Thank you!
Anushree Mathur