From: Hans-Jörg Höxer Subject: Re: [EXT] Re: vmm(4)/amd64: reduce use of extern To: Date: Mon, 28 Apr 2025 15:25:48 +0200 Hi, On Mon, Apr 28, 2025 at 01:20:15PM +0200, Mark Kettenis wrote: > > Date: Mon, 28 Apr 2025 12:57:18 +0200 > > From: Hans-Jörg Höxer > > > > Hi, > > > > this diff reduces the use of "extern" in amd64/vmm_machdep.c and related > > files. There might be some more low hanging fruits in eg. pmap.c. > > The problem is that ends up getting included by a lot > of files (even from userland). So there is a big risk of namespace > pollution. This is somewhat mitigated by #ifdef _KERNEL, but some of > the userland code in base does do a #define _KERNEL. It is also > mitigated by using a cpu_ prefix for the symbol names. I see and agree. New approach: Diff below just deals with amd64/vmm_machdep.c and varibles declared in dev/vmm.c. I'd suggest to declare those in dev/vmm.h. Future implementations of vmm_machdep.c eg. for arm64 will likely need those, too. Take care, HJ. ---------------------------------------------------------------------------- commit dd3e5f229f00bc357b1121ed56180b8c0a87124d Author: Hans-Joerg Hoexer Date: Mon Apr 28 15:15:07 2025 +0200 vmm(4)/amd64: reduce use of extern diff --git a/sys/arch/amd64/amd64/vmm_machdep.c b/sys/arch/amd64/amd64/vmm_machdep.c index 9b5d56da27b..c9a2f8b73f9 100644 --- a/sys/arch/amd64/amd64/vmm_machdep.c +++ b/sys/arch/amd64/amd64/vmm_machdep.c @@ -193,9 +193,6 @@ const struct kmem_pa_mode vmm_kp_contig = { .kp_zero = 1, }; -extern struct cfdriver vmm_cd; -extern const struct cfattach vmm_ca; - /* * Helper struct to easily get the VMCS field IDs needed in vmread/vmwrite * to access the individual fields of the guest segment registers. This @@ -225,12 +222,6 @@ const struct { VMCS_GUEST_IA32_TR_AR, VMCS_GUEST_IA32_TR_BASE } }; -/* Pools for VMs and VCPUs */ -extern struct pool vm_pool; -extern struct pool vcpu_pool; - -extern struct vmm_softc *vmm_softc; - /* IDT information used when populating host state area */ extern vaddr_t idt_vaddr; extern struct gate_descriptor *idt; diff --git a/sys/dev/vmm/vmm.h b/sys/dev/vmm/vmm.h index 00cf820c9f1..f27433b9e1b 100644 --- a/sys/dev/vmm/vmm.h +++ b/sys/dev/vmm/vmm.h @@ -228,6 +228,12 @@ struct vmm_softc { uint8_t vpids[512]; /* [p] bitmap of VPID/ASIDs */ }; +extern struct vmm_softc *vmm_softc; +extern struct pool vm_pool; +extern struct pool vcpu_pool; +extern struct cfdriver vmm_cd; +extern const struct cfattach vmm_ca; + int vmm_probe(struct device *, void *, void *); int vmm_activate(struct device *, int); void vmm_attach(struct device *, struct device *, void *);