Skip to content

Commit 9f564f1

Browse files
Yihang Limartinkpetersen
authored andcommitted
scsi: hisi_sas: Create all dump files during debugfs initialization
For the current debugfs of hisi_sas, after user triggers dump, the driver allocate memory space to save the register information and create debugfs files to display the saved information. In this process, the debugfs files created after each dump. Therefore, when the dump is triggered while the driver is unbind, the following hang occurs: [67840.853907] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000a0 [67840.862947] Mem abort info: [67840.865855] ESR = 0x0000000096000004 [67840.869713] EC = 0x25: DABT (current EL), IL = 32 bits [67840.875125] SET = 0, FnV = 0 [67840.878291] EA = 0, S1PTW = 0 [67840.881545] FSC = 0x04: level 0 translation fault [67840.886528] Data abort info: [67840.889524] ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000 [67840.895117] CM = 0, WnR = 0, TnD = 0, TagAccess = 0 [67840.900284] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0 [67840.905709] user pgtable: 4k pages, 48-bit VAs, pgdp=0000002803a1f000 [67840.912263] [00000000000000a0] pgd=0000000000000000, p4d=0000000000000000 [67840.919177] Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP [67840.996435] pstate: 80400009 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [67841.003628] pc : down_write+0x30/0x98 [67841.007546] lr : start_creating.part.0+0x60/0x198 [67841.012495] sp : ffff8000b979ba20 [67841.016046] x29: ffff8000b979ba20 x28: 0000000000000010 x27: 0000000000024b40 [67841.023412] x26: 0000000000000012 x25: ffff20202b355ae8 x24: ffff20202b35a8c8 [67841.030779] x23: ffffa36877928208 x22: ffffa368b4972240 x21: ffff8000b979bb18 [67841.038147] x20: ffff00281dc1e3c0 x19: fffffffffffffffe x18: 0000000000000020 [67841.045515] x17: 0000000000000000 x16: ffffa368b128a530 x15: ffffffffffffffff [67841.052888] x14: ffff8000b979bc18 x13: ffffffffffffffff x12: ffff8000b979bb18 [67841.060263] x11: 0000000000000000 x10: 0000000000000000 x9 : ffffa368b1289b18 [67841.067640] x8 : 0000000000000012 x7 : 0000000000000000 x6 : 00000000000003a9 [67841.075014] x5 : 0000000000000000 x4 : ffff002818c5cb00 x3 : 0000000000000001 [67841.082388] x2 : 0000000000000000 x1 : ffff002818c5cb00 x0 : 00000000000000a0 [67841.089759] Call trace: [67841.092456] down_write+0x30/0x98 [67841.096017] start_creating.part.0+0x60/0x198 [67841.100613] debugfs_create_dir+0x48/0x1f8 [67841.104950] debugfs_create_files_v3_hw+0x88/0x348 [hisi_sas_v3_hw] [67841.111447] debugfs_snapshot_regs_v3_hw+0x708/0x798 [hisi_sas_v3_hw] [67841.118111] debugfs_trigger_dump_v3_hw_write+0x9c/0x120 [hisi_sas_v3_hw] [67841.125115] full_proxy_write+0x68/0xc8 [67841.129175] vfs_write+0xd8/0x3f0 [67841.132708] ksys_write+0x70/0x108 [67841.136317] __arm64_sys_write+0x24/0x38 [67841.140440] invoke_syscall+0x50/0x128 [67841.144385] el0_svc_common.constprop.0+0xc8/0xf0 [67841.149273] do_el0_svc+0x24/0x38 [67841.152773] el0_svc+0x38/0xd8 [67841.156009] el0t_64_sync_handler+0xc0/0xc8 [67841.160361] el0t_64_sync+0x1a4/0x1a8 [67841.164189] Code: b9000882 d2800002 d2800023 f9800011 (c85ffc05) [67841.170443] ---[ end trace 0000000000000000 ]--- To fix this issue, create all directories and files during debugfs initialization. In this way, the driver only needs to allocate memory space to save information each time the user triggers dumping. Signed-off-by: Yihang Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Xingui Yang <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 90f17e3 commit 9f564f1

File tree

1 file changed

+77
-22
lines changed

1 file changed

+77
-22
lines changed

drivers/scsi/hisi_sas/hisi_sas_v3_hw.c

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,6 +3576,11 @@ debugfs_to_reg_name_v3_hw(int off, int base_off,
35763576
return NULL;
35773577
}
35783578

3579+
static bool debugfs_dump_is_generated_v3_hw(void *p)
3580+
{
3581+
return p ? true : false;
3582+
}
3583+
35793584
static void debugfs_print_reg_v3_hw(u32 *regs_val, struct seq_file *s,
35803585
const struct hisi_sas_debugfs_reg *reg)
35813586
{
@@ -3601,6 +3606,9 @@ static int debugfs_global_v3_hw_show(struct seq_file *s, void *p)
36013606
{
36023607
struct hisi_sas_debugfs_regs *global = s->private;
36033608

3609+
if (!debugfs_dump_is_generated_v3_hw(global->data))
3610+
return -EPERM;
3611+
36043612
debugfs_print_reg_v3_hw(global->data, s,
36053613
&debugfs_global_reg);
36063614

@@ -3612,6 +3620,9 @@ static int debugfs_axi_v3_hw_show(struct seq_file *s, void *p)
36123620
{
36133621
struct hisi_sas_debugfs_regs *axi = s->private;
36143622

3623+
if (!debugfs_dump_is_generated_v3_hw(axi->data))
3624+
return -EPERM;
3625+
36153626
debugfs_print_reg_v3_hw(axi->data, s,
36163627
&debugfs_axi_reg);
36173628

@@ -3623,6 +3634,9 @@ static int debugfs_ras_v3_hw_show(struct seq_file *s, void *p)
36233634
{
36243635
struct hisi_sas_debugfs_regs *ras = s->private;
36253636

3637+
if (!debugfs_dump_is_generated_v3_hw(ras->data))
3638+
return -EPERM;
3639+
36263640
debugfs_print_reg_v3_hw(ras->data, s,
36273641
&debugfs_ras_reg);
36283642

@@ -3635,6 +3649,9 @@ static int debugfs_port_v3_hw_show(struct seq_file *s, void *p)
36353649
struct hisi_sas_debugfs_port *port = s->private;
36363650
const struct hisi_sas_debugfs_reg *reg_port = &debugfs_port_reg;
36373651

3652+
if (!debugfs_dump_is_generated_v3_hw(port->data))
3653+
return -EPERM;
3654+
36383655
debugfs_print_reg_v3_hw(port->data, s, reg_port);
36393656

36403657
return 0;
@@ -3690,6 +3707,9 @@ static int debugfs_cq_v3_hw_show(struct seq_file *s, void *p)
36903707
struct hisi_sas_debugfs_cq *debugfs_cq = s->private;
36913708
int slot;
36923709

3710+
if (!debugfs_dump_is_generated_v3_hw(debugfs_cq->complete_hdr))
3711+
return -EPERM;
3712+
36933713
for (slot = 0; slot < HISI_SAS_QUEUE_SLOTS; slot++)
36943714
debugfs_cq_show_slot_v3_hw(s, slot, debugfs_cq);
36953715

@@ -3711,8 +3731,12 @@ static void debugfs_dq_show_slot_v3_hw(struct seq_file *s, int slot,
37113731

37123732
static int debugfs_dq_v3_hw_show(struct seq_file *s, void *p)
37133733
{
3734+
struct hisi_sas_debugfs_dq *debugfs_dq = s->private;
37143735
int slot;
37153736

3737+
if (!debugfs_dump_is_generated_v3_hw(debugfs_dq->hdr))
3738+
return -EPERM;
3739+
37163740
for (slot = 0; slot < HISI_SAS_QUEUE_SLOTS; slot++)
37173741
debugfs_dq_show_slot_v3_hw(s, slot, s->private);
37183742

@@ -3726,6 +3750,9 @@ static int debugfs_iost_v3_hw_show(struct seq_file *s, void *p)
37263750
struct hisi_sas_iost *iost = debugfs_iost->iost;
37273751
int i, max_command_entries = HISI_SAS_MAX_COMMANDS;
37283752

3753+
if (!debugfs_dump_is_generated_v3_hw(iost))
3754+
return -EPERM;
3755+
37293756
for (i = 0; i < max_command_entries; i++, iost++) {
37303757
__le64 *data = &iost->qw0;
37313758

@@ -3745,6 +3772,9 @@ static int debugfs_iost_cache_v3_hw_show(struct seq_file *s, void *p)
37453772
int i, tab_idx;
37463773
__le64 *iost;
37473774

3775+
if (!debugfs_dump_is_generated_v3_hw(iost_cache))
3776+
return -EPERM;
3777+
37483778
for (i = 0; i < HISI_SAS_IOST_ITCT_CACHE_NUM; i++, iost_cache++) {
37493779
/*
37503780
* Data struct of IOST cache:
@@ -3768,6 +3798,9 @@ static int debugfs_itct_v3_hw_show(struct seq_file *s, void *p)
37683798
struct hisi_sas_debugfs_itct *debugfs_itct = s->private;
37693799
struct hisi_sas_itct *itct = debugfs_itct->itct;
37703800

3801+
if (!debugfs_dump_is_generated_v3_hw(itct))
3802+
return -EPERM;
3803+
37713804
for (i = 0; i < HISI_SAS_MAX_ITCT_ENTRIES; i++, itct++) {
37723805
__le64 *data = &itct->qw0;
37733806

@@ -3787,6 +3820,9 @@ static int debugfs_itct_cache_v3_hw_show(struct seq_file *s, void *p)
37873820
int i, tab_idx;
37883821
__le64 *itct;
37893822

3823+
if (!debugfs_dump_is_generated_v3_hw(itct_cache))
3824+
return -EPERM;
3825+
37903826
for (i = 0; i < HISI_SAS_IOST_ITCT_CACHE_NUM; i++, itct_cache++) {
37913827
/*
37923828
* Data struct of ITCT cache:
@@ -3804,28 +3840,27 @@ static int debugfs_itct_cache_v3_hw_show(struct seq_file *s, void *p)
38043840
}
38053841
DEFINE_SHOW_ATTRIBUTE(debugfs_itct_cache_v3_hw);
38063842

3807-
static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
3843+
static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba, int index)
38083844
{
38093845
u64 *debugfs_timestamp;
3810-
int dump_index = hisi_hba->debugfs_dump_index;
38113846
struct dentry *dump_dentry;
38123847
struct dentry *dentry;
38133848
char name[256];
38143849
int p;
38153850
int c;
38163851
int d;
38173852

3818-
snprintf(name, 256, "%d", dump_index);
3853+
snprintf(name, 256, "%d", index);
38193854

38203855
dump_dentry = debugfs_create_dir(name, hisi_hba->debugfs_dump_dentry);
38213856

3822-
debugfs_timestamp = &hisi_hba->debugfs_timestamp[dump_index];
3857+
debugfs_timestamp = &hisi_hba->debugfs_timestamp[index];
38233858

38243859
debugfs_create_u64("timestamp", 0400, dump_dentry,
38253860
debugfs_timestamp);
38263861

38273862
debugfs_create_file("global", 0400, dump_dentry,
3828-
&hisi_hba->debugfs_regs[dump_index][DEBUGFS_GLOBAL],
3863+
&hisi_hba->debugfs_regs[index][DEBUGFS_GLOBAL],
38293864
&debugfs_global_v3_hw_fops);
38303865

38313866
/* Create port dir and files */
@@ -3834,7 +3869,7 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38343869
snprintf(name, 256, "%d", p);
38353870

38363871
debugfs_create_file(name, 0400, dentry,
3837-
&hisi_hba->debugfs_port_reg[dump_index][p],
3872+
&hisi_hba->debugfs_port_reg[index][p],
38383873
&debugfs_port_v3_hw_fops);
38393874
}
38403875

@@ -3844,7 +3879,7 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38443879
snprintf(name, 256, "%d", c);
38453880

38463881
debugfs_create_file(name, 0400, dentry,
3847-
&hisi_hba->debugfs_cq[dump_index][c],
3882+
&hisi_hba->debugfs_cq[index][c],
38483883
&debugfs_cq_v3_hw_fops);
38493884
}
38503885

@@ -3854,32 +3889,32 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38543889
snprintf(name, 256, "%d", d);
38553890

38563891
debugfs_create_file(name, 0400, dentry,
3857-
&hisi_hba->debugfs_dq[dump_index][d],
3892+
&hisi_hba->debugfs_dq[index][d],
38583893
&debugfs_dq_v3_hw_fops);
38593894
}
38603895

38613896
debugfs_create_file("iost", 0400, dump_dentry,
3862-
&hisi_hba->debugfs_iost[dump_index],
3897+
&hisi_hba->debugfs_iost[index],
38633898
&debugfs_iost_v3_hw_fops);
38643899

38653900
debugfs_create_file("iost_cache", 0400, dump_dentry,
3866-
&hisi_hba->debugfs_iost_cache[dump_index],
3901+
&hisi_hba->debugfs_iost_cache[index],
38673902
&debugfs_iost_cache_v3_hw_fops);
38683903

38693904
debugfs_create_file("itct", 0400, dump_dentry,
3870-
&hisi_hba->debugfs_itct[dump_index],
3905+
&hisi_hba->debugfs_itct[index],
38713906
&debugfs_itct_v3_hw_fops);
38723907

38733908
debugfs_create_file("itct_cache", 0400, dump_dentry,
3874-
&hisi_hba->debugfs_itct_cache[dump_index],
3909+
&hisi_hba->debugfs_itct_cache[index],
38753910
&debugfs_itct_cache_v3_hw_fops);
38763911

38773912
debugfs_create_file("axi", 0400, dump_dentry,
3878-
&hisi_hba->debugfs_regs[dump_index][DEBUGFS_AXI],
3913+
&hisi_hba->debugfs_regs[index][DEBUGFS_AXI],
38793914
&debugfs_axi_v3_hw_fops);
38803915

38813916
debugfs_create_file("ras", 0400, dump_dentry,
3882-
&hisi_hba->debugfs_regs[dump_index][DEBUGFS_RAS],
3917+
&hisi_hba->debugfs_regs[index][DEBUGFS_RAS],
38833918
&debugfs_ras_v3_hw_fops);
38843919
}
38853920

@@ -4542,22 +4577,34 @@ static void debugfs_release_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
45424577
int i;
45434578

45444579
devm_kfree(dev, hisi_hba->debugfs_iost_cache[dump_index].cache);
4580+
hisi_hba->debugfs_iost_cache[dump_index].cache = NULL;
45454581
devm_kfree(dev, hisi_hba->debugfs_itct_cache[dump_index].cache);
4582+
hisi_hba->debugfs_itct_cache[dump_index].cache = NULL;
45464583
devm_kfree(dev, hisi_hba->debugfs_iost[dump_index].iost);
4584+
hisi_hba->debugfs_iost[dump_index].iost = NULL;
45474585
devm_kfree(dev, hisi_hba->debugfs_itct[dump_index].itct);
4586+
hisi_hba->debugfs_itct[dump_index].itct = NULL;
45484587

4549-
for (i = 0; i < hisi_hba->queue_count; i++)
4588+
for (i = 0; i < hisi_hba->queue_count; i++) {
45504589
devm_kfree(dev, hisi_hba->debugfs_dq[dump_index][i].hdr);
4590+
hisi_hba->debugfs_dq[dump_index][i].hdr = NULL;
4591+
}
45514592

4552-
for (i = 0; i < hisi_hba->queue_count; i++)
4593+
for (i = 0; i < hisi_hba->queue_count; i++) {
45534594
devm_kfree(dev,
45544595
hisi_hba->debugfs_cq[dump_index][i].complete_hdr);
4596+
hisi_hba->debugfs_cq[dump_index][i].complete_hdr = NULL;
4597+
}
45554598

4556-
for (i = 0; i < DEBUGFS_REGS_NUM; i++)
4599+
for (i = 0; i < DEBUGFS_REGS_NUM; i++) {
45574600
devm_kfree(dev, hisi_hba->debugfs_regs[dump_index][i].data);
4601+
hisi_hba->debugfs_regs[dump_index][i].data = NULL;
4602+
}
45584603

4559-
for (i = 0; i < hisi_hba->n_phy; i++)
4604+
for (i = 0; i < hisi_hba->n_phy; i++) {
45604605
devm_kfree(dev, hisi_hba->debugfs_port_reg[dump_index][i].data);
4606+
hisi_hba->debugfs_port_reg[dump_index][i].data = NULL;
4607+
}
45614608
}
45624609

45634610
static const struct hisi_sas_debugfs_reg *debugfs_reg_array_v3_hw[DEBUGFS_REGS_NUM] = {
@@ -4684,8 +4731,6 @@ static int debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba)
46844731
debugfs_snapshot_itct_reg_v3_hw(hisi_hba);
46854732
debugfs_snapshot_iost_reg_v3_hw(hisi_hba);
46864733

4687-
debugfs_create_files_v3_hw(hisi_hba);
4688-
46894734
debugfs_snapshot_restore_v3_hw(hisi_hba);
46904735
hisi_hba->debugfs_dump_index++;
46914736

@@ -4769,6 +4814,17 @@ static void debugfs_bist_init_v3_hw(struct hisi_hba *hisi_hba)
47694814
hisi_hba->debugfs_bist_linkrate = SAS_LINK_RATE_1_5_GBPS;
47704815
}
47714816

4817+
static void debugfs_dump_init_v3_hw(struct hisi_hba *hisi_hba)
4818+
{
4819+
int i;
4820+
4821+
hisi_hba->debugfs_dump_dentry =
4822+
debugfs_create_dir("dump", hisi_hba->debugfs_dir);
4823+
4824+
for (i = 0; i < hisi_sas_debugfs_dump_count; i++)
4825+
debugfs_create_files_v3_hw(hisi_hba, i);
4826+
}
4827+
47724828
static void debugfs_exit_v3_hw(struct hisi_hba *hisi_hba)
47734829
{
47744830
debugfs_remove_recursive(hisi_hba->debugfs_dir);
@@ -4784,8 +4840,7 @@ static void debugfs_init_v3_hw(struct hisi_hba *hisi_hba)
47844840
/* create bist structures */
47854841
debugfs_bist_init_v3_hw(hisi_hba);
47864842

4787-
hisi_hba->debugfs_dump_dentry =
4788-
debugfs_create_dir("dump", hisi_hba->debugfs_dir);
4843+
debugfs_dump_init_v3_hw(hisi_hba);
47894844

47904845
debugfs_phy_down_cnt_init_v3_hw(hisi_hba);
47914846
debugfs_fifo_init_v3_hw(hisi_hba);

0 commit comments

Comments
 (0)