From patchwork Sun Oct 30 06:23:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 12926 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1667314wru; Sat, 29 Oct 2022 23:33:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7lRe/MAfOcX8EmdmPwif7L1g69dEzoqfi3rSyZcE82AIAJ9EQzzQDGWF35cUC+dQuiF33o X-Received: by 2002:a17:90a:708e:b0:213:6876:330 with SMTP id g14-20020a17090a708e00b0021368760330mr20838536pjk.167.1667111608660; Sat, 29 Oct 2022 23:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667111608; cv=none; d=google.com; s=arc-20160816; b=b8qgY5z2R6URcZCliRv9DFhrz5kkrCUkoD8dvb4N3fAEEuPyqZSXH+qtHqQNOc1pqO 4Wk/j8PS45s7dslveseLNp+KFLHF6QN+ucBIvtNyxZ8Q7uEeDWglT2ZssVC7fD8p7JQC H06OieQJkwLOEFvlSVj3fvgiAva99fcSV9kfGjThNmuycyOXeFz3d4vMS8aO1Iv8aQkC TuVm8QiRWTRSb1dvmuqrBJAnnUIjpUhJE3cFfLUfuO2Ll+AOPqtNn/yijdm/laRjGAUd 4w+GiMgaL3lQzqVSD47T45Ha5lvGV6UYaSYHyy1C5PZ6uCUsEcdUXNln+eDjCaTOMSnS DyQw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j68-20020a625547000000b00567719e34aesi3933326pfb.49.2022.10.29.23.33.16; Sat, 29 Oct 2022 23:33: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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748093222306477266?= X-GMAIL-MSGID: =?utf-8?q?1748093222306477266?= 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;