Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp171109rdb; Mon, 22 Jan 2024 16:16:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuySMHJOmMvph/Yc8Ll/4J1v+E59Y53SZrHkQtY2E0R184vfKighJHEbiCY+GXdcIB+VuW X-Received: by 2002:a05:6808:144e:b0:3bd:9b5f:3fc3 with SMTP id x14-20020a056808144e00b003bd9b5f3fc3mr6667101oiv.31.1705968986262; Mon, 22 Jan 2024 16:16:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705968986; cv=pass; d=google.com; s=arc-20160816; b=ZSJGsXvJOgldkcL1+aIjFSm4VQrBnWi/bQaJr2791i8nqPjk1/WwbkngLYRDFru4Gk 7pJwle6BJtLhJci9KWtnwv48hAZ14go2d924QUbTX1XAISa/i0QHL45eKdwFQcqdhZfc eB58k5l4t1YKn3uz4JSr3Ge+d5ygFHyJZzZHLA4LYm2DUEsa4UYlvY/ftSx15kcL66pK rAC6jKkPEcPk1YR59Jyc5gTvxnoTsTTHMsDXRXA9wRxPAJBGOvyZb+O4hSbdy+cteK5N 3A1+j+6dF1zNdOc4/hPk+3ozJ3PtIxobBmjEIUkXalcoVkP4WI1+0MBzmDZka2MIWLXc uphQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CIctFGfeg8VcEMgulmUlzupg7VIE2psyZpu5ak1kbkY=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=TrzAAd1Dvu5/Zq1TEInDKEremzehPy5DzUP4g1YFiDzZ891H/E6jZ8/6moIE4sJplP 506ZtKGKkcbe1+PQRQnrYU+eWisjnKkMxQ6+ypGA7EUXQGlCfP6+2i0LVN0wgv2TXOaW y28DzUGWABQrukN9XBx9qyeOyyITfEgS526vnb6w7akgARm7zpZUqvJ32WYyIIAymCCz iJvDFz/9vH5u6HvzbEsuCmD/wpxseDI+QheQBboNjrpf0+9uhIHURuOAfxpRv27cEI/W xrGbd5GX7TdGkHAGPFmkK9Jo97hEVx/5sWr/3gkShhIXrAXLNhGQ51I/jgkUi71lVBOK 5Kvw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mBVSzyQR; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34400-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f35-20020a631023000000b005ce0cf4a97esi124047pgl.75.2024.01.22.16.16.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34400-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mBVSzyQR; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34400-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 34C5528C2C8 for ; Tue, 23 Jan 2024 00:13:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AA7C6EB6F; Mon, 22 Jan 2024 23:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mBVSzyQR" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EBD260DFF; Mon, 22 Jan 2024 23:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967761; cv=none; b=KQOVvIJZE3FOq4XVxZQeW9obO82aHI2izWfQscvkydUdhhN+eiJeZxmnOd2IlJ9J5ZxRGBMrxtqq5I5LtNctOQ02DXm9V7LxqrYfgC9yBb4bxnLeZ3E6pRWAPo4PJzE8hxNoMzvvoZLTRrR0y4i9pk1CiiW2gWXTZLnPAJnYsUE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967761; c=relaxed/simple; bh=XLMGHHUMCwCCeRTe62GURVCoY0QSRu3OqMgxogG936c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J6L5A0UzjUkbHoU1I2hBbH/X0Eljrj3F5ZW1fGG+gx3a872uUbsprlyE6vK9MATmvQLHIzuwlP9ujij074OXz/iyU8YMdB/6k0sHna5BLhpj9bP0dkfCH9fM6U/fNJSWzHb5mEe8v9ovwsTjmUigIQubksONUDGiBXKdPcF0Qy8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=mBVSzyQR; arc=none smtp.client-ip=192.55.52.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705967759; x=1737503759; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XLMGHHUMCwCCeRTe62GURVCoY0QSRu3OqMgxogG936c=; b=mBVSzyQRZGRf5l0PRuEXCl40arPnUwnntJN9KXHHYWMbjjptsnzdV5vO J6yRiEYbtH/u7IjzFr3VYmAmPNNjFNr+G+a+zTDfJNQaAIzPv38Pmxhwu QQCaD+yq9KiM47uYOHLJ90UXEui/MQpF1uZW3Q98kPTpsSThdwbF9EvWO q6rzO0fR64fcnZ3tR2C8+EOm8g8z/bK0n9RDAWOuNJ62wIFlg5x7HCEHW Qy6yHQDzTlUntMl0A5U4RJN++VjDomsoZZEwoIkEwkxJc3bqLhOv8Xfke zwPtXgUmu1iCesbVa23e5l5OYyvaulpX1HUO0iXHUhs2hERew7ucGvqZ1 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="400217846" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="400217846" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="27817966" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:50 -0800 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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v18 094/121] KVM: TDX: handle KVM hypercall with TDG.VP.VMCALL Date: Mon, 22 Jan 2024 15:54:10 -0800 Message-Id: <22e331335d6498153edb928bd125cb4a21365d2b.1705965635.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 23ee254d42c3..d922e3786163 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1058,8 +1058,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