Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp1435128rwj; Sun, 30 Oct 2022 00:16:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM70M1QN546REAskxo7fssNsFTjxpdtGHDn3ubeT7e2WIHep/FaDImlSXlFJQsuC3zrWFCfo X-Received: by 2002:a05:6a00:158d:b0:56d:59f0:d273 with SMTP id u13-20020a056a00158d00b0056d59f0d273mr638886pfk.51.1667114188763; Sun, 30 Oct 2022 00:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667114188; cv=none; d=google.com; s=arc-20160816; b=jMDGdCb8YF3uSqbACZ/BGpk6RLqCVaZ8NTYnW/+e7LbJFmYQc7OS59co7vpuRkFu0u zaqX0lSvodwBQWKfVYFZnSZ7YOR6A115hEilNoEHoN92ZtXbCDjY/xK/huI6fiDIU+RY QWJUOHDIr+jiw50+r/xT6pobVziJTFQMxgbcdrKWct4N5A1CD68HHpkBLkMtrD157pLu 2ZHPaKzAqVcXCHLRgDZTaoSvnnGiiYhJgHpzL/Pl0s2kE/sA4LTdyh2ZgSCgtwid5Qsd dHJDONP250JPikVAsDb+5GB4LGZ8C7ScDr9Os9ONzxoQdDpmuMsD7HnTBGWZi/Fg7nbW bbFw== 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=Vw+MYFv99srb83WSolCJEuuQb/lGNZlzuTBjYgiJrRo=; b=N8TdHu+wf+4/PHNakVYHfwpKxvWrfgb5NqisrhyjieJTN8Jnqi00jeKwF0CXMQLFgg 2Yt/Q6U6SJxv0gakLtbU0ykjO/ASx+aOypf7lTTm4g+AhLzA8BI10oDWW/PVt1mzlst5 CjZyndFlqg8bOM0mx/PzabYwHyyRM3vGBwpNqtZKvMJt4OvaeYLVUr1YrmSYQdreMzxe 8QUdNFmJC4cdhd6b3lPrD6VwnJWHv4s3FilbpoZhFC7KpgGh3AYyOCbhQWNHTx5/3t0Z kZhKNXAbsipSTt+pyK08nJgnhPG3l1Ue5NyuPsfG2rqWfq6yRy5E6+l5ofvaMm+kb33X M5ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZzKjbI1g; 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 qe5-20020a17090b4f8500b00212dc2e1abesi5318552pjb.47.2022.10.30.00.16.17; Sun, 30 Oct 2022 00:16:28 -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=ZzKjbI1g; 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 S230311AbiJ3Gcs (ORCPT + 99 others); Sun, 30 Oct 2022 02:32:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231411AbiJ3Gb1 (ORCPT ); Sun, 30 Oct 2022 02:31:27 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7FC9119; Sat, 29 Oct 2022 23:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667111098; x=1698647098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eBqMoB0m83MuwaAMk2sQDSmkQWX2Pc0er+8L/z4c57c=; b=ZzKjbI1gpsjCAC7SDOIamduifeNx4FJfsXDSkQpOPP5t21X+GqaL4br/ LFp5UkoKaX9HXsJywvCk9DYwm7IBBzmmt3yiuZoool53yq1zB/kUONvyO 2qGyi1X1ApHSk3Ihxh68NoTtlaZmj6tJaqVfEaxkOh4XtAsK/U6+KL06u TITfOPO/YtG70UGCzFfDPm3agjf+qiwEJjtTBeUjTLs+fHJlpTFO30wOO +WqJro6JJAd7Ab0o5y3bvq4ed78VIGVVohUUBY4n4bc397225j6bUZQL4 eDVkCmRs7H0ZtA9VtrvzjhH/2LriOwhlr7lfSNZkIlbC/VnQCV71SWQIV g==; X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="395037211" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="395037211" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:13 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="878393140" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="878393140" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:13 -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 Subject: [PATCH v10 093/108] KVM: TDX: handle KVM hypercall with TDG.VP.VMCALL Date: Sat, 29 Oct 2022 23:23:34 -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.9 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 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 65d9b88f1d50..f6477d577001 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -782,8 +782,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