From patchwork Mon Sep 27 22:13:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 514735 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp4555560jao; Mon, 27 Sep 2021 15:24:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnFxH1IX+waxl6Xx/sEfUHv3tMKoybFsRBloOcAow3mZZuW25XDaMmrpMPVFsnJDC1g6UA X-Received: by 2002:a4a:ba90:: with SMTP id d16mr1943660oop.31.1632781469352; Mon, 27 Sep 2021 15:24:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632781469; cv=none; d=google.com; s=arc-20160816; b=ZzDLaV0GWZa27wlOZYcABlz7vhemnE18x6JHeYFnL9Xxxl9cD6pxICbWe5stAp+5z0 uW1vGZbe/RNacvkUTtCzP7WHMhMzoX2bNx/9CEflcI1ZDX+ztbTVu0/G/DesvREDgWeZ 3iJqlLSC7SUnuGtjCcUhCr5KDaIrazYH4BhOfxgQAmTG1CLP/wJhhiCiAiXMtO9YEVPP GeQsDVwlLGngprFpQ/CB+7hlqzo0Uy7DXyS83KMPFzSIpWia0ZLkrn93bPQOqwROhgzz rDTyS2PgAb8UJm/7GE/8nfxhbS7kLZlRhTgRqDsC+6aAnGyayG80OS5eKPqyOvqOW/bg PvHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=vhj6xazBaJToXUVOSdB9AuUCAs0ejcKbfrLA1IUKsDg=; b=em+hjF2fR2xJLwQPyJmV8YabbfwAsvJPDMyev2XrLkWjirpVy0kcmH81dwoOyXWUEl W8GFyLofiiTs3HOjEgnmwwYaAG+69Yf4L7E/HwCwqEsj9OvgSrkFSHxBWNZxICTXSBap tM47wTecD+7FKgsQA9vd9UoN9va2Y80T/pB5FsAJNKvskP3mBc4hiNPMN6uSyo+RG83x LipSJStimHY6ZdMIXXJIc7umZ60Vj3nLHCQJhC1oaKYRRR9hAUJ5kuhotfl0Xp34Yl1b 7Id0Ak+XzS5KOZen+04K+4CJYU7m6jqflrdu87IWM7z8PTZGPeCQrhz+NWKsa0bsZL7a 8Fxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dgf28wDH; 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 p15si17758018otl.45.2021.09.27.15.24.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Sep 2021 15:24:29 -0700 (PDT) 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=dgf28wDH; 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]:34038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUz2y-0004TV-Pr for patch@linaro.org; Mon, 27 Sep 2021 18:24:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUyt1-0000yJ-3v for qemu-devel@nongnu.org; Mon, 27 Sep 2021 18:14:11 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:40599) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUysy-0005xB-TK for qemu-devel@nongnu.org; Mon, 27 Sep 2021 18:14:10 -0400 Received: by mail-pj1-x102a.google.com with SMTP id d4-20020a17090ad98400b0019ece228690so246791pjv.5 for ; Mon, 27 Sep 2021 15:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vhj6xazBaJToXUVOSdB9AuUCAs0ejcKbfrLA1IUKsDg=; b=dgf28wDHd3fbzfkteSK7AbNJUBU+xGyp6XbbdOEE4a53jvgfYzO3oS57FhopZaFFc1 4z47pgNNx+YSOiAk3uQw4wg4+FZl4rQDVKQb6eKoTG2o/OPpev8Ptr9x7v1KFlqMqWZl OGmchlVqrp0jVXkNuMzFEQljSkv/k9+DAS9t8yw5jP4DPWNB6O9iCgmxq8MB1JOO6nia VmtjRKCvt36N0i7+1aChadsQ+8K/0B2DB/MIiFLl8/ZrwGrfOfAaqrIoxV8IpwYrJMAE 53oDuZtbuUzijIZSz8G4UC3aPVhQQeA1x4DQCc4xAJ00jQJkCgWX3XYX6AFUX/IBCJ8D r7Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vhj6xazBaJToXUVOSdB9AuUCAs0ejcKbfrLA1IUKsDg=; b=ZdCF9RH26um+0RMzL7BB0mxirDy5mKRYpokz/l6x1p3bYdoZCeNiACtRVlY7gRvz7n FjLe+Uu0FMJPQczMe/AdTFn+CdPS1pAK0r5jqPBS5CsCr7QkQgDUmoVcZwO9r6iA5ifG C5kXi1YA7jtCBxikdHiZlNvrHdqAWSI3xh4nH/sr8/hJQopZCldhLL93ebJExx44w76X 9bMsqxvD9+4VZdWtXT20o8mvOka8jGvFNH3mtXCNfpjlXhIrLuvtoN0g2qBNqz0S9ne9 +U5uCcQBtn69jTEDSi6Gla0OszgyorXkQIcrRBF8EMuF19hJ1lpQFqhKEp1ycX1A+geO 7UPQ== X-Gm-Message-State: AOAM5336YmroHQyfbiAdS1Rbl30+UXxMnayru1iuCzevIaoJ4ULSDiIq GCWTH7/sXzeJHbL1lYa4TZSCvg== X-Received: by 2002:a17:902:a710:b029:12b:9b9f:c461 with SMTP id w16-20020a170902a710b029012b9b9fc461mr2053119plq.59.1632780847087; Mon, 27 Sep 2021 15:14:07 -0700 (PDT) Received: from p14s.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id g27sm18817742pfk.173.2021.09.27.15.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 15:14:05 -0700 (PDT) From: Mathieu Poirier To: mst@redhat.com Subject: [PATCH v4 1/3] vhost-user-rng: Add vhost-user-rng implementation Date: Mon, 27 Sep 2021 16:13:57 -0600 Message-Id: <20210927221359.2917482-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210927221359.2917482-1-mathieu.poirier@linaro.org> References: <20210927221359.2917482-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=mathieu.poirier@linaro.org; helo=mail-pj1-x102a.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Introduce a random number generator (RNG) backend that communicates with a vhost-user server to retrieve entropy. That way other VMM that comply with the vhost user protocl can use the same vhost-user daemon without having to write yet another RNG driver. Reviewed-by: Alex Bennée Signed-off-by: Mathieu Poirier --- hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + hw/virtio/vhost-user-rng.c | 289 +++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-rng.h | 33 ++++ 4 files changed, 328 insertions(+) create mode 100644 hw/virtio/vhost-user-rng.c create mode 100644 include/hw/virtio/vhost-user-rng.h -- 2.25.1 diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 35ab45e2095c..c144d42f9bd0 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -63,3 +63,8 @@ config VHOST_USER_I2C bool default y depends on VIRTIO && VHOST_USER + +config VHOST_USER_RNG + bool + default y + depends on VIRTIO && VHOST_USER diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index bc352a600911..ae6b2cde1068 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -27,6 +27,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], if_true: files('vhost-user-i2c-pci.c')) +virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c')) diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c new file mode 100644 index 000000000000..209ee5bf9acd --- /dev/null +++ b/hw/virtio/vhost-user-rng.c @@ -0,0 +1,289 @@ +/* + * Vhost-user RNG virtio device + * + * Copyright (c) 2021 Mathieu Poirier + * + * Implementation seriously tailored on vhost-user-i2c.c + * + * 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-rng.h" +#include "qemu/error-report.h" +#include "standard-headers/linux/virtio_ids.h" + +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); + 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); + + 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 = status & VIRTIO_CONFIG_S_DRIVER_OK; + + if (!vdev->vm_running) { + should_start = false; + } + + if (rng->vhost_dev.started == 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) +{ + /* No feature bits used yet */ + return 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); + + 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); + + 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 (rng->vhost_dev.started) { + 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, "vhost-user-rng", 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: + 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); + + vu_rng_set_status(vdev, 0); + + vhost_dev_cleanup(&rng->vhost_dev); + g_free(rng->vhost_dev.vqs); + rng->vhost_dev.vqs = NULL; + virtio_delete_queue(rng->req_vq); + virtio_cleanup(vdev); + vhost_user_cleanup(&rng->vhost_user); +} + +static const VMStateDescription vu_rng_vmstate = { + .name = "vhost-user-rng", + .unmigratable = 1, +}; + +static Property vu_rng_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserRNG, chardev), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vu_rng_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, vu_rng_properties); + dc->vmsd = &vu_rng_vmstate; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + + 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; +} + +static const TypeInfo vu_rng_info = { + .name = TYPE_VHOST_USER_RNG, + .parent = TYPE_VIRTIO_DEVICE, + .instance_size = sizeof(VHostUserRNG), + .class_init = vu_rng_class_init, +}; + +static void vu_rng_register_types(void) +{ + type_register_static(&vu_rng_info); +} + +type_init(vu_rng_register_types) diff --git a/include/hw/virtio/vhost-user-rng.h b/include/hw/virtio/vhost-user-rng.h new file mode 100644 index 000000000000..071539996d1d --- /dev/null +++ b/include/hw/virtio/vhost-user-rng.h @@ -0,0 +1,33 @@ +/* + * Vhost-user RNG virtio device + * + * Copyright (c) 2021 Mathieu Poirier + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _QEMU_VHOST_USER_RNG_H +#define _QEMU_VHOST_USER_RNG_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "chardev/char-fe.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 >*/ +}; + +#endif /* _QEMU_VHOST_USER_RNG_H */ From patchwork Mon Sep 27 22:13:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 514732 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp4550384jao; Mon, 27 Sep 2021 15:15:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7ff4UNECzeMWyI0Q2r2K5jqtCtp0m9D/fI8gwhewyU1zS5xZ/2nOMzs1+kyGj70fPLrMb X-Received: by 2002:a05:6130:31b:: with SMTP id ay27mr2497809uab.135.1632780955743; Mon, 27 Sep 2021 15:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632780955; cv=none; d=google.com; s=arc-20160816; b=OsWoCtHK33RglUxbfpqL90Ca+bf7cSGhJLKigAnZ4Nr7ucJNe2G6yGYxR/nwFUymLV JoYaaBKxV+yBypknHH3zHmvrGYOuk+lCZdrliAVnntgb9dnN0rJqUrvbUjmWU1TwvAmx WTR+pxNshPmSR1Tph9LvIpd5CEiT9yffqhbWgbvpMe7UFrcxjBFmFD+dbahA3qbJ0hCQ KTaxzflHNSMwrvLl0SNGtPuNCi1X0I3qnbfIx656n3HGVyGrCkbWV9iTHYCUF1ZJfekM Zzn9BMl50pywg0jyG2Hb4K3Ugb1eu4l/AA5AKIwfL6HAcan/NhJBUQVxA3tfFveRf+kM R7tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=ATiigdiyl6eSZmUol7/b9Qr5eElVhu1VmJG7FVbfZqg=; b=WBf6xQ4v+QZ6ndvjRT2BVsNakY0/9gv5fzP1pl7OgyrrCx+wYmNak8bIHIaX1F8YII 7rytIayV6BF4BcpB+kOnXRJP+4otzMtJZhczglS83V932uYWbZn9ODsF5wGKqFpVKfSs w9d3xYGa6KGorVmodBevWBPljQvgJr31W9O2QfS8ZtydK5ZMTQBJDrjhRn/BnnneRWVP W/tp3QYGVpKfDr3uBypbAvix57ZiHXOKgIFEVxz879ZNECLrRXWabT6weHYTrZtiSehO PF1Zbr/rvxnz6HcoJijUQN0PBPj4iGTYQzzawEM44KT2SRPR0l2qfyg2dG1vP6gFZrUq OhGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fN44a0lU; 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 z18si542079uam.59.2021.09.27.15.15.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Sep 2021 15:15:55 -0700 (PDT) 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=fN44a0lU; 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]:45284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUyug-000156-Rq for patch@linaro.org; Mon, 27 Sep 2021 18:15:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUyt2-00011d-Gt for qemu-devel@nongnu.org; Mon, 27 Sep 2021 18:14:12 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:45941) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUyt0-0005yz-Pj for qemu-devel@nongnu.org; Mon, 27 Sep 2021 18:14:12 -0400 Received: by mail-pg1-x52a.google.com with SMTP id n18so19080094pgm.12 for ; Mon, 27 Sep 2021 15:14:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ATiigdiyl6eSZmUol7/b9Qr5eElVhu1VmJG7FVbfZqg=; b=fN44a0lUfQlAfGSPxCBxKfk6pV0lvqzivUShpdCmmxVKdwrnD4PFJoYXKlrngaxsp4 3Eo00y8XMoEDK4aFYw2TjPP4Bt6ERTxCji2MQ8mY1oXrmYWt+LQUWJE6Crjbx6pjpZTA YVo81ZnUOPjApiGNcO4dPvhi7mxgLAG8+hyAM3y4R8X/1Yu6VfS70Yn7RwJA03cfCn2j r+Z2Mn6HMzgzN7nZgAbXZD2XjZfqHbO/b8lvsGyKJEfrMDI9f925PgELmELTA4ZVUPgH ub8SxLgf8k78YxQA+JZ2eU4NgTEFHf3zJGkb+hYKxTr/sCu9upYSeU9wlj9+TCVcXhhz FXJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ATiigdiyl6eSZmUol7/b9Qr5eElVhu1VmJG7FVbfZqg=; b=RTspd/eH/LQGil+12dOriy2tJ0hKTPo2HfSaR5mpjqj4AjJX7Pl9JAgLUUxVwRYHgi u8P1pBgobbWBUbQlpgXmDoEcJMWw7k4ADsMPBzrLQFQnJG7iSpIBGmtrgTKnzOSNWmku oDvuda/BbbkYtgfhIEUEtNcU4i9SFcrQ/5AJg6Xo4yJXMlh3ltfjon95xyheldUASl4k q8l7OUKPsjkMJf6HrAi1QBp5huiRonAOa+zPwPVIRpHd/CcKAdqUh6jV6on3F8txandh vABmnkGX3bYW6C7YcLCTuoa0z4M7NqEo7yuotnGN8uR/LPpyfjjWw9ICoYLEYwD5ookF 9fWw== X-Gm-Message-State: AOAM532BhzgBDxPaPGAuZTDCc6cT5Xd2+FOHcf3/xdmC3IvFrLY1Zdpf 5M9yOcLNDxw2b0ZQZhnKw26RxrUFW33Wog== X-Received: by 2002:a63:dc14:: with SMTP id s20mr1566619pgg.291.1632780849451; Mon, 27 Sep 2021 15:14:09 -0700 (PDT) Received: from p14s.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id g27sm18817742pfk.173.2021.09.27.15.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 15:14:07 -0700 (PDT) From: Mathieu Poirier To: mst@redhat.com Subject: [PATCH v4 2/3] vhost-user-rng-pci: Add vhost-user-rng-pci implementation Date: Mon, 27 Sep 2021 16:13:58 -0600 Message-Id: <20210927221359.2917482-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210927221359.2917482-1-mathieu.poirier@linaro.org> References: <20210927221359.2917482-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=mathieu.poirier@linaro.org; helo=mail-pg1-x52a.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This patch provides a PCI bus interface to the vhost-user-rng backend. Reviewed-by: Alex Bennée Signed-off-by: Mathieu Poirier --- hw/virtio/meson.build | 1 + hw/virtio/vhost-user-rng-pci.c | 79 ++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 hw/virtio/vhost-user-rng-pci.c -- 2.25.1 diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index ae6b2cde1068..521f7d64a86a 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -28,6 +28,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], if_true: files('vhost-user-i2c-pci.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) +virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_true: files('vhost-user-rng-pci.c')) virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c')) diff --git a/hw/virtio/vhost-user-rng-pci.c b/hw/virtio/vhost-user-rng-pci.c new file mode 100644 index 000000000000..c83dc8681385 --- /dev/null +++ b/hw/virtio/vhost-user-rng-pci.c @@ -0,0 +1,79 @@ +/* + * Vhost-user RNG virtio device PCI glue + * + * Copyright (c) 2021 Mathieu Poirier + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-rng.h" +#include "virtio-pci.h" + +struct VHostUserRNGPCI { + VirtIOPCIProxy parent_obj; + VHostUserRNG vdev; +}; + +typedef struct VHostUserRNGPCI VHostUserRNGPCI; + +#define TYPE_VHOST_USER_RNG_PCI "vhost-user-rng-pci-base" + +DECLARE_INSTANCE_CHECKER(VHostUserRNGPCI, VHOST_USER_RNG_PCI, + TYPE_VHOST_USER_RNG_PCI) + +static Property vhost_user_rng_pci_properties[] = { + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vhost_user_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VHostUserRNGPCI *dev = VHOST_USER_RNG_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&dev->vdev); + + if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors = 1; + } + + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void vhost_user_rng_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_rng_pci_realize; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + device_class_set_props(dc, vhost_user_rng_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_OTHERS; +} + +static void vhost_user_rng_pci_instance_init(Object *obj) +{ + VHostUserRNGPCI *dev = VHOST_USER_RNG_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_RNG); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_rng_pci_info = { + .base_name = TYPE_VHOST_USER_RNG_PCI, + .non_transitional_name = "vhost-user-rng-pci", + .instance_size = sizeof(VHostUserRNGPCI), + .instance_init = vhost_user_rng_pci_instance_init, + .class_init = vhost_user_rng_pci_class_init, +}; + +static void vhost_user_rng_pci_register(void) +{ + virtio_pci_types_register(&vhost_user_rng_pci_info); +} + +type_init(vhost_user_rng_pci_register); From patchwork Mon Sep 27 22:13:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 514733 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp4550567jao; Mon, 27 Sep 2021 15:16:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyig2H2kFZhrBd1dcEG5KCeZdE3YjlN4iOAu4JSu1gHsht5WD2xKfwpVEpRIrnf/esWB0zS X-Received: by 2002:ab0:1001:: with SMTP id f1mr2334930uab.115.1632780969992; Mon, 27 Sep 2021 15:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632780969; cv=none; d=google.com; s=arc-20160816; b=kS2VE4NxeGL+bO4JCeHx9B9+9JcAXmMG1RQHlJFuZk/FkfHxLHwg0L6GdxgmjH7+Cj GBhi1raRei055w0GrH3akZR1yV7sVQo4Qom2XAsGW8anSBMEMZ0uIA9DaeGv9yuHmB83 dyMCp9pNceIEjHGVFaaxBIMKX8A2/xte98kglp4/TYI1rnGK8BWRI8XbvHEZZYeoAdEA z5/XGNooNgd3s4TlXQLbEKvz9NzDhDtYAQDcaLwjseuTDGbdTP+xcCZu6wmkQpKfg9jk XS4+f1dUmulTLngiowq+7l2AjLeuDtjrvyF+4ba+c+QiNtWAtA8vEgAlGRNoVfrSt0db Ornw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=KtS1hmH2XT8liprRsgtkHnkZYg8FqiZUr8kHkqHwVa4=; b=u0JGv4scFmGP34SKuxsecVc91A1+9O8QkkU5Zczz9SoSTDP2+IfI2Hyf10nVbi+YVI AFIvhNfwc9d83iV7608IPlCpsJARRy1r+u8lPrY5UFtvxulPVMY/vMunUBVLZPTpaNtf ZCbJN5UHOS0SYlyX85954RQIEtZcWb5l29A7O2gAl4EvKCA0bGoe/GOSg40gCVt8MV0l KkL2YXsLFb8BzvCCw7PCSpTEdkol0y2N+rHrNRg3Bruhnfs91g0c2u4zYGl95UHsu3uW SEC8R1S8hur+lzKJc6c9KNwPoaH1xmCiFtiFYYm/5DEaIByThbJNIdmgpLnfqq8PtnGx 7g9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bPu2JdAK; 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 l17si12243987vsj.304.2021.09.27.15.16.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Sep 2021 15:16:09 -0700 (PDT) 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=bPu2JdAK; 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]:45492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUyuv-0001FM-E0 for patch@linaro.org; Mon, 27 Sep 2021 18:16:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUyt5-00016w-0u for qemu-devel@nongnu.org; Mon, 27 Sep 2021 18:14:15 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:42896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUyt3-00060q-9T for qemu-devel@nongnu.org; Mon, 27 Sep 2021 18:14:14 -0400 Received: by mail-pf1-x430.google.com with SMTP id q23so17141351pfs.9 for ; Mon, 27 Sep 2021 15:14:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KtS1hmH2XT8liprRsgtkHnkZYg8FqiZUr8kHkqHwVa4=; b=bPu2JdAKwnEoX96XuF+rVS0NoinCGh0+AmP21DGaLZmzABNYqZ3IeJ91Uz8N6GDuKx qwq8ccMj+x0xMMMJZI/TC8vwzyAZfqjqdfBL43K0oYxnw2p38n2SDn3F+Vlt85phruTf JjVPuhcQ5doK1z+arNb3TewWw4pfNQ9OrDHQgSfn/CQf7hfRHF3bkBFktyPOWrQj8KIw BTzhJAN8CjW/AThNHG8OXXzGc3JyfNxQ5CmHt3cK5wPgMkYALI8QXDRIpz1tVtsGPFFc pPbGTe3/WMPpRVArD+gQF0pklZgAr8WTHhqV4ANg+QCjT3Dc2eH0d5RxD7dC47aSoN1+ MqXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KtS1hmH2XT8liprRsgtkHnkZYg8FqiZUr8kHkqHwVa4=; b=pBfCroHuUfw2wKBMwD2owSS6Wlr/7ctL6UjvkUKfeWG+yzUlINBgtXTiANxgbZqL3y FosAxeweYLSagx3l6sRKFqUZk5AQY9l9U+2WcEEtVrJLoH5olVuEZzOGOSiGufzrLeO6 OuharXFTfWdKctx1Dq9vq/GSO9vr08laAAu1LgaQmKdcoLTKnkIf66Uau4Pib41U/QLe 3By4UpnQv2MdNp+hk3M3cbT+/nkjvjE4hMAatX1OeZBdSXheZIoO2sM3hFCMOA8UMDi8 Pmcw+wWwwCmaLA2We31Ql+jUYCayDzK38t1jpMcFN9Xom33a38M4/2GdP2gEvz4U3iRh Q/JQ== X-Gm-Message-State: AOAM530czA3cNmjRYFlGxfXCUnx11STC/pHf1183hPqJWPKp1KP+pO6q bjY/FIM6DstMvyYKMuRbU0m9QNa0pUGnAw== X-Received: by 2002:aa7:954e:0:b0:438:a1c2:340d with SMTP id w14-20020aa7954e000000b00438a1c2340dmr2230188pfq.30.1632780851964; Mon, 27 Sep 2021 15:14:11 -0700 (PDT) Received: from p14s.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id g27sm18817742pfk.173.2021.09.27.15.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 15:14:10 -0700 (PDT) From: Mathieu Poirier To: mst@redhat.com Subject: [PATCH v4 3/3] docs: Add documentation for vhost based RNG implementation Date: Mon, 27 Sep 2021 16:13:59 -0600 Message-Id: <20210927221359.2917482-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210927221359.2917482-1-mathieu.poirier@linaro.org> References: <20210927221359.2917482-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=mathieu.poirier@linaro.org; helo=mail-pf1-x430.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Add description and example for the vhost-user based RNG implementation. Signed-off-by: Mathieu Poirier --- docs/system/devices/vhost-user-rng.rst | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docs/system/devices/vhost-user-rng.rst -- 2.25.1 diff --git a/docs/system/devices/vhost-user-rng.rst b/docs/system/devices/vhost-user-rng.rst new file mode 100644 index 000000000000..a145d4105c1a --- /dev/null +++ b/docs/system/devices/vhost-user-rng.rst @@ -0,0 +1,39 @@ +QEMU vhost-user-rng - RNG emulation +=================================== + +Background +---------- + +What follows builds on the material presented in vhost-user.rst - it should +be reviewed before moving forward with the content in this file. + +Description +----------- + +The vhost-user-rng device implementation was designed to work with a random +number generator daemon such as the one found in the vhost-device crate of +the rust-vmm project available on github [1]. + +[1]. https://github.com/rust-vmm/vhost-device + +Examples +-------- + +The daemon should be started first: + +:: + + host# vhost-device-rng --socket-path=rng.sock -c 1 -m 512 -p 1000 + +The QEMU invocation needs to create a chardev socket the device can +use to communicate as well as share the guests memory over a memfd. + +:: + + host# qemu-system \ + -chardev socket,path=$(PATH)/rng.sock,id=rng0 \ + -device vhost-user-rng-pci,chardev=rng0 \ + -m 4096 \ + -object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \ + -numa node,memdev=mem \ + ...