[RESEND] clk: Warn and add workaround on misuse of .parent_data with .name only

Message ID 20230111193957.27650-1-ansuelsmth@gmail.com
State New
Headers
Series [RESEND] clk: Warn and add workaround on misuse of .parent_data with .name only |

Commit Message

Christian Marangi Jan. 11, 2023, 7:39 p.m. UTC
  By a simple mistake in a .parent_names to .parent_data conversion it was
found that clk core assume fw_name is always provided with a parent_data
struct for each parent and never fallback to .name to get parent name even
if declared.

This is caused by clk_core_get that only checks for parent .fw_name and
doesn't handle .name.

While it's sane to request the dev to correctly do the conversion and
add both .fw_name and .name in a parent_data struct, it's not sane to
silently drop parents without a warning.

Fix this in 2 ways. Add a kernel warning when a wrong implementation is
used and copy .name in .fw_name in parent map populate function to
handle clk problems and malfunctions.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/clk/clk.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
  

Comments

kernel test robot Jan. 28, 2023, 5:08 a.m. UTC | #1
Greeting,

FYI, we noticed WARNING:at_drivers/clk/clk.c:#clk_core_populate_parent_map due to commit (built with gcc-11):

commit: cc3ff324b29f06b124b57f745fcc4ec624c87d16 ("[RESEND PATCH] clk: Warn and add workaround on misuse of .parent_data with .name only")
url: https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/clk-Warn-and-add-workaround-on-misuse-of-parent_data-with-name-only/20230112-034048
base: https://git.kernel.org/cgit/linux/kernel/git/clk/linux.git clk-next
patch link: https://lore.kernel.org/all/20230111193957.27650-1-ansuelsmth@gmail.com/
patch subject: [RESEND PATCH] clk: Warn and add workaround on misuse of .parent_data with .name only

in testcase: kunit
version: 
with following parameters:

	group: group-02



on test machine: 8 threads 1 sockets Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz (Haswell) with 16G memory

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):


If you fix the issue, kindly add following tag
| Reported-by: kernel test robot <oliver.sang@intel.com>
| Link: https://lore.kernel.org/oe-lkp/202301280943.6a383af9-oliver.sang@intel.com


[   81.119809][  T621] ------------[ cut here ]------------
[   81.130925][  T621] Empty .fw_name with .name in test_gate's .parent_data. Using .name for .fw_name declaration.
[ 81.141019][ T621] WARNING: CPU: 7 PID: 621 at drivers/clk/clk.c:4057 clk_core_populate_parent_map+0x405/0x610 
[   81.152038][  T621] Modules linked in: clk_gate_test intel_rapl_msr intel_rapl_common btrfs blake2b_generic xor raid6_pq libcrc32c x86_pkg_temp_thermal intel_powerclamp i915 coretemp sd_mod t10_pi kvm_intel crc64_rocksoft_generic crc64_rocksoft crc64 intel_gtt sg kvm drm_display_helper ipmi_devintf irqbypass ipmi_msghandler crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel sha512_ssse3 drm_buddy ttm ahci rapl mei_wdt libahci drm_kms_helper intel_cstate syscopyarea mei_me sysfillrect libata intel_uncore video mei sysimgblt wmi drm fuse ip_tables
[   81.200885][  T621] CPU: 7 PID: 621 Comm: kunit_try_catch Tainted: G                 N 6.2.0-rc1-00001-gcc3ff324b29f #1
[   81.211561][  T621] Hardware name: Dell Inc. OptiPlex 9020/0DNKMN, BIOS A05 12/05/2013
[ 81.219409][ T621] RIP: clk_core_populate_parent_map+0x405/0x610 
[ 81.226916][ T621] Code: 3c 24 00 0f 84 e8 fd ff ff 48 8b 44 24 20 80 38 00 0f 85 a3 01 00 00 48 8b 04 24 48 c7 c7 20 78 eb 83 48 8b 30 e8 8b 77 1d 01 <0f> 0b 4c 89 e0 48 c1 e8 03 42 80 3c 38 00 0f 85 6f 01 00 00 49 8b
All code
========
   0:	3c 24                	cmp    $0x24,%al
   2:	00 0f                	add    %cl,(%rdi)
   4:	84 e8                	test   %ch,%al
   6:	fd                   	std    
   7:	ff                   	(bad)  
   8:	ff 48 8b             	decl   -0x75(%rax)
   b:	44 24 20             	rex.R and $0x20,%al
   e:	80 38 00             	cmpb   $0x0,(%rax)
  11:	0f 85 a3 01 00 00    	jne    0x1ba
  17:	48 8b 04 24          	mov    (%rsp),%rax
  1b:	48 c7 c7 20 78 eb 83 	mov    $0xffffffff83eb7820,%rdi
  22:	48 8b 30             	mov    (%rax),%rsi
  25:	e8 8b 77 1d 01       	callq  0x11d77b5
  2a:*	0f 0b                	ud2    		<-- trapping instruction
  2c:	4c 89 e0             	mov    %r12,%rax
  2f:	48 c1 e8 03          	shr    $0x3,%rax
  33:	42 80 3c 38 00       	cmpb   $0x0,(%rax,%r15,1)
  38:	0f 85 6f 01 00 00    	jne    0x1ad
  3e:	49                   	rex.WB
  3f:	8b                   	.byte 0x8b

Code starting with the faulting instruction
===========================================
   0:	0f 0b                	ud2    
   2:	4c 89 e0             	mov    %r12,%rax
   5:	48 c1 e8 03          	shr    $0x3,%rax
   9:	42 80 3c 38 00       	cmpb   $0x0,(%rax,%r15,1)
   e:	0f 85 6f 01 00 00    	jne    0x183
  14:	49                   	rex.WB
  15:	8b                   	.byte 0x8b
[   81.246189][  T621] RSP: 0018:ffffc90000b17bb8 EFLAGS: 00010282
[   81.252058][  T621] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[   81.259819][  T621] RDX: 0000000000000004 RSI: 0000000000000008 RDI: fffff52000162f69
[   81.267588][  T621] RBP: 0000000000000000 R08: 0000000000000001 R09: ffffc90000b179ef
[   81.275349][  T621] R10: fffff52000162f3d R11: 0000000000000001 R12: ffffc90000b17e60
[   81.283111][  T621] R13: 0000000000000000 R14: ffff88841e5f9180 R15: dffffc0000000000
[   81.290858][  T621] FS:  0000000000000000(0000) GS:ffff8883b8980000(0000) knlGS:0000000000000000
[   81.299564][  T621] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   81.305953][  T621] CR2: 00007fb2ba883550 CR3: 000000041ce14004 CR4: 00000000001706e0
[   81.313714][  T621] DR0: ffffffff86045121 DR1: ffffffff86045122 DR2: ffffffff86045123
[   81.321473][  T621] DR3: ffffffff86045123 DR6: 00000000ffff0ff0 DR7: 0000000000000600
[   81.329231][  T621] Call Trace:
[   81.332363][  T621]  <TASK>
[ 81.335150][ T621] __clk_register (drivers/clk/clk.c:4150) 
[ 81.339656][ T621] clk_hw_register (include/linux/err.h:60 drivers/clk/clk.c:4242) 
[ 81.344063][ T621] __clk_hw_register_gate (drivers/clk/clk-gate.c:172) 
[ 81.349252][ T621] ? devm_clk_hw_release_gate (drivers/clk/clk-gate.c:134) 
[ 81.354612][ T621] ? update_curr (include/linux/cgroup.h:424 include/linux/cgroup.h:493 include/linux/cgroup.h:722 kernel/sched/fair.c:930) 
[ 81.359029][ T621] ? load_balance (kernel/sched/fair.c:11511) 
[ 81.363706][ T621] clk_gate_register_test_parent_data_legacy (drivers/clk/clk-gate_test.c:78 (discriminator 1)) clk_gate_test
[ 81.371901][ T621] ? clk_gate_register_test_parent_hw (drivers/clk/clk-gate_test.c:68) clk_gate_test
[ 81.379494][ T621] ? io_schedule_timeout (kernel/sched/core.c:6437) 
[ 81.384601][ T621] ? set_cpus_allowed_ptr (kernel/sched/core.c:2971) 
[ 81.389609][ T621] ? migrate_enable (kernel/sched/core.c:2971) 
[ 81.394274][ T621] kunit_try_run_case (lib/kunit/test.c:397) 
[ 81.399121][ T621] ? kunit_catch_run_case (lib/kunit/test.c:382) 
[ 81.404138][ T621] kunit_generic_run_threadfn_adapter (lib/kunit/try-catch.c:30) 
[ 81.410187][ T621] ? kunit_try_catch_throw (lib/kunit/try-catch.c:25) 
[ 81.415277][ T621] kthread (kernel/kthread.c:376) 
[ 81.419182][ T621] ? kthread_complete_and_exit (kernel/kthread.c:331) 
[ 81.424617][ T621] ret_from_fork (arch/x86/entry/entry_64.S:314) 
[   81.428863][  T621]  </TASK>
[   81.431732][  T621] ---[ end trace 0000000000000000 ]---
[   81.437519][  T617]     ok 4 clk_gate_register_test_parent_data_legacy
[   81.438007][  T617]     ok 5 clk_gate_register_test_parent_hw
[   81.444626][  T623] gate bit exceeds LOWORD field
[   81.454990][  T617]     ok 6 clk_gate_register_test_hiword_invalid
[   81.454995][  T617] # clk-gate-register-test: pass:6 fail:0 skip:0 total:6
[   81.461124][  T617] # Totals: pass:6 fail:0 skip:0 total:6
[   81.467942][  T617] ok 1 clk-gate-register-test
[   81.477887][  T617]     KTAP version 1
[   81.481605][  T617]     # Subtest: clk-gate-test
[   81.481607][  T617]     1..3
[   81.486715][  T617]     ok 1 clk_gate_test_parent_rate
[   81.489938][  T625] clk_unregister: unregistering prepared clock: test_gate
[   81.501985][  T625] clk_unregister: unregistering prepared clock: test_parent
[   81.509082][  T617]     ok 2 clk_gate_test_enable
[   81.509592][  T617]     ok 3 clk_gate_test_disable
[   81.514273][  T617] # clk-gate-test: pass:3 fail:0 skip:0 total:3
[   81.519038][  T617] # Totals: pass:3 fail:0 skip:0 total:3
[   81.525093][  T617] ok 2 clk-gate-test
[   81.534272][  T617]     KTAP version 1
[   81.537994][  T617]     # Subtest: clk-gate-invert-test
[   81.537997][  T617]     1..2
[   81.543646][  T627] clk_unregister: unregistering prepared clock: test_gate
[   81.553473][  T627] clk_unregister: unregistering prepared clock: test_parent
[   81.560568][  T617]     ok 1 clk_gate_test_invert_enable
[   81.561066][  T617]     ok 2 clk_gate_test_invert_disable
[   81.566341][  T617] # clk-gate-invert-test: pass:2 fail:0 skip:0 total:2
[   81.571695][  T617] # Totals: pass:2 fail:0 skip:0 total:2
[   81.578336][  T617] ok 3 clk-gate-invert-test
[   81.588104][  T617]     KTAP version 1
[   81.591826][  T617]     # Subtest: clk-gate-hiword-test
[   81.591829][  T617]     1..2
[   81.597377][  T629] clk_unregister: unregistering prepared clock: test_gate
[   81.607364][  T629] clk_unregister: unregistering prepared clock: test_parent
[   81.614472][  T617]     ok 1 clk_gate_test_hiword_enable
[   81.614987][  T617]     ok 2 clk_gate_test_hiword_disable
[   81.620270][  T617] # clk-gate-hiword-test: pass:2 fail:0 skip:0 total:2
[   81.625629][  T617] # Totals: pass:2 fail:0 skip:0 total:2
[   81.632270][  T617] ok 4 clk-gate-hiword-test
[   81.642073][  T617]     KTAP version 1
[   81.645796][  T617]     # Subtest: clk-gate-is_enabled-test
[   81.645798][  T617]     1..4
[   81.651734][  T617]     ok 1 clk_gate_test_is_enabled
[   81.654866][  T617]     ok 2 clk_gate_test_is_disabled
[   81.660199][  T617]     ok 3 clk_gate_test_is_enabled_inverted
[   81.665624][  T617]     ok 4 clk_gate_test_is_disabled_inverted
[   81.671423][  T617] # clk-gate-is_enabled-test: pass:4 fail:0 skip:0 total:4
[   81.677294][  T617] # Totals: pass:4 fail:0 skip:0 total:4
[   81.684286][  T617] ok 5 clk-gate-is_enabled-test
[   81.737822][  T641]     KTAP version 1
[   81.741540][  T641]     # Subtest: clk-leaf-mux-set-rate-parent
[   81.741543][  T641]     1..1
[   81.748253][  T641]     ok 1 clk_leaf_mux_set_rate_parent_determine_rate
[   81.751119][  T641] ok 1 clk-leaf-mux-set-rate-parent
[   81.762775][  T641]     KTAP version 1
[   81.766498][  T641]     # Subtest: clk-test
[   81.766502][  T641]     1..4
[   81.770991][  T641]     ok 1 clk_test_get_rate
[   81.774516][  T641]     ok 2 clk_test_set_get_rate
[   81.779284][  T641]     ok 3 clk_test_set_set_get_rate
[   81.784257][  T641]     ok 4 clk_test_round_set_get_rate
[   81.789343][  T641] # clk-test: pass:4 fail:0 skip:0 total:4
[   81.794613][  T641] # Totals: pass:4 fail:0 skip:0 total:4
[   81.800234][  T641] ok 2 clk-test
[   81.808994][  T641]     KTAP version 1
[   81.812718][  T641]     # Subtest: clk-multiple-parents-mux-test
[   81.812721][  T641]     1..3
[   81.819246][  T641]     ok 1 clk_test_multiple_parents_mux_get_parent
[   81.822643][  T641]     ok 2 clk_test_multiple_parents_mux_has_parent
[   81.829698][  T641]     ok 3 clk_test_multiple_parents_mux_set_range_set_parent_get_rate # SKIP This needs to be fixed in the core.
[   81.836074][  T641] # clk-multiple-parents-mux-test: pass:2 fail:0 skip:1 total:3
[   81.847794][  T641] # Totals: pass:2 fail:0 skip:1 total:3
[   81.855207][  T641] ok 3 clk-multiple-parents-mux-test
[   81.865764][  T641]     KTAP version 1
[   81.869487][  T641]     # Subtest: clk-mux-notifier
[   81.869491][  T641]     1..1
[   81.878469][  T641]     ok 1 clk_mux_notifier_set_parent_test
[   81.881330][  T641] ok 4 clk-mux-notifier
[   81.891344][  T641]     KTAP version 1
[   81.895065][  T641]     # Subtest: clk-orphan-transparent-multiple-parent-mux-test
[   81.895069][  T641]     1..9
[   81.903098][  T641]     ok 1 clk_test_orphan_transparent_multiple_parent_mux_get_parent


To reproduce:

        git clone https://github.com/intel/lkp-tests.git
        cd lkp-tests
        sudo bin/lkp install job.yaml           # job file is attached in this email
        bin/lkp split-job --compatible job.yaml # generate the yaml file for lkp run
        sudo bin/lkp run generated-yaml-file

        # if come across any failure that blocks the test,
        # please remove ~/.lkp and /lkp dir to run from a clean state.
  

Patch

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 57b83665e5c3..dccd4ea6f692 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -4015,10 +4015,21 @@  static int clk_core_populate_parent_map(struct clk_core *core,
 			ret = clk_cpy_name(&parent->name, parent_names[i],
 					   true);
 		} else if (parent_data) {
+			const char *parent_name;
+
 			parent->hw = parent_data[i].hw;
 			parent->index = parent_data[i].index;
+			parent_name = parent_data[i].fw_name;
+
+			if (!parent_name && parent_data[i].name) {
+				WARN(1, "Empty .fw_name with .name in %s's .parent_data. Using .name for .fw_name declaration.\n",
+				     core->name);
+				parent_name = parent_data[i].name;
+			}
+
 			ret = clk_cpy_name(&parent->fw_name,
-					   parent_data[i].fw_name, false);
+					   parent_name, false);
+
 			if (!ret)
 				ret = clk_cpy_name(&parent->name,
 						   parent_data[i].name,