Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2679307rwd; Sun, 28 May 2023 22:03:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5uwBIhp42l5BOnZhHOO9fiGRErgGf73q32NZVOR8d3uKp/tfOC22t0pQRj2HtZ7C1zTU59 X-Received: by 2002:a17:902:ce90:b0:1ac:310d:872d with SMTP id f16-20020a170902ce9000b001ac310d872dmr10344227plg.52.1685336587781; Sun, 28 May 2023 22:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685336587; cv=none; d=google.com; s=arc-20160816; b=BueN+sSaKbAcQpTBSkxlmkF9dj+wuKHdsQKjOChmbb+s9gdLSksNzAsF76MJcKeZLQ kHVB1ppmn1uXgznz+hjeaWj0XrkuqrFjdcsE+JkLuQCBehktX3C2/aEPwr7jXBT+6rLA C+Ep+tnI8HLGj6icY1SvWZC52Hd5IClbopLH5XVExybIpogUS3dwOqt6XMzq/7Lxli1I NPU88oBXmMum73INSCmZVaHLQypNm6cK172ZMkClIFuUXRat38xdCULwdK6sBlCFgXcM RrRZsy5yn42n1v+Krg7QhO/nr+Nr3q/NcJYHUDun08r9v2Gh7Vyrcth2KJ+hcl6tJEsx MnnQ== 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=Vj6IIF3gskFqwmAOfffkPHjDVC2sewo154AEoLi1Q2I=; b=oSuEozlai/vLr5ht7DyrqXHtLwU3D278fzNYE8qkwmg+7yykfYkV/okTnC+MVIe17g dgBk6cYe40GVkyVlJJjyFPSD65ttyaPE0H1W1wt3DXbrcM8/VoGXVusoERtJZAZyzu5I THL0g/sxcaPTnr2Rez/wv2bxVHZGXx8dA6T3ylcxJM2nh6LkBMTjnIt+8hhFovuRyhke TTE28pt6HOuBmw+WG9ofkwpXMSJiAKAUsfijfAUa/uN2ZA6Y1/53tlHP9OiQwDBAPrsy G85noHBhDjDaSWWmzqwXlRjknTl2njBONLAep8K3aq9Yq86H2SiTendYE7C7Md9mQnpc jFSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ntytWpCw; 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 u11-20020a170902e5cb00b001ae0691dff4si9543690plf.630.2023.05.28.22.02.55; Sun, 28 May 2023 22:03:07 -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=ntytWpCw; 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 S232144AbjE2E3Z (ORCPT + 99 others); Mon, 29 May 2023 00:29:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231947AbjE2E2f (ORCPT ); Mon, 29 May 2023 00:28:35 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ECEC1723; Sun, 28 May 2023 21:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334304; x=1716870304; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j4UaGjqUHdHWF5P+EfOyo+SrZ3HJFlS7UZYjla+5tLQ=; b=ntytWpCwLjuY8kPkTx/UlVXePINYi09WONzcTIUxTtvZzNDdjtLtvmuC 0gS6Ta+SxM6B1w6GAUvPvdH5BGXZ1HaR32NGug6kiPtZkgGKE3+d/wbJd 092i+NQC7NyVmc01CMXKWQbOi3KPPc88IxCKGxXZt7kC+2tMHI9IFQL7e iG8aP0eZTshxZci4IOOV7ojXjx7zsjImsWBD5c4K7OoV7s0nDVfRyVEAr gqC8gVQLPWlYMEoG96LWKEVDtCdwXpWgdta3BfZVYw4+FveY3o4G6D8Di LoK0ctczxDDaQmCuI0UOICbePJpH4b0fKu/6kERnZp28LIXNJEvtb6JYP A==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="356993402" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="356993402" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="830223409" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="830223409" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:38 -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 Subject: [PATCH v14 089/113] KVM: TDX: handle KVM hypercall with TDG.VP.VMCALL Date: Sun, 28 May 2023 21:20:11 -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=-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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: 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 f4ac5b4662e1..8d3a5f9d208a 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -868,8 +868,39 @@ static int tdx_handle_triple_fault(struct kvm_vcpu *vcpu) return 0; } +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 != 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 = kvm_r10_read(vcpu); + a0 = kvm_r11_read(vcpu); + a1 = kvm_r12_read(vcpu); + a2 = kvm_r13_read(vcpu); + a3 = kvm_r14_read(vcpu); + + ret = __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; -- 2.25.1