port-arm/58194: Resurrect vmt(4) from bitrot

On this architecture vmt(4) used to search for a node "/hypervisor" in the
FDT and probed the VMware hypervisor call only when the node was
found. However, things appear to have changed and VMware no longer provides
the FDT node.

Since vmt(4) doesn't actually need to read anything from FDT, and the
hypervisor call logically resides in virtual CPUs themselves, it would be
better to attach it directly to cpu, just like how it's probed on x86.
This commit is contained in:
pho 2024-05-09 12:09:58 +00:00
parent 151775b8cf
commit 3dc92541ec
13 changed files with 163 additions and 93 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: ad.aarch64,v 1.12 2023/04/11 10:30:41 riastradh Exp $
# $NetBSD: ad.aarch64,v 1.13 2024/05/09 12:09:58 pho Exp $
./@MODULEDIR@/amdgpu modules-base-kernel kmod
./@MODULEDIR@/amdgpu/amdgpu.kmod modules-base-kernel kmod
./@MODULEDIR@/bpfjit modules-base-kernel kmod,sljit
@ -77,3 +77,5 @@
./@MODULEDIR@/exec_elf64/exec_elf64.kmod modules-base-kernel kmod
./@MODULEDIR@/sljit modules-base-kernel kmod,sljit
./@MODULEDIR@/sljit/sljit.kmod modules-base-kernel kmod,sljit
./@MODULEDIR@/vmt modules-base-kernel kmod
./@MODULEDIR@/vmt/vmt.kmod modules-base-kernel kmod

View File

@ -1,4 +1,4 @@
.\" $NetBSD: vmt.4,v 1.3 2020/10/27 08:57:10 ryo Exp $
.\" $NetBSD: vmt.4,v 1.4 2024/05/09 12:09:58 pho Exp $
.\" $OpenBSD: vmt.4,v 1.4 2010/10/26 05:07:31 jmc Exp $
.\"
.\" Copyright (c) 2008 Marco Peereboom <marco@openbsd.org>
@ -23,7 +23,6 @@
.Nd VMware Tools driver
.Sh SYNOPSIS
.Cd "vmt0 at cpu0"
.Cd "vmt0 at fdt?"
.Sh DESCRIPTION
The
.Nm

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.c,v 1.74 2024/02/07 04:20:26 msaitoh Exp $ */
/* $NetBSD: cpu.c,v 1.75 2024/05/09 12:09:58 pho Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.74 2024/02/07 04:20:26 msaitoh Exp $");
__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.75 2024/05/09 12:09:58 pho Exp $");
#include "locators.h"
#include "opt_arm_debug.h"
@ -180,6 +180,11 @@ cpu_attach(device_t dv, cpuid_t id)
cpu_setup_rng(dv, ci);
cpu_setup_aes(dv, ci);
cpu_setup_chacha(dv, ci);
struct cpufeature_attach_args cfaa;
memset(&cfaa, 0, sizeof(cfaa));
cfaa.ci = ci;
config_found(dv, &cfaa, NULL, CFARGS(.iattr = "cpufeaturebus"));
}
struct cpuidtab {

View File

@ -0,0 +1,119 @@
/* $NetBSD */
/*
* Copyright (c) 2024 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/device.h>
#include <sys/module.h>
#include <dev/vmt/vmtreg.h>
#include <dev/vmt/vmtvar.h>
static int vmt_match(device_t, cfdata_t, void *);
static void vmt_attach(device_t, device_t, void *);
static int vmt_detach(device_t, int);
CFATTACH_DECL_NEW(vmt, sizeof(struct vmt_softc),
vmt_match, vmt_attach, vmt_detach, NULL);
static bool vmt_attached = false;
static int
vmt_match(device_t parent, cfdata_t match, void *aux)
{
/* vmt should not attach to more than a single CPU. */
if (vmt_attached)
return 0;
return vmt_probe();
}
static void
vmt_attach(device_t parent, device_t self, void *aux)
{
struct vmt_softc *sc = device_private(self);
aprint_naive("\n");
aprint_normal(": VMware Tools driver\n");
sc->sc_dev = self;
vmt_common_attach(sc);
vmt_attached = true;
}
static int
vmt_detach(device_t self, int flags)
{
struct vmt_softc *sc = device_private(self);
int rv;
rv = vmt_common_detach(sc);
if (rv != 0)
return rv;
vmt_attached = false;
return 0;
}
MODULE(MODULE_CLASS_DRIVER, vmt, "sysmon_power,sysmon_taskq");
#ifdef _MODULE
#include "ioconf.c"
#endif
static int
vmt_modcmd(modcmd_t cmd, void *aux)
{
int error = 0;
switch (cmd) {
case MODULE_CMD_INIT:
#ifdef _MODULE
error = config_init_component(cfdriver_ioconf_vmt,
cfattach_ioconf_vmt, cfdata_ioconf_vmt);
#endif
break;
case MODULE_CMD_FINI:
#ifdef _MODULE
error = config_fini_component(cfdriver_ioconf_vmt,
cfattach_ioconf_vmt, cfdata_ioconf_vmt);
#endif
break;
case MODULE_CMD_AUTOUNLOAD:
error = EBUSY;
break;
default:
error = ENOTTY;
break;
}
return error;
}

View File

@ -1,4 +1,4 @@
# $NetBSD: files.aarch64,v 1.44 2024/02/18 09:03:44 andvar Exp $
# $NetBSD: files.aarch64,v 1.45 2024/05/09 12:09:58 pho Exp $
defflag opt_cpuoptions.h AARCH64_ALIGNMENT_CHECK
defflag opt_cpuoptions.h AARCH64_EL0_STACK_ALIGNMENT_CHECK
@ -73,9 +73,14 @@ file arch/aarch64/aarch64/disasm.c ddb
# mainbus files
device mainbus { [addr = -1], [size = 0], [intr = -1] }
device cpu { }
device cpufeaturebus {}
device cpu { }: cpufeaturebus
file arch/aarch64/aarch64/cpu.c cpu
# VMware Tools driver
attach vmt at cpufeaturebus
file arch/aarch64/aarch64/vmt.c vmt
# bus_space(9)
define bus_space_generic
file arch/aarch64/aarch64/bus_space.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.h,v 1.49 2023/02/25 00:40:22 riastradh Exp $ */
/* $NetBSD: cpu.h,v 1.50 2024/05/09 12:09:59 pho Exp $ */
/*-
* Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
@ -247,6 +247,9 @@ cpu_dosoftints(void)
#endif
}
struct cpufeature_attach_args {
struct cpu_info *ci;
};
#endif /* _KERNEL */

View File

@ -1,5 +1,5 @@
#
# $NetBSD: GENERIC64,v 1.214 2023/10/11 07:49:29 rin Exp $
# $NetBSD: GENERIC64,v 1.215 2024/05/09 12:09:59 pho Exp $
#
# GENERIC ARM (aarch64) kernel
#
@ -131,7 +131,7 @@ cpus* at fdt? pass 0
cpu* at fdt? pass 0
cpu* at acpi?
vmt* at fdt? # VMware Tools
vmt0 at cpu0 # VMware Tools
# Performance monitors
armpmu* at fdt?

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmt.c,v 1.21 2020/10/27 08:57:11 ryo Exp $ */
/* $NetBSD: vmt.c,v 1.22 2024/05/09 12:09:59 pho Exp $ */
/* $OpenBSD: vmt.c,v 1.11 2011/01/27 21:29:25 dtucker Exp $ */
/*
@ -20,7 +20,8 @@
/*
* Protocol reverse engineered by Ken Kato:
* https://sites.google.com/site/chitchatvmback/backdoor
* https://sites.google.com/site/chitchatvmback/backdoor (dead link)
* https://web.archive.org/web/20230325103442/https://sites.google.com/site/chitchatvmback/backdoor (archive)
*/
#include <sys/param.h>

View File

@ -1,4 +1,4 @@
# $NetBSD: files.fdt,v 1.72 2024/01/18 07:48:57 skrll Exp $
# $NetBSD: files.fdt,v 1.73 2024/05/09 12:09:59 pho Exp $
include "external/bsd/libfdt/conf/files.libfdt"
@ -216,10 +216,6 @@ file dev/fdt/simple_amplifier.c simpleamp
attach genet at fdt with genet_fdt
file dev/fdt/genet_fdt.c genet_fdt
# VMware Tools driver
attach vmt at fdt with vmt_fdt
file dev/fdt/vmt_fdt.c vmt_fdt
# Google Goldfish RTC
attach gfrtc at fdt with gfrtc_fdt
file dev/fdt/gfrtc_fdt.c gfrtc_fdt

View File

@ -1,71 +0,0 @@
/* $NetBSD: vmt_fdt.c,v 1.6 2024/02/07 04:20:28 msaitoh Exp $ */
/*
* Copyright (c) 2020 Ryo Shimizu
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vmt_fdt.c,v 1.6 2024/02/07 04:20:28 msaitoh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <dev/fdt/fdtvar.h>
#include <dev/vmt/vmtreg.h>
#include <dev/vmt/vmtvar.h>
static int vmt_fdt_match(device_t, cfdata_t, void *);
static void vmt_fdt_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(vmt_fdt, sizeof(struct vmt_softc),
vmt_fdt_match, vmt_fdt_attach, NULL, NULL);
static const struct device_compatible_entry compat_data[] = {
{ .compat = "vmware" },
DEVICE_COMPAT_EOL
};
static int
vmt_fdt_match(device_t parent, cfdata_t cf, void *aux)
{
const struct fdt_attach_args * const faa = aux;
if (OF_finddevice("/hypervisor") != faa->faa_phandle)
return 0;
return of_compatible_match(faa->faa_phandle, compat_data);
}
static void
vmt_fdt_attach(device_t parent, device_t self, void *aux)
{
struct vmt_softc * const sc = device_private(self);
aprint_naive("\n");
aprint_normal(": VMware Tools driver\n");
sc->sc_dev = self;
vmt_common_attach(sc);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmt_subr.c,v 1.9 2024/04/02 20:04:16 christos Exp $ */
/* $NetBSD: vmt_subr.c,v 1.10 2024/05/09 12:09:59 pho Exp $ */
/* $OpenBSD: vmt.c,v 1.11 2011/01/27 21:29:25 dtucker Exp $ */
/*
@ -20,7 +20,8 @@
/*
* Protocol reverse engineered by Ken Kato:
* https://sites.google.com/site/chitchatvmback/backdoor
* https://sites.google.com/site/chitchatvmback/backdoor (dead link)
* https://web.archive.org/web/20230325103442/https://sites.google.com/site/chitchatvmback/backdoor (archive)
*/
#include <sys/param.h>

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.285 2024/04/02 22:37:34 riastradh Exp $
# $NetBSD: Makefile,v 1.286 2024/05/09 12:09:59 pho Exp $
.include <bsd.own.mk>
@ -242,6 +242,11 @@ SUBDIR+= odcm
SUBDIR+= powernow
SUBDIR+= tco
SUBDIR+= tprof_x86
.endif
.if ${MACHINE_CPU} == "aarch64" || \
${MACHINE_ARCH} == "i386" || \
${MACHINE_ARCH} == "x86_64"
SUBDIR+= vmt
.endif

View File

@ -1,11 +1,16 @@
# $NetBSD: Makefile,v 1.4 2020/10/27 08:57:11 ryo Exp $
# $NetBSD: Makefile,v 1.5 2024/05/09 12:09:59 pho Exp $
.include "../Makefile.inc"
.if ${MACHINE_CPU} == "aarch64"
.PATH: ${S}/arch/aarch64/aarch64
.elif ${MACHINE_ARCH} == "i386" || \
${MACHINE_ARCH} == "x86_64"
.PATH: ${S}/arch/x86/x86
.endif
.PATH: ${S}/dev/vmt
KMOD= vmt
KMOD= vmt
IOCONF= vmt.ioconf
SRCS= vmt.c \
vmt_subr.c