Skip to contentSkip to conversation

x86/apic/flat64: Add back the early_param("apic", parse_apic)

PATCH Superseded Dexuan Cui 3 participants 7 messages May 29, 2020 – May 31, 2020

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH 1/1 x86/apic/flat64: Add back the early_param("apic", parse_apic)

parse_apic() allows the user to try a different apic driver than the default one that's automatically chosen. It works for x86_32, but doesn't work for x86_64 becauase it was removed in 2009 for x86_64 by:
commit 7b38725318f4 ("x86: remove subarchitecture support code"), whose changelog doesn't explicitly describe the removal for x86_64.

The patch adds back the functionality for x86_64. The intent is mainly to work around an APIC emulation bug in Hyper-V in the case of kdump:
currently Hyper-V does not honor the disabled state of the local APICs, and all the IOAPIC-based interrupts may not be delivered to the correct virtual CPU, if the logical-mode APIC driver is used (the kdump kernel usually uses the logical-mode APIC driver, since typically only 1 CPU is active). Luckily the kdump issue can be worked around by forcing the kdump kernel to use physical mode, before the fix to Hyper-V becomes widely available.

IMHO the patch is safe because the current default algorithm to choose the apic driver is unchanged; the patch makes a difference only when the user specifies the apic= kernel parameter, e.g. "apic=physical flat".

---
 arch/x86/kernel/apic/apic_flat_64.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
arch/x86/kernel/apic/apic_flat_64.c +26 -1
index 7862b152a052..efbec63bb01f 100644
@@ -23,9 +23,34 @@ static struct apic apic_flat;
 struct apic *apic __ro_after_init = &apic_flat;
 EXPORT_SYMBOL_GPL(apic);
 
+static int cmdline_apic __initdata;
+static int __init parse_apic(char *arg)
+{
+	struct apic **drv;
+
+	if (!arg)
+		return -EINVAL;
+
+	for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
+		if (!strcmp((*drv)->name, arg)) {
+			apic = *drv;
+			cmdline_apic = 1;
+			return 0;
+		}
+	}
+
+	/* Parsed again by __setup for debug/verbose */
+	return 0;
+}
+early_param("apic", parse_apic);
+
+
 static int flat_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
 {
-	return 1;
+	if (!cmdline_apic)
+		return 1;
+
+	return apic == &apic_flat;
 }
 
 /*
Signature · 1 line
2.25.1
#1 lore raw
Quoted 16 lines · Dexuan Cui

parse_apic() allows the user to try a different apic driver than the default one that's automatically chosen. It works for x86_32, but doesn't work for x86_64 becauase it was removed in 2009 for x86_64 by:
commit 7b38725318f4 ("x86: remove subarchitecture support code"), whose changelog doesn't explicitly describe the removal for x86_64.

The patch adds back the functionality for x86_64. The intent is mainly to work around an APIC emulation bug in Hyper-V in the case of kdump:
currently Hyper-V does not honor the disabled state of the local APICs, and all the IOAPIC-based interrupts may not be delivered to the correct virtual CPU, if the logical-mode APIC driver is used (the kdump kernel usually uses the logical-mode APIC driver, since typically only 1 CPU is active). Luckily the kdump issue can be worked around by forcing the kdump kernel to use physical mode, before the fix to Hyper-V becomes widely available.

Quoted 8 lines

IMHO the patch is safe because the current default algorithm to choose the apic driver is unchanged; the patch makes a difference only when the user specifies the apic= kernel parameter, e.g. "apic=physical flat".

---
 arch/x86/kernel/apic/apic_flat_64.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

Hi,
Looks like you will also need to update Documentation/admin-guide/kernel-parameters.txt, where it says:

For X86-32, this can also be used to specify an APIC driver name.

Quoted 41 lines
arch/x86/kernel/apic/apic_flat_64.c +26 -1
index 7862b152a052..efbec63bb01f 100644
@@ -23,9 +23,34 @@ static struct apic apic_flat;
 struct apic *apic __ro_after_init = &apic_flat;
 EXPORT_SYMBOL_GPL(apic);
 
+static int cmdline_apic __initdata;
+static int __init parse_apic(char *arg)
+{
+	struct apic **drv;
+
+	if (!arg)
+		return -EINVAL;
+
+	for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
+		if (!strcmp((*drv)->name, arg)) {
+			apic = *drv;
+			cmdline_apic = 1;
+			return 0;
+		}
+	}
+
+	/* Parsed again by __setup for debug/verbose */
+	return 0;
+}
+early_param("apic", parse_apic);
+
+
 static int flat_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
 {
-	return 1;
+	if (!cmdline_apic)
+		return 1;
+
+	return apic == &apic_flat;
 }
 
 /*
Signature · 1 line
~Randy
author maintainer
#2 lore raw
Quoted 10 lines

From: Randy Dunlap <[email protected]>
Sent: Friday, May 29, 2020 6:33 AM
Hi,
Looks like you will also need to update Documentation/admin-guide/kernel-parameters.txt, where it says:

For X86-32, this can also be used to specify an APIC driver name.
--
~Randy

Hi Randy,
Thanks for you reminder! I just posted a v2 for this with you Cc'd.

Thanks,
-- Dexuan

#3 lore raw
In reply to Dexuan Cui
Thank you for the patch! Perhaps something to improve:

Hi Dexuan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tip/x86/core]
[also build test WARNING on tip/auto-latest v5.7-rc7 next-20200529] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Dexuan-Cui/x86-apic-flat64-Add-back-the-early_param-apic-parse_apic/20200531-065251
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 9cb1fd0efd195590b828b9b865421ad345a4a145
config: x86_64-defconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 2388a096e7865c043e83ece4e26654bd3d1a20d5)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> WARNING: modpost: vmlinux.o(.text+0x55232): Section mismatch in reference from the function flat_acpi_madt_oem_check() to the variable .init.data:disable_timer_pin_1

The function flat_acpi_madt_oem_check() references
the variable __initdata disable_timer_pin_1.
This is often because flat_acpi_madt_oem_check lacks a __initdata annotation or the annotation of disable_timer_pin_1 is wrong.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#4 lore raw
Quoted 21 lines

From: kbuild test robot <[email protected]>
Sent: Saturday, May 30, 2020 9:27 PM
[...]
Hi Dexuan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tip/x86/core]
[also build test WARNING on tip/auto-latest v5.7-rc7 next-20200529] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see
[...]
url: [...]
base: [...]
config: x86_64-defconfig (attached as .config)
compiler: clang version 11.0.0 [...]
reproduce (this is a W=1 build):
[...]
All warnings (new ones prefixed by >>, old ones prefixed by <<):

Quoted 7 lines
Quoted 1 line
Quoted 1 line

WARNING: modpost: vmlinux.o(.text+0x55232): Section mismatch in

reference from the function flat_acpi_madt_oem_check() to the variable .init.data:disable_timer_pin_1
The function flat_acpi_madt_oem_check() references
the variable __initdata disable_timer_pin_1.
This is often because flat_acpi_madt_oem_check lacks a __initdata annotation or the annotation of disable_timer_pin_1 is wrong.

The warning is not accurate because flat_acpi_madt_oem_check() has nothing to do with the variable disable_timer_pin_1.

I just posted a v3 patch to fix the warning by adding the __init tag for flat_acpi_madt_oem_check().

Thanks,
-- Dexuan

#5 lore raw
In reply to Dexuan Cui
Thank you for the patch! Perhaps something to improve:

Hi Dexuan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tip/x86/core]
[also build test WARNING on tip/auto-latest v5.7-rc7 next-20200529] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Dexuan-Cui/x86-apic-flat64-Add-back-the-early_param-apic-parse_apic/20200531-065251
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 9cb1fd0efd195590b828b9b865421ad345a4a145
config: x86_64-rhel (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce (this is a W=1 build):
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> WARNING: modpost: vmlinux.o(.text+0x6a947): Section mismatch in reference from the function flat_acpi_madt_oem_check() to the variable .init.data:_node_to_pnode

The function flat_acpi_madt_oem_check() references
the variable __initdata _node_to_pnode.
This is often because flat_acpi_madt_oem_check lacks a __initdata annotation or the annotation of _node_to_pnode is wrong.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#6 lore raw
Quoted 26 lines

From: kbuild test robot <[email protected]>
Sent: Sunday, May 31, 2020 11:37 AM

Hi Dexuan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tip/x86/core]
[also build test WARNING on tip/auto-latest v5.7-rc7 next-20200529] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see
[...]
url: [...]
base: [...]
config: x86_64-rhel (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce (this is a W=1 build):

        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

Quoted 7 lines
Quoted 1 line
Quoted 1 line

WARNING: modpost: vmlinux.o(.text+0x6a947): Section mismatch in

reference from the function flat_acpi_madt_oem_check() to the variable .init.data:_node_to_pnode
The function flat_acpi_madt_oem_check() references
the variable __initdata _node_to_pnode.
This is often because flat_acpi_madt_oem_check lacks a __initdata annotation or the annotation of _node_to_pnode is wrong.

This is an out-of-date report against v1 of the patch. I posted v3 about two hours ago, which addressed the warning.

Thanks,
Dexuan