From patchwork Fri Jan 29 00:43:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 12054811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69159C433DB for ; Fri, 29 Jan 2021 00:46:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2988264DEC for ; Fri, 29 Jan 2021 00:46:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231604AbhA2AqC (ORCPT ); Thu, 28 Jan 2021 19:46:02 -0500 Received: from mail-dm6nam11on2040.outbound.protection.outlook.com ([40.107.223.40]:41665 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231459AbhA2Aos (ORCPT ); Thu, 28 Jan 2021 19:44:48 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TKq6Vka/tWULRoKEe/S6DQG5AgkBeemdA6TxOI2Y6rBHB/LW826etPHHCrJhDUYN1Oe9mjisX9Ks5Dwm4NTpGUfqpbHE6EqsdqXs10E7zztYInAuIMCcnTeCF0cVMNHleG+RjP6B9UP7wF+r9s9ZpIeCjcku8+xoB6Dgo0IAA/HvNrdzyEhOlwbIgrvtFb5EmWgWcd6OZYgGbrlGsWiduH5IwQDGRBQAPuwhIfWVDRbY8xp5m2807Rc3BUkzrMOOhsLs76e3nsH/EQrbz5PehrTqmg+N9iYgpcyfsvcjlBuNo8u8d1pqr5EGeAwiDUVEG2yNbX+p7dY6EviV9wmI0w== 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-SenderADCheck; bh=CF4J1hbbttjCvzB0KcY0I9jxXx45BP3e7FK7pX8dQ8Q=; b=BFB2HfBMAGQUBBSkPimiOcSl6T+fp/ERYjjHh8hNoAkLOh20GjKZXTzOF8X5PYlPFV9TjVpULLR1CJtbXPi3hDQCZ4I72p+La5eXVKKcFX2OQT/Y2X4riSftIYyZ4uncqTDRlB6pZZEtoZ5sn+bPIbDOGWiJv5DPR+pMUQ7zU7ToYdZfZdNBJ80ZcLohpR+di2oEFQIKpTedc4PM8H65Dj+xfpvsX5RVgpPPj9H02PE7EdgAyDPBTjCb/yZIJOIUK8XKrn9RvE649g1akyMoXYX6+BDE48IDNEzP6eR1BpFPJdi9tlmTQAx/zFYDCAEvpCpVRfqnU2mgtQO8HmUnjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=CF4J1hbbttjCvzB0KcY0I9jxXx45BP3e7FK7pX8dQ8Q=; b=V5P7WmaDwYwn9qNupGJpOVVaOJtpW4QONnSpUSvrQh18Z7t7nyhZ81HjX0MBFC3xdrbhjevQSdrkgTFdcmvZFsTAjMNtHzh8BMhJO1AcBo+2RREVKxEijKUdG9vBBYSfV1GpgYQwaALYwomwfe+OKMrPrN/86IxST5ameSZia/E= Authentication-Results: tencent.com; dkim=none (message not signed) header.d=none;tencent.com; dmarc=none action=none header.from=amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17; Fri, 29 Jan 2021 00:43:24 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::8c0e:9a64:673b:4fff]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::8c0e:9a64:673b:4fff%5]) with mapi id 15.20.3805.019; Fri, 29 Jan 2021 00:43:24 +0000 Subject: [PATCH v4 1/2] x86/cpufeatures: Add the Virtual SPEC_CTRL feature From: Babu Moger To: pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de Cc: fenghua.yu@intel.com, tony.luck@intel.com, wanpengli@tencent.com, kvm@vger.kernel.org, thomas.lendacky@amd.com, peterz@infradead.org, seanjc@google.com, joro@8bytes.org, x86@kernel.org, kyung.min.park@intel.com, linux-kernel@vger.kernel.org, krish.sadhukhan@oracle.com, hpa@zytor.com, mgross@linux.intel.com, vkuznets@redhat.com, kim.phillips@amd.com, wei.huang2@amd.com, jmattson@google.com Date: Thu, 28 Jan 2021 18:43:22 -0600 Message-ID: <161188100272.28787.4097272856384825024.stgit@bmoger-ubuntu> In-Reply-To: <161188083424.28787.9510741752032213167.stgit@bmoger-ubuntu> References: <161188083424.28787.9510741752032213167.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR13CA0236.namprd13.prod.outlook.com (2603:10b6:806:25::31) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by SA9PR13CA0236.namprd13.prod.outlook.com (2603:10b6:806:25::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.8 via Frontend Transport; Fri, 29 Jan 2021 00:43:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: de15430a-e38a-48c1-bd4f-08d8c3eee278 X-MS-TrafficTypeDiagnostic: SN1PR12MB2560: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1388; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w/gjyunOwikS2pHW0YuWutY7hq++DPgcetead33dAtVgSGHt903e/Rmt49qEv3bbXY3tNMWbkwA+Wzx7EsYLxqLpV/ptrbIEpWzLGs7/JD8Ralby8koqSBim5Xlxm4xnDdFEVyusl4o+1MqAerrmXSSsRtpw2fJZC29ZPuydABpwI/5ZCnW2IB/iajtl2UaueZ6W4qMctprDuHuq5WvXfedkdAIh5Yi3xmfdApGWfPfoJf4CRMW+rQTfg2GMWdyD3cKio1vNap1+Cd3ba0FQQ3aC5vLm/seM+9TWShp21RqE1CPnw75/jvZV6b9EFfaHJOvc6IhVs2VUgMTAuxq0c4Y/1A5gB15+uKBB2eLbOGAGE50eeRtiNrXLo/VQP5q2rEheAKWomjE+f3/ekjvRwjkttM9kAIosHehuyn3kqjUwdyEjAFAgR6D70FV65HaWp2858Cae/HXwgt+qn0PVH9H3XDHaVohHrdVk/n6VR8wptZhvizKcheOS/2zy+PGg3Y9npJXWQVikmKsn+wBMDw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN1PR12MB2560.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(7916004)(396003)(39860400002)(136003)(366004)(346002)(376002)(956004)(16576012)(52116002)(7416002)(8936002)(8676002)(316002)(86362001)(103116003)(44832011)(16526019)(186003)(33716001)(4326008)(478600001)(6486002)(9686003)(66476007)(66556008)(5660300002)(26005)(2906002)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?vyjDI32oYpxnmwtUyivdqnNFP4w0HF?= =?utf-8?q?xr3WCS5NUZlM3xPlI7SBCzH9JypTOkQykTgMVw6L0FMxwU14ck1J6Jt6FEoyiBNaD?= =?utf-8?q?LIulIK+Sivh0078coqTrXXrUMx1dPfIcKW0WDxHijJ+htGnJZb97sgDlZNnU1YlQv?= =?utf-8?q?/cJ7gEwwVekllaih3S9BllF7hcNboaJC7Gy3GWjEf+paJ8iRnLU1YWRG3bLkEf1eA?= =?utf-8?q?u84XOqcicKOWgytwoTE6sP4olw2SO39CaSFe1X/vw1ZLk761m3uLSkHs0hiL42EpQ?= =?utf-8?q?8RXAe8+hXxvU/EU8kL4XRh9REoSqGSEq9WndgPAQQjP9m0GJWFG0tr/tOBgJ2yuEb?= =?utf-8?q?TjYQLXxKC931koJJHMhfm8rQUpldn2+51TWRzXslxnJQA6JMnqNy/KSd990ciBxP6?= =?utf-8?q?S9nT9eB95HKsSGe/S5sOOMUxiJ2pkG+0vOLAjeWDmGtVZSvc3YTiWgVW3HrefRMH8?= =?utf-8?q?Qx2KiEsfe2fJFslUY/MQDowITCcUbPHtpZKn/ubqiXPjYfFJcx2ydnVK3ToC6FvCU?= =?utf-8?q?MpwHr25oT138c6qHC7CbzSfeD1KWPtVUaezon2XmgQ7/Xi/R9BDwhTan65zK/JxTT?= =?utf-8?q?leHlwc03SuTQoue71nkyL6X/IE+nq6U3jBQXDduEb2H6AewE1Nw14JzenhtHXqO/A?= =?utf-8?q?xGgblWm9O8lblWNdvYnJFfkYMs3BrlRLc4xBdUd6ZezRqgQDi/6oJNlZn1IZvHHmj?= =?utf-8?q?jZQmgobsnJZEPY0dqlSlmfwtyjeBwyqXrjMRlafh6k+Uo/pziSC52uLs5TV+3bPNI?= =?utf-8?q?zQzg2FmvY8R/1wnk/2SXn7Bu1nPwge5IxuLgXb/frnfqvvAHVnGhvShqpdNjVtLi4?= =?utf-8?q?hZm/9xKQ0J3j+mM3pfNcCWWhByPzSivEG86YEwjwbveOTWdzx968L87ETz7FNV/EE?= =?utf-8?q?K9sME4fUrwH0yqwUxb4mO2hoyE8WRVi5lTZ226YMmP3DR8jhpC1nwt2CQyAUarZzD?= =?utf-8?q?2q5TNBBehzcMbyBYVaIb7PvQN2GDOutYbcZBBGRY2Rnh9AIqdmu25EtehIxufUeOD?= =?utf-8?q?zHCTJkkR0Tlca0qFqN?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: de15430a-e38a-48c1-bd4f-08d8c3eee278 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2021 00:43:24.3610 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uSSRzNK0lfttjnTULG947f13wFC1Bgli6ByHLmsZnMjfjINJAN49gJ/d7nbdMFbR X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2560 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Newer AMD processors have a feature to virtualize the use of the SPEC_CTRL MSR. Presence of this feature is indicated via CPUID function 0x8000000A_EDX[20]: GuestSpecCtrl. When present, the SPEC_CTRL MSR is automatically virtualized. Signed-off-by: Babu Moger Acked-by: Borislav Petkov --- arch/x86/include/asm/cpufeatures.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 84b887825f12..3fcd0624b1bc 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -337,6 +337,7 @@ #define X86_FEATURE_AVIC (15*32+13) /* Virtual Interrupt Controller */ #define X86_FEATURE_V_VMSAVE_VMLOAD (15*32+15) /* Virtual VMSAVE VMLOAD */ #define X86_FEATURE_VGIF (15*32+16) /* Virtual GIF */ +#define X86_FEATURE_V_SPEC_CTRL (15*32+20) /* Virtual SPEC_CTRL */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (ECX), word 16 */ #define X86_FEATURE_AVX512VBMI (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/ From patchwork Fri Jan 29 00:43:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 12054831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1CE0C433E0 for ; Fri, 29 Jan 2021 00:48:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F9F964D99 for ; Fri, 29 Jan 2021 00:48:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbhA2ArU (ORCPT ); Thu, 28 Jan 2021 19:47:20 -0500 Received: from mail-dm6nam11on2081.outbound.protection.outlook.com ([40.107.223.81]:51312 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231652AbhA2ApT (ORCPT ); Thu, 28 Jan 2021 19:45:19 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kQD9raEwsFGG4TaRa19VC4bst+E1P+AkaF7UnpSo9C9Uz7W/xKAFVznjgHbvikytQrhyCn+QIGgu8LADVfBgjNsBiHyMf5bDsHNb+UlzrAbjJuBhKWwMNXxjjHITkjDVzDxpIX6IonZ6Ah+XKtmV+RikKlD9N6QZE1yIqGBbmmgx1uTSJWkWA10mj4WdBdLZdhLPhnvXAPfW7ARw2eZxGialBPnrRDrT0/STL3N866WCl8p91Uq1d2D45FxpWVROhqd/oF55ywEGBHppPgC4Up2EWCTXz+z5gG3doWceeqGJURD9O+/6b2lSye0EXy7L1SNcsrHEFUUKN7t67yvORA== 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-SenderADCheck; bh=cbGm3ocNhLunoo9a9azp9O3/ggkhDcw6JXr/msUKJQ0=; b=SYl70fulnN0mRkZT1fKjAlSrDkVmFinZrU/dCoVBbsejP36aAG+4NH/gdtv4qoWsE3dLk6c3qN764k4MHk9aOoEDhRWyy6DUQMSicR+H3RHl3bWW4XXqRSJLiypJYLTX6qaguTwbdmbG0lXKdvYVKgpLAcjiRD7UpBxxd3Z4hK5SG1jUTgFSVPM07E2WwBy+ewrP1n3mvJeu8g2NBqChRA6nXlCccl2i05vWocJ0qTDBSJFjNMG1yq8rYoonOG20PK5v+qFKpfobB7RtWPI0k5q8QKaNpq0P1M41D2Ytx+n41CLHDH+CehqZhBmjAtWkbCJVX/2yFL2aWi2EqRcV8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=cbGm3ocNhLunoo9a9azp9O3/ggkhDcw6JXr/msUKJQ0=; b=V1FFT4WzsP6jyc8UJqiWHI7+3SnPlGvnMZksb4GYcJBUC4v78l9sWGC3pUmSkdOwnJzL172NP4NFdgMSx6SlaKtUok9Eyuh/WPnngwAVmvw/yoV0dxWWdcKFoC86q2XguyYKfhtUFmDk4D0TeFwpRUFeDPICAhph+vTfj087qz4= Authentication-Results: tencent.com; dkim=none (message not signed) header.d=none;tencent.com; dmarc=none action=none header.from=amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17; Fri, 29 Jan 2021 00:43:31 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::8c0e:9a64:673b:4fff]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::8c0e:9a64:673b:4fff%5]) with mapi id 15.20.3805.019; Fri, 29 Jan 2021 00:43:31 +0000 Subject: [PATCH v4 2/2] KVM: SVM: Add support for Virtual SPEC_CTRL From: Babu Moger To: pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de Cc: fenghua.yu@intel.com, tony.luck@intel.com, wanpengli@tencent.com, kvm@vger.kernel.org, thomas.lendacky@amd.com, peterz@infradead.org, seanjc@google.com, joro@8bytes.org, x86@kernel.org, kyung.min.park@intel.com, linux-kernel@vger.kernel.org, krish.sadhukhan@oracle.com, hpa@zytor.com, mgross@linux.intel.com, vkuznets@redhat.com, kim.phillips@amd.com, wei.huang2@amd.com, jmattson@google.com Date: Thu, 28 Jan 2021 18:43:29 -0600 Message-ID: <161188100955.28787.11816849358413330720.stgit@bmoger-ubuntu> In-Reply-To: <161188083424.28787.9510741752032213167.stgit@bmoger-ubuntu> References: <161188083424.28787.9510741752032213167.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0401CA0008.namprd04.prod.outlook.com (2603:10b6:803:21::18) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by SN4PR0401CA0008.namprd04.prod.outlook.com (2603:10b6:803:21::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.16 via Frontend Transport; Fri, 29 Jan 2021 00:43:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1fc49e40-95a2-4800-b663-08d8c3eee66e X-MS-TrafficTypeDiagnostic: SN1PR12MB2560: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mImU/BqrsWbu3ls/juIwhE4zSuf77BfSL+UN6vWYQ4Bk7RDFMlI8EiXxUnUkH45BqnWeRyzJOENwnqWK32eVNaNz1Zdy/ey/W9M57lfcpY80m19fI9CtklxAbhQirFWylV3MSM9ewqjHh/KmN4FFhj3NBzsIFEUHLfY5JwOpbjJjbb1cEr9qvGQA7XczwmAuk0TIl2RytznaVyrFbCXBH4Vy8iVpYO8Eg04IhIWpFbDGq/8JxTCZorpmw5gX9MlYFVkTYuGrTulmewAXIGGugUwYMVDDXTTDCUZYwXQbeiEyfNDnoBayzb4hO+FjR//mLaUJNDTDXZcOMRBqNyeCDkNiGpiHRpKqgHE+RaM0tViSFDcw6+doA4Dwq8esGD4+mPJ20JalQJt2P75E93UHeRj3SS8tmZyj+jit/P0+U9mn9pKaO9wHQ90bwmYMsnhMYtPf7HQMct2wksYmO7zDDRLrC4TUy0koY7vgFoDp1Rqrfnwj8Otvt9HPw7Y92PXYDOuw54KGGH1cYExv7wygCw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN1PR12MB2560.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(7916004)(396003)(39860400002)(136003)(366004)(346002)(376002)(956004)(16576012)(52116002)(7416002)(8936002)(8676002)(316002)(86362001)(83380400001)(103116003)(44832011)(16526019)(186003)(33716001)(4326008)(478600001)(6486002)(9686003)(66476007)(66556008)(5660300002)(26005)(2906002)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?C8Bc0X7+5vnrpA5bQsfqkotrBd5Mq9?= =?utf-8?q?Gq/2Eew5Nfq52rQk2HlVZZhlunF+XSqya/anpPzFWF7aBEXVj4izW4E+rjW2Xar9N?= =?utf-8?q?+OUnKcx0tzUuLfuiHAfNQOjj80c5AwQ6egxoTwm0EdebFjTrffZB7cBIEWocku9DX?= =?utf-8?q?zxv4owSO9dZ5YcAkSe+6Et2TKl+c5n6gsNLmrk5+/5xcYyFbwusZiaptt4cHLmEKN?= =?utf-8?q?KuHYN9iFagbiKpzAHS0D1838HsfF85YaWMnpLqEzCvGzzz8l6yJVsIbHmpA15lG/s?= =?utf-8?q?t07exB3xedstwAtXD3h0BHLGfzzOI21NNlUO8StSCaB7hQ0ysNvhIxyKnV832xVdv?= =?utf-8?q?XGSrbl0mXmkmC9ISbZ/6bPUjhpA8BaxiYJ2hTfEhbA9kgSchdOLtQ4SN2fGrEYztq?= =?utf-8?q?wN8ZWLmYdx+vqPpqRp7g1F/YxsbGqqaFnQHyWZQ7NbI3XER4akQQKNq7FUWSVdUUG?= =?utf-8?q?rgIJp8FF5H2X0TmHPPjzR+MLyXc1CtiFHsQkagXeoupOVey87EGx7BlUwnsFIab/P?= =?utf-8?q?5N2i9kaoODZI1aHuqmB1qEGzPDb7Mi9OUMGbMiCm7tCFPRo12fcNmeeoKgKRGwjhg?= =?utf-8?q?fS7TlH6zb8uaxzIwyVQWxI2oJi3ZZ71qrD3z10BauMOw0c/3yRFqi0LFNRpB6gmD3?= =?utf-8?q?COwwb4wwG+r20dDxXZcNgqA3+Mjo3+oc9seRaNXEy+jEDpLbjOHUjL7tsRZy5MTNB?= =?utf-8?q?dnGR+p6hYnZCfxaF0s0o0HucdtN4KlsqpaiIsMC6ZVZ05HlU6JCH9VkKa9Jqq94yw?= =?utf-8?q?HTFymozNBP/wat9OBm88BkAPNI6Rozuc0TLHFXjLiFT0mAMLVB7KmRKN5l+6Luf0O?= =?utf-8?q?52pE4Ve0PxSPRFXqTongCvATOtf3gvnL24Fdvn1wgNDUieERmtythDn1AfRtzlk3x?= =?utf-8?q?VvGMhgWXtfvNFJpoaJGbNCepqGU05W14ZVOrZZoQC8duCE5MFkRgreUmS2juua6nP?= =?utf-8?q?BLgOt4TQW14FPQ7H3jK9io+avLsDodADPQr+wDJph90dnWk1zrNwk9GAiT5fKT/ql?= =?utf-8?q?CXRKShcoCW7CJJLiYy?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1fc49e40-95a2-4800-b663-08d8c3eee66e X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2021 00:43:31.0262 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uF3sUefeyQgwEN5PqOhq/1TSWCN46/ZMr26ZhNfE8Ujy+le7FmANaLiVlhOEtz+g X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2560 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Newer AMD processors have a feature to virtualize the use of the SPEC_CTRL MSR. Presence of this feature is indicated via CPUID function 0x8000000A_EDX[20]: GuestSpecCtrl. Hypervisors are not required to enable this feature since it is automatically enabled on processors that support it. A hypervisor may wish to impose speculation controls on guest execution or a guest may want to impose its own speculation controls. Therefore, the processor implements both host and guest versions of SPEC_CTRL. When in host mode, the host SPEC_CTRL value is in effect and writes update only the host version of SPEC_CTRL. On a VMRUN, the processor loads the guest version of SPEC_CTRL from the VMCB. When the guest writes SPEC_CTRL, only the guest version is updated. On a VMEXIT, the guest version is saved into the VMCB and the processor returns to only using the host SPEC_CTRL for speculation control. The guest SPEC_CTRL is located at offset 0x2E0 in the VMCB. The effective SPEC_CTRL setting is the guest SPEC_CTRL setting or'ed with the hypervisor SPEC_CTRL setting. This allows the hypervisor to ensure a minimum SPEC_CTRL if desired. This support also fixes an issue where a guest may sometimes see an inconsistent value for the SPEC_CTRL MSR on processors that support this feature. With the current SPEC_CTRL support, the first write to SPEC_CTRL is intercepted and the virtualized version of the SPEC_CTRL MSR is not updated. When the guest reads back the SPEC_CTRL MSR, it will be 0x0, instead of the actual expected value. There isn’t a security concern here, because the host SPEC_CTRL value is or’ed with the Guest SPEC_CTRL value to generate the effective SPEC_CTRL value. KVM writes with the guest's virtualized SPEC_CTRL value to SPEC_CTRL MSR just before the VMRUN, so it will always have the actual value even though it doesn’t appear that way in the guest. The guest will only see the proper value for the SPEC_CTRL register if the guest was to write to the SPEC_CTRL register again. With Virtual SPEC_CTRL support, the save area spec_ctrl is properly saved and restored. So, the guest will always see the proper value when it is read back. Signed-off-by: Babu Moger --- arch/x86/include/asm/svm.h | 4 +++- arch/x86/kvm/svm/nested.c | 2 ++ arch/x86/kvm/svm/svm.c | 27 ++++++++++++++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 1c561945b426..772e60efe243 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -269,7 +269,9 @@ struct vmcb_save_area { * SEV-ES guests when referenced through the GHCB or for * saving to the host save area. */ - u8 reserved_7[80]; + u8 reserved_7[72]; + u32 spec_ctrl; /* Guest version of SPEC_CTRL at 0x2E0 */ + u8 reserved_7b[4]; u32 pkru; u8 reserved_7a[20]; u64 reserved_8; /* rax already available at 0x01f8 */ diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 7a605ad8254d..9e51f9e4f631 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -534,6 +534,7 @@ int nested_svm_vmrun(struct vcpu_svm *svm) hsave->save.cr3 = vmcb->save.cr3; else hsave->save.cr3 = kvm_read_cr3(&svm->vcpu); + hsave->save.spec_ctrl = vmcb->save.spec_ctrl; copy_vmcb_control_area(&hsave->control, &vmcb->control); @@ -675,6 +676,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) kvm_rip_write(&svm->vcpu, hsave->save.rip); svm->vmcb->save.dr7 = DR7_FIXED_1; svm->vmcb->save.cpl = 0; + svm->vmcb->save.spec_ctrl = hsave->save.spec_ctrl; svm->vmcb->control.exit_int_info = 0; vmcb_mark_all_dirty(svm->vmcb); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index f923e14e87df..756129caa611 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1244,6 +1244,14 @@ static void init_vmcb(struct vcpu_svm *svm) svm_check_invpcid(svm); + /* + * If the host supports V_SPEC_CTRL then disable the interception + * of MSR_IA32_SPEC_CTRL. + */ + if (boot_cpu_has(X86_FEATURE_V_SPEC_CTRL)) + set_msr_interception(&svm->vcpu, svm->msrpm, MSR_IA32_SPEC_CTRL, + 1, 1); + if (kvm_vcpu_apicv_active(&svm->vcpu)) avic_init_vmcb(svm); @@ -2678,7 +2686,10 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) !guest_has_spec_ctrl_msr(vcpu)) return 1; - msr_info->data = svm->spec_ctrl; + if (boot_cpu_has(X86_FEATURE_V_SPEC_CTRL)) + msr_info->data = svm->vmcb->save.spec_ctrl; + else + msr_info->data = svm->spec_ctrl; break; case MSR_AMD64_VIRT_SPEC_CTRL: if (!msr_info->host_initiated && @@ -2779,7 +2790,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) if (kvm_spec_ctrl_test_value(data)) return 1; - svm->spec_ctrl = data; + if (boot_cpu_has(X86_FEATURE_V_SPEC_CTRL)) + svm->vmcb->save.spec_ctrl = data; + else + svm->spec_ctrl = data; if (!data) break; @@ -3791,7 +3805,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) * is no need to worry about the conditional branch over the wrmsr * being speculatively taken. */ - x86_spec_ctrl_set_guest(svm->spec_ctrl, svm->virt_spec_ctrl); + if (!static_cpu_has(X86_FEATURE_V_SPEC_CTRL)) + x86_spec_ctrl_set_guest(svm->spec_ctrl, svm->virt_spec_ctrl); svm_vcpu_enter_exit(vcpu, svm); @@ -3810,13 +3825,15 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) * If the L02 MSR bitmap does not intercept the MSR, then we need to * save it. */ - if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))) + if (!static_cpu_has(X86_FEATURE_V_SPEC_CTRL) && + unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))) svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL); if (!sev_es_guest(svm->vcpu.kvm)) reload_tss(vcpu); - x86_spec_ctrl_restore_host(svm->spec_ctrl, svm->virt_spec_ctrl); + if (!static_cpu_has(X86_FEATURE_V_SPEC_CTRL)) + x86_spec_ctrl_restore_host(svm->spec_ctrl, svm->virt_spec_ctrl); if (!sev_es_guest(svm->vcpu.kvm)) { vcpu->arch.cr2 = svm->vmcb->save.cr2;