From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [PATCH v3 1/4] vhost-user-rng: Add vhost-user-rng implementation
Date: Thu, 22 Jul 2021 10:44:55 -0600 [thread overview]
Message-ID: <20210722164455.GA2446676@p14s> (raw)
In-Reply-To: <87mtqgkpub.fsf@linaro.org>
Hi Alex,
On Wed, Jul 21, 2021 at 09:52:50AM +0100, Alex Bennée wrote:
>
> Mathieu Poirier <mathieu.poirier@linaro.org> writes:
>
> > 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 <mathieu.poirier@linaro.org>
> > ---
> > hw/virtio/Kconfig | 5 +
> > hw/virtio/meson.build | 1 +
>
> FWIW there are simple merge failures for the meson and Kconfig parts due
> to I2C being merged.
>
Right, merging I2C before this set will definitely break things.
> <snip>
> > +
> > + 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;
> > + }
>
> g_new0 will abort on memory allocation failure (which is fine for
> userspace ;-) so you don't need the check and erro handling exit here.
>
Ok, I'll fix this.
> > +
> > + 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 <mathieu.poirier@linaro.org>
> > + *
> > + * 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 */
>
> Otherwise:
>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Thanks for taking the time to review this set.
>
> --
> Alex Bennée
next prev parent reply other threads:[~2021-07-22 16:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-10 0:59 [PATCH v3 0/4] virtio: Add vhost-user based RNG Mathieu Poirier
2021-07-10 0:59 ` [PATCH v3 1/4] vhost-user-rng: Add vhost-user-rng implementation Mathieu Poirier
2021-07-21 8:52 ` Alex Bennée
2021-07-22 16:44 ` Mathieu Poirier [this message]
2021-07-10 0:59 ` [PATCH v3 2/4] vhost-user-rng-pci: Add vhost-user-rng-pci implementation Mathieu Poirier
2021-07-21 8:56 ` Alex Bennée
2021-07-21 20:15 ` Alex Bennée
2021-07-10 0:59 ` [PATCH v3 3/4] vhost-user-rng: backend: Add RNG vhost-user daemon implementation Mathieu Poirier
2021-07-21 11:30 ` Alex Bennée
2021-07-21 20:14 ` Alex Bennée
2021-07-22 17:54 ` Mathieu Poirier
2021-07-23 9:01 ` Alex Bennée
2021-07-10 0:59 ` [PATCH v3 4/4] docs: Add documentation for vhost based RNG implementation Mathieu Poirier
2021-07-21 16:55 ` Alex Bennée
2021-07-17 20:32 ` [PATCH v3 0/4] virtio: Add vhost-user based RNG Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210722164455.GA2446676@p14s \
--to=mathieu.poirier@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).