Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3462966rwb; Fri, 30 Sep 2022 04:06:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7wt5Zgl3miynqny9LnISQ5aUl8gRU7WlBT4NK0uKxOm21ihGPPC0n4esVBiLB921SYeAci X-Received: by 2002:a05:6402:3988:b0:44e:6f08:ddfb with SMTP id fk8-20020a056402398800b0044e6f08ddfbmr7185769edb.89.1664535970453; Fri, 30 Sep 2022 04:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664535970; cv=none; d=google.com; s=arc-20160816; b=AO7IE6s/7oQg3isH+BiEcKNpabXDYrWszPTsgZmT5McPx4Awelu4psg6rAzUM+4eO0 kdl4FKwLV2tNM22o8PMaOlbfjHQ3OFpSlmOfLOUecRoYxWMWw8HRgsnRk+6Um5maVWu3 NVZarCUlRRTVo3mmj8ET8uDAyHa/u2x/wjWEEqkEwY+M/2EU3ubQFQN6ALpPzFfwW6Uf 0Vc+xPx2SyJb9qA7d9RXxjT8ItUW2LXxNgNw7jjiqm+H6a1OBanizZTpO/4870z6NFWD wGmMbE/GtbRFg7Wh3H1XWsiMEMdoKWa3FMj5tx8yJVKD+G29pLwFiEh0dG7BNl+/CJ2c II+A== 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=eU/WsU6z+SIBegaTmvR5+Sdw63RRPyxFzFhSmLy5q14=; b=dnKV2mWSks4mTu1R2K8fv4eFlG2HBGlmad3u3/ku/3bCBvQVSID44qFb4PQI49xP/j TI0b55+2TxI43f5mfxwrMIldl2CSezNKh7ZVcV6clyvv8kityZ5OJexiHyqDxxHDNoG9 /l1dsYQKSqD5zXqcdZySsFFw9wuKrGUg2vayXq4nQoBl/FW+lCthxiMV/vHWBAT+Y4s9 erSiF/9YQGJREY0BoxbSVly4/1335te4jrvYzZ+NwCiJSRIoJSS9Drayvl0i0qUPJ70g FvQB9AROJjKS2937BHIVNIsDIJ4Tf27xR1Qet2tW39Ii2jU1R1aM8trxxgZFqgC5xYy2 6+jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="hh3/igGU"; 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 ga29-20020a1709070c1d00b00782d7448ce5si1555897ejc.734.2022.09.30.04.05.44; Fri, 30 Sep 2022 04:06:10 -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="hh3/igGU"; 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 S231674AbiI3KYc (ORCPT + 99 others); Fri, 30 Sep 2022 06:24:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231693AbiI3KTe (ORCPT ); Fri, 30 Sep 2022 06:19:34 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9B6D1CE60F; Fri, 30 Sep 2022 03:19:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533147; x=1696069147; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6YyqKyK6x+kgbFyp0+yYM9gZEPI08ZOunLWqbUMhTLI=; b=hh3/igGUJbM+Ihop1LIoSpfyeylXBXw0wY8h4aUbVJYGewjyTM+rCBWY yrsRY0gCtYOWzWdtePdOa5KPNsIpk6ivYkVs4EYJYBfqVJfTQAuur7Tg/ NIidURn0FDPv9xepxDL5iIpgnmQKAQRkU77vq/LB6249U50pQLAGe8ypZ Mha6uL9njiTKj880xmg5xWgefopWuupor2UrzeVhFKIDWFJXTP47TJJnU gYqEGTJ6JeeyoXaZGWZVjcESo+tCx+gv6K/zwanuQv+As13OL9P9/AM5z eiMfCKW+uw9Syb/rSUhjznCI+pGoF3CawuiFgzGN0q343g+gDxHGiar/M Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="328540153" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="328540153" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:05 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807774" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807774" 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; 30 Sep 2022 03:19:05 -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 , Sean Christopherson Subject: [PATCH v9 083/105] KVM: x86: Split core of hypercall emulation to helper function Date: Fri, 30 Sep 2022 03:18: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=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 96fd23392c1e..de7a716e774c 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1998,6 +1998,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 fda72bef6c90..43b1681a0952 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9526,26 +9526,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; @@ -9554,11 +9543,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) { @@ -9617,6 +9601,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