From patchwork Thu Jan 4 21:09:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759880 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183755wrw; Thu, 4 Jan 2024 13:12:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHj3XuyX1oZfZsDkYgkFWX5IFwFG+CtQR1OwBo/MRBH90ELiuaBce8GT+BvR74vxBHTHH6s X-Received: by 2002:a05:6214:23c9:b0:680:ce74:9367 with SMTP id hr9-20020a05621423c900b00680ce749367mr1072233qvb.51.1704402753196; Thu, 04 Jan 2024 13:12:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402753; cv=none; d=google.com; s=arc-20160816; b=gaTqH2XmIJsnuaWNcNQHl0vhI8/2qfW0HypEcbnZH+cwBauM3rAwKqDsfcoCKqkziz +EJAgniCuZYrZ/7nw8WoZaysRiMk+nbJEIKbpBtY7QBhi1PTi0bMyiWNxs/Sq+NHcEyQ axSe4J5fGATyoGNQ7gaclUtkqIOAWE3xHO96Luvi+fHNGi79pqxWrQM8rbB6T6SMaFff 33/Ma8yr5xfJ20YieU3MMrhrbkfdr9pyYK+l27QreKHCq4tozVGJsSgNT/FQlq9nHIIz oPOKVLX5nV2TM3LuUgnOH5VkMME9I8rw/faGjOgUd54HNEXa+5vVPLDopV/t8VZeZ32O 3bDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Y495qePK8I0MtWarRTJJHJBwMiwJ1dsE2SsAlZjc2kg=; fh=FJgCuuUiQlhQb75y4DqgTcYU/2dmCchdcJEae1kKAEw=; b=kXkPyQ5i7sefEdySVAFcC2yBOvBTO6teg6F/r/folwWkAhOFATOfrozy08HDawYTiu /N5x71NZ1rts9T49KimTCWCIXsNkohQvCDWvvB5q65SON0nUVc4TJCMiMjIKmeYm2OSE B2TdsdqjZB2jfvUs4Sk5XTB/WoNik7N5JAVKwi3xoBMr3n4Wsc8CUTLrebqUsbSaNFrX V9Z+bUtDoNNMvvhDmBB1jrSAUadnYec+tJLJrXw+IX2IJd4BqFTKyfUWzkaZTr5Cd9DA hgBEknAjuW8vNLm4Yo2EwXsIYf/tsaM+LmB9AhYlHqaKsVsv001AKZbplzGZxiKGLzf6 8cTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VxuEYMn4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h12-20020a05620a21cc00b00781cac2c402si292895qka.369.2024.01.04.13.12.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:12:33 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VxuEYMn4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUyP-0006vC-O3; Thu, 04 Jan 2024 16:09:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyN-0006tc-9b for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:51 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyK-0007RA-1g for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:51 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3373bc6d625so730578f8f.3 for ; Thu, 04 Jan 2024 13:09:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402586; x=1705007386; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y495qePK8I0MtWarRTJJHJBwMiwJ1dsE2SsAlZjc2kg=; b=VxuEYMn4lGcfZIEBtMaWZhy4bBvhalwIdvuax3GU4K8yeoZlxEofUME+lPwC6EfH6Z LFCRT3bS5UyZVErjH5uHZQTOzkC9jy7hK7TWkV/4tX9QWlMoB/9cJ8hSgXwkZBJ5L0a+ 7e593SbNX3HigyDqq/IG+i+cEFNgxGqy1pnsCl6Zy/C89x6A/wdJjKRUrRVhfxgpBiv9 WcoVsnmNU7SGgkgggpt6ol5eBts5YW71oSgduvuMVtYM1SC1fPGzSizyHwgtd3qPDDe7 0o2/zbHgy2ZZrjxhQcVfLwonFvG1dn4QFixBv9JgFcYJXvMx3xYyzuwpYj57dpjt3l7P REEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402586; x=1705007386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y495qePK8I0MtWarRTJJHJBwMiwJ1dsE2SsAlZjc2kg=; b=U5AyYFby8wmrqq8PC8g9qEYPKs46ARNYXcvh/kWshn2L7enKGwFe4PQqzrwBGPEOrZ e6CtDl6rgnBOrUvomHF87cjjjC30nGbq6NzswrXN43aBZpE49uvLZpW9cisuEKvXnBUn d/Ynv8a9iPrH5wQjAfHidJBHpkR9P9CwWMYijpmnCotngcHbrFPW3pL4w5fAcHycvrsf ZtXNTofMFoYs52JvhhDSvCMvdO77E/Xhh/sVYCP5KB5oODTcWLQRWPDs4trr70TtAUaN YZldwGIh+pMSh8EhWEcJIqsCipIHSvYnpC0sK40XooZqgT81cwMoQcK3qNJynJbFoSRP zfXg== X-Gm-Message-State: AOJu0YzuVlLlSZvYkscWR2B2nS6ZFPYWBf43ki94z84tHkGc/ZKYBo4v kgEWhmnr7amtCwctIydfRvQ5TC+qnRWcOg== X-Received: by 2002:adf:fc89:0:b0:337:5557:b716 with SMTP id g9-20020adffc89000000b003375557b716mr528903wrr.72.1704402586287; Thu, 04 Jan 2024 13:09:46 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id d1-20020adfa341000000b0033662fb321esm108634wrb.33.2024.01.04.13.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:45 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 303A85F932; Thu, 4 Jan 2024 21:09:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi Subject: [PATCH v9 01/11] virtio: split into vhost-user-base and vhost-user-device Date: Thu, 4 Jan 2024 21:09:35 +0000 Message-Id: <20240104210945.1223134-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Lets keep a cleaner split between the base class and the derived vhost-user-device which we can use for generic vhost-user stubs. This includes an update to introduce the vq_size property so the number of entries in a virtq can be defined. Signed-off-by: Alex Bennée --- v5 - s/parent/parent_obj/ - remove left over vhost-user-device.h - use DEFINE_TYPES v6 - rebase and set .abstract = true for vhost-user-device v7 - checkpatch line length + MAINTAINERS - s/abstract = true/dc->user_creatable = false/ for both mmio and pci --- MAINTAINERS | 6 + ...{vhost-user-device.h => vhost-user-base.h} | 21 +- hw/virtio/vhost-user-base.c | 346 ++++++++++++++++++ hw/virtio/vhost-user-device-pci.c | 13 +- hw/virtio/vhost-user-device.c | 338 +---------------- hw/virtio/meson.build | 1 + 6 files changed, 383 insertions(+), 342 deletions(-) rename include/hw/virtio/{vhost-user-device.h => vhost-user-base.h} (71%) create mode 100644 hw/virtio/vhost-user-base.c diff --git a/MAINTAINERS b/MAINTAINERS index 395f26ba861..0e832fd5d13 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2304,6 +2304,12 @@ F: include/sysemu/rng*.h F: backends/rng*.c F: tests/qtest/virtio-rng-test.c +vhost-user-stubs +M: Alex Bennée +S: Maintained +F: hw/virtio/vhost-user-base.c +F: hw/virtio/vhost-user-device* + vhost-user-rng M: Mathieu Poirier S: Supported diff --git a/include/hw/virtio/vhost-user-device.h b/include/hw/virtio/vhost-user-base.h similarity index 71% rename from include/hw/virtio/vhost-user-device.h rename to include/hw/virtio/vhost-user-base.h index 3ddf88a146a..51d0968b893 100644 --- a/include/hw/virtio/vhost-user-device.h +++ b/include/hw/virtio/vhost-user-base.h @@ -6,8 +6,8 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef QEMU_VHOST_USER_DEVICE_H -#define QEMU_VHOST_USER_DEVICE_H +#ifndef QEMU_VHOST_USER_BASE_H +#define QEMU_VHOST_USER_BASE_H #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" @@ -17,11 +17,13 @@ OBJECT_DECLARE_TYPE(VHostUserBase, VHostUserBaseClass, VHOST_USER_BASE) struct VHostUserBase { - VirtIODevice parent; + VirtIODevice parent_obj; + /* Properties */ CharBackend chardev; uint16_t virtio_id; uint32_t num_vqs; + uint32_t vq_size; /* can't exceed VIRTIO_QUEUE_MAX */ uint32_t config_size; /* State tracking */ VhostUserState vhost_user; @@ -31,16 +33,17 @@ struct VHostUserBase { bool connected; }; - /* needed so we can use the base realize after specialisation - tweaks */ +/* + * Needed so we can use the base realize after specialisation + * tweaks + */ struct VHostUserBaseClass { - /*< private >*/ VirtioDeviceClass parent_class; - /*< public >*/ + DeviceRealize parent_realize; }; -/* shared for the benefit of the derived pci class */ + #define TYPE_VHOST_USER_DEVICE "vhost-user-device" -#endif /* QEMU_VHOST_USER_DEVICE_H */ +#endif /* QEMU_VHOST_USER_BASE_H */ diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c new file mode 100644 index 00000000000..620fa5cb4a4 --- /dev/null +++ b/hw/virtio/vhost-user-base.c @@ -0,0 +1,346 @@ +/* + * Base vhost-user-base implementation. This can be used to derive a + * more fully specified vhost-user backend either generically (see + * vhost-user-device) or via a specific stub for a device which + * encapsulates some fixed parameters. + * + * Copyright (c) 2023 Linaro Ltd + * Author: Alex Bennée + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-base.h" +#include "qemu/error-report.h" + +static void vub_start(VirtIODevice *vdev) +{ + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + VHostUserBase *vub = VHOST_USER_BASE(vdev); + int ret, i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret = vhost_dev_enable_notifiers(&vub->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret = k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, true); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + vub->vhost_dev.acked_features = vdev->guest_features; + + ret = vhost_dev_start(&vub->vhost_dev, vdev, true); + if (ret < 0) { + error_report("Error starting vhost-user-base: %d", -ret); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i = 0; i < vub->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&vub->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&vub->vhost_dev, vdev); +} + +static void vub_stop(VirtIODevice *vdev) +{ + VHostUserBase *vub = VHOST_USER_BASE(vdev); + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&vub->vhost_dev, vdev, true); + + ret = k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&vub->vhost_dev, vdev); +} + +static void vub_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserBase *vub = VHOST_USER_BASE(vdev); + bool should_start = virtio_device_should_start(vdev, status); + + if (vhost_dev_is_started(&vub->vhost_dev) == should_start) { + return; + } + + if (should_start) { + vub_start(vdev); + } else { + vub_stop(vdev); + } +} + +/* + * For an implementation where everything is delegated to the backend + * we don't do anything other than return the full feature set offered + * by the daemon (module the reserved feature bit). + */ +static uint64_t vub_get_features(VirtIODevice *vdev, + uint64_t requested_features, Error **errp) +{ + VHostUserBase *vub = VHOST_USER_BASE(vdev); + /* This should be set when the vhost connection initialises */ + g_assert(vub->vhost_dev.features); + return vub->vhost_dev.features & ~(1ULL << VHOST_USER_F_PROTOCOL_FEATURES); +} + +/* + * To handle VirtIO config we need to know the size of the config + * space. We don't cache the config but re-fetch it from the guest + * every time in case something has changed. + */ +static void vub_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VHostUserBase *vub = VHOST_USER_BASE(vdev); + Error *local_err = NULL; + + /* + * There will have been a warning during vhost_dev_init, but lets + * assert here as nothing will go right now. + */ + g_assert(vub->config_size && vub->vhost_user.supports_config == true); + + if (vhost_dev_get_config(&vub->vhost_dev, config, + vub->config_size, &local_err)) { + error_report_err(local_err); + } +} + +/* + * When the daemon signals an update to the config we just need to + * signal the guest as we re-read the config on demand above. + */ +static int vub_config_notifier(struct vhost_dev *dev) +{ + virtio_notify_config(dev->vdev); + return 0; +} + +const VhostDevConfigOps vub_config_ops = { + .vhost_dev_config_notifier = vub_config_notifier, +}; + +static void vub_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserBase *vub) +{ + vhost_user_cleanup(&vub->vhost_user); + + for (int i = 0; i < vub->num_vqs; i++) { + VirtQueue *vq = g_ptr_array_index(vub->vqs, i); + virtio_delete_queue(vq); + } + + virtio_cleanup(vdev); +} + +static int vub_connect(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(vdev); + struct vhost_dev *vhost_dev = &vub->vhost_dev; + + if (vub->connected) { + return 0; + } + vub->connected = true; + + /* + * If we support VHOST_USER_GET_CONFIG we must enable the notifier + * so we can ping the guest when it updates. + */ + if (vub->vhost_user.supports_config) { + vhost_dev_set_config_notifier(vhost_dev, &vub_config_ops); + } + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vub_start(vdev); + } + + return 0; +} + +static void vub_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(vdev); + + if (!vub->connected) { + return; + } + vub->connected = false; + + if (vhost_dev_is_started(&vub->vhost_dev)) { + vub_stop(vdev); + } +} + +static void vub_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev = opaque; + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(vdev); + + switch (event) { + case CHR_EVENT_OPENED: + if (vub_connect(dev) < 0) { + qemu_chr_fe_disconnect(&vub->chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + vub_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void vub_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(dev); + int ret; + + if (!vub->chardev.chr) { + error_setg(errp, "vhost-user-base: missing chardev"); + return; + } + + if (!vub->virtio_id) { + error_setg(errp, "vhost-user-base: need to define device id"); + return; + } + + if (!vub->num_vqs) { + vub->num_vqs = 1; /* reasonable default? */ + } + + if (!vub->vq_size) { + vub->vq_size = 64; + } + + /* + * We can't handle config requests unless we know the size of the + * config region, specialisations of the vhost-user-base will be + * able to set this. + */ + if (vub->config_size) { + vub->vhost_user.supports_config = true; + } + + if (!vhost_user_init(&vub->vhost_user, &vub->chardev, errp)) { + return; + } + + virtio_init(vdev, vub->virtio_id, vub->config_size); + + /* + * Disable guest notifiers, by default all notifications will be via the + * asynchronous vhost-user socket. + */ + vdev->use_guest_notifier_mask = false; + + /* Allocate queues */ + vub->vqs = g_ptr_array_sized_new(vub->num_vqs); + for (int i = 0; i < vub->num_vqs; i++) { + g_ptr_array_add(vub->vqs, + virtio_add_queue(vdev, vub->vq_size, + vub_handle_output)); + } + + vub->vhost_dev.nvqs = vub->num_vqs; + vub->vhost_dev.vqs = g_new0(struct vhost_virtqueue, vub->vhost_dev.nvqs); + + /* connect to backend */ + ret = vhost_dev_init(&vub->vhost_dev, &vub->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, errp); + + if (ret < 0) { + do_vhost_user_cleanup(vdev, vub); + } + + qemu_chr_fe_set_handlers(&vub->chardev, NULL, NULL, vub_event, NULL, + dev, NULL, true); +} + +static void vub_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBase *vub = VHOST_USER_BASE(dev); + struct vhost_virtqueue *vhost_vqs = vub->vhost_dev.vqs; + + /* This will stop vhost backend if appropriate. */ + vub_set_status(vdev, 0); + vhost_dev_cleanup(&vub->vhost_dev); + g_free(vhost_vqs); + do_vhost_user_cleanup(vdev, vub); +} + +static void vub_class_init(ObjectClass *klass, void *data) +{ + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + + vdc->realize = vub_device_realize; + vdc->unrealize = vub_device_unrealize; + vdc->get_features = vub_get_features; + vdc->get_config = vub_get_config; + vdc->set_status = vub_set_status; +} + +static const TypeInfo vub_types[] = { + { + .name = TYPE_VHOST_USER_BASE, + .parent = TYPE_VIRTIO_DEVICE, + .instance_size = sizeof(VHostUserBase), + .class_init = vub_class_init, + .class_size = sizeof(VHostUserBaseClass), + .abstract = true + } +}; + +DEFINE_TYPES(vub_types) diff --git a/hw/virtio/vhost-user-device-pci.c b/hw/virtio/vhost-user-device-pci.c index 41f9b7905b4..efaf55d3dd4 100644 --- a/hw/virtio/vhost-user-device-pci.c +++ b/hw/virtio/vhost-user-device-pci.c @@ -9,21 +9,18 @@ #include "qemu/osdep.h" #include "hw/qdev-properties.h" -#include "hw/virtio/vhost-user-device.h" +#include "hw/virtio/vhost-user-base.h" #include "hw/virtio/virtio-pci.h" struct VHostUserDevicePCI { VirtIOPCIProxy parent_obj; + VHostUserBase vub; }; -typedef struct VHostUserDevicePCI VHostUserDevicePCI; - #define TYPE_VHOST_USER_DEVICE_PCI "vhost-user-device-pci-base" -DECLARE_INSTANCE_CHECKER(VHostUserDevicePCI, - VHOST_USER_DEVICE_PCI, - TYPE_VHOST_USER_DEVICE_PCI) +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserDevicePCI, VHOST_USER_DEVICE_PCI) static void vhost_user_device_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) { @@ -39,6 +36,10 @@ static void vhost_user_device_pci_class_init(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); + + /* Reason: stop users confusing themselves */ + dc->user_creatable = false; + k->realize = vhost_user_device_pci_realize; set_bit(DEVICE_CATEGORY_INPUT, dc->categories); pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; diff --git a/hw/virtio/vhost-user-device.c b/hw/virtio/vhost-user-device.c index 2b028cae08d..67aa934710d 100644 --- a/hw/virtio/vhost-user-device.c +++ b/hw/virtio/vhost-user-device.c @@ -1,7 +1,10 @@ /* - * Generic vhost-user stub. This can be used to connect to any - * vhost-user backend. All configuration details must be handled by - * the vhost-user daemon itself + * Generic vhost-user-device implementation for any vhost-user-backend + * + * This is a concrete implementation of vhost-user-base which can be + * configured via properties. It is useful for development and + * prototyping. It expects configuration details (if any) to be + * handled by the vhost-user daemon itself. * * Copyright (c) 2023 Linaro Ltd * Author: Alex Bennée @@ -13,329 +16,9 @@ #include "qapi/error.h" #include "hw/qdev-properties.h" #include "hw/virtio/virtio-bus.h" -#include "hw/virtio/vhost-user-device.h" +#include "hw/virtio/vhost-user-base.h" #include "qemu/error-report.h" -static void vub_start(VirtIODevice *vdev) -{ - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - VHostUserBase *vub = VHOST_USER_BASE(vdev); - int ret, i; - - if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); - return; - } - - ret = vhost_dev_enable_notifiers(&vub->vhost_dev, vdev); - if (ret < 0) { - error_report("Error enabling host notifiers: %d", -ret); - return; - } - - ret = k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, true); - if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); - goto err_host_notifiers; - } - - vub->vhost_dev.acked_features = vdev->guest_features; - - ret = vhost_dev_start(&vub->vhost_dev, vdev, true); - if (ret < 0) { - error_report("Error starting vhost-user-device: %d", -ret); - goto err_guest_notifiers; - } - - /* - * guest_notifier_mask/pending not used yet, so just unmask - * everything here. virtio-pci will do the right thing by - * enabling/disabling irqfd. - */ - for (i = 0; i < vub->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&vub->vhost_dev, vdev, i, false); - } - - return; - -err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false); -err_host_notifiers: - vhost_dev_disable_notifiers(&vub->vhost_dev, vdev); -} - -static void vub_stop(VirtIODevice *vdev) -{ - VHostUserBase *vub = VHOST_USER_BASE(vdev); - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - int ret; - - if (!k->set_guest_notifiers) { - return; - } - - vhost_dev_stop(&vub->vhost_dev, vdev, true); - - ret = k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false); - if (ret < 0) { - error_report("vhost guest notifier cleanup failed: %d", ret); - return; - } - - vhost_dev_disable_notifiers(&vub->vhost_dev, vdev); -} - -static void vub_set_status(VirtIODevice *vdev, uint8_t status) -{ - VHostUserBase *vub = VHOST_USER_BASE(vdev); - bool should_start = virtio_device_should_start(vdev, status); - - if (vhost_dev_is_started(&vub->vhost_dev) == should_start) { - return; - } - - if (should_start) { - vub_start(vdev); - } else { - vub_stop(vdev); - } -} - -/* - * For an implementation where everything is delegated to the backend - * we don't do anything other than return the full feature set offered - * by the daemon (module the reserved feature bit). - */ -static uint64_t vub_get_features(VirtIODevice *vdev, - uint64_t requested_features, Error **errp) -{ - VHostUserBase *vub = VHOST_USER_BASE(vdev); - /* This should be set when the vhost connection initialises */ - g_assert(vub->vhost_dev.features); - return vub->vhost_dev.features & ~(1ULL << VHOST_USER_F_PROTOCOL_FEATURES); -} - -/* - * To handle VirtIO config we need to know the size of the config - * space. We don't cache the config but re-fetch it from the guest - * every time in case something has changed. - */ -static void vub_get_config(VirtIODevice *vdev, uint8_t *config) -{ - VHostUserBase *vub = VHOST_USER_BASE(vdev); - Error *local_err = NULL; - - /* - * There will have been a warning during vhost_dev_init, but lets - * assert here as nothing will go right now. - */ - g_assert(vub->config_size && vub->vhost_user.supports_config == true); - - if (vhost_dev_get_config(&vub->vhost_dev, config, - vub->config_size, &local_err)) { - error_report_err(local_err); - } -} - -/* - * When the daemon signals an update to the config we just need to - * signal the guest as we re-read the config on demand above. - */ -static int vub_config_notifier(struct vhost_dev *dev) -{ - virtio_notify_config(dev->vdev); - return 0; -} - -const VhostDevConfigOps vub_config_ops = { - .vhost_dev_config_notifier = vub_config_notifier, -}; - -static void vub_handle_output(VirtIODevice *vdev, VirtQueue *vq) -{ - /* - * Not normally called; it's the daemon that handles the queue; - * however virtio's cleanup path can call this. - */ -} - -static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserBase *vub) -{ - vhost_user_cleanup(&vub->vhost_user); - - for (int i = 0; i < vub->num_vqs; i++) { - VirtQueue *vq = g_ptr_array_index(vub->vqs, i); - virtio_delete_queue(vq); - } - - virtio_cleanup(vdev); -} - -static int vub_connect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserBase *vub = VHOST_USER_BASE(vdev); - struct vhost_dev *vhost_dev = &vub->vhost_dev; - - if (vub->connected) { - return 0; - } - vub->connected = true; - - /* - * If we support VHOST_USER_GET_CONFIG we must enable the notifier - * so we can ping the guest when it updates. - */ - if (vub->vhost_user.supports_config) { - vhost_dev_set_config_notifier(vhost_dev, &vub_config_ops); - } - - /* restore vhost state */ - if (virtio_device_started(vdev, vdev->status)) { - vub_start(vdev); - } - - return 0; -} - -static void vub_disconnect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserBase *vub = VHOST_USER_BASE(vdev); - - if (!vub->connected) { - return; - } - vub->connected = false; - - if (vhost_dev_is_started(&vub->vhost_dev)) { - vub_stop(vdev); - } -} - -static void vub_event(void *opaque, QEMUChrEvent event) -{ - DeviceState *dev = opaque; - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserBase *vub = VHOST_USER_BASE(vdev); - - switch (event) { - case CHR_EVENT_OPENED: - if (vub_connect(dev) < 0) { - qemu_chr_fe_disconnect(&vub->chardev); - return; - } - break; - case CHR_EVENT_CLOSED: - vub_disconnect(dev); - break; - case CHR_EVENT_BREAK: - case CHR_EVENT_MUX_IN: - case CHR_EVENT_MUX_OUT: - /* Ignore */ - break; - } -} - -static void vub_device_realize(DeviceState *dev, Error **errp) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserBase *vub = VHOST_USER_BASE(dev); - int ret; - - if (!vub->chardev.chr) { - error_setg(errp, "vhost-user-device: missing chardev"); - return; - } - - if (!vub->virtio_id) { - error_setg(errp, "vhost-user-device: need to define device id"); - return; - } - - if (!vub->num_vqs) { - vub->num_vqs = 1; /* reasonable default? */ - } - - /* - * We can't handle config requests unless we know the size of the - * config region, specialisations of the vhost-user-device will be - * able to set this. - */ - if (vub->config_size) { - vub->vhost_user.supports_config = true; - } - - if (!vhost_user_init(&vub->vhost_user, &vub->chardev, errp)) { - return; - } - - virtio_init(vdev, vub->virtio_id, vub->config_size); - - /* - * Disable guest notifiers, by default all notifications will be via the - * asynchronous vhost-user socket. - */ - vdev->use_guest_notifier_mask = false; - - /* Allocate queues */ - vub->vqs = g_ptr_array_sized_new(vub->num_vqs); - for (int i = 0; i < vub->num_vqs; i++) { - g_ptr_array_add(vub->vqs, - virtio_add_queue(vdev, 4, vub_handle_output)); - } - - vub->vhost_dev.nvqs = vub->num_vqs; - vub->vhost_dev.vqs = g_new0(struct vhost_virtqueue, vub->vhost_dev.nvqs); - - /* connect to backend */ - ret = vhost_dev_init(&vub->vhost_dev, &vub->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - - if (ret < 0) { - do_vhost_user_cleanup(vdev, vub); - } - - qemu_chr_fe_set_handlers(&vub->chardev, NULL, NULL, vub_event, NULL, - dev, NULL, true); -} - -static void vub_device_unrealize(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserBase *vub = VHOST_USER_BASE(dev); - struct vhost_virtqueue *vhost_vqs = vub->vhost_dev.vqs; - - /* This will stop vhost backend if appropriate. */ - vub_set_status(vdev, 0); - vhost_dev_cleanup(&vub->vhost_dev); - g_free(vhost_vqs); - do_vhost_user_cleanup(vdev, vub); -} - -static void vub_class_init(ObjectClass *klass, void *data) -{ - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); - - vdc->realize = vub_device_realize; - vdc->unrealize = vub_device_unrealize; - vdc->get_features = vub_get_features; - vdc->get_config = vub_get_config; - vdc->set_status = vub_set_status; -} - -static const TypeInfo vub_info = { - .name = TYPE_VHOST_USER_BASE, - .parent = TYPE_VIRTIO_DEVICE, - .instance_size = sizeof(VHostUserBase), - .class_init = vub_class_init, - .class_size = sizeof(VHostUserBaseClass), - .abstract = true -}; - - /* * The following is a concrete implementation of the base class which * allows the user to define the key parameters via the command line. @@ -349,6 +32,7 @@ static const VMStateDescription vud_vmstate = { static Property vud_properties[] = { DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), DEFINE_PROP_UINT16("virtio-id", VHostUserBase, virtio_id, 0), + DEFINE_PROP_UINT32("vq_size", VHostUserBase, vq_size, 64), DEFINE_PROP_UINT32("num_vqs", VHostUserBase, num_vqs, 1), DEFINE_PROP_UINT32("config_size", VHostUserBase, config_size, 0), DEFINE_PROP_END_OF_LIST(), @@ -358,6 +42,9 @@ static void vud_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + /* Reason: stop inexperienced users confusing themselves */ + dc->user_creatable = false; + device_class_set_props(dc, vud_properties); dc->vmsd = &vud_vmstate; set_bit(DEVICE_CATEGORY_INPUT, dc->categories); @@ -366,14 +53,11 @@ static void vud_class_init(ObjectClass *klass, void *data) static const TypeInfo vud_info = { .name = TYPE_VHOST_USER_DEVICE, .parent = TYPE_VHOST_USER_BASE, - .instance_size = sizeof(VHostUserBase), .class_init = vud_class_init, - .class_size = sizeof(VHostUserBaseClass), }; static void vu_register_types(void) { - type_register_static(&vub_info); type_register_static(&vud_info); } diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index c0055a78326..51c3f97c2d0 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -17,6 +17,7 @@ if have_vhost if have_vhost_user # fixme - this really should be generic specific_virtio_ss.add(files('vhost-user.c')) + system_virtio_ss.add(files('vhost-user-base.c')) system_virtio_ss.add(files('vhost-user-device.c')) system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('vhost-user-device-pci.c')) endif From patchwork Thu Jan 4 21:09:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759876 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183371wrw; Thu, 4 Jan 2024 13:11:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXlexhYJoS40F+ybLQTu3136bnWGkpJ9hv5OTuV90u5F29jggWObTP5CVjcpF9YCoo+9DB X-Received: by 2002:a05:6902:e10:b0:dbc:de49:636b with SMTP id df16-20020a0569020e1000b00dbcde49636bmr1163565ybb.12.1704402694193; Thu, 04 Jan 2024 13:11:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402694; cv=none; d=google.com; s=arc-20160816; b=uarkc0gqRbFcqR3c5T4dVeN0z82JvGoYZt9ja5nDLfd52NPie58DvehBWmSAfHYb+P +pCjs2E2O+tEywAO+eJ1wJU6Ad/nMIHSg3lTnF43gZRo69IWUTr2QFpbA8nfktCSPCBG b1PAaUdJSB/AW8ugKViV3Ju9EXQSnEwgk1MFeNXTDDp4KoomMNy+mx89EVne7cwltptK h7A3D7xuONQ0iihVYBu3KNKCgXUcn/8vgUrpo3HJJyzcZTI30AG5ABoL4iosz9bcDh8j xMDVRuJyUOYLgCZbef1YwKAiOfX7kVFc+o/EIELQQx1Ft+nAEpqF6kqcrJUa7XJJ7CtI GXGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZD8gKWnWBsgVd7TCyN00x3s8+apLf0F3UjlTxysTxrM=; fh=FJgCuuUiQlhQb75y4DqgTcYU/2dmCchdcJEae1kKAEw=; b=xWLhH4N2ymJcfGsNF4VANKS82bWgb9xMUdhGx33LyyOvo2jmY87D3M4dhzNAy9oxHd uWcwhmX/WrzesD0L9hQIgQf/hu/ClDZPQzQeq1l6vKaZi8GvBtLbu+pV/mEzp+ROZQ1T 50bxi+A/cpA9T9k5PZYYBt0LMXcWv8mb08ek8MP35b3k4NvpO7avDFEgxFWVvYIGgk79 TQlVwORJfEZkpaNOw5PfMpB40k2LW9PdbNM2U0KMzOE5xAKsLensnunYDpb9in3qfg+6 fdoyRQ6FuoKYxk6fvdeAk3NkvT/7acWEk7Gz2P5ohTHEpo2idZoypY+o+YDCQ/Co7OiJ 6xuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E3A6MIaP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bp30-20020a05620a459e00b00781b9927e1bsi323799qkb.256.2024.01.04.13.11.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:11:34 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E3A6MIaP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUyP-0006un-9q; Thu, 04 Jan 2024 16:09:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyN-0006td-IK for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:51 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyL-0007RO-Pk for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:51 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3368b1e056eso787992f8f.3 for ; Thu, 04 Jan 2024 13:09:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402588; x=1705007388; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZD8gKWnWBsgVd7TCyN00x3s8+apLf0F3UjlTxysTxrM=; b=E3A6MIaPkEyMw46IRgs6QAdxWIDnWKd0gC5hD1HjuZ8kbXg8vFx7RI3vYdFBdlk18h aBOY6S4YaYN28Vf+t/Z6Q60mwPyDnZgPiHS5y1tkfrX3gHcKBVeZu+HALfWYezaxJYQP GhtWcNnfT4IE3GEtR9zGPTreVChIeMmQOxamMD6DdEEDT8K5FIdMBpVfrkRNzc9nW2A/ LQ03ejYTe4233klTsfnE3yQheNTavORGKJqwcJMEZQMPv6Ihz2jJ3rXjZB6qsJ00b4ga 9tp4vxkzq07hA8bSUt8yleNhIuyO0mQEWWTbhqKmkrxOYCMyrXy2AhxWoaSQwNtIDhbd 8uig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402588; x=1705007388; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZD8gKWnWBsgVd7TCyN00x3s8+apLf0F3UjlTxysTxrM=; b=ajnOMLl+0+1Rp8CZHKRI26HRnoMfsCGvT8r7CXx0q1wEkfHd0O5a21aWnPYQalmNUD FjWlCVqmQQ01i0U5l1hs/SlodsRR+eyojhjrn5GX2a9fUhSJYvD2G7fBqaGpq/l5zLp2 a/4mTckd0oz0/Ir5k9Eis5qsw+x9TqEaZw098oFarKi4i1+HDs8Y5j+8uRGjyB4UOuhf OWqW9GOyUGHsTWd0FzYdQ8sQiIKweWUq/qxa07nwxF5uLxbcJ9lKML+KNUEejPlVviwX tuzjJItUaww0xBGLvNC199ANpjlyNakRTJm8r4aNf61oLOjkq513Ec5jLzEhnQiBXDut 9LlQ== X-Gm-Message-State: AOJu0YzqUSLAOsrRDsW25D5CMk0DEPbgqiRITGopaDzcMoS3tXlzlnmp tVYbXaX1itsJluxGmDLFnGCYGRkFADjG6Q== X-Received: by 2002:adf:fad0:0:b0:337:404d:4e9f with SMTP id a16-20020adffad0000000b00337404d4e9fmr609500wrs.79.1704402588522; Thu, 04 Jan 2024 13:09:48 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id c11-20020a5d414b000000b00336aa190139sm109726wrq.5.2024.01.04.13.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:45 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 46D3B5F933; Thu, 4 Jan 2024 21:09:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi Subject: [PATCH v9 02/11] hw/virtio: convert vhost-user-base to async shutdown Date: Thu, 4 Jan 2024 21:09:36 +0000 Message-Id: <20240104210945.1223134-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We are about to convert at least one stubs which was using the async teardown so lets use it for all the cases. Signed-off-by: Alex Bennée --- hw/virtio/vhost-user-base.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c index 620fa5cb4a4..78cfa9a5bbc 100644 --- a/hw/virtio/vhost-user-base.c +++ b/hw/virtio/vhost-user-base.c @@ -201,6 +201,8 @@ static int vub_connect(DeviceState *dev) return 0; } +static void vub_event(void *opaque, QEMUChrEvent event); + static void vub_disconnect(DeviceState *dev) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -211,9 +213,13 @@ static void vub_disconnect(DeviceState *dev) } vub->connected = false; - if (vhost_dev_is_started(&vub->vhost_dev)) { - vub_stop(vdev); - } + vub_stop(vdev); + vhost_dev_cleanup(&vub->vhost_dev); + + /* Re-instate the event handler for new connections */ + qemu_chr_fe_set_handlers(&vub->chardev, + NULL, NULL, vub_event, + NULL, dev, NULL, true); } static void vub_event(void *opaque, QEMUChrEvent event) @@ -230,7 +236,9 @@ static void vub_event(void *opaque, QEMUChrEvent event) } break; case CHR_EVENT_CLOSED: - vub_disconnect(dev); + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &vub->chardev, &vub->vhost_dev, + vub_disconnect, vub_event); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: From patchwork Thu Jan 4 21:09:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759877 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183592wrw; Thu, 4 Jan 2024 13:12:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVJbw/aJesIbeZCvcbWqaP+48FDjlRFZAtH0N8Ehj7lsKA0FPXmvVMqD0gNbwGBBGUff8Z X-Received: by 2002:a05:620a:4949:b0:781:5efd:403b with SMTP id vz9-20020a05620a494900b007815efd403bmr1184292qkn.13.1704402730374; Thu, 04 Jan 2024 13:12:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402730; cv=none; d=google.com; s=arc-20160816; b=lxeTjlzAbayxRA0cLtuZdobohIavCt5oceBse7PfPj9ZwlhSTaMXcYO2SqCkc9iTIN q02dnOmzyNrc1/WCYrD8DZOOJORBaF9YK+rkROOU6a59UXhonJ6bGdzelwlc8VKeMGB1 19OnoilVTuXt10PTULxgJr6WWIlg3m6WnWJo496/OapiCwghJ24eYdHLIPlAjK8oKLQe P1ZvgvZ/hlqMDHx3ivH7clVx01ywzmoQ0BzUSZNc+J3s6MxmlQeZ1aXL+m9sh/tVRFIZ VZcG37P0y9aD8ppACWPNdZbpO1UwTFzU7H54U0mQgN/kXAdJ91mV1pxxIZk0gOtlRl6N OPPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xQ8hd0QsqUAs9Wsy9pGcftHF7w2pIduJuDBfpTEm2Uk=; fh=FJgCuuUiQlhQb75y4DqgTcYU/2dmCchdcJEae1kKAEw=; b=PxnA6KOuwOKPYeogWrqJnY6cG71cQ/JztYhGwLWkwskcvz+wspheGltM7If/E5NSLq +ef4GOT7tewQcpZ/E1fdti8XnfH1t6tjpSUtG2vMDBpWSCqRcBH4WmOQP73+iMMRHRwc 906/iBw/QI/NkI7Zg6mVT1daA26/eIIi/r5n2LsWr/H1hNcVdIcCV1WI0WWzEfNVAqiB FCKckSmTNdiftkFbToBOypAtuwBwvH94xnFNZ81/7QiJGVZdq7JFw/KhdxtHdA5gGVOB ASMnwV05khtuCphogo6R9W9Dg4FbBSI2UTCws5yH/hLmyihlgbcrCk3Fzrj2jpT2MGJB iYEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="wqAS3/qz"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w15-20020a05620a424f00b0077f2dc466d7si308154qko.434.2024.01.04.13.12.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:12:10 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="wqAS3/qz"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUzh-0007vx-AD; Thu, 04 Jan 2024 16:11:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyR-0006vm-S3 for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:55 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyO-0007S3-AJ for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:54 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3366e78d872so814704f8f.3 for ; Thu, 04 Jan 2024 13:09:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402591; x=1705007391; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xQ8hd0QsqUAs9Wsy9pGcftHF7w2pIduJuDBfpTEm2Uk=; b=wqAS3/qzfkFHWfvIZPloQPniep3M6GRjs71N9zOKsc4uxelAP5qFU//ZvBD0AM0DKv CYxqGMwlAEaVZ7eT2z+riSMO5CrT09BBIB5oW6VjEmO9q3EzXF7PCdTIeblp9BG6oaBK VC1+y/bRs7Gk26ikJMce4rOGFz9d5P0MIfEkMfBGFN5vtoa8GWQ6M3hnwuFX+Oji8U+h fV6qXW+sEJFuyxs33Ym/R+c2LZ1L9i85kKCUbogszCVrNpPMAyCg4Se42Rl8q4Gji+li Hso3TWqqu9y+Cgl0NLUa74llyIcds8j9PghJK7koUpTgEZJn+ddwlG7PQPxYIADAtu0M 6EQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402591; x=1705007391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xQ8hd0QsqUAs9Wsy9pGcftHF7w2pIduJuDBfpTEm2Uk=; b=mJtIZv4bWaDFKbCnZnBZoFoKmaTdBYs6+S/e8B0QScDEjG7A0YfPRHhAI2bj5GNHn2 EtL4DB8bp9cAVkVa672hJMqdqzN6fqG075DnOy/KREWP9hyA9e5rZBshy6i6SAv7zyET SoSVwIuY/zEueIyGfNFccAR/YKvWXVx56Ir7vATK5fVEl81QSVA/wTS3seu54lsu/5cW XKmeFYpDge1ZTYDHgqW3JyJIJImrr+nj+oJoRECL5rpe6mXs5UeFOAsIA93xIQ1zjwn/ IbfXR4RceDDV3WZkZ2ybZqPmvLJDZbtATgMOplKcb/oiltm+gc62NjO6FBNWKTwS21M3 Yv8g== X-Gm-Message-State: AOJu0Yzvok98NdOCS5ldMANc92o//ohaI5c7ZZyPStSFQ5J1Q1LzOkKm nXgu8dcKaJHR3GIbPFL6WPyPtAaMJoNJQw== X-Received: by 2002:a5d:58d7:0:b0:336:5cc0:db75 with SMTP id o23-20020a5d58d7000000b003365cc0db75mr344227wrf.209.1704402590893; Thu, 04 Jan 2024 13:09:50 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id t3-20020a0560001a4300b003374555d88esm106960wry.56.2024.01.04.13.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:48 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 5F78D5F936; Thu, 4 Jan 2024 21:09:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi Subject: [PATCH v9 03/11] hw/virtio: derive vhost-user-rng from vhost-user-base Date: Thu, 4 Jan 2024 21:09:37 +0000 Message-Id: <20240104210945.1223134-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Now we can take advantage of our new base class and make vhost-user-rng a much simpler boilerplate wrapper. Also as this doesn't require any target specific hacks we only need to build the stubs once. Acked-by: Mark Cave-Ayland Signed-off-by: Alex Bennée --- v5 - don't remove the in-QEMU RNG emulation! v7 - s/parent/parent_obj/ v8 - fix merge conflict (idx == VIRTIO_CONFIG_IRQ_IDX not needed as base doesn't use notifiers) --- include/hw/virtio/vhost-user-rng.h | 13 +- hw/virtio/vhost-user-rng.c | 294 +++-------------------------- hw/virtio/meson.build | 9 +- 3 files changed, 31 insertions(+), 285 deletions(-) diff --git a/include/hw/virtio/vhost-user-rng.h b/include/hw/virtio/vhost-user-rng.h index ddd9f01eea6..10868c7de4d 100644 --- a/include/hw/virtio/vhost-user-rng.h +++ b/include/hw/virtio/vhost-user-rng.h @@ -12,22 +12,13 @@ #include "hw/virtio/virtio.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" -#include "chardev/char-fe.h" +#include "hw/virtio/vhost-user-base.h" #define TYPE_VHOST_USER_RNG "vhost-user-rng" OBJECT_DECLARE_SIMPLE_TYPE(VHostUserRNG, VHOST_USER_RNG) struct VHostUserRNG { - /*< private >*/ - VirtIODevice parent; - CharBackend chardev; - struct vhost_virtqueue *vhost_vq; - struct vhost_dev vhost_dev; - VhostUserState vhost_user; - VirtQueue *req_vq; - bool connected; - - /*< public >*/ + VHostUserBase parent_obj; }; #endif /* QEMU_VHOST_USER_RNG_H */ diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c index 24ac1a22c83..01879c863df 100644 --- a/hw/virtio/vhost-user-rng.c +++ b/hw/virtio/vhost-user-rng.c @@ -3,7 +3,7 @@ * * Copyright (c) 2021 Mathieu Poirier * - * Implementation seriously tailored on vhost-user-i2c.c + * Simple wrapper of the generic vhost-user-device. * * SPDX-License-Identifier: GPL-2.0-or-later */ @@ -13,297 +13,47 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/vhost-user-rng.h" -#include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -static const int feature_bits[] = { - VIRTIO_F_RING_RESET, - VHOST_INVALID_FEATURE_BIT -}; - -static void vu_rng_start(VirtIODevice *vdev) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - int ret; - int i; - - if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); - return; - } - - ret = vhost_dev_enable_notifiers(&rng->vhost_dev, vdev); - if (ret < 0) { - error_report("Error enabling host notifiers: %d", -ret); - return; - } - - ret = k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, true); - if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); - goto err_host_notifiers; - } - - rng->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&rng->vhost_dev, vdev, true); - if (ret < 0) { - error_report("Error starting vhost-user-rng: %d", -ret); - goto err_guest_notifiers; - } - - /* - * guest_notifier_mask/pending not used yet, so just unmask - * everything here. virtio-pci will do the right thing by - * enabling/disabling irqfd. - */ - for (i = 0; i < rng->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&rng->vhost_dev, vdev, i, false); - } - - return; - -err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, false); -err_host_notifiers: - vhost_dev_disable_notifiers(&rng->vhost_dev, vdev); -} - -static void vu_rng_stop(VirtIODevice *vdev) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - int ret; - - if (!k->set_guest_notifiers) { - return; - } - - vhost_dev_stop(&rng->vhost_dev, vdev, true); - - ret = k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, false); - if (ret < 0) { - error_report("vhost guest notifier cleanup failed: %d", ret); - return; - } - - vhost_dev_disable_notifiers(&rng->vhost_dev, vdev); -} - -static void vu_rng_set_status(VirtIODevice *vdev, uint8_t status) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - bool should_start = virtio_device_should_start(vdev, status); - - if (vhost_dev_is_started(&rng->vhost_dev) == should_start) { - return; - } - - if (should_start) { - vu_rng_start(vdev); - } else { - vu_rng_stop(vdev); - } -} - -static uint64_t vu_rng_get_features(VirtIODevice *vdev, - uint64_t requested_features, Error **errp) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - return vhost_get_features(&rng->vhost_dev, feature_bits, - requested_features); -} - -static void vu_rng_handle_output(VirtIODevice *vdev, VirtQueue *vq) -{ - /* - * Not normally called; it's the daemon that handles the queue; - * however virtio's cleanup path can call this. - */ -} - -static void vu_rng_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - /* - * We don't support interrupts, return early if index is set to - * VIRTIO_CONFIG_IRQ_IDX. - */ - if (idx == VIRTIO_CONFIG_IRQ_IDX) { - return; - } - - vhost_virtqueue_mask(&rng->vhost_dev, vdev, idx, mask); -} - -static bool vu_rng_guest_notifier_pending(VirtIODevice *vdev, int idx) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - /* - * We don't support interrupts, return early if index is set to - * VIRTIO_CONFIG_IRQ_IDX. - */ - if (idx == VIRTIO_CONFIG_IRQ_IDX) { - return false; - } - - return vhost_virtqueue_pending(&rng->vhost_dev, idx); -} - -static void vu_rng_connect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - if (rng->connected) { - return; - } - - rng->connected = true; - - /* restore vhost state */ - if (virtio_device_started(vdev, vdev->status)) { - vu_rng_start(vdev); - } -} - -static void vu_rng_disconnect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - - if (!rng->connected) { - return; - } - - rng->connected = false; - - if (vhost_dev_is_started(&rng->vhost_dev)) { - vu_rng_stop(vdev); - } -} - -static void vu_rng_event(void *opaque, QEMUChrEvent event) -{ - DeviceState *dev = opaque; - - switch (event) { - case CHR_EVENT_OPENED: - vu_rng_connect(dev); - break; - case CHR_EVENT_CLOSED: - vu_rng_disconnect(dev); - break; - case CHR_EVENT_BREAK: - case CHR_EVENT_MUX_IN: - case CHR_EVENT_MUX_OUT: - /* Ignore */ - break; - } -} - -static void vu_rng_device_realize(DeviceState *dev, Error **errp) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserRNG *rng = VHOST_USER_RNG(dev); - int ret; - - if (!rng->chardev.chr) { - error_setg(errp, "missing chardev"); - return; - } - - if (!vhost_user_init(&rng->vhost_user, &rng->chardev, errp)) { - return; - } - - virtio_init(vdev, VIRTIO_ID_RNG, 0); - - rng->req_vq = virtio_add_queue(vdev, 4, vu_rng_handle_output); - if (!rng->req_vq) { - error_setg_errno(errp, -1, "virtio_add_queue() failed"); - goto virtio_add_queue_failed; - } - - rng->vhost_dev.nvqs = 1; - rng->vhost_dev.vqs = g_new0(struct vhost_virtqueue, rng->vhost_dev.nvqs); - ret = vhost_dev_init(&rng->vhost_dev, &rng->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - if (ret < 0) { - error_setg_errno(errp, -ret, "vhost_dev_init() failed"); - goto vhost_dev_init_failed; - } - - qemu_chr_fe_set_handlers(&rng->chardev, NULL, NULL, vu_rng_event, NULL, - dev, NULL, true); - - return; - -vhost_dev_init_failed: - g_free(rng->vhost_dev.vqs); - virtio_delete_queue(rng->req_vq); -virtio_add_queue_failed: - virtio_cleanup(vdev); - vhost_user_cleanup(&rng->vhost_user); -} - -static void vu_rng_device_unrealize(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserRNG *rng = VHOST_USER_RNG(dev); - struct vhost_virtqueue *vhost_vqs = rng->vhost_dev.vqs; - - vu_rng_set_status(vdev, 0); - - vhost_dev_cleanup(&rng->vhost_dev); - g_free(vhost_vqs); - virtio_delete_queue(rng->req_vq); - virtio_cleanup(vdev); - vhost_user_cleanup(&rng->vhost_user); -} - -static struct vhost_dev *vu_rng_get_vhost(VirtIODevice *vdev) -{ - VHostUserRNG *rng = VHOST_USER_RNG(vdev); - return &rng->vhost_dev; -} - static const VMStateDescription vu_rng_vmstate = { .name = "vhost-user-rng", .unmigratable = 1, }; -static Property vu_rng_properties[] = { - DEFINE_PROP_CHR("chardev", VHostUserRNG, chardev), +static Property vrng_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), DEFINE_PROP_END_OF_LIST(), }; +static void vu_rng_base_realize(DeviceState *dev, Error **errp) +{ + VHostUserBase *vub = VHOST_USER_BASE(dev); + VHostUserBaseClass *vubs = VHOST_USER_BASE_GET_CLASS(dev); + + /* Fixed for RNG */ + vub->virtio_id = VIRTIO_ID_RNG; + vub->num_vqs = 1; + vub->vq_size = 4; + + vubs->parent_realize(dev, errp); +} + static void vu_rng_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); - device_class_set_props(dc, vu_rng_properties); dc->vmsd = &vu_rng_vmstate; - set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + device_class_set_props(dc, vrng_properties); + device_class_set_parent_realize(dc, vu_rng_base_realize, + &vubc->parent_realize); - vdc->realize = vu_rng_device_realize; - vdc->unrealize = vu_rng_device_unrealize; - vdc->get_features = vu_rng_get_features; - vdc->set_status = vu_rng_set_status; - vdc->guest_notifier_mask = vu_rng_guest_notifier_mask; - vdc->guest_notifier_pending = vu_rng_guest_notifier_pending; - vdc->get_vhost = vu_rng_get_vhost; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); } static const TypeInfo vu_rng_info = { .name = TYPE_VHOST_USER_RNG, - .parent = TYPE_VIRTIO_DEVICE, + .parent = TYPE_VHOST_USER_BASE, .instance_size = sizeof(VHostUserRNG), .class_init = vu_rng_class_init, }; diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 51c3f97c2d0..b5c1a461e34 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -18,8 +18,15 @@ if have_vhost # fixme - this really should be generic specific_virtio_ss.add(files('vhost-user.c')) system_virtio_ss.add(files('vhost-user-base.c')) + + # MMIO Stubs system_virtio_ss.add(files('vhost-user-device.c')) + system_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) + + # PCI Stubs system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('vhost-user-device-pci.c')) + system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_RNG'], + if_true: files('vhost-user-rng-pci.c')) endif if have_vhost_vdpa system_virtio_ss.add(files('vhost-vdpa.c')) @@ -37,7 +44,6 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-us specific_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) -specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vhost-user-scmi.c')) @@ -49,7 +55,6 @@ virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vs virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input-pci.c')) -virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_SCSI', if_true: files('vhost-user-scsi-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-pci.c')) From patchwork Thu Jan 4 21:09:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759873 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183143wrw; Thu, 4 Jan 2024 13:11:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHN7E8Gn56fWKF8i+P05euH2PUK6IVJQ8lbHMdIcO72LVQwoKEDsvSSVD9qwG7oMbm7n/VV X-Received: by 2002:a25:908c:0:b0:dbd:2bf6:ca7b with SMTP id t12-20020a25908c000000b00dbd2bf6ca7bmr1075062ybl.35.1704402659919; Thu, 04 Jan 2024 13:10:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402659; cv=none; d=google.com; s=arc-20160816; b=C2qPnaqyJFSrxVsLbzUzpW/ayVUe6U8UItWjL08De1OHOBvG8czaDx/zm82GLHhtv9 W90s7sDpOFVXCWanKdxszEdf/tamg3hmpHaahxY2zeaxbMI9ps7J3rFLybQC6M2kWJtc v9zdqJTF3BuMSLT1qRcORIJ0Vy4xT6p+EDOV+20PqV7Plkgz2WoTUgrNWICIEMw+48bo WBr9eZOcN/s2Aksgbg34Z4SIQ1IuOoOd/Qo0ZeHIXdrCG5YuiZtvES0WB/jHrujaL7Zv M36YBlFrfXjuR2fJv56c3AhAy4sHR02R+OObpPOEK5KqTny/WY5r0XkmUlf8SPbzi0Rk 6IKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jwTm1suZhlMwV2M5kVHJC6RGfViT9oAO5/a0mhNTiYU=; fh=FJgCuuUiQlhQb75y4DqgTcYU/2dmCchdcJEae1kKAEw=; b=Eg9in59CgHeaoJydiOLhTC2PtuUvIJpoczIkLgPUA0hMkt3yD6SyBh8jzYJrgAgcwt BdH56A2j4dehrpo6eC0rfNz2M4JRG0XtybOHN702cNfvJ4Ex4Q426y9okFZhW1UTUO7o AjOMTtmxY+u5jN64vS8mt55wWyBYBLiO5FQ5/a4XtxpCZdSjvt5Ov2jwZovvwuBiTDBV CrWgSQKu6k0vRgXlneECH48ivMzL1q4G/3uwp8yP0kya5B5MSZMFOMz3RWLnONUaJkVR CDBQ64kdJMa03ZvcbkU2o/6+d7PlFFCnyWb8udYMAGmHttTAaKUlWCbxWz9J+lOCFF+N bFZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v49Ds5Ip; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bs9-20020ac86f09000000b004256217f1a9si377217qtb.347.2024.01.04.13.10.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:10:59 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v49Ds5Ip; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUz0-00073v-Iu; Thu, 04 Jan 2024 16:10:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyU-0006wn-26 for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:58 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyQ-0007UM-Qs for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:57 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40d4f5d902dso8554815e9.2 for ; Thu, 04 Jan 2024 13:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402593; x=1705007393; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jwTm1suZhlMwV2M5kVHJC6RGfViT9oAO5/a0mhNTiYU=; b=v49Ds5IpmykPixwPB2bce/Ld+ryrA3q1Wux4yLywNQiSO1o0sefdr68lsG7uYsjjNp 4c/0cEyYGJTO0z3y9wh7DD6F1aFrE0rfRM61nsgYmHSFVdbrie6EVhjZU0wzZBQVl9Vy VJk7iGRcJAJ3RUN4Af1U8N3clFpgNDWXRG0l/pBMng6I4Jk5dPX8dg1VrtiYtZTRsn1A n/w6+aUFA7J4ErYAzkm0K1B7Crs/80usUn8TLQmQRDfs4Yr3o/Iv0kLDO7XKRRCIrx1F YgaxabmhVT/AZLPT1vPI6nBYaC5UU/9NxC3YXBkQoOjrwwGfW+m+0pNt3x/bRy4ikevR 9sUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402593; x=1705007393; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jwTm1suZhlMwV2M5kVHJC6RGfViT9oAO5/a0mhNTiYU=; b=Qv7RyYKkx7Snv5hn90EC+JJpNBn5dbGuhw1BWd74eWQ0Z4FanIscx3d3PzrxDcvuEQ Usic1Alr0xUAOCLXr0pclaiJMFfp3i2mdT5ZzzZFzu14//aW4nOw8NEulyfZ87111h9M +vZinHphv16JlF6xtOYwS/F/D/vtDZeTQQbK4R8vtz57DDpfyOraU30eHfjQfy8GjIw5 3/S6NIO59G7MzKeBOX2JVXY7FYM6oyTYYe+PyiD4+Vghn40RFUGq77CJvVHahrQWpJQz 594LAeKzuTHbJ2FBQFbj/UBqB2AfZvr/ayX6V0/cXjW95DQIQX26UjqxY9xe73rnekUf oLiw== X-Gm-Message-State: AOJu0YyDskV2tjfEhOWIvGdBG/Qx/i6l9mwkGu+GMvA6DEjnMzW2NoWd /HRcL+TWNXx9vyccNTxyzPUfxh+e9QrmdA== X-Received: by 2002:a05:600c:5190:b0:40e:36a2:905c with SMTP id fa16-20020a05600c519000b0040e36a2905cmr170918wmb.116.1704402593049; Thu, 04 Jan 2024 13:09:53 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id k39-20020a05600c1ca700b0040d8af75e19sm6791206wms.24.2024.01.04.13.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:48 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 79A475F93B; Thu, 4 Jan 2024 21:09:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi Subject: [PATCH v9 04/11] hw/virtio: derive vhost-user-gpio from vhost-user-base Date: Thu, 4 Jan 2024 21:09:38 +0000 Message-Id: <20240104210945.1223134-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Now the new base class supports config handling we can take advantage and make vhost-user-gpio a much simpler boilerplate wrapper. Also as this doesn't require any target specific hacks we only need to build the stubs once. Acked-by: Mark Cave-Ayland Acked-by: Viresh Kumar Signed-off-by: Alex Bennée --- v7 - s/parent/parent_obj/ v8 - fix merge conflicts --- include/hw/virtio/vhost-user-gpio.h | 25 +- hw/virtio/vhost-user-gpio.c | 407 ++-------------------------- hw/virtio/meson.build | 5 +- 3 files changed, 22 insertions(+), 415 deletions(-) diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-user-gpio.h index a9d3f9b049f..5814a8400a0 100644 --- a/include/hw/virtio/vhost-user-gpio.h +++ b/include/hw/virtio/vhost-user-gpio.h @@ -12,34 +12,13 @@ #include "hw/virtio/virtio.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" -#include "standard-headers/linux/virtio_gpio.h" -#include "chardev/char-fe.h" +#include "hw/virtio/vhost-user-base.h" #define TYPE_VHOST_USER_GPIO "vhost-user-gpio-device" OBJECT_DECLARE_SIMPLE_TYPE(VHostUserGPIO, VHOST_USER_GPIO); struct VHostUserGPIO { - /*< private >*/ - VirtIODevice parent_obj; - CharBackend chardev; - struct virtio_gpio_config config; - struct vhost_virtqueue *vhost_vqs; - struct vhost_dev vhost_dev; - VhostUserState vhost_user; - VirtQueue *command_vq; - VirtQueue *interrupt_vq; - /** - * There are at least two steps of initialization of the - * vhost-user device. The first is a "connect" step and - * second is a "start" step. Make a separation between - * those initialization phases by using two fields. - * - * @connected: see vu_gpio_connect()/vu_gpio_disconnect() - * @started_vu: see vu_gpio_start()/vu_gpio_stop() - */ - bool connected; - bool started_vu; - /*< public >*/ + VHostUserBase parent_obj; }; #endif /* _QEMU_VHOST_USER_GPIO_H */ diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index a83437a5da3..9f37c254159 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -11,388 +11,25 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/vhost-user-gpio.h" -#include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -#include "trace.h" +#include "standard-headers/linux/virtio_gpio.h" -#define VHOST_NVQS 2 - -/* Features required from VirtIO */ -static const int feature_bits[] = { - VIRTIO_F_VERSION_1, - VIRTIO_F_NOTIFY_ON_EMPTY, - VIRTIO_RING_F_INDIRECT_DESC, - VIRTIO_RING_F_EVENT_IDX, - VIRTIO_GPIO_F_IRQ, - VIRTIO_F_RING_RESET, - VHOST_INVALID_FEATURE_BIT +static Property vgpio_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_END_OF_LIST(), }; -static void vu_gpio_get_config(VirtIODevice *vdev, uint8_t *config) +static void vgpio_realize(DeviceState *dev, Error **errp) { - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); + VHostUserBase *vub = VHOST_USER_BASE(dev); + VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev); - memcpy(config, &gpio->config, sizeof(gpio->config)); -} + /* Fixed for GPIO */ + vub->virtio_id = VIRTIO_ID_GPIO; + vub->num_vqs = 2; + vub->config_size = sizeof(struct virtio_gpio_config); -static int vu_gpio_config_notifier(struct vhost_dev *dev) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(dev->vdev); - - memcpy(dev->vdev->config, &gpio->config, sizeof(gpio->config)); - virtio_notify_config(dev->vdev); - - return 0; -} - -const VhostDevConfigOps gpio_ops = { - .vhost_dev_config_notifier = vu_gpio_config_notifier, -}; - -static int vu_gpio_start(VirtIODevice *vdev) -{ - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - struct vhost_dev *vhost_dev = &gpio->vhost_dev; - int ret, i; - - if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); - return -ENOSYS; - } - - ret = vhost_dev_enable_notifiers(vhost_dev, vdev); - if (ret < 0) { - error_report("Error enabling host notifiers: %d", ret); - return ret; - } - - ret = k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, true); - if (ret < 0) { - error_report("Error binding guest notifier: %d", ret); - goto err_host_notifiers; - } - - /* - * Before we start up we need to ensure we have the final feature - * set needed for the vhost configuration. The backend may also - * apply backend_features when the feature set is sent. - */ - vhost_ack_features(&gpio->vhost_dev, feature_bits, vdev->guest_features); - - ret = vhost_dev_start(&gpio->vhost_dev, vdev, false); - if (ret < 0) { - error_report("Error starting vhost-user-gpio: %d", ret); - goto err_guest_notifiers; - } - gpio->started_vu = true; - - /* - * guest_notifier_mask/pending not used yet, so just unmask - * everything here. virtio-pci will do the right thing by - * enabling/disabling irqfd. - */ - for (i = 0; i < gpio->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&gpio->vhost_dev, vdev, i, false); - } - - /* - * As we must have VHOST_USER_F_PROTOCOL_FEATURES (because - * VHOST_USER_GET_CONFIG requires it) we need to explicitly enable - * the vrings. - */ - g_assert(vhost_dev->vhost_ops && - vhost_dev->vhost_ops->vhost_set_vring_enable); - ret = vhost_dev->vhost_ops->vhost_set_vring_enable(vhost_dev, true); - if (ret == 0) { - return 0; - } - - error_report("Failed to start vrings for vhost-user-gpio: %d", ret); - -err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, gpio->vhost_dev.nvqs, false); -err_host_notifiers: - vhost_dev_disable_notifiers(&gpio->vhost_dev, vdev); - - return ret; -} - -static void vu_gpio_stop(VirtIODevice *vdev) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - struct vhost_dev *vhost_dev = &gpio->vhost_dev; - int ret; - - if (!gpio->started_vu) { - return; - } - gpio->started_vu = false; - - if (!k->set_guest_notifiers) { - return; - } - - vhost_dev_stop(vhost_dev, vdev, false); - - ret = k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false); - if (ret < 0) { - error_report("vhost guest notifier cleanup failed: %d", ret); - return; - } - - vhost_dev_disable_notifiers(vhost_dev, vdev); -} - -static void vu_gpio_set_status(VirtIODevice *vdev, uint8_t status) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - bool should_start = virtio_device_should_start(vdev, status); - - trace_virtio_gpio_set_status(status); - - if (!gpio->connected) { - return; - } - - if (vhost_dev_is_started(&gpio->vhost_dev) == should_start) { - return; - } - - if (should_start) { - if (vu_gpio_start(vdev)) { - qemu_chr_fe_disconnect(&gpio->chardev); - } - } else { - vu_gpio_stop(vdev); - } -} - -static uint64_t vu_gpio_get_features(VirtIODevice *vdev, uint64_t features, - Error **errp) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - - return vhost_get_features(&gpio->vhost_dev, feature_bits, features); -} - -static void vu_gpio_handle_output(VirtIODevice *vdev, VirtQueue *vq) -{ - /* - * Not normally called; it's the daemon that handles the queue; - * however virtio's cleanup path can call this. - */ -} - -static void vu_gpio_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - - /* - * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the macro of configure interrupt's IDX, If this driver does not - * support, the function will return - */ - - if (idx == VIRTIO_CONFIG_IRQ_IDX) { - return; - } - - vhost_virtqueue_mask(&gpio->vhost_dev, vdev, idx, mask); -} - -static struct vhost_dev *vu_gpio_get_vhost(VirtIODevice *vdev) -{ - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - return &gpio->vhost_dev; -} - -static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserGPIO *gpio) -{ - virtio_delete_queue(gpio->command_vq); - virtio_delete_queue(gpio->interrupt_vq); - g_free(gpio->vhost_vqs); - virtio_cleanup(vdev); - vhost_user_cleanup(&gpio->vhost_user); -} - -static int vu_gpio_connect(DeviceState *dev, Error **errp) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - struct vhost_dev *vhost_dev = &gpio->vhost_dev; - int ret; - - if (gpio->connected) { - return 0; - } - - vhost_dev_set_config_notifier(vhost_dev, &gpio_ops); - gpio->vhost_user.supports_config = true; - - gpio->vhost_dev.nvqs = VHOST_NVQS; - gpio->vhost_dev.vqs = gpio->vhost_vqs; - - ret = vhost_dev_init(vhost_dev, &gpio->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - if (ret < 0) { - return ret; - } - - gpio->connected = true; - - /* restore vhost state */ - if (virtio_device_started(vdev, vdev->status)) { - vu_gpio_start(vdev); - } - - return 0; -} - -static void vu_gpio_event(void *opaque, QEMUChrEvent event); - -static void vu_gpio_disconnect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - - if (!gpio->connected) { - return; - } - gpio->connected = false; - - vu_gpio_stop(vdev); - vhost_dev_cleanup(&gpio->vhost_dev); - - /* Re-instate the event handler for new connections */ - qemu_chr_fe_set_handlers(&gpio->chardev, - NULL, NULL, vu_gpio_event, - NULL, dev, NULL, true); -} - -static void vu_gpio_event(void *opaque, QEMUChrEvent event) -{ - DeviceState *dev = opaque; - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(vdev); - Error *local_err = NULL; - - switch (event) { - case CHR_EVENT_OPENED: - if (vu_gpio_connect(dev, &local_err) < 0) { - qemu_chr_fe_disconnect(&gpio->chardev); - return; - } - break; - case CHR_EVENT_CLOSED: - /* defer close until later to avoid circular close */ - vhost_user_async_close(dev, &gpio->chardev, &gpio->vhost_dev, - vu_gpio_disconnect, vu_gpio_event); - break; - case CHR_EVENT_BREAK: - case CHR_EVENT_MUX_IN: - case CHR_EVENT_MUX_OUT: - /* Ignore */ - break; - } -} - -static int vu_gpio_realize_connect(VHostUserGPIO *gpio, Error **errp) -{ - VirtIODevice *vdev = &gpio->parent_obj; - DeviceState *dev = &vdev->parent_obj; - struct vhost_dev *vhost_dev = &gpio->vhost_dev; - int ret; - - ret = qemu_chr_fe_wait_connected(&gpio->chardev, errp); - if (ret < 0) { - return ret; - } - - /* - * vu_gpio_connect() may have already connected (via the event - * callback) in which case it will just report success. - */ - ret = vu_gpio_connect(dev, errp); - if (ret < 0) { - qemu_chr_fe_disconnect(&gpio->chardev); - return ret; - } - g_assert(gpio->connected); - - ret = vhost_dev_get_config(vhost_dev, (uint8_t *)&gpio->config, - sizeof(gpio->config), errp); - - if (ret < 0) { - error_report("vhost-user-gpio: get config failed"); - - qemu_chr_fe_disconnect(&gpio->chardev); - vhost_dev_cleanup(vhost_dev); - return ret; - } - - return 0; -} - -static void vu_gpio_device_realize(DeviceState *dev, Error **errp) -{ - ERRP_GUARD(); - - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(dev); - int retries, ret; - - if (!gpio->chardev.chr) { - error_setg(errp, "vhost-user-gpio: chardev is mandatory"); - return; - } - - if (!vhost_user_init(&gpio->vhost_user, &gpio->chardev, errp)) { - return; - } - - virtio_init(vdev, VIRTIO_ID_GPIO, sizeof(gpio->config)); - - gpio->command_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output); - gpio->interrupt_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output); - gpio->vhost_vqs = g_new0(struct vhost_virtqueue, VHOST_NVQS); - - gpio->connected = false; - - qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, vu_gpio_event, NULL, - dev, NULL, true); - - retries = VU_REALIZE_CONN_RETRIES; - g_assert(!*errp); - do { - if (*errp) { - error_prepend(errp, "Reconnecting after error: "); - error_report_err(*errp); - *errp = NULL; - } - ret = vu_gpio_realize_connect(gpio, errp); - } while (ret < 0 && retries--); - - if (ret < 0) { - do_vhost_user_cleanup(vdev, gpio); - } - - return; -} - -static void vu_gpio_device_unrealize(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio = VHOST_USER_GPIO(dev); - - vu_gpio_set_status(vdev, 0); - qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, NULL, NULL, NULL, NULL, - false); - vhost_dev_cleanup(&gpio->vhost_dev); - do_vhost_user_cleanup(vdev, gpio); + vubc->parent_realize(dev, errp); } static const VMStateDescription vu_gpio_vmstate = { @@ -400,31 +37,21 @@ static const VMStateDescription vu_gpio_vmstate = { .unmigratable = 1, }; -static Property vu_gpio_properties[] = { - DEFINE_PROP_CHR("chardev", VHostUserGPIO, chardev), - DEFINE_PROP_END_OF_LIST(), -}; - static void vu_gpio_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); - device_class_set_props(dc, vu_gpio_properties); dc->vmsd = &vu_gpio_vmstate; + device_class_set_props(dc, vgpio_properties); + device_class_set_parent_realize(dc, vgpio_realize, + &vubc->parent_realize); set_bit(DEVICE_CATEGORY_INPUT, dc->categories); - vdc->realize = vu_gpio_device_realize; - vdc->unrealize = vu_gpio_device_unrealize; - vdc->get_features = vu_gpio_get_features; - vdc->get_config = vu_gpio_get_config; - vdc->set_status = vu_gpio_set_status; - vdc->guest_notifier_mask = vu_gpio_guest_notifier_mask; - vdc->get_vhost = vu_gpio_get_vhost; } static const TypeInfo vu_gpio_info = { .name = TYPE_VHOST_USER_GPIO, - .parent = TYPE_VIRTIO_DEVICE, + .parent = TYPE_VHOST_USER_BASE, .instance_size = sizeof(VHostUserGPIO), .class_init = vu_gpio_class_init, }; diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index b5c1a461e34..87042e59017 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -21,10 +21,13 @@ if have_vhost # MMIO Stubs system_virtio_ss.add(files('vhost-user-device.c')) + system_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) system_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) # PCI Stubs system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('vhost-user-device-pci.c')) + system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], + if_true: files('vhost-user-gpio-pci.c')) system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_RNG'], if_true: files('vhost-user-rng-pci.c')) endif @@ -44,8 +47,6 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-us specific_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) -specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) -specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vhost-user-scmi.c')) specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SCMI'], if_true: files('vhost-user-scmi-pci.c')) From patchwork Thu Jan 4 21:09:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759883 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183886wrw; Thu, 4 Jan 2024 13:13:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhb6tTKT+7X1QmGO3fLMWj31GreWE+SWbd+EqjLi+HCADNnkeMp8ckiPU+3n8SdfakJCR+ X-Received: by 2002:a05:622a:138a:b0:428:d35a:6903 with SMTP id o10-20020a05622a138a00b00428d35a6903mr1265031qtk.98.1704402781192; Thu, 04 Jan 2024 13:13:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402781; cv=none; d=google.com; s=arc-20160816; b=JVs7xhcBpraMxlMZSmCi6EGn3IQTypBncTH85YKQ95F0FqEMhDW4WiOubBVkATvqim mvrP+1uVoQo4ynkbj4N8g4Prpv1ua5Ibnjpbp1qOjJhMwCGqk+mHLz0ROk7bm3Xir63d yHm7f9j+LXcmX1M+Wv6vLI17xZhz7cSp4e5OgqPf/JMar9osIR1JCl1NRsWSRFoKmEf7 l16/F7Q4Bt/NSReXYydQxxFgUhC8KWb+U7PCz9X8Q/5+BYA3MFZXkjyESxrRkRM4u20u wjhgO6cqHBj6uIptxEwNcBgAXU3x8Os8Qd8Q5QhgGGbNVweH4jcpBC83yAsNZTMT2l1e B+Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hh0+ImQqmxIGNzYiVpYYalUliqD3F7N5qwavBV7W4Xg=; fh=FJgCuuUiQlhQb75y4DqgTcYU/2dmCchdcJEae1kKAEw=; b=OiwNNJg7XuGIhNU+nNnroNvOvBBaWhY66ZbMhZeUDWjk3Au33cMx5VjLFzJxB+ZRLe zcn1MCN8+CidZ50DCN+IJqMmVZ1G3FpVMoeKfseAhLvcYmnLJPUoIuZk0DfA9UBTvmnS igGFkQpbUb47ADCAIctpCBr/uL2eF6dxDzhZmlCnqSN9P9fSPXNIIW/CiJk0WJPiWesN cWwCTIJNnOG74CP/PaIgM0t8u6nIZ3s4VGneP7qkPePhi87hCa0M+jgQIbsY3b19aiRK odZK+bis8OGVGE95b5dBJ6XAJIKCTOP2yrXE1CkfA9yvHVNOCktaQm4xPbQmsXvjyzR0 3NzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="S5ab7mw/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bb30-20020a05622a1b1e00b00428242b9a00si332846qtb.597.2024.01.04.13.13.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:13:01 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="S5ab7mw/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUzs-0008Ib-Fs; Thu, 04 Jan 2024 16:11:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyT-0006wg-PS for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:58 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyQ-0007US-Qj for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:57 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3374eb61cbcso876016f8f.0 for ; Thu, 04 Jan 2024 13:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402593; x=1705007393; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hh0+ImQqmxIGNzYiVpYYalUliqD3F7N5qwavBV7W4Xg=; b=S5ab7mw/Auk+gr1GfocEdHvrpnX7BHEpJYVyUwiFdCWujoOIcxsvRPqyHUyzl7QvC6 B3RMTo53ShqktSKCajxREVTRRf2okoLnt0hBOX612xSbZ7c54b8UiwH7Lycyw7TxgVyp /Cx9let75uelYeb9D9PB2nEjRpIavbZwu9aHJzBMLKs0dZ16fyY/9qGeJY/qmBH0SHFL PN7pNe4/5/gm0CNrEwXKtqBsLwJBS/0SRgGQSSGbcTCQv3cUfV0di8k37X5RzeuOdl/w HopT+TAsnu0ifMADBPrbvEL1p00cdFjYXz7PeLznszR5+X3jYatuqpw44v7WDvTYDbdU Q4tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402593; x=1705007393; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hh0+ImQqmxIGNzYiVpYYalUliqD3F7N5qwavBV7W4Xg=; b=S8EFBLXUcKwQLhPEOGt5bhnXRQQo7JAGAWxr9gj5ivGFvx0VPHXUNZIYZMTCT08OKg CeGHArWxFuMhKBOAYzbQ8YkM/7MDkPCMtBYUn2y6sb8WAPjWWaF6WS90y3mWz/hdwx8O rbBCYJOn/uBVlkavqUQAjV7Xl7toLGCo675m4lJvGEeNQbEz1uuUQ1qfRy0hRQNdR934 tK3ibtnyqk8kZHoDzj9muuk1vRGtOPuXeDkkL+LDEuxTn1OYV5THu5Q3nnJDI4IgZJli i/bsA/iQcUvBZ99HRt+WQ0viJpalG9paHtDOrE/tKbnK6NT0WQZZQY7AX+ZDW7dOskEr zmtw== X-Gm-Message-State: AOJu0YyUv0wO2J6kCfu3oU+u2zGx5RDHh5V4uJMtNvW7E8+jGznWZItQ LkcI/lBL+3okZW2G/40q+I1MYgr8NyKgHw== X-Received: by 2002:a5d:4252:0:b0:337:4b63:ea54 with SMTP id s18-20020a5d4252000000b003374b63ea54mr735040wrr.85.1704402593297; Thu, 04 Jan 2024 13:09:53 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id l15-20020a5d410f000000b00336e43e8e57sm106775wrp.58.2024.01.04.13.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:48 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 913905F93C; Thu, 4 Jan 2024 21:09:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi Subject: [PATCH v9 05/11] hw/virtio: derive vhost-user-i2c from vhost-user-base Date: Thu, 4 Jan 2024 21:09:39 +0000 Message-Id: <20240104210945.1223134-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Now we can take advantage of the new base class and make vhost-user-i2c a much simpler boilerplate wrapper. Also as this doesn't require any target specific hacks we only need to build the stubs once. Acked-by: Mark Cave-Ayland Acked-by: Viresh Kumar Signed-off-by: Alex Bennée --- v7 - s/parent/parent_obj/ --- include/hw/virtio/vhost-user-i2c.h | 14 +- hw/virtio/vhost-user-i2c.c | 272 ++--------------------------- hw/virtio/meson.build | 5 +- 3 files changed, 23 insertions(+), 268 deletions(-) diff --git a/include/hw/virtio/vhost-user-i2c.h b/include/hw/virtio/vhost-user-i2c.h index 0f7acd40e3a..a9b5612ad01 100644 --- a/include/hw/virtio/vhost-user-i2c.h +++ b/include/hw/virtio/vhost-user-i2c.h @@ -9,23 +9,17 @@ #ifndef QEMU_VHOST_USER_I2C_H #define QEMU_VHOST_USER_I2C_H +#include "hw/virtio/virtio.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" +#include "hw/virtio/vhost-user-base.h" #define TYPE_VHOST_USER_I2C "vhost-user-i2c-device" + OBJECT_DECLARE_SIMPLE_TYPE(VHostUserI2C, VHOST_USER_I2C) struct VHostUserI2C { - VirtIODevice parent; - CharBackend chardev; - struct vhost_virtqueue *vhost_vq; - struct vhost_dev vhost_dev; - VhostUserState vhost_user; - VirtQueue *vq; - bool connected; + VHostUserBase parent_obj; }; -/* Virtio Feature bits */ -#define VIRTIO_I2C_F_ZERO_LENGTH_REQUEST 0 - #endif /* QEMU_VHOST_USER_I2C_H */ diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c index 4eef3f06337..a464f5e0399 100644 --- a/hw/virtio/vhost-user-i2c.c +++ b/hw/virtio/vhost-user-i2c.c @@ -14,253 +14,22 @@ #include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -static const int feature_bits[] = { - VIRTIO_I2C_F_ZERO_LENGTH_REQUEST, - VIRTIO_F_RING_RESET, - VHOST_INVALID_FEATURE_BIT +static Property vi2c_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_END_OF_LIST(), }; -static void vu_i2c_start(VirtIODevice *vdev) -{ - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - int ret, i; - - if (!k->set_guest_notifiers) { - error_report("binding does not support guest notifiers"); - return; - } - - ret = vhost_dev_enable_notifiers(&i2c->vhost_dev, vdev); - if (ret < 0) { - error_report("Error enabling host notifiers: %d", -ret); - return; - } - - ret = k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, true); - if (ret < 0) { - error_report("Error binding guest notifier: %d", -ret); - goto err_host_notifiers; - } - - i2c->vhost_dev.acked_features = vdev->guest_features; - - ret = vhost_dev_start(&i2c->vhost_dev, vdev, true); - if (ret < 0) { - error_report("Error starting vhost-user-i2c: %d", -ret); - goto err_guest_notifiers; - } - - /* - * guest_notifier_mask/pending not used yet, so just unmask - * everything here. virtio-pci will do the right thing by - * enabling/disabling irqfd. - */ - for (i = 0; i < i2c->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&i2c->vhost_dev, vdev, i, false); - } - - return; - -err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, false); -err_host_notifiers: - vhost_dev_disable_notifiers(&i2c->vhost_dev, vdev); -} - -static void vu_i2c_stop(VirtIODevice *vdev) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - int ret; - - if (!k->set_guest_notifiers) { - return; - } - - vhost_dev_stop(&i2c->vhost_dev, vdev, true); - - ret = k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, false); - if (ret < 0) { - error_report("vhost guest notifier cleanup failed: %d", ret); - return; - } - - vhost_dev_disable_notifiers(&i2c->vhost_dev, vdev); -} - -static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - bool should_start = virtio_device_should_start(vdev, status); - - if (vhost_dev_is_started(&i2c->vhost_dev) == should_start) { - return; - } - - if (should_start) { - vu_i2c_start(vdev); - } else { - vu_i2c_stop(vdev); - } -} - -static uint64_t vu_i2c_get_features(VirtIODevice *vdev, - uint64_t requested_features, Error **errp) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - virtio_add_feature(&requested_features, VIRTIO_I2C_F_ZERO_LENGTH_REQUEST); - return vhost_get_features(&i2c->vhost_dev, feature_bits, requested_features); -} - -static void vu_i2c_handle_output(VirtIODevice *vdev, VirtQueue *vq) -{ - /* - * Not normally called; it's the daemon that handles the queue; - * however virtio's cleanup path can call this. - */ -} - -static void vu_i2c_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - /* - * We don't support interrupts, return early if index is set to - * VIRTIO_CONFIG_IRQ_IDX. - */ - if (idx == VIRTIO_CONFIG_IRQ_IDX) { - return; - } - - vhost_virtqueue_mask(&i2c->vhost_dev, vdev, idx, mask); -} - -static bool vu_i2c_guest_notifier_pending(VirtIODevice *vdev, int idx) -{ - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - /* - * We don't support interrupts, return early if index is set to - * VIRTIO_CONFIG_IRQ_IDX. - */ - if (idx == VIRTIO_CONFIG_IRQ_IDX) { - return false; - } - - return vhost_virtqueue_pending(&i2c->vhost_dev, idx); -} - -static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserI2C *i2c) -{ - vhost_user_cleanup(&i2c->vhost_user); - virtio_delete_queue(i2c->vq); - virtio_cleanup(vdev); -} - -static int vu_i2c_connect(DeviceState *dev) +static void vi2c_realize(DeviceState *dev, Error **errp) { - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); + VHostUserBase *vub = VHOST_USER_BASE(dev); + VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev); - if (i2c->connected) { - return 0; - } - i2c->connected = true; + /* Fixed for I2C */ + vub->virtio_id = VIRTIO_ID_I2C_ADAPTER; + vub->num_vqs = 1; + vub->vq_size = 4; - /* restore vhost state */ - if (virtio_device_started(vdev, vdev->status)) { - vu_i2c_start(vdev); - } - - return 0; -} - -static void vu_i2c_disconnect(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - if (!i2c->connected) { - return; - } - i2c->connected = false; - - if (vhost_dev_is_started(&i2c->vhost_dev)) { - vu_i2c_stop(vdev); - } -} - -static void vu_i2c_event(void *opaque, QEMUChrEvent event) -{ - DeviceState *dev = opaque; - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - - switch (event) { - case CHR_EVENT_OPENED: - if (vu_i2c_connect(dev) < 0) { - qemu_chr_fe_disconnect(&i2c->chardev); - return; - } - break; - case CHR_EVENT_CLOSED: - vu_i2c_disconnect(dev); - break; - case CHR_EVENT_BREAK: - case CHR_EVENT_MUX_IN: - case CHR_EVENT_MUX_OUT: - /* Ignore */ - break; - } -} - -static void vu_i2c_device_realize(DeviceState *dev, Error **errp) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(dev); - int ret; - - if (!i2c->chardev.chr) { - error_setg(errp, "vhost-user-i2c: missing chardev"); - return; - } - - if (!vhost_user_init(&i2c->vhost_user, &i2c->chardev, errp)) { - return; - } - - virtio_init(vdev, VIRTIO_ID_I2C_ADAPTER, 0); - - i2c->vhost_dev.nvqs = 1; - i2c->vq = virtio_add_queue(vdev, 4, vu_i2c_handle_output); - i2c->vhost_dev.vqs = g_new0(struct vhost_virtqueue, i2c->vhost_dev.nvqs); - - ret = vhost_dev_init(&i2c->vhost_dev, &i2c->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - if (ret < 0) { - g_free(i2c->vhost_dev.vqs); - do_vhost_user_cleanup(vdev, i2c); - } - - qemu_chr_fe_set_handlers(&i2c->chardev, NULL, NULL, vu_i2c_event, NULL, - dev, NULL, true); -} - -static void vu_i2c_device_unrealize(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserI2C *i2c = VHOST_USER_I2C(dev); - struct vhost_virtqueue *vhost_vqs = i2c->vhost_dev.vqs; - - /* This will stop vhost backend if appropriate. */ - vu_i2c_set_status(vdev, 0); - vhost_dev_cleanup(&i2c->vhost_dev); - g_free(vhost_vqs); - do_vhost_user_cleanup(vdev, i2c); + vubc->parent_realize(dev, errp); } static const VMStateDescription vu_i2c_vmstate = { @@ -268,30 +37,21 @@ static const VMStateDescription vu_i2c_vmstate = { .unmigratable = 1, }; -static Property vu_i2c_properties[] = { - DEFINE_PROP_CHR("chardev", VHostUserI2C, chardev), - DEFINE_PROP_END_OF_LIST(), -}; - static void vu_i2c_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); - device_class_set_props(dc, vu_i2c_properties); dc->vmsd = &vu_i2c_vmstate; + device_class_set_props(dc, vi2c_properties); + device_class_set_parent_realize(dc, vi2c_realize, + &vubc->parent_realize); set_bit(DEVICE_CATEGORY_INPUT, dc->categories); - vdc->realize = vu_i2c_device_realize; - vdc->unrealize = vu_i2c_device_unrealize; - vdc->get_features = vu_i2c_get_features; - vdc->set_status = vu_i2c_set_status; - vdc->guest_notifier_mask = vu_i2c_guest_notifier_mask; - vdc->guest_notifier_pending = vu_i2c_guest_notifier_pending; } static const TypeInfo vu_i2c_info = { .name = TYPE_VHOST_USER_I2C, - .parent = TYPE_VIRTIO_DEVICE, + .parent = TYPE_VHOST_USER_BASE, .instance_size = sizeof(VHostUserI2C), .class_init = vu_i2c_class_init, }; diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 87042e59017..0a4d29ace64 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -22,12 +22,15 @@ if have_vhost # MMIO Stubs system_virtio_ss.add(files('vhost-user-device.c')) system_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) + system_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) system_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) # PCI Stubs system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('vhost-user-device-pci.c')) system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c')) + system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], + if_true: files('vhost-user-i2c-pci.c')) system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_RNG'], if_true: files('vhost-user-rng-pci.c')) endif @@ -46,7 +49,6 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock.c specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) -specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vhost-user-scmi.c')) specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SCMI'], if_true: files('vhost-user-scmi-pci.c')) @@ -54,7 +56,6 @@ virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk-pci.c')) -virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_SCSI', if_true: files('vhost-user-scsi-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-pci.c')) From patchwork Thu Jan 4 21:09:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759878 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183599wrw; Thu, 4 Jan 2024 13:12:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmYsOtA7GQTPEPXsGe+fY0EjA4GXx2nbMgsTaos1+zCNVAKYQh9HCxtixVGrCYqJic5uHj X-Received: by 2002:a05:622a:94:b0:429:76be:7550 with SMTP id o20-20020a05622a009400b0042976be7550mr61182qtw.65.1704402731071; Thu, 04 Jan 2024 13:12:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402731; cv=none; d=google.com; s=arc-20160816; b=DEb+oe5sr1ZSrwQys/HZXYxbBdtR8Y4A4gqhhAk9wwukrSZK3APHveZQSo9HpTegGG 1DzVv/UoMrgb7DIprYaZ3BWuZfMms2Ajfi9K1I6t7fZ0zK8QI8p7X2Squ4IWFGP6aq1g iAkiv5BtJr1PYFhu1bfv3cdvRHSkd1ZdxyPYmceAY+mLXKuVaFvW9+fxIG9TA1INSWw8 96YhDI95YwgTaFoMiPzMkmP9ydaKM7U5/s4rMDLas/rF+wwwmbDYEnPYLaGKsxKft94d TzSwz7O3GPSaVhhQAl+OH8QyAAkJy8F8QctJXNV/lpdC0JTclZGKeRmMWE3+xWuJFtd7 pxJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ErbqFiCME9GSZ0GgdLckktr8frFgaWJboyeK7BGi/ZI=; fh=FJgCuuUiQlhQb75y4DqgTcYU/2dmCchdcJEae1kKAEw=; b=Lt9GogNOAJ6lbO3fQ3mDyihONy2rv/JZnw20kAfL6qqzZCSegWdKpVPssINLH+LnU8 R6AFHd0KzO2DMvgftgFLOaYX4E4WWp2/7Ygx6o1QLVNnwrnecfPTIQ6E80HcK0gcuIba HGt5hxq5vCMHi7JZYmF+TNguWD0S1RUooG1JhMpmKRDKUeOAQ9KYfYt0jMbfAYhqn4V7 80uxgspQD4a9RknNaZhnxsHgn0Uisw2XtH/OCJeXjGGz1YsZmTpqLqiq31HUgJHdAm2o X/ZUkocYwj8PHZgqGLZLig6SlM6rigpqcOjvErCGEvwSJt+5i/H0hxYj9Np+30Li+xsf +95Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iXzpPkDK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q13-20020a05622a030d00b004283d18bb96si353911qtw.432.2024.01.04.13.12.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:12:11 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iXzpPkDK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUyt-00072e-OG; Thu, 04 Jan 2024 16:10:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyP-0006vB-Fl for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:53 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyM-0007RU-NA for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:53 -0500 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40d8902da73so6831505e9.2 for ; Thu, 04 Jan 2024 13:09:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402589; x=1705007389; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ErbqFiCME9GSZ0GgdLckktr8frFgaWJboyeK7BGi/ZI=; b=iXzpPkDKFH4JbVoeFqYJgCfN4D+fjkkFSv/zlmPFyVJaRsTJCqCrxSHjFi0qlGnRa4 +HspzeJQC+htNVSnoY/UIIu0PFHCIbSYrBTJFINKf3FYLTJu7hAP3p3bVSH3vrIsWOYh o/Q70qv2iGi72xYuHerci790VvA+PO8KzkufLJGq32SPyW7dhIdVdvznp3it+vqs+zC4 fhK6LN7FDVUdJEE0/wA2miOC4wIy3ideoCENULu385SIqXVK6VPZFxxACW/SlE8vDXJL MaxkTLIXd2MjBM5r2N6uPH52I34Owv+Cai9f8qPtjWpwLeUYs3TmltrYOd4KJama9euC Lx0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402589; x=1705007389; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ErbqFiCME9GSZ0GgdLckktr8frFgaWJboyeK7BGi/ZI=; b=pWuqGQGz6nyPx123/FO4paiB5vlUzT3lq/5LZeATsWbZFleOoHpUQgAhkvy0XNTRGx xvk4/KT6r6y7dBOTPqIV8GM+/sAJYJagSO9H/g/UgsPXM7NSV4BBoFoHUpYM7nvOLc64 i1Lvd7oYw/SVNq334toCcEJbJaluvH+JMZ7sx7ZwWKGjgpd/aIvxS856INFcbO3ie42o uDrMpk5T+M91XQX/C1BcxSJYftPN8UCGPUuwMxsynSbfzydYuDnpqdGsy5PxhH+nWx+D 0exeriTk65TYgKiI/PKS5YYXcxX5Z2k3ghfJXJsscnm4lJJxw5RD94Lncey8fA1HoPVN rC5w== X-Gm-Message-State: AOJu0YwOf+1qurDmpzNTmU1Hp0oCRQXBx2JBeemtbzwUfltgjA/0zuIy x6xP9KDCeO7Lxt94S7jEgQ2DK1Vk2gODaw== X-Received: by 2002:a05:600c:3515:b0:40e:35ac:d140 with SMTP id h21-20020a05600c351500b0040e35acd140mr465735wmq.11.1704402588891; Thu, 04 Jan 2024 13:09:48 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id g17-20020a05600c001100b0040d8d11bf63sm349772wmc.41.2024.01.04.13.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:48 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id ADFE85F93E; Thu, 4 Jan 2024 21:09:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi Subject: [PATCH v9 06/11] hw/virtio: add vhost-user-snd and virtio-snd-pci devices Date: Thu, 4 Jan 2024 21:09:40 +0000 Message-Id: <20240104210945.1223134-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Manos Pitsidianakis Tested with rust-vmm vhost-user-sound daemon: RUST_LOG=trace cargo run --bin vhost-user-sound -- --socket /tmp/snd.sock --backend null Invocation: qemu-system-x86_64 \ -qmp unix:./qmp-sock,server,wait=off \ -m 4096 \ -numa node,memdev=mem \ -object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \ -D qemu.log \ -d guest_errors,trace:\*snd\*,trace:\*sound\*,trace:\*vhost\* \ -chardev socket,id=vsnd,path=/tmp/snd.sock \ -device vhost-user-snd-pci,chardev=vsnd,id=snd \ /path/to/disk [AJB: imported from https://github.com/epilys/qemu-virtio-snd/commit/54ae1cdd15fef2d88e9e387a175f099a38c636f4.patch] Signed-off-by: Alex Bennée Signed-off-by: Manos Pitsidianakis --- v7 - s/parent/parent_obj/ - add MAINTAINERS - add missing s-o-b --- MAINTAINERS | 7 +++ include/hw/virtio/vhost-user-snd.h | 24 ++++++++++ hw/virtio/vhost-user-snd-pci.c | 75 ++++++++++++++++++++++++++++++ hw/virtio/vhost-user-snd.c | 67 ++++++++++++++++++++++++++ hw/virtio/Kconfig | 5 ++ hw/virtio/meson.build | 3 ++ 6 files changed, 181 insertions(+) create mode 100644 include/hw/virtio/vhost-user-snd.h create mode 100644 hw/virtio/vhost-user-snd-pci.c create mode 100644 hw/virtio/vhost-user-snd.c diff --git a/MAINTAINERS b/MAINTAINERS index 0e832fd5d13..607f71817f8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2327,6 +2327,13 @@ F: hw/virtio/vhost-user-gpio* F: include/hw/virtio/vhost-user-gpio.h F: tests/qtest/libqos/virtio-gpio.* +vhost-user-snd +M: Alex Bennée +R: Manos Pitsidianakis +S: Maintained +F: hw/virtio/vhost-user-snd* +F: include/hw/virtio/vhost-user-snd.h + vhost-user-scmi R: mzamazal@redhat.com S: Supported diff --git a/include/hw/virtio/vhost-user-snd.h b/include/hw/virtio/vhost-user-snd.h new file mode 100644 index 00000000000..f9260116a73 --- /dev/null +++ b/include/hw/virtio/vhost-user-snd.h @@ -0,0 +1,24 @@ +/* + * Vhost-user Sound virtio device + * + * Copyright (c) 2021 Mathieu Poirier + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_VHOST_USER_SND_H +#define QEMU_VHOST_USER_SND_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "hw/virtio/vhost-user-base.h" + +#define TYPE_VHOST_USER_SND "vhost-user-snd" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserSound, VHOST_USER_SND) + +struct VHostUserSound { + VHostUserBase parent_obj; +}; + +#endif /* QEMU_VHOST_USER_SND_H */ diff --git a/hw/virtio/vhost-user-snd-pci.c b/hw/virtio/vhost-user-snd-pci.c new file mode 100644 index 00000000000..d61cfdae631 --- /dev/null +++ b/hw/virtio/vhost-user-snd-pci.c @@ -0,0 +1,75 @@ +/* + * Vhost-user Sound virtio device PCI glue + * + * Copyright (c) 2023 Manos Pitsidianakis + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-snd.h" +#include "hw/virtio/virtio-pci.h" + +struct VHostUserSoundPCI { + VirtIOPCIProxy parent_obj; + VHostUserSound vdev; +}; + +typedef struct VHostUserSoundPCI VHostUserSoundPCI; + +#define TYPE_VHOST_USER_SND_PCI "vhost-user-snd-pci-base" + +DECLARE_INSTANCE_CHECKER(VHostUserSoundPCI, VHOST_USER_SND_PCI, + TYPE_VHOST_USER_SND_PCI) + +static Property vhost_user_snd_pci_properties[] = { + DEFINE_PROP_END_OF_LIST(), +}; + +static void vhost_user_snd_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VHostUserSoundPCI *dev = VHOST_USER_SND_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&dev->vdev); + + vpci_dev->nvectors = 1; + + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void vhost_user_snd_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); + k->realize = vhost_user_snd_pci_realize; + set_bit(DEVICE_CATEGORY_SOUND, dc->categories); + device_class_set_props(dc, vhost_user_snd_pci_properties); + pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision = 0x00; + pcidev_k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO; +} + +static void vhost_user_snd_pci_instance_init(Object *obj) +{ + VHostUserSoundPCI *dev = VHOST_USER_SND_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_SND); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_snd_pci_info = { + .base_name = TYPE_VHOST_USER_SND_PCI, + .non_transitional_name = "vhost-user-snd-pci", + .instance_size = sizeof(VHostUserSoundPCI), + .instance_init = vhost_user_snd_pci_instance_init, + .class_init = vhost_user_snd_pci_class_init, +}; + +static void vhost_user_snd_pci_register(void) +{ + virtio_pci_types_register(&vhost_user_snd_pci_info); +} + +type_init(vhost_user_snd_pci_register); diff --git a/hw/virtio/vhost-user-snd.c b/hw/virtio/vhost-user-snd.c new file mode 100644 index 00000000000..9a217543f85 --- /dev/null +++ b/hw/virtio/vhost-user-snd.c @@ -0,0 +1,67 @@ +/* + * Vhost-user snd virtio device + * + * Copyright (c) 2023 Manos Pitsidianakis + * + * Simple wrapper of the generic vhost-user-device. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-snd.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_snd.h" + +static const VMStateDescription vu_snd_vmstate = { + .name = "vhost-user-snd", + .unmigratable = 1, +}; + +static Property vsnd_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vu_snd_base_realize(DeviceState *dev, Error **errp) +{ + VHostUserBase *vub = VHOST_USER_BASE(dev); + VHostUserBaseClass *vubs = VHOST_USER_BASE_GET_CLASS(dev); + + vub->virtio_id = VIRTIO_ID_SOUND; + vub->num_vqs = 4; + vub->config_size = sizeof(struct virtio_snd_config); + vub->vq_size = 64; + + vubs->parent_realize(dev, errp); +} + +static void vu_snd_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); + + dc->vmsd = &vu_snd_vmstate; + device_class_set_props(dc, vsnd_properties); + device_class_set_parent_realize(dc, vu_snd_base_realize, + &vubc->parent_realize); + + set_bit(DEVICE_CATEGORY_SOUND, dc->categories); +} + +static const TypeInfo vu_snd_info = { + .name = TYPE_VHOST_USER_SND, + .parent = TYPE_VHOST_USER_BASE, + .instance_size = sizeof(VHostUserSound), + .class_init = vu_snd_class_init, +}; + +static void vu_snd_register_types(void) +{ + type_register_static(&vu_snd_info); +} + +type_init(vu_snd_register_types) diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 92c9cf6c96c..aa63ff7fd41 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -101,6 +101,11 @@ config VHOST_VDPA_DEV default y depends on VIRTIO && VHOST_VDPA && LINUX +config VHOST_USER_SND + bool + default y + depends on VIRTIO && VHOST_USER + config VHOST_USER_SCMI bool default y diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 0a4d29ace64..118d4d4da7c 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -24,6 +24,7 @@ if have_vhost system_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) system_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) system_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) + system_virtio_ss.add(when: 'CONFIG_VHOST_USER_SND', if_true: files('vhost-user-snd.c')) # PCI Stubs system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('vhost-user-device-pci.c')) @@ -33,6 +34,8 @@ if have_vhost if_true: files('vhost-user-i2c-pci.c')) system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_RNG'], if_true: files('vhost-user-rng-pci.c')) + system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SND'], + if_true: files('vhost-user-snd-pci.c')) endif if have_vhost_vdpa system_virtio_ss.add(files('vhost-vdpa.c')) From patchwork Thu Jan 4 21:09:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759874 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183158wrw; Thu, 4 Jan 2024 13:11:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSa5M799BUOBJ5wtl9QfDqC4mbXaY3/nOvrg1J9993RIbqrPqvr3fG0XBZdZv4Lid0JZRK X-Received: by 2002:a05:6214:19ed:b0:67f:c943:6359 with SMTP id q13-20020a05621419ed00b0067fc9436359mr1253225qvc.72.1704402662377; Thu, 04 Jan 2024 13:11:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402662; cv=none; d=google.com; s=arc-20160816; b=AGnyxbtEozUCQaDBJKZekH3Ts+WJ2R2uRU0QKb4RKVHrdKbWifdETYGftDEDQNG2gM 0ljOkyyHLvI3+AeLiMinZQ0bjkEgH7fd0jfZZxudbIl8817pwr7Jk3VDN2nm5gndkKmX M9zI6rqejoFJdD6X5NPtpHmLnSSnnh4Ps0LjNvM10x7LMe6KAWOk3E+CXq/eLpMgwv+c 0OpkMym1HjZvh+QOXAo/nkiTll810Cu9qX8hyCJ5QAM/JQ2dxku8pdXdJ52MF4gCZ9XE bRKXcmu74yODbDoecuVkSpMfSW/eZ0A3+Zvj8t+WYFMcf9UkNqGwTb1gS62p+S4tWgRM CSSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8OfSNqfYw1yegwimMaKEPeX4MqQs2j01XgstIe7tBng=; fh=FJgCuuUiQlhQb75y4DqgTcYU/2dmCchdcJEae1kKAEw=; b=DwBl2XwnDcHG4yJRxXJ6z6rgMi6yqmyb7Etf4BVMSEf3zKtxS2YwbNRQaONR79Osc+ +T3uTD12zuYh22m8aeCVbPgmvkjxc0Ti3gUXB+GgdkBPLDU6Sz0PzUbG39sJqs2H4BJl OStzNRKLEGqAZC3DIwclHwwrD0oEe8fGCDu29CEiHJvjztNRFmtZWmMEUANNCnBAElBC Qr7zR4viuHv88+CHRTPxJ0KiB0kFvr9+txYoicLdw30hYdr7QbAt4py8Dwo4VYIlNClH sWHKbYrpU9L550A5R0OREfzKXL1ZmEaDG+c+hYIVLtjuwIEndHEDn1eNQsoHr6pUHZdr hgDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mflICYL1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f3-20020a0cf3c3000000b0068080216cafsi291792qvm.369.2024.01.04.13.11.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:11:02 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mflICYL1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUzJ-0007Ek-JF; Thu, 04 Jan 2024 16:10:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyQ-0006ve-3d for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:55 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyN-0007Rn-UL for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:53 -0500 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40d5f40ce04so9136485e9.2 for ; Thu, 04 Jan 2024 13:09:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402590; x=1705007390; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8OfSNqfYw1yegwimMaKEPeX4MqQs2j01XgstIe7tBng=; b=mflICYL1syYT6P0n9kPkT5tIBC2rHnhMSj7I1jmhCNTR5GEGjm2OXTthVY4k1dogoA keLEa+m2hxCjxPo00R2RGZNjwxMdOxmX51utcjORHh6SlcAyKWCYpq7sbptUL51C3PlG 1zTJvh4nncFkoYZlcLlpj6vkZZasmeudFPO+JS1imYeYcugL2xwfi5qHWMaqe7kOSayg SqurIQx/wSLe8JUYn6CVHFIR1rqafoHAKVtwobHR8woCbV71nnVEjK8OZEE6H5giAW9X Mw23DSXZLcB70Dxf4XncPIgEPcLqqrGfYn9Bshwn0W+RitmgiikJuhUu+7lhFLxN5oJj 68uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402590; x=1705007390; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8OfSNqfYw1yegwimMaKEPeX4MqQs2j01XgstIe7tBng=; b=VqOVwGqWznCrv/If3OkOGclqSJKqv8lx98dILCGrmCgwQEBDdKO+G5P6RaUnCbvlnH I/FG7dZDrrNyADR57w8FDtFJYF/ZZAoL02/o+Qv4UB+PaQWQJr28OFL4tmnBtHCoHPlu lbKD0gGKgP8SizrPyqiXtJRYDsz1snxMQHn6svm2MzVvMhkZ1NGGd/5Sd7s3aSwHSRaM 6N0e2A6+RY9EnePH9Htn4lTvTHsOUorN6SEiv1+ETBzWlqaskJO5c5VNzmsq7hmI0K/l 6smK9vgUqXHwkKLPPU+dok41SLbvvgvXkgzddenBdn6WvE1aFwsObaluL0nnlGcKOxtG ECHg== X-Gm-Message-State: AOJu0YzABvl1PKxyadL7TR43wk8vfUnyF2gv6PJyPIgL+zQq7trFl/iE WiRQTj6nAStoD1xRiSKZJzpbjZ7HFC5c8g== X-Received: by 2002:a1c:7710:0:b0:40c:3905:51e4 with SMTP id t16-20020a1c7710000000b0040c390551e4mr676241wmi.68.1704402590483; Thu, 04 Jan 2024 13:09:50 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id m40-20020a05600c3b2800b0040d79907acasm6822175wms.26.2024.01.04.13.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:48 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C3A485F93F; Thu, 4 Jan 2024 21:09:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi Subject: [PATCH v9 07/11] docs/system: add a basic enumeration of vhost-user devices Date: Thu, 4 Jan 2024 21:09:41 +0000 Message-Id: <20240104210945.1223134-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Make it clear the vhost-user-device is intended for expert use only. Signed-off-by: Alex Bennée --- v5 - split vhost-user-device out of the table - sort the table alphabetically - add sound and scmi devices v6 - add note re vhost-user-device v7 - fix patching description --- docs/system/devices/vhost-user-rng.rst | 2 + docs/system/devices/vhost-user.rst | 70 +++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/docs/system/devices/vhost-user-rng.rst b/docs/system/devices/vhost-user-rng.rst index a145d4105c1..ead14053264 100644 --- a/docs/system/devices/vhost-user-rng.rst +++ b/docs/system/devices/vhost-user-rng.rst @@ -1,3 +1,5 @@ +.. _vhost_user_rng: + QEMU vhost-user-rng - RNG emulation =================================== diff --git a/docs/system/devices/vhost-user.rst b/docs/system/devices/vhost-user.rst index a80e95a48ae..c6afc4836f9 100644 --- a/docs/system/devices/vhost-user.rst +++ b/docs/system/devices/vhost-user.rst @@ -8,13 +8,81 @@ outside of QEMU itself. To do this there are a number of things required. vhost-user device -=================== +================= These are simple stub devices that ensure the VirtIO device is visible to the guest. The code is mostly boilerplate although each device has a ``chardev`` option which specifies the ID of the ``--chardev`` device that connects via a socket to the vhost-user *daemon*. +Each device will have an virtio-mmio and virtio-pci variant. See your +platform details for what sort of virtio bus to use. + +.. list-table:: vhost-user devices + :widths: 20 20 60 + :header-rows: 1 + + * - Device + - Type + - Notes + * - vhost-user-blk + - Block storage + - See contrib/vhost-user-blk + * - vhost-user-fs + - File based storage driver + - See https://gitlab.com/virtio-fs/virtiofsd + * - vhost-user-gpio + - Proxy gpio pins to host + - See https://github.com/rust-vmm/vhost-device + * - vhost-user-gpu + - GPU driver + - See contrib/vhost-user-gpu + * - vhost-user-i2c + - Proxy i2c devices to host + - See https://github.com/rust-vmm/vhost-device + * - vhost-user-input + - Generic input driver + - See contrib/vhost-user-input + * - vhost-user-rng + - Entropy driver + - :ref:`vhost_user_rng` + * - vhost-user-scmi + - System Control and Management Interface + - See https://github.com/rust-vmm/vhost-device + * - vhost-user-snd + - Audio device + - See https://github.com/rust-vmm/vhost-device/staging + * - vhost-user-scsi + - SCSI based storage + - See contrib/vhost-user-scsi + * - vhost-user-vsock + - Socket based communication + - See https://github.com/rust-vmm/vhost-device + +The referenced *daemons* are not exhaustive, any conforming backend +implementing the device and using the vhost-user protocol should work. + +vhost-user-device +^^^^^^^^^^^^^^^^^ + +The vhost-user-device is a generic development device intended for +expert use while developing new backends. The user needs to specify +all the required parameters including: + + - Device ``virtio-id`` + - The ``num_vqs`` it needs and their ``vq_size`` + - The ``config_size`` if needed + +.. note:: + To prevent user confusion you cannot currently instantiate + vhost-user-device without first patching out:: + + /* Reason: stop inexperienced users confusing themselves */ + dc->user_creatable = false; + + in ``vhost-user-device.c`` and ``vhost-user-device-pci.c`` file and + rebuilding. + vhost-user daemon ================= From patchwork Thu Jan 4 21:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759881 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183782wrw; Thu, 4 Jan 2024 13:12:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfrrrzDhv2vFaLRs3s+f6zlfy84uTM8I5h1F0ZBgF7Wp8VvVtjKMFQFMUn375aixS/bTBR X-Received: by 2002:a05:6214:27ce:b0:67a:cd6a:754c with SMTP id ge14-20020a05621427ce00b0067acd6a754cmr1405343qvb.33.1704402757114; Thu, 04 Jan 2024 13:12:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402757; cv=none; d=google.com; s=arc-20160816; b=LFoCv9CsaVp0AUJTBjrtAzIpYssGzWaqVE7o+KsDvCsK4Mis2Re42W0HsDRhCTxykY IKSfA1KewAxywLRrIG743rIMGFn1360iR/zuIrTW6P2wFxjkEUygLCL9cHJyMKNVDbzf hRmFNzdJ3TBw+0qHuDbR6aW0GQcXL00uDu83ivXsvKpd6RR0xu+ysDw59ojdHOJ916jW hPD0CA2Ds0kjupS0UWzuZAoA0LYKEQkwa3eXq73cOXJCYDZVF6jGlmKVuUTHhlrM6P7i rKCQ1AbVeVZOCNA3MUx0qWoNWpEnbgfnl811PmZX99LEaAsmxJSttaLoAF/Aax4nypc6 4mVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JUJr8BLQDLPEix8Bguij0E5/vO2xzpMTsHXu8b9VU1E=; fh=Ud52xLVns4YOXK9oAfV6buiiCgh2jRAKo3BCP7q+jII=; b=vxkWZG7fhDHYbrG55O2jIiSpDA1NrHNk/LDJ9OB/DGmkIGEf5XKkuBcFu7NiUwtv9G T7o8Ejuh34zZI76pudtuSuGdFR/z2fWPr42W5b6C1JRREPvWVPEdhDzMXvF4hZSGefLX 29IfQm7x8p72dK9HTa8Ps/O35Kl5AtDrAJsBTHpvhC5ayH86LGk3tBFKIdJRjA/vSVHA y6uuty1Kj2nMObYHBVPh9XWk6d6hq7p/YYvke1ipIlyQ82/WAxIizlMKzRJQWWJFjDz7 gv4KO44DBhSgihbzxZwnc/7I1jemYl8qCvFaxzwirFXxGfYRDaQLxbc0PZWp0UpBcjz2 J6BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aNDpaX4x; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n12-20020a0ce48c000000b0067f28a9598dsi308830qvl.282.2024.01.04.13.12.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:12:37 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aNDpaX4x; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUzV-0007gA-5N; Thu, 04 Jan 2024 16:11:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyR-0006vj-1v for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:55 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyO-0007SL-QZ for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:54 -0500 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40d88724fb9so10213285e9.3 for ; Thu, 04 Jan 2024 13:09:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402591; x=1705007391; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JUJr8BLQDLPEix8Bguij0E5/vO2xzpMTsHXu8b9VU1E=; b=aNDpaX4xV/syJ0BOIdcdBECwNiKxKBmHS+8AoTSFZA2FcfTmUFXRYfxUI1q63xv20P KAxacvNESVz6G+xmeolpSSpgkoiNaI3hAoGi68yE05zZ1ZXU7XpEtnij/SsbMZrrpsm2 AI5B6lzjsSoT93UJKDrbqJOfzb6f6teQnzraek1jh5cisWvWT+RofznY7SATpb06qelu YgvBr1N837bhe59SdS58Q5kUXOvhJHKc2NqfozFJZbmBlsAmBlWselVLTFWZ3NDaT9+z FkD6Qkv5PWMDker75ZsGa773Dkc/s9KShJXED0AqStlw+48IBRI7e60+IwuAMnqDrv6Y u/tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402591; x=1705007391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JUJr8BLQDLPEix8Bguij0E5/vO2xzpMTsHXu8b9VU1E=; b=i7Flu8kw1YwY6YXWSt4GKX2xXC99DmiHYqmqEJf8j4v/KayhKz4TuS0RTKgcXtzHbI kLa70YRhtiKWPcndadHuWqHRdqgHevdQnVNvaAkxwQnBlfJ/+d2ZGWUEZhKQLmjrwNgL ySVJkbg9xTkjI2+oZfq6Mtm489huNGZstCoCOu4q8xFBGdoEUU3uov8TAIIlB/T6mFJp SyRDKqzQLs9SPt4V1qBUOmS+0GFIRfy9q3lMYNA12ZGor3DL8X9s0RUyixUwvYOuETE7 7hWcomz+TfO4srIXmXC5NBUhaaLe9ghG/vgYIScFKMo1KL9WOxyUf0tUZn02fslKFVHa x1Ww== X-Gm-Message-State: AOJu0YwQBYrJAjkfMoGkxE11X1/mvo1HEYBUGa816Vg5aXrkSv1O4Iub 1ZWO7qAhtEMdEueSad4C6n7wb9jELIEmgg== X-Received: by 2002:a05:600c:a45:b0:40e:3511:2c39 with SMTP id c5-20020a05600c0a4500b0040e35112c39mr674820wmq.172.1704402590686; Thu, 04 Jan 2024 13:09:50 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id z10-20020a05600c0a0a00b0040d91fa270fsm352701wmp.36.2024.01.04.13.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:48 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id D828E5F940; Thu, 4 Jan 2024 21:09:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi , Leo Yan Subject: [PATCH v9 08/11] hw/virtio: Support set_config() callback in vhost-user-base Date: Thu, 4 Jan 2024 21:09:42 +0000 Message-Id: <20240104210945.1223134-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Leo Yan The Virtio input device invokes set_config() callback for retrieving the event configuration info, but the callback is not supported in vhost-user-base. This patch adds support set_config() callback in vhost-user-base. Signed-off-by: Leo Yan Reviewed-by: Marc-André Lureau Message-Id: <20231120043721.50555-2-leo.yan@linaro.org> Signed-off-by: Alex Bennée --- hw/virtio/vhost-user-base.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c index 78cfa9a5bbc..a83167191ee 100644 --- a/hw/virtio/vhost-user-base.c +++ b/hw/virtio/vhost-user-base.c @@ -140,6 +140,22 @@ static void vub_get_config(VirtIODevice *vdev, uint8_t *config) } } +static void vub_set_config(VirtIODevice *vdev, const uint8_t *config_data) +{ + VHostUserBase *vub = VHOST_USER_BASE(vdev); + int ret; + + g_assert(vub->config_size && vub->vhost_user.supports_config == true); + + ret = vhost_dev_set_config(&vub->vhost_dev, config_data, + 0, vub->config_size, + VHOST_SET_CONFIG_TYPE_FRONTEND); + if (ret) { + error_report("vhost guest set device config space failed: %d", ret); + return; + } +} + /* * When the daemon signals an update to the config we just need to * signal the guest as we re-read the config on demand above. @@ -337,6 +353,7 @@ static void vub_class_init(ObjectClass *klass, void *data) vdc->unrealize = vub_device_unrealize; vdc->get_features = vub_get_features; vdc->get_config = vub_get_config; + vdc->set_config = vub_set_config; vdc->set_status = vub_set_status; } From patchwork Thu Jan 4 21:09:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759875 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183321wrw; Thu, 4 Jan 2024 13:11:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOswJmMK4Xdp8+1yrci5tPAajEWdq9jRhXYY5XdPU6lg3F8h/r1zCJWiFTEKLyyLextel+ X-Received: by 2002:a05:622a:550:b0:428:142b:e405 with SMTP id m16-20020a05622a055000b00428142be405mr1630777qtx.42.1704402686481; Thu, 04 Jan 2024 13:11:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402686; cv=none; d=google.com; s=arc-20160816; b=AAQjnfW1v6Uzy5pCgz+CIuCA8Pxd7Llc8VED/VzzLg3kBxry6Onay9WliEza+coJYR 5m3BFNILx5ky9A1NFYdtSv/mxPQlfGTckJ2J6so9UDcBqeSm6xXc96Y4cGnlJjkq0Dc3 TmiMCj+k/hE9jw9DIACnOCK9T2/Clfq5uMl2mvecncthnE53ZudBuYQT03qUKY8cWlfc T8CpjIbNA09/tj21jEccSdkYsHfq7k9GwXKpjdFc8Nw3NzuBEHC6q8JHTTqelzKWuH6m e5/kboawCoS096QQrOZ+M7Ja3NjsNA6p4eyvJnoDO1mXA0I0Nuyn75Vw91wphCIyRlBp RtxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ObKwt//EhgHompi9v5X1bJx9VVsKykUNbS0pmE1n/mg=; fh=Ud52xLVns4YOXK9oAfV6buiiCgh2jRAKo3BCP7q+jII=; b=J8+2IyFRuCjx66qY6pjR27d6qWTSPk8ObMJ5RI/rRduahWJm42V7mBYjf/2upInhWR 501HI6mZQwEOD/BaTpCiQAJUhcfYSZHfqytPP43OMCDJmDoYHQRmtYR+YSGMksmZpqYc abrVREjlzc3+OZbZoBd2vy74SlpJgu9ixkP0fafKAb9YLdz75BEMHh9ohkTZ44cSXwHY qJ4Ly5TxaFyrjYCbZDLWEnMlMN56EIAAfTEYukqDab/B5LiKyOdJ1ZJwvrfc3JoIW+aw 5HWrVaIcI3C/VfFpG6YdTV7Bct4U4cY6YVpHc9N2IJyS/ajy6HFDrl/ZV0GLU1GONVir 5GIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OU2uwP39; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g2-20020ac87f42000000b004283ef47c2asi388249qtk.109.2024.01.04.13.11.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:11:26 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OU2uwP39; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUz4-000770-F5; Thu, 04 Jan 2024 16:10:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyU-0006wr-Kz for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:59 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyS-0007Uy-43 for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:58 -0500 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3367a304091so746452f8f.3 for ; Thu, 04 Jan 2024 13:09:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402594; x=1705007394; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ObKwt//EhgHompi9v5X1bJx9VVsKykUNbS0pmE1n/mg=; b=OU2uwP397KAm1ZEdhQjXLEzjpSaCFAc6gk+pwolayN8MsHArE54Zqi5rqu/1UMUIqq dGyR98wO7QLzX1+bzDmBY5QFqxROE7O592BuzpvH/05644C53ojzmOp5Ah8jtba9Y3r1 7YCAx1RZ4u20eVOynwIC76jKwTs/zv7dPVjnrx7W3N6RIPN5zTvunIgJPRh/QpHKWBk9 UUfa9XlypS18DAGjWZ4p7uB2mH3vhwR1ijchLQxDwwJe5hAn5jsljwJTdB81MrpY6gjV GjFA7/w3YqOPQkGJSwOycQS/2Oc1GWqt3g1CLyCjix9hZyHtZuoTk+JThQjSPePKHzKY F4dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402594; x=1705007394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ObKwt//EhgHompi9v5X1bJx9VVsKykUNbS0pmE1n/mg=; b=xRpuBVyTaHijfX40HFULGqcsWe8dq3l4FuAP8z6CLqkMeNWE1MmAiq320P4BJrkdvE 7ovC/plgqJGAZhGqUYNJcFYB/axuSXBSVW1Mb6P0h/wzJmuoJcFNJTTsgsBkt+uFKmhC lEInkgaVLK4dchYicG2wC1TIM8PQ+9hZZRcQnIVRxlQlhtDbc+tL/3HeB2d995fc/a7u SjSBiR6hIwsVFZ9j+cihrjRfRa2QOYNGmgyppesYwm99NwYU46MlOBijJQCVEanFvwy5 jvDNjRUOXqih4DND6dxnesYZyNzdg1PStktIz6Q6qTIrZHHZMkrkHHQF63MzwjldEcqD vNSA== X-Gm-Message-State: AOJu0YxYqo7YyOsj8riwYMrhr2kn9ubLnEyOimdv/2FU1qumebFaNjr2 f+QMN/7Y4vnvLZEQUPcJuTF87smBCklTWQ== X-Received: by 2002:a5d:4ecf:0:b0:336:6e2f:930e with SMTP id s15-20020a5d4ecf000000b003366e2f930emr407735wrv.176.1704402594551; Thu, 04 Jan 2024 13:09:54 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id j3-20020a056000124300b003368c8d120fsm110223wrx.7.2024.01.04.13.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:53 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id EFA455F942; Thu, 4 Jan 2024 21:09:45 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi , Leo Yan Subject: [PATCH v9 09/11] docs/system: Add vhost-user-input documentation Date: Thu, 4 Jan 2024 21:09:43 +0000 Message-Id: <20240104210945.1223134-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Leo Yan This adds basic documentation for vhost-user-input. Signed-off-by: Leo Yan Message-Id: <20231120043721.50555-3-leo.yan@linaro.org> Signed-off-by: Alex Bennée --- MAINTAINERS | 1 + docs/system/device-emulation.rst | 1 + docs/system/devices/vhost-user-input.rst | 45 ++++++++++++++++++++++++ docs/system/devices/vhost-user.rst | 4 ++- 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 docs/system/devices/vhost-user-input.rst diff --git a/MAINTAINERS b/MAINTAINERS index 607f71817f8..ff70987aeb3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2274,6 +2274,7 @@ L: virtio-fs@lists.linux.dev virtio-input M: Gerd Hoffmann S: Odd Fixes +F: docs/system/devices/vhost-user-input.rst F: hw/input/vhost-user-input.c F: hw/input/virtio-input*.c F: include/hw/virtio/virtio-input.h diff --git a/docs/system/device-emulation.rst b/docs/system/device-emulation.rst index d1f3277cb02..f19777411cd 100644 --- a/docs/system/device-emulation.rst +++ b/docs/system/device-emulation.rst @@ -94,6 +94,7 @@ Emulated Devices devices/virtio-gpu.rst devices/virtio-pmem.rst devices/virtio-snd.rst + devices/vhost-user-input.rst devices/vhost-user-rng.rst devices/canokey.rst devices/usb-u2f.rst diff --git a/docs/system/devices/vhost-user-input.rst b/docs/system/devices/vhost-user-input.rst new file mode 100644 index 00000000000..118eb78101c --- /dev/null +++ b/docs/system/devices/vhost-user-input.rst @@ -0,0 +1,45 @@ +.. _vhost_user_input: + +QEMU vhost-user-input - Input emulation +======================================= + +This document describes the setup and usage of the Virtio input device. +The Virtio input device is a paravirtualized device for input events. + +Description +----------- + +The vhost-user-input device implementation was designed to work with a daemon +polling on input devices and passes input events to the guest. + +QEMU provides a backend implementation in contrib/vhost-user-input. + +Linux kernel support +-------------------- + +Virtio input requires a guest Linux kernel built with the +``CONFIG_VIRTIO_INPUT`` option. + +Examples +-------- + +The backend daemon should be started first: + +:: + + host# vhost-user-input --socket-path=input.sock \ + --evdev-path=/dev/input/event17 + +The QEMU invocation needs to create a chardev socket to communicate with the +backend daemon and access the VirtIO queues with the guest over the +:ref:`shared memory `. + +:: + + host# qemu-system \ + -chardev socket,path=/tmp/input.sock,id=mouse0 \ + -device vhost-user-input-pci,chardev=mouse0 \ + -m 4096 \ + -object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \ + -numa node,memdev=mem \ + ... diff --git a/docs/system/devices/vhost-user.rst b/docs/system/devices/vhost-user.rst index c6afc4836f9..9b2da106cec 100644 --- a/docs/system/devices/vhost-user.rst +++ b/docs/system/devices/vhost-user.rst @@ -42,7 +42,7 @@ platform details for what sort of virtio bus to use. - See https://github.com/rust-vmm/vhost-device * - vhost-user-input - Generic input driver - - See contrib/vhost-user-input + - :ref:`vhost_user_input` * - vhost-user-rng - Entropy driver - :ref:`vhost_user_rng` @@ -91,6 +91,8 @@ following the :ref:`vhost_user_proto`. There are a number of daemons that can be built when enabled by the project although any daemon that meets the specification for a given device can be used. +.. _shared_memory_object: + Shared memory object ==================== From patchwork Thu Jan 4 21:09:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759882 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183844wrw; Thu, 4 Jan 2024 13:12:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFctLSjL5RotccfV+Yy1OrEVcteUkp1RNoPX8nToUsDG/wDwR1AyuKz0xn3bJUu8g1Qvxp9 X-Received: by 2002:a05:6808:f10:b0:3bc:d0:ac71 with SMTP id m16-20020a0568080f1000b003bc00d0ac71mr1338060oiw.24.1704402772629; Thu, 04 Jan 2024 13:12:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402772; cv=none; d=google.com; s=arc-20160816; b=fFlBfTqnbSOIW9UBnZfPdduAF8CwA0u08xD52lImpHW4iFUUR2A6JCgglVyfsz3fiO 5TqrnswzOnDpZqsxxUNVd8z57xnq5sZjaALvHlE8nc5GssY6HKRaOXMSpqpl1PC2bMDq FX3ccGhW1fI6ycFUOGwTeFINfZI+Sns7VF1NkG0FKPLm9onh3FWY6uqRmNus78jI57b3 tDADXmBqqQb0UbIkywdiS94f9WKBnu4+g9JRzKJgGMmlOfE0cO3GkCJuD1GVPCQ5MIsJ U6nLxR1xVQf4u0fUfTVRl44hMdmIQ+RsHWQUtY7s/ida4G27LvLZ41ysgGi+hlar8oX8 1gtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zpHAzaxTJd2Vec5B4UMxY6RAVe5qp1syQpkc++MJBDc=; fh=Ud52xLVns4YOXK9oAfV6buiiCgh2jRAKo3BCP7q+jII=; b=VfWD8zaCgFH6GXkMVQEkPZPyCOknIbYnsAhf6paGFoYbxRsHI2zi1J31taD+Q5znFE ETHHPcLTNTrgBGKYOHTsi7XBRKExDaq/ZUJGOxfVTlViqELk3qgORnZbOl2CqIsjF0Hr +ZPLmtNfBtsNU/NNnuTStW9uiXhx9ejnvb6L8QvTrkaZLWlQ6Cnmek9bK2e//ItCEcDF oQuMqWc01Dfb9T3bJQrN/iisaw99dxxzNvJgRWvGEcDAd/H5vZC2gmt0Ftwsew5r1oZH LHdpCNyTjAKligT+MtHoMxNTfw7Z8UQAAI13G6l4SaAGqVSuD7Y7y2YPbHG/appaltgH y13g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h2KQymzd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t21-20020a05620a451500b00781cb2e8277si333593qkp.133.2024.01.04.13.12.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:12:52 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h2KQymzd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUzT-0007XU-UQ; Thu, 04 Jan 2024 16:10:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyV-0006ww-FK for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:10:00 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyS-0007V3-Dr for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:59 -0500 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40d60c49ee7so9243295e9.0 for ; Thu, 04 Jan 2024 13:09:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402594; x=1705007394; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zpHAzaxTJd2Vec5B4UMxY6RAVe5qp1syQpkc++MJBDc=; b=h2KQymzdBk5p3CjRKSsD7qYmEBdFEtMMCbPbEv7JPR1AQ0kZCDcO1+mioyce/wrlbp LzFVCEpuNqkpv0r51hmTYDWOn+whCTZsqVaVllp3d96+aUXqLMHA42UxgKJSFPGYXHdS 0uYoBdz5mBecY3G/SF4vlxv/pbb5W4H4Lum/1rdYay+ae9Zfie9chYx6Z99hJzKkOOfm FLwKWFHb7nG4f2Z29STWGkF/QlB3p8F/YIKjdf2Rvz+D012dlT0w5yol/721R0V9AxtI h0u8Isy/uzIijLG9nNJUC5Rj/wmrO3AlAcNCzNSbSkMnNify9MGaH/4Qk6ZhMSO2QdkP iVzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402594; x=1705007394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zpHAzaxTJd2Vec5B4UMxY6RAVe5qp1syQpkc++MJBDc=; b=XAZrbOfX8owaUSYayoADC40Z5lUs3PAySkQvGmNsHTMc0vH0cMaSNDsI5Q/Z46Xzqt SNDUheqUNoyMXoowYeKNbUOQbhhM3A2q3it2s5xyW8V3un6Rx7US/gO0dZO9CMaULkob TQWqW7VkyScfV0BSqtD9boCzQ0MBqdRz3woZnXxu/YbzKwXpt7kyfvKcoYgp1x8ItkvX YYn37fB3jmt7iZvG9zEN8tSnjp7CP1+2BFyb4i677FY2a3iPCSE+vfp/1HMts7SbO8Hu sLmOFOyv1YWHl3Vl887TBa683arBsoavkl1hMCVfqQhVpwnRLyZtVbr4Ek0Y0OxOWxJM LEmA== X-Gm-Message-State: AOJu0Ywn3FDuW8yyryn9nI7Zec6NbBb8H/lUpk/MAk5Q7YyTT//1/LnQ IlHzVOplX1J6jXdnJPHCywCUfy8xo6djxA== X-Received: by 2002:a7b:c8d3:0:b0:40d:87ed:7c80 with SMTP id f19-20020a7bc8d3000000b0040d87ed7c80mr711291wml.18.1704402594740; Thu, 04 Jan 2024 13:09:54 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id f17-20020a05600c155100b0040d934f48d3sm353945wmg.32.2024.01.04.13.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:53 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 141C95F944; Thu, 4 Jan 2024 21:09:46 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi , Leo Yan Subject: [PATCH v9 10/11] hw/virtio: Move vhost-user-input into virtio folder Date: Thu, 4 Jan 2024 21:09:44 +0000 Message-Id: <20240104210945.1223134-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Leo Yan vhost-user-input is in the input folder. On the other hand, the folder 'hw/virtio' maintains other virtio stubs (e.g. I2C, RNG, GPIO, etc). This patch moves vhost-user-input into the virtio folder for better code organization. No functionality change. Signed-off-by: Leo Yan Reviewed-by: Manos Pitsidianakis Message-Id: <20231120043721.50555-4-leo.yan@linaro.org> Signed-off-by: Alex Bennée --- MAINTAINERS | 2 +- hw/{input => virtio}/vhost-user-input.c | 0 hw/input/meson.build | 1 - hw/virtio/meson.build | 4 +++- 4 files changed, 4 insertions(+), 3 deletions(-) rename hw/{input => virtio}/vhost-user-input.c (100%) diff --git a/MAINTAINERS b/MAINTAINERS index ff70987aeb3..66bd1eadc78 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2275,8 +2275,8 @@ virtio-input M: Gerd Hoffmann S: Odd Fixes F: docs/system/devices/vhost-user-input.rst -F: hw/input/vhost-user-input.c F: hw/input/virtio-input*.c +F: hw/virtio/vhost-user-input.c F: include/hw/virtio/virtio-input.h F: contrib/vhost-user-input/* diff --git a/hw/input/vhost-user-input.c b/hw/virtio/vhost-user-input.c similarity index 100% rename from hw/input/vhost-user-input.c rename to hw/virtio/vhost-user-input.c diff --git a/hw/input/meson.build b/hw/input/meson.build index 640556bbbcc..3cc8ab85f0c 100644 --- a/hw/input/meson.build +++ b/hw/input/meson.build @@ -11,7 +11,6 @@ system_ss.add(when: 'CONFIG_TSC2005', if_true: files('tsc2005.c')) system_ss.add(when: 'CONFIG_VIRTIO_INPUT', if_true: files('virtio-input.c')) system_ss.add(when: 'CONFIG_VIRTIO_INPUT', if_true: files('virtio-input-hid.c')) system_ss.add(when: 'CONFIG_VIRTIO_INPUT_HOST', if_true: files('virtio-input-host.c')) -system_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input.c')) system_ss.add(when: 'CONFIG_PXA2XX', if_true: files('pxa2xx_keypad.c')) system_ss.add(when: 'CONFIG_TSC210X', if_true: files('tsc210x.c')) diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 118d4d4da7c..c924afcafc0 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -25,6 +25,7 @@ if have_vhost system_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) system_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) system_virtio_ss.add(when: 'CONFIG_VHOST_USER_SND', if_true: files('vhost-user-snd.c')) + system_virtio_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input.c')) # PCI Stubs system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('vhost-user-device-pci.c')) @@ -36,6 +37,8 @@ if have_vhost if_true: files('vhost-user-rng-pci.c')) system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SND'], if_true: files('vhost-user-snd-pci.c')) + system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_INPUT'], + if_true: files('vhost-user-input-pci.c')) endif if have_vhost_vdpa system_virtio_ss.add(files('vhost-vdpa.c')) @@ -59,7 +62,6 @@ virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk-pci.c')) -virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_SCSI', if_true: files('vhost-user-scsi-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-pci.c')) From patchwork Thu Jan 4 21:09:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759879 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183737wrw; Thu, 4 Jan 2024 13:12:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSbos4L8eTvZ62HKS4OvUegGDRupCipuOMS+gqrF8K9rn9HkYpMuGRaFhgH/7cOBpo1BJp X-Received: by 2002:a25:910c:0:b0:dbd:ad04:1cf6 with SMTP id v12-20020a25910c000000b00dbdad041cf6mr1073260ybl.27.1704402751339; Thu, 04 Jan 2024 13:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402751; cv=none; d=google.com; s=arc-20160816; b=nMh35PZYuN4QmpNonfg3mAEltVJLxQwYDtyhGJU5+opwcFxJ+mUt58O5e2qCwW16B6 TjscetrD5m+xHSEIofU1Q/JKMelFrOil6a7nnx953e+OyASfFSaK6OwGtFtrz4xgziGR DjaLR+ujss9pFmaAABPz0g+LbROc1HzQaC7sTLDFTF/Q3znOZUxqmIWTTuD1SHQgCf3g +e0omY+7ErGNdETuEt0yKmVwhbUn+GHtubHLBdF6f9bIhs/Tg+UGdEdhUTBCf6PsQOrJ mK3p1CUqK/dZtSjwMycuPDqczO60AjwJdY4wObNQ1CDL6AXDDlA1VPSFCPiKX3Qdwmx6 DOTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YUt/1uqyWaURmVAVVhlqD6XH9TChabURPi6+UCY421E=; fh=Ud52xLVns4YOXK9oAfV6buiiCgh2jRAKo3BCP7q+jII=; b=HYUtzLXnIeuHKimJIKhT5HxlO9dJpMo/mC8s3Esc6vk/K0Vr3NOM8UoBsCtpOpFnWz PajvXleEvDi7b3kdrqv/+JiEajNIxVpKomCKOnMKjFbiAbKdDeGXAabLI/MsYZ6Rt/gq a/Di2Z9saLXwTPPsWSNdura3U+vtkRow2o7zdFXyHIlXdSaz2MFJCjs9GK7ppqx+EKCU PitM3FjnUdATjDfLwrFvJzGcalmF69dmwIz/n/EUidjnbEM1zuQxrjaNPHlQ0CIWMD6B 6V16Q6YPF+z1l0DQCF292u5R2/CkG2u6QX369e4CfX7E4AAv9GtYNl46zbsQmp4vQqFU YTGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gOKRMYXj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 17-20020ac85951000000b004288831c10csi390111qtz.180.2024.01.04.13.12.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:12:31 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gOKRMYXj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUzV-0007oI-KV; Thu, 04 Jan 2024 16:11:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyW-0006xd-V7 for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:10:04 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyT-0007VA-1F for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:59 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3367632ce7bso685406f8f.2 for ; Thu, 04 Jan 2024 13:09:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402595; x=1705007395; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YUt/1uqyWaURmVAVVhlqD6XH9TChabURPi6+UCY421E=; b=gOKRMYXj0XR5JMaNzepaez0PaMD37d/3Cr75TrriUzoOjTQPE2qu1ube7hGYyc5zRX UETsDwFsPs/U17YH66GL846/Wo2RnSFn5i2dPM85vZYZC5ohD+ka8wIflukQrYZh3AWe ebBEkfETayg6p96YdipMyFZUAsIKhy3ATnt90wr0X2PmjTvEHXzbdR4IywzSGKiFH8p7 qEcE6cIvPdLbBd2u0D4TIlhX0BJN9Gv3xq9hPgI9FmDl8P2LBEYumTEIomdIcgqIBEL6 nhjFcJUrbw2HHYnGcx23TU5okhuXTQK3z2M9TMejO+FeR+XBhyV7//3UA2lgLG2/Eo22 cuKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402595; x=1705007395; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YUt/1uqyWaURmVAVVhlqD6XH9TChabURPi6+UCY421E=; b=eGXC0efE0KXWpkpJugKDBm+jmscuARaAugvjTlgS2al5A3B/Myii5+DhGd6ab6Wl5t hzQ95Wft2ZnUE2i0MHI99CWuNxp8F7xH1w6YYrlZuBTcKxp4UMLUSYmr/GeOlCHp2KFn Wj/pFA3mN8lSska+iB1srS53dlRueOYEjT5ep0u/dqQlL/HUX0KuoMTbzu4oi3qKGSAZ 7uvFVH5VzRtwFub4sQt1MjDqrcCsY7HH/LhmyuMeYP2CQFUEmlvd/Ex/H1foVNTOqka5 JG7Qm13q1kznVYKuqAzv8szM42Zu1icxJvxo8l7orMzKiw6lrte7Ap5PY4+ddC1PIgcY nx3Q== X-Gm-Message-State: AOJu0YySppVL5g71i/LwtwWN7xcb7jl0059/Q7YEGHLR6b5u1aX4QxAP IV249gvIcj034PML9VvFfRnGZwDzjjM8FQ== X-Received: by 2002:a5d:5d0e:0:b0:336:7a5c:ffdf with SMTP id ch14-20020a5d5d0e000000b003367a5cffdfmr902957wrb.13.1704402595038; Thu, 04 Jan 2024 13:09:55 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id f17-20020adfc991000000b0033609b71825sm107862wrh.35.2024.01.04.13.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:53 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 2B0755F92F; Thu, 4 Jan 2024 21:09:46 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi , Leo Yan Subject: [PATCH v9 11/11] hw/virtio: derive vhost-user-input from vhost-user-base Date: Thu, 4 Jan 2024 21:09:45 +0000 Message-Id: <20240104210945.1223134-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Leo Yan This patch derives vhost-user-input from vhost-user-base class, so make the input stub as a simpler boilerplate wrapper. With the refactoring, vhost-user-input adds the property 'chardev', this leads to conflict with the vhost-user-input-pci adds the same property. To resolve the error, remove the duplicate property from vhost-user-input-pci. Signed-off-by: Leo Yan Reviewed-by: Manos Pitsidianakis Message-Id: <20231120043721.50555-5-leo.yan@linaro.org> Signed-off-by: Alex Bennée --- include/hw/virtio/virtio-input.h | 6 +- hw/virtio/vhost-user-input-pci.c | 3 - hw/virtio/vhost-user-input.c | 114 +++++-------------------------- 3 files changed, 21 insertions(+), 102 deletions(-) diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h index a6c97036440..e69c0aeca38 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -1,6 +1,8 @@ #ifndef QEMU_VIRTIO_INPUT_H #define QEMU_VIRTIO_INPUT_H +#include "hw/virtio/vhost-user.h" +#include "hw/virtio/vhost-user-base.h" #include "ui/input.h" #include "sysemu/vhost-user-backend.h" @@ -97,9 +99,7 @@ struct VirtIOInputHost { }; struct VHostUserInput { - VirtIOInput parent_obj; - - VhostUserBackend *vhost; + VHostUserBase parent_obj; }; void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event); diff --git a/hw/virtio/vhost-user-input-pci.c b/hw/virtio/vhost-user-input-pci.c index b858898a363..3f4761ce88a 100644 --- a/hw/virtio/vhost-user-input-pci.c +++ b/hw/virtio/vhost-user-input-pci.c @@ -30,9 +30,6 @@ static void vhost_user_input_pci_instance_init(Object *obj) virtio_instance_init_common(obj, &dev->vhi, sizeof(dev->vhi), TYPE_VHOST_USER_INPUT); - - object_property_add_alias(obj, "chardev", - OBJECT(&dev->vhi), "chardev"); } static const VirtioPCIDeviceTypeInfo vhost_user_input_pci_info = { diff --git a/hw/virtio/vhost-user-input.c b/hw/virtio/vhost-user-input.c index 4ee3542106e..bedec0468c3 100644 --- a/hw/virtio/vhost-user-input.c +++ b/hw/virtio/vhost-user-input.c @@ -5,83 +5,25 @@ */ #include "qemu/osdep.h" -#include "qemu/error-report.h" -#include "qapi/error.h" - #include "hw/virtio/virtio-input.h" -static int vhost_input_config_change(struct vhost_dev *dev) -{ - error_report("vhost-user-input: unhandled backend config change"); - return -1; -} - -static const VhostDevConfigOps config_ops = { - .vhost_dev_config_notifier = vhost_input_config_change, +static Property vinput_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_END_OF_LIST(), }; -static void vhost_input_realize(DeviceState *dev, Error **errp) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(dev); - VirtIOInput *vinput = VIRTIO_INPUT(dev); - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - - vhost_dev_set_config_notifier(&vhi->vhost->dev, &config_ops); - vinput->cfg_size = sizeof_field(virtio_input_config, u); - if (vhost_user_backend_dev_init(vhi->vhost, vdev, 2, errp) == -1) { - return; - } -} - -static void vhost_input_change_active(VirtIOInput *vinput) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(vinput); - - if (vinput->active) { - vhost_user_backend_start(vhi->vhost); - } else { - vhost_user_backend_stop(vhi->vhost); - } -} - -static void vhost_input_get_config(VirtIODevice *vdev, uint8_t *config_data) -{ - VirtIOInput *vinput = VIRTIO_INPUT(vdev); - VHostUserInput *vhi = VHOST_USER_INPUT(vdev); - Error *local_err = NULL; - int ret; - - memset(config_data, 0, vinput->cfg_size); - - ret = vhost_dev_get_config(&vhi->vhost->dev, config_data, vinput->cfg_size, - &local_err); - if (ret) { - error_report_err(local_err); - return; - } -} - -static void vhost_input_set_config(VirtIODevice *vdev, - const uint8_t *config_data) +static void vinput_realize(DeviceState *dev, Error **errp) { - VHostUserInput *vhi = VHOST_USER_INPUT(vdev); - int ret; + VHostUserBase *vub = VHOST_USER_BASE(dev); + VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev); - ret = vhost_dev_set_config(&vhi->vhost->dev, config_data, - 0, sizeof(virtio_input_config), - VHOST_SET_CONFIG_TYPE_FRONTEND); - if (ret) { - error_report("vhost-user-input: set device config space failed"); - return; - } + /* Fixed for input device */ + vub->virtio_id = VIRTIO_ID_INPUT; + vub->num_vqs = 2; + vub->vq_size = 4; + vub->config_size = sizeof(virtio_input_config); - virtio_notify_config(vdev); -} - -static struct vhost_dev *vhost_input_get_vhost(VirtIODevice *vdev) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(vdev); - return &vhi->vhost->dev; + vubc->parent_realize(dev, errp); } static const VMStateDescription vmstate_vhost_input = { @@ -91,40 +33,20 @@ static const VMStateDescription vmstate_vhost_input = { static void vhost_input_class_init(ObjectClass *klass, void *data) { - VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass); - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); dc->vmsd = &vmstate_vhost_input; - vdc->get_config = vhost_input_get_config; - vdc->set_config = vhost_input_set_config; - vdc->get_vhost = vhost_input_get_vhost; - vic->realize = vhost_input_realize; - vic->change_active = vhost_input_change_active; -} - -static void vhost_input_init(Object *obj) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(obj); - - vhi->vhost = VHOST_USER_BACKEND(object_new(TYPE_VHOST_USER_BACKEND)); - object_property_add_alias(obj, "chardev", - OBJECT(vhi->vhost), "chardev"); -} - -static void vhost_input_finalize(Object *obj) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(obj); - - object_unref(OBJECT(vhi->vhost)); + device_class_set_props(dc, vinput_properties); + device_class_set_parent_realize(dc, vinput_realize, + &vubc->parent_realize); + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); } static const TypeInfo vhost_input_info = { .name = TYPE_VHOST_USER_INPUT, - .parent = TYPE_VIRTIO_INPUT, + .parent = TYPE_VHOST_USER_BASE, .instance_size = sizeof(VHostUserInput), - .instance_init = vhost_input_init, - .instance_finalize = vhost_input_finalize, .class_init = vhost_input_class_init, };