Re: [PATCH V13 6/6] docs: sample driver to demonstrate how to implement virtio-mdev framework

From: Jason Wang
Date: Mon Nov 18 2019 - 22:05:33 EST



On 2019/11/18 äå11:45, Cornelia Huck wrote:
On Mon, 18 Nov 2019 18:59:23 +0800
Jason Wang <jasowang@xxxxxxxxxx> wrote:

[Note: I have not looked into the reworked architecture of this *at all*
so far; just something that I noted...]

This sample driver creates mdev device that simulate virtio net device
over virtio mdev transport. The device is implemented through vringh
and workqueue. A device specific dma ops is to make sure HVA is used
directly as the IOVA. This should be sufficient for kernel virtio
driver to work.

Only 'virtio' type is supported right now. I plan to add 'vhost' type
on top which requires some virtual IOMMU implemented in this sample
driver.

Signed-off-by: Jason Wang <jasowang@xxxxxxxxxx>
---
MAINTAINERS | 1 +
samples/Kconfig | 10 +
samples/vfio-mdev/Makefile | 1 +
samples/vfio-mdev/mvnet_loopback.c | 690 +++++++++++++++++++++++++++++
4 files changed, 702 insertions(+)
create mode 100644 samples/vfio-mdev/mvnet_loopback.c

+static struct mvnet_dev {
+ struct class *vd_class;
+ struct idr vd_idr;
+ struct device dev;
+} mvnet_dev;
This structure embeds a struct device (a reference-counted structure),
yet it is a static variable. This is giving a bad example to potential
implementers; just allocate it dynamically.


Yes, as spotted by Greg.



+static void mvnet_device_release(struct device *dev)
+{
+ dev_dbg(dev, "mvnet: released\n");
And that also means you need a proper release function here, of
course.


Right.

Thanks



+}