[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YLSC6AthAl+VeQsv@kroah.com>
Date: Mon, 31 May 2021 08:32:08 +0200
From: Greg KH <gregkh@...uxfoundation.org>
To: Yongji Xie <xieyongji@...edance.com>
Cc: "Michael S. Tsirkin" <mst@...hat.com>,
Jason Wang <jasowang@...hat.com>,
Stefan Hajnoczi <stefanha@...hat.com>,
Stefano Garzarella <sgarzare@...hat.com>,
Parav Pandit <parav@...dia.com>,
Christoph Hellwig <hch@...radead.org>,
Christian Brauner <christian.brauner@...onical.com>,
Randy Dunlap <rdunlap@...radead.org>,
Matthew Wilcox <willy@...radead.org>,
Al Viro <viro@...iv.linux.org.uk>,
Jens Axboe <axboe@...nel.dk>, bcrl@...ck.org,
Jonathan Corbet <corbet@....net>,
Mika Penttilä <mika.penttila@...tfour.com>,
Dan Carpenter <dan.carpenter@...cle.com>, joro@...tes.org,
virtualization <virtualization@...ts.linux-foundation.org>,
netdev@...r.kernel.org, kvm <kvm@...r.kernel.org>,
linux-fsdevel@...r.kernel.org, iommu@...ts.linux-foundation.org,
linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: Re: [PATCH v7 11/12] vduse: Introduce VDUSE - vDPA Device in
Userspace
On Mon, May 31, 2021 at 02:19:37PM +0800, Yongji Xie wrote:
> Hi Greg,
>
> Thanks a lot for the review!
>
> On Mon, May 31, 2021 at 12:56 PM Greg KH <gregkh@...uxfoundation.org> wrote:
> >
> > On Mon, May 17, 2021 at 05:55:12PM +0800, Xie Yongji wrote:
> > > +struct vduse_dev {
> > > + struct vduse_vdpa *vdev;
> > > + struct device dev;
> > > + struct cdev cdev;
> >
> > You now have 2 reference counted devices controling the lifespace of a
> > single structure. A mess that is guaranteed to go wrong. Please never
> > do this.
> >
>
> These two are both used by cdev_device_add(). Looks like I didn't find
> any problem. Any suggestions?
Make one of these dynamic and do not have them both control the lifespan
of the structure.
> > > + struct vduse_virtqueue *vqs;
> > > + struct vduse_iova_domain *domain;
> > > + char *name;
> > > + struct mutex lock;
> > > + spinlock_t msg_lock;
> > > + atomic64_t msg_unique;
> >
> > Why do you need an atomic and a lock?
> >
>
> You are right. We don't need an atomic here.
>
> > > + wait_queue_head_t waitq;
> > > + struct list_head send_list;
> > > + struct list_head recv_list;
> > > + struct list_head list;
> > > + struct vdpa_callback config_cb;
> > > + struct work_struct inject;
> > > + spinlock_t irq_lock;
> > > + unsigned long api_version;
> > > + bool connected;
> > > + int minor;
> > > + u16 vq_size_max;
> > > + u32 vq_num;
> > > + u32 vq_align;
> > > + u32 config_size;
> > > + u32 device_id;
> > > + u32 vendor_id;
> > > +};
> > > +
> > > +struct vduse_dev_msg {
> > > + struct vduse_dev_request req;
> > > + struct vduse_dev_response resp;
> > > + struct list_head list;
> > > + wait_queue_head_t waitq;
> > > + bool completed;
> > > +};
> > > +
> > > +struct vduse_control {
> > > + unsigned long api_version;
> >
> > u64?
> >
>
> OK.
>
> > > +};
> > > +
> > > +static unsigned long max_bounce_size = (64 * 1024 * 1024);
> > > +module_param(max_bounce_size, ulong, 0444);
> > > +MODULE_PARM_DESC(max_bounce_size, "Maximum bounce buffer size. (default: 64M)");
> > > +
> > > +static unsigned long max_iova_size = (128 * 1024 * 1024);
> > > +module_param(max_iova_size, ulong, 0444);
> > > +MODULE_PARM_DESC(max_iova_size, "Maximum iova space size (default: 128M)");
> > > +
> > > +static bool allow_unsafe_device_emulation;
> > > +module_param(allow_unsafe_device_emulation, bool, 0444);
> > > +MODULE_PARM_DESC(allow_unsafe_device_emulation, "Allow emulating unsafe device."
> > > + " We must make sure the userspace device emulation process is trusted."
> > > + " Otherwise, don't enable this option. (default: false)");
> > > +
> >
> > This is not the 1990's anymore, please never use module parameters, make
> > these per-device attributes if you really need them.
> >
>
> These parameters will be used before the device is created. Or do you
> mean add some attributes to the control device?
You need to do something, as no one can mess with a module parameter
easily. Why do you need them at all, shouldn't it "just work" properly
with no need for userspace interaction?
> > > +static int vduse_init(void)
> > > +{
> > > + int ret;
> > > +
> > > + if (max_bounce_size >= max_iova_size)
> > > + return -EINVAL;
> > > +
> > > + ret = misc_register(&vduse_misc);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + vduse_class = class_create(THIS_MODULE, "vduse");
> >
> > If you have a misc device, you do not need to create a class at the same
> > time. Why are you doing both here? Just stick with the misc device, no
> > need for anything else.
> >
>
> The misc device is the control device represented by
> /dev/vduse/control. Then a VDUSE device represented by
> /dev/vduse/$NAME can be created by the ioctl(VDUSE_CREATE_DEV) on this
> control device.
Ah. Then how about using the same MAJOR for all of these, and just have
the first minor (0) be your control? That happens for other device
types (raw, loop, etc.). Or just document this really well please, as
it was not obvious what you were doing here.
thanks,
greg k-h
Powered by blists - more mailing lists