From patchwork Fri Aug 7 00:46: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: 11704577 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 51DFC138C for ; Fri, 7 Aug 2020 00:46:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 522F92075A for ; Fri, 7 Aug 2020 00:46:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="sJa92ZZ/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726490AbgHGAqe (ORCPT ); Thu, 6 Aug 2020 20:46:34 -0400 Received: from mail-dm6nam12on2046.outbound.protection.outlook.com ([40.107.243.46]:19169 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726011AbgHGAqd (ORCPT ); Thu, 6 Aug 2020 20:46:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P8gmW0Eo7GjSnGNbE/i+0usv/YxBzYRsKAbE6mFEmNHDqnlOWIC/HyvgHod7XD3TmQ6wY8lpNmbGyLVsuQCudPBC7zjJ76rVXoTCV+lQ0Lo/+dpXQ+L+oTH54bjPkP6Ciz0b2Xd8FojZwGF/JrCdkeYCiYf1xGQA1NvRQyDzG23BQy1lDXhQIY1Dcoa2Y2ddoWfSZ7vi5+z+MYboGgUbvZ00nio1XpmoQ67A4FCag43zBpCiFoHhQCWNQItw8byJxWcOK/s/Ja+vOiVj+V1ceZgjMez0z6mEGMaMxQsETjL7+8jxycz0ElvqINNL0L8rion30l5L48wK6A61EmJ61g== 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=MLHr1P/78y+aHbvdJT3nm6q4XPc5Zv8AvX3Ih1p4e2s=; b=LBzKGs9CrR6FYBEc3yaBQfh1gEclcvnmSy0uxUgUbtHlFGzxZsQsn8KKA9cQL+1f7Ntr6+DhDR0yNxYUtcDOOGHvKaVhoJl7pVGBF6V0vfwWNWORuyFpXtsyD06TzsV/Jz6nfKJKja+IhR9srBGCas68Be06Gs1pI1sl4vvMI6PtK/hJG/zOK/bQ/OKO7HPD75x2lnsVdcauYA7817tnEFjV9dN+RZoT4GJoBsF4BrDxX0xlwMByx3pC7SQldZ+r/fDqF8G29Lo9VLNbB+4yahbWler4F+RslJjhP25PW419OoUyCzeq4As6yLN9vjyeIy+hCde0+Fo9Ez8g/qFOMw== 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=MLHr1P/78y+aHbvdJT3nm6q4XPc5Zv8AvX3Ih1p4e2s=; b=sJa92ZZ/361HCVcre0vLVHFxixDDxh4Zf7a3L9UZ9Czt4Xc1BqfgeaQmAZSjsCW/Xga4KYJ1PU67LgdnMyUwCjaMoPNuggJ00tjy382J8xjFQ24XSOTEfVvplKaK2DEyyhKR4+UeV64aSzcBZBP/xD2syvr453ZB+2r4yfqNJ9c= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:46:30 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:46:30 +0000 Subject: [PATCH v4 01/12] KVM: SVM: Introduce vmcb_set_intercept, vmcb_clr_intercept and vmcb_is_intercept From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:46:28 -0500 Message-ID: <159676118836.12805.4817403954662511426.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN4PR0501CA0092.namprd05.prod.outlook.com (2603:10b6:803:22::30) 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 SN4PR0501CA0092.namprd05.prod.outlook.com (2603:10b6:803:22::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.7 via Frontend Transport; Fri, 7 Aug 2020 00:46: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: 733b359f-7d37-4ca2-9574-08d83a6b532d X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: tZFlDbDoACf2SfQlE5MGWF8L7EM7CziQPuc/ecXGl7ljr9AtwtPg7xV+wQUEkz1wcFrfaGxGtbSkWPb7wi7NnAN0A4MLFJJj4DZv+cDyimsjY7LGzrFHktJ5UMulkvv3PVss+sSk7WZfgsKhyMzGxhOjM2aPpMBjnjGQ5utN+xVQiBwoFKdjt55DJVD3SDk7eScDf833fddBa2h3lDSReA/tOvGLWTmwiUYbYh7LJBoeYM+OHm+h36juctfAymt20Mj0i7HlprNNUZYC9Eu6QPXje2Lz6fHa/hi7mJ1ehYxmqFDOJFw3PLb3Pr3ieBoyq6Op+U+C4g2xVMLDt9PN7A== 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: MQ6H6b2AiVCK/0jzZF/oEdC41B3xYT+pkn5ytHuku5GqMDu+gHKlEaE2Dwb34sJmlCvlXWLF4TILRSZBh8ogSylSCEv5Bj5jH/xGKviAT5H+d5gLA4QMJvGvmn/x2ekQkBH4Q5RXPBcrFcZuyLjGI4lQbY8oeUYmOvU78slpAc5YL7eYYLPO7nVqRPLt6tgW41frZloBz5Z1B3H+I2XsHZLSpSiavukKKqOwRBsOXLud1ARm796VwCAafZTg/13Z6zkyQWGBGD0nWubXZZ3iT07OpsMARqA7xiNZDU9hyyU89sh7l6GwmyNU8DhrKhs5VlVJ1HKN9pNhvx5/N+oJYsd+kZbDqh7rFG3CRgp/SrAWo5KpnX9WqQ/Vj1cbaPkl6vwmmdZ+v7IzXb5XYEkNXN4xtNephgiztGUAO7IFiXN+OJkNRUMpLAur4iSVNwNEUtYvsEI19QVzeMw2bqulpir5Lm9gb4Z/pvIXbyHDt8H4OMlwyYsSolFWk2xe25omzyTy8MnSLYowVt1PyysUYdf+89htoxnLQmKsbf8MQoJ9rp3DFS/WCe30IlKv6xmFsacGvGVgg+IeagrcF+IiGNU7lvyuoMhue/73ulVmN3QXdz41zXniJL33xEygRIo8v43y0XXuobG2cU/NVia9Gg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 733b359f-7d37-4ca2-9574-08d83a6b532d X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:46:30.5722 (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: EiWojceaHJg5MTfYuzggx0IG4prWwPAsYWEjZoCg0AWItk9E5NzxOJeA7lURFsjx X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 --- 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 6ac4c00a5d82..9f3c4ce2498d 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -217,6 +217,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 Aug 7 00:46:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704579 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 679481392 for ; Fri, 7 Aug 2020 00:46:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6372E22CBB for ; Fri, 7 Aug 2020 00:46: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="e+BMdZSo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726563AbgHGAql (ORCPT ); Thu, 6 Aug 2020 20:46:41 -0400 Received: from mail-dm6nam12on2057.outbound.protection.outlook.com ([40.107.243.57]:36993 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726566AbgHGAqk (ORCPT ); Thu, 6 Aug 2020 20:46:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WUxLw+rXMhwkA8w6AsfXawf5ShyUchWT5x1NGS49W1dXyrrkhbyZznKBGjUaxlZdx3ZOCKv12IZDs7+EXKGXC0UAREPhSBe2vtgz9Pfr4iB65QnbezPJxBbwE/YppBIKZ/NWX+dd9rd+yZvodPuvpE/2Bg/aSPFcxcG6w9zB+r3jqJ47uYSi4LiKTLwLqV3kKd1OBYPcZkTHB/jvcK6eplwRMc+GrISt1jczn8+sLClWc68Ptqj19x33OHzuGqUhtb1giorAWhiSC6C9DyF9TCszXCpR7HaEnU6kA/mw3SogwKMW1p6B01STFop9ytrsfCQXaw6M+WCY0OGyB+tASQ== 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=VuwCb5C9JkblCU6rnYzFKqHshivrMHcXY9J26eoDsSM=; b=ezJo9YiorN1y7ZxqEzMQ3hkLUj2dmy06LCnQqDGUV1Jx3PndUsSgI+xuR+qjO7VbCi4MGsn4LTKRDPX4+Ppt+9ZerkFBEnPN/19C8OVsHv7VNuPpoOR2RT+C+BehgEC36HDDGn7+ZjS2HTOINNSZS/ol5fCHu1cXCbyZFZbtv46uPXspwC/1fg8RHDWFEFWHcTXarwWOiFoOO+RKBw/UOyn9QJWXwC/ADnJuwiSl+CgsmmTQckeigSsc6CTNk6A40xMIk8hKe0Jxu2GYAzmf9XAYsgHpoJlo31vsbqe9fOEJypBJ0gER3JIkqPZPsokY9a0IqJm0/F9uA8wVMh0hGA== 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=VuwCb5C9JkblCU6rnYzFKqHshivrMHcXY9J26eoDsSM=; b=e+BMdZSoGY1mvGVqpPBbmB2+23ej6G0Ca/vUKvML061Sm64WuXulkixGtIKN2QmtHo6yhESHP4cyd08vyWfYZs5mIhPeiRd6BLLzO350tAVEG1s1WpP3mTD3ghCXkjseEkVO8R8PSHUf+S9xphNFU83SWO16dcrXdqJquZi2Puo= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:46:37 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:46:37 +0000 Subject: [PATCH v4 02/12] KVM: SVM: Change intercept_cr to generic intercepts From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:46:35 -0500 Message-ID: <159676119579.12805.4839763918770862251.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN2PR01CA0076.prod.exchangelabs.com (2603:10b6:800::44) 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 SN2PR01CA0076.prod.exchangelabs.com (2603:10b6:800::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 00:46: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: 9ea08657-9676-4a86-f0d5-08d83a6b56f7 X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: u2Mj5J7E+hhZxNjaimNn8iCQjMh6P66IdoTdZrAZ9x+HcBoaIMfLd6pxRT/jEv1MnbIVnTMUcgjeJfFnKXtEwqDAmZsGyLwkG4i959bFKfOnuMM0+Z2xthzJ3ddRT4KqmeHOfGDpKIlS/fS3XguozYdAgRUmnwiRusc0EVawpstNFtWqC8lrNLX5nnEdG/jgez0Ub6E20X9K4ImQZIA17i5W5DODCD7A3VPOazOmUwmjo11/mg3MVgcGuHRz0npV/mL9018quUgzxRgTWGAobx1SGWWCDFIAJhT15Md3R0VGWic4uVtBSms4V0G7TAJrd5e8ukyA1n7CS7EkdFLnRR3i2GZ+ozspgmLgPLntfd5wq/yBVul62vD6YTalT4y7 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1j0I4OkJcSQ2Rw4mNU/scdD6Aeij8P/DfmCWGJXNug35vAeqjjtlicmDgbDjMcdAq0l8rfWmjjrSeeBbDzFMOPmf2NoCBzzcIg7+LqbJDLKf1lYCtIApQEF47WNNI2jZU8weYiCvexNSGGuOnK99p+b9IPsMc0qAGa8+dl6CZqc9d8ojDRMThhOoVa6n+XEAovti2CIbBAQq7l8OtNhbZZi6699OzZdtnvnWEwzWqQ0KceNyhdryvgKRGQEAwfXx7ejP4CLScieE41S7Df01e9UW9GNTrD6H7gt32w8u16PGQUpApWgC1TKKwhvZDP2ytlZrEncBbu5lPush+hKrdPkDiPDM7Ct7AdnjXT027IS3WWHTPuohEq16Pm+jnypRkXf0pNotTTHNquZb4ZZl2fC+mw9t9LqpCb68f8XWWTS3g+5m5bVegWcOYmGKAEBdt6Cruy6k0IFqayLjT7IOmF7VpIlXtI2nDPuD/PkrpsJVK4jogXqSBLdtvLmANyDHlBVQ94PjHvwD4d9qY2G9XqN+NwJvGHmRvsO90GkfXlgVXOYYuJAdXYhuL/c+9COCEdXIyw/de3ktZdVekwmHte5+Y+x7ZJJDXgIjZGX6fGMIIxVdyvHyQKnIJVYFwMVTXLWuatQyeKs3f/ppoJcm4A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ea08657-9676-4a86-f0d5-08d83a6b56f7 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:46:36.9245 (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: CqFVzD29S5agImvIAdleDfHxwTBicHpRMrDHwoNMRTTLdFRuIM1d87lBzf+5FTa0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 --- 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 6bceafb19108..4f7faca0d0b4 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -105,6 +105,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; mark_dirty(svm->vmcb, VMCB_INTERCEPTS); @@ -117,15 +118,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 @@ -138,7 +141,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; @@ -147,7 +152,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; @@ -430,8 +439,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); @@ -703,8 +712,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 c0da4dd78ac5..334bda8b31c1 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2797,8 +2797,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 9f3c4ce2498d..6d314cee5496 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -219,24 +219,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); } @@ -245,7 +245,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); } @@ -254,7 +254,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 Aug 7 00:46: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: 11704581 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 BC1B31392 for ; Fri, 7 Aug 2020 00:46:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B68DE22CF7 for ; Fri, 7 Aug 2020 00:46:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="KTeJ/GzV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726606AbgHGAqs (ORCPT ); Thu, 6 Aug 2020 20:46:48 -0400 Received: from mail-dm6nam12on2049.outbound.protection.outlook.com ([40.107.243.49]:39648 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726011AbgHGAqr (ORCPT ); Thu, 6 Aug 2020 20:46:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oXLTVLHun390HTRNtYIERD40OinVhm7QXeXKwaCcak+nsSI0XYGak0Jjn/egM+6SGf/Pv5tHxJFMFPqnH4oZIK4L/JGR3fcJKixLwF/r2vTna9eHKJL8aX1Jn5WV4JDeCwOSAr3LuXu87UfmCX1I2LqEUS+fys45Lzp1PpM8+HB7EFPIvODEXSjVMc+tVKBiznza7OwvObPp/6UGWy3pn7Tupe2z9S08CGaz/37pmI7VyOQrPxFZQsewO9K0bJm/LqaR44CVQklBjoTNUlY0k/O86NjPLVHf3KpqKdQoBdDMb4ijK+yBZQISGJloVh7Pq/egzDXg+RQmUKL99s5+9A== 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=k0yTwZNd26VQ1TVLHsYQBlG2BWZkf51oWo+ZYW4hiN4=; b=VjA17nkJMcD7+P+Bi4oQOAa61ALnezaCWTo+iq9jaelaclMb4kmxbaSHnaGL+dsqPoHNxhaAQ0B4AVkWOTX+Jic82Ui6X05Tf10uHmwxZq+53AVG8ZnOHZppPJdnYQGI39Zz6jvH3Ync5BlN5uoLFZ3+rqQyJfXvEf68vLw3CA488JgXcD3Lj8z+ghHA4eNYpZpEmNBuxD+2hXCd2pxnUDxNx6S44b8GAqe7p2RMJSZ0IUXBPBy1bBGWiLE30Lkn3ZkH3I1JIDk3XvvCrbXO0qDO8iuFcUma1l2NYWXU/tYYX3oD/UUCvoH1cxJy+sbZ9StOE7SGhEfEJMf5Fo3rlQ== 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=k0yTwZNd26VQ1TVLHsYQBlG2BWZkf51oWo+ZYW4hiN4=; b=KTeJ/GzVfj94oAqRsmGQCo5Gd0Ccg0cwsiQW6Lfs9M+Z59IAsxuHw03QhEw0gXT3acASolXnm4+Y2uzHJJF3B/9oH/FXGRYueZLRLHdlylKgHwSAjehLAEdys3cgfmmvQ5vA4NUhUTyOdfIkocYS5gVcJTioTEx9hV/FpF7IN+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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:46:43 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:46:43 +0000 Subject: [PATCH v4 03/12] KVM: SVM: Change intercept_dr to generic intercepts From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:46:42 -0500 Message-ID: <159676120207.12805.9462937617728281607.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN4PR0701CA0018.namprd07.prod.outlook.com (2603:10b6:803:28::28) 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 SN4PR0701CA0018.namprd07.prod.outlook.com (2603:10b6:803:28::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.15 via Frontend Transport; Fri, 7 Aug 2020 00:46:42 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 21ad7bdf-ccec-4eac-e481-08d83a6b5abb X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: rN2Z8mdXdONwkIQbvE9570HAmddUBh8O1BIOJ/OD6O4MXJDI4+Nbq1Rc0YL5CyDMf6jRq4yTYFkyj2ybU3+lbK3DDxpqO15n/y4zZc8s7x4nmBk+pCjhgVNA9mgOB53nYygTcyETd3EyFLOCkmXoe6HNLezsw6iYQ+JIxuZwsOOxtPb6oNz62eFSNoF1ShitFdu93gE/k3O4rT00SUpSM4dt3A6/MQm5f6u/gHST0LiwxZq5ZPyGD1F9FsDlE5sumnWIGlmWuw3NR+2b9tpEsr6epjoXGcFlsJgtCFS6Rq8cSsy78gj11+g4pQg8gQsjehtc7qTaknWxO6lj3/L/IFIFA526HSwFsMh7fMXfGv7jEil9hr9l+mK2N8IIQwyA 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: YS0K8FH4ERu3l0DY+1Fcd7G7s+EGbIDwl4Uj0oBp0JwsxFREPqwDYzw6ICuKme2mQTLD08pMLIK6PURb38SCyEigIp0qTq+zrzuvk3FSPEsI00AnKSk/5QhduXjwwJmtMdLSRzALlviNekiZIk/qwoZvVGAKDfjR7UpJSmRh8/39EhAOHqB0LpLstJcgtEwR8f6FGohOUFAfGKT2DN9WXss8KGYQVTJB5rTPLeuBAwHqGueBy147OoQfFMmV1fUOAG3YBO5PwmZ6ZmA9aU79M4meWfLcz0ekyn33ShaOGtB1IJ4YX550dbuNbnKbJn+fZR+Kx5p/XBFQM4t99C7D862x1ZAEemHxKFRYqJZ7LhrpxUCnx52NYAwyIog+noApwPmo0lWb5VfL9v/L5uBHdv//G0+L6rRyErecufS35uLct5g3+/+z31xYdf6TEMmvvAPwm3TW3dipqNmoR4K5z2/7iWtykNhqU5q82S/dkbY6ZbcvMWmL4D7sLQTVum8xkP61f0nJYZW3n1cguIsB+/VxiK3u/X9xGzQ5sk3O74eTVGy/Gs6csGdAXKk4FtZZli52COCcPhYoPfxAk5Nk80RjlKxJZAPlDaoUTHaAV/xa1ALPavBo9mbBk5J9tKox0pOmlmKFCvm54MXwEPrp3Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21ad7bdf-ccec-4eac-e481-08d83a6b5abb X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:46:43.2579 (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: q8RoLnzkVKY75bk3w83a9Bk7dynttNSQ0B74QM6VnjuyJ60qt6Sdd9KWHj+bBuSQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 --- 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 4f7faca0d0b4..14165689bd8d 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -121,7 +121,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; @@ -144,7 +143,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; } @@ -157,7 +155,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; @@ -717,8 +714,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 334bda8b31c1..6d95025938d8 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2799,8 +2799,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 6d314cee5496..24138874e8d0 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -261,22 +261,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); } @@ -285,7 +285,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 Aug 7 00:46:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704583 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 58F4D138C for ; Fri, 7 Aug 2020 00:46:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51355221E4 for ; Fri, 7 Aug 2020 00:46:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="ndQkI2dA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726644AbgHGAqy (ORCPT ); Thu, 6 Aug 2020 20:46:54 -0400 Received: from mail-dm6nam12on2066.outbound.protection.outlook.com ([40.107.243.66]:55392 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726640AbgHGAqw (ORCPT ); Thu, 6 Aug 2020 20:46:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HdDoxCkUAhslwj5yKRz5v4FXjVXoNQqgycgkGxonjyHd6O1fAKFT8QSYMdKCeXnh2anfknzRRHvALgB6cgCRh3zf1ofGSP5t+JqT4v6p74TJh05s4MRBJ4xqrfQAJ8rHnAhh8Mg73N8xIV6FXwcxVC1FCY50tzU9+P2JXncuz5sD1MRsrzKV7yLeTggnV6ZF25iBw8mDTLYtUNM719+Po2H1irYsCOg0zbzpkf1dRprRu66ij3pAJvHT42/JI/I23lVfZ9aFLbRZMhdoMA8kw0eUkI72w+AKf1zqlsRcCiTw+TQ3L25Vu9sPspsyAl1/gPVIhjYeZjFjnGDiVheIqQ== 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=OTb7FxoV9P8KyrwoTsh9R6moGRtFKsdc50bAbWtEPe0=; b=Mvn24k9kJ5tbCcIxc8uW6Kmri6qfwskpqVO9q7KrcekaKDt+SjhNaTzfYl6iBh4BnCu1rOd2aA09ScZGi0/bmVqot0lNqvJnFzk1Swu/bibBaVSmBwTuA43srkQ+/IyiTVvVs+oE69MRZdxl/dY1HY3sYEpJDGdYhFQ+qZdcNIi9YwppJT7nZ6+qvo+0HlUTXTJkjqfUhGCsB0bYaI1b/8TPedzRiGokBiWBERmwiNe1TfRvxZOCrAMyW07ZVSb0csvpvV68HYJlTYgwYlDIx4xFdjx2cB9Qkv3suxb4zK/FoX+GCkv5Hx5OCmLZuYutmlEDtsDXX6T4IvdBCjqDpw== 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=OTb7FxoV9P8KyrwoTsh9R6moGRtFKsdc50bAbWtEPe0=; b=ndQkI2dAqCSAw5tXUWPn++Q3Fsnp31nDNIMEZTSvMeVxsS0mm/cNNLnqfuNh5MxgY9C8Lw4lQy4eLEAWmvf0MKTkeMjlzrnaGkuQQ3lHG2ASAufCbqLKmdOiscscmA8jvF7c6YG0XHQVCvI+CYLpXFbgq2EzSF9EU2ccdplBis4= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:46:49 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:46:49 +0000 Subject: [PATCH v4 04/12] KVM: SVM: Modify intercept_exceptions to generic intercepts From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:46:48 -0500 Message-ID: <159676120839.12805.2738643693308373916.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN2PR01CA0050.prod.exchangelabs.com (2603:10b6:800::18) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [127.0.1.1] (165.204.77.1) by SN2PR01CA0050.prod.exchangelabs.com (2603:10b6:800::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 00:46:49 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 231637c3-a4f9-4b36-6b62-08d83a6b5e84 X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: M8NTY8ZSlOF7f64q3dsGzN/yq100CgXV6zvQch0VsjLbWbBATIpt5m6FMVWGnmhN8q6FAhj1SfJKezjbcv9AvfdBoY2VgKap2aurfE4MWiqImg8fTmcMwEHHUiVzGw/KXaWykUa8Rzj1N+5KyLK+gQ8Bx/iAwVOhTSt64Oq7IOtSc6pPojSh1F6UcJTcegvbB2Ffd8qZlpK+ufeUXdMzKee3W1OoGsivh09pyduhHtfZUkxKsM8DWAeuaNgasZDTAogDiMPXQy8kBzR20vJEvJHDdh2T0c8SgrTflkOZsmYwNWykPcrlWNoQZ2yv9gtWxzneH98FoyyCv5aSGqJqRujxoKOFBZJkVqmcfO6gJlX8SGq+QQGqwkekCoJjXRid 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: cJ82OCskPljAWxM7iW5lw12pn7L9DPEwzzVTsH81J+/j/sqvtdKYR8HxlZ9483VeCX/ZIFlK37SLFOy9bI6JIhy9+GL1ZT/z7uc7PIPHQOkqlCyDvA5VcitN438yO6NjZvH6so6BB9QsAxE02NrnKc6Gx9bvBlorALenUwfQwooOdQEvqDzUDLOdLdFKYFQDcrnq75jhCuXm3Nco573PUqkgwUXXxWWSqpTFw+eZ494zYP2oRaittPiHU0K8F/joiDIOJUI7k8DeBj8HE2jz1ktAZmgpPRTOIX2bGqvwoS4hP+f2Ms7ifFMcteLgmd7hD/SYAk95noL9aCO9RIfOkPFy8Quy8oJsniu7p4zFojh5LZU13J2lFxy4GYLB3qvT0mdjBFhNS6NO34rRIMrYkH8BVexlUEPV7tahXly4x68I9ynJhPW5bTBEYX3YwfT2miUTYLu5FIvHlgwEwwMoOJb03ypnyq4xvyNP7Zs7dpTQ/q+WWxxe3ErwZEL/iDnMfDiic6v8OP7SKp9g+WQvlE61RR2REQyJsyXjSVnUdtkImIq5z7ggQstNm52BIKxNwkw2SHEourcriUYDtd0Oz3cBHqRx1uKWw3325Sy63wOqKiqe/2VsS9/sqL9bkwzNhXAhluTQzoOXVzK1m+veXA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 231637c3-a4f9-4b36-6b62-08d83a6b5e84 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:46:49.6302 (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: FsfCgkjs0cRSgwX8zxyo98qfFgtIQxzX8XuFj9ZyKuaGn9T5dreg1++mBrRKjFEb X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 14165689bd8d..080c76dc05d4 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -116,12 +116,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) { @@ -143,7 +142,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; } @@ -155,7 +153,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; @@ -438,7 +435,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 */ @@ -773,7 +770,7 @@ static bool nested_exit_on_exception(struct vcpu_svm *svm) { unsigned int nr = svm->vcpu.arch.exception.nr; - return (svm->nested.ctl.intercept_exceptions & (1 << nr)); + return (svm->nested.ctl.intercepts[EXCEPTION_VECTOR] & (1 << nr)); } static void nested_svm_inject_exception_vmexit(struct vcpu_svm *svm) @@ -922,7 +919,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 6d95025938d8..d4ac2c5bb365 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -988,11 +988,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. @@ -1000,7 +1000,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); set_intercept(svm, INTERCEPT_INTR); set_intercept(svm, INTERCEPT_NMI); @@ -1078,7 +1078,7 @@ static void init_vmcb(struct vcpu_svm *svm) /* Setup VMCB for Nested Paging */ control->nested_ctl |= SVM_NESTED_CTL_NP_ENABLE; 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; @@ -1120,7 +1120,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); } mark_all_dirty(svm->vmcb); @@ -1631,11 +1631,11 @@ static void update_bp_intercept(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); } else vcpu->guest_debug = 0; } @@ -2801,7 +2801,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 24138874e8d0..246ee5fc8077 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -294,7 +294,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); } @@ -303,7 +303,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 Aug 7 00:46:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704585 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 1F5D1138C for ; Fri, 7 Aug 2020 00:47:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C3CD2173E for ; Fri, 7 Aug 2020 00:47:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="wny73jfL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbgHGArA (ORCPT ); Thu, 6 Aug 2020 20:47:00 -0400 Received: from mail-dm6nam12on2079.outbound.protection.outlook.com ([40.107.243.79]:1361 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726710AbgHGAq7 (ORCPT ); Thu, 6 Aug 2020 20:46:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PRk6Ap3TCaWOadtB1Cyal6hmRtl20wiq2gI2iuSVm8ejRH01fSVy9IuJso/mtlslH7kaH979aX8z67a1h4jO8RCoewFzFpE+B1Ui9SEUjV5OcZnsssqgmVK3LSi+fSahfn1N+X7K9meNMILERloGjvZRbPh2QIRrhtx/KdSp6+qbvOV00KBBkiYNS/XE24zAdCL955De88OWOWHPwXtf9Xu+mM3ht/VR/jM53Wta+qCY8KhEUHlWeO3/5DiB9AUET4cmtHzogt5kRRSVexn5476wpOPaYWv+oDe3zJbw4EhllR418oOGG4XzZFYx+5Bz+tg/UrTI/Ct9lwdaLu/9fQ== 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=2AaFux4gDWhfQ9H+l4AdMGyAUmhoVV8Qe4bc2cntnB0=; b=P1aOtcCGGCKPIplQHYwAkrfI/bCvPasQFDEGxFkgdlmXH47wCmXbYyNyyUniTS8S0EWnyPagsxVQRP4Lukt/boCYyXDwdg7WOlX7WSGHNFQlFxU1vxh5JDRcunLWannmgpKMCifRuWmo//YSjig+P19GfYFO6sNoRcyU8ovP2bbxv3Sai+umsEtFeb1WgJE/9N456/aJ8DdILvCFQEu6EuYZVPGFlwHnDh7hm+hcZeoYOM9tkMIRjAJ0GD0GqJlgmniNgcW9/0ugjtgGE/i0i5qRFs1v1Ba3I+gpVoZislu5kPMCUGMkrx0Xc6tc5p2EKfSqMMkq4+1TXSwkR7Qldg== 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=2AaFux4gDWhfQ9H+l4AdMGyAUmhoVV8Qe4bc2cntnB0=; b=wny73jfLd5IGFkffi5FBFEJ7eiq+3W8Pv5huHFH5tEaKESBp6jppjrYopNVQYkQipUxVSmqrDGh6/ZQTEKgOlCoXTstYSA0Hhjxzaj4AyFeRNC/SHBiwjcU6VVcKDlApdlKhAgE11/i0TlSOORgr8Uy7LvvbDiBIg1Mv+M/nm8k= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:46:56 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:46:56 +0000 Subject: [PATCH v4 05/12] KVM: SVM: Modify 64 bit intercept field to two 32 bit vectors From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:46:54 -0500 Message-ID: <159676121478.12805.17232897630131635542.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN6PR2101CA0003.namprd21.prod.outlook.com (2603:10b6:805:106::13) 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 SN6PR2101CA0003.namprd21.prod.outlook.com (2603:10b6:805:106::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.0 via Frontend Transport; Fri, 7 Aug 2020 00:46:55 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b2c02720-1037-4ec7-89ee-08d83a6b624f X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: A46CfIVdispn7vrmizgb/A7PdBjPj8kpzSEbrIYn0JYR0osUJ1eLuyAwCz326RI/vWyTp4z+MIviF9ybE5LGjTr8GyQuAhaf+tS/HXxZDqvv5V5fz4O6FmCmtCoKSBH0Gbr1NT4PwNXUW6o5XWgldiOU5921ykU1ccEy2ikX3lkXoby72P7MTWf2MDrWFakTFJ5N3VnCin0yafhf6m5iLAqGmpmWndk4A1VS9a5gqGn7WeebNuYToz4JX2F3R/pOH84OSqaAYqnoU6tth5AnWRYrC9L9vw8FoSvGUdnez35WQcWc4xH32gdagubEQXgpAv8CZMmCp2IO3Bh7tqZqYA== 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(30864003)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: wPY+Np0CELTVowtgJzriNkkGFjYzitq0/iQd6dLAChb2Q35fNr8uxsD03mYijzs9UP8lkfTjRi6rWmQ2T0DVaKZxoVwdjk9VuF478gom4QTbslloL7suJseI2V/ChrDcYDXS8tP4iiOaKBGYIgxrskVwwZJfkyja2icLk62iakSRqhWQCygxhDAE3NjK0/zCael+ZjHu/8vBqg9FXdmwxwb+XWDkKXfxIX6JAVtTNiSHextAJxoIge/OjZnUxDcwJmkc+zwWSzT953G+OWtI0J0RGmpKUFBCE0yB1oUIK5c5A3tArid083g+xb6PWtGTkCiNk+xkWzVth0DL7qbSDJ5PiZm9waxpPEQ+4ab3FBKumgTrkn/QKf0rH+ZvGAcaEIibCUAeHIHo6KpQ2C59cqlAx6o9t9UAZC5ZtSlshyuPHvZPb2+Ih9fKpeZlQss2tu5URRmS1WBFdDnrkpc2XjKCX9qshvsFYkC+YQmQYyDAE1CmaOLPX1IM6BGzWkvRuCG9InBw1r0xfnxekXzLFt94u04+Gt964K1pE79+bxDFqedx2Q9WPhAketzMTzbN95h0D+oPTC9Qh3giM1lPJ0UWj7iODcYagGojPy0kjFo/Oybgbgo+nCeOMtb46+A1ynf9n9B2t6aqCMIFCG/e9Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b2c02720-1037-4ec7-89ee-08d83a6b624f X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:46:55.9625 (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: oteYnN2D9u/BXLhMpQroCAloH5JU8/sFTWvIQ6LMlBj3iK+nl9Oj4NsR3Ts7FGF0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 080c76dc05d4..2f498641e15f 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -121,8 +121,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); @@ -133,16 +131,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, @@ -153,7 +149,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; @@ -186,7 +181,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++) { @@ -212,7 +207,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) @@ -436,7 +431,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); @@ -648,7 +644,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]; @@ -675,7 +671,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; @@ -729,8 +725,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; } } @@ -838,7 +833,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 d4ac2c5bb365..9bafb025df05 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2204,12 +2204,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; @@ -2802,7 +2799,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); @@ -3677,7 +3675,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; @@ -3686,9 +3683,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; @@ -3947,7 +3943,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 246ee5fc8077..2fe26c2df3e4 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -312,7 +312,7 @@ static inline void 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); } @@ -321,14 +321,14 @@ static inline void 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 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 svm_nested_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); } void 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 Aug 7 00:47:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704587 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 1BCE8138C for ; Fri, 7 Aug 2020 00:47:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A600221E2 for ; Fri, 7 Aug 2020 00:47:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="tcMCXdku" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726776AbgHGArG (ORCPT ); Thu, 6 Aug 2020 20:47:06 -0400 Received: from mail-dm6nam12on2082.outbound.protection.outlook.com ([40.107.243.82]:26337 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726756AbgHGArF (ORCPT ); Thu, 6 Aug 2020 20:47:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l5aqcOXrTaifaAvFy6uwcY1WXOdn3bx2BrCk0nxlWqPCOOdc2o9lqSiDP4DvdoLmFxcgESq75Zpy1SCSYT9jm2dRdF7Q6y37ycwO1E+T0uxAJIKeDZ7OSODoBg1UckP8lrp0c2O1qhdckktjAALd1pJVczWDmKTQowpc0Ys0t/P41iyjwAs55/RN2+Syd1M/DEOpuWLD1R/vuc3cbj4c3bVbSJQWBWOXDkeMAsoFgyOnK/Pa7AFMV6rdNfedqQPvNSqKX1z4JHmZm4pRhSwourr6bdT3DkAyKv/7K2Yv1tiyfoZw5vbzcP15/JDoPzUIh1Ry8mdvSUClkD2i2aqO5A== 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=snlA7AjhiwpY0bRQHsigms3px53kQiNRgM0dGvVeQHU=; b=JqK2G4p+fHEL5Lfn1SYIJl7nNNsOkC+HaNpotf3YSHmAmdSGZHgR38HBXitarissEz4GJQBF5xJSXvw9wf2YJVmgrg47+y8/d/ftufmMwFkwDGRSuiYcLVXJ69R/sFCQC4pxq8MF+CJCxvPS+/IMY7L4HHy8JwqoxTfUVetPvrFRYHE6Et84gQVRTkBVbJCDUlJCPawdlbdSHSiwYMrmYX8vHVFKufOtcwNBQw/9GIloaC+1GV4gzP1qwiBRPQ1/XZrxf4646bKg8Q5HnpTTfPsgnmSyrqquSJh4r/Nz+7yvHi7E/Qe+xh6HaV9X7Hes8mm7WZtttIW91KD2tc6uAA== 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=snlA7AjhiwpY0bRQHsigms3px53kQiNRgM0dGvVeQHU=; b=tcMCXdkuEZEkYTwdfiMRpzOb4cA2iz3eKz3SL90ilaWuWrsR2dwEkYn3OjV4yP2vo0so6O9OyPW3sQ+JV66e1D8JgMT4Q4sxzvmJprQsT8eXBrqlKf566FiIBQZ59G41ANo4AIqHNHzGW47e5Cq5fLzJqf2K9oehYJ4KNvjaGCA= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:47:02 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:47:02 +0000 Subject: [PATCH v4 06/12] KVM: SVM: Add new intercept vector in vmcb_control_area From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:47:01 -0500 Message-ID: <159676122109.12805.1137119026568471621.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SA0PR11CA0054.namprd11.prod.outlook.com (2603:10b6:806:d0::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 SA0PR11CA0054.namprd11.prod.outlook.com (2603:10b6:806:d0::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16 via Frontend Transport; Fri, 7 Aug 2020 00:47:01 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8ee70220-ed8d-4770-99c3-08d83a6b6632 X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: Vp5wyEsKEGQ2RPnuaLmAV90sKd9yq7OurGeKvBFLdLeMW1B8BOPNOHtNeJ+QH4m9Tgkq3YeiKtSRKW0uzu9bO+hp5pTuCfBfLEtUYDAWd3G2MSRazyVQ7ikjtUm0QUbSRNloWqFCpGpuDJwMMhGqA8JZI7LhxC1WBmR7bUZGPvUikEnZCx6jgk/kptVVU2xbIwITQJuhAN+c9LUWkmOhePn+fzgJ8hbGuNwd3eSFj/FA1cShw4k80W9aS+YJ0jP/sOHJ5Bcy+0F9s16HT/SpI1TN3Ld/+OLAm165yNtzm5t1os/pwd3ZtEidFPAd+y0lqOHK0J4N6emN8vdNGVMjVTlxOo8f7HizmlvbS9MyvSmuJhid5Ur6tpb6GcYzJzkpxePu2eRg+yBroI69IOLUIg== 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(966005)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ZmgZgKTodl47EQOATtTwdZIoRv56GPjo4z68tu58aoNNg55bJ+jmA5a3I9wpOgvzpMCwfm/Tr1yh5TReCHOH5V1wvkSGHYbq/NMP/5bNvuNTFT7XIKQsU5rCRBZvvZ3SDI+ne2A88zQWoRo5Es0lTHdQ4BRQvoo3FoXqKHsyOhq+pEfNxI1WUD+4cB0qID+1ZhNirASqMar/3vgBtsPCbMhVjz2tx6E0fSXivIhkvE0764p3La1w/gc6m164Qsj5uLp0rzqXp11M8ETxuNM4DG2zHkEEdVoLPSrp53XGspE9259YrAqQQSnP5m+7hTiZAp8Vbys8Lm9ah1YJXiK3pFmKhQWaLOCeSq3gtf0cYzT0cvjxiO2SapD4hq2xs0sktcSYkWDw6bZh/0sxGedSk5lqFjsXWYsdjm4v6FbDC54mroEUGoSunY0pzvR6h8B6GKAJbT3bkXoitho6iqJKEeW+/9IJIUsb+OTqfj3FmsyWtDvF4I+Ws83gPUatcnrsk5T8Howdh1SpOmvKNEz/8rZZbNRyJHUL5rM5lOt6/2lvkwkOKYbCV4TwniuS7KP8DEv61M+gjPhH00F+Cx+3+Ct/SMaL0lxPaADnssEUPeFvNNxb5XCFL2I3Or2l9a3HAp7y0SjAzisD4cx1k3hgYA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ee70220-ed8d-4770-99c3-08d83a6b6632 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:47:02.4988 (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: iBmQikv6itZfzPqHO0F2I5rSQ9zCa9+Y9KF2SJtyXpYfmIS2bFT+kG6gjxRVbi+n X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 2f498641e15f..c0f14432f15d 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -432,7 +432,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 Aug 7 00:47:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704589 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 17197138C for ; Fri, 7 Aug 2020 00:47:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 184B2221E2 for ; Fri, 7 Aug 2020 00:47: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="CsMMfp1o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726809AbgHGArO (ORCPT ); Thu, 6 Aug 2020 20:47:14 -0400 Received: from mail-dm6nam12on2078.outbound.protection.outlook.com ([40.107.243.78]:60064 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726038AbgHGArL (ORCPT ); Thu, 6 Aug 2020 20:47:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aM+NIZJmp96LN++Mu7vykIgR0bN9Zg3Z4U7oaORPxJwr6GUy1nsBTFLPIRZ7OYxU+jy++TZz249DCPdr/6fcHGa6Skeyk8oqZ4jx0FH6fjElgfRDdwpzgecoeomfW5qBqEavJkC6tc8akpo9paxhqDnVqmPSk5QvgSZ+xaoNEcb20fDYqEJ4Z0ap6pBqDCqcg11xIwb9iEPxYUwmUlYr/d4BwMnFim1JDx1NemY9PUOH2JDs20UKG6pzCSTW5mRzjMMaMzsmtTaIEVIPSeE70qEAWVUk9K+iiBqYJyW7k50oWIdU5Jse8k9MOFi2SwJYeQot7pJ1AzTI3MbDN1FXHg== 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=OqIK+sbjSGRERqMOW+99tS1Wit9VDhwdsPbKcW9fJ3E=; b=VxNQnu2w4I6P0b+vHtLAypoS6NzTgI8htzvD7+m5uu8L9kNmdYr8HJvAzAGQM+8zvxjcJh8Bs+TXvJHKGX+UW/88OTuhU+yXjAuswN+TP04uYSuiPx1RJeayJCTxEZk3TJtR8plu5kJUr8nnEfIOAmnZOizShN1+dS5L0p1UfZjISkBQcqZG1zXkO/m3F0PWHc4zSapCGePF2TdHPL5GlFgfU4Ew6iM1uPIE+8uUR70/bgDT2O8g649a6ZhDj1wGD0kYKm/K50WsyMfMujaiTncS+APx70wieb/5m+FuD2t68XqWIDX1Apseer39IYBb/jOJIEQqENBPBAAulAiD9Q== 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=OqIK+sbjSGRERqMOW+99tS1Wit9VDhwdsPbKcW9fJ3E=; b=CsMMfp1o7Wq/DbK6oUi/P9lYjq3Kbtpa0FvTcqKYV8gQOySWC/cVz++KioSsyqylXDqTpN2sg3KLVswRXANv74Je8cKqfvgJzOKNCVoz5cr9QPqcDaDsmwUxUWontt6avc13MCjSQzYEfPrMM9NxzL0qROow4ZhPOauCPmJH/Ek= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:47:08 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:47:08 +0000 Subject: [PATCH v4 07/12] KVM: nSVM: Cleanup nested_state data structure From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:47:07 -0500 Message-ID: <159676122778.12805.17553021827193643253.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN4PR0501CA0004.namprd05.prod.outlook.com (2603:10b6:803:40::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 SN4PR0501CA0004.namprd05.prod.outlook.com (2603:10b6:803:40::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 00:47:08 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a9904e1e-b7e1-44d1-77b0-08d83a6b69f7 X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: Y40n/j9ipOS+V0QXFlO/MCBrP5ZxWorhenGDpu8yyaQ4Ul77rnP/0T+wt8DpRCoHUK06ciXc/876S1n4aFU3Ih+G8r7mKKYdiIVR+L07rUI8t3W22WyH3VyvRtbmCKaGq4ykv6rkSNx+jsmN20MfuJD5VRsgU1+lbpkv6sxtqLPBVIFy/0uBTW8y5N+iS39Vl1uMoLkMbIlqa/T/Z5fxiMdirrvnWHiAVtORblGrfPejkCs6MUHP+L/MLRUxzZH94BIGAJJkh8wCNBAX5YKZ5DB+sXSX9dVXYhJsA1RUK+X1IQTZbUCyI8ZU6yBPhSo4KHov5Rlzp8n7wo0H37cgEg== 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: j7LtQbVM76IRViR1XFcAu5tdeoFm6CfuZy8NMuqVAtZ61KA037t1wDqWAoQAyRO9xOTuqtHwVkqevv7UzuNim0i3RV/OjA+pt2o9RQdVhqiz4XD1FW4bWCoPrmP3/QwSc95zX+CjSW4/UNyAkqlyfMwjJDN0/jrzu7IKe75xTrHaWiggz6g5qxohSbzkUL6UZ5PreJGXsKYg3dzRZUQTxcUDToW+OT2o9ZZiqTLICjcx0d+vogMwlq2fjQB69hqJG7CDD1TnXy11n45014QpsYFicK/AHlBpwAYaUJ7ylfM0hoVlg3MUhbqHW18P0eVO2wAAl+5aJamOoCtlLTubSMc1lz9aSA4j8h57PfsIdJaghpCBSGbnvSkKNQGzXMFy+3bwXBAsFAiIqlGXx06Lo4N9Z0LUgwFE80TjpqNT2HTOBLi50Meg+c86RIVpgOSV6NM7W2XkqT6a/tGevEb2/c9g7EbYCo6t/QABopQVa/xRaNu4c/qpHozJPU1QHb0XP2SKlCBu0D8L2m+B7w0twqHmGqlSrGXoNgPmx5gTzAgSt15UUNOk4ffCwCfPWt4errWF7X1Zyp49/eF24Cf3Qbb4RFYqYzgD6T2r31eLH2daImqXzdgEqPXpie++Ow5k2yijMh0xLnPEbckhumV1oA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a9904e1e-b7e1-44d1-77b0-08d83a6b69f7 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:47:08.8151 (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: U6UK47SErVNhgTNTit45hRbaFsDn3fb+HfVRtAIE1FdtRXBcOu4CmK59d0plOHeb X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 c0f14432f15d..aa591120b4ab 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -116,8 +116,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 2fe26c2df3e4..0025d6f2641f 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -86,7 +86,6 @@ struct 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 Aug 7 00:47:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704591 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 4F301138C for ; Fri, 7 Aug 2020 00:47:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F83A22CBB for ; Fri, 7 Aug 2020 00:47:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="0Df6oRfN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726766AbgHGArU (ORCPT ); Thu, 6 Aug 2020 20:47:20 -0400 Received: from mail-dm6nam12on2052.outbound.protection.outlook.com ([40.107.243.52]:53217 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726845AbgHGArT (ORCPT ); Thu, 6 Aug 2020 20:47:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=doVC5UVNc06B64mRBuZ+clV+j+tEnGutCOcKmAmVafqHEbJgULi8esCjg7fkX1UjiqeqUU9ZCD7pfTgzIjfJgcFDJwtD6+tqC1z3Eu5nbDrpeW6OI7TAJYHE6X4dQhyfozOu/Frpjq5dPzJCXKUHT6hHz5FcX0sUmHhAKPJDRnPn3iG/LeMiDSaBmURPKE5qfLXrkcZK9/iRhdoRiyEOwCUNDMztzMLKxkRaxS1Gbe7I33TUIake1rVbtPulFkVKui0u9NF7WbZvgvnnSNU/6FoRNXjo8Pi25ftB8M+EMLAEAT7/Az4kuFhgw1jOTV1nsMx+98sMC18CIDUqsUa61w== 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=gcn+PDyVWiZ5BWEFkJ0PL3+4l3UCjnMBz5UVdGFUwho=; b=Z0qs8MG+d8Fam1CnQBK9Njxn0c5HlwBVKoJOP8UpZQSdSndBDAXkCFlWTrJLJ4wPNMVOJXx6T+UkeYl0ibqbt8ada9GBBIm5Aw7cwFd4282TM2MaLlj+TzpWHr+XMxezUgtWZJIWWA46PzU0WYv3RxVQZ2bb9STuJx3LV2HyV/iSapd3Lh8IbkcxqtCBQ3F/oWPScpftp8e/NxLTh8x/weswZiUNqlDUJKZAd5suzRGT7c89isPMAsZaVhyB2Pq9dyacZ6SSOZRc+bKVs8hK8wTZRwGzY3m2KeWdeuzMw3jz3xK5pB8oyobTLNS02rlrxm8ry41McDWPWhZdZcg/VA== 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=gcn+PDyVWiZ5BWEFkJ0PL3+4l3UCjnMBz5UVdGFUwho=; b=0Df6oRfNnAYzwgTCLSLLK98w41xDVQ8KiKRfrb83042sVrZjp5OMvxmL8pm3IwgvCbW+07Pb4icSTiJCJi2gR5Yz9ANc67h6JJH3oYL68a/koUTWbV+6JsiY4OnW5KuO0cP7ILDduBJOaaAH+N5l4VHaSCEhT/DkBa4DvwreIHA= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:47:16 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:47:16 +0000 Subject: [PATCH v4 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, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:47:13 -0500 Message-ID: <159676123395.12805.16488410340966484419.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN4PR0501CA0028.namprd05.prod.outlook.com (2603:10b6:803:40::41) 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 SN4PR0501CA0028.namprd05.prod.outlook.com (2603:10b6:803:40::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.6 via Frontend Transport; Fri, 7 Aug 2020 00:47:14 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7b33244e-f071-4e77-f77f-08d83a6b6e5f X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:106; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TqYIRbW4d8CwZvPjj9pzbo1lpjEbwgf/cC11XLsOL5Jl5TMrXNWYdw9BZRMZhJHWKOTyNkpiTEscKTnLx6RIWgXYTNxRB1Gh4t9E1qQvIucX1fRYHXOsxDYpiE3XUUbo7JpRewspNOfnXjKRuHoTV+2WB/tlQqtU/exaEDetyjCFHI/oLZrE0pb1ihcLf5NYeLkqchMtsegtJtrqmGrnhTU6oMiBOAO49Xdg909B6SHbA1wr2NDjGmpBFtDIpxy5kpVfXvYDpLb7dreRJdeyq52lJbuM70URHoeRy2FiyrvGdFTbU/DLWATs+/CIhPy7 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mYmSWAUnL4jw1+qo0kqQ/AEBqVd7YIt0xbzNwFkxB33fnmX3AJTGVeK/eCXkPaKyCGFBfCM9mCWHUtORk/olkeb2vcVkvFebx32ZnlthEZLWppZ9zVS88AtYatNwvaYxNtIrAYL7xgBfCJZMkZCvAr8vD1OCXUBjEdLTh784JZN4+1GLlYPE+k9YGGWLTDqYLFoSIxkUxSZBr/oFceHsuT0RebOMPfTC3SH86hCgkZXlln/a3dMwtd9H7fQ5Ni3CHzVXSZn5hV1UhNBU6qd3Mo7+fekWnSRrmo6nCyE7kuuL1fZs8IkobOHnXgV43LhrvEIdHk0PVqIzSpmFLSDcqt+Gl/tjc4HT4nNeoH4/PkwVL9k+TN7Czk+R+OeXvmnXRHMiMxOyzQ4qPSyCijUaIy4sEl5QsiGMJ74L+XJzPEylbw64wGmbsK7nAX4UwSYoPlcjQio73vJ2UL95Chr17XR138gCZNMeSofVuTRmXE7GpahQkWjDFwItZhAQWtlE+YMXm/KSxM+LTZfcpKG/73vZ1NfA1GaYJ8OC6+Q0MRYGhc6QdEh+BkP7UdopXg88CAbCs0rTfnH1NkTm8RGz23uB9oD/8/Oq+yTdtjtCFenX2xqV0YhGceHq0HnTK4Gr5sYHUpdFx5yfitd3p6fbHg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7b33244e-f071-4e77-f77f-08d83a6b6e5f X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:47:16.2268 (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: Tl6yjEqXYR4SPZ21mJX3Ik6KntmwSsv87kmdfeqj2Mwm8pQieUJUKDDm0RwsIUn8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 set_intercept, clr_intercept and is_intercept for 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 9bafb025df05..b40ed18cb5c2 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -977,14 +977,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); + set_intercept(svm, INTERCEPT_CR0_READ); + set_intercept(svm, INTERCEPT_CR3_READ); + set_intercept(svm, INTERCEPT_CR4_READ); + set_intercept(svm, INTERCEPT_CR0_WRITE); + set_intercept(svm, INTERCEPT_CR3_WRITE); + set_intercept(svm, INTERCEPT_CR4_WRITE); if (!kvm_vcpu_apicv_active(&svm->vcpu)) - set_cr_intercept(svm, INTERCEPT_CR8_WRITE); + set_intercept(svm, INTERCEPT_CR8_WRITE); set_dr_intercepts(svm); @@ -1079,8 +1079,8 @@ static void init_vmcb(struct vcpu_svm *svm) control->nested_ctl |= SVM_NESTED_CTL_NP_ENABLE; 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); + clr_intercept(svm, INTERCEPT_CR3_READ); + clr_intercept(svm, INTERCEPT_CR3_WRITE); save->g_pat = svm->vcpu.arch.pat; save->cr3 = 0; save->cr4 = 0; @@ -1534,11 +1534,11 @@ static void update_cr0_intercept(struct vcpu_svm *svm) mark_dirty(svm->vmcb, VMCB_CR); if (gcr0 == *hcr0) { - clr_cr_intercept(svm, INTERCEPT_CR0_READ); - clr_cr_intercept(svm, INTERCEPT_CR0_WRITE); + clr_intercept(svm, INTERCEPT_CR0_READ); + clr_intercept(svm, INTERCEPT_CR0_WRITE); } else { - set_cr_intercept(svm, INTERCEPT_CR0_READ); - set_cr_intercept(svm, INTERCEPT_CR0_WRITE); + set_intercept(svm, INTERCEPT_CR0_READ); + set_intercept(svm, INTERCEPT_CR0_WRITE); } } @@ -2915,7 +2915,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 (!is_intercept(svm, INTERCEPT_CR0_WRITE)) vcpu->arch.cr0 = svm->vmcb->save.cr0; if (npt_enabled) vcpu->arch.cr3 = svm->vmcb->save.cr3; @@ -3041,13 +3041,13 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr) if (svm_nested_virtualize_tpr(vcpu)) return; - clr_cr_intercept(svm, INTERCEPT_CR8_WRITE); + clr_intercept(svm, INTERCEPT_CR8_WRITE); if (irr == -1) return; if (tpr >= irr) - set_cr_intercept(svm, INTERCEPT_CR8_WRITE); + set_intercept(svm, INTERCEPT_CR8_WRITE); } bool svm_nmi_blocked(struct kvm_vcpu *vcpu) @@ -3235,7 +3235,7 @@ static inline void sync_cr8_to_lapic(struct kvm_vcpu *vcpu) if (svm_nested_virtualize_tpr(vcpu)) return; - if (!is_cr_intercept(svm, INTERCEPT_CR8_WRITE)) { + if (!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 0025d6f2641f..6c3f0e1c4555 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -231,31 +231,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 Aug 7 00:47:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704593 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 6084F138C for ; Fri, 7 Aug 2020 00:47:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E8932173E for ; Fri, 7 Aug 2020 00:47:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="oBOeDrQz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726862AbgHGAr0 (ORCPT ); Thu, 6 Aug 2020 20:47:26 -0400 Received: from mail-dm6nam12on2083.outbound.protection.outlook.com ([40.107.243.83]:11136 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726066AbgHGAr0 (ORCPT ); Thu, 6 Aug 2020 20:47:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xt4CtOFKmDQh6FFaHWnbmrAvysif7zwvSfGBneaKFd+LrrEoKUJtS5YLTcphqQMvoh0mzuwh+uiphKG0p2KPPYO+4Z5Bb0YIKdtpWlUAgHTWX+bqJvYtYzOxoDmZbgQkSCC9mCBAjqRcFihHhjB9qCSHxpc+AJs4BhO4n/Aa6ohVQRF0HQ80CQ7rtOrjwHRJ9sd2lcmjN5Kg0Lt1bqO6hUnanQTSP/ilyK0C4rMDY/doGEhQCZTsuQoOI8W0Zq1CeLW/tvOit6wf8s2kTKXAFzS2TIiIpxHh7/XfDB/A+PRSSXZ9HAw7zjrhiuYjYFM/GQXetZh4DutBdBRGO3Dnbg== 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=GWkruwpGWx0iXEsbTAy7FsBZna5e6rAFluE3Xj0qMm4=; b=dBeug/suh93ZIYA0jUCPAEwib5Yk9H+aYO1v1gKsDJ/4bsUBXWeDgCqoR7DlSCejGYvGx0rLvIC3PRCp3lk/+/Cy0aO220Ai+C0x9CB7y2hGRhDhXVF0KExW/7nHIwsyx9KVGmuEq6ZF2mQsvkKX0QQYCfMoXGMHUyD9YpJra2MMNTxX/3UT8cvRL+DRY9aygMRCxJGqWzeeh7XzKvaZmO/vW7ftZF/GOSH01Qe/DUJSbaUvqp8MlFDVtkFjlsIVEUaiMzZGQMYgROwfadz4OZT/DehOGDlrNYMr7t6RoVDoCQQhoiCIOqDtv0fS/RtV4q5oAyR8Xr0/QbaIwYRL7Q== 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=GWkruwpGWx0iXEsbTAy7FsBZna5e6rAFluE3Xj0qMm4=; b=oBOeDrQzWOJX0GvAddTZEzkvXDOF8MSd0tRSzPZxFkJv3vcO9CBFrCQbmLPU+KEuhRaC9APeyWqIUptb2eTLiE2kc9qpLMzn/EjNzIlBbfwDGS3A+HviD5/85FWNSnJf8ymEHWzQ46d8zSNA+qCwyEQAnvzmLswPAUixfHZ6OWs= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:47:22 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:47:22 +0000 Subject: [PATCH v4 09/12] KVM: SVM: Remove set_exception_intercept and clr_exception_intercept From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:47:21 -0500 Message-ID: <159676124143.12805.14542564267316476190.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN6PR04CA0089.namprd04.prod.outlook.com (2603:10b6:805:f2::30) 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 SN6PR04CA0089.namprd04.prod.outlook.com (2603:10b6:805:f2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 00:47:22 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: afbe4503-7278-4822-1d18-08d83a6b7242 X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: oJzU+kKrjl4k9YdfCnrv81kVw3CrXboRK60CHjCTGS518hMenD2FBiaJxXqH6vFSvle6JaLk/VRNrF3XwlDKVZu5QVA3rX1EqhRY3Z2whmjKKmiRUHCuUj7RAk18V49KwQsqSQFJLj1sMVzgLO9ZOuIzrhNlOtQTNgC6lA9izE0gcNITTE51k6s+6pEW6pwH/E+X84ZUdJ4COcNFsGcYqokp+2/3D9vJaS1CqvgmlCCKn5NdTlYlPTxtj1AHLVbY+ZMTRFNAIVz+ANWP8QEz2GG9vLCgrusqe7aijWE4b8U0RVZPboYB5jydxKfYiPtp 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: B/BurHhAnbxup1D7nPd6L2l/n/CJwaag8mxp5IsTY9Z7Mk3R+b4uBLJmpS//KM8HRBwVFqRuu0f7ih8lvGc4WAfCPoHhqoxKs42whUGcRP7B1ph1cZWn1rhaohy3q9IxCtqNiBK8WEvJ7SbQA7QOPWNszz+DoHYvnWCw2oH646LEigZ3ACHEH6Uex9qz8QaSRzmegzH6E/XA3iXaz6toSmPr+wJVY10S8que+r3tvxLGLk47zV6L/Rit1alZcF8abRQojd4914MNx3hQZknPi8jwiMwhrcSzH3dxnQBsqJ5n1xTkr5xy1mWiTNF3TH2iuVXCtHljNFMTQ9TliaeMc1tLpAjC0lP9iHtAodZteLSf6f1XJjn50v/coqCSGCmER5fkiTBDZyFT2lGi/RxLzes+NPE5ydtWyVqmDWpSM332NgXdW1Dr6TuCE9xYyML0zOGT2Lh+jBh1oR9zpLlh292hUQIEprGX3f9ellbp5lr27cPU7+JFvKpAF2sg+BiBt7jr9I6gD5G+c/ewFqTqabQaQYLQ0wI5bSb/MN6SlAOo8TgQ1sNxY4X5hOf4RXdtj64EC6aFDRGh68/NkKF0pXB3x6TATjfWTmhJpfZofuXyb4DCrvgidsO7XjYj935Stbw2IinC+WisRsA+aN8aog== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: afbe4503-7278-4822-1d18-08d83a6b7242 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:47:22.6921 (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: wzPw/rKHJKES+kHDAChxqOHFYrpK3rGqjbJzaFDuYpzn749mxiZRBYgzKq4vM1oC X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 b40ed18cb5c2..3c718caa3b99 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -988,11 +988,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); + set_intercept(svm, INTERCEPT_PF_VECTOR); + set_intercept(svm, INTERCEPT_UD_VECTOR); + set_intercept(svm, INTERCEPT_MC_VECTOR); + set_intercept(svm, INTERCEPT_AC_VECTOR); + set_intercept(svm, INTERCEPT_DB_VECTOR); /* * Guest access to VMware backdoor ports could legitimately * trigger #GP because of TSS I/O permission bitmap. @@ -1000,7 +1000,7 @@ static void init_vmcb(struct vcpu_svm *svm) * as VMware does. */ if (enable_vmware_backdoor) - set_exception_intercept(svm, INTERCEPT_GP_VECTOR); + set_intercept(svm, INTERCEPT_GP_VECTOR); set_intercept(svm, INTERCEPT_INTR); set_intercept(svm, INTERCEPT_NMI); @@ -1078,7 +1078,7 @@ static void init_vmcb(struct vcpu_svm *svm) /* Setup VMCB for Nested Paging */ control->nested_ctl |= SVM_NESTED_CTL_NP_ENABLE; clr_intercept(svm, INTERCEPT_INVLPG); - clr_exception_intercept(svm, INTERCEPT_PF_VECTOR); + clr_intercept(svm, INTERCEPT_PF_VECTOR); clr_intercept(svm, INTERCEPT_CR3_READ); clr_intercept(svm, INTERCEPT_CR3_WRITE); save->g_pat = svm->vcpu.arch.pat; @@ -1120,7 +1120,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); + clr_intercept(svm, INTERCEPT_UD_VECTOR); } mark_all_dirty(svm->vmcb); @@ -1631,11 +1631,11 @@ static void update_bp_intercept(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); - clr_exception_intercept(svm, INTERCEPT_BP_VECTOR); + 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); + set_intercept(svm, INTERCEPT_BP_VECTOR); } else vcpu->guest_debug = 0; } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 6c3f0e1c4555..c89ebaaa3be3 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -264,24 +264,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 set_intercept(struct vcpu_svm *svm, int bit) { struct vmcb *vmcb = get_host_vmcb(svm); From patchwork Fri Aug 7 00:47:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704595 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 B1876138C for ; Fri, 7 Aug 2020 00:47:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC0F222D01 for ; Fri, 7 Aug 2020 00:47:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="omFEPVcZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726900AbgHGArf (ORCPT ); Thu, 6 Aug 2020 20:47:35 -0400 Received: from mail-dm6nam12on2084.outbound.protection.outlook.com ([40.107.243.84]:14497 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726890AbgHGArd (ORCPT ); Thu, 6 Aug 2020 20:47:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gvL6Hq1ZE8XXf4+wAgQa3hF3QLtrkSiAYiD5D3gtMVPfvcKvnNEnd4JJaOcEyzV3ZnSJaDxHr5DEsMOnCc2WiCclkjyWPbT9IU5bF4D5pzvV+em/BOLK1S3ZIThtrxoBZSpNYFe3V44BdNXNeOH/G1xJXEk4bYy7p5UXlgpL0V9G5GCr7dq1Tma2M448Wws3zC50Zpb7gRATFG5HEix+KTD3Ws7G6l65IBTXAJE+RQCypIJOd9C2UDoJyEVf+SfIIjCeECFw4CJjIet2pfAQtCAQU7GW9H4ct/atNnfaKEjy3HOV8HpoV93v65WVeoEUN3hBVX95ESJxSrQQTkhPJA== 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=2JAO9IwuArf4iNlvGYie7oELfhsQUOp2WXm/dj6OfnE=; b=obt3XHUJAgc6+t/13bV3GiNCInZmu8f6BNddU5Ubs1XPmuO08cCbU9kVBW4RLqbPNo7MaF14kt5yggbIG+4q9GBuZR6Jvyu2zbJ1v6RAAyyw5GoJekmxFAa/ID1hRp4BUrYFEvDa4KwmpTUtGBA8vqvPDGNYct2NUw6VEqGSieavMKohKGLjlE8jvBG/xp87AAAaQA2egWfoN+xUrvIKuvSPs/5haHl+ErThM3WL+G16jTeSkic9Y5Vrf8AY3W4eW+TqONsWAJ3HkYDc1uxvHSyrAvt+ooSYzPJRP2Ae25I8f9HNzXkj/Wpr9vHmYF187HI8ml1ltihBc6FXMKoGlQ== 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=2JAO9IwuArf4iNlvGYie7oELfhsQUOp2WXm/dj6OfnE=; b=omFEPVcZ90dR5bFa9pzFpm7bM+5giEcccV3H0nOUqlhrS+jHkASzHAv/F9hHTBuqwQ3+rX8L6lDeNnwqrtKWHnfACkmhBnKNh2CguDQAmckTSQWyAdd61Wr+6OEc//8G3cbzMwOnEwt4ifE0NsFqJ285wFRWbOKmZOg/Ja0zFs0= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:47:29 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:47:29 +0000 Subject: [PATCH v4 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, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:47:27 -0500 Message-ID: <159676124786.12805.2925649566619758811.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN2PR01CA0084.prod.exchangelabs.com (2603:10b6:800::52) 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 SN2PR01CA0084.prod.exchangelabs.com (2603:10b6:800::52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 00:47:28 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b582a267-5ba5-4834-1cf3-08d83a6b7612 X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: pqoqLb8TIZGbZvVlkibggfJhTYERvf0wVvDLAVBZ35U7RaOJp+jcolJSITT1fh2WVh2J0ujdl19pK9VbqclnfAF1cQVBwjrO+qBP0M3BwuLJxSxt7T+mTEuNR3YnBUApVk0W+7SSUK9LZaAi5+WT99DE4k9UrQUIXoFOMLsNt024GWRB8SGO6PyTYVhBvNi7e5X9WE2KMlgkDY6Fgout9BY7YLT1MIo/MyEndwrXJzTHCyVl5N8zoeH0piJCmKWOMqApTi5q+px9nV6l06hLml4sgM7UOTZJ7DzpO0b2CELfyoW9KVxjpI/Mpjsaq5Cs 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: t1xg3c4BfAeXvSX4lmMmAuWzitBrqxXYbOVz8jw28utG/Yb4YbGRO5zEjH7G0ixpgqfxwTy46Pwk1l8YC8GoRU96ezRRbFulHkW8dy8DH7JwYTMHL9Q2swOcD9c4EvSx/qXBM5c0kC3iYSSjRVWQ26z9/jzLWXBZq5O6sYAG3rRi+3PgCw5zbTPBPAXUhHsI11x1ryNanSo3Xd0EToyOjzPrVZqRVJC4BQkUMQ9wstTbJOSUaSvlG777tYe0PtPEwsxPQjHcLI36lfFi9cc7ARfbgGIZBMm+FBV8i6HDTp4qjGNUGguyJrMnTfZZz4WuY0bLSiwPqIQjCoZV9cbIMGdAzndzmixVOUjb52kYCu8AnbZP8YVE+YF9IWP3TBnZKkfRVciS0LF64QkSMhSHTN7lNa6hSs14N+mtrkpxiiX+i7+giXlr6Ho0I/Wpn2kd/vMAgSbhVQFEIobh6RI8Lin0SgIhLIIYmBi4mfXaygxZo1e2yiYU7RGqhm3yS5Wi3rgLv0SqJc0FCBAY84LelA/2G+hVzVcKRalCcnxhHvBFXvzOU+cSUvuuo9/KE84LXkg+1fl6iXfAyTD6MN7eUTWrjKnYZaW3sKldQFel/HgORDTP5htE2FCpEclwAuhmA4nNdQtj36ZDqW5ksBeRwg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b582a267-5ba5-4834-1cf3-08d83a6b7612 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:47:29.2014 (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: r7l6P09MHePrPByys7ZQO0YkDymO2/UzLf9bcDuWqoP3yXSmQ8Xf5IGqk4SoeKmt X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 --- 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 d4a4cec034d0..32b7d9c07645 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4640,7 +4640,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; } @@ -4951,7 +4951,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); @@ -5024,7 +5024,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)); @@ -5190,7 +5190,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); } @@ -5244,7 +5244,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, @@ -5326,7 +5326,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_failValid(vcpu, diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 13745f2a5ecd..ff7920844702 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1597,33 +1597,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. @@ -5534,7 +5507,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 639798e4a6ca..adac99d9cbc8 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -353,8 +353,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 88c593f83b28..5806f606dd23 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10699,6 +10699,34 @@ u64 kvm_spec_ctrl_valid_bits(struct kvm_vcpu *vcpu) } EXPORT_SYMBOL_GPL(kvm_spec_ctrl_valid_bits); +/* + * 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 6eb62e97e59f..a8995806431d 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -365,5 +365,7 @@ void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu); void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu); u64 kvm_spec_ctrl_valid_bits(struct kvm_vcpu *vcpu); bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu); +int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r, + struct x86_exception *e); #endif From patchwork Fri Aug 7 00:47:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704597 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 45B4F138C for ; Fri, 7 Aug 2020 00:47:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43D5022CBB for ; Fri, 7 Aug 2020 00:47:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="A1qjkMfY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726925AbgHGArk (ORCPT ); Thu, 6 Aug 2020 20:47:40 -0400 Received: from mail-dm6nam12on2072.outbound.protection.outlook.com ([40.107.243.72]:41569 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726897AbgHGAri (ORCPT ); Thu, 6 Aug 2020 20:47:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FdEUvzbTj26WUSMlPVWi62mcdatjtL8qeIGUW67b7B9Gk62c5sAxAKAFVSdCLY4BSy4Ii/BS4iYpjE5YrLIhtvLaTg4V91x5o0BkAzEisv12I/e5GTon69LDOdGD/HN0fAZMWqnuiNrUgnP8Syc7N7PfpQbu4aMcrD1P1gq3yK8vtSw5a76FbrlJiEDxli9TfU5XN1mrO02c+dHGeLVCttX/KPv1O3kbcA/DoAOYq4WY2VmoBMRYqzn64anrpUneuDQDZHkC59yZfaNkACrUbD4Ke8RyKpndnAw6mtExoQnIz9zyRWOnkBfVVnR4N3BJ2BhIGeLlIfBrtipQlOXfvw== 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=PtVMDA17QHF58Sc1VHOQOPfkSjBakAfLYn119R2gy94=; b=nd/sD4jE2JkOJS0QwPZppbE37XmU8TENHxTJPVfeRNFGrQSpKFAIbw9njp8cg/5etw2xMM5hdzioz5jp8B3VzipB1wgx87fkSgF3KlpFWvx61USLOoIDvF9JMlceFyEtShM7vpZ212g4jAALvIjkI5x8Fz2heINP/5nuQRx2ajAUSP1+QGnhuaL3GLc/iLCga6HSKD79DhUdUIRUyefe7d6lUbQgs7sqL+Ll+wO0taiJYP3u/0SKNyj6QuWpLpT8tATYd5dLjT4G45HQv/pRLFzXi4fBRHMRrrdcvhQ1gj4KCn+HnjksKwHRyFvwy4zpscXeuPYCU8+sn9p4kTiAAw== 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=PtVMDA17QHF58Sc1VHOQOPfkSjBakAfLYn119R2gy94=; b=A1qjkMfYMeJ2WJh9h6v43rmG5nRjPqE28TRq+oIzJ2YYekrP8FfJeaWVnCshUspxNDMwV3TRdOWHvUfvVkxPc84UexQghYFnz1TW/iWQ6OEQ6nkdGMGLsfoqfJydIP5CONedrRD/NuwGUXJQhGetzASpMf4v8Q4QVwfTKDWJY4g= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:47:35 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:47:35 +0000 Subject: [PATCH v4 11/12] KVM: X86: Move handling of INVPCID types to x86 From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:47:34 -0500 Message-ID: <159676125434.12805.10237694695339928467.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN4PR0201CA0017.namprd02.prod.outlook.com (2603:10b6:803:2b::27) 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 SN4PR0201CA0017.namprd02.prod.outlook.com (2603:10b6:803:2b::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 00:47:34 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: dab1bbd3-c345-4e97-1cd4-08d83a6b79e2 X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: lf0SdhK1IPpR793PDLBfWN552Ff/PuDnKv53otHllYjtKxl651gQyU68sR1LYXGK9gaN3QYB1kTltl1sZyE4QrYULQ/OgZMkCsXFdIUECUUv1FpsYmlC1AS4c5GLTQ8MDHzlHKOtkTiKqPgnHPQOh9W1PQrkgmhjPV11BuBumOlnNRZiaemvjBD5m8X4WIWFfPuPZnWLttQgNxIXJ1sx+SJjQ7EtX8jgKymTSBgjBeHdPMb95G2eoBZfWeZoVjzDhgZHS0jrOTps6Pgz6kUKVYP0MzMpLi1cLYET0rSRJPnK/e9SF2sKiLXWj3AL3g7HTdZm2yEdz5qk2en7GZdd7w== 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ryC6bF8NhTjv2eObez4g+z5nbltwLX/tT+Lxm48gt50z9ckSWR0nzjJl/L9PCynLG3k1ktyOTmM9GXKeUSUzD40M7Yco2HkOBjU20Vl0U3EDq3Moth76xmqJ+2RMCc8a9LU2wQFoGsAYw7sRqUn1AZ3rF8xS0460BcWOKIYNGI9E6sSAi40+mBIScdDykcyfJGp2Nff9YMr/IQOocSl4oDSa7D9ujwgKnQm3IEDRSqpPBbN8dCRtUmjvg8wfpNKN4JmLnPifNfhiLIxa8+Kj67tmh03clcOmu9eEheaGpp78r2hT9mnijs98lFB7M+uZvVAC+TaN7Sfk0hevnObwjqpV12BAADRa0AtC87XWTtty7xswcjY7djcPGYNcQnTSaGtGdWjJXpBif3SIqvd5pzY2X6GWRG0Rujz4ZEJNDxGugXSLbe/BJnUSp9A+2p1HC3VdV5fjUbcCu83mtIetzCwEnwoyGC5D+xsb8km+Da6n8aVaSNquffR1bu7Lh3dzLGY4QUuMD/vezUaEmkHZvxNd3fTPhuTNkNI8BTumeHGQ+N+v3NOyr7Q4f45vH//z3C/vgio26BlB0R7IgYHoKxhqPIX2+FCP8mS8lKm18wELxlvso0BAWsD3i/QANy/O0UwwXVJDdXqsdMV7Hc/AVQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dab1bbd3-c345-4e97-1cd4-08d83a6b79e2 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:47:35.7636 (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: afeCjAXn8qiiLuIFSd8vGlj+H7VS2xVUQFwfdSkhZVmBQb5qYMu5mMsecUFQjwlZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 ff7920844702..02652edce9d1 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5473,16 +5473,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); @@ -5505,68 +5500,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 5806f606dd23..8dcd68058327 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -10727,6 +10728,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 a8995806431d..c6b728f1fed2 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -367,5 +367,6 @@ u64 kvm_spec_ctrl_valid_bits(struct kvm_vcpu *vcpu); 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); #endif From patchwork Fri Aug 7 00:47:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11704599 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 3B07F138C for ; Fri, 7 Aug 2020 00:47:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35D9122D04 for ; Fri, 7 Aug 2020 00:47:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="wRI/oGBR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726940AbgHGArs (ORCPT ); Thu, 6 Aug 2020 20:47:48 -0400 Received: from mail-dm6nam12on2046.outbound.protection.outlook.com ([40.107.243.46]:12897 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726933AbgHGArp (ORCPT ); Thu, 6 Aug 2020 20:47:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VBT4sgyve1ja0W9Mf9IgGNzdwfQZoiIz8wjgEuEH0NDkHpU0pQcakLw30Y8r1819m4US5gD/BjA+7Q7TrlhO4C5dxVMiQ6P2COWDETS1aj40fBQ4Qy6u65WzhvLqWjoPYYg5WVWxaLA0dOPh9LJbjuq6CgOQb2sv7AgFmnngBfbuDEQJxngR/vH32HNgqUBY6ivm5dd1GV3/jTnLESy/NV5xuyiIfKbI17S5sf0KSTwPihoveln6ZhQBs5B6yMCmFyR2A5is1DjDU+JF88UFE+O3hqQsaw/2695499GcDzS6kpQu5jb8XIz55NYET/bMnheWeA3R0POjf6PJ/LxRRw== 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=ZtemhJXG++vrCo084ayRfMhauo89lXnlsKI/xI4+f7Y=; b=OUGOaqHnkBQFMJrCu7nxKixfjAHeQAUwSI3zx90mVCakJEpnwuw+QgzEd06zcCeLWv+4r08CLi4zIUrZzvXMYv6aqYhBKayDDBvWt+gSvXGk12c6LcCVIxVzvAHO9PLg/yPi+vE4AREnBe4ww4ROV4Rbg+Lb/qrobChVr9jXr6DUbgddM3IXEzzZKeWEhf+AezepJzlbbtf7s6sXEBop2sviNKNMy9sLW3pjltUv4iVEiZlN4T2sQRQZOJfEA5dT/o+F0oAP31GRLu9hmS6ttBvjtDcw780aGd/0dsysR8Je6vcAhPJQfwGC+7jSpVTa5zMAgcOrGRLeDLWmmBALTA== 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=ZtemhJXG++vrCo084ayRfMhauo89lXnlsKI/xI4+f7Y=; b=wRI/oGBR1leYNCcEuQ745D/YT4Os0b52lCSyIWF8bie4FCEhk8JnCR4aD5660u51IGt+/cKn04+ZNst3UVHCKHe6dUCy6jertTvkE39ZdA9IvPIUeK6bKNRw/aZiAZ/dFRJHN4xaOz7nSG121WkrQaL+hlXtmVTu5MsJvLjcQro= 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 SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 00:47:42 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::691c:c75:7cc2:7f2c%6]) with mapi id 15.20.3239.023; Fri, 7 Aug 2020 00:47:42 +0000 Subject: [PATCH v4 12/12] KVM:SVM: Enable INVPCID feature on AMD From: Babu Moger To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, sean.j.christopherson@intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de Date: Thu, 06 Aug 2020 19:47:40 -0500 Message-ID: <159676126090.12805.5961438692882905158.stgit@bmoger-ubuntu> In-Reply-To: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> References: <159676101387.12805.18038347880482984693.stgit@bmoger-ubuntu> User-Agent: StGit/0.17.1-dirty X-ClientProxiedBy: SN4PR0801CA0009.namprd08.prod.outlook.com (2603:10b6:803:29::19) 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 SN4PR0801CA0009.namprd08.prod.outlook.com (2603:10b6:803:29::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 00:47:41 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b660ee9d-d818-4088-0e7d-08d83a6b7dc3 X-MS-TrafficTypeDiagnostic: SA0PR12MB4479: 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: 3lYaPpkStke8ozVIdwaCXs5F2FLKtlbzRwXsndweFAg9L1MgSVs5jvMC1Whw1k/BZEE2FU903mno9iq/mU3DgvQKBYV4apmXWwDIjb5JQRA7qIHrb+VWFlm62gBFK82/MM/uVUqsSd+6h0OB6ArDvb8+PiULv7RFPL1Ax5Ydatbv2JHOf7vCHG+sc5JSTQ5RyMUvRXFOFJQyYilqbSIVI/nlftFzvskXz95vPVkuCWhOC3m0HssSbgmZiUpfSBs7T2ow2dHq4YZlLo81F9uEIVYFcAF9d7NJIRTngbwnt3H0VQ/kMqnGppPB8mwbWE5SBM4hV2bBxwtgKFCdbf+9otQr+r4gjV7bri4OnwvHdkhyANUVBi9JVA7mbi+nU6vVeF9E5tkDjF+B/Vort2/6gQ== 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;SFTY:;SFS:(4636009)(7916004)(39860400002)(396003)(376002)(346002)(136003)(366004)(5660300002)(6486002)(52116002)(2906002)(16576012)(4326008)(83380400001)(7416002)(956004)(44832011)(33716001)(26005)(9686003)(8676002)(966005)(66476007)(66556008)(103116003)(66946007)(8936002)(86362001)(16526019)(186003)(478600001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: gJctfP2enpbrkVw3I6/7JQX8Gq7H4FdSpCmFjJWvKNXTTQqyIYL7NGoYepdEGwViIBv/1LmOyi0qWipNo8em3ZVb3gKweGYBFT3kqeNJO7JcbP+hFC83+M8m9OJ/idfd7+sVcdi0IzdnXc5hpJkj+dHEbG1lNpCJfBd5VQUcpfamxVIO3NwGiE6m/qHk/gWy9mAdB0VPfWYXI+YSkgiKiDGb2Ha0iM4m/xJq65S88Q/XcSTK+j3owLok+fMwYOK7b2WACPTIXnX6Cj7UQdWCB2sbTZnD0MvTXy+1Wz0E29WRtyTIt+gihBHh3rff+RuU4tQN8WFQAfyKCmFp1oVi1hclIxTTxXw+bJxdVJdsFC9Ru6BNZHR+GM6TPXTSmRLJgkCHRfe79wIFdV0UvhzbJ84HSNq+bmV9WQjlfVT1OpxVnThL1LNUsx7Qt4CmWiRtmBLwvb3WyWb58yd29Sowo1c+NtwHaV+XdhfgrN9KeCePHD4b7IEZ5VRY+m3Xe73kqy/8c4wIDbuK/aCnjx2tpKIk4miFpg0rEMmk4fq4ZMT6BO+EwFJfPYJgxd5IxPX6y4ln4qRF7OCFo2RlO+LAKkgbvt58l4tnQuCiHT5oomyajDJCQbwVaMOFy+n2hAkQaWxkDeu/LvYMA4wax46DVA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b660ee9d-d818-4088-0e7d-08d83a6b7dc3 X-MS-Exchange-CrossTenant-AuthSource: SN1PR12MB2560.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 00:47:42.0741 (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: +43hnExN+6VM4IOOepB0bfI7wm2Mhx4Vzf5E3yYRvgM1qWThMU+4hhdfsubsWPMe X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 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 3c718caa3b99..053dfd00efa1 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) @@ -970,6 +973,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) + set_intercept(svm, INTERCEPT_INVPCID); + else + clr_intercept(svm, INTERCEPT_INVPCID); + } +} + static void init_vmcb(struct vcpu_svm *svm) { struct vmcb_control_area *control = &svm->vmcb->control; @@ -1099,6 +1117,8 @@ static void init_vmcb(struct vcpu_svm *svm) clr_intercept(svm, INTERCEPT_PAUSE); } + svm_check_invpcid(svm); + if (kvm_vcpu_apicv_active(&svm->vcpu)) avic_init_vmcb(svm); @@ -2714,6 +2734,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, @@ -2776,6 +2823,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, @@ -3561,6 +3609,9 @@ static void svm_cpuid_update(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;