From patchwork Wed Aug 26 19:13:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6248013A4 for ; Wed, 26 Aug 2020 19:14:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 450542083B for ; Wed, 26 Aug 2020 19:14:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="vFRBgGPw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727122AbgHZTOA (ORCPT ); Wed, 26 Aug 2020 15:14:00 -0400 Received: from mail-eopbgr770083.outbound.protection.outlook.com ([40.107.77.83]:22217 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727772AbgHZTNz (ORCPT ); Wed, 26 Aug 2020 15:13:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oE+NxzmJ+mLhkQOvN+//MtPu5m9MdOVyh24GXJlpG6pkQB1uLTs1TwGPhThualoX0T9C7M5bE5y949+BIiWcZyhlWpjaHaUNoj1P7lQK5jHLHUYt6H5JneyUafUElTYKxPe6KEc8wbJB79owTqPynKW7CP6kYZ70BJjnSOknad2jBew0ydmJjSG4JWzy3GDnyv0Wjw0Hk3yjeOmOYaxIhbYwkoSNiyevJSeDQRlKHcWE8Q1uv3uxUKrW2WebnbQgjuT7tiCrFEWTuGvnS/K4XH/gPjmq2OtrtUmfeCVGQUNZrqUaMY4nfh/DpFZDtk2cf6mRNyfUP4U5upkgKpAD3A== 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=BnA8rp8+HxgO9is7tLLaDPXB8cL3FzUpBFn/5y8ITMY=; b=hmyVWBBtyC6VI0zlLmaH7qc0EbWriCG43fqO4Dx3eewo5Uf6sUt81HNy0ibZYt1Wo9b7SWFww+WLAhoLLYLw9ramQXHrrdcg6OgJXnoIUU+5aEMWFFqA9P7C48dCcXqm83f1uzMcjOfZfenYErCFpQvw1lTVcBpQv/8Anlbo4hL4gfFhZEHHAk7AiJ0t1a6lePgJqC40PpMI0ElPIvL7UTbK+ps4mQe+X3xNwUJ5qFgdBMaO9gwjHr8h6gh0KRQa4Jwg0f3iUZe2o2iFFNpn2iNe3K+JUBHS4f+GoZCy22iqcv/7P0R6KqvGtMWniXaeIzvOVaf2KVh1Jh23rlVWrA== 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=BnA8rp8+HxgO9is7tLLaDPXB8cL3FzUpBFn/5y8ITMY=; b=vFRBgGPwOp2K+5m8T0MoMCj/9lBWh7sE2tZehh2ZpaAPIJ+lO4hVGPbbdF/j5ABgs83cLhI7jBhzSpu99KcSQic5Jlu+dqqiIweJFR0qb5H10wX5kJO5GpBCSVCp4NH4fxNFMuy93lEGmfZvmukl34DnE8c1PuM5iSvEPU3r+OY= 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 SN1PR12MB2384.namprd12.prod.outlook.com (2603:10b6:802:25::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Wed, 26 Aug 2020 19:13:54 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:13:54 +0000 Subject: [PATCH v5 01/12] KVM: SVM: Introduce vmcb_(set_intercept/clr_intercept/_is_intercept) From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:13:51 -0500 Message-ID: <159846923148.18873.3524447445230117185.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM6PR21CA0013.namprd21.prod.outlook.com (2603:10b6:5:174::23) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM6PR21CA0013.namprd21.prod.outlook.com (2603:10b6:5:174::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.3 via Frontend Transport; Wed, 26 Aug 2020 19:13:52 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: bd3a577b-397d-4031-d2f5-08d849f42c63 X-MS-TrafficTypeDiagnostic: SN1PR12MB2384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G5oeM5eEZu6M5UHPOM6lVRZlWJN9Xcc/+x4HIs11Y+ujDrBddVSn15U53r8PebT2f/5ewYsQhIQQBeth2unnulZezV1PWS/mPliop9bhbhFVYdv7IPpx35UpQVodAPzD0s5e4/sfzueIjTR7+RBYbeGRHpfnIsZeFEdLKd9Wh5iVLO1WsNOcRz/PPWNYErAfj0JymYL1z2FoDXYoZXFSRXodUTdUIjYYBxIufH4iyVZSNspEuG+rHpDNYXM+9nyArMavo6ksSxSghhJ9yExbwjacvxwZeKYJCtzvQS4CEtxHtrpQdI1RRzwxDLFbBpElXHBYD6H+GbIuS2SjS0SEdg== 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)(366004)(136003)(376002)(396003)(39860400002)(103116003)(4326008)(186003)(66946007)(5660300002)(66476007)(66556008)(44832011)(86362001)(33716001)(9686003)(52116002)(7416002)(6486002)(8936002)(8676002)(16576012)(2906002)(316002)(26005)(478600001)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: c/pIvlwkvV2zIdW+tHu1rh2/z9e+ykuopNWRetMEt5DSPiu3K8V2cOnH+4ikIDJ4GxlD+oJ5p8JILUXUpU/FhzwApL271G2yPPpoXXrJcYdKe2vio0e4bgVzhg2f0+86fz25h73Q4f0v6YuBfEM9ESffWX9vzNCCOtAXGgylIVQEU0DJaCZNfWK46z/+ObqaxMHAlurXEQoG3qlZvp049kqeBz3uRSvNlGgW7zMmEmRdPgXeCxyDqIQDeHDbj00ggRcC4pL7Kl8+X0aIZtOrXVIYyRovcaaBUAp/GyIJwzVphJQ5X9XdwjanOwWLmIJuM77FrznlQjG5BxgwZ6DPbI212Eg7Sxl4hxOogYr8q6KxC57gvbmHkbruUZHu3rGwfs+4k6m6niyKPK1U5wHB6z+Su8g9i6XuDCL7j9qkG6dzEA9OnU0L5+VdXH1PCS0hLXOBi4VYD9bQPi/2LGtdQx63L1weKk48HN+vGenjOY14Mg0zJeO2qjrZ+8yFdj+8NxNfzDPsp5Ny7Gf82+A42soq+EwvzAmz6UWuLwYNIpzFRXeW4v2ehWaMp09XbmKlmbCL3BuZ59x6elE+asr3+VUoJKhA4+WJ4ceYHOdZjPASOFIRLus8FqK/GQSvoORi2BCGmsj0aMWq/3CmrNpiKg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bd3a577b-397d-4031-d2f5-08d849f42c63 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:13:53.9831 (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: 01Musu7qnrRF8+S2QFrymTzQmq/KGSWVYO+bB/G+ARNN5E3hl3YDuBrZk42DNU4b X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2384 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is in preparation for the future intercept vector additions. Add new functions vmcb_set_intercept, vmcb_clr_intercept and vmcb_is_intercept using kernel APIs __set_bit, __clear_bit and test_bit espectively. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/kvm/svm/svm.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index a798e1731709..1cff7644e70b 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -214,6 +214,21 @@ static inline struct vmcb *get_host_vmcb(struct vcpu_svm *svm) return svm->vmcb; } +static inline void vmcb_set_intercept(struct vmcb_control_area *control, int bit) +{ + __set_bit(bit, (unsigned long *)&control->intercept_cr); +} + +static inline void vmcb_clr_intercept(struct vmcb_control_area *control, int bit) +{ + __clear_bit(bit, (unsigned long *)&control->intercept_cr); +} + +static inline bool vmcb_is_intercept(struct vmcb_control_area *control, int bit) +{ + return test_bit(bit, (unsigned long *)&control->intercept_cr); +} + static inline void set_cr_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); From patchwork Wed Aug 26 19:13:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739529 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A778F14E5 for ; Wed, 26 Aug 2020 19:14:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BD412083B for ; Wed, 26 Aug 2020 19:14:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="f4tWSiwm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727821AbgHZTOO (ORCPT ); Wed, 26 Aug 2020 15:14:14 -0400 Received: from mail-bn7nam10on2065.outbound.protection.outlook.com ([40.107.92.65]:64192 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727772AbgHZTOF (ORCPT ); Wed, 26 Aug 2020 15:14:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LI7igB/YlPW4eYJjH40QOc44pxuluwyJBZAoSRKkr13dgCFeYS/zJiStf3TBhgC/6bFYShG3tPW9rmPHQ4dSrUaPduJgpmVOH+cze5r6NAlRvG4mtrnDRrbQwUJ8jS8FshGkcqVi8TUUHN94JUc4nHAB/2KRMOH9Rg4JWKcB3F6yr6MJDgUOI5BD498x0sPzdqmQNRraLnZDmZo5rVdJNkFxZIvYhgyCV/shMK5F/GoElEGvQ6Tv+S+poZn9mQjdvNEZK6+Z0mKeCQXcvbSTcTMDUY3OlCnPym9FBCSMGdSiaOSF8HdMH7pE/O4Xb7jNsi6jCcNDKGmvAL883i8PtA== 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=kOjuipFjJFW6NJStl8V3ODovc8K5IpQW1UGena9ytZg=; b=Pvsw7atgS6ND7Cs9MBWt4Hgj1qseFYBI8dPMgDBthmAYQ3OOJLaYZFN02WQdZPssAMJaIbdYcZ288qm1K0mPNv0oceQcRF3xy/SZeDoigOYf0DAXoaWuV0MfmhzFqQCk+qTjWX2cq8Z7/e5ooUn3uzKzODZ7i6TkmvV/X5m4jhKxJIzBsJ6FeUKL56f0WReK74z6osqkTMeDx94vymvVZIFn6VVgv9E+nVKwxrukLcdp6ASaAc+wSn92QcLwY2F9VcHC3gAFGplUTOTZ6J6xveQqjReulh3Ds2rTRsoKn8Klg9DIxSqRXm+z3G69eWKoXySh/OCv1DTSlz8fvu0N/A== 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=kOjuipFjJFW6NJStl8V3ODovc8K5IpQW1UGena9ytZg=; b=f4tWSiwmIyrtWP0oCxWO0ffvQMgH/8HuI8OLdsC6VxtH/Wd1BjsLtgXKMjD3A0N69lEYU4DdRHxPpfO+9kBQfxT2tBGIhtKDeU/dTBdq7gEeDEj1CRl6lws1VD8n43GOisZszlipMV3KcKsn1hZNtXW5Y+uLFoU1Jk6e3J1c9js= 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 SN1PR12MB2461.namprd12.prod.outlook.com (2603:10b6:802:27::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Wed, 26 Aug 2020 19:14:01 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:14:01 +0000 Subject: [PATCH v5 02/12] KVM: SVM: Change intercept_cr to generic intercepts From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:13:59 -0500 Message-ID: <159846923918.18873.8521340533771523718.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR13CA0024.namprd13.prod.outlook.com (2603:10b6:3:23::34) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM5PR13CA0024.namprd13.prod.outlook.com (2603:10b6:3:23::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.10 via Frontend Transport; Wed, 26 Aug 2020 19:14:00 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f6163e3d-4cc7-416f-7a63-08d849f430ba X-MS-TrafficTypeDiagnostic: SN1PR12MB2461: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VhW4S5LMDrOifx4VYXmKCjdHmRr8WwhIAsvSOja0/T6G17xF3tsfwXcmUgvTm4CcW3kNhI5TVMrbPaqDgaKu9PWs7dfpni83I6x8xZ2EW/GBwfFrJBMI+sqixXW0njp1Irs32ioyVwHSRY3LWeIu+UF6p0PbfmLAzuJApOOQwTwMQh1PfziEgtV9c0x0yNpPc8FtFpJTx1gyr2kwXMEJcHodMUGZ1Bxn3oleNzU4Z3Wjp3cNKzwE57de7eqx67ZIo8Oa2X1ofjF9AXgdrM8tn5aIkb4PPe5f69rkyWLj2mvqUaFGVgDKnWUwIKw5/0Sgzl+1c8q7yQayvBhDx94k2LY3jNEbpJoRqTDnvjgS0x/KluMZIwKTwnrc1gNyH6Y3 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:(7916004)(4636009)(346002)(376002)(136003)(39860400002)(396003)(366004)(956004)(44832011)(66556008)(8936002)(66946007)(66476007)(16576012)(9686003)(7416002)(26005)(478600001)(6486002)(186003)(86362001)(52116002)(8676002)(316002)(5660300002)(4326008)(83380400001)(2906002)(33716001)(103116003)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mT3yP7HC1Lzzj6Bp3fY2mXgF6CsnFSvx+Y1ZENiSahmITkaSyC5UInTCbTngEsu5m+58wIP15sCON5SKNZiO1xesq9Cmu3YWi6twmMVRXjQEC6s0tqKHC7uVN3g+Yb1LjbfeaBo1VPH+bTOoUCCiAZto0ezPKs7yYtz0Lv5hANPyeP6mIpDJ4oS9eYLKjTZONWBU87FD93nPx5jHmhfejp5Vbjnb7hiBXdmoq1gcFxZLC0wpQWIV1kucIbF7IGWzmxL1OwxXflLQCghRghDD8DDdZTeG5YeJGu6ckGUGy4mZuuUpOgAAM/0vLO78TU374jIRTIXXM7B60pNZLFf3Vl/DMVy6bsg25fMo0hD5FaXlGLJu/dsPdZ4GjZ1ifnIzuo40cfi6X7+4Ioua0n+PHFdVICenZmP2g2eDbMa7ElKu1zrkINeKGlZZ9tceZblg4RXEkDjK4dDDY96Ycl72g9Rz7kU8mN2H54xDK6cvV0pgkbkIWFO4eMwPNibPHf+lBj9kjB4dOKkjxsW0V6MVvqTaSkB/gaGqj6uZTDVn76QJA5OKjSsrxTWrRgaCpLI/xd74tIt8Kxr6CJ/fx7SPkjP15No4dDJWUpgpXA0JRiIzwQrHu6y451YaPr1r5A7k1OPyrVaJy5sVOgon4iRkwg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6163e3d-4cc7-416f-7a63-08d849f430ba X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:14:01.2789 (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: fZ1HvVu3xq3NxRD4HOp3Sk00jxgn/CYXelECoCJFvChz8QpKm1udlx8t8IZTkgGd X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2461 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Change intercept_cr to generic intercepts in vmcb_control_area. Use the new vmcb_set_intercept, vmcb_clr_intercept and vmcb_is_intercept where applicable. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/include/asm/svm.h | 42 ++++++++++++++++++++++++++++++++---------- arch/x86/kvm/svm/nested.c | 26 +++++++++++++++++--------- arch/x86/kvm/svm/svm.c | 4 ++-- arch/x86/kvm/svm/svm.h | 12 ++++++------ 4 files changed, 57 insertions(+), 27 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 8a1f5382a4ea..d4739f4eae63 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -4,6 +4,37 @@ #include +/* + * VMCB Control Area intercept bits starting + * at Byte offset 000h (Vector 0). + */ + +enum vector_offset { + CR_VECTOR = 0, + MAX_VECTORS, +}; + +enum { + /* Byte offset 000h (Vector 0) */ + INTERCEPT_CR0_READ = 0, + INTERCEPT_CR1_READ, + INTERCEPT_CR2_READ, + INTERCEPT_CR3_READ, + INTERCEPT_CR4_READ, + INTERCEPT_CR5_READ, + INTERCEPT_CR6_READ, + INTERCEPT_CR7_READ, + INTERCEPT_CR8_READ, + INTERCEPT_CR0_WRITE = 16, + INTERCEPT_CR1_WRITE, + INTERCEPT_CR2_WRITE, + INTERCEPT_CR3_WRITE, + INTERCEPT_CR4_WRITE, + INTERCEPT_CR5_WRITE, + INTERCEPT_CR6_WRITE, + INTERCEPT_CR7_WRITE, + INTERCEPT_CR8_WRITE, +}; enum { INTERCEPT_INTR, @@ -57,7 +88,7 @@ enum { struct __attribute__ ((__packed__)) vmcb_control_area { - u32 intercept_cr; + u32 intercepts[MAX_VECTORS]; u32 intercept_dr; u32 intercept_exceptions; u64 intercept; @@ -240,15 +271,6 @@ struct __attribute__ ((__packed__)) vmcb { #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK #define SVM_SELECTOR_CODE_MASK (1 << 3) -#define INTERCEPT_CR0_READ 0 -#define INTERCEPT_CR3_READ 3 -#define INTERCEPT_CR4_READ 4 -#define INTERCEPT_CR8_READ 8 -#define INTERCEPT_CR0_WRITE (16 + 0) -#define INTERCEPT_CR3_WRITE (16 + 3) -#define INTERCEPT_CR4_WRITE (16 + 4) -#define INTERCEPT_CR8_WRITE (16 + 8) - #define INTERCEPT_DR0_READ 0 #define INTERCEPT_DR1_READ 1 #define INTERCEPT_DR2_READ 2 diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index fb68467e6049..5f65b759abcb 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -98,6 +98,7 @@ static void nested_svm_uninit_mmu_context(struct kvm_vcpu *vcpu) void recalc_intercepts(struct vcpu_svm *svm) { struct vmcb_control_area *c, *h, *g; + unsigned int i; vmcb_mark_dirty(svm->vmcb, VMCB_INTERCEPTS); @@ -110,15 +111,17 @@ void recalc_intercepts(struct vcpu_svm *svm) svm->nested.host_intercept_exceptions = h->intercept_exceptions; - c->intercept_cr = h->intercept_cr; + for (i = 0; i < MAX_VECTORS; i++) + c->intercepts[i] = h->intercepts[i]; + c->intercept_dr = h->intercept_dr; c->intercept_exceptions = h->intercept_exceptions; c->intercept = h->intercept; if (g->int_ctl & V_INTR_MASKING_MASK) { /* We only want the cr8 intercept bits of L1 */ - c->intercept_cr &= ~(1U << INTERCEPT_CR8_READ); - c->intercept_cr &= ~(1U << INTERCEPT_CR8_WRITE); + vmcb_clr_intercept(c, INTERCEPT_CR8_READ); + vmcb_clr_intercept(c, INTERCEPT_CR8_WRITE); /* * Once running L2 with HF_VINTR_MASK, EFLAGS.IF does not @@ -131,7 +134,9 @@ void recalc_intercepts(struct vcpu_svm *svm) /* We don't want to see VMMCALLs from a nested guest */ c->intercept &= ~(1ULL << INTERCEPT_VMMCALL); - c->intercept_cr |= g->intercept_cr; + for (i = 0; i < MAX_VECTORS; i++) + c->intercepts[i] |= g->intercepts[i]; + c->intercept_dr |= g->intercept_dr; c->intercept_exceptions |= g->intercept_exceptions; c->intercept |= g->intercept; @@ -140,7 +145,11 @@ void recalc_intercepts(struct vcpu_svm *svm) static void copy_vmcb_control_area(struct vmcb_control_area *dst, struct vmcb_control_area *from) { - dst->intercept_cr = from->intercept_cr; + unsigned int i; + + for (i = 0; i < MAX_VECTORS; i++) + dst->intercepts[i] = from->intercepts[i]; + dst->intercept_dr = from->intercept_dr; dst->intercept_exceptions = from->intercept_exceptions; dst->intercept = from->intercept; @@ -487,8 +496,8 @@ int nested_svm_vmrun(struct vcpu_svm *svm) nested_vmcb->control.event_inj, nested_vmcb->control.nested_ctl); - trace_kvm_nested_intercepts(nested_vmcb->control.intercept_cr & 0xffff, - nested_vmcb->control.intercept_cr >> 16, + trace_kvm_nested_intercepts(nested_vmcb->control.intercepts[CR_VECTOR] & 0xffff, + nested_vmcb->control.intercepts[CR_VECTOR] >> 16, nested_vmcb->control.intercept_exceptions, nested_vmcb->control.intercept); @@ -765,8 +774,7 @@ static int nested_svm_intercept(struct vcpu_svm *svm) vmexit = nested_svm_intercept_ioio(svm); break; case SVM_EXIT_READ_CR0 ... SVM_EXIT_WRITE_CR8: { - u32 bit = 1U << (exit_code - SVM_EXIT_READ_CR0); - if (svm->nested.ctl.intercept_cr & bit) + if (vmcb_is_intercept(&svm->nested.ctl, exit_code)) vmexit = NESTED_EXIT_DONE; break; } diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 03dd7bac8034..523936b80dda 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2813,8 +2813,8 @@ static void dump_vmcb(struct kvm_vcpu *vcpu) } pr_err("VMCB Control Area:\n"); - pr_err("%-20s%04x\n", "cr_read:", control->intercept_cr & 0xffff); - pr_err("%-20s%04x\n", "cr_write:", control->intercept_cr >> 16); + pr_err("%-20s%04x\n", "cr_read:", control->intercepts[CR_VECTOR] & 0xffff); + pr_err("%-20s%04x\n", "cr_write:", control->intercepts[CR_VECTOR] >> 16); pr_err("%-20s%04x\n", "dr_read:", control->intercept_dr & 0xffff); pr_err("%-20s%04x\n", "dr_write:", control->intercept_dr >> 16); pr_err("%-20s%08x\n", "exceptions:", control->intercept_exceptions); diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 1cff7644e70b..e775c502a074 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -216,24 +216,24 @@ static inline struct vmcb *get_host_vmcb(struct vcpu_svm *svm) static inline void vmcb_set_intercept(struct vmcb_control_area *control, int bit) { - __set_bit(bit, (unsigned long *)&control->intercept_cr); + __set_bit(bit, (unsigned long *)&control->intercepts); } static inline void vmcb_clr_intercept(struct vmcb_control_area *control, int bit) { - __clear_bit(bit, (unsigned long *)&control->intercept_cr); + __clear_bit(bit, (unsigned long *)&control->intercepts); } static inline bool vmcb_is_intercept(struct vmcb_control_area *control, int bit) { - return test_bit(bit, (unsigned long *)&control->intercept_cr); + return test_bit(bit, (unsigned long *)&control->intercepts); } static inline void set_cr_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); - vmcb->control.intercept_cr |= (1U << bit); + vmcb_set_intercept(&vmcb->control, bit); recalc_intercepts(svm); } @@ -242,7 +242,7 @@ static inline void clr_cr_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); - vmcb->control.intercept_cr &= ~(1U << bit); + vmcb_clr_intercept(&vmcb->control, bit); recalc_intercepts(svm); } @@ -251,7 +251,7 @@ static inline bool is_cr_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); - return vmcb->control.intercept_cr & (1U << bit); + return vmcb_is_intercept(&vmcb->control, bit); } static inline void set_dr_intercepts(struct vcpu_svm *svm) From patchwork Wed Aug 26 19:14:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739531 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 936D013A4 for ; Wed, 26 Aug 2020 19:14:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70680207BC for ; Wed, 26 Aug 2020 19:14:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="fvsKoVJn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727807AbgHZTOY (ORCPT ); Wed, 26 Aug 2020 15:14:24 -0400 Received: from mail-eopbgr770055.outbound.protection.outlook.com ([40.107.77.55]:31745 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727813AbgHZTON (ORCPT ); Wed, 26 Aug 2020 15:14:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TbAKKOGaHYt0Q8TWZVLw4LQgI0Tkaya0CFab4ItrlP6/KazXZgve0DKu55iYKFJgu4ZcZtvtQjyRTgQiJXAMrOsXpm0eEDum9hzyPZm+H9ydWjMwv4PJ1JegnT9qMm2bVyaxSDW+0SH5Hn83k8Ohi8VGNfHpfErm25vGm8ycjn1XK9Ac4wvNszDUwnyEQz2CE4gc9uPHQbIi2oqStul9G+uyHMQ9h0zEfeQb4MMuaJTjk1to9KcBLvf6hUbau9Ejmdf0kShNPBkw2AIqyW0WMMCsFLIJdk5/3ckR8HgZeEdUaAyHNvrvNL/kw7LG3Yd+Yzbe4k3QgKkudcIIE3ktMw== 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=Bckht8T8MtG8i/+MDkmslAfdqqqLtYTbpiPUur41qhk=; b=VWwTs6KpQ7+fZ7OmBjT7dVR0f/RWgAnPKbJF9FEZl6R2mYa2CnXHJatlhAwaBL6KzEYLtA0Ww3X5dvtvEOQPv77KsPidfwzdF7y9aRr+fuQCvICd+TcV39xix7clUaMKvuCyYZpKIijs5GLMM8zwjj/wXp7/TLyuk6AwSzo+9Q32hOXZ/mxJxXkutezMU3PBk0yUgkw8g2KK4EShjDHk0pEkC7UB+crGaSe94WHTw6YMJiHEm5IjIdfBGvx8RJGse8OnpdroZJBBPQU1fRNtuHhy+9s+mu0of8sjRAWKf5uFV6oBitxikoycT/K1T7quSm2xVZZKPeL3UqsbiDPoYA== 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=Bckht8T8MtG8i/+MDkmslAfdqqqLtYTbpiPUur41qhk=; b=fvsKoVJn9HrIBdGgq6h7bkfKH6iwFLrfpQ0TRKRUTocfvF70C4COIJONVSYRaj6M7+IK+lhcQXHBr0a8UliksOsx1p7qfpq60Ol5K8WW0nVVT3IoE3Pbw+EShjRkSODx4iYoieObuVEPW+Xq+2l41s+veXc4tKp0UExjakA0124= 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 SN1PR12MB2384.namprd12.prod.outlook.com (2603:10b6:802:25::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Wed, 26 Aug 2020 19:14:09 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:14:09 +0000 Subject: [PATCH v5 03/12] KVM: SVM: Change intercept_dr to generic intercepts From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:14:06 -0500 Message-ID: <159846924650.18873.2599714820148493539.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR18CA0079.namprd18.prod.outlook.com (2603:10b6:3:3::17) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM5PR18CA0079.namprd18.prod.outlook.com (2603:10b6:3:3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:14:07 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b259a83e-3a1a-4b12-0fd8-08d849f43556 X-MS-TrafficTypeDiagnostic: SN1PR12MB2384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xQSYsGvg0LL7yBA9smwKohORBTcOZJfxX2M9WLrF06km4VTU3pve9DxGAtYp7VpzGHXGDST8w7akvU22GneIqjHN6Gd+lhP8p79E+Dmy2LoDV0OEwYF4+IFCho0GwfltHN6I6VPDbPMOgSJT10Ku4thJ5q7q24psU6qrWuzBWLmYd51hNAu7aRUnFbdnpzgzHbwJNLYOV++XT1K3lsA+XAAOvfkGqPNAtZMc9z77xvipA4SmaKew1JVTDPiVgK11c+lyygmAdS6RtAAIa7JfHWOCGNWBgPn59929Or1F3h8h0lc9lnTVzpmGt37lUXC6HN3IgEjYDuXX488pfyEnzlc2k1cOY2RsGb3Wh1j/2xxjmRGyIAR+Df36pxuf6Azb 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)(366004)(136003)(376002)(396003)(39860400002)(103116003)(4326008)(186003)(66946007)(5660300002)(66476007)(66556008)(44832011)(86362001)(33716001)(9686003)(52116002)(7416002)(83380400001)(6486002)(8936002)(8676002)(16576012)(2906002)(316002)(26005)(478600001)(956004)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 64tfhUfbdqs3Bu2zvi0v63Kk3DkGy6ea11/3wc8FT/KfxWr6eYrf0R2H5nFmsZ1ZuiB8cL4sAjGmyY233ol38vR/KhBSCuS3FNpvuWy8FWAaICklVydsdJSkOk383jbRQ7x5qFCC489JHw0O6LJJdndFHXEWtDgtKiNVGuG9X2Axd/8s2Pt+qb24SY5V5W677UUDRJ61Yp2LBVrqqwnCkyOe9YFET0/CE38RkVb4tRua9YX24FHoSali1IKVxrLSupbCO1LFfx4IBLgAktNnToGnQjtB2lKUgJzgk5jEh7S/1U4TuiF1eCpPpeQaCSusiEHWKl1oe72WJYRU6N/VdT8/+ciSPpvkULA/GIcG/TVFH9sQoe3UeYaKtQ4eCzixwiOl0Ra89ZgWQD00FFhdckoq/dpaXOJM2uyzCgr838zA1OoIUqBmTQ/oGKb5KtkzbFZCk8cr0lkmaKH9h/r6sTMnm7yY3pglAuFOLUS/6OfWse0hJziUW25E0Qi9sHdxL55XaNNPogj+R7hhQx/vw4pzmd+El979uUF5VHef8x5PsyAHUPYBztBJANOu+9b05u7Miu7KkZNpFxBG0vgiBLTCD0+/s4hdl1iPTbk2x7iVSjsxAjIgKhcpHJYYaNTm+3XwT3cJ8duo7xgw02kEgg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b259a83e-3a1a-4b12-0fd8-08d849f43556 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:14:09.0414 (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: dyomhryTBUOxBvOoOd6/JlXvpCoLN7y5b2AAigOdR1M/dm8TG2eU9G2YeTqVQJX9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2384 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Modify intercept_dr to generic intercepts in vmcb_control_area. Use the generic vmcb_set_intercept, vmcb_clr_intercept and vmcb_is_intercept to set/clear/test the intercept_dr bits. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/include/asm/svm.h | 36 ++++++++++++++++++------------------ arch/x86/kvm/svm/nested.c | 6 +----- arch/x86/kvm/svm/svm.c | 4 ++-- arch/x86/kvm/svm/svm.h | 34 +++++++++++++++++----------------- 4 files changed, 38 insertions(+), 42 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index d4739f4eae63..ffc89d8e4fcb 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -11,6 +11,7 @@ enum vector_offset { CR_VECTOR = 0, + DR_VECTOR, MAX_VECTORS, }; @@ -34,6 +35,23 @@ enum { INTERCEPT_CR6_WRITE, INTERCEPT_CR7_WRITE, INTERCEPT_CR8_WRITE, + /* Byte offset 004h (Vector 1) */ + INTERCEPT_DR0_READ = 32, + INTERCEPT_DR1_READ, + INTERCEPT_DR2_READ, + INTERCEPT_DR3_READ, + INTERCEPT_DR4_READ, + INTERCEPT_DR5_READ, + INTERCEPT_DR6_READ, + INTERCEPT_DR7_READ, + INTERCEPT_DR0_WRITE = 48, + INTERCEPT_DR1_WRITE, + INTERCEPT_DR2_WRITE, + INTERCEPT_DR3_WRITE, + INTERCEPT_DR4_WRITE, + INTERCEPT_DR5_WRITE, + INTERCEPT_DR6_WRITE, + INTERCEPT_DR7_WRITE, }; enum { @@ -89,7 +107,6 @@ enum { struct __attribute__ ((__packed__)) vmcb_control_area { u32 intercepts[MAX_VECTORS]; - u32 intercept_dr; u32 intercept_exceptions; u64 intercept; u8 reserved_1[40]; @@ -271,23 +288,6 @@ struct __attribute__ ((__packed__)) vmcb { #define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK #define SVM_SELECTOR_CODE_MASK (1 << 3) -#define INTERCEPT_DR0_READ 0 -#define INTERCEPT_DR1_READ 1 -#define INTERCEPT_DR2_READ 2 -#define INTERCEPT_DR3_READ 3 -#define INTERCEPT_DR4_READ 4 -#define INTERCEPT_DR5_READ 5 -#define INTERCEPT_DR6_READ 6 -#define INTERCEPT_DR7_READ 7 -#define INTERCEPT_DR0_WRITE (16 + 0) -#define INTERCEPT_DR1_WRITE (16 + 1) -#define INTERCEPT_DR2_WRITE (16 + 2) -#define INTERCEPT_DR3_WRITE (16 + 3) -#define INTERCEPT_DR4_WRITE (16 + 4) -#define INTERCEPT_DR5_WRITE (16 + 5) -#define INTERCEPT_DR6_WRITE (16 + 6) -#define INTERCEPT_DR7_WRITE (16 + 7) - #define SVM_EVTINJ_VEC_MASK 0xff #define SVM_EVTINJ_TYPE_SHIFT 8 diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 5f65b759abcb..ba11fc3bf843 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -114,7 +114,6 @@ void recalc_intercepts(struct vcpu_svm *svm) for (i = 0; i < MAX_VECTORS; i++) c->intercepts[i] = h->intercepts[i]; - c->intercept_dr = h->intercept_dr; c->intercept_exceptions = h->intercept_exceptions; c->intercept = h->intercept; @@ -137,7 +136,6 @@ void recalc_intercepts(struct vcpu_svm *svm) for (i = 0; i < MAX_VECTORS; i++) c->intercepts[i] |= g->intercepts[i]; - c->intercept_dr |= g->intercept_dr; c->intercept_exceptions |= g->intercept_exceptions; c->intercept |= g->intercept; } @@ -150,7 +148,6 @@ static void copy_vmcb_control_area(struct vmcb_control_area *dst, for (i = 0; i < MAX_VECTORS; i++) dst->intercepts[i] = from->intercepts[i]; - dst->intercept_dr = from->intercept_dr; dst->intercept_exceptions = from->intercept_exceptions; dst->intercept = from->intercept; dst->iopm_base_pa = from->iopm_base_pa; @@ -779,8 +776,7 @@ static int nested_svm_intercept(struct vcpu_svm *svm) break; } case SVM_EXIT_READ_DR0 ... SVM_EXIT_WRITE_DR7: { - u32 bit = 1U << (exit_code - SVM_EXIT_READ_DR0); - if (svm->nested.ctl.intercept_dr & bit) + if (vmcb_is_intercept(&svm->nested.ctl, exit_code)) vmexit = NESTED_EXIT_DONE; break; } diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 523936b80dda..1a5f3908b388 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2815,8 +2815,8 @@ static void dump_vmcb(struct kvm_vcpu *vcpu) pr_err("VMCB Control Area:\n"); pr_err("%-20s%04x\n", "cr_read:", control->intercepts[CR_VECTOR] & 0xffff); pr_err("%-20s%04x\n", "cr_write:", control->intercepts[CR_VECTOR] >> 16); - pr_err("%-20s%04x\n", "dr_read:", control->intercept_dr & 0xffff); - pr_err("%-20s%04x\n", "dr_write:", control->intercept_dr >> 16); + pr_err("%-20s%04x\n", "dr_read:", control->intercepts[DR_VECTOR] & 0xffff); + pr_err("%-20s%04x\n", "dr_write:", control->intercepts[DR_VECTOR] >> 16); pr_err("%-20s%08x\n", "exceptions:", control->intercept_exceptions); pr_err("%-20s%016llx\n", "intercepts:", control->intercept); pr_err("%-20s%d\n", "pause filter count:", control->pause_filter_count); diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index e775c502a074..d3b34e0276c5 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -258,22 +258,22 @@ static inline void set_dr_intercepts(struct vcpu_svm *svm) { struct vmcb *vmcb = get_host_vmcb(svm); - vmcb->control.intercept_dr = (1 << INTERCEPT_DR0_READ) - | (1 << INTERCEPT_DR1_READ) - | (1 << INTERCEPT_DR2_READ) - | (1 << INTERCEPT_DR3_READ) - | (1 << INTERCEPT_DR4_READ) - | (1 << INTERCEPT_DR5_READ) - | (1 << INTERCEPT_DR6_READ) - | (1 << INTERCEPT_DR7_READ) - | (1 << INTERCEPT_DR0_WRITE) - | (1 << INTERCEPT_DR1_WRITE) - | (1 << INTERCEPT_DR2_WRITE) - | (1 << INTERCEPT_DR3_WRITE) - | (1 << INTERCEPT_DR4_WRITE) - | (1 << INTERCEPT_DR5_WRITE) - | (1 << INTERCEPT_DR6_WRITE) - | (1 << INTERCEPT_DR7_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR0_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR1_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR2_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR3_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR4_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR5_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR6_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR0_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR1_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR2_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR3_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR4_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR5_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR6_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_WRITE); recalc_intercepts(svm); } @@ -282,7 +282,7 @@ static inline void clr_dr_intercepts(struct vcpu_svm *svm) { struct vmcb *vmcb = get_host_vmcb(svm); - vmcb->control.intercept_dr = 0; + vmcb->control.intercepts[DR_VECTOR] = 0; recalc_intercepts(svm); } From patchwork Wed Aug 26 19:14:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739549 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A9B514E5 for ; Wed, 26 Aug 2020 19:16:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 482ED207F7 for ; Wed, 26 Aug 2020 19:16:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="1L2ObYWs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727973AbgHZTPv (ORCPT ); Wed, 26 Aug 2020 15:15:51 -0400 Received: from mail-eopbgr770078.outbound.protection.outlook.com ([40.107.77.78]:17060 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727839AbgHZTPs (ORCPT ); Wed, 26 Aug 2020 15:15:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YnYrpGCGE7Uis/Nf/Df73147cbwGO7WM+FYm3b4GBlr/ZJiIK9SWb6bSPDnUX0ZeIVD88mdQdvN8A3EzreVasOe/kNyXn51mq/ykl4orRFB96nJT/diVTvGvNRpD8AXFLROKcllZa4Y2DH/GSprwUOKQHy2IPFyDRqbVOtFHzWozMVSOD90Hxb0ybHrR8FdtrQji03Na44+FVrPkOKvbTjKg0pJNW7xDpTveKwXZ//STeIcabVMhbZYdXUcoPgjU3Ekg6WaJKjX5TaJukzSZBOoGIW1Rcnkg/0/eqOWDnkgBCtdLhrepPooHPjUlefNtAoGVSpBnDKYvUtA2blvGdg== 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=/iuhytloBtnaKsztjIqH3ytB44RmUMXEQwPPBKhD3vE=; b=QXQBjVExXUlkZNyXyl/FK5OPpmI7+YZgfjC+WENdEi2Mlv2wMcNYPLAX4PHx/GAPPRCh2WeIZagjm35f8gMGkUibaSNIE/PiJbe3Os8rNej7/ENCuTJOsATs+SXvn9BepjuNrijFx/NwJDCk8Bx1V0ygqB5osTQ6l6uSIDOTjXT80U5ac2zb2HvVC7722/ZXsn6GqDOeSs/AYZ4MDPYfypohRoXBU5hO/HUjLfIqEKuN0ocx30/PbfyQJHvTD1sURK2W8us2Q1iO0j4wFiCMZj8katTcb5Kw6qWNJN6n/2p9bVrbMVaIow7imMagRNAP6wMsyk2m/Jgp9vIl6Xr67Q== 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=/iuhytloBtnaKsztjIqH3ytB44RmUMXEQwPPBKhD3vE=; b=1L2ObYWsEYui4KA4TX+kmj0O4eOec1xa10t+9GS6lPvQfgxvCOrYPSEf9CxQYvdAE+EGJrj6xPNaJ9SQLEtIQHajROFwQI+PCq9kX3SLrbiriNpuyJHfIqyDgK8YSnwr7jUW9GTtnOpLayIoTz2N0t9MgAVybzEnW9iCWZtmLuw= 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 SN1PR12MB2384.namprd12.prod.outlook.com (2603:10b6:802:25::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Wed, 26 Aug 2020 19:14:17 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:14:17 +0000 Subject: [PATCH v5 04/12] KVM: SVM: Modify intercept_exceptions to generic intercepts From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:14:14 -0500 Message-ID: <159846925426.18873.12673817778834207178.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM6PR03CA0004.namprd03.prod.outlook.com (2603:10b6:5:40::17) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM6PR03CA0004.namprd03.prod.outlook.com (2603:10b6:5:40::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:14:16 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5f7070dc-c365-4888-cba1-08d849f43a74 X-MS-TrafficTypeDiagnostic: SN1PR12MB2384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Yatw7g+RgDlKxNMqgsrKHIU04/SIDQNZ0k6uzcs8zewQMRGK0+M7wIDVvp/z5ddqarUk2itKcWx5T54thj/wL3VmfPtBfXkNcbqJYfE4/nk0/TQQMKzj1bGLs1JYMeJNoyYERis2scB7tRJREC+7+CjGWl/JfeddXyEx11Wk8yUJad8IRERx5zmk+h4+qZgQWh2BwNgGzwkMXQX3I5AlKPiui7TQ/lYJMaZa6+zLVAJiNgpS0NNGf182usUxVkNa8lCaeRA/YfzBNts1feSQJb8oidQUrOKBfhEz3hWSkn33gYCTnhfgVsOrCVD0EEN+jnhgpfel3u/CWLzJ2btnZxxsWyYySiGWbwW5iBhmtVbsUAr5+lXNKsL+Ojmy4DBU 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)(366004)(136003)(376002)(396003)(39860400002)(103116003)(4326008)(186003)(66946007)(5660300002)(66476007)(66556008)(44832011)(86362001)(33716001)(9686003)(52116002)(7416002)(83380400001)(6486002)(8936002)(8676002)(16576012)(2906002)(316002)(26005)(478600001)(956004)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 71t1I7s+Yr/q0IA3C9OhQgiycxGsUaQ9tlptvbhPuEni2p3B5yjUS4rhv/BKY+hxh2jjAsg88p1osfNsFRIrv5novUIT+2TMHxyO0cs3H73tbFVkqhRy0NLUhb+3/N6ELCy0EsZ6OowcKqyw++Qi3dtTAdNbY6Jml83OOlmbEkdUr2EETPYdajotWqg4uozF2hbvRso6fRSuQy09indFX6capDb37akasq5NgU4VywRZF84SBY6BjIoC0ZxTRLu7U7at6pZmVrfmp+q2tojrjhfkMQBxrexRUB0pc4bm2cuZ6nTn2oU+sLoZOl2m2zIXQHXmatUSZmOk6cqwcBieoeJYriZEVXG6i03Sq8piwx/I11mptG2JqhmSRxJ9JPQDiAZXyLKfGfq61ToW/ms0L0qV/8bfwinloGSLLK79cFO55oitGETwWXun3XdPXIyNQ23B9lRKeXfa9HRJlgwaNiYvqhCMf1Ft6vZtSHHdvshvUrrrpAXDZjVSDt/j17Gz1D4UpZQ5vFM2T1rtSbqxAsluQAb+mNZbpI2q4pJf8T6x8r0a8qtOsvX29CR7utzv728FeVOStyKk7g5tgoZPBm0FT+5HhBw8LKffV9r8yDbC1lDlmz3srZ0sHbuq4FZAThQ1eD4SFvxXw5YrpxL/qQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f7070dc-c365-4888-cba1-08d849f43a74 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:14:17.6154 (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: d36fe4fBLYlcKC/CdB2ifvHJ1sWboiNXch1VeOe41fdvUvM2xPMalUSW5g33JMVI X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2384 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Modify intercept_exceptions to generic intercepts in vmcb_control_area. Use the generic vmcb_set_intercept, vmcb_clr_intercept and vmcb_is_intercept to set/clear/test the intercept_exceptions bits. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/include/asm/svm.h | 22 +++++++++++++++++++++- arch/x86/kvm/svm/nested.c | 12 +++++------- arch/x86/kvm/svm/svm.c | 22 +++++++++++----------- arch/x86/kvm/svm/svm.h | 4 ++-- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index ffc89d8e4fcb..51833a611eba 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -3,6 +3,7 @@ #define __SVM_H #include +#include /* * VMCB Control Area intercept bits starting @@ -12,6 +13,7 @@ enum vector_offset { CR_VECTOR = 0, DR_VECTOR, + EXCEPTION_VECTOR, MAX_VECTORS, }; @@ -52,6 +54,25 @@ enum { INTERCEPT_DR5_WRITE, INTERCEPT_DR6_WRITE, INTERCEPT_DR7_WRITE, + /* Byte offset 008h (Vector 2) */ + INTERCEPT_DE_VECTOR = 64 + DE_VECTOR, + INTERCEPT_DB_VECTOR = 64 + DB_VECTOR, + INTERCEPT_BP_VECTOR = 64 + BP_VECTOR, + INTERCEPT_OF_VECTOR = 64 + OF_VECTOR, + INTERCEPT_BR_VECTOR = 64 + BR_VECTOR, + INTERCEPT_UD_VECTOR = 64 + UD_VECTOR, + INTERCEPT_NM_VECTOR = 64 + NM_VECTOR, + INTERCEPT_DF_VECTOR = 64 + DF_VECTOR, + INTERCEPT_TS_VECTOR = 64 + TS_VECTOR, + INTERCEPT_NP_VECTOR = 64 + NP_VECTOR, + INTERCEPT_SS_VECTOR = 64 + SS_VECTOR, + INTERCEPT_GP_VECTOR = 64 + GP_VECTOR, + INTERCEPT_PF_VECTOR = 64 + PF_VECTOR, + INTERCEPT_MF_VECTOR = 64 + MF_VECTOR, + INTERCEPT_AC_VECTOR = 64 + AC_VECTOR, + INTERCEPT_MC_VECTOR = 64 + MC_VECTOR, + INTERCEPT_XM_VECTOR = 64 + XM_VECTOR, + INTERCEPT_VE_VECTOR = 64 + VE_VECTOR, }; enum { @@ -107,7 +128,6 @@ enum { struct __attribute__ ((__packed__)) vmcb_control_area { u32 intercepts[MAX_VECTORS]; - u32 intercept_exceptions; u64 intercept; u8 reserved_1[40]; u16 pause_filter_thresh; diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index ba11fc3bf843..798ae2fabc74 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -109,12 +109,11 @@ void recalc_intercepts(struct vcpu_svm *svm) h = &svm->nested.hsave->control; g = &svm->nested.ctl; - svm->nested.host_intercept_exceptions = h->intercept_exceptions; + svm->nested.host_intercept_exceptions = h->intercepts[EXCEPTION_VECTOR]; for (i = 0; i < MAX_VECTORS; i++) c->intercepts[i] = h->intercepts[i]; - c->intercept_exceptions = h->intercept_exceptions; c->intercept = h->intercept; if (g->int_ctl & V_INTR_MASKING_MASK) { @@ -136,7 +135,6 @@ void recalc_intercepts(struct vcpu_svm *svm) for (i = 0; i < MAX_VECTORS; i++) c->intercepts[i] |= g->intercepts[i]; - c->intercept_exceptions |= g->intercept_exceptions; c->intercept |= g->intercept; } @@ -148,7 +146,6 @@ static void copy_vmcb_control_area(struct vmcb_control_area *dst, for (i = 0; i < MAX_VECTORS; i++) dst->intercepts[i] = from->intercepts[i]; - dst->intercept_exceptions = from->intercept_exceptions; dst->intercept = from->intercept; dst->iopm_base_pa = from->iopm_base_pa; dst->msrpm_base_pa = from->msrpm_base_pa; @@ -495,7 +492,7 @@ int nested_svm_vmrun(struct vcpu_svm *svm) trace_kvm_nested_intercepts(nested_vmcb->control.intercepts[CR_VECTOR] & 0xffff, nested_vmcb->control.intercepts[CR_VECTOR] >> 16, - nested_vmcb->control.intercept_exceptions, + nested_vmcb->control.intercepts[EXCEPTION_VECTOR], nested_vmcb->control.intercept); /* Clear internal status */ @@ -835,7 +832,7 @@ static bool nested_exit_on_exception(struct vcpu_svm *svm) { unsigned int nr = svm->vcpu.arch.exception.nr; - return (svm->nested.ctl.intercept_exceptions & (1 << nr)); + return (svm->nested.ctl.intercepts[EXCEPTION_VECTOR] & (1 << nr)); } static void nested_svm_inject_exception_vmexit(struct vcpu_svm *svm) @@ -984,7 +981,8 @@ int nested_svm_exit_special(struct vcpu_svm *svm) case SVM_EXIT_EXCP_BASE ... SVM_EXIT_EXCP_BASE + 0x1f: { u32 excp_bits = 1 << (exit_code - SVM_EXIT_EXCP_BASE); - if (get_host_vmcb(svm)->control.intercept_exceptions & excp_bits) + if (get_host_vmcb(svm)->control.intercepts[EXCEPTION_VECTOR] & + excp_bits) return NESTED_EXIT_HOST; else if (exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR && svm->vcpu.arch.apf.host_apf_flags) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 1a5f3908b388..11892e86cb39 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1003,11 +1003,11 @@ static void init_vmcb(struct vcpu_svm *svm) set_dr_intercepts(svm); - set_exception_intercept(svm, PF_VECTOR); - set_exception_intercept(svm, UD_VECTOR); - set_exception_intercept(svm, MC_VECTOR); - set_exception_intercept(svm, AC_VECTOR); - set_exception_intercept(svm, DB_VECTOR); + set_exception_intercept(svm, INTERCEPT_PF_VECTOR); + set_exception_intercept(svm, INTERCEPT_UD_VECTOR); + set_exception_intercept(svm, INTERCEPT_MC_VECTOR); + set_exception_intercept(svm, INTERCEPT_AC_VECTOR); + set_exception_intercept(svm, INTERCEPT_DB_VECTOR); /* * Guest access to VMware backdoor ports could legitimately * trigger #GP because of TSS I/O permission bitmap. @@ -1015,7 +1015,7 @@ static void init_vmcb(struct vcpu_svm *svm) * as VMware does. */ if (enable_vmware_backdoor) - set_exception_intercept(svm, GP_VECTOR); + set_exception_intercept(svm, INTERCEPT_GP_VECTOR); svm_set_intercept(svm, INTERCEPT_INTR); svm_set_intercept(svm, INTERCEPT_NMI); @@ -1093,7 +1093,7 @@ static void init_vmcb(struct vcpu_svm *svm) /* Setup VMCB for Nested Paging */ control->nested_ctl |= SVM_NESTED_CTL_NP_ENABLE; svm_clr_intercept(svm, INTERCEPT_INVLPG); - clr_exception_intercept(svm, PF_VECTOR); + clr_exception_intercept(svm, INTERCEPT_PF_VECTOR); clr_cr_intercept(svm, INTERCEPT_CR3_READ); clr_cr_intercept(svm, INTERCEPT_CR3_WRITE); save->g_pat = svm->vcpu.arch.pat; @@ -1135,7 +1135,7 @@ static void init_vmcb(struct vcpu_svm *svm) if (sev_guest(svm->vcpu.kvm)) { svm->vmcb->control.nested_ctl |= SVM_NESTED_CTL_SEV_ENABLE; - clr_exception_intercept(svm, UD_VECTOR); + clr_exception_intercept(svm, INTERCEPT_UD_VECTOR); } vmcb_mark_all_dirty(svm->vmcb); @@ -1646,11 +1646,11 @@ static void update_exception_bitmap(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); - clr_exception_intercept(svm, BP_VECTOR); + clr_exception_intercept(svm, INTERCEPT_BP_VECTOR); if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) { if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) - set_exception_intercept(svm, BP_VECTOR); + set_exception_intercept(svm, INTERCEPT_BP_VECTOR); } } @@ -2817,7 +2817,7 @@ static void dump_vmcb(struct kvm_vcpu *vcpu) pr_err("%-20s%04x\n", "cr_write:", control->intercepts[CR_VECTOR] >> 16); pr_err("%-20s%04x\n", "dr_read:", control->intercepts[DR_VECTOR] & 0xffff); pr_err("%-20s%04x\n", "dr_write:", control->intercepts[DR_VECTOR] >> 16); - pr_err("%-20s%08x\n", "exceptions:", control->intercept_exceptions); + pr_err("%-20s%08x\n", "exceptions:", control->intercepts[EXCEPTION_VECTOR]); pr_err("%-20s%016llx\n", "intercepts:", control->intercept); pr_err("%-20s%d\n", "pause filter count:", control->pause_filter_count); pr_err("%-20s%d\n", "pause filter threshold:", diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index d3b34e0276c5..2fc305f647a3 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -291,7 +291,7 @@ static inline void set_exception_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); - vmcb->control.intercept_exceptions |= (1U << bit); + vmcb_set_intercept(&vmcb->control, bit); recalc_intercepts(svm); } @@ -300,7 +300,7 @@ static inline void clr_exception_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); - vmcb->control.intercept_exceptions &= ~(1U << bit); + vmcb_clr_intercept(&vmcb->control, bit); recalc_intercepts(svm); } From patchwork Wed Aug 26 19:14:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739533 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F13514E5 for ; Wed, 26 Aug 2020 19:14:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E02BA214F1 for ; Wed, 26 Aug 2020 19:14:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="E7ZlXrll" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727882AbgHZTOa (ORCPT ); Wed, 26 Aug 2020 15:14:30 -0400 Received: from mail-bn7nam10on2082.outbound.protection.outlook.com ([40.107.92.82]:51745 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726910AbgHZTO2 (ORCPT ); Wed, 26 Aug 2020 15:14:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h+0U2K3shNqNNVJxVZ2bkstU/TT0hVpRrnT/3aNmBR+9mtdjKXwQkqf9VNTcA+uokhW8ltGg9oM9ZrcroTLE0rsCub5zdWauwAS3+Z5XO0zK/gb6V9mC4P8exbfD2y4YBil4bRC/ETXxJdo49W+Sel4atlxGQJdPe0zH/mb/3xiIRdioMdfZoZcbzyJpoKkFQTLOWD8xXekmQV/yneA+7wOuf1dHIqnUtXr3Sz/LOu/GWxQXNn3zwZe4t2RoODsA4BRu7hMjJmnLPL993unnGnKYlr5/xJ+l/gnavcesze8Bu59iYGybFo1tN1G0HFu6tg5KguvMwUYA2suL8GDwYQ== 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=jRIsWxT0ILE3KT36R9KGtHzYCpDFmOG+Nwbu2l6CWZw=; b=aSu5ZfpqIwzBZqgOB/5gYNumhFWZ3WqaQKDo3G22THEdVhtXime6dyPpJ1kZkgfimU9ifTikxY8XanilGzeO1PpWi4o01pedfieCZJGSuE67MwilMKQPDo2ekSZ3Qr1PD50wqBLtxsHZunVf3INEo0pScMM0OBjoDBUPUgrXWBRvw+p12xLEELiEEE/YI9rywSG62RRkQccIoZyi3A0h0O7506+nFvTd6hY83XQmRZVdbqKIIFqpWGrhNhIGNTh1UN/1hVeHjYAW6LWsOFX5+3VH2h2dxA8NhvlzAhaXFmJlwm6o7UDiUaQ26Bv0sqEWMFlXrr5FjW/AXmqp6GqH1Q== 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=jRIsWxT0ILE3KT36R9KGtHzYCpDFmOG+Nwbu2l6CWZw=; b=E7ZlXrllwbdycdKn64pZxqOu//gcOvITzU3orNUDgNPlz52a7vsv5mJ/VCTitRnEw+PHjm00BBNlR5rhIy2NOqbBw38qhqp0KsV4YM0ARTGf6B3rNqVe7WCGKPx5Lq/HbXbs3899kmXNhuz7zFTOFSJiGjprsd+5QsfwaADGpT8= 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 SN1PR12MB2461.namprd12.prod.outlook.com (2603:10b6:802:27::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Wed, 26 Aug 2020 19:14:25 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:14:25 +0000 Subject: [PATCH v5 05/12] KVM: SVM: Modify 64 bit intercept field to two 32 bit vectors From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:14:22 -0500 Message-ID: <159846926282.18873.15781891247605539136.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM3PR11CA0022.namprd11.prod.outlook.com (2603:10b6:0:54::32) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM3PR11CA0022.namprd11.prod.outlook.com (2603:10b6:0:54::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:14:23 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 59d6b046-c014-493c-9c0b-08d849f43eed X-MS-TrafficTypeDiagnostic: SN1PR12MB2461: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2887; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nW6/6QBi2rxujD0LhCKriqExYnriBvsw4UoLfPRpyJqkAR5BtAK7gICoU59iq1rzdsMfy/aqJhZgCwvJfXLrbFM5A/NFYlwgfMDwkIRTjSntvdNxWKl8A0PAmzIwnk5erJXriMLT2jrdIogAj1tS4x84BiMHJm6AOUhLWQlHnRiT+RHLaHl3/t5miCzvKOEcwgzCRiSFEFUCZ494V4IQSa85DpzA4TVr44gESXt3HMW3JUVngau+lTJfKlmHz0mVMHTm3MuJXiSUX59JLUdM/QJjcwLDr//DrXeyICrJMgkKa0FSzzspm8wSxzgw6A1zFF7isDZrrlZ7cnhcU7UslA== 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:(7916004)(4636009)(346002)(376002)(136003)(39860400002)(396003)(366004)(956004)(44832011)(66556008)(8936002)(66946007)(66476007)(16576012)(9686003)(7416002)(26005)(478600001)(6486002)(186003)(86362001)(52116002)(8676002)(316002)(5660300002)(4326008)(83380400001)(2906002)(33716001)(30864003)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 9/K7FLIwNyayPwvsu5YBCLQ6eeZnbhDuftiKfi+Eg7fqeolztvJ4Ma8xYzPONR2iWC8Tw8x/JdwV8VR6kNMBMFJr08/K7w3qZMGeI+E+vS+DfXSXpnj3X+jCMQiSCgQSX6c8bylqLCxzt7P0vePoN9b77TTikOwERGmfSzLNzjb1HDklg4hW8DCMmBqKWrrod/J4uIMXS01b/Q+S7y7oeLYfZcaKCKzN7NCm0EHB9ZqF3g5EGgugxxRBpZx1n5PF7rBJN1GNfkhdGAnmDz/95rkIOUsA7XzbxzqGPv8YAbnnBfhP+m8j8mAzQFP+iSnOYR3xCm4sA2TjfVOlf/xDgt5kMrcNauagwYERnkvHe3phn8Bjyb39oXkgfcOLYKU8KRkEE+HCMrGh6ojlJ0aYCO8LBQTjG+suyQGXNDaWrgy0Ib+u0WpZUCVFKyllVfPva6qPzNatcSvr3hm0iJJ2iTlD8ydsxLWg0tvio1G0DvZRZTORXVd24WFTfVvFFOQKCmVRFrgeIOO8lSwoXxfADQQd2wWap6yGaL7KNQ6TIDUDXSm6KQv/NOfKxc7cEnbzemg6mYtx0ypJC/FIVhwhhv5k/2slrf4l8Tso/rT5vwpiJoZymRD9zepCsuRVi7PsaV2d8Qy8Egwxopl6NPrWEA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59d6b046-c014-493c-9c0b-08d849f43eed X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:14:25.1201 (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: 0k9SOBKGWtA+G1WGEgS+uegL276N13S2br0j3SWMSTkir587Tkp2GsiZfPN+dOEk X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2461 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Convert all the intercepts to one array of 32 bit vectors in vmcb_control_area. This makes it easy for future intercept vector additions. Also update trace functions. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/include/asm/svm.h | 14 +++++++------- arch/x86/kvm/svm/nested.c | 25 ++++++++++--------------- arch/x86/kvm/svm/svm.c | 16 ++++++---------- arch/x86/kvm/svm/svm.h | 12 ++++++------ arch/x86/kvm/trace.h | 18 +++++++++++------- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 51833a611eba..9f0fa02fc838 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -14,6 +14,8 @@ enum vector_offset { CR_VECTOR = 0, DR_VECTOR, EXCEPTION_VECTOR, + INTERCEPT_VECTOR_3, + INTERCEPT_VECTOR_4, MAX_VECTORS, }; @@ -73,10 +75,8 @@ enum { INTERCEPT_MC_VECTOR = 64 + MC_VECTOR, INTERCEPT_XM_VECTOR = 64 + XM_VECTOR, INTERCEPT_VE_VECTOR = 64 + VE_VECTOR, -}; - -enum { - INTERCEPT_INTR, + /* Byte offset 00Ch (Vector 3) */ + INTERCEPT_INTR = 96, INTERCEPT_NMI, INTERCEPT_SMI, INTERCEPT_INIT, @@ -108,7 +108,8 @@ enum { INTERCEPT_TASK_SWITCH, INTERCEPT_FERR_FREEZE, INTERCEPT_SHUTDOWN, - INTERCEPT_VMRUN, + /* Byte offset 010h (Vector 4) */ + INTERCEPT_VMRUN = 128, INTERCEPT_VMMCALL, INTERCEPT_VMLOAD, INTERCEPT_VMSAVE, @@ -128,8 +129,7 @@ enum { struct __attribute__ ((__packed__)) vmcb_control_area { u32 intercepts[MAX_VECTORS]; - u64 intercept; - u8 reserved_1[40]; + u32 reserved_1[15 - MAX_VECTORS]; u16 pause_filter_thresh; u16 pause_filter_count; u64 iopm_base_pa; diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 798ae2fabc74..772e6d8e6459 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -114,8 +114,6 @@ void recalc_intercepts(struct vcpu_svm *svm) for (i = 0; i < MAX_VECTORS; i++) c->intercepts[i] = h->intercepts[i]; - c->intercept = h->intercept; - if (g->int_ctl & V_INTR_MASKING_MASK) { /* We only want the cr8 intercept bits of L1 */ vmcb_clr_intercept(c, INTERCEPT_CR8_READ); @@ -126,16 +124,14 @@ void recalc_intercepts(struct vcpu_svm *svm) * affect any interrupt we may want to inject; therefore, * interrupt window vmexits are irrelevant to L0. */ - c->intercept &= ~(1ULL << INTERCEPT_VINTR); + vmcb_clr_intercept(c, INTERCEPT_VINTR); } /* We don't want to see VMMCALLs from a nested guest */ - c->intercept &= ~(1ULL << INTERCEPT_VMMCALL); + vmcb_clr_intercept(c, INTERCEPT_VMMCALL); for (i = 0; i < MAX_VECTORS; i++) c->intercepts[i] |= g->intercepts[i]; - - c->intercept |= g->intercept; } static void copy_vmcb_control_area(struct vmcb_control_area *dst, @@ -146,7 +142,6 @@ static void copy_vmcb_control_area(struct vmcb_control_area *dst, for (i = 0; i < MAX_VECTORS; i++) dst->intercepts[i] = from->intercepts[i]; - dst->intercept = from->intercept; dst->iopm_base_pa = from->iopm_base_pa; dst->msrpm_base_pa = from->msrpm_base_pa; dst->tsc_offset = from->tsc_offset; @@ -179,7 +174,7 @@ static bool nested_svm_vmrun_msrpm(struct vcpu_svm *svm) */ int i; - if (!(svm->nested.ctl.intercept & (1ULL << INTERCEPT_MSR_PROT))) + if (!(vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_MSR_PROT))) return true; for (i = 0; i < MSRPM_OFFSETS; i++) { @@ -205,7 +200,7 @@ static bool nested_svm_vmrun_msrpm(struct vcpu_svm *svm) static bool nested_vmcb_check_controls(struct vmcb_control_area *control) { - if ((control->intercept & (1ULL << INTERCEPT_VMRUN)) == 0) + if ((vmcb_is_intercept(control, INTERCEPT_VMRUN)) == 0) return false; if (control->asid == 0) @@ -493,7 +488,8 @@ int nested_svm_vmrun(struct vcpu_svm *svm) trace_kvm_nested_intercepts(nested_vmcb->control.intercepts[CR_VECTOR] & 0xffff, nested_vmcb->control.intercepts[CR_VECTOR] >> 16, nested_vmcb->control.intercepts[EXCEPTION_VECTOR], - nested_vmcb->control.intercept); + nested_vmcb->control.intercepts[INTERCEPT_VECTOR_3], + nested_vmcb->control.intercepts[INTERCEPT_VECTOR_4]); /* Clear internal status */ kvm_clear_exception_queue(&svm->vcpu); @@ -710,7 +706,7 @@ static int nested_svm_exit_handled_msr(struct vcpu_svm *svm) u32 offset, msr, value; int write, mask; - if (!(svm->nested.ctl.intercept & (1ULL << INTERCEPT_MSR_PROT))) + if (!(vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_MSR_PROT))) return NESTED_EXIT_HOST; msr = svm->vcpu.arch.regs[VCPU_REGS_RCX]; @@ -737,7 +733,7 @@ static int nested_svm_intercept_ioio(struct vcpu_svm *svm) u8 start_bit; u64 gpa; - if (!(svm->nested.ctl.intercept & (1ULL << INTERCEPT_IOIO_PROT))) + if (!(vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_IOIO_PROT))) return NESTED_EXIT_HOST; port = svm->vmcb->control.exit_info_1 >> 16; @@ -791,8 +787,7 @@ static int nested_svm_intercept(struct vcpu_svm *svm) break; } default: { - u64 exit_bits = 1ULL << (exit_code - SVM_EXIT_INTR); - if (svm->nested.ctl.intercept & exit_bits) + if (vmcb_is_intercept(&svm->nested.ctl, exit_code)) vmexit = NESTED_EXIT_DONE; } } @@ -900,7 +895,7 @@ static void nested_svm_intr(struct vcpu_svm *svm) static inline bool nested_exit_on_init(struct vcpu_svm *svm) { - return (svm->nested.ctl.intercept & (1ULL << INTERCEPT_INIT)); + return vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_INIT); } static void nested_svm_init(struct vcpu_svm *svm) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 11892e86cb39..17bfa34033ac 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2218,12 +2218,9 @@ static bool check_selective_cr0_intercepted(struct vcpu_svm *svm, { unsigned long cr0 = svm->vcpu.arch.cr0; bool ret = false; - u64 intercept; - - intercept = svm->nested.ctl.intercept; if (!is_guest_mode(&svm->vcpu) || - (!(intercept & (1ULL << INTERCEPT_SELECTIVE_CR0)))) + (!(vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_SELECTIVE_CR0)))) return false; cr0 &= ~SVM_CR0_SELECTIVE_MASK; @@ -2818,7 +2815,8 @@ static void dump_vmcb(struct kvm_vcpu *vcpu) pr_err("%-20s%04x\n", "dr_read:", control->intercepts[DR_VECTOR] & 0xffff); pr_err("%-20s%04x\n", "dr_write:", control->intercepts[DR_VECTOR] >> 16); pr_err("%-20s%08x\n", "exceptions:", control->intercepts[EXCEPTION_VECTOR]); - pr_err("%-20s%016llx\n", "intercepts:", control->intercept); + pr_err("%-20s%08x\n", "intercept1:", control->intercepts[INTERCEPT_VECTOR_3]); + pr_err("%-20s%08x\n", "intercept2:", control->intercepts[INTERCEPT_VECTOR_4]); pr_err("%-20s%d\n", "pause filter count:", control->pause_filter_count); pr_err("%-20s%d\n", "pause filter threshold:", control->pause_filter_thresh); @@ -3738,7 +3736,6 @@ static int svm_check_intercept(struct kvm_vcpu *vcpu, break; case SVM_EXIT_WRITE_CR0: { unsigned long cr0, val; - u64 intercept; if (info->intercept == x86_intercept_cr_write) icpt_info.exit_code += info->modrm_reg; @@ -3747,9 +3744,8 @@ static int svm_check_intercept(struct kvm_vcpu *vcpu, info->intercept == x86_intercept_clts) break; - intercept = svm->nested.ctl.intercept; - - if (!(intercept & (1ULL << INTERCEPT_SELECTIVE_CR0))) + if (!(vmcb_is_intercept(&svm->nested.ctl, + INTERCEPT_SELECTIVE_CR0))) break; cr0 = vcpu->arch.cr0 & ~SVM_CR0_SELECTIVE_MASK; @@ -4010,7 +4006,7 @@ static bool svm_apic_init_signal_blocked(struct kvm_vcpu *vcpu) * if an INIT signal is pending. */ return !gif_set(svm) || - (svm->vmcb->control.intercept & (1ULL << INTERCEPT_INIT)); + (vmcb_is_intercept(&svm->vmcb->control, INTERCEPT_INIT)); } static void svm_vm_destroy(struct kvm *kvm) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 2fc305f647a3..2cde5091775a 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -309,7 +309,7 @@ static inline void svm_set_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); - vmcb->control.intercept |= (1ULL << bit); + vmcb_set_intercept(&vmcb->control, bit); recalc_intercepts(svm); } @@ -318,14 +318,14 @@ static inline void svm_clr_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); - vmcb->control.intercept &= ~(1ULL << bit); + vmcb_clr_intercept(&vmcb->control, bit); recalc_intercepts(svm); } static inline bool svm_is_intercept(struct vcpu_svm *svm, int bit) { - return (svm->vmcb->control.intercept & (1ULL << bit)) != 0; + return vmcb_is_intercept(&svm->vmcb->control, bit); } static inline bool vgif_enabled(struct vcpu_svm *svm) @@ -389,17 +389,17 @@ static inline bool nested_svm_virtualize_tpr(struct kvm_vcpu *vcpu) static inline bool nested_exit_on_smi(struct vcpu_svm *svm) { - return (svm->nested.ctl.intercept & (1ULL << INTERCEPT_SMI)); + return vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_SMI); } static inline bool nested_exit_on_intr(struct vcpu_svm *svm) { - return (svm->nested.ctl.intercept & (1ULL << INTERCEPT_INTR)); + return vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_INTR); } static inline bool nested_exit_on_nmi(struct vcpu_svm *svm) { - return (svm->nested.ctl.intercept & (1ULL << INTERCEPT_NMI)); + return vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_NMI); } int enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index b66432b015d2..6e7262229e6a 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -544,26 +544,30 @@ TRACE_EVENT(kvm_nested_vmrun, ); TRACE_EVENT(kvm_nested_intercepts, - TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept), - TP_ARGS(cr_read, cr_write, exceptions, intercept), + TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u32 intercept1, + __u32 intercept2), + TP_ARGS(cr_read, cr_write, exceptions, intercept1, intercept2), TP_STRUCT__entry( __field( __u16, cr_read ) __field( __u16, cr_write ) __field( __u32, exceptions ) - __field( __u64, intercept ) + __field( __u32, intercept1 ) + __field( __u32, intercept2 ) ), TP_fast_assign( __entry->cr_read = cr_read; __entry->cr_write = cr_write; __entry->exceptions = exceptions; - __entry->intercept = intercept; + __entry->intercept1 = intercept1; + __entry->intercept2 = intercept2; ), - TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx", - __entry->cr_read, __entry->cr_write, __entry->exceptions, - __entry->intercept) + TP_printk("cr_read: %04x cr_write: %04x excp: %08x " + "intercept1: %08x intercept2: %08x", + __entry->cr_read, __entry->cr_write, __entry->exceptions, + __entry->intercept1, __entry->intercept2) ); /* * Tracepoint for #VMEXIT while nested From patchwork Wed Aug 26 19:14:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739535 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F13FD13A4 for ; Wed, 26 Aug 2020 19:14:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3143207BC for ; Wed, 26 Aug 2020 19:14:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="hD9KPKla" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbgHZTOn (ORCPT ); Wed, 26 Aug 2020 15:14:43 -0400 Received: from mail-bn7nam10on2042.outbound.protection.outlook.com ([40.107.92.42]:11707 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727907AbgHZTOi (ORCPT ); Wed, 26 Aug 2020 15:14:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UT0Jwi3sOfOJAbK+LIsvQEu4k2awNVIYLBJLNtog6RYtTabrSgp3WzC+uHOKoHj3UryyDMC+c935zeBnD1FqSlYV2JFKQsV9M2hZMOCqsFqrN5DGkipbe69VGwxYdqw6Me1ChOnKFcteyg7JC66bTtNSBaMjBudiaBvzLfDNQ61j2JZHC1majHO/ZjpPIITmD6yNJL8JLDLaVn0r8Sidu3GUr4p7xHop1DEQfICWzsQzbVKafZDWsLG3sJBG2RTMhz2LylYuoqD4HxCKIQ5gB49J1pwHEO+B1Fi+Ecj4UzH2s/Cow89yqSDkdgL6XKC23Fs2AudZv4MOBbVPPYUqtQ== 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=XAJ3gLkCEa1T8AveMIsuX7jH78jUznLkEZ+oqhm5kPI=; b=TqBMGjTaFKgrAPE2qGMl1BKgxKzCPxpBYrfxowdwjdCkzNOfS0zjhNGNtn4ewRgtIx4NFxXvfLmUH09YWy64tFZDjiCYt06JGesQvA27E4c2N4GZEogXbUdHEO1zkiisPFiDHqStQzBYiPB60XjP0kCPa7CyLjDC3plNCi7X60nGPWGP9Ck/o33w4RBKONvaRt6BTWMxWAO/3O8nWOt6pR6oJE8BC6lPkABSfJFzb0aGL4GyMI6CIMjpi5fUs60cMlxlf4aT2uD6KGsyFxHwmrYgjdnQ1lyHHbnWkOu4RKNJ6t3mfPVTIscGRFBs4xYESLeFSEY9HhxmcCtIGYd5uw== 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=XAJ3gLkCEa1T8AveMIsuX7jH78jUznLkEZ+oqhm5kPI=; b=hD9KPKlax10DWg9qhRkrwQjwTkxzWvg/ROgjMnms5oHPv2PqfTngXQT7fePdcoDbifLr8WjZ2b8MGVk3I4+CQMM3KgjeJUyxWiHATo1ecUFd/q9PzQLIsaGNr4PIyBGNztA8JDb/ce29adC/mwzBb9oDum2BdZpqeHiB82EmXYE= 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 SN1PR12MB2461.namprd12.prod.outlook.com (2603:10b6:802:27::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Wed, 26 Aug 2020 19:14:32 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:14:32 +0000 Subject: [PATCH v5 06/12] KVM: SVM: Add new intercept vector in vmcb_control_area From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:14:30 -0500 Message-ID: <159846927031.18873.4812578770870007547.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM3PR03CA0021.namprd03.prod.outlook.com (2603:10b6:0:50::31) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM3PR03CA0021.namprd03.prod.outlook.com (2603:10b6:0:50::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:14:31 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 430d451c-4ae0-4cbd-8bd8-08d849f44358 X-MS-TrafficTypeDiagnostic: SN1PR12MB2461: 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: 8OAPVk4TA0seU+Z6MbsbJsLJIPMU6YakfKjSb6HxSf8XTXLeTgF8z3kvB+7jiRbXkn47AG61nJOOnPitOcE5d+YoHJfdYXdftQgHJZgMvOoM0s9TsOM16rrMswEReQmWKToCEAAVgkplps4fJfiYlXWov0+aJdGjd+NOBadvjpvz98Kdzrn3dUU2pH6PO/1YjIBhX1e39djSNc+8hgJnjrUmqW1wY4riB4QOMm+bVupW1JFXBcEsQHCG2PV93xIxLDuRMVmx2910ufDYLAUmHH6qXqlB4VUcMQKMRUNhyxIPFzTGP4npnCUGaaWQ5ffPTO+RgvNvVJtIHcOe/jppSU4aO9K4IuTyyJqfFudZ3uDSTas9gE1GMlJMl4DYZbnq0uFitBxcNAs2dDZsHriwhQ== 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:(7916004)(4636009)(346002)(376002)(136003)(39860400002)(396003)(366004)(956004)(44832011)(66556008)(8936002)(66946007)(66476007)(16576012)(9686003)(7416002)(26005)(478600001)(6486002)(186003)(86362001)(52116002)(966005)(8676002)(316002)(5660300002)(4326008)(83380400001)(2906002)(33716001)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: bIqtvppJ0msJgOgu4XhHKfpomWbWrziisq0l5xtYMXNJ9mSAcq3IixDKE+0Y0kPr7SAcDpUx9vj4E8Y5C3Oev7jX2ZgR76JpvPoMtSnqwTmLVyECKvXKelDtOLepF4GxHR0/Suf5cWhm/qr6xrd0+jWUwmuEaCb/hJ7TqovAu3Jal6qWeBOpqzUHKNW+zRa6sTlJYoBtr0aA7KISkN6tFFRrRg18ntveNjl7qsjU3YY2ORgrnHwzg7tFVIWEXZatCz+DFtfUXEEg+Wa8Af7n2M9NTJjWVV3CIPTOPB2XlYkYcxt1w/Rb832I6XHcZnzqSV0iyefU8WyeiHkXYbjbRhaRdzLyPOQP+0DUZUYEPa26joZnzrMUA2tg4d8KjUiJUuZC6Q7N43Dn/0NOW5IeDhbOs6n2h4UdhDTcnOTh9n2mqwyjjBzgeNMh1k+HEOYNYrE/Fvwvkg7r+4WqEnV+MIJJ5MqO/8/xLST9ZrC6bEdUKOsskHE2JRw6G/IP2FdedAs4KRF12X0s7H5MkDIjk3vJBSIsN8RLVXLUs2i+I5iYbqFIUShGGj5AlZYooB3fWJQ2d63drcPqEgnH4UJ3KwgSQzSpdw4TfDa9p6/RQMnJYOS46tlAyKxF/G/qScVXvp+cSMr5nQfmXcN8Hf19vA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 430d451c-4ae0-4cbd-8bd8-08d849f44358 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:14:32.4998 (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: b6m3FbkXHwc3jpwwEzATLiABJ6hvvJWQeMy9viNCkMWOT551JBqif2xWn4jNh7xb X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2461 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The new intercept bits have been added in vmcb control area to support few more interceptions. Here are the some of them. - INTERCEPT_INVLPGB, - INTERCEPT_INVLPGB_ILLEGAL, - INTERCEPT_INVPCID, - INTERCEPT_MCOMMIT, - INTERCEPT_TLBSYNC, Add new intercept vector in vmcb_control_area to support these instructions. Also update kvm_nested_vmrun trace function to support the new addition. AMD documentation for these instructions is available at "AMD64 Architecture Programmer’s Manual Volume 2: System Programming, Pub. 24593 Rev. 3.34(or later)" The documentation can be obtained at the links below: Link: https://www.amd.com/system/files/TechDocs/24593.pdf Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/include/asm/svm.h | 7 +++++++ arch/x86/kvm/svm/nested.c | 3 ++- arch/x86/kvm/trace.h | 13 ++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 9f0fa02fc838..623c392a55ac 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -16,6 +16,7 @@ enum vector_offset { EXCEPTION_VECTOR, INTERCEPT_VECTOR_3, INTERCEPT_VECTOR_4, + INTERCEPT_VECTOR_5, MAX_VECTORS, }; @@ -124,6 +125,12 @@ enum { INTERCEPT_MWAIT_COND, INTERCEPT_XSETBV, INTERCEPT_RDPRU, + /* Byte offset 014h (Vector 5) */ + INTERCEPT_INVLPGB = 160, + INTERCEPT_INVLPGB_ILLEGAL, + INTERCEPT_INVPCID, + INTERCEPT_MCOMMIT, + INTERCEPT_TLBSYNC, }; diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 772e6d8e6459..a04c9909386a 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -489,7 +489,8 @@ int nested_svm_vmrun(struct vcpu_svm *svm) nested_vmcb->control.intercepts[CR_VECTOR] >> 16, nested_vmcb->control.intercepts[EXCEPTION_VECTOR], nested_vmcb->control.intercepts[INTERCEPT_VECTOR_3], - nested_vmcb->control.intercepts[INTERCEPT_VECTOR_4]); + nested_vmcb->control.intercepts[INTERCEPT_VECTOR_4], + nested_vmcb->control.intercepts[INTERCEPT_VECTOR_5]); /* Clear internal status */ kvm_clear_exception_queue(&svm->vcpu); diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index 6e7262229e6a..11046171b5d9 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -544,9 +544,10 @@ TRACE_EVENT(kvm_nested_vmrun, ); TRACE_EVENT(kvm_nested_intercepts, - TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u32 intercept1, - __u32 intercept2), - TP_ARGS(cr_read, cr_write, exceptions, intercept1, intercept2), + TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, + __u32 intercept1, __u32 intercept2, __u32 intercept3), + TP_ARGS(cr_read, cr_write, exceptions, intercept1, + intercept2, intercept3), TP_STRUCT__entry( __field( __u16, cr_read ) @@ -554,6 +555,7 @@ TRACE_EVENT(kvm_nested_intercepts, __field( __u32, exceptions ) __field( __u32, intercept1 ) __field( __u32, intercept2 ) + __field( __u32, intercept3 ) ), TP_fast_assign( @@ -562,12 +564,13 @@ TRACE_EVENT(kvm_nested_intercepts, __entry->exceptions = exceptions; __entry->intercept1 = intercept1; __entry->intercept2 = intercept2; + __entry->intercept3 = intercept3; ), TP_printk("cr_read: %04x cr_write: %04x excp: %08x " - "intercept1: %08x intercept2: %08x", + "intercept1: %08x intercept2: %08x intercept3: %08x", __entry->cr_read, __entry->cr_write, __entry->exceptions, - __entry->intercept1, __entry->intercept2) + __entry->intercept1, __entry->intercept2, __entry->intercept3) ); /* * Tracepoint for #VMEXIT while nested From patchwork Wed Aug 26 19:14:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739537 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59AF514E5 for ; Wed, 26 Aug 2020 19:15:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 414C7208E4 for ; Wed, 26 Aug 2020 19:15:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="ArH+bCzy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726972AbgHZTO7 (ORCPT ); Wed, 26 Aug 2020 15:14:59 -0400 Received: from mail-bn7nam10on2042.outbound.protection.outlook.com ([40.107.92.42]:11707 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726834AbgHZTOq (ORCPT ); Wed, 26 Aug 2020 15:14:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xnjop5hHLWYWH6SRPp86WXkx32GDSE3YzlBeg4zJcbHckgwZkek3D4B/GebF/PMF+pOsG2keuB4lC/hCHFxnd9V5Ir488kha7/tXOrTvtYIsV16flQcAw5TLPh0ZlW5ssJovsFrqcjIjeUHkhRJpzRYQ5XPxoStaJmjGYOi5K6bzFl58w9IOYY/943J4hs553HpWD6wEuM+1YkGDBHNlqdZ7MDFlQ4An/wZPCt8CXq0bv0Hl8bk6K7MEF+2Zu/8osVTKpx8ykXRnlPvOAKkfjfuvx/p9X99YjGDZOV881vj8EmSXUCzF8xgWlU1bZl/OvW15rijJ8KNchdcE1XWqgg== 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=RaMlFYNoR1P0Krz72BADyV2LKcblkTBsnbNQpWGXfpM=; b=O+ZiAvEddQUbT82yFahtrXJ8Gq65M3DEpkZODa+QLQ4Eo0C2B7a4IEL2ZHoHLrB/ahP2o2PG51qH8jCTVaXv+nKKLl4OQ/HI3RT2SF7bDVOWnrvcaid6bJkhAGvtztcY3O1mQ26oicq4N2aqb643jFtyiCR4tO7koLH5SNDPW+3zAfVT6vOAIJg0e3xly/BmLMmZugIwdDR/G7+IlkDpj/AIsZx+XKaSRiThg6rQZgl1zZll5Vs0xIsb/Wdf6kUYcWhD60igWSQfsJ0N/OdJPBZ8WB4SeQWeG1DN6C259so+Bdz75S95uhE4oq84OhUWeulzY3W/BTQpQmpCvY8wUA== 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=RaMlFYNoR1P0Krz72BADyV2LKcblkTBsnbNQpWGXfpM=; b=ArH+bCzyPZ38C+LWMii4SbyZIBAuLPkBVCfdTBvHGWlTN3J3B5kmQUHZfz5iPMPmNqS032NIEAP/YzJQIKK5uglALN4um63xfMX+Llgt4KFcdBeECmRUOU0vX3oUWI5YbXj9enYEaEvwTKy5C2f9wXwDRnYvKqp+zgifmXkNjN0= 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 SN1PR12MB2461.namprd12.prod.outlook.com (2603:10b6:802:27::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Wed, 26 Aug 2020 19:14:40 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:14:40 +0000 Subject: [PATCH v5 07/12] KVM: nSVM: Cleanup nested_state data structure From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:14:37 -0500 Message-ID: <159846927770.18873.7353727438893595666.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR18CA0049.namprd18.prod.outlook.com (2603:10b6:3:22::11) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM5PR18CA0049.namprd18.prod.outlook.com (2603:10b6:3:22::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:14:39 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c59a09a5-93a9-4a9d-9166-08d849f447ff X-MS-TrafficTypeDiagnostic: SN1PR12MB2461: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1169; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bya1Sg5/7WEtUMwbW12kIASYsaS6pi0VkmydcBc9Tf/0ptGX2s5nixXxo51lGsFmD89JOFSvINAQrYli4XCi867LNw/Ecx2fXia6guAjD3egXroDcqQQE6oo7YdDJ13oe8oXVMgDhQ4tnhdl3YuVNILw87KUR5l2yKsyuj2pEr94dXMb7DT5xBIaQV+jreDTUl98T/VLI82y+DSZBIKG8QZX9UlK7qqwLc9sU6Cjwtp78suAGZOxfh1N7FcBs/7HrGbxNdl4xnCnfnnllKjYXwQ4UrziPh/oclIarRbQTvGU+wwuOg96YewiEduT4XdYH0RQiBfJ/6+gBVX1sW29xA== 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:(7916004)(4636009)(346002)(376002)(136003)(39860400002)(396003)(366004)(956004)(44832011)(66556008)(8936002)(66946007)(66476007)(16576012)(9686003)(7416002)(26005)(478600001)(6486002)(186003)(86362001)(52116002)(8676002)(316002)(5660300002)(4326008)(83380400001)(2906002)(33716001)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: nKRDeoYZbBZ0Uoa1SrWYONKzE67/WRZU2vOPWhr+89PoPwUycG+cFr9V9G5XHmUeUFWQjvahHjpfNRBolKAD1V7gYeDUpomdkRKavQTORg7hfqMUs6mdVdm1sXDhgjdQPSdS/eEXahEYZV+fAqQSV8+xAlqkor7txceYv8HwbS3W7gdBH6v0bE0hpdvzGPmujQoOf93vZZdQP6/NWIxLgwDhFhIfKyLvPSM9O+rLRfGWFILpbar4JtSWh903Mi3VpQKrjlT4FF8RPZp9sJMgI2UDNVbRrqaYc2fY9KLIRBxfQJA4BYmXlGHxDyfUjQJWoEP1TZkNd9vBd86qQ0R8r0z7k0t8/LyixfevXZBRStau7BYOUNoijKAC8ownLpSZGSkoyv7aGmoJ0ZA8YmQaRyZnt6jqAuvhBuy/K4JAXB8XPDSPrqhgWj/LIOqs8MiR0IFvKOXJofgUGWw9H+lLZcB3QydIW0NxX6lct8iz/RQzYqjsifEceKl7zWB+kXDAUjhOizFA8fgDGuzAt0jDTaThjsTIiml4pVF3UHbLOpWx8FD/1SvRZ0Lbiw1blLjRiEV/cHDlg/AhOyAU8IK8i8RwTryAsvwxiMZPzLTbIatOVBDAfPb2SWLY2kNulL/FRIf1esmV/mIVhs9t81GXMw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c59a09a5-93a9-4a9d-9166-08d849f447ff X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:14:40.3513 (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: KAxKWKl51HsLWzjXpZLey4/65T3yiWGM8ACpgO4lAWUWZag4N60dR1feuncXARvv X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2461 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org host_intercept_exceptions is not used anywhere. Clean it up. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/kvm/svm/nested.c | 2 -- arch/x86/kvm/svm/svm.h | 1 - 2 files changed, 3 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index a04c9909386a..9595c1a1a039 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -109,8 +109,6 @@ void recalc_intercepts(struct vcpu_svm *svm) h = &svm->nested.hsave->control; g = &svm->nested.ctl; - svm->nested.host_intercept_exceptions = h->intercepts[EXCEPTION_VECTOR]; - for (i = 0; i < MAX_VECTORS; i++) c->intercepts[i] = h->intercepts[i]; diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 2cde5091775a..ffb35a83048f 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -86,7 +86,6 @@ struct svm_nested_state { u64 hsave_msr; u64 vm_cr_msr; u64 vmcb; - u32 host_intercept_exceptions; /* These are the merged vectors */ u32 *msrpm; From patchwork Wed Aug 26 19:14:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739539 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E517E13B6 for ; Wed, 26 Aug 2020 19:15:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C43BF2083B for ; Wed, 26 Aug 2020 19:15:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="fkMFJuUA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727944AbgHZTPG (ORCPT ); Wed, 26 Aug 2020 15:15:06 -0400 Received: from mail-bn7nam10on2042.outbound.protection.outlook.com ([40.107.92.42]:11707 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727909AbgHZTO7 (ORCPT ); Wed, 26 Aug 2020 15:14:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VHF24SsS6jw0i6Ch9Vmf/O64Th3tiFC2qtKl6NfOu+phbUyULCzvJLornsCN6u55RLGC66tyE3Z5hBMBcZ+Br65Ct0f9DCLc/dXyiqcYzLpFDMZxf/DaX355C1iYt+R1pl2vHYTwpVfSbMXW54cpUuftDhnRZU5llqQF++Ppyk6J0N3I1lw+ORk8S8Xfv5+U9wqD9GhaGnO7rMONjuphk2t0jpPWy9Jle1j02bHNv1KuMXveujtdwmNcuDyBf/HDFmIp0Dck7YOvEy+kNud72UgHjuKGdVqtKNxI8i+t+BktTDnKQWTEu8UYsZjolo+K6RKSCvmaPUwjxQqCOiQ0Jg== 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=ig/6wsw048VE9ZPJm9cY0oj5dbpCDYIjCRHQNAwOgaY=; b=DS4I770TwmPZKIz/JLUIAcc7C9K8F1SVc7wf8oRcA66gsCLuLHS+HtRRoNFbBb8v9YaHSFrde3nqNNbXRr/L31pZMv5GDQlw1KNoypTP7xAvY6yXsgci7y6crIQuUfDuvZTvec5jzRu9+jOY9aMVhbY2DdhA3Nc4sxsf/ihDR4aypuX1TZnu9x5fn11LHgEZtqteyRIWc/1ND2wgxcp02J3HHV3A3XwdZwkzseGPpcbw6QwnallJIOtoZFejUpqJLAvzQms7uqn6TYcNQRJB3yPCo7HV68VWFmdO7fuTEt5nwlQCwU55H32LNauK1JM5dZbvxaqUaCjKbzsprSJfJg== 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=ig/6wsw048VE9ZPJm9cY0oj5dbpCDYIjCRHQNAwOgaY=; b=fkMFJuUAOZAf3Og0CJy48YJD2p7KUG2aK6fK78TCd+J7XfygCm73FWWa5OEp1vOo3dNYts1nZuTzfSVN/dwB5hha/mECphuVIr+VfTxtbKTK2hzIVgzJPCCmcJknqMRLfs6K5cUdExjSwuh/ktpvP6P3x3sqdy94LCxfNdD1iXs= 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 SN1PR12MB2461.namprd12.prod.outlook.com (2603:10b6:802:27::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Wed, 26 Aug 2020 19:14:47 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:14:47 +0000 Subject: [PATCH v5 08/12] KVM: SVM: Remove set_cr_intercept, clr_cr_intercept and is_cr_intercept From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:14:45 -0500 Message-ID: <159846928555.18873.13387843427538792883.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM6PR18CA0026.namprd18.prod.outlook.com (2603:10b6:5:15b::39) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM6PR18CA0026.namprd18.prod.outlook.com (2603:10b6:5:15b::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:14:46 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 587ccd52-562c-43ac-ae12-08d849f44c56 X-MS-TrafficTypeDiagnostic: SN1PR12MB2461: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:40; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MCCok5emPjuZ4y8uO7GlwVkWLQ6o5I7Un6i4qG9AE28r1gHWHPDofHyhmICRruZWml8aBdzxfBJSShRIgzyS0hJl1SYDWxAbToBzFvMPotm6E3I5PtNy8oyeynAXcEwbpJYqQPxX+NHIOkca/a6e0rf8fDQQXqJMtnOrqcv0p1/ro7TuM0bwIjHkekoLA/zDE/C7J6r934h4T9GJLL7zYc6W/kUoQ/zqOsM00ErbSWX/h+osqhIlm5fR283YOHlAr18fFM8hy303EXqny6mL9FgRgRjtudKMMoU53E0OFX8kjjg569SYQ0k7EDDVdUE2k6NGsRHb+TwDtgSZiy8gKA== 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:(7916004)(4636009)(346002)(376002)(136003)(39860400002)(396003)(366004)(956004)(44832011)(66556008)(8936002)(66946007)(66476007)(16576012)(9686003)(7416002)(26005)(478600001)(6486002)(186003)(86362001)(52116002)(8676002)(316002)(5660300002)(4326008)(83380400001)(2906002)(33716001)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: x77CqYzSXFINFbX7CKY4vw5D+8Uvw5ifReIeq6eD94ZrrV+LciluS0Is0X7EF7l4Eq/1zfLrGMsC7BDD1pkoQUaZxg0BGBmohUjps944n7993tL2r6q11AOUovST3H+CMOC4cRStGowdJ/5zhNKokBsnPHWvbPw7PColA2Rob/i12j3+lkSA2zffKyE+iCMIx25zU77IA7NB0ZLDx+4ivaeTfbV3HwVFXqU6NVJEofBzz9DRAOcbEy7Yludt2X91zhd4sYE49by0NxDYXn+DqSqtg/hcIQ5OXSoFypgmiKsYcPz2LTOWEdvpxyYPFH1a8lBgUJPjRJe7IzVJkojP4oYFE7ej8ola67vrgMtO9mNVHiNpq5BZMJ59faOX3rayGekZOI/ajuzLHeILjE2u3gOSZR9JD+Mo0cQSNapQBR+NL7bFe9ggJGzX99xrNGD/YaqIT1YGklbtIka1XjNnO2naQ2muoJt+9hVlxVMS9iG9saKuNgAMPIYJJ6LiWT5G4ZeWdE0SowQZt87i7CmGDbOM9WeZ8WL/9CishVFYVMQLrTNKSpyNt0Nh4R6rFobs93nU5om/oi1yE/W0HZ9IkhoXiEXKuGXcpLtK83d03+PFcFA4pd7egq/fdHEEBDYVPs5ceTlHBhIhIaz4lXKb/w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 587ccd52-562c-43ac-ae12-08d849f44c56 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:14:47.6061 (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: xTFR2b3a1BWWxzAmuYOeJxd+Lj82HkT3hs8gBug3ilUDFlVyO5kBkeoCub3c1SiK X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2461 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Remove set_cr_intercept, clr_cr_intercept and is_cr_intercept. Instead call generic svm_set_intercept, svm_clr_intercept an dsvm_is_intercep tfor all cr intercepts. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/kvm/svm/svm.c | 34 +++++++++++++++++----------------- arch/x86/kvm/svm/svm.h | 25 ------------------------- 2 files changed, 17 insertions(+), 42 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 17bfa34033ac..0d7397f4a4f7 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -992,14 +992,14 @@ static void init_vmcb(struct vcpu_svm *svm) svm->vcpu.arch.hflags = 0; - set_cr_intercept(svm, INTERCEPT_CR0_READ); - set_cr_intercept(svm, INTERCEPT_CR3_READ); - set_cr_intercept(svm, INTERCEPT_CR4_READ); - set_cr_intercept(svm, INTERCEPT_CR0_WRITE); - set_cr_intercept(svm, INTERCEPT_CR3_WRITE); - set_cr_intercept(svm, INTERCEPT_CR4_WRITE); + svm_set_intercept(svm, INTERCEPT_CR0_READ); + svm_set_intercept(svm, INTERCEPT_CR3_READ); + svm_set_intercept(svm, INTERCEPT_CR4_READ); + svm_set_intercept(svm, INTERCEPT_CR0_WRITE); + svm_set_intercept(svm, INTERCEPT_CR3_WRITE); + svm_set_intercept(svm, INTERCEPT_CR4_WRITE); if (!kvm_vcpu_apicv_active(&svm->vcpu)) - set_cr_intercept(svm, INTERCEPT_CR8_WRITE); + svm_set_intercept(svm, INTERCEPT_CR8_WRITE); set_dr_intercepts(svm); @@ -1094,8 +1094,8 @@ static void init_vmcb(struct vcpu_svm *svm) control->nested_ctl |= SVM_NESTED_CTL_NP_ENABLE; svm_clr_intercept(svm, INTERCEPT_INVLPG); clr_exception_intercept(svm, INTERCEPT_PF_VECTOR); - clr_cr_intercept(svm, INTERCEPT_CR3_READ); - clr_cr_intercept(svm, INTERCEPT_CR3_WRITE); + svm_clr_intercept(svm, INTERCEPT_CR3_READ); + svm_clr_intercept(svm, INTERCEPT_CR3_WRITE); save->g_pat = svm->vcpu.arch.pat; save->cr3 = 0; save->cr4 = 0; @@ -1549,11 +1549,11 @@ static void update_cr0_intercept(struct vcpu_svm *svm) vmcb_mark_dirty(svm->vmcb, VMCB_CR); if (gcr0 == *hcr0) { - clr_cr_intercept(svm, INTERCEPT_CR0_READ); - clr_cr_intercept(svm, INTERCEPT_CR0_WRITE); + svm_clr_intercept(svm, INTERCEPT_CR0_READ); + svm_clr_intercept(svm, INTERCEPT_CR0_WRITE); } else { - set_cr_intercept(svm, INTERCEPT_CR0_READ); - set_cr_intercept(svm, INTERCEPT_CR0_WRITE); + svm_set_intercept(svm, INTERCEPT_CR0_READ); + svm_set_intercept(svm, INTERCEPT_CR0_WRITE); } } @@ -2931,7 +2931,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) trace_kvm_exit(exit_code, vcpu, KVM_ISA_SVM); - if (!is_cr_intercept(svm, INTERCEPT_CR0_WRITE)) + if (!svm_is_intercept(svm, INTERCEPT_CR0_WRITE)) vcpu->arch.cr0 = svm->vmcb->save.cr0; if (npt_enabled) vcpu->arch.cr3 = svm->vmcb->save.cr3; @@ -3056,13 +3056,13 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr) if (nested_svm_virtualize_tpr(vcpu)) return; - clr_cr_intercept(svm, INTERCEPT_CR8_WRITE); + svm_clr_intercept(svm, INTERCEPT_CR8_WRITE); if (irr == -1) return; if (tpr >= irr) - set_cr_intercept(svm, INTERCEPT_CR8_WRITE); + svm_set_intercept(svm, INTERCEPT_CR8_WRITE); } bool svm_nmi_blocked(struct kvm_vcpu *vcpu) @@ -3250,7 +3250,7 @@ static inline void sync_cr8_to_lapic(struct kvm_vcpu *vcpu) if (nested_svm_virtualize_tpr(vcpu)) return; - if (!is_cr_intercept(svm, INTERCEPT_CR8_WRITE)) { + if (!svm_is_intercept(svm, INTERCEPT_CR8_WRITE)) { int cr8 = svm->vmcb->control.int_ctl & V_TPR_MASK; kvm_set_cr8(vcpu, cr8); } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index ffb35a83048f..8128bac75fa2 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -228,31 +228,6 @@ static inline bool vmcb_is_intercept(struct vmcb_control_area *control, int bit) return test_bit(bit, (unsigned long *)&control->intercepts); } -static inline void set_cr_intercept(struct vcpu_svm *svm, int bit) -{ - struct vmcb *vmcb = get_host_vmcb(svm); - - vmcb_set_intercept(&vmcb->control, bit); - - recalc_intercepts(svm); -} - -static inline void clr_cr_intercept(struct vcpu_svm *svm, int bit) -{ - struct vmcb *vmcb = get_host_vmcb(svm); - - vmcb_clr_intercept(&vmcb->control, bit); - - recalc_intercepts(svm); -} - -static inline bool is_cr_intercept(struct vcpu_svm *svm, int bit) -{ - struct vmcb *vmcb = get_host_vmcb(svm); - - return vmcb_is_intercept(&vmcb->control, bit); -} - static inline void set_dr_intercepts(struct vcpu_svm *svm) { struct vmcb *vmcb = get_host_vmcb(svm); From patchwork Wed Aug 26 19:14:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739541 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 205E014E5 for ; Wed, 26 Aug 2020 19:15:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 023752083B for ; Wed, 26 Aug 2020 19:15:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="YAZc+znH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727912AbgHZTPX (ORCPT ); Wed, 26 Aug 2020 15:15:23 -0400 Received: from mail-bn7nam10on2042.outbound.protection.outlook.com ([40.107.92.42]:11707 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727926AbgHZTPF (ORCPT ); Wed, 26 Aug 2020 15:15:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f6cOnFj95mK2T0e3Xx+D3rKH2XX2/AAIbG/WWWqYgyffzNX4EnuWYolk534DpioqRLE1vvjLRGjo6cHEgk3jsD+Zn58s4atlw9P8/VlNIMtlJJZEREtW47U8lP6uQ3jEQdLh+oCC6sK6js9eAMxyxaneJA9DK3KKeK0bq56Sf2/Jd/LxfZ4FyWscM/eJWu5M90lra/If81c4Z2sTRV9Er/8LVQW+0I4RztOlgD2ZCzI+sN1hzxN+4Af7J2sD9sAnCvYCx2GtanrDdVvtaiDXWdC4LdV1o9mzN4NgdaDMXQhglGHgNeXFN3BH1zWEY/ULFDZFAOvDOj6g+vu/YYKpIw== 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=aUE9LovJnl2mai/pRtM6NHspDACFry7Dmota7pTHAcA=; b=TvcbFXbQHaJZCPw+TcYzl548pJmDX9+umczAPt25o5q2FulgHd2OgbRRzOO2c3WQlwhhviBERU1Ze4iPSbLZnY9d8n8G0przz0dJHkdOfx2jbSBLIMNWpyBUd8trV58TuKJ8P1aIDqX0DbrNelINYF6O+2TRmEP5yIDfGuyG8BwSmM49A2y+yqBl0FsWOIl807nxDO5RDd8aMrI/g6G41DHssvvMYZXcgaPgRhXy5U0YRCJ/s225qdP9hMMyDpiG0OLJAL95S4BgKNY6u2P7Q7z8oIgh4BOHvXMKAeJzLcCbIkNxXN79bCWpVg6HvzStNElP5DjU8ROQabvxYO7+fw== 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=aUE9LovJnl2mai/pRtM6NHspDACFry7Dmota7pTHAcA=; b=YAZc+znH71xlrWaDuC7IsQIdEKrITAwLiMEbFfO6k1LqWKw8v0B0d1GEil9MkxFkbJ35xnggH7mQXG2/hwmUpgkXMGyhe0SI7PFujbV+Qnb1DvVJJyLaTGg4iPKxLYsJdGsyiYj+EEfLAKcGhA2Wd8z3hob65M+XH32J5JN4T3w= 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 SN1PR12MB2461.namprd12.prod.outlook.com (2603:10b6:802:27::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Wed, 26 Aug 2020 19:14:56 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:14:56 +0000 Subject: [PATCH v5 09/12] KVM: SVM: Remove set_exception_intercept and clr_exception_intercept From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:14:52 -0500 Message-ID: <159846929287.18873.881746433536011970.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM6PR03CA0007.namprd03.prod.outlook.com (2603:10b6:5:40::20) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM6PR03CA0007.namprd03.prod.outlook.com (2603:10b6:5:40::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:14:54 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 09be53a0-5427-40e2-26d4-08d849f45156 X-MS-TrafficTypeDiagnostic: SN1PR12MB2461: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:224; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 92Gt4SMksu/mETBovjwDXrlXS36B+WwIP+Z6xR1Q/jsDPO90xtITihgGjRXaih4xFnJk2JnDxARIKeakW/aEUns4t6kKUjuUSLV2DdcPNkHhN6MA1h5ys1qFzH5Q3D2CTDjhPN4bc5WJ7mdmLXFHI260Ml7T1wSb/nQFlRhrbvjbH9omPJHGuYc6nKTJG36helgDiHrirsYFJliq+Eezfqo9X7bN+gN1Iv25qxmHmuIrvoTHn2xxms4HSNF7eGzXg4F4BV3nkK6LixNcJ1fI3Xir1yyZH6A5aji+WdEGqRBp0l9NYqm4HNbBETYXsedA 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:(7916004)(4636009)(346002)(376002)(136003)(39860400002)(396003)(366004)(956004)(44832011)(66556008)(8936002)(66946007)(66476007)(16576012)(9686003)(7416002)(26005)(478600001)(6486002)(186003)(86362001)(52116002)(8676002)(316002)(5660300002)(4326008)(83380400001)(2906002)(33716001)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: rvLTm60XuqW/52DOvf2V+8jKNzrtvdHxutFYc5AJ4etJGap5HPyxKK6oP2SlvznClD73xIqxMFYeg3lRZrpWEHiELU3jJPz4yzsLkuUMp5LMNHhQZrPt4YZdbjkrKy2ee67una8v74PD9C5BRahCCCW0suhDmWCD7uwXTqn3UssS11DlCSUeQ5v0NhSR9klbrNUZT/Ng7TViTNAM4lNjR4GoS20/T+95rubPcPLDJMq8Kxl78iftgX1pHDxCWLtLUjp5x5GqH8UIm73JHjLJSah+P70JWBTMXYUwaBSmARljaKuN8F3wgQ8azbginF2Px4PMC7T68EsMAwNxWh+GYWfHi5OEC1int0CdLbwM4w+2Kkd1e06iTWbuBMEPikHEMrk1r1hv4I8ziRk8npD2m6qZobtsAV2psEaQkjLGIUOJ7lI3XTdNnZJ700y79Hrn4JTdRghD5qELgJo90YTaE/XFlismUkzhp3cjIn5ZR8pDAz4apCRtyMc2dQBjS6NMcYpdtCetcp1OAxr1eT2x+zFXEt4dLZCWwNLhJi1S9Ay9tbBujZnWIie9wkeAWcn3Uu2copasZC+3HJdNc2nT59nB2/MFQsrrFDwSv92B+hxDE3et1YGX8X/6ayafq8i8GkzBkofP5qS3VvCpWD+dVg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09be53a0-5427-40e2-26d4-08d849f45156 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:14:55.9602 (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: twgQ2e1H2+d95GC3XGzNXRxIPCaAgTkeKARKCT6SSobfepL1tpPn/oTW1XW8JERH X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2461 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Remove set_exception_intercept and clr_exception_intercept. Replace with generic set_intercept and clr_intercept for these calls. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/kvm/svm/svm.c | 20 ++++++++++---------- arch/x86/kvm/svm/svm.h | 18 ------------------ 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 0d7397f4a4f7..96617b61e531 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1003,11 +1003,11 @@ static void init_vmcb(struct vcpu_svm *svm) set_dr_intercepts(svm); - set_exception_intercept(svm, INTERCEPT_PF_VECTOR); - set_exception_intercept(svm, INTERCEPT_UD_VECTOR); - set_exception_intercept(svm, INTERCEPT_MC_VECTOR); - set_exception_intercept(svm, INTERCEPT_AC_VECTOR); - set_exception_intercept(svm, INTERCEPT_DB_VECTOR); + svm_set_intercept(svm, INTERCEPT_PF_VECTOR); + svm_set_intercept(svm, INTERCEPT_UD_VECTOR); + svm_set_intercept(svm, INTERCEPT_MC_VECTOR); + svm_set_intercept(svm, INTERCEPT_AC_VECTOR); + svm_set_intercept(svm, INTERCEPT_DB_VECTOR); /* * Guest access to VMware backdoor ports could legitimately * trigger #GP because of TSS I/O permission bitmap. @@ -1015,7 +1015,7 @@ static void init_vmcb(struct vcpu_svm *svm) * as VMware does. */ if (enable_vmware_backdoor) - set_exception_intercept(svm, INTERCEPT_GP_VECTOR); + svm_set_intercept(svm, INTERCEPT_GP_VECTOR); svm_set_intercept(svm, INTERCEPT_INTR); svm_set_intercept(svm, INTERCEPT_NMI); @@ -1093,7 +1093,7 @@ static void init_vmcb(struct vcpu_svm *svm) /* Setup VMCB for Nested Paging */ control->nested_ctl |= SVM_NESTED_CTL_NP_ENABLE; svm_clr_intercept(svm, INTERCEPT_INVLPG); - clr_exception_intercept(svm, INTERCEPT_PF_VECTOR); + svm_clr_intercept(svm, INTERCEPT_PF_VECTOR); svm_clr_intercept(svm, INTERCEPT_CR3_READ); svm_clr_intercept(svm, INTERCEPT_CR3_WRITE); save->g_pat = svm->vcpu.arch.pat; @@ -1135,7 +1135,7 @@ static void init_vmcb(struct vcpu_svm *svm) if (sev_guest(svm->vcpu.kvm)) { svm->vmcb->control.nested_ctl |= SVM_NESTED_CTL_SEV_ENABLE; - clr_exception_intercept(svm, INTERCEPT_UD_VECTOR); + svm_clr_intercept(svm, INTERCEPT_UD_VECTOR); } vmcb_mark_all_dirty(svm->vmcb); @@ -1646,11 +1646,11 @@ static void update_exception_bitmap(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); - clr_exception_intercept(svm, INTERCEPT_BP_VECTOR); + svm_clr_intercept(svm, INTERCEPT_BP_VECTOR); if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) { if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) - set_exception_intercept(svm, INTERCEPT_BP_VECTOR); + svm_set_intercept(svm, INTERCEPT_BP_VECTOR); } } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 8128bac75fa2..fc4bfea3f555 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -261,24 +261,6 @@ static inline void clr_dr_intercepts(struct vcpu_svm *svm) recalc_intercepts(svm); } -static inline void set_exception_intercept(struct vcpu_svm *svm, int bit) -{ - struct vmcb *vmcb = get_host_vmcb(svm); - - vmcb_set_intercept(&vmcb->control, bit); - - recalc_intercepts(svm); -} - -static inline void clr_exception_intercept(struct vcpu_svm *svm, int bit) -{ - struct vmcb *vmcb = get_host_vmcb(svm); - - vmcb_clr_intercept(&vmcb->control, bit); - - recalc_intercepts(svm); -} - static inline void svm_set_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); From patchwork Wed Aug 26 19:15:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 174A713B6 for ; Wed, 26 Aug 2020 19:15:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6A8B2078A for ; Wed, 26 Aug 2020 19:15:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="D84YzPd2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727022AbgHZTPo (ORCPT ); Wed, 26 Aug 2020 15:15:44 -0400 Received: from mail-co1nam11on2076.outbound.protection.outlook.com ([40.107.220.76]:57728 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727017AbgHZTPl (ORCPT ); Wed, 26 Aug 2020 15:15:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dhLhBybPDM3oiYajdObGZvj2zY35K03trf6fmpK/U+zO4N5zBjrS/HVSCf4CpbZO/pLAvqs1jMwNJl9R4ZVixomCGFkWKeIupJN6uMsG9N6U+Vy1uNupYy3Hce62xFZHGlZMS5D++L5wMlNEOfUlKm9YK+owiKWaPB736xrZglW2nfEgpgbXfLpMo4xqeHlQEUD7bfPRPpTvp8ujlw4BldML4W52iPuxvOuZIVSUE3Ger8T8o6rtjGKcSobat3QZtWdxBWlcJWNchiTyoVj2LsIimYNekGxFKjmU4zxnR064TeJp18s2RWZF353w8N1yPd5Dn7ZJ8G4rhyGohe6o+A== 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=x2VobKazc2SHtgQtsnoWiyopnSb2d9K5GeJXr0aX2eQ=; b=XsKqi/HpGfkjyRjqlwnSQj4sOos/lskLL+WzRzGWiosDrKX3d0aCQZJ764asTXDYMpLYhdAtwQcEpFuxKsPaflU00oajCpWcvpWYpZohT7EH4fMwpwOPkM/av7NP+zftY8CenSsVwGIKzF0J9mebD5YpViaj7w/nY5MwTC7xbMNc93HWf/zzQZq25EkUN5iwMK/Ci2mDPxvgU5EL4+8gcsiNr7Ta9J/NTrSpzqkKLrKKm5UPCdNam70RdbTChPUliQxlqfL6sG2LU8FgLumcvYTzr7BnTXlkn4fSTpwfAt0VBqZEbtOZoKPskLtGz81wo6SlDUGlEhQ+Q7BIfmV1RQ== 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=x2VobKazc2SHtgQtsnoWiyopnSb2d9K5GeJXr0aX2eQ=; b=D84YzPd2564QMJ/Mk9DpcsRaLHJqzF5aDFc0/noeKpHpYEkec29wKDhwKmSw+6EC2zEhsoP1oQtiUl1IS5biUZHwGwdY4lY21oRkz35EBGuNP2Q8TaYsxTJMyHa0TVJC8w7NP60D3RIpsK/y5K7UMWn8nbn3Hb0/UpGepaJvqJw= 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 SN1PR12MB2384.namprd12.prod.outlook.com (2603:10b6:802:25::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Wed, 26 Aug 2020 19:15:04 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:15:04 +0000 Subject: [PATCH v5 10/12] KVM: X86: Rename and move the function vmx_handle_memory_failure to x86.c From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:15:01 -0500 Message-ID: <159846930119.18873.955266273208700176.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR04CA0059.namprd04.prod.outlook.com (2603:10b6:3:ef::21) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM5PR04CA0059.namprd04.prod.outlook.com (2603:10b6:3:ef::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:15:02 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8bb44841-fa82-49e5-8892-08d849f455ee X-MS-TrafficTypeDiagnostic: SN1PR12MB2384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X69pOGsfDArRPp+CkK16Dv4SZ0jtYaVA3lI/pnkgpJOAxYfWAchmGJuPusj5hsYUTeczdNPZflXwImmfp+dyK1pfs+Ltsy3fjKZcyCYGqvYB2/6yEOfPzbrrivQipLqvfv/VsxID0bQUCHlvDCLBUZHnVWn5HnXq2TJQXbltFtAHPWKqtM3XFUnIS43tiqKNBA46WkOpfkPnOOkTPUkt4GUlaktznv8qtsUw0NRD47XN94EaQF3R4d7NXUKZJPt/IeLV5aUxqeBJjvG+fjwoRhorPHlDqzED6P/GzCFfzFPE7qRRGWqpM4Isv5snhowo 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)(366004)(136003)(376002)(396003)(39860400002)(103116003)(4326008)(186003)(66946007)(5660300002)(66476007)(66556008)(44832011)(86362001)(33716001)(9686003)(52116002)(7416002)(83380400001)(6486002)(8936002)(8676002)(16576012)(2906002)(316002)(26005)(478600001)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: VjfAxk/139XVMgqHm7nHbvHByy/gVOOwVMmm0SOtgF28iPRItWkXUME8Zx0lgM2EinR4YMGU1GYo3RugkrBTph8v5WLxHPcOQZDo9FuZHityiDZrg+26+KTeDZIHCMUZjQUwxaz0tphLO1howbknkRkGMDNuihvL4BdonQVSy7KafSvVQCTUHQCRD41xf90SOrRDphSkyOfx9BVQja0F8vdy8/RETd0k7jiCAzHFHlg+AZr10NnIZWOEhOcaHg8LK/aZ7as12Fufd6bRmIDkwaNMRkEGetnQSJpiOC3sNosk6kuQa7qoihpTdmsf/3Uzk/Vt+JqJsVCQyMK7LYG9FEmQG5VCptCOVduu077tuHgwpmK3w2Nsx74vCRELKpLtnTXHWWUVNklywNFo62vmVG80INhWKlUkACR1brT0G/wMF7wCkT+Inee+sLWZQ1JYsBEdXm2fLCIvGgM+sEjNcXj+XxHhksKCFJAuy8QMb9k6dLnQiB3uHAaQoRZ22xDMF2dxKXvdA2WkR0/mPh713566+Ha6IzQ4LIHwn1TCf3/o5PImyrYgRyyI0t5NsdKx8wFAp/rg13WChv/5DI8uizH16jbYHG3aAqlYWkRYC4PCR8gDp0aCDhDZ5bwsM9pX1Dv8AUaQGfn1UGiP4d9bkA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8bb44841-fa82-49e5-8892-08d849f455ee X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:15:04.1185 (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: IzjSIZPJMvahdCpi3gIzmZIvCn1a95femRo86o1KqnQCS9cRnUxlcUPZscsOyI6g X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2384 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Handling of kvm_read/write_guest_virt*() errors can be moved to common code. The same code can be used by both VMX and SVM. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/kvm/vmx/nested.c | 12 ++++++------ arch/x86/kvm/vmx/vmx.c | 29 +---------------------------- arch/x86/kvm/vmx/vmx.h | 2 -- arch/x86/kvm/x86.c | 28 ++++++++++++++++++++++++++++ arch/x86/kvm/x86.h | 2 ++ 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 23b58c28a1c9..28becd22d9d9 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4688,7 +4688,7 @@ static int nested_vmx_get_vmptr(struct kvm_vcpu *vcpu, gpa_t *vmpointer, r = kvm_read_guest_virt(vcpu, gva, vmpointer, sizeof(*vmpointer), &e); if (r != X86EMUL_CONTINUE) { - *ret = vmx_handle_memory_failure(vcpu, r, &e); + *ret = kvm_handle_memory_failure(vcpu, r, &e); return -EINVAL; } @@ -4995,7 +4995,7 @@ static int handle_vmread(struct kvm_vcpu *vcpu) /* _system ok, nested_vmx_check_permission has verified cpl=0 */ r = kvm_write_guest_virt_system(vcpu, gva, &value, len, &e); if (r != X86EMUL_CONTINUE) - return vmx_handle_memory_failure(vcpu, r, &e); + return kvm_handle_memory_failure(vcpu, r, &e); } return nested_vmx_succeed(vcpu); @@ -5068,7 +5068,7 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu) return 1; r = kvm_read_guest_virt(vcpu, gva, &value, len, &e); if (r != X86EMUL_CONTINUE) - return vmx_handle_memory_failure(vcpu, r, &e); + return kvm_handle_memory_failure(vcpu, r, &e); } field = kvm_register_readl(vcpu, (((instr_info) >> 28) & 0xf)); @@ -5230,7 +5230,7 @@ static int handle_vmptrst(struct kvm_vcpu *vcpu) r = kvm_write_guest_virt_system(vcpu, gva, (void *)¤t_vmptr, sizeof(gpa_t), &e); if (r != X86EMUL_CONTINUE) - return vmx_handle_memory_failure(vcpu, r, &e); + return kvm_handle_memory_failure(vcpu, r, &e); return nested_vmx_succeed(vcpu); } @@ -5283,7 +5283,7 @@ static int handle_invept(struct kvm_vcpu *vcpu) return 1; r = kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e); if (r != X86EMUL_CONTINUE) - return vmx_handle_memory_failure(vcpu, r, &e); + return kvm_handle_memory_failure(vcpu, r, &e); /* * Nested EPT roots are always held through guest_mmu, @@ -5365,7 +5365,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu) return 1; r = kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e); if (r != X86EMUL_CONTINUE) - return vmx_handle_memory_failure(vcpu, r, &e); + return kvm_handle_memory_failure(vcpu, r, &e); if (operand.vpid >> 16) return nested_vmx_fail(vcpu, diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 46ba2e03a892..b15b4c6e3b46 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1598,33 +1598,6 @@ static int skip_emulated_instruction(struct kvm_vcpu *vcpu) return 1; } -/* - * Handles kvm_read/write_guest_virt*() result and either injects #PF or returns - * KVM_EXIT_INTERNAL_ERROR for cases not currently handled by KVM. Return value - * indicates whether exit to userspace is needed. - */ -int vmx_handle_memory_failure(struct kvm_vcpu *vcpu, int r, - struct x86_exception *e) -{ - if (r == X86EMUL_PROPAGATE_FAULT) { - kvm_inject_emulated_page_fault(vcpu, e); - return 1; - } - - /* - * In case kvm_read/write_guest_virt*() failed with X86EMUL_IO_NEEDED - * while handling a VMX instruction KVM could've handled the request - * correctly by exiting to userspace and performing I/O but there - * doesn't seem to be a real use-case behind such requests, just return - * KVM_EXIT_INTERNAL_ERROR for now. - */ - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 0; - - return 0; -} - /* * Recognizes a pending MTF VM-exit and records the nested state for later * delivery. @@ -5558,7 +5531,7 @@ static int handle_invpcid(struct kvm_vcpu *vcpu) r = kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e); if (r != X86EMUL_CONTINUE) - return vmx_handle_memory_failure(vcpu, r, &e); + return kvm_handle_memory_failure(vcpu, r, &e); if (operand.pcid >> 12 != 0) { kvm_inject_gp(vcpu, 0); diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 26175a4759fa..7c578564a8fc 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -354,8 +354,6 @@ struct shared_msr_entry *find_msr_entry(struct vcpu_vmx *vmx, u32 msr); void pt_update_intercept_for_msr(struct vcpu_vmx *vmx); void vmx_update_host_rsp(struct vcpu_vmx *vmx, unsigned long host_rsp); int vmx_find_msr_index(struct vmx_msrs *m, u32 msr); -int vmx_handle_memory_failure(struct kvm_vcpu *vcpu, int r, - struct x86_exception *e); #define POSTED_INTR_ON 0 #define POSTED_INTR_SN 1 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 539ea1cd6020..5d7930ecdddc 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10763,6 +10763,34 @@ void kvm_fixup_and_inject_pf_error(struct kvm_vcpu *vcpu, gva_t gva, u16 error_c } EXPORT_SYMBOL_GPL(kvm_fixup_and_inject_pf_error); +/* + * Handles kvm_read/write_guest_virt*() result and either injects #PF or returns + * KVM_EXIT_INTERNAL_ERROR for cases not currently handled by KVM. Return value + * indicates whether exit to userspace is needed. + */ +int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r, + struct x86_exception *e) +{ + if (r == X86EMUL_PROPAGATE_FAULT) { + kvm_inject_emulated_page_fault(vcpu, e); + return 1; + } + + /* + * In case kvm_read/write_guest_virt*() failed with X86EMUL_IO_NEEDED + * while handling a VMX instruction KVM could've handled the request + * correctly by exiting to userspace and performing I/O but there + * doesn't seem to be a real use-case behind such requests, just return + * KVM_EXIT_INTERNAL_ERROR for now. + */ + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; + vcpu->run->internal.ndata = 0; + + return 0; +} +EXPORT_SYMBOL_GPL(kvm_handle_memory_failure); + EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_fast_mmio); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq); diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 995ab696dcf0..d3a41144eb30 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -372,6 +372,8 @@ void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu); int kvm_spec_ctrl_test_value(u64 value); int kvm_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4); bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu); +int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r, + struct x86_exception *e); #define KVM_MSR_RET_INVALID 2 From patchwork Wed Aug 26 19:15:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739545 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DE1913B6 for ; Wed, 26 Aug 2020 19:16:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF2B8207F7 for ; Wed, 26 Aug 2020 19:16:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="kfK6nvVQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727964AbgHZTPw (ORCPT ); Wed, 26 Aug 2020 15:15:52 -0400 Received: from mail-co1nam11on2076.outbound.protection.outlook.com ([40.107.220.76]:57728 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726838AbgHZTPq (ORCPT ); Wed, 26 Aug 2020 15:15:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BFfgPfnugRXTAy2ojTR1lPl4xzogFGOZgc9FxkWzw9h+tT2MqBgEtDAh4yNGiycbMQldjOlvPPQgP31fhdJl3ER45GanfhPPSUWOkwByfXwK5KWUNjP7Tzyr+mUCygx6wg7KyzzKOIF1XJ8NquDgtAMusA/SKdQJQDMsFRGpMFsAVeekgTvXH8idpebYGJaQaGFNd8cbW3tMyvhgJmhVDWT5kOCUVy7+XAqOo0YGxi12+a7jp4esdHF5nfYsMuOL0N2rzBmi+ZjIIyzB7mk+RkazyBAqklReJ+fXiYtKhvPWr7MU2m7Zoo5wTWOBIb6VeJjK0H6gUbd6L9rcdXdWig== 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=FczUHdNz8TZmMjKROJr9AgBabQceT5tAe4HHtJdYUjk=; b=C940DQekVfgfeRB9S6ZKAmhZwLOpeik1OFVytrhp28Ner6EwTpMXZ730aX3E+jYTvOK3Y2W0KiPo01fwAhd7uKE/YT8xOjyrdFlFDZQvZMyY4QuvvHeTqM2Y8sDpJEK/EirEeo2dhSu+JHHFAIq+81nTkMDiGVNzknF96QBvhol15Lj6zaOC1261/i/42Z4tuFA7N5+PWPoKgibyGJCj4QLVIcRVE2IBDGihuK+SAuEUPqxN9Rf6b0OQGPgEkcH47njjLcCAF2lHbosLPycLElNO92rVcSHL6izTpWH9J+ZPmJv2hrBAuPwDgMQokyv1lxkjwjn0uq4KB9AHDCk+xA== 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=FczUHdNz8TZmMjKROJr9AgBabQceT5tAe4HHtJdYUjk=; b=kfK6nvVQmYRmnE1N1FF6IcR0KUoNMnI3Qxmo6BlugehmG5u/sRKytAr4E+MoyvTxNmYtxG4NabVVg21+7/23D35P9I3dzMaO8K/O3ZdW+Y8LkcwpNnu57aEBXv43dYz119pE/1riiBlJBEwELgBCB5hCErV4aSGZ2Vk40JuYxiE= 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 SN1PR12MB2384.namprd12.prod.outlook.com (2603:10b6:802:25::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Wed, 26 Aug 2020 19:15:12 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:15:12 +0000 Subject: [PATCH v5 11/12] KVM: X86: Move handling of INVPCID types to x86 From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:15:09 -0500 Message-ID: <159846930937.18873.8981656942066067627.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM3PR14CA0144.namprd14.prod.outlook.com (2603:10b6:0:53::28) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM3PR14CA0144.namprd14.prod.outlook.com (2603:10b6:0:53::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:15:10 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6a66744f-6935-42b0-5535-08d849f45ada X-MS-TrafficTypeDiagnostic: SN1PR12MB2384: 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: 5aCMhHk7rsCvWgIywvl2ijc7B4Jco0wciJzDtTVmz8wMME8JTCdp2RsS+cOSf2FINaSZq/8GdV/07Vnao6yjGj9u7M07WYBsROkPAe6n0Ant3HdB9+s+RNuCTrl/JVI9uevSYF2VZsLpDw9I+5VWIM6wFehyYIYaiSHl0s1cE85de+n59J+H45YvHltQ6AHpgYMquxUqIoRSuf4Pj2s89sgzedg6qsFzCaC5L02pdwXLysShS3zsFkkIuWpv2cZ/rKV73w/qEgp6g3krdyR3b2yr+FfdzZScsMKPZBRx29JPoY45sz/qgmBQaBMnYK3BMDWYPNDxRrOZgBAdgPtmaA== 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)(366004)(136003)(376002)(396003)(39860400002)(103116003)(4326008)(186003)(66946007)(5660300002)(66476007)(66556008)(44832011)(86362001)(33716001)(9686003)(52116002)(7416002)(83380400001)(6486002)(8936002)(8676002)(16576012)(2906002)(316002)(26005)(478600001)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: C1yxCgrwNimp6w/FGn8xuchEAXukh4qrt8KlBF0091maEy4M8y3yg7vXyZKjw9c6fVhYQWbX8lygna77N8T0+nP5plAi3ZiJ9AKUDPwVmkcrKlBkpdg2YdbLOqcVZbpCd78DxmoZQReiCuJvpd+dUnnsZgTgfOxGaO1QvTU13o+2sjrjVbXAk7SEXAyZF0indJZB0XKhXw9JCSsLrspcKZY26UcidvVEKCmYRJsEOoykOlwP37obD5FASgnNkzKHmNsF6C1EDW/JjBqG1zKlr1G9x8omksPddJWNtKo8RrQa5yGpVrLlNWiSs8vKDZZM+Q84lrowv2OyuQMOLpZ7I70u0CmQA7S9ik5si5LY4/BwIdoUNqbUYq0mUAJaEycEuy3KGw/kAfEgr9wK2IM/tRN1p0AhmbXv+JOvlGgP8SbVMT4ZVR/mVaCXX9gtNXi3TrNkdVPm7kEjTzCwq64z9PQk4ZYKG96vwyjPXXgTILZWBdVFDXk+1Dcjoj4kOB50TpThj/y8BJOFX7S9AnL5AA6B9JBTl6Na4alQl8AAebwMvDVZPkrsrDH8vwVe5OKUEomB1s2XvTUBYjkYSfw2AoAQtIaFH/QC/nmcDvN0Y1L2IGroZgKt+L6gj3GWAF3VEKYDfMkmHQ0ZtjCf3RO7Nw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6a66744f-6935-42b0-5535-08d849f45ada X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:15:11.9700 (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: OBOK0SZqOlvun/f4FaQb9zarGnxnS6j2X6gMbUDwOOZkzrwI+KQy+xzJ0mKB7Egq X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2384 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org INVPCID instruction handling is mostly same across both VMX and SVM. So, move the code to common x86.c. Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/kvm/vmx/vmx.c | 68 +----------------------------------------- arch/x86/kvm/x86.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/kvm/x86.h | 1 + 3 files changed, 80 insertions(+), 67 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b15b4c6e3b46..ff42d27f641f 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5497,16 +5497,11 @@ static int handle_invpcid(struct kvm_vcpu *vcpu) { u32 vmx_instruction_info; unsigned long type; - bool pcid_enabled; gva_t gva; - struct x86_exception e; - unsigned i; - unsigned long roots_to_free = 0; struct { u64 pcid; u64 gla; } operand; - int r; if (!guest_cpuid_has(vcpu, X86_FEATURE_INVPCID)) { kvm_queue_exception(vcpu, UD_VECTOR); @@ -5529,68 +5524,7 @@ static int handle_invpcid(struct kvm_vcpu *vcpu) sizeof(operand), &gva)) return 1; - r = kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e); - if (r != X86EMUL_CONTINUE) - return kvm_handle_memory_failure(vcpu, r, &e); - - if (operand.pcid >> 12 != 0) { - kvm_inject_gp(vcpu, 0); - return 1; - } - - pcid_enabled = kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE); - - switch (type) { - case INVPCID_TYPE_INDIV_ADDR: - if ((!pcid_enabled && (operand.pcid != 0)) || - is_noncanonical_address(operand.gla, vcpu)) { - kvm_inject_gp(vcpu, 0); - return 1; - } - kvm_mmu_invpcid_gva(vcpu, operand.gla, operand.pcid); - return kvm_skip_emulated_instruction(vcpu); - - case INVPCID_TYPE_SINGLE_CTXT: - if (!pcid_enabled && (operand.pcid != 0)) { - kvm_inject_gp(vcpu, 0); - return 1; - } - - if (kvm_get_active_pcid(vcpu) == operand.pcid) { - kvm_mmu_sync_roots(vcpu); - kvm_make_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu); - } - - for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++) - if (kvm_get_pcid(vcpu, vcpu->arch.mmu->prev_roots[i].pgd) - == operand.pcid) - roots_to_free |= KVM_MMU_ROOT_PREVIOUS(i); - - kvm_mmu_free_roots(vcpu, vcpu->arch.mmu, roots_to_free); - /* - * If neither the current cr3 nor any of the prev_roots use the - * given PCID, then nothing needs to be done here because a - * resync will happen anyway before switching to any other CR3. - */ - - return kvm_skip_emulated_instruction(vcpu); - - case INVPCID_TYPE_ALL_NON_GLOBAL: - /* - * Currently, KVM doesn't mark global entries in the shadow - * page tables, so a non-global flush just degenerates to a - * global flush. If needed, we could optimize this later by - * keeping track of global entries in shadow page tables. - */ - - /* fall-through */ - case INVPCID_TYPE_ALL_INCL_GLOBAL: - kvm_mmu_unload(vcpu); - return kvm_skip_emulated_instruction(vcpu); - - default: - BUG(); /* We have already checked above that type <= 3 */ - } + return kvm_handle_invpcid(vcpu, type, gva); } static int handle_pml_full(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5d7930ecdddc..39ca22e0f8b2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -71,6 +71,7 @@ #include #include #include +#include #include #include #include @@ -10791,6 +10792,83 @@ int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r, } EXPORT_SYMBOL_GPL(kvm_handle_memory_failure); +int kvm_handle_invpcid(struct kvm_vcpu *vcpu, unsigned long type, gva_t gva) +{ + bool pcid_enabled; + struct x86_exception e; + unsigned i; + unsigned long roots_to_free = 0; + struct { + u64 pcid; + u64 gla; + } operand; + int r; + + r = kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e); + if (r != X86EMUL_CONTINUE) + return kvm_handle_memory_failure(vcpu, r, &e); + + if (operand.pcid >> 12 != 0) { + kvm_inject_gp(vcpu, 0); + return 1; + } + + pcid_enabled = kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE); + + switch (type) { + case INVPCID_TYPE_INDIV_ADDR: + if ((!pcid_enabled && (operand.pcid != 0)) || + is_noncanonical_address(operand.gla, vcpu)) { + kvm_inject_gp(vcpu, 0); + return 1; + } + kvm_mmu_invpcid_gva(vcpu, operand.gla, operand.pcid); + return kvm_skip_emulated_instruction(vcpu); + + case INVPCID_TYPE_SINGLE_CTXT: + if (!pcid_enabled && (operand.pcid != 0)) { + kvm_inject_gp(vcpu, 0); + return 1; + } + + if (kvm_get_active_pcid(vcpu) == operand.pcid) { + kvm_mmu_sync_roots(vcpu); + kvm_make_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu); + } + + for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++) + if (kvm_get_pcid(vcpu, vcpu->arch.mmu->prev_roots[i].pgd) + == operand.pcid) + roots_to_free |= KVM_MMU_ROOT_PREVIOUS(i); + + kvm_mmu_free_roots(vcpu, vcpu->arch.mmu, roots_to_free); + /* + * If neither the current cr3 nor any of the prev_roots use the + * given PCID, then nothing needs to be done here because a + * resync will happen anyway before switching to any other CR3. + */ + + return kvm_skip_emulated_instruction(vcpu); + + case INVPCID_TYPE_ALL_NON_GLOBAL: + /* + * Currently, KVM doesn't mark global entries in the shadow + * page tables, so a non-global flush just degenerates to a + * global flush. If needed, we could optimize this later by + * keeping track of global entries in shadow page tables. + */ + + /* fall-through */ + case INVPCID_TYPE_ALL_INCL_GLOBAL: + kvm_mmu_unload(vcpu); + return kvm_skip_emulated_instruction(vcpu); + + default: + BUG(); /* We have already checked above that type <= 3 */ + } +} +EXPORT_SYMBOL_GPL(kvm_handle_invpcid); + EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_fast_mmio); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq); diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index d3a41144eb30..6781fd660a29 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -374,6 +374,7 @@ int kvm_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4); bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu); int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r, struct x86_exception *e); +int kvm_handle_invpcid(struct kvm_vcpu *vcpu, unsigned long type, gva_t gva); #define KVM_MSR_RET_INVALID 2 From patchwork Wed Aug 26 19:15:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11739551 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BB5314E5 for ; Wed, 26 Aug 2020 19:16:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 267742078A for ; Wed, 26 Aug 2020 19:16:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="FLlue/ha" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbgHZTQ3 (ORCPT ); Wed, 26 Aug 2020 15:16:29 -0400 Received: from mail-co1nam11on2076.outbound.protection.outlook.com ([40.107.220.76]:57728 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726936AbgHZTPt (ORCPT ); Wed, 26 Aug 2020 15:15:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QQay5lsvAOOcfMXr2w37htCLflt09EieoGw1y7GXnXastzoDsoOkUkbV/zM0quae+Wf65dLpa7NgWENnYFAeVJSc79g5gbTrt2ZANENmHXXnumMa0AMoDxyTU87umwh+yPJvsavmAzE9l2Wl6+bpcx7QaEWfY7v/RSG9uZi+kdaEbGRAHrEe04SH6QRCyMu6AxTqVOrzGa09M5FHdnxw8Go7qyhRJaZSha91j0YsGYLiSjNrqK26Ux3b0H/Yv/b1PLBA+qr9NThiIqtBffKsBHnk6tmgxpiqSfC/TWsCHGAV0/SCsPJM0urXMnXJzj9NFCvhmVU8keYjhbpPtYdQWw== 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=OkAXNOlTrAqAiZAxtVv7rpz3P8AgatFSU4lWiD+EO5o=; b=JXXWGJ7F5vmuET23QUGhneVZNS8TFUugK9PS/xx2DTVtPnNf6naU94NZvW9W3YY37jY5cAYAIRmwR8ag2hjmvxez7LKHU2CAzByxPqspObU4LNg/gM6oNW9HEyANfjwgWQsy++UsL6fIAlITG46l8nz3+mW5UFFoG9mOXcdQ1FuRG7gPT92Fl4gZSlSoB2Jjm/kY8n9ghvX17kqibRSfGPx234PQAFEK4KJEVEem2nWBV2wv0crCGLwiqXw7pco1sE+/ArMQognQ1WK1jn8QTc9fZD3MYuhDl9oJrf1bpoXivRuWa57a+J5evwj9zcf1C3w0+5Mi6cybC30x0LXkrg== 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=OkAXNOlTrAqAiZAxtVv7rpz3P8AgatFSU4lWiD+EO5o=; b=FLlue/haI+AwinNSv2pHukpp8HzvOhr8ev28OWVm9tM1JXd0CSc51oWBywHFbMEw8DgtwWGEUR1sIzu5SKg7X7qXpnNEvNqjQgVbBhQEoBBEMkEzabpXQIEJuzSjHviQz4vz/Aneb5cFZZrHPNE6uomuOL4gyibY9YQKq6lS3y4= 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 SN1PR12MB2384.namprd12.prod.outlook.com (2603:10b6:802:25::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Wed, 26 Aug 2020 19:15:19 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::ccd9:728:9577:200d%4]) with mapi id 15.20.3305.026; Wed, 26 Aug 2020 19:15:19 +0000 Subject: [PATCH v5 12/12] KVM:SVM: Enable INVPCID feature on AMD From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: wanpengli@tencent.com, kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, babu.moger@amd.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Wed, 26 Aug 2020 14:15:17 -0500 Message-ID: <159846931719.18873.17261041399321750933.stgit@bmoger-ubuntu> In-Reply-To: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> References: <159846887637.18873.14677728679411578606.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR16CA0046.namprd16.prod.outlook.com (2603:10b6:4:15::32) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by DM5PR16CA0046.namprd16.prod.outlook.com (2603:10b6:4:15::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 26 Aug 2020 19:15:18 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 240ce38b-b4c6-47b4-7eb9-08d849f45f34 X-MS-TrafficTypeDiagnostic: SN1PR12MB2384: 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: QWdUFG5EbscY2A2qWFiHbnGnw8GJdi1QYIbfT5pob1rcxff4628eY7FWQt6RLY7RifZuQ7lkeqRYlOVAmJ54LHGGcT8Dv6/6z2Fa5IvrfQC6q6ippC8EJ/VS30bzrMn3CsYrIdViF6XeTD8kbFC+pFUox4XXIjuE3WORAsdLz0jkRSyVe0QHcFSCSuNwIOYpIQSGR61nr2Q8UZBsgxsDPkXERGTK9MAz8QSKvwVOFqISA6vwuXIe2TDzR0v4Mwqghg1e4XdTMhBVbAa6PLzsOWQ+2TrHHiDW1KY8zD6+qIvNq8jgffaxHVuCB3b4lNedeLkcngncspivo4Eq2YK03Lxsh1n2dZ52/XwzaTSLJc19ZRUOpwRNHh3G56Wt/f+Unwrl9dtEIwPbXLIfRZYEoA== 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)(366004)(136003)(376002)(396003)(39860400002)(103116003)(4326008)(186003)(966005)(66946007)(5660300002)(66476007)(66556008)(44832011)(86362001)(33716001)(9686003)(52116002)(7416002)(83380400001)(6486002)(8936002)(8676002)(16576012)(2906002)(316002)(26005)(478600001)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: M4Xm76KyeYBCR+u4Aud0xIBFf6+LZxcd9bFgXh3hOPHh1DBwkVgWxD/P00L0+wrbywO7zy+KXplXRLDA0U/J+pkSDVkH1ckzL8PIz4LjiVCR/V7WrwcNrvg5b7KZdMpvmperVccXyhAOguzcmTiBQ3XpWFBZxcZ5H9Bpw2y3dv0HDzolBhE5elj5FkmzKS3PFy0hELBLOoKEs1/iMan1nAszWSOwWS010Rzc4mt/OlOYhmiG6pnZYFw8qNfRBIdy7nItbEFW2yBSQZOx9idOZ+il9wLxfvAUHtTJmYn/pXbT0CXUe6fsEwPggaS+uXUfPEN3Lr+CkF6sRp433NCKGUu2vG21cKM5Wg+DrXQM3dU4Nm1FFVYCjBeAOP+aY8aUQP541H/ThnNNlvpiRFfOnQjzSXqUqijjkYScvL1EgISCxWxEJHUe/A/3FyemDru2OphKkYr3KyoKTJ4xhwyjP2NnNdYwEBOK/RrGwKmJg2J47AXUaNSeE+FmCZ1eL+gOy0CejKlp9BCCgW+sJy3fqS3d4QYZkjQ/+QpunSRDFUCMeM1VzNr2gNpgEJKqEPCqBTXN+k5nSRBBMFPl6sc/Wmpzd1vhRHGSmvKS6D/SRXxqKbvmKxGqyquAzJfK9GEp3owuXotdsO95zV/tc4EVUg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 240ce38b-b4c6-47b4-7eb9-08d849f45f34 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2020 19:15:19.2647 (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: ZwMkEbIYL7uksKNYLIf3hbk3d0PfonZ5oZ3wlhAO2U2PauXnnS7WkGiS9AHjxbEB X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2384 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The following intercept bit has been added to support VMEXIT for INVPCID instruction: Code Name Cause A2h VMEXIT_INVPCID INVPCID instruction The following bit has been added to the VMCB layout control area to control intercept of INVPCID: Byte Offset Bit(s) Function 14h 2 intercept INVPCID Enable the interceptions when the the guest is running with shadow page table enabled and handle the tlbflush based on the invpcid instruction type. For the guests with nested page table (NPT) support, the INVPCID feature works as running it natively. KVM does not need to do any special handling in this case. AMD documentation for INVPCID feature is available at "AMD64 Architecture Programmer’s Manual Volume 2: System Programming, Pub. 24593 Rev. 3.34(or later)" The documentation can be obtained at the links below: Link: https://www.amd.com/system/files/TechDocs/24593.pdf Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 Signed-off-by: Babu Moger Reviewed-by: Jim Mattson --- arch/x86/include/uapi/asm/svm.h | 2 ++ arch/x86/kvm/svm/svm.c | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/svm.h index 2e8a30f06c74..522d42dfc28c 100644 --- a/arch/x86/include/uapi/asm/svm.h +++ b/arch/x86/include/uapi/asm/svm.h @@ -76,6 +76,7 @@ #define SVM_EXIT_MWAIT_COND 0x08c #define SVM_EXIT_XSETBV 0x08d #define SVM_EXIT_RDPRU 0x08e +#define SVM_EXIT_INVPCID 0x0a2 #define SVM_EXIT_NPF 0x400 #define SVM_EXIT_AVIC_INCOMPLETE_IPI 0x401 #define SVM_EXIT_AVIC_UNACCELERATED_ACCESS 0x402 @@ -171,6 +172,7 @@ { SVM_EXIT_MONITOR, "monitor" }, \ { SVM_EXIT_MWAIT, "mwait" }, \ { SVM_EXIT_XSETBV, "xsetbv" }, \ + { SVM_EXIT_INVPCID, "invpcid" }, \ { SVM_EXIT_NPF, "npf" }, \ { SVM_EXIT_AVIC_INCOMPLETE_IPI, "avic_incomplete_ipi" }, \ { SVM_EXIT_AVIC_UNACCELERATED_ACCESS, "avic_unaccelerated_access" }, \ diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 96617b61e531..5c6b8d0f7628 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -813,6 +813,9 @@ static __init void svm_set_cpu_caps(void) if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) || boot_cpu_has(X86_FEATURE_AMD_SSBD)) kvm_cpu_cap_set(X86_FEATURE_VIRT_SSBD); + + /* Enable INVPCID feature */ + kvm_cpu_cap_check_and_set(X86_FEATURE_INVPCID); } static __init int svm_hardware_setup(void) @@ -985,6 +988,21 @@ static u64 svm_write_l1_tsc_offset(struct kvm_vcpu *vcpu, u64 offset) return svm->vmcb->control.tsc_offset; } +static void svm_check_invpcid(struct vcpu_svm *svm) +{ + /* + * Intercept INVPCID instruction only if shadow page table is + * enabled. Interception is not required with nested page table + * enabled. + */ + if (kvm_cpu_cap_has(X86_FEATURE_INVPCID)) { + if (!npt_enabled) + svm_set_intercept(svm, INTERCEPT_INVPCID); + else + svm_clr_intercept(svm, INTERCEPT_INVPCID); + } +} + static void init_vmcb(struct vcpu_svm *svm) { struct vmcb_control_area *control = &svm->vmcb->control; @@ -1114,6 +1132,8 @@ static void init_vmcb(struct vcpu_svm *svm) svm_clr_intercept(svm, INTERCEPT_PAUSE); } + svm_check_invpcid(svm); + if (kvm_vcpu_apicv_active(&svm->vcpu)) avic_init_vmcb(svm); @@ -2730,6 +2750,33 @@ static int mwait_interception(struct vcpu_svm *svm) return nop_interception(svm); } +static int invpcid_interception(struct vcpu_svm *svm) +{ + struct kvm_vcpu *vcpu = &svm->vcpu; + unsigned long type; + gva_t gva; + + if (!guest_cpuid_has(vcpu, X86_FEATURE_INVPCID)) { + kvm_queue_exception(vcpu, UD_VECTOR); + return 1; + } + + /* + * For an INVPCID intercept: + * EXITINFO1 provides the linear address of the memory operand. + * EXITINFO2 provides the contents of the register operand. + */ + type = svm->vmcb->control.exit_info_2; + gva = svm->vmcb->control.exit_info_1; + + if (type > 3) { + kvm_inject_gp(vcpu, 0); + return 1; + } + + return kvm_handle_invpcid(vcpu, type, gva); +} + static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { [SVM_EXIT_READ_CR0] = cr_interception, [SVM_EXIT_READ_CR3] = cr_interception, @@ -2792,6 +2839,7 @@ static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { [SVM_EXIT_MWAIT] = mwait_interception, [SVM_EXIT_XSETBV] = xsetbv_interception, [SVM_EXIT_RDPRU] = rdpru_interception, + [SVM_EXIT_INVPCID] = invpcid_interception, [SVM_EXIT_NPF] = npf_interception, [SVM_EXIT_RSM] = rsm_interception, [SVM_EXIT_AVIC_INCOMPLETE_IPI] = avic_incomplete_ipi_interception, @@ -3622,6 +3670,9 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) svm->nrips_enabled = kvm_cpu_cap_has(X86_FEATURE_NRIPS) && guest_cpuid_has(&svm->vcpu, X86_FEATURE_NRIPS); + /* Check again if INVPCID interception if required */ + svm_check_invpcid(svm); + if (!kvm_vcpu_apicv_active(vcpu)) return;