Update virtio headers (to fix build)
Subsystems (5)
cover Update virtio headers (to fix build)
Since we implement some virtio devices in kvmtool, we were including older copies of some virtio UAPI header files in our tree, but were relying on some other headers to be provided by the distribution. This leads to problems when we need to use newer virtio features (like the recent virtio_balloon stat update), which breaks compilation on some (older) distros.
To fix this and avoid similar problems in the future, just copy in the virtio UAPI headers from the kernel tree, as we do already for the actual KVM interface headers. To simplify future syncs, also update our update_headers.sh script on the way.
Please have a look!
Cheers,
Andre
Andre Przywara (4):
update virtio_mmio.h
util: include virtio UAPI headers in sync
include: update virtio UAPI headers
include: add new virtio uapi header files
include/linux/virtio_9p.h | 44 ++++++ include/linux/virtio_balloon.h | 119 ++++++++++++++++ include/linux/virtio_blk.h | 203 +++++++++++++++++++++++++++ include/linux/virtio_config.h | 101 ++++++++++++++ include/linux/virtio_console.h | 78 +++++++++++ include/linux/virtio_ids.h | 63 +++++++-- include/linux/virtio_mmio.h | 55 +++++++- include/linux/virtio_net.h | 200 +++++++++++++++++++++++---- include/linux/virtio_pci.h | 208 ++++++++++++++++++++++++++++ include/linux/virtio_ring.h | 244 +++++++++++++++++++++++++++++++++ include/linux/virtio_rng.h | 8 ++ include/linux/virtio_scsi.h | 118 ++++++++-------- include/linux/virtio_vsock.h | 16 ++- util/update_headers.sh | 10 ++ virtio/mmio.c | 8 +- 15 files changed, 1372 insertions(+), 103 deletions(-) create mode 100644 include/linux/virtio_9p.h create mode 100644 include/linux/virtio_balloon.h create mode 100644 include/linux/virtio_blk.h create mode 100644 include/linux/virtio_config.h create mode 100644 include/linux/virtio_console.h create mode 100644 include/linux/virtio_pci.h create mode 100644 include/linux/virtio_ring.h create mode 100644 include/linux/virtio_rng.h
Signature · 6 lines
2.25.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH 1/4 update virtio_mmio.h
At the time we pulled in virtio_mmio.h from the kernel tree (commit a08bb43a0c37c "kvmtool: Copy Linux' up-to-date virtio headers"), this was not an official UAPI header file, so wasn't stable and was not shipped with distributions.
This has changed with Linux commit 51be7a9a261c ("virtio_mmio: expose header to userspace"), so we can now use that file officially. However before that the name of some symbols have changed, so we have to adjust their usage in our source.
This pulls in virtio_mmio.h from Linux v5.18.0.
--- include/linux/virtio_mmio.h | 55 ++++++++++++++++++++++++++++++++----- virtio/mmio.c | 8 +++--- 2 files changed, 52 insertions(+), 11 deletions(-)
include/linux/virtio_mmio.h +48 -7
@@ -51,23 +51,29 @@/* Virtio vendor ID - Read Only */ #define VIRTIO_MMIO_VENDOR_ID 0x00c -/* Bitmask of the features supported by the host +/* Bitmask of the features supported by the device (host) * (32 bits per set) - Read Only */ -#define VIRTIO_MMIO_HOST_FEATURES 0x010 +#define VIRTIO_MMIO_DEVICE_FEATURES 0x010 -/* Host features set selector - Write Only */ -#define VIRTIO_MMIO_HOST_FEATURES_SEL 0x014 +/* Device (host) features set selector - Write Only */ +#define VIRTIO_MMIO_DEVICE_FEATURES_SEL 0x014 -/* Bitmask of features activated by the guest +/* Bitmask of features activated by the driver (guest) * (32 bits per set) - Write Only */ -#define VIRTIO_MMIO_GUEST_FEATURES 0x020 +#define VIRTIO_MMIO_DRIVER_FEATURES 0x020/* Activated features set selector - Write Only */ -#define VIRTIO_MMIO_GUEST_FEATURES_SEL 0x024 +#define VIRTIO_MMIO_DRIVER_FEATURES_SEL 0x024 + + +#ifndef VIRTIO_MMIO_NO_LEGACY /* LEGACY DEVICES ONLY! */ /* Guest's memory page size in bytes - Write Only */ #define VIRTIO_MMIO_GUEST_PAGE_SIZE 0x028 +#endif + +/* Queue selector - Write Only */ #define VIRTIO_MMIO_QUEUE_SEL 0x030
@@ -77,12 +83,21 @@/* Queue size for the currently selected queue - Write Only */ #define VIRTIO_MMIO_QUEUE_NUM 0x038 + +#ifndef VIRTIO_MMIO_NO_LEGACY /* LEGACY DEVICES ONLY! */ +/* Used Ring alignment for the currently selected queue - Write Only */ #define VIRTIO_MMIO_QUEUE_ALIGN 0x03c/* Guest's PFN for the currently selected queue - Read Write */ #define VIRTIO_MMIO_QUEUE_PFN 0x040 +#endif + + +/* Ready bit for the currently selected queue - Read Write */ +#define VIRTIO_MMIO_QUEUE_READY 0x044 +/* Queue notifier - Write Only */ #define VIRTIO_MMIO_QUEUE_NOTIFY 0x050
@@ -95,6 +110,32 @@/* Device status register - Read Write */ #define VIRTIO_MMIO_STATUS 0x070 +/* Selected queue's Descriptor Table address, 64 bits in two halves */ +#define VIRTIO_MMIO_QUEUE_DESC_LOW 0x080 +#define VIRTIO_MMIO_QUEUE_DESC_HIGH 0x084 + +/* Selected queue's Available Ring address, 64 bits in two halves */ +#define VIRTIO_MMIO_QUEUE_AVAIL_LOW 0x090 +#define VIRTIO_MMIO_QUEUE_AVAIL_HIGH 0x094 + +/* Selected queue's Used Ring address, 64 bits in two halves */ +#define VIRTIO_MMIO_QUEUE_USED_LOW 0x0a0 +#define VIRTIO_MMIO_QUEUE_USED_HIGH 0x0a4 + +/* Shared memory region id */ +#define VIRTIO_MMIO_SHM_SEL 0x0ac + +/* Shared memory region length, 64 bits in two halves */ +#define VIRTIO_MMIO_SHM_LEN_LOW 0x0b0 +#define VIRTIO_MMIO_SHM_LEN_HIGH 0x0b4 + +/* Shared memory region base address, 64 bits in two halves */ +#define VIRTIO_MMIO_SHM_BASE_LOW 0x0b8 +#define VIRTIO_MMIO_SHM_BASE_HIGH 0x0bc + +/* Configuration atomicity value */ +#define VIRTIO_MMIO_CONFIG_GENERATION 0x0fc +/* The config space is defined by each driver as * the per-driver configuration space - Read Write */ #define VIRTIO_MMIO_CONFIG 0x100
virtio/mmio.c +4 -4
@@ -142,7 +142,7 @@ static void virtio_mmio_config_in(struct kvm_cpu *vcpu,case VIRTIO_MMIO_INTERRUPT_STATUS :ioport__write32 (data, *(u32 *)(((void *)&vmmio->hdr) + addr));break ; -case VIRTIO_MMIO_HOST_FEATURES : +case VIRTIO_MMIO_DEVICE_FEATURES :if (vmmio->hdr.host_features_sel ==0 ) val = vdev->ops->get_host_features (vmmio->kvm, vmmio->dev);
@@ -173,8 +173,8 @@ static void virtio_mmio_config_out(struct kvm_cpu *vcpu,u32 val =0 ;switch (addr) { -case VIRTIO_MMIO_HOST_FEATURES_SEL : -case VIRTIO_MMIO_GUEST_FEATURES_SEL : +case VIRTIO_MMIO_DEVICE_FEATURES_SEL : +case VIRTIO_MMIO_DRIVER_FEATURES_SEL : val =ioport__read32 (data); *(u32 *)(((void *)&vmmio->hdr) + addr) = val;break ;
@@ -193,7 +193,7 @@ static void virtio_mmio_config_out(struct kvm_cpu *vcpu, vdev->endian =kvm_cpu__get_endianness (vcpu);virtio_notify_status (kvm, vdev, vmmio->dev, vmmio->hdr.status);break ; -case VIRTIO_MMIO_GUEST_FEATURES : +case VIRTIO_MMIO_DRIVER_FEATURES :if (vmmio->hdr.guest_features_sel ==0 ) { val =ioport__read32 (data); virtio_set_guest_features(vmmio->kvm, vdev,
Signature · 6 lines
2.25.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH 2/4 util: include virtio UAPI headers in sync
In reply to Andre PrzywaraWe already have an update_headers.sh sync script, where we occasionally update the KVM interface UAPI kernel headers into our tree. So far this covered only the generic kvm.h, plus each architecture's version of that file.
Commit bc77bf49df6e ("stat: Add descriptions for new virtio_balloon stat types") used newer virtio symbols, which some older distros do not include in their kernel headers package. To help fixing this and to avoid similar problems in the future, add the virtio headers to our sync script, so that we can get the same, up-to-date versions of the headers easily.
--- util/update_headers.sh | 10 ++++++++++ 1 file changed, 10 insertions(+)
util/update_headers.sh +10 -0
@@ -9,6 +9,11 @@ set -ue +VIRTIO_LIST="virtio_9p.h virtio_balloon.h virtio_blk.h virtio_config.h \ + virtio_console.h virtio_ids.h virtio_mmio.h virtio_net.h \ + virtio_pci.h virtio_ring.h virtio_rng.h virtio_scsi.h \ + virtio_vsock.h" + if [ "$#" -ge 1 ] then LINUX_ROOT="$1"
@@ -25,6 +30,11 @@ fi cp -- "$LINUX_ROOT/include/uapi/linux/kvm.h" include/linux +for header in $VIRTIO_LIST +do + cp -- "$LINUX_ROOT/include/uapi/linux/$header" include/linux +done + unset KVMTOOL_PATH copy_optional_arch () {
Signature · 6 lines
2.25.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH 3/4 include: update virtio UAPI headers
In reply to Andre PrzywaraCommit a08bb43a0c37 ("kvmtool: Copy Linux' up-to-date virtio headers") copied the kernel's virtio UAPI headers into the kvmtool tree, because at the time some distros didn't include (all of) them in their kernel headers package.
Let's update those copies, so that we can use newer features, if needed.
This syncs in the already existing copies of the headers from Linux v5.18.0.
--- include/linux/virtio_ids.h | 63 ++++++++--- include/linux/virtio_net.h | 200 +++++++++++++++++++++++++++++++---- include/linux/virtio_scsi.h | 118 +++++++++++---------- include/linux/virtio_vsock.h | 16 ++- 4 files changed, 305 insertions(+), 92 deletions(-)
include/linux/virtio_ids.h +51 -12
@@ -29,17 +29,56 @@* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#define VIRTIO_ID_NET 1/* virtio net */ -#define VIRTIO_ID_BLOCK 2/* virtio block */ -#define VIRTIO_ID_CONSOLE 3/* virtio console */ -#define VIRTIO_ID_RNG 4/* virtio rng */ -#define VIRTIO_ID_BALLOON 5/* virtio balloon */ -#define VIRTIO_ID_RPMSG 7/* virtio remote processor messaging */ -#define VIRTIO_ID_SCSI 8/* virtio scsi */ -#define VIRTIO_ID_9P 9/* 9p virtio console */ -#define VIRTIO_ID_RPROC_SERIAL 11/* virtio remoteproc serial link */ -#define VIRTIO_ID_CAIF 12/* Virtio caif */ -#define VIRTIO_ID_INPUT 18/* virtio input */ -#define VIRTIO_ID_VSOCK 19/* virtio vsock transport */ +#define VIRTIO_ID_NET 1/* virtio net */ +#define VIRTIO_ID_BLOCK 2/* virtio block */ +#define VIRTIO_ID_CONSOLE 3/* virtio console */ +#define VIRTIO_ID_RNG 4/* virtio rng */ +#define VIRTIO_ID_BALLOON 5/* virtio balloon */ +#define VIRTIO_ID_IOMEM 6/* virtio ioMemory */ +#define VIRTIO_ID_RPMSG 7/* virtio remote processor messaging */ +#define VIRTIO_ID_SCSI 8/* virtio scsi */ +#define VIRTIO_ID_9P 9/* 9p virtio console */ +#define VIRTIO_ID_MAC80211_WLAN 10/* virtio WLAN MAC */ +#define VIRTIO_ID_RPROC_SERIAL 11/* virtio remoteproc serial link */ +#define VIRTIO_ID_CAIF 12/* Virtio caif */ +#define VIRTIO_ID_MEMORY_BALLOON 13/* virtio memory balloon */ +#define VIRTIO_ID_GPU 16/* virtio GPU */ +#define VIRTIO_ID_CLOCK 17/* virtio clock/timer */ +#define VIRTIO_ID_INPUT 18/* virtio input */ +#define VIRTIO_ID_VSOCK 19/* virtio vsock transport */ +#define VIRTIO_ID_CRYPTO 20/* virtio crypto */ +#define VIRTIO_ID_SIGNAL_DIST 21/* virtio signal distribution device */ +#define VIRTIO_ID_PSTORE 22/* virtio pstore device */ +#define VIRTIO_ID_IOMMU 23/* virtio IOMMU */ +#define VIRTIO_ID_MEM 24/* virtio mem */ +#define VIRTIO_ID_SOUND 25/* virtio sound */ +#define VIRTIO_ID_FS 26/* virtio filesystem */ +#define VIRTIO_ID_PMEM 27/* virtio pmem */ +#define VIRTIO_ID_RPMB 28/* virtio rpmb */ +#define VIRTIO_ID_MAC80211_HWSIM 29/* virtio mac80211-hwsim */ +#define VIRTIO_ID_VIDEO_ENCODER 30/* virtio video encoder */ +#define VIRTIO_ID_VIDEO_DECODER 31/* virtio video decoder */ +#define VIRTIO_ID_SCMI 32/* virtio SCMI */ +#define VIRTIO_ID_NITRO_SEC_MOD 33/* virtio nitro secure module*/ +#define VIRTIO_ID_I2C_ADAPTER 34/* virtio i2c adapter */ +#define VIRTIO_ID_WATCHDOG 35/* virtio watchdog */ +#define VIRTIO_ID_CAN 36/* virtio can */ +#define VIRTIO_ID_DMABUF 37/* virtio dmabuf */ +#define VIRTIO_ID_PARAM_SERV 38/* virtio parameter server */ +#define VIRTIO_ID_AUDIO_POLICY 39/* virtio audio policy */ +#define VIRTIO_ID_BT 40/* virtio bluetooth */ +#define VIRTIO_ID_GPIO 41/* virtio gpio */ + +/* +* Virtio Transitional IDs +*/ + +#define VIRTIO_TRANS_ID_NET 1000/* transitional virtio net */ +#define VIRTIO_TRANS_ID_BLOCK 1001/* transitional virtio block */ +#define VIRTIO_TRANS_ID_BALLOON 1002/* transitional virtio balloon */ +#define VIRTIO_TRANS_ID_CONSOLE 1003/* transitional virtio console */ +#define VIRTIO_TRANS_ID_SCSI 1004/* transitional virtio SCSI */ +#define VIRTIO_TRANS_ID_RNG 1005/* transitional virtio rng */ +#define VIRTIO_TRANS_ID_9P 1009/* transitional virtio 9p console */ #endif /* _LINUX_VIRTIO_IDS_H */
include/linux/virtio_net.h +177 -23
268 lines not on this page · raw message
include/linux/virtio_scsi.h +64 -54
147 lines not on this page · raw message
include/linux/virtio_vsock.h +13 -3
@@ -31,13 +31,16 @@* Copyright (C) Stefan Hajnoczi <[email protected]>, 2015 */ -#ifndef _LINUX_VIRTIO_VSOCK_H -#define _LINUX_VIRTIO_VSOCK_H +#ifndef _UAPI_LINUX_VIRTIO_VSOCK_H +#define _UAPI_LINUX_VIRTIO_VSOCK_H#include <linux/types.h> #include <linux/virtio_ids.h> #include <linux/virtio_config.h> +/* The feature bitmap for virtio vsock */ +#define VIRTIO_VSOCK_F_SEQPACKET 1/* SOCK_SEQPACKET supported */ +struct virtio_vsock_config {__le64 guest_cid; } __attribute__((packed));
@@ -65,6 +68,7 @@ struct virtio_vsock_hdr {enum virtio_vsock_type {VIRTIO_VSOCK_TYPE_STREAM =1 , +VIRTIO_VSOCK_TYPE_SEQPACKET =2 , };enum virtio_vsock_op {
@@ -91,4 +95,10 @@ enum virtio_vsock_shutdown { VIRTIO_VSOCK_SHUTDOWN_SEND = 2, }; -#endif /* _LINUX_VIRTIO_VSOCK_H */ +/* VIRTIO_VSOCK_OP_RW flags values */ +enum virtio_vsock_rw { +VIRTIO_VSOCK_SEQ_EOM =1 , +VIRTIO_VSOCK_SEQ_EOR =2 , +}; + +#endif /* _UAPI_LINUX_VIRTIO_VSOCK_H */
Signature · 6 lines
2.25.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH 4/4 include: add new virtio uapi header files
In reply to Andre PrzywaraCommit a08bb43a0c37 ("kvmtool: Copy Linux' up-to-date virtio headers") copied in some of the virtio UAPI headers from the kernel tree, but didn't include all of them, as we were relying on some of them being provided by the distribution.
Now commit bc77bf49df6e ("stat: Add descriptions for new virtio_balloon
stat types") used some newer virtio balloon symbols, that some older
distros (e.g. Ubuntu 18.04) do not carry, which breaks compilation
there:
=======================
CC builtin-stat.obuiltin-stat.c: In function 'do_memstat':
builtin-stat.c:86:8: error: 'VIRTIO_BALLOON_S_HTLB_PGALLOC' undeclared (first use in this function); did you mean 'VIRTIO_BALLOON_S_AVAIL'?
case VIRTIO_BALLOON_S_HTLB_PGALLOC:
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VIRTIO_BALLOON_S_AVAILbuiltin-stat.c:86:8: note: each undeclared identifier is reported only once for each function it appears in
=======================
To fix this include the remaining virtio headers (those that we actually need for kvmtool at the moment), from Linux v5.18.0.
--- include/linux/virtio_9p.h | 44 ++++++ include/linux/virtio_balloon.h | 119 ++++++++++++++++ include/linux/virtio_blk.h | 203 +++++++++++++++++++++++++++ include/linux/virtio_config.h | 101 ++++++++++++++ include/linux/virtio_console.h | 78 +++++++++++ include/linux/virtio_pci.h | 208 ++++++++++++++++++++++++++++ include/linux/virtio_ring.h | 244 +++++++++++++++++++++++++++++++++ include/linux/virtio_rng.h | 8 ++ 8 files changed, 1005 insertions(+) create mode 100644 include/linux/virtio_9p.h create mode 100644 include/linux/virtio_balloon.h create mode 100644 include/linux/virtio_blk.h create mode 100644 include/linux/virtio_config.h create mode 100644 include/linux/virtio_console.h create mode 100644 include/linux/virtio_pci.h create mode 100644 include/linux/virtio_ring.h create mode 100644 include/linux/virtio_rng.h
include/linux/virtio_9p.h new file +44 -0
@@ -0,0 +1,44 @@ +#ifndef _LINUX_VIRTIO_9P_H +#define _LINUX_VIRTIO_9P_H +/* This header is BSD licensed so anyone can use the definitions to implement +* compatible drivers/servers. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* 3. Neither the name of IBM nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. */ +#include <linux/virtio_types.h> +#include <linux/virtio_ids.h> +#include <linux/virtio_config.h> + +/* The feature bitmap for virtio 9P */ + +/* The mount point is specified in a config variable */ +#define VIRTIO_9P_MOUNT_TAG 0 + +struct virtio_9p_config { +/* length of the tag name */ +__virtio16 tag_len; +/* non-NULL terminated tag name */ +__u8 tag[0 ]; +} __attribute__((packed)); + +#endif /* _LINUX_VIRTIO_9P_H */
include/linux/virtio_balloon.h new file +119 -0
119 lines not on this page · raw message
include/linux/virtio_blk.h new file +203 -0
203 lines not on this page · raw message
include/linux/virtio_config.h new file +101 -0
101 lines not on this page · raw message
include/linux/virtio_console.h new file +78 -0
78 lines not on this page · raw message
include/linux/virtio_pci.h new file +208 -0
208 lines not on this page · raw message
include/linux/virtio_ring.h new file +244 -0
244 lines not on this page · raw message
include/linux/virtio_rng.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef _LINUX_VIRTIO_RNG_H +#define _LINUX_VIRTIO_RNG_H +/* This header is BSD licensed so anyone can use the definitions to implement +* compatible drivers/servers. */ +#include <linux/virtio_ids.h> +#include <linux/virtio_config.h> + +#endif /* _LINUX_VIRTIO_RNG_H */
Signature · 6 lines
2.25.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Will Deacon
AppliedQuoted 8 lines · Andre Przywara
Since we implement some virtio devices in kvmtool, we were including older copies of some virtio UAPI header files in our tree, but were relying on some other headers to be provided by the distribution. This leads to problems when we need to use newer virtio features (like the recent
virtio_balloonstat update), which breaks compilation on some (older) distros.[...]
Applied to kvmtool (master), thanks!
[1/4] update virtio_mmio.h
https://git.kernel.org/will/kvmtool/c/7e2209945bb5 [2/4] util: include virtio UAPI headers in sync https://git.kernel.org/will/kvmtool/c/393e2187cf68 [3/4] include: update virtio UAPI headers https://git.kernel.org/will/kvmtool/c/e5390783db61 [4/4] include: add new virtio uapi header files https://git.kernel.org/will/kvmtool/c/1a992bbaab08
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev