From patchwork Wed Nov 10 10:18:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 12611689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2BAAC433FE for ; Wed, 10 Nov 2021 10:18:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8767F61241 for ; Wed, 10 Nov 2021 10:18:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231307AbhKJKV3 (ORCPT ); Wed, 10 Nov 2021 05:21:29 -0500 Received: from mail-bn8nam12on2057.outbound.protection.outlook.com ([40.107.237.57]:20065 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231208AbhKJKVZ (ORCPT ); Wed, 10 Nov 2021 05:21:25 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lnVt1dyTU/7DTyU6L7Y/lDciN2x+FnNQV+sHrK9flo+J5xxrywl2QSFzUMPotkPqzSc+LmgVOenYzZFcV15nsX5oAtDmYxG+vMPPQYhnDfp4l3TCa8TvSRBQXZ84BamzGlItI6hCq8vtYGxs4eDeDMukv+REDUBt8Way0UYJfRhCPztlcLS5ui4Q+Nbyv4OSEgFuxC81UvBCW7dqShjvfvB8j/lpIMbVW9j0jNwmt+B6fsEbWkHw9o5kLXqGIEAK/euvBseiEqTaVclZvhv6wJxKxdfwCkNUyMMh/8QM8DK8wLMQAlSBTwHmErqxLq8IOky2UsAEtp5AIQI+muJafg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=K7IxYuQVjoP9kkn2N7Up6cVHXCHxz3TCDm3Zz81pnG0=; b=jbWNfahHl4ucd5dvuu4RXRSrttJbs3IbLDwFQ4QefqFKoIJS/P9EZfSNpskM2S0VGuSu+0oHQybeGBNRwQDqJdN3Lx2//CUaitJCmjRgUpk/mkJ1hjTkfDrFH4Js2L9i5bJwv3pywc415D221zlKQChgxAkX40E6Lh4USfHCNYKGu1QMBBQqFmtCt17+cOIEoRUnOYLfLhP0VjqLINO8nNZXIigcd3NLQQbwIVEzNOnWjhc1jT5C9kIRjiAc4JKWwh8UapsX7Wh+1gYOkHuNcqS3w4ZZsKbnLvbUxhLjyWONxxvufPvKiPVF1VV8X+oaU/edhzXdgQ1ZQapwjdGyaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K7IxYuQVjoP9kkn2N7Up6cVHXCHxz3TCDm3Zz81pnG0=; b=kbYMV8DuKMox3NEfeEiwg4pYyvGUQUUYkxilM9jPATkQrNDS/IlJOYNISP68jtWHI7IPtPmkNRyqU1C/JPgYgUkn48Y6IQWKIraQI8Ppn0Ui5xHsuHBAl4nqi2FP61u97t8j6L05ZPWVwxBsZpo3nMqc6RXDkLPvhn51OI9cliI= Received: from DM6PR13CA0017.namprd13.prod.outlook.com (2603:10b6:5:bc::30) by DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.15; Wed, 10 Nov 2021 10:18:35 +0000 Received: from DM6NAM11FT021.eop-nam11.prod.protection.outlook.com (2603:10b6:5:bc:cafe::70) by DM6PR13CA0017.outlook.office365.com (2603:10b6:5:bc::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.7 via Frontend Transport; Wed, 10 Nov 2021 10:18:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT021.mail.protection.outlook.com (10.13.173.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 10:18:35 +0000 Received: from sos-ubuntu2004-quartz01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 10 Nov 2021 04:18:34 -0600 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH 1/2] x86/apic: Add helper function to get maximum physical APIC ID Date: Wed, 10 Nov 2021 04:18:04 -0600 Message-ID: <20211110101805.16343-2-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211110101805.16343-1-suravee.suthikulpanit@amd.com> References: <20211110101805.16343-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd26cec7-92d7-49c0-ec3a-08d9a433748f X-MS-TrafficTypeDiagnostic: DM6PR12MB2714: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1148; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wqNv7RnuEXoXpxRFlht0I2OxZb5AwVZkKAMKGGDmYBglqK2jAxaxH92xnSdlnLxVZxbA9WB8SsahU19xn1f+SW3gDsOp/6Vi1kNDYZpYMkCF2ShA1yDhGg8MGyqYyNjFT8oyg5J/ngiRN51SD0tdZ1Ja4PtCX2xwU5LF1ZI/Ft8sdXsQjy27WqAnW63bvnCL0o/oemIrOjjle1G9OFyU92qr21kNNr1tOBSJu+5C4B7Og+hiWY8ZCjsELJdfjQkz2cO6BKoaXzYIdnyl5El2sYd48APz45VMBQw2Fg0mLMIK4MMHv7EKNarV1BbzOZ/VwQfcgpnY0mTbVjw1lY+c8qTs7jSYG2NkfpIYiCSY387XiQ6T8S1OAeKbV6zAqq+KyQ3KLOvyyJZM+w9vHoGqduT8JmRW8sIB1XvqzENVdir6VtS0BrJAVYKAxcRf4ckTpbEfqH1znEkxDs+SeKt+ranEFQtkrcG1tZAodoUADxTaahVBSoo10ifk6Nn9edBjgKVrH9jdPw/9Abquz7cCt6rXex3N/btYsjNLR4UGse8TSNikrs7IiEHQPwm00Garg7JvL9PrZnLMehzn0N/72N7vu8TLrEIWkWhQv4+NJHqKYLimzdero2Ni8zFegAoaTg/Bucuy3JeEt6v4USBsrbCkPk1KQTmGoXuGRtf2daZb4L0RHcPVTarUW1ROAyUoobmcTh5t3nEeISfa1wXS7hZkCtJ4ebEmnJNsIgKeVKM= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(2616005)(2906002)(8676002)(1076003)(186003)(36756003)(82310400003)(5660300002)(4326008)(7416002)(16526019)(426003)(316002)(8936002)(6666004)(47076005)(36860700001)(336012)(110136005)(81166007)(54906003)(508600001)(86362001)(70586007)(70206006)(356005)(26005)(44832011)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 10:18:35.4782 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd26cec7-92d7-49c0-ec3a-08d9a433748f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT021.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2714 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Export the max_physical_apicid via a helper function since this information is required by AMD SVM AVIC support. Reviewed-by: Tom Lendacky Signed-off-by: Suravee Suthikulpanit --- arch/x86/include/asm/apic.h | 1 + arch/x86/kernel/apic/apic.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 48067af94678..77d9cb2a7e28 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -435,6 +435,7 @@ static inline void apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v)) {} #endif /* CONFIG_X86_LOCAL_APIC */ extern void apic_ack_irq(struct irq_data *data); +extern u32 apic_get_max_phys_apicid(void); static inline void ack_APIC_irq(void) { diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index b70344bf6600..47653d8c05f2 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -2361,6 +2361,12 @@ bool apic_id_is_primary_thread(unsigned int apicid) } #endif +u32 apic_get_max_phys_apicid(void) +{ + return max_physical_apicid; +} +EXPORT_SYMBOL_GPL(apic_get_max_phys_apicid); + /* * Should use this API to allocate logical CPU IDs to keep nr_logical_cpuids * and cpuid_to_apicid[] synchronized. From patchwork Wed Nov 10 10:18:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 12611691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C03F5C4332F for ; Wed, 10 Nov 2021 10:18:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8EF36124C for ; Wed, 10 Nov 2021 10:18:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231215AbhKJKVb (ORCPT ); Wed, 10 Nov 2021 05:21:31 -0500 Received: from mail-co1nam11on2073.outbound.protection.outlook.com ([40.107.220.73]:61701 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231209AbhKJKV1 (ORCPT ); Wed, 10 Nov 2021 05:21:27 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UW9MugQ+GUYdfdjf5yYIJGfpPwihrQy43QZ49XOTtAXZYmg6Sj8FVDyRCOf10l7Zuj0S0HmNU6vk+JLl6ooNrD6USWUk67SSP8Z0/MWDW/Yls3tdQFabwCBCWGavonNM7tFeajH/dmaJaO1RaA3xbIPzBU7DErIGIH2gpWLZtSFsWk9iuesBgLwCDk5dRDWXFJ1YEZblFAHYda64a1z3wQmwIjZ+/G4Pz+EE1bUpvattFhsL3aQyzKgpjSjlOYWtaXstwZVfOjv0bYk9Mwc8ZAiEXKFO1vbVnE+pGdfFNvxUg6Y6K1LcR97hLqphnTZzpT67MuLUswmS37UonTSuvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sN3KTU2T3+BSLdubD5iCle52NOu4cmjSf5Z5AGhMixQ=; b=DDHF8RwDvN/fpZobLSAtuc0eC1Sigyvjce4Kiu4xo3EgoEYK1QCbo2KPHqKBjG5dj4sXiA8af03FdpdDk7WMKyyLrhltAViGxh7QbmuH+asDoJQcGhPHlJjm3k5QlBf9FPdDIwh2VuYn+jygWNID+UQWSG6dj5yw6K/FoeqvoO+/81jlxuT7SDBNnuZy97putpmPxtBMouYR5SV9uL2NYeERt+nLP+cmj5UBl3i8gGi7x40FmkIjwge5mSdAiLPcZsJcTU/EaLPqa3tGtjgXTdsPLODrUrEQFXjDZ8qepOxiKEIaYMk0qM+41E/znD7rlk02GImEn23wPS9rvUq40Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sN3KTU2T3+BSLdubD5iCle52NOu4cmjSf5Z5AGhMixQ=; b=qGU7TzOXDAxHRWUGgZi8kINTTz6cQmbD5dUtsF8Mr/7qPvzsacN3FqKs7m6oawcGbxiMMafbbs3OPERbMqD/dAOxAyccl4HwgqVEXiFhjmZwo3EwCSWY3ai0XpofgpG0lLyxtEK0+haVB+nQjhfrsEzYHb52iUVouvlGc5O/zd0= Received: from DM6PR14CA0043.namprd14.prod.outlook.com (2603:10b6:5:18f::20) by SJ0PR12MB5405.namprd12.prod.outlook.com (2603:10b6:a03:3af::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.15; Wed, 10 Nov 2021 10:18:36 +0000 Received: from DM6NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:5:18f:cafe::ae) by DM6PR14CA0043.outlook.office365.com (2603:10b6:5:18f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Wed, 10 Nov 2021 10:18:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT010.mail.protection.outlook.com (10.13.172.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 10:18:36 +0000 Received: from sos-ubuntu2004-quartz01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 10 Nov 2021 04:18:35 -0600 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH 2/2] KVM: SVM: Extend host physical APIC ID field to support more than 8-bit Date: Wed, 10 Nov 2021 04:18:05 -0600 Message-ID: <20211110101805.16343-3-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211110101805.16343-1-suravee.suthikulpanit@amd.com> References: <20211110101805.16343-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6b4dfdbd-ea52-48be-b4bc-08d9a4337523 X-MS-TrafficTypeDiagnostic: SJ0PR12MB5405: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 99Zz3j+GREiMM8R+5+red5bd+hQQSeClHVRk29uUK4nknsZE0cLbSvZe4qXe5vbsFl17O6ydfPZUry/Dtv2aFkAByuPCwN5Uq2EckcsSlzlYRav2fXriEQO+08THMcQJL4vcUmKB0RBMRyTPfTJEogT/PI/VHDKaVZWO2YodkG30YkfFaoyXIP17mbq1bYDOqxRNycLqgLT5Vj+4p0jHtJiispCQzntNA9vwPqiW1tBrk0Md5t/iDeFI690HyU6g10t6LBy73+Vf9q+ld2Go2Wf3KBUOrt0oyPogfg9W/3Dz5Fl17vVIQVs3G1m1w9S/kIu0xUFT0HGPNlfYjmmj2lOtBEgxdv7aKXbDGRJt+jUPH+thjWNrXFtbtWeL4sf1Cjczu8ErpbO29td9FT0Q03JDBHFIEBqmpuvzLI6a81/kzxv61sgiaCoGGsZ90UaGKlL4JTA/J2uHGVWpk1sNESe6NB0mx4FrOdudKMzMtT9cV91FE1Z7ZOzRYCnetVQqcvf+vCPkrUvOkTydLlDIZlLvawl45brtsXmipA4dn4RVuuZWUU/XAdpWYLdQ8i+hoveYi7hX9uX7q4CuxXs3okP/NCzJvydi/lG3rRpKeu56Fd+wRPLtbtIoD0Iko4DWkiwd+UrYG/6/VjjF4OOiBpG7w6LR7llcxgd91vh7gq1cUYcZKtae4Bhn6SpgF4puqaHKZ+tSHSdPc+ooAsHC8/Y6hpflvv4vSOQD/RchuXM= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(356005)(186003)(70586007)(1076003)(5660300002)(16526019)(83380400001)(26005)(86362001)(36860700001)(47076005)(2906002)(8936002)(44832011)(2616005)(70206006)(36756003)(316002)(7416002)(7696005)(82310400003)(336012)(426003)(8676002)(54906003)(6666004)(110136005)(81166007)(4326008)(508600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 10:18:36.4198 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6b4dfdbd-ea52-48be-b4bc-08d9a4337523 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5405 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The AVIC physical APIC ID table entry contains the host physical APIC ID field, which the hardware uses to keep track of where each vCPU is running. Originally, the field is an 8-bit value, which can only support physical APIC ID up to 255. To support system with larger APIC ID, the AVIC hardware extends this field to support up to the largest possible physical APIC ID available on the system. Therefore, replace the hard-coded mask value with the value calculated from the maximum possible physical APIC ID in the system. Reviewed-by: Tom Lendacky Signed-off-by: Suravee Suthikulpanit --- arch/x86/kvm/svm/avic.c | 53 ++++++++++++++++++++++++++++++++++------- arch/x86/kvm/svm/svm.c | 6 +++++ arch/x86/kvm/svm/svm.h | 2 +- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 8052d92069e0..0b073f63dabd 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -19,6 +19,7 @@ #include #include +#include #include #include "trace.h" @@ -63,6 +64,7 @@ static DEFINE_HASHTABLE(svm_vm_data_hash, SVM_VM_DATA_HASH_BITS); static u32 next_vm_id = 0; static bool next_vm_id_wrapped = 0; +static u64 avic_host_physical_id_mask; static DEFINE_SPINLOCK(svm_vm_data_hash_lock); /* @@ -133,6 +135,46 @@ void avic_vm_destroy(struct kvm *kvm) spin_unlock_irqrestore(&svm_vm_data_hash_lock, flags); } +int avic_init_host_physical_apicid_mask(void) +{ + unsigned int eax, ebx, ecx, edx; + u32 level_type, core_mask_width, max_phys_mask_width; + + /* + * Calculate minimum number of bits required to represent + * host physical APIC ID for each processor (level type 2) + * using CPUID leaf 0xb sub-leaf 0x1. + */ + cpuid_count(0xb, 0x1, &eax, &ebx, &ecx, &edx); + level_type = (ecx >> 8) & 0xff; + + /* + * If level-type 2 (i.e. processor type) not available, + * or host is in xAPIC mode, default to only 8-bit mask. + */ + if (level_type != 2 || !x2apic_mode) { + avic_host_physical_id_mask = 0xffULL; + goto out; + } + + core_mask_width = eax & 0xF; + + max_phys_mask_width = get_count_order(apic_get_max_phys_apicid()); + + /* + * Sanity check to ensure core_mask_width for a processor does not + * exceed the calculated mask. + */ + if (WARN_ON(core_mask_width > max_phys_mask_width)) + return -EINVAL; + + avic_host_physical_id_mask = BIT(max_phys_mask_width) - 1; +out: + pr_debug("Using AVIC host physical APIC ID mask %#0llx\n", + avic_host_physical_id_mask); + return 0; +} + int avic_vm_init(struct kvm *kvm) { unsigned long flags; @@ -943,22 +985,17 @@ avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int cpu, bool r) void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { u64 entry; - /* ID = 0xff (broadcast), ID > 0xff (reserved) */ int h_physical_id = kvm_cpu_get_apicid(cpu); struct vcpu_svm *svm = to_svm(vcpu); - /* - * Since the host physical APIC id is 8 bits, - * we can support host APIC ID upto 255. - */ - if (WARN_ON(h_physical_id > AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK)) + if (WARN_ON(h_physical_id > avic_host_physical_id_mask)) return; entry = READ_ONCE(*(svm->avic_physical_id_cache)); WARN_ON(entry & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK); - entry &= ~AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK; - entry |= (h_physical_id & AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK); + entry &= ~avic_host_physical_id_mask; + entry |= h_physical_id; entry &= ~AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK; if (svm->avic_is_running) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 989685098b3e..0b066bb5149d 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1031,6 +1031,12 @@ static __init int svm_hardware_setup(void) nrips = false; } + if (avic) { + r = avic_init_host_physical_apicid_mask(); + if (r) + avic = false; + } + enable_apicv = avic = avic && npt_enabled && boot_cpu_has(X86_FEATURE_AVIC); if (enable_apicv) { diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 5d30db599e10..e215092d0411 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -497,7 +497,6 @@ extern struct kvm_x86_nested_ops svm_nested_ops; #define AVIC_LOGICAL_ID_ENTRY_VALID_BIT 31 #define AVIC_LOGICAL_ID_ENTRY_VALID_MASK (1 << 31) -#define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK (0xFFULL) #define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK (0xFFFFFFFFFFULL << 12) #define AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK (1ULL << 62) #define AVIC_PHYSICAL_ID_ENTRY_VALID_MASK (1ULL << 63) @@ -525,6 +524,7 @@ int avic_init_vcpu(struct vcpu_svm *svm); void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu); void avic_vcpu_put(struct kvm_vcpu *vcpu); void avic_post_state_restore(struct kvm_vcpu *vcpu); +int avic_init_host_physical_apicid_mask(void); void svm_set_virtual_apic_mode(struct kvm_vcpu *vcpu); void svm_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu); bool svm_check_apicv_inhibit_reasons(ulong bit);