From nobody Mon Feb 9 01:31:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39C5FC433F5 for ; Fri, 30 Sep 2022 10:26:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232617AbiI3K0u (ORCPT ); Fri, 30 Sep 2022 06:26:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232036AbiI3KVk (ORCPT ); Fri, 30 Sep 2022 06:21:40 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4A8A15AB66; Fri, 30 Sep 2022 03:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533164; x=1696069164; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HIrS6Twn7gSGBcV6L396WMWo2mZfJEBr9hTtzQbiApM=; b=NfhpYQ9bQlX5OlMV98ViIWlgJg+t9n8gqalR3HHO9TifWlzDEDobVLbW x987wMcNGIfRtgCRDmjaQv8nRg3g+DcvM+wMeXlc01gCRArgdfuUjU93W F8BSpWJOO7TtNFpoFVNyYY82oQ6cthL7IL0Z09RNNtciWzrR7IxugrZEO EM3mhhhViXQg6SGfWnIdEnUIoUgEsIVgwbMTWpr6lhUNe8xGgzlKx5M+I otrwNgj+mgPAcR8eA6uYfeu9m58QffS4zNjOLsOTaJzgvUEQYN3LHG2vA 7HRfQRjBOJE+xfdgitvnAIRtQ7m7TikDz/P5PZNM/fzV/ZLE0SrWo+zhd w==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="328540165" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="328540165" 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:06 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807798" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807798" 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:06 -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: [PATCH v9 090/105] KVM: TDX: handle KVM hypercall with TDG.VP.VMCALL Date: Fri, 30 Sep 2022 03:18:24 -0700 Message-Id: <50aea5742fbf45d17248903ab3811a4cf32b7fc6.1664530908.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata The TDX Guest-Host communication interface (GHCI) specification defines the ABI for the guest TD to issue hypercall. It reserves vendor specific arguments for VMM specific use. Use it as KVM hypercall and handle it. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/tdx.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 3392da81ef14..4e3c45e3b24d 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -774,8 +774,39 @@ static int tdx_handle_triple_fault(struct kvm_vcpu *vc= pu) return 0; } =20 +static int tdx_emulate_vmcall(struct kvm_vcpu *vcpu) +{ + unsigned long nr, a0, a1, a2, a3, ret; + + /* + * ABI for KVM tdvmcall argument: + * In Guest-Hypervisor Communication Interface(GHCI) specification, + * Non-zero leaf number (R10 !=3D 0) is defined to indicate + * vendor-specific. KVM uses this for KVM hypercall. NOTE: KVM + * hypercall number starts from one. Zero isn't used for KVM hypercall + * number. + * + * R10: KVM hypercall number + * arguments: R11, R12, R13, R14. + */ + nr =3D kvm_r10_read(vcpu); + a0 =3D kvm_r11_read(vcpu); + a1 =3D kvm_r12_read(vcpu); + a2 =3D kvm_r13_read(vcpu); + a3 =3D kvm_r14_read(vcpu); + + ret =3D __kvm_emulate_hypercall(vcpu, nr, a0, a1, a2, a3, true); + + tdvmcall_set_return_code(vcpu, ret); + + return 1; +} + static int handle_tdvmcall(struct kvm_vcpu *vcpu) { + if (tdvmcall_exit_type(vcpu)) + return tdx_emulate_vmcall(vcpu); + switch (tdvmcall_leaf(vcpu)) { default: break; --=20 2.25.1