Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp1448336rwj; Sun, 30 Oct 2022 00:32:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Ie1s1LMgGtXbqxgHB1Os28MOq+2P5Hoa+1jNI1Thflk8ViAoS30d6j0Qt+G+6SNyUSYyb X-Received: by 2002:a17:90b:3505:b0:20d:2c35:9834 with SMTP id ls5-20020a17090b350500b0020d2c359834mr8471992pjb.122.1667115129419; Sun, 30 Oct 2022 00:32:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667115129; cv=none; d=google.com; s=arc-20160816; b=BOiaCmgzwrg2I1KeeLTVJVoJ4l7l76FmQm/TE9nZdPoilHQJH5qXBNyjUaCTuAR/3t o43xpJbdIZQgQoXsYOsmc6vxmZwCsrfJVj/CrUc0J3rMHZvf3+LUdjmTHBVAPz38peae TkYtQTfIdCatT0Zt27pfYhBAQ52U4R9/ACBnXkQ4IxwfYgrK6W0ErL1hxKKfOJmQLH9h el+EDSXjhtaMCAWicBM6lYUhKeyCuT7+Snh+cqNhd+x1aUijUlsr6Jga3R8bXd82B/fW FkSptwmJDdluXtQd3+0NqXXBq8QMrmk2WmZgdOx7van6xqEfZptYORORD2g3hRWy7HMr DsnA== 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=Chq0J6ZS7N54dVQB0feSxO9NZVXC6078nDa3DN0lLsw=; b=judv8aSqO2/W+mryBPVUsytUVJTLhNY9DkpRuvskkcxKpTZDjQzaMLRlbvLYMbHwKB kqRPQXQ3J9NZM+cNXmd3FDScJP3+kmGaxwCVkSwTPEWJ1KP8cszS+U/dh4TfEZ0PiVEe dERkiu6xCIU1abFY9OJUAzblgjRZ+/sUuA3ndjeZnBL2dXeh/ZfFbjyWV7fWQWEY7b1E vvhN5mbnU7bvn6J3Jm1d0qd3kdK10AxQfFM/eNLHy75K068MkLNhtfVB3q8iVY46x/q2 EACoSFE3wOX8i86KRA0L1M+r62Qg8LiPrityiR3L3efE/TzmpkaWQI9cRpHlPJPjFXY+ nE7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h70NMDf2; 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 z10-20020a17090acb0a00b0020ad8a730dbsi3796402pjt.58.2022.10.30.00.31.57; Sun, 30 Oct 2022 00:32:09 -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=h70NMDf2; 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 S231171AbiJ3GcC (ORCPT + 99 others); Sun, 30 Oct 2022 02:32:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231321AbiJ3Ga2 (ORCPT ); Sun, 30 Oct 2022 02:30:28 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E54FB0A; Sat, 29 Oct 2022 23:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667111093; x=1698647093; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SVVFPTYiF9KYWEo+FXLY2P2CyEXga1RHRMRYTXfVETU=; b=h70NMDf2z8z5+VThR5w0zANIaocnyNUR0+wLyWJtmO1Xp6QsCVsDKRwu JRe1RRf1wRGDG2VZg9WVzBFaHlgGoViVDO8weiZ7Jn6MojdmAR9k1qd4J DeMD60yFHh8hbzX6IFxONzVKNrMRshDI8rVBh2PyuQEq1GPF5XHZ7OAI4 lxuqZ5t+khOtPNWsvpXqskCa8VirEzVJRjcITetTpudpGaupnlv/FNj0K gkQxbTa8u10regbr1v5eU8SuHH+hYGAW7zSDFe+Br/PUdVNOe8I2gdz6U fieS9pRJVOv5qbKElD0VWkxDUiBryeNTbxx+GGqR/lug1ACfMHC0Vg7dy Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="395037199" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="395037199" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:11 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="878393119" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="878393119" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:11 -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 , Sean Christopherson Subject: [PATCH v10 086/108] KVM: x86: Split core of hypercall emulation to helper function Date: Sat, 29 Oct 2022 23:23:27 -0700 Message-Id: <906a188cbc382ff2d26954984b72d6e0f617382b.1667110240.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.9 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 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 70549018987d..094fff5414e1 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2004,6 +2004,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 ad7b227b68dd..fad5108dff1e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9684,26 +9684,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; @@ -9712,11 +9701,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) { @@ -9775,6 +9759,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