Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2620139rdg; Mon, 16 Oct 2023 09:35:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH02Geu5BGxF+O86rEUm3KgUnMXyyDcCm/9KbGKzDbEtoXNr4FkJXxcSrFOx0pYp/C8Jg2G X-Received: by 2002:a17:90a:3f16:b0:279:1367:b9a3 with SMTP id l22-20020a17090a3f1600b002791367b9a3mr29903490pjc.4.1697474105161; Mon, 16 Oct 2023 09:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697474105; cv=none; d=google.com; s=arc-20160816; b=YYjBq2ETAcisG8JsrWJLIl4ZVEHCjJO+VipdD3xMWgLJcemj6hum+6MUiedVeJbezh fWRIjuT9sWwtnjbMhUdzMqwr19Fs1wtux16NdCnDrlHN2lajUZOlOD9PM4qGQcSDhYMQ R4K5d/gZLUxSyttOav80nmjAAC4Me0t5YnKOkNV5zfPHixQ34j+WU4X3FpTTkejgBv90 49Og0uBmXMPngKCk5+F9O6suGQxnyn0sAjX8djVdRG+n2Vqp7DiSrqoSCH2hr1Co+lFm UeGyDo1AkSprvruEqgLpFh615YMJZZR0IJtapwGRA5kvcT0jsplfhEXLLwhCsrQYF1eV fHBA== 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=dtP53cUtnoOA/Y54p8cQjDes7HeoaCZgWrgLcbO7MnQ=; fh=lRdU2Q/1zx5DcPdZuWBjshA5VT5Oc9cEhB1tCFiV0Nw=; b=n8C12OFB23eG/r/YsQgdUcyGwSgPRG6L4nTGeaQ5T4GETJQnlUXz5oaWBwDEsxzy1O NfBoOVARNz48PCLWkFZbQ0U7sZRPOLcL4G7umouraCT7x1du+dLHzb/21VpvpIUxQsPX s/3y9MxvmOabGjKvc54NfMhlb0qlHqyN7oifcG7Rik+jEctxVZkHBGZ22q5OrZc+Zcqh 9Xwqw7hX7Biz0agIY2ayUj7WaFLT26MzaClqEBQ0rkyDfiM/JRewENvydmYL3O9w7cTH vHkyJ4YN9i3/HouxS7CNe2kRTsEy35GZJz+/V/gFxxzYg/fuoN1C1ydvoKBGIi4P5Qaw NWxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IdXH+4oX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z3-20020a17090ad78300b002791baa4729si6329453pju.57.2023.10.16.09.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:35:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IdXH+4oX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 8A5088021EC4; Mon, 16 Oct 2023 09:35:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234111AbjJPQeT (ORCPT + 99 others); Mon, 16 Oct 2023 12:34:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234184AbjJPQdl (ORCPT ); Mon, 16 Oct 2023 12:33:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43FE5479D; Mon, 16 Oct 2023 09:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473238; x=1729009238; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i2dR5ItEFftjCJiG59AV7yvV3LMkSNvIShT4KE4blHc=; b=IdXH+4oX3GWvmS/gKvAO4hXzJjHAJjdnqyYY1xIfFQfZDBHZBRw1nJR5 X0Pe0F0awbvMxUnhApgjZda/bntUf6PvPfyQimp3TlMgXr0ehJfPpmR/L sOzbAWhGdgHaHfc3q+BPSorY/an6V2BqDP6VSfSdgBb7zywLPcPBXrzP8 0n+RaDiUAkPMoso6M1e/shBReLTKCjdzi31lAuuU9ksMSvk7Aw0yivZSj 9/hfGxIMXzLj2ulLiI4wFX1MCdtRzV8GgOYtAAoR0AzcR4NnVUxVV2Mhh jVPWlmhKgeupQd9xGq+2DGEBjrJsmG4xpdqOplzYAhCisbHGabaNolH/Z A==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="364922025" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="364922025" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="846448289" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="846448289" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:03 -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 v16 089/116] KVM: TDX: handle KVM hypercall with TDG.VP.VMCALL Date: Mon, 16 Oct 2023 09:14:41 -0700 Message-Id: <9833756b73569332788c493dc67d5ee9291f1088.1697471314.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=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:35:02 -0700 (PDT) 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 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index fa1cf0a8b5f9..89e92c696760 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -982,8 +982,41 @@ 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, 0); + + tdvmcall_set_return_code(vcpu, ret); + + if (nr == KVM_HC_MAP_GPA_RANGE && !ret) + return 0; + 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