Skip to content

Commit 7c8c50c

Browse files
Yihang Ligregkh
Yihang Li
authored andcommitted
scsi: hisi_sas: Create all dump files during debugfs initialization
[ Upstream commit 9f564f1 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 0449286 commit 7c8c50c

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
@@ -3560,6 +3560,11 @@ debugfs_to_reg_name_v3_hw(int off, int base_off,
35603560
return NULL;
35613561
}
35623562

3563+
static bool debugfs_dump_is_generated_v3_hw(void *p)
3564+
{
3565+
return p ? true : false;
3566+
}
3567+
35633568
static void debugfs_print_reg_v3_hw(u32 *regs_val, struct seq_file *s,
35643569
const struct hisi_sas_debugfs_reg *reg)
35653570
{
@@ -3585,6 +3590,9 @@ static int debugfs_global_v3_hw_show(struct seq_file *s, void *p)
35853590
{
35863591
struct hisi_sas_debugfs_regs *global = s->private;
35873592

3593+
if (!debugfs_dump_is_generated_v3_hw(global->data))
3594+
return -EPERM;
3595+
35883596
debugfs_print_reg_v3_hw(global->data, s,
35893597
&debugfs_global_reg);
35903598

@@ -3596,6 +3604,9 @@ static int debugfs_axi_v3_hw_show(struct seq_file *s, void *p)
35963604
{
35973605
struct hisi_sas_debugfs_regs *axi = s->private;
35983606

3607+
if (!debugfs_dump_is_generated_v3_hw(axi->data))
3608+
return -EPERM;
3609+
35993610
debugfs_print_reg_v3_hw(axi->data, s,
36003611
&debugfs_axi_reg);
36013612

@@ -3607,6 +3618,9 @@ static int debugfs_ras_v3_hw_show(struct seq_file *s, void *p)
36073618
{
36083619
struct hisi_sas_debugfs_regs *ras = s->private;
36093620

3621+
if (!debugfs_dump_is_generated_v3_hw(ras->data))
3622+
return -EPERM;
3623+
36103624
debugfs_print_reg_v3_hw(ras->data, s,
36113625
&debugfs_ras_reg);
36123626

@@ -3619,6 +3633,9 @@ static int debugfs_port_v3_hw_show(struct seq_file *s, void *p)
36193633
struct hisi_sas_debugfs_port *port = s->private;
36203634
const struct hisi_sas_debugfs_reg *reg_port = &debugfs_port_reg;
36213635

3636+
if (!debugfs_dump_is_generated_v3_hw(port->data))
3637+
return -EPERM;
3638+
36223639
debugfs_print_reg_v3_hw(port->data, s, reg_port);
36233640

36243641
return 0;
@@ -3674,6 +3691,9 @@ static int debugfs_cq_v3_hw_show(struct seq_file *s, void *p)
36743691
struct hisi_sas_debugfs_cq *debugfs_cq = s->private;
36753692
int slot;
36763693

3694+
if (!debugfs_dump_is_generated_v3_hw(debugfs_cq->complete_hdr))
3695+
return -EPERM;
3696+
36773697
for (slot = 0; slot < HISI_SAS_QUEUE_SLOTS; slot++)
36783698
debugfs_cq_show_slot_v3_hw(s, slot, debugfs_cq);
36793699

@@ -3695,8 +3715,12 @@ static void debugfs_dq_show_slot_v3_hw(struct seq_file *s, int slot,
36953715

36963716
static int debugfs_dq_v3_hw_show(struct seq_file *s, void *p)
36973717
{
3718+
struct hisi_sas_debugfs_dq *debugfs_dq = s->private;
36983719
int slot;
36993720

3721+
if (!debugfs_dump_is_generated_v3_hw(debugfs_dq->hdr))
3722+
return -EPERM;
3723+
37003724
for (slot = 0; slot < HISI_SAS_QUEUE_SLOTS; slot++)
37013725
debugfs_dq_show_slot_v3_hw(s, slot, s->private);
37023726

@@ -3710,6 +3734,9 @@ static int debugfs_iost_v3_hw_show(struct seq_file *s, void *p)
37103734
struct hisi_sas_iost *iost = debugfs_iost->iost;
37113735
int i, max_command_entries = HISI_SAS_MAX_COMMANDS;
37123736

3737+
if (!debugfs_dump_is_generated_v3_hw(iost))
3738+
return -EPERM;
3739+
37133740
for (i = 0; i < max_command_entries; i++, iost++) {
37143741
__le64 *data = &iost->qw0;
37153742

@@ -3729,6 +3756,9 @@ static int debugfs_iost_cache_v3_hw_show(struct seq_file *s, void *p)
37293756
int i, tab_idx;
37303757
__le64 *iost;
37313758

3759+
if (!debugfs_dump_is_generated_v3_hw(iost_cache))
3760+
return -EPERM;
3761+
37323762
for (i = 0; i < HISI_SAS_IOST_ITCT_CACHE_NUM; i++, iost_cache++) {
37333763
/*
37343764
* Data struct of IOST cache:
@@ -3752,6 +3782,9 @@ static int debugfs_itct_v3_hw_show(struct seq_file *s, void *p)
37523782
struct hisi_sas_debugfs_itct *debugfs_itct = s->private;
37533783
struct hisi_sas_itct *itct = debugfs_itct->itct;
37543784

3785+
if (!debugfs_dump_is_generated_v3_hw(itct))
3786+
return -EPERM;
3787+
37553788
for (i = 0; i < HISI_SAS_MAX_ITCT_ENTRIES; i++, itct++) {
37563789
__le64 *data = &itct->qw0;
37573790

@@ -3771,6 +3804,9 @@ static int debugfs_itct_cache_v3_hw_show(struct seq_file *s, void *p)
37713804
int i, tab_idx;
37723805
__le64 *itct;
37733806

3807+
if (!debugfs_dump_is_generated_v3_hw(itct_cache))
3808+
return -EPERM;
3809+
37743810
for (i = 0; i < HISI_SAS_IOST_ITCT_CACHE_NUM; i++, itct_cache++) {
37753811
/*
37763812
* Data struct of ITCT cache:
@@ -3788,28 +3824,27 @@ static int debugfs_itct_cache_v3_hw_show(struct seq_file *s, void *p)
37883824
}
37893825
DEFINE_SHOW_ATTRIBUTE(debugfs_itct_cache_v3_hw);
37903826

3791-
static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
3827+
static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba, int index)
37923828
{
37933829
u64 *debugfs_timestamp;
3794-
int dump_index = hisi_hba->debugfs_dump_index;
37953830
struct dentry *dump_dentry;
37963831
struct dentry *dentry;
37973832
char name[256];
37983833
int p;
37993834
int c;
38003835
int d;
38013836

3802-
snprintf(name, 256, "%d", dump_index);
3837+
snprintf(name, 256, "%d", index);
38033838

38043839
dump_dentry = debugfs_create_dir(name, hisi_hba->debugfs_dump_dentry);
38053840

3806-
debugfs_timestamp = &hisi_hba->debugfs_timestamp[dump_index];
3841+
debugfs_timestamp = &hisi_hba->debugfs_timestamp[index];
38073842

38083843
debugfs_create_u64("timestamp", 0400, dump_dentry,
38093844
debugfs_timestamp);
38103845

38113846
debugfs_create_file("global", 0400, dump_dentry,
3812-
&hisi_hba->debugfs_regs[dump_index][DEBUGFS_GLOBAL],
3847+
&hisi_hba->debugfs_regs[index][DEBUGFS_GLOBAL],
38133848
&debugfs_global_v3_hw_fops);
38143849

38153850
/* Create port dir and files */
@@ -3818,7 +3853,7 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38183853
snprintf(name, 256, "%d", p);
38193854

38203855
debugfs_create_file(name, 0400, dentry,
3821-
&hisi_hba->debugfs_port_reg[dump_index][p],
3856+
&hisi_hba->debugfs_port_reg[index][p],
38223857
&debugfs_port_v3_hw_fops);
38233858
}
38243859

@@ -3828,7 +3863,7 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38283863
snprintf(name, 256, "%d", c);
38293864

38303865
debugfs_create_file(name, 0400, dentry,
3831-
&hisi_hba->debugfs_cq[dump_index][c],
3866+
&hisi_hba->debugfs_cq[index][c],
38323867
&debugfs_cq_v3_hw_fops);
38333868
}
38343869

@@ -3838,32 +3873,32 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38383873
snprintf(name, 256, "%d", d);
38393874

38403875
debugfs_create_file(name, 0400, dentry,
3841-
&hisi_hba->debugfs_dq[dump_index][d],
3876+
&hisi_hba->debugfs_dq[index][d],
38423877
&debugfs_dq_v3_hw_fops);
38433878
}
38443879

38453880
debugfs_create_file("iost", 0400, dump_dentry,
3846-
&hisi_hba->debugfs_iost[dump_index],
3881+
&hisi_hba->debugfs_iost[index],
38473882
&debugfs_iost_v3_hw_fops);
38483883

38493884
debugfs_create_file("iost_cache", 0400, dump_dentry,
3850-
&hisi_hba->debugfs_iost_cache[dump_index],
3885+
&hisi_hba->debugfs_iost_cache[index],
38513886
&debugfs_iost_cache_v3_hw_fops);
38523887

38533888
debugfs_create_file("itct", 0400, dump_dentry,
3854-
&hisi_hba->debugfs_itct[dump_index],
3889+
&hisi_hba->debugfs_itct[index],
38553890
&debugfs_itct_v3_hw_fops);
38563891

38573892
debugfs_create_file("itct_cache", 0400, dump_dentry,
3858-
&hisi_hba->debugfs_itct_cache[dump_index],
3893+
&hisi_hba->debugfs_itct_cache[index],
38593894
&debugfs_itct_cache_v3_hw_fops);
38603895

38613896
debugfs_create_file("axi", 0400, dump_dentry,
3862-
&hisi_hba->debugfs_regs[dump_index][DEBUGFS_AXI],
3897+
&hisi_hba->debugfs_regs[index][DEBUGFS_AXI],
38633898
&debugfs_axi_v3_hw_fops);
38643899

38653900
debugfs_create_file("ras", 0400, dump_dentry,
3866-
&hisi_hba->debugfs_regs[dump_index][DEBUGFS_RAS],
3901+
&hisi_hba->debugfs_regs[index][DEBUGFS_RAS],
38673902
&debugfs_ras_v3_hw_fops);
38683903
}
38693904

@@ -4645,22 +4680,34 @@ static void debugfs_release_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
46454680
int i;
46464681

46474682
devm_kfree(dev, hisi_hba->debugfs_iost_cache[dump_index].cache);
4683+
hisi_hba->debugfs_iost_cache[dump_index].cache = NULL;
46484684
devm_kfree(dev, hisi_hba->debugfs_itct_cache[dump_index].cache);
4685+
hisi_hba->debugfs_itct_cache[dump_index].cache = NULL;
46494686
devm_kfree(dev, hisi_hba->debugfs_iost[dump_index].iost);
4687+
hisi_hba->debugfs_iost[dump_index].iost = NULL;
46504688
devm_kfree(dev, hisi_hba->debugfs_itct[dump_index].itct);
4689+
hisi_hba->debugfs_itct[dump_index].itct = NULL;
46514690

4652-
for (i = 0; i < hisi_hba->queue_count; i++)
4691+
for (i = 0; i < hisi_hba->queue_count; i++) {
46534692
devm_kfree(dev, hisi_hba->debugfs_dq[dump_index][i].hdr);
4693+
hisi_hba->debugfs_dq[dump_index][i].hdr = NULL;
4694+
}
46544695

4655-
for (i = 0; i < hisi_hba->queue_count; i++)
4696+
for (i = 0; i < hisi_hba->queue_count; i++) {
46564697
devm_kfree(dev,
46574698
hisi_hba->debugfs_cq[dump_index][i].complete_hdr);
4699+
hisi_hba->debugfs_cq[dump_index][i].complete_hdr = NULL;
4700+
}
46584701

4659-
for (i = 0; i < DEBUGFS_REGS_NUM; i++)
4702+
for (i = 0; i < DEBUGFS_REGS_NUM; i++) {
46604703
devm_kfree(dev, hisi_hba->debugfs_regs[dump_index][i].data);
4704+
hisi_hba->debugfs_regs[dump_index][i].data = NULL;
4705+
}
46614706

4662-
for (i = 0; i < hisi_hba->n_phy; i++)
4707+
for (i = 0; i < hisi_hba->n_phy; i++) {
46634708
devm_kfree(dev, hisi_hba->debugfs_port_reg[dump_index][i].data);
4709+
hisi_hba->debugfs_port_reg[dump_index][i].data = NULL;
4710+
}
46644711
}
46654712

46664713
static const struct hisi_sas_debugfs_reg *debugfs_reg_array_v3_hw[DEBUGFS_REGS_NUM] = {
@@ -4787,8 +4834,6 @@ static int debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba)
47874834
debugfs_snapshot_itct_reg_v3_hw(hisi_hba);
47884835
debugfs_snapshot_iost_reg_v3_hw(hisi_hba);
47894836

4790-
debugfs_create_files_v3_hw(hisi_hba);
4791-
47924837
debugfs_snapshot_restore_v3_hw(hisi_hba);
47934838
hisi_hba->debugfs_dump_index++;
47944839

@@ -4872,6 +4917,17 @@ static void debugfs_bist_init_v3_hw(struct hisi_hba *hisi_hba)
48724917
hisi_hba->debugfs_bist_linkrate = SAS_LINK_RATE_1_5_GBPS;
48734918
}
48744919

4920+
static void debugfs_dump_init_v3_hw(struct hisi_hba *hisi_hba)
4921+
{
4922+
int i;
4923+
4924+
hisi_hba->debugfs_dump_dentry =
4925+
debugfs_create_dir("dump", hisi_hba->debugfs_dir);
4926+
4927+
for (i = 0; i < hisi_sas_debugfs_dump_count; i++)
4928+
debugfs_create_files_v3_hw(hisi_hba, i);
4929+
}
4930+
48754931
static void debugfs_exit_v3_hw(struct hisi_hba *hisi_hba)
48764932
{
48774933
debugfs_remove_recursive(hisi_hba->debugfs_dir);
@@ -4892,8 +4948,7 @@ static void debugfs_init_v3_hw(struct hisi_hba *hisi_hba)
48924948
/* create bist structures */
48934949
debugfs_bist_init_v3_hw(hisi_hba);
48944950

4895-
hisi_hba->debugfs_dump_dentry =
4896-
debugfs_create_dir("dump", hisi_hba->debugfs_dir);
4951+
debugfs_dump_init_v3_hw(hisi_hba);
48974952

48984953
debugfs_phy_down_cnt_init_v3_hw(hisi_hba);
48994954
debugfs_fifo_init_v3_hw(hisi_hba);

0 commit comments

Comments
 (0)