Merge branch 'freebsd/current/main' into hardened/current/master

This commit is contained in:
HardenedBSD Sync Services 2024-11-05 00:01:19 -07:00
commit ea7c25888c
No known key found for this signature in database
51 changed files with 549 additions and 254 deletions

View File

@ -187,6 +187,8 @@
..
vkbd
..
vmm
..
wg
..
wi

View File

@ -310,6 +310,13 @@ INCS+= iconv.h
LSUBDIRS+= dev/usb
.endif
.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "aarch64" || \
${MACHINE_CPUARCH} == "riscv"
.if ${MK_BHYVE} != "no"
LSUBDIRS+= dev/vmm
.endif
.endif
.if ${MACHINE_CPUARCH} == "powerpc" && ${MACHINE_ARCH} != "powerpcspe"
_dev_powermac_nvram= dev/powermac_nvram
.endif

View File

@ -16,7 +16,8 @@ enum {
};
struct vmctx {
int fd;
int fd; /* device file descriptor */
int ctlfd; /* vmm control descriptor */
struct {
vm_paddr_t base;
vm_size_t size;

View File

@ -37,6 +37,7 @@
#include <sys/cpuset.h>
#include <capsicum_helpers.h>
#include <err.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
@ -50,11 +51,12 @@
#include <vm/vm.h>
#include <machine/vmm.h>
#include <machine/vmm_dev.h>
#ifdef WITH_VMMAPI_SNAPSHOT
#include <machine/vmm_snapshot.h>
#endif
#include <dev/vmm/vmm_dev.h>
#include "vmmapi.h"
#include "internal.h"
@ -78,58 +80,104 @@
#define PROT_RW (PROT_READ | PROT_WRITE)
#define PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC)
#define CREATE(x) sysctlbyname("hw.vmm.create", NULL, NULL, (x), strlen((x)))
#define DESTROY(x) sysctlbyname("hw.vmm.destroy", NULL, NULL, (x), strlen((x)))
static int
vm_device_open(const char *name)
{
int fd, len;
char *vmfile;
char devpath[PATH_MAX];
len = strlen("/dev/vmm/") + strlen(name) + 1;
vmfile = malloc(len);
assert(vmfile != NULL);
snprintf(vmfile, len, "/dev/vmm/%s", name);
assert(strlen(name) <= VM_MAX_NAMELEN);
(void)snprintf(devpath, sizeof(devpath), "/dev/vmm/%s", name);
return (open(devpath, O_RDWR));
}
/* Open the device file */
fd = open(vmfile, O_RDWR, 0);
static int
vm_ctl_create(const char *name, int ctlfd)
{
struct vmmctl_vm_create vmc;
free(vmfile);
return (fd);
memset(&vmc, 0, sizeof(vmc));
if (strlcpy(vmc.name, name, sizeof(vmc.name)) >= sizeof(vmc.name)) {
errno = ENAMETOOLONG;
return (-1);
}
return (ioctl(ctlfd, VMMCTL_VM_CREATE, &vmc));
}
int
vm_create(const char *name)
{
int error, fd;
/* Try to load vmm(4) module before creating a guest. */
if (modfind("vmm") < 0)
kldload("vmm");
return (CREATE(name));
if (modfind("vmm") < 0) {
error = kldload("vmm");
if (error != 0)
return (-1);
}
fd = open("/dev/vmmctl", O_RDWR, 0);
if (fd < 0)
return (fd);
error = vm_ctl_create(name, fd);
if (error != 0) {
error = errno;
(void)close(fd);
errno = error;
return (-1);
}
(void)close(fd);
return (0);
}
struct vmctx *
vm_open(const char *name)
{
return (vm_openf(name, 0));
}
struct vmctx *
vm_openf(const char *name, int flags)
{
struct vmctx *vm;
int saved_errno;
bool created;
created = false;
vm = malloc(sizeof(struct vmctx) + strlen(name) + 1);
assert(vm != NULL);
vm->fd = -1;
vm->fd = vm->ctlfd = -1;
vm->memflags = 0;
vm->name = (char *)(vm + 1);
strcpy(vm->name, name);
memset(vm->memsegs, 0, sizeof(vm->memsegs));
if ((vm->fd = vm_device_open(vm->name)) < 0)
if ((vm->ctlfd = open("/dev/vmmctl", O_RDWR, 0)) < 0)
goto err;
vm->fd = vm_device_open(vm->name);
if (vm->fd < 0 && errno == ENOENT) {
if (flags & VMMAPI_OPEN_CREATE) {
if (vm_ctl_create(vm->name, vm->ctlfd) != 0)
goto err;
vm->fd = vm_device_open(vm->name);
created = true;
}
}
if (vm->fd < 0)
goto err;
if (!created && (flags & VMMAPI_OPEN_REINIT) != 0 && vm_reinit(vm) != 0)
goto err;
return (vm);
err:
saved_errno = errno;
free(vm);
if (created)
vm_destroy(vm);
else
vm_close(vm);
errno = saved_errno;
return (NULL);
}
@ -139,20 +187,24 @@ vm_close(struct vmctx *vm)
{
assert(vm != NULL);
close(vm->fd);
if (vm->fd >= 0)
(void)close(vm->fd);
if (vm->ctlfd >= 0)
(void)close(vm->ctlfd);
free(vm);
}
void
vm_destroy(struct vmctx *vm)
{
assert(vm != NULL);
struct vmmctl_vm_destroy vmd;
if (vm->fd >= 0)
close(vm->fd);
DESTROY(vm->name);
memset(&vmd, 0, sizeof(vmd));
(void)strlcpy(vmd.name, vm->name, sizeof(vmd.name));
if (ioctl(vm->ctlfd, VMMCTL_VM_DESTROY, &vmd) != 0)
warn("ioctl(VMMCTL_VM_DESTROY)");
free(vm);
vm_close(vm);
}
struct vcpu *

View File

@ -117,6 +117,9 @@ int vm_munmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, size_t len);
int vm_create(const char *name);
struct vmctx *vm_open(const char *name);
#define VMMAPI_OPEN_CREATE 0x01 /* create if the VM does not exist */
#define VMMAPI_OPEN_REINIT 0x02 /* reinitialize the VM if it exists */
struct vmctx *vm_openf(const char *name, int flags);
void vm_close(struct vmctx *ctx);
void vm_destroy(struct vmctx *ctx);
int vm_limit_rights(struct vmctx *ctx);

View File

@ -89,16 +89,81 @@ ns_get_sector_size(struct nvme_namespace_data *nsdata)
}
static void
devlist(const struct cmd *f, int argc, char *argv[])
scan_namespace(int fd, int ctrlr, uint32_t nsid)
{
struct nvme_controller_data cdata;
struct nvme_namespace_data nsdata;
char name[64];
uint8_t mn[64];
uint8_t buf[7];
uint32_t i;
uint64_t size;
int ctrlr, fd, found, ret;
if (read_namespace_data(fd, nsid, &nsdata) != 0)
return;
if (nsdata.nsze == 0)
return;
snprintf(name, sizeof(name), "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr,
NVME_NS_PREFIX, nsid);
size = nsdata.nsze * (uint64_t)ns_get_sector_size(&nsdata);
if (opt.human) {
humanize_number(buf, sizeof(buf), size, "B",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
printf(" %10s (%s)\n", name, buf);
} else {
printf(" %10s (%juMB)\n", name, (uintmax_t)size / 1024 / 1024);
}
}
static bool
scan_controller(int ctrlr)
{
struct nvme_controller_data cdata;
struct nvme_ns_list nslist;
char name[64];
uint8_t mn[64];
uint32_t nsid;
int fd, ret;
snprintf(name, sizeof(name), "%s%d", NVME_CTRLR_PREFIX, ctrlr);
ret = open_dev(name, &fd, 0, 0);
if (ret == EACCES) {
warnx("could not open "_PATH_DEV"%s\n", name);
return (false);
} else if (ret != 0)
return (false);
if (read_controller_data(fd, &cdata) != 0) {
close(fd);
return (true);
}
nvme_strvis(mn, cdata.mn, sizeof(mn), NVME_MODEL_NUMBER_LENGTH);
printf("%6s: %s\n", name, mn);
nsid = 0;
for (;;) {
if (read_active_namespaces(fd, nsid, &nslist) != 0)
break;
for (u_int i = 0; i < nitems(nslist.ns); i++) {
nsid = nslist.ns[i];
if (nsid == 0) {
break;
}
scan_namespace(fd, ctrlr, nsid);
}
if (nsid == 0 || nsid >= NVME_GLOBAL_NAMESPACE_TAG - 1)
break;
}
close(fd);
return (true);
}
static void
devlist(const struct cmd *f, int argc, char *argv[])
{
int ctrlr, found;
if (arg_parse(argc, argv, f))
return;
@ -108,41 +173,8 @@ devlist(const struct cmd *f, int argc, char *argv[])
while (ctrlr < NVME_MAX_UNIT) {
ctrlr++;
sprintf(name, "%s%d", NVME_CTRLR_PREFIX, ctrlr);
ret = open_dev(name, &fd, 0, 0);
if (ret == EACCES) {
warnx("could not open "_PATH_DEV"%s\n", name);
continue;
} else if (ret != 0)
continue;
if (scan_controller(ctrlr))
found++;
if (read_controller_data(fd, &cdata))
continue;
nvme_strvis(mn, cdata.mn, sizeof(mn), NVME_MODEL_NUMBER_LENGTH);
printf("%6s: %s\n", name, mn);
for (i = 0; i < cdata.nn; i++) {
if (read_namespace_data(fd, i + 1, &nsdata))
continue;
if (nsdata.nsze == 0)
continue;
sprintf(name, "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr,
NVME_NS_PREFIX, i + 1);
size = nsdata.nsze * (uint64_t)ns_get_sector_size(&nsdata);
if (opt.human) {
humanize_number(buf, sizeof(buf), size, "B",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
printf(" %10s (%s)\n", name, buf);
} else {
printf(" %10s (%juMB)\n", name, (uintmax_t)size / 1024 / 1024);
}
}
close(fd);
}
if (found == 0) {

View File

@ -142,6 +142,30 @@ read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata)
return (0);
}
int
read_active_namespaces(int fd, uint32_t nsid, struct nvme_ns_list *nslist)
{
struct nvme_pt_command pt;
memset(&pt, 0, sizeof(pt));
pt.cmd.opc = NVME_OPC_IDENTIFY;
pt.cmd.nsid = htole32(nsid);
pt.cmd.cdw10 = htole32(2);
pt.buf = nslist;
pt.len = sizeof(*nslist);
pt.is_read = 1;
if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0)
return (errno);
/* Convert data to host endian */
nvme_ns_list_swapbytes(nslist);
if (nvme_completion_is_error(&pt.cpl))
return (EIO);
return (0);
}
int
open_dev(const char *str, int *fd, int write, int exit_on_error)
{

View File

@ -81,6 +81,7 @@ int open_dev(const char *str, int *fd, int write, int exit_on_error);
void get_nsid(int fd, char **ctrlr_str, uint32_t *nsid);
int read_controller_data(int fd, struct nvme_controller_data *cdata);
int read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata);
int read_active_namespaces(int fd, uint32_t nsid, struct nvme_ns_list *nslist);
void print_hex(void *data, uint32_t length);
void print_namespace(struct nvme_namespace_data *nsdata);
void read_logpage(int fd, uint8_t log_page, uint32_t nsid, uint8_t lsp,

View File

@ -63,14 +63,14 @@ def build_response_packet(echo, ip, icmp, oip_ihl, special):
if icmp.type in icmp_id_seq_types:
pkt = ip / icmp / load
else:
ip.options = ""
del ip.options
pkt = ip / icmp / oip / oicmp / load
return pkt
def generate_ip_options(opts):
if not opts:
return ""
return []
routers = [
"192.0.2.10",
@ -85,11 +85,11 @@ def generate_ip_options(opts):
]
routers_zero = [0, 0, 0, 0, 0, 0, 0, 0, 0]
if opts == "EOL":
options = sc.IPOption(b"\x00")
options = sc.IPOption_EOL()
elif opts == "NOP":
options = sc.IPOption(b"\x01")
options = sc.IPOption_NOP()
elif opts == "NOP-40":
options = sc.IPOption(b"\x01" * 40)
options = sc.IPOption_NOP() * 40
elif opts == "RR":
ToolsHelper.set_sysctl("net.inet.ip.process_options", 0)
options = sc.IPOption_RR(pointer=40, routers=routers)
@ -116,9 +116,9 @@ def generate_ip_options(opts):
options = b"\x9f"
elif opts == "unk-40":
ToolsHelper.set_sysctl("net.inet.ip.process_options", 0)
options = sc.IPOption(b"\x9f" * 40)
options = b"\x9f" * 40
else:
options = ""
options = []
return options
@ -134,7 +134,7 @@ def pinger(
icmp_code: sc.scapy.fields.MultiEnumField,
# IP arguments
ihl: Optional[sc.scapy.fields.BitField] = None,
flags: Optional[sc.scapy.fields.FlagsField] = None,
flags: Optional[sc.scapy.fields.FlagsField] = 0,
opts: Optional[str] = None,
oip_ihl: Optional[sc.scapy.fields.BitField] = None,
special: Optional[str] = None,
@ -169,7 +169,7 @@ def pinger(
:keyword ihl: Internet Header Length, defaults to None
:type ihl: class:`scapy.fields.BitField`, optional
:keyword flags: IP flags - one of `DF`, `MF` or `evil`, defaults to None
:keyword flags: IP flags - one of `DF`, `MF` or `evil`, defaults to 0
:type flags: class:`scapy.fields.FlagsField`, optional
:keyword opts: Include IP options - one of `EOL`, `NOP`, `NOP-40`, `unk`,
`unk-40`, `RR`, `RR-same`, `RR-trunc`, `LSRR`, `LSRR-trunc`, `SSRR` or
@ -270,15 +270,15 @@ def pinger(
def redact(output):
"""Redact some elements of ping's output"""
pattern_replacements = [
("localhost \([0-9]{1,3}(\.[0-9]{1,3}){3}\)", "localhost"),
("from [0-9]{1,3}(\.[0-9]{1,3}){3}", "from"),
(r"localhost \([0-9]{1,3}(\.[0-9]{1,3}){3}\)", "localhost"),
(r"from [0-9]{1,3}(\.[0-9]{1,3}){3}", "from"),
("hlim=[0-9]*", "hlim="),
("ttl=[0-9]*", "ttl="),
("time=[0-9.-]*", "time="),
("cp: .*", "cp: xx xx xx xx xx xx xx xx"),
("dp: .*", "dp: xx xx xx xx xx xx xx xx"),
("\(-[0-9\.]+[0-9]+ ms\)", "(- ms)"),
("[0-9\.]+/[0-9.]+", "/"),
(r"\(-[0-9\.]+[0-9]+ ms\)", "(- ms)"),
(r"[0-9\.]+/[0-9.]+", "/"),
]
for pattern, repl in pattern_replacements:
output = re.sub(pattern, repl, output)
@ -724,6 +724,7 @@ PING(56=40+8+8 bytes) 2001:db8::1 --> 2001:db8::2
@pytest.mark.parametrize("expected", testdata)
@pytest.mark.require_user("root")
@pytest.mark.require_user("unprivileged")
def test_ping(self, expected):
"""Test ping"""
ping = subprocess.run(
@ -753,6 +754,7 @@ PING(56=40+8+8 bytes) 2001:db8::1 --> 2001:db8::2
@pytest.mark.parametrize("expected", ping46_testdata)
@pytest.mark.require_user("root")
@pytest.mark.require_user("unprivileged")
def test_ping_46(self, expected):
"""Test ping -4/ping -6"""
for version in [4, 6]:

View File

@ -465,7 +465,9 @@ vmm_handler(module_t mod, int what, void *arg)
switch (what) {
case MOD_LOAD:
if (vmm_is_hw_supported()) {
vmmdev_init();
error = vmmdev_init();
if (error != 0)
break;
error = vmm_init();
if (error == 0)
vmm_initialized = 1;

View File

@ -343,6 +343,11 @@ static int
as3722_detach(device_t dev)
{
struct as3722_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
if (sc->irq_h != NULL)
@ -351,7 +356,7 @@ as3722_detach(device_t dev)
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
LOCK_DESTROY(sc);
return (bus_generic_detach(dev));
return (0);
}
static phandle_t

View File

@ -1393,6 +1393,11 @@ static int
dc_detach(device_t dev)
{
struct dc_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
@ -1412,7 +1417,7 @@ dc_detach(device_t dev)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res);
LOCK_DESTROY(sc);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t tegra_dc_methods[] = {

View File

@ -1272,6 +1272,12 @@ static int
hdmi_detach(device_t dev)
{
struct hdmi_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
TEGRA_DRM_DEREGISTER_CLIENT(device_get_parent(sc->dev), sc->dev);
@ -1294,7 +1300,7 @@ hdmi_detach(device_t dev)
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
if (sc->mem_res != NULL)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t tegra_hdmi_methods[] = {

View File

@ -586,6 +586,11 @@ static int
host1x_detach(device_t dev)
{
struct host1x_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
@ -608,7 +613,7 @@ host1x_detach(device_t dev)
if (sc->mem_res != NULL)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res);
LOCK_DESTROY(sc);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t host1x_methods[] = {

View File

@ -166,13 +166,18 @@ static int
tegra_abpmisc_detach(device_t dev)
{
struct tegra_abpmisc_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
if (sc->abp_misc_res != NULL)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->abp_misc_res);
if (sc->strap_opt_res != NULL)
bus_release_resource(dev, SYS_RES_MEMORY, 1, sc->strap_opt_res);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t tegra_abpmisc_methods[] = {

View File

@ -499,6 +499,11 @@ static int
tegra_efuse_detach(device_t dev)
{
struct tegra_efuse_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
dev_sc = NULL;
@ -509,7 +514,7 @@ tegra_efuse_detach(device_t dev)
if (sc->mem_res != NULL)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t tegra_efuse_methods[] = {

View File

@ -740,6 +740,11 @@ static int
tegra_i2c_detach(device_t dev)
{
struct tegra_i2c_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
tegra_i2c_hw_init(sc);
@ -753,7 +758,7 @@ tegra_i2c_detach(device_t dev)
LOCK_DESTROY(sc);
if (sc->iicbus)
device_delete_child(dev, sc->iicbus);
return (bus_generic_detach(dev));
return (0);
}
static phandle_t

View File

@ -280,6 +280,11 @@ static int
tegra_mc_detach(device_t dev)
{
struct tegra_mc_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
if (sc->irq_h != NULL)
@ -290,7 +295,7 @@ tegra_mc_detach(device_t dev)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res);
LOCK_DESTROY(sc);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t tegra_mc_methods[] = {

View File

@ -266,6 +266,11 @@ static int
tegra_rtc_detach(device_t dev)
{
struct tegra_rtc_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
if (sc->irq_h != NULL)
@ -276,7 +281,7 @@ tegra_rtc_detach(device_t dev)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res);
LOCK_DESTROY(sc);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t tegra_rtc_methods[] = {

View File

@ -915,6 +915,11 @@ static int
ti_adc_detach(device_t dev)
{
struct ti_adc_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
@ -938,7 +943,7 @@ ti_adc_detach(device_t dev)
if (sc->sc_mem_res)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t ti_adc_methods[] = {

View File

@ -450,6 +450,11 @@ static int
max77620_detach(device_t dev)
{
struct max77620_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
if (sc->irq_h != NULL)
@ -458,7 +463,7 @@ max77620_detach(device_t dev)
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
LOCK_DESTROY(sc);
return (bus_generic_detach(dev));
return (0);
}
static phandle_t

View File

@ -366,11 +366,16 @@ static int
max77620_rtc_detach(device_t dev)
{
struct max77620_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
LOCK_DESTROY(sc);
return (bus_generic_detach(dev));
return (0);
}
/*

View File

@ -362,7 +362,9 @@ vmm_handler(module_t mod, int what, void *arg)
switch (what) {
case MOD_LOAD:
/* TODO: if (vmm_is_hw_supported()) { */
vmmdev_init();
error = vmmdev_init();
if (error != 0)
break;
error = vmm_init();
if (error == 0)
vmm_initialized = true;

View File

@ -38,7 +38,6 @@ ACPI_MODULE_NAME("CONTAINER")
static int acpi_syscont_probe(device_t);
static int acpi_syscont_attach(device_t);
static int acpi_syscont_detach(device_t);
static int acpi_syscont_alloc_msi(device_t, device_t,
int count, int maxcount, int *irqs);
static int acpi_syscont_release_msi(device_t bus, device_t dev,
@ -54,7 +53,7 @@ static device_method_t acpi_syscont_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, acpi_syscont_probe),
DEVMETHOD(device_attach, acpi_syscont_attach),
DEVMETHOD(device_detach, acpi_syscont_detach),
DEVMETHOD(device_detach, bus_generic_detach),
/* Bus interface */
DEVMETHOD(bus_add_child, bus_generic_add_child),
@ -108,13 +107,6 @@ acpi_syscont_attach(device_t dev)
return (bus_generic_attach(dev));
}
static int
acpi_syscont_detach(device_t dev)
{
return (bus_generic_detach(dev));
}
static int
acpi_syscont_alloc_msi(device_t bus, device_t dev, int count, int maxcount,
int *irqs)

View File

@ -42,7 +42,6 @@
static int adb_bus_probe(device_t dev);
static int adb_bus_attach(device_t dev);
static int adb_bus_detach(device_t dev);
static void adb_bus_enumerate(void *xdev);
static void adb_probe_nomatch(device_t dev, device_t child);
static int adb_print_child(device_t dev, device_t child);
@ -57,7 +56,7 @@ static device_method_t adb_bus_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, adb_bus_probe),
DEVMETHOD(device_attach, adb_bus_attach),
DEVMETHOD(device_detach, adb_bus_detach),
DEVMETHOD(device_detach, bus_generic_detach),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
DEVMETHOD(device_suspend, bus_generic_suspend),
DEVMETHOD(device_resume, bus_generic_resume),
@ -188,11 +187,6 @@ adb_bus_enumerate(void *xdev)
config_intrhook_disestablish(&sc->enum_hook);
}
static int adb_bus_detach(device_t dev)
{
return (bus_generic_detach(dev));
}
static void
adb_probe_nomatch(device_t dev, device_t child)
{

View File

@ -281,7 +281,9 @@ dpaa2_mc_detach(device_t dev)
struct dpaa2_devinfo *dinfo = NULL;
int error;
bus_generic_detach(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
if (sc->rcdev)
@ -292,10 +294,6 @@ dpaa2_mc_detach(device_t dev)
if (dinfo)
free(dinfo, M_DPAA2_MC);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
return (device_delete_children(dev));
}

View File

@ -309,6 +309,7 @@ static int
dwwdt_detach(device_t dev)
{
struct dwwdt_softc *sc = device_get_softc(dev);
int error;
if (dwwdt_started(sc)) {
/*
@ -318,6 +319,10 @@ dwwdt_detach(device_t dev)
return (EBUSY);
}
error = bus_generic_detach(dev);
if (error != 0)
return (error);
EVENTHANDLER_DEREGISTER(watchdog_list, sc->sc_evtag);
sc->sc_evtag = NULL;
@ -337,7 +342,7 @@ dwwdt_detach(device_t dev)
sc->sc_mem_res);
}
return (bus_generic_detach(dev));
return (0);
}
static int

View File

@ -4030,6 +4030,10 @@ ena_detach(device_t pdev)
return (EBUSY);
}
rc = bus_generic_detach(pdev);
if (rc != 0)
return (rc);
ether_ifdetach(adapter->ifp);
ifmedia_removeall(&adapter->media);
@ -4096,7 +4100,7 @@ ena_detach(device_t pdev)
free(ena_dev, M_DEVBUF);
return (bus_generic_detach(pdev));
return (0);
}
/******************************************************************************

View File

@ -189,12 +189,17 @@ int
simplebus_detach(device_t dev)
{
struct simplebus_softc *sc;
int rv;
rv = bus_generic_detach(dev);
if (rv != 0)
return (rv);
sc = device_get_softc(dev);
if (sc->ranges != NULL)
free(sc->ranges, M_DEVBUF);
return (bus_generic_detach(dev));
return (0);
}
void

View File

@ -213,7 +213,6 @@ static device_method_t gpiomdio_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, gpiomdio_probe),
DEVMETHOD(device_attach, gpiomdio_attach),
DEVMETHOD(device_detach, bus_generic_detach),
/* MDIO interface */
DEVMETHOD(miibus_readreg, gpiomdio_readreg),

View File

@ -820,6 +820,11 @@ gve_detach(device_t dev)
{
struct gve_priv *priv = device_get_softc(dev);
if_t ifp = priv->ifp;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
ether_ifdetach(ifp);
@ -836,7 +841,7 @@ gve_detach(device_t dev)
taskqueue_free(priv->service_tq);
if_free(ifp);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t gve_methods[] = {

View File

@ -637,8 +637,6 @@ hifn_detach(device_t dev)
crypto_unregister_all(sc->sc_cid);
bus_generic_detach(dev); /*XXX should be no children, right? */
bus_teardown_intr(dev, sc->sc_irq, sc->sc_intrhand);
/* XXX don't store rid */
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq);

View File

@ -226,11 +226,16 @@ static int
act8846_detach(device_t dev)
{
struct act8846_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
LOCK_DESTROY(sc);
return (bus_generic_detach(dev));
return (0);
}
static device_method_t act8846_methods[] = {

View File

@ -1879,6 +1879,11 @@ static int
mana_gd_detach(device_t dev)
{
struct gdma_context *gc = device_get_softc(dev);
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
mana_remove(&gc->mana);
@ -1890,7 +1895,7 @@ mana_gd_detach(device_t dev)
pci_disable_busmaster(dev);
return (bus_generic_detach(dev));
return (0);
}

View File

@ -59,14 +59,6 @@ mdio_attach(device_t dev)
return (bus_generic_attach(dev));
}
static int
mdio_detach(device_t dev)
{
bus_generic_detach(dev);
return (0);
}
static int
mdio_readreg(device_t dev, int phy, int reg)
{
@ -108,7 +100,7 @@ static device_method_t mdio_methods[] = {
DEVMETHOD(device_identify, mdio_identify),
DEVMETHOD(device_probe, mdio_probe),
DEVMETHOD(device_attach, mdio_attach),
DEVMETHOD(device_detach, mdio_detach),
DEVMETHOD(device_detach, bus_generic_detach),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
/* bus interface */

View File

@ -376,10 +376,10 @@ nvmf_scan_active_nslist(struct nvmf_softc *sc, struct nvme_ns_list *nslist,
MPASS(nsid == nslist->ns[nitems(nslist->ns) - 1] && nsid != 0);
if (nsid >= 0xfffffffd)
if (nsid >= NVME_GLOBAL_NAMESPACE_TAG - 1)
*nsidp = 0;
else
*nsidp = nsid + 1;
*nsidp = nsid;
return (true);
}

View File

@ -464,7 +464,6 @@ safe_detach(device_t dev)
mtx_destroy(&sc->sc_ringmtx);
safe_dma_free(sc, &sc->sc_ringalloc);
bus_generic_detach(dev);
bus_teardown_intr(dev, sc->sc_irq, sc->sc_ih);
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq);

View File

@ -138,7 +138,6 @@ static device_method_t sfp_fdt_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, sfp_fdt_probe),
DEVMETHOD(device_attach, sfp_fdt_attach),
DEVMETHOD(device_detach, bus_generic_detach),
/* SFF */
DEVMETHOD(sff_get_i2c_bus, sfp_fdt_get_i2c_bus),

View File

@ -8,6 +8,7 @@
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/ioccom.h>
#include <sys/jail.h>
#include <sys/kernel.h>
@ -917,11 +918,88 @@ SYSCTL_PROC(_hw_vmm, OID_AUTO, create,
NULL, 0, sysctl_vmm_create, "A",
NULL);
void
static int
vmmctl_open(struct cdev *cdev, int flags, int fmt, struct thread *td)
{
int error;
error = vmm_priv_check(td->td_ucred);
if (error != 0)
return (error);
if ((flags & FWRITE) == 0)
return (EPERM);
return (0);
}
static int
vmmctl_ioctl(struct cdev *cdev, u_long cmd, caddr_t data, int fflag,
struct thread *td)
{
int error;
switch (cmd) {
case VMMCTL_VM_CREATE: {
struct vmmctl_vm_create *vmc;
vmc = (struct vmmctl_vm_create *)data;
vmc->name[VM_MAX_NAMELEN] = '\0';
for (size_t i = 0; i < nitems(vmc->reserved); i++) {
if (vmc->reserved[i] != 0) {
error = EINVAL;
return (error);
}
}
error = vmmdev_create(vmc->name, td->td_ucred);
break;
}
case VMMCTL_VM_DESTROY: {
struct vmmctl_vm_destroy *vmd;
vmd = (struct vmmctl_vm_destroy *)data;
vmd->name[VM_MAX_NAMELEN] = '\0';
for (size_t i = 0; i < nitems(vmd->reserved); i++) {
if (vmd->reserved[i] != 0) {
error = EINVAL;
return (error);
}
}
error = vmmdev_lookup_and_destroy(vmd->name, td->td_ucred);
break;
}
default:
error = ENOTTY;
break;
}
return (error);
}
static struct cdevsw vmmctlsw = {
.d_name = "vmmctl",
.d_version = D_VERSION,
.d_open = vmmctl_open,
.d_ioctl = vmmctl_ioctl,
};
int
vmmdev_init(void)
{
struct cdev *cdev;
int error;
error = make_dev_p(MAKEDEV_CHECKNAME, &cdev, &vmmctlsw, NULL,
UID_ROOT, GID_WHEEL, 0600, "vmmctl");
if (error)
return (error);
pr_allow_flag = prison_add_allow(NULL, "vmm", NULL,
"Allow use of vmm in a jail.");
return (0);
}
int

View File

@ -18,7 +18,7 @@ struct thread;
struct vm;
struct vcpu;
void vmmdev_init(void);
int vmmdev_init(void);
int vmmdev_cleanup(void);
int vmmdev_machdep_ioctl(struct vm *vm, struct vcpu *vcpu, u_long cmd,
caddr_t data, int fflag, struct thread *td);
@ -54,4 +54,17 @@ extern const size_t vmmdev_machdep_ioctl_count;
#endif /* _KERNEL */
struct vmmctl_vm_create {
char name[VM_MAX_NAMELEN + 1];
int reserved[16];
};
struct vmmctl_vm_destroy {
char name[VM_MAX_NAMELEN + 1];
int reserved[16];
};
#define VMMCTL_VM_CREATE _IOWR('V', 0, struct vmmctl_vm_create)
#define VMMCTL_VM_DESTROY _IOWR('V', 1, struct vmmctl_vm_destroy)
#endif /* _DEV_VMM_DEV_H_ */

View File

@ -673,12 +673,17 @@ static int
fsl_pcib_detach(device_t dev)
{
struct fsl_pcib_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
mtx_destroy(&sc->sc_cfg_mtx);
return (bus_generic_detach(dev));
return (0);
}
static int

View File

@ -259,6 +259,11 @@ cuda_attach(device_t dev)
static int cuda_detach(device_t dev) {
struct cuda_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
@ -267,7 +272,7 @@ static int cuda_detach(device_t dev) {
bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_memrid, sc->sc_memr);
mtx_destroy(&sc->sc_mutex);
return (bus_generic_detach(dev));
return (0);
}
static uint8_t

View File

@ -524,6 +524,11 @@ static int
pmu_detach(device_t dev)
{
struct pmu_softc *sc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
@ -535,7 +540,7 @@ pmu_detach(device_t dev)
bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_memrid, sc->sc_memr);
mtx_destroy(&sc->sc_mutex);
return (bus_generic_detach(dev));
return (0);
}
static uint8_t

View File

@ -102,12 +102,11 @@ enum vm_reg_name {
#define VM_INTINFO_HWEXCEPTION (3 << 8)
#define VM_INTINFO_SWINTR (4 << 8)
#define VM_MAX_NAMELEN 32
#define VM_MAX_SUFFIXLEN 15
#ifdef _KERNEL
#define VM_MAX_NAMELEN 32
struct vm;
struct vm_exception;
struct vm_exit;

View File

@ -34,6 +34,8 @@
#ifndef _VMM_DEV_H_
#define _VMM_DEV_H_
#include <machine/vmm.h>
struct vm_memmap {
vm_paddr_t gpa;
int segid; /* memory segment */

View File

@ -255,7 +255,9 @@ vmm_handler(module_t mod, int what, void *arg)
switch (what) {
case MOD_LOAD:
/* TODO: check if has_hyp here? */
vmmdev_init();
error = vmmdev_init();
if (error != 0)
break;
error = vmm_init();
if (error == 0)
vmm_initialized = true;

View File

@ -30,11 +30,9 @@
#include <machine/atomic.h>
#if defined(_KERNEL) || defined(_STANDALONE)
#include <sys/systm.h>
#else
#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <stdbool.h>
#define KASSERT(exp, msg) /* */
#endif
#define REFCOUNT_SATURATED(val) (((val) & (1U << 31)) != 0)

View File

@ -47,7 +47,14 @@ find_device() {
ctladm port -o on -p 0 >/dev/null
HEXLUN=`printf %x $LUN`
while true; do
dev=`camcontrol devlist | awk -v lun=$HEXLUN '/FREEBSD CTL/ && $9==lun {split($10, fields, /[,]/); print fields[1];}' | sed 's:[()]::'`
dev=`camcontrol devlist | awk -v lun=$HEXLUN '
/FREEBSD CTL.*,pass/ && $9==lun {
split($10, fields, /[,]/); print fields[1];
}
/FREEBSD CTL.*\(pass/ && $9==lun {
split($10, fields, /[,]/); print fields[2];
}
' | sed 's:[()]::'`
if [ -z "$dev" -o ! -c /dev/$dev ]; then
retries=$(( $retries - 1 ))
if [ $retries -eq 0 ]; then

View File

@ -43,6 +43,14 @@ err()
exit 1
}
cleanup()
{
rc=$?
rm -fr "$GITARC_TMPDIR"
trap - EXIT
exit $rc
}
err_usage()
{
cat >&2 <<__EOF__
@ -147,6 +155,12 @@ __EOF__
exit 1
}
# Use xmktemp instead of mktemp when creating temporary files.
xmktemp()
{
mktemp "${GITARC_TMPDIR:?}/tmp.XXXXXXXXXX" || exit 1
}
#
# Fetch the value of a boolean config variable ($1) and return true
# (0) if the variable is true. The default value to use if the
@ -200,7 +214,7 @@ diff2status()
err "invalid diff ID $diff"
fi
tmp=$(mktemp)
tmp=$(xmktemp)
echo '{"names":["'"$diff"'"]}' |
arc_call_conduit -- phid.lookup > "$tmp"
status=$(jq -r "select(.response != []) | .response.${diff}.status" < "$tmp")
@ -279,7 +293,7 @@ create_one_review()
return 1
fi
msg=$(mktemp)
msg=$(xmktemp)
git show -s --format='%B' "$commit" > "$msg"
printf "\nTest Plan:\n" >> "$msg"
printf "\nReviewers:\n" >> "$msg"
@ -308,7 +322,6 @@ create_one_review()
]}' |
arc_call_conduit -- differential.revision.edit >&3
fi
rm -f "$msg"
return 0
}
@ -328,7 +341,7 @@ diff2reviewers()
jq '.response.data[0].attachments.reviewers.reviewers[] | select(.status == "accepted").reviewerPHID')
if [ -n "$userids" ]; then
echo '{
"constraints": {"phids": ['"$(printf "%s" "$userids" | tr '[:space:]' ',')"']}
"constraints": {"phids": ['"$(echo "$userids" | tr '[:blank:]' ',')"']}
}' |
arc_call_conduit -- user.search |
jq -r '.response.data[].fields.username'
@ -532,7 +545,7 @@ find_author()
# don't know if the prior _ are _ or + or any number of other characters.
# Since there's issues here, prompt
a=$(printf "%s <%s>\n" "${name}" $(echo "$addr" | sed -e 's/\(.*\)_/\1@/'))
echo "Making best guess: Truning ${addr} to ${a}"
echo "Making best guess: Turning ${addr} to ${a}"
if ! prompt; then
echo "ABORT"
return
@ -542,38 +555,46 @@ find_author()
patch_commit()
{
local diff reviewid review_data authorid user_data user_addr user_name author
local tmp author_addr author_name
local diff reviewid review_data authorid user_data user_addr user_name
local diff_data author_addr author_name author tmp
diff=$1
reviewid=$(diff2phid "$diff")
# Get the author phid for this patch
review_data=$(mktemp)
review_data=$(xmktemp)
echo '{"constraints": {"phids": ["'"$reviewid"'"]}}' | \
arc_call_conduit -- differential.revision.search > "$review_data"
authorid=$(jq -r '.response.data[].fields.authorPHID' "$review_data")
# Get metadata about the user that submitted this patch
user_data=$(mktemp)
user_data=$(xmktemp)
echo '{"constraints": {"phids": ["'"$authorid"'"]}}' | \
arc_call_conduit -- user.search | \
jq -r '.response.data[].fields' > "$user_data"
user_addr=$(jq -r '.username' "$user_data")
user_name=$(jq -r '.realName' "$user_data")
rm "$user_data"
# Dig the data out of querydiffs api endpoint, although it's deprecated,
# since it's one of the few places we can get email addresses. It's unclear
# if we can expect multiple difference ones of these. Some records don't
# have this data, so we remove all the 'null's. We sort the results and
# remove duplicates 'just to be sure' since we've not seen multiple
# records that match.
diff_data=$(mktemp)
diff_data=$(xmktemp)
echo '{"revisionIDs": [ '"${diff#D}"' ]}' | \
arc_call_conduit -- differential.querydiffs |
jq -r '.response | flatten | .[]' > "$diff_data"
author_addr=$(jq -r ".authorEmail?" "$diff_data" | sort -u)
author_name=$(jq -r ".authorName?" "$diff_data" | sort -u)
# JSON will return "null" when a field is not populated.
# Turn this string into an empty one.
if [ "$author_addr" = "null" ]; then
author_addr=""
fi
if [ "$author_name" = "null" ]; then
author_name=""
fi
author=$(find_author "$user_addr" "$user_name" "$author_addr" "$author_name")
rm "$diff_data"
# If we had to guess, and the user didn't want to guess, abort
if [ "${author}" = "ABORT" ]; then
@ -581,12 +602,11 @@ patch_commit()
exit 1
fi
tmp=$(mktemp)
jq -r '.response.data[].fields.title' "$review_data" > $tmp
echo >> $tmp
jq -r '.response.data[].fields.summary' "$review_data" >> $tmp
echo >> $tmp
rm "$review_data"
tmp=$(xmktemp)
jq -r '.response.data[].fields.title' "$review_data" > "$tmp"
echo >> "$tmp"
jq -r '.response.data[].fields.summary' "$review_data" >> "$tmp"
echo >> "$tmp"
# XXX this leaves an extra newline in some cases.
reviewers=$(diff2reviewers "$diff" | sed '/^$/d' | paste -sd ',' - | sed 's/,/, /g')
if [ -n "$reviewers" ]; then
@ -595,7 +615,6 @@ patch_commit()
# XXX TODO refactor with gitarc__stage maybe?
printf "Differential Revision:\thttps://reviews.freebsd.org/%s\n" "${diff}" >> "$tmp"
git commit --author "${author}" --file "$tmp"
rm "$tmp"
}
gitarc__patch()
@ -655,7 +674,7 @@ gitarc__stage()
git checkout -q -b "${branch}" main
fi
tmp=$(mktemp)
tmp=$(xmktemp)
for commit in $commits; do
git show -s --format=%B "$commit" > "$tmp"
title=$(git show -s --format=%s "$commit")
@ -816,4 +835,7 @@ if get_bool_config arc.browse false; then
BROWSE=--browse
fi
GITARC_TMPDIR=$(mktemp -d) || exit 1
trap cleanup EXIT HUP INT QUIT TRAP USR1 TERM
gitarc__"${verb}" "$@"

View File

@ -521,41 +521,23 @@ do_open(const char *vmname)
{
struct vmctx *ctx;
int error;
bool reinit, romboot;
reinit = false;
bool romboot;
romboot = bootrom_boot();
error = vm_create(vmname);
if (error) {
if (errno == EEXIST) {
if (romboot) {
reinit = true;
} else {
/*
* The virtual machine has been setup by the
* userspace bootloader.
*/
}
} else {
perror("vm_create");
exit(4);
}
} else {
if (!romboot) {
/*
* If the virtual machine was just created then a
* bootrom must be configured to boot it.
*/
fprintf(stderr, "virtual machine cannot be booted\n");
exit(4);
}
}
ctx = vm_open(vmname);
/*
* If we don't have a boot ROM, the guest context must have been
* initialized by bhyveload(8) or equivalent.
*/
ctx = vm_openf(vmname, romboot ? VMMAPI_OPEN_REINIT : 0);
if (ctx == NULL) {
perror("vm_open");
exit(4);
if (errno != ENOENT)
err(4, "vm_openf");
if (!romboot)
errx(4, "no bootrom was configured");
ctx = vm_openf(vmname, VMMAPI_OPEN_CREATE);
if (ctx == NULL)
err(4, "vm_openf");
}
#ifndef WITHOUT_CAPSICUM
@ -563,13 +545,6 @@ do_open(const char *vmname)
err(EX_OSERR, "vm_limit_rights");
#endif
if (reinit) {
error = vm_reinit(ctx);
if (error) {
perror("vm_reinit");
exit(4);
}
}
error = vm_set_topology(ctx, cpu_sockets, cpu_cores, cpu_threads, 0);
if (error)
errx(EX_OSERR, "vm_set_topology");

View File

@ -388,13 +388,8 @@ main(int argc, char *argv[])
if (vmname == NULL)
usage(opts);
error = 0;
if (!error && create)
error = vm_create(vmname);
if (!error) {
ctx = vm_open(vmname);
ctx = vm_openf(vmname, create ? VMMAPI_OPEN_CREATE : 0);
if (ctx == NULL) {
fprintf(stderr,
"vm_open: %s could not be opened: %s\n",
@ -402,8 +397,8 @@ main(int argc, char *argv[])
exit(1);
}
vcpu = vm_vcpu_open(ctx, vcpuid);
}
error = 0;
if (!error && memsize)
error = vm_setup_memory(ctx, memsize, VM_MMAP_ALL);