Skip to content

Commit 45afabe

Browse files
AboorvaDevarajangregkh
authored andcommitted
powerpc/hv-gpci: fix preempt count leak in sysfs show paths
[ Upstream commit dbc30a5 ] Four sysfs show() callbacks in hv-gpci take get_cpu_var(hv_gpci_reqb) (which calls preempt_disable()) but only call the matching put_cpu_var() on the error path under the 'out:' label. Every successful read leaks one preempt_disable(): processor_bus_topology_show() processor_config_show() affinity_domain_via_virtual_processor_show() affinity_domain_via_domain_show() (affinity_domain_via_partition_show() was already correct.) On a CONFIG_PREEMPT=y kernel, repeated reads raise preempt_count and eventually return to userspace with preemption still disabled. The next user-mode page fault then hits faulthandler_disabled() == 1, gets forced to SIGSEGV, and the resulting coredump trips 'BUG: scheduling while atomic' in call_usermodehelper_exec -> wait_for_completion_state -> schedule: BUG: scheduling while atomic: <task>/<pid>/0x00000004 ... __schedule_bug+0x6c/0x90 __schedule+0x58c/0x13a0 schedule+0x48/0x1a0 schedule_timeout+0x104/0x170 wait_for_completion_state+0x16c/0x330 call_usermodehelper_exec+0x254/0x2d0 vfs_coredump+0x1050/0x2590 get_signal+0xb9c/0xc80 do_notify_resume+0xf8/0x470 Add an out_success label that calls put_cpu_var() before returning the byte count, mirroring affinity_domain_via_partition_show(). Fixes: 71f1c39 ("powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show processor bus topology information") Fixes: 1a160c2 ("powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show processor config information") Fixes: 71a7ccb ("powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via virtual processor information") Fixes: a69a57c ("powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via domain information") Signed-off-by: Aboorva Devarajan <aboorvad@linux.ibm.com> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/20260508041256.3447113-1-aboorvad@linux.ibm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ef05dae commit 45afabe

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

arch/powerpc/perf/hv-gpci.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static ssize_t processor_bus_topology_show(struct device *dev, struct device_att
210210
0, 0, buf, &n, arg);
211211

212212
if (!ret)
213-
return n;
213+
goto out_success;
214214

215215
if (ret != H_PARAMETER)
216216
goto out;
@@ -244,12 +244,14 @@ static ssize_t processor_bus_topology_show(struct device *dev, struct device_att
244244
starting_index, 0, buf, &n, arg);
245245

246246
if (!ret)
247-
return n;
247+
goto out_success;
248248

249249
if (ret != H_PARAMETER)
250250
goto out;
251251
}
252252

253+
out_success:
254+
put_cpu_var(hv_gpci_reqb);
253255
return n;
254256

255257
out:
@@ -278,7 +280,7 @@ static ssize_t processor_config_show(struct device *dev, struct device_attribute
278280
0, 0, buf, &n, arg);
279281

280282
if (!ret)
281-
return n;
283+
goto out_success;
282284

283285
if (ret != H_PARAMETER)
284286
goto out;
@@ -312,12 +314,14 @@ static ssize_t processor_config_show(struct device *dev, struct device_attribute
312314
starting_index, 0, buf, &n, arg);
313315

314316
if (!ret)
315-
return n;
317+
goto out_success;
316318

317319
if (ret != H_PARAMETER)
318320
goto out;
319321
}
320322

323+
out_success:
324+
put_cpu_var(hv_gpci_reqb);
321325
return n;
322326

323327
out:
@@ -346,7 +350,7 @@ static ssize_t affinity_domain_via_virtual_processor_show(struct device *dev,
346350
0, 0, buf, &n, arg);
347351

348352
if (!ret)
349-
return n;
353+
goto out_success;
350354

351355
if (ret != H_PARAMETER)
352356
goto out;
@@ -382,12 +386,14 @@ static ssize_t affinity_domain_via_virtual_processor_show(struct device *dev,
382386
starting_index, secondary_index, buf, &n, arg);
383387

384388
if (!ret)
385-
return n;
389+
goto out_success;
386390

387391
if (ret != H_PARAMETER)
388392
goto out;
389393
}
390394

395+
out_success:
396+
put_cpu_var(hv_gpci_reqb);
391397
return n;
392398

393399
out:
@@ -416,7 +422,7 @@ static ssize_t affinity_domain_via_domain_show(struct device *dev, struct device
416422
0, 0, buf, &n, arg);
417423

418424
if (!ret)
419-
return n;
425+
goto out_success;
420426

421427
if (ret != H_PARAMETER)
422428
goto out;
@@ -448,12 +454,14 @@ static ssize_t affinity_domain_via_domain_show(struct device *dev, struct device
448454
starting_index, 0, buf, &n, arg);
449455

450456
if (!ret)
451-
return n;
457+
goto out_success;
452458

453459
if (ret != H_PARAMETER)
454460
goto out;
455461
}
456462

463+
out_success:
464+
put_cpu_var(hv_gpci_reqb);
457465
return n;
458466

459467
out:

0 commit comments

Comments
 (0)