Skip to contentSkip to conversation

qemu: use virtio linux headers in portable code

PATCH In review Michael S. Tsirkin 6 participants 38 messages May 26, 2013 – May 29, 2013

Subsystems (3)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

v2 cover qemu: use virtio linux headers in portable code

virtio linux headers are actually pretty portable:
all we need is implement linux/types.h in a portable way, and we can import them and use on any platform.

These patches do exactly that, as a pre-requisite
to adding support for new virtio layout.

Note: if someone adds non-portable code in files we import from linux-headers, we'll have to revert to copying code manually. This didn't happen yet so hopefully it won't.

Changes from v1:
- add stubs for non linux platforms
- fix mingw cross build

Michael S. Tsirkin (11):
make: pull in linux-headers on all platforms
scripts/update-linux-headers.sh: add virtio
virtio-9p: switch to linux-headers
virtio-net, eth: use linux-headers
virtio-blk: switch to linux-headers
virtio-balloon: switch to linux-headers
virtio-rng: switch to linux-headers
virtio-console: switch to linux-headers
virtio: add virtio_ids from linux-headers
virtio-pci: switch to linux-headers
virtio: use ring structure from linux-headers

 Makefile.target                      |   5 +-
 configure                            |   7 +-
 hw/9pfs/virtio-9p.h                  |  13 +--
 hw/block/dataplane/virtio-blk.c      |  12 +--
 hw/block/virtio-blk.c                |  10 +-
 hw/virtio/virtio-balloon.c           |   2 +-
 hw/virtio/virtio-pci.c               |  49 +--------
 hw/virtio/virtio.c                   |  23 +---
 include/hw/virtio/virtio-balloon.h   |  37 +------
 include/hw/virtio/virtio-blk.h       |  86 +--------------
 include/hw/virtio/virtio-net.h       | 141 +-----------------------
 include/hw/virtio/virtio-rng.h       |   5 +-
 include/hw/virtio/virtio-serial.h    |  38 +------
 include/hw/virtio/virtio.h           |  45 +-------
 include/net/eth.h                    |   5 +-
 include/net/tap.h                    |  24 +----
 linux-headers/linux/if_ether.h       | 140 ++++++++++++++++++++++++
 linux-headers/linux/virtio_9p.h      |  44 ++++++++
 linux-headers/linux/virtio_balloon.h |  59 ++++++++++
 linux-headers/linux/virtio_blk.h     | 128 ++++++++++++++++++++++
 linux-headers/linux/virtio_console.h |  74 +++++++++++++
 linux-headers/linux/virtio_ids.h     |  43 ++++++++
 linux-headers/linux/virtio_net.h     | 202 +++++++++++++++++++++++++++++++++++
 linux-headers/linux/virtio_pci.h     |  97 +++++++++++++++++
 linux-headers/linux/virtio_rng.h     |   8 ++
 scripts/update-linux-headers.sh      |  17 ++-
 26 files changed, 862 insertions(+), 452 deletions(-)
 create mode 100644 linux-headers/linux/if_ether.h
 create mode 100644 linux-headers/linux/virtio_9p.h
 create mode 100644 linux-headers/linux/virtio_balloon.h
 create mode 100644 linux-headers/linux/virtio_blk.h
 create mode 100644 linux-headers/linux/virtio_console.h
 create mode 100644 linux-headers/linux/virtio_ids.h
 create mode 100644 linux-headers/linux/virtio_net.h
 create mode 100644 linux-headers/linux/virtio_pci.h
 create mode 100644 linux-headers/linux/virtio_rng.h
Signature · 1 line
MST
author maintainer
#1 lore raw

PATCH v2 1/11 make: pull in linux-headers on all platforms

Things we pull from linux-headers are actually quite portable. All we need is implement linux/types.h using stdint.h and we are able to compile on any platform.

---
 Makefile.target | 5 +++--
 configure       | 7 ++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
Makefile.target +3 -2
index ce4391f..5d69d50 100644
@@ -6,9 +6,10 @@ include config-devices.mak
 include $(SRC_PATH)/rules.mak
 
 $(call set-vpath, $(SRC_PATH))
-ifdef CONFIG_LINUX
-QEMU_CFLAGS += -I../linux-headers
+ifndef CONFIG_LINUX
+QEMU_CFLAGS += -I../linux-stubs
 endif
+QEMU_CFLAGS += -I../linux-headers
 QEMU_CFLAGS += -I.. -I$(SRC_PATH)/target-$(TARGET_BASE_ARCH) -DNEED_CPU_H
 
 QEMU_CFLAGS+=-I$(SRC_PATH)/include
configure +6 -1
index 5ae7e4a..8321f8b 100755
@@ -427,6 +427,7 @@ fi
 
 # OS specific
 
+QEMU_LINUX_HEADER_INCLUDES="-I\$(SRC_PATH)/linux-stubs -I\$(SRC_PATH)/linux-headers "
 case $targetos in
 CYGWIN*)
   mingw32="yes"
@@ -547,10 +548,14 @@ Haiku)
   if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
     audio_possible_drivers="$audio_possible_drivers fmod"
   fi
-  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers $QEMU_INCLUDES"
+  QEMU_LINUX_HEADER_INCLUDES="-I\$(SRC_PATH)/linux-headers "
 ;;
 esac
 
+#Always pull in linux-headers, we make sure they are
+#cross-platform
+QEMU_INCLUDES="$QEMU_LINUX_HEADER_INCLUDES$QEMU_INCLUDES"
+
 if [ "$bsd" = "yes" ] ; then
   if [ "$darwin" != "yes" ] ; then
     usb="bsd"
Signature · 1 line
MST
author maintainer
#2 lore raw

PATCH v2 2/11 scripts/update-linux-headers.sh: add virtio

In reply to Michael S. Tsirkin

Add virtio headers to make it easy to keep
things in sync.

---
 scripts/update-linux-headers.sh | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
scripts/update-linux-headers.sh +16 -1
index 120a694..334fba9 100755
@@ -61,7 +61,22 @@ done
 
 rm -rf "$output/linux-headers/linux"
 mkdir -p "$output/linux-headers/linux"
-for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h; do
+for header in \
+    kvm.h \
+    kvm_para.h \
+    vfio.h \
+    vhost.h \
+    virtio_9p.h \
+    virtio_balloon.h \
+    virtio_blk.h \
+    virtio_config.h \
+    virtio_console.h \
+    virtio_ids.h \
+    virtio_net.h \
+    virtio_pci.h \
+    virtio_ring.h \
+    virtio_rng.h \
+    ; do
     cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
 done
 rm -rf "$output/linux-headers/asm-generic"
Signature · 1 line
MST
author maintainer
#3 lore raw

PATCH v2 3/11 virtio-9p: switch to linux-headers

In reply to Michael S. Tsirkin

It's easier to keep everything in sync if
we just use linux headers for virtio constants.
Add virtio-9p header from linux 3.10-rc1, and
remove duplicate symbols from virtio-9p.h

---
 hw/9pfs/virtio-9p.h             | 13 +-----------
 linux-headers/linux/virtio_9p.h | 44 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 12 deletions(-)
 create mode 100644 linux-headers/linux/virtio_9p.h
hw/9pfs/virtio-9p.h +1 -12
index 1d6eedb..5ba4411 100644
@@ -11,10 +11,7 @@
 #include "fsdev/virtio-9p-marshal.h"
 #include "qemu/thread.h"
 #include "block/coroutine.h"
-
-/* The feature bitmap for virtio 9P */
-/* The mount point is specified in a config variable */
-#define VIRTIO_9P_MOUNT_TAG 0
+#include "linux/virtio_9p.h"
 
 enum {
     P9_TLERROR = 6,
@@ -277,14 +274,6 @@ typedef struct V9fsWriteState {
     int cnt;
 } V9fsWriteState;
 
-struct virtio_9p_config
-{
-    /* number of characters in tag */
-    uint16_t tag_len;
-    /* Variable size tag name */
-    uint8_t tag[0];
-} QEMU_PACKED;
-
 typedef struct V9fsMkState {
     V9fsPDU *pdu;
     size_t offset;
linux-headers/linux/virtio_9p.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#4 lore raw

PATCH v2 4/11 virtio-net, eth: use linux-headers

In reply to Michael S. Tsirkin

It's easier to keep everything virtio in sync if
we just use headers exported from linux kernel.
Import linux/virtio_net.h and linux/if_ether.h
that it depends on. Switch to symbols from
that header for stuff that was
duplicated in tap.h and eth.h

---
 include/hw/virtio/virtio-net.h   | 141 +--------------------------
 include/net/eth.h                |   5 +-
 include/net/tap.h                |  24 +----
 linux-headers/linux/if_ether.h   | 140 +++++++++++++++++++++++++++
 linux-headers/linux/virtio_net.h | 202 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 347 insertions(+), 165 deletions(-)
 create mode 100644 linux-headers/linux/if_ether.h
 create mode 100644 linux-headers/linux/virtio_net.h
include/hw/virtio/virtio-net.h +3 -138
index b315ac9..65616c0 100644
@@ -16,46 +16,13 @@
 
 #include "hw/virtio/virtio.h"
 #include "hw/pci/pci.h"
+#include "linux/virtio_net.h"
+#include "linux/virtio_ids.h"
 
 #define TYPE_VIRTIO_NET "virtio-net-device"
 #define VIRTIO_NET(obj) \
         OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET)
 
-#define ETH_ALEN    6
-
-/* from Linux's virtio_net.h */
-
-/* The ID for virtio_net */
-#define VIRTIO_ID_NET   1
-
-/* The feature bitmap for virtio net */
-#define VIRTIO_NET_F_CSUM       0       /* Host handles pkts w/ partial csum */
-#define VIRTIO_NET_F_GUEST_CSUM 1       /* Guest handles pkts w/ partial csum */
-#define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Control channel offload
-                                         * configuration support */
-#define VIRTIO_NET_F_MAC        5       /* Host has given MAC address. */
-#define VIRTIO_NET_F_GSO        6       /* Host handles pkts w/ any GSO type */
-#define VIRTIO_NET_F_GUEST_TSO4 7       /* Guest can handle TSOv4 in. */
-#define VIRTIO_NET_F_GUEST_TSO6 8       /* Guest can handle TSOv6 in. */
-#define VIRTIO_NET_F_GUEST_ECN  9       /* Guest can handle TSO[6] w/ ECN in. */
-#define VIRTIO_NET_F_GUEST_UFO  10      /* Guest can handle UFO in. */
-#define VIRTIO_NET_F_HOST_TSO4  11      /* Host can handle TSOv4 in. */
-#define VIRTIO_NET_F_HOST_TSO6  12      /* Host can handle TSOv6 in. */
-#define VIRTIO_NET_F_HOST_ECN   13      /* Host can handle TSO[6] w/ ECN in. */
-#define VIRTIO_NET_F_HOST_UFO   14      /* Host can handle UFO in. */
-#define VIRTIO_NET_F_MRG_RXBUF  15      /* Host can merge receive buffers. */
-#define VIRTIO_NET_F_STATUS     16      /* virtio_net_config.status available */
-#define VIRTIO_NET_F_CTRL_VQ    17      /* Control channel available */
-#define VIRTIO_NET_F_CTRL_RX    18      /* Control channel RX mode support */
-#define VIRTIO_NET_F_CTRL_VLAN  19      /* Control channel VLAN filtering */
-#define VIRTIO_NET_F_CTRL_RX_EXTRA 20   /* Extra RX mode control support */
-#define VIRTIO_NET_F_MQ         22      /* Device supports Receive Flow
-                                         * Steering */
-
-#define VIRTIO_NET_F_CTRL_MAC_ADDR   23 /* Set MAC address */
-
-#define VIRTIO_NET_S_LINK_UP    1       /* Link is up */
-
 #define TX_TIMER_INTERVAL 150000 /* 150 us */
 
 /* Limit the number of packets that can be sent via a single flush
@@ -75,72 +42,6 @@ typedef struct virtio_net_conf
 /* Maximum packet size we can receive from tap device: header + 64k */
 #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10))
 
-struct virtio_net_config
-{
-    /* The config defining mac address ($ETH_ALEN bytes) */
-    uint8_t mac[ETH_ALEN];
-    /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
-    uint16_t status;
-    /* Max virtqueue pairs supported by the device */
-    uint16_t max_virtqueue_pairs;
-} QEMU_PACKED;
-
-/*
- * Control virtqueue data structures
- *
- * The control virtqueue expects a header in the first sg entry
- * and an ack/status response in the last entry.  Data for the
- * command goes in between.
- */
-struct virtio_net_ctrl_hdr {
-    uint8_t class;
-    uint8_t cmd;
-};
-
-typedef uint8_t virtio_net_ctrl_ack;
-
-#define VIRTIO_NET_OK     0
-#define VIRTIO_NET_ERR    1
-
-/*
- * Control the RX mode, ie. promisucous, allmulti, etc...
- * All commands require an "out" sg entry containing a 1 byte
- * state value, zero = disable, non-zero = enable.  Commands
- * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
- * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
- */
-#define VIRTIO_NET_CTRL_RX    0
- #define VIRTIO_NET_CTRL_RX_PROMISC      0
- #define VIRTIO_NET_CTRL_RX_ALLMULTI     1
- #define VIRTIO_NET_CTRL_RX_ALLUNI       2
- #define VIRTIO_NET_CTRL_RX_NOMULTI      3
- #define VIRTIO_NET_CTRL_RX_NOUNI        4
- #define VIRTIO_NET_CTRL_RX_NOBCAST      5
-
-/*
- * Control the MAC
- *
- * The MAC filter table is managed by the hypervisor, the guest should
- * assume the size is infinite.  Filtering should be considered
- * non-perfect, ie. based on hypervisor resources, the guest may
- * received packets from sources not specified in the filter list.
- *
- * In addition to the class/cmd header, the TABLE_SET command requires
- * two out scatterlists.  Each contains a 4 byte count of entries followed
- * by a concatenated byte stream of the ETH_ALEN MAC addresses.  The
- * first sg list contains unicast addresses, the second is for multicast.
- * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
- * is available.
- *
- * The ADDR_SET command requests one out scatterlist, it contains a
- * 6 bytes MAC address. This functionality is present if the
- * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available.
- */
-struct virtio_net_ctrl_mac {
-    uint32_t entries;
-    uint8_t macs[][ETH_ALEN];
-};
-
 typedef struct VirtIONetQueue {
     VirtQueue *rx_vq;
     VirtQueue *tx_vq;
@@ -195,43 +96,7 @@ typedef struct VirtIONet {
     uint64_t curr_guest_offloads;
 } VirtIONet;
 
-#define VIRTIO_NET_CTRL_MAC    1
- #define VIRTIO_NET_CTRL_MAC_TABLE_SET        0
- #define VIRTIO_NET_CTRL_MAC_ADDR_SET         1
-
-/*
- * Control VLAN filtering
- *
- * The VLAN filter table is controlled via a simple ADD/DEL interface.
- * VLAN IDs not added may be filterd by the hypervisor.  Del is the
- * opposite of add.  Both commands expect an out entry containing a 2
- * byte VLAN ID.  VLAN filterting is available with the
- * VIRTIO_NET_F_CTRL_VLAN feature bit.
- */
-#define VIRTIO_NET_CTRL_VLAN       2
- #define VIRTIO_NET_CTRL_VLAN_ADD             0
- #define VIRTIO_NET_CTRL_VLAN_DEL             1
-
-/*
- * Control Multiqueue
- *
- * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
- * enables multiqueue, specifying the number of the transmit and
- * receive queues that will be used. After the command is consumed and acked by
- * the device, the device will not steer new packets on receive virtqueues
- * other than specified nor read from transmit virtqueues other than specified.
- * Accordingly, driver should not transmit new packets  on virtqueues other than
- * specified.
- */
-struct virtio_net_ctrl_mq {
-    uint16_t virtqueue_pairs;
-};
-
-#define VIRTIO_NET_CTRL_MQ   4
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
-
+#define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Guest offload control */
 /*
  * Control network offloads
  *
include/net/eth.h +1 -4
index 1d48e06..6102394 100644
@@ -26,13 +26,12 @@
 #ifndef QEMU_ETH_H
 #define QEMU_ETH_H
 
+#include <linux/if_ether.h>
 #include <sys/types.h>
 #include <string.h>
 #include "qemu/bswap.h"
 #include "qemu/iov.h"
 
-#define ETH_ALEN 6
-
 struct eth_header {
     uint8_t  h_dest[ETH_ALEN];   /* destination eth addr */
     uint8_t  h_source[ETH_ALEN]; /* source ether addr    */
@@ -170,8 +169,6 @@ struct tcp_hdr {
 #define IP_HEADER_VERSION(ip)     \
     ((ip->ip_ver_len >> 4)&0xf)
 
-#define ETH_P_IP                  (0x0800)
-#define ETH_P_IPV6                (0x86dd)
 #define ETH_P_VLAN                (0x8100)
 #define ETH_P_DVLAN               (0x88a8)
 #define VLAN_VID_MASK             0x0fff
include/net/tap.h +1 -23
index a994f20..2eff653 100644
@@ -28,6 +28,7 @@
 
 #include "qemu-common.h"
 #include "qapi-types.h"
+#include "linux/virtio_net.h"
 
 bool tap_has_ufo(NetClientState *nc);
 int tap_has_vnet_hdr(NetClientState *nc);
@@ -43,27 +44,4 @@ int tap_get_fd(NetClientState *nc);
 struct vhost_net;
 struct vhost_net *tap_get_vhost_net(NetClientState *nc);
 
-struct virtio_net_hdr
-{
-#define VIRTIO_NET_HDR_F_NEEDS_CSUM     1       // Use csum_start, csum_offset
-#define VIRTIO_NET_HDR_F_DATA_VALID    2       // Csum is valid
-    uint8_t flags;
-#define VIRTIO_NET_HDR_GSO_NONE         0       // Not a GSO frame
-#define VIRTIO_NET_HDR_GSO_TCPV4        1       // GSO frame, IPv4 TCP (TSO)
-#define VIRTIO_NET_HDR_GSO_UDP          3       // GSO frame, IPv4 UDP (UFO)
-#define VIRTIO_NET_HDR_GSO_TCPV6        4       // GSO frame, IPv6 TCP
-#define VIRTIO_NET_HDR_GSO_ECN          0x80    // TCP has ECN set
-    uint8_t gso_type;
-    uint16_t hdr_len;
-    uint16_t gso_size;
-    uint16_t csum_start;
-    uint16_t csum_offset;
-};
-
-struct virtio_net_hdr_mrg_rxbuf
-{
-    struct virtio_net_hdr hdr;
-    uint16_t num_buffers;   /* Number of merged rx buffers */
-};
-
 #endif /* QEMU_NET_TAP_H */
linux-headers/linux/if_ether.h new file +140 -0

140 lines not on this page · raw message

linux-headers/linux/virtio_net.h new file +202 -0

202 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#5 lore raw

PATCH v2 5/11 virtio-blk: switch to linux-headers

In reply to Michael S. Tsirkin

It's easier to keep everything in sync if
we just use linux headers for virtio constants.
Add virtio_blk.h header from linux 3.10-rc1, and
remove duplicate symbols from virtio-blk.h

In particular, it turns out that linux does not have struct virtio_blk_inhdr for the status field, so make this struct match the qemu coding style.

---
 hw/block/dataplane/virtio-blk.c  |  12 ++--
 hw/block/virtio-blk.c            |  10 +--
 include/hw/virtio/virtio-blk.h   |  86 ++------------------------
 linux-headers/linux/virtio_blk.h | 128 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 144 insertions(+), 92 deletions(-)
 create mode 100644 linux-headers/linux/virtio_blk.h
hw/block/dataplane/virtio-blk.c +6 -6
index 0356665..e582ff3 100644
@@ -87,7 +87,7 @@ static void complete_request(struct iocb *iocb, ssize_t ret, void *opaque)
 {
     VirtIOBlockDataPlane *s = opaque;
     VirtIOBlockRequest *req = container_of(iocb, VirtIOBlockRequest, iocb);
-    struct virtio_blk_inhdr hdr;
+    VirtIOBlockInHdr hdr;
     int len;
 
     if (likely(ret >= 0)) {
@@ -128,7 +128,7 @@ static void complete_request(struct iocb *iocb, ssize_t ret, void *opaque)
 static void complete_request_early(VirtIOBlockDataPlane *s, unsigned int head,
                                    QEMUIOVector *inhdr, unsigned char status)
 {
-    struct virtio_blk_inhdr hdr = {
+    VirtIOBlockInHdr hdr = {
         .status = status,
     };
 
@@ -215,16 +215,16 @@ static int process_request(IOQueue *ioq, struct iovec iov[],
 
     /* Grab inhdr for later */
     in_size = iov_size(in_iov, in_num);
-    if (in_size < sizeof(struct virtio_blk_inhdr)) {
+    if (in_size < sizeof(VirtIOBlockInHdr)) {
         error_report("virtio_blk request inhdr too short");
         return -EFAULT;
     }
     inhdr = g_slice_new(QEMUIOVector);
     qemu_iovec_init(inhdr, 1);
     qemu_iovec_concat_iov(inhdr, in_iov, in_num,
-            in_size - sizeof(struct virtio_blk_inhdr),
-            sizeof(struct virtio_blk_inhdr));
-    iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr));
+            in_size - sizeof(VirtIOBlockInHdr),
+            sizeof(VirtIOBlockInHdr));
+    iov_discard_back(in_iov, &in_num, sizeof(VirtIOBlockInHdr));
 
     /* TODO Linux sets the barrier bit even when not advertised! */
     outhdr.type &= ~VIRTIO_BLK_T_BARRIER;
hw/block/virtio-blk.c +5 -5
index cf12469..d8131f7 100644
@@ -30,7 +30,7 @@ typedef struct VirtIOBlockReq
 {
     VirtIOBlock *dev;
     VirtQueueElement elem;
-    struct virtio_blk_inhdr *in;
+    VirtIOBlockInHdr *in;
     struct virtio_blk_outhdr *out;
     struct virtio_scsi_inhdr *scsi;
     QEMUIOVector qiov;
@@ -487,11 +487,11 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
     memset(&blkcfg, 0, sizeof(blkcfg));
     stq_raw(&blkcfg.capacity, capacity);
     stl_raw(&blkcfg.seg_max, 128 - 2);
-    stw_raw(&blkcfg.cylinders, s->conf->cyls);
+    stw_raw(&blkcfg.geometry.cylinders, s->conf->cyls);
     stl_raw(&blkcfg.blk_size, blk_size);
     stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
     stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
-    blkcfg.heads = s->conf->heads;
+    blkcfg.geometry.heads = s->conf->heads;
     /*
      * We must ensure that the block device capacity is a multiple of
      * the logical block size. If that is not the case, let's use
@@ -504,9 +504,9 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
      * per track (cylinder).
      */
     if (bdrv_getlength(s->bs) /  s->conf->heads / s->conf->secs % blk_size) {
-        blkcfg.sectors = s->conf->secs & ~s->sector_mask;
+        blkcfg.geometry.sectors = s->conf->secs & ~s->sector_mask;
     } else {
-        blkcfg.sectors = s->conf->secs;
+        blkcfg.geometry.sectors = s->conf->secs;
     }
     blkcfg.size_max = 0;
     blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
include/hw/virtio/virtio-blk.h +5 -81

100 lines not on this page · raw message

linux-headers/linux/virtio_blk.h new file +128 -0

128 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#6 lore raw

PATCH v2 6/11 virtio-balloon: switch to linux-headers

In reply to Michael S. Tsirkin

It's easier to keep everything in sync if
we just use linux headers for virtio constants. Add virtio_balloon.h header from linux 3.10-rc1, and remove duplicate symbols from virtio-balloon.h

---
 hw/virtio/virtio-balloon.c           |  2 +-
 include/hw/virtio/virtio-balloon.h   | 37 ++--------------------
 linux-headers/linux/virtio_balloon.h | 59 ++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 35 deletions(-)
 create mode 100644 linux-headers/linux/virtio_balloon.h
hw/virtio/virtio-balloon.c +1 -1
index d669756..548508b 100644
@@ -216,7 +216,7 @@ static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
     VirtQueueElement *elem = &s->stats_vq_elem;
-    VirtIOBalloonStat stat;
+    struct virtio_balloon_stat stat;
     size_t offset = 0;
     qemu_timeval tv;
 
include/hw/virtio/virtio-balloon.h +3 -34
index f863bfe..dc0702d 100644
@@ -17,45 +17,14 @@
 
 #include "hw/virtio/virtio.h"
 #include "hw/pci/pci.h"
+#include "linux/virtio_balloon.h"
+#include "linux/virtio_ids.h"
+
 
 #define TYPE_VIRTIO_BALLOON "virtio-balloon-device"
 #define VIRTIO_BALLOON(obj) \
         OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON)
 
-/* from Linux's linux/virtio_balloon.h */
-
-/* The ID for virtio_balloon */
-#define VIRTIO_ID_BALLOON 5
-
-/* The feature bitmap for virtio balloon */
-#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
-#define VIRTIO_BALLOON_F_STATS_VQ 1       /* Memory stats virtqueue */
-
-/* Size of a PFN in the balloon interface. */
-#define VIRTIO_BALLOON_PFN_SHIFT 12
-
-struct virtio_balloon_config
-{
-    /* Number of pages host wants Guest to give up. */
-    uint32_t num_pages;
-    /* Number of pages we've actually got in balloon. */
-    uint32_t actual;
-};
-
-/* Memory Statistics */
-#define VIRTIO_BALLOON_S_SWAP_IN  0   /* Amount of memory swapped in */
-#define VIRTIO_BALLOON_S_SWAP_OUT 1   /* Amount of memory swapped out */
-#define VIRTIO_BALLOON_S_MAJFLT   2   /* Number of major faults */
-#define VIRTIO_BALLOON_S_MINFLT   3   /* Number of minor faults */
-#define VIRTIO_BALLOON_S_MEMFREE  4   /* Total amount of free memory */
-#define VIRTIO_BALLOON_S_MEMTOT   5   /* Total amount of memory */
-#define VIRTIO_BALLOON_S_NR       6
-
-typedef struct VirtIOBalloonStat {
-    uint16_t tag;
-    uint64_t val;
-} QEMU_PACKED VirtIOBalloonStat;
-
 typedef struct VirtIOBalloon {
     VirtIODevice parent_obj;
     VirtQueue *ivq, *dvq, *svq;
linux-headers/linux/virtio_balloon.h new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#7 lore raw

PATCH v2 7/11 virtio-rng: switch to linux-headers

In reply to Michael S. Tsirkin

It's easier to keep everything in sync if
we just use linux headers for virtio constants.
Add virtio_rng.h header from linux 3.10-rc1, and
remove duplicate symbols from virtio-rng.h

---
 include/hw/virtio/virtio-rng.h   | 5 ++---
 linux-headers/linux/virtio_rng.h | 8 ++++++++
 2 files changed, 10 insertions(+), 3 deletions(-)
 create mode 100644 linux-headers/linux/virtio_rng.h
include/hw/virtio/virtio-rng.h +2 -3
index debaa15..a0cc62e 100644
@@ -14,14 +14,13 @@
 
 #include "sysemu/rng.h"
 #include "sysemu/rng-random.h"
+#include "linux/virtio_rng.h"
+#include "linux/virtio_ids.h"
 
 #define TYPE_VIRTIO_RNG "virtio-rng-device"
 #define VIRTIO_RNG(obj) \
         OBJECT_CHECK(VirtIORNG, (obj), TYPE_VIRTIO_RNG)
 
-/* The Virtio ID for the virtio rng device */
-#define VIRTIO_ID_RNG    4
-
 struct VirtIORNGConf {
     RngBackend *rng;
     uint64_t max_bytes;
linux-headers/linux/virtio_rng.h new file +8 -0
new file mode 100644
index 0000000..c4d5de8
@@ -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 · 1 line
MST
author maintainer
#8 lore raw

PATCH v2 8/11 virtio-console: switch to linux-headers

In reply to Michael S. Tsirkin

It's easier to keep everything in sync if
we just use linux headers for virtio constants. Add virtio_console.h header from linux 3.10-rc1, and remove duplicate symbols from virtio-serial.h

---
 include/hw/virtio/virtio-serial.h    | 38 +-----------------
 linux-headers/linux/virtio_console.h | 74 ++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 37 deletions(-)
 create mode 100644 linux-headers/linux/virtio_console.h
include/hw/virtio/virtio-serial.h +1 -37
index 1d2040b..7dd76ab 100644
@@ -17,49 +17,13 @@
 
 #include "hw/qdev.h"
 #include "hw/virtio/virtio.h"
-
-/* == Interface shared between the guest kernel and qemu == */
-
-/* The Virtio ID for virtio console / serial ports */
-#define VIRTIO_ID_CONSOLE		3
-
-/* Features supported */
-#define VIRTIO_CONSOLE_F_MULTIPORT	1
-
-#define VIRTIO_CONSOLE_BAD_ID           (~(uint32_t)0)
-
-struct virtio_console_config {
-    /*
-     * These two fields are used by VIRTIO_CONSOLE_F_SIZE which
-     * isn't implemented here yet
-     */
-    uint16_t cols;
-    uint16_t rows;
-
-    uint32_t max_nr_ports;
-} QEMU_PACKED;
-
-struct virtio_console_control {
-    uint32_t id;		/* Port number */
-    uint16_t event;		/* The kind of control event (see below) */
-    uint16_t value;		/* Extra information for the key */
-};
+#include "linux/virtio_console.h"
 
 struct virtio_serial_conf {
     /* Max. number of ports we can have for a virtio-serial device */
     uint32_t max_virtserial_ports;
 };
 
-/* Some events for the internal messages (control packets) */
-#define VIRTIO_CONSOLE_DEVICE_READY	0
-#define VIRTIO_CONSOLE_PORT_ADD		1
-#define VIRTIO_CONSOLE_PORT_REMOVE	2
-#define VIRTIO_CONSOLE_PORT_READY	3
-#define VIRTIO_CONSOLE_CONSOLE_PORT	4
-#define VIRTIO_CONSOLE_RESIZE		5
-#define VIRTIO_CONSOLE_PORT_OPEN	6
-#define VIRTIO_CONSOLE_PORT_NAME	7
-
 /* == In-qemu interface == */
 
 #define TYPE_VIRTIO_SERIAL_PORT "virtio-serial-port"
linux-headers/linux/virtio_console.h new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#9 lore raw

PATCH v2 9/11 virtio: add virtio_ids from linux-headers

In reply to Michael S. Tsirkin

All imported headers will use it.

---
 linux-headers/linux/virtio_ids.h | 43 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 linux-headers/linux/virtio_ids.h
linux-headers/linux/virtio_ids.h new file +43 -0
new file mode 100644
index 0000000..284fc3a
@@ -0,0 +1,43 @@
+#ifndef _LINUX_VIRTIO_IDS_H
+#define _LINUX_VIRTIO_IDS_H
+/*
+ * Virtio IDs
+ *
+ * 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. */
+
+#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 */
+
+#endif /* _LINUX_VIRTIO_IDS_H */
Signature · 1 line
MST
author maintainer
#10 lore raw

PATCH v2 10/11 virtio-pci: switch to linux-headers

In reply to Michael S. Tsirkin

It's easier to keep everything in sync if
we just use linux headers for virtio constants.
Add virtio_pci.h header from linux 3.10-rc1, and
remove duplicate symbols from virtio-pci.h

---
 hw/virtio/virtio-pci.c           | 49 +++-----------------
 linux-headers/linux/virtio_pci.h | 97 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 44 deletions(-)
 create mode 100644 linux-headers/linux/virtio_pci.h
hw/virtio/virtio-pci.c +5 -44
index 70d2c6b..8707463 100644
@@ -34,53 +34,14 @@
 #include "qemu/range.h"
 #include "hw/virtio/virtio-bus.h"
 #include "qapi/visitor.h"
-
-/* from Linux's linux/virtio_pci.h */
-
-/* A 32-bit r/o bitmask of the features supported by the host */
-#define VIRTIO_PCI_HOST_FEATURES        0
-
-/* A 32-bit r/w bitmask of features activated by the guest */
-#define VIRTIO_PCI_GUEST_FEATURES       4
-
-/* A 32-bit r/w PFN for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_PFN            8
-
-/* A 16-bit r/o queue size for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_NUM            12
-
-/* A 16-bit r/w queue selector */
-#define VIRTIO_PCI_QUEUE_SEL            14
-
-/* A 16-bit r/w queue notifier */
-#define VIRTIO_PCI_QUEUE_NOTIFY         16
-
-/* An 8-bit device status register.  */
-#define VIRTIO_PCI_STATUS               18
-
-/* An 8-bit r/o interrupt status register.  Reading the value will return the
- * current contents of the ISR and will also clear it.  This is effectively
- * a read-and-acknowledge. */
-#define VIRTIO_PCI_ISR                  19
-
-/* MSI-X registers: only enabled if MSI-X is enabled. */
-/* A 16-bit vector for configuration changes. */
-#define VIRTIO_MSI_CONFIG_VECTOR        20
-/* A 16-bit vector for selected queue notifications. */
-#define VIRTIO_MSI_QUEUE_VECTOR         22
+#include "linux/virtio_pci.h"
 
 /* Config space size */
-#define VIRTIO_PCI_CONFIG_NOMSI         20
-#define VIRTIO_PCI_CONFIG_MSI           24
-#define VIRTIO_PCI_REGION_SIZE(dev)     (msix_present(dev) ? \
-                                         VIRTIO_PCI_CONFIG_MSI : \
-                                         VIRTIO_PCI_CONFIG_NOMSI)
+#define VIRTIO_PCI_REGION_SIZE(dev)     VIRTIO_PCI_CONFIG_OFF(msix_present(dev))
 
 /* The remaining space is defined by each driver as the per-driver
  * configuration space */
-#define VIRTIO_PCI_CONFIG(dev)          (msix_enabled(dev) ? \
-                                         VIRTIO_PCI_CONFIG_MSI : \
-                                         VIRTIO_PCI_CONFIG_NOMSI)
+#define VIRTIO_PCI_CONFIG_SIZE(dev)     VIRTIO_PCI_CONFIG_OFF(msix_enabled(dev))
 
 /* How many bits to shift physical queue address written to QUEUE_PFN.
  * 12 is historical, and due to x86 page size. */
@@ -386,7 +347,7 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr,
                                        unsigned size)
 {
     VirtIOPCIProxy *proxy = opaque;
-    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
     uint64_t val = 0;
     if (addr < config) {
         return virtio_ioport_read(proxy, addr);
@@ -417,7 +378,7 @@ static void virtio_pci_config_write(void *opaque, hwaddr addr,
                                     uint64_t val, unsigned size)
 {
     VirtIOPCIProxy *proxy = opaque;
-    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
     if (addr < config) {
         virtio_ioport_write(proxy, addr, val);
         return;
linux-headers/linux/virtio_pci.h new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#11 lore raw

PATCH v2 11/11 virtio: use ring structure from linux-headers

In reply to Michael S. Tsirkin

We already have ring structure in virtio-ring.h for use by dataplane. Use it in virtio.h as well, renaming some conflicting functions.

---
 hw/virtio/virtio.c         | 23 +++++------------------
 include/hw/virtio/virtio.h | 45 +++------------------------------------------
 2 files changed, 8 insertions(+), 60 deletions(-)
hw/virtio/virtio.c +5 -18
index 8176c14..20bb6c2 100644
@@ -145,7 +145,7 @@ static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
     return lduw_phys(pa);
 }
 
-static inline uint16_t vring_used_event(VirtQueue *vq)
+static inline uint16_t vring_used_event_idx(VirtQueue *vq)
 {
     return vring_avail_ring(vq, vq->vring.num);
 }
@@ -192,7 +192,7 @@ static inline void vring_used_flags_unset_bit(VirtQueue *vq, int mask)
     stw_phys(pa, lduw_phys(pa) & ~mask);
 }
 
-static inline void vring_avail_event(VirtQueue *vq, uint16_t val)
+static inline void vring_avail_event_idx(VirtQueue *vq, uint16_t val)
 {
     hwaddr pa;
     if (!vq->notification) {
@@ -206,7 +206,7 @@ void virtio_queue_set_notification(VirtQueue *vq, int enable)
 {
     vq->notification = enable;
     if (vq->vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
-        vring_avail_event(vq, vring_avail_idx(vq));
+        vring_avail_event_idx(vq, vring_avail_idx(vq));
     } else if (enable) {
         vring_used_flags_unset_bit(vq, VRING_USED_F_NO_NOTIFY);
     } else {
@@ -448,7 +448,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
 
     i = head = virtqueue_get_head(vq, vq->last_avail_idx++);
     if (vq->vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
-        vring_avail_event(vq, vring_avail_idx(vq));
+        vring_avail_event_idx(vq, vring_avail_idx(vq));
     }
 
     if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_INDIRECT) {
@@ -740,19 +740,6 @@ void virtio_irq(VirtQueue *vq)
     virtio_notify_vector(vq->vdev, vq->vector);
 }
 
-/* Assuming a given event_idx value from the other size, if
- * we have just incremented index from old to new_idx,
- * should we trigger an event? */
-static inline int vring_need_event(uint16_t event, uint16_t new, uint16_t old)
-{
-	/* Note: Xen has similar logic for notification hold-off
-	 * in include/xen/interface/io/ring.h with req_event and req_prod
-	 * corresponding to event_idx + 1 and new respectively.
-	 * Note also that req_event and req_prod in Xen start at 1,
-	 * event indexes in virtio start at 0. */
-	return (uint16_t)(new - event - 1) < (uint16_t)(new - old);
-}
-
 static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
 {
     uint16_t old, new;
@@ -773,7 +760,7 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
     vq->signalled_used_valid = true;
     old = vq->signalled_used;
     new = vq->signalled_used = vring_used_idx(vq);
-    return !v || vring_need_event(vring_used_event(vq), new, old);
+    return !v || vring_need_event(vring_used_event_idx(vq), new, old);
 }
 
 void virtio_notify(VirtIODevice *vdev, VirtQueue *vq)
include/hw/virtio/virtio.h +3 -42

53 lines not on this page · raw message

Signature · 1 line
MST
#12 lore raw
In reply to Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin

virtio linux headers are actually pretty portable:
all we need is implement linux/types.h in a portable way, and we can import them and use on any platform.

These patches do exactly that, as a pre-requisite
to adding support for new virtio layout.

Note: if someone adds non-portable code in files we import from linux-headers, we'll have to revert to copying code manually. This didn't happen yet so hopefully it won't.

This series breaks compilation on MacOSX:

CC net/eth.o
In file included from net/eth.c:18:
In file included from /Users/pm215/src/qemu/include/net/eth.h:29:
/Users/pm215/src/qemu/linux-headers/linux/if_ether.h:24:10: fatal
error: 'linux/types.h' file not found

#include <linux/types.h>
         ^

1 error generated.
make: *** [net/eth.o] Error 1

thanks
-- PMM

author maintainer
#13 lore raw
Quoted 19 lines · Peter Maydell
Quoted 10 lines · Michael S. Tsirkin

virtio linux headers are actually pretty portable:
all we need is implement linux/types.h in a portable way, and we can import them and use on any platform.

These patches do exactly that, as a pre-requisite
to adding support for new virtio layout.

Note: if someone adds non-portable code in files we import from linux-headers, we'll have to revert to copying code manually. This didn't happen yet so hopefully it won't.

This series breaks compilation on MacOSX:

CC net/eth.o
In file included from net/eth.c:18:
In file included from /Users/pm215/src/qemu/include/net/eth.h:29:
/Users/pm215/src/qemu/linux-headers/linux/if_ether.h:24:10: fatal
error: 'linux/types.h' file not found

Quoted 7 lines
#include <linux/types.h>
         ^

1 error generated.
make: *** [net/eth.o] Error 1

thanks
-- PMM

Could be a stale file in your tree ...
Did configure get re-run?
Could you post the config-host.mak file please?

#14 lore raw
Quoted 13 lines · Michael S. Tsirkin
Quoted 11 lines · Peter Maydell

This series breaks compilation on MacOSX:

CC net/eth.o
In file included from net/eth.c:18:
In file included from /Users/pm215/src/qemu/include/net/eth.h:29:
/Users/pm215/src/qemu/linux-headers/linux/if_ether.h:24:10: fatal
error: 'linux/types.h' file not found

#include <linux/types.h>
         ^

1 error generated.
make: *** [net/eth.o] Error 1

Quoted 3 lines

Could be a stale file in your tree ...
Did configure get re-run?
Could you post the config-host.mak file please?

Configure did get rerun, but where are you expecting the header to pull linux/types.h from? Your patchset adds files which include it but doesn't add any copy itself, so if you're not on a Linux host then it just doesn't exist...

config-host.mak attached.

thanks
-- PMM

author maintainer
#15 lore raw
Quoted 23 lines · Peter Maydell
Quoted 13 lines · Michael S. Tsirkin
Quoted 11 lines · Peter Maydell

This series breaks compilation on MacOSX:

CC net/eth.o
In file included from net/eth.c:18:
In file included from /Users/pm215/src/qemu/include/net/eth.h:29:
/Users/pm215/src/qemu/linux-headers/linux/if_ether.h:24:10: fatal
error: 'linux/types.h' file not found

#include <linux/types.h>
         ^

1 error generated.
make: *** [net/eth.o] Error 1

Quoted 3 lines

Could be a stale file in your tree ...
Did configure get re-run?
Could you post the config-host.mak file please?

Configure did get rerun, but where are you expecting the header to pull linux/types.h from? Your patchset adds files which include it but doesn't add any copy itself, so if you're not on a Linux host then it just doesn't exist...

Quoted 4 lines

config-host.mak attached.

thanks
-- PMM

Ouch. Forgot to git-add them. Thanks.

I'll send a fixed version -
could you please try this patch on top?

linux-stubs: linux/types.h

This adds a directory with minimal stubs that
make it possible to use some linux headers
in qemu in a portable environment.

---

linux-stubs/linux/types.h new file +37 -0
new file mode 100644
index 0000000..8642cbb
@@ -0,0 +1,37 @@
+#ifndef STUBS_LINUX_TYPES_H
+#define STUBS_LINUX_TYPES_H
+
+#include <stdint.h>
+
+/*
+ * Below are Linux-specific types that should never collide with
+ * any application/library that wants linux/types.h.
+ */
+
+typedef uint8_t __u8;
+typedef uint16_t __u16;
+typedef uint32_t __u32;
+typedef uint64_t __u64;
+
+#ifdef __CHECKER__
+#define __bitwise__ __attribute__((bitwise))
+#else
+#define __bitwise__
+#endif
+#ifdef __CHECK_ENDIAN__
+#define __bitwise __bitwise__
+#else
+#define __bitwise
+#endif
+
+typedef __u16 __bitwise __le16;
+typedef __u16 __bitwise __be16;
+typedef __u32 __bitwise __le32;
+typedef __u32 __bitwise __be32;
+typedef __u64 __bitwise __le64;
+typedef __u64 __bitwise __be64;
+
+typedef __u16 __bitwise __sum16;
+typedef __u32 __bitwise __wsum;
+
+#endif
Signature · 1 line
MST
#16 lore raw

Il 26/05/2013 20:10, Michael S. Tsirkin ha scritto:

Quoted 78 lines · Peter Maydell
Quoted 23 lines · Michael S. Tsirkin
Quoted 13 lines · Peter Maydell
Quoted 11 lines

This series breaks compilation on MacOSX:

CC net/eth.o
In file included from net/eth.c:18:
In file included from /Users/pm215/src/qemu/include/net/eth.h:29:
/Users/pm215/src/qemu/linux-headers/linux/if_ether.h:24:10: fatal
error: 'linux/types.h' file not found

#include <linux/types.h>
         ^

1 error generated.
make: *** [net/eth.o] Error 1

Quoted 3 lines

Could be a stale file in your tree ...
Did configure get re-run?
Could you post the config-host.mak file please?

Configure did get rerun, but where are you expecting the header to pull linux/types.h from? Your patchset adds files which include it but doesn't add any copy itself, so if you're not on a Linux host then it just doesn't exist...

Quoted 4 lines

config-host.mak attached.

thanks
-- PMM

Ouch. Forgot to git-add them. Thanks.

I'll send a fixed version -
could you please try this patch on top?

linux-stubs: linux/types.h

This adds a directory with minimal stubs that
make it possible to use some linux headers
in qemu in a portable environment.

---

linux-stubs/linux/types.h new file +26 -0
new file mode 100644
index 0000000..8642cbb
@@ -0,0 +1,37 @@
+#ifndef STUBS_LINUX_TYPES_H
+#define STUBS_LINUX_TYPES_H
+
+#include <stdint.h>
+
+/*
+ * Below are Linux-specific types that should never collide with
+ * any application/library that wants linux/types.h.
+ */
+
+typedef uint8_t __u8;
+typedef uint16_t __u16;
+typedef uint32_t __u32;
+typedef uint64_t __u64;
+
+#ifdef __CHECKER__
+#define __bitwise__ __attribute__((bitwise))
+#else
+#define __bitwise__
+#endif
+#ifdef __CHECK_ENDIAN__
+#define __bitwise __bitwise__
+#else
+#define __bitwise
+#endif
+

linux-stubs/linux/types.h line 36

Quoted 10 lines
linux-stubs/linux/types.h new file +10 -0
+typedef __u16 __bitwise __le16;
+typedef __u16 __bitwise __be16;
+typedef __u32 __bitwise __le32;
+typedef __u32 __bitwise __be32;
+typedef __u64 __bitwise __le64;
+typedef __u64 __bitwise __be64;
+
+typedef __u16 __bitwise __sum16;
+typedef __u32 __bitwise __wsum;
+

I don't like defining __-prefixed types. Can we preprocess linux-headers to avoid usage of __u8/16/32/64, and to s,linux/types.h,stdint.h, ?

Paolo

Quoted 4 lines
linux-stubs/linux/types.h new file +1 -0
+#endif
author maintainer
#17 lore raw
Quoted 94 lines · Paolo Bonzini

Il 26/05/2013 20:10, Michael S. Tsirkin ha scritto:

Quoted 78 lines · Peter Maydell
Quoted 23 lines · Michael S. Tsirkin
Quoted 13 lines · Peter Maydell
Quoted 11 lines

This series breaks compilation on MacOSX:

CC net/eth.o
In file included from net/eth.c:18:
In file included from /Users/pm215/src/qemu/include/net/eth.h:29:
/Users/pm215/src/qemu/linux-headers/linux/if_ether.h:24:10: fatal
error: 'linux/types.h' file not found

#include <linux/types.h>
         ^

1 error generated.
make: *** [net/eth.o] Error 1

Quoted 3 lines

Could be a stale file in your tree ...
Did configure get re-run?
Could you post the config-host.mak file please?

Configure did get rerun, but where are you expecting the header to pull linux/types.h from? Your patchset adds files which include it but doesn't add any copy itself, so if you're not on a Linux host then it just doesn't exist...

Quoted 4 lines

config-host.mak attached.

thanks
-- PMM

Ouch. Forgot to git-add them. Thanks.

I'll send a fixed version -
could you please try this patch on top?

linux-stubs: linux/types.h

This adds a directory with minimal stubs that
make it possible to use some linux headers
in qemu in a portable environment.

---

linux-stubs/linux/types.h new file +26 -0
new file mode 100644
index 0000000..8642cbb
@@ -0,0 +1,37 @@
+#ifndef STUBS_LINUX_TYPES_H
+#define STUBS_LINUX_TYPES_H
+
+#include <stdint.h>
+
+/*
+ * Below are Linux-specific types that should never collide with
+ * any application/library that wants linux/types.h.
+ */
+
+typedef uint8_t __u8;
+typedef uint16_t __u16;
+typedef uint32_t __u32;
+typedef uint64_t __u64;
+
+#ifdef __CHECKER__
+#define __bitwise__ __attribute__((bitwise))
+#else
+#define __bitwise__
+#endif
+#ifdef __CHECK_ENDIAN__
+#define __bitwise __bitwise__
+#else
+#define __bitwise
+#endif
+

linux-stubs/linux/types.h line 36

Quoted 10 lines
linux-stubs/linux/types.h new file +10 -0
+typedef __u16 __bitwise __le16;
+typedef __u16 __bitwise __be16;
+typedef __u32 __bitwise __le32;
+typedef __u32 __bitwise __be32;
+typedef __u64 __bitwise __le64;
+typedef __u64 __bitwise __be64;
+
+typedef __u16 __bitwise __sum16;
+typedef __u32 __bitwise __wsum;
+

I don't like defining __-prefixed types. Can we preprocess linux-headers to avoid usage of __u8/16/32/64, and to s,linux/types.h,stdint.h, ?

Quoted 1 line

Paolo

Let's not be purists, and do the practical thing.

When I suggested this you didn't like it:

Quoted 5 lines
Quoted 3 lines

I can think of two ways:
- strip linux/types.h in update_headers
- add a stub linux/types.h for non linux platforms

The latter, using stdint.h types, would be fine.

And now, I think it's cleaner to keep it as is. Most likely, these specific __ types work fine, *if* we see a problem we can think what's to be done. In particular, there are __le/__be tags there which can be useful to do static code analysis.

What's the worst case failure scanario? Conflict with some system standard header on some strange target OS, this results in a failed build, and we go and try to fix it, almost surely with ifndef around some of the stubs. Why worry now?

Quoted 4 lines
Quoted 4 lines

+#endif

#18 lore raw

Il 26/05/2013 20:37, Michael S. Tsirkin ha scritto:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I don't like defining __-prefixed types. Can we preprocess linux-headers to avoid usage of __u8/16/32/64, and to s,linux/types.h,stdint.h, ?

Quoted 9 lines
Quoted 1 line
Quoted 1 line

Paolo

Let's not be purists, and do the practical thing.

When I suggested this you didn't like it:

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

I can think of two ways:
- strip linux/types.h in update_headers
- add a stub linux/types.h for non linux platforms

The latter, using stdint.h types, would be fine.

My fault. I should have looked at linux/types.h (actually asm-generic/).

Paolo

author maintainer
#19 lore raw
Quoted 13 lines · Paolo Bonzini

Il 26/05/2013 20:37, Michael S. Tsirkin ha scritto:

Quoted 12 lines
Quoted 5 lines
Quoted 5 lines

I don't like defining __-prefixed types. Can we preprocess linux-headers to avoid usage of __u8/16/32/64, and to s,linux/types.h,stdint.h, ?

Paolo

Let's not be purists, and do the practical thing.

When I suggested this you didn't like it:

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

I can think of two ways:
- strip linux/types.h in update_headers
- add a stub linux/types.h for non linux platforms

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

The latter, using stdint.h types, would be fine.

My fault. I should have looked at linux/types.h (actually asm-generic/).

Paolo

Not really, __uX appear in the headers that were posted. What I'm saying is - a chance of a conflict is very remote, if it happens it's a build failure so easy to debug.

Signature · 1 line
MST
#20 lore raw

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 5 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted. What I'm saying is - a chance of a conflict is very remote, if it happens it's a build failure so easy to debug.

I'm sure that others will complain, :) but you can go ahead.

Paolo

#21 lore raw
Quoted 4 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 3 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Quoted 4 lines
Quoted 2 lines

What I'm saying is - a chance of a conflict is very remote, if it happens it's a build failure so easy to debug.

I'm sure that others will complain, :) but you can go ahead.

I think we should clean up the virtio headers in the kernel first. Seems like a good thing to do given the standardization effort too.

There are lots of headers in uapi that use the C99 int types so there doesn't seem to be a reason they couldn't be used in virtio. fuse.h even has a:

    #ifdef __KERNEL__
    #include <linux/types.h>
    #else
    #include <stdint.h>
    #endif

Which seems like a reasonable thing to do.

The only other kernel dependency is linux/if_ether.h to define ETH_ALEN. But it seems completely reasonable to define a VIRTIO_NET_MAC_ALEN or something like that.

This would make the virtio headers completely stand alone and includable in userspace (without violating C99).

Perhaps it's even worth moving the headers from uapi/linux to uapi/virtio. Rusty, what do you think?

Regards,

Anhtony Liguori

Quoted 2 lines

Paolo

author maintainer
#22 lore raw
Quoted 9 lines · Anthony Liguori
Quoted 4 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 3 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

What I'm saying is - a chance of a conflict is very remote, if it happens it's a build failure so easy to debug.

I'm sure that others will complain, :) but you can go ahead.

I think we should clean up the virtio headers in the kernel first. Seems like a good thing to do given the standardization effort too. There are lots of headers in uapi that use the C99 int types

I found 4:

$ grep -l uint include/uapi/linux/*h
include/uapi/linux/dm-log-userspace.h
include/uapi/linux/fuse.h
include/uapi/linux/jffs2.h
include/uapi/linux/pps.h
include/uapi/linux/rds.h
include/uapi/linux/sctp.h

That's not really lots.

Quoted 11 lines

so there
doesn't seem to be a reason they couldn't be used in virtio. fuse.h even has a:

    #ifdef __KERNEL__
    #include <linux/types.h>
    #else
    #include <stdint.h>
    #endif

Which seems like a reasonable thing to do.

In kernel, we really want to use things like endian-ness checks (and, we really should have them in userspace too!). So we want __le32 and other kernel goodies
like that. stdint.h won't cut it.

Quoted 3 lines

The only other kernel dependency is linux/if_ether.h to define ETH_ALEN. But it seems completely reasonable to define a VIRTIO_NET_MAC_ALEN or something like that.

Ugh. Not really reasonable IMO. We also use ETH_P_IP in code, would like to get rid of redefining that too.
But we can have our own linux/if_ether.h for non-linux hosts, just with a
couple of macros like that, it's not a big deal.

Quoted 12 lines

This would make the virtio headers completely stand alone and includable in userspace (without violating C99).

Perhaps it's even worth moving the headers from uapi/linux to uapi/virtio. Rusty, what do you think?

Regards,

Anhtony Liguori

Quoted 2 lines

Paolo

#23 lore raw
Quoted 40 lines · Michael S. Tsirkin
Quoted 9 lines · Anthony Liguori
Quoted 4 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 3 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

What I'm saying is - a chance of a conflict is very remote, if it happens it's a build failure so easy to debug.

I'm sure that others will complain, :) but you can go ahead.

I think we should clean up the virtio headers in the kernel first. Seems like a good thing to do given the standardization effort too. There are lots of headers in uapi that use the C99 int types

I found 4:

$ grep -l uint include/uapi/linux/*h
include/uapi/linux/dm-log-userspace.h
include/uapi/linux/fuse.h
include/uapi/linux/jffs2.h
include/uapi/linux/pps.h
include/uapi/linux/rds.h
include/uapi/linux/sctp.h

That's not really lots.

Quoted 10 lines

so there
doesn't seem to be a reason they couldn't be used in virtio. fuse.h even has a:

    #ifdef __KERNEL__
    #include <linux/types.h>
    #else
    #include <stdint.h>
    #endif
Quoted 6 lines
Quoted 1 line

Which seems like a reasonable thing to do.

In kernel, we really want to use things like endian-ness checks (and, we really should have them in userspace too!). So we want __le32 and other kernel goodies
like that. stdint.h won't cut it.

With the spec being standardized, I think having a stand alone set of headers is a good thing. Licensing is problematic here too.

If virtio headers depend on other Linux headers, then it really doesn't matter if they are BSD licensed if you need a GPL header (like linux/if_ether.h).

Now, we can certainly debate the copyrightability of these defines and what have you but if the headers are meant to be 1) consumed outside the kernel 2) licensed under a different license than the general kernel then depending on kernel goodies is the wrong strategy.

Quoted 9 lines
Quoted 3 lines

The only other kernel dependency is linux/if_ether.h to define ETH_ALEN. But it seems completely reasonable to define a VIRTIO_NET_MAC_ALEN or something like that.

Ugh. Not really reasonable IMO. We also use ETH_P_IP in code, would like to get rid of redefining that too.
But we can have our own linux/if_ether.h for non-linux hosts, just with a
couple of macros like that, it's not a big deal.

See above.

Regards,

Anthony Liguori

Quoted 13 lines
Quoted 13 lines

This would make the virtio headers completely stand alone and includable in userspace (without violating C99).

Perhaps it's even worth moving the headers from uapi/linux to uapi/virtio. Rusty, what do you think?

Regards,

Anhtony Liguori

Quoted 2 lines

Paolo

author maintainer
#24 lore raw
Quoted 44 lines · Anthony Liguori
Quoted 42 lines · Michael S. Tsirkin
Quoted 9 lines · Anthony Liguori
Quoted 4 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 3 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

What I'm saying is - a chance of a conflict is very remote, if it happens it's a build failure so easy to debug.

I'm sure that others will complain, :) but you can go ahead.

I think we should clean up the virtio headers in the kernel first. Seems like a good thing to do given the standardization effort too. There are lots of headers in uapi that use the C99 int types

I found 4:

$ grep -l uint include/uapi/linux/*h
include/uapi/linux/dm-log-userspace.h
include/uapi/linux/fuse.h
include/uapi/linux/jffs2.h
include/uapi/linux/pps.h
include/uapi/linux/rds.h
include/uapi/linux/sctp.h

That's not really lots.

Quoted 11 lines

so there
doesn't seem to be a reason they couldn't be used in virtio. fuse.h even has a:

    #ifdef __KERNEL__
    #include <linux/types.h>
    #else
    #include <stdint.h>
    #endif

Which seems like a reasonable thing to do.

Quoted 7 lines
Quoted 4 lines

In kernel, we really want to use things like endian-ness checks (and, we really should have them in userspace too!). So we want __le32 and other kernel goodies
like that. stdint.h won't cut it.

With the spec being standardized, I think having a stand alone set of headers is a good thing.

Sure, that's possible. We'll have to find some way to preserve the endian-ness annotations, I think.
And then import them into kernel/qemu with some script, converting to kernel/qemu style and annotations?

Quoted 10 lines

Licensing is problematic here too.

If virtio headers depend on other Linux headers, then it really doesn't matter if they are BSD licensed if you need a GPL header (like linux/if_ether.h).

Now, we can certainly debate the copyrightability of these defines and what have you but if the headers are meant to be 1) consumed outside the kernel 2) licensed under a different license than the general kernel then depending on kernel goodies is the wrong strategy.

Well specifically if_ether.h says GPLv2+ so it's OK for QEMU. Do you mean for some other non GPL app?

Quoted 29 lines
Quoted 9 lines
Quoted 3 lines

The only other kernel dependency is linux/if_ether.h to define ETH_ALEN. But it seems completely reasonable to define a VIRTIO_NET_MAC_ALEN or something like that.

Ugh. Not really reasonable IMO. We also use ETH_P_IP in code, would like to get rid of redefining that too.
But we can have our own linux/if_ether.h for non-linux hosts, just with a
couple of macros like that, it's not a big deal.

See above.

Regards,

Anthony Liguori

Quoted 13 lines
Quoted 13 lines

This would make the virtio headers completely stand alone and includable in userspace (without violating C99).

Perhaps it's even worth moving the headers from uapi/linux to uapi/virtio. Rusty, what do you think?

Regards,

Anhtony Liguori

Quoted 2 lines

Paolo

#25 lore raw
Quoted 50 lines · Michael S. Tsirkin
Quoted 49 lines · Anthony Liguori
Quoted 46 lines · Michael S. Tsirkin
Quoted 9 lines · Anthony Liguori
Quoted 4 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 3 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

What I'm saying is - a chance of a conflict is very remote, if it happens it's a build failure so easy to debug.

I'm sure that others will complain, :) but you can go ahead.

I think we should clean up the virtio headers in the kernel first. Seems like a good thing to do given the standardization effort too. There are lots of headers in uapi that use the C99 int types

I found 4:

$ grep -l uint include/uapi/linux/*h
include/uapi/linux/dm-log-userspace.h
include/uapi/linux/fuse.h
include/uapi/linux/jffs2.h
include/uapi/linux/pps.h
include/uapi/linux/rds.h
include/uapi/linux/sctp.h

That's not really lots.

Quoted 11 lines

so there
doesn't seem to be a reason they couldn't be used in virtio. fuse.h even has a:

    #ifdef __KERNEL__
    #include <linux/types.h>
    #else
    #include <stdint.h>
    #endif

Which seems like a reasonable thing to do.

In kernel, we really want to use things like endian-ness checks (and, we really should have them in userspace too!). So we want __le32 and other kernel goodies
like that. stdint.h won't cut it.

Quoted 7 lines
Quoted 2 lines

With the spec being standardized, I think having a stand alone set of headers is a good thing.

Sure, that's possible. We'll have to find some way to preserve the endian-ness annotations, I think.
And then import them into kernel/qemu with some script, converting to kernel/qemu style and annotations?

See below.

Quoted 6 lines
Quoted 6 lines

Licensing is problematic here too.

If virtio headers depend on other Linux headers, then it really doesn't matter if they are BSD licensed if you need a GPL header (like linux/if_ether.h).

Quoted 7 lines
Quoted 4 lines

Now, we can certainly debate the copyrightability of these defines and what have you but if the headers are meant to be 1) consumed outside the kernel 2) licensed under a different license than the general kernel then depending on kernel goodies is the wrong strategy.

Well specifically if_ether.h says GPLv2+ so it's OK for QEMU. Do you mean for some other non GPL app?

Ignore QEMU for the moment.

The headers say they are BSD licensed... but they include a GPLv2+ header. Doesn't make a lot of sense, does it?

Again, I think it's something pretty basic here. Either (1) these are kernel/userspace headers that are meant to be consumed through libc or whatever (2) these are kernel-private headers not to be consumed outside of the kernel (3) these are headers meant to be copied widely and used as a reference implementation of virtio.

If (1) or (2), copying them into QEMU via a magic sanitizing script is wrong. We should just keep doing what we're doing.

If (3), then we should clean up the virtio headers to be license clean and usable outside of the kernel. We shouldn't try to solve this problem in QEMU (via scripts) if we can just solve it in the kernel.

Regards,

Anthony Liguori

Quoted 30 lines
Quoted 30 lines
Quoted 10 lines
Quoted 4 lines

The only other kernel dependency is linux/if_ether.h to define ETH_ALEN. But it seems completely reasonable to define a VIRTIO_NET_MAC_ALEN or something like that.

Ugh. Not really reasonable IMO. We also use ETH_P_IP in code, would like to get rid of redefining that too.
But we can have our own linux/if_ether.h for non-linux hosts, just with a
couple of macros like that, it's not a big deal.

See above.

Regards,

Anthony Liguori

Quoted 13 lines
Quoted 13 lines

This would make the virtio headers completely stand alone and includable in userspace (without violating C99).

Perhaps it's even worth moving the headers from uapi/linux to uapi/virtio. Rusty, what do you think?

Regards,

Anhtony Liguori

Quoted 2 lines

Paolo

author maintainer
#26 lore raw
Quoted 7 lines · Anthony Liguori
Quoted 2 lines

Well specifically if_ether.h says GPLv2+ so it's OK for QEMU. Do you mean for some other non GPL app?

Ignore QEMU for the moment.

The headers say they are BSD licensed... but they include a GPLv2+ header.

Above is a bit misleading. To be precise, they don't include a GPLv2+ header. One header merely includes this line:
#include <linux/if_ether.h>

Signature · 1 line
MST
#27 lore raw
In reply to Anthony Liguori
Quoted 2 lines · Anthony Liguori

The headers say they are BSD licensed... but they include a GPLv2+ header. Doesn't make a lot of sense, does it?

It makes perfect sense: you're overthinking it. It just means that copying the BSD headers outside Linux is encouraged.

And it's clearly nonsensical to claim the GPL on kernel headers means that userspace needs to be GPL. So please ignore this licensing red-herring.

And we'll bikeshed the headers in the standard when we have to :) They certainly don't need to be cut&paste into the kernel sources.

Cheers,
Rusty.

#28 lore raw
Quoted 6 lines · Rusty Russell
Quoted 2 lines · Anthony Liguori

The headers say they are BSD licensed... but they include a GPLv2+ header. Doesn't make a lot of sense, does it?

It makes perfect sense: you're overthinking it. It just means that copying the BSD headers outside Linux is encouraged.

Copying by hand and modifying. This patch series attempts to do it automatically within QEMU.

Quoted 3 lines

And it's clearly nonsensical to claim the GPL on kernel headers means that userspace needs to be GPL. So please ignore this licensing red-herring.

You're missing context, I suspect. This series is trying to automatically copy the headers from Linux. We currently have a manually copied version.

The headers are not currently well suited for automatic copying because
(1) they use kernel types (2) they pull in dependencies from throughout the kernel.

This discussion comes down to whether we want to make it easier to automatically copy the headers or do we maintain the status quo and require manual munging to pull in the headers.

Regards,

Anthony Liguori

Quoted 6 lines

And we'll bikeshed the headers in the standard when we have to :) They certainly don't need to be cut&paste into the kernel sources.

Cheers,
Rusty.

author maintainer
#29 lore raw
Quoted 24 lines · Anthony Liguori
Quoted 6 lines · Rusty Russell
Quoted 2 lines · Anthony Liguori

The headers say they are BSD licensed... but they include a GPLv2+ header. Doesn't make a lot of sense, does it?

It makes perfect sense: you're overthinking it. It just means that copying the BSD headers outside Linux is encouraged.

Copying by hand and modifying. This patch series attempts to do it automatically within QEMU.

Quoted 3 lines

And it's clearly nonsensical to claim the GPL on kernel headers means that userspace needs to be GPL. So please ignore this licensing red-herring.

You're missing context, I suspect. This series is trying to automatically copy the headers from Linux. We currently have a manually copied version.

The headers are not currently well suited for automatic copying because
(1) they use kernel types (2) they pull in dependencies from throughout the kernel.

Quoted 7 lines

This discussion comes down to whether we want to make it easier to automatically copy the headers or do we maintain the status quo and require manual munging to pull in the headers.

Regards,

Anthony Liguori

Okay, what if I

1. add a stub if_ether.h with a couple of macros we want
2. replace the types during copying

Would this address all concerns?

Quoted 6 lines
Quoted 6 lines

And we'll bikeshed the headers in the standard when we have to :) They certainly don't need to be cut&paste into the kernel sources.

Cheers,
Rusty.

#30 lore raw
Quoted 31 lines · Michael S. Tsirkin
Quoted 30 lines · Anthony Liguori
Quoted 6 lines · Rusty Russell
Quoted 2 lines · Anthony Liguori

The headers say they are BSD licensed... but they include a GPLv2+ header. Doesn't make a lot of sense, does it?

It makes perfect sense: you're overthinking it. It just means that copying the BSD headers outside Linux is encouraged.

Copying by hand and modifying. This patch series attempts to do it automatically within QEMU.

Quoted 3 lines

And it's clearly nonsensical to claim the GPL on kernel headers means that userspace needs to be GPL. So please ignore this licensing red-herring.

You're missing context, I suspect. This series is trying to automatically copy the headers from Linux. We currently have a manually copied version.

The headers are not currently well suited for automatic copying because
(1) they use kernel types (2) they pull in dependencies from throughout the kernel.

This discussion comes down to whether we want to make it easier to automatically copy the headers or do we maintain the status quo and require manual munging to pull in the headers.

Regards,

Quoted 8 lines
Quoted 1 line

Anthony Liguori

Okay, what if I

1. add a stub if_ether.h with a couple of macros we want
2. replace the types during copying

Would this address all concerns?

If Rusty doesn't like the idea of making the headers usable directly, then I don't object to having stubs/scripts to sanitize them in QEMU.

Regards,

Anthony Liguori

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

And we'll bikeshed the headers in the standard when we have to :) They certainly don't need to be cut&paste into the kernel sources.

Cheers,
Rusty.

#31 lore raw
In reply to Anthony Liguori
Quoted 8 lines · Anthony Liguori
Quoted 4 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 3 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Personally, I find it hard to care. What matters is not what the standard has carved out, but whether we have clashes, reserved namespace or no. And that won't happen for these.

If someone wants to convert all the kernel headers, I won't NAK it though.

Quoted 2 lines

Perhaps it's even worth moving the headers from uapi/linux to uapi/virtio. Rusty, what do you think?

Hmm, #include <virtio/virtio_net.h> etc would be worthwhile if that also worked on FreeBSD. Bryan CC'd...

Cheers,
Rusty.

#32 lore raw
Quoted 8 lines · Rusty Russell
Quoted 7 lines · Anthony Liguori
Quoted 4 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 3 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted.

Quoted 8 lines
Quoted 1 line

Which is a problem because this is a reserved namespace in C99.

Personally, I find it hard to care. What matters is not what the standard has carved out, but whether we have clashes, reserved namespace or no. And that won't happen for these.

If someone wants to convert all the kernel headers, I won't NAK it though.

virtio headers are special. Linux headers are normally only consumed in the kernel or in a userspace application running on Linux.

virtio headers may be used either in a userspace application running on !Linux (we need to support QEMU on Windows) or even in a foreign kernel.

linux/types.h is unusable outside of Linux because it pulls in a bunch of other headers. If you look at Michael's patch, he adds his own version of types.h. It's unfortunate for every user of the headers to do this.

Regards,

Anthony Liguori

Quoted 8 lines
Quoted 2 lines

Perhaps it's even worth moving the headers from uapi/linux to uapi/virtio. Rusty, what do you think?

Hmm, #include <virtio/virtio_net.h> etc would be worthwhile if that also worked on FreeBSD. Bryan CC'd...

Cheers,
Rusty.

#33 lore raw
Quoted 16 lines · Anthony Liguori
Quoted 14 lines · Rusty Russell
Quoted 8 lines · Anthony Liguori
Quoted 4 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 3 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Personally, I find it hard to care. What matters is not what the standard has carved out, but whether we have clashes, reserved namespace or no. And that won't happen for these.

Quoted 8 lines
Quoted 2 lines

If someone wants to convert all the kernel headers, I won't NAK it though.

virtio headers are special. Linux headers are normally only consumed in the kernel or in a userspace application running on Linux.

virtio headers may be used either in a userspace application running on !Linux (we need to support QEMU on Windows) or even in a foreign kernel.

No.

s/virtio/SCSI/. s/virtio/if_eth/. s/virtio/TCPIP/.

Cheers,
Rusty.

#34 lore raw
In reply to Anthony Liguori
Quoted 16 lines · Anthony Liguori
Quoted 14 lines · Rusty Russell
Quoted 8 lines · Anthony Liguori
Quoted 4 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 3 lines
Quoted 1 line

My fault. I should have looked at linux/types.h (actually asm-generic/).

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Personally, I find it hard to care. What matters is not what the standard has carved out, but whether we have clashes, reserved namespace or no. And that won't happen for these.

Quoted 8 lines
Quoted 2 lines

If someone wants to convert all the kernel headers, I won't NAK it though.

virtio headers are special. Linux headers are normally only consumed in the kernel or in a userspace application running on Linux.

virtio headers may be used either in a userspace application running on !Linux (we need to support QEMU on Windows) or even in a foreign kernel.

No.

s/virtio/SCSI/. s/virtio/if_eth/. s/virtio/TCPIP/.

Cheers,
Rusty.

#35 lore raw
In reply to Rusty Russell
Quoted 15 lines · Rusty Russell
Quoted 4 lines · Anthony Liguori
Quoted 2 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 1 line
Quoted 1 line

My fault. I should have looked at linux/types.h (actually

asm-generic/).

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Personally, I find it hard to care. What matters is not what the standard has carved out, but whether we have clashes, reserved namespace or no. And that won't happen for these.

Quoted 10 lines

If someone wants to convert all the kernel headers, I won't NAK it though.

Quoted 2 lines

Perhaps it's even worth moving the headers from uapi/linux to uapi/virtio. Rusty, what do you think?

Hmm, #include <virtio/virtio_net.h> etc would be worthwhile if that also worked on FreeBSD. Bryan CC'd...

I've only done minor work on the VirtIO headers when importing them to FreeBSD - mostly converting the _XX types to the preferred C99 variants, along with some misc nits. I'm not too concerned with keeping the headers identical to what is in Linux; I manually merge in required changes when supporting a new feature and this hasn't been an issue. I'm content as long as they remain BSD licensed. Growing GPL'ed #includes is a bit worrisome, but I have a hard time foreseeing what the VirtIO files could possibly depend on that isn't trivial.

I don't think I have enough context to understand the ' #include <virtio/virtio_net.h> etc' suggestion ... In FreeBSD, the VirtIO headers files exist only in the source tree along side the corresponding device, ie. sys/dev/virtio/network/virtio_net.h, sys/dev/virtio/pci/virtio_pci.h, etc. The FreeBSD hypervisor (bhyve) just duplicates the needed definitions/defines. This will be fixed at some point, but bhyve's VirtIO is so barebones there is bigger fish to fry.

Quoted 3 lines

Cheers,
Rusty.

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#36 lore raw
In reply to Rusty Russell
Quoted 15 lines · Rusty Russell
Quoted 4 lines · Anthony Liguori
Quoted 2 lines · Paolo Bonzini

Il 26/05/2013 22:02, Michael S. Tsirkin ha scritto:

Quoted 1 line
Quoted 1 line

My fault. I should have looked at linux/types.h (actually

asm-generic/).

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

Not really, __uX appear in the headers that were posted.

Which is a problem because this is a reserved namespace in C99.

Personally, I find it hard to care. What matters is not what the standard has carved out, but whether we have clashes, reserved namespace or no. And that won't happen for these.

Quoted 10 lines

If someone wants to convert all the kernel headers, I won't NAK it though.

Quoted 2 lines

Perhaps it's even worth moving the headers from uapi/linux to uapi/virtio. Rusty, what do you think?

Hmm, #include <virtio/virtio_net.h> etc would be worthwhile if that also worked on FreeBSD. Bryan CC'd...

I've only done minor work on the VirtIO headers when importing them to FreeBSD - mostly converting the _XX types to the preferred C99 variants, along with some misc nits. I'm not too concerned with keeping the headers identical to what is in Linux; I manually merge in required changes when supporting a new feature and this hasn't been an issue. I'm content as long as they remain BSD licensed. Growing GPL'ed #includes is a bit worrisome, but I have a hard time foreseeing what the VirtIO files could possibly depend on that isn't trivial.

I don't think I have enough context to understand the ' #include <virtio/virtio_net.h> etc' suggestion ... In FreeBSD, the VirtIO headers files exist only in the source tree along side the corresponding device, ie. sys/dev/virtio/network/virtio_net.h, sys/dev/virtio/pci/virtio_pci.h, etc. The FreeBSD hypervisor (bhyve) just duplicates the needed definitions/defines. This will be fixed at some point, but bhyve's VirtIO is so barebones there is bigger fish to fry.

Quoted 3 lines

Cheers,
Rusty.

#37 lore raw
In reply to Michael S. Tsirkin
Quoted 4 lines · Michael S. Tsirkin

Ouch. Forgot to git-add them. Thanks.

I'll send a fixed version -
could you please try this patch on top?

With this extra patch MacOSX compiles.

thanks
-- PMM