x86: Make XDBC work
cover x86: Make XDBC work
Hi!
These are the patches I needed to make XDBC go on my tigerlake NUC.
PATCH 1/3 x86/tsc: Be consistent about use_tsc_delay()
Currently loops_per_jiffy is set in tsc_early_init(), but then don't switch to delay_tsc, with the result that delay_loop is used with loops_per_jiffy set for delay_tsc.
Then in (late) tsc_init() lpj_fine is set (which is mostly unused) and after which use_tsc_delay() is finally called.
Move both loops_per_jiffy and use_tsc_delay() into tsc_enable_sched_clock() which is called the moment tsc_khz is determined, be it early or late. Keeping the lot consistent.
--- arch/x86/kernel/tsc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/tsc.c +3 -3
@@ -1487,6 +1487,9 @@ static unsigned long __init get_loops_pestatic void __init tsc_enable_sched_clock (void ) { + loops_per_jiffy =get_loops_per_jiffy (); +use_tsc_delay (); +/* Sanitize TSC ADJUST before cyc2ns gets initialized */ tsc_store_and_check_tsc_adjust (true);cyc2ns_init_boot_cpu ();
@@ -1502,8 +1505,6 @@ void __init tsc_early_init(void)return ;if (!determine_cpu_tsc_frequencies (true))return ; - loops_per_jiffy =get_loops_per_jiffy (); -tsc_enable_sched_clock (); }
@@ -1537,7 +1538,6 @@ void __init tsc_init(void)enable_sched_clock_irqtime (); lpj_fine =get_loops_per_jiffy (); -use_tsc_delay ();check_system_tsc_reliable ();
PATCH 2/3 usb: early: xhci-dbc: Remove duplicate keep parsing
In reply to Peter ZijlstraThe generic earlyprintk= parsing already parses the optional ",keep", no need to duplicate that in the xdbc driver.
--- arch/x86/kernel/early_printk.c | 2 +- drivers/usb/early/xhci-dbc.c | 5 ++--- include/linux/usb/xhci-dbgp.h | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-)
arch/x86/kernel/early_printk.c +1 -1
@@ -387,7 +387,7 @@ static int __init setup_early_printk(cha#endif #ifdef CONFIG_EARLY_PRINTK_USB_XDBC if (!strncmp (buf,"xdbc" ,4 )) -early_xdbc_parse_parameter (buf +4 ); +early_xdbc_parse_parameter (buf +4 , keep);#endif buf++;
drivers/usb/early/xhci-dbc.c +2 -3
@@ -599,7 +599,7 @@ static int __init xdbc_early_setup(void)return 0 ; } -int __init early_xdbc_parse_parameter (char *s) +int __init early_xdbc_parse_parameter (char *s,int keep_early) {unsigned long dbgp_num =0 ;u32 bus, dev, func, offset;
@@ -608,8 +608,7 @@ int __init early_xdbc_parse_parameter(chif (!early_pci_allowed ())return -EPERM ; -if (strstr (s,"keep" )) - early_console_keep = true; + early_console_keep = keep_early;if (xdbc.xdbc_reg)return 0 ;
include/linux/usb/xhci-dbgp.h +1 -1
@@ -15,7 +15,7 @@#define __LINUX_XHCI_DBGP_H#ifdef CONFIG_EARLY_PRINTK_USB_XDBC -int __init early_xdbc_parse_parameter (char *s); +int __init early_xdbc_parse_parameter (char *s,int keep_early);int __init early_xdbc_setup_hardware (void );void __init early_xdbc_register_console (void );#else
PATCH 3/3 usb: early: xhci-dbc: Fix xdbc number parsing
In reply to Peter Zijlstrakstrtoul() assumes the string contains the number only and is \0 terminated, this is not the case, as such things like:
earlyprintk=xdbc1,keep
go completely sideways. Use simple_strtoul() instead.
--- drivers/usb/early/xhci-dbc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/early/xhci-dbc.c +6 -2
@@ -603,6 +603,7 @@ int __init early_xdbc_parse_parameter(ch {unsigned long dbgp_num =0 ;u32 bus, dev, func, offset; +char *e;int ret;if (!early_pci_allowed ())
@@ -613,8 +614,11 @@ int __init early_xdbc_parse_parameter(chif (xdbc.xdbc_reg)return 0 ; -if (*s &&kstrtoul (s,0 , &dbgp_num)) - dbgp_num =0 ; +if (*s) { + dbgp_num =simple_strtoul (s, &e,10 ); +if (s == e) + dbgp_num =0 ; + }pr_notice ("dbgp_num: %lu\n" , dbgp_num);
Re: [PATCH 3/3] usb: early: xhci-dbc: Fix xdbc number parsing
Quoted 23 lines · Peter Zijlstra
kstrtoul()assumes the string contains the number only and is \0 terminated, this is not the case, as such things like:earlyprintk=xdbc1,keep
go completely sideways. Use
simple_strtoul()instead.Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- drivers/usb/early/xhci-dbc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/usb/early/xhci-dbc.c +1
-0@@ -603,6 +603,7 @@ int __init early_xdbc_parse_parameter(ch {unsigned long dbgp_num =0 ;u32 bus, dev, func, offset; +char *e;int ret;if (!early_pci_allowed ())
drivers/usb/early/xhci-dbc.c int __init early_xdbc_parse_parameter(ch · line 617
Quoted 6 lines
drivers/usb/early/xhci-dbc.c +1
-2@@ -613,8 +614,11 @@ int __init early_xdbc_parse_parameter(chif (xdbc.xdbc_reg)return 0 ; -if (*s &&kstrtoul (s,0 , &dbgp_num)) - dbgp_num =0 ; +if (*s) {
Do you think we need a code comment here stating something like
"use deprecated simple_strtoul() as kstrtoul can't handle characters after the number"
drivers/usb/early/xhci-dbc.c int __init early_xdbc_parse_parameter(ch · line 622
Quoted 5 lines
drivers/usb/early/xhci-dbc.c +4
-0+ dbgp_num =simple_strtoul (s, &e,10 ); +if (s == e) + dbgp_num =0 ; + }
If not then PATCH 2/3 and 3/3 looks good to me
I don't know much about PATCH 1/3, the tsc change, but it didn't cause any issues for me either.
Thanks
-Mathias
Hi Peter,
Quoted 4 lines · Peter Zijlstra
Hi!
These are the patches I needed to make XDBC go on my tigerlake NUC.
I finally tested these patches (in mainline).
It's working well for me. Thanks.
Signature · 1 line
~Randy