virtq

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package virtq is the device side of a virtio split virtqueue: it takes descriptor chains the driver made available and returns them used.

Everything in the rings is written by the guest and checked here: the available index may not run ahead of the queue, a chain may not loop or be longer than the queue, every buffer must lie in guest memory, device-writable buffers must follow the readable ones, and indirect descriptors (not negotiated) are refused.

Reference: the virtio spec, split-ring.tex — struct virtq_desc (:185-196), the descriptor rules (:146-151, :218-223, :266-278), struct virtq_avail (:298), struct virtq_used (:393-409) and the used length rules (:456-462).

Index

Constants

View Source
const (
	DescNext     uint16 = 1
	DescWrite    uint16 = 2
	DescIndirect uint16 = 4
)

Descriptor flags (split-ring.tex:192-196).

View Source
const MaxSize = 32768

MaxSize is the largest queue size (virtio: 32768).

Variables

View Source
var ErrRing = errors.New("virtq: malformed ring")

ErrRing is wrapped by every error a malformed ring causes.

Functions

func Gather

func Gather(c Chain, max uint64) (req []byte, ok bool)

Gather copies the readable buffers of c into one host buffer (at most max bytes; ok false if the chain is longer). Copying is what makes the request immune to the guest rewriting it while it is checked.

func Scatter

func Scatter(c Chain, p []byte) uint32

Scatter copies p into the writable buffers of c and returns how many bytes fitted.

Types

type Chain

type Chain struct {
	Head     uint16
	Readable [][]byte
	Writable [][]byte
	ReadLen  uint64
	WriteLen uint64
}

Chain is one descriptor chain: its head index and its buffers, which are views of guest memory.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is one split virtqueue as the device sees it.

func New

func New(mem gpudev.Memory, size uint16, desc, avail, used uint64) (*Queue, error)

New maps a queue of size entries whose rings the driver placed at the guest-physical addresses desc, avail and used.

func (*Queue) Pop

func (q *Queue) Pop() (c Chain, ok bool, err error)

Pop returns the next available chain, or ok false when there is none.

func (*Queue) Push

func (q *Queue) Push(head uint16, written uint32)

Push returns chain head to the driver with written bytes written (split-ring.tex:456: the length is set before the index moves).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL