diff --git a/sysutils/bhyve+/Makefile b/sysutils/bhyve+/Makefile index 849ab4848bc6..14aa08a4533c 100644 --- a/sysutils/bhyve+/Makefile +++ b/sysutils/bhyve+/Makefile @@ -1,94 +1,113 @@ PORTNAME= bhyve+ PORTVERSION= 0.1.0 CATEGORIES= sysutils MAINTAINER= pali.gabor@gmail.com COMMENT= BHyVe with unofficial extensions WWW= https://github.com/pgj/freebsd-bhyve-plus-port LICENSE= BSD2CLAUSE ONLY_FOR_ARCHS= amd64 USES= kmod uidfix .include SRCS= ${SRC_BASE}/sys/modules/vmm \ ${SRC_BASE}/sys/amd64/vmm \ ${SRC_BASE}/lib/libvmmapi \ ${SRC_BASE}/usr.sbin/bhyve \ ${SRC_BASE}/usr.sbin/bhyvectl \ ${SRC_BASE}/usr.sbin/bhyveload \ ${SRC_BASE}/share/mk \ ${SRC_BASE}/contrib/bmake/mk .for _src in ${SRCS} . if !exists(${_src}) && empty(IGNORE) IGNORE+= requires bhyve and vmm source files in ${_src} . endif .endfor USE_GITHUB= yes GH_ACCOUNT= conclusiveeng GH_PROJECT= lib9p GH_TAGNAME= 7ef466772108856ee3e093735033232a6f1a3f04 USE_LDCONFIG= yes +LIBVMMAPI_VERSION= 5.1 +LIB9P_VERSION= 1.1 + +PLIST_SUB= 9P_SHLIB_MAJOR=${LIB9P_VERSION} \ + VMMAPI_SHLIB_MAJOR=${LIBVMMAPI_VERSION} + .if 1200000 <= ${OSVERSION} && ${OSVERSION} < 1300000 EXTRA_PATCHES= ${PATCHDIR}/freebsd-12 ${PATCHDIR}/freebsd-12/3 .elif 1301000 <= ${OSVERSION} && ${OSVERSION} < 1400000 EXTRA_PATCHES= ${PATCHDIR}/freebsd-13/1 .elif 1400000 <= ${OSVERSION} && ${OSVERSION} < 1500000 -EXTRA_PATCHES= ${PATCHDIR}/freebsd-14 +EXTRA_PATCHES= ${PATCHDIR}/freebsd-14 +LIBVMMAPI_VERSION= 6.1 .else . if empty(IGNORE) IGNORE+= cannot build: unsupported system . endif .endif WRKSRC= ${WRKDIR} _LINKS= sys/cam/ctl \ sys/contrib/dev/acpica \ sys/dev/e1000 \ sys/dev/mii \ sys/dev/usb/controller \ sys/dev/virtio \ sys/amd64/include \ sys/x86/include \ stand/userboot post-extract: @${MKDIR} ${WRKSRC}/contrib @cd ${WRKSRC} && ${LN} -s ../${GH_PROJECT}-${GH_TAGNAME} contrib/lib9p .for _link in ${_LINKS} @${MKDIR} $$(dirname ${WRKSRC}/${_link}) @cd ${WRKSRC} && ${LN} -s ${SRC_BASE}/${_link} ${_link} .endfor .for _src in ${SRCS} @cd ${_src} && ${COPYTREE_SHARE} . ${WRKDIR}/${_src:S/${SRC_BASE}//1} .endfor @cd ${FILESDIR} && ${COPYTREE_SHARE} kernconf ${WRKSRC} +post-patch: + @cd ${WRKSRC} && \ + ${REINPLACE_CMD} 's/%%9P_SHLIB_MAJOR%%/${LIB9P_VERSION}/g' \ + contrib/lib9p/Makefile \ + usr.sbin/bhyve/Makefile + @cd ${WRKSRC} && \ + ${REINPLACE_CMD} 's/%%VMMAPI_SHLIB_MAJOR%%/${LIBVMMAPI_VERSION}/g' \ + lib/libvmmapi/Makefile \ + usr.sbin/bhyve/Makefile \ + usr.sbin/bhyvectl/Makefile \ + usr.sbin/bhyveload/Makefile + do-build: @cd ${WRKSRC}/contrib/lib9p && \ ${MAKE} SRCTOP=${WRKSRC} SYSDIR=${SRC_BASE}/sys LIB9PDIR= .for _src in ${SRCS} . if exists(${_src}/Makefile) @cd ${WRKSRC}/${_src:S/${SRC_BASE}//1} && \ ${MAKE} SRCTOP=${WRKSRC} SYSDIR=${SRC_BASE}/sys DEBUG_FLAGS=-g \ MK_CTF=yes KERNBUILDDIR=${WRKSRC}/kernconf . endif .endfor do-install: - ${INSTALL_LIB} ${WRKSRC}/contrib/lib9p/lib9p.so.1.1 ${STAGEDIR}${PREFIX}/lib - ${INSTALL_LIB} ${WRKSRC}/lib/libvmmapi/libvmmapi.so.5.1 ${STAGEDIR}${PREFIX}/lib + ${INSTALL_LIB} ${WRKSRC}/contrib/lib9p/lib9p.so.${LIB9P_VERSION} ${STAGEDIR}${PREFIX}/lib + ${INSTALL_LIB} ${WRKSRC}/lib/libvmmapi/libvmmapi.so.${LIBVMMAPI_VERSION} ${STAGEDIR}${PREFIX}/lib .for _bin in bhyve bhyveload bhyvectl ${INSTALL_PROGRAM} ${WRKSRC}/usr.sbin/${_bin}/${_bin} ${STAGEDIR}${PREFIX}/sbin ${INSTALL_MAN} ${WRKSRC}/usr.sbin/${_bin}/${_bin}.8.gz ${STAGEDIR}${PREFIX}/man/man8 .endfor ${INSTALL_KLD} ${WRKSRC}/sys/modules/vmm/vmm.ko ${STAGEDIR}${KMODDIR} .include diff --git a/sysutils/bhyve+/files/freebsd-12/patch-libvmmapi b/sysutils/bhyve+/files/freebsd-12/patch-libvmmapi index 16f14a57bf9a..6131d5eaebcf 100644 --- a/sysutils/bhyve+/files/freebsd-12/patch-libvmmapi +++ b/sysutils/bhyve+/files/freebsd-12/patch-libvmmapi @@ -1,33 +1,33 @@ ---- lib/libvmmapi/Makefile.orig 2021-09-04 01:05:23.110816000 UTC +--- lib/libvmmapi/Makefile.orig +++ lib/libvmmapi/Makefile @@ -6,6 +6,7 @@ INCS= vmmapi.h WARNS?= 2 -+SHLIB_MAJOR?= 5.1 ++SHLIB_MAJOR= %%VMMAPI_SHLIB_MAJOR%% LIBADD= util ---- usr.sbin/bhyvectl/Makefile.orig 2021-09-04 02:33:12.704720000 +0200 -+++ usr.sbin/bhyvectl/Makefile 2021-09-04 02:34:28.740202000 +0200 +--- usr.sbin/bhyvectl/Makefile.orig ++++ usr.sbin/bhyvectl/Makefile @@ -8,7 +8,8 @@ MAN= bhyvectl.8 -LIBADD= vmmapi util +LIBADD= util -+LDADD= ../../lib/libvmmapi/libvmmapi.so.5.1 ++LDADD= ../../lib/libvmmapi/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% WARNS?= 3 ---- usr.sbin/bhyveload/Makefile.orig 2021-09-04 02:33:20.942548000 +0200 -+++ usr.sbin/bhyveload/Makefile 2021-09-04 02:35:58.712996000 +0200 +--- usr.sbin/bhyveload/Makefile.orig ++++ usr.sbin/bhyveload/Makefile @@ -5,7 +5,7 @@ MAN= bhyveload.8 PACKAGE= bhyve -LIBADD= vmmapi -+LDADD= ../../lib/libvmmapi/libvmmapi.so.5.1 ++LDADD= ../../lib/libvmmapi/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% WARNS?= 3 diff --git a/sysutils/bhyve+/files/freebsd-12/patch-msi-x-mappings b/sysutils/bhyve+/files/freebsd-12/patch-msi-x-mappings index 4c8f453abbbb..76becc6a97a3 100644 --- a/sysutils/bhyve+/files/freebsd-12/patch-msi-x-mappings +++ b/sysutils/bhyve+/files/freebsd-12/patch-msi-x-mappings @@ -1,132 +1,132 @@ ---- usr.sbin/bhyve/pci_emul.h.orig 2021-08-19 23:00:57 UTC +--- usr.sbin/bhyve/pci_emul.h.orig +++ usr.sbin/bhyve/pci_emul.h @@ -146,6 +146,7 @@ struct pci_devinst { struct msix_table_entry *table; /* allocated at runtime */ void *pba_page; int pba_page_offset; + void *table_page; } pi_msix; void *pi_arg; /* devemu-private data */ ---- usr.sbin/bhyve/pci_passthru.c.orig 2021-08-19 23:00:57 UTC +--- usr.sbin/bhyve/pci_passthru.c.orig +++ usr.sbin/bhyve/pci_passthru.c @@ -324,13 +324,14 @@ msix_table_read(struct passthru_softc *sc, uint64_t of return (data); } + /* Should make this an assert. */ if (offset < pi->pi_msix.table_offset) return (-1); offset -= pi->pi_msix.table_offset; index = offset / MSIX_TABLE_ENTRY_SIZE; if (index >= pi->pi_msix.table_count) - return (-1); + goto readbar; entry = &pi->pi_msix.table[index]; entry_offset = offset % MSIX_TABLE_ENTRY_SIZE; @@ -357,6 +358,33 @@ msix_table_read(struct passthru_softc *sc, uint64_t of } return (data); + +readbar: + if (pi->pi_msix.table_page != NULL && offset < 4096) { + switch(size) { + case 1: + src8 = (uint8_t *)(pi->pi_msix.table_page + offset); + data = *src8; + break; + case 2: + src16 = (uint16_t *)(pi->pi_msix.table_page + offset); + data = *src16; + break; + case 4: + src32 = (uint32_t *)(pi->pi_msix.table_page + offset); + data = *src32; + break; + case 8: + src64 = (uint64_t *)(pi->pi_msix.table_page + offset); + data = *src64; + break; + default: + return (-1); + } + return (data); + } + + return (-1); } static void @@ -403,13 +431,14 @@ msix_table_write(struct vmctx *ctx, int vcpu, struct p return; } + /* Should make this an assert. */ if (offset < pi->pi_msix.table_offset) return; offset -= pi->pi_msix.table_offset; index = offset / MSIX_TABLE_ENTRY_SIZE; if (index >= pi->pi_msix.table_count) - return; + goto writebar; entry = &pi->pi_msix.table[index]; entry_offset = offset % MSIX_TABLE_ENTRY_SIZE; @@ -432,6 +461,31 @@ msix_table_write(struct vmctx *ctx, int vcpu, struct p entry->msg_data, entry->vector_control); } } + +writebar: + if (pi->pi_msix.table_page != NULL && offset < 4096) { + switch(size) { + case 1: + dest8 = (uint8_t *)(pi->pi_msix.table_page + offset); + *dest8 = data; + break; + case 2: + dest16 = (uint16_t *)(pi->pi_msix.table_page + offset); + *dest16 = data; + break; + case 4: + dest32 = (uint32_t *)(pi->pi_msix.table_page + offset); + *dest32 = data; + break; + case 8: + dest64 = (uint64_t *)(pi->pi_msix.table_page + offset); + *dest64 = data; + break; + default: + break; + } + return; + } } static int @@ -466,6 +520,21 @@ init_msix_table(struct vmctx *ctx, struct passthru_sof idx = pi->pi_msix.table_bar; start = pi->pi_bar[idx].addr; remaining = pi->pi_bar[idx].size; + + /* + * Some device (against better documentation of the spec) + * are mapping other usable address space into the same page + * as the end of the MSI-X tables. + * At least Intel AX200 being one of them apparently. + * Map the page and fall back to it for any reads/writes outside + * the MSI-X table in msix_table_{read,write}. + */ + pi->pi_msix.table_page = mmap(NULL, 4096, PROT_READ | PROT_WRITE, + MAP_SHARED, memfd, sc->psc_bar[idx].addr + table_offset); + if (pi->pi_msix.table_page == MAP_FAILED) { + warn("Failed to map table page for MSI-X on %d/%d/%d", b, s, f); + return (-1); + } if (pi->pi_msix.pba_bar == pi->pi_msix.table_bar) { pba_offset = pi->pi_msix.pba_offset; diff --git a/sysutils/bhyve+/files/freebsd-12/patch-virtio-9p b/sysutils/bhyve+/files/freebsd-12/patch-virtio-9p index 1e14bcd58d61..d24cd4db2fb4 100644 --- a/sysutils/bhyve+/files/freebsd-12/patch-virtio-9p +++ b/sysutils/bhyve+/files/freebsd-12/patch-virtio-9p @@ -1,385 +1,385 @@ ---- usr.sbin/bhyve/Makefile.orig 2021-08-19 23:00:57 UTC +--- usr.sbin/bhyve/Makefile.orig +++ usr.sbin/bhyve/Makefile @@ -3,6 +3,7 @@ # .include +CFLAGS+=-I${SRCTOP}/contrib/lib9p CFLAGS+=-I${SRCTOP}/sys .PATH: ${SRCTOP}/sys/cam/ctl @@ -43,6 +44,7 @@ SRCS= \ pci_lpc.c \ pci_nvme.c \ pci_passthru.c \ + pci_virtio_9p.c \ pci_virtio_block.c \ pci_virtio_console.c \ pci_virtio_net.c \ @@ -71,7 +73,8 @@ SRCS= \ .PATH: ${BHYVE_SYSDIR}/sys/amd64/vmm SRCS+= vmm_instruction_emul.c -LIBADD= vmmapi md pthread z util sbuf cam +LIBADD= md pthread z util sbuf cam casper cap_pwd cap_grp -+LDADD= ../../contrib/lib9p/lib9p.so.1.1 ../../lib/libvmmapi/libvmmapi.so.5.1 ++LDADD= ../../contrib/lib9p/lib9p.so.%%9P_SHLIB_MAJOR%% ../../lib/libvmmapi/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% .if ${MK_INET_SUPPORT} != "no" CFLAGS+=-DINET ---- usr.sbin/bhyve/pci_virtio_9p.c.orig 2021-08-19 22:44:10 UTC +--- usr.sbin/bhyve/pci_virtio_9p.c.orig +++ usr.sbin/bhyve/pci_virtio_9p.c @@ -0,0 +1,344 @@ +/*- + * Copyright (c) 2015 iXsystems Inc. + * Copyright (c) 2017-2018 Jakub Klama + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * VirtIO filesystem passthrough using 9p protocol. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "bhyverun.h" +#include "pci_emul.h" +#include "virtio.h" + +#define VT9P_MAX_IOV 128 +#define VT9P_RINGSZ 256 +#define VT9P_MAXTAGSZ 256 +#define VT9P_CONFIGSPACESZ (VT9P_MAXTAGSZ + sizeof(uint16_t)) + +static int pci_vt9p_debug; +#define DPRINTF(params) if (pci_vt9p_debug) printf params +#define WPRINTF(params) printf params + +/* + * Per-device softc + */ +struct pci_vt9p_softc { + struct virtio_softc vsc_vs; + struct vqueue_info vsc_vq; + pthread_mutex_t vsc_mtx; + uint64_t vsc_cfg; + uint64_t vsc_features; + char * vsc_rootpath; + struct pci_vt9p_config * vsc_config; + struct l9p_backend * vsc_fs_backend; + struct l9p_server * vsc_server; + struct l9p_connection * vsc_conn; +}; + +struct pci_vt9p_request { + struct pci_vt9p_softc * vsr_sc; + struct iovec * vsr_iov; + size_t vsr_niov; + size_t vsr_respidx; + size_t vsr_iolen; + uint16_t vsr_idx; +}; + +struct pci_vt9p_config { + uint16_t tag_len; + char tag[0]; +} __attribute__((packed)); + +static int pci_vt9p_send(struct l9p_request *, const struct iovec *, + const size_t, const size_t, void *); +static void pci_vt9p_drop(struct l9p_request *, const struct iovec *, size_t, + void *); +static void pci_vt9p_reset(void *); +static void pci_vt9p_notify(void *, struct vqueue_info *); +static int pci_vt9p_cfgread(void *, int, int, uint32_t *); +static void pci_vt9p_neg_features(void *, uint64_t); + +static struct virtio_consts vt9p_vi_consts = { + "vt9p", /* our name */ + 1, /* we support 1 virtqueue */ + VT9P_CONFIGSPACESZ, /* config reg size */ + pci_vt9p_reset, /* reset */ + pci_vt9p_notify, /* device-wide qnotify */ + pci_vt9p_cfgread, /* read virtio config */ + NULL, /* write virtio config */ + pci_vt9p_neg_features, /* apply negotiated features */ + (1 << 0), /* our capabilities */ +}; + + +static void +pci_vt9p_reset(void *vsc) +{ + struct pci_vt9p_softc *sc; + + sc = vsc; + + DPRINTF(("vt9p: device reset requested !\n")); + vi_reset_dev(&sc->vsc_vs); +} + +static void +pci_vt9p_neg_features(void *vsc, uint64_t negotiated_features) +{ + struct pci_vt9p_softc *sc = vsc; + + sc->vsc_features = negotiated_features; +} + +static int +pci_vt9p_cfgread(void *vsc, int offset, int size, uint32_t *retval) +{ + struct pci_vt9p_softc *sc = vsc; + void *ptr; + + ptr = (uint8_t *)sc->vsc_config + offset; + memcpy(retval, ptr, size); + return (0); +} + +static int +pci_vt9p_get_buffer(struct l9p_request *req, struct iovec *iov, size_t *niov, + void *arg) +{ + struct pci_vt9p_request *preq = req->lr_aux; + size_t n = preq->vsr_niov - preq->vsr_respidx; + + memcpy(iov, preq->vsr_iov + preq->vsr_respidx, + n * sizeof(struct iovec)); + *niov = n; + return (0); +} + +static int +pci_vt9p_send(struct l9p_request *req, const struct iovec *iov, + const size_t niov, const size_t iolen, void *arg) +{ + struct pci_vt9p_request *preq = req->lr_aux; + struct pci_vt9p_softc *sc = preq->vsr_sc; + + preq->vsr_iolen = iolen; + + pthread_mutex_lock(&sc->vsc_mtx); + vq_relchain(&sc->vsc_vq, preq->vsr_idx, preq->vsr_iolen); + vq_endchains(&sc->vsc_vq, 1); + pthread_mutex_unlock(&sc->vsc_mtx); + free(preq); + return (0); +} + +static void +pci_vt9p_drop(struct l9p_request *req, const struct iovec *iov, size_t niov, + void *arg) +{ + struct pci_vt9p_request *preq = req->lr_aux; + struct pci_vt9p_softc *sc = preq->vsr_sc; + + pthread_mutex_lock(&sc->vsc_mtx); + vq_relchain(&sc->vsc_vq, preq->vsr_idx, 0); + vq_endchains(&sc->vsc_vq, 1); + pthread_mutex_unlock(&sc->vsc_mtx); + free(preq); +} + +static void +pci_vt9p_notify(void *vsc, struct vqueue_info *vq) +{ + struct iovec iov[VT9P_MAX_IOV]; + struct pci_vt9p_softc *sc; + struct pci_vt9p_request *preq; + uint16_t idx, n, i; + uint16_t flags[VT9P_MAX_IOV]; + + sc = vsc; + + while (vq_has_descs(vq)) { + n = vq_getchain(vq, &idx, iov, VT9P_MAX_IOV, flags); + preq = calloc(1, sizeof(struct pci_vt9p_request)); + preq->vsr_sc = sc; + preq->vsr_idx = idx; + preq->vsr_iov = iov; + preq->vsr_niov = n; + preq->vsr_respidx = 0; + + /* Count readable descriptors */ + for (i = 0; i < n; i++) { + if (flags[i] & VRING_DESC_F_WRITE) + break; + + preq->vsr_respidx++; + } + + for (int i = 0; i < n; i++) { + DPRINTF(("vt9p: vt9p_notify(): desc%d base=%p, " + "len=%zu, flags=0x%04x\r\n", i, iov[i].iov_base, + iov[i].iov_len, flags[i])); + } + + l9p_connection_recv(sc->vsc_conn, iov, preq->vsr_respidx, preq); + } +} + + +static int +pci_vt9p_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) +{ + struct pci_vt9p_softc *sc; + char *opt; + char *sharename = NULL; + char *rootpath = NULL; + int rootfd; + bool ro = false; + cap_rights_t rootcap; + + if (opts == NULL) { + printf("virtio-9p: share name and path required\n"); + return (1); + } + + while ((opt = strsep(&opts, ",")) != NULL) { + if (strchr(opt, '=') != NULL) { + if (sharename != NULL) { + printf("virtio-9p: more than one share name given\n"); + return (1); + } + + sharename = strsep(&opt, "="); + rootpath = opt; + continue; + } + + if (strcmp(opt, "ro") == 0) { + DPRINTF(("read-only mount requested\r\n")); + ro = true; + continue; + } + + printf("virtio-9p: invalid option '%s'\n", opt); + return (1); + } + + if (strlen(sharename) > VT9P_MAXTAGSZ) { + printf("virtio-9p: share name too long\n"); + return (1); + } + + rootfd = open(rootpath, O_DIRECTORY); + if (rootfd < 0) + return (-1); + + sc = calloc(1, sizeof(struct pci_vt9p_softc)); + sc->vsc_config = calloc(1, sizeof(struct pci_vt9p_config) + + VT9P_MAXTAGSZ); + + pthread_mutex_init(&sc->vsc_mtx, NULL); + + cap_rights_init(&rootcap, + CAP_LOOKUP, CAP_ACL_CHECK, CAP_ACL_DELETE, CAP_ACL_GET, + CAP_ACL_SET, CAP_READ, CAP_WRITE, CAP_SEEK, CAP_FSTAT, + CAP_CREATE, CAP_FCHMODAT, CAP_FCHOWNAT, CAP_FTRUNCATE, + CAP_LINKAT_SOURCE, CAP_LINKAT_TARGET, CAP_MKDIRAT, CAP_MKNODAT, + CAP_PREAD, CAP_PWRITE, CAP_RENAMEAT_SOURCE, CAP_RENAMEAT_TARGET, + CAP_SEEK, CAP_SYMLINKAT, CAP_UNLINKAT, CAP_EXTATTR_DELETE, + CAP_EXTATTR_GET, CAP_EXTATTR_LIST, CAP_EXTATTR_SET, + CAP_FUTIMES, CAP_FSTATFS, CAP_FSYNC, CAP_FPATHCONF); + + if (cap_rights_limit(rootfd, &rootcap) != 0) + return (1); + + sc->vsc_config->tag_len = (uint16_t)strlen(sharename); + memcpy(sc->vsc_config->tag, sharename, sc->vsc_config->tag_len); + + if (l9p_backend_fs_init(&sc->vsc_fs_backend, rootfd, ro) != 0) { + errno = ENXIO; + return (1); + } + + if (l9p_server_init(&sc->vsc_server, sc->vsc_fs_backend) != 0) { + errno = ENXIO; + return (1); + } + + if (l9p_connection_init(sc->vsc_server, &sc->vsc_conn) != 0) { + errno = EIO; + return (1); + } + + sc->vsc_conn->lc_msize = L9P_MAX_IOV * PAGE_SIZE; + sc->vsc_conn->lc_lt.lt_get_response_buffer = pci_vt9p_get_buffer; + sc->vsc_conn->lc_lt.lt_send_response = pci_vt9p_send; + sc->vsc_conn->lc_lt.lt_drop_response = pci_vt9p_drop; + + vi_softc_linkup(&sc->vsc_vs, &vt9p_vi_consts, sc, pi, &sc->vsc_vq); + sc->vsc_vs.vs_mtx = &sc->vsc_mtx; + sc->vsc_vq.vq_qsize = VT9P_RINGSZ; + + /* initialize config space */ + pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_9P); + pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR); + pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_STORAGE); + pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_9P); + pci_set_cfgdata16(pi, PCIR_SUBVEND_0, VIRTIO_VENDOR); + + if (vi_intr_init(&sc->vsc_vs, 1, fbsdrun_virtio_msix())) + return (1); + vi_set_io_bar(&sc->vsc_vs, 0); + + return (0); +} + +struct pci_devemu pci_de_v9p = { + .pe_emu = "virtio-9p", + .pe_init = pci_vt9p_init, + .pe_barwrite = vi_pci_write, + .pe_barread = vi_pci_read +}; +PCI_EMUL_SET(pci_de_v9p); --- usr.sbin/bhyve/virtio.h.orig 2021-08-19 22:41:21 UTC +++ usr.sbin/bhyve/virtio.h @@ -216,6 +216,7 @@ struct vring_used { #define VIRTIO_DEV_CONSOLE 0x1003 #define VIRTIO_DEV_RANDOM 0x1005 #define VIRTIO_DEV_SCSI 0x1008 +#define VIRTIO_DEV_9P 0x1009 /* * PCI config space constants. diff --git a/sysutils/bhyve+/files/freebsd-13/1/patch-custom-libs b/sysutils/bhyve+/files/freebsd-13/1/patch-custom-libs index cee70aee6367..61b6a93ce908 100644 --- a/sysutils/bhyve+/files/freebsd-13/1/patch-custom-libs +++ b/sysutils/bhyve+/files/freebsd-13/1/patch-custom-libs @@ -1,21 +1,21 @@ ---- usr.sbin/bhyve/Makefile.orig 2022-04-26 00:11:28.231312000 +0000 -+++ usr.sbin/bhyve/Makefile 2022-04-26 00:12:31.807022000 +0000 +--- usr.sbin/bhyve/Makefile.orig ++++ usr.sbin/bhyve/Makefile @@ -3,7 +3,7 @@ # .include -CFLAGS+=-I${.CURDIR}/../../contrib/lib9p +CFLAGS+=-I${SRCTOP}/contrib/lib9p CFLAGS+=-I${SRCTOP}/sys .PATH: ${SRCTOP}/sys/cam/ctl @@ -84,7 +84,8 @@ .PATH: ${BHYVE_SYSDIR}/sys/amd64/vmm SRCS+= vmm_instruction_emul.c -LIBADD= vmmapi md nv pthread z util sbuf cam 9p +LIBADD= md nv pthread z util sbuf cam -+LDADD= ../../contrib/lib9p/lib9p.so.1.1 ../../lib/libvmmapi/libvmmapi.so.5.1 ++LDADD= ../../contrib/lib9p/lib9p.so.%%9P_SHLIB_MAJOR%% ../../lib/libvmmapi/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% .if ${MK_CASPER} != "no" LIBADD+= casper diff --git a/sysutils/bhyve+/files/freebsd-13/1/patch-lib9p b/sysutils/bhyve+/files/freebsd-13/1/patch-lib9p index b60692f4f5a5..8a0eefb16f83 100644 --- a/sysutils/bhyve+/files/freebsd-13/1/patch-lib9p +++ b/sysutils/bhyve+/files/freebsd-13/1/patch-lib9p @@ -1,12 +1,12 @@ ---- share/mk/src.libnames.mk.orig 2022-04-26 00:33:13.464870000 +0000 -+++ share/mk/src.libnames.mk 2022-04-26 00:34:36.615330000 +0000 +--- share/mk/src.libnames.mk.orig ++++ share/mk/src.libnames.mk @@ -265,6 +265,9 @@ # 2nd+ order consumers. Auto-generating this would be better. _DP_80211= sbuf bsdxml _DP_9p= sbuf +.if ${MK_CASPER} != "no" +_DP_9p+= casper cap_pwd cap_grp +.endif # XXX: Not bootstrapped so uses host version on non-FreeBSD, so don't use a # FreeBSD-specific dependency list .if ${.MAKE.OS} == "FreeBSD" || !defined(BOOTSTRAPPING) diff --git a/sysutils/bhyve+/files/freebsd-13/1/patch-libvmmapi b/sysutils/bhyve+/files/freebsd-13/1/patch-libvmmapi index 5bb87bd36d46..1ce7f3e3e829 100644 --- a/sysutils/bhyve+/files/freebsd-13/1/patch-libvmmapi +++ b/sysutils/bhyve+/files/freebsd-13/1/patch-libvmmapi @@ -1,34 +1,34 @@ ---- usr.sbin/bhyvectl/Makefile.orig 2022-04-26 00:35:36.192928000 +0000 -+++ usr.sbin/bhyvectl/Makefile 2022-04-26 00:36:35.181368000 +0000 +--- usr.sbin/bhyvectl/Makefile.orig ++++ usr.sbin/bhyvectl/Makefile @@ -10,7 +10,8 @@ MAN= bhyvectl.8 -LIBADD= vmmapi util +LIBADD= util -+LDADD= ../../lib/libvmmapi/libvmmapi.so.5.1 ++LDADD= ../../lib/libvmmapi/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% WARNS?= 3 ---- usr.sbin/bhyveload/Makefile.orig 2022-04-26 00:36:44.251099000 +0000 -+++ usr.sbin/bhyveload/Makefile 2022-04-26 00:37:15.919627000 +0000 +--- usr.sbin/bhyveload/Makefile.orig ++++ usr.sbin/bhyveload/Makefile @@ -5,7 +5,7 @@ MAN= bhyveload.8 PACKAGE= bhyve -LIBADD= vmmapi -+LDADD= ../../lib/libvmmapi/libvmmapi.so.5.1 ++LDADD= ../../lib/libvmmapi/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% WARNS?= 3 ---- lib/libvmmapi/Makefile.orig 2022-04-26 00:37:35.557718000 +0000 -+++ lib/libvmmapi/Makefile 2022-04-26 00:38:23.135897000 +0000 +--- lib/libvmmapi/Makefile.orig ++++ lib/libvmmapi/Makefile @@ -5,6 +5,8 @@ SRCS= vmmapi.c vmmapi_freebsd.c INCS= vmmapi.h -+SHLIB_MAJOR?= 5.1 ++SHLIB_MAJOR= %%VMMAPI_SHLIB_MAJOR%% + LIBADD= util CFLAGS+= -I${.CURDIR} diff --git a/sysutils/bhyve+/files/freebsd-14/patch-bhyvectl b/sysutils/bhyve+/files/freebsd-14/patch-bhyvectl deleted file mode 100644 index ae14ada4fc5f..000000000000 --- a/sysutils/bhyve+/files/freebsd-14/patch-bhyvectl +++ /dev/null @@ -1,12 +0,0 @@ ---- usr.sbin/bhyvectl/Makefile.orig 2021-09-04 02:33:12.704720000 +0200 -+++ usr.sbin/bhyvectl/Makefile 2021-09-04 02:34:28.740202000 +0200 -@@ -10,7 +10,8 @@ - - MAN= bhyvectl.8 - --LIBADD= vmmapi util -+LIBADD= util -+LDADD= ${SRCTOP}/lib/libvmmapi/libvmmapi.so.5.1 - - WARNS?= 3 - diff --git a/sysutils/bhyve+/files/freebsd-14/patch-bhyveload b/sysutils/bhyve+/files/freebsd-14/patch-bhyveload deleted file mode 100644 index 616f68b1fc2c..000000000000 --- a/sysutils/bhyve+/files/freebsd-14/patch-bhyveload +++ /dev/null @@ -1,11 +0,0 @@ ---- usr.sbin/bhyveload/Makefile.orig 2021-09-25 15:07:46.189926000 +0000 -+++ usr.sbin/bhyveload/Makefile 2021-09-25 15:08:40.718294000 +0000 -@@ -5,7 +5,7 @@ - MAN= bhyveload.8 - PACKAGE= bhyve - --LIBADD= vmmapi -+LDADD= ${SRCTOP}/lib/libvmmapi/libvmmapi.so.5.1 - - WARNS?= 3 - diff --git a/sysutils/bhyve+/files/freebsd-14/patch-custom-libs b/sysutils/bhyve+/files/freebsd-14/patch-custom-libs index 8bc50391d41b..721ea1e559e9 100644 --- a/sysutils/bhyve+/files/freebsd-14/patch-custom-libs +++ b/sysutils/bhyve+/files/freebsd-14/patch-custom-libs @@ -1,21 +1,21 @@ ---- usr.sbin/bhyve/Makefile.orig 2021-09-04 02:15:16.364660000 +0200 -+++ usr.sbin/bhyve/Makefile 2021-09-04 02:21:26.014446000 +0200 +--- usr.sbin/bhyve/Makefile.orig ++++ usr.sbin/bhyve/Makefile @@ -3,7 +3,7 @@ # .include -CFLAGS+=-I${.CURDIR}/../../contrib/lib9p +CFLAGS+=-I${SRCTOP}/contrib/lib9p CFLAGS+=-I${SRCTOP}/sys .PATH: ${SRCTOP}/sys/cam/ctl -@@ -83,7 +83,8 @@ +@@ -88,7 +88,8 @@ .PATH: ${BHYVE_SYSDIR}/sys/amd64/vmm SRCS+= vmm_instruction_emul.c -LIBADD= vmmapi md nv pthread z util sbuf cam 9p -+LIBADD= md nv pthread z util sbuf cam -+LDADD= ${SRCTOP}/contrib/lib9p/lib9p.so.1.1 ${SRCTOP}/lib/libvmmapi/libvmmapi.so.5.1 ++LIBADD= md nv pthread z util sbuf cam 9p ++LDADD= ${SRCTOP}/contrib/lib9p/lib9p.so.%%9P_SHLIB_MAJOR%% ${SRCTOP}/lib/libvmmapi/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% - .if ${MK_CASPER} != "no" - LIBADD+= casper + .if ${MK_BHYVE_SNAPSHOT} != "no" + LIBADD+= ucl xo diff --git a/sysutils/bhyve+/files/freebsd-14/patch-libvmmapi b/sysutils/bhyve+/files/freebsd-14/patch-libvmmapi index d54c9340ca0c..66890febaf6f 100644 --- a/sysutils/bhyve+/files/freebsd-14/patch-libvmmapi +++ b/sysutils/bhyve+/files/freebsd-14/patch-libvmmapi @@ -1,9 +1,34 @@ ---- lib/libvmmapi/Makefile.orig 2021-09-04 01:05:23.110816000 UTC +--- lib/libvmmapi/Makefile.orig +++ lib/libvmmapi/Makefile -@@ -6,6 +6,7 @@ +@@ -2,7 +2,7 @@ + + PACKAGE=lib${LIB} + LIB= vmmapi +-SHLIB_MAJOR= 6 ++SHLIB_MAJOR= %%VMMAPI_SHLIB_MAJOR%% + SRCS= vmmapi.c vmmapi_freebsd.c INCS= vmmapi.h -+SHLIB_MAJOR?= 5.1 +--- usr.sbin/bhyvectl/Makefile.orig ++++ usr.sbin/bhyvectl/Makefile +@@ -10,7 +10,8 @@ + + MAN= bhyvectl.8 + +-LIBADD= vmmapi util ++LIBADD= util ++LDADD= ${SRCTOP}/lib/libvmmapi/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% + + WARNS?= 3 + +--- usr.sbin/bhyveload/Makefile.orig ++++ usr.sbin/bhyveload/Makefile +@@ -5,7 +5,7 @@ + MAN= bhyveload.8 + PACKAGE= bhyve + +-LIBADD= vmmapi ++LDADD= ${SRCTOP}/lib/libvmmapi/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% - LIBADD= util + WARNS?= 3 diff --git a/sysutils/bhyve+/files/patch-lib9p b/sysutils/bhyve+/files/patch-lib9p index f48b6a8efa91..8818ca5f926f 100644 --- a/sysutils/bhyve+/files/patch-lib9p +++ b/sysutils/bhyve+/files/patch-lib9p @@ -1,24 +1,24 @@ --- contrib/lib9p/Makefile.orig 2021-01-08 21:21:39.000000000 UTC +++ contrib/lib9p/Makefile @@ -5,7 +5,7 @@ .include LIB= 9p -SHLIB_MAJOR= 1 -+SHLIB_MAJOR= 1.1 ++SHLIB_MAJOR= %%9P_SHLIB_MAJOR%% SRCS= pack.c \ connection.c \ request.c log.c \ @@ -23,11 +23,9 @@ LIBADD= sbuf .if ${MK_CASPER} != "no" -LIBADD+= libcasper libcap_pwd libcap_grp +LIBADD+= casper cap_pwd cap_grp CFLAGS+= -DWITH_CASPER .endif - -SUBDIR= example cscope: .PHONY cd ${.CURDIR}; cscope -buq $$(find . -name '*.[ch]' -print) diff --git a/sysutils/bhyve+/pkg-plist b/sysutils/bhyve+/pkg-plist index 4744907bb592..e7314210a479 100644 --- a/sysutils/bhyve+/pkg-plist +++ b/sysutils/bhyve+/pkg-plist @@ -1,9 +1,9 @@ sbin/bhyve sbin/bhyvectl sbin/bhyveload -lib/lib9p.so.1.1 -lib/libvmmapi.so.5.1 +lib/lib9p.so.%%9P_SHLIB_MAJOR%% +lib/libvmmapi.so.%%VMMAPI_SHLIB_MAJOR%% man/man8/bhyve.8.gz man/man8/bhyvectl.8.gz man/man8/bhyveload.8.gz /%%KMODDIR%%/vmm.ko