From patchwork Fri Jan 29 00:43:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 12054809 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=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 7F1F0C433DB for ; Fri, 29 Jan 2021 00:45:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3555D64D99 for ; Fri, 29 Jan 2021 00:45:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231650AbhA2ApM (ORCPT ); Thu, 28 Jan 2021 19:45:12 -0500 Received: from mail-dm6nam08on2058.outbound.protection.outlook.com ([40.107.102.58]:18528 "EHLO NAM04-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231444AbhA2AoL (ORCPT ); Thu, 28 Jan 2021 19:44:11 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GDwu4WxI9kECLFkQg22VTsOTxgKfsHQoM/talrVLxoER3/ir1qm1F5krjpMrUxs6H/mBOUvhVeyu/xo40eJejdP+02t6cut9KoSg9/zfMc9PZPVjEOxciI4XuOFFUku+/bkY3HWLLqxsKxwHczdVZ5ef29Wnv5hjBVFCJSJ9mND+Fu0dH96a1GcSbjdZ2ePUX2rCx/36hPzPmxDWiB4EeLx6rHe0yyXFb9DnEjcmmqM82TUNyVcWEUgq1MEsNqmrW4GABrK9G7gQ1DAqjUn/710+GKReNfEf3h3GAlLbae0EG+LLoLjddXvF5bbGSf8MKloc1990G7kFwi/qQEUJQA== 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=u0wlbu+rGSGyJtV82TTyePIZ+f3cfD9tyoTp4dGGUeo=; b=AZfcy3nvY+QPk2hT6tCtmOJQDUOgYc6GXSgVQf52hcUyAXsMmh0SdDu+8F9zUNQW77hx880oHtuH8UDaarf97slznjIgNpvXSq7Q2yQjHJag7MFGGAyXugdCfY84W/oUqMrRLFrH3MjbfwysYDCVL6ySLZCvxmuOQRyp1Lac5I9uUrWLCKGgOAjMVZHvBTB95Sigvc8DGey8TRXNPWPAvdlF9s35/rOPE1RGvlhpqCY0qNawuqxb16XwuPxWxLBqRzzVHPA8o3m7inIqAea8SsC/Iux4IMCrTCic3GR42zxsOe1mR/TxkMMuEvEU7k8n8n0Li39dpRpVRANJZBrrSg== 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=u0wlbu+rGSGyJtV82TTyePIZ+f3cfD9tyoTp4dGGUeo=; b=HJ4aOVoin8ZbTlKjqFWo+ScuzFFWqMi2vVCh1N1DsITZyj1mqwc1muacfEduoNII5x9O56hKTnuQqOxam56ulmBKW5qigNoA5PEkUEJcT/ItfEaa6m0hrPj0xMEieM714Qezl5YPsoFxAF3x+qktaUpyQbfOo5CSH1XT3yaTn3s= 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:17 +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:17 +0000 Subject: [PATCH v4 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: Thu, 28 Jan 2021 18:43:16 -0600 Message-ID: <161188083424.28787.9510741752032213167.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0107.namprd04.prod.outlook.com (2603:10b6:806:122::22) 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 SN7PR04CA0107.namprd04.prod.outlook.com (2603:10b6:806:122::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17 via Frontend Transport; Fri, 29 Jan 2021 00:43:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 60361f35-5746-4c87-6fc2-08d8c3eede62 X-MS-TrafficTypeDiagnostic: SN1PR12MB2560: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AU6Ynwm8ZILj39g8BC+OVmKCeiduD6FfHlExKYDkxilUBtY/N7I5/nmfVBSySQpxu7YyD7Wtft6EEen1oEjCZaAh6x2cBSUTBtK5JiYbO7mzWQvmltW6VAW0dGrJoPm/klaD8nnJnC5yGA7bYXJhzO4PNswEQw538e1gDqzIXQQwy/tYk7WFN83XU8vQqaJTY3ye5pXHM68LExX4leY/mKB/Z4bIAKRp4SAvIo1y04agYePRa/952QTXWDfXUxNwgv+WNmzZi1D2hHwpkg8Ek5urhYib6hgn83XDxpZYH2JPLh5Mo5aUuJr+JhR5F7+TH+mlRnNZPPoHd6My5xzuEA+9Gb2L6+msRfafYlC7XZt+AVzSL7I7ntocisSxz5uopay6xwQ4WBX8Y4i/2tKPUNJxLi+3MMVBkLDwbVvYjovndrvpehf7K/j+mwEMh3pQ0KaLSGfW79f2XBqkEMI8NQrz9RTbMI2MGRFGpcSJNrSwgIbp9JS3DYf2kIw+85uSuuYm0ynbTQGzKQYBdgMWYTpARhLWRwcRx4+pIkMkb22L8nNtlLwEpgBH4GW/z1aDU3PPh6nI/E6DfpOQdwuNpf6eBx7nVk7jNroCn/opJlk= 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)(966005)(4326008)(478600001)(6486002)(9686003)(66476007)(66556008)(5660300002)(26005)(2906002)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?YUXaFMbFNkg2HQ9+3lzUvD6XoYryJg?= =?utf-8?q?+mf1593IfswCKdVLwuDruByUXdGe6J/J6MhRFCiX+wLGkeubXloz5FA05ex5f7+k9?= =?utf-8?q?oq+/MOxloTVi59N2G+A49w98KBzU+na6/fyGSImLA+ZrdkuFQgF2Ky4zLQvu7MAkI?= =?utf-8?q?L/yInk91JvdD3hvVAHQhkUvPvOmevR33ZPwzJYErCFQwdj6AsKH86Ci50uXuBoi9M?= =?utf-8?q?BXFYytZgFEmMa9Z7mOsNv/rhkeWl/5V4OftQA7p8G6hPbo5FXEHEgiYnIyjY+NXgm?= =?utf-8?q?0n2srzESoUDo2vqVlQnnTwfdsgPOFZVWUA16kPQaENq6qzUIdfbesQP8PBRm5j2Hy?= =?utf-8?q?nfTo5fNH9bNZllYzaMgXPZakSsK1rB137JaFXT7IgXkJ0P123e/5UGkzdfQPnYMht?= =?utf-8?q?vUkop3R0FUDcIOi9L4yPk747LwnUxW/agxxNZKO+LFGaByzQYDY4Zhm0y/H2lguUL?= =?utf-8?q?LfF6o8J/G3n3BuLbiV/qRTfhbvJ62eFgHzn0mqPkghMbsVwjCsCUJn8OQCoqGLj3h?= =?utf-8?q?gsNI086Aw0sdQuuyzXVT98Z1PprijnSUu5pX6G44Q+NK1AL83OnAcnqQwOPExcwQV?= =?utf-8?q?5vNvpAgF0nSyHMqZ7ZrLSscY9aoDkY5vFxn/VUwArrCQ0XJ0kXBytYPaAXclUYmyh?= =?utf-8?q?5G34GTbDuJuItpGNtFBgUMiJMqorkng2i33K9xwpDOowu6NEgfQ+HC3kjh48Fk6f6?= =?utf-8?q?GwhTpABKL9lJeCV938m3ExKwQcfO1+kZ7G7yuCSoi5JoaR+iwmIm2be40TzX+gBbT?= =?utf-8?q?5WEUNDbrqN2OInC0KfhogcykqKflxivmM/EQICVHXl2B0jbFSAVgK6p09W+ZqVnsN?= =?utf-8?q?OCD5dLWlkWnnR6Dmo8cgh89+U4FTbjnJ5qbxwWirf3asc44WcHx1a2JDhYFqylemS?= =?utf-8?q?JLfOA0PSAJ2G/MUDqxNmGcCvRet6evv0gszobf5+NbURu0NWMpdqXa/dN+dTDRmtW?= =?utf-8?q?Xo5a911e9QBb2pj6pY9nlBqBZbOlKb2IAAlPTmHdOKAFd9iimWZT6bBXP+ZLZGGIx?= =?utf-8?q?StSw2g/3PP8rHRhW4N?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60361f35-5746-4c87-6fc2-08d8c3eede62 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:17.5240 (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: 1tNBKMZwh0nJYQqRF9NtATWL+7Elc7S8D7nlAMqt+yg1XKfNkUCoYV2PkwstKuIH 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 on the guest. The series adds the feature support and enables the feature on SVM. --- v4: 1. Taken care of comments from Sean Christopherson. a. Updated svm_set_msr/svm_get_msr to read/write the spec_ctrl value directly from save spec_ctrl. b. Disabled the msr_interception in init_vmcb when V_SPEC_CTRL is present. c. Added the save restore for nested vm. Also tested to make sure the nested SPEC_CTRL settings properly saved and restored between L2 and L1 guests. 2. Added the kvm-unit-tests to verify that. Sent those patches separately. v3: 1. Taken care of recent changes in vmcb_save_area. Needed to adjust the save area spec_ctrl definition. 2. Taken care of few comments from Tom. a. Initialised the save area spec_ctrl in case of SEV-ES. b. Removed the changes in svm_get_msr/svm_set_msr. c. Reverted the changes to disable the msr interception to avoid compatibility issue. 3. Updated the patch #1 with Acked-by from Boris. 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. v3: https://lore.kernel.org/kvm/161073115461.13848.18035972823733547803.stgit@bmoger-ubuntu/ v2: https://lore.kernel.org/kvm/160867624053.3471.7106539070175910424.stgit@bmoger-ubuntu/ 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/nested.c | 2 ++ arch/x86/kvm/svm/svm.c | 27 ++++++++++++++++++++++----- 4 files changed, 28 insertions(+), 6 deletions(-) --