From patchwork Mon Jun 14 20:28:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 459924 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp3613369jae; Mon, 14 Jun 2021 13:30:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwznRDgX7dURFcEbrzXA6MpRxMMIcqJ5+yn/hJfq2ogK4vG+Mhi+oexaf8s+lSYGGRu3T/o X-Received: by 2002:a67:7984:: with SMTP id u126mr1198283vsc.60.1623702609238; Mon, 14 Jun 2021 13:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623702609; cv=none; d=google.com; s=arc-20160816; b=rRZj59Zu0cbw6UZtcvd9JLzjLG6yKzbnFc5Y3YVHxhZEnrOtIjgvyOfkBtiHLzSf8q vXTCEye6djelLeMRR0EGkJgdOLN6ysHeDJ5Q8CofLpo43y7U85pX4lNLFZsthjn4ac8G VTr2R83WjHfn2BYfH3wXsgpT2kCZmkUNYef6TanmVKE5xXKjXxffPmHl7ROO5odujFn+ 745/oKxrXgh2fXdMulbO9CXW1Y2H42ch31wCvGd/0Ve/jeRbOUE+dFtQ2USceTEhjSW9 BCH0qUMZDh/MzDXhWu5USj8tPxfe0vcAPScdlrI/9jmFuKDoQH7KA1CtS2Li/WImuGPu YjaQ== 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=OhxZvgPrm7ef3poM6zsNJTUnNBRvQVJmMr/OyqsDOyY=; b=p3UpvZ8PLz0zIOTeH/1Pnv4dXNbIu2h5XStq6T2lc4KRU32zQsgHBOdxly69V+Kqwn 90TjeSQIpAbpelr8eJCFFcXDbnksuYIAafctV0VosjUUtfcdQBQpHpoNpqXWbcunTA5u BTF+bVmchA4oGVJHRiDRGUFngSSzCy9mmJVAjmAw/c+zCe3+V+RO4+9hf1Qr/P+XHrEu 5lBlVA9hASEhiSlsPGtu1I5F2LzhZsWbn3cQziAqDoEhZRqNnTDUE123rhh36u3e4aQ7 diGzAUxEKmbeL1brTBIe2YO51kuwVYE0VqxAl02llVWC+AjGHoTfOoz0Arm0j2rHQ3J1 rxXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a52eH9e7; 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 d17si6764030vsf.253.2021.06.14.13.30.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jun 2021 13:30: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=a52eH9e7; 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]:60974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lstDk-0001az-C1 for patch@linaro.org; Mon, 14 Jun 2021 16:30:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lstCW-0001Z6-VO for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:52 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:37448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lstCT-0005gk-TI for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:52 -0400 Received: by mail-pf1-x429.google.com with SMTP id y15so11472829pfl.4 for ; Mon, 14 Jun 2021 13:28:49 -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=OhxZvgPrm7ef3poM6zsNJTUnNBRvQVJmMr/OyqsDOyY=; b=a52eH9e7NTScTq0N+5+9Fs5pdm6nzjDGhtj5T80tTC4rFWJh5426YsCM/NeCSBd9t2 5EEFp6siW3hQQ+YPv+eisGABBolRd5IVgeaB5we7AHXa1Jjs9K7NzU3eznKcCbyOtnu1 OBjcphGFNwBRaBlyVVVf554HOOo1032VEQPqp5JCHIn0bNzivYt13JWdvUDGoZNEQPy/ zkmnfo1YJSsgSe76h8tUjfzr3+3BdhvezVdCj6hts1icp0340Yp5Mm9Ywd+GcBbxr3U1 aWTPX/R5q8GbdJ614OzBYHuwmWdtzJQjRWQV4ayV2+PhRHz5R929CbzjTLq/VSDRjRKJ a5xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OhxZvgPrm7ef3poM6zsNJTUnNBRvQVJmMr/OyqsDOyY=; b=GftWsgPFVWoLzc5MFMXHak2UmESVDmtdHhWBay5SLVTzfQnBp+DxObfLm2NkpW36BW DftCcJZIS1/0XrDM1C53N6bhzhwjuh9qTk0DFNHO9fUhpj74Ww/rUKkwnG/ByEKwgoDf ke6bRx/7zaDpERb8Ps9E9FNZkYzdBdPdyPmB08ns04Up7DzdauDJWkS7U5kxk0glk8Us jQRLDxRAy8qAc6vB3OT/iP0/w7RgHEHK6TWuETD0APLLGhL4KWKFA6ieKaGQfMbDz4dH UeOkBVPL9jIn7/0fzrw2eVjoXY9aC3XXDOC4GX1BdoH/BNBcK2OiS6aO2OsMSHeGZ8oJ fLRw== X-Gm-Message-State: AOAM5317zWHWddTFlRkJ+CvnrXUn38G8dhCzDGqqMC20zGQpQQbEX/57 FdD33TWRkhWcN7HjY2wpoD1AU0Qdv/MAQA== X-Received: by 2002:a63:4f47:: with SMTP id p7mr19114721pgl.52.1623702528587; Mon, 14 Jun 2021 13:28:48 -0700 (PDT) Received: from p14s.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id fs10sm289029pjb.31.2021.06.14.13.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 13:28:47 -0700 (PDT) From: Mathieu Poirier To: mst@redhat.com, alex.bennee@linaro.org Subject: [PATCH v2 1/5] vhost-user-rng: Add vhost-user-rng implementation Date: Mon, 14 Jun 2021 14:28:38 -0600 Message-Id: <20210614202842.581640-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614202842.581640-1-mathieu.poirier@linaro.org> References: <20210614202842.581640-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=mathieu.poirier@linaro.org; helo=mail-pf1-x429.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: qemu-devel@nongnu.org, stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Following in the footsteps of what whas done for vhost-user-i2c and virtiofsd, introduce a random number generator (RNG) backend that communicates with a vhost-user server to retrieve entropy. That way another VMM could be using the same vhost-user daemon and avoid having to write yet another RNG driver. Signed-off-by: Mathieu Poirier --- hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + hw/virtio/vhost-user-rng.c | 294 +++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-rng.h | 33 ++++ 4 files changed, 333 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 0eda25c4e1bf..69066ab14e6d 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -58,3 +58,8 @@ config VIRTIO_MEM depends on LINUX depends on VIRTIO_MEM_SUPPORTED select MEM_DEVICE + +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 fbff9bc9d4de..e386791f2a05 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -25,6 +25,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock. virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) 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_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..78447e8d3791 --- /dev/null +++ b/hw/virtio/vhost-user-rng.c @@ -0,0 +1,294 @@ +/* + * 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); + if (!rng->vhost_dev.vqs) { + error_setg_errno(errp, -1, "memory allocation failed"); + goto vhost_dev_init_failed; + } + + ret = vhost_dev_init(&rng->vhost_dev, &rng->vhost_user, + VHOST_BACKEND_TYPE_USER, 0); + 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 Jun 14 20:28:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 459921 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp3612778jae; Mon, 14 Jun 2021 13:29:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzc7syaec8CfnT1fGHn88I9hHJJl3TL+lCNMGXYM0n0kWwasP5/iF+a+J+3rr3RsLP/2x7f X-Received: by 2002:a05:6102:482:: with SMTP id n2mr1540818vsa.60.1623702560975; Mon, 14 Jun 2021 13:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623702560; cv=none; d=google.com; s=arc-20160816; b=Jh7vtqAM6jdwOvtb7/fOFOKTEaP3ixb4wzY3TflvfMi26RYzaMFghdaOQa5sR0cbcX 7IDmohRabzaeoBPfIugmVtp1E2ZKmDNGhXb2bJG5UJQOZ5pOFjscwd3QaqQjRy0T46/j i0XQGVS4nGDO3odjXtNGw5fUBxbjX+lS54yw/ndjk5kUNqW1wWfsj5kz5XRQLu4kKZpB ppbM1yxUbxpWCCfVyrBY2bohWk9nKb9Er7U+SXWot6hUyX5ppzdpXCjDp3ft56c4pPw5 IMDqv9cvb/TL8mssebbAC0+g148DeIk0uy1P1eBjsWgDSJeqUd1IBfweMypsbNDioOx3 q/mw== 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=S/O1M1xy8qnEH5DkM7qojc/M8Nl3BQRdLguDgKBWfTs=; b=hmAZ8Vjjd5Zv6Sbfbm3wRDV1hDTGJhSYdZ+eOjE01MpvUjArxY8rKrlRWs66sndKWS jgvQsIzp/T1kuq01ErGuEZEsKWqeS3NUwcSwQAm88a7jhxcFgQugKScA8utjMtBJLCKo 426GxehU0yHIv4nY1YDDRJEPAEJnkH5HNknBodBdbNEyPg0nHMnfvTdozKdY6G16PL7w bHkjKve4uYpY779nssswHwBcV91Ltk7iL6xZkc4jHlEvNk4SXE6XeqNuG1Oy4IQpvoXC Z79f0A4pGSHeoLVpfzMmA2KxqKmxDAk14lJdrIvLEq8Bjiujm7opQx3oN/6AYhmd5t/t rDrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uwJlMdZV; 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 r19si7062521uak.257.2021.06.14.13.29.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jun 2021 13:29:20 -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=uwJlMdZV; 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]:32794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lstCy-0001dM-2U for patch@linaro.org; Mon, 14 Jun 2021 16:29:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lstCX-0001Zn-CH for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:53 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:39469) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lstCV-0005hh-8L for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:53 -0400 Received: by mail-pf1-x434.google.com with SMTP id k15so11479269pfp.6 for ; Mon, 14 Jun 2021 13:28:50 -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=S/O1M1xy8qnEH5DkM7qojc/M8Nl3BQRdLguDgKBWfTs=; b=uwJlMdZVaXiyGEgP+3OEI/TXrlInB9r6omG3EGV92FwIFilzEzEyMgd33NakDVtMYK xUj07IrAoTyapdoBi7XR0pb3BgkR3OQJWqhso3tIm8OAfeJ1RXmNLRHRMytpQYhCJqYO RLw5X7IjmM6jsA0FZhd55K6LdJoWcs0Paas5Z/lhH5wbU73VL4bom8AJk5ob9NWsEJ3W EAaVXZ9Wr/YVNIReLb9ZCMrO3L/WPhUOcO9gFdV8byUSYcl0FUDLncF3eiTjZipxeA66 y7L/uCe0USgK81wbm+eFfmg0asCfFQAqIi58vegIuYEnEOQEdGS1d0rf1fb3rIIJ4wI0 9m7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S/O1M1xy8qnEH5DkM7qojc/M8Nl3BQRdLguDgKBWfTs=; b=gNqq4qnMgSqhoWiya5f6xaZ5BxFfU25RnxLmAW28L70U3s64x0FYAVjA6NOoCQICxz S7GCsE/95y+h2POdE/vVdtCkWprvq2UmM12kLH9VUUyF1lebTV/WpZKHmSiaGoIPGj8J rizj1wMXotM/dtsFXrxHHxd6nsvWZYQzWYvd4/xnX1LVa9BZRDh1RcuAXGJoTQkSE6Qy FzWl9R1BjTdpfWSqgHykKX/WPpbLx9I9rxqAhE9Tz15Pvoz+PhedOLtSH7sa1ckIe7Sh smiVLhnnDX1wuuLbnYYfz+8ZmAYFWOyGfjxYAMIXJSr3077zrU86E4xepGtoHbuuCvfd gxCQ== X-Gm-Message-State: AOAM530UsOQUOrv6ZPBC59UjlFk57ItfrOYAd7ZQf6N7LufP1i5Ll+zK K1QRwauWvKodYnrB6CefVCG1dB3DITIAMA== X-Received: by 2002:a63:4849:: with SMTP id x9mr19000109pgk.59.1623702530017; Mon, 14 Jun 2021 13:28:50 -0700 (PDT) Received: from p14s.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id fs10sm289029pjb.31.2021.06.14.13.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 13:28:49 -0700 (PDT) From: Mathieu Poirier To: mst@redhat.com, alex.bennee@linaro.org Subject: [PATCH v2 2/5] vhost-user-rng-pci: Add vhost-user-rng-pci implementation Date: Mon, 14 Jun 2021 14:28:39 -0600 Message-Id: <20210614202842.581640-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614202842.581640-1-mathieu.poirier@linaro.org> References: <20210614202842.581640-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=mathieu.poirier@linaro.org; helo=mail-pf1-x434.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: qemu-devel@nongnu.org, stratos-dev@op-lists.linaro.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 backed. The implentation is similar to what was done for vhost-user-i2c-pci and vhost-user-fs-pci. 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 e386791f2a05..1430b370e64d 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -26,6 +26,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) 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_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..ffff2de39fd4 --- /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_COMMUNICATION_OTHER; +} + +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 Jun 14 20:28:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 459925 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp3614923jae; Mon, 14 Jun 2021 13:32:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAL6yPSzO4/wBDWNNrH6ZYyLup3O/jHfabAlqMMfNi072cQjedHReYHx7bEPrGwpj1liWt X-Received: by 2002:a05:6122:a1e:: with SMTP id 30mr1158432vkn.3.1623702737315; Mon, 14 Jun 2021 13:32:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623702737; cv=none; d=google.com; s=arc-20160816; b=aRLULjQ7Pq9T+4HdveTzvsievmfeTcU6WrO1A71JuMYyug/6lR3gmLSI/Sryj+/tLc 3dHhhxx21vRG5MqIXNNCKERl3XbDF3ZYKB+mzsiUezv5fCwF3nAWFbBHGwfp5aG9GS/d rCZ2eR1NNBlotSrzc0LSqavyh6EdNKJrG2pgAWfAXrqb+UhN31DL7eM2UKwUNebsQgmR jyxYKwJoLnFrBQnPG1OqRG4e8ztCZ5wdoQyFh/59fOfnHrSnc17GIb6SAr7zb+vDP3Y8 msm45bi9AWFT4c5v7M1EEZXCJV/YymwYNLUuJ4yeN1HE0NtsngbCgHPheku/nCZwXFJX 8scQ== 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=wsArIT9POHADwotE155k6PW8w3SZaIZZYryywmPDcwI=; b=z4Gg4d+err8tPYH6ElYG8DN+PVNrYX6SISY7AnjHS/7kpaEr5vJae0y+oJVNHE0WjN 9+baKrGDDNLBbrij8RlLLESatl1nfODLay+zdA/9K3w3daV/EEEAs94bqTrp1KAFpJd1 2GHkOfQ0ZtGjhYkDoOj4zfILYldFZO7eDM6D2xEpdQBJxNXt4v+GxrfVJFBdrU4ad2Io 94i+AAS49bRvRtslMM+NKf2jkQFbKwjI+kqAzRV3ep8QZEdcY6TlXSNBuVfLUpaEdY5L OcNCLAtP2BGXeBTWVIo1btXI1ofj9epIcxjJHqUJdOT5wLmVl4K1thJzsvWUWNiUw8fh Jelg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="tv/Nq874"; 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 h16si6642716uae.60.2021.06.14.13.32.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jun 2021 13:32:17 -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="tv/Nq874"; 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]:41246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lstFo-0007Kw-N0 for patch@linaro.org; Mon, 14 Jun 2021 16:32:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52020) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lstCa-0001i0-8N for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:56 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:40850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lstCX-0005im-BV for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:56 -0400 Received: by mail-pf1-x42a.google.com with SMTP id q25so11477277pfh.7 for ; Mon, 14 Jun 2021 13:28:52 -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=wsArIT9POHADwotE155k6PW8w3SZaIZZYryywmPDcwI=; b=tv/Nq874R1qNP6d+1CQJL0cPJwnR8BGer76XojIoSK0Yb5DTRPigGh1pYh3/mH0Ary sQpSX6md7XMZATrgXjWukl1BAN7b5XXA2jxLNTcaPMhCZS3PSI13ag9ysVkZi7de7vYx 26kWujgmKX9hYbeGW+CGxQYF1pzn5R6QgFK9RW2ynd6gVAaDC2zbVGAcZbFg0/z9TB0I 3ELEe3P95QCBUPltRecyTdDDkgPJkcEHXwaljpkZtwIYDPVEqX4mOyuhPjBi5Nzwg8V5 s0d7l/+GX+J6CLsMAdEklh288oBjT54hAu1+6k2R2xmE3wX37NbKWsEp+0weGMReS9W5 PJ8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wsArIT9POHADwotE155k6PW8w3SZaIZZYryywmPDcwI=; b=B61qMiJE3dqOy2Q3V8Gpr/33/htU5MuyhONTj7gykUfqYpLoMQnPgbHWx/sr+jwhi9 W6N3Gn1pn05SBRucXkteaQH0FjVoJ0XLJMEtPczwJ2hBHz5VloeVS3p/pYtgrqJyzs2l QGBQA+60myO82ZbpN4pgxlczGA5GIOodB8qtTakEbUCcb2YXW76e9Ylz4llLUxhGOYWT gyFVif5ygxxE/+kvigtnLM0HRhH/7Zu2tFjn5auTaOJ267VURtUMxAD0e7JeOsONxAiC vFpkKL9FHulASesJBCl5mf/5MvL7PeyXnn+ItVB43LNuzswuVW9g+LXO77uNjBKC/FXs EzDQ== X-Gm-Message-State: AOAM531sjLQ4KeailkhAXEcyfYbWhRT/5gtouljRcYRIjjss5TQjedgY 8igOYSoBALK7U+Y+VfgnKnSeDg== X-Received: by 2002:a63:5522:: with SMTP id j34mr18635259pgb.148.1623702531896; Mon, 14 Jun 2021 13:28:51 -0700 (PDT) Received: from p14s.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id fs10sm289029pjb.31.2021.06.14.13.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 13:28:50 -0700 (PDT) From: Mathieu Poirier To: mst@redhat.com, alex.bennee@linaro.org Subject: [PATCH v2 3/5] vhost-user-rng: backend: Add RNG vhost-user daemon implementation Date: Mon, 14 Jun 2021 14:28:40 -0600 Message-Id: <20210614202842.581640-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614202842.581640-1-mathieu.poirier@linaro.org> References: <20210614202842.581640-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=mathieu.poirier@linaro.org; helo=mail-pf1-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 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: qemu-devel@nongnu.org, stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This patch provides the vhost-user backend implementation to work in tandem with the vhost-user-rng implementation of the QEMU VMM. It uses the vhost-user API so that other VMM can re-use the interface without having to write the driver again. Signed-off-by: Mathieu Poirier --- tools/meson.build | 8 + tools/vhost-user-rng/50-qemu-rng.json.in | 5 + tools/vhost-user-rng/main.c | 403 +++++++++++++++++++++++ tools/vhost-user-rng/meson.build | 10 + 4 files changed, 426 insertions(+) create mode 100644 tools/vhost-user-rng/50-qemu-rng.json.in create mode 100644 tools/vhost-user-rng/main.c create mode 100644 tools/vhost-user-rng/meson.build -- 2.25.1 diff --git a/tools/meson.build b/tools/meson.build index 3e5a0abfa29f..66b0a11fbb45 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -24,3 +24,11 @@ endif if have_virtiofsd subdir('virtiofsd') endif + +have_virtiorng = (have_system and + have_tools and + 'CONFIG_LINUX' in config_host) + +if have_virtiorng + subdir('vhost-user-rng') +endif diff --git a/tools/vhost-user-rng/50-qemu-rng.json.in b/tools/vhost-user-rng/50-qemu-rng.json.in new file mode 100644 index 000000000000..9186c3c6fe1d --- /dev/null +++ b/tools/vhost-user-rng/50-qemu-rng.json.in @@ -0,0 +1,5 @@ +{ + "description": "QEMU vhost-user-rng", + "type": "bridge", + "binary": "@libexecdir@/vhost-user-rng" +} diff --git a/tools/vhost-user-rng/main.c b/tools/vhost-user-rng/main.c new file mode 100644 index 000000000000..c3b8f6922757 --- /dev/null +++ b/tools/vhost-user-rng/main.c @@ -0,0 +1,403 @@ +/* + * VIRTIO RNG Emulation via vhost-user + * + * Copyright (c) 2021 Mathieu Poirier + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#define G_LOG_DOMAIN "vhost-user-rng" +#define G_LOG_USE_STRUCTURED 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qemu/cutils.h" +#include "subprojects/libvhost-user/libvhost-user-glib.h" +#include "subprojects/libvhost-user/libvhost-user.h" + +#ifndef container_of +#define container_of(ptr, type, member) ({ \ + const typeof(((type *) 0)->member) * __mptr = (ptr); \ + (type *) ((char *) __mptr - offsetof(type, member)); }) +#endif + +typedef struct { + VugDev dev; + struct itimerspec ts; + timer_t rate_limit_timer; + pthread_mutex_t rng_mutex; + pthread_cond_t rng_cond; + int64_t quota_remaining; + bool activate_timer; + GMainLoop *loop; +} VuRNG; + +static gboolean print_cap, verbose; +static gchar *source_path, *socket_path; +static gint source_fd, socket_fd = -1; + +/* Defaults tailored on virtio-rng.c */ +static uint32_t period_ms = 1 << 16; +static uint64_t max_bytes = INT64_MAX; + +static void check_rate_limit(union sigval sv) +{ + VuRNG *rng = sv.sival_ptr; + bool wakeup = false; + + pthread_mutex_lock(&rng->rng_mutex); + /* + * The timer has expired and the guest has used all available + * entropy, which means function vu_rng_handle_request() is waiting + * on us. As such wake it up once we're done here. + */ + if (rng->quota_remaining == 0) { + wakeup = true; + } + + /* + * Reset the entropy available to the guest and tell function + * vu_rng_handle_requests() to start the timer before using it. + */ + rng->quota_remaining = max_bytes; + rng->activate_timer = true; + pthread_mutex_unlock(&rng->rng_mutex); + + if (wakeup) { + pthread_cond_signal(&rng->rng_cond); + } +} + +static void setup_timer(VuRNG *rng) +{ + struct sigevent sev; + int ret; + + memset(&rng->ts, 0, sizeof(struct itimerspec)); + rng->ts.it_value.tv_sec = period_ms / 1000; + rng->ts.it_value.tv_nsec = (period_ms % 1000) * 1000000; + + /* + * Call function check_rate_limit() as if it was the start of + * a new thread when the timer expires. + */ + sev.sigev_notify = SIGEV_THREAD; + sev.sigev_notify_function = check_rate_limit; + sev.sigev_value.sival_ptr = rng; + /* Needs to be NULL if defaults attributes are to be used. */ + sev.sigev_notify_attributes = NULL; + ret = timer_create(CLOCK_MONOTONIC, &sev, &rng->rate_limit_timer); + if (ret < 0) { + fprintf(stderr, "timer_create() failed\n"); + } + +} + + +/* Virtio helpers */ +static uint64_t rng_get_features(VuDev *dev) +{ + if (verbose) { + g_info("%s: replying", __func__); + } + return 0; +} + +static void rng_set_features(VuDev *dev, uint64_t features) +{ + if (verbose && features) { + g_autoptr(GString) s = g_string_new("Requested un-handled feature"); + g_string_append_printf(s, " 0x%" PRIx64 "", features); + g_info("%s: %s", __func__, s->str); + } +} + +static void vu_rng_handle_requests(VuDev *dev, int qidx) +{ + VuRNG *rng = container_of(dev, VuRNG, dev.parent); + VuVirtq *vq = vu_get_queue(dev, qidx); + VuVirtqElement *elem; + size_t to_read; + int len, ret; + + for (;;) { + /* Get element in the vhost virtqueue */ + elem = vu_queue_pop(dev, vq, sizeof(VuVirtqElement)); + if (!elem) { + break; + } + + /* Get the amount of entropy to read from the vhost server */ + to_read = elem->in_sg[0].iov_len; + + pthread_mutex_lock(&rng->rng_mutex); + + /* + * We have consumed all entropy available for this time slice. + * Wait for the timer (check_rate_limit()) to tell us about the + * start of a new time slice. + */ + if (rng->quota_remaining == 0) { + pthread_cond_wait(&rng->rng_cond, &rng->rng_mutex); + } + + /* Start the timer if the last time slice has expired */ + if (rng->activate_timer == true) { + rng->activate_timer = false; + ret = timer_settime(rng->rate_limit_timer, 0, &rng->ts, NULL); + if (ret < 0) { + fprintf(stderr, "timer_settime() failed\n"); + } + } + + /* Make sure we don't read more than it's available */ + if (rng->quota_remaining < to_read) { + to_read = rng->quota_remaining; + } + + len = read(source_fd, elem->in_sg[0].iov_base, to_read); + + /* Simply return 0 if an error occurs */ + if (len < 0) { + len = 0; + } + + rng->quota_remaining -= len; + + pthread_mutex_unlock(&rng->rng_mutex); + + vu_queue_push(dev, vq, elem, len); + free(elem); + } + + vu_queue_notify(dev, vq); +} + +static void +vu_rng_queue_set_started(VuDev *dev, int qidx, bool started) +{ + VuVirtq *vq = vu_get_queue(dev, qidx); + + g_debug("queue started %d:%d\n", qidx, started); + + if (!qidx) { + vu_set_queue_handler(dev, vq, started ? vu_rng_handle_requests : NULL); + } +} + +/* + * Any messages not handled here are processed by the libvhost library + * itself. + */ +static int rng_process_msg(VuDev *dev, VhostUserMsg *msg, int *do_reply) +{ + VuRNG *rng = container_of(dev, VuRNG, dev.parent); + + if (msg->request == VHOST_USER_NONE) { + g_main_loop_quit(rng->loop); + return 1; + } + + return 0; +} + +static const VuDevIface vuiface = { + .set_features = rng_set_features, + .get_features = rng_get_features, + .queue_set_started = vu_rng_queue_set_started, + .process_msg = rng_process_msg, +}; + +static gboolean hangup(gpointer user_data) +{ + GMainLoop *loop = (GMainLoop *) user_data; + + g_printerr("%s: caught hangup/quit signal, quitting", __func__); + g_main_loop_quit(loop); + return true; +} + +static void panic(VuDev *dev, const char *msg) +{ + g_critical("%s\n", msg); + exit(EXIT_FAILURE); +} + +/* Print vhost-user.json backend program capabilities */ +static void print_capabilities(void) +{ + printf("{\n"); + printf(" \"type\": \"RNG\"\n"); + printf(" \"filename\": [ RNG source ]\n"); + printf("}\n"); +} + +static GOptionEntry options[] = { + { "socket-path", 's', 0, G_OPTION_ARG_FILENAME, &socket_path, + "Location of vhost-user Unix domain socket, incompatible with --fd", + "PATH" }, + { "fd", 'f', 0, G_OPTION_ARG_INT, &socket_fd, + "Specify the backend file-descriptor, incompatible with --socket-path", + "FD" }, + { "period", 'p', 0, G_OPTION_ARG_INT, &period_ms, + "Time needed (in ms) to transfer a maximum amount of byte", NULL }, + { "max-bytes", 'm', 0, G_OPTION_ARG_INT64, &max_bytes, + "Maximum amount of byte that can be transferred in a period", NULL }, + { "filename", 'n', 0, G_OPTION_ARG_FILENAME, &source_path, + "RNG source, defaults to /dev/urandom", "PATH" }, + { "print-capabilities", 'c', 0, G_OPTION_ARG_NONE, &print_cap, + "Output to stdout the backend capabilities in JSON format and exit", + NULL}, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, + "Be more verbose in output", NULL}, + { NULL } +}; + +int main(int argc, char *argv[]) +{ + GError *error = NULL; + GOptionContext *context; + g_autoptr(GSocket) socket = NULL; + char default_source[] = "/dev/urandom"; + char *source = default_source; + VuRNG rng; + + context = g_option_context_new("vhost-user emulation of RNG device"); + g_option_context_add_main_entries(context, options, "vhost-user-rng"); + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_printerr("option parsing failed: %s\n", error->message); + exit(1); + } + + if (print_cap) { + print_capabilities(); + exit(0); + } + + if (!socket_path && socket_fd < 0) { + g_printerr("Please specify either --fd or --socket-path\n"); + exit(EXIT_FAILURE); + } + + if (socket_path && socket_fd > 0) { + g_printerr("Either --fd or --socket-path, not both\n"); + exit(EXIT_FAILURE); + } + + if (max_bytes > INT64_MAX) { + g_printerr("'max-bytes' parameter must be non-negative, " + "and less than 2^63\n"); + exit(EXIT_FAILURE); + } + + if (period_ms <= 0) { + g_printerr("'period' parameter expects a positive integer\n"); + exit(EXIT_FAILURE); + } + + /* + * Now create a vhost-user socket that we will receive messages + * on. Once we have our handler set up we can enter the glib main + * loop. + */ + if (socket_path) { + g_autoptr(GSocketAddress) addr = g_unix_socket_address_new(socket_path); + g_autoptr(GSocket) bind_socket = g_socket_new(G_SOCKET_FAMILY_UNIX, + G_SOCKET_TYPE_STREAM, + G_SOCKET_PROTOCOL_DEFAULT, + &error); + + if (!g_socket_bind(bind_socket, addr, false, &error)) { + g_printerr("Failed to bind to socket at %s (%s).\n", + socket_path, error->message); + exit(EXIT_FAILURE); + } + if (!g_socket_listen(bind_socket, &error)) { + g_printerr("Failed to listen on socket %s (%s).\n", + socket_path, error->message); + } + g_message("awaiting connection to %s", socket_path); + socket = g_socket_accept(bind_socket, NULL, &error); + if (!socket) { + g_printerr("Failed to accept on socket %s (%s).\n", + socket_path, error->message); + } + } else { + socket = g_socket_new_from_fd(socket_fd, &error); + if (!socket) { + g_printerr("Failed to connect to FD %d (%s).\n", + socket_fd, error->message); + exit(EXIT_FAILURE); + } + } + + /* Overwrite default RNG source with what user provided, if any */ + if (source_path) { + source = source_path; + } + + source_fd = open(source, O_RDWR); + if (source_fd < 0) { + g_printerr("Failed to open RNG source %s\n", source); + g_socket_close(socket, &error); + unlink(socket_path); + exit(EXIT_FAILURE); + } + + /* catch exit signals */ + g_unix_signal_add(SIGHUP, hangup, rng.loop); + g_unix_signal_add(SIGINT, hangup, rng.loop); + + /* + * Create the main loop first so all the various sources can be + * added. As well as catching signals we need to ensure vug_init + * can add it's GSource watches. + */ + rng.loop = g_main_loop_new(NULL, FALSE); + + if (!vug_init(&rng.dev, 1, g_socket_get_fd(socket), + panic, &vuiface)) { + g_printerr("Failed to initialize libvhost-user-glib.\n"); + exit(EXIT_FAILURE); + } + + rng.quota_remaining = max_bytes; + rng.activate_timer = true; + pthread_mutex_init(&rng.rng_mutex, NULL); + pthread_cond_init(&rng.rng_cond, NULL); + setup_timer(&rng); + + if (verbose) { + g_info("period_ms: %d tv_sec: %ld tv_nsec: %lu\n", + period_ms, rng.ts.it_value.tv_sec, rng.ts.it_value.tv_nsec); + } + + g_message("entering main loop, awaiting messages"); + g_main_loop_run(rng.loop); + g_message("finished main loop, cleaning up"); + + g_main_loop_unref(rng.loop); + vug_deinit(&rng.dev); + timer_delete(rng.rate_limit_timer); + close(source_fd); + unlink(socket_path); +} diff --git a/tools/vhost-user-rng/meson.build b/tools/vhost-user-rng/meson.build new file mode 100644 index 000000000000..4dc386daf335 --- /dev/null +++ b/tools/vhost-user-rng/meson.build @@ -0,0 +1,10 @@ +executable('vhost-user-rng', files( + 'main.c'), + dependencies: [qemuutil, glib, gio, rt], + install: true, + install_dir: get_option('libexecdir')) + +configure_file(input: '50-qemu-rng.json.in', + output: '50-qemu-rng.json', + configuration: config_host, + install_dir: qemu_datadir / 'vhost-user') From patchwork Mon Jun 14 20:28:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 459922 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp3612861jae; Mon, 14 Jun 2021 13:29:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN6ceuAkU8DEydVkYL0JtasSl+T/4fqRA7Ypvf8Y528x3lr0tN7CeZPyyQZo/t5aBod2pH X-Received: by 2002:a05:6102:10c4:: with SMTP id t4mr1203372vsr.58.1623702568288; Mon, 14 Jun 2021 13:29:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623702568; cv=none; d=google.com; s=arc-20160816; b=ZRk3QC0UhriQFonQlsP+4QFhuJ5qYJB4sWP1EvdZxMyR7/MqfFVwUyKd9/alhqNgZO Y+5Aifn4CKM30FqMkALaA0XKSGBaZTCftHGCQ9tEhuma6dsUGyf2FGvXXuMrrVEAlVUf S7tISa6f5voSdeubq4qeG3eSjReSczhlXvbdAg8L5KsXcLC4oKz1GQF7x3AqfYHJkJFg UZbbVKe2KC0Wmy+Nq30ZWGhcfK101MiCRPj6wya4Y2OVgoAs5bk1Ju6e7blyKAFGBGwu LpKVaA0zSrhP1UdBayegrjqsSpelvw/R41kXMO74zrr3JsjEcxGtMIqDjG+/KrlTRNtG dXHA== 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=bw6uvOLKEisckETLGn7QqEllExX+W/+p46wjCLwcazI=; b=s0uEkTP9v6ze1zy1W0HaUCC1tEjKyEqddEhEdi50w0c4FzoU80ROmgZoERcHfuTkct sZmaMiWlt/9Gvq8HsVZmF5QReP2q6StWQOc8Guri5qAIDVqw+zX4jOYh14aXdqV+/law Jso0Y5dUfKCjrh0p6bKqvg87DlN+QFw6JLlSRusHbclAYV8imdQA6lQg4BF9Yh0NzilG 5hbJerI5QWynrPY2UVZs92RHZCSfag6oA1Za/yMjc+GF/TI6+YwH24Xvw7Uerd8rpi3a ppb27QzWIrgPk8RpBCypnL5cJgMrZHX1naI2HlQvm7Cao1nVMkhP+K3nROeFtNCr5wML nchg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rtpzrMif; 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 t16si51818uad.27.2021.06.14.13.29.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jun 2021 13:29:28 -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=rtpzrMif; 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]:33116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lstD5-0001qR-Ni for patch@linaro.org; Mon, 14 Jun 2021 16:29:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lstCa-0001jc-Mh for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:56 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:51985) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lstCY-0005jJ-SO for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:56 -0400 Received: by mail-pj1-x1032.google.com with SMTP id k5so10445123pjj.1 for ; Mon, 14 Jun 2021 13:28:54 -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=bw6uvOLKEisckETLGn7QqEllExX+W/+p46wjCLwcazI=; b=rtpzrMifexv0tMpt5pch/6fVS/DcGS2EWxZHa7G19DKK0CqrrcXawJkLvelUGYqCEb VO/UhL1nD49Z98z3QM8nbs/wo0qpuQIvkYk4qa858sd1/KvUWLJbDufjgeFRleIqGj77 mJg04i2YSxOpJDb0ulrDEzq+5Y9QESU65kIk/JfN3VcxC+AbRNwpE1yOZ5jP8YgtvFfA rCAF6oom0WWD94anc4saGYj/jvJV4M5f5SsVGGJgpc9VoTNIiPzc7E9A1VRO/PyqZay+ oZlKFhye3ggDjRs0WyuWdus2qX7eioJhTfSyzGq7d2ir+9PdnD4JtPoBY6/7QVqgCDkZ jK+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bw6uvOLKEisckETLGn7QqEllExX+W/+p46wjCLwcazI=; b=t4S5MtVNm24bMnOrVJSdmrO4HKsT/7vi7gi5LbPsrEFJXdZh7CRO67DiaIVe2lthRx N9oO1ojChhP2NUYXgt0eiGe0NPnjepX5CCi8N5nHQo2AxgYeUJXt9B56yDDL9qwWclVE Oj1IZhGPYaRYkqGfPaci6eYKNTk1SVF/NE4MqaZNFh3JWm15E/TXCCf2AJoSByxJsM17 GroZgtpu3Sb/eQ7MPlwk/26BHqrP+tIyF+bcJSa/4dCrw0fzCS24EypgukPEgZR+UFgX fJJ1fNYXb3pA5Yu9JPUvjwOycAlmCn+KPMwsbT0XI9EieLCb8PEfmCeLlnwl4/RLXmxz JxgQ== X-Gm-Message-State: AOAM532EA3pIx0xn9ER9YC8cWpCmmCssAv0y6ZBl01+bRx+koi4Rwr53 7OzYG8/WPMBAoczIpAj1og0aAw== X-Received: by 2002:a17:90b:1285:: with SMTP id fw5mr963928pjb.35.1623702533603; Mon, 14 Jun 2021 13:28:53 -0700 (PDT) Received: from p14s.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id fs10sm289029pjb.31.2021.06.14.13.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 13:28:52 -0700 (PDT) From: Mathieu Poirier To: mst@redhat.com, alex.bennee@linaro.org Subject: [PATCH v2 4/5] docs: Add documentation for vhost based RNG implementation Date: Mon, 14 Jun 2021 14:28:41 -0600 Message-Id: <20210614202842.581640-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614202842.581640-1-mathieu.poirier@linaro.org> References: <20210614202842.581640-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=mathieu.poirier@linaro.org; helo=mail-pj1-x1032.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: qemu-devel@nongnu.org, stratos-dev@op-lists.linaro.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. Tailored on Viresh Kumar's vhost-user-i2c documentation. Signed-off-by: Mathieu Poirier --- docs/tools/vhost-user-rng.rst | 74 +++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 docs/tools/vhost-user-rng.rst -- 2.25.1 diff --git a/docs/tools/vhost-user-rng.rst b/docs/tools/vhost-user-rng.rst new file mode 100644 index 000000000000..7f69d7bb3c58 --- /dev/null +++ b/docs/tools/vhost-user-rng.rst @@ -0,0 +1,74 @@ +QEMU vhost-user-rng - RNG emulation backend +=========================================== + +Synopsis +-------- + +**vhost-user-rng** [*OPTIONS*] + +Description +----------- + +This program is a vhost-user backend that emulates a VirtIO random number +generator (RNG). It uses the host's random number generator pool, +/dev/urandom by default but configurable at will, to satisfy requests from +guests. + +This program is designed to work with QEMU's ``-device +vhost-user-rng-pci`` but should work with any virtual machine monitor +(VMM) that supports vhost-user. See the Examples section below. + +Options +------- + +.. program:: vhost-user-rng + +.. option:: -h, --help + + Print help. + +.. option:: -v, --verbose + + Increase verbosity of output + +.. option:: -s, --socket-path=PATH + + Listen on vhost-user UNIX domain socket at PATH. Incompatible with --fd. + +.. option:: -f, --fd=FDNUM + + Accept connections from vhost-user UNIX domain socket file descriptor FDNUM. + The file descriptor must already be listening for connections. + Incompatible with --socket-path. + +.. option:: -p, --period + + Rate, in milliseconds, at which the RNG hardware can generate random data. + Used in conjunction with the --max-bytes option. + +.. option:: -m, --max-bytes + + In conjuction with the --period parameter, provides the maximum number of byte + per milliseconds a RNG device can generate. + +Examples +-------- + +The daemon should be started first: + +:: + + host# vhost-user-rng --socket-path=rng.sock --period=1000 --max-bytes=4096 + +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 \ + ... From patchwork Mon Jun 14 20:28:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 459926 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp3615786jae; Mon, 14 Jun 2021 13:33:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnZnu0DSBQUayAE2yESRGdNjLGo8mPWaB8kOc54OtJtsUBczO8nqovJDheT4O9GoN6nKDO X-Received: by 2002:a1c:3dc2:: with SMTP id k185mr1002217wma.15.1623702812226; Mon, 14 Jun 2021 13:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623702812; cv=none; d=google.com; s=arc-20160816; b=zNVbRSa4HWZ3/nwFa+xYb9VxO7DrJK0+c4C8i2RRNdSyN0+6IasO/yYDXnSTMwMdNw jS4VpQcKsWIa6OMWSzdlhB9WWPNGXZNKdcPHjx5dFu5XsJ4FZP3Z/EjQyxoWKCrFkQhf tt0qjmHHXYln17OhrtoyKhx/fX6TdIDDJm2GyjAqhoX3GW9tif+JzcemNlTrUUfXBvV9 9GqMm2jkW3NPe7qDi/Dm2GPpiSaho8PPSFRGPA49aXTlT8HTZ9Q5bmkJ5toIt8W31beV 42pNSAjmYXWecBAsajoU3u+6X1FGu7Rl1LmOnXeka9wmb26WxO2ylVGpupDI5oxobQuk o2vg== 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=j1HHKQpv5asbS7zXpA/KWjRl+aND7sfZOUIRchm3QA0=; b=kcYArvbwdbV2PuDUZN02BMVSeGbehok4dLOH8zdDFRNEepFxur3xsSpcnghj66gvXd 47wNsgs0HBkjHMXVnLZwQmgmIhMEdLlldXXeqlbgjSvNiOal5s7uRIl7Hm22PNJvtgnQ ZffzqAILgIN9G8f1I8dbADRISbr22fBPXEM6LM5gixp3CoH/mHfZFgNjbiDotllV0T6m Ibq8w6N+qfBPdFFnrDH68pT5s8gH3m+E8Uw3S+8hzZVH8jc1Qbog52qpUN01bWf36rMv An+mFgcN8whCTw6hFL0nsWCJqH6uOCC+JpSg8mDOG64aS9lEuA+dHGwZyrrKZ8eMPkdY xNrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cRhWTiWF; 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 z16si16456302wro.399.2021.06.14.13.33.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jun 2021 13:33:32 -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=cRhWTiWF; 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]:43522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lstH1-0000S2-8V for patch@linaro.org; Mon, 14 Jun 2021 16:33:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lstCc-0001oD-By for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:58 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:35423) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lstCa-0005ka-G7 for qemu-devel@nongnu.org; Mon, 14 Jun 2021 16:28:58 -0400 Received: by mail-pj1-x1029.google.com with SMTP id fy24-20020a17090b0218b029016c5a59021fso363521pjb.0 for ; Mon, 14 Jun 2021 13:28:56 -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=j1HHKQpv5asbS7zXpA/KWjRl+aND7sfZOUIRchm3QA0=; b=cRhWTiWFDsaWm9Mj7pZLkO0jXgi33MRfRjxgAFryiplemV2DyM1CXSYYaRxGTQlSqI 8b6MiscUKMLlkLaNhcjouWej6JeGSYGKx/Dzn4oSEutilczNS80K3Yzn3IR/hMXI89+b qswn/17Fz3+jxoUND0qYFVzEN2BbtpgL86J0UEiErnxND1TPRDYzm/205MFeLu+uOsni Fw7mB9sX1Fb+mGrP8oocHQWgzKkK1ZaVl4l/o+PA184EZQcnG22FZ3FGf0dK7uwm8R8E yVymH9xeH3YS3IiCHjt2lppD0IUFpuJoKYhxBVUX1NmAoi4WOhgPdcswMg2g9NwZwaNT ucVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j1HHKQpv5asbS7zXpA/KWjRl+aND7sfZOUIRchm3QA0=; b=B/u3lDGKOrOF1ELkAJjHZHTZ37RDBw1ncDhDjzAaQUBlXfDl24m6OqFHO4ew4Pv/Zn V7mQEblIJog2E5nGaeiEo3/p650sT50/szVfEpl2vINDaOOEF/vrLf4TWsAUDe6c7ezq 5HBie3GAILClSPFMNl3MqVlmnlMRUVaq/d44yXlLuaHF++med0+EaibZPTJ6fku/+7Jz BXCXI/Nf4NHQ+ayq+C7exIXS2eI1oWsC6kgeUXduQAXJ5w7BMok2D2UX5VycSK1e5mGx Sr2V/elyyckRnYTfx4x/CttKrbFfCYRUGDGHrP+xKm6kv4ROKmUIuhsN7afPdr6XhxnK zBqw== X-Gm-Message-State: AOAM532VSKl/idSUJgkQYpbBP0Ym2xmqUYdzQs9J0MMkrzL6PQFGopcy HhFHGxFABJJBC15O4PNWJ6y/rA== X-Received: by 2002:a17:90b:4d8c:: with SMTP id oj12mr20619128pjb.188.1623702535323; Mon, 14 Jun 2021 13:28:55 -0700 (PDT) Received: from p14s.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id fs10sm289029pjb.31.2021.06.14.13.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 13:28:54 -0700 (PDT) From: Mathieu Poirier To: mst@redhat.com, alex.bennee@linaro.org Subject: [PATCH v2 5/5] MAINTAINERS: Add maintainer for vhost-user RNG implementation Date: Mon, 14 Jun 2021 14:28:42 -0600 Message-Id: <20210614202842.581640-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614202842.581640-1-mathieu.poirier@linaro.org> References: <20210614202842.581640-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=mathieu.poirier@linaro.org; helo=mail-pj1-x1029.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: qemu-devel@nongnu.org, stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This patch adds entry for the vhost-user-rng related files. Signed-off-by: Mathieu Poirier --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.25.1 diff --git a/MAINTAINERS b/MAINTAINERS index 36055f14c594..4fedca72c183 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1951,6 +1951,15 @@ F: include/sysemu/rng*.h F: backends/rng*.c F: tests/qtest/virtio-rng-test.c +vhost-user-rng +M: Mathieu Poirier +S: Supported +F: docs/tools/vhost-user-rng.rst +F: hw/virtio/vhost-user-rng.c +F: hw/virtio/vhost-user-rng-pci.c +F: include/hw/virtio/vhost-user-rng.h +F: tools/vhost-user-rng/* + virtio-crypto M: Gonglei S: Supported