From patchwork Thu Dec 10 17:09:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 11965805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E60C5C4167B for ; Thu, 10 Dec 2020 17:50:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87DDB23E1D for ; Thu, 10 Dec 2020 17:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392555AbgLJRNo (ORCPT ); Thu, 10 Dec 2020 12:13:44 -0500 Received: from mail-bn8nam11on2059.outbound.protection.outlook.com ([40.107.236.59]:9021 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2392489AbgLJRNc (ORCPT ); Thu, 10 Dec 2020 12:13:32 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qek+XS/7pdg0pgT04Ql7dVDEwxvwxXTu/N0TTR+T4cHrFdDevyjCSx9sh8mTqTeYalUekkc6Wy7B/CMm3iqRvExEorhMTtKbUsWvZjLurtQFLEsxLgm13FERxr4srQZ4t6gepFvJhkUkUd2OHQ/Fli9a0+uSltAevDuY5BDJ5M5MezN+9RINFuve2F6T5w7skL3ovMbuVWqKS9Hm95HiTC4Ue7nOtZmPcsncN9I1LZVbKifHdCMV8iGsvsI9kwtT2uWWhepRJA4sexpWYu+KNVv80vCrtydr7Z4421j6Em+y57LrUrOHwIJsX7tFPaVE1zAgY9AHuZIkf+nS5k1Vqg== 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=8CmqtN4gBaYiDKhaGn4hwAyhEc/1DYcFY65MrkQf+5I=; b=g1JHLk3kIe3X4bhAbbEZBiDgJotGjaczhfAGgx1HTXsfkZzoAkhWizTxfyM5kVMxKAWkqfJM1lMOvRIAtKDvdFW+HQTnESdpZd+MetXS40Cpsw6c7OLZRlYaVbA2nEGBGY5QN2E1368n62R5wVMiiPWwcrfSk3dvsiCYjWGOLKYP+gFf/Ah+GK1IYJ0Vyc/34yNh1Rc1F99cfWwIA37F4qc4d4xTW51Qmr6qXalzH4+3aBHyLwM8MEB9oL2W59JpaVa/tzGXUYLmZGeIG+u8YpTlhz9N78pYhTuY5/Lw2NWrRzhom2VMcFVHlPsThct4vrUYGh83JGAwtoqLkpW03w== 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=8CmqtN4gBaYiDKhaGn4hwAyhEc/1DYcFY65MrkQf+5I=; b=g5szKvevR5Aiv06odTccjv6Qs+LLWp9nczMS+mIJUCBIi2Y0/+QhuOF2/N9qCqcAPRIDVLWy1TQjGth/LggFAIaMMxiTqIiNtaUqFN7NG5XvUDaWLGt4qoQBRSgtzw6fH/pl5qzS1Gpkj2hemq7w5IlYTt7enVWASzt3Tp8yaqo= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR1201MB0149.namprd12.prod.outlook.com (2603:10b6:910:1c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12; Thu, 10 Dec 2020 17:11:55 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::a10a:295e:908d:550d]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::a10a:295e:908d:550d%8]) with mapi id 15.20.3632.021; Thu, 10 Dec 2020 17:11:55 +0000 From: Tom Lendacky To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: Paolo Bonzini , Jim Mattson , Joerg Roedel , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Borislav Petkov , Ingo Molnar , Thomas Gleixner , Brijesh Singh Subject: [PATCH v5 11/34] KVM: SVM: Prepare for SEV-ES exit handling in the sev.c file Date: Thu, 10 Dec 2020 11:09:46 -0600 Message-Id: <5b8b0ffca8137f3e1e257f83df9f5c881c8a96a3.1607620209.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CH2PR14CA0009.namprd14.prod.outlook.com (2603:10b6:610:60::19) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by CH2PR14CA0009.namprd14.prod.outlook.com (2603:10b6:610:60::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Thu, 10 Dec 2020 17:11:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 06d0c3e1-0283-4f7f-1676-08d89d2eb239 X-MS-TrafficTypeDiagnostic: CY4PR1201MB0149: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D18yWKl2Dv+C0zqpiP7lN7rsLFnYiElCTiuTQ6nq6bfLtc+uWXIGo0KWWOkwY6TKfRq/Qf7kXL39YzQPuEJkuby+3IB4cMG9qS6SSEOpWJif9RNeq7Ae9xgLs69jeMlOGNAohdyb4SvDBjxb+wq6z9Y72PnXM4ukw+LbF1vMUnxsgUSWtDG2+BWtTs1imnTpAfArdb0eVPA609cR1oSRRThnuqejn3/Kxcd/Jh6tj1QOCsbL3yNpWwYTZBdzXQyd+CLLkevyHhHggOakLf+wIRgE/Gu54KBlewYlDaePHoe+j5BrRXfhC0+7iOSm1B5m6CFoxFLhbzQtVk0Axa1pWET+Bs3RkSA8yvEBXm978xLW+vgh1WwGJ5dFw77Y6IXc X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(346002)(376002)(366004)(2906002)(5660300002)(6666004)(26005)(52116002)(186003)(83380400001)(16526019)(54906003)(6486002)(956004)(2616005)(8936002)(7696005)(508600001)(66946007)(66476007)(36756003)(8676002)(86362001)(34490700003)(4326008)(7416002)(66556008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0AnR5bse5+04dFzo4qxxL0/LHzhBmiqYsEkq/pbAkTO6POdjkWOid+EQ+WmGwhjdxWV1diT6kYk/OoEJYB0ml4wY8GnClSi/scQnz7DzJjNBsxIFrSCRLRJfPFiaPr8tzpACACQa7JSqxGVKG9z1oSOao+K8d14meo3hLAwm5nEHhaPbOHwZZLUIxunAPsT56MfX5KvM+LPRKDAqUfpMQZoUPv2lNTtV6xbcBpiLvPJ61VHCp0oc9Zv53mYgfmJp1MDDMSIoFCqbE/0NO4A3UkMoLCYXJvnXyFjYP9i59pMfA8OBhuP+vT4GdFFjW93ItV/ZawfCFbPB80Ww6zlrBTf8ElV2NXUCvOdcH07QcotwgaXNQHgAeNqnZ81D5XCLj6o89THeGEOoz/9xgvSrQjiy7rFeU0OcSdCOlRyJY2AIVHEv/MWXDlmlzvc2ld3BWOtW9eV2epnlaqKdH6oqUqNfM4o2HDd6+NtT/m2qlq/1xxhiczF9zSqwhqZRk2RPO6Oc4tKLc1BWA8jN6gdze3UAhz+b/Qb6k3z0dBOepbU5k/FDdT1ZdfZJARigG2QLEboxspKHRueMzsQTaa8rxUv0xnzcn+VPfB+hXatUAYfWpRUhmsITzYq2x/mm0Xd13vmd4X9UEXJoThXDQ15D0J17rUQu1GIG8i05IulPaZrRw1fbCvTQcawDXcDQ12mCFHVe/KUKJmKZUilaFEBqnULB6dNevywNJ5nzdpeOh5lw/gs/a0TIxltxl/TyQ66ZJQOTAyYQPY/iHpzH2TfJtb7OYhvFL+dXqg6GBx5P6o3DPTrSq5i/Ua3oVkVxVZtsre+XqRrYSyebsO/BAbhaVaiV+0oEZUm61q35aARjSX+bonkaezqHeqyML8y6HfUg7uqPNdNyLSlBXJ+rj63y8dr+qb85iVliiLj81vQj7KUOCtxgQke/jeLSO+qrJaM8iL3DzGiPPcPsyVp2ndUX/glXKiKwKfJN+i1Hsua5yz+QNmt8A24r5+JKNXtYsowu X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2020 17:11:55.6017 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 06d0c3e1-0283-4f7f-1676-08d89d2eb239 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WUeKvcRild/cLPDI8LJg3ZURo9NgsN5RICn22nmtlP8RIL2n18xKjzjxfPd63+cMKEMrhMqfIzvtHFcRGNkegA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0149 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Tom Lendacky This is a pre-patch to consolidate some exit handling code into callable functions. Follow-on patches for SEV-ES exit handling will then be able to use them from the sev.c file. Signed-off-by: Tom Lendacky --- arch/x86/kvm/svm/svm.c | 64 +++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 3b02620ba9a9..ce7bcb9cf90c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3151,6 +3151,43 @@ static void dump_vmcb(struct kvm_vcpu *vcpu) "excp_to:", save->last_excp_to); } +static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code) +{ + if (exit_code < ARRAY_SIZE(svm_exit_handlers) && + svm_exit_handlers[exit_code]) + return 0; + + vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%llx\n", exit_code); + dump_vmcb(vcpu); + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON; + vcpu->run->internal.ndata = 2; + vcpu->run->internal.data[0] = exit_code; + vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu; + + return -EINVAL; +} + +static int svm_invoke_exit_handler(struct vcpu_svm *svm, u64 exit_code) +{ + if (svm_handle_invalid_exit(&svm->vcpu, exit_code)) + return 0; + +#ifdef CONFIG_RETPOLINE + if (exit_code == SVM_EXIT_MSR) + return msr_interception(svm); + else if (exit_code == SVM_EXIT_VINTR) + return interrupt_window_interception(svm); + else if (exit_code == SVM_EXIT_INTR) + return intr_interception(svm); + else if (exit_code == SVM_EXIT_HLT) + return halt_interception(svm); + else if (exit_code == SVM_EXIT_NPF) + return npf_interception(svm); +#endif + return svm_exit_handlers[exit_code](svm); +} + static void svm_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2, u32 *intr_info, u32 *error_code) { @@ -3217,32 +3254,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) if (exit_fastpath != EXIT_FASTPATH_NONE) return 1; - if (exit_code >= ARRAY_SIZE(svm_exit_handlers) - || !svm_exit_handlers[exit_code]) { - vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%x\n", exit_code); - dump_vmcb(vcpu); - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = - KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON; - vcpu->run->internal.ndata = 2; - vcpu->run->internal.data[0] = exit_code; - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu; - return 0; - } - -#ifdef CONFIG_RETPOLINE - if (exit_code == SVM_EXIT_MSR) - return msr_interception(svm); - else if (exit_code == SVM_EXIT_VINTR) - return interrupt_window_interception(svm); - else if (exit_code == SVM_EXIT_INTR) - return intr_interception(svm); - else if (exit_code == SVM_EXIT_HLT) - return halt_interception(svm); - else if (exit_code == SVM_EXIT_NPF) - return npf_interception(svm); -#endif - return svm_exit_handlers[exit_code](svm); + return svm_invoke_exit_handler(svm, exit_code); } static void reload_tss(struct kvm_vcpu *vcpu)