From patchwork Fri Sep 11 19:27:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771433 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 0E8FD618 for ; Fri, 11 Sep 2020 19:35:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2FED22208 for ; Fri, 11 Sep 2020 19:34:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="ZSIqcAu9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725796AbgIKTew (ORCPT ); Fri, 11 Sep 2020 15:34:52 -0400 Received: from mail-dm6nam10on2075.outbound.protection.outlook.com ([40.107.93.75]:49377 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725835AbgIKT2K (ORCPT ); Fri, 11 Sep 2020 15:28:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lyi/i5NGGL/Rvpld8rudFDBOXQAoQ6EmJYNoTQf6T87GTa18MAeIcPRl7DkqBzaKZ7J5xKAH4s2/SYPsyziLzys2/6i4oYHwxJjH/keDQ22ioMCOtcRt0yfACZq5E6/yRqxJ0nRiGwQ5kRlsbIxUYpD9zFBBDwOjZ3pu00WkSKogH+CFNwmncJ5BWRM1tDcDXf3ADQxXd8y7aKJPBz/SLg9FC6PO+Of1Aa+mw0BFs5qhAF+0eclnLnL5bXNHkYcBZ2ksGcBBt2GyAQLOndLfY3LQlQZoRhlkOVtuz+FpCnGub5eI4bMQ0cWIwXn6mhe5i0BOLXwIZn8CUPlysLa0gQ== 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=VsEd+IONZz7nfctO26GqncX8mvyIk9ArYkf/jcTkvFc=; b=ah55lTjUgyAfEzMyoB/+bmeVmU7lDljyB9MmchYKzAJLJOD5PTZxbTTxmzw23o/G0WIudzO1h4+ithnyyU4hCfoKKCcVLE8ckOhwuBVckU+IpMGk/m7XF9tuF4PNsozu3IWbz7s3hUunyQJ3+VQPMqHCOyTTFR5KPaY8uXtfXQBVrT2OONbIn8B3L6HCiJ2xVZQhM5sCwMhQkjaAmNosLCweVew7J0ADrF6XLhhfI6EEQ43WHgvsJX45Bvjsumn0uRYcdV6riX/W2DNKK6p7RQlO/ZF+Ne/AK3g7ea0Gy7YCCkoyCrKgg+HG9m+8ZTUcZ3+tbPpgCtbTzWIq9fgtVw== 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=VsEd+IONZz7nfctO26GqncX8mvyIk9ArYkf/jcTkvFc=; b=ZSIqcAu9yl+jFb9f5uCa8bVNysyKKqSIkJdqgJxCXbSNiRdW9QrDRz42Gk23leVR1XB7oLUf3mIZFW3t1aLvUbRu/oKru3ccdhw8LSxGX8+XqBchPIXkw+iYE+WwVBVU/jbCFWa+ziOh9EtD1DcQrXNv/OVV3BtcXqMcLbf4jTA= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:27:59 +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.3370.017; Fri, 11 Sep 2020 19:27:59 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:27:58 -0500 Message-ID: <159985247876.11252.16039238014239824460.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN4PR0501CA0024.namprd05.prod.outlook.com (2603:10b6:803:40::37) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by SN4PR0501CA0024.namprd05.prod.outlook.com (2603:10b6:803:40::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Fri, 11 Sep 2020 19:27:59 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9a6adda3-6338-44b3-632a-08d85688cb29 X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: a9qzhktaRsluvhbmJeJFRn5DaeGO4OL2y54em7ojLe0W7t/J6E2SMQERQakKhbi2DtBRUiPIjMJGoBYNLmYurlp7rfr88ppH3eA1fYVcjB6R+9wnWvwDT3YtyL4nK9jDv2THNRAgCi5rE7O0pfMXSMA9fVCbme7A/FgWZPD6Gq5IGN+tWB9BEUpV5oM36mwwv9sLn8/3Ba+ypMO3wyK7fNBx1BsRj6QDfCN5mOBmQo0yg5J6xbEDhSbzjMdhHZ00vF1hjP0gdnwZM+i76ZE7csFyGo67i9Hx5ArBOyN48XQVoFZhCPPTvRcsUN6xN9O3OYv67U8/ljE96/2x/8EtNQ== 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 9WapRrfjuvClAjC/klkuCCrpya3FMC6Mw7ZfWjaNY02hXHFoLFMPo7WGKFEaYfy2PP0Kk/WiSZz/tcLGlqyAZwlI164e2TF2kOjbpoXcvqUNaGyXpbnYD8aakKniJh7SWZyihBYUVgOCAhNg9lJx1l/bsGhVsuq9keEgrdJXITjNQ8GghHowcP8hpEmNGuJrXhv9bhZIR5HSJIlcIa4Xo4ikU5sRLedLenNJjyC5S+bNPK4BnGtfutGPh2mW7kThEk1M6IB6fkqQuf6q0Xhl14treha6raITcjdJtlyCn/+Hvl405ql8TMbeOKAAKEUdevecLfFavHSeyXrVWlSCT40XEy9P3js3Y7gfJTPppWVtFGc3fC80EfX25JOl2KjHncbOqys1Aqpi5EBf8PBeR44LRTSWSaMPjIB+rP40+pWqnO/YVqYzTOpAIhF/GS3l1NAeNNrq9MpmopF4dd/FWjIbDzY5UjgxyC8T/LnADS0bF+TlDyWaQmeAjXOWd8nZLwZuToMHQvCeSTQ4nHJbVvpHSEX7O+Np1HHtwAdBZbJkG9ulWN03WJutbsw+VdUrB50gLLMSRZh5gE2w9Hp+imwbeQhcZeJ5H2ju3/1CRx6JQBK+LgTvpKi7L6JK4DdraC50j6LiN8siGJMD7qC05w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a6adda3-6338-44b3-632a-08d85688cb29 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:27:59.8182 (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: XTcBLrJJTxGiO9p1X9IR1N4kZHBdQuMxK06yI7AYY9uXOmI4ku+eF8cYzoJrvALQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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 Fri Sep 11 19:28:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771435 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 EE0DD1709 for ; Fri, 11 Sep 2020 19:35:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C78E82220F for ; Fri, 11 Sep 2020 19:35:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="lafIg+nU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725853AbgIKTet (ORCPT ); Fri, 11 Sep 2020 15:34:49 -0400 Received: from mail-dm6nam10on2075.outbound.protection.outlook.com ([40.107.93.75]:49377 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725783AbgIKT2V (ORCPT ); Fri, 11 Sep 2020 15:28:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cp8M1C6QJCTi3fEnTHCXFQPNNxhfMtxjT6lCqJQVukPgNZpCkJFNP3Du19+Jk1BWgbgWH62As9kS7VZxH9PkjVD+8Ozy1D2c3E5AecP5XK2KUFPsg/vbgZO/Vz+NfNAWcrSGUfqGIVNKtVPXSLcmXpeWOi6FVCgZKr1e9gyCOXsowrkoyGZfNSsSYk7oPnmg9CxhZiyyYGcHjIWk88MMWrHw61ZL6ZFL6xjkz2ZVuafUX9NWB/WX9gfeV4q2otrnXiFN2FoDSfyZ9zYD4fDhrdv4VYSq/fnsWrwXEq/c6PS2i1hY42uf1xMnvHEwWU6khAuxSts1pLDK0YJwqHXaFA== 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=epTd2sqgyV2oHEQKepmcFy2r+btPsCycThlOKFFYiag=; b=C7NPesV7ntsCKTrsujIqZEgBE46xX28bES2NYz4WEb0IPRMDGbHi3Ho9FbrwV78gBrfGlSTLcDWqXX3617a/kC4z6+1X9ZiJnJqz3SqB5ZOxL6qRHPxfcK2IDiY/JDNgPAdlVPRVk3f2RwcRTosQAESOiE+Ji23Be7ny0uYSNMTKADfxSIav/pP/OC6QIlwzMWDTw/fTzQj/FlSzEs3gnGp1B81+en+ODSv4Nx3gC0cvGyl1yf3TiqBRihMeJbY1Aeb1fB+/kFW3gob+21edw4OUuXKxMHlu9g6pCXyJssg4NGPI2Fie27tvIFRyW0E58bstekEk/fHSXopOah9t7g== 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=epTd2sqgyV2oHEQKepmcFy2r+btPsCycThlOKFFYiag=; b=lafIg+nU2aC0bLSy+Otb38HhURX2yAqqWVLbp2cseBih7tKlsyhNVfLhocMt1ICxHRVQ8VUMRGiJ099fNSEVeLy02DDypin6TPlvqI0HIRRtsurbhnHxvp8BYhnwlNSbRiBBf0Nlw6OJxkghMyzEMic/TvT07rj9RMd+Tit4W5E= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:28:07 +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.3370.017; Fri, 11 Sep 2020 19:28:07 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:28:05 -0500 Message-ID: <159985248506.11252.9081085950784508671.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR05CA0024.namprd05.prod.outlook.com (2603:10b6:3:d4::34) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM5PR05CA0024.namprd05.prod.outlook.com (2603:10b6:3:d4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.4 via Frontend Transport; Fri, 11 Sep 2020 19:28:06 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a6aa8f17-ecc5-4864-9297-08d85688cfa3 X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: n9HjTeBKI4XXU9Jd8PhZtLFSp1NoIZdh6K1WXbvdxT8Ysn7dQ6sWOX6dWTkDfPt5bstegpCLDMOnO9c82xph0/pd2DpKHW6nHQJGIWBHTaZd4g1zCShr8wSqRF1up8YnVyR50KCgo76zaiOLTXCvcQw1T/xGuBRWUrxMhJeu60/jBXeMLSRtIH+mVCahSrBPauu9oXjs9GKTmbDfK0rM3wgdFzDw7J7qN73qzCAjV/SXG9mw0+UdHfAVjFt0MhZRBBiQqaDiQNJCMmuZrVXaaj2lQL/ennzxdar3+elhO0Ec6YEPSnLepTDHCynJFmDHuemrhlyjNZCCT1jjwq9AFlK801wuJTDMG3YGVVyYR8Bh3QlCmNqCuoiYjAEqQ562 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005)(83380400001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: VQHryGawRkZhShK0zJxMcGVKKk0Wo/cAv0Zy4kRu1Oqhoqx5ef6Sn9190lOA6fpzV4xT2dCh820eFUNUr4PCI+JCh2MbQux8xaUgc2gMfv9blva/C3WZA5Q52G1iRhqCqzgYKiXT5xil8Alv6GPMwtTfR88u/ISg3jHJEsu6uWzB8RW6kiGM6Pz4YPoW/qxqJ5PaSh1ArGav5Xz047kAGKLsJ5gm2FLMdNwC82zuFdgI+pk2mm5GvKey4qlO+w+Hl2VS6saf4zOOP9nqkNXNWQb2FTLgashw8dC2eA34p6OExRPXC+6QbpzE0pLwOpxy5DaCrEMuYoUS1zKdv7kfysZ/nuBkR0kumReuB2m7pkPDkCfjTR9/Ydr5gdf0xR2SvUb3VPVMuq0Dv7irvz5L7BAjNarmPeHQ852Z0iLC4j+dBdTaTU+Ty2V9iHvrhXhe6/7lrr6EeH5lbH8QVC3eG9W8sI//20iNPAoGtdk4gxDFBNDgnLKXCfuBitOYUHdc3cbMqEd4NzEKZdjG0WKlgrTJPYO6M1kwglShIYEyl1vul9yufQXpOpGgqN1pMC3rN+0L2ixGD+11n10EH2V47jzGI4BehqIp2RYNjzDtf60DKx5RTqraAuhsw1qZyth9IPe0Wb5jKFln/PBJTQIipw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6aa8f17-ecc5-4864-9297-08d85688cfa3 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:28:07.3409 (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: Y9I29RHbMwXGIB9oVSKo/npJgX/Xshqfy88+UH1c3iA2FQLvDfqevOu8Sl1oVbz6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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 Fri Sep 11 19:28:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771415 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 ECEA4139F for ; Fri, 11 Sep 2020 19:32:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0A502220E for ; Fri, 11 Sep 2020 19:32:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="qPbcDISq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725887AbgIKTce (ORCPT ); Fri, 11 Sep 2020 15:32:34 -0400 Received: from mail-dm6nam10on2075.outbound.protection.outlook.com ([40.107.93.75]:49377 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725895AbgIKTcS (ORCPT ); Fri, 11 Sep 2020 15:32:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EEaMcmLd5PlUuFgnT5Se2DEtpxhRqLVKNZhtguIF0SvnSA0+vc0p/RN9VaWTJfCXSgljK3psSvcCAmzCYEadEmZ0WX9CXbWMo+njm8/AUvflLSXfcF+rpf04/TnAuZX36845G/Hdyag1AmgmzdZFP3Bzleg/ZZqsrzWeqc1ZlbZh3jEcHBwg/P+PkwsS+GcCC61Y00dt699Tt2NINI9wgaXCarhtB0ADcSktGOsxRF3E9jwiNA8a/pZXiMfuktJ5YxwaEyG11vS7kiddKhqfMfK0g8rSHhLD6H3tKj38k/DicsDwX9pP4eDm7PiD2SDRt28Bmswccx7IMz1hGG+Pag== 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=fxI0klGKMl7daCyQYoiqlfLP3wvifwYsQqsx9i7BXz0=; b=PQ0MxPq3ntR0kfmWAi8qi94rEC8Yx626SMwPZ7UocrVAYA2z1PS4g7r/H5COsnE42vUs1LRAL2OL+gpl/oNaqhYF1ZqU8Diiu8npC3tVxqtMu+fcI+3HKCXkty3NPa67Zw5YT/VzAm04fl/t9KyeVQob+SNTt6TaXs2lw01ZJ4bXkKo6tEpp9Us8s7o+13UDonlPCHGdHmvFS6I/olHd7Lce3erDGJAaKXDHolM/2TOCDCGc6iMtsbBjZJBv4fon2RA4M0qbLSxIHag5I1NN6C9ggf3CUAdsv6FeiUEN7RZHWP7m2T5b4eKwQ3BIuTKgCTUMxdXMK6UQoL0C8q+nSg== 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=fxI0klGKMl7daCyQYoiqlfLP3wvifwYsQqsx9i7BXz0=; b=qPbcDISquG0jYGLIQv9W59tfAeizXSzZFoeWjVw7S6KbYVemyDuPkoncr7E67q+2xi/QDdEPDku4/EFvq2JzX9q5jrD4ZYVTptLq/ddZs40SQs/IUOtJunD1wnxTH2YX7eG91IOAnA9q6idDHjqMzDVfrtihoUG6/0wrtrc0s+I= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:28:15 +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.3370.017; Fri, 11 Sep 2020 19:28:15 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:28:12 -0500 Message-ID: <159985249255.11252.10000868032136333355.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR05CA0016.namprd05.prod.outlook.com (2603:10b6:3:d4::26) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM5PR05CA0016.namprd05.prod.outlook.com (2603:10b6:3:d4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Fri, 11 Sep 2020 19:28:13 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0dd14278-cf76-4de6-e217-08d85688d406 X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: 47l3NZo063R/OtBYnB8vSqKGbs+k65QdSVN+bJNDr+4+7OpMKolrJYrLyQjqUauTkCZhil1Jr7Oz92JRcqAllYYuj4Ou3fIVHggDthZkU5mFVHateV1D/e+g/DSQXRcF8Vcj3Qi5gGeADjfxl6UvDCTBkBdRUYdIyNXPK/9KH7ESgcpqlhzsEo5Kbj2MZqRdxvnz6Ghh8pZ7QkkFW7ff1U+KSGMOauEi1KmwQ0Cu7xAhxU1PFyvi3gc1fzRiWmOSJZPfr1/RG5ZmBhJNWE+hc205pyCOEVIrBMH7aippKOPzVkTv4fLIcWFXqaJIsWdJn/ANBaPUGINNuBfiQaIbjOj5TBTvmkJN5Yl65Zob6VvcHQJAkwcaANjXc3zDsRMM 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005)(83380400001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Qtdpy3+WZPRCaYWruw8ojAnAVEY+TSEwpKbtzZjNNeUo3KjXF7PgtiVMxkeqmFPjXsp4aQXQRrfVpdY14LHsvxoERKGYlxbNlk2WRfwg3fgjG7oke4DJV9fkxq8lg/c8nRycWqPuhHXAI4kEu3lPJ8Zs8QAUzNklC+Uy2LKDX0Lg3VRrATX4ZwaeE+CY69wteuOgtZje0LEhVuRfmZ7ZveYLKvrWgyaKYDmxEreo1G/aWl+bakeCX1nevXR/CvlzegPDLiPvNCS1w30nbyxVdhHjuLb70kY4o9oXkclIT9l6wDYScd/5twPREl2U4X45FkD/vQty6XMISKJS4OD9XWWeS4VQIakof6XDs+fQVaRoXvhuygVmELCKcBWMXtLK3DxBu5JRbe2GmC1UHxTAtwMsmAa625yoXM/lyQroR1TUhIU3WZRObkocdaIcPsOBGC0Xk9QSvdb3UzdfdRUM/clj2dikkgS1rCN880RzkaFLO+Ir+qb4qXC3sp+jhf0k5TEWfijcYyMPq1g5Mu06rDlmGE9Y2sJVXu2C68Hj7ENCZSkaLL/fQtFA9onH8QCOJ3aQr2xC08dFfp3riN0kWqk4X2HIXonwSOBrJXflOkkeBjkJs5Q4HT+x64WdzDZkRJ0UyKBiNC0W6yFE6kIQnA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0dd14278-cf76-4de6-e217-08d85688d406 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:28:15.1603 (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: NEO9khH65FBnBeGbXt8fdGvHXAAyFdZ2hoaImTG3ZfkMBRQC2809RrkFpI684zYl X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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 Fri Sep 11 19:28:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771423 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 34D88139F for ; Fri, 11 Sep 2020 19:34:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0DB62220E for ; Fri, 11 Sep 2020 19:34:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="PeMFZ3ET" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725860AbgIKT30 (ORCPT ); Fri, 11 Sep 2020 15:29:26 -0400 Received: from mail-dm6nam12on2052.outbound.protection.outlook.com ([40.107.243.52]:48352 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725932AbgIKT24 (ORCPT ); Fri, 11 Sep 2020 15:28:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aG2Tll2pzNN+ENNmFpwX6AC19H/r0ee+shEZldZnAlsYBxzRnIlQOBv7NGT8LYI1M3J/yt+xXRaW3xUYBfrKzndZxwVaVvd+p4YDacoafcP8Rb3jbyNFNZz7Vf5BxCPCNDyxp5WXXR0EOYAiN3IPERhaOjA49D0MamKC5wgj0YCgOlUV/hcRNLVc6kdal+ddn7ztqElw5qwpnjb068vR9Pzku1GtU+ykG7iePy9RlDdoSw+SbD990T9EjF+aVQlJsQGK8wHD89Ow17E1BpKxCwNbEPn5WY9kBvcSXBZ0wXf8lMdceCdlJwPFjxzKezjrMCZujSNGCg/sVLYAEPoQ7A== 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=AL+2BO66nGX6+M1cLiCu3XKZ7Z3ha+Wor8cAKP1WRVQ=; b=nBdzrEnjkWb97MvUzDxXdH+H/e3raU4v/6BnOowNFeQDytea5j+PKKks7BIgGAn4DUSP75fE4N4ayuTZOqNDFz62iaqucB6aiiHuReXSRtABO4pUZEw7XmQBcHkfHEe7QmgVLe1JEnD8kqb/i4CDYAF0Bxpivo5KHycaIVlNLdwz9LcbJ389itT9E36PH1wMP3dRjKk0+0UwCcvouzkVCb2vCy6csmndVXdnC+6hOav8f/JEOeMapd21J4xfL6SZez0OTzwJglWMVCpt2sYO/l1SN/SEKQemqqLaYoyg6ppoISCbVnwcgkB5a9wCph6IaaCzq4tkeTj3BFa7hRO9FQ== 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=AL+2BO66nGX6+M1cLiCu3XKZ7Z3ha+Wor8cAKP1WRVQ=; b=PeMFZ3ETDNsjReAFbg8sqeQPPhZbarVcodMgvg9COme3FCF9x9zDWavhs/k2XlqfC2BjcCZ0BTD3UFMZAvqUgXSnGVpXkPnj01Iiq9yfYPg/S2tkndfaB0QVsWVQizxyDBgvf+doZu2mEkSwtUOyNuV1qzT+zMaULY/s40aeNNo= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:28:23 +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.3370.017; Fri, 11 Sep 2020 19:28:22 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:28:20 -0500 Message-ID: <159985250037.11252.1361972528657052410.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR21CA0002.namprd21.prod.outlook.com (2603:10b6:3:ac::12) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM5PR21CA0002.namprd21.prod.outlook.com (2603:10b6:3:ac::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.3 via Frontend Transport; Fri, 11 Sep 2020 19:28:21 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2f3c5257-7ce8-4398-12c8-08d85688d8e9 X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: yEIFpCZeinqkYtYtortozdt5uBBA5tcNWdHf9ivIMEmh550KXyffJkmWi24SpYtl8D28eYn/PpDFJGrjjfliupbDzd35CxcN5k8blOwBM3DxywWIk6gFnMzZTmaegDwHxEoC8q0pPzSmY8UKcdcLeX6QU9NFHxWF9JRL7CK3UeF4FKJxMz5GPyCntv/nidV8ZIZMbK0gFJRp7/37kxLL2bhtbrg58mtjJrhhuAYhozIAirdd7Tlkc1insf9565XNqmKXurOK547A6+2vcQ0hu8HPLNfnt1oNOeiPPyJ5ypESB2ik8T8WRobS0veYlAjnNiaC2nF77X/CoC2quRCQECMk1Z2bStS0/TDTM6mb3M5VpxSJOp/rPv96yCsmCDwd 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005)(83380400001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 4xtVsTswC3Iwp3mfSTjWS7J812DuJGwVqWsilaWqQvjhS1nzEJim6VemQ6LtxeQWu63gWY/RMB8Gt1y0v1/xIw9DQ2RdtbyU9eCQZ1bg8hFP8eEGvY+c9Von4eVq6jYjMA0kt97zMAKurithVM9W7gvwqLdNe42Z5Csdc9TbjaARAlBnduvUEkA/XjPlEre1PIVIZCtyLSxcGJgcC6pyGmzuHbjgiP3wbVWkccMN+9a/wKPoLB6RFAyrQNyw+QwB+VTeClp8KZDkyzumel7ncFbHrrLzkKUeklDDjsMhCAbbEontdhU9bV2z9jYF8CoSqjFMwLZqNNIuaJ89H2r0JBUWaPxqVXZlaELaeyfjy1TCZ7h12CVZFN6+irREOQj+BnOc7WW7GPZcilVho4/bWRMiAjoayKtzJai9AyA5eFTXFzOPpFuL76nce69pqcfN3QigTZ0rKW/8YJzuAUJpKiin+hbeWCe3NhIbmbcqsIJTAGSeS4xXnbqEK+fQvKatNuaKGKaF0JctKSBFQSfFp3rWFJmmJ9TT8zt2zEj9VGjyTyFwSZWHbpb5/+oyF6vQNsYgOGbwcJWFNtz6yMgeb0HbDFClN51udDDmE6+mwMrh3Zx5a14+b/e45zIaTc5Ju1UPVVVv7FDCNeluF0CGGg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f3c5257-7ce8-4398-12c8-08d85688d8e9 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:28:22.8978 (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: ZxvxJYxIig4UmT8fxKWOj1a+OWl4xcYQ2Hv0yf13jR87n4KVCjz1N+bb0sb2rASh X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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..c161bd38f401 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] & BIT(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 Fri Sep 11 19:28:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771403 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 A20F5618 for ; Fri, 11 Sep 2020 19:30:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 745042220E for ; Fri, 11 Sep 2020 19:30:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="lPsJufYl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725959AbgIKTaD (ORCPT ); Fri, 11 Sep 2020 15:30:03 -0400 Received: from mail-dm6nam12on2052.outbound.protection.outlook.com ([40.107.243.52]:48352 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725802AbgIKT30 (ORCPT ); Fri, 11 Sep 2020 15:29:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UdWDR9gbdqYptLcsazVKiI51Zsz9D+n1exLjwTwYIVjL0xcH9Tfk3beuJeMDHhvLOpH3sh7PSpc/vjnQJKVbCpjTB1GvzcD6rx9LquhaxmPEZZBpvKymEuxFUa2filD4njqA7pohRjXcC0yYJEqOAdHwLf+m68SOoiQNgJ08GBBdzN45xCrNqn7bC4Ge50ckVdnPEzXzFFqrJmpgvPX+QIHkY5KuNtX1ZLc7UjhvikVpff/Bz0sF5ZfN7ncJi2VHzS9iIYS79vB5qvoCuWAK1vkpKyH0SF1wAnMBKmsOgWeLvkbvYAu5fP9z+glPlsY2rBp2fEn2He6CTXpOm9Oovw== 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=WHU2Xn9kiLh7WV7gEewUQFD8r994ls4feZ7pKTUJhMM=; b=TPaTe4xjXv2T8qwQqiuUnZlWHnwzlpvaoRh/Ppyj2nfeVWBJ3/YiZ6xz7HyQCPKY5NBv+jEw5k9JY77sIMpO1vYzfgKKgusPx+O7MoKZkZGXFToslchJPKD/VnDaro8Q60RVcqjvUGCb9QFv1Awt689Np1a4dkjNpSgBQxDzht4/Cu+LCIQldjZD61nsuwvZ9bfUQ1jTWZduZ8d+lF4W4KPBowahGH+RevXIZPSNnqSOpVUdPDyr624Adx4hOjsHnzYZZQ1RVoFb2PE+nZy87W+SUnVJbE5T9CBc6rJF9LkTMb0Wi4RZkIHaMWnJTzVgvEfrkpkEcRAZOhThL9JceA== 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=WHU2Xn9kiLh7WV7gEewUQFD8r994ls4feZ7pKTUJhMM=; b=lPsJufYlMJbmGg25TcNWvDUS9rzB1M+cuN2fFFcwSp3BAv9x/jH0UPm/FB9O5AHXFQzmdzm4YS4bwnFLnML/YZPmHqk6/Zjdfajg9fONX7s7Zm9sSPIfEmGiZOcKLS+HzioFUkO6VaRjPk97v8B+RGPZpddfz/uTHTqrYXRKDEY= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:28:30 +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.3370.017; Fri, 11 Sep 2020 19:28:30 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:28:28 -0500 Message-ID: <159985250813.11252.5736581193881040525.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM6PR21CA0001.namprd21.prod.outlook.com (2603:10b6:5:174::11) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM6PR21CA0001.namprd21.prod.outlook.com (2603:10b6:5:174::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.3 via Frontend Transport; Fri, 11 Sep 2020 19:28:29 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4763efc2-9803-4457-143c-08d85688dd4c X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: Y1uRsmfS5aNeAKhIabt8/tfZ8hVZWmVN7TFzQjXofZ5/iJLWnrTlIMODWOMdZJ6O9W5UCowMROtA78ZejPl/SfC6y+Cw1MTQnnY15rgp7J6kVRrBdXbY+44M3xPz0OV0DfzDve2iv3t/Bw4DsYdElIeV0XAqHTDaPF6jekyfCn+oUdv1sf/pXzBMEA8i/7UdsqJHouwlmmO1mDaANE2MBqpROsRZ2Y3h/79FlSGOBxQhFs4uH6UryMDuxc/mWZqc646CQvoZ8I9fsOAsAtHS/pdx7es4CtUWnIOIfRuXrter8UsueyY+jaZ0F1pVG1rl/QSmHiVrECTJ/UCRvdK5+A== 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(30864003)(6486002)(316002)(478600001)(26005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ackTLmmsH3eQpgUNpVfme4fQhQqHsxF5+6cOU0ioSDs8+MCEz7RUhkNDW7gEfS+WjLF3uSmKdEID6r42t8Dnun4a4NSHfTs0k3Z9oJilm4YYaPXyb0immaY9pSDMiwrxUBaqIeNfcCqiJOddFY7A+rwr2m7u9CIwlr+nHMftmni9+WHVZhdPz58sE3ALtKwRhd/johmRd29bJPqpgSz7VbRs7thJPQofVZJSAG+NUTvEK8Ap9MEWwGiQm74HfZZKtRghTe29MAygMyytvwfqkpjzvac+euWzyuTv8+fl6K4PnNQc1wMOTMTb9GXhCDFCHm3PyUHdYLmWrS++ccrjWRfmFca9sJE5Aykxly9oxqM4GSnpgcCS4aRaxfbVWzz2L1lpUGXZrMzJ66Dw1aE+IHiiKqkogs6SJZmJH1tQxa4wIn484wPW/HBL6v8ZT4oJ7z76n4YzqLP6pE+fJWwGuBWVXMPwr0R1thuO0GUZN/hROlS3hLhozLMGP02LPfw+otebR90x2T/nl9GN7BAOWxtZg08XLdjXj7pGMh63/zKSjkWmbGqEQihbxLI56JmRgx32oQ062PR7WeXVufYBf8j/w0mFjqdr3FfrZJUd6LsX3m4X1qU7ZWJ7oQTcKBxt4Mz3CWF7iMV4MeDWtkWfcw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4763efc2-9803-4457-143c-08d85688dd4c X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:28:30.2586 (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: YTlNTU7PsBDGu/g6kwPotJeEfIQrk/RZbETJZtVj4RZV4ZX/FLECV8zuaC2m2oxx X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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 c161bd38f401..353d550a5bb7 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 Fri Sep 11 19:28:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771411 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 F38A41709 for ; Fri, 11 Sep 2020 19:31:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6D7F22224 for ; Fri, 11 Sep 2020 19:31:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="uyvpP9ME" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725915AbgIKTbv (ORCPT ); Fri, 11 Sep 2020 15:31:51 -0400 Received: from mail-dm6nam12on2052.outbound.protection.outlook.com ([40.107.243.52]:48352 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725811AbgIKTbK (ORCPT ); Fri, 11 Sep 2020 15:31:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MW+riekq5FNZ7JmejLmWD9dW/NA8w8u7YTWZ79RNNaIZu0FjF3QSr7YrD46dIi4/fKes0Ni1600QIcM/1jTkUy9iYLNrTpkQcUr9FgUsUU+eIDKHkO5v+8dIvSouyLmjJekepxKHHjr1fGl73e9zgk1FLw2FOd/ht23lu70Hx5D7gVoEk8l7HSN8ztggXHTkoRKG0xGX2m4C0GfXFnk9VYOiPcCCU7rrwLbQcIVuj/q4sJhgj3qW7xpl/FoIi8DHB4Hu9Rfglxocc05JSpFibdzmqACfKoEWGlg6UPbnqaLC4V2kTBEHPUvKcHnRXxZmoKrG3vI8reYYhg8OFRsx3A== 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=Ji8bao6PEXOBRnbVSa/HgJpXSzz+KaVMysJDSmCCHPo=; b=BdyhAfTfqWfR0KKg94Hwm2X8qKKzEcvHF/kB7sxqcKSkRBn81I3dg5l8ppBR3xHBPRETY9h8coTDyz2xgiNBHKv7vBtVUXL46CgKS2Mt0+aLsUDC1bMCCSc8I/+8wgys9/VI1EZ1mPuAq6pPIuhC5VCzEJBOy2+aadFnJwMhljqigyx2ugN9s3FiZFknV2Q2tblJ266gHoe9b1XTEtux48oZXBP5vDA37UMxmGnxODe7zdlYbPt0nQLOQMjFtTXaeQwDzCT3NBKPQB3BxbNwseQeOKe2XFWABDs1sQH01s6j8W8Dv6aVpJWOuX8aiNcUkFtS7264yhs7tMhDYYUrzA== 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=Ji8bao6PEXOBRnbVSa/HgJpXSzz+KaVMysJDSmCCHPo=; b=uyvpP9MEiev6FWXKZD+QEVNoGE/uniF2ZVZkvLiS0pj/a3mIMZL+su16DUfSnAm0TBZF1A0D8CnwkmKuyknxySAVBH0Z9GfVHogEM9kGSow+Sbr8koaoaKVkFAawW55mm5KlqO2HEn3v2N0U9E+sSDKBpgFMp3mtVl0qlVtWjwY= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:28:37 +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.3370.017; Fri, 11 Sep 2020 19:28:37 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:28:35 -0500 Message-ID: <159985251547.11252.16994139329949066945.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM6PR21CA0019.namprd21.prod.outlook.com (2603:10b6:5:174::29) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM6PR21CA0019.namprd21.prod.outlook.com (2603:10b6:5:174::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.0 via Frontend Transport; Fri, 11 Sep 2020 19:28:36 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 72ddbb70-a117-42e9-532b-08d85688e1a5 X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: B96j0Lr7tzGEcgdRfy2bB9dt2wZgIsq72OwJtTrSvNkPTFWijrjyNl1MUvovicwcCNX4QJJ0Nc/whVBZJ5oYpBqpbVUs4ACG6jA6FidVTE21OaG3WmBcIte3uvAV+1D7usivUopKQ4fuZ/OqlNzE5dl2xtegNk7sNht7uahKOjFBa+FtNmgkb9npgYmSSPjK/Nk7soeSz6eCytAk9zOT/fW0EPyHRemGAYl4D9NhhVPp/ISPXEkwcrwiihU7YK5htLd+SPLhTMhjZNfl7TCEGbbOR15G5WpGp81OiPYwzTeA1LHzdHixpPDBBpAd3/KZ3dA2SibP569m1GBu44gw8Rw174XK6p7GM38BBza2PjHrmZDWdl4jYzOBG+x2bt0+KaDbbpRBS7n4QJpM616KqA== 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(966005)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 9+7BLEuD9nIzGIuF1xB6E92TnjPINbJfnSsIkH3jSOjtWUDmj8H4vUtz/Sx2eCUsof0chS/JeRm/mftoxf+JZ7hI1lIpEMdHLeY8uXAFf23gIFOi43+d/vYDEcYKj4gM4UNV87zth0EpiliuB8tycRKCA9rcR8Lwe4K8WaAD7Jsj3VlU66eBSmjg+VwN6iFDWl5RYQUJkGDvqYQzUzWwV2hgYUSotUUmyNuZYfJpwKkkEDBotevau3PQgv9UoNEj9+8qY8MjKjbdDSuntCqtvt/jixvnAPFSI9Yj7O1LbcHf7wfZjpPhXSTd6V9bZxfQxokFCg05KLZIemFVwajpIZIZvc7Vl5x8G14oXrpFyZ4QiATMtzaWlmjP1m+VyGb/iu5r69WvfQDOBvL/SkoMCUg/5Oib0h99Pm6IrI6ngG/V9wySX/5OnArakZcNBMeaPpRcrPokp6ubZIUlx7DlqH6S+RYYfoMWS6iWqcgh9Bfy4YCXntUh6JwQnNy5VmNyxuCkeq0KXppImOjjMhqrgXRizbxHg2kMB4fKtf1rfzDy+xVxEUiDaeurSkP6Gy+y9qaxnzvBzpstw1E81/fnu47cdOmXTlQkZWFKVxPenINoKgqs9Q/+W/W7o/pXJFyL/XNVODlC+QQxLmcxjeVGgg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72ddbb70-a117-42e9-532b-08d85688e1a5 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:28:37.5473 (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: /M9hQPVT97YjCiKV89ODUT7mQ6hBbsyLePb4sNSe/N1uSwGhPZDe8r1uqxaTGXhc X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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 353d550a5bb7..c833f6265b59 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 Fri Sep 11 19:28:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771413 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 1776E618 for ; Fri, 11 Sep 2020 19:32:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8D2E2220E for ; Fri, 11 Sep 2020 19:32:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="XBUrx+aJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726003AbgIKTbK (ORCPT ); Fri, 11 Sep 2020 15:31:10 -0400 Received: from mail-dm6nam12on2080.outbound.protection.outlook.com ([40.107.243.80]:23168 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725994AbgIKTaq (ORCPT ); Fri, 11 Sep 2020 15:30:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hS//sYbddjXmPodD+HFUUVL9sILWva5IjllvHVQlmJBwswMQHbOz4dWPppTOgsi5O9YZ3agNT7UxdJGs/ISPSDCFRNd/oFxXe3ed4yDuHtdrdlIz0aU/dbIbLh2WwTUttNax5JTfuDsSnnuXlFWzjF32DrYRzOCToi0GfbaMcYlVcTiLpNidgBhqYGWeSW39lBOkjefyEY1VScJxTRf/6xO9OTFyNgZWFw0J/ojXcPEIXwR/wX63g6UyA5UPyY0GuFi+2dRPWXo44K/2e5tyS4HJWYegkuMKXAaSioWm59OF91CV3EU1i7q+0iUgKUtR7Ps7PoLufR5fW+0uxAwSDw== 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=2JU1ERznecWKXTmr3oMM4GGrl46agKbxbrbch5Bn4/M=; b=j8S5GLk+9w5IcToLeyTQMEP+avWfvcM9liLf4N3yq//BqMGk9N11kMdy9LJbDfUSqN16sh6GgwufB5Ps0jDNuGJy426jvfq0AwSMiVZi0fDV+CfIrQrXPxgyBTAhaZGQwsgx6FiSLd3y1aXRLBOMZXjGZI+NLdER+6UN7kKqq/zDY7kO96gWArNAGGUvcBqffuEKYad/KOHl2B5qFbjqc6v0AAOtfTuIqj35jBUs2hEYv+BfJYVu1Uqx6Ri2l7TOnCrh7Au2uZHHWun4c7reNM8f9O7KHcWngwJ67c/HWL8i4leNZh6RsSfGAfbiozQE+fw/TYvT03CKn75EbiDZeA== 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=2JU1ERznecWKXTmr3oMM4GGrl46agKbxbrbch5Bn4/M=; b=XBUrx+aJzHI6O4F2pLAxkJlccwkuSPaiD34HXghoK89C2stuKKg9b8YBnSqy+TsZ1+XxkXfJkHE1hsU3cWoFfuduoyGboDnhsZ7egFAMDeluntd78HroCINDb+MR+X7T1gLpSVx4wbIxMy+DmD0AQSPGlGSQppBBVjPcw03fJWs= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:28:45 +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.3370.017; Fri, 11 Sep 2020 19:28:44 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:28:42 -0500 Message-ID: <159985252277.11252.8819848322175521354.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM6PR03CA0022.namprd03.prod.outlook.com (2603:10b6:5:40::35) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM6PR03CA0022.namprd03.prod.outlook.com (2603:10b6:5:40::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Fri, 11 Sep 2020 19:28:43 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a53d6f11-9b6e-4218-7bbd-08d85688e608 X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: Koe9NhzthnI2Ljzd4u0CWzU9N0ne2OSAsaXg6BcpqQ95K6qGIGZCguO77/IAWU+KYQpN52eOESnfRjIjmf+f+46xYT5E1nCEMf8fDqVkoTaK/iFesSSTC/THVwvqil2uzHyDlBbYR2pCb0bz/8AdavMb0xhZGPDhySxfISfAn/BAZ6QY6Dpys2dXcdl8bDZk9KSOA0+nyO1PofvheQGZ4e8zCbUMYyDZYCt8NHHqbEj2R3SI4YZDcM15NuoFlirUnIapBg9bI5aQfZc5t7G0Qs3fTqbW2gW9SndKSr6AMkF4M1cQebQj2LRlvxni92d0+NikJZMthIkP3FPjKDWh3A== 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: tOvaZsLacTieHmxBfRd7ASDNGBxn7dVkNa/F8ATajLmVO/UiE6EhRvOA2J/ib8MidlSmKb5P/XBSvvhPWuwFoXV58M3EgTkILYERJEgHDrgXybxrOlGYGXokjpEv3TiWP08fzGa4hYoxVuOngeCIWAN0GiJiP1x5jurkq/25VBoROwAO2WqIL0eyWCQlEKVrYKM5HdkLyOEbgsMsJl0iSo7Fm0+M83ZHM1fwee4UEKJ0YGBgIFwp0jHc0G6Tj17gAStkpuiOimX3pSIeSfc64ojsvzzAWU5+B2aMZSfh4VBaxFaCtxbTLHvI04Ej17ST7vMwELSCNoO6s+cwvLDmi2N+NXPjfKWN7TlIlRr1oPCXAQ3xpuXS2RlRUKPzhCm5TiYcssc3lYCfJi/n8CTWT16ANWqvsU+MxS3bvH0CxO5zmFWdiNBZXRpRBRRTtL/bIE6eocGn03vifHysojHeHQSJr3j80t3sQGkTsAVFqglUtq0QBl237tb3ma3IgoNTVfC71HqIUhfGq9+BVlZ//H17Z8TXt1AVHJNIftm8TT8zwivpfi2pRPOyjDWjBViZpgJfk02hM6Mug/avMJLdS1QvPMS3ecTFJFfedkPVlnMLGKUzo5/2552523oeVfNS5HKnkgpfWM9ictSAjOeekw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a53d6f11-9b6e-4218-7bbd-08d85688e608 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:28:44.9440 (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: JJ9cmmFitBaqp7LC7juO6cAGC8R9HMyCHJYL50ICA5419QEQJyaKlYtwmv8VVTVx X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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 c833f6265b59..7121756685ee 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 Fri Sep 11 19:28:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771409 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 D2BD3139F for ; Fri, 11 Sep 2020 19:31:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4F502220D for ; Fri, 11 Sep 2020 19:31: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="JTwvGTIU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726020AbgIKTbW (ORCPT ); Fri, 11 Sep 2020 15:31:22 -0400 Received: from mail-dm6nam12on2080.outbound.protection.outlook.com ([40.107.243.80]:23168 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725967AbgIKTbB (ORCPT ); Fri, 11 Sep 2020 15:31:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UUwivRyycJCJbXqdMI52jDXZ4OK+Yx9dLPhUS95l5sNtY3TSh+EFtj+KtUUnPy8/xKedz+Nxi7dO6ezNA1mJPetkPmLeVB2Q/c/PtOr0VWBxJg/Uaj/ArTAJaKNLbV2OYRhT/BbTl1+gK7L6W1+zCZ7lNuOls6i+EMUHH6GAn12HRjIrnVQtZ+02rgeN2CFrL2lddxJ5y5L7F8hecJ77xviajVzEdXL05G5kAmx++/E5Wkrvwwql+30JlS53GHlPFItL42DLFwbKl+QaHd5jyFNE0IJneEJYU0vLY+fAXQf/v+3uTsNqmaRyaIp/phWYsgB7QGF3WyfYwWFZKLQAbw== 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=VZ1YYlirYwtrX93IahhNr7QfkU8yvVzC4cs5fkEBR7k1eDuLL5CqVYLKx5iJMUesbZHM7h+yUW3n45qnte8hqgpNu05VxzX72haZ3EWHp2uvn0XJulp+es/75cvEPGrE+JVpU/egWXTCmhOj3wE9HwBHh7NtQxFO7tQZ8um0WyzBjCHeCdQbLz1mtMebCeGE3cBJKpxAApeG11AVZKAbNXKUCwOAfbgbBKHHqpRctqEkFUzyS5qOup5ICJAwwxlBO7aZPS62oYTUHYxPoV4EwAo3T+7BWNjvCtb5/uWYJy2jkKh0V43Eo0A0/4UbCuvCIztToynwlwuGtZwObVfj/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=ig/6wsw048VE9ZPJm9cY0oj5dbpCDYIjCRHQNAwOgaY=; b=JTwvGTIURYwNLkQ7DHTOILKeHu8k5IH+EP0qkDO95C+Korr5ONqvHpbTqAKy1QFWiHcB+WBvbjZSGfKgAGmfia5lRRQU4dtZGV2KTrKszdFqHlWOODH635l7K1FaMtZ7D7MNKbk5goLeKCaoUg41W7Bwa2+yLWlPldrWM+3GxGA= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:28:52 +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.3370.017; Fri, 11 Sep 2020 19:28:52 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:28:50 -0500 Message-ID: <159985253016.11252.16945893859439811480.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR1101CA0001.namprd11.prod.outlook.com (2603:10b6:4:4c::11) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM5PR1101CA0001.namprd11.prod.outlook.com (2603:10b6:4:4c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Fri, 11 Sep 2020 19:28:51 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b4da534b-f813-4756-696d-08d85688ea8e X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: kvcRhVk8lqEvjQ8Gj0JCSqZYkYnYilwI8xDdt/B0tqSNHZXTkuxavTUckDEhIsroaar0RavwuH1wl7u/hiZyF/gB53IH0RjarSGdnhZNXA37tYzbI1dXEJo9dCfwVuSB04HthWMFgSBrMdi5nvGRN9bxDbbH5QDmtm7Ze1q0UQZ/lMJIFq4oCRM/nV7uy3xYZDf0a4b9xoGPUgkCf4z++7JnOIL+quxTtVMqb79Qhz58m9ZmLtnlErCShr3lSjBysktA2xYRMkaYQuqwxcHw7maeWDfgjBNFPgioNLy+QyoSJ1xRL/EJ2G7vh9jd0TAk4VwXJ+gsYFsb6Z0XCkDo4A== 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: FqY7eG3Wg+AKBgqaE17meuXzZU7dT7AnhINp2Ot+Ry0PDezdEYydpXLLRqwXt3AxicsuNc7wt+xvXDzKNHmLr+31hEqUjEpiNijH9urFzVWvi+mIIq/NrbEdJpsxnfDmMYgmSJDK7gQMDMLpjIiRIeSJr2N6WSJhR26u1pSH7tloG00hML1IOJhzbXeSTEaGf64q67EvMXmpDuHnMgFTvNgZHY779GgANFRtNVi6zmGPA/+n5uipELRBWnyCHz4GTZFfB2FAdnLqAwYneGrm6YCAfzBdiN5L0TwdcddOfoz64IXO+Rh7tZK2EQydfvcPt0jPf0RFYkD93hFDumM1ZBCH9Q5nIZeMARBEaWBa/VG8yPVA3ND9XYJIwN3/f/rZlXJuupmCzESIRzidCi135aHwFxjN8Zl/TcGQrAXN2flS6vqWWg4fTs4FAKCna7flWYjtCIIdglMD466roiMj2sRS+m9AeNShc+rgrvGNpLyDaIaVHWHZkxULD6WrWOmTiZ/UNow6A+BIiMoqbNvpv2kc5uZ9Pvcul5IgtJnjJa5KUKYNNtWwvvD1IA2kFzOS9aDvMXiI4kkZs7T9706LUmffaUNyxhFwHB6agg8mGSct3NgP22tlbbWokhzco40obmg6CTVdO9uwY0vKIJZ1RQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4da534b-f813-4756-696d-08d85688ea8e X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:28:52.5037 (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: w38KTf8h0bEE6I8qbx/Ac/AOTiJbEZIpUqWRHFMDHHVzYkOpdtutLMgzx7PkHJTT X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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 Fri Sep 11 19:28:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771405 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 F41A2618 for ; Fri, 11 Sep 2020 19:30:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C010E22209 for ; Fri, 11 Sep 2020 19:30: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="MiSJ5VfI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725973AbgIKTaZ (ORCPT ); Fri, 11 Sep 2020 15:30:25 -0400 Received: from mail-dm6nam12on2080.outbound.protection.outlook.com ([40.107.243.80]:23168 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725961AbgIKTaG (ORCPT ); Fri, 11 Sep 2020 15:30:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lksgQaWKrRyadFYuftU7boTx594WFSkLkQNodurwtRdBfPO2QWHtDHUnVcX9RMmFIO27QB5BApMobM0D4lZ9jVtnghSJmtTyRjzDqVKAIzx2FnUe651dWPFievOyUWcFmb86ZFF0hdpg8yFSqrbdzc9y/IbmWPW6EZes+r0eQqqTeJe0ERx8wGLmygXoIqTo2LJjyZiMcI7WyPhjMpwQMommHPStDPBBG94taz/SJ4v8duAolxyU88Syn+5msJi5jWoR5mPij7LiIwCYdxa2qXENi+fsYBuqyhHjvAc3NrSWbmA+fXJYF+LJTlUNhWP6HRT8Kbwyk+fJE2U/tOeGFg== 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=HH52FEfV8pFrfnRlFxGswbtf98yf5djSbqqeYqVAZ6Yi+PTIx9UnGtrpg8f1gmySSmusyNkplPxMY8audjcltlWQvyvqsRO88BMEP0nsKf3p4fIWq1D50FsZjpRgj8MeOnO6A7FiwiXFHOURb+lpMRgmhnr/dycA2NB72LKgP/9L6mY5EV/NNIyLRclr+/gAT4etCQuZpk8wrV2pGO6qQBAlPkprbRg/sMSqRO3vIBszbl7ysFuWlbBqg94XIypcfyO3ixir6IpdDXnSfo80OiJ4DBUKHei6VGfuVkwtNV+kyQ3Xu3Iupd22i8c89p8UbcG0PDccJCHo0VzxUY/Wrw== 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=MiSJ5VfI9hqcFjMsHoJxN/FyiyWAXcBC93XQPL+EBdNIXGU0nbSk298oNQ/HfOIBKdmoRAjrwmqsga9jRHb7nSV03mHcYRvePXibKyV/B8QZSLaO9N5BHkZ0gyk7n2ZyT7KxTi8MiFDh9gBVSSZwFbLMvGQsjrVzjw2V4HM+VWg= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:28:59 +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.3370.017; Fri, 11 Sep 2020 19:28:59 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:28:57 -0500 Message-ID: <159985253773.11252.10287556137071236912.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM3PR12CA0078.namprd12.prod.outlook.com (2603:10b6:0:57::22) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM3PR12CA0078.namprd12.prod.outlook.com (2603:10b6:0:57::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Fri, 11 Sep 2020 19:28:58 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ee797f34-03fc-44ed-2ba5-08d85688eed9 X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: IO9efR1mWtEGp8WtjW5PRb2MpwUdv/FjVmdwf6YhLUq6M3+Lao+yfPZkL3O3Z4p7pdLb7U9jWoMYKIbAWvZX4XdGBRN5RKW2kL0z7fya9VTxqUA+WtkX5pgQTdXciO6y7QAzJor5JbI4nHQg5qmX08zXT09FtMeiQINguRayEtyH+eoO4HGQM5fM8t/C7duPkYCfjeA4DNeEC4W2EBIswkl4A5z3W+4nAnmtqpxXNRG8MnHv2L0KFWH+U8RN29xPkNYAvepPhrV0P7xOOry18HL+8WrAWbfoCFezKo0XHFhYu2EV8Pmx07MPcNBS3drj 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: AUhA1tZZp9ITDeYm1WL4m1XpL9sxVGnXXBF55V70W9fHqegvm981Fkc/ajlLWSM0GNlVQL0iuorAxKmSuSUU8oeAqLwJge/hmZNo1KQ+rw00oCJSMfr+GVdrJCd5aclzfgFxkGZtDLHbpzDpEy/rR3sBZcZdCDXVCiWCu1ycXla3xZJmzQLRU/H8kPa3auPA5x5rivu56Ar5/vWrWTsdxmyV9VwJr3kyhsXaQFIQ3PSu72wMoYnnR5+WANyP4HGLfFfDTSzhe6FRdnNt25WnQ9CNbdcfss3nb9Jg1meOa+hzlhxI1P8K9xaRzlnNOvEoqCuUZvE8x+KnT8VU3b8nd/jBChap4Hg+ndSeoDNSBbdr/YLVz9xzGU9C4eEbtIN5+30c/l2xWgPfAs5Af8w0GcjZOPbLfR90GLbM9vXPNcowmJO4Ztm2tTUsU6mh6yy7SShAMnkYl9NNkdbw9TlBmburhNWCIvkInjeUUi66Vyt7c9gGHF1p+XhQmTceuwBrPG9xKi2BQk7YAFnHf/in1GuxTREjnuFhxj5whfCXc2Ox61w1psQiFjG/YMa2w1OGb+BtpyPTQvoHBwRIdJYOZaCF5useQuRuG7FlV0R71yaXbHJ9pipuiZfW0Nt0thDTpZkhClG2VMFY16ERxE3WnQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee797f34-03fc-44ed-2ba5-08d85688eed9 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:28:59.7155 (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: 4Jr6GRER4y7BsWOISla2FQM+uVxJI6Ec9M20mrxoLGXGIdGwu909CueuRaD+P251 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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 Fri Sep 11 19:29:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771401 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 D7BDB6CA for ; Fri, 11 Sep 2020 19:29:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B032922209 for ; Fri, 11 Sep 2020 19:29: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="bkDeC0zt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725933AbgIKT33 (ORCPT ); Fri, 11 Sep 2020 15:29:29 -0400 Received: from mail-dm6nam12on2048.outbound.protection.outlook.com ([40.107.243.48]:28736 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725940AbgIKT3Y (ORCPT ); Fri, 11 Sep 2020 15:29:24 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kp/xIAtsvxuyHaW3Y3Rw8bTIVED3ITOiN3CwPoki4hhHA5nLLD+O4oYh3itSnbY3SA8qKEvsOsm3cVTIVS/YGSZHCmMTq6yiSYTTdAOlu2GJEIrp6hE3iJ2IHQMOiuXMCnfwzE9hKLhcV/qWVwTNNnBItIkNsu2LWykZP8Lx4PFCdR75mOrAItrCbX2i8RRnzG8aVqGkjfFe8AyGEr0Mu7zLk/7RTjCNHLzEHxRsOyQI8g/P+FxyDuqnSdI6ZjOCTNQKhpOmEDJFHyiRhA0LK3UuuHA8XrjHpYWmj3IDMYp1g5+P1X/JqkJs0JvP4h/ndc9RR9vn0FXRO3hbXZUIWQ== 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=tAalj1SfgdRviESXHxYFGTZ2fKZ5+vPge7wml6icgJE=; b=l9Wfr2hEPKNFaoRpV6l5GSnrUDMhueUq+yZd15+rGXMRIZq5LrQWDLHp9Xo+kt2Cq9NoydMJWrz2jyOajFhhSuf+3U+yXiGYdqOjCHIjQxrWCV13bPBdIWD2ZAr4XRyYE+ahxfEnkxjRSJI9PhVK63BKmXdT47T4ijwAYFE03nXZRmaTWZQAiTBWX8fWwTceIShsVpWtBVrLi/p06+HGX+5Tr+/lPKnJuaBGfzjrR04GVgXfdxJC8SrcgBM9bgo/xgC88GBkvTN5OLl7owOYZrWGeIKDZTDVQgDGDJ3QJ41xsOjdEM/cvpStoqRUvCvXSsCH7Yh0/qNu/NpVD+f/JQ== 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=tAalj1SfgdRviESXHxYFGTZ2fKZ5+vPge7wml6icgJE=; b=bkDeC0zt6Q5ilVOFrJb7VsS7fzUkX/SAx9f6yuoyd19E5ZSV4HVIV6ufv8eS4hwC/Hqzet2BbrlSvridqA0Y/nTpsX2dgmNsOdHKuEwP+MIOhrcBPdcC8fbuHxWIqlG1ZiSbRaOhIrlkeqAAC7A/EjKCUoR51gUH3q1QLsYab/4= 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 SN1PR12MB2429.namprd12.prod.outlook.com (2603:10b6:802:26::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Fri, 11 Sep 2020 19:29:07 +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.3370.017; Fri, 11 Sep 2020 19:29:07 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:29:05 -0500 Message-ID: <159985254493.11252.6603092560732507607.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR12CA0055.namprd12.prod.outlook.com (2603:10b6:3:103::17) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM5PR12CA0055.namprd12.prod.outlook.com (2603:10b6:3:103::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Fri, 11 Sep 2020 19:29:05 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d2075ebc-91d9-4778-e970-08d85688f325 X-MS-TrafficTypeDiagnostic: SN1PR12MB2429: 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: hgCh3QgvYbJULpbrjGe9ycWFu8JT/Sj2AWPAKQQCZ2AZBkkTiPPR5EpGXxnTAEF+L5FGCcvet5xtT0IUx7HbUaDdFWFjZ7v9dOnQaZELhwGancFUje+/M3dGwalehyL+XmqliAKrWm0QGVm3FIN6N/pYnxkWdxSX/C/9Ihe/dVgQ8dopNukGGETksMJgLrbpvwCMNpiuNn4hgkesOxL0LeumohuAvOPczFRGlfJKfFvCQEHsDX+U/PpC6/j1jdAU40tYg/PyJUhWtf/n1VycpglujiD1KMPhRe4IxGS8eblStQs2AwZZSMUSdeDWWHgZ 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)(396003)(39860400002)(346002)(366004)(376002)(136003)(8676002)(8936002)(4326008)(478600001)(316002)(7416002)(16576012)(2906002)(6486002)(44832011)(956004)(9686003)(5660300002)(66556008)(66476007)(66946007)(33716001)(83380400001)(26005)(16526019)(103116003)(52116002)(86362001)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: wi151IewAyqDVg949CO6MK2GhRnhoMKz49qxnL9KWEwjfjL2rn2AslcHNsjlI8MKE9UqKoK0RLY/04PHNg7QIW0jszNHtiLCN4tIcIdB/q1d4972X9q98TglieVA4lMN202DblPD6SstXozh4qiVO9qHTV2ORg/NT1RLhMJLolQIO4k+mR57buRtXRbBtuj06vFsFYt6ZeVBP3/jzIIYZfsDWuapGv0CgtU6Mx86Vl7vvMxIieVyUu984/Yn1BJ+P+W/po2QmetGWQmgyjQrMwFnQeH/gBFNAJWU3B3zalZefKxvPnjQ0aH7JvM9XHlSCJbaYbc8UEOCacm/IvXsJ50Ax41KtV3yqG/vpckNBevJdihs8tBafH6qL6ge3ZMrbQEeHsnF9xKxvmLdxcRYCgZVXx7TdftDmDns5bQJQE66NjROCpBTy9HRAS85pPeSVDyUpdCBpZ2BORQ3S3yMwmLkicGn2qha8UcXI7FkXFk9Gb5ioKQfBSvczj81HPocVO3itAl7qqh0SypfGSH3tYy+vyIMzyCECeHjmE6Wt+TEundHAQxLMCw15ZWFAooA08MXP+v3aVpSZryRiGmx3sgOdaQxIEH99u0WEiPzwMDmKM2wmH41UE8UTiS16wi79pJp98nHkSBa4cwc1U4+CA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2075ebc-91d9-4778-e970-08d85688f325 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:29:06.9093 (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: Y1NZizZlRuR1QAhRinC76ybTSeeovlm9YeO6KpOStoAXe8vuy0SIoQGA0MiwPEH9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2429 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 Fri Sep 11 19:29:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771407 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 32591618 for ; Fri, 11 Sep 2020 19:30:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0777D22209 for ; Fri, 11 Sep 2020 19:30: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="LZh2NYB3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725985AbgIKTaf (ORCPT ); Fri, 11 Sep 2020 15:30:35 -0400 Received: from mail-dm6nam12on2080.outbound.protection.outlook.com ([40.107.243.80]:23168 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725967AbgIKTaM (ORCPT ); Fri, 11 Sep 2020 15:30:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PVp8/D6dg7UYl5jOYP4Rz8N7s3wYsQ8nZH0ipNvK8yr+8+WbypNFixsBkEKi+ltKtgnA32UvICPd6j5c6hZ+t+/1BCcxj4bYAbHRKxXSc+ExMRAiBFHFF9dbotry4vV1SYK7sAMQsIPlx0CGk64T0l3KC7BGDHmeQdo1pvXs0o7kx5XBjq8c9NmU9QJxLDmym8A7Y0pPa931vNOQSxFl7BA7wN3QH0NEoDcWi6dGcPeqxHj9TAyvMOhZChO0QJJNpxy8LFqC3uWJEPTYXv4i2IRhIlTNJK5QWz/fgLPZtCjcFXqgxp55YadRZdb83HWEewgjKaj6X7XBzGNLKVd/Kw== 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=Bo7A55r8LzwTXveT41z6YyaoAL51n5OyErkIMp7EtxPEF/ak+OyVVb76OfFgZZjdvMC18Fiq6ntWUkvRMsLVLTxLRBt6eR5n6k3XhFcpmqumbK1bGcEComfbV0oX4ypfgEEBpWex2fgt/qqHpmFdKyCvwtf0sMgsMI3Oc1PkaY7wkladovrkjVo4CMOv73ZAQiek3lS6+znA9HBaz0iHRDodb/9jxmrm3hi2xDubpLNZqZEbRwrdIlKmflq0Bmm7ealowuVV0KyEPAMB9LYP8X34hLnKsanoY3sADqmQplsCzJnLQlnqmRSt5q03/nQ1Mk0lMQuIJBpr5JHuA6SbPA== 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=LZh2NYB3m1MhkxjkL2Es2d789g7COoydSC/6Td1bOnMFhNBgUZ4mdA1PqkZL5r7ng6TQ4NNbbtj7ORfAdJ70rJOy0pN4B43xggNspOtMfsLQyqFLbKDf4L+qJ7sawmbRX9AmlNtyYCU/pHyTuPaEdk+7gvWVYJIZZtB4L/23pyc= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:29:14 +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.3370.017; Fri, 11 Sep 2020 19:29:14 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:29:12 -0500 Message-ID: <159985255212.11252.10322694343971983487.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM6PR21CA0019.namprd21.prod.outlook.com (2603:10b6:5:174::29) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM6PR21CA0019.namprd21.prod.outlook.com (2603:10b6:5:174::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.0 via Frontend Transport; Fri, 11 Sep 2020 19:29:12 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5dcf06e2-ae72-43ab-e035-08d85688f76a X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: yXXwpYfsCClg0cYf8tqqxRg8TyjBTy8v/3fkiEGtlLrDIF23SVtQsGGgDjt/YkBmx0rIoC6WDHSHcnklp50iWDQf1VCnzzfDVArCgGdwq2T8ut/dsO6cVcdk1FZq3s/9odBER3W+GaM/yKsMoYGHF3MIRq2wYx7GoPHfHd7xY9NyIY9BRhfGGo8I42F6azr/cgqnPz0H2QId80aJoze9pGWutsTW+MPbQm7srz7NrMwLmqwG+1VYkV5H61zOeCSchjWfgVvSgKqux6BsmEhKjyCRkAbvG+S6D6Rx77Ax1wPo0Rmi29sHg7GSJYOUNZ9FaCKn8G+CHbBjkKptBP/kBg== 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: MyzM3+ceSbBN7CxHGqWsyAnq9bo04I8yawN4kmb2bxJ4F2E+S4b39e2iZtl/QAi+Auiabuixxu12npjjbY0koMPy5Wu7W77xmosC+/Jol5unNdjbvFVvhBnK0bLAkMf8AJdmHy9H6ZVmaYE1nD4jEp12J1Cbo0ZiwcODPTQFtNvapUEfLxCIzckqD6BbA7D5j/VBUOgARVlKS51JENGslcY9q1Rw3aGy0eyATbpZ3e1pBmiJcs3ZiwD97udN2i1ypuRGKJpWwF4Bxh5B5Z8q/gENewjUgODqJhfUJEasrQ/+orR4ovJ11NcKHO+qHDvwdo7Q1MtLH/BiLDOoNu7mObPhuFviiq/rEDTfMjOmXWCz6O1Zn7ZEG21FRDeHQXN6E8dgMyT38ArgCiGQPW5PqUpBcKUPsY0lY2htA6HZeFaMJEKVJb6Ayhl4rGaZKC+bJSKzLcMXNKXUYJUpiwnCVnzsTf/xiMWbkvIkiLCF55MUAwjnlnEzGRxJInT3/LcA217tkH0SFQe8GGTtKv8A3eXPFXBQ8pzNKkh5go4+sshCg/lTRGnYAypB0EdS0455CteO931cvB+nolot2CoMBWUzzTs1tiFgw0UXn8kX58/tR73IGN5UcInK6yEqZFUCNeNL1NkKqsoaDweDQgU5kQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5dcf06e2-ae72-43ab-e035-08d85688f76a X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:29:14.0931 (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: fikmjmct7G7ZOj/vluPB0K7FNRhWsCTrAJsFCJd1jZ3s0sh/FiRQ8BjHwRBwFT8R X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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 Fri Sep 11 19:29:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11771417 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 6D7C0618 for ; Fri, 11 Sep 2020 19:32:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D4482220D for ; Fri, 11 Sep 2020 19:32:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="URM/CrWG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725962AbgIKTcy (ORCPT ); Fri, 11 Sep 2020 15:32:54 -0400 Received: from mail-dm6nam12on2080.outbound.protection.outlook.com ([40.107.243.80]:23168 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725946AbgIKTa1 (ORCPT ); Fri, 11 Sep 2020 15:30:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l/ygOT/nfeocDkE7V5nETQ+DE/+DtQgt1BrQNdS5ItsK9Yf3dlveoxhI4KdhUqmHR0239enxe7yVii786325VLgNXnH6zYxyb3dZs6b8e0ETb2ANG3sjNvb2J/lNt5eAtxVb9zaXnu/CgZ49hqUpDzWZjo2/2y5fN38ISyOToVSmeUCjnF8PrFtNHGTo96NQ4XcmTEUb/MJQd31fwjjASXHZfp+rXkHJkxQweRYH4Z0u7kpzxLcbtXtejIuBq+ZJz6dzfb9Un9la67cwfIPvuJjivt/E1XX8w+dazU1uPn7iS9Z039aXu2G9T7ur9Dp3dOQlRZLufCBmYDO+yhO3uQ== 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=FHFxkqscIu6vih5chvqyqM9P/+/DM3lfFhmRILMuLZtGlN34xSlRcxeu8pso5MLmjDw529AEzVEcjK7BIHtcSa3dE0DB/6lu2lpn/BCE8LqFvkI9KSKMxQb6T66NCWzTv716NGlq64R7CpQeK8XV4jAeYDTTUg/6oAP1Xpom2SmB6a+WzCCR/Prh5GXkv71cqlCN5Az9Nv4a9VzxERJgrkfU35WwNAD65wUhsoPZAX8L9j4w9XZLJuKMlRsmd004iHLMxI8weBDptBeBoj79lMSrGnofthQgCmFq0q6k/HbYxw9otR58oHpejH7HiP7idqzJtCyPGPQnDVHmHt/Izg== 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=URM/CrWGegNNWYTOnoTnliBmIQ5/38rt5wy5XZfrMhNql8SH5977xiBn1lPYZhKdyKelAAmsRNndNvWCUTd+7+Qq59K96Upw/MDZnHDifgBovMISzzWypeFrqEVKp70k1IQ1z4o2MPao+I13QqoMsjtIuYmrI+AwjeYWdWI5yeM= 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 SA0PR12MB4543.namprd12.prod.outlook.com (2603:10b6:806:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Fri, 11 Sep 2020 19:29:21 +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.3370.017; Fri, 11 Sep 2020 19:29:21 +0000 Subject: [PATCH v6 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: Fri, 11 Sep 2020 14:29:19 -0500 Message-ID: <159985255929.11252.17346684135277453258.stgit@bmoger-ubuntu> In-Reply-To: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> References: <159985237526.11252.1516487214307300610.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: DM5PR11CA0015.namprd11.prod.outlook.com (2603:10b6:3:115::25) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by DM5PR11CA0015.namprd11.prod.outlook.com (2603:10b6:3:115::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Fri, 11 Sep 2020 19:29:20 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 09d7cd9f-eb82-4c84-a658-08d85688fbbc X-MS-TrafficTypeDiagnostic: SA0PR12MB4543: 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: 3acOUmEatGSTHR51j9KsduzN0bk8ttazp3uk1mlM/xL8ld7Av5FNjaQD5iEu/ipiuZoq7NlxG9VnDwKlssglnOOi3IWJ58rN9lCdHtEKnVDVd83QLb+IIRXQgFACcgW6IiDdIvjEd9gpS34FgvrIgauCjj+37GVAFSVWpx1ZHzhhSBZKV2E6YIjz0+lap9cUNu55oEA89FxX3JQEWXqWQm3/vHUS0ao0zp1mQFAmRl8EXHI6UEIz+CTWFvKu2rLHqUGtc9uzFsVOi30GqEK5Z+R1PuuIYG3iWUFaBs51DiSVbjBRSFxP6Uc2Ax/HKveXbFjv4B2VG0IifPcasQvaWR/rZtLLbBwZu6MSw4+OEAgh6bElmUgNr/YukkJ7CCFqoKPsQXPwiMqOjQF4pxofMQ== 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)(376002)(136003)(346002)(366004)(39860400002)(396003)(2906002)(956004)(66946007)(66476007)(103116003)(8676002)(66556008)(52116002)(5660300002)(7416002)(9686003)(4326008)(966005)(8936002)(44832011)(186003)(16526019)(86362001)(33716001)(16576012)(6486002)(316002)(478600001)(26005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ftcRtVNGPKezWI4cLqPQq3NBB8sj6GkOuuUCVYOxln8baZlHCx02xDNQYgxUtR28pG/G4eLvaxZHJvIlbokY1xXpfjG8x5GXJAbl5wJWv/XowoFZSw+X2QyODMX37QnMKs0MsA/b5QM0kln09I2ew4qbJe5IFZswQrbr28FG8uqGTa8Pa+6KttvFniI+5GpJb5HyGK00f03/6+AxRfJ4uTCe7apSLe8e+NI6Y7o3d8AIIpuMcOPgrzx5Ne7p9rRk50noj3hQ8ePPV6395mnUCoKF6E9L6vRePsiAkTJYUPFAi2It/4n+a2sjEzyW9ta0PmIf+HQhs6BIofYHBwIYuVcbz1sS8AzR6pIhisXefWzUhWpCUGMpEkxLSRmiEpx/vk0IzoSyPEf1RB3+RWchtf10xkkhyz0YTWXH3WkNXNrtgMiKSaLaidQ23WQy4MNvpp+WAknV9gpTeJn3u1iNSAl/RNYH8RgUNUPCJl0xa/jUt1L06hjqfzvWihz9v/j5RO7698VktOs/K1XHr4RF74/l9c+muDqZxgD//JryE0jmuNJMObabQKUr01+cFg5w7OkmzBGbHwLRsyEpKAd6kgHMDMEOPoORHx94wNeE7dbFL4cDFFOetEY1lS4w13X+/WLC3NjvGK/bEIqGuX3xLw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09d7cd9f-eb82-4c84-a658-08d85688fbbc X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2020 19:29:21.7407 (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: KUGa6/K+8lw4oRujfMvwPndjhN6H4foF+C4SnwYCiTXRJRUqZT+vARLIL7BuIgo/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4543 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;