Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2687907rwd; Sun, 28 May 2023 22:14:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47rLB6MJ1sTHgDr4XIRDnvpuFGbeM7dzU2BfyEu1LUF/Wbwl4fprCNDYSlGpdeXF+octF6 X-Received: by 2002:a17:902:9b91:b0:1a9:21bc:65f8 with SMTP id y17-20020a1709029b9100b001a921bc65f8mr8464961plp.11.1685337269914; Sun, 28 May 2023 22:14:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685337269; cv=none; d=google.com; s=arc-20160816; b=fl3heT2wyOqQmFjBAmEnEbJip7AbzJcEhlJuc064PgxP8XJ6T0Lf/+rlLQkFaNqGPe XR7Dd9W5nb2JB1nAMhfydlvY+p5oFJzZOp2ZRY5UHDTVpBgXjGjck0uEB9QECt0ULGid O7JAT7np3cY33QTw1+K02d+t399JTkaokY+yTuS6AlxdA8N2+H+nBvYsSLQH6kf6gtVX gqjJSLFpfkYVNFyD9BOQVzyXf/5+ke/UTrJyKwgwS1rG3g7VIFeF0AGCOKrnn63mA6IU tJIgMrIXvLUoo2escHfMDzqftFL2scTyLT5nTI4iUxs+zMftLGO2g1qBUlHnNMkIoL0n IbZA== 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=58ZBEx5GPdccV7lF5p9TRUE6Vkwh/nrJx1WbI8F+a4s=; b=qhMYmYeCX8tnjdo55UEVR22GNSQTpKBmTeHS1o8Z5mt5S6hbSva3/liEwSBUwGtEpm oL/6F5bDXqBKm0+LXP7uTb2xavGmjRVTjP/a1hz5E4xK/NOX/uKiR9UwCK+f94Mw8gsM VFkSukigl42iIwIoeGTKpFL/dznnWUojl908kbwobl4LWEz2ouRUdPQdvBYR+WijQnnj I0nk3Uaz706P0vk8T7VXhLpCOLI8rcp4sb5klcNLc45iqE5lItexPu1mzOrqPBXObnrg zC/QqRqUNwUfp3xqFe4pTOzvptUByXk+3LOjtPwcWuruPbdOfRMf4lJp/Ln/z37VJP4v Mz/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HR5sARys; 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 e7-20020a170902744700b001ac939babd7si3349771plt.507.2023.05.28.22.14.18; Sun, 28 May 2023 22:14:29 -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=HR5sARys; 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 S232377AbjE2Eec (ORCPT + 99 others); Mon, 29 May 2023 00:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231463AbjE2E3p (ORCPT ); Mon, 29 May 2023 00:29:45 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27AEB1BC2; Sun, 28 May 2023 21:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334344; x=1716870344; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T8E6G+p7vlXbPEqpZL2A+lvcw3k2toz2ujK7va7nN8M=; b=HR5sARysFfhtpGnl9jT97rycKFTJfEN8HDokREHk4UkmCwdvcNsUHcix Szt6CPuyQ1neoYbNIw63ECQboq/AlGZuM4fO3hAlGLygPFF/8tgKGGY/S bK9YCwD8Onu8GiKx1TTXfvj9tObWQq+3jEFzEah+r30dfqhOFwEhZV0F+ ooV9k8AVtinJWCxDQ3Ys0vm19rdJ21PlWYSwi3yDnacgbXjpwftLjthFG H0GmciN00J1WzI6qjwpIq8fEzMBSX+j5bnDuPfcdGidTRhZEbTNoyQKf2 ukj5W8pPHOwbO5y7IQXF6ITEeJaGhg4EcaHWx32m5Tfd8+zEF5+tO6gF/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="334966239" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="334966239" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="775784512" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="775784512" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:34 -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, Sean Christopherson Subject: [PATCH v14 082/113] KVM: x86: Split core of hypercall emulation to helper function Date: Sun, 28 May 2023 21:20:04 -0700 Message-Id: <7975cfc1f537284b4abb48fc76750289146d79f8.1685333728.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.6 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 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 0380581c5570..5fe1ebc6ce0b 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2110,6 +2110,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 1550e15b9049..1e166749869f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9821,26 +9821,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; @@ -9849,11 +9838,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) { @@ -9916,6 +9900,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