Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp112020lqb; Thu, 23 May 2024 12:18:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVJwghlLkuRdEWeU6cD3uuhU/7cD00cxF1XIxo02GQIF+ZR4iYNwnI5VBmpENFkOysIe/YDO0ZZflThjUV1RP/3Z4fZnFkkrXUN8Q6WA== X-Google-Smtp-Source: AGHT+IHombT9JvZvoByFMJVArM7IADjAw5bd2m0CYXRWczscRJhIe08P1LoSqwFZnoVsgr6tCqvM X-Received: by 2002:ae9:e317:0:b0:792:bb93:6876 with SMTP id af79cd13be357-794ab08d7afmr16336685a.3.1716491880450; Thu, 23 May 2024 12:18:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716491880; cv=pass; d=google.com; s=arc-20160816; b=TruV6XM9FM+2HDTXjcNf5l/vBKzrX+PT4eCcmd/XszdDafZeAqKgVVvgH5yVkwPeyI PB72YkHmXZZSHYuWqZmrT3yyn8uMBxTmrb/huuXNXk/Rd0iTMrZAJJbJ8OUkU/bLl+xD RSbcD7d6zlfkz11FuKSRLgJHJh/x1Xsp/Rf5l9MswlE0nxNmHF75dRPtq/bE8vBtNRz9 ZnNVugegpn0toubY3CiHR1uFF6VXgpwYTw9mXvagqAVOYaM8nBQEwWVoHChhN2U/AAMQ 09rWCdfRKJu0Bw56q6akYbahzx1QgHmJZ759mzoSmYmZauwMYEDgFcyU+QL+a/YYWDHu 9BSw== 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=fgzBKFVe3W/OltftBIQOvr5AHwhCBi+hZRdG/bf/ttU=; fh=QkwLKIoT9kPFq9ZF3dLm99Kn736/yRHgRjoXbSswJ0A=; b=pXxvXz30lg4xweACEr9X8uW4uD6oXGRFUPr7oV9JorkrYdFCq6+NE2VnJV2NlfEqJp d5RAYoH0AG6MbPqQ6SuGu2F1TJWo5HqnDA0nmqFrpRxOEfYbF0F4MeERpXP7STxgmon/ o6n7ZBfl/86Z/yJWzAWzNY9DgFhy8UEFb0/Wryj3jRo6gUiPm1xp6STg5cjsSb4KsFXL WUnlJ4uKn7b4TUNFSmFPaMmIa7P3/zLRNs15Cz/5mtKbGlXPttfqVbPQJJHsDr5UJEHG 6StedwMcC3/71VORw++TASBANc7oZ+JqxcQskfBd1PujoxDeo/LPqltzOjihwRzzneHt /kBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=cgI4moMm; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-187920-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187920-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf30a54dsi1018908185a.337.2024.05.23.12.18.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 12:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187920-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=cgI4moMm; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-187920-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187920-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1F9321C22C5A for ; Thu, 23 May 2024 19:18:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E83EA85920; Thu, 23 May 2024 19:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="cgI4moMm" Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 393EE85643 for ; Thu, 23 May 2024 19:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716491751; cv=none; b=BR+tuMSq0/3SU9o0b0gj2ZuCPAJWVPdW344S1wknqxVHOMhXiL4+OoRwDZ/9oEx/6F1qv+xLAe8rU8FMTsrKyzWhmTDEeTftGcyv2HSnrE9gyNNCF4DbTtRLS5x4n0KjY7NUg2s+6OR8+zHSMkOXI+1mOuJqy81Gar8F2gd/+h4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716491751; c=relaxed/simple; bh=CtLXgavYKdr/P8ISBNI90oH6x47hhuCLLXFyLqS812I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GZAi6Ahu5xDx30vIlQ2lMlEsWqR579koxy2V5/Rpd4XZMZHOI9VjmauXVH1TymNeEnCiav9cLKrgBqCgNeJr1/Y7nzvmv/WpIVresLMgEMMUVJJN7JKvR9p134ThV7J5Ibk0QNOS0aR02MEiH2YIADyALidkkPxYfYlI3Nzi9y8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=cgI4moMm; arc=none smtp.client-ip=209.85.210.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-6f361af4cb6so1743234a34.3 for ; Thu, 23 May 2024 12:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1716491749; x=1717096549; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fgzBKFVe3W/OltftBIQOvr5AHwhCBi+hZRdG/bf/ttU=; b=cgI4moMm9F+RgkeoK0uq6bvHfLI4iChKy9tCEWbicj5aRmBp+SmfoJEwCE0rXiuRkR CvHiYtWQg0ze3HAXSLFc00jWuk0GHEd4WPiF46NDuz0vs/ZrUNVWuGkjx9d8MUL+mFli 0qOQU7WbNuHnB2dNdIY8q1Jwo1AhbUzJIRCaU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716491749; x=1717096549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fgzBKFVe3W/OltftBIQOvr5AHwhCBi+hZRdG/bf/ttU=; b=LYAmhj0hESBo+r/qwHxpyYa54SSweJQT0w3h4rW2cw1uGrAILWpJ/TO8PyqroMzDQ0 EIPGtZ13BWERBMquSCG+HcoQqGllDprBfVAq/aWNEzZbbJlEOazdnE0amdHHn1XkvDR3 Xyhp2bxJ4Ux336QsEeW3r+kQXuoxKG9aw4FL14Ht1prefBK1379iy2oCke1m2xCK5rPb wKOMseaUERrLXlqWYXbmQKHynFWZNRXjyNjKah4yLfJD1ihzJ2lCHpLHSDqztV+hve+r J1wQ1sPMBk4CdfJ/rFXvjma5C3HtSABR/2N7RZSySZJRfp5r0xE8ebOEDe6JL2NSPg8k O87A== X-Gm-Message-State: AOJu0YyF/EfyUU/BTq4ld/T1DxpbmWItVJcw6eGA7bfJds/7+jpB+Psf XSp3xFiTWbA5AQwcHwjxvzwxrZStc9gFWCc/WfMkuPCYFLy57qAPrAfXe9gmexDY6kdFOhWJDli mDVldj1tAKl5Qcil/uxL7uXs+FsQVcvZCEu+pCFDRGWMqZ3Kt/NYrtnds+QiytQ/hk6b3Qc3NPg muA/i+PuV56/gPVNZq7x5y/vsdjoa3hZw4CmwxamZEhfZfVxaZz0r/ X-Received: by 2002:a9d:6c11:0:b0:6f0:e8a8:da6b with SMTP id 46e09a7af769-6f8d0b30fd1mr116700a34.36.1716491748866; Thu, 23 May 2024 12:15:48 -0700 (PDT) Received: from amakhalov-build-vm.eng.vmware.com ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e4a89b61dsm21219821cf.45.2024.05.23.12.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 12:15:48 -0700 (PDT) From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, mingo@redhat.com, tglx@linutronix.de Cc: x86@kernel.org, netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, zackr@vmware.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, timothym@vmware.com, akaher@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com, horms@kernel.org, kirill.shutemov@linux.intel.com, Alexey Makhalov , Tim Merrifield Subject: [PATCH v10 8/8] x86/vmware: Add TDX hypercall support Date: Thu, 23 May 2024 12:14:46 -0700 Message-Id: <20240523191446.54695-9-alexey.makhalov@broadcom.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240523191446.54695-1-alexey.makhalov@broadcom.com> References: <20240523191446.54695-1-alexey.makhalov@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit VMware hypercalls use I/O port, VMCALL or VMMCALL instructions. Add __tdx_hypercall path to support TDX guests. No change in high bandwidth hypercalls, as only low bandwidth ones are supported for TDX guests. Co-developed-by: Tim Merrifield Signed-off-by: Tim Merrifield Signed-off-by: Alexey Makhalov --- arch/x86/include/asm/vmware.h | 45 +++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 78567920b23f..e9acce119be0 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -18,6 +18,12 @@ * arg2 - Hypercall command * arg3 bits [15:0] - Port number, LB and direction flags * + * - Low bandwidth TDX hypercalls (x86_64 only) are similar to LB + * hypercalls. They also have up to 6 input and 6 output on registers + * arguments, with different argument to register mapping: + * %r12 (arg0), %rbx (arg1), %r13 (arg2), %rdx (arg3), + * %rsi (arg4), %rdi (arg5). + * * - High bandwidth (HB) hypercalls are I/O port based only. They have * up to 7 input and 7 output arguments passed and returned using * registers: %eax (arg0), %ebx (arg1), %ecx (arg2), %edx (arg3), @@ -54,12 +60,27 @@ #define VMWARE_CMD_GETHZ 45 #define VMWARE_CMD_GETVCPU_INFO 68 #define VMWARE_CMD_STEALCLOCK 91 +/* + * Hypercall command mask: + * bits [6:0] command, range [0, 127] + * bits [19:16] sub-command, range [0, 15] + */ +#define VMWARE_CMD_MASK 0xf007fU #define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) #define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) extern u8 vmware_hypercall_mode; +#define VMWARE_TDX_VENDOR_LEAF 0x1af7e4909ULL +#define VMWARE_TDX_HCALL_FUNC 1 + +extern unsigned long vmware_tdx_hypercall(unsigned long cmd, + unsigned long in1, unsigned long in3, + unsigned long in4, unsigned long in5, + u32 *out1, u32 *out2, u32 *out3, + u32 *out4, u32 *out5); + /* * The low bandwidth call. The low word of %edx is presumed to have OUT bit * set. The high word of %edx may contain input data from the caller. @@ -88,6 +109,10 @@ unsigned long vmware_hypercall1(unsigned long cmd, unsigned long in1) { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, 0, 0, 0, + NULL, NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -106,6 +131,10 @@ unsigned long vmware_hypercall3(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, 0, 0, 0, + out1, out2, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -124,6 +153,10 @@ unsigned long vmware_hypercall4(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, 0, 0, 0, + out1, out2, out3, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -143,6 +176,10 @@ unsigned long vmware_hypercall5(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, + NULL, out2, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=c" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -164,6 +201,10 @@ unsigned long vmware_hypercall6(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, 0, 0, + NULL, out2, out3, out4, out5); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=c" (*out2), "=d" (*out3), "=S" (*out4), "=D" (*out5) @@ -185,6 +226,10 @@ unsigned long vmware_hypercall7(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, + out1, out2, out3, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 58442c2581e7..5bea95039690 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -428,6 +428,57 @@ static bool __init vmware_legacy_x2apic_available(void) (eax & GETVCPU_INFO_LEGACY_X2APIC); } +#ifdef CONFIG_INTEL_TDX_GUEST +/* + * TDCALL[TDG.VP.VMCALL] uses %rax (arg0) and %rcx (arg2). Therefore, + * we remap those registers to %r12 and %r13, respectively. + */ +unsigned long vmware_tdx_hypercall(unsigned long cmd, + unsigned long in1, unsigned long in3, + unsigned long in4, unsigned long in5, + u32 *out1, u32 *out2, u32 *out3, + u32 *out4, u32 *out5) +{ + struct tdx_module_args args; + + if (!hypervisor_is_type(X86_HYPER_VMWARE)) { + pr_warn_once("Incorrect usage\n"); + return ULONG_MAX; + } + + if (cmd & ~VMWARE_CMD_MASK) { + pr_warn_once("Out of range command %lx\n", cmd); + return ULONG_MAX; + } + + args.rbx = in1; + args.rdx = in3; + args.rsi = in4; + args.rdi = in5; + args.r10 = VMWARE_TDX_VENDOR_LEAF; + args.r11 = VMWARE_TDX_HCALL_FUNC; + args.r12 = VMWARE_HYPERVISOR_MAGIC; + args.r13 = cmd; + args.r15 = 0; /* CPL */ + + __tdx_hypercall(&args); + + if (out1) + *out1 = args.rbx; + if (out2) + *out2 = args.r13; + if (out3) + *out3 = args.rdx; + if (out4) + *out4 = args.rsi; + if (out5) + *out5 = args.rdi; + + return args.r12; +} +EXPORT_SYMBOL_GPL(vmware_tdx_hypercall); +#endif + #ifdef CONFIG_AMD_MEM_ENCRYPT static void vmware_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs) -- 2.39.0