Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4694521iob; Sun, 8 May 2022 22:16:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIgPaDsRkNXFUR4YzTHDXRkDrahT99ceiNP7eupf7D0hvjYueI1bcEjE82MgVls3SFyWDW X-Received: by 2002:aa7:84d1:0:b0:510:8796:4f38 with SMTP id x17-20020aa784d1000000b0051087964f38mr12137101pfn.8.1652073407907; Sun, 08 May 2022 22:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652073407; cv=none; d=google.com; s=arc-20160816; b=sAso01OJL0Rc8C6t7311YaOoCQAYhJm4LC/9oqSctUZIy5520DGyVy4NeFp+/0ztY8 JAOlx8BGAegScnyix7C5rjGfV0oq+ncWtSJT2p8NfmmFJslQkCl4Jpufale3CP6xbZxf 0VDr120UOeLKiG856X8LqsytTle1KbKqMWrFnKUFvF7CbCEMe+6RU6s8jVJzRdu41l9S di1bEYnMDsz2bF/N7dzbYjAaBuMBY7nl/M3jhFwdgcJomxwLBCslgxAm5Ux8lB0EMR5f q1L19DoQ5unrF7b9B73e+6akkqdW6sXtlGcWQrZ4pOy7TOjymrz/rnsdduyzaWScvg1t pDcg== 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=BfzKEeZ6VPiAEIuwHgjx3l6azrYFIBY9cpNnZfD28vY=; b=kLW5m5z5+vSdIhD/UzPA+sedxCJoSFCAjgZHj+7MsHS0k/mWwhBOpY/B1Thdg5cWQi +xwGlJdpab5/onoTjGsckSX2vagBJPLOjt1wQMgd9j6Jbg4BWNh/tz0+L2xOQ7mrMjVV 5v0q8TLhiom7oCMHTMMXh1/b5CI87LLViW8xS6ifUotspvPSzF0vU4/r5a2EXHTqv8zH Xkx0qbdL2PeRFkoUFz7XQURGEupL7KsvqAMsvNjCl9ryr20QOesockvlvIGwdDfPYyhG ijuLSQYGxUsJBiq3Qlmt+D3iouprOl2SKn/1eTI9BqwALAosfoSMHRPZJNSoE6O9T68j rvhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fziwpUtw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id lx10-20020a17090b4b0a00b001d27a7d1737si17097477pjb.1.2022.05.08.22.16.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 22:16:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fziwpUtw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA9C7FE20C; Sun, 8 May 2022 22:12:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383949AbiEESXd (ORCPT + 99 others); Thu, 5 May 2022 14:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383282AbiEESTo (ORCPT ); Thu, 5 May 2022 14:19:44 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2297E5DA7C; Thu, 5 May 2022 11:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651774559; x=1683310559; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cixCPEKKpzvmyK7DHYTRav82CT9isuogv5cupV3KuZM=; b=fziwpUtwaZKF5G4as7bNB4GyI78vDX+SjYVmVkLBui6JN7pwNnbJPNQ1 xPrCCAlXu0f+iYQhQxJNHv7o1XUGFMEHnUYER41hMCjiwhAvNYUlSJdPH S2HuVRc85D0+6H5cjwVC1xjKNib8HRk+kdEaNPRrX/xspyCAYwKyeW4dB 3IOpLAyUNTI02Y26KpFOwuxxobfUsZXnt2jCVyCxIrgztnrWE/NDm2EN4 Vy0Nns/DRVDAeep0rSFF+Tuly/P2P/wxR8vMGt0Y4pjrw9hln0XWOBgXh lFcy2g0oYDosS7ZGfd6UVFXLMFn5xgyITCRSbOskXwoRjlzCO5gFin1vj A==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="248113929" X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="248113929" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:53 -0700 X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="665083440" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:53 -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 Subject: [RFC PATCH v6 083/104] KVM: x86: Split core of hypercall emulation to helper function Date: Thu, 5 May 2022 11:15:17 -0700 Message-Id: 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=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 d6dce57fe0eb..f67fe33e6661 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1867,6 +1867,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 2691abb46fac..5f291470a6f6 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9259,26 +9259,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; @@ -9287,11 +9276,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) { @@ -9350,6 +9334,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