Skip to contentSkip to conversation

Input 20190522 patches

GIT PULL Applied Gerd Hoffmann 3 participants 7 messages May 22, 2019 – Jun 5, 2019 Kbuild

lore
Share & tools
lore
#1 lore raw

[Qemu-devel] [PULL 2/3] libvhost-user: fix -Werror=format= on ppc64

In reply to Gerd Hoffmann

From: Marc-André Lureau <[email protected]>

That should fix the following warning:

/home/pm215/qemu/contrib/libvhost-user/libvhost-user.c: In function ‘vu_set_mem_table_exec_postcopy’:
/home/pm215/qemu/contrib/libvhost-user/libvhost-user.c:666:9: error:
format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 5 has type ‘__u64’ [-Werror=format=]
DPRINT("%s: region %d: Registered userfault for %llx + %llx\n", ^
/home/pm215/qemu/contrib/libvhost-user/libvhost-user.c:666:9: error:
format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 6 has type ‘__u64’ [-Werror=format=]
cc1: all warnings being treated as errors

Message-id: [email protected]

{ kraxel: s/PRIu64/PRIx64/ ]

---
 contrib/libvhost-user/libvhost-user.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
contrib/libvhost-user/libvhost-user.c +4 -2
index 0ffa0f45c890..c56f2dfe44a4 100644
@@ -663,8 +663,10 @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg)
                      __func__, i);
             return false;
         }
-        DPRINT("%s: region %d: Registered userfault for %llx + %llx\n",
-                __func__, i, reg_struct.range.start, reg_struct.range.len);
+        DPRINT("%s: region %d: Registered userfault for %"
+               PRIx64 " + %" PRIx64 "\n", __func__, i,
+               (uint64_t)reg_struct.range.start,
+               (uint64_t)reg_struct.range.len);
         /* Now it's registered we can let the client at it */
         if (mprotect((void *)(uintptr_t)dev_region->mmap_addr,
                      dev_region->size + dev_region->mmap_offset,
Signature · 1 line
2.18.1
#2 lore raw

[Qemu-devel] [PULL 1/3] libvhost-user: fix cast warnings on 32 bits

In reply to Gerd Hoffmann

From: Marc-André Lureau <[email protected]>

Fixes warnings:
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Message-id: [email protected]

---
 contrib/libvhost-user/libvhost-user.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
contrib/libvhost-user/libvhost-user.c +3 -3
index 3825b1cacff5..0ffa0f45c890 100644
@@ -621,7 +621,7 @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg)
          * data that's already arrived in the shared process.
          * TODO: How to do hugepage
          */
-        ret = madvise((void *)dev_region->mmap_addr,
+        ret = madvise((void *)(uintptr_t)dev_region->mmap_addr,
                       dev_region->size + dev_region->mmap_offset,
                       MADV_DONTNEED);
         if (ret) {
@@ -633,7 +633,7 @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg)
          * in neighbouring pages.
          * TODO: Turn this backon later.
          */
-        ret = madvise((void *)dev_region->mmap_addr,
+        ret = madvise((void *)(uintptr_t)dev_region->mmap_addr,
                       dev_region->size + dev_region->mmap_offset,
                       MADV_NOHUGEPAGE);
         if (ret) {
@@ -666,7 +666,7 @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg)
         DPRINT("%s: region %d: Registered userfault for %llx + %llx\n",
                 __func__, i, reg_struct.range.start, reg_struct.range.len);
         /* Now it's registered we can let the client at it */
-        if (mprotect((void *)dev_region->mmap_addr,
+        if (mprotect((void *)(uintptr_t)dev_region->mmap_addr,
                      dev_region->size + dev_region->mmap_offset,
                      PROT_READ | PROT_WRITE)) {
             vu_panic(dev, "failed to mprotect region %d for postcopy (%s)",
Signature · 1 line
2.18.1
#3 lore raw

[Qemu-devel] [PULL 3/3] contrib: add vhost-user-input

In reply to Gerd Hoffmann

From: Marc-André Lureau <[email protected]>

Add a vhost-user input backend example, based on virtio-input-host device. It takes an evdev path as argument, and can be associated with a vhost-user-input device via a UNIX socket:

$ vhost-user-input -p /dev/input/eventX -s /tmp/vui.sock
$ qemu ... -chardev socket,id=vuic,path=/tmp/vui.sock
  -device vhost-user-input-pci,chardev=vuic

This example is intentionally not included in $TOOLS, and not installed by default.

Message-id: [email protected]

---
 Makefile                               |  11 +
 Makefile.objs                          |   1 +
 contrib/vhost-user-input/main.c        | 393 +++++++++++++++++++++++++
 MAINTAINERS                            |   1 +
 contrib/vhost-user-input/Makefile.objs |   1 +
 5 files changed, 407 insertions(+)
 create mode 100644 contrib/vhost-user-input/main.c
 create mode 100644 contrib/vhost-user-input/Makefile.objs
Makefile +11 -0
index 155f066a206f..8598ab9ec482 100644
@@ -408,6 +408,7 @@ dummy := $(call unnest-vars,, \
                 libvhost-user-obj-y \
                 vhost-user-scsi-obj-y \
                 vhost-user-blk-obj-y \
+                vhost-user-input-obj-y \
                 qga-vss-dll-obj-y \
                 block-obj-y \
                 block-obj-m \
@@ -618,6 +619,16 @@ rdmacm-mux$(EXESUF): LIBS += "-libumad"
 rdmacm-mux$(EXESUF): $(rdmacm-mux-obj-y) $(COMMON_LDADDS)
 	$(call LINK, $^)
 
+ifdef CONFIG_VHOST_USER_INPUT
+ifdef CONFIG_LINUX
+vhost-user-input$(EXESUF): $(vhost-user-input-obj-y) libvhost-user.a libqemuutil.a
+	$(call LINK, $^)
+
+# build by default, do not install
+all: vhost-user-input$(EXESUF)
+endif
+endif
+
 module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak
 	$(call quiet-command,$(PYTHON) $< $@ \
 	$(addprefix $(SRC_PATH)/,$(patsubst %.mo,%.c,$(block-obj-m))), \
Makefile.objs +1 -0
index 2b0793ecc9ff..485f9624191a 100644
@@ -122,6 +122,7 @@ vhost-user-scsi.o-libs := $(LIBISCSI_LIBS)
 vhost-user-scsi-obj-y = contrib/vhost-user-scsi/
 vhost-user-blk-obj-y = contrib/vhost-user-blk/
 rdmacm-mux-obj-y = contrib/rdmacm-mux/
+vhost-user-input-obj-y = contrib/vhost-user-input/
 
 ######################################################################
 trace-events-subdirs =
contrib/vhost-user-input/main.c new file +393 -0

393 lines not on this page · raw message

MAINTAINERS +1 -0
index a6948ebc63bc..73a010508251 100644
@@ -1532,6 +1532,7 @@ S: Maintained
 F: hw/input/vhost-user-input.c
 F: hw/input/virtio-input*.c
 F: include/hw/virtio/virtio-input.h
+F: contrib/vhost-user-input/*
 
 virtio-serial
 M: Amit Shah <[email protected]>
contrib/vhost-user-input/Makefile.objs new file +1 -0
new file mode 100644
index 000000000000..b1fad90d51b6
@@ -0,0 +1 @@
+vhost-user-input-obj-y = main.o
Signature · 1 line
2.18.1
#0 lore raw

The following changes since commit a4f667b6714916683408b983cfe0a615a725775f:

Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20190521-3' into staging (2019-05-21 16:30:13 +0100)

are available in the Git repository at:

git://git.kraxel.org/qemu tags/input-20190522-pull-request

for you to fetch changes up to 06914c97d3ade856371c9a59cbe6a9b13422471f:

contrib: add vhost-user-input (2019-05-22 07:16:58 +0200)

----------------------------------------------------------------
input: add vhost-user-input to contrib.

----------------------------------------------------------------

Marc-André Lureau (3):
libvhost-user: fix cast warnings on 32 bits
libvhost-user: fix -Werror=format= on ppc64
contrib: add vhost-user-input

 Makefile                               |  11 +
 Makefile.objs                          |   1 +
 contrib/libvhost-user/libvhost-user.c  |  12 +-
 contrib/vhost-user-input/main.c        | 393 +++++++++++++++++++++++++
 MAINTAINERS                            |   1 +
 contrib/vhost-user-input/Makefile.objs |   1 +
 6 files changed, 414 insertions(+), 5 deletions(-)
 create mode 100644 contrib/vhost-user-input/main.c
 create mode 100644 contrib/vhost-user-input/Makefile.objs
Signature · 1 line
2.18.1
#6 lore raw
Quoted 9 lines · Gerd Hoffmann

The following changes since commit a4f667b6714916683408b983cfe0a615a725775f:

Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20190521-3' into staging (2019-05-21 16:30:13 +0100)

are available in the Git repository at:

git://git.kraxel.org/qemu tags/input-20190522-pull-request

Quoted 8 lines

for you to fetch changes up to 06914c97d3ade856371c9a59cbe6a9b13422471f:

contrib: add vhost-user-input (2019-05-22 07:16:58 +0200)

----------------------------------------------------------------
input: add vhost-user-input to contrib.

----------------------------------------------------------------

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.1
for any user-visible changes.

-- PMM

#4 lore raw

Re: [Qemu-devel] [PULL 3/3] contrib: add vhost-user-input

In reply to Gerd Hoffmann
Quoted 12 lines · Gerd Hoffmann

From: Marc-André Lureau <[email protected]>

Add a vhost-user input backend example, based on virtio-input-host device. It takes an evdev path as argument, and can be associated with a vhost-user-input device via a UNIX socket:

$ vhost-user-input -p /dev/input/eventX -s /tmp/vui.sock
$ qemu ... -chardev socket,id=vuic,path=/tmp/vui.sock
  -device vhost-user-input-pci,chardev=vuic
Quoted 6 lines

This example is intentionally not included in $TOOLS, and not installed by default.

Message-id: [email protected]

Hi; Coverity spotted a problem with this patch:

Quoted 49 lines
contrib/vhost-user-input/main.c new file +49 -0
+int
+main(int argc, char *argv[])
+{
+    GMainLoop *loop = NULL;
+    VuInput vi = { 0, };
+    int rc, ver, fd;
+    virtio_input_config id;
+    struct input_id ids;
+    GError *error = NULL;
+    GOptionContext *context;
+
+    context = g_option_context_new(NULL);
+    g_option_context_add_main_entries(context, entries, NULL);
+    if (!g_option_context_parse(context, &argc, &argv, &error)) {
+        g_printerr("Option parsing failed: %s\n", error->message);
+        exit(EXIT_FAILURE);
+    }
+    if (opt_print_caps) {
+        g_print("{\n");
+        g_print("  \"type\": \"input\",\n");
+        g_print("  \"features\": [\n");
+        g_print("    \"evdev-path\",\n");
+        g_print("    \"no-grab\"\n");
+        g_print("  ]\n");
+        g_print("}\n");
+        exit(EXIT_SUCCESS);
+    }
+    if (!opt_evdev) {
+        g_printerr("Please specify an evdev path\n");
+        exit(EXIT_FAILURE);
+    }
+    if ((!!opt_socket_path + (opt_fdnum != -1)) != 1) {
+        g_printerr("Please specify either --fd or --socket-path\n");
+        exit(EXIT_FAILURE);
+    }
+
+    vi.evdevfd = open(opt_evdev, O_RDWR);
+    if (vi.evdevfd < 0) {
+        g_printerr("Failed to open evdev: %s\n", g_strerror(errno));
+        exit(EXIT_FAILURE);
+    }
+
+    rc = ioctl(vi.evdevfd, EVIOCGVERSION, &ver);
+    if (rc < 0) {
+        g_printerr("%s: is not an evdev device\n", argv[1]);
+        exit(EXIT_FAILURE);
+    }
+
+    if (!opt_nograb) {

contrib/vhost-user-input/main.c line 345

Quoted 10 lines
contrib/vhost-user-input/main.c new file +10 -0
+        rc = ioctl(vi.evdevfd, EVIOCGRAB, 1);
+        if (rc < 0) {
+            g_printerr("Failed to grab device\n");
+            exit(EXIT_FAILURE);
+        }
+    }
+
+    vi.config = g_array_new(false, false, sizeof(virtio_input_config));
+    memset(&id, 0, sizeof(id));
+    ioctl(vi.evdevfd, EVIOCGNAME(sizeof(id.u.string) - 1), id.u.string);

CID 1401704 -- we don't check the return value from ioctl().

Quoted 16 lines
contrib/vhost-user-input/main.c new file +16 -0
+    id.select = VIRTIO_INPUT_CFG_ID_NAME;
+    id.size = strlen(id.u.string);
+    g_array_append_val(vi.config, id);
+
+    if (ioctl(vi.evdevfd, EVIOCGID, &ids) == 0) {
+        memset(&id, 0, sizeof(id));
+        id.select = VIRTIO_INPUT_CFG_ID_DEVIDS;
+        id.size = sizeof(struct virtio_input_devids);
+        id.u.ids.bustype = cpu_to_le16(ids.bustype);
+        id.u.ids.vendor  = cpu_to_le16(ids.vendor);
+        id.u.ids.product = cpu_to_le16(ids.product);
+        id.u.ids.version = cpu_to_le16(ids.version);
+        g_array_append_val(vi.config, id);
+    }
+
+    vi_bits_config(&vi, EV_KEY, KEY_CNT);

contrib/vhost-user-input/main.c line 371

Quoted 10 lines
contrib/vhost-user-input/main.c new file +10 -0
+    vi_bits_config(&vi, EV_REL, REL_CNT);
+    vi_bits_config(&vi, EV_ABS, ABS_CNT);
+    vi_bits_config(&vi, EV_MSC, MSC_CNT);
+    vi_bits_config(&vi, EV_SW,  SW_CNT);
+    g_debug("config length: %u", vi.config->len);
+
+    if (opt_socket_path) {
+        int lsock = unix_listen(opt_socket_path, &error_fatal);
+        fd = accept(lsock, NULL, NULL);
+        close(lsock);

This is CID 1401705 -- failure to check return value from unix_listen() -- which I just realised I probably replied to the wrong version of the patch to point out, so I mention it again here.

contrib/vhost-user-input/main.c line 374

Quoted 3 lines
contrib/vhost-user-input/main.c new file +3 -0
+    } else {
+        fd = opt_fdnum;
+    }

thanks
-- PMM

#5 lore raw

Re: [Qemu-devel] [PULL 3/3] contrib: add vhost-user-input

Hi

Quoted 76 lines · Peter Maydell
Quoted 12 lines · Gerd Hoffmann

From: Marc-André Lureau <[email protected]>

Add a vhost-user input backend example, based on virtio-input-host device. It takes an evdev path as argument, and can be associated with a vhost-user-input device via a UNIX socket:

$ vhost-user-input -p /dev/input/eventX -s /tmp/vui.sock
$ qemu ... -chardev socket,id=vuic,path=/tmp/vui.sock
  -device vhost-user-input-pci,chardev=vuic
Quoted 6 lines

This example is intentionally not included in $TOOLS, and not installed by default.

Message-id: [email protected]

Hi; Coverity spotted a problem with this patch:

Quoted 53 lines
contrib/vhost-user-input/main.c new file +53 -0
+int
+main(int argc, char *argv[])
+{
+    GMainLoop *loop = NULL;
+    VuInput vi = { 0, };
+    int rc, ver, fd;
+    virtio_input_config id;
+    struct input_id ids;
+    GError *error = NULL;
+    GOptionContext *context;
+
+    context = g_option_context_new(NULL);
+    g_option_context_add_main_entries(context, entries, NULL);
+    if (!g_option_context_parse(context, &argc, &argv, &error)) {
+        g_printerr("Option parsing failed: %s\n", error->message);
+        exit(EXIT_FAILURE);
+    }
+    if (opt_print_caps) {
+        g_print("{\n");
+        g_print("  \"type\": \"input\",\n");
+        g_print("  \"features\": [\n");
+        g_print("    \"evdev-path\",\n");
+        g_print("    \"no-grab\"\n");
+        g_print("  ]\n");
+        g_print("}\n");
+        exit(EXIT_SUCCESS);
+    }
+    if (!opt_evdev) {
+        g_printerr("Please specify an evdev path\n");
+        exit(EXIT_FAILURE);
+    }
+    if ((!!opt_socket_path + (opt_fdnum != -1)) != 1) {
+        g_printerr("Please specify either --fd or --socket-path\n");
+        exit(EXIT_FAILURE);
+    }
+
+    vi.evdevfd = open(opt_evdev, O_RDWR);
+    if (vi.evdevfd < 0) {
+        g_printerr("Failed to open evdev: %s\n", g_strerror(errno));
+        exit(EXIT_FAILURE);
+    }
+
+    rc = ioctl(vi.evdevfd, EVIOCGVERSION, &ver);
+    if (rc < 0) {
+        g_printerr("%s: is not an evdev device\n", argv[1]);
+        exit(EXIT_FAILURE);
+    }
+
+    if (!opt_nograb) {
+        rc = ioctl(vi.evdevfd, EVIOCGRAB, 1);
+        if (rc < 0) {
+            g_printerr("Failed to grab device\n");
+            exit(EXIT_FAILURE);
Quoted 8 lines

contrib/vhost-user-input/main.c line 345

Quoted 6 lines
contrib/vhost-user-input/main.c new file +6 -0
+        }
+    }
+
+    vi.config = g_array_new(false, false, sizeof(virtio_input_config));
+    memset(&id, 0, sizeof(id));
+    ioctl(vi.evdevfd, EVIOCGNAME(sizeof(id.u.string) - 1), id.u.string);

CID 1401704 -- we don't check the return value from ioctl().

ok, I'll send a fix

Quoted 24 lines
Quoted 24 lines
contrib/vhost-user-input/main.c new file +23 -0
+    id.select = VIRTIO_INPUT_CFG_ID_NAME;
+    id.size = strlen(id.u.string);
+    g_array_append_val(vi.config, id);
+
+    if (ioctl(vi.evdevfd, EVIOCGID, &ids) == 0) {
+        memset(&id, 0, sizeof(id));
+        id.select = VIRTIO_INPUT_CFG_ID_DEVIDS;
+        id.size = sizeof(struct virtio_input_devids);
+        id.u.ids.bustype = cpu_to_le16(ids.bustype);
+        id.u.ids.vendor  = cpu_to_le16(ids.vendor);
+        id.u.ids.product = cpu_to_le16(ids.product);
+        id.u.ids.version = cpu_to_le16(ids.version);
+        g_array_append_val(vi.config, id);
+    }
+
+    vi_bits_config(&vi, EV_KEY, KEY_CNT);
+    vi_bits_config(&vi, EV_REL, REL_CNT);
+    vi_bits_config(&vi, EV_ABS, ABS_CNT);
+    vi_bits_config(&vi, EV_MSC, MSC_CNT);
+    vi_bits_config(&vi, EV_SW,  SW_CNT);
+    g_debug("config length: %u", vi.config->len);
+
+    if (opt_socket_path) {
Quoted 8 lines

contrib/vhost-user-input/main.c line 371

Quoted 3 lines
contrib/vhost-user-input/main.c new file +3 -0
+        int lsock = unix_listen(opt_socket_path, &error_fatal);
+        fd = accept(lsock, NULL, NULL);
+        close(lsock);

This is CID 1401705 -- failure to check return value from unix_listen() -- which I just realised I probably replied to the wrong version of the patch to point out, so I mention it again here.

coverity should realize that passing &error_fatal will not return, no?

Can we mark this as false-positive?

Quoted 7 lines

contrib/vhost-user-input/main.c line 374

Quoted 4 lines
contrib/vhost-user-input/main.c new file +3 -0
+    } else {
+        fd = opt_fdnum;
+    }

thanks
-- PMM