From patchwork Mon Jan 22 23:54:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 13526515 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mBVSzyQR" 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: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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;