From patchwork Sun Dec 10 14:39:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 176348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6548572vqy; Sun, 10 Dec 2023 06:40:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGH8beoyDpqY7TGnIWZcEDDi5Iy35FevtYPvAXYnz0A8vtIMk0nVfAue71F8MqFaWrTHisi X-Received: by 2002:a05:6358:5916:b0:16e:29a9:f5af with SMTP id g22-20020a056358591600b0016e29a9f5afmr1614943rwf.27.1702219256660; Sun, 10 Dec 2023 06:40:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702219256; cv=none; d=google.com; s=arc-20160816; b=nflbpqw1IVPV+3ZX0pphAM8V1NbBc+4jD/9Dw4Q3Z9l4+Tl3a6hWWrebqMerZpEWFE bgK42jAQ4wtYQ1NHF1zmPrWdXaRXHWTAfJSpP6x6215aOn+BnSPHSXBrUKiErUkItkoy pWnLlxCY02TZjmyMeM/dEN43kk4ZHDwMG3U23iakJnVRD6YNgZz0U01o3vfHRlTtCQqB fmGDA7w5kX/8iZEFl7ioS1R6rE06xH8zKZ0W9uJIGRluaZ2Pbw5u8abR9MXeIutTn0i1 nj2iunxCbP1rSeVILoLfGB3ERwof6VnF8vO2Dd8nb3VmE4yH/TnFRVYSnrMmKgYfKCZC X7AQ== 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=HVLjVY9mJN6FnT/miwVquh5A22rKCi19EOMtMN09Emg=; fh=aY4p+IxQCHNFbG2VKX+b4inZsek66tdYdHRTsEXnV8s=; b=Yrv13YoxHiu51JDzwQ5dZrdh7G8E5fhZGQk1uxzmQkyfKR+mW28MZyBiL5xbRXZxn/ +jWWLngk3r6rS+REDqEpQl6McyIqZpvuKlPp2w+P/T2JzKgfhNUZ9+Z1yM+7WumwBjLU zDJPMAgSXzImyaiLtIcx33sR0D+PtCofeeLUijSHvPzZ00rGm59m3qu4pEnHA0KtZmAo A+TaMjMIlna83vR7caF9kBo7baHDuczrxKJroL9fOO/4CqYEc4fWeqrjXyMhGyVD9wHG 3Ztcum2GrrYdcEe4vjdPeYVMzvYudroUpPt20MC5tK40JH9b4IBvWtjGjOgKYruK2yEN 6v9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OOnu8ib1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id x6-20020a170902b40600b001d06b5f9af4si4547916plr.441.2023.12.10.06.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 06:40:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OOnu8ib1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id E9E6D808EF58; Sun, 10 Dec 2023 06:40:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232586AbjLJOjg (ORCPT + 99 others); Sun, 10 Dec 2023 09:39:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232582AbjLJOje (ORCPT ); Sun, 10 Dec 2023 09:39:34 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 846B9FA; Sun, 10 Dec 2023 06:39:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702219180; x=1733755180; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=vZQoWNlvUytP34lGQnPLapbQ8i70uET28Hp4eaTV6Iw=; b=OOnu8ib1tlin9o13oQJRhua1AzserXN0dYvncm5sdA2X7M0MR/UuQiRx 3c9T3p/M89QxMB+bdl3XXQ2HElgpEfrv+Mqax2YgDq8N4fHNtJD0NnxJp 9/RTpGGjSqHdajl1/h2t/Zh/qOIBpFcg7jrOZV65zzkllRfKa8n8Nj4Uq QU15GcHU/39sYPegcc2F3LfK+TyaNXhHD7PhhgCLiLb7bePsyRs5/Ak1A AZycUzJ7QRKglaG79h0Wb2T5sRDnTklpR3B6E+hR6QCYPglwWhoS+IkYc rQq7Mm+NYHYhYd8RbrgAi4X1w+NqoRiU4uGne6XrMfkWRAJUk1tu9jC+5 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="374064421" X-IronPort-AV: E=Sophos;i="6.04,265,1695711600"; d="scan'208";a="374064421" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2023 06:39:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="1019911255" X-IronPort-AV: E=Sophos;i="6.04,265,1695711600"; d="scan'208";a="1019911255" Received: from lchen43-mobl2.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.209.172]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2023 06:39:35 -0800 From: Zhang Rui To: tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, mingo@redhat.com, rafael.j.wysocki@intel.com Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, x86@kernel.org, peterz@infradead.org, jsperbeck@google.com, andres@anarazel.de Subject: [PATCH] x86/acpi: Do strict X2APIC ID check only when LAPIC contains enabled CPUs Date: Sun, 10 Dec 2023 22:39:25 +0800 Message-Id: <20231210143925.38722-1-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 10 Dec 2023 06:40:54 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784906259366169448 X-GMAIL-MSGID: 1784906259366169448 Commit 8e9c42d776d6 ("x86/acpi: Ignore invalid x2APIC entries") does strict X2APIC ID check when LAPIC contains valid CPUs. The code assumes LAPIC contains valid CPUs when acpi_table_parse_madt(LAPIC) returns a postive value. This is wrong because acpi_table_parse_madt() return value only represents the number of legal entries parsed. For example, LAPIC entry with LAPIC ID 0xff is counted as a legal entry, but it doesn't describe a valid CPU. And when all LAPIC entries have LAPIC ID 0xff, the return value is positive but LAPIC does not contain any valid CPU. In this case, kernel erroneously does strict X2APIC ID check and loses the CPUs described in X2APIC entries. Fix the problem by doing strict X2APIC ID check less aggressively, say only when LAPIC contains enabled CPUs. Fixes: 8e9c42d776d6 ("x86/acpi: Ignore invalid x2APIC entries") Reported-by: John Sperbeck Closes: https://lore.kernel.org/all/20231122221947.781812-1-jsperbeck@google.com/ Tested-by: John Sperbeck Reported-by: Andres Freund Closes: https://lore.kernel.org/all/20231206065850.hs7k554v6wym7gw5@awork3.anarazel.de/ Tested-by: Andres Freund Signed-off-by: Zhang Rui --- arch/x86/kernel/acpi/boot.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index 1a0dd80d81ac..c6495ebca91a 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -266,6 +266,7 @@ static int __init acpi_parse_lapic(union acpi_subtable_headers * header, const unsigned long end) { struct acpi_madt_local_apic *processor = NULL; + int cpu; processor = (struct acpi_madt_local_apic *)header; @@ -289,9 +290,13 @@ acpi_parse_lapic(union acpi_subtable_headers * header, const unsigned long end) * to not preallocating memory for all NR_CPUS * when we use CPU hotplug. */ - acpi_register_lapic(processor->id, /* APIC ID */ - processor->processor_id, /* ACPI ID */ - processor->lapic_flags & ACPI_MADT_ENABLED); + cpu = acpi_register_lapic(processor->id, /* APIC ID */ + processor->processor_id, /* ACPI ID */ + processor->lapic_flags & ACPI_MADT_ENABLED); + + /* Do strict X2APIC ID check only when LAPIC contains enabled CPUs */ + if (cpu >= 0) + has_lapic_cpus = true; return 0; } @@ -1134,7 +1139,6 @@ static int __init acpi_parse_madt_lapic_entries(void) if (!count) { count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC, acpi_parse_lapic, MAX_LOCAL_APIC); - has_lapic_cpus = count > 0; x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC, acpi_parse_x2apic, MAX_LOCAL_APIC); }