From patchwork Tue Dec 22 22:31:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11987373 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=-8.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS 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 00FDEC433E0 for ; Tue, 22 Dec 2020 22:32:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC6FE22573 for ; Tue, 22 Dec 2020 22:32:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728480AbgLVWcX (ORCPT ); Tue, 22 Dec 2020 17:32:23 -0500 Received: from mail-bn8nam08on2053.outbound.protection.outlook.com ([40.107.100.53]:4961 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728107AbgLVWcX (ORCPT ); Tue, 22 Dec 2020 17:32:23 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bkzy+SUttUwmMB6gQt9OX4EIKLuxBs/ox8/xtl1AhjwccM5k5bPedFgGjnUoF1j9GhdNJX53zUTkgQaNT0zSB91T0e1RJqvSjY0TjNRGD8Y5bmBYIaFLc3gRKZkE1TmPqSPXtK4oZ6A4eYA6CK7heqohiIA41DsvHkrI5j5t6l3S4lX6ezDOpPr0lxzAT+UrQhLumUgyxvfk7+Y9PQXdBwHbSIFFlO67HjjTtvHwfO8MD1xOpna3zpNjh4RvftvKYi4aSBr2Y1788HFtgdSSGEQNL1RpT4MLMIqFhzQ2kd11EKrqUS24DdhoDtyJtBLPA+QCzyXChi59AhzUV3J5dg== 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=5qYrX56Hz+pCEzPspCsNmO5uEZXRwWohviujneZgWnE=; b=Av9b6lXWnvsIVPxbdVotpQYUFSAColuLO+7j46zlwaKSUoekLy8YIOo0z/5li9G2xPxypGuJgwj4UrvzT9IWaaYVE2PClfv8AWO/6IpqY7Qm5o4KeasDpU367avD8oyE3aOkCKEYWtxFu3DEsNvghcKOiFbRLgRbQQCikMZyZYDsU6Wfe63d+8QAEWQhfwExZB/I/+WIAJkjMQq4dQOy9miydwAPGxqzK8k0JQbYexM+p2NH859Bg23FMotFjJuSr/itJyZBFenAQcV4Z3Xru4lnxFRHM30WgOq8OkADESk4xnpruMMkSHGebZV0MfaHSi1cAZ5no1RVMFMkUM/trg== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5qYrX56Hz+pCEzPspCsNmO5uEZXRwWohviujneZgWnE=; b=Ei8H1NtBp1wy9wSRroDNM1k0EGA5L8Eih8tSKLWqE4TN7RYKOevWtDOEqGats8wt0v6nJ126Ma23fTRp5uKeAnJlob5j9WsbY0p+fXH4antnXtsNgK0JcwV3/Jjya1DUP8IjhioBZ8qY9yzuVDTgXXwIyOQZ755zvHYqtf4MwTQ= 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 SN1PR12MB2381.namprd12.prod.outlook.com (2603:10b6:802:2f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.33; Tue, 22 Dec 2020 22:31:27 +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.3676.033; Tue, 22 Dec 2020 22:31:27 +0000 Subject: [PATCH v2 0/2] x86: Add the feature 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: Tue, 22 Dec 2020 16:31:26 -0600 Message-ID: <160867624053.3471.7106539070175910424.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0154.namprd05.prod.outlook.com (2603:10b6:803:2c::32) 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 SN4PR0501CA0154.namprd05.prod.outlook.com (2603:10b6:803:2c::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.13 via Frontend Transport; Tue, 22 Dec 2020 22:31:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b3a1e841-00bc-49cb-f9c5-08d8a6c95291 X-MS-TrafficTypeDiagnostic: SN1PR12MB2381: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iw6Qc/kjqqhOdJV0dmMVRGGLhwC4phSLkoX9dKOW5nZ2XvFH/32IKg6vqmuQ2unyylDFSxD2NM4J3gpRlNnDj8arCklACb4H89omdIKBScyZixeLjx2U0vJJ37a8SN2xPgf5lXgGGDGcGWjcIeYJC5alz5HY539qO/20E5OXHM2OScMlRxtqqNKTv6a4WaOsg1FwFe7mh0Q9yWVB/DjDm9OrMcirly+3z1+nnL6YrOi2nfFAdhWNV86hVbCHibgquCv9904l4wpkdo04X3qDRBHrKKsUbQ+KrA5VEVBXBU3irHS93YJs/1ksbl9ninlQQoezPWuhe1nj44q0qbJhJyKOzHva39hjR7C3jqeysGcTEeGqRQqpL9QH5VZYwLdHEq0+o4MYIgEB87dE37EuH8IaeTwbl60ji1RMYDFjxoTZA9xg94FKCMMe+sAWzu6M1yyfuvF+LSWd3ih68kov9A== 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)(346002)(376002)(136003)(39840400004)(396003)(366004)(16526019)(66476007)(26005)(186003)(83380400001)(66946007)(4326008)(103116003)(5660300002)(7416002)(9686003)(66556008)(478600001)(966005)(33716001)(956004)(8676002)(6486002)(86362001)(316002)(2906002)(8936002)(52116002)(44832011)(16576012);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8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ZiCZdpQtwqVN2/h+63bZMT/0OZOZca4AFegnxukqpfNaD?= =?utf-8?q?V/YhLNQMaOe3+o1LsizoJ13L/moXjt7YVDXYTO6XjHQzH+WEQLQRohOV1vrbzn5iL?= =?utf-8?q?JMhEEVGxkEfjvRMUnQ5?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Dec 2020 22:31:27.5131 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: b3a1e841-00bc-49cb-f9c5-08d8a6c95291 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Rx7iKQ3Sq3cGPQCG6ybybuiLtCWxq0WKPhPl2SbXgsvPtxwzvHiEde/GeCIlQK0L X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2381 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 on the guest. The series adds the feature support and enables the feature on SVM. --- v2: NOTE: This is not final yet. Sending out the patches to make sure I captured all the comments correctly. 1. Most of the changes are related to Jim and Sean's feedback. 2. Improved the description of patch #2. 3. Updated the vmcb save area's guest spec_ctrl value(offset 0x2E0) properly. Initialized during init_vmcb and svm_set_msr and returned the value from save area for svm_get_msr. 4. As Jim commented, transferred the value into the VMCB prior to VMRUN and out of the VMCB after #VMEXIT. 5. Added kvm-unit-test to detect the SPEC CTRL feature. https://lore.kernel.org/kvm/160865324865.19910.5159218511905134908.stgit@bmoger-ubuntu/ 6. Sean mantioned of renaming MSR_AMD64_VIRT_SPEC_CTRL. But, it might create even more confusion, so dropped the idea for now. v1: https://lore.kernel.org/kvm/160738054169.28590.5171339079028237631.stgit@bmoger-ubuntu/ --- Babu Moger (2): x86/cpufeatures: Add the Virtual SPEC_CTRL feature KVM: SVM: Add support for Virtual SPEC_CTRL arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/svm.h | 4 +++- arch/x86/kvm/svm/svm.c | 29 +++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) --