Skip to contentSkip to conversation

soc: xilinx: Fix for call trace due to the usage of smp_processor_id()

PATCH Applied Jay Buddhabhatti 2 participants 2 messages Oct 27, 2023 – Nov 15, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: xilinx: Fix for call trace due to the usage of smp_processor_id()

From: HariBabu Gattem <[email protected]>

When preemption is enabled in kernel and if any task which can be preempted should not use smp_processor_id() directly, since CPU switch can happen at any time, the previous value of cpu_id differs with current cpu_id. As a result we see the below call trace during xlnx_event_manager_probe.

[ 6.140197] dump_backtrace+0x0/0x190
[ 6.143884] show_stack+0x18/0x40
[ 6.147220] dump_stack_lvl+0x7c/0xa0
[ 6.150907] dump_stack+0x18/0x34
[ 6.154241] check_preemption_disabled+0x124/0x134
[ 6.159068] debug_smp_processor_id+0x20/0x2c
[ 6.163453] xlnx_event_manager_probe+0x48/0x250

To protect cpu_id, It is recommended to use get_cpu()/put_cpu() to disable preemption, get the cpu_id and enable preemption respectively. (For Reference, Documentation/locking/preempt-locking.rst and Documentation/kernel-hacking/hacking.rst)

Use preempt_disable()/smp_processor_id()/preempt_enable() API's to achieve the same.

---
 drivers/soc/xilinx/xlnx_event_manager.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/soc/xilinx/xlnx_event_manager.c +4 -1
index 86a048a10a13..edfb1d5c10c6 100644
@@ -555,7 +555,7 @@ static void xlnx_disable_percpu_irq(void *data)
 static int xlnx_event_init_sgi(struct platform_device *pdev)
 {
 	int ret = 0;
-	int cpu = smp_processor_id();
+	int cpu;
 	/*
 	 * IRQ related structures are used for the following:
 	 * for each SGI interrupt ensure its mapped by GIC IRQ domain
@@ -592,9 +592,12 @@ static int xlnx_event_init_sgi(struct platform_device *pdev)
 	sgi_fwspec.param[0] = sgi_num;
 	virq_sgi = irq_create_fwspec_mapping(&sgi_fwspec);
 
+	cpu = get_cpu();
 	per_cpu(cpu_number1, cpu) = cpu;
 	ret = request_percpu_irq(virq_sgi, xlnx_event_handler, "xlnx_event_mgmt",
 				 &cpu_number1);
+	put_cpu();
+
 	WARN_ON(ret);
 	if (ret) {
 		irq_dispose_mapping(virq_sgi);
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 46 lines · Jay Buddhabhatti

From: HariBabu Gattem <[email protected]>

When preemption is enabled in kernel and if any task which can be preempted should not use smp_processor_id() directly, since CPU switch can happen at any time, the previous value of cpu_id differs with current cpu_id. As a result we see the below call trace during xlnx_event_manager_probe.

[ 6.140197] dump_backtrace+0x0/0x190
[ 6.143884] show_stack+0x18/0x40
[ 6.147220] dump_stack_lvl+0x7c/0xa0
[ 6.150907] dump_stack+0x18/0x34
[ 6.154241] check_preemption_disabled+0x124/0x134
[ 6.159068] debug_smp_processor_id+0x20/0x2c
[ 6.163453] xlnx_event_manager_probe+0x48/0x250

To protect cpu_id, It is recommended to use get_cpu()/put_cpu() to disable preemption, get the cpu_id and enable preemption respectively. (For Reference, Documentation/locking/preempt-locking.rst and Documentation/kernel-hacking/hacking.rst)

Use preempt_disable()/smp_processor_id()/preempt_enable() API's to achieve the same.

---
  drivers/soc/xilinx/xlnx_event_manager.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/soc/xilinx/xlnx_event_manager.c +1 -1
index 86a048a10a13..edfb1d5c10c6 100644
@@ -555,7 +555,7 @@ static void xlnx_disable_percpu_irq(void *data)
  static int xlnx_event_init_sgi(struct platform_device *pdev)
  {
  	int ret = 0;
-	int cpu = smp_processor_id();
+	int cpu;
  	/*
  	 * IRQ related structures are used for the following:
  	 * for each SGI interrupt ensure its mapped by GIC IRQ domain
@@ -592,9 +592,12 @@ static int xlnx_event_init_sgi(struct platform_device *pdev)
  	sgi_fwspec.param[0] = sgi_num;
  	virq_sgi = irq_create_fwspec_mapping(&sgi_fwspec);

drivers/soc/xilinx/xlnx_event_manager.c static int xlnx_event_init_sgi(struct platform_device *pdev) · line 603

Quoted 10 lines
drivers/soc/xilinx/xlnx_event_manager.c +3 -0
 
+	cpu = get_cpu();
  	per_cpu(cpu_number1, cpu) = cpu;
  	ret = request_percpu_irq(virq_sgi, xlnx_event_handler, "xlnx_event_mgmt",
  				 &cpu_number1);
+	put_cpu();
+
  	WARN_ON(ret);
  	if (ret) {
  		irq_dispose_mapping(virq_sgi);

Applied.
M