[PATCH v1 2/2] vmw_balloon: Add arm64 support

From: Jerrin Shaji George

Date: Wed Dec 02 2026 - 16:38:37 EST


This patch adds arm64 support for the VMware balloon driver. On
arm64 the hypervisor handles the balloon's x86 I/O port protocol
through HVC #0x86.

The hypervisor assumes 4 KiB pages, so depend on ARM64_4K_PAGES, and
keep big-endian excluded.

Return -ENODEV unless the guest is VMware. On arm64 that means the SMCCC
conduit is HVC and the DMI system vendor is "VMware, Inc.", which
VMware's arm64 firmware reports in SMBIOS.

Based on the VMware Photon OS patches by Cyprien Laplace and
Keerthana K.

Link: https://github.com/vmware/photon/blob/5.0/SPECS/92/linux/aarch64/0005-vmw_balloon-add-arm64-support.patch
Link: https://github.com/vmware/photon/blob/5.0/SPECS/92/linux/aarch64/0003-arm64-VMware-hypervisor-detection.patch
Co-developed-by: Keerthana K <keerthana.kalyanasundaram@xxxxxxxxxxxx>
Signed-off-by: Keerthana K <keerthana.kalyanasundaram@xxxxxxxxxxxx>
Signed-off-by: Jerrin Shaji George <jerrin.shaji-george@xxxxxxxxxxxx>
---
drivers/misc/Kconfig | 4 +-
drivers/misc/vmw_balloon.c | 82 +++++++++++++++++++++++++++++++-------
2 files changed, 71 insertions(+), 15 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index c40e89cc5724..127f75d9aff5 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -346,7 +346,9 @@ config DS1682

config VMWARE_BALLOON
tristate "VMware Balloon Driver"
- depends on VMWARE_VMCI && X86 && HYPERVISOR_GUEST
+ depends on VMWARE_VMCI
+ depends on (X86 && HYPERVISOR_GUEST) || (ARM64 && ARM64_4K_PAGES)
+ depends on !CPU_BIG_ENDIAN
select BALLOON
help
This is VMware physical memory management driver which acts
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 3edb934dd7fd..6b4232b11dcb 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -32,7 +32,14 @@
#include <linux/balloon.h>
#include <linux/vmw_vmci_defs.h>
#include <linux/vmw_vmci_api.h>
+#include <linux/dmi.h>
+
+#ifdef CONFIG_X86
#include <asm/hypervisor.h>
+#elif defined(CONFIG_ARM64)
+#include <linux/arm-smccc.h>
+#include <asm/vmware.h>
+#endif

MODULE_AUTHOR("VMware, Inc.");
MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver");
@@ -447,26 +454,56 @@ static inline void vmballoon_stats_page_add(struct vmballoon *b,
atomic64_add(val, &b->stats->page_stat[stat][size]);
}

+#ifdef CONFIG_X86
+static inline unsigned long
+__vmballoon_call(unsigned long cmd, unsigned long arg1, unsigned long arg2,
+ unsigned long *caps, unsigned long *result)
+{
+ unsigned long status, dummy2, dummy3;
+
+ asm volatile ("inl %%dx"
+ : "=a" (status), "=c" (*caps), "=d" (dummy2),
+ "=b" (*result), "=S" (dummy3)
+ : "0" (VMW_BALLOON_HV_MAGIC), "1" (cmd),
+ "2" (VMW_BALLOON_HV_PORT), "3" (arg1), "4" (arg2)
+ : "memory");
+
+ return status;
+}
+#elif defined(CONFIG_ARM64)
+static inline unsigned long
+__vmballoon_call(unsigned long cmd, unsigned long arg1, unsigned long arg2,
+ unsigned long *caps, unsigned long *result)
+{
+ register u64 x0 asm("x0") = VMW_BALLOON_HV_MAGIC;
+ register u64 x1 asm("x1") = arg1;
+ register u32 w2 asm("w2") = cmd;
+ register u32 w3 asm("w3") = VMW_BALLOON_HV_PORT;
+ register u64 x4 asm("x4") = arg2;
+ register u32 w7 asm("w7") = X86_IO_W7_WITH | X86_IO_W7_DIR |
+ (2 << X86_IO_W7_SIZE_SHIFT);
+
+ /* x1 carries the full target when 64-bit targets are negotiated. */
+ asm volatile ("hvc %[magic]"
+ : "+r" (x0), "+r" (x1), "+r" (w2), "+r" (w3), "+r" (x4)
+ : "r" (w7), [magic] "i" (X86_IO_MAGIC)
+ : "cc", "memory");
+
+ *caps = w2;
+ *result = x1;
+ return x0;
+}
+#endif
+
static inline unsigned long
__vmballoon_cmd(struct vmballoon *b, unsigned long cmd, unsigned long arg1,
unsigned long arg2, unsigned long *result)
{
- unsigned long status, dummy1, dummy2, dummy3, local_result;
+ unsigned long status, dummy1, local_result;

vmballoon_stats_op_inc(b, cmd, VMW_BALLOON_OP_STAT);

- asm volatile ("inl %%dx" :
- "=a"(status),
- "=c"(dummy1),
- "=d"(dummy2),
- "=b"(local_result),
- "=S"(dummy3) :
- "0"(VMW_BALLOON_HV_MAGIC),
- "1"(cmd),
- "2"(VMW_BALLOON_HV_PORT),
- "3"(arg1),
- "4"(arg2) :
- "memory");
+ status = __vmballoon_call(cmd, arg1, arg2, &dummy1, &local_result);

/* update the result if needed */
if (result)
@@ -1809,6 +1846,23 @@ int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
enum migrate_mode mode);
#endif /* CONFIG_BALLOON_MIGRATION */

+static bool __init vmballoon_supported(void)
+{
+#ifdef CONFIG_X86
+ return hypervisor_is_type(X86_HYPER_VMWARE);
+#elif defined(CONFIG_ARM64)
+ /*
+ * The balloon protocol is carried by HVC. HVC is undefined where
+ * firmware does not provide it, so do not execute it unless the
+ * SMCCC conduit is HVC.
+ */
+ if (arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_HVC)
+ return false;
+
+ return dmi_match(DMI_SYS_VENDOR, "VMware, Inc.");
+#endif
+}
+
static int __init vmballoon_init(void)
{
int error;
@@ -1817,7 +1871,7 @@ static int __init vmballoon_init(void)
* Check if we are running on VMware's hypervisor and bail out
* if we are not.
*/
- if (x86_hyper_type != X86_HYPER_VMWARE)
+ if (!vmballoon_supported())
return -ENODEV;

INIT_DELAYED_WORK(&balloon.dwork, vmballoon_work);
--
2.52.0