Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3473512rwb; Fri, 30 Sep 2022 04:14:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7K6dhCLRr7p2dw2ymDlekdHYvpyIzx0DTE/8T9IsNOmnJmkceQjcoRMRm+/z5nVsoteWnw X-Received: by 2002:a17:903:2683:b0:17c:6ecc:d03 with SMTP id jf3-20020a170903268300b0017c6ecc0d03mr2591811plb.151.1664536496805; Fri, 30 Sep 2022 04:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664536496; cv=none; d=google.com; s=arc-20160816; b=fEMl968lzDMHP0/NgQxYUFqceB0u0wBSV+vJq2514ljUs4NXW2AblJJFpCSJOlkstL qCxuA/sC5pMOrVoaCKCz/oe8ZHTJgrHYdkmeOT4wMaTG/t1575WobhwZ58X9Adc1USvI 0aWMb2rCdglh0msQoyX48aq5cVvDjPHUGgLNFYoYBxI9uUoEVCtN21eeolxrYMfynHCP ktlggfFD4+OM0X3Ifmub86VIOh70TCCBVUTfFvwih4YWNQ2TvshovNhxfZWhXUHM/uYx H/qE2Pw2rPdSmyL2TXYC5VUe79QRVhsqOwOgZweeDv0iuOSUddMIUb6/q+k7nseCpa2F z0Zg== 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=K18Q85cTLkvqRlmKZQR/X2UJ/zHuOS1Cvqs8USd9E4g=; b=gemIz17rZZxj2NUsutbop5QrtQ4msJnmVtq0Huy6hYo4vnfOMUq84wqTr4qJERmqO/ Z54E4E4QGCBp1c6Q2jz3FzvAnQuZi1yQEHGqE46Ut2ZDcbkUSPk4K6w43hiIKd51gZP7 4JioSW3p0F4o2TpnzG7d19fDWzleIXOH971yEPjIaT4qNbmrZrftlQGMzkr9/MSC34DS G/wyR69csAiUNw+6XB7/3uchOh1+QSel/rOYUw6klaYfiFUJg71P3VMD8+OsgOje7lP7 b1iIijAm/j6eVHPxZdnaO4ZTFyQ0GqRsgWnC33DnpRXLAN7HHb2GNMly484tL98BcY/Y oyKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NfhpYQ9b; 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 s5-20020a170902ea0500b0017811e39246si276560plg.397.2022.09.30.04.14.45; Fri, 30 Sep 2022 04:14:56 -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=NfhpYQ9b; 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 S232615AbiI3K0t (ORCPT + 99 others); Fri, 30 Sep 2022 06:26:49 -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: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 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 *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