Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp334777rwb; Tue, 25 Jul 2023 16:57:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlEqKG7e0TjgcSqRnbEgpXJfMMzwSi6y/b2q1Oxupt8lI5EBJNPV0VA/OLIzKT7uKCELRlmV X-Received: by 2002:aa7:d883:0:b0:522:2782:537 with SMTP id u3-20020aa7d883000000b0052227820537mr284994edq.15.1690329465864; Tue, 25 Jul 2023 16:57:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690329465; cv=none; d=google.com; s=arc-20160816; b=wKis+DUopTRuLNmjR2LsG5RfHa9Xv60heaWzyzBR+QICmEsH3l0vW0QBjWm3YvIodt Z8+tcsLrX8v14JSuOAuueviptZDX12g5QTFZEPP31eSJ3eitNsyc33GcATXWVhyf1Rms WgNdgDSmmRXG/2CBzcuDZXNfLskLP0fTWI5M5GBXv5JVTXz1iIFPlky0m3exii40ErKE 3wwbCteL1Tu6n54y1HSQfSvXn4pP4M3lFspaZxqgk2zfhe0B83dli2ADg5TCqfbTXGSr o1Jr6s5jlhoYs5pByNvgQIhv+r6mAlcgM3lXmueZiW0hNlHyaUymrnEzDlbBq1Mv2JQG 7T6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9ofgpW0A06BWV9fBMR0Q+S/Cl6B2yvT1+gesyhklFXY=; fh=aHvdLX1Pa61KvQFmeZODM982ht845x7CZ22gIB9kxIo=; b=sqZQZNAqsaK5u1iosN15vShaDZzjWWBIwlCErGsX4VRKZfPRbEd/mwsNz1650c6tGD DLGZAHAM5e4Ma3cPDlYNax41sGvAvBxnYkL9QaxjmH5+wtcqmJPJxfASKLHU0RoOQFft MvlPsfOK9FAsRbVX92MDKjUjtswjMC/OopMAtzLqPZzBjIX2dcwhHRN+6ZTOp9zy4wAl tAU2kZ31/RhKdXCiXACHG5TU+rzyq8kOL6hSAbeSopVodbyDuEV0UzudThDAEcH7hSDp 70Gs672kHj44DQqEUef5v0uuPCCoFpXOifZxSQDna6M/YUVbY4KnT6r6iKLjIcGU7W/W CpNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YYhgVvGL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x21-20020aa7dad5000000b00522467311e0si2047744eds.634.2023.07.25.16.57.21; Tue, 25 Jul 2023 16:57:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YYhgVvGL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232537AbjGYWYU (ORCPT + 99 others); Tue, 25 Jul 2023 18:24:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbjGYWWA (ORCPT ); Tue, 25 Jul 2023 18:22:00 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1080C4C20; Tue, 25 Jul 2023 15:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323458; x=1721859458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yffpgCm1vzGyx4bV+WRMVxatCK4JGCBdo5kYG+oAprc=; b=YYhgVvGLzSnmO43G9wlNQ4CI/4BxYlMTHyGDOre781JHaUOygeaSTp/K xiU0B8pzhwuB5p13pGHi0rracTxXg0uphpQjzRZDJ+6AeSVF7jrsMKZ4S zlqF9Fvx5nuNUej0rmR+L9LcK6FnFO0JbBoXuvueMvKRPazMxeb2m1ZJW 2cCMB4WJbxCwdPedbovs+fJM/vB9KdCdQT4m/KakEEXMkwIkRZBgldzFs Ek4bUqMukjfT1fofSWm6kifLvEa4kt4wQ4TEoVGPaeDr41sLwmXYE7xG0 KqE5hU9meOdhYpBWHB8q2+utpbQWKuPYr/sEFj/rhnX1CsE42W2MI7aeN g==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="367882650" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="367882650" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="840001861" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="840001861" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:58 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Sean Christopherson Subject: [PATCH v15 082/115] KVM: x86: Split core of hypercall emulation to helper function Date: Tue, 25 Jul 2023 15:14:33 -0700 Message-Id: <74e951ee3015699c76c66210d6152ebdbb0ad48c.1690322424.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson By necessity, TDX will use a different register ABI for hypercalls. Break out the core functionality so that it may be reused for TDX. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm_host.h | 4 +++ arch/x86/kvm/x86.c | 54 ++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 8bd2d7df15f9..c58ceded3437 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2118,6 +2118,10 @@ static inline void kvm_clear_apicv_inhibit(struct kvm *kvm, kvm_set_or_clear_apicv_inhibit(kvm, reason, false); } +unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr, + unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, + int op_64_bit); int kvm_emulate_hypercall(struct kvm_vcpu *vcpu); int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 error_code, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c7d34b04ccdf..747cc86c60dc 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9838,26 +9838,15 @@ static int complete_hypercall_exit(struct kvm_vcpu *vcpu) return kvm_skip_emulated_instruction(vcpu); } -int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) +unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr, + unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, + int op_64_bit) { - unsigned long nr, a0, a1, a2, a3, ret; - int op_64_bit; - - if (kvm_xen_hypercall_enabled(vcpu->kvm)) - return kvm_xen_hypercall(vcpu); - - if (kvm_hv_hypercall_enabled(vcpu)) - return kvm_hv_hypercall(vcpu); - - nr = kvm_rax_read(vcpu); - a0 = kvm_rbx_read(vcpu); - a1 = kvm_rcx_read(vcpu); - a2 = kvm_rdx_read(vcpu); - a3 = kvm_rsi_read(vcpu); + unsigned long ret; trace_kvm_hypercall(nr, a0, a1, a2, a3); - op_64_bit = is_64_bit_hypercall(vcpu); if (!op_64_bit) { nr &= 0xFFFFFFFF; a0 &= 0xFFFFFFFF; @@ -9866,11 +9855,6 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) a3 &= 0xFFFFFFFF; } - if (static_call(kvm_x86_get_cpl)(vcpu) != 0) { - ret = -KVM_EPERM; - goto out; - } - ret = -KVM_ENOSYS; switch (nr) { @@ -9933,6 +9917,34 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) ret = -KVM_ENOSYS; break; } + return ret; +} +EXPORT_SYMBOL_GPL(__kvm_emulate_hypercall); + +int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) +{ + unsigned long nr, a0, a1, a2, a3, ret; + int op_64_bit; + + if (kvm_xen_hypercall_enabled(vcpu->kvm)) + return kvm_xen_hypercall(vcpu); + + if (kvm_hv_hypercall_enabled(vcpu)) + return kvm_hv_hypercall(vcpu); + + nr = kvm_rax_read(vcpu); + a0 = kvm_rbx_read(vcpu); + a1 = kvm_rcx_read(vcpu); + a2 = kvm_rdx_read(vcpu); + a3 = kvm_rsi_read(vcpu); + op_64_bit = is_64_bit_hypercall(vcpu); + + if (static_call(kvm_x86_get_cpl)(vcpu) != 0) { + ret = -KVM_EPERM; + goto out; + } + + ret = __kvm_emulate_hypercall(vcpu, nr, a0, a1, a2, a3, op_64_bit); out: if (!op_64_bit) ret = (u32)ret; -- 2.25.1