Commit Graph

239 Commits

Author SHA1 Message Date
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
Aleksandr Fedorov
fc035df8af if_vtnet(4): Restore the ability to set promisc mode.
PR:	254343, 255054
Reviewed by:	vmaffione (mentor), donner
Approved by:	vmaffione (mentor), donner
MFC after:	2 weeks
Sponsored by:	vstack.com
Differential Revision:	https://reviews.freebsd.org/D30639
2022-02-05 18:47:46 +03:00
Mark Johnston
526ddf174e vtnet: Mark MRG_RXBUF headers as initialized before loading fields
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-01-20 08:25:14 -05:00
Gleb Smirnoff
3f6ab5493f vtnet: don't leak pfil(9) data on detach
PR:		260667
Submitted by:	<ghuckriede blackberry.com>
2022-01-04 18:41:05 -08:00
Mateusz Guzik
88646c4e5f virtio: plug some of set-but-not-used vars
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-12-14 14:38:42 +00:00
Mateusz Guzik
4d78ef3e81 virtio console: plug set-but-not-used vars
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-12-14 14:14:34 +00:00
Mateusz Guzik
0d3b2bd7e6 vtnet: plug set-but-not-used vars
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-12-14 14:08:28 +00:00
Mark Johnston
a4667e09e6 Convert vm_page_alloc() callers to use vm_page_alloc_noobj().
Remove page zeroing code from consumers and stop specifying
VM_ALLOC_NOOBJ.  In a few places, also convert an allocation loop to
simply use VM_ALLOC_WAITOK.

Similarly, convert vm_page_alloc_domain() callers.

Note that callers are now responsible for assigning the pindex.

Reviewed by:	alc, hselasky, kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31986
2021-10-19 21:22:56 -04:00
Alex Richardson
9017870541 Add missing const after 6c4f95161d
I accidentally didn't include hunk in the committed patch.

Fixes:		6c4f95161d ("virtio: make the write_config buffer argument const")
2021-10-11 13:20:56 +01:00
Alex Richardson
6c4f95161d virtio: make the write_config buffer argument const
No functional change intended, but noticed that we could add const here
while adding linuxkpi support for virtio.

Reviewed By:	bryanv, imp
Differential Revision: https://reviews.freebsd.org/D32370
2021-10-11 11:52:18 +01:00
Stephen J. Kiernan
fd80208a5f Add SDT probes virtqueue::enqueue_segments:{entry,return}
This allows one to be able to map the sglist entries passed into the
vq_ring_enqueue_segments() function to the segment indexes used in
the virtqueue.

This function normally gets inlined and may not available via FBT
probes.

Differential Revision: https://reviews.freebsd.org/D31620
2021-08-27 13:08:59 -04:00
Mark Johnston
710c055673 virtio: Add KMSAN hooks for network and block devices
This ensures that host-written data is marked as initialized.

Sponsored by:	The FreeBSD Foundation
2021-08-11 16:41:38 -04:00
Andrew Turner
89c085b899 Only use byte register access in legacy virtio pci
Some simulators don't implement arbitrary sized memory access to the
virtio PCI registers. Follow Linux and use single byte accesses to read
and write to these registers.

Reviewed by:	bryanv, emaste (previous version)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31424
2021-08-11 10:18:54 +00:00
Luiz Otavio O Souza
5afe81a7b2 virtio: enable VTNET_LEGACY_TX when ALTQ is enabled.
ALTQ only works on network drivers which use if_start (rather than
if_transmit). vtnet uses if_start if built with VTNET_LEGACY_TX. Default
to that the kernel is built with ALTQ enabled, to reduce user surprise.

MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-07-29 07:54:39 +02:00
Warner Losh
ddfc9c4c59 newbus: Move from bus_child_{pnpinfo,location}_src to bus_child_{pnpinfo,location} with sbuf
Now that the upper layers all go through a layer to tie into these
information functions that translates an sbuf into char * and len. The
current interface suffers issues of what to do in cases of truncation,
etc. Instead, migrate all these functions to using struct sbuf and these
issues go away. The caller is also in charge of any memory allocation
and/or expansion that's needed during this process.

Create a bus_generic_child_{pnpinfo,location} and make it default. It
just returns success. This is for those busses that have no information
for these items. Migrate the now-empty routines to using this as
appropriate.

Document these new interfaces with man pages, and oversight from before.

Reviewed by:		jhb, bcr
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D29937
2021-06-22 20:52:06 -06:00
Mark Johnston
5b81e2e1bc virtio_scsi: Zero stack-allocated CCBs
Fixes:	3394d4239b ("cam: allocate CCBs from UMA for SCSI and ATA IO")
Reported by:	syzbot+2e9ce63919709feb3d1c@syzkaller.appspotmail.com
Reviewed by:	trasz
Sponsored by:	The FreeBSD Foundation
2021-05-16 22:20:39 -04:00
Alfredo Dal'Ava Junior
fb53b42e36 virtio-modern: fix PCI common read/write functions on big endian targets
Virtio modern has the common data organized in little endian, but
on powerpc64 BE it was reading and writing in the wrong endian.

Submitted by:	Leonardo Bianconi <leonardo.bianconi@eldorado.org.br>
Reviewed by:	bryanv, alfredo
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D28947
2021-05-07 02:40:35 -03:00
Ka Ho Ng
4e1e1d667f virtio_blk: Fix issuing T_GET_ID before DRIVER_OK status
DRIVER_OK status is set after device_attach() succeeds. For now postpone
disk_create to attach_completed() method.

MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Reviewed by:	grehan
Approved by:	lwhsu (mentor)
Differential Revision:	https://reviews.freebsd.org/D30049
2021-05-05 23:22:16 +08:00
Alexander V. Chernikov
4044af03a4 Fix vtnet TCP lro panic
Differential Revision: https://reviews.freebsd.org/D29900
Reviewed by:	hps, kp
2021-04-19 17:06:34 +01:00
Ka Ho Ng
cf5d111240 virtio_pci_legacy: Allow memory space for configuration
For guests running under some kind of VMMs, configuration structure is
available in memory space but not I/O space.

Reported by:	Yuan Rui <number201724@me.com>
MFC after:	2 weeks
Reviewed by:	rpokala, bryanv, jhb
Approved by:	philip (mentor)
Differential Revision:	https://reviews.freebsd.org/D28818
2021-03-20 15:45:34 +08:00
Ka Ho Ng
faf9a4e914 virtio_pci_legacy: Use the table BAR and PBA BAR from MSI-X cap
The MSI-X resource shouldn't be assumed to be always on BAR1.
The Virtio v1.1 Spec did not specify that MSI-X table and PBA BAR has to
be BAR1 either.

Reported by:	Yuan Rui <number201724@me.com>
MFC after:	2 weeks
Reviewed by:	bryanv, jhb
Approved by:	philip (mentor)
Differential Revision:	https://reviews.freebsd.org/D28817
2021-03-20 15:45:34 +08:00
Michael Tuexen
d4697a6b56 vtnet: fix TSO for TCP/IPv6
The decision whether a TCP packet is sent over IPv4 or IPv6 was
based on ethertype, which works correctly. In D27926 the criteria
was changed to checking if the CSUM_IP_TSO flag is set in the
csum-flags and then considering it to be TCP/IPv4.
However, the TCP stack sets the flag to CSUM_TSO for IPv4 and IPv6,
where CSUM_TSO is defined as CSUM_IP_TSO|CSUM_IP6_TSO.
Therefore TCP/IPv6 packets gets mis-classified as TCP/IPv4,
which breaks TSO for TCP/IPv6.
This patch bases the check again on the ethertype.
This fix will be MFC instantly as discussed with re(gjb).

MFC after:		instantly
PR:			254366
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D29331
2021-03-18 21:32:20 +01:00
Ka Ho Ng
54ac6f721e bhyve: virtio shares definitions between sys/dev/virtio
Definitions inside usr.sbin/bhyve/virtio.h are thrown away.
Definitions in sys/dev/virtio are used instead.

This reduces code duplication.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	grehan
Approved by:	philip (mentor)
Differential Revision:	https://reviews.freebsd.org/D29084
2021-03-16 19:29:39 +08:00
Alex Richardson
c1b554c868 if_vtnet: Fix pointer-sign and used parameter warnings
Reviewed By:	grehan
Differential Revision: https://reviews.freebsd.org/D28726
2021-02-22 17:41:04 +00:00
Jessica Clarke
85ad7f8da1 virtio_mmio: Delete a stale #if 0'ed debug print
This was blindly moved in r360722 but the variable being printed is not
yet initialised. It's of little use and can easily be added back in the
right place if needed by someone debugging, so just delete it.

Reported by:	bryanv
2021-01-21 02:14:41 +00:00
Jessica Clarke
633218ee46 virtio: Reduce boilerplate for device driver module definitions
Rather than have every device register itself for both virtio_pci and
virtio_mmio, provide a VIRTIO_DRIVER_MODULE wrapper to declare both,
merge VIRTIO_SIMPLE_PNPTABLE with VIRTIO_SIMPLE_PNPINFO and make the
latter register for both buses. This also has the benefit of abstracting
away the available transports and their names.

Reviewed by:	bryanv
Differential Revision:	https://reviews.freebsd.org/D28073
2021-01-21 01:07:23 +00:00
Jessica Clarke
be79a2c60f virtio_mmio: Fix V1 device probing spec conformance (section 4.2.3.1.1)
We must check MagicValue not just Version before anything else, and then
we must check DeviceID and immediately abort if zero (and this must not
be an error).

Do all this when probing rather than at the start of attaching as that's
where this belongs, and provides a clear boundary between the device
detection and device initialisation parts of the specified driver
initialisation process. This also means we don't create empty device
instances for placeholder devices, reducing clutter on systems that
pre-allocate a large number, such as QEMU's AArch64 virt machine (which
provides 32).

Reviewed by:	bryanv
Differential Revision:	https://reviews.freebsd.org/D28070
2021-01-21 01:05:21 +00:00
Jessica Clarke
0e72f2c541 virtio_mmio: Fix a style(9) issue 2021-01-21 01:05:20 +00:00
Bryan Venteicher
e6cc42f181 virtio: Handle possible failure of virtio_finalize_features()
Try to standardize how drivers negotiate feature and the
function names

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27930
2021-01-19 04:55:26 +00:00
Bryan Venteicher
2bfab35774 if_vtnet: Add counter for received host LRO
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27928
2021-01-19 04:55:26 +00:00
Bryan Venteicher
475a60aec7 if_vtnet: Misc Tx path cleanup
- Add and fix a few error path counters
  - Improve sysctl descriptions
  - Use flags consistently to determine IPv4 vs IPv6

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27926
2021-01-19 04:55:26 +00:00
Bryan Venteicher
6b53aeed91 if_vtnet: Set lro_nsegs for host LRO packets
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27933
2021-01-19 04:55:25 +00:00
Bryan Venteicher
74cd316a09 if_vtnet: Resort softc fields
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27925
2021-01-19 04:55:25 +00:00
Bryan Venteicher
33b5433fd7 if_vtnet: Remove unnecessary TUNABLE_INTs because of CTLFLAG_RDTUN
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27923
2021-01-19 04:55:25 +00:00
Bryan Venteicher
4f18e23f84 if_vtnet: Schedule Rx task if pending items when enabling interrupt
Prior to V1, the driver would enable interrupts and then notify the
host that DRIVER_OK. Since for V1, DRIVER_OK needs to be set before
notifying the virtqueues, there may be items in the queues waiting
to be processed by the time interrupts are enabled.

This fixes a bug where the Rx queue would appear stuck, only being
usable after an interface down/up cycle.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27922
2021-01-19 04:55:25 +00:00
Bryan Venteicher
c3187190c7 if_vtnet: Disable F_MTU feature if MTU is invalid
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27931
2021-01-19 04:55:25 +00:00
Bryan Venteicher
bd8809df20 if_vtnet: Limit allocations of unused virtqueues
For multiqueue, we may use fewer than the provided maximum number of
queues. Try to limit allocations of the unused queues: no interrupts,
no indirect descriptors, and no taskqueues.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27921
2021-01-19 04:55:25 +00:00
Bryan Venteicher
b470419ea5 if_vtnet: Rework 4be723f63 max multiqueue pairs check
Verify the max_virtqueue_pairs is within the range allowed by
the spec.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27920
2021-01-19 04:55:25 +00:00
Bryan Venteicher
42343a6316 if_vtnet: Add support for software LRO
This useful when running on hosts that support checksum offloading
but not the GUEST_TSO (LRO) feature. Or potentially, some GRO-like
support when doing forwarding.

Only enable SW LRO when the host LRO is not available since both
tends to be harmful, and difficult to enable/disable selectively
with only a single IFCAP_LRO flag.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27919
2021-01-19 04:55:25 +00:00
Bryan Venteicher
177761e4c4 if_vtnet: Set the interface max TSO values
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27917
2021-01-19 04:55:25 +00:00
Bryan Venteicher
e36a6b1b1f if_vtnet: Add support for CTRL_GUEST_OFFLOADS feature
This allows the Rx checksum and LRO to be modified without a full
reinit of the device.

Remove IFCAP_RXCSUM_IPV6 from the interface capabilities since in
VirtIO Rx checksums are just enabled or disabled for all protocols.

Properly update IFCAP_LRO if LRO is becomes disabled when Rx
checksums are disabled.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27916
2021-01-19 04:55:25 +00:00
Bryan Venteicher
dc9029d863 if_vtnet: Move ioctl handlers into separate functions
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27914 https://reviews.freebsd.org/D27915
2021-01-19 04:55:25 +00:00
Bryan Venteicher
44559b26af if_vtnet: Cleanup the reinit process
In modern VirtIO, the virtqueues cannot be notified before setting
DRIVER_OK status.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27932
2021-01-19 04:55:25 +00:00
Bryan Venteicher
32e0493c92 if_vtnet: Cleanup the interface setup methods
Defer the ether_ifattach until the interface capabilities
are configured

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27913
2021-01-19 04:55:25 +00:00
Bryan Venteicher
2520cd3821 if_vtnet: Only set IFCAP_JUMBO_MTU when jumbo MTU is supported
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27912
2021-01-19 04:55:24 +00:00
Bryan Venteicher
baa5234fbe if_vtnet: Move the Tx interrupt threshold into the Txq structure
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27911
2021-01-19 04:55:24 +00:00
Bryan Venteicher
05041794d0 if_vtnet: Defer updating generated MAC address until attached
This improves spec compliance because the driver is not suppose
to notify the device prior to setting the DRIVER_OK status, which
could happen with the VIRTIO_NET_F_CTRL_MAC_ADDR.

The VIRTIO_NET_F_MAC feature should always be negotiated so would
be a rare situation.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27910
2021-01-19 04:55:24 +00:00
Bryan Venteicher
25dbc30ef5 if_vtnet: Remove at attach PROMISC handling
This may have been required in an early, early, early version of the
specification but I cannot find any reference to it, and a promiscuous
default seems very odd so remove this code.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27909
2021-01-19 04:55:24 +00:00
Bryan Venteicher
6a73339365 if_vtnet: Support VIRTIO_NET_F_SPEED_DUPLEX
This features lets the guest driver know the speed and duplex of
the "link". Instead of trying to support many media types based
on the possible/likely speeds/duplexes, only use the speed to
set the interface baudrate.

Cleanup ifmedia code to match other drivers.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27908
2021-01-19 04:55:24 +00:00
Bryan Venteicher
aabdf5b6e8 if_vtnet: Support VIRTIO_NET_F_MTU
This feature lets the guest driver know the maximum MTU size
supported by the host device. If set, use this to limit the
acceptable MTUs, and improve how the receive mbuf cluster size
then is selected.

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27907
2021-01-19 04:55:24 +00:00