Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4107938rwb; Sun, 7 Aug 2022 15:14:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR55Ipelr8MY/gZvV6xXqVvye2ylAPAUSaiCuwXE5cQ7PiH3E/zp9SSZKRfWEdh0rTTqXnix X-Received: by 2002:a17:902:e805:b0:16f:4a25:b5bd with SMTP id u5-20020a170902e80500b0016f4a25b5bdmr15944639plg.85.1659910475355; Sun, 07 Aug 2022 15:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659910475; cv=none; d=google.com; s=arc-20160816; b=EiMh8RgLqaEoGLjjWt/5kZH3HTZNlRCOOlaOAnkXyTZCtS6nbph/3ek+SzoMyzk0Ve 4FbGw8mWuOdDD8OL7pi2Lt9XW1UjLoqjGglcoXCBgrOPG5Wb+GHH8E+PTWHDqtYvQKTS xsdcl63qBG2EENFS9hIpaU8zTr/+2SXgI9lB9uWde+uJs982Ky9FxAMau/Agv4x7xPDL Cn6VW8PpPfWpodJEE4N1gwrW05lZsvt0WbHz9zj8PnmJ3dy4U7rRAQuYqKvELPTKvD9u PzxB9/+dmMYUzQVRJF/iLPX22iz/xAeTZSUN5hAhyFNGBAUOwSa032Wd2tBIeoKDLJQl 1OKw== 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=ptb/nHoCFyQ2uKXQVCqEXoDMEF8/DD/CKbx2Z1D3bCg=; b=CD+g5kbnrftvHYGFeOSqkOxpceZs3P37dDOj/yXjytPh+VY4PQywoyQ6JnOZ4FvcXj +xKOXHb7vUpvrvIz4GjVDhjeMVpQANFrcS52khny1BXDynXGKKAr08iHLLQRuETy5r33 wPzBY4bMGBf0hp2AFQ6dswAiwpeeGuJ1zgeR5pePVaSz2uUSoA3o8U7sZkaq3VVtsvet 0kK7Q0taM1K5LCjY4YrU7gWy0gXv+hlmJ5hwDjYj1giUeEmuFxPNqr9/HI1a2DmCJnq+ /Em4ANHA1MM/DrbjpqU5s6Dsv+B9IycKPHf90kagYoIOcLbn5ePBwO8yGDngerqmkgas atqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P2zcuqkE; 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 k1-20020a170902c40100b0016f90347391si9087230plk.99.2022.08.07.15.14.19; Sun, 07 Aug 2022 15:14:35 -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=P2zcuqkE; 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 S242316AbiHGWK4 (ORCPT + 99 others); Sun, 7 Aug 2022 18:10:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241870AbiHGWHQ (ORCPT ); Sun, 7 Aug 2022 18:07:16 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6371CBC17; Sun, 7 Aug 2022 15:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659909798; x=1691445798; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9k8hHT4h6MN648mDsUmZu+Cs5u9gYRKRacre65MQmzg=; b=P2zcuqkERoeJ36kwHn5dwZnO7VG6E4XplayhfnrHqnlS+ZHVc83Nr//V bDJTCptW8WqpO32gHfVIyHcgJgiWLYjTZUIs41CvREyP8Uv20QGL/0sMD MVrsR4FXXNPR4wJGpwz239Btf1JVTlR5RAt7VHpxBifLpkB0xFnyEVzqi YIVAZ5Ldrb4WGi3EQ88ADyfBzfmCtuC5ZNPcIoedLSP0d2cVibYLPCll3 rBq0WhiO28nHBvuxlSGTscMaOFfdDH0ZIjnwni5POeAQNhnlJoJ1prc6F ERMZ223EUw+g31CBU20WmYhmUVYOYLIUWh4PKIEilihIqxdG3ig7DL3qG w==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="270240400" X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="270240400" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:43 -0700 X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="663682737" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:43 -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 v8 089/103] KVM: TDX: handle KVM hypercall with TDG.VP.VMCALL Date: Sun, 7 Aug 2022 15:02:14 -0700 Message-Id: <78f8eae8b9286409bfde60d06a05d822cd246fc9.1659854791.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=-5.0 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_PASS,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 c3cea3cb4d15..849bae37246a 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -906,8 +906,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