Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2005249pxb; Wed, 9 Feb 2022 08:58:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgdezdDOApdJ3W3VC1JONoM2I0l+00YL9OfB9wWlywty5jDSokNSwjSvk7h2ivhykP86Am X-Received: by 2002:a17:902:ccc1:: with SMTP id z1mr3281130ple.107.1644425890050; Wed, 09 Feb 2022 08:58:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1644425890; cv=pass; d=google.com; s=arc-20160816; b=yRIwDy6IXGxqfTClqtrGZlbQ7viVDVMysLPXLVl0TBioyeq3LqslZjFv/YjirnHbpV Y6B9Im+O38DLPncfJt9Jcb2Kz/Lb99SaRh0Uz4zSOejuPUrDPyeXwmbGYbMZoVheBj/D ah8aQ3oeNb7723w+6TYIpaZhfRA9dsPTH8HIRaiOrRECFPnVvE+PTWEqYmDlqN1N1uxR 6DgFbkijFDSRxoZCDHsV2uOPx7Cwq/djWmyr4vPzigE5Z/zC6Nbl1knUHmaO+ecn3DD/ 2glB/IbwWUDkG428JYpCUKz8ViIMz7ZXvC0QT3KDoUpTUSR59H7UPjF73JdjtrPPOJO7 Pdxg== ARC-Message-Signature: i=2; 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=fJ7ONnk0TLdhlVL5b9RWLdTrzo4diA46HHcN4K4CP/c=; b=tt5fa+hao9MGN23bqH6U2wAxHg6e+7XWeE2hiFALvBKW6AYDkGw+hEWQmnbKgoo81X I/M0C9Hxr8MXRS/+i6NGK6JGVJVAPOhRt4GJF/TQ+U5lk65keMGF1yUYSR96k1rr4vZF MZuuZH9nIBVxfTxlwXj5pB8QVZrlWGx3/cac1DmnBEzok1IFfu8n0fwGP2Ozgrbj9ehy 8PXLqpBSypSwaWXCGgG+REi8DlDuLwfnPk7fzWc/PY8yx5Sq1OWCDJkLeoSkYuIrytrp gXmSf9kI9UzUsxj4xBH4K116f5IE+Rje3Q6B5xaFv68yDw/UoIKASdrC+7Ts4mi2Tbq8 T4Pw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=vWQYUqwh; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e3si16107924pgb.68.2022.02.09.08.57.55; Wed, 09 Feb 2022 08:58:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=vWQYUqwh; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235788AbiBIPXE (ORCPT + 99 others); Wed, 9 Feb 2022 10:23:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbiBIPXB (ORCPT ); Wed, 9 Feb 2022 10:23:01 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2064.outbound.protection.outlook.com [40.107.220.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCBD9C05CB86; Wed, 9 Feb 2022 07:23:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CwhiSResrggktMJyjrOvKHOg8VDQppjcaxTMy+DfMm9qmXz/nmLnEWhmGyv4OU3D3bg7s5cz//JWkN5klHKHjZkJXckueqWUEoDajrGbbgoHPljWf3ZdmABiXCe4PW3tg/o3TiOwKL1rNLXa12LCJNciEL5ArrwEOMr55t1fd8yrHrrfh871IFnTVypky7QmZNlj8jC8riJ6l8q1vJfP8mcrQmeBz8SdHvXEV82wmb6dd7PKuEYtyp50jSKIMqMJYbtZKMFFdEX7BdndTA92jybdVetG65YWIwkSh3/Txua2vLh+Bw6IbxRLfQHYw7KwPQyVXCuJnb/Pb7nvNMkDkQ== 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=fJ7ONnk0TLdhlVL5b9RWLdTrzo4diA46HHcN4K4CP/c=; b=kcQpjaFQ494fjkW5/RiTxVHeJ1XjR2U6ZOGVePnwSCRYkK3IVZiOS+u4fgPosn0bjjnFd8FOa6FvOOAuF2DcozEQoBgKfeyUzmWWOnRKlhJQ5USkaDWhKvfgG2kmk5A+RuzsDQTd2pje4SQOLXZji1uIivCHsmJwSt2mqZ7hyYgtfxbrPyN9Qwy+4x45IuNsNNAoEvwiAjVkUYEBmBlOXJMzMHyo96DUFvb8JQTsibZOhLZCCQej+5XRR/sqlYtkj5xsRS40nGdEqfzXKn9MUL8i2g2NLekzZt2wtgiGHSszR5EC8b87BvLg+pwqJKTJXUbHOe0n1pX1Zd0HQw/AcQ== 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=fJ7ONnk0TLdhlVL5b9RWLdTrzo4diA46HHcN4K4CP/c=; b=vWQYUqwhoA1WQIct1gKRGsvYpt8uKq4VM00Sf1ugAog4rK0+pk+p0uy/FQea11L+sZSxrk8vUonbgMa9RS7o7NkYXdDEW0BSYo+VLRQIbEYh7CZbfRPRJxycBVCg8E7hPTz/wvvIhTXakkmVsHlvv28muvEe4XNMbaq4AJsPUQM= Received: from DM5PR04CA0030.namprd04.prod.outlook.com (2603:10b6:3:12b::16) by BL1PR12MB5030.namprd12.prod.outlook.com (2603:10b6:208:313::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Wed, 9 Feb 2022 15:23:03 +0000 Received: from DM6NAM11FT038.eop-nam11.prod.protection.outlook.com (2603:10b6:3:12b:cafe::dd) by DM5PR04CA0030.outlook.office365.com (2603:10b6:3:12b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.16 via Frontend Transport; Wed, 9 Feb 2022 15:23:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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 DM6NAM11FT038.mail.protection.outlook.com (10.13.173.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4975.11 via Frontend Transport; Wed, 9 Feb 2022 15:23:03 +0000 Received: from sp5-759chost.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.18; Wed, 9 Feb 2022 09:23:01 -0600 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v5] KVM: SVM: Allow AVIC support on system w/ physical APIC ID > 255 Date: Wed, 9 Feb 2022 09:20:38 -0600 Message-ID: <20220209152038.12303-1-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d5a7c7e9-41ad-4ea0-cdce-08d9ebe0108e X-MS-TrafficTypeDiagnostic: BL1PR12MB5030:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8y0XKDRfijKlspS7HK9fj06T688etpa7yPyKvIvfdUi5iq+Q2SuPCAjqH8F8EFCyc5OUG4tJzu/aO7ZmUtzJSGjLXA5iFjieU7SwYbh8xcELBfXVddAo+gYda6/42YC/UOjjy+p5I8T8SbIFnAsvvRdqUgL5UD3/qKNRnhvr3meqX09cmIe5rmzHzJ0XDiSs8JwgwRVWuQIDgNVeTWpbWULSdGRHpthi8MIFtYdEJbHpo7FPgLIF0vVvHZgZtijWqsCTsDWDGATQG8DUDHL0xqxfDQW3pvXJKEogYRLlODalkMCRPVreJ+8QvRKunjwQc8H+Y6o/3bzwQ1GRRMqs/tfR8Z/HSTHOKjI3eNRZ3A1d9S+vtxjnUczv4Gz8rUH39ij/SSgpcif9Q/ewt6lTRN1FraqHSUBaZK94/inPPOnHmPCHG0SKTNZmGJAbjf4FI9QQfYMGWBT+Nk7SXDrRpIgfyD4pZu7NDFznuLouudT99KrTdAsOqlKxF25woIJYFp7tc/n/Dl6rnc3FGe6dONRVpYOd6iPqomJElrOmyB6mmxGJKQsa55whYzSls6UEByrNvwm1OqjCRyQK6TcroD9I3QfmEqHe0jUM4io4/dQU6aoP/9tXPTVOx1UaWUj+nTZpVAjRo8LxSgxxEQvkNr/yJa2fXVupynysguaVZwKLr7YcsGGWfEemlbHXCi8t/unqPPjYnS8cOUdpk8eLeQ== 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:(13230001)(4636009)(46966006)(36840700001)(40470700004)(4326008)(70206006)(8676002)(70586007)(81166007)(47076005)(5660300002)(8936002)(54906003)(110136005)(316002)(36756003)(7416002)(2906002)(44832011)(426003)(82310400004)(336012)(7696005)(508600001)(186003)(16526019)(1076003)(2616005)(26005)(356005)(83380400001)(40460700003)(36860700001)(86362001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 15:23:03.1538 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d5a7c7e9-41ad-4ea0-cdce-08d9ebe0108e 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: DM6NAM11FT038.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5030 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 AVIC physical APIC ID table entry contains host physical APIC ID field, which is used by the hardware to keep track of where each vCPU is running. Originally, this field is 8-bit when AVIC was introduced. The AMD64 Architecture Programmer’s Manual Volume 2 revision 3.38 specify the physical APIC ID table entry bit [11:8] as reserved for older generation of AVIC hardware. For newer hardware, this field is used to specify host physical APIC ID larger than 255. Unfortunately, there is no CPUID bit to help determine if AVIC hardware can support 12-bit host physical APIC ID. For older system, since the reserved bits [11:8] is documented as should be zero, it should be safe to increase the host physical ID mask to 12 bits and clear the field when programing new physical APIC ID. Suggested-by: Sean Christopherson Cc: Maxim Levitsky Signed-off-by: Suravee Suthikulpanit --- arch/x86/kvm/svm/avic.c | 8 ++------ arch/x86/kvm/svm/svm.h | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 90364d02f22a..54ad98731181 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" @@ -974,17 +975,12 @@ 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); lockdep_assert_preemption_disabled(); - /* - * 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_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK)) return; /* diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 47ef8f4a9358..cede59cd8999 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -565,7 +565,7 @@ 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_HOST_PHYSICAL_ID_MASK GENMASK_ULL(11, 0) #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) -- 2.25.1