Re: [PATCH v3] powerpc/imc: Dont create debugfs files for cpu-less nodes

2019-09-19 Thread Michael Ellerman
On Tue, 2019-08-27 at 10:16:35 UTC, Madhavan Srinivasan wrote:
> Commit <684d984038aa> ('powerpc/powernv: Add debugfs interface for imc-mode
> and imc') added debugfs interface for the nest imc pmu devices to support
> changing of different ucode modes. Primarily adding this capability for
> debug. But when doing so, the code did not consider the case of cpu-less
> nodes. So when reading the _cmd_ or _mode_ file of a cpu-less node
> will create this crash.
> 
...
> 
> Fixes: 684d984038aa ('powerpc/powernv: Add debugfs interface for imc-mode and 
> imc')
> Reported-by: Qian Cai 
> Suggested-by: Michael Ellerman 
> Signed-off-by: Madhavan Srinivasan 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/41ba17f20ea835c489e77bd54e2da73184e22060

cheers


[PATCH v3] powerpc/imc: Dont create debugfs files for cpu-less nodes

2019-08-27 Thread Madhavan Srinivasan
Commit <684d984038aa> ('powerpc/powernv: Add debugfs interface for imc-mode
and imc') added debugfs interface for the nest imc pmu devices to support
changing of different ucode modes. Primarily adding this capability for
debug. But when doing so, the code did not consider the case of cpu-less
nodes. So when reading the _cmd_ or _mode_ file of a cpu-less node
will create this crash.

[ 1139.415461][ T5301] Faulting instruction address: 0xc00d0d58
[ 1139.415492][ T5301] Oops: Kernel access of bad area, sig: 11 [#1]
[ 1139.415509][ T5301] LE PAGE_SIZE=64K MMU=Radix MMU=Hash SMP NR_CPUS=256
DEBUG_PAGEALLOC NUMA PowerNV
[ 1139.415542][ T5301] Modules linked in: i2c_opal i2c_core ip_tables x_tables
xfs sd_mod bnx2x mdio ahci libahci tg3 libphy libata firmware_class dm_mirror
dm_region_hash dm_log dm_mod
[ 1139.415595][ T5301] CPU: 67 PID: 5301 Comm: cat Not tainted 5.2.0-rc6-next-
20190627+ #19
[ 1139.415634][ T5301] NIP:  c00d0d58 LR: c049aa18 
CTR:c00d0d50
[ 1139.415675][ T5301] REGS: c00020194548f9e0 TRAP: 0300   Not tainted  
(5.2.0-rc6-next-20190627+)
[ 1139.415705][ T5301] MSR:  90009033   
CR:28022822  XER: 
[ 1139.415777][ T5301] CFAR: c049aa14 DAR: 0003fc08 
DSISR:4000 IRQMASK: 0
[ 1139.415777][ T5301] GPR00: c049aa18 c00020194548fc70 
c16f8b03fc08
[ 1139.415777][ T5301] GPR04: c00020194548fcd0  
14884e7300011eaa
[ 1139.415777][ T5301] GPR08: 7eea5a52 c00d0d50 

[ 1139.415777][ T5301] GPR12: c00d0d50 c000201fff7f8c00 

[ 1139.415777][ T5301] GPR16: 000d 7fffeb0c3368 

[ 1139.415777][ T5301] GPR20:   
0002
[ 1139.415777][ T5301] GPR24:   
000200010ec9
[ 1139.415777][ T5301] GPR28: c00020194548fdf0 c00020049a584ef8 
c00020049a584ea8
[ 1139.416116][ T5301] NIP [c00d0d58] imc_mem_get+0x8/0x20
[ 1139.416143][ T5301] LR [c049aa18] simple_attr_read+0x118/0x170
[ 1139.416158][ T5301] Call Trace:
[ 1139.416182][ T5301] [c00020194548fc70] 
[c049a970]simple_attr_read+0x70/0x170 (unreliable)
[ 1139.416255][ T5301] [c00020194548fd10] 
[c054385c]debugfs_attr_read+0x6c/0xb0
[ 1139.416305][ T5301] [c00020194548fd60] [c0454c1c]__vfs_read+0x3c/0x70
[ 1139.416363][ T5301] [c00020194548fd80] [c0454d0c] vfs_read+0xbc/0x1a0
[ 1139.416392][ T5301] [c00020194548fdd0] [c045519c]ksys_read+0x7c/0x140
[ 1139.416434][ T5301] [c00020194548fe20] 
[c000b108]system_call+0x5c/0x70
[ 1139.416473][ T5301] Instruction dump:
[ 1139.416511][ T5301] 4e800020 6000 7c0802a6 6000 7c801d28 3860 
4e800020 6000
[ 1139.416572][ T5301] 6000 6000 7c0802a6 6000 <7d201c28> 3860 
f924 4e800020
[ 1139.416636][ T5301] ---[ end trace c44d1fb4ace04784 ]---
[ 1139.520686][ T5301]
[ 1140.520820][ T5301] Kernel panic - not syncing: Fatal exception

Patch fixes the issue with a more robust check for vbase to NULL.

Before patch, ls output for the debugfs imc directory

# ls /sys/kernel/debug/powerpc/imc/
imc_cmd_0imc_cmd_251  imc_cmd_253  imc_cmd_255  imc_mode_0imc_mode_251  
imc_mode_253  imc_mode_255
imc_cmd_250  imc_cmd_252  imc_cmd_254  imc_cmd_8imc_mode_250  imc_mode_252  
imc_mode_254  imc_mode_8

After patch, ls output for the debugfs imc directory

# ls /sys/kernel/debug/powerpc/imc/
imc_cmd_0  imc_cmd_8  imc_mode_0  imc_mode_8

Actual bug here is that, we have two loops with potentially
different loop counts. That is, in imc_get_mem_addr_nest(), loop count
is obtained from the dt entries. But incase of export_imc_mode_and_cmd(),
loop was based on for_each_nid() count. Patch fixes the loop count in
latter based on the struct mem_info. Ideally it would be better
to have array size in struct imc_pmu. 

Fixes: 684d984038aa ('powerpc/powernv: Add debugfs interface for imc-mode and 
imc')
Reported-by: Qian Cai 
Suggested-by: Michael Ellerman 
Signed-off-by: Madhavan Srinivasan 
---
Changelog v2:
- No logic changes.
- Just added more commit message.

Changelog v1:
- Modified the cpumask check.
 arch/powerpc/platforms/powernv/opal-imc.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal-imc.c 
b/arch/powerpc/platforms/powernv/opal-imc.c
index 186109bdd41b..e04b20625cb9 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -53,9 +53,9 @@ static void export_imc_mode_and_cmd(struct device_node *node,
struct imc_pmu *pmu_ptr)
 {
static u64 loc, *imc_mode_addr, *imc_cmd_addr;
-   int chip = 0, nid;
char mode[16], cmd[16];
u32 cb_offset;
+   struct imc_mem_info *ptr = pmu_ptr->mem_info;