Commit graph

288 commits

Author SHA1 Message Date
Ed Maste e6b88237c6 p9fs: use M_WAITOK where appropriate
device_attach routines are allowed to sleep, and this routine already
has other M_WAITOK allocations.

Reported by:	markj
Reviewed by:	markj
Fixes: 1efd69f933 ("p9fs: move NULL check immediately after alloc...")
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45721
2024-06-24 22:02:13 -04:00
Ed Maste 1efd69f933 p9fs: move NULL check immediately after allocation
Reported by:	Shawn Webb (HardenedBSD)
Reviewed by:	dfr
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45719
2024-06-24 15:36:11 -04:00
Doug Rabson e97ad33a89 Add an implementation of the 9P filesystem
This is derived from swills@ fork of the Juniper virtfs with many
changes by me including bug fixes, style improvements, clearer layering
and more consistent logging. The filesystem is renamed to p9fs to better
reflect its function and to prevent possible future confusion with
virtio-fs.

Several updates and fixes from Juniper have been integrated into this
version by Val Packett and these contributions along with the original
Juniper authors are credited below.

To use this with bhyve, add 'virtio_p9fs_load=YES' to loader.conf. The
bhyve virtio-9p device allows access from the guest to files on the host
by mapping a 'sharename' to a host path. It is possible to use p9fs as a
root filesystem by adding this to /boot/loader.conf:

	vfs.root.mountfrom="p9fs:sharename"

for non-root filesystems add something like this to /etc/fstab:

	sharename /mnt p9fs rw 0 0

In both examples, substitute the share name used on the bhyve command
line.

The 9P filesystem protocol relies on stateful file opens which map
protocol-level FIDs to host file descriptors. The FreeBSD vnode
interface doesn't really support this and we use heuristics to guess the
right FID to use for file operations.  This can be confused by privilege
lowering and does not guarantee that the FID created for a given file
open is always used for file operations, even if the calling process is
using the file descriptor from the original open call. Improving this
would involve changes to the vnode interface which is out-of-scope for
this import.

Differential Revision: https://reviews.freebsd.org/D41844
Reviewed by: kib, emaste, dch
MFC after: 3 months
Co-authored-by: Val Packett <val@packett.cool>
Co-authored-by: Ka Ho Ng <kahon@juniper.net>
Co-authored-by: joyu <joyul@juniper.net>
Co-authored-by: Kumara Babu Narayanaswamy <bkumara@juniper.net>
2024-06-19 13:12:04 +01:00
Gordon Bergling 018a361f89 virtio(4): Fix two typos in KASSERT messages
- s/emtpy/empty/

MFC after:	5 days
2024-06-16 18:02:46 +02:00
Mark Johnston de140d60d5 virtio: Use device_set_descf()
No functional change intended.

MFC after:	1 week
2024-06-02 19:38:41 -04:00
Gleb Smirnoff a01c7081fe vtnet: use CURVNET_SET() instead of CURVNET_SET_QUIET()
We don't expect the VNET context to be set for virtqueue neither
for taskqueue handlers.

Suggested by:	zec
Fixes:		3f2b960775
2024-04-18 07:58:00 -07:00
Cristian Marussi e1c4c8dd8d vtscmi: Add a virtio-scmi driver
Add a new virtio backend to support SCMI VirtIO devices (type 32) as
defined by the VirtIO specification since version v1.2.

https://docs.oasis-open.org/virtio/virtio/v1.2/cs01/virtio-v1.2-cs01.pdf

Reviewed by:	andrew, bryanv
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43047
2024-04-11 09:58:56 +00:00
Gleb Smirnoff 3f2b960775 vtnet: set VNET context in RX handler
The context is required for NIC-level pfil(9) filtering.
2024-03-28 14:12:39 -07:00
Warner Losh 0ea4b40848 vtnet: Avoid ifdefs based on __NO_STRICT_ALIGNMENT
Some platforms require an adjustment of the ethernet hearders. Rather
than make this be on __NO_STRICT_ALIGNMENT being defined, define
VTNET_ETHER_ALIGN to be either 0 or ETHER_ALIGN (aka 2). Add a test to
the if statements to only do them when != 0. This eliminates the #ifdef
sprinkled in the code, still communicates the intent and gives the same
compiled results.

Sponsored by:		Netflix
Reviewed by:		bz, bryanv
Differential Revision:	https://reviews.freebsd.org/D43654
2024-02-04 22:43:49 -07:00
Warner Losh d9e0e42627 vtnet: Account for the padding when selecting allocation size
While we account for the padding in the length of the mbuf we use, we do
not account for it when we 'guess' the size of the mbuf to allocate
based in the MTU of the device. This leads to a situation where we might
fail if the mtu is close to a bucket size (say 2018) such that the added
padding would push us over the edge for a full-sized packet. mtu of 2018
is super rare (2016 and 2020 would both work), but fix it none-the-less.
It's a shame we can't just set VTNET_RX_HEADER_PAD to 2 in this case. The 4
seems hard-coded somewhere I've not found documented (I think it's in the
protocol given the comments about VIRTIO_F_ANY_LAYOUT).

Sponsored by:		Netflix
Reviewed by:		bz
Differential Revision:	https://reviews.freebsd.org/D43656
2024-02-04 22:43:39 -07:00
Bryan Venteicher e6b8c1d780 virtio: Add more device IDs from the specification 2024-01-30 23:08:12 -06:00
Warner Losh 3be59adbb5 vtnet: Adjust for ethernet alignment.
If the header that we add to the packet's size is 0 % 4 and we're
strictly aligning, then we need to adjust where we store the header so
the packet that follows will have it's struct ip header properly
aligned.  We do this on allocation (and when we check the length of the
mbufs in the lro_nomrg case). We can't just adjust the clustersz in the
softc, because it's also used to allocate the mbufs and it needs to be
the proper size for that. Since we otherwise use the size of the mbuf
(or sometimes the smaller size of the received packet) to compute how
much we can buffer, this ensures no overflows. The 2 byte adjustment
also does not affect how many packets we can receive in the lro_nomrg
case.

PR:			271288
Sponsored by:		Netflix
Reviewed by:		bryanv
Differential Revision:	https://reviews.freebsd.org/D43224
2024-01-28 22:08:55 -07:00
Gordon Bergling 97a4045aaf virtio(4): Fix a typo in a source code comment
- s/recevied/received/

MFC after:	3 days
2024-01-22 21:59:06 +01:00
Warner Losh 23699ff23c Revert "vtnet: Adjust rx buffer so IP header 32-bit aligned"
This reverts commit 9e6d11ce9a.

This wasn't right to start with...

Requested by: markj
2023-12-28 10:22:23 -07:00
Warner Losh 8ee1cc4a7f Revert "vtnet: Better adjust for ethernet alignment."
This reverts commit e9da71cd35.

This was inadvertantly pushed and turns out ot be not quite right.

Requested by: markj
2023-12-28 10:22:14 -07:00
Warner Losh e9da71cd35 vtnet: Better adjust for ethernet alignment.
Move adjustment of the mbuf from where we allocate it to where we are
about to queue it to the device. Do this only on those platforms that
require it. This allows us to receive an entire jumbo frame on other
platforms. It also doesn't make the adjustment on subsequent frames when
we queue mulitple mbufs for LRO operations.

For the normal use case on armv7, there's no difference because we only
ever allocate one mbuf. However, for the LRO cases it increases what's
available in LRO. It also ensure that we get enough mbufs in those cases
as well (though I have no ability to test this on a LRO scenario with
armv7).

This has the side effect of reverting 527b62e37e68.

Fixes:			527b62e37e68
Sponsored by:		Netflix
2023-12-27 23:25:53 -07:00
Warner Losh 9e6d11ce9a vtnet: Adjust rx buffer so IP header 32-bit aligned
Call madj(m, ETHER_ALIGN) to offset rx buffers when allocating them.
This improves performance everywhere, and allows armv7 to work at all.

PR:			271288 (PR had a different fix than I wound up with)
MFC After:		3 days
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D43136
2023-12-20 21:16:45 -07:00
Warner Losh fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
Alexander Motin 8c4ee0b22c Use xpt_path_sbuf() in few drivers
xpt_path_string() is now a wrapper around xpt_path_sbuf().  Using it
to than concatenate result to another sbuf makes no sense.  Just call
xpt_path_sbuf() directly.

MFC after:	1 month
2023-11-23 11:29:19 -05:00
Andrew Turner 4386935191 vtgpu: Fix the physical memory size
Use the correct endian switching function when switching to a little
endian 64-bit address. Even on a little-endian machine this will
truncate the address to a 32-bit value.

Sponsored by:	Arm Ltd
2023-09-21 11:50:29 +01:00
Mina Galić 180c02405b virtio: remove virtio_alloc_virtqueues' flags arg
Summary:
the flags argument is unused.
Its initial design idea has been superceded by the addition of
virtio_setup_intr and related APIs.

Sponsored by: The FreeBSD Foundation

Reviewers: bryanv

Reviewed By: bryanv

Subscribers: cognet, imp

Differential Revision: https://reviews.freebsd.org/D41850
2023-09-18 22:03:31 +02:00
Mina Galić ccb576a83c virtio: use bool for boolean functions
Summary:
these static functions:
- vq_ring_use_indirect

and these public functions:
- virtio_bus_is_modern
- virtio_with_feature
- virtqueue_empty
- virtqueue_full

exclusively return a boolean value.
Change their return values to bool.

Sponsored by: The FreeBSD Foundation

Reviewers: bryanv

Reviewed By: bryanv

Subscribers: cognet, imp

Differential Revision: https://reviews.freebsd.org/D41848
2023-09-18 22:03:26 +02:00
John-Mark Gurney f1c5a2e3a6 virtio_random: Pipeline fetching the data
Queue an initial fetch of data during attach and after every read
rather than synchronously fetching data and polling for completion.

If data has not been returned from an previous fetch during read,
just return EAGAIN rather than blocking.

Co-authored-by: John Baldwin <jhb@FreeBSD.org>

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D41656
2023-09-05 08:59:43 -07:00
Andrew Turner 02f2706606 Add a virtio-gpu 2D driver
Add a driver to connect vt to the VirtIO GPU device in 2D mode. This
provides a output on the display when a qemu virtio gpu device is
added, e.g. with -device virtio-gpu-pci.

Tested on qemu using UTM, and a Hetzner arm64 VM instance.

Reviewed by:	bryanv (earlier version)
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D40094
2023-08-17 12:26:57 +01:00
Warner Losh 031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Kristof Provost 580cadd6a5 vtnet: allow IFF_ALLMULTI to be set without VIRTIO_NET_F_CTRL_RX
If the host doesn't announce VIRTIO_NET_F_CTRL_RX we cannot disable all
multicast traffic. Previously we'd refuse to set the IFF_ALLMULTI flag,
which is the exact opposite of what is actually happening.

This broke things such as igmpproxy.

See also:	https://redmine.pfsense.org/issues/14301
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D41356
2023-08-11 09:42:29 +02:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Gleb Smirnoff a6b55ee6be net: replace IFF_KNOWSEPOCH with IFF_NEEDSEPOCH
Expect that drivers call into the network stack with the net epoch
entered. This has already been the fact since early 2020. The net
interrupts, that are marked with INTR_TYPE_NET, were entering epoch
since 511d1afb6b. For the taskqueues there is NET_TASK_INIT() and
all drivers that were known back in 2020 we marked with it in
6c3e93cb5a. However in e87c494015 we took conservative approach
and preferred to opt-in rather than opt-out for the epoch.

This change not only reverts e87c494015 but adds a safety belt to
avoid panicing with INVARIANTS if there is a missed driver. With
INVARIANTS we will run in_epoch() check, print a warning and enter
the net epoch.  A driver that prints can be quickly fixed with the
IFF_NEEDSEPOCH flag, but better be augmented to properly enter the
epoch itself.

Note on TCP LRO: it is a backdoor to enter the TCP stack bypassing
some layers of net stack, ignoring either old IFF_KNOWSEPOCH or the
new IFF_NEEDSEPOCH.  But the tcp_lro_flush_all() asserts the presence
of network epoch.  Indeed, all NIC drivers that support LRO already
provide the epoch, either with help of INTR_TYPE_NET or just running
NET_EPOCH_ENTER() in their code.

Reviewed by:		zlei, gallatin, erj
Differential Revision:	https://reviews.freebsd.org/D39510
2023-04-17 09:08:35 -07:00
Gleb Smirnoff a22561501f net: use pfil_mbuf_{in,out} where we always have an mbuf
This finalizes what has been started in 0b70e3e78b.

Reviewed by:		kp, mjg
Differential revision:	https://reviews.freebsd.org/D37976
2023-02-14 10:02:49 -08:00
Justin Hibbits 4ee967921a Mechanically convert if_vtnet(4) to IfAPI
Reviewed By:	bryanv
Sponsored by:	Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D37799
2023-01-24 14:36:28 -05:00
Mitchell Horne 6f5141456e vtblk: secondary fix for dumping
The code paths while dumping do not got through busdma. As such,
safeguard against calling bus_dmamap_sync() with a NULL map. The x86
implementation tolerates this but others do not, resulting in a
NULL dereference panic when dumping to a vtblk device on arm64, riscv,
etc.

Fixes:		782105f7c8 ("vtblk: Use busdma")
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37990
2023-01-23 15:21:36 -04:00
Colin Percival 9af32ef564 vtblk: Bypass iommu on powerpc
Virtio operates with physical addresses, while busdma is designed to
map these to produce bus addresses.  On most supported platforms,
these two are interchangeable; on powerpc platforms, they are not.

When on powerpc, set an IOMMU of NULL, which causes the powerpc busdma
code to bypass the iommu mapping; this leaves us with the physical
buffer addresses which the virtio host expects to see.

Tested by:	alfredo
Fixes:	782105f7c8 ("vtblk: Use busdma")
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D37891
2023-01-10 19:42:04 -08:00
Mark Johnston db494ceb65 virtio: Silence a -Wunused warning
Remove virtio_swap_endian().  htole*() are nops on little-endian
platforms.  No functional change intended.

MFC after:	1 week
Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D37298
2022-11-14 15:07:34 -05:00
Colin Percival 75549de770 vtblk: Fix dumping
Now that vtblk uses busdma, it keeps important information inside its
request structures.  The functions used for kernel dumps synthesize
their own request structures rather than using structures initialized
with the necessary bits for busdma.

Add busdma-bypass paths.  Since dumping writes contiguous blocks of
physical memory, vtblk doesn't need busdma in that case.

Reported by:	glebius
Tested by:	glebius
Differential Revision:	https://reviews.freebsd.org/D37243
2022-11-03 00:52:43 -07:00
Colin Percival 782105f7c8 vtblk: Use busdma
We assume that bus addresses from busdma are the same thing as
"physical" addresses in the Virtio specification; this seems to
be true for the platforms on which Virtio is currently supported.

For block devices which are limited to a single data segment per
I/O, we request PAGE_SIZE alignment from busdma; this is necessary
in order to support unaligned I/Os from userland, which may cross
a boundary between two non-physically-contiguous pages.  On devices
which support more data segments per I/O, we retain the existing
behaviour of limiting I/Os to (max data segs - 1) * PAGE_SIZE.

Reviewed by:	bryanv
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D36667
2022-10-17 23:02:21 -07:00
Colin Percival 3a8aff9d08 vtblk: Include pointer to softc in request
No functional change intended.

Reviewed by:	bryanv, imp
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D36666
2022-10-17 23:02:21 -07:00
Colin Percival cc25cfc9cf vtblk: Requeue inside vtblk_request_execute
Most virtio_blk requests are launched from vtblk_startio; prior to this
commit, if vtblk_request_execute failed (e.g. due to a lack of space on
the virtio queue) vtblk_startio would requeue the request to be
reattempted later.

Add a flag "vbr_requeue_on_error" to requests and perform the requeuing
from inside vtblk_request_execute instead.

No functional change intended.

Reviewed by:	bryanv, imp
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D36665
2022-10-17 23:02:21 -07:00
Colin Percival 86f8f5ccb7 vtblk: Make vtblk_request_execute return void.
The error, if any, now gets stashed in the request structure.  (Step 1
of reworking this driver to use busdma.)

No functional change intended.

Reviewed by:	bryanv, imp
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D36664
2022-10-17 23:02:21 -07:00
Colin Percival 0e1f5ab7db virtio_mmio: Support command-line parameters
The Virtio MMIO bus driver was added in 2014 with support for devices
exposed via FDT; in 2018 support was added to discover Virtio MMIO
devices via ACPI tables, as in QEMU.  The Firecracker VMM eschews both
FDT and ACPI, instead presenting device information via kernel command
line arguments of the form virtio_mmio.device=<parameters>.

These command line parameters get converted into kernel environment
variables; this adds support for parsing those variables and attaching
virtio_mmio children to nexus.

There is a case to be made that it would be cleaner to have a new
"cmdlinebus" attached to nexus and virtio_mmio children attached to
that.  A future commit might do that.

Discussed with:	imp, jrtc27
Sponsored by:	https://patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D36189
2022-10-17 23:02:21 -07:00
Bryan Venteicher 926cedd9a0 virtio_mmio: Improve V1 spec conformance
Implement the virtio_bus_finalize_features method so the FEATURES_OK
status bit is set. Implement the virtio_bus_config_generation method
to ensure larger than 4-byte reads are consistent.

Reviewed by:	cperciva
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36150
2022-08-17 15:15:04 -05:00
Bryan Venteicher dc6f578a8f virtio_mmio: correct offset of VIRTIO_MMIO_CONFIG_GENERATION 2022-08-03 22:54:36 -05:00
Mitchell Horne 489ba22236 kerneldump: remove physical argument from d_dumper
The physical address argument is essentially ignored by every dumper
method. In addition, the dump routines don't actually pass a real
address; every call to dump_append() passes a value of zero for
physical.

Reviewed by:	markj
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D35173
2022-05-13 10:42:48 -03:00
John Baldwin 5c4c96d3ee virtio: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-06 15:46:57 -07:00
Michael Tuexen 53236f905d if_vtnet: improve dumping a kernel
Disable software LRO during kernel dumping, because having it enabled
requires to be in a network epoch, which might or might not be the
case depending on the code path resulting in the panic.

Reviewed by:		markj
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D34787
2022-04-19 00:40:31 +02:00
John Baldwin 127b40e7dc vtnet: offset is only used for INET or INET6. 2022-04-13 16:08:21 -07:00
John Baldwin b25ddb782f virtio: Use __diagused for variables only used in KASSERT(). 2022-04-13 16:08:19 -07:00
Warner Losh 76e9675663 vtpci_legacy_register_msix: eliminate write only variable dev
Sponsored by:		Netflix
2022-04-04 22:30:42 -06:00
Eugene Grosbein adbf7727b3 virtio_random(8): avoid deadlock at shutdown time
FreeBSD 13+ running as virtual guest may load virtio_random(8) driver
by means of devd(8) unless the driver is blacklisted or disabled
via device.hints(5). Currently, the driver may prevent
the system from rebooting or shutting down correctly.

This change deactivates virtio_random at very late stage
during system shutdown sequence to avoid deadlock
that results in kernel hang.

PR:		253175
Tested by:	tom
MFC after:	3 days
2022-03-16 11:41:51 +07:00