From nobody Fri Dec 26 05:29:59 2025 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 9417D36094 for ; Tue, 9 Jan 2024 08:41:04 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="KmV4t3hc" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-28d80eddc63so867921a91.3 for ; Tue, 09 Jan 2024 00:41:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1704789663; x=1705394463; 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=yGIzhL7QiBJFkwlC84l4JtgAxPW7nCL9ZrpZ+JYeVUM=; b=KmV4t3hcborFZ7wZ1h47UVgsFK2U0eQ2JiiG88zR+oMtlwu39qGMWdszGOSwMU2wBH Y7Xp5/s8N5t6MOEO7Kxr30G4KnF3LNdVql2OUl4WJCEB4B7HgeOa72sBMEXWdRIu3r98 2WWwFDxoRv3/2P6wYMt7G5+piCYttLDCh4rBo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704789663; x=1705394463; 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=yGIzhL7QiBJFkwlC84l4JtgAxPW7nCL9ZrpZ+JYeVUM=; b=X8feB6RdVzAyIDWKaxrPM5XqQXDSbzmz0Ct22lN3+kgcSxUVyZ2SG4CHu013tkT51i 45iouW2/YC9/6a360jROgRbR7nBIFWCI1VcaQ3vt4qA1BWI4+9AOMZnlEh2G1DXyz4eO xT06Mnm5jzmrMngy6UBsEk9x+FPs+475XGFV12kikJ3M1EmXYq8al+q7mEtZLleE2xPG yD1DeGA6ZRza+WSHlM59WdFfYPbqX9y3OyRlTjTQyr/mjbuX/Bnvb7Wy2aqZwWCSz1jO LX+Bga6H9LTqje2L3rzKZ7eupUSN9mCHLl2GwSBBGCDHIyTtpwGOLTOIHN2872CG+826 iVlw== X-Gm-Message-State: AOJu0YzFD5EBdBVIsGXEZ109A9Z42ZJy7JSSiIFlsZ3/cc1SVTEiI7dW lRYzaRz1nDiqXZo/uKkKzr2lJ2kJ/MeuyxONgMmrhnZjEEG6WlYCq55t4pu9D2msP25DxMbiuoE m5RCnOPjUX+8+rfBPV4z+pnC2Nw3JhM7egofE+p5d/tTc9c5sd8l6DPj4BKDdsPqukI0bhMhPVQ KUr37k5SX1g9aCTiOp1dDRu6Q= X-Google-Smtp-Source: AGHT+IFwhg0QPgY1zieo2mYaER5J++Hqqx/FALBiHvj1m0CoJbfRm3Oju7tMnr9qpw3bVSOjNCfmzg== X-Received: by 2002:a17:90b:4d8e:b0:28c:be1d:71b with SMTP id oj14-20020a17090b4d8e00b0028cbe1d071bmr2072134pjb.24.1704789663221; Tue, 09 Jan 2024 00:41:03 -0800 (PST) Received: from amakhalov-build-vm.eng.vmware.com ([128.177.82.146]) by smtp.gmail.com with ESMTPSA id sf15-20020a17090b51cf00b0028d435cc2cbsm4772293pjb.15.2024.01.09.00.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 00:41:02 -0800 (PST) From: Alexey Makhalov X-Google-Original-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, namit@vmware.com, timothym@vmware.com, akaher@vmware.com, jsipek@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 Subject: [PATCH v6 1/7] x86/vmware: Move common macros to vmware.h Date: Tue, 9 Jan 2024 00:40:46 -0800 Message-Id: <20240109084052.58661-2-amakhalov@vmware.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240109084052.58661-1-amakhalov@vmware.com> References: <20240109084052.58661-1-amakhalov@vmware.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move VMware hypercall macros to vmware.h. This is a prerequisite for the introduction of vmware_hypercall API. No functional changes besides exporting vmware_hypercall_mode symbol. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit --- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++------ arch/x86/kernel/cpu/vmware.c | 57 +++------------------------ 2 files changed, 66 insertions(+), 63 deletions(-) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index ac9fc51e2b18..de2533337611 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -8,25 +8,34 @@ =20 /* * The hypercall definitions differ in the low word of the %edx argument - * in the following way: the old port base interface uses the port - * number to distinguish between high- and low bandwidth versions. + * in the following way: the old I/O port based interface uses the port + * number to distinguish between high- and low bandwidth versions, and + * uses IN/OUT instructions to define transfer direction. * * The new vmcall interface instead uses a set of flags to select * bandwidth mode and transfer direction. The flags should be loaded * into %dx by any user and are automatically replaced by the port - * number if the VMWARE_HYPERVISOR_PORT method is used. - * - * In short, new driver code should strictly use the new definition of - * %dx content. + * number if the I/O port method is used. */ =20 -/* Old port-based version */ -#define VMWARE_HYPERVISOR_PORT 0x5658 -#define VMWARE_HYPERVISOR_PORT_HB 0x5659 +#define VMWARE_HYPERVISOR_HB BIT(0) +#define VMWARE_HYPERVISOR_OUT BIT(1) + +#define VMWARE_HYPERVISOR_PORT 0x5658 +#define VMWARE_HYPERVISOR_PORT_HB (VMWARE_HYPERVISOR_PORT | \ + VMWARE_HYPERVISOR_HB) + +#define VMWARE_HYPERVISOR_MAGIC 0x564d5868U + +#define VMWARE_CMD_GETVERSION 10 +#define VMWARE_CMD_GETHZ 45 +#define VMWARE_CMD_GETVCPU_INFO 68 +#define VMWARE_CMD_STEALCLOCK 91 + +#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) +#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) =20 -/* Current vmcall / vmmcall version */ -#define VMWARE_HYPERVISOR_HB BIT(0) -#define VMWARE_HYPERVISOR_OUT BIT(1) +extern u8 vmware_hypercall_mode; =20 /* The low bandwidth call. The low word of edx is presumed clear. */ #define VMWARE_HYPERCALL \ @@ -54,4 +63,43 @@ "rep insb", \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) + +#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ + __asm__("inl (%%dx), %%eax" : \ + "=3Da"(eax), "=3Dc"(ecx), "=3Dd"(edx), "=3Db"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMCALL(cmd, eax, ebx, ecx, edx) \ + __asm__("vmcall" : \ + "=3Da"(eax), "=3Dc"(ecx), "=3Dd"(edx), "=3Db"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx) \ + __asm__("vmmcall" : \ + "=3Da"(eax), "=3Dc"(ecx), "=3Dd"(edx), "=3Db"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_CMD(cmd, eax, ebx, ecx, edx) do { \ + switch (vmware_hypercall_mode) { \ + case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ + VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ + VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + default: \ + VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ + break; \ + } \ + } while (0) + #endif diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 11f83d07925e..4db8e1daa4a1 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -41,60 +41,14 @@ =20 #define CPUID_VMWARE_INFO_LEAF 0x40000000 #define CPUID_VMWARE_FEATURES_LEAF 0x40000010 -#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) -#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) =20 -#define VMWARE_HYPERVISOR_MAGIC 0x564D5868 - -#define VMWARE_CMD_GETVERSION 10 -#define VMWARE_CMD_GETHZ 45 -#define VMWARE_CMD_GETVCPU_INFO 68 -#define VMWARE_CMD_LEGACY_X2APIC 3 -#define VMWARE_CMD_VCPU_RESERVED 31 -#define VMWARE_CMD_STEALCLOCK 91 +#define VCPU_LEGACY_X2APIC 3 +#define VCPU_RESERVED 31 =20 #define STEALCLOCK_NOT_AVAILABLE (-1) #define STEALCLOCK_DISABLED 0 #define STEALCLOCK_ENABLED 1 =20 -#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ - __asm__("inl (%%dx), %%eax" : \ - "=3Da"(eax), "=3Dc"(ecx), "=3Dd"(edx), "=3Db"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMCALL(cmd, eax, ebx, ecx, edx) \ - __asm__("vmcall" : \ - "=3Da"(eax), "=3Dc"(ecx), "=3Dd"(edx), "=3Db"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx) \ - __asm__("vmmcall" : \ - "=3Da"(eax), "=3Dc"(ecx), "=3Dd"(edx), "=3Db"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_CMD(cmd, eax, ebx, ecx, edx) do { \ - switch (vmware_hypercall_mode) { \ - case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ - VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ - VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - default: \ - VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ - break; \ - } \ - } while (0) - struct vmware_steal_time { union { uint64_t clock; /* stolen time counter in units of vtsc */ @@ -108,7 +62,8 @@ struct vmware_steal_time { }; =20 static unsigned long vmware_tsc_khz __ro_after_init; -static u8 vmware_hypercall_mode __ro_after_init; +u8 vmware_hypercall_mode __ro_after_init; +EXPORT_SYMBOL_GPL(vmware_hypercall_mode); =20 static inline int __vmware_platform(void) { @@ -476,8 +431,8 @@ static bool __init vmware_legacy_x2apic_available(void) { uint32_t eax, ebx, ecx, edx; VMWARE_CMD(GETVCPU_INFO, eax, ebx, ecx, edx); - return !(eax & BIT(VMWARE_CMD_VCPU_RESERVED)) && - (eax & BIT(VMWARE_CMD_LEGACY_X2APIC)); + return !(eax & BIT(VCPU_RESERVED)) && + (eax & BIT(VCPU_LEGACY_X2APIC)); } =20 #ifdef CONFIG_AMD_MEM_ENCRYPT --=20 2.39.0 From nobody Fri Dec 26 05:29:59 2025 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 0564E364B9 for ; Tue, 9 Jan 2024 08:41:06 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="SQZjHs1J" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6d9bec20980so1212185b3a.2 for ; Tue, 09 Jan 2024 00:41:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1704789666; x=1705394466; 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=JTBheJ0yx/IBrzgt25TIRXHMWXRBVoQjsLuJ3eOyhd0=; b=SQZjHs1JPS/mnWB85XIOQnuPhsQk5y5CKK8xDSiCvno9WrP9/gCsqHlTYeH1YUKiP8 plI0/kXnzHbVhHdBMl+vaCHu5TPklCmciNia8dqHsM6R9nn+LUHQiEU17Ud7boiOu16n lSzoMZkUU+FdJ7oi20BawDUzln2Ig64sMZNGE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704789666; x=1705394466; 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=JTBheJ0yx/IBrzgt25TIRXHMWXRBVoQjsLuJ3eOyhd0=; b=nSKa/8ffIbY1idSv8qR4Qpa6hhs5mwVpCgDzN7WImL5Ep7molxQ2xMdkGwfwC2/VW1 WTg8+K1Yre4y4easkSpq0X2QPullMsBPNeShiLtTfL0YpVzPSPcG7bVcnDGj8W873Vam Lk/E6SZbl+o9akFN6urKXW66Nve3AjGKkRCS1fDp2EJcIF6j/SShHV8d67pfNbNX7c1A 0M5CupgOD6AgtR/nQabR3qF5YYtBEXFQYOpQppEpPZKwnPxqQXytl50NnzpFSl/NrkwC 4wBKFhXlVJIM1UTX6qfZICgZYQ7iTdqaE//64NgHobgH1FJbB9BfbjYC+u9tyQyshOu2 HA1A== X-Gm-Message-State: AOJu0YxwafHHluROkyO3AmHhmaeKXKGE4s9rEyCKEhpIEQcR4EljATZE MczxMw9veLPlOT/jBhwlG//w9Iukc+vrg/CJW7N2gBxVqIYWQpr7xM68OhjntTD4bFtiPlUyqq/ IedhMZlmMGBtt27jGkWDZFybfWLIHRpetubmPYDXGQEg0YLBGkOVV09ogQRdLTNEKElrqmvVjUH Re9zZwhyAUlJHJ4z8dHB3qsYI= X-Google-Smtp-Source: AGHT+IGBE6XIXMUc4laEpuRDUpZXQvJvaTfNJ/ADIzbkQ6endzb8AhfC7UGOs2v31/huC+/hP2Zm8A== X-Received: by 2002:a05:6a20:3d93:b0:199:8b61:b2d with SMTP id s19-20020a056a203d9300b001998b610b2dmr1777313pzi.40.1704789665730; Tue, 09 Jan 2024 00:41:05 -0800 (PST) Received: from amakhalov-build-vm.eng.vmware.com ([128.177.82.146]) by smtp.gmail.com with ESMTPSA id sf15-20020a17090b51cf00b0028d435cc2cbsm4772293pjb.15.2024.01.09.00.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 00:41:05 -0800 (PST) From: Alexey Makhalov X-Google-Original-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, namit@vmware.com, timothym@vmware.com, akaher@vmware.com, jsipek@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 Subject: [PATCH v6 2/7] x86/vmware: Introduce VMware hypercall API Date: Tue, 9 Jan 2024 00:40:47 -0800 Message-Id: <20240109084052.58661-3-amakhalov@vmware.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240109084052.58661-1-amakhalov@vmware.com> References: <20240109084052.58661-1-amakhalov@vmware.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce vmware_hypercall family of functions. It is a common implementation to be used by the VMware guest code and virtual device drivers in architecture independent manner. The API consists of vmware_hypercallX and vmware_hypercall_hb_{out,in} set of functions by analogy with KVM hypercall API. Architecture specific implementation is hidden inside. It will simplify future enhancements in VMware hypercalls such as SEV-ES and TDX related changes without needs to modify a caller in device drivers code. Current implementation extends an idea from commit bac7b4e84323 ("x86/vmware: Update platform detection code for VMCALL/VMMCALL hypercalls") to have a slow, but safe path in VMWARE_HYPERCALL earlier during the boot when alternatives are not yet applied. This logic was inherited from VMWARE_CMD from the commit mentioned above. Default alternative code was optimized by size to reduce excessive nop alignment once alternatives are applied. Total default code size is 26 bytes, in worse case (3 bytes alternative) remaining 23 bytes will be aligned by only 3 long NOP instructions. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit Reviewed-by: Jeff Sipek --- arch/x86/include/asm/vmware.h | 288 +++++++++++++++++++----- arch/x86/kernel/cpu/vmware.c | 35 ++- drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 6 +- drivers/input/mouse/vmmouse.c | 2 + drivers/ptp/ptp_vmw.c | 2 + 5 files changed, 252 insertions(+), 81 deletions(-) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index de2533337611..2ac87068184a 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -7,14 +7,37 @@ #include =20 /* - * The hypercall definitions differ in the low word of the %edx argument + * VMware hypercall ABI. + * + * - Low bandwidth (LB) hypercalls (I/O port based, vmcall and vmmcall) + * have up to 6 input and 6 output arguments passed and returned using + * registers: %eax (arg0), %ebx (arg1), %ecx (arg2), %edx (arg3), + * %esi (arg4), %edi (arg5). + * The following input arguments must be initialized by the caller: + * arg0 - VMWARE_HYPERVISOR_MAGIC + * arg2 - Hypercall command + * arg3 bits [15:0] - Port number, LB and direction flags + * + * - 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), + * %esi (arg4), %edi (arg5), %ebp (arg6). + * The following input arguments must be initialized by the caller: + * arg0 - VMWARE_HYPERVISOR_MAGIC + * arg1 - Hypercall command + * arg3 bits [15:0] - Port number, HB and direction flags + * + * For compatibility purposes, x86_64 systems use only lower 32 bits + * for input and output arguments. + * + * The hypercall definitions differ in the low word of the %edx (arg3) * in the following way: the old I/O port based interface uses the port * number to distinguish between high- and low bandwidth versions, and * uses IN/OUT instructions to define transfer direction. * * The new vmcall interface instead uses a set of flags to select * bandwidth mode and transfer direction. The flags should be loaded - * into %dx by any user and are automatically replaced by the port + * into arg3 by any user and are automatically replaced by the port * number if the I/O port method is used. */ =20 @@ -37,69 +60,218 @@ =20 extern u8 vmware_hypercall_mode; =20 -/* The low bandwidth call. The low word of edx is presumed clear. */ -#define VMWARE_HYPERCALL \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT) ", %%dx; " \ - "inl (%%dx), %%eax", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) - /* - * The high bandwidth out call. The low word of edx is presumed to have the - * HB and OUT bits set. + * 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. */ -#define VMWARE_HYPERCALL_HB_OUT \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep outsb", \ +#define VMWARE_HYPERCALL \ + ALTERNATIVE_3("cmpb $" \ + __stringify(CPUID_VMWARE_FEATURES_ECX_VMMCALL) \ + ", %[mode]\n\t" \ + "jg 2f\n\t" \ + "je 1f\n\t" \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax\n\t" \ + "jmp 3f\n\t" \ + "1: vmmcall\n\t" \ + "jmp 3f\n\t" \ + "2: vmcall\n\t" \ + "3:\n\t", \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax", X86_FEATURE_HYPERVISOR, \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) =20 +static inline +unsigned long vmware_hypercall1(unsigned long cmd, unsigned long in1) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=3Da" (out0) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (in1), + "c" (cmd), + "d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall3(unsigned long cmd, unsigned long in1, + uint32_t *out1, uint32_t *out2) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (in1), + "c" (cmd), + "d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall4(unsigned long cmd, unsigned long in1, + uint32_t *out1, uint32_t *out2, + uint32_t *out3) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2), "=3Dd" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (in1), + "c" (cmd), + "d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall5(unsigned long cmd, unsigned long in1, + unsigned long in3, unsigned long in4, + unsigned long in5, uint32_t *out2) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=3Da" (out0), "=3Dc" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (in1), + "c" (cmd), + "d" (in3), + "S" (in4), + "D" (in5) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall6(unsigned long cmd, unsigned long in1, + unsigned long in3, uint32_t *out2, + uint32_t *out3, uint32_t *out4, + uint32_t *out5) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=3Da" (out0), "=3Dc" (*out2), "=3Dd" (*out3), "=3DS" (*out4), + "=3DD" (*out5) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (in1), + "c" (cmd), + "d" (in3) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall7(unsigned long cmd, unsigned long in1, + unsigned long in3, unsigned long in4, + unsigned long in5, uint32_t *out1, + uint32_t *out2, uint32_t *out3) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2), "=3Dd" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (in1), + "c" (cmd), + "d" (in3), + "S" (in4), + "D" (in5) + : "cc", "memory"); + return out0; +} + + +#ifdef CONFIG_X86_64 +#define VMW_BP_REG "%%rbp" +#define VMW_BP_CONSTRAINT "r" +#else +#define VMW_BP_REG "%%ebp" +#define VMW_BP_CONSTRAINT "m" +#endif + /* - * The high bandwidth in call. The low word of edx is presumed to have the - * HB bit set. + * High bandwidth calls are not supported on encrypted memory guests. + * The caller should check cc_platform_has(CC_ATTR_MEM_ENCRYPT) and use + * low bandwidth hypercall it memory encryption is set. + * This assumption simplifies HB hypercall impementation to just I/O port + * based approach without alternative patching. */ -#define VMWARE_HYPERCALL_HB_IN \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep insb", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) +static inline +unsigned long vmware_hypercall_hb_out(unsigned long cmd, unsigned long in2, + unsigned long in3, unsigned long in4, + unsigned long in5, unsigned long in6, + uint32_t *out1) +{ + unsigned long out0; + + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep outsb\n\t" + "pop " VMW_BP_REG "\n\t" + UNWIND_HINT_RESTORE + : "=3Da" (out0), "=3Db" (*out1) + : "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (cmd), + "c" (in2), + "d" (in3 | VMWARE_HYPERVISOR_PORT_HB), + "S" (in4), + "D" (in5), + [in6] VMW_BP_CONSTRAINT (in6) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall_hb_in(unsigned long cmd, unsigned long in2, + unsigned long in3, unsigned long in4, + unsigned long in5, unsigned long in6, + uint32_t *out1) +{ + unsigned long out0; =20 -#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ - __asm__("inl (%%dx), %%eax" : \ - "=3Da"(eax), "=3Dc"(ecx), "=3Dd"(edx), "=3Db"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMCALL(cmd, eax, ebx, ecx, edx) \ - __asm__("vmcall" : \ - "=3Da"(eax), "=3Dc"(ecx), "=3Dd"(edx), "=3Db"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx) \ - __asm__("vmmcall" : \ - "=3Da"(eax), "=3Dc"(ecx), "=3Dd"(edx), "=3Db"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_CMD(cmd, eax, ebx, ecx, edx) do { \ - switch (vmware_hypercall_mode) { \ - case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ - VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ - VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - default: \ - VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ - break; \ - } \ - } while (0) + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep insb\n\t" + "pop " VMW_BP_REG "\n\t" + UNWIND_HINT_RESTORE + : "=3Da" (out0), "=3Db" (*out1) + : "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (cmd), + "c" (in2), + "d" (in3 | VMWARE_HYPERVISOR_PORT_HB), + "S" (in4), + "D" (in5), + [in6] VMW_BP_CONSTRAINT (in6) + : "cc", "memory"); + return out0; +} +#undef VMW_BP_REG +#undef VMW_BP_CONSTRAINT =20 #endif diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 4db8e1daa4a1..3aa1adaed18f 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -67,9 +67,10 @@ EXPORT_SYMBOL_GPL(vmware_hypercall_mode); =20 static inline int __vmware_platform(void) { - uint32_t eax, ebx, ecx, edx; - VMWARE_CMD(GETVERSION, eax, ebx, ecx, edx); - return eax !=3D (uint32_t)-1 && ebx =3D=3D VMWARE_HYPERVISOR_MAGIC; + uint32_t eax, ebx, ecx; + + eax =3D vmware_hypercall3(VMWARE_CMD_GETVERSION, 0, &ebx, &ecx); + return eax !=3D UINT_MAX && ebx =3D=3D VMWARE_HYPERVISOR_MAGIC; } =20 static unsigned long vmware_get_tsc_khz(void) @@ -121,21 +122,12 @@ static void __init vmware_cyc2ns_setup(void) pr_info("using clock offset of %llu ns\n", d->cyc2ns_offset); } =20 -static int vmware_cmd_stealclock(uint32_t arg1, uint32_t arg2) +static int vmware_cmd_stealclock(uint32_t addr_hi, uint32_t addr_lo) { - uint32_t result, info; - - asm volatile (VMWARE_HYPERCALL : - "=3Da"(result), - "=3Dc"(info) : - "a"(VMWARE_HYPERVISOR_MAGIC), - "b"(0), - "c"(VMWARE_CMD_STEALCLOCK), - "d"(0), - "S"(arg1), - "D"(arg2) : - "memory"); - return result; + uint32_t info; + + return vmware_hypercall5(VMWARE_CMD_STEALCLOCK, 0, 0, addr_hi, addr_lo, + &info); } =20 static bool stealclock_enable(phys_addr_t pa) @@ -344,10 +336,10 @@ static void __init vmware_set_capabilities(void) =20 static void __init vmware_platform_setup(void) { - uint32_t eax, ebx, ecx, edx; + uint32_t eax, ebx, ecx; uint64_t lpj, tsc_khz; =20 - VMWARE_CMD(GETHZ, eax, ebx, ecx, edx); + eax =3D vmware_hypercall3(VMWARE_CMD_GETHZ, UINT_MAX, &ebx, &ecx); =20 if (ebx !=3D UINT_MAX) { lpj =3D tsc_khz =3D eax | (((uint64_t)ebx) << 32); @@ -429,8 +421,9 @@ static uint32_t __init vmware_platform(void) /* Checks if hypervisor supports x2apic without VT-D interrupt remapping. = */ static bool __init vmware_legacy_x2apic_available(void) { - uint32_t eax, ebx, ecx, edx; - VMWARE_CMD(GETVCPU_INFO, eax, ebx, ecx, edx); + uint32_t eax; + + eax =3D vmware_hypercall1(VMWARE_CMD_GETVCPU_INFO, 0); return !(eax & BIT(VCPU_RESERVED)) && (eax & BIT(VCPU_LEGACY_X2APIC)); } diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h b/drivers/gpu/drm/vmwg= fx/vmwgfx_msg_x86.h index 23899d743a90..e040ee21ea1a 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h @@ -68,6 +68,8 @@ "=3Dd"(edx), \ "=3DS"(si), \ "=3DD"(di) : \ + [port] "i" (VMWARE_HYPERVISOR_PORT), \ + [mode] "m" (vmware_hypercall_mode), \ "a"(magic), \ "b"(in_ebx), \ "c"(cmd), \ @@ -110,7 +112,7 @@ "push %%rbp;" \ UNWIND_HINT_UNDEFINED \ "mov %12, %%rbp;" \ - VMWARE_HYPERCALL_HB_OUT \ + "rep outsb;" \ "pop %%rbp;" \ UNWIND_HINT_RESTORE : \ "=3Da"(eax), \ @@ -139,7 +141,7 @@ "push %%rbp;" \ UNWIND_HINT_UNDEFINED \ "mov %12, %%rbp;" \ - VMWARE_HYPERCALL_HB_IN \ + "rep insb;" \ "pop %%rbp;" \ UNWIND_HINT_RESTORE : \ "=3Da"(eax), \ diff --git a/drivers/input/mouse/vmmouse.c b/drivers/input/mouse/vmmouse.c index ea9eff7c8099..ad94c835ee66 100644 --- a/drivers/input/mouse/vmmouse.c +++ b/drivers/input/mouse/vmmouse.c @@ -91,6 +91,8 @@ struct vmmouse_data { "=3Dd"(out4), \ "=3DS"(__dummy1), \ "=3DD"(__dummy2) : \ + [port] "i" (VMWARE_HYPERVISOR_PORT), \ + [mode] "m" (vmware_hypercall_mode), \ "a"(VMMOUSE_PROTO_MAGIC), \ "b"(in1), \ "c"(VMMOUSE_PROTO_CMD_##cmd), \ diff --git a/drivers/ptp/ptp_vmw.c b/drivers/ptp/ptp_vmw.c index 27c5547aa8a9..279d191d2df9 100644 --- a/drivers/ptp/ptp_vmw.c +++ b/drivers/ptp/ptp_vmw.c @@ -29,6 +29,8 @@ static int ptp_vmw_pclk_read(u64 *ns) asm volatile (VMWARE_HYPERCALL : "=3Da"(ret), "=3Db"(nsec_hi), "=3Dc"(nsec_lo), "=3Dd"(unused1), "=3DS"(unused2), "=3DD"(unused3) : + [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), "a"(VMWARE_MAGIC), "b"(0), "c"(VMWARE_CMD_PCLK_GETTIME), "d"(0) : "memory"); --=20 2.39.0 From nobody Fri Dec 26 05:29:59 2025 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 39D24364DF for ; Tue, 9 Jan 2024 08:41:09 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="DMVXD8d2" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-28bd623c631so2487739a91.3 for ; Tue, 09 Jan 2024 00:41:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1704789668; x=1705394468; 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=FPJVwuu4FbYV5iHDsqoRPE2dBrY067QdoWIAplCPCFE=; b=DMVXD8d2ot/QyaFPTd3zHlKeSnOax3L3T3NmsFRPUqGItdLIKwOm0jDEuK2ZHcN4mi /4Cx0xNTs4IHdGkE+S97j8ZCuOtUfukNspTWqps179yI+swRvBeN6CRmtQnSagHVzXWg OTauDj9RSjU61oLgoXYFciA+FsyScRBU4is8E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704789668; x=1705394468; 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=FPJVwuu4FbYV5iHDsqoRPE2dBrY067QdoWIAplCPCFE=; b=hNU30DBYEpq77s61gTczXHLBhsUAG+1ZaZb7A1C6j6SWgydE5204Kie4zPzi2+2Uxz hMrCbUBjf7aY5oTStIntRJeNU2oPG19j046/l1SAhaP9pJ2b9MUV1gvPbK6j+Cwgv0Ul XSuL/n6H9JNNgPz+wJHgQEs9F6vKFNUh1mWktaBING4nafX2f01kEQTyhMEe5IX8xVDE 5SjMxONwNuW+FPEoYxBoBUWLEi2cgSu3+u3jQuAEO+ZR61Ah/uRjVpyrC2J2QugZkXci muIin9rk2sinop5PIbtAz+qf3Fxzv6g8IBSRS8qzm9U8ZYEHsfOcVh9mCXTFZUZhpm0t szVA== X-Gm-Message-State: AOJu0YxjNXkVwoq3JVXG5s9b1vRrIen+1oIWvUpP4rPZbhkxcK8erjlJ HT/PcqL24nT2cUpN7JpmsT2t5N7IuGEjsIsYxIVWPRqzjqypkeq0UjNAYfMSO0UcQsFEizXfXLh +B+BkM5LJWSUBlpz3mZzUM+wF7a8w2L5DxdPVh+p2/JDxkQ0ofatQ1UTdbHiQ9oSGuLrRE5oOr1 iqDcUAJMf+URvOL9zqwdlT2Ug= X-Google-Smtp-Source: AGHT+IHAPtZomE9mWKHoozKKh5MePdVFthGgcxrjU58Rdxj6mVhm/Q5Fx+S7eOIDUdrTFXC0gW+1xQ== X-Received: by 2002:a17:90a:c392:b0:28c:825e:2cf4 with SMTP id h18-20020a17090ac39200b0028c825e2cf4mr2891154pjt.41.1704789668319; Tue, 09 Jan 2024 00:41:08 -0800 (PST) Received: from amakhalov-build-vm.eng.vmware.com ([128.177.82.146]) by smtp.gmail.com with ESMTPSA id sf15-20020a17090b51cf00b0028d435cc2cbsm4772293pjb.15.2024.01.09.00.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 00:41:07 -0800 (PST) From: Alexey Makhalov X-Google-Original-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, namit@vmware.com, timothym@vmware.com, akaher@vmware.com, jsipek@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 Subject: [PATCH v6 3/7] ptp/vmware: Use VMware hypercall API Date: Tue, 9 Jan 2024 00:40:48 -0800 Message-Id: <20240109084052.58661-4-amakhalov@vmware.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240109084052.58661-1-amakhalov@vmware.com> References: <20240109084052.58661-1-amakhalov@vmware.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit Reviewed-by: Jeff Sipek --- drivers/ptp/ptp_vmw.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/ptp/ptp_vmw.c b/drivers/ptp/ptp_vmw.c index 279d191d2df9..e5bb521b9b82 100644 --- a/drivers/ptp/ptp_vmw.c +++ b/drivers/ptp/ptp_vmw.c @@ -14,7 +14,6 @@ #include #include =20 -#define VMWARE_MAGIC 0x564D5868 #define VMWARE_CMD_PCLK(nr) ((nr << 16) | 97) #define VMWARE_CMD_PCLK_GETTIME VMWARE_CMD_PCLK(0) =20 @@ -24,17 +23,10 @@ static struct ptp_clock *ptp_vmw_clock; =20 static int ptp_vmw_pclk_read(u64 *ns) { - u32 ret, nsec_hi, nsec_lo, unused1, unused2, unused3; - - asm volatile (VMWARE_HYPERCALL : - "=3Da"(ret), "=3Db"(nsec_hi), "=3Dc"(nsec_lo), "=3Dd"(unused1), - "=3DS"(unused2), "=3DD"(unused3) : - [port] "i" (VMWARE_HYPERVISOR_PORT), - [mode] "m" (vmware_hypercall_mode), - "a"(VMWARE_MAGIC), "b"(0), - "c"(VMWARE_CMD_PCLK_GETTIME), "d"(0) : - "memory"); + u32 ret, nsec_hi, nsec_lo; =20 + ret =3D vmware_hypercall3(VMWARE_CMD_PCLK_GETTIME, 0, + &nsec_hi, &nsec_lo); if (ret =3D=3D 0) *ns =3D ((u64)nsec_hi << 32) | nsec_lo; return ret; --=20 2.39.0 From nobody Fri Dec 26 05:29:59 2025 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 8EA4537144 for ; Tue, 9 Jan 2024 08:41:11 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="PVdwNc7v" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-28bc870c540so2363456a91.2 for ; Tue, 09 Jan 2024 00:41:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1704789671; x=1705394471; 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=SEgaCDdnwo0fD24sb4/z6MOqtwJ556s/e7KBa+2g7Wk=; b=PVdwNc7vpkZoU8b8ai6hLKFKYd1pOeng6wjjcCWU4ucR+iQ62Jmwe8h8LR6PKm/inf dR8yQ5HwI2bxDRlI+ox2uHTYEI+fQhbRItIlfQNscdfcytFOvz/hf2BekFaQfSStccJi eq4Hy+sFj8EwJUibMDtWDcbxwJMWPjce3qTWk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704789671; x=1705394471; 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=SEgaCDdnwo0fD24sb4/z6MOqtwJ556s/e7KBa+2g7Wk=; b=Y05zj3MtWhaVRKMV6yKLKtO6/K/1+LSTrtzg38UPARUiSHY6MUMiBSVFmJqJbIV+VS sScsIiNiDVgKZdGynGeH6ESaXxXAT/0JLnrrHEozNY195j7LIdt7Xw7Ppvl6nbThVDhi 63uh9MH5L5ee1lJoaOSqRmgBTohEf601tSohvnZZ2OUqa0jHfCoUv1C9QRgcawkW5yuj WZ96eslfNQBN5FNyfjC65lkvZ3p5eI1j0SrVq28tDy5fJwYNO43amOOD217vVIfMdkEG K1eJnPXbofDBkU6FwRHStd8uObIzkRiW7nzcsgKZINm1wHzldfOokPNP9OtIQjgupVKb nLsg== X-Gm-Message-State: AOJu0YzmMmnjo/LjmSf9W3X7zpQcPV6tobjVTB9hl8PvKK+jkr7CxT+E Y8BE9HGoyACPJVXA80b6rgMV56vdWKuvj23tC6ntEdZ134i/1k1vCyu1z0C9x7omPssWmQvrCJz W8o6ZJOSQHQBooSaq0Ow4XhpfDwzXQmIMRjpH++0IVo+XvOF+Ozhev/n3gvTsp7cuWWFOJUpiuj 1OOFI4wiaESL1UyH4VhnQq5uA= X-Google-Smtp-Source: AGHT+IF4zprEYtAB/zOYraKqOcdK6uqYclm+dCePYYQaPiX59pDcuOolguML72v3YC4fFVOtSyvgZw== X-Received: by 2002:a17:90b:468e:b0:285:b78a:dbce with SMTP id ir14-20020a17090b468e00b00285b78adbcemr2589756pjb.37.1704789670702; Tue, 09 Jan 2024 00:41:10 -0800 (PST) Received: from amakhalov-build-vm.eng.vmware.com ([128.177.82.146]) by smtp.gmail.com with ESMTPSA id sf15-20020a17090b51cf00b0028d435cc2cbsm4772293pjb.15.2024.01.09.00.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 00:41:10 -0800 (PST) From: Alexey Makhalov X-Google-Original-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, namit@vmware.com, timothym@vmware.com, akaher@vmware.com, jsipek@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 Subject: [PATCH v6 4/7] input/vmmouse: Use VMware hypercall API Date: Tue, 9 Jan 2024 00:40:49 -0800 Message-Id: <20240109084052.58661-5-amakhalov@vmware.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240109084052.58661-1-amakhalov@vmware.com> References: <20240109084052.58661-1-amakhalov@vmware.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit Reviewed-by: Zack Rusin Acked-by: Dmitry Torokhov --- drivers/input/mouse/vmmouse.c | 78 ++++++++++------------------------- 1 file changed, 22 insertions(+), 56 deletions(-) diff --git a/drivers/input/mouse/vmmouse.c b/drivers/input/mouse/vmmouse.c index ad94c835ee66..fb1d986a6895 100644 --- a/drivers/input/mouse/vmmouse.c +++ b/drivers/input/mouse/vmmouse.c @@ -21,19 +21,16 @@ #include "psmouse.h" #include "vmmouse.h" =20 -#define VMMOUSE_PROTO_MAGIC 0x564D5868U - /* * Main commands supported by the vmmouse hypervisor port. */ -#define VMMOUSE_PROTO_CMD_GETVERSION 10 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_DATA 39 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_STATUS 40 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND 41 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_RESTRICT 86 +#define VMWARE_CMD_ABSPOINTER_DATA 39 +#define VMWARE_CMD_ABSPOINTER_STATUS 40 +#define VMWARE_CMD_ABSPOINTER_COMMAND 41 +#define VMWARE_CMD_ABSPOINTER_RESTRICT 86 =20 /* - * Subcommands for VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND + * Subcommands for VMWARE_CMD_ABSPOINTER_COMMAND */ #define VMMOUSE_CMD_ENABLE 0x45414552U #define VMMOUSE_CMD_DISABLE 0x000000f5U @@ -76,30 +73,6 @@ struct vmmouse_data { char dev_name[128]; }; =20 -/* - * Hypervisor-specific bi-directional communication channel - * implementing the vmmouse protocol. Should never execute on - * bare metal hardware. - */ -#define VMMOUSE_CMD(cmd, in1, out1, out2, out3, out4) \ -({ \ - unsigned long __dummy1, __dummy2; \ - __asm__ __volatile__ (VMWARE_HYPERCALL : \ - "=3Da"(out1), \ - "=3Db"(out2), \ - "=3Dc"(out3), \ - "=3Dd"(out4), \ - "=3DS"(__dummy1), \ - "=3DD"(__dummy2) : \ - [port] "i" (VMWARE_HYPERVISOR_PORT), \ - [mode] "m" (vmware_hypercall_mode), \ - "a"(VMMOUSE_PROTO_MAGIC), \ - "b"(in1), \ - "c"(VMMOUSE_PROTO_CMD_##cmd), \ - "d"(0) : \ - "memory"); \ -}) - /** * vmmouse_report_button - report button state on the correct input device * @@ -147,14 +120,12 @@ static psmouse_ret_t vmmouse_report_events(struct psm= ouse *psmouse) struct input_dev *abs_dev =3D priv->abs_dev; struct input_dev *pref_dev; u32 status, x, y, z; - u32 dummy1, dummy2, dummy3; unsigned int queue_length; unsigned int count =3D 255; =20 while (count--) { /* See if we have motion data. */ - VMMOUSE_CMD(ABSPOINTER_STATUS, 0, - status, dummy1, dummy2, dummy3); + status =3D vmware_hypercall1(VMWARE_CMD_ABSPOINTER_STATUS, 0); if ((status & VMMOUSE_ERROR) =3D=3D VMMOUSE_ERROR) { psmouse_err(psmouse, "failed to fetch status data\n"); /* @@ -174,7 +145,8 @@ static psmouse_ret_t vmmouse_report_events(struct psmou= se *psmouse) } =20 /* Now get it */ - VMMOUSE_CMD(ABSPOINTER_DATA, 4, status, x, y, z); + status =3D vmware_hypercall4(VMWARE_CMD_ABSPOINTER_DATA, 4, + &x, &y, &z); =20 /* * And report what we've got. Prefer to report button @@ -249,14 +221,10 @@ static psmouse_ret_t vmmouse_process_byte(struct psmo= use *psmouse) static void vmmouse_disable(struct psmouse *psmouse) { u32 status; - u32 dummy1, dummy2, dummy3, dummy4; - - VMMOUSE_CMD(ABSPOINTER_COMMAND, VMMOUSE_CMD_DISABLE, - dummy1, dummy2, dummy3, dummy4); =20 - VMMOUSE_CMD(ABSPOINTER_STATUS, 0, - status, dummy1, dummy2, dummy3); + vmware_hypercall1(VMWARE_CMD_ABSPOINTER_COMMAND, VMMOUSE_CMD_DISABLE); =20 + status =3D vmware_hypercall1(VMWARE_CMD_ABSPOINTER_STATUS, 0); if ((status & VMMOUSE_ERROR) !=3D VMMOUSE_ERROR) psmouse_warn(psmouse, "failed to disable vmmouse device\n"); } @@ -273,26 +241,24 @@ static void vmmouse_disable(struct psmouse *psmouse) static int vmmouse_enable(struct psmouse *psmouse) { u32 status, version; - u32 dummy1, dummy2, dummy3, dummy4; =20 /* * Try enabling the device. If successful, we should be able to * read valid version ID back from it. */ - VMMOUSE_CMD(ABSPOINTER_COMMAND, VMMOUSE_CMD_ENABLE, - dummy1, dummy2, dummy3, dummy4); + vmware_hypercall1(VMWARE_CMD_ABSPOINTER_COMMAND, VMMOUSE_CMD_ENABLE); =20 /* * See if version ID can be retrieved. */ - VMMOUSE_CMD(ABSPOINTER_STATUS, 0, status, dummy1, dummy2, dummy3); + status =3D vmware_hypercall1(VMWARE_CMD_ABSPOINTER_STATUS, 0); if ((status & 0x0000ffff) =3D=3D 0) { psmouse_dbg(psmouse, "empty flags - assuming no device\n"); return -ENXIO; } =20 - VMMOUSE_CMD(ABSPOINTER_DATA, 1 /* single item */, - version, dummy1, dummy2, dummy3); + version =3D vmware_hypercall1(VMWARE_CMD_ABSPOINTER_DATA, + 1 /* single item */); if (version !=3D VMMOUSE_VERSION_ID) { psmouse_dbg(psmouse, "Unexpected version value: %u vs %u\n", (unsigned) version, VMMOUSE_VERSION_ID); @@ -303,11 +269,11 @@ static int vmmouse_enable(struct psmouse *psmouse) /* * Restrict ioport access, if possible. */ - VMMOUSE_CMD(ABSPOINTER_RESTRICT, VMMOUSE_RESTRICT_CPL0, - dummy1, dummy2, dummy3, dummy4); + vmware_hypercall1(VMWARE_CMD_ABSPOINTER_RESTRICT, + VMMOUSE_RESTRICT_CPL0); =20 - VMMOUSE_CMD(ABSPOINTER_COMMAND, VMMOUSE_CMD_REQUEST_ABSOLUTE, - dummy1, dummy2, dummy3, dummy4); + vmware_hypercall1(VMWARE_CMD_ABSPOINTER_COMMAND, + VMMOUSE_CMD_REQUEST_ABSOLUTE); =20 return 0; } @@ -344,7 +310,7 @@ static bool vmmouse_check_hypervisor(void) */ int vmmouse_detect(struct psmouse *psmouse, bool set_properties) { - u32 response, version, dummy1, dummy2; + u32 response, version, type; =20 if (!vmmouse_check_hypervisor()) { psmouse_dbg(psmouse, @@ -353,9 +319,9 @@ int vmmouse_detect(struct psmouse *psmouse, bool set_pr= operties) } =20 /* Check if the device is present */ - response =3D ~VMMOUSE_PROTO_MAGIC; - VMMOUSE_CMD(GETVERSION, 0, version, response, dummy1, dummy2); - if (response !=3D VMMOUSE_PROTO_MAGIC || version =3D=3D 0xffffffffU) + response =3D ~VMWARE_HYPERVISOR_MAGIC; + version =3D vmware_hypercall3(VMWARE_CMD_GETVERSION, 0, &response, &type); + if (response !=3D VMWARE_HYPERVISOR_MAGIC || version =3D=3D 0xffffffffU) return -ENXIO; =20 if (set_properties) { --=20 2.39.0 From nobody Fri Dec 26 05:29:59 2025 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 654E9374D2 for ; Tue, 9 Jan 2024 08:41:14 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="RevAv1Dy" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d3eae5c1d7so11295095ad.2 for ; Tue, 09 Jan 2024 00:41:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1704789673; x=1705394473; 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=w4fqQW4tVkY4+iDxNTKrlMFni5bXA+fktb5wYdGHO48=; b=RevAv1DyaGJumXtHJHPwdIoB6HHeigqmJk19r3w6Fp/D1W9LIVrQ4VP76Zb8JnAbX5 g+sRE4da0UfP1yuL+Xw60Elr1u2JbOu/FaOpCk8nmrjmw5+O+iUnujjT1SNRupZgvkSM n6MBNw40jDq2Il3S3TYV046UzNl1yjKevASEM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704789673; x=1705394473; 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=w4fqQW4tVkY4+iDxNTKrlMFni5bXA+fktb5wYdGHO48=; b=N1dfGi0Qd2cSgw2rSfovwNbD4+ymCaXWPgNux5wRNSOpczeD8de6DsA3Cl9RRTq61R CTcp8NzcuT/6phKD7WaHMoTJsSI9D7FKbi6OatGk75XN8LUqnBa+SeZVNpq8GkxdCs00 xsl5T4tx/taG8ym6ZdipmNi3h+hLjM+u+pVJvpcHjxNH8Dw+E3s7SeYg/DP9ljD5cmv/ hYRfFiGdRfh9KW0/DelIvg5e9WdglxNpjiX7e0ZRD+6UG3dlbvt0UqkhUw0xuS5O6v0X 8s4WFsfVzjktIDwNV4m1zPsU0GjPoBzDoAoAYxlbbi/psaB/tcSmErZN+QHMcsg7hIdi oBzA== X-Gm-Message-State: AOJu0YywHED2RZx606/HknSMWjEmMoeYU2cvu/I0H4czOh7frLYw12RD 8zGcGN9rvn0BTqSCDNUJ9TgGZUCzFRTAmf6Om2P+vBoVH9yEd0mmmydvD21+xIKTD7Xpf+r6QZG jd5tM4seDikAUQWL3WUlwq4bAI99705YF+KpNYnwVe0YXElTdKgAY0uoEvpBuqrFcXOMZyQ+lbR EDEVfFz+LPRGa99cZu3zXJUHk= X-Google-Smtp-Source: AGHT+IFAD5bRsf3RR1HHFjMxMEpHlSJKTu+RpJzmzm9Ri3CTqL8Pqe45zwdmVg1YAVvo5tUtslFbJA== X-Received: by 2002:a17:90a:b112:b0:28c:acb8:b2a5 with SMTP id z18-20020a17090ab11200b0028cacb8b2a5mr2018612pjq.24.1704789673178; Tue, 09 Jan 2024 00:41:13 -0800 (PST) Received: from amakhalov-build-vm.eng.vmware.com ([128.177.82.146]) by smtp.gmail.com with ESMTPSA id sf15-20020a17090b51cf00b0028d435cc2cbsm4772293pjb.15.2024.01.09.00.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 00:41:12 -0800 (PST) From: Alexey Makhalov X-Google-Original-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, namit@vmware.com, timothym@vmware.com, akaher@vmware.com, jsipek@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 Subject: [PATCH v6 5/7] drm/vmwgfx: Use VMware hypercall API Date: Tue, 9 Jan 2024 00:40:50 -0800 Message-Id: <20240109084052.58661-6-amakhalov@vmware.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240109084052.58661-1-amakhalov@vmware.com> References: <20240109084052.58661-1-amakhalov@vmware.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h: implement arm64 variant of vmware_hypercall. And keep it here until introduction of ARM64 VMWare hypervisor interface. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit Reviewed-by: Zack Rusin --- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 173 +++++++------------ drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h | 197 +++++++++++++++------- drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 187 -------------------- 3 files changed, 197 insertions(+), 360 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/v= mwgfx_msg.c index 2651fe0ef518..1f15990d3934 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c @@ -48,8 +48,6 @@ =20 #define RETRIES 3 =20 -#define VMW_HYPERVISOR_MAGIC 0x564D5868 - #define VMW_PORT_CMD_MSG 30 #define VMW_PORT_CMD_HB_MSG 0 #define VMW_PORT_CMD_OPEN_CHANNEL (MSG_TYPE_OPEN << 16 | VMW_PORT_CMD_MSG) @@ -104,20 +102,18 @@ static const char* const mksstat_kern_name_desc[MKSST= AT_KERN_COUNT][2] =3D */ static int vmw_open_channel(struct rpc_channel *channel, unsigned int prot= ocol) { - unsigned long eax, ebx, ecx, edx, si =3D 0, di =3D 0; + u32 ecx, edx, esi, edi; =20 - VMW_PORT(VMW_PORT_CMD_OPEN_CHANNEL, - (protocol | GUESTMSG_FLAG_COOKIE), si, di, - 0, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall6(VMW_PORT_CMD_OPEN_CHANNEL, + (protocol | GUESTMSG_FLAG_COOKIE), 0, + &ecx, &edx, &esi, &edi); =20 if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) =3D=3D 0) return -EINVAL; =20 channel->channel_id =3D HIGH_WORD(edx); - channel->cookie_high =3D si; - channel->cookie_low =3D di; + channel->cookie_high =3D esi; + channel->cookie_low =3D edi; =20 return 0; } @@ -133,17 +129,13 @@ static int vmw_open_channel(struct rpc_channel *chann= el, unsigned int protocol) */ static int vmw_close_channel(struct rpc_channel *channel) { - unsigned long eax, ebx, ecx, edx, si, di; - - /* Set up additional parameters */ - si =3D channel->cookie_high; - di =3D channel->cookie_low; + u32 ecx; =20 - VMW_PORT(VMW_PORT_CMD_CLOSE_CHANNEL, - 0, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall5(VMW_PORT_CMD_CLOSE_CHANNEL, + 0, channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ecx); =20 if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) =3D=3D 0) return -EINVAL; @@ -163,24 +155,18 @@ static int vmw_close_channel(struct rpc_channel *chan= nel) static unsigned long vmw_port_hb_out(struct rpc_channel *channel, const char *msg, bool hb) { - unsigned long si, di, eax, ebx, ecx, edx; + u32 ebx, ecx; unsigned long msg_len =3D strlen(msg); =20 /* HB port can't access encrypted memory. */ if (hb && !cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { - unsigned long bp =3D channel->cookie_high; - u32 channel_id =3D (channel->channel_id << 16); - - si =3D (uintptr_t) msg; - di =3D channel->cookie_low; - - VMW_PORT_HB_OUT( + vmware_hypercall_hb_out( (MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG, - msg_len, si, di, - VMWARE_HYPERVISOR_HB | channel_id | - VMWARE_HYPERVISOR_OUT, - VMW_HYPERVISOR_MAGIC, bp, - eax, ebx, ecx, edx, si, di); + msg_len, + channel->channel_id << 16, + (uintptr_t) msg, channel->cookie_low, + channel->cookie_high, + &ebx); =20 return ebx; } @@ -194,14 +180,13 @@ static unsigned long vmw_port_hb_out(struct rpc_chann= el *channel, memcpy(&word, msg, bytes); msg_len -=3D bytes; msg +=3D bytes; - si =3D channel->cookie_high; - di =3D channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_MSG | (MSG_TYPE_SENDPAYLOAD << 16), - word, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + + vmware_hypercall5(VMW_PORT_CMD_MSG | + (MSG_TYPE_SENDPAYLOAD << 16), + word, channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ecx); } =20 return ecx; @@ -220,22 +205,17 @@ static unsigned long vmw_port_hb_out(struct rpc_chann= el *channel, static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *rep= ly, unsigned long reply_len, bool hb) { - unsigned long si, di, eax, ebx, ecx, edx; + u32 ebx, ecx, edx; =20 /* HB port can't access encrypted memory */ if (hb && !cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { - unsigned long bp =3D channel->cookie_low; - u32 channel_id =3D (channel->channel_id << 16); - - si =3D channel->cookie_high; - di =3D (uintptr_t) reply; - - VMW_PORT_HB_IN( + vmware_hypercall_hb_in( (MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG, - reply_len, si, di, - VMWARE_HYPERVISOR_HB | channel_id, - VMW_HYPERVISOR_MAGIC, bp, - eax, ebx, ecx, edx, si, di); + reply_len, + channel->channel_id << 16, + channel->cookie_high, + (uintptr_t) reply, channel->cookie_low, + &ebx); =20 return ebx; } @@ -245,14 +225,13 @@ static unsigned long vmw_port_hb_in(struct rpc_channe= l *channel, char *reply, while (reply_len) { unsigned int bytes =3D min_t(unsigned long, reply_len, 4); =20 - si =3D channel->cookie_high; - di =3D channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_MSG | (MSG_TYPE_RECVPAYLOAD << 16), - MESSAGE_STATUS_SUCCESS, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall7(VMW_PORT_CMD_MSG | + (MSG_TYPE_RECVPAYLOAD << 16), + MESSAGE_STATUS_SUCCESS, + channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx); =20 if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) =3D=3D 0) break; @@ -276,22 +255,18 @@ static unsigned long vmw_port_hb_in(struct rpc_channe= l *channel, char *reply, */ static int vmw_send_msg(struct rpc_channel *channel, const char *msg) { - unsigned long eax, ebx, ecx, edx, si, di; + u32 ebx, ecx; size_t msg_len =3D strlen(msg); int retries =3D 0; =20 while (retries < RETRIES) { retries++; =20 - /* Set up additional parameters */ - si =3D channel->cookie_high; - di =3D channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_SENDSIZE, - msg_len, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall5(VMW_PORT_CMD_SENDSIZE, + msg_len, channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ecx); =20 if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) =3D=3D 0) { /* Expected success. Give up. */ @@ -329,7 +304,7 @@ STACK_FRAME_NON_STANDARD(vmw_send_msg); static int vmw_recv_msg(struct rpc_channel *channel, void **msg, size_t *msg_len) { - unsigned long eax, ebx, ecx, edx, si, di; + u32 ebx, ecx, edx; char *reply; size_t reply_len; int retries =3D 0; @@ -341,15 +316,11 @@ static int vmw_recv_msg(struct rpc_channel *channel, = void **msg, while (retries < RETRIES) { retries++; =20 - /* Set up additional parameters */ - si =3D channel->cookie_high; - di =3D channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_RECVSIZE, - 0, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall7(VMW_PORT_CMD_RECVSIZE, + 0, channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx); =20 if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) =3D=3D 0) { DRM_ERROR("Failed to get reply size for host message.\n"); @@ -384,16 +355,12 @@ static int vmw_recv_msg(struct rpc_channel *channel, = void **msg, =20 reply[reply_len] =3D '\0'; =20 - - /* Ack buffer */ - si =3D channel->cookie_high; - di =3D channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_RECVSTATUS, - MESSAGE_STATUS_SUCCESS, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall5(VMW_PORT_CMD_RECVSTATUS, + MESSAGE_STATUS_SUCCESS, + channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ecx); =20 if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) =3D=3D 0) { kfree(reply); @@ -652,13 +619,7 @@ static inline void reset_ppn_array(PPN64 *arr, size_t = size) */ static inline void hypervisor_ppn_reset_all(void) { - unsigned long eax, ebx, ecx, edx, si =3D 0, di =3D 0; - - VMW_PORT(VMW_PORT_CMD_MKSGS_RESET, - 0, si, di, - 0, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall1(VMW_PORT_CMD_MKSGS_RESET, 0); } =20 /** @@ -669,13 +630,7 @@ static inline void hypervisor_ppn_reset_all(void) */ static inline void hypervisor_ppn_add(PPN64 pfn) { - unsigned long eax, ebx, ecx, edx, si =3D 0, di =3D 0; - - VMW_PORT(VMW_PORT_CMD_MKSGS_ADD_PPN, - (unsigned long)pfn, si, di, - 0, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall1(VMW_PORT_CMD_MKSGS_ADD_PPN, (unsigned long)pfn); } =20 /** @@ -686,13 +641,7 @@ static inline void hypervisor_ppn_add(PPN64 pfn) */ static inline void hypervisor_ppn_remove(PPN64 pfn) { - unsigned long eax, ebx, ecx, edx, si =3D 0, di =3D 0; - - VMW_PORT(VMW_PORT_CMD_MKSGS_REMOVE_PPN, - (unsigned long)pfn, si, di, - 0, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall1(VMW_PORT_CMD_MKSGS_REMOVE_PPN, (unsigned long)pfn); } =20 #if IS_ENABLED(CONFIG_DRM_VMWGFX_MKSSTATS) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h b/drivers/gpu/drm/vm= wgfx/vmwgfx_msg_arm64.h index 4f40167ad61f..29bd0af83038 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h @@ -34,6 +34,8 @@ #define VMWARE_HYPERVISOR_HB BIT(0) #define VMWARE_HYPERVISOR_OUT BIT(1) =20 +#define VMWARE_HYPERVISOR_MAGIC 0x564D5868 + #define X86_IO_MAGIC 0x86 =20 #define X86_IO_W7_SIZE_SHIFT 0 @@ -45,86 +47,159 @@ #define X86_IO_W7_IMM_SHIFT 5 #define X86_IO_W7_IMM_MASK (0xff << X86_IO_W7_IMM_SHIFT) =20 -static inline void vmw_port(unsigned long cmd, unsigned long in_ebx, - unsigned long in_si, unsigned long in_di, - unsigned long flags, unsigned long magic, - unsigned long *eax, unsigned long *ebx, - unsigned long *ecx, unsigned long *edx, - unsigned long *si, unsigned long *di) +static inline +unsigned long vmware_hypercall1(unsigned long cmd, unsigned long in1) { - register u64 x0 asm("x0") =3D magic; - register u64 x1 asm("x1") =3D in_ebx; + register u64 x0 asm("x0") =3D VMWARE_HYPERVISOR_MAGIC; + register u64 x1 asm("x1") =3D in1; register u64 x2 asm("x2") =3D cmd; - register u64 x3 asm("x3") =3D flags | VMWARE_HYPERVISOR_PORT; - register u64 x4 asm("x4") =3D in_si; - register u64 x5 asm("x5") =3D in_di; + register u64 x3 asm("x3") =3D VMWARE_HYPERVISOR_PORT; + register u64 x7 asm("x7") =3D ((u64)X86_IO_MAGIC << 32) | + X86_IO_W7_WITH | + X86_IO_W7_DIR | + (2 << X86_IO_W7_SIZE_SHIFT); =20 + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0) + : "r" (x1), "r" (x2), "r" (x3), "r" (x7) + : "memory"); + + return x0; +} + +static inline +unsigned long vmware_hypercall5(unsigned long cmd, unsigned long in1, + unsigned long in3, unsigned long in4, + unsigned long in5, uint32_t *out2) +{ + register u64 x0 asm("x0") =3D VMWARE_HYPERVISOR_MAGIC; + register u64 x1 asm("x1") =3D in1; + register u64 x2 asm("x2") =3D cmd; + register u64 x3 asm("x3") =3D in3 | VMWARE_HYPERVISOR_PORT; + register u64 x4 asm("x4") =3D in4; + register u64 x5 asm("x5") =3D in5; register u64 x7 asm("x7") =3D ((u64)X86_IO_MAGIC << 32) | X86_IO_W7_WITH | X86_IO_W7_DIR | (2 << X86_IO_W7_SIZE_SHIFT); =20 - asm volatile("mrs xzr, mdccsr_el0 \n\t" - : "+r"(x0), "+r"(x1), "+r"(x2), - "+r"(x3), "+r"(x4), "+r"(x5) - : "r"(x7) - :); - *eax =3D x0; - *ebx =3D x1; - *ecx =3D x2; - *edx =3D x3; - *si =3D x4; - *di =3D x5; + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0), "+r" (x2) + : "r" (x1), "r" (x3), "r" (x4), "r" (x5), "r" (x7) + : "memory"); + + *out2 =3D x2; + return x0; } =20 -static inline void vmw_port_hb(unsigned long cmd, unsigned long in_ecx, - unsigned long in_si, unsigned long in_di, - unsigned long flags, unsigned long magic, - unsigned long bp, u32 w7dir, - unsigned long *eax, unsigned long *ebx, - unsigned long *ecx, unsigned long *edx, - unsigned long *si, unsigned long *di) +static inline +unsigned long vmware_hypercall6(unsigned long cmd, unsigned long in1, + unsigned long in3, uint32_t *out2, + uint32_t *out3, uint32_t *out4, + uint32_t *out5) { - register u64 x0 asm("x0") =3D magic; + register u64 x0 asm("x0") =3D VMWARE_HYPERVISOR_MAGIC; + register u64 x1 asm("x1") =3D in1; + register u64 x2 asm("x2") =3D cmd; + register u64 x3 asm("x3") =3D in3 | VMWARE_HYPERVISOR_PORT; + register u64 x4 asm("x4"); + register u64 x5 asm("x5"); + register u64 x7 asm("x7") =3D ((u64)X86_IO_MAGIC << 32) | + X86_IO_W7_WITH | + X86_IO_W7_DIR | + (2 << X86_IO_W7_SIZE_SHIFT); + + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0), "+r" (x2), "+r" (x3), "=3Dr" (x4), "=3Dr" (x5) + : "r" (x1), "r" (x7) + : "memory"); + + *out2 =3D x2; + *out3 =3D x3; + *out4 =3D x4; + *out5 =3D x5; + return x0; +} + +static inline +unsigned long vmware_hypercall7(unsigned long cmd, unsigned long in1, + unsigned long in3, unsigned long in4, + unsigned long in5, uint32_t *out1, + uint32_t *out2, uint32_t *out3) +{ + register u64 x0 asm("x0") =3D VMWARE_HYPERVISOR_MAGIC; + register u64 x1 asm("x1") =3D in1; + register u64 x2 asm("x2") =3D cmd; + register u64 x3 asm("x3") =3D in3 | VMWARE_HYPERVISOR_PORT; + register u64 x4 asm("x4") =3D in4; + register u64 x5 asm("x5") =3D in5; + register u64 x7 asm("x7") =3D ((u64)X86_IO_MAGIC << 32) | + X86_IO_W7_WITH | + X86_IO_W7_DIR | + (2 << X86_IO_W7_SIZE_SHIFT); + + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0), "+r" (x1), "+r" (x2), "+r" (x3) + : "r" (x4), "r" (x5), "r" (x7) + : "memory"); + + *out1 =3D x1; + *out2 =3D x2; + *out3 =3D x3; + return x0; +} + +static inline +unsigned long vmware_hypercall_hb(unsigned long cmd, unsigned long in2, + unsigned long in3, unsigned long in4, + unsigned long in5, unsigned long in6, + uint32_t *out1, int dir) +{ + register u64 x0 asm("x0") =3D VMWARE_HYPERVISOR_MAGIC; register u64 x1 asm("x1") =3D cmd; - register u64 x2 asm("x2") =3D in_ecx; - register u64 x3 asm("x3") =3D flags | VMWARE_HYPERVISOR_PORT_HB; - register u64 x4 asm("x4") =3D in_si; - register u64 x5 asm("x5") =3D in_di; - register u64 x6 asm("x6") =3D bp; + register u64 x2 asm("x2") =3D in2; + register u64 x3 asm("x3") =3D in3 | VMWARE_HYPERVISOR_PORT_HB; + register u64 x4 asm("x4") =3D in4; + register u64 x5 asm("x5") =3D in5; + register u64 x6 asm("x6") =3D in6; register u64 x7 asm("x7") =3D ((u64)X86_IO_MAGIC << 32) | X86_IO_W7_STR | X86_IO_W7_WITH | - w7dir; - - asm volatile("mrs xzr, mdccsr_el0 \n\t" - : "+r"(x0), "+r"(x1), "+r"(x2), - "+r"(x3), "+r"(x4), "+r"(x5) - : "r"(x6), "r"(x7) - :); - *eax =3D x0; - *ebx =3D x1; - *ecx =3D x2; - *edx =3D x3; - *si =3D x4; - *di =3D x5; -} + dir; =20 -#define VMW_PORT(cmd, in_ebx, in_si, in_di, flags, magic, eax, ebx, ecx, e= dx, \ - si, di) \ - vmw_port(cmd, in_ebx, in_si, in_di, flags, magic, &eax, &ebx, &ecx, \ - &edx, &si, &di) + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0), "+r" (x1) + : "r" (x2), "r" (x3), "r" (x4), "r" (x5), + "r" (x6), "r" (x7) + : "memory"); =20 -#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, flags, magic, bp, eax, = ebx, \ - ecx, edx, si, di) \ - vmw_port_hb(cmd, in_ecx, in_si, in_di, flags, magic, bp, \ - 0, &eax, &ebx, &ecx, &edx, &si, &di) + *out1 =3D x1; + return x0; +} =20 -#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, flags, magic, bp, eax, e= bx, \ - ecx, edx, si, di) \ - vmw_port_hb(cmd, in_ecx, in_si, in_di, flags, magic, bp, \ - X86_IO_W7_DIR, &eax, &ebx, &ecx, &edx, &si, &di) +static inline +unsigned long vmware_hypercall_hb_out(unsigned long cmd, unsigned long in2, + unsigned long in3, unsigned long in4, + unsigned long in5, unsigned long in6, + uint32_t *out1) +{ + return vmware_hypercall_hb(cmd, in2, in3, in4, in5, in6, out1, 0); +} =20 +static inline +unsigned long vmware_hypercall_hb_in(unsigned long cmd, unsigned long in2, + unsigned long in3, unsigned long in4, + unsigned long in5, unsigned long in6, + uint32_t *out1) +{ + return vmware_hypercall_hb(cmd, in2, in3, in4, in5, in6, out1, + X86_IO_W7_DIR); +} #endif =20 #endif /* _VMWGFX_MSG_ARM64_H */ diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h b/drivers/gpu/drm/vmwg= fx/vmwgfx_msg_x86.h index e040ee21ea1a..13304d34cc6e 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h @@ -37,193 +37,6 @@ =20 #include =20 -/** - * Hypervisor-specific bi-directional communication channel. Should never - * execute on bare metal hardware. The caller must make sure to check for - * supported hypervisor before using these macros. - * - * The last two parameters are both input and output and must be initializ= ed. - * - * @cmd: [IN] Message Cmd - * @in_ebx: [IN] Message Len, through EBX - * @in_si: [IN] Input argument through SI, set to 0 if not used - * @in_di: [IN] Input argument through DI, set ot 0 if not used - * @flags: [IN] hypercall flags + [channel id] - * @magic: [IN] hypervisor magic value - * @eax: [OUT] value of EAX register - * @ebx: [OUT] e.g. status from an HB message status command - * @ecx: [OUT] e.g. status from a non-HB message status command - * @edx: [OUT] e.g. channel id - * @si: [OUT] - * @di: [OUT] - */ -#define VMW_PORT(cmd, in_ebx, in_si, in_di, \ - flags, magic, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile (VMWARE_HYPERCALL : \ - "=3Da"(eax), \ - "=3Db"(ebx), \ - "=3Dc"(ecx), \ - "=3Dd"(edx), \ - "=3DS"(si), \ - "=3DD"(di) : \ - [port] "i" (VMWARE_HYPERVISOR_PORT), \ - [mode] "m" (vmware_hypercall_mode), \ - "a"(magic), \ - "b"(in_ebx), \ - "c"(cmd), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di) : \ - "memory"); \ -}) - - -/** - * Hypervisor-specific bi-directional communication channel. Should never - * execute on bare metal hardware. The caller must make sure to check for - * supported hypervisor before using these macros. - * - * The last 3 parameters are both input and output and must be initialized. - * - * @cmd: [IN] Message Cmd - * @in_ecx: [IN] Message Len, through ECX - * @in_si: [IN] Input argument through SI, set to 0 if not used - * @in_di: [IN] Input argument through DI, set to 0 if not used - * @flags: [IN] hypercall flags + [channel id] - * @magic: [IN] hypervisor magic value - * @bp: [IN] - * @eax: [OUT] value of EAX register - * @ebx: [OUT] e.g. status from an HB message status command - * @ecx: [OUT] e.g. status from a non-HB message status command - * @edx: [OUT] e.g. channel id - * @si: [OUT] - * @di: [OUT] - */ -#ifdef __x86_64__ - -#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \ - flags, magic, bp, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile ( \ - UNWIND_HINT_SAVE \ - "push %%rbp;" \ - UNWIND_HINT_UNDEFINED \ - "mov %12, %%rbp;" \ - "rep outsb;" \ - "pop %%rbp;" \ - UNWIND_HINT_RESTORE : \ - "=3Da"(eax), \ - "=3Db"(ebx), \ - "=3Dc"(ecx), \ - "=3Dd"(edx), \ - "=3DS"(si), \ - "=3DD"(di) : \ - "a"(magic), \ - "b"(cmd), \ - "c"(in_ecx), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di), \ - "r"(bp) : \ - "memory", "cc"); \ -}) - - -#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \ - flags, magic, bp, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile ( \ - UNWIND_HINT_SAVE \ - "push %%rbp;" \ - UNWIND_HINT_UNDEFINED \ - "mov %12, %%rbp;" \ - "rep insb;" \ - "pop %%rbp;" \ - UNWIND_HINT_RESTORE : \ - "=3Da"(eax), \ - "=3Db"(ebx), \ - "=3Dc"(ecx), \ - "=3Dd"(edx), \ - "=3DS"(si), \ - "=3DD"(di) : \ - "a"(magic), \ - "b"(cmd), \ - "c"(in_ecx), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di), \ - "r"(bp) : \ - "memory", "cc"); \ -}) - -#elif defined(__i386__) - -/* - * In the 32-bit version of this macro, we store bp in a memory location - * because we've ran out of registers. - * Now we can't reference that memory location while we've modified - * %esp or %ebp, so we first push it on the stack, just before we push - * %ebp, and then when we need it we read it from the stack where we - * just pushed it. - */ -#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \ - flags, magic, bp, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile ("push %12;" \ - "push %%ebp;" \ - "mov 0x04(%%esp), %%ebp;" \ - VMWARE_HYPERCALL_HB_OUT \ - "pop %%ebp;" \ - "add $0x04, %%esp;" : \ - "=3Da"(eax), \ - "=3Db"(ebx), \ - "=3Dc"(ecx), \ - "=3Dd"(edx), \ - "=3DS"(si), \ - "=3DD"(di) : \ - "a"(magic), \ - "b"(cmd), \ - "c"(in_ecx), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di), \ - "m"(bp) : \ - "memory", "cc"); \ -}) - - -#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \ - flags, magic, bp, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile ("push %12;" \ - "push %%ebp;" \ - "mov 0x04(%%esp), %%ebp;" \ - VMWARE_HYPERCALL_HB_IN \ - "pop %%ebp;" \ - "add $0x04, %%esp;" : \ - "=3Da"(eax), \ - "=3Db"(ebx), \ - "=3Dc"(ecx), \ - "=3Dd"(edx), \ - "=3DS"(si), \ - "=3DD"(di) : \ - "a"(magic), \ - "b"(cmd), \ - "c"(in_ecx), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di), \ - "m"(bp) : \ - "memory", "cc"); \ -}) -#endif /* defined(__i386__) */ - #endif /* defined(__i386__) || defined(__x86_64__) */ =20 #endif /* _VMWGFX_MSG_X86_H */ --=20 2.39.0 From nobody Fri Dec 26 05:29:59 2025 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 C1C7A374ED for ; Tue, 9 Jan 2024 08:41:16 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="J7sHR0az" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-28d7870574bso1053625a91.3 for ; Tue, 09 Jan 2024 00:41:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1704789676; x=1705394476; 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=X8/C+cZAZlDGQnbyhqyYcqig/5vzt/WyH0xZX56gmkE=; b=J7sHR0az6M0IXYCdVG/4uiYdDAiynV1u/UguMMYdYPWYEHBc+RYmVfigAJj3gArvRI 6lI5NCvc4Q0ekM/CpM0QoTzAIXsys5/JGi6nLnzNzaxouExrBKyF7SWNy+EiFz35YS2r An36GZdqHxElNIzgMEeKQVkfwttm0BkwzkPn8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704789676; x=1705394476; 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=X8/C+cZAZlDGQnbyhqyYcqig/5vzt/WyH0xZX56gmkE=; b=iu3hVMNdgjEta9Ti6lbWrC9nn2IcOU0vxg19x18yvu9q+d/BNt4dIkjknj18Bpc6n8 9T4VWpynCNyK2PgvDCOWg6zDI0wvljA+Z8Ofr1OoR5iCTLhNW0B3HHp9oMRJLsA4OzDJ Xg5vbear+N97yWyphSnhbjyGIwjrCsRVS0UDG3vxGwBgUipf7dcjPtEFXFVVUsbHTFAS xnE4QifPFwrJkPoIEnciljLEMeFqyrRRyP5clanbHvuTkKWo3PrFWsQBQilCKs1sfoe5 MJMbFzSDiarV0QWI4FBEN6UzXDKGNHzUHvnF36HRntFEtCrvsq+MbqoPH0zH0hA70oqm JT1A== X-Gm-Message-State: AOJu0YzSrpp5HAzM84xiDHttjb0m/PykYOAUkwWwi01UEijQMAJEWzBr 8DsL6Yb01NChs8JYRqHGAY7VW0fbwh/Lgb8zA1lkRxYiWStzWt5Zg1YWErNcllkkVc1VJUBdNH6 XhaqPB2/RmLxFehFOMH7bzr5B3RhPyb6sqp/7ZMz7iLUTEA+mGscH+cdAhKSuaR5SnziaJkd/9k 5kcGQfprKlldLYNkEW3dBC+hE= X-Google-Smtp-Source: AGHT+IEKSJPQQ5kZXHfegHUZEeEfLJv3dBHvaNcjAImiJtqEMm+GIdULd8bk6lMU/uJqJHQXXQBX1A== X-Received: by 2002:a17:90a:d50d:b0:28d:1e1b:d73b with SMTP id t13-20020a17090ad50d00b0028d1e1bd73bmr1951835pju.19.1704789675730; Tue, 09 Jan 2024 00:41:15 -0800 (PST) Received: from amakhalov-build-vm.eng.vmware.com ([128.177.82.146]) by smtp.gmail.com with ESMTPSA id sf15-20020a17090b51cf00b0028d435cc2cbsm4772293pjb.15.2024.01.09.00.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 00:41:15 -0800 (PST) From: Alexey Makhalov X-Google-Original-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, namit@vmware.com, timothym@vmware.com, akaher@vmware.com, jsipek@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 Subject: [PATCH v6 6/7] x86/vmware: Undefine VMWARE_HYPERCALL Date: Tue, 9 Jan 2024 00:40:51 -0800 Message-Id: <20240109084052.58661-7-amakhalov@vmware.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240109084052.58661-1-amakhalov@vmware.com> References: <20240109084052.58661-1-amakhalov@vmware.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" No more direct use of VMWARE_HYPERCALL macro should be allowed. Signed-off-by: Alexey Makhalov --- arch/x86/include/asm/vmware.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 2ac87068184a..84a31f579a30 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -273,5 +273,6 @@ unsigned long vmware_hypercall_hb_in(unsigned long cmd,= unsigned long in2, } #undef VMW_BP_REG #undef VMW_BP_CONSTRAINT +#undef VMWARE_HYPERCALL =20 #endif --=20 2.39.0 From nobody Fri Dec 26 05:29:59 2025 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 60BE838DE6 for ; Tue, 9 Jan 2024 08:41:19 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="d5lMnuwk" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6daa89a6452so1468539b3a.2 for ; Tue, 09 Jan 2024 00:41:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1704789678; x=1705394478; 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=HeZ7Yc/QAQMqHdvRNSeL3MLzDzQAumC8yqHea160CSY=; b=d5lMnuwkPYtFwt9V3EurtqkaHaeRVMcXG9Y96ybFJ5SouEnCo2kepx9FkpgUv51S+o cifzO1eNoGAErRguitjRMTad/XHH93kN5ScsMyrnUV89x1J/aA83RS5IF5O8UZtv9AbD LQzw7X9bedcsDWdi82Nzsk9U9TgwxNrs/IGBw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704789678; x=1705394478; 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=HeZ7Yc/QAQMqHdvRNSeL3MLzDzQAumC8yqHea160CSY=; b=cI5IKOiTMaj2bBrdeYtONKQW0yPU+aDJUqeVrNtova5pOcPEDw9rXM4VPAFwLgyiTY zLUQmVsqaku7uP09oagpMBSLUZd7vP5Bk+hOVcTtPWR3saSPs4kRG9iq4B6/yTgf0zts gu9UrDmdvLXl/lupHPtlvLFf9mSpoRcOOssQoD301lRtWDS9rMUW8nC9b8ZLRn8aWeg1 jm1lzCG+xyFkyNZL4ghyR9/Bwdj4zzz2+Imv81CXXnc0YF9tr0nHaATfIfc2nwIiMheW ynhQ7QyuMR7EBZ47XaI+w89qWiUN/yW6uoyGZE1ASaE28QogFaTHb1EOkiCbcemr049q a5uQ== X-Gm-Message-State: AOJu0YwssGnTN8pFu2g6gCBKliUoTRwH9TuBF/O12j2VMHipct4tnNsx paNEH3acfZsFg2OCRLRRHai8/Xjl8aub8xR6ss7haJRT/2n/VPEPlfB6hEzqYn3IqWFdxtVfWOJ hy5kNtojXzaym88VSN8VAA2siG+Y7qOyaInSCXU+JwyvnDSQMHk4LnTRnw4cpmzphUKHGIPFrA4 ttrCaPl0hBtj6q6gjjobbV6Bk= X-Google-Smtp-Source: AGHT+IFxx53kVarjHq5z7rzVIUwCkyk+NGFUSVTP7cmO2YtnOt1zBEsFEwgvVWBZJ0j2JxOYS0P1zg== X-Received: by 2002:a05:6a21:8187:b0:199:bb69:a6ed with SMTP id pd7-20020a056a21818700b00199bb69a6edmr1524423pzb.114.1704789678164; Tue, 09 Jan 2024 00:41:18 -0800 (PST) Received: from amakhalov-build-vm.eng.vmware.com ([128.177.82.146]) by smtp.gmail.com with ESMTPSA id sf15-20020a17090b51cf00b0028d435cc2cbsm4772293pjb.15.2024.01.09.00.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 00:41:17 -0800 (PST) From: Alexey Makhalov X-Google-Original-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, namit@vmware.com, timothym@vmware.com, akaher@vmware.com, jsipek@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 Subject: [PATCH v6 7/7] x86/vmware: Add TDX hypercall support Date: Tue, 9 Jan 2024 00:40:52 -0800 Message-Id: <20240109084052.58661-8-amakhalov@vmware.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240109084052.58661-1-amakhalov@vmware.com> References: <20240109084052.58661-1-amakhalov@vmware.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Nadav Amit Acked-by: Kirill A. Shutemov Acked-by: Dave Hansen --- arch/x86/include/asm/vmware.h | 79 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 25 +++++++++++ 2 files changed, 104 insertions(+) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 84a31f579a30..3bd593c6591d 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,61 @@ #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 =20 #define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) #define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) =20 extern u8 vmware_hypercall_mode; =20 +#define VMWARE_TDX_VENDOR_LEAF 0x1af7e4909ULL +#define VMWARE_TDX_HCALL_FUNC 1 + +extern unsigned long vmware_tdx_hypercall(unsigned long cmd, + struct tdx_module_args *args); + +/* + * TDCALL[TDG.VP.VMCALL] uses %rax (arg0) and %rcx (arg2). Therefore, + * we remap those registers to %r12 and %r13, respectively. + */ +static inline +unsigned long vmware_tdx_hypercall_args(unsigned long cmd, unsigned long i= n1, + unsigned long in3, unsigned long in4, + unsigned long in5, + uint32_t *out1, uint32_t *out2, + uint32_t *out3, uint32_t *out4, + uint32_t *out5) +{ + unsigned long ret; + + struct tdx_module_args args =3D { + .rbx =3D in1, + .rdx =3D in3, + .rsi =3D in4, + .rdi =3D in5, + }; + + ret =3D vmware_tdx_hypercall(cmd, &args); + + if (out1) + *out1 =3D args.rbx; + if (out2) + *out2 =3D args.r13; + if (out3) + *out3 =3D args.rdx; + if (out4) + *out4 =3D args.rsi; + if (out5) + *out5 =3D args.rdi; + + return ret; +} + /* * 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. @@ -87,6 +142,10 @@ unsigned long vmware_hypercall1(unsigned long cmd, unsi= gned long in1) { unsigned long out0; =20 + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall_args(cmd, in1, 0, 0, 0, + NULL, NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=3Da" (out0) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -105,6 +164,10 @@ unsigned long vmware_hypercall3(unsigned long cmd, uns= igned long in1, { unsigned long out0; =20 + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall_args(cmd, in1, 0, 0, 0, + out1, out2, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -124,6 +187,10 @@ unsigned long vmware_hypercall4(unsigned long cmd, uns= igned long in1, { unsigned long out0; =20 + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall_args(cmd, in1, 0, 0, 0, + out1, out2, out3, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2), "=3Dd" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -143,6 +210,10 @@ unsigned long vmware_hypercall5(unsigned long cmd, uns= igned long in1, { unsigned long out0; =20 + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall_args(cmd, in1, in3, in4, in5, + NULL, out2, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=3Da" (out0), "=3Dc" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -165,6 +236,10 @@ unsigned long vmware_hypercall6(unsigned long cmd, uns= igned long in1, { unsigned long out0; =20 + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall_args(cmd, in1, in3, 0, 0, + NULL, out2, out3, out4, out5); + asm_inline volatile (VMWARE_HYPERCALL : "=3Da" (out0), "=3Dc" (*out2), "=3Dd" (*out3), "=3DS" (*out4), "=3DD" (*out5) @@ -186,6 +261,10 @@ unsigned long vmware_hypercall7(unsigned long cmd, uns= igned long in1, { unsigned long out0; =20 + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall_args(cmd, in1, in3, in4, in5, + out1, out2, out3, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2), "=3Dd" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 3aa1adaed18f..84caa67d4820 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -428,6 +428,31 @@ static bool __init vmware_legacy_x2apic_available(void) (eax & BIT(VCPU_LEGACY_X2APIC)); } =20 +#ifdef CONFIG_INTEL_TDX_GUEST +unsigned long vmware_tdx_hypercall(unsigned long cmd, + struct tdx_module_args *args) +{ + if (!hypervisor_is_type(X86_HYPER_VMWARE)) + return ULONG_MAX; + + if (cmd & ~VMWARE_CMD_MASK) { + pr_warn_once("Out of range command %lx\n", cmd); + return ULONG_MAX; + } + + args->r10 =3D VMWARE_TDX_VENDOR_LEAF; + args->r11 =3D VMWARE_TDX_HCALL_FUNC; + args->r12 =3D VMWARE_HYPERVISOR_MAGIC; + args->r13 =3D cmd; + args->r15 =3D 0; /* CPL */ + + __tdx_hypercall(args); + + 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) --=20 2.39.0