From nobody Wed Dec 17 05:09:17 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD94C16D33B; Tue, 25 Jun 2024 15:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719329231; cv=none; b=hR+IPQuufTJxTDQ7wOAfQOsoYu/TYNDgosfsrGnBM60oNuMxRA65LUn+OMTCs3xDcPny8Z0GxxqHNTIDunS+VgJAXz0NpB8hrEh82KTuzerWD8Lo8tqh3odmNwSXjo64QRAb0DyWRPP/5iZLXBqC3QNODk3mkW9p9ZYACSw3Z1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719329231; c=relaxed/simple; bh=NaHYcXHUvRMCeIVv6/wq6UvEGGGIsD1hnbqPZ43Pnso=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=DkqN2RyrWRkTNX4i5dX7znO5WuDVmDdVtA1ZXDLEWgYZ0Z3ewp6HZptANPc+fIcQmUI/5YfWsivWjvfa36cmWqVeDqrOlQwN5AVj7AJodjyaB+8HJKiyY/hvLBs/+RPRWsj4+lbhIg592h3cVy6TEr8fXATyQJQvCJZFYuQn+1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cYpC4v9W; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=piXV1ynJ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cYpC4v9W"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="piXV1ynJ" Date: Tue, 25 Jun 2024 15:27:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719329227; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9hAMBcv6VL3EZKfoLliXyCaakiFHzknzDtJKbHQOpfA=; b=cYpC4v9WSKTML9LtI7GQHaIIAqtITPsRnnqbVv4mvC9+T77mEtiehBp0Pj4/JXwoniubki wGJte6VlWDn5aJ/4Sfnm2k9PBJaqKMMtPKb+ESVi26tsmuw1cdMH3v3itH4RmZorZ3IcaZ DasVP5j8Om90y19nF6D804RuRCYD9A5bQRsYUszL35XMpy+CcUYlxlvLvAMNLu/1/0g0h2 irv0pGbSo6Rk6s22Re276jd6CYJ8l4dN1w9eAsE2r2EwZtamL2rkjRJsOYBRYzoIeWq4s+ el3R6MruxxqJX/wNoM2H8QjlvZCDX1e8mK/Sa4tfeDtR0mDsrYfbou1Unk6llg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719329227; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9hAMBcv6VL3EZKfoLliXyCaakiFHzknzDtJKbHQOpfA=; b=piXV1ynJRl107KVUxTW16PkcvEEOsqWAH2x1g5MeLzAU7Oo3z5fnPjV7Oz9YJX60US7/Df QyjNAYBtOVaxW7Bw== From: "tip-bot2 for Alexey Makhalov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/vmware] x86/vmware: Use VMware hypercall API Cc: Alexey Makhalov , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240613191650.9913-6-alexey.makhalov@broadcom.com> References: <20240613191650.9913-6-alexey.makhalov@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171932922749.2215.2343015379199487912.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/vmware branch of tip: Commit-ID: b2c13c23ea9c1f748315b8c2c028bb3ae18f1e12 Gitweb: https://git.kernel.org/tip/b2c13c23ea9c1f748315b8c2c028bb3ae= 18f1e12 Author: Alexey Makhalov AuthorDate: Thu, 13 Jun 2024 12:16:47 -07:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 25 Jun 2024 17:15:47 +02:00 x86/vmware: Use VMware hypercall API Remove VMWARE_CMD macro and move to vmware_hypercall API. No functional changes intended. Use u32/u64 instead of uint32_t/uint64_t across the file. Signed-off-by: Alexey Makhalov Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20240613191650.9913-6-alexey.makhalov@broad= com.com --- arch/x86/kernel/cpu/vmware.c | 95 +++++++++-------------------------- 1 file changed, 25 insertions(+), 70 deletions(-) diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index faf7068..24d6fd8 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -49,54 +49,16 @@ #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 */ + u64 clock; /* stolen time counter in units of vtsc */ struct { /* only for little-endian */ - uint32_t clock_low; - uint32_t clock_high; + u32 clock_low; + u32 clock_high; }; }; - uint64_t reserved[7]; + u64 reserved[7]; }; =20 static unsigned long vmware_tsc_khz __ro_after_init; @@ -166,9 +128,10 @@ unsigned long vmware_hypercall_slow(unsigned long cmd, =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; + u32 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) @@ -220,21 +183,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(u32 addr_hi, u32 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; + u32 info; + + return vmware_hypercall5(VMWARE_CMD_STEALCLOCK, 0, 0, addr_hi, addr_lo, + &info); } =20 static bool stealclock_enable(phys_addr_t pa) @@ -269,15 +223,15 @@ static bool vmware_is_stealclock_available(void) * Return: * The steal clock reading in ns. */ -static uint64_t vmware_steal_clock(int cpu) +static u64 vmware_steal_clock(int cpu) { struct vmware_steal_time *steal =3D &per_cpu(vmw_steal_time, cpu); - uint64_t clock; + u64 clock; =20 if (IS_ENABLED(CONFIG_64BIT)) clock =3D READ_ONCE(steal->clock); else { - uint32_t initial_high, low, high; + u32 initial_high, low, high; =20 do { initial_high =3D READ_ONCE(steal->clock_high); @@ -289,7 +243,7 @@ static uint64_t vmware_steal_clock(int cpu) high =3D READ_ONCE(steal->clock_high); } while (initial_high !=3D high); =20 - clock =3D ((uint64_t)high << 32) | low; + clock =3D ((u64)high << 32) | low; } =20 return mul_u64_u32_shr(clock, vmware_cyc2ns.cyc2ns_mul, @@ -443,13 +397,13 @@ static void __init vmware_set_capabilities(void) =20 static void __init vmware_platform_setup(void) { - uint32_t eax, ebx, ecx, edx; - uint64_t lpj, tsc_khz; + u32 eax, ebx, ecx; + u64 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); + lpj =3D tsc_khz =3D eax | (((u64)ebx) << 32); do_div(tsc_khz, 1000); WARN_ON(tsc_khz >> 32); pr_info("TSC freq read from hypervisor : %lu.%03lu MHz\n", @@ -500,7 +454,7 @@ static u8 __init vmware_select_hypercall(void) * If !boot_cpu_has(X86_FEATURE_HYPERVISOR), vmware_hypercall_mode * intentionally defaults to 0. */ -static uint32_t __init vmware_platform(void) +static u32 __init vmware_platform(void) { if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) { unsigned int eax; @@ -528,8 +482,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); + u32 eax; + + eax =3D vmware_hypercall1(VMWARE_CMD_GETVCPU_INFO, 0); return !(eax & BIT(VMWARE_CMD_VCPU_RESERVED)) && (eax & BIT(VMWARE_CMD_LEGACY_X2APIC)); }