From e5e64f4e67fc052d43ae5ac7f033bc7ffb78f614 Mon Sep 17 00:00:00 2001 From: daichx Date: Mon, 24 Jun 2024 22:31:38 +0800 Subject: [PATCH] anolis: intel_th: Fixing occasional device number duplication issue with intel_th driver. ANBZ: #13367 [ 14.101120] sysfs: cannot create duplicate filename '/dev/char/237:2' [ 14.107705] CPU: 1 PID: 849 Comm: modprobe Tainted: G OE 4.19.91-26.4.3.kos5.x86_64 #1 [ 14.116971] Hardware name: IEITSYSTEMS Qingqiu/Qingqiu, BIOS 1.02.08 03/21/2024 [ 14.127007] dump_stack+0x66/0x90 [ 14.130462] sysfs_warn_dup.cold.0+0x17/0x23 [ 14.134871] sysfs_do_create_link_sd.isra.0+0xaa/0xd0 [ 14.140060] device_add+0x5d5/0x690 [ 14.143683] intel_th_subdevice_alloc+0x385/0x450 [intel_th] [ 14.149477] ? add_dr+0x35/0x60 [ 14.152752] ? add_dr+0x35/0x60 [ 14.156026] intel_th_output_enable+0xaf/0xe0 [intel_th] [ 14.161471] intel_th_gth_probe+0x216/0x4a0 [intel_th_gth] [ 14.167090] ? mutex_unlock+0x5/0x30 [ 14.170801] ? kernfs_remove_by_name_ns+0x5b/0x90 [ 14.175639] intel_th_probe+0x69/0x120 [intel_th] [ 14.180478] really_probe+0x23e/0x390 [ 14.184270] driver_probe_device+0xd1/0x110 [ 14.188585] __driver_attach+0xea/0x110 [ 14.192551] ? driver_probe_device+0x110/0x110 [ 14.197126] ? driver_probe_device+0x110/0x110 [ 14.201703] bus_for_each_dev+0x63/0x90 [ 14.205673] bus_add_driver+0x152/0x230 [ 14.209640] ? 0xffffffffc0404000 [ 14.210395] ngbe 0000:43:00.0: 4.000 Gb/s available PCIe bandwidth, limited by 5 GT/s x1 link at 0000:00:17.0 (capable of 16.000 Gb/s with 5 GT/s x4 link) [ 14.213086] driver_register+0x6b/0xb0 [ 14.213089] ? 0xffffffffc0404000 [ 14.213096] do_one_initcall+0x46/0x1c3 [ 14.233611] ngbe 0000:43:00.0 eth0: NCSI : support [ 14.234372] ? free_unref_page_commit+0x9b/0x110 [ 14.234377] ? memcg_kmem_put_cache+0x5/0x50 [ 14.238346] ngbe 0000:43:00.0 eth0: PHY: Internal, PBA No: Wang Xun GbE Family Controller [ 14.243264] ? kmem_cache_alloc_trace+0x145/0x190 [ 14.243267] ? do_init_module+0x22/0x210 [ 14.243272] do_init_module+0x5a/0x210 [ 14.248026] ngbe 0000:43:00.0 eth0: 02:02:03:15:01:01 [ 14.252423] load_module+0x1519/0x15d0 [ 14.252429] ? __se_sys_finit_module+0x82/0xc0 [ 14.260737] ngbe 0000:43:00.0 eth0: Enabled Features: RxQ: 4 TxQ: 4 [ 14.265569] __se_sys_finit_module+0x82/0xc0 [ 14.265573] do_syscall_64+0x5f/0x1b0 Signed-off-by: daichx Signed-off-by: Bo Liu Reviewed-by: Bitao Hu Reviewed-by: Guixin Liu Link: https://gitee.com/anolis/cloud-kernel/pulls/4470 Signed-off-by: wangkaiyuan --- drivers/hwtracing/intel_th/core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/hwtracing/intel_th/core.c b/drivers/hwtracing/intel_th/core.c index cc7f879bb175..31d553760063 100644 --- a/drivers/hwtracing/intel_th/core.c +++ b/drivers/hwtracing/intel_th/core.c @@ -17,12 +17,14 @@ #include #include #include +#include #include "intel_th.h" #include "debug.h" static bool host_mode __read_mostly; module_param(host_mode, bool, 0444); +static DEFINE_SPINLOCK(intel_th_lock); static DEFINE_IDA(intel_th_ida); @@ -716,7 +718,7 @@ int intel_th_output_enable(struct intel_th *th, unsigned int otype) { struct intel_th_device *thdev; int src = 0, dst = 0; - + spin_lock(&intel_th_lock); for (src = 0, dst = 0; dst <= th->num_thdevs; src++, dst++) { for (; src < ARRAY_SIZE(intel_th_subdevices); src++) { if (intel_th_subdevices[src].type != INTEL_TH_OUTPUT) @@ -729,8 +731,10 @@ int intel_th_output_enable(struct intel_th *th, unsigned int otype) } /* no unallocated matching subdevices */ - if (src == ARRAY_SIZE(intel_th_subdevices)) + if (src == ARRAY_SIZE(intel_th_subdevices)) { + spin_unlock(&intel_th_lock); return -ENODEV; + } for (; dst < th->num_thdevs; dst++) { if (th->thdev[dst]->type != INTEL_TH_OUTPUT) @@ -749,16 +753,18 @@ int intel_th_output_enable(struct intel_th *th, unsigned int otype) if (dst == th->num_thdevs) goto found; } - + spin_unlock(&intel_th_lock); return -ENODEV; found: thdev = intel_th_subdevice_alloc(th, &intel_th_subdevices[src]); - if (IS_ERR(thdev)) + if (IS_ERR(thdev)) { + spin_unlock(&intel_th_lock); return PTR_ERR(thdev); + } th->thdev[th->num_thdevs++] = thdev; - + spin_unlock(&intel_th_lock); return 0; } EXPORT_SYMBOL_GPL(intel_th_output_enable); @@ -767,6 +773,7 @@ static int intel_th_populate(struct intel_th *th) { int src; + spin_lock(&intel_th_lock); /* create devices for each intel_th_subdevice */ for (src = 0; src < ARRAY_SIZE(intel_th_subdevices); src++) { const struct intel_th_subdevice *subdev = @@ -792,13 +799,14 @@ static int intel_th_populate(struct intel_th *th) /* ENODEV for individual subdevices is allowed */ if (PTR_ERR(thdev) == -ENODEV) continue; - + spin_unlock(&intel_th_lock); return PTR_ERR(thdev); } th->thdev[th->num_thdevs++] = thdev; } + spin_unlock(&intel_th_lock); return 0; } -- Gitee