Commit graph

15 commits

Author SHA1 Message Date
Mark Johnston
dc450b388b vmm: Remove more of vmmdev_open()
The softc pointer is now unused, just remove it.

Reported by:	se
Fixes:	66fc442421 ("vmm: Remove an incorrect credential check in vmmdev_open()")
2024-09-05 00:36:27 +00:00
Mark Johnston
66fc442421 vmm: Remove an incorrect credential check in vmmdev_open()
Checking pointer equality here is too strict and can lead to incorrect
errors, as credentials are frequently copied to avoid reference counting
overhead.

The check is new with commit 4008758105 and was added with the goal of
allowing non-root users to create VMs in mind.  Just remove it for now.

Reported by:	Alonso Cárdenas Márquez <acardenas@bsd-peru.org>
Reviewed by:	jhb
Fixes:		4008758105 ("vmm: Validate credentials when opening a vmmdev")
Differential Revision:	https://reviews.freebsd.org/D46535
2024-09-04 22:54:25 +00:00
Mark Johnston
cef5f43f81 vmm: Use make_dev_s() to create vmm devices
This avoids creating windows where a device file is accessible but the
device-specific field is not set.

Now that vmmdev_mtx is a sleepable lock, avoid dropping it while
creating devices files.  This makes it easier to handle races and
simplifies some code; for example, the VSC_LINKED flag is no longer
needed.

Suggested by:	jhb
Reviewed by:	imp, jhb
Differential Revision:	https://reviews.freebsd.org/D46488
2024-09-01 14:09:17 +00:00
Mark Johnston
887c0877a6 vmm: Use an sx lock for vmmdev_mtx
This will make it easier to atomically create the device file and set
its si_drv1 member.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D46487
2024-09-01 14:03:16 +00:00
Mark Johnston
4008758105 vmm: Validate credentials when opening a vmmdev
Rather than performing privilege checks after a specific VM's device
file is opened, do it once at the time the device file is opened.  This
means that one can continue to access a VM via its device fd after
attaching to a jail which does not have vmm enabled, but this seems like
a reasonable semantic to have anyway.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D46486
2024-09-01 14:03:16 +00:00
Mark Johnston
a852dc580c vmm: Harmonize compat ioctl definitions
For compat ioctls and structures, we use a mix of suffixes: _old,
_fbsd<version>, _<version>.  Standardize on _<version> to make things
more consistent.  No functional change intended.

Reported by:	jhb
Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46449
2024-08-28 19:12:32 +00:00
Mark Johnston
72ea8f41e1 vmm: Let devmem devices reference the VM credential
Otherwise they are globally visible (in jails with allow.vmm set),
instead of being restricted to the jail to which the VM belongs.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46448
2024-08-28 19:12:16 +00:00
Mark Johnston
c23da668fa vmm: Be more consistent with the credential used for VM lookup
vmmdev_lookup() is used from sysctl context to find a VM by name.
There, a reference credential is already passed, so use that instead of
assuming that it's the same as curthread->td_ucred, even though that's
true today.  No functional change intended.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46447
2024-08-28 18:57:33 +00:00
Mark Johnston
f4002135a2 vmm: Remove an unneeded lookup in devmem_create_cdev()
The sole caller of this function already holds a pointer to the VM's
softc, so rather than passing the VM name and looking it up again, just
pass the softc pointer directly.  This function is only called from an
ioctl context, so the softc structure will remain live.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46446
2024-08-28 18:57:21 +00:00
Mark Johnston
063a8bd908 vmm: Factor most of sysctl_vmm_destroy() into a separate function
This will make it easy to share code with an ioctl handler which creates
VMs.  No functional change intended.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46445
2024-08-28 18:57:12 +00:00
Mark Johnston
d581970976 vmm: Factor most of sysctl_vmm_create() out into a separate function
This will make it easy to share code with an ioctl handler which creates
VMs.  No functional change intended.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46444
2024-08-28 18:57:03 +00:00
Mark Johnston
e12b6aaf0d vmm: Move compat ioctl definitions to vmm_dev.c
There is no reason to keep them in vmm_dev.h.  No functional change
intended.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46432
2024-08-26 18:42:13 +00:00
Mark Johnston
b9ef152bec vmm: Merge vmm_dev.c
This file contains the vmm device file implementation.  Most of this
code is not machine-dependent and so shouldn't be duplicated this way.
Move most of it into a generic dev/vmm/vmm_dev.c.  This will make it
easier to introduce a cdev-based interface for VM creation, which in
turn makes it possible to implement support for running bhyve as an
unprivileged user.

Machine-dependent ioctls continue to be handled in machine-dependent
code.  To make the split a bit easier to handle, introduce a pair of
tables which define MI and MD ioctls.  Each table entry can set flags
which determine which locks need to be held in order to execute the
handler.  vmmdev_ioctl() now looks up the ioctl in one of the tables,
acquires locks and either handles the ioctl directly or calls
vmmdev_machdep_ioctl() to handle it.

No functional change intended.  There is a lot of churn in this change
but the underlying logic in the ioctl handlers is the same.  For now,
vmm_dev.h is still mostly separate, even though some parts could be
merged in principle.  This would involve changing include paths for
userspace, though.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46431
2024-08-26 18:41:39 +00:00
Mark Johnston
93e81baa1c vmm: Move duplicated stats code into a generic file
There is a small difference between the arm64 and amd64 implementations:
the latter makes use of a "scope" to exclude AMD-specific stats on Intel
systems and vice-versa.  Replace this with a more generic predicate
callback which can be used for the same purpose.

No functional change intended.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46430
2024-08-26 18:41:14 +00:00
Mark Johnston
3ccb02334b vmm: Move vmm_ktr.h to a common directory
No functional change intended.

Reviewed by:	corvink, jhb, emaste
Differential Revision:	https://reviews.freebsd.org/D46429
2024-08-26 18:41:05 +00:00