[RFC PATCH 1/4] common: add UAPI for SQ/CQ doorbell polling
"rom.wang" <[email protected]> Mon, 20 Jul 2026 22:10:37 +0800
| Newsgroups | dev.linux.lists.virtualization,org.kernel.vger.kvm,org.kernel.vger.linux-kernel,org.kernel.vger.linux-scsi,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
From: Yufeng Wang <[email protected]> Define VIRTIO_F_SQCQ_POLL (bit 42) and the associated SQ/CQ doorbell structures for split virtqueue polling mode. - include/uapi/linux/virtio_config.h: feature bit 42 - include/uapi/linux/virtio_ring.h: struct vring_sq, struct vring_cq (128-byte aligned for cache-line isolation on ARM Neoverse N2/V2) - include/uapi/linux/virtio_pci.h: sqe/cqe_ring PCI config registers at offsets 64-76 Signed-off-by: Yufeng Wang <[email protected]> --- include/uapi/linux/virtio_config.h | 8 +++++++- include/uapi/linux/virtio_pci.h | 9 +++++++++ include/uapi/linux/virtio_ring.h | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h index 2445f365bce7..dbda23e44b62 100644 --- a/include/uapi/linux/virtio_config.h +++ b/include/uapi/linux/virtio_config.h @@ -52,7 +52,7 @@ * rest are per-device feature bits. */ #define VIRTIO_TRANSPORT_F_START 28 -#define VIRTIO_TRANSPORT_F_END 42 +#define VIRTIO_TRANSPORT_F_END 43 #ifndef VIRTIO_CONFIG_NO_LEGACY /* Do we get callbacks when the ring is completely used, even if we've @@ -120,4 +120,10 @@ */ #define VIRTIO_F_ADMIN_VQ 41 +/* + * This feature indicates that both driver and device support + * SQ/CQ polling mode to replace interrupt-based notifications. + */ +#define VIRTIO_F_SQCQ_POLL 42 + #endif /* _UAPI_LINUX_VIRTIO_CONFIG_H */ diff --git a/include/uapi/linux/virtio_pci.h b/include/uapi/linux/virtio_pci.h index e732e3456e27..f5058d1b4b16 100644 --- a/include/uapi/linux/virtio_pci.h +++ b/include/uapi/linux/virtio_pci.h @@ -193,6 +193,11 @@ struct virtio_pci_modern_common_cfg { __le16 admin_queue_index; /* read-only */ __le16 admin_queue_num; /* read-only */ + + __le32 sqe_ring_lo; /* read-write: SQ DMA addr low */ + __le32 sqe_ring_hi; /* read-write: SQ DMA addr high */ + __le32 cqe_ring_lo; /* read-write: CQ DMA addr low */ + __le32 cqe_ring_hi; /* read-write: CQ DMA addr high */ }; /* Fields in VIRTIO_PCI_CAP_PCI_CFG: */ @@ -235,6 +240,10 @@ struct virtio_pci_cfg_cap { #define VIRTIO_PCI_COMMON_Q_RESET 58 #define VIRTIO_PCI_COMMON_ADM_Q_IDX 60 #define VIRTIO_PCI_COMMON_ADM_Q_NUM 62 +#define VIRTIO_PCI_COMMON_SQE_LO 64 +#define VIRTIO_PCI_COMMON_SQE_HI 68 +#define VIRTIO_PCI_COMMON_CQE_LO 72 +#define VIRTIO_PCI_COMMON_CQE_HI 76 #endif /* VIRTIO_PCI_NO_MODERN */ diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h index 3c478582a3c2..d1f2b9584d7c 100644 --- a/include/uapi/linux/virtio_ring.h +++ b/include/uapi/linux/virtio_ring.h @@ -131,6 +131,31 @@ struct vring_used { vring_used_elem_t ring[]; }; +/* + * SQ/CQ doorbell structures for polling mode (VIRTIO_F_SQCQ_POLL). + * These are allocated separately from the vring and their DMA addresses + * are communicated via PCI config space registers. + * + * Ownership: + * SQ: Guest writes idx, Device reads it. + * CQ: Device writes idx, Guest reads it. + * + * Flags (8-bit): + * Set to 1 before sleeping, cleared to 0 after waking up. + * Direct assignment — no read-modify-write. + */ +struct vring_sq { + __virtio64 idx; /* Producer position (updated by guest) */ + __u8 sq_need_wakeup; /* 1 = device should be woken on next kick */ + __u8 reserved[55]; /* Reserved for future use */ +} __attribute__((aligned(128))); + +struct vring_cq { + __virtio64 idx; /* Producer position (updated by device) */ + __u8 cq_need_wakeup; /* 1 = guest should be woken on completion */ + __u8 reserved[55]; /* Reserved for future use */ +} __attribute__((aligned(128))); + /* * The ring element addresses are passed between components with different * alignments assumptions. Thus, we might need to decrease the compiler-selected -- 2.34.1