Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1492398rwb; Tue, 29 Nov 2022 14:30:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf7t4pVFsWdEEUwabiK4bp1eyIe8W8qPeWY5CCtNl+X7PYtE+kaE/r+8zZBGzCIG00TcdHKF X-Received: by 2002:a17:906:f6c6:b0:78d:b367:20c1 with SMTP id jo6-20020a170906f6c600b0078db36720c1mr47146905ejb.530.1669761026825; Tue, 29 Nov 2022 14:30:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669761026; cv=none; d=google.com; s=arc-20160816; b=Bnh8nwGps1Gf/ROfPb8ihIlHbh5f6CUR4Wm26pLF1B5+aNc79plZmVKsniGGEIozrn AcxuHK6i0MaCo3wl8Fph2bMy6gB5InmqJu02lIB9J5CSlFxFBx7n6zj9HErZWVVd2Wlt KuU5lrZjd7S77Alc6aso07XUGsFUQPLsTR3NYC88fRH2kzsalhpBAu6Vuz+1Dm1N+LFU ps3jmUQQh+vMSOP5EppOyfaejXCycA8aXveaUg5ilN0P6jOnK8b/AoxLCq7KT3PDXWkz MSxGQBHugjXuSp3g0/QwoXPLHFin32pPE+TEH6s4mir3zyrdkWetOnSmDmLA2p6nOGce kAsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=IVD3U7umaa5f2mOjx5X7KPJ6YQ8eaBe3vZYbgDlLhjQ=; b=IqNUGpYezemWzy4ZAhgC9keeDdYBh9lk7ccH7+AjiUfKwZwkVgmC3Q0kyxNAybNw5h wgjrblZM/f9w2wtRBxGFWBytypSX8Kpbg2tXkJ6rJ95nNE+BLbDBZf2T1wQTZsgjEiPa PXHZqHS/Lf4C7lf48CXu0AEpNjXLJy9IFv+6emXiMP3KS5BwApIN9U3EbfNq/9cHbKYV 8DBJLYWvlVV8WCPWavugFruWHVnrHRpszPNrtCpi1tcH6UEVSGOVCqFRTyCyjxGWVPzA EL9EgDekxXzA3pZvgqITwTr/gQKTcoTYFh+cRhzRTdMnzomIsXFF1jM+q8Lzb9prn7WB sqYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=Qc47TciV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=o2.pl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020a1709064fc500b0078d148daf4bsi14833459ejw.409.2022.11.29.14.30.06; Tue, 29 Nov 2022 14:30:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=Qc47TciV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=o2.pl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236645AbiK2Vu3 (ORCPT + 84 others); Tue, 29 Nov 2022 16:50:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236616AbiK2Vu0 (ORCPT ); Tue, 29 Nov 2022 16:50:26 -0500 Received: from mx-out.tlen.pl (mx-out.tlen.pl [193.222.135.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42A956E548 for ; Tue, 29 Nov 2022 13:50:21 -0800 (PST) Received: (wp-smtpd smtp.tlen.pl 12337 invoked from network); 29 Nov 2022 22:50:18 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=1024a; t=1669758618; bh=IVD3U7umaa5f2mOjx5X7KPJ6YQ8eaBe3vZYbgDlLhjQ=; h=From:To:Cc:Subject; b=Qc47TciVr80fpve617IfPe5eySDEB4VUAlTd0DL3y+17YDHdRDxLhseXmqLBaLCoV zlvNVamTdnDg8MH1F7H4v7z1QgHiuTXMwuXWytofrmBbV6xvz2B/ZKYwltb59nZ+FS CzA22h826hNNSd179GjC4937Q0I9IcB3jg2YoLGg= Received: from aaeq124.neoplus.adsl.tpnet.pl (HELO localhost.localdomain) (mat.jonczyk@o2.pl@[83.4.120.124]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with SMTP for ; 29 Nov 2022 22:50:18 +0100 From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= , Paul Menzel , Robert Elliott , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Johan Hovold , "Maciej W . Rozycki" , Yinghai Lu , Daniel Sneddon Subject: [PATCH] x86/apic: handle no CONFIG_X86_X2APIC on systems with x2APIC enabled by BIOS Date: Tue, 29 Nov 2022 22:50:08 +0100 Message-Id: <20221129215008.7247-1-mat.jonczyk@o2.pl> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-WP-MailID: f0dc8ad877cb05c45d5d1b2524f54152 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 000000A [ARN0] X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A kernel that was compiled without CONFIG_X86_X2APIC was unable to boot on platforms that have x2APIC turned on by BIOS [1]. The kernel was supposed to panic with an approprite error message in validate_x2apic() in arch/x86/kernel/apic/apic.c . However, validate_x2apic() was run too late in the boot cycle, and the kernel tried to initialize the APIC nonetheless. This resulted in an earlier panic in setup_local_APIC() on /* * Double-check whether this APIC is really registered. * This is meaningless in clustered apic mode, so we skip it. */ BUG_ON(!apic->apic_id_registered()); during execution of Call Trace: ? _printk+0x63/0x7e apic_intr_mode_init+0xde/0xfc x86_late_time_init+0x1b/0x2f start_kernel+0x5db/0x69b secondary_startup_64_no_verify+0xe0/0xeb In my experiments, a panic message in setup_local_APIC() was not visible in the graphical console, which resulted in a hang with no indication what has gone wrong. [2] Instead of calling panic(), disable the APIC, which should result in a somewhat working system with the PIC only (and no SMP). This way the user would be able to diagnose the problem more easily. Implementation of this is much simpler then disabling the x2APIC mode only, which may not be possible on newer systems with locked x2APIC. The proper place to disable the APIC in this case is in check_x2apic(), which is called early from setup_arch(). Doing this in __apic_intr_mode_select() is too late, and in my experiments resulted in a broken system with no working PCI interrupts and "failed to register GSI" warnings on the screen. The check_x2apic() function was empty on kernels without CONFIG_X86_X2APIC. Modify arch/x86/include/asm/apic.h to remove the empty inline stub and provide proper declaration irrespective of CONFIG_X86_X2APIC setting. [1] Here I differentiate between two cases: 1. APIC already switched into the x2APIC mode by BIOS, it is in x2APIC mode when kernel starts booting. 2. x2APIC made available by BIOS to the operating system, but is in legacy mode when kernel starts booting. Only in case 1. the kernel did not boot without CONFIG_X86_X2APIC. [2] Tested with CONFIG_FB_EFI and CONFIG_EARLY_PRINTK enabled. Reported-by: Paul Menzel Link: https://lkml.org/lkml/2020/2/21/1627 Reported-by: Robert Elliott (Servers) Link: https://lore.kernel.org/lkml/20220911084711.13694-3-mat.jonczyk@o2.pl/ Signed-off-by: Mateusz Jończyk Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Johan Hovold Cc: Maciej W. Rozycki Cc: Yinghai Lu Cc: Daniel Sneddon --- A separate patch to enable CONFIG_X86_X2APIC by default and update the help text of this option is being worked on. arch/x86/Kconfig | 4 ++-- arch/x86/include/asm/apic.h | 3 +-- arch/x86/kernel/apic/apic.c | 13 ++++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 67745ceab0db..b2c0fce3f257 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -462,8 +462,8 @@ config X86_X2APIC Some Intel systems circa 2022 and later are locked into x2APIC mode and can not fall back to the legacy APIC modes if SGX or TDX are - enabled in the BIOS. They will be unable to boot without enabling - this option. + enabled in the BIOS. They will boot with very reduced functionality + without enabling this option. If you don't know what to do here, say N. diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 3415321c8240..3216da7074ba 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -249,7 +249,6 @@ static inline u64 native_x2apic_icr_read(void) extern int x2apic_mode; extern int x2apic_phys; extern void __init x2apic_set_max_apicid(u32 apicid); -extern void __init check_x2apic(void); extern void x2apic_setup(void); static inline int x2apic_enabled(void) { @@ -258,13 +257,13 @@ static inline int x2apic_enabled(void) #define x2apic_supported() (boot_cpu_has(X86_FEATURE_X2APIC)) #else /* !CONFIG_X86_X2APIC */ -static inline void check_x2apic(void) { } static inline void x2apic_setup(void) { } static inline int x2apic_enabled(void) { return 0; } #define x2apic_mode (0) #define x2apic_supported() (0) #endif /* !CONFIG_X86_X2APIC */ +extern void __init check_x2apic(void); struct irq_data; diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index c6876d3ea4b1..20d9a604da7c 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -1931,16 +1931,19 @@ void __init check_x2apic(void) } } #else /* CONFIG_X86_X2APIC */ -static int __init validate_x2apic(void) +void __init check_x2apic(void) { if (!apic_is_x2apic_enabled()) - return 0; + return; /* - * Checkme: Can we simply turn off x2apic here instead of panic? + * Checkme: Can we simply turn off x2APIC here instead of disabling the APIC? */ - panic("BIOS has enabled x2apic but kernel doesn't support x2apic, please disable x2apic in BIOS.\n"); + pr_err("Kernel does not support x2APIC, please recompile with CONFIG_X86_X2APIC.\n"); + pr_err("Disabling APIC, expect reduced performance and functionality.\n"); + + disable_apic = 1; + setup_clear_cpu_cap(X86_FEATURE_APIC); } -early_initcall(validate_x2apic); static inline void try_to_enable_x2apic(int remap_mode) { } static inline void __x2apic_enable(void) { } base-commit: b7b275e60bcd5f89771e865a8239325f86d9927d -- 2.25.1