Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp281676rwb; Tue, 25 Jul 2023 16:02:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlHdMTqsxJigSHXyAuU5RGlCE9QoXrMrkKhpJn6GwH/4iOPFsjH4XZ+TzMZzOJuJr7mJJwXJ X-Received: by 2002:a17:906:5dce:b0:993:d117:e3b9 with SMTP id p14-20020a1709065dce00b00993d117e3b9mr158289ejv.20.1690326141045; Tue, 25 Jul 2023 16:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690326141; cv=none; d=google.com; s=arc-20160816; b=COgKJX8yfDBFCLKlqeM/xzZ51fUBqvbpuACp1PFifFgreIKczzpY9Cnxnv4T3aIRKZ GgQ6IX/LKmc5fVJ4a+lNCTLv5h3YM3TeHe3TRzaqLtYVF3Q16Cc91K5s9SoU4eE3p6cj o7E8b4xXsG+63kehCnoTxCkmno8ylcjUx03DxML9/mUw079224vt323DwTNl1d4U1sPw DZKZAX1FQM8YUB57UcwWXXZCw1O/EML1rTT5nhvgtGnqGw5IlM0XbdMq/onCOyCEu5tR onb6hwg7POYsAoTrFlmN7EPPPaEA1j5VmSPdNvuO1e23IvyPmwRbmpKygNpRSwQysNws Uyhw== 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=zlmSdlpgEAreVwiscmOhlz1ofibs1wYVmQACeG77uUk=; fh=juxwNcA6iKwLISFgUCNwdoIYC0NKLUseq3xZdq25RR4=; b=EdIkQkpzgNkj6Sx/iFw94+fU848dH2nfZxKxgAvTd+1DW8EhxpJufw9dVFMxrJlGx+ l/XrGKsSk4aygyBAG5F2i0BTWe5Mc5O/Q2q+52hSe6qZS4kRjU9IAPUSW9eUebSXO5+0 w1475VswnHEAV8X3bwDajbElIbye00nplxV3AP2B8ggpLgRFUjYEZqVQCaOgsJwOa8GY semOJLy6mhM15lEt2xDhXD0l6p+AJD2ZR9airdBZhUStzjZMwWW4dzWyrG/dN/zCV2MQ g4aRKf8zpTi1LISoAiD2vpBwOZATFWoKRvnZ1lS8lzjxiGDHYZFjwxDne6/S9Lw3X5Zq IJEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eC1rgBXW; 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 d1-20020a1709064c4100b0098286b503e4si7936049ejw.1041.2023.07.25.16.01.55; Tue, 25 Jul 2023 16:02:21 -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=eC1rgBXW; 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 S232909AbjGYWYr (ORCPT + 99 others); Tue, 25 Jul 2023 18:24:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232842AbjGYWXD (ORCPT ); Tue, 25 Jul 2023 18:23:03 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AB5A5249; Tue, 25 Jul 2023 15:18:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323494; x=1721859494; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0201nZOQNDeXU1m+PIlO4jk2v5Jd3RpUfZElkXE2XPI=; b=eC1rgBXWX3B0CH1TbmzoWaRoZdZDDeF36mQC69KwnAIponCJySHC7OH0 E41Sc9kledoJGT/KOz9HOOBjFcgkHkzpiuSLrIeA2GFaisz4KwhwXcmzp v5zGUhRMkiiHRLAlxfgNGacFE0GPxHP9Y2BUDcOlDoSvnY2sVi+B6+Fp+ KY+QOlpdtCRZ4RXoXV/JZiZkqHnQ6Zq3lU6eMx6Fy6WIXbbem9AO1Pooc OWfE6wuaqjO7sEx8WcmpcJsWPpSgDwUhu+mH/610hN1nlOjni01ryO7Qd uAd+TFHhEVsYmXWKAajBmWJY3OdhcigjHeBILx+SISKObhna7hAdBWoxz w==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="367882690" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="367882690" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="840001890" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="840001890" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:02 -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, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v15 090/115] KVM: TDX: handle KVM hypercall with TDG.VP.VMCALL Date: Tue, 25 Jul 2023 15:14:41 -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.4 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 0a1ccd16d17f..19500a05f7b5 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -889,8 +889,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