aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/virtio/block
Commit message (Collapse)AuthorAgeFilesLines
* virtio_blk: Fix initialisation of dump request structureSarah Walker2026-04-091-40/+54
| | | | | | | | | | | Commit c8c37141 ("virtio_blk: Use bus_dma for command/ack buffer allocations") failed to update initialisation of the dedicated dump request structure. This caused a panic on attempting to dump core to a virtio_blk device. Reviewed by: asomers Sponsored by: Arm Ltd Pull Request: https://reviews.freebsd.org/D56156
* virtio_blk: Use bus_dma for command/ack buffer allocationsSarah Walker2026-03-031-39/+182
| | | | | | | | | | | | | While the majority of virtio platforms will be fully coherent, some may require cache maintenance or other specific device memory handling (eg for secure partitioning). Using bus_dma allows for these usecases. The virtio buffers are marked as coherent; this should ensure that sync calls are no-ops in the common cases. Reviewed by: andrew, br Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54960
* virtio_blk: Limit use of indirect descriptorsAndrew Turner2025-06-231-1/+5
| | | | | | | | | | | | | | Pass 0 as the number of indirect descriptors when they are not supported. This fixes an issue on the Arm FVP model where we don't negotiate them, however pass a number of segments greater than VIRTIO_MAX_INDIRECT. This leads to virtqueue_alloc failing and virtio_blk failing to attach. Reviewed by: Harry Moulton <harry.moulton@arm.com> Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D50909
* diskinfo: print attachment field for virtio_blk devicesRobert Wing2025-05-271-0/+2
| | | | | | PR: 286280 Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D50489
* vtblk: Invoke busdma completion callbacks when pollingMark Johnston2024-07-041-27/+39
| | | | | | | | | | | | | | | | | | | | vtblk_poll_request() is used for kernel dumps and for fetching the block device's identifier string during device probing. In the latter case, it was not calling bus_dmamap_sync() after completing the I/O, but this is required in general. Thus: - Factor out per-request code from vtblk_queue_completed(). - Use it in vtblk_poll_request() once virtqueue_poll() finishes. - While here, assert that virtqueue_poll() returns the request that we expect. Reported by: KMSAN Fixes: 782105f7c898 ("vtblk: Use busdma") Reviewed by: cperciva, imp Sponsored by: Klara, Inc. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D45665
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-1/+0
| | | | | | | | | | | | | | | | 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
* virtio: remove virtio_alloc_virtqueues' flags argMina Galić2023-09-181-1/+1
| | | | | | | | | | | | | | | | | 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
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | 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
* vtblk: secondary fix for dumpingMitchell Horne2023-01-231-20/+26
| | | | | | | | | | | | 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: 782105f7c898 ("vtblk: Use busdma") Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37990
* vtblk: Bypass iommu on powerpcColin Percival2023-01-111-3/+11
| | | | | | | | | | | | | | | 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: 782105f7c898 ("vtblk: Use busdma") Sponsored by: https://www.patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D37891
* vtblk: Fix dumpingColin Percival2022-11-031-3/+17
| | | | | | | | | | | | | | 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
* vtblk: Use busdmaColin Percival2022-10-181-17/+144
| | | | | | | | | | | | | | | | | 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
* vtblk: Include pointer to softc in requestColin Percival2022-10-181-6/+13
| | | | | | | | No functional change intended. Reviewed by: bryanv, imp Sponsored by: https://www.patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D36666
* vtblk: Requeue inside vtblk_request_executeColin Percival2022-10-181-3/+5
| | | | | | | | | | | | | | | | 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
* vtblk: Make vtblk_request_execute return void.Colin Percival2022-10-181-11/+21
| | | | | | | | | | | 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
* kerneldump: remove physical argument from d_dumperMitchell Horne2022-05-131-3/+2
| | | | | | | | | | | 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
* virtio: Remove unused devclass arguments to DRIVER_MODULE.John Baldwin2022-05-061-3/+1
|
* virtio: Add KMSAN hooks for network and block devicesMark Johnston2021-08-111-0/+3
| | | | | | This ensures that host-written data is marked as initialized. Sponsored by: The FreeBSD Foundation
* virtio_blk: Fix issuing T_GET_ID before DRIVER_OK statusKa Ho Ng2021-05-051-2/+18
| | | | | | | | | | | 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
* virtio: Reduce boilerplate for device driver module definitionsJessica Clarke2021-01-211-6/+2
| | | | | | | | | | | 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
* virtio: Handle possible failure of virtio_finalize_features()Bryan Venteicher2021-01-191-9/+19
| | | | | | | | Try to standardize how drivers negotiate feature and the function names Reviewed by: grehan (mentor) Differential Revision: https://reviews.freebsd.org/D27930
* virtio_blk: Use DISKFLAG_WRITE_PROTECT for RO disksBryan Venteicher2021-01-191-22/+10
| | | | | Reviewed by: grehan (mentor) Differential Revision: https://reviews.freebsd.org/D27905
* virtio_blk: Add modern (V1) supportBryan Venteicher2021-01-192-65/+125
| | | | | | | | | | | Rework the header file changes from 2cc8a52 to use our canonical upstream, Linux. geom_disk already checks DISKFLAG_CANDELETE for BIO_DELETE so remove an unnecessary check. Reviewed by: grehan (mentor) Differential Revision: https://reviews.freebsd.org/D27902
* Make MAXPHYS tunable. Bump MAXPHYS to 1M.Konstantin Belousov2020-11-281-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace MAXPHYS by runtime variable maxphys. It is initialized from MAXPHYS by default, but can be also adjusted with the tunable kern.maxphys. Make b_pages[] array in struct buf flexible. Size b_pages[] for buffer cache buffers exactly to atop(maxbcachebuf) (currently it is sized to atop(MAXPHYS)), and b_pages[] for pbufs is sized to atop(maxphys) + 1. The +1 for pbufs allow several pbuf consumers, among them vmapbuf(), to use unaligned buffers still sized to maxphys, esp. when such buffers come from userspace (*). Overall, we save significant amount of otherwise wasted memory in b_pages[] for buffer cache buffers, while bumping MAXPHYS to desired high value. Eliminate all direct uses of the MAXPHYS constant in kernel and driver sources, except a place which initialize maxphys. Some random (and arguably weird) uses of MAXPHYS, e.g. in linuxolator, are converted straight. Some drivers, which use MAXPHYS to size embeded structures, get private MAXPHYS-like constant; their convertion is out of scope for this work. Changes to cam/, dev/ahci, dev/ata, dev/mpr, dev/mpt, dev/mvs, dev/siis, where either submitted by, or based on changes by mav. Suggested by: mav (*) Reviewed by: imp, mav, imp, mckusick, scottl (intermediate versions) Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D27225 Notes: svn path=/head/; revision=368124
* virtio: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-1/+0
| | | | Notes: svn path=/head/; revision=365091
* Add VIRTIO_BLK_T_DISCARD support to the virtio-blk driverAllan Jude2020-07-162-31/+118
| | | | | | | | | | | | | | | | | | | If the hypervisor advertises support for the DISCARD command then the guest can perform TRIM commands, freeing space on the backing store. If VIRTIO_BLK_F_DISCARD is enabled, advertise DISKFLAG_CANDELETE Tested with FreeBSD guests on bhyve and KVM Reviewed by: jhb Tested by: freqlabs MFC after: 1 month Relnotes: yes Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D21708 Notes: svn path=/head/; revision=363255
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)Pawel Biernacki2020-02-261-2/+3
| | | | | | | | | | | | | | | | | | | r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are still not MPSAFE (or already are but aren’t properly marked). Use it in preparation for a general review of all nodes. This is non-functional change that adds annotations to SYSCTL_NODE and SYSCTL_PROC nodes using one of the soon-to-be-required flags. Mark all obvious cases as MPSAFE. All entries that haven't been marked as MPSAFE before are by default marked as NEEDGIANT Approved by: kib (mentor, blanket) Commented by: kib, gallatin, melifaro Differential Revision: https://reviews.freebsd.org/D23718 Notes: svn path=/head/; revision=358333
* Ever since the block layer expanded its command syntax beyond justScott Long2020-02-071-0/+6
| | | | | | | | | | | BIO_READ and BIO_WRITE, we've handled this expanded syntax poorly in drivers when the driver doesn't support a particular command. Do a sweep and fix that. Reported by: imp Notes: svn path=/head/; revision=357647
* virtio(4): Add PNP match metadata for virtio devicesConrad Meyer2019-06-041-7/+5
| | | | | | | | | | | | | | Register MODULE_PNP_INFO for virtio devices using the newbus PNP information provided by the previous commit. Matching can be quite simple; existing probe routines only matched on bus (implicit) and device_type. The same matching criteria are retained exactly, but is now also available to devmatch(8). Reviewed by: bryanv, markj; imp (earlier version) Differential Revision: https://reviews.freebsd.org/D20407 Notes: svn path=/head/; revision=348599
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326255
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326022
* Create an API to reset a struct bio (g_reset_bio). This is mandatoryWarner Losh2016-02-171-3/+4
| | | | | | | | | | | | for all struct bio you get back from g_{new,alloc}_bio. Temporary bios that you create on the stack or elsewhere should use this before first use of the bio, and between uses of the bio. At the moment, it is nothing more than a wrapper around bzero, but that may change in the future. The wrapper also removes one place where we encode the size of struct bio in the KBI. Notes: svn path=/head/; revision=295707
* Do not report stripe size if it is equal to sector size.Alexander Motin2015-04-181-1/+2
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=281698
* Size of opt_io_size field is 32 bit.Alexander Motin2015-03-051-1/+1
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=279651
* Reenable VIRTIO_BLK_F_TOPOLOGY feature.Alexander Motin2015-03-051-0/+1
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=279642
* Rework vtblk dump handling of in flight requestsBryan Venteicher2015-01-271-41/+31
| | | | | | | | | | | | | | | | | Previously, the driver resets the device and abandon the requests that are caught in flight when the dump was initiated. This was problematic if the system is resumed after the dump is completed. While that is probably not the typical action, it is simple to rework the driver to very likely have the device usable after the dump without making it more likely for the dump to fail. The in flight requests are simply queued for completion once the dump is finished. Requested by: markj MFC after: 1 month Notes: svn path=/head/; revision=277788
* Cleanup and performance improvement of the virtio_blk driverBryan Venteicher2014-11-301-417/+422
| | | | | | | | | | | | | - Add support for GEOM direct completion. Depending on the benchmark, this tends to give a ~30% improvement w.r.t IOPs and BW. - Remove an invariants check in the strategy routine. This assertion is caught later on by an existing panic. - Rename and resort various related functions to make more sense. MFC after: 1 month Notes: svn path=/head/; revision=275335
* Add Virtio MMIO bus driver.Ruslan Bukin2014-11-181-0/+2
| | | | | | | Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=274655
* Always append new bios to the tail of the queue, instead of sorting themBryan Venteicher2014-06-101-1/+1
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=267313
* Add unmapped IO support to virtio_blk(4)Bryan Venteicher2014-01-131-3/+4
| | | | Notes: svn path=/head/; revision=260582
* Merge virtio changes from projects/virtioBryan Venteicher2013-07-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Contains projects/virtio commits: r245738: virtio: Minor man page tweaks r246060: virtio: Cleanup feature description printing r246306: virtio: Remove old debugging flag r247238: virtio: Remove PRIx64 macros from format strings r247239: virtio: Constify some fields r247240: virtio: Minor code simplifications r249962: virtio: Update to my freebsd.org email address MFC after: 1 month Notes: svn path=/head/; revision=252707
* Merge several virtio_blk changes from projects/virtioBryan Venteicher2013-07-042-26/+240
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The notable changes of this commit are support for disk resizing and chases updates to the spec regarding write caching. Contains projects/virtio commits: r245713: virtio_blk: Replace __FUNCTION__ with __func__ r245714: virtio_blk: Use more consistent mutex name r245715: virtio_blk: Print device name too if failed to reinit during dump r245716: virtio_blk: Remove an unuseful ASSERT r245723: virtio_blk: Record the vendor and device information r245724: virtio_blk: Add resize support r245726: virtio_blk: More verbose ASSERT messages r245730: virtio_blk: Tweak resize announcement message r246061: virtio_blk: Do not always read entire config r246062: virtio_blk: Use topology to set the stripe size/offset r246307: virtio_blk: Correct stripe offset calculation r246063: virtio_blk: Add support for write cache enable feature r246303: virtio_blk: Expand a comment r252529: virtio_blk: Improve write cache handling r252681: virtio_blk: Remove unneeded curly braces MFC after: 1 month Notes: svn path=/head/; revision=252703
* Convert VirtIO to use ithreads instead of taskqueuesBryan Venteicher2013-07-041-42/+5
| | | | | | | | | | | | | | | | | | | | | | | | | Contains projects/virtio commits: r245709: Each VirtIO device was scheduling its own taskqueue(9) to do the off-level interrupt handling. ithreads(9) is the more nature way to do this. The primary motivation for this work to better support network multiqueue. r245710: virtio: Change virtqueue intr handlers to return void r245711: virtio_blk: Remove interrupt taskqueue r245721: vtnet: Remove interrupt taskqueue r245722: virtio_scsi: Remove interrupt taskqueue r245747: vtnet: Remove taskqueue fields missed in r245721 MFC after: 1 month Notes: svn path=/head/; revision=252702
* Only set the barrier flag if the feature was negotiatedBryan Venteicher2013-03-051-8/+41
| | | | | | | | | | | | | | | | When the VirtIO barrier feature is not negotiated, the driver must enforce the proper ordering for BIO_ORDERED BIOs. All the in-flight BIOs must complete before starting the BIO, and the ordered BIO must complete before subsequent BIOs can start. Also fix a few whitespace nits. Reported by: neel Approved by: grehan (mentor) MFC after: 3 days Notes: svn path=/head/; revision=247829
* virtio: Start taskqueues threads after attach cannot failBryan Venteicher2012-12-141-2/+3
| | | | | | | | | | | | | If virtio_setup_intr() failed during boot, we would hang in taskqueue_free() -> taskqueue_terminate() for all the taskq threads to terminate. This will never happen since the scheduler is not running by this point. Reported by: neel, grehan Approved by: grehan (mentor) Notes: svn path=/head/; revision=244200
* Various VirtIO improvementsPeter Grehan2012-07-111-42/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | PCI: - Properly handle interrupt fallback from MSIX to MSI to legacy. The host may not have sufficient resources to support MSIX, so we must be able to fallback to legacy interrupts. - Add interface to get the (sub) vendor and device IDs. - Rename flags to VTPCI_FLAG_* like other VirtIO drivers. Block: - No longer allocate vtblk_requests from separate UMA zone. malloc(9) from M_DEVBUF is sufficient. Assert segment counts at allocation. - More verbose error and debug messages. Network: - Remove stray write once variable. Virtqueue: - Shuffle code around in preparation of converting the mb()s to the appropriate atomic(9) operations. - Only walk the descriptor chain when freeing if INVARIANTS is defined since the result is only KASSERT()ed. Submitted by: Bryan Venteicher (bryanv@daemoninthecloset.org) Notes: svn path=/head/; revision=238360
* Do not include <sys/types.h> in the local headers. The .c files includingDavid E. O'Brien2012-07-031-2/+0
| | | | | | | them have already included <sys/param.h> before these headers are included. Notes: svn path=/head/; revision=238072
* Sync with Bryan Venteicher's virtio git repo:Peter Grehan2012-04-161-1/+3
| | | | | | | | | | d04e609bdd1973cc7d2e8b38b7dcfae057b0962d virtio_blk: Use correct temporary variable in vtblk_poll_request Obtained from: Bryan Venteicher bryanv at daemoninthecloset dot org Notes: svn path=/head/; revision=234349