Module Name: src Committed By: pho Date: Thu May 9 12:10:00 UTC 2024
Modified Files: src/distrib/sets/lists/modules: ad.aarch64 src/share/man/man4: vmt.4 src/sys/arch/aarch64/aarch64: cpu.c src/sys/arch/aarch64/conf: files.aarch64 src/sys/arch/aarch64/include: cpu.h src/sys/arch/evbarm/conf: GENERIC64 src/sys/arch/x86/x86: vmt.c src/sys/dev/fdt: files.fdt src/sys/dev/vmt: vmt_subr.c src/sys/modules: Makefile src/sys/modules/vmt: Makefile Added Files: src/sys/arch/aarch64/aarch64: vmt.c Removed Files: src/sys/dev/fdt: vmt_fdt.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/distrib/sets/lists/modules/ad.aarch64 cvs rdiff -u -r1.3 -r1.4 src/share/man/man4/vmt.4 cvs rdiff -u -r1.74 -r1.75 src/sys/arch/aarch64/aarch64/cpu.c cvs rdiff -u -r0 -r1.1 src/sys/arch/aarch64/aarch64/vmt.c cvs rdiff -u -r1.44 -r1.45 src/sys/arch/aarch64/conf/files.aarch64 cvs rdiff -u -r1.49 -r1.50 src/sys/arch/aarch64/include/cpu.h cvs rdiff -u -r1.214 -r1.215 src/sys/arch/evbarm/conf/GENERIC64 cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/x86/vmt.c cvs rdiff -u -r1.72 -r1.73 src/sys/dev/fdt/files.fdt cvs rdiff -u -r1.6 -r0 src/sys/dev/fdt/vmt_fdt.c cvs rdiff -u -r1.9 -r1.10 src/sys/dev/vmt/vmt_subr.c cvs rdiff -u -r1.285 -r1.286 src/sys/modules/Makefile cvs rdiff -u -r1.4 -r1.5 src/sys/modules/vmt/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/modules/ad.aarch64 diff -u src/distrib/sets/lists/modules/ad.aarch64:1.12 src/distrib/sets/lists/modules/ad.aarch64:1.13 --- src/distrib/sets/lists/modules/ad.aarch64:1.12 Tue Apr 11 10:30:41 2023 +++ src/distrib/sets/lists/modules/ad.aarch64 Thu May 9 12:09:58 2024 @@ -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 Index: src/share/man/man4/vmt.4 diff -u src/share/man/man4/vmt.4:1.3 src/share/man/man4/vmt.4:1.4 --- src/share/man/man4/vmt.4:1.3 Tue Oct 27 08:57:10 2020 +++ src/share/man/man4/vmt.4 Thu May 9 12:09:58 2024 @@ -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 <ma...@openbsd.org> @@ -23,7 +23,6 @@ .Nd VMware Tools driver .Sh SYNOPSIS .Cd "vmt0 at cpu0" -.Cd "vmt0 at fdt?" .Sh DESCRIPTION The .Nm Index: src/sys/arch/aarch64/aarch64/cpu.c diff -u src/sys/arch/aarch64/aarch64/cpu.c:1.74 src/sys/arch/aarch64/aarch64/cpu.c:1.75 --- src/sys/arch/aarch64/aarch64/cpu.c:1.74 Wed Feb 7 04:20:26 2024 +++ src/sys/arch/aarch64/aarch64/cpu.c Thu May 9 12:09:58 2024 @@ -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 { Index: src/sys/arch/aarch64/conf/files.aarch64 diff -u src/sys/arch/aarch64/conf/files.aarch64:1.44 src/sys/arch/aarch64/conf/files.aarch64:1.45 --- src/sys/arch/aarch64/conf/files.aarch64:1.44 Sun Feb 18 09:03:44 2024 +++ src/sys/arch/aarch64/conf/files.aarch64 Thu May 9 12:09:58 2024 @@ -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 Index: src/sys/arch/aarch64/include/cpu.h diff -u src/sys/arch/aarch64/include/cpu.h:1.49 src/sys/arch/aarch64/include/cpu.h:1.50 --- src/sys/arch/aarch64/include/cpu.h:1.49 Sat Feb 25 00:40:22 2023 +++ src/sys/arch/aarch64/include/cpu.h Thu May 9 12:09:59 2024 @@ -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 */ Index: src/sys/arch/evbarm/conf/GENERIC64 diff -u src/sys/arch/evbarm/conf/GENERIC64:1.214 src/sys/arch/evbarm/conf/GENERIC64:1.215 --- src/sys/arch/evbarm/conf/GENERIC64:1.214 Wed Oct 11 07:49:29 2023 +++ src/sys/arch/evbarm/conf/GENERIC64 Thu May 9 12:09:59 2024 @@ -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? Index: src/sys/arch/x86/x86/vmt.c diff -u src/sys/arch/x86/x86/vmt.c:1.21 src/sys/arch/x86/x86/vmt.c:1.22 --- src/sys/arch/x86/x86/vmt.c:1.21 Tue Oct 27 08:57:11 2020 +++ src/sys/arch/x86/x86/vmt.c Thu May 9 12:09:59 2024 @@ -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> Index: src/sys/dev/fdt/files.fdt diff -u src/sys/dev/fdt/files.fdt:1.72 src/sys/dev/fdt/files.fdt:1.73 --- src/sys/dev/fdt/files.fdt:1.72 Thu Jan 18 07:48:57 2024 +++ src/sys/dev/fdt/files.fdt Thu May 9 12:09:59 2024 @@ -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 simplea 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 Index: src/sys/dev/vmt/vmt_subr.c diff -u src/sys/dev/vmt/vmt_subr.c:1.9 src/sys/dev/vmt/vmt_subr.c:1.10 --- src/sys/dev/vmt/vmt_subr.c:1.9 Tue Apr 2 20:04:16 2024 +++ src/sys/dev/vmt/vmt_subr.c Thu May 9 12:09:59 2024 @@ -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> Index: src/sys/modules/Makefile diff -u src/sys/modules/Makefile:1.285 src/sys/modules/Makefile:1.286 --- src/sys/modules/Makefile:1.285 Tue Apr 2 22:37:34 2024 +++ src/sys/modules/Makefile Thu May 9 12:09:59 2024 @@ -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 Index: src/sys/modules/vmt/Makefile diff -u src/sys/modules/vmt/Makefile:1.4 src/sys/modules/vmt/Makefile:1.5 --- src/sys/modules/vmt/Makefile:1.4 Tue Oct 27 08:57:11 2020 +++ src/sys/modules/vmt/Makefile Thu May 9 12:09:59 2024 @@ -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 Added files: Index: src/sys/arch/aarch64/aarch64/vmt.c diff -u /dev/null src/sys/arch/aarch64/aarch64/vmt.c:1.1 --- /dev/null Thu May 9 12:10:00 2024 +++ src/sys/arch/aarch64/aarch64/vmt.c Thu May 9 12:09:58 2024 @@ -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; +}