Commit Graph

265 Commits

Author SHA1 Message Date
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
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