Dsphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget,/translations/zh_CN/driver-api/virtio/virtiomodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/zh_TW/driver-api/virtio/virtiomodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/it_IT/driver-api/virtio/virtiomodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/ja_JP/driver-api/virtio/virtiomodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/ko_KR/driver-api/virtio/virtiomodnameN classnameN refexplicituh1hhh ubh)}(hhh]hPortuguese (Brazilian)}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/pt_BR/driver-api/virtio/virtiomodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/sp_SP/driver-api/virtio/virtiomodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhF/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio.rsthKubhtarget)}(h .. _virtio:h]h}(h]h ]h"]h$]h&]refidvirtiouh1hhKhhhhhhubhsection)}(hhh](htitle)}(hVirtio on Linuxh]hVirtio on Linux}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Introductionh]h Introduction}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhK ubh paragraph)}(hX_Virtio is an open standard that defines a protocol for communication between drivers and devices of different types, see Chapter 5 ("Device Types") of the virtio spec (`[1]`_). Originally developed as a standard for paravirtualized devices implemented by a hypervisor, it can be used to interface any compliant device (real or emulated) with a driver.h](hVirtio is an open standard that defines a protocol for communication between drivers and devices of different types, see Chapter 5 (“Device Types”) of the virtio spec (}(hhhhhNhNubh reference)}(h`[1]`_h]h[1]}(hjhhhNhNubah}(h]h ]h"]h$]h&]name[1]hԌid2uh1jhhresolvedKubh). Originally developed as a standard for paravirtualized devices implemented by a hypervisor, it can be used to interface any compliant device (real or emulated) with a driver.}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hFor illustrative purposes, this document will focus on the common case of a Linux kernel running in a virtual machine and using paravirtualized devices provided by the hypervisor, which exposes them as virtio devices via standard mechanisms such as PCI.h]hFor illustrative purposes, this document will focus on the common case of a Linux kernel running in a virtual machine and using paravirtualized devices provided by the hypervisor, which exposes them as virtio devices via standard mechanisms such as PCI.}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubeh}(h] introductionah ]h"] introductionah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(h)Device - Driver communication: virtqueuesh]h)Device - Driver communication: virtqueues}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj:hhhhhKubh)}(hXiAlthough the virtio devices are really an abstraction layer in the hypervisor, they're exposed to the guest as if they are physical devices using a specific transport method -- PCI, MMIO or CCW -- that is orthogonal to the device itself. The virtio spec defines these transport methods in detail, including device discovery, capabilities and interrupt handling.h]hXkAlthough the virtio devices are really an abstraction layer in the hypervisor, they’re exposed to the guest as if they are physical devices using a specific transport method -- PCI, MMIO or CCW -- that is orthogonal to the device itself. The virtio spec defines these transport methods in detail, including device discovery, capabilities and interrupt handling.}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj:hhubh)}(hXCThe communication between the driver in the guest OS and the device in the hypervisor is done through shared memory (that's what makes virtio devices so efficient) using specialized data structures called virtqueues, which are actually ring buffers [#f1]_ of buffer descriptors similar to the ones used in a network device:h](hThe communication between the driver in the guest OS and the device in the hypervisor is done through shared memory (that’s what makes virtio devices so efficient) using specialized data structures called virtqueues, which are actually ring buffers }(hjYhhhNhNubhfootnote_reference)}(h[#f1]_h]h1}(hjchhhNhNubah}(h]id1ah ]h"]h$]h&]autoKhԌf1docnamedriver-api/virtio/virtiouh1jahjYjKubhD of buffer descriptors similar to the ones used in a network device:}(hjYhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK"hj:hhubhindex)}(hhh]h}(h]h ]h"]h$]h&]entries](singlevring_desc (C struct) c.vring_deschNtauh1jhj:hhhNhNubhdesc)}(hhh](hdesc_signature)}(h vring_desch]hdesc_signature_line)}(hstruct vring_desch](hdesc_sig_keyword)}(hstructh]hstruct}(hjhhhNhNubah}(h]h ]kah"]h$]h&]uh1jhjhhhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhKubhdesc_sig_space)}(h h]h }(hjhhhNhNubah}(h]h ]wah"]h$]h&]uh1jhjhhhjhKubh desc_name)}(h vring_desch]h desc_sig_name)}(hjh]h vring_desc}(hjhhhNhNubah}(h]h ]nah"]h$]h&]uh1jhjubah}(h]h ](sig-namedescnameeh"]h$]h&]hhuh1jhjhhhjhKubeh}(h]h ]h"]h$]h&]hhƌ add_permalinkuh1jsphinx_line_type declaratorhjhhhjhKubah}(h]jah ](sig sig-objecteh"]h$]h&] is_multiline _toc_parts) _toc_namehuh1jhjhKhjhhubh desc_content)}(hhh]h)}(hNVirtio ring descriptors, 16 bytes long. These can chain together via **next**.h](hEVirtio ring descriptors, 16 bytes long. These can chain together via }(hjhhhNhNubhstrong)}(h**next**h]hnext}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhK^hjhhubah}(h]h ]h"]h$]h&]uh1jhjhhhjhKubeh}(h]h ](cstructeh"]h$]h&]domainj(objtypej)desctypej)noindex noindexentrynocontentsentryuh1jhhhj:hNhNubh container)}(hX**Definition**:: struct vring_desc { __virtio64 addr; __virtio32 len; __virtio16 flags; __virtio16 next; }; **Members** ``addr`` buffer address (guest-physical) ``len`` buffer length ``flags`` descriptor flags ``next`` index of the next descriptor in the chain, if the VRING_DESC_F_NEXT flag is set. We chain unused descriptors via this, too.h](h)}(h**Definition**::h](j)}(h**Definition**h]h Definition}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj9ubh:}(hj9hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhKbhj5ubh literal_block)}(hjstruct vring_desc { __virtio64 addr; __virtio32 len; __virtio16 flags; __virtio16 next; };h]hjstruct vring_desc { __virtio64 addr; __virtio32 len; __virtio16 flags; __virtio16 next; };}hjXsbah}(h]h ]h"]h$]h&]hhuh1jVhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhKdhj5ubh)}(h **Members**h]j)}(hjih]hMembers}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjgubah}(h]h ]h"]h$]h&]uh1hhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhKkhj5ubhdefinition_list)}(hhh](hdefinition_list_item)}(h)``addr`` buffer address (guest-physical) h](hterm)}(h``addr``h]hliteral)}(hjh]haddr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhKbhjubh definition)}(hhh]h)}(hbuffer address (guest-physical)h]hbuffer address (guest-physical)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhKbhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhKbhjubj)}(h``len`` buffer length h](j)}(h``len``h]j)}(hjh]hlen}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhKchjubj)}(hhh]h)}(h buffer lengthh]h buffer length}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhKchjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhKchjubj)}(h``flags`` descriptor flags h](j)}(h ``flags``h]j)}(hjh]hflags}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhKdhjubj)}(hhh]h)}(hdescriptor flagsh]hdescriptor flags}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhKdhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhKdhjubj)}(h``next`` index of the next descriptor in the chain, if the VRING_DESC_F_NEXT flag is set. We chain unused descriptors via this, too.h](j)}(h``next``h]j)}(hj=h]hnext}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj;ubah}(h]h ]h"]h$]h&]uh1jhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhKfhj7ubj)}(hhh]h)}(h{index of the next descriptor in the chain, if the VRING_DESC_F_NEXT flag is set. We chain unused descriptors via this, too.h]h{index of the next descriptor in the chain, if the VRING_DESC_F_NEXT flag is set. We chain unused descriptors via this, too.}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1hhi/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:40: ./include/uapi/linux/virtio_ring.hhKehjSubah}(h]h ]h"]h$]h&]uh1jhj7ubeh}(h]h ]h"]h$]h&]uh1jhjRhKfhjubeh}(h]h ]h"]h$]h&]uh1jhj5ubeh}(h]h ] kernelindentah"]h$]h&]uh1j3hj:hhhNhNubh)}(hAll the buffers the descriptors point to are allocated by the guest and used by the host either for reading or for writing but not for both.h]hAll the buffers the descriptors point to are allocated by the guest and used by the host either for reading or for writing but not for both.}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK+hj:hhubh)}(hX Refer to Chapter 2.5 ("Virtqueues") of the virtio spec (`[1]`_) for the reference definitions of virtqueues and "Virtqueues and virtio ring: How the data travels" blog post (`[2]`_) for an illustrated overview of how the host device and the guest driver communicate.h](hubah}(h]h ]h"]h$]h&]uh1jh_/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:56: ./include/linux/virtio.hhKhj:ubj)}(hhh]h)}(h7the maximum number of elements supported by the device.h]h7the maximum number of elements supported by the device.}(hjYhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjUhKhjVubah}(h]h ]h"]h$]h&]uh1jhj:ubeh}(h]h ]h"]h$]h&]uh1jhjUhKhjubj)}(h'``reset`` vq is in reset state or not. h](j)}(h ``reset``h]j)}(hjyh]hreset}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjwubah}(h]h ]h"]h$]h&]uh1jh_/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:56: ./include/linux/virtio.hhKhjsubj)}(hhh]h)}(hvq is in reset state or not.h]hvq is in reset state or not.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhKhjubah}(h]h ]h"]h$]h&]uh1jhjsubeh}(h]h ]h"]h$]h&]uh1jhjhKhjubj)}(h;``priv`` a pointer for the virtqueue implementation to use.h](j)}(h``priv``h]j)}(hjh]hpriv}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jh_/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:56: ./include/linux/virtio.hhKhjubj)}(hhh]h)}(h2a pointer for the virtqueue implementation to use.h]h2a pointer for the virtqueue implementation to use.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hh_/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:56: ./include/linux/virtio.hhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhKhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ] kernelindentah"]h$]h&]uh1j3hj:hhhj/hNubh)}(h**Description**h]j)}(hjh]h Description}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hh_/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:56: ./include/linux/virtio.hhKhj:hhubh)}(hA note on **num_free**: with indirect buffers, each buffer needs one element in the queue, otherwise a buffer will need one element per sg element.h](h A note on }(hj hhhNhNubj)}(h **num_free**h]hnum_free}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh}: with indirect buffers, each buffer needs one element in the queue, otherwise a buffer will need one element per sg element.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hh_/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:56: ./include/linux/virtio.hhKhj:hhubh)}(hXSThe callback function pointed by this struct is triggered when the device has consumed the buffers provided by the driver. More specifically, the trigger will be an interrupt issued by the hypervisor (see vring_interrupt()). Interrupt request handlers are registered for a virtqueue during the virtqueue setup process (transport-specific).h]hXSThe callback function pointed by this struct is triggered when the device has consumed the buffers provided by the driver. More specifically, the trigger will be an interrupt issued by the hypervisor (see vring_interrupt()). Interrupt request handlers are registered for a virtqueue during the virtqueue setup process (transport-specific).}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK;hj:hhubj)}(hhh]h}(h]h ]h"]h$]h&]entries](jvring_interrupt (C function)c.vring_interrupthNtauh1jhj:hhhNhNubj)}(hhh](j)}(h0irqreturn_t vring_interrupt (int irq, void *_vq)h]j)}(h/irqreturn_t vring_interrupt(int irq, void *_vq)h](h)}(hhh]j)}(h irqreturn_th]h irqreturn_t}(hjVhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjSubah}(h]h ]h"]h$]h&] refdomainj(reftype identifier reftargetjXmodnameN classnameNjj)}j]j ASTIdentifier)}jlvring_interruptsbc.vring_interruptasbuh1hhjOhhhe/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:65: ./drivers/virtio/virtio_ring.chM ubj)}(h h]h }(hj{hhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjOhhhjzhM ubj)}(hvring_interrupth]j)}(hjwh]hvring_interrupt}(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubah}(h]h ](jjeh"]h$]h&]hhuh1jhjOhhhjzhM ubhdesc_parameterlist)}(h(int irq, void *_vq)h](hdesc_parameter)}(hint irqh](hdesc_sig_keyword_type)}(hinth]hint}(hjhhhNhNubah}(h]h ]ktah"]h$]h&]uh1jhjubj)}(h h]h }(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubj)}(hirqh]hirq}(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]noemphhhuh1jhjubj)}(h void *_vqh](j)}(hvoidh]hvoid}(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubj)}(h h]h }(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubhdesc_sig_punctuation)}(h*h]h*}(hjhhhNhNubah}(h]h ]pah"]h$]h&]uh1jhjubj)}(h_vqh]h_vq}(hjhhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]noemphhhuh1jhjubeh}(h]h ]h"]h$]h&]hhuh1jhjOhhhjzhM ubeh}(h]h ]h"]h$]h&]hhjuh1jjjhjKhhhjzhM ubah}(h]jFah ](jjeh"]h$]h&]jj)jhuh1jhjzhM hjHhhubj)}(hhh]h)}(h"notify a virtqueue on an interrupth]h"notify a virtqueue on an interrupt}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1hhe/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:65: ./drivers/virtio/virtio_ring.chM hj8hhubah}(h]h ]h"]h$]h&]uh1jhjHhhhjzhM ubeh}(h]h ](j(functioneh"]h$]h&]j-j(j.jSj/jSj0j1j2uh1jhhhj:hNhNubj4)}(h**Parameters** ``int irq`` the IRQ number (ignored) ``void *_vq`` the struct virtqueue to notify **Description** Calls the callback function of **_vq** to process the virtqueue notification.h](h)}(h**Parameters**h]j)}(hj]h]h Parameters}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj[ubah}(h]h ]h"]h$]h&]uh1hhe/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:65: ./drivers/virtio/virtio_ring.chM hjWubj)}(hhh](j)}(h%``int irq`` the IRQ number (ignored) h](j)}(h ``int irq``h]j)}(hj|h]hint irq}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjzubah}(h]h ]h"]h$]h&]uh1jhe/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:65: ./drivers/virtio/virtio_ring.chM hjvubj)}(hhh]h)}(hthe IRQ number (ignored)h]hthe IRQ number (ignored)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhM hjubah}(h]h ]h"]h$]h&]uh1jhjvubeh}(h]h ]h"]h$]h&]uh1jhjhM hjsubj)}(h-``void *_vq`` the struct virtqueue to notify h](j)}(h ``void *_vq``h]j)}(hjh]h void *_vq}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhe/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:65: ./drivers/virtio/virtio_ring.chM hjubj)}(hhh]h)}(hthe struct virtqueue to notifyh]hthe struct virtqueue to notify}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhM hjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhM hjsubeh}(h]h ]h"]h$]h&]uh1jhjWubh)}(h**Description**h]j)}(hjh]h Description}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhe/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:65: ./drivers/virtio/virtio_ring.chM hjWubh)}(hMCalls the callback function of **_vq** to process the virtqueue notification.h](hCalls the callback function of }(hj hhhNhNubj)}(h**_vq**h]h_vq}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh' to process the virtqueue notification.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhe/var/lib/git/docbuild/linux/Documentation/driver-api/virtio/virtio:65: ./drivers/virtio/virtio_ring.chM hjWubeh}(h]h ] kernelindentah"]h$]h&]uh1j3hj:hhhNhNubeh}(h]&device-driver-communication-virtqueuesah ]h"])device - driver communication: virtqueuesah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hDevice discovery and probingh]hDevice discovery and probing}(hj9 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj6 hhhhhKFubh)}(hIn the kernel, the virtio core contains the virtio bus driver and transport-specific drivers like `virtio-pci` and `virtio-mmio`. Then there are individual virtio drivers for specific device types that are registered to the virtio bus driver.h](hbIn the kernel, the virtio core contains the virtio bus driver and transport-specific drivers like }(hjG hhhNhNubhtitle_reference)}(h `virtio-pci`h]h virtio-pci}(hjQ hhhNhNubah}(h]h ]h"]h$]h&]uh1jO hjG ubh and }(hjG hhhNhNubjP )}(h `virtio-mmio`h]h virtio-mmio}(hjc hhhNhNubah}(h]h ]h"]h$]h&]uh1jO hjG ubhr. Then there are individual virtio drivers for specific device types that are registered to the virtio bus driver.}(hjG hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKHhj6 hhubh)}(hXHow a virtio device is found and configured by the kernel depends on how the hypervisor defines it. Taking the `QEMU virtio-console `__ device as an example. When using PCI as a transport method, the device will present itself on the PCI bus with vendor 0x1af4 (Red Hat, Inc.) and device id 0x1003 (virtio console), as defined in the spec, so the kernel will detect it as it would do with any other PCI device.h](hoHow a virtio device is found and configured by the kernel depends on how the hypervisor defines it. Taking the }(hj{ hhhNhNubj)}(he`QEMU virtio-console `__h]hQEMU virtio-console}(hj hhhNhNubah}(h]h ]h"]h$]h&]nameQEMU virtio-consolerefuriKhttps://gitlab.com/qemu-project/qemu/-/blob/master/hw/char/virtio-console.cuh1jhj{ ubhX device as an example. When using PCI as a transport method, the device will present itself on the PCI bus with vendor 0x1af4 (Red Hat, Inc.) and device id 0x1003 (virtio console), as defined in the spec, so the kernel will detect it as it would do with any other PCI device.}(hj{ hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKMhj6 hhubh)}(hDuring the PCI enumeration process, if a device is found to match the virtio-pci driver (according to the virtio-pci device table, any PCI device with vendor id = 0x1af4)::h]hDuring the PCI enumeration process, if a device is found to match the virtio-pci driver (according to the virtio-pci device table, any PCI device with vendor id = 0x1af4):}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKUhj6 hhubjW)}(h/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */ static const struct pci_device_id virtio_pci_id_table[] = { { PCI_DEVICE(PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_ANY_ID) }, { 0 } };h]h/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */ static const struct pci_device_id virtio_pci_id_table[] = { { PCI_DEVICE(PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_ANY_ID) }, { 0 } };}hj sbah}(h]h ]h"]h$]h&]hhuh1jVhhhKYhj6 hhubh)}(hpthen the virtio-pci driver is probed and, if the probing goes well, the device is registered to the virtio bus::h]hothen the virtio-pci driver is probed and, if the probing goes well, the device is registered to the virtio bus:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK_hj6 hhubjW)}(hXstatic int virtio_pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) { ... if (force_legacy) { rc = virtio_pci_legacy_probe(vp_dev); /* Also try modern mode if we can't map BAR0 (no IO space). */ if (rc == -ENODEV || rc == -ENOMEM) rc = virtio_pci_modern_probe(vp_dev); if (rc) goto err_probe; } else { rc = virtio_pci_modern_probe(vp_dev); if (rc == -ENODEV) rc = virtio_pci_legacy_probe(vp_dev); if (rc) goto err_probe; } ... rc = register_virtio_device(&vp_dev->vdev);h]hXstatic int virtio_pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) { ... if (force_legacy) { rc = virtio_pci_legacy_probe(vp_dev); /* Also try modern mode if we can't map BAR0 (no IO space). */ if (rc == -ENODEV || rc == -ENOMEM) rc = virtio_pci_modern_probe(vp_dev); if (rc) goto err_probe; } else { rc = virtio_pci_modern_probe(vp_dev); if (rc == -ENODEV) rc = virtio_pci_legacy_probe(vp_dev); if (rc) goto err_probe; } ... rc = register_virtio_device(&vp_dev->vdev);}hj sbah}(h]h ]h"]h$]h&]hhuh1jVhhhKbhj6 hhubh)}(hWhen the device is registered to the virtio bus the kernel will look for a driver in the bus that can handle the device and call that driver's ``probe`` method.h](hWhen the device is registered to the virtio bus the kernel will look for a driver in the bus that can handle the device and call that driver’s }(hj hhhNhNubj)}(h ``probe``h]hprobe}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh method.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKzhj6 hhubh)}(hAt this point, the virtqueues will be allocated and configured by calling the appropriate ``virtio_find`` helper function, such as virtio_find_single_vq() or virtio_find_vqs(), which will end up calling a transport-specific ``find_vqs`` method.h](hZAt this point, the virtqueues will be allocated and configured by calling the appropriate }(hj hhhNhNubj)}(h``virtio_find``h]h virtio_find}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubhw helper function, such as virtio_find_single_vq() or virtio_find_vqs(), which will end up calling a transport-specific }(hj hhhNhNubj)}(h ``find_vqs``h]hfind_vqs}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh method.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK~hj6 hhubeh}(h]device-discovery-and-probingah ]h"]device discovery and probingah$]h&]uh1hhhhhhhhKFubh)}(hhh](h)}(h Referencesh]h References}(hj4 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1 hhhhhKubh)}(hX_`[1]` Virtio Spec v1.2: https://docs.oasis-open.org/virtio/virtio/v1.2/virtio-v1.2.htmlh](h)}(h_`[1]`h]h[1]}(hjF hhhNhNubah}(h]jah ]h"][1]ah$]h&]uh1hhjB referencedKubh Virtio Spec v1.2: }(hjB hhhNhNubj)}(h?https://docs.oasis-open.org/virtio/virtio/v1.2/virtio-v1.2.htmlh]h?https://docs.oasis-open.org/virtio/virtio/v1.2/virtio-v1.2.html}(hjZ hhhNhNubah}(h]h ]h"]h$]h&]refurij\ uh1jhjB ubeh}(h]h ]h"]h$]h&]uh1hhhhKhj1 hhubh)}(h-Check for later versions of the spec as well.h]h-Check for later versions of the spec as well.}hjo sbah}(h]h ]h"]h$]h&]hhuh1hhj1 hhhhhKubh)}(h_`[2]` Virtqueues and virtio ring: How the data travels https://www.redhat.com/en/blog/virtqueues-and-virtio-ring-how-data-travelsh](h)}(h_`[2]`h]h[2]}(hj hhhNhNubah}(h]jah ]h"][2]ah$]h&]uh1hhj} jU Kubh2 Virtqueues and virtio ring: How the data travels }(hj} hhhNhNubj)}(hJhttps://www.redhat.com/en/blog/virtqueues-and-virtio-ring-how-data-travelsh]hJhttps://www.redhat.com/en/blog/virtqueues-and-virtio-ring-how-data-travels}(hj hhhNhNubah}(h]h ]h"]h$]h&]refurij uh1jhj} ubeh}(h]h ]h"]h$]h&]uh1hhhhKhj1 hhubhrubric)}(h Footnotesh]h Footnotes}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj1 hhhhhKubhfootnote)}(h5that's why they may be also referred to as virtrings.h](hlabel)}(hhh]h1}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj hhhNhNubh)}(hj h]h7that’s why they may be also referred to as virtrings.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubeh}(h]jsah ]h"]f1ah$]h&]jmajrKjtjuuh1j hhhKhj1 hhubeh}(h] referencesah ]h"] referencesah$]h&]uh1hhhhhhhhKubeh}(h](virtio-on-linuxheh ]h"](virtio on linuxvirtioeh$]h&]uh1hhhhhhhhKexpect_referenced_by_name}j hsexpect_referenced_by_id}hhsubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourcehnj _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}([1]](jjef1]jca[2]]jaurefids}(h]hajs]jcaunameids}(j hj j j7j4j3 j0 j. j+ j j jR jj jj jsu nametypes}(j j j7j3 j. j jR j j uh}(hhj hj4hj0 j:jmjcjjj-j3jFjKj+ j6 j j1 jjF jj jsj u footnote_refs}j\ ]jcas citation_refs} autofootnotes]j aautofootnote_refs]jcasymbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}j( KsRparse_messages]transform_messages]hsystem_message)}(hhh]h)}(hhh]h,Hyperlink target "virtio" is not referenced.}hj sbah}(h]h ]h"]h$]h&]uh1hhj ubah}(h]h ]h"]h$]h&]levelKtypeINFOsourcehnjlineKuh1j uba transformerN include_log] decorationNhhub.