From owner-dev-commits-src-main@freebsd.org Thu Jun 3 19:47:39 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C177B640015; Thu, 3 Jun 2021 19:47:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FwxJC4ssKz4jM9; Thu, 3 Jun 2021 19:47:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 81C777C27; Thu, 3 Jun 2021 19:47:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 153JldVp021836; Thu, 3 Jun 2021 19:47:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 153JldxH021835; Thu, 3 Jun 2021 19:47:39 GMT (envelope-from git) Date: Thu, 3 Jun 2021 19:47:39 GMT Message-Id: <202106031947.153JldxH021835@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: e9e00cc0c987 - main - madt_setup_local: extract special case checks into a helper MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e9e00cc0c98738f0ce7bface221c920c36a1356e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2021 19:47:39 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=e9e00cc0c98738f0ce7bface221c920c36a1356e commit e9e00cc0c98738f0ce7bface221c920c36a1356e Author: Konstantin Belousov AuthorDate: 2021-06-02 22:27:32 +0000 Commit: Konstantin Belousov CommitDate: 2021-06-03 19:47:31 +0000 madt_setup_local: extract special case checks into a helper Reviewed by: markj Tested by: David Sebek Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D30624 --- sys/x86/acpica/madt.c | 114 ++++++++++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/sys/x86/acpica/madt.c b/sys/x86/acpica/madt.c index 035a618f68a3..e041296d4ca5 100644 --- a/sys/x86/acpica/madt.c +++ b/sys/x86/acpica/madt.c @@ -134,70 +134,84 @@ static const char *x2apic_sandy_dis[] = { }; /* - * Initialize the local APIC on the BSP. + * Automatically detect several configurations where x2APIC mode is + * known to cause troubles. User can override the setting with + * hw.x2apic_enable tunable. */ -static int -madt_setup_local(void) +static const char * +madt_x2apic_disable_reason(void) { ACPI_TABLE_DMAR *dmartbl; vm_paddr_t dmartbl_physaddr; const char *reason; char *hw_vendor; u_int p[4]; - int i, user_x2apic; - bool bios_x2apic; + int i; - if ((cpu_feature2 & CPUID2_X2APIC) != 0) { - reason = NULL; + reason = NULL; + dmartbl_physaddr = acpi_find_table(ACPI_SIG_DMAR); + if (dmartbl_physaddr != 0) { + dmartbl = acpi_map_table(dmartbl_physaddr, ACPI_SIG_DMAR); + if ((dmartbl->Flags & ACPI_DMAR_X2APIC_OPT_OUT) != 0) + reason = "by DMAR table"; + acpi_unmap_table(dmartbl); + if (reason != NULL) + return (reason); + } + + if (vm_guest == VM_GUEST_VMWARE) { + vmware_hvcall(VMW_HVCMD_GETVCPU_INFO, p); + if ((p[0] & VMW_VCPUINFO_VCPU_RESERVED) != 0 || + (p[0] & VMW_VCPUINFO_LEGACY_X2APIC) == 0) + return ("inside VMWare without intr redirection"); + } + + if (vm_guest == VM_GUEST_XEN) + return ("due to running under XEN"); + + if (vm_guest == VM_GUEST_NO && + CPUID_TO_FAMILY(cpu_id) == 0x6 && + CPUID_TO_MODEL(cpu_id) == 0x2a) { + hw_vendor = kern_getenv("smbios.planar.maker"); /* - * Automatically detect several configurations where - * x2APIC mode is known to cause troubles. User can - * override the setting with hw.x2apic_enable tunable. + * It seems that some SandyBridge-based notebook + * BIOSes have a bug which prevents booting AP in + * x2APIC mode. Since the only way to detect mobile + * CPU is to check northbridge pci id, which cannot be + * done that early, disable x2APIC for all such + * machines. */ - dmartbl_physaddr = acpi_find_table(ACPI_SIG_DMAR); - if (dmartbl_physaddr != 0) { - dmartbl = acpi_map_table(dmartbl_physaddr, - ACPI_SIG_DMAR); - if ((dmartbl->Flags & ACPI_DMAR_X2APIC_OPT_OUT) != 0) - reason = "by DMAR table"; - acpi_unmap_table(dmartbl); - } - if (reason != NULL) { - /* Already disabled */ - } else if (vm_guest == VM_GUEST_VMWARE) { - vmware_hvcall(VMW_HVCMD_GETVCPU_INFO, p); - if ((p[0] & VMW_VCPUINFO_VCPU_RESERVED) != 0 || - (p[0] & VMW_VCPUINFO_LEGACY_X2APIC) == 0) - reason = - "inside VMWare without intr redirection"; - } else if (vm_guest == VM_GUEST_XEN) { - reason = "due to running under XEN"; - } else if (vm_guest == VM_GUEST_NO && - CPUID_TO_FAMILY(cpu_id) == 0x6 && - CPUID_TO_MODEL(cpu_id) == 0x2a) { - hw_vendor = kern_getenv("smbios.planar.maker"); - /* - * It seems that some SandyBridge-based - * notebook BIOSes have a bug which prevents - * booting AP in x2APIC mode. Since the only - * way to detect mobile CPU is to check - * northbridge pci id, which cannot be done - * that early, disable x2APIC for all such - * machines. - */ - if (hw_vendor != NULL) { - for (i = 0; i < nitems(x2apic_sandy_dis); i++) { - if (strcmp(hw_vendor, - x2apic_sandy_dis[i]) == 0) { - reason = - "for a suspected SandyBridge BIOS bug"; - break; - } + if (hw_vendor != NULL) { + for (i = 0; i < nitems(x2apic_sandy_dis); i++) { + if (strcmp(hw_vendor, x2apic_sandy_dis[i]) == + 0) { + reason = + "for a suspected SandyBridge BIOS bug"; + break; } - freeenv(hw_vendor); } + freeenv(hw_vendor); } + if (reason != NULL) + return (reason); + } + + return (NULL); +} + +/* + * Initialize the local APIC on the BSP. + */ +static int +madt_setup_local(void) +{ + const char *reason; + int user_x2apic; + bool bios_x2apic; + + if ((cpu_feature2 & CPUID2_X2APIC) != 0) { + reason = madt_x2apic_disable_reason(); bios_x2apic = lapic_is_x2apic(); if (reason != NULL && bios_x2apic) { if (bootverbose)