Index | Thread | Search

From:
Mike Larkin <mlarkin@nested.page>
Subject:
Re: [EXT] Re: vmm(4)/amd64: reduce use of extern
To:
Dave Voutila <dv@sisu.io>
Cc:
Mark Kettenis <mark.kettenis@xs4all.nl>, Hans-Jörg Höxer <hshoexer@genua.de>, tech@openbsd.org
Date:
Tue, 29 Apr 2025 23:29:22 -0700

Download raw body.

Thread
On Tue, Apr 29, 2025 at 01:54:54PM -0400, Dave Voutila wrote:
> Mark Kettenis <mark.kettenis@xs4all.nl> writes:
>
> >> Date: Mon, 28 Apr 2025 15:25:48 +0200
> >> From: Hans-Jörg Höxer <hshoexer@genua.de>
> >>
> >> 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 <hshoexer@genua.de>
> >> > >
> >> > > 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 <machine/cpu.h> 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.
> >
> > Cool, yes, I think that's fine.  Maybe give dv@ or mlarkin@ a couple
> > of days to protest ;).
> >
> > ok kettenis@
> >
>
> ok dv@ as long as this doesn't break anything related to the
> vmm(4)/arm64 stuff we have lingering :D. I don't think that's hooked up
> to the default build config.
>

I'll fix it if it does. ok mlarkin

> >> ----------------------------------------------------------------------------
> >> commit dd3e5f229f00bc357b1121ed56180b8c0a87124d
> >> Author: Hans-Joerg Hoexer <hshoexer@genua.de>
> >> 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 *);
> >>
> >> [2:application/pkcs7-signature Show Save:smime.p7s (5kB)]
> >>
>