Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys/dev/nvmm/x86



> Date: Sat, 18 Jul 2026 22:04:30 +0900
> From: Takashi YAMAMOTO <yamt9999%gmail.com@localhost>
> 
> On Wed, Jul 15, 2026 at 10:22 AM Taylor R Campbell <riastradh%netbsd.org@localhost> wrote:
> >
> > nvmm: Add support for extended CPU state (XSAVE) beyond x87/SSE.
> 
> i have been using a similar patch for a while. but i haven't committed
> it because
> i was not happy to implement cpuid emulation bits in kernel like this.

Sorry, didn't realize you were working on this already!

> it's simpler to make qemu provide them via NVMM_VCPU_CONF_CPUID
> or something similar. (in addition to xcr0)
> cpuid emulation is quite complex and will likely be more complex in future.
> it's better to leverage what qemu already has.
> what do you think?

No opinion, sounds reasonable on its face -- while it is sometimes
nice to just expose all (safe) host features to the guest, I would
also want it to be easy to specify the exact features up front for
reliable migration.  Would this require adding a hook to let qemu
completely override the CPUID visible to the guest, or can qemu use
the existing CPUID overrides to manage it?  I think they might be
limited in space.

> > Instead, we can expose the XSAVE area in another location in the
> > virtual machine uvm object, and create an ioctl for querying its
> > object address and size so userland can mmap it.  TBD.
> 
> i was thinking of having a new NVMM_IOC_VCPU_xxx to get the extra MD state.

Yes, that's what I had in mind.  Something like:

	struct nvmm_ioc_vcpu_xstate xstate = {
		.thingamajig = NVMM_X86_VCPU_XSTATE_XSAVE,
	};
	void *vxsave;
	struct xsave_header *xsave;

	if (ioctl(nvmm_fd, NVMM_IOC_VCPU_MAP_XSTATE, &xstate) == -1)
		goto fail;
	vxsave = mmap(NULL, roundup(xstate.size, PAGE_SIZE),
	    PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FILE, nvmm_fd,
	    xstate.offset);
	if (vxsave == MAP_FAILED)
		goto fail;
	xsave = vxsave;

Then NVMM_IOC_VCPU_GETSTATE/NVMM_IOC_VCPU_SETSTATE with the flag
NVMM_X86_STATE_XSAVE, or setting the flag in comm->state_wanted /
comm->state_cached, would arrange to make it available in the mmapped
region, just like the other state is already made available in the
mmapped comm page.

Except we should probably consider how it might look on Arm (with SVE
and SME) or RISC-V before committing to this ioctl interface.


Home | Main Index | Thread Index | Old Index