Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3390906iog; Mon, 27 Jun 2022 15:16:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tXkeSCOnfosPRef4YorqpDDE5qE61rSEhjfo8+5CZxfspgWYf3pdw5ZrpKXQv4nKqwaxmA X-Received: by 2002:a05:6402:5249:b0:435:a419:300a with SMTP id t9-20020a056402524900b00435a419300amr19392550edd.56.1656368178022; Mon, 27 Jun 2022 15:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656368178; cv=none; d=google.com; s=arc-20160816; b=QKazWR5+9u5IqxgYTdx5l2bFVB88FZpVJnAFhQeoznfIMU31sv+OLIJSh7pLWxIwJR OEREaODfNf0YittPkKzassL8JBkD2I4M8RWjxZz/0w9OdVk8x5cBDJLpbRGHO4GP7EJ8 XztsPZohYct+h4atimWww0CKD3XXK/qweTc5zxP+9DBXh/py29xZmEHyfzBd4R6HO7MS BT5VlgNPVYSoA6uwSfHAClx+4CB/A4uGz/lprz9yVn6E5vfs62bhUFu+a2CrPlWURXyz XfuCK9V22h5bbr4+I1pL3X66KORiVBfmKdVDfHi1dx7XVC3jLCaMIwg4a7wQmO4IF+GZ dRBw== 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=o2r2EHheoXLyXp4gJONbv36kZZnb6AXHNSzU1NLUdtY=; b=pkhjhRTVznuSU+CMUPaZOTYuR/2kvDVpq3Sk93u/KUh6eJFZCrxjKgY4gDxEjsCQ3F DKyqQ29xoG4uRbB1yfJ2ss5fv1qmQ3M7q3WC3/P44/o0LYc5DW6YQKGPkrNtzdgC8+Vu XKxKRIxJnjjJXQqTr0Y+rguN4Pt+eiqEEcQRqVEoDVEzWlhORKX+ITQOxx7aaqLq+IdJ h/UuRCqzzwM1wMapeo4kDxzot2F4GWLRBA8Y5bgX6NjngBPOiG+t4C2NZbf2LCR4mp9X 7cZElkEp8N9bO7gz3m6j7MwhuBbMFM70lmytnXzIsE4ZzXpNRKlTbuJkex6b3BriSp0p pJYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="aA/d/pmm"; 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 v17-20020a056402349100b004352610c39asi13496669edc.233.2022.06.27.15.15.52; Mon, 27 Jun 2022 15:16:18 -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="aA/d/pmm"; 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 S242377AbiF0WBc (ORCPT + 99 others); Mon, 27 Jun 2022 18:01:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241580AbiF0Vzs (ORCPT ); Mon, 27 Jun 2022 17:55:48 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8938414D09; Mon, 27 Jun 2022 14:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366907; x=1687902907; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YgV1xFu5YP/ElF21x2KrlvBL7tTG8eau0e2bIOp97ps=; b=aA/d/pmmhVvjnUmPUNwj766hAppzXYC271myA0tPKZU/W3AFQE1HUMrM O+xUPqbtQeYWtMca1YR8+W7C8+6Pl+WSiQ8S6d3w8om5vdQOQ+vdOwexw 3m7fPzuCZYcR2I902cUgz+PNpDupgmFNrsYb0hqznk9mvSjvtHrVzOxnc J/dFe/j9pTUtwSNrkAmt7DCFU+n72ItNrs0Rn1tmxQjKCkVinCvDEBEX5 zzr65JGRxLoscpWeyYv+kRcBp8DgMBTGoFh5vtDmMKKn8h+Y/YTaolu5N 7o0iloaDSFKT7phghcIrAVjCdDmExs2isYBjwgl1zCnbh854Bfcygp+Sc Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="279116137" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="279116137" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:55:01 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863727" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:55:01 -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 Subject: [PATCH v7 088/102] KVM: TDX: handle KVM hypercall with TDG.VP.VMCALL Date: Mon, 27 Jun 2022 14:54:20 -0700 Message-Id: <84daf515aa16b748bffb4e7ec7e1e24466a75e66.1656366338.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.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 c9663df83292..a30be04229d7 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -919,8 +919,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