Re: [PATCH v3 02/19] vdpa_sim: remove unnecessary headers inclusion

2020-12-03 Thread Stefano Garzarella

Hi Randy,

On Thu, Dec 03, 2020 at 09:37:48AM -0800, Randy Dunlap wrote:

On 12/3/20 9:04 AM, Stefano Garzarella wrote:

Some headers are not necessary, so let's remove them to do
some cleaning.

Signed-off-by: Stefano Garzarella 


Hi,
What makes you say that some of these are unnecessary?

Please use Rule #1 from Documentation/process/submit-checklist.rst:

1) If you use a facility then #include the file that defines/declares
  that facility.  Don't depend on other header files pulling in ones
  that you use.


so just because it will compile without these headers being explictly
#included does not mean that you should remove them.


Thanks for the clarification. I tried to follow this rule already 
pointed out by Jason, but of course I missed the __init and __exit 
macros...


I'll check better for the next version!





---
v3:
- avoided to remove some headers with structures and functions directly
  used (device.h, slab.h, virtio_byteorder.h)[Jason]
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 6a90fdb9cbfc..b08f28d20d8d 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -7,20 +7,10 @@
  *
  */

-#include 


above is used by __init and __exit.


 #include 
 #include 
-#include 
-#include 
-#include 


Looks OK to remove poll.h.


 #include 
-#include 


Might be OK for sched.h.


-#include 


Might be OK for wait.h.


-#include 
-#include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 



I didn't check the others.



Thanks,
Stefano

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v3 19/19] vdpa: split vdpasim to core and net modules

2020-12-03 Thread Stefano Garzarella

On Thu, Dec 03, 2020 at 09:25:52AM -0800, Randy Dunlap wrote:

Hi,

On 12/3/20 9:05 AM, Stefano Garzarella wrote:

diff --git a/drivers/vdpa/Kconfig b/drivers/vdpa/Kconfig
index 2c892e890b9e..b0f91ad8eb47 100644
--- a/drivers/vdpa/Kconfig
+++ b/drivers/vdpa/Kconfig
@@ -9,15 +9,20 @@ menuconfig VDPA
 if VDPA

 config VDPA_SIM
-   tristate "vDPA device simulator"
+   tristate "vDPA device simulator core"
depends on RUNTIME_TESTING_MENU && HAS_DMA
select DMA_OPS
select VHOST_RING
+   help
+ Enable this module to support vDPA device simulators. These devices
+ are used for testing, prototyping and development of vDPA.
+
+config VDPA_SIM_NET
+   tristate "vDPA simulator for networking device"
+   depends on VDPA_SIM
select GENERIC_NET_UTILS
help
- vDPA networking device simulator which loop TX traffic back
- to RX. This device is used for testing, prototyping and
- development of vDPA.
+ vDPA networking device simulator which loop TX traffic back to RX.


 loops


It was pre-existing, but since I'm there I'll fix it, thanks!

Stefano

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH net-next] tun: fix ubuf refcount incorrectly on error path

2020-12-03 Thread Jason Wang


On 2020/12/3 下午4:00, wangyunjian wrote:

From: Yunjian Wang 

After setting callback for ubuf_info of skb, the callback
(vhost_net_zerocopy_callback) will be called to decrease
the refcount when freeing skb. But when an exception occurs
afterwards, the error handling in vhost handle_tx() will
try to decrease the same refcount again. This is wrong and
fix this by clearing ubuf_info when meeting errors.

Fixes: 4477138fa0ae ("tun: properly test for IFF_UP")
Fixes: 90e33d459407 ("tun: enable napi_gro_frags() for TUN/TAP driver")

Signed-off-by: Yunjian Wang 
---
  drivers/net/tun.c | 11 +++
  1 file changed, 11 insertions(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 2dc1988a8973..3614bb1b6d35 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1861,6 +1861,12 @@ static ssize_t tun_get_user(struct tun_struct *tun, 
struct tun_file *tfile,
if (unlikely(!(tun->dev->flags & IFF_UP))) {
err = -EIO;
rcu_read_unlock();
+   if (zerocopy) {
+   skb_shinfo(skb)->destructor_arg = NULL;
+   skb_shinfo(skb)->tx_flags &= ~SKBTX_DEV_ZEROCOPY;
+   skb_shinfo(skb)->tx_flags &= ~SKBTX_SHARED_FRAG;
+   }
+
goto drop;
}
  
@@ -1874,6 +1880,11 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
  
  		if (unlikely(headlen > skb_headlen(skb))) {

atomic_long_inc(>dev->rx_dropped);
+   if (zerocopy) {
+   skb_shinfo(skb)->destructor_arg = NULL;
+   skb_shinfo(skb)->tx_flags &= 
~SKBTX_DEV_ZEROCOPY;
+   skb_shinfo(skb)->tx_flags &= ~SKBTX_SHARED_FRAG;
+   }
napi_free_frags(>napi);
rcu_read_unlock();
mutex_unlock(>napi_mutex);



It looks to me then we miss the failure feedback.

The issues comes from the inconsistent error handling in tun.

I wonder whether we can simply do uarg->callback(uarg, false) if 
necessary on every failture path on tun_get_user().


Note that, zerocopy has a lot of issues which makes it not good for 
production environment.


Thanks

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

[PATCH V2 19/19] vdpa: introduce virtio pci driver

2020-12-03 Thread Jason Wang
This patch introduce a vDPA driver for virtio-pci device. It bridges
the virtio-pci control command to the vDPA bus. This will be used for
features prototyping and testing.

Note that get/restore virtqueue state is not supported which needs
extension on the virtio specification.

Signed-off-by: Jason Wang 
---
 drivers/vdpa/Kconfig  |   6 +
 drivers/vdpa/Makefile |   1 +
 drivers/vdpa/virtio_pci/Makefile  |   2 +
 drivers/vdpa/virtio_pci/vp_vdpa.c | 455 ++
 4 files changed, 464 insertions(+)
 create mode 100644 drivers/vdpa/virtio_pci/Makefile
 create mode 100644 drivers/vdpa/virtio_pci/vp_vdpa.c

diff --git a/drivers/vdpa/Kconfig b/drivers/vdpa/Kconfig
index 358f6048dd3c..18cad14f533e 100644
--- a/drivers/vdpa/Kconfig
+++ b/drivers/vdpa/Kconfig
@@ -48,4 +48,10 @@ config MLX5_VDPA_NET
  be executed by the hardware. It also supports a variety of stateless
  offloads depending on the actual device used and firmware version.
 
+config VP_VDPA
+   tristate "Virtio PCI bridge vDPA driver"
+   depends on PCI_MSI && VIRTIO_PCI_MODERN
+   help
+ This kernel module that bridges virtio PCI device to vDPA bus.
+
 endif # VDPA
diff --git a/drivers/vdpa/Makefile b/drivers/vdpa/Makefile
index d160e9b63a66..67fe7f3d6943 100644
--- a/drivers/vdpa/Makefile
+++ b/drivers/vdpa/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_VDPA) += vdpa.o
 obj-$(CONFIG_VDPA_SIM) += vdpa_sim/
 obj-$(CONFIG_IFCVF)+= ifcvf/
 obj-$(CONFIG_MLX5_VDPA) += mlx5/
+obj-$(CONFIG_VP_VDPA)+= virtio_pci/
diff --git a/drivers/vdpa/virtio_pci/Makefile b/drivers/vdpa/virtio_pci/Makefile
new file mode 100644
index ..231088d3af7d
--- /dev/null
+++ b/drivers/vdpa/virtio_pci/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_VP_VDPA) += vp_vdpa.o
diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c 
b/drivers/vdpa/virtio_pci/vp_vdpa.c
new file mode 100644
index ..fa0321e77fb3
--- /dev/null
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -0,0 +1,455 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * vDPA bridge driver for modern virtio-pci device
+ *
+ * Copyright (c) 2020, Red Hat Inc. All rights reserved.
+ * Author: Jason Wang 
+ *
+ * Based on virtio_pci_modern.c.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define VP_VDPA_QUEUE_MAX 256
+#define VP_VDPA_DRIVER_NAME "vp_vdpa"
+
+struct vp_vring {
+   void __iomem *notify;
+   char msix_name[256];
+   struct vdpa_callback cb;
+   int irq;
+};
+
+struct vp_vdpa {
+   struct vdpa_device vdpa;
+   struct virtio_pci_modern_device mdev;
+   struct vp_vring *vring;
+   struct vdpa_callback cb;
+   char msix_name[256];
+   int config_irq;
+   int queues;
+   int vectors;
+};
+
+static struct vp_vdpa *vdpa_to_vp(struct vdpa_device *vdpa)
+{
+   return container_of(vdpa, struct vp_vdpa, vdpa);
+}
+
+static struct virtio_pci_modern_device *vdpa_to_mdev(struct vdpa_device *vdpa)
+{
+   struct vp_vdpa *vp_vdpa = vdpa_to_vp(vdpa);
+
+   return _vdpa->mdev;
+}
+
+static u64 vp_vdpa_get_features(struct vdpa_device *vdpa)
+{
+   struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
+
+   return vp_modern_get_features(mdev);
+}
+
+static int vp_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+   struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
+
+   vp_modern_set_features(mdev, features);
+
+   return 0;
+}
+
+static u8 vp_vdpa_get_status(struct vdpa_device *vdpa)
+{
+   struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
+
+   return vp_modern_get_status(mdev);
+}
+
+static void vp_vdpa_free_irq(struct vp_vdpa *vp_vdpa)
+{
+   struct virtio_pci_modern_device *mdev = _vdpa->mdev;
+   struct pci_dev *pdev = mdev->pci_dev;
+   int i;
+
+   for (i = 0; i < vp_vdpa->queues; i++) {
+   if (vp_vdpa->vring[i].irq != VIRTIO_MSI_NO_VECTOR) {
+   vp_modern_queue_vector(mdev, i, VIRTIO_MSI_NO_VECTOR);
+   devm_free_irq(>dev, vp_vdpa->vring[i].irq,
+ _vdpa->vring[i]);
+   vp_vdpa->vring[i].irq = VIRTIO_MSI_NO_VECTOR;
+   }
+   }
+
+   if (vp_vdpa->config_irq != VIRTIO_MSI_NO_VECTOR) {
+   vp_modern_config_vector(mdev, VIRTIO_MSI_NO_VECTOR);
+   devm_free_irq(>dev, vp_vdpa->config_irq, vp_vdpa);
+   vp_vdpa->config_irq = VIRTIO_MSI_NO_VECTOR;
+   }
+
+   if (vp_vdpa->vectors) {
+   pci_free_irq_vectors(pdev);
+   vp_vdpa->vectors = 0;
+   }
+}
+
+static irqreturn_t vp_vdpa_vq_handler(int irq, void *arg)
+{
+   struct vp_vring *vring = arg;
+
+   if (vring->cb.callback)
+   return vring->cb.callback(vring->cb.private);
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t 

[PATCH V2 18/19] virtio_vdpa: don't warn when fail to disable vq

2020-12-03 Thread Jason Wang
There's no guarantee that the device can disable a specific virtqueue
through set_vq_ready(). One example is the modern virtio-pci
device. So this patch removes the warning.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_vdpa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
index 4a9ddb44b2a7..e28acf482e0c 100644
--- a/drivers/virtio/virtio_vdpa.c
+++ b/drivers/virtio/virtio_vdpa.c
@@ -225,9 +225,8 @@ static void virtio_vdpa_del_vq(struct virtqueue *vq)
list_del(>node);
spin_unlock_irqrestore(_dev->lock, flags);
 
-   /* Select and deactivate the queue */
+   /* Select and deactivate the queue (best effort) */
ops->set_vq_ready(vdpa, index, 0);
-   WARN_ON(ops->get_vq_ready(vdpa, index));
 
vring_del_virtqueue(vq);
 
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 17/19] vdpa: set the virtqueue num during register

2020-12-03 Thread Jason Wang
This patch delay the queue number setting to vDPA device
registering. This allows us to probe the virtqueue numbers between
device allocation and registering.

Signed-off-by: Jason Wang 
---
 drivers/vdpa/ifcvf/ifcvf_main.c   | 5 ++---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 ++---
 drivers/vdpa/vdpa.c   | 8 
 drivers/vdpa/vdpa_sim/vdpa_sim.c  | 4 ++--
 include/linux/vdpa.h  | 7 +++
 5 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
index 8b4028556cb6..d65f3221d8ed 100644
--- a/drivers/vdpa/ifcvf/ifcvf_main.c
+++ b/drivers/vdpa/ifcvf/ifcvf_main.c
@@ -438,8 +438,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
}
 
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
-   dev, _vdpa_ops,
-   IFCVF_MAX_QUEUE_PAIRS * 2);
+   dev, _vdpa_ops);
if (adapter == NULL) {
IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
return -ENOMEM;
@@ -463,7 +462,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++)
vf->vring[i].irq = -EINVAL;
 
-   ret = vdpa_register_device(>vdpa);
+   ret = vdpa_register_device(>vdpa, IFCVF_MAX_QUEUE_PAIRS * 2);
if (ret) {
IFCVF_ERR(pdev, "Failed to register ifcvf to vdpa bus");
goto err;
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c 
b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 1fa6fcac8299..3c3eb2a02f76 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -1940,8 +1940,7 @@ void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev)
max_vqs = MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues);
max_vqs = min_t(u32, max_vqs, MLX5_MAX_SUPPORTED_VQS);
 
-   ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, 
mdev->device, _vdpa_ops,
-2 * mlx5_vdpa_max_qps(max_vqs));
+   ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, 
mdev->device, _vdpa_ops);
if (IS_ERR(ndev))
return ndev;
 
@@ -1968,7 +1967,7 @@ void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev)
if (err)
goto err_res;
 
-   err = vdpa_register_device(>vdev);
+   err = vdpa_register_device(>vdev, 2 * 
mlx5_vdpa_max_qps(max_vqs));
if (err)
goto err_reg;
 
diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index a69ffc991e13..ba89238f9898 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -61,7 +61,6 @@ static void vdpa_release_dev(struct device *d)
  * initialized but before registered.
  * @parent: the parent device
  * @config: the bus operations that is supported by this device
- * @nvqs: number of virtqueues supported by this device
  * @size: size of the parent structure that contains private data
  *
  * Driver should use vdpa_alloc_device() wrapper macro instead of
@@ -72,7 +71,6 @@ static void vdpa_release_dev(struct device *d)
  */
 struct vdpa_device *__vdpa_alloc_device(struct device *parent,
const struct vdpa_config_ops *config,
-   int nvqs,
size_t size)
 {
struct vdpa_device *vdev;
@@ -99,7 +97,6 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
vdev->index = err;
vdev->config = config;
vdev->features_valid = false;
-   vdev->nvqs = nvqs;
 
err = dev_set_name(>dev, "vdpa%u", vdev->index);
if (err)
@@ -122,11 +119,14 @@ EXPORT_SYMBOL_GPL(__vdpa_alloc_device);
  * vdpa_register_device - register a vDPA device
  * Callers must have a succeed call of vdpa_alloc_device() before.
  * @vdev: the vdpa device to be registered to vDPA bus
+ * @nvqs: number of virtqueues supported by this device
  *
  * Returns an error when fail to add to vDPA bus
  */
-int vdpa_register_device(struct vdpa_device *vdev)
+int vdpa_register_device(struct vdpa_device *vdev, int nvqs)
 {
+   vdev->nvqs = nvqs;
+
return device_add(>dev);
 }
 EXPORT_SYMBOL_GPL(vdpa_register_device);
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 6a90fdb9cbfc..b129cb4dd013 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -357,7 +357,7 @@ static struct vdpasim *vdpasim_create(void)
else
ops = _net_config_ops;
 
-   vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, 
VDPASIM_VQ_NUM);
+   vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops);
if (!vdpasim)
goto err_alloc;
 
@@ -393,7 +393,7 @@ static struct vdpasim *vdpasim_create(void)
vringh_set_iotlb(>vqs[1].vring, vdpasim->iommu);
 
 

[PATCH V2 16/19] virtio-pci: introduce modern device module

2020-12-03 Thread Jason Wang
Signed-off-by: Jason Wang 
---
 drivers/virtio/Kconfig |  10 +-
 drivers/virtio/Makefile|   1 +
 drivers/virtio/virtio_pci_common.h |  27 +-
 drivers/virtio/virtio_pci_modern.c | 617 -
 drivers/virtio/virtio_pci_modern_dev.c | 599 
 include/linux/virtio_pci_modern.h  | 111 +
 6 files changed, 721 insertions(+), 644 deletions(-)
 create mode 100644 drivers/virtio/virtio_pci_modern_dev.c
 create mode 100644 include/linux/virtio_pci_modern.h

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 7b41130d3f35..d1a6bd2a975f 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -12,6 +12,14 @@ config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
  This option is selected if the architecture may need to enforce
  VIRTIO_F_ACCESS_PLATFORM
 
+config VIRTIO_PCI_MODERN
+   tristate "Modern Virtio PCI Device"
+   depends on PCI
+   help
+ Modern PCI device implementation. This module implement the
+ basic probe and control for devices which is based on modern
+ PCI device with possible vendor specific extensions.
+
 menuconfig VIRTIO_MENU
bool "Virtio drivers"
default y
@@ -20,7 +28,7 @@ if VIRTIO_MENU
 
 config VIRTIO_PCI
tristate "PCI driver for virtio devices"
-   depends on PCI
+   depends on VIRTIO_PCI_MODERN
select VIRTIO
help
  This driver provides support for virtio based paravirtual device
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 591e6f72aa54..f097578aaa8f 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
+obj-$(CONFIG_VIRTIO_PCI_MODERN) += virtio_pci_modern_dev.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
 virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
diff --git a/drivers/virtio/virtio_pci_common.h 
b/drivers/virtio/virtio_pci_common.h
index f35ff5b6b467..beec047a8f8d 100644
--- a/drivers/virtio/virtio_pci_common.h
+++ b/drivers/virtio/virtio_pci_common.h
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -39,32 +40,6 @@ struct virtio_pci_vq_info {
unsigned msix_vector;
 };
 
-struct virtio_pci_modern_device {
-   struct pci_dev *pci_dev;
-
-   struct virtio_pci_common_cfg __iomem *common;
-   /* Device-specific data (non-legacy mode)  */
-   void __iomem *device;
-   /* Base of vq notifications (non-legacy mode). */
-   void __iomem *notify_base;
-   /* Where to read and clear interrupt */
-   u8 __iomem *isr;
-
-   /* So we can sanity-check accesses. */
-   size_t notify_len;
-   size_t device_len;
-
-   /* Capability for when we need to map notifications per-vq. */
-   int notify_map_cap;
-
-   /* Multiply queue_notify_off by this value. (non-legacy mode). */
-   u32 notify_offset_multiplier;
-
-   int modern_bars;
-
-   struct virtio_device_id id;
-};
-
 /* Our device structure */
 struct virtio_pci_device {
struct virtio_device vdev;
diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index a5e3a5e40323..fbd4ebc00eb6 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -19,158 +19,6 @@
 #define VIRTIO_RING_NO_LEGACY
 #include "virtio_pci_common.h"
 
-/*
- * Type-safe wrappers for io accesses.
- * Use these to enforce at compile time the following spec requirement:
- *
- * The driver MUST access each field using the “natural” access
- * method, i.e. 32-bit accesses for 32-bit fields, 16-bit accesses
- * for 16-bit fields and 8-bit accesses for 8-bit fields.
- */
-static inline u8 vp_ioread8(const u8 __iomem *addr)
-{
-   return ioread8(addr);
-}
-static inline u16 vp_ioread16 (const __le16 __iomem *addr)
-{
-   return ioread16(addr);
-}
-
-static inline u32 vp_ioread32(const __le32 __iomem *addr)
-{
-   return ioread32(addr);
-}
-
-static inline void vp_iowrite8(u8 value, u8 __iomem *addr)
-{
-   iowrite8(value, addr);
-}
-
-static inline void vp_iowrite16(u16 value, __le16 __iomem *addr)
-{
-   iowrite16(value, addr);
-}
-
-static inline void vp_iowrite32(u32 value, __le32 __iomem *addr)
-{
-   iowrite32(value, addr);
-}
-
-static void vp_iowrite64_twopart(u64 val,
-__le32 __iomem *lo, __le32 __iomem *hi)
-{
-   vp_iowrite32((u32)val, lo);
-   vp_iowrite32(val >> 32, hi);
-}
-
-/*
- * vp_modern_map_capability - map a part of virtio pci capability
- * @mdev: the modern virtio-pci device
- * @off: offset of the capability
- * @minlen: minimal length of the capability
- * @align: align requirement
- * @start: start from the capability
- * @size: map size
- * @len: the length that is actually mapped
- *
- * Returns the io address of for 

[PATCH V2 15/19] virito-pci-modern: rename map_capability() to vp_modern_map_capability()

2020-12-03 Thread Jason Wang
To ease the split, map_capability() was renamed to
vp_modern_map_capability(). While at it, add the comments for the
arguments and switch to use virtio_pci_modern_device as the first
parameter.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 46 +++---
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 217573f2588d..a5e3a5e40323 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -63,12 +63,25 @@ static void vp_iowrite64_twopart(u64 val,
vp_iowrite32(val >> 32, hi);
 }
 
-static void __iomem *map_capability(struct pci_dev *dev, int off,
-   size_t minlen,
-   u32 align,
-   u32 start, u32 size,
-   size_t *len)
+/*
+ * vp_modern_map_capability - map a part of virtio pci capability
+ * @mdev: the modern virtio-pci device
+ * @off: offset of the capability
+ * @minlen: minimal length of the capability
+ * @align: align requirement
+ * @start: start from the capability
+ * @size: map size
+ * @len: the length that is actually mapped
+ *
+ * Returns the io address of for the part of the capability
+ */
+void __iomem *vp_modern_map_capability(struct virtio_pci_modern_device *mdev, 
int off,
+  size_t minlen,
+  u32 align,
+  u32 start, u32 size,
+  size_t *len)
 {
+   struct pci_dev *dev = mdev->pci_dev;
u8 bar;
u32 offset, length;
void __iomem *p;
@@ -582,7 +595,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
vq->priv = (void __force *)mdev->notify_base +
off * mdev->notify_offset_multiplier;
} else {
-   vq->priv = (void __force *)map_capability(mdev->pci_dev,
+   vq->priv = (void __force *)vp_modern_map_capability(mdev,
  mdev->notify_map_cap, 
2, 2,
  off * 
mdev->notify_offset_multiplier, 2,
  NULL);
@@ -956,15 +969,15 @@ static int vp_modern_probe(struct 
virtio_pci_modern_device *mdev)
return err;
 
err = -EINVAL;
-   mdev->common = map_capability(pci_dev, common,
+   mdev->common = vp_modern_map_capability(mdev, common,
  sizeof(struct virtio_pci_common_cfg), 4,
  0, sizeof(struct virtio_pci_common_cfg),
  NULL);
if (!mdev->common)
goto err_map_common;
-   mdev->isr = map_capability(pci_dev, isr, sizeof(u8), 1,
-  0, 1,
-  NULL);
+   mdev->isr = vp_modern_map_capability(mdev, isr, sizeof(u8), 1,
+0, 1,
+NULL);
if (!mdev->isr)
goto err_map_isr;
 
@@ -989,9 +1002,10 @@ static int vp_modern_probe(struct 
virtio_pci_modern_device *mdev)
 * Otherwise, map each VQ individually later.
 */
if ((u64)notify_length + (notify_offset % PAGE_SIZE) <= PAGE_SIZE) {
-   mdev->notify_base = map_capability(pci_dev, notify, 2, 2,
-  0, notify_length,
-  >notify_len);
+   mdev->notify_base = vp_modern_map_capability(mdev, notify,
+2, 2,
+0, notify_length,
+>notify_len);
if (!mdev->notify_base)
goto err_map_notify;
} else {
@@ -1002,9 +1016,9 @@ static int vp_modern_probe(struct 
virtio_pci_modern_device *mdev)
 * is more than enough for all existing devices.
 */
if (device) {
-   mdev->device = map_capability(pci_dev, device, 0, 4,
- 0, PAGE_SIZE,
- >device_len);
+   mdev->device = vp_modern_map_capability(mdev, device, 0, 4,
+   0, PAGE_SIZE,
+   >device_len);
if (!mdev->device)
goto err_map_device;
}
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 14/19] virtio-pci-modern: introduce helper to get notification offset

2020-12-03 Thread Jason Wang
This patch introduces help to get notification offset of modern device.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index bccad1329871..217573f2588d 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -303,6 +303,21 @@ static u16 vp_modern_get_num_queues(struct 
virtio_pci_modern_device *mdev)
return vp_ioread16(>common->num_queues);
 }
 
+/*
+ * vp_modern_get_queue_notify_off - get notification offset for a virtqueue
+ * @mdev: the modern virtio-pci device
+ * @index: the queue index
+ *
+ * Returns the notification offset for a virtqueue
+ */
+static u16 vp_modern_get_queue_notify_off(struct virtio_pci_modern_device 
*mdev,
+ u16 index)
+{
+   vp_iowrite16(index, >common->queue_select);
+
+   return vp_ioread16(>common->queue_notify_off);
+}
+
 /* virtio config->finalize_features() implementation */
 static int vp_finalize_features(struct virtio_device *vdev)
 {
@@ -516,7 +531,6 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
 {
 
struct virtio_pci_modern_device *mdev = _dev->mdev;
-   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
struct virtqueue *vq;
u16 num, off;
int err;
@@ -524,9 +538,6 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
if (index >= vp_modern_get_num_queues(mdev))
return ERR_PTR(-ENOENT);
 
-   /* Select the queue we're interested in */
-   vp_iowrite16(index, >queue_select);
-
/* Check if queue is either not available or already active. */
num = vp_modern_get_queue_size(mdev, index);
if (!num || vp_modern_get_queue_enable(mdev, index))
@@ -538,7 +549,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
}
 
/* get offset of notification word for this vq */
-   off = vp_ioread16(>queue_notify_off);
+   off = vp_modern_get_queue_notify_off(mdev, index);
 
info->msix_vector = msix_vec;
 
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 13/19] virtio-pci-modern: introduce helper for getting queue nums

2020-12-03 Thread Jason Wang
This patch introduces helper for getting queue num of modern device.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 7a89226135af..bccad1329871 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -292,6 +292,17 @@ static u16 vp_modern_get_queue_size(struct 
virtio_pci_modern_device *mdev,
 
 }
 
+/*
+ * vp_modern_get_num_queues - get the number of virtqueues
+ * @mdev: the modern virtio-pci device
+ *
+ * Returns the number of virtqueues
+ */
+static u16 vp_modern_get_num_queues(struct virtio_pci_modern_device *mdev)
+{
+   return vp_ioread16(>common->num_queues);
+}
+
 /* virtio config->finalize_features() implementation */
 static int vp_finalize_features(struct virtio_device *vdev)
 {
@@ -510,7 +521,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
u16 num, off;
int err;
 
-   if (index >= vp_ioread16(>num_queues))
+   if (index >= vp_modern_get_num_queues(mdev))
return ERR_PTR(-ENOENT);
 
/* Select the queue we're interested in */
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 12/19] virtio-pci-modern: introduce helper for setting/geting queue size

2020-12-03 Thread Jason Wang
This patch introduces helper for setting/getting queue size for modern
device.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 34 --
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 0e62820b83ff..7a89226135af 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -262,6 +262,36 @@ static bool vp_modern_get_queue_enable(struct 
virtio_pci_modern_device *mdev,
return vp_ioread16(>common->queue_enable);
 }
 
+/*
+ * vp_modern_set_queue_size - set size for a virtqueue
+ * @mdev: the modern virtio-pci device
+ * @index: the queue index
+ * @size: the size of the virtqueue
+ */
+static void vp_modern_set_queue_size(struct virtio_pci_modern_device *mdev,
+u16 index, u16 size)
+{
+   vp_iowrite16(index, >common->queue_select);
+   vp_iowrite16(size, >common->queue_size);
+
+}
+
+/*
+ * vp_modern_get_queue_size - get size for a virtqueue
+ * @mdev: the modern virtio-pci device
+ * @index: the queue index
+ *
+ * Returns the size of the virtqueue
+ */
+static u16 vp_modern_get_queue_size(struct virtio_pci_modern_device *mdev,
+   u16 index)
+{
+   vp_iowrite16(index, >common->queue_select);
+
+   return vp_ioread16(>common->queue_size);
+
+}
+
 /* virtio config->finalize_features() implementation */
 static int vp_finalize_features(struct virtio_device *vdev)
 {
@@ -487,7 +517,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
vp_iowrite16(index, >queue_select);
 
/* Check if queue is either not available or already active. */
-   num = vp_ioread16(>queue_size);
+   num = vp_modern_get_queue_size(mdev, index);
if (!num || vp_modern_get_queue_enable(mdev, index))
return ERR_PTR(-ENOENT);
 
@@ -510,7 +540,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
return ERR_PTR(-ENOMEM);
 
/* activate the queue */
-   vp_iowrite16(virtqueue_get_vring_size(vq), >queue_size);
+   vp_modern_set_queue_size(mdev, index, virtqueue_get_vring_size(vq));
vp_modern_queue_address(mdev, index, virtqueue_get_desc_addr(vq),
virtqueue_get_avail_addr(vq),
virtqueue_get_used_addr(vq));
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 11/19] virtio-pci-modern: introduce helper to set/get queue_enable

2020-12-03 Thread Jason Wang
This patch introduces a helper to set/get queue_enable for modern device.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 37 +-
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 05b21e18f46c..0e62820b83ff 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -234,6 +234,34 @@ static void vp_modern_queue_address(struct 
virtio_pci_modern_device *mdev,
 >queue_used_hi);
 }
 
+/*
+ * vp_modern_set_queue_enable - enable a virtqueue
+ * @mdev: the modern virtio-pci device
+ * @index: the queue index
+ * @enable: whether the virtqueue is enable or not
+ */
+static void vp_modern_set_queue_enable(struct virtio_pci_modern_device *mdev,
+  u16 index, bool enable)
+{
+   vp_iowrite16(index, >common->queue_select);
+   vp_iowrite16(enable, >common->queue_enable);
+}
+
+/*
+ * vp_modern_get_queue_enable - enable a virtqueue
+ * @mdev: the modern virtio-pci device
+ * @index: the queue index
+ *
+ * Returns whether a virtqueue is enabled or not
+ */
+static bool vp_modern_get_queue_enable(struct virtio_pci_modern_device *mdev,
+  u16 index)
+{
+   vp_iowrite16(index, >common->queue_select);
+
+   return vp_ioread16(>common->queue_enable);
+}
+
 /* virtio config->finalize_features() implementation */
 static int vp_finalize_features(struct virtio_device *vdev)
 {
@@ -460,7 +488,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
 
/* Check if queue is either not available or already active. */
num = vp_ioread16(>queue_size);
-   if (!num || vp_ioread16(>queue_enable))
+   if (!num || vp_modern_get_queue_enable(mdev, index))
return ERR_PTR(-ENOENT);
 
if (num & (num - 1)) {
@@ -538,7 +566,6 @@ static int vp_modern_find_vqs(struct virtio_device *vdev, 
unsigned nvqs,
  struct irq_affinity *desc)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   struct virtio_pci_common_cfg __iomem *cfg = vp_dev->mdev.common;
struct virtqueue *vq;
int rc = vp_find_vqs(vdev, nvqs, vqs, callbacks, names, ctx, desc);
 
@@ -548,10 +575,8 @@ static int vp_modern_find_vqs(struct virtio_device *vdev, 
unsigned nvqs,
/* Select and activate all queues. Has to be done last: once we do
 * this, there's no way to go back except reset.
 */
-   list_for_each_entry(vq, >vqs, list) {
-   vp_iowrite16(vq->index, >queue_select);
-   vp_iowrite16(1, >queue_enable);
-   }
+   list_for_each_entry(vq, >vqs, list)
+   vp_modern_set_queue_enable(_dev->mdev, vq->index, true);
 
return 0;
 }
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 10/19] virtio-pci-modern: introduce vp_modern_queue_address()

2020-12-03 Thread Jason Wang
This patch introduce a helper to set virtqueue address for modern address.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 33 --
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 05cd409c0731..05b21e18f46c 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -210,6 +210,30 @@ static u16 vp_modern_queue_vector(struct 
virtio_pci_modern_device *mdev,
return vp_ioread16(>queue_msix_vector);
 }
 
+/*
+ * vp_modern_queue_address - set the virtqueue address
+ * @mdev: the modern virtio-pci device
+ * @index: the queue index
+ * @desc_addr: address of the descriptor area
+ * @driver_addr: address of the driver area
+ * @device_addr: address of the device area
+ */
+static void vp_modern_queue_address(struct virtio_pci_modern_device *mdev,
+   u16 index, u64 desc_addr, u64 driver_addr,
+   u64 device_addr)
+{
+   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+
+   vp_iowrite16(index, >queue_select);
+
+   vp_iowrite64_twopart(desc_addr, >queue_desc_lo,
+>queue_desc_hi);
+   vp_iowrite64_twopart(driver_addr, >queue_avail_lo,
+>queue_avail_hi);
+   vp_iowrite64_twopart(device_addr, >queue_used_lo,
+>queue_used_hi);
+}
+
 /* virtio config->finalize_features() implementation */
 static int vp_finalize_features(struct virtio_device *vdev)
 {
@@ -459,12 +483,9 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
 
/* activate the queue */
vp_iowrite16(virtqueue_get_vring_size(vq), >queue_size);
-   vp_iowrite64_twopart(virtqueue_get_desc_addr(vq),
->queue_desc_lo, >queue_desc_hi);
-   vp_iowrite64_twopart(virtqueue_get_avail_addr(vq),
->queue_avail_lo, >queue_avail_hi);
-   vp_iowrite64_twopart(virtqueue_get_used_addr(vq),
->queue_used_lo, >queue_used_hi);
+   vp_modern_queue_address(mdev, index, virtqueue_get_desc_addr(vq),
+   virtqueue_get_avail_addr(vq),
+   virtqueue_get_used_addr(vq));
 
if (mdev->notify_base) {
/* offset should not wrap */
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 09/19] virtio-pci-modern: introduce vp_modern_set_queue_vector()

2020-12-03 Thread Jason Wang
This patch introduces a helper to set virtqueue MSI vector.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 35 --
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index a128e5814045..05cd409c0731 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -191,6 +191,25 @@ static void vp_modern_set_features(struct 
virtio_pci_modern_device *mdev,
vp_iowrite32(features >> 32, >guest_feature);
 }
 
+/*
+ * vp_modern_queue_vector - set the MSIX vector for a specific virtqueue
+ * @mdev: the modern virtio-pci device
+ * @index: queue index
+ * @vector: the config vector
+ *
+ * Returns the config vector read from the device
+ */
+static u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,
+ u16 index, u16 vector)
+{
+   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+
+   vp_iowrite16(index, >queue_select);
+   vp_iowrite16(vector, >queue_msix_vector);
+   /* Flush the write out to device */
+   return vp_ioread16(>queue_msix_vector);
+}
+
 /* virtio config->finalize_features() implementation */
 static int vp_finalize_features(struct virtio_device *vdev)
 {
@@ -474,8 +493,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device 
*vp_dev,
}
 
if (msix_vec != VIRTIO_MSI_NO_VECTOR) {
-   vp_iowrite16(msix_vec, >queue_msix_vector);
-   msix_vec = vp_ioread16(>queue_msix_vector);
+   msix_vec = vp_modern_queue_vector(mdev, index, msix_vec);
if (msix_vec == VIRTIO_MSI_NO_VECTOR) {
err = -EBUSY;
goto err_assign_vector;
@@ -522,17 +540,10 @@ static void del_vq(struct virtio_pci_vq_info *info)
struct virtqueue *vq = info->vq;
struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
struct virtio_pci_modern_device *mdev = _dev->mdev;
-   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
-
 
-   vp_iowrite16(vq->index, >queue_select);
-
-   if (vp_dev->msix_enabled) {
-   vp_iowrite16(VIRTIO_MSI_NO_VECTOR,
->queue_msix_vector);
-   /* Flush the write out to device */
-   vp_ioread16(>queue_msix_vector);
-   }
+   if (vp_dev->msix_enabled)
+   vp_modern_queue_vector(mdev, vq->index,
+  VIRTIO_MSI_NO_VECTOR);
 
if (!mdev->notify_base)
pci_iounmap(mdev->pci_dev, (void __force __iomem *)vq->priv);
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 08/19] virtio-pci-modern: introduce vp_modern_generation()

2020-12-03 Thread Jason Wang
This patch introduces vp_modern_generation() to get device generation.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index cb14fc334a9c..a128e5814045 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -289,15 +289,26 @@ static void vp_set(struct virtio_device *vdev, unsigned 
offset,
}
 }
 
-static u32 vp_generation(struct virtio_device *vdev)
+/*
+ * vp_modern_generation - get the device genreation
+ * @mdev: the modern virtio-pci device
+ *
+ * Returns the genreation read from device
+ */
+static u32 vp_modern_generation(struct virtio_pci_modern_device *mdev)
 {
-   struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   struct virtio_pci_modern_device *mdev = _dev->mdev;
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
 
return vp_ioread8(>config_generation);
 }
 
+static u32 vp_generation(struct virtio_device *vdev)
+{
+   struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+
+   return vp_modern_generation(_dev->mdev);
+}
+
 /*
  * vp_modern_get_status - get the device status
  * @mdev: the modern virtio-pci device
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 07/19] virtio-pci-modern: introduce helpers for setting and getting features

2020-12-03 Thread Jason Wang
This patch introduces helpers for setting and getting features.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 43 +++---
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index ccde0a41209a..cb14fc334a9c 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -137,12 +137,16 @@ static void __iomem *map_capability(struct pci_dev *dev, 
int off,
return p;
 }
 
-/* virtio config->get_features() implementation */
-static u64 vp_get_features(struct virtio_device *vdev)
+/*
+ * vp_modern_get_features - get features from device
+ * @mdev: the modern virtio-pci device
+ *
+ * Returns the features read from the device
+ */
+static u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev)
 {
-   struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   struct virtio_pci_modern_device *mdev = _dev->mdev;
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+
u64 features;
 
vp_iowrite32(0, >device_feature_select);
@@ -153,6 +157,14 @@ static u64 vp_get_features(struct virtio_device *vdev)
return features;
 }
 
+/* virtio config->get_features() implementation */
+static u64 vp_get_features(struct virtio_device *vdev)
+{
+   struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+
+   return vp_modern_get_features(_dev->mdev);
+}
+
 static void vp_transport_features(struct virtio_device *vdev, u64 features)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
@@ -163,12 +175,26 @@ static void vp_transport_features(struct virtio_device 
*vdev, u64 features)
__virtio_set_bit(vdev, VIRTIO_F_SR_IOV);
 }
 
+/*
+ * vp_modern_set_features - set features to device
+ * @mdev: the modern virtio-pci device
+ * @features: the features set to device
+ */
+static void vp_modern_set_features(struct virtio_pci_modern_device *mdev,
+  u64 features)
+{
+   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+
+   vp_iowrite32(0, >guest_feature_select);
+   vp_iowrite32((u32)features, >guest_feature);
+   vp_iowrite32(1, >guest_feature_select);
+   vp_iowrite32(features >> 32, >guest_feature);
+}
+
 /* virtio config->finalize_features() implementation */
 static int vp_finalize_features(struct virtio_device *vdev)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   struct virtio_pci_modern_device *mdev = _dev->mdev;
-   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
u64 features = vdev->features;
 
/* Give virtio_ring a chance to accept features. */
@@ -183,10 +209,7 @@ static int vp_finalize_features(struct virtio_device *vdev)
return -EINVAL;
}
 
-   vp_iowrite32(0, >guest_feature_select);
-   vp_iowrite32((u32)vdev->features, >guest_feature);
-   vp_iowrite32(1, >guest_feature_select);
-   vp_iowrite32(vdev->features >> 32, >guest_feature);
+   vp_modern_set_features(_dev->mdev, vdev->features);
 
return 0;
 }
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 06/19] virtio-pci-modern: introduce helpers for setting and getting status

2020-12-03 Thread Jason Wang
This patch introduces helpers to allow set and get device status.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 37 +++---
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 2e37bfc89655..ccde0a41209a 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -275,41 +275,62 @@ static u32 vp_generation(struct virtio_device *vdev)
return vp_ioread8(>config_generation);
 }
 
+/*
+ * vp_modern_get_status - get the device status
+ * @mdev: the modern virtio-pci device
+ *
+ * Returns the status read from device
+ */
+static u8 vp_modern_get_status(struct virtio_pci_modern_device *mdev)
+{
+   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+
+   return vp_ioread8(>device_status);
+}
+
 /* config->{get,set}_status() implementations */
 static u8 vp_get_status(struct virtio_device *vdev)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   struct virtio_pci_modern_device *mdev = _dev->mdev;
+
+   return vp_modern_get_status(_dev->mdev);
+}
+
+/*
+ * vp_modern_set_status - set status to device
+ * @mdev: the modern virtio-pci device
+ * @status: the status set to device
+ */
+static void vp_modern_set_status(struct virtio_pci_modern_device *mdev,
+u8 status)
+{
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
 
-   return vp_ioread8(>device_status);
+   vp_iowrite8(status, >device_status);
 }
 
 static void vp_set_status(struct virtio_device *vdev, u8 status)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   struct virtio_pci_modern_device *mdev = _dev->mdev;
-   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
 
/* We should never be setting status to 0. */
BUG_ON(status == 0);
-   vp_iowrite8(status, >device_status);
+   vp_modern_set_status(_dev->mdev, status);
 }
 
 static void vp_reset(struct virtio_device *vdev)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
struct virtio_pci_modern_device *mdev = _dev->mdev;
-   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
 
/* 0 status means a reset. */
-   vp_iowrite8(0, >device_status);
+   vp_modern_set_status(mdev, 0);
/* After writing 0 to device_status, the driver MUST wait for a read of
 * device_status to return 0 before reinitializing the device.
 * This will flush out the status write, and flush in device writes,
 * including MSI-X interrupts, if any.
 */
-   while (vp_ioread8(>device_status))
+   while (vp_modern_get_status(mdev))
msleep(1);
/* Flush pending VQ/configuration callbacks. */
vp_synchronize_vectors(vdev);
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 05/19] virtio-pci-modern: introduce helper to set config vector

2020-12-03 Thread Jason Wang
This patch introduces vp_modern_config_vector() for setting config
vector.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 4be9afad547e..2e37bfc89655 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -315,9 +315,16 @@ static void vp_reset(struct virtio_device *vdev)
vp_synchronize_vectors(vdev);
 }
 
-static u16 vp_config_vector(struct virtio_pci_device *vp_dev, u16 vector)
+/*
+ * vp_modern_config_vector - set the vector for config interrupt
+ * @mdev: the modern virtio-pci device
+ * @vector: the config vector
+ *
+ * Returns the config vector read from the device
+ */
+static u16 vp_modern_config_vector(struct virtio_pci_modern_device *mdev,
+  u16 vector)
 {
-   struct virtio_pci_modern_device *mdev = _dev->mdev;
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
 
/* Setup the vector used for configuration events */
@@ -327,6 +334,11 @@ static u16 vp_config_vector(struct virtio_pci_device 
*vp_dev, u16 vector)
return vp_ioread16(>msix_config);
 }
 
+static u16 vp_config_vector(struct virtio_pci_device *vp_dev, u16 vector)
+{
+   return vp_modern_config_vector(_dev->mdev, vector);
+}
+
 static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
  struct virtio_pci_vq_info *info,
  unsigned index,
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 02/19] virtio-pci: split out modern device

2020-12-03 Thread Jason Wang
This patch splits out the virtio-pci modern device only attributes
into another structure. While at it, a dedicated probe method for
modern only attributes is introduced. This may help for split the
logic into a dedicated module.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_common.h |  25 +++--
 drivers/virtio/virtio_pci_modern.c | 159 -
 2 files changed, 105 insertions(+), 79 deletions(-)

diff --git a/drivers/virtio/virtio_pci_common.h 
b/drivers/virtio/virtio_pci_common.h
index b2f0eb4067cb..f35ff5b6b467 100644
--- a/drivers/virtio/virtio_pci_common.h
+++ b/drivers/virtio/virtio_pci_common.h
@@ -39,22 +39,16 @@ struct virtio_pci_vq_info {
unsigned msix_vector;
 };
 
-/* Our device structure */
-struct virtio_pci_device {
-   struct virtio_device vdev;
+struct virtio_pci_modern_device {
struct pci_dev *pci_dev;
 
-   /* In legacy mode, these two point to within ->legacy. */
-   /* Where to read and clear interrupt */
-   u8 __iomem *isr;
-
-   /* Modern only fields */
-   /* The IO mapping for the PCI config space (non-legacy mode) */
struct virtio_pci_common_cfg __iomem *common;
/* Device-specific data (non-legacy mode)  */
void __iomem *device;
/* Base of vq notifications (non-legacy mode). */
void __iomem *notify_base;
+   /* Where to read and clear interrupt */
+   u8 __iomem *isr;
 
/* So we can sanity-check accesses. */
size_t notify_len;
@@ -68,6 +62,19 @@ struct virtio_pci_device {
 
int modern_bars;
 
+   struct virtio_device_id id;
+};
+
+/* Our device structure */
+struct virtio_pci_device {
+   struct virtio_device vdev;
+   struct pci_dev *pci_dev;
+   struct virtio_pci_modern_device mdev;
+
+   /* In legacy mode, these two point to within ->legacy. */
+   /* Where to read and clear interrupt */
+   u8 __iomem *isr;
+
/* Legacy only field */
/* the IO mapping for the PCI config space */
void __iomem *ioaddr;
diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index df1481fd400c..524490a94ca4 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -141,7 +141,8 @@ static void __iomem *map_capability(struct pci_dev *dev, 
int off,
 static u64 vp_get_features(struct virtio_device *vdev)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;
+   struct virtio_pci_modern_device *mdev = _dev->mdev;
+   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
u64 features;
 
vp_iowrite32(0, >device_feature_select);
@@ -166,7 +167,8 @@ static void vp_transport_features(struct virtio_device 
*vdev, u64 features)
 static int vp_finalize_features(struct virtio_device *vdev)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;
+   struct virtio_pci_modern_device *mdev = _dev->mdev;
+   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
u64 features = vdev->features;
 
/* Give virtio_ring a chance to accept features. */
@@ -194,12 +196,13 @@ static void vp_get(struct virtio_device *vdev, unsigned 
offset,
   void *buf, unsigned len)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   void __iomem *device = vp_dev->device;
+   struct virtio_pci_modern_device *mdev = _dev->mdev;
+   void __iomem *device = mdev->device;
u8 b;
__le16 w;
__le32 l;
 
-   BUG_ON(offset + len > vp_dev->device_len);
+   BUG_ON(offset + len > mdev->device_len);
 
switch (len) {
case 1:
@@ -231,12 +234,13 @@ static void vp_set(struct virtio_device *vdev, unsigned 
offset,
   const void *buf, unsigned len)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   void __iomem *device = vp_dev->device;
+   struct virtio_pci_modern_device *mdev = _dev->mdev;
+   void __iomem *device = mdev->device;
u8 b;
__le16 w;
__le32 l;
 
-   BUG_ON(offset + len > vp_dev->device_len);
+   BUG_ON(offset + len > mdev->device_len);
 
switch (len) {
case 1:
@@ -265,7 +269,8 @@ static void vp_set(struct virtio_device *vdev, unsigned 
offset,
 static u32 vp_generation(struct virtio_device *vdev)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-   struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;
+   struct virtio_pci_modern_device *mdev = _dev->mdev;
+   struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
 
return vp_ioread8(>config_generation);
 }
@@ -274,7 +279,8 @@ static u32 vp_generation(struct virtio_device *vdev)
 static u8 vp_get_status(struct virtio_device *vdev)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
- 

[PATCH V2 04/19] virtio-pci-modern: introduce vp_modern_remove()

2020-12-03 Thread Jason Wang
This patch introduces vp_modern_remove() doing device resources
cleanup to make it can be used.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 5d2d2ae0dfdb..4be9afad547e 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -873,9 +873,12 @@ int virtio_pci_modern_probe(struct virtio_pci_device 
*vp_dev)
return 0;
 }
 
-void virtio_pci_modern_remove(struct virtio_pci_device *vp_dev)
+/*
+ * vp_modern_probe: remove and cleanup the modern virtio pci device
+ * @mdev: the modern virtio-pci device
+ */
+static void vp_modern_remove(struct virtio_pci_modern_device *mdev)
 {
-   struct virtio_pci_modern_device *mdev = _dev->mdev;
struct pci_dev *pci_dev = mdev->pci_dev;
 
if (mdev->device)
@@ -886,3 +889,10 @@ void virtio_pci_modern_remove(struct virtio_pci_device 
*vp_dev)
pci_iounmap(pci_dev, mdev->common);
pci_release_selected_regions(pci_dev, mdev->modern_bars);
 }
+
+void virtio_pci_modern_remove(struct virtio_pci_device *vp_dev)
+{
+   struct virtio_pci_modern_device *mdev = _dev->mdev;
+
+   vp_modern_remove(mdev);
+}
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 01/19] virtio-pci: do not access iomem via struct virtio_pci_device directly

2020-12-03 Thread Jason Wang
Instead of accessing iomem via struct virito_pci_device directly,
tweak to call the io accessors through the iomem structure. This will
ease the splitting of modern virtio device logic.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 76 ++
 1 file changed, 46 insertions(+), 30 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 3d6ae5a5e252..df1481fd400c 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -141,12 +141,13 @@ static void __iomem *map_capability(struct pci_dev *dev, 
int off,
 static u64 vp_get_features(struct virtio_device *vdev)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+   struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;
u64 features;
 
-   vp_iowrite32(0, _dev->common->device_feature_select);
-   features = vp_ioread32(_dev->common->device_feature);
-   vp_iowrite32(1, _dev->common->device_feature_select);
-   features |= ((u64)vp_ioread32(_dev->common->device_feature) << 32);
+   vp_iowrite32(0, >device_feature_select);
+   features = vp_ioread32(>device_feature);
+   vp_iowrite32(1, >device_feature_select);
+   features |= ((u64)vp_ioread32(>device_feature) << 32);
 
return features;
 }
@@ -165,6 +166,7 @@ static void vp_transport_features(struct virtio_device 
*vdev, u64 features)
 static int vp_finalize_features(struct virtio_device *vdev)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+   struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;
u64 features = vdev->features;
 
/* Give virtio_ring a chance to accept features. */
@@ -179,10 +181,10 @@ static int vp_finalize_features(struct virtio_device 
*vdev)
return -EINVAL;
}
 
-   vp_iowrite32(0, _dev->common->guest_feature_select);
-   vp_iowrite32((u32)vdev->features, _dev->common->guest_feature);
-   vp_iowrite32(1, _dev->common->guest_feature_select);
-   vp_iowrite32(vdev->features >> 32, _dev->common->guest_feature);
+   vp_iowrite32(0, >guest_feature_select);
+   vp_iowrite32((u32)vdev->features, >guest_feature);
+   vp_iowrite32(1, >guest_feature_select);
+   vp_iowrite32(vdev->features >> 32, >guest_feature);
 
return 0;
 }
@@ -192,6 +194,7 @@ static void vp_get(struct virtio_device *vdev, unsigned 
offset,
   void *buf, unsigned len)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+   void __iomem *device = vp_dev->device;
u8 b;
__le16 w;
__le32 l;
@@ -200,21 +203,21 @@ static void vp_get(struct virtio_device *vdev, unsigned 
offset,
 
switch (len) {
case 1:
-   b = ioread8(vp_dev->device + offset);
+   b = ioread8(device + offset);
memcpy(buf, , sizeof b);
break;
case 2:
-   w = cpu_to_le16(ioread16(vp_dev->device + offset));
+   w = cpu_to_le16(ioread16(device + offset));
memcpy(buf, , sizeof w);
break;
case 4:
-   l = cpu_to_le32(ioread32(vp_dev->device + offset));
+   l = cpu_to_le32(ioread32(device + offset));
memcpy(buf, , sizeof l);
break;
case 8:
-   l = cpu_to_le32(ioread32(vp_dev->device + offset));
+   l = cpu_to_le32(ioread32(device + offset));
memcpy(buf, , sizeof l);
-   l = cpu_to_le32(ioread32(vp_dev->device + offset + sizeof l));
+   l = cpu_to_le32(ioread32(device + offset + sizeof l));
memcpy(buf + sizeof l, , sizeof l);
break;
default:
@@ -228,6 +231,7 @@ static void vp_set(struct virtio_device *vdev, unsigned 
offset,
   const void *buf, unsigned len)
 {
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+   void __iomem *device = vp_dev->device;
u8 b;
__le16 w;
__le32 l;
@@ -237,21 +241,21 @@ static void vp_set(struct virtio_device *vdev, unsigned 
offset,
switch (len) {
case 1:
memcpy(, buf, sizeof b);
-   iowrite8(b, vp_dev->device + offset);
+   iowrite8(b, device + offset);
break;
case 2:
memcpy(, buf, sizeof w);
-   iowrite16(le16_to_cpu(w), vp_dev->device + offset);
+   iowrite16(le16_to_cpu(w), device + offset);
break;
case 4:
memcpy(, buf, sizeof l);
-   iowrite32(le32_to_cpu(l), vp_dev->device + offset);
+   iowrite32(le32_to_cpu(l), device + offset);
break;
case 8:
memcpy(, buf, sizeof l);
-   iowrite32(le32_to_cpu(l), vp_dev->device + offset);
+   iowrite32(le32_to_cpu(l), device + offset);
   

[PATCH V2 03/19] virtio-pci-modern: factor out modern device initialization logic

2020-12-03 Thread Jason Wang
This patch factors out the modern device initialization logic into a
helper. Note that it still depends on the caller to enable pci device
which allows the caller to use e.g devres.

Signed-off-by: Jason Wang 
---
 drivers/virtio/virtio_pci_modern.c | 50 +-
 1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 524490a94ca4..5d2d2ae0dfdb 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -703,11 +703,16 @@ static inline void check_offsets(void)
 offsetof(struct virtio_pci_common_cfg, queue_used_hi));
 }
 
-/* the PCI probing function */
-int virtio_pci_modern_probe(struct virtio_pci_device *vp_dev)
+/*
+ * vp_modern_probe: probe the modern virtio pci device, note that the
+ * caller is required to enable PCI device before calling this function.
+ * @mdev: the modern virtio-pci device
+ *
+ * Return 0 on succeed otherwise fail
+ */
+static int vp_modern_probe(struct virtio_pci_modern_device *mdev)
 {
-   struct virtio_pci_modern_device *mdev = _dev->mdev;
-   struct pci_dev *pci_dev = vp_dev->pci_dev;
+   struct pci_dev *pci_dev = mdev->pci_dev;
int err, common, isr, notify, device;
u32 notify_length;
u32 notify_offset;
@@ -826,18 +831,8 @@ int virtio_pci_modern_probe(struct virtio_pci_device 
*vp_dev)
  >device_len);
if (!mdev->device)
goto err_map_device;
-
-   vp_dev->vdev.config = _pci_config_ops;
-   } else {
-   vp_dev->vdev.config = _pci_config_nodev_ops;
}
 
-   vp_dev->config_vector = vp_config_vector;
-   vp_dev->setup_vq = setup_vq;
-   vp_dev->del_vq = del_vq;
-   vp_dev->isr = mdev->isr;
-   vp_dev->vdev.id = mdev->id;
-
return 0;
 
 err_map_device:
@@ -851,6 +846,33 @@ int virtio_pci_modern_probe(struct virtio_pci_device 
*vp_dev)
return err;
 }
 
+/* the PCI probing function */
+int virtio_pci_modern_probe(struct virtio_pci_device *vp_dev)
+{
+   struct virtio_pci_modern_device *mdev = _dev->mdev;
+   struct pci_dev *pci_dev = vp_dev->pci_dev;
+   int err;
+
+   mdev->pci_dev = pci_dev;
+
+   err = vp_modern_probe(mdev);
+   if (err)
+   return err;
+
+   if (mdev->device)
+   vp_dev->vdev.config = _pci_config_ops;
+   else
+   vp_dev->vdev.config = _pci_config_nodev_ops;
+
+   vp_dev->config_vector = vp_config_vector;
+   vp_dev->setup_vq = setup_vq;
+   vp_dev->del_vq = del_vq;
+   vp_dev->isr = mdev->isr;
+   vp_dev->vdev.id = mdev->id;
+
+   return 0;
+}
+
 void virtio_pci_modern_remove(struct virtio_pci_device *vp_dev)
 {
struct virtio_pci_modern_device *mdev = _dev->mdev;
-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH V2 00/19] vDPA driver for virtio-pci device

2020-12-03 Thread Jason Wang
Hi all:

This series tries to implement a vDPA driver for virtio-pci device
which will bridge between vDPA bus and virtio-pci device.

This could be used for future feature prototyping and testing.

Please review

Changes from V2:

- don't try to use devres for virtio-pci core
- tweak the commit log
- split the patches furtherly to ease the reviewing

Changes from V1:

- Split common codes from virito-pci and share it with vDPA driver
- Use dynamic id in order to be less confusing with virtio-pci driver
- No feature whitelist, supporting any features (mq, config etc)

Thanks

Jason Wang (19):
  virtio-pci: do not access iomem via struct virtio_pci_device directly
  virtio-pci: split out modern device
  virtio-pci-modern: factor out modern device initialization logic
  virtio-pci-modern: introduce vp_modern_remove()
  virtio-pci-modern: introduce helper to set config vector
  virtio-pci-modern: introduce helpers for setting and getting status
  virtio-pci-modern: introduce helpers for setting and getting features
  virtio-pci-modern: introduce vp_modern_generation()
  virtio-pci-modern: introduce vp_modern_set_queue_vector()
  virtio-pci-modern: introduce vp_modern_queue_address()
  virtio-pci-modern: introduce helper to set/get queue_enable
  virtio-pci-modern: introduce helper for setting/geting queue size
  virtio-pci-modern: introduce helper for getting queue nums
  virtio-pci-modern: introduce helper to get notification offset
  virito-pci-modern: rename map_capability() to
vp_modern_map_capability()
  virtio-pci: introduce modern device module
  vdpa: set the virtqueue num during register
  virtio_vdpa: don't warn when fail to disable vq
  vdpa: introduce virtio pci driver

 drivers/vdpa/Kconfig   |   6 +
 drivers/vdpa/Makefile  |   1 +
 drivers/vdpa/ifcvf/ifcvf_main.c|   5 +-
 drivers/vdpa/mlx5/net/mlx5_vnet.c  |   5 +-
 drivers/vdpa/vdpa.c|   8 +-
 drivers/vdpa/vdpa_sim/vdpa_sim.c   |   4 +-
 drivers/vdpa/virtio_pci/Makefile   |   2 +
 drivers/vdpa/virtio_pci/vp_vdpa.c  | 455 +++
 drivers/virtio/Kconfig |  10 +-
 drivers/virtio/Makefile|   1 +
 drivers/virtio/virtio_pci_common.h |  22 +-
 drivers/virtio/virtio_pci_modern.c | 506 +++--
 drivers/virtio/virtio_pci_modern_dev.c | 599 +
 drivers/virtio/virtio_vdpa.c   |   3 +-
 include/linux/vdpa.h   |   7 +-
 include/linux/virtio_pci_modern.h  | 111 +
 16 files changed, 1273 insertions(+), 472 deletions(-)
 create mode 100644 drivers/vdpa/virtio_pci/Makefile
 create mode 100644 drivers/vdpa/virtio_pci/vp_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_modern_dev.c
 create mode 100644 include/linux/virtio_pci_modern.h

-- 
2.25.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v2 2/2] drivers: gpio: add virtio-gpio guest driver

2020-12-03 Thread Jason Wang


On 2020/12/4 上午3:11, Enrico Weigelt, metux IT consult wrote:

Introducing new gpio driver for virtual GPIO devices via virtio.

The driver allows routing gpio control into VM guests, eg. brigding
virtual gpios to specific host gpios, or attaching simulators for
automatic application testing.

Changes v2:
 * fixed uapi header license
 * sorted include's
 * fixed formatting
 * fixed unneeded devm allocation - plain kzalloc/kfree is enough
 * fixed missing devm_kzalloc fail check
 * use devm_kcalloc() for array allocation
 * added virtio-gpio protocol specification

Signed-off-by: Enrico Weigelt, metux IT consult 
---
  Documentation/gpio/virtio-gpio.rst | 176 
  MAINTAINERS|   6 +
  drivers/gpio/Kconfig   |   9 +
  drivers/gpio/Makefile  |   1 +
  drivers/gpio/gpio-virtio.c | 332 +
  include/uapi/linux/virtio_gpio.h   |  39 +
  include/uapi/linux/virtio_ids.h|   1 +
  7 files changed, 564 insertions(+)
  create mode 100644 Documentation/gpio/virtio-gpio.rst
  create mode 100644 drivers/gpio/gpio-virtio.c
  create mode 100644 include/uapi/linux/virtio_gpio.h

diff --git a/Documentation/gpio/virtio-gpio.rst 
b/Documentation/gpio/virtio-gpio.rst
new file mode 100644
index ..04642be07b96
--- /dev/null
+++ b/Documentation/gpio/virtio-gpio.rst
@@ -0,0 +1,176 @@
+"
+Virtio-GPIO protocol specification
+"
+...
+Specification for virtio-based virtiual GPIO devices
+...
+



Is the plan to keep this doc synced with the one in the virtio 
specification?




++
++Version_ 1.0
++
+
+===
+General
+===
+
+The virtio-gpio protocol provides access to general purpose IO devices
+to virtual machine guests. These virtualized GPIOs could be either provided
+by some simulator (eg. virtual HIL), routed to some external device or
+routed to real GPIOs on the host (eg. virtualized embedded applications).
+
+Instead of simulating some existing real GPIO chip within an VMM, this
+protocol provides an hardware independent interface between host and guest
+that solely relies on an active virtio connection (no matter which transport
+actually used), no other buses or additional platform driver logic required.
+
+===
+Protocol layout
+===
+
+--
+Configuration space
+--
+
+++--+---+
+| Offset | Type | Description   |
+++==+===+
+| 0x00   | uint8| version   |
+++--+---+
+| 0x02   | uint16   | number of GPIO lines  |
+++--+---+
+| 0x04   | uint32   | size of gpio name block   |
+++--+---+
+| 0x20   | char[32] | device name (0-terminated)|
+++--+---+
+| 0x40   | char[]   | line names block  |
+++--+---+
+



I think it's better to use u8 ot uint8_t here.Git grep told me the 
former is more popular under Documentation/.




+- for version field currently only value 1 supported.
+- the line names block holds a stream of zero-terminated strings,
+  holding the individual line names.



I'm not sure but does this mean we don't have a fixed length of config 
space? Need to check whether it can bring any trouble to 
migration(compatibility).




+- unspecified fields are reserved for future use and should be zero.
+
+
+Virtqueues and messages:
+
+
+- Queue #0: transmission from host to guest
+- Queue #1: transmission from guest to host



Virtio became more a popular in the area without virtualization. So I 
think it's better to use "device/driver" instead of "host/guest" here.




+
+The queues transport messages of the struct virtio_gpio_event:
+
+Message format:
+---
+
+++--+---+
+| Offset | Type | Description   |
+++==+===+
+| 0x00   | uint16   | event type|
+++--+---+
+| 0x02   | uint16   | line id   |
+++--+---+
+| 0x04   | uint32   | value |
+++--+---+



Not a native speaker but event sounds like something driver read from 
device. Looking at the below lists, most of them except for 
VIRTIO_GPIO_EV_HOST_LEVEL looks more like a command.


Another question is, what's the benefit of unifying the message format 
of the two queues. E.g VIRTIO_GPIO_EV_HOST_LEVEL can only works fro rxq.




+
+Message types:
+--
+
++---+---+-+
+| Code  | Symbol  

Re: [PATCH] vdpa/mlx5: Use random MAC for the vdpa net instance

2020-12-03 Thread Jason Wang


On 2020/12/3 下午8:24, Eli Cohen wrote:

It is mentioned in Parav's patchset that this will be coming in a
subsequent patch to his vdpa tool.

So I think kernel has two options:
- require a mac when device is created, we supply it to guest

Yes, the driver should always set VIRTIO_NET_F_MAC and provide a MAC -
either random or whatever configured using the vdpa too.



A questions here, I think current mlx5 vdpa works for VF only. So I 
think the VF should have a given MAC? If yes, can we use that MAC?


Thanks






___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH v3 02/19] vdpa_sim: remove unnecessary headers inclusion

2020-12-03 Thread Randy Dunlap
On 12/3/20 9:04 AM, Stefano Garzarella wrote:
> Some headers are not necessary, so let's remove them to do
> some cleaning.
> 
> Signed-off-by: Stefano Garzarella 

Hi,
What makes you say that some of these are unnecessary?

Please use Rule #1 from Documentation/process/submit-checklist.rst:

1) If you use a facility then #include the file that defines/declares
   that facility.  Don't depend on other header files pulling in ones
   that you use.


so just because it will compile without these headers being explictly
#included does not mean that you should remove them.


> ---
> v3:
> - avoided to remove some headers with structures and functions directly
>   used (device.h, slab.h, virtio_byteorder.h)[Jason]
> ---
>  drivers/vdpa/vdpa_sim/vdpa_sim.c | 10 --
>  1 file changed, 10 deletions(-)
> 
> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c 
> b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> index 6a90fdb9cbfc..b08f28d20d8d 100644
> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> @@ -7,20 +7,10 @@
>   *
>   */
>  
> -#include 

above is used by __init and __exit.

>  #include 
>  #include 
> -#include 
> -#include 
> -#include 

Looks OK to remove poll.h.

>  #include 
> -#include 

Might be OK for sched.h.

> -#include 

Might be OK for wait.h.

> -#include 
> -#include 
>  #include 
> -#include 
> -#include 
>  #include 
>  #include 
>  #include 
> 

I didn't check the others.


-- 
~Randy

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v3 19/19] vdpa: split vdpasim to core and net modules

2020-12-03 Thread Randy Dunlap
Hi,

On 12/3/20 9:05 AM, Stefano Garzarella wrote:
> diff --git a/drivers/vdpa/Kconfig b/drivers/vdpa/Kconfig
> index 2c892e890b9e..b0f91ad8eb47 100644
> --- a/drivers/vdpa/Kconfig
> +++ b/drivers/vdpa/Kconfig
> @@ -9,15 +9,20 @@ menuconfig VDPA
>  if VDPA
>  
>  config VDPA_SIM
> - tristate "vDPA device simulator"
> + tristate "vDPA device simulator core"
>   depends on RUNTIME_TESTING_MENU && HAS_DMA
>   select DMA_OPS
>   select VHOST_RING
> + help
> +   Enable this module to support vDPA device simulators. These devices
> +   are used for testing, prototyping and development of vDPA.
> +
> +config VDPA_SIM_NET
> + tristate "vDPA simulator for networking device"
> + depends on VDPA_SIM
>   select GENERIC_NET_UTILS
>   help
> -   vDPA networking device simulator which loop TX traffic back
> -   to RX. This device is used for testing, prototyping and
> -   development of vDPA.
> +   vDPA networking device simulator which loop TX traffic back to RX.

 loops


thanks.
-- 
~Randy

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 19/19] vdpa: split vdpasim to core and net modules

2020-12-03 Thread Stefano Garzarella
From: Max Gurtovoy 

Introduce new vdpa_sim_net and vdpa_sim (core) drivers. This is a
preparation for adding a vdpa simulator module for block devices.

Signed-off-by: Max Gurtovoy 
[sgarzare: various cleanups/fixes]
Signed-off-by: Stefano Garzarella 
---
v2:
- Fixed "warning: variable 'dev' is used uninitialized" reported by
  'kernel test robot' and Dan Carpenter
- rebased on top of other changes (dev_attr, get_config(), notify(), etc.)
- left batch_mapping module parameter in the core [Jason]

v1:
- Removed unused headers
- Removed empty module_init() module_exit()
- Moved vdpasim_is_little_endian() in vdpa_sim.h
- Moved vdpasim16_to_cpu/cpu_to_vdpasim16() in vdpa_sim.h
- Added vdpasim*_to_cpu/cpu_to_vdpasim*() also for 32 and 64
- Replaced 'select VDPA_SIM' with 'depends on VDPA_SIM' since selected
  option can not depend on other [Jason]
---
 drivers/vdpa/vdpa_sim/vdpa_sim.h | 105 +
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 224 +--
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 171 
 drivers/vdpa/Kconfig |  13 +-
 drivers/vdpa/vdpa_sim/Makefile   |   1 +
 5 files changed, 292 insertions(+), 222 deletions(-)
 create mode 100644 drivers/vdpa/vdpa_sim/vdpa_sim.h
 create mode 100644 drivers/vdpa/vdpa_sim/vdpa_sim_net.c

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h
new file mode 100644
index ..b02142293d5b
--- /dev/null
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h
@@ -0,0 +1,105 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2020, Red Hat Inc. All rights reserved.
+ */
+
+#ifndef _VDPA_SIM_H
+#define _VDPA_SIM_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define VDPASIM_FEATURES   ((1ULL << VIRTIO_F_ANY_LAYOUT) | \
+(1ULL << VIRTIO_F_VERSION_1)  | \
+(1ULL << VIRTIO_F_ACCESS_PLATFORM))
+
+struct vdpasim;
+
+struct vdpasim_virtqueue {
+   struct vringh vring;
+   struct vringh_kiov in_iov;
+   struct vringh_kiov out_iov;
+   unsigned short head;
+   bool ready;
+   u64 desc_addr;
+   u64 device_addr;
+   u64 driver_addr;
+   u32 num;
+   void *private;
+   irqreturn_t (*cb)(void *data);
+};
+
+struct vdpasim_dev_attr {
+   u64 supported_features;
+   size_t config_size;
+   size_t buffer_size;
+   int nvqs;
+   u32 id;
+
+   work_func_t work_fn;
+   void (*get_config)(struct vdpasim *vdpasim, void *config);
+   void (*set_config)(struct vdpasim *vdpasim, const void *config);
+};
+
+/* State of each vdpasim device */
+struct vdpasim {
+   struct vdpa_device vdpa;
+   struct vdpasim_virtqueue *vqs;
+   struct work_struct work;
+   struct vdpasim_dev_attr dev_attr;
+   /* spinlock to synchronize virtqueue state */
+   spinlock_t lock;
+   /* virtio config according to device type */
+   void *config;
+   struct vhost_iotlb *iommu;
+   void *buffer;
+   u32 status;
+   u32 generation;
+   u64 features;
+   /* spinlock to synchronize iommu table */
+   spinlock_t iommu_lock;
+};
+
+struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr);
+
+/* TODO: cross-endian support */
+static inline bool vdpasim_is_little_endian(struct vdpasim *vdpasim)
+{
+   return virtio_legacy_is_little_endian() ||
+   (vdpasim->features & (1ULL << VIRTIO_F_VERSION_1));
+}
+
+static inline u16 vdpasim16_to_cpu(struct vdpasim *vdpasim, __virtio16 val)
+{
+   return __virtio16_to_cpu(vdpasim_is_little_endian(vdpasim), val);
+}
+
+static inline __virtio16 cpu_to_vdpasim16(struct vdpasim *vdpasim, u16 val)
+{
+   return __cpu_to_virtio16(vdpasim_is_little_endian(vdpasim), val);
+}
+
+static inline u32 vdpasim32_to_cpu(struct vdpasim *vdpasim, __virtio32 val)
+{
+   return __virtio32_to_cpu(vdpasim_is_little_endian(vdpasim), val);
+}
+
+static inline __virtio32 cpu_to_vdpasim32(struct vdpasim *vdpasim, u32 val)
+{
+   return __cpu_to_virtio32(vdpasim_is_little_endian(vdpasim), val);
+}
+
+static inline u64 vdpasim64_to_cpu(struct vdpasim *vdpasim, __virtio64 val)
+{
+   return __virtio64_to_cpu(vdpasim_is_little_endian(vdpasim), val);
+}
+
+static inline __virtio64 cpu_to_vdpasim64(struct vdpasim *vdpasim, u64 val)
+{
+   return __cpu_to_virtio64(vdpasim_is_little_endian(vdpasim), val);
+}
+
+#endif
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 557b2129b41b..7ff074ea04ea 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * VDPA networking device simulator.
+ * VDPA device simulator core.
  *
  * Copyright (c) 2020, Red Hat Inc. All rights reserved.
  * Author: Jason Wang 
@@ -11,107 +11,21 @@
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+

[PATCH v3 18/19] vdpa_sim: split vdpasim_virtqueue's iov field in out_iov and in_iov

2020-12-03 Thread Stefano Garzarella
vringh_getdesc_iotlb() manages 2 iovs for writable and readable
descriptors. This is very useful for the block device, where for
each request we have both types of descriptor.

Let's split the vdpasim_virtqueue's iov field in out_iov and
in_iov to use them with vringh_getdesc_iotlb().

We are using VIRTIO terminology for "out" (readable by the device)
and "in" (writable by the device) descriptors.

Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
v2:
- used VIRTIO terminology [Stefan]
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 38b6b5e7348c..557b2129b41b 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -36,7 +36,8 @@ u8 macaddr_buf[ETH_ALEN];
 
 struct vdpasim_virtqueue {
struct vringh vring;
-   struct vringh_kiov iov;
+   struct vringh_kiov in_iov;
+   struct vringh_kiov out_iov;
unsigned short head;
bool ready;
u64 desc_addr;
@@ -202,12 +203,12 @@ static void vdpasim_net_work(struct work_struct *work)
 
while (true) {
total_write = 0;
-   err = vringh_getdesc_iotlb(>vring, >iov, NULL,
+   err = vringh_getdesc_iotlb(>vring, >out_iov, NULL,
   >head, GFP_ATOMIC);
if (err <= 0)
break;
 
-   err = vringh_getdesc_iotlb(>vring, NULL, >iov,
+   err = vringh_getdesc_iotlb(>vring, NULL, >in_iov,
   >head, GFP_ATOMIC);
if (err <= 0) {
vringh_complete_iotlb(>vring, txq->head, 0);
@@ -215,13 +216,13 @@ static void vdpasim_net_work(struct work_struct *work)
}
 
while (true) {
-   read = vringh_iov_pull_iotlb(>vring, >iov,
+   read = vringh_iov_pull_iotlb(>vring, >out_iov,
 vdpasim->buffer,
 PAGE_SIZE);
if (read <= 0)
break;
 
-   write = vringh_iov_push_iotlb(>vring, >iov,
+   write = vringh_iov_push_iotlb(>vring, >in_iov,
  vdpasim->buffer, read);
if (write <= 0)
break;
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 17/19] vdpa_sim: make vdpasim->buffer size configurable

2020-12-03 Thread Stefano Garzarella
Allow each device to specify the size of the buffer allocated
in vdpa_sim.

Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index fb714d88e77f..38b6b5e7348c 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -65,6 +65,7 @@ struct vdpasim;
 struct vdpasim_dev_attr {
u64 supported_features;
size_t config_size;
+   size_t buffer_size;
int nvqs;
u32 id;
 
@@ -410,7 +411,7 @@ static struct vdpasim *vdpasim_create(struct 
vdpasim_dev_attr *dev_attr)
if (!vdpasim->iommu)
goto err_iommu;
 
-   vdpasim->buffer = kvmalloc(PAGE_SIZE, GFP_KERNEL);
+   vdpasim->buffer = kvmalloc(dev_attr->buffer_size, GFP_KERNEL);
if (!vdpasim->buffer)
goto err_iommu;
 
@@ -779,6 +780,7 @@ static int __init vdpasim_dev_init(void)
dev_attr.config_size = sizeof(struct virtio_net_config);
dev_attr.get_config = vdpasim_net_get_config;
dev_attr.work_fn = vdpasim_net_work;
+   dev_attr.buffer_size = PAGE_SIZE;
 
vdpasim_dev = vdpasim_create(_attr);
 
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 16/19] vdpa_sim: use kvmalloc to allocate vdpasim->buffer

2020-12-03 Thread Stefano Garzarella
The next patch will make the buffer size configurable from each
device.
Since the buffer could be larger than a page, we use kvmalloc()
instead of kmalloc().

Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 1243b02488f7..fb714d88e77f 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -410,7 +410,7 @@ static struct vdpasim *vdpasim_create(struct 
vdpasim_dev_attr *dev_attr)
if (!vdpasim->iommu)
goto err_iommu;
 
-   vdpasim->buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
+   vdpasim->buffer = kvmalloc(PAGE_SIZE, GFP_KERNEL);
if (!vdpasim->buffer)
goto err_iommu;
 
@@ -699,7 +699,7 @@ static void vdpasim_free(struct vdpa_device *vdpa)
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
 
cancel_work_sync(>work);
-   kfree(vdpasim->buffer);
+   kvfree(vdpasim->buffer);
if (vdpasim->iommu)
vhost_iotlb_free(vdpasim->iommu);
kfree(vdpasim->vqs);
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 15/19] vdpa_sim: set vringh notify callback

2020-12-03 Thread Stefano Garzarella
Instead of calling the vq callback directly, we can leverage the
vringh_notify() function, adding vdpasim_vq_notify() and setting it
in the vringh notify callback.

Suggested-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
v3:
- cleared notify during reset [Jason]
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 23 +++
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 03a8717f80ea..1243b02488f7 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -123,6 +123,17 @@ static struct vdpasim *dev_to_sim(struct device *dev)
return vdpa_to_sim(vdpa);
 }
 
+static void vdpasim_vq_notify(struct vringh *vring)
+{
+   struct vdpasim_virtqueue *vq =
+   container_of(vring, struct vdpasim_virtqueue, vring);
+
+   if (!vq->cb)
+   return;
+
+   vq->cb(vq->private);
+}
+
 static void vdpasim_queue_ready(struct vdpasim *vdpasim, unsigned int idx)
 {
struct vdpasim_virtqueue *vq = >vqs[idx];
@@ -134,6 +145,8 @@ static void vdpasim_queue_ready(struct vdpasim *vdpasim, 
unsigned int idx)
  (uintptr_t)vq->driver_addr,
  (struct vring_used *)
  (uintptr_t)vq->device_addr);
+
+   vq->vring.notify = vdpasim_vq_notify;
 }
 
 static void vdpasim_vq_reset(struct vdpasim *vdpasim,
@@ -147,6 +160,8 @@ static void vdpasim_vq_reset(struct vdpasim *vdpasim,
vq->private = NULL;
vringh_init_iotlb(>vring, vdpasim->dev_attr.supported_features,
  VDPASIM_QUEUE_MAX, false, NULL, NULL, NULL);
+
+   vq->vring.notify = NULL;
 }
 
 static void vdpasim_reset(struct vdpasim *vdpasim)
@@ -223,10 +238,10 @@ static void vdpasim_net_work(struct work_struct *work)
smp_wmb();
 
local_bh_disable();
-   if (txq->cb)
-   txq->cb(txq->private);
-   if (rxq->cb)
-   rxq->cb(rxq->private);
+   if (vringh_need_notify_iotlb(>vring) > 0)
+   vringh_notify(>vring);
+   if (vringh_need_notify_iotlb(>vring) > 0)
+   vringh_notify(>vring);
local_bh_enable();
 
if (++pkts > 4) {
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 14/19] vdpa_sim: add set_config callback in vdpasim_dev_attr

2020-12-03 Thread Stefano Garzarella
The set_config callback can be used by the device to parse the
config structure modified by the driver.

The callback will be invoked, if set, in vdpasim_set_config() after
copying bytes from caller buffer into vdpasim->config buffer.

Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index f935ade0806b..03a8717f80ea 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -70,6 +70,7 @@ struct vdpasim_dev_attr {
 
work_func_t work_fn;
void (*get_config)(struct vdpasim *vdpasim, void *config);
+   void (*set_config)(struct vdpasim *vdpasim, const void *config);
 };
 
 /* State of each vdpasim device */
@@ -598,7 +599,15 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, 
unsigned int offset,
 static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset,
 const void *buf, unsigned int len)
 {
-   /* No writable config supportted by vdpasim */
+   struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
+
+   if (offset + len > vdpasim->dev_attr.config_size)
+   return;
+
+   memcpy(vdpasim->config + offset, buf, len);
+
+   if (vdpasim->dev_attr.set_config)
+   vdpasim->dev_attr.set_config(vdpasim, vdpasim->config);
 }
 
 static u32 vdpasim_get_generation(struct vdpa_device *vdpa)
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 13/19] vdpa_sim: add get_config callback in vdpasim_dev_attr

2020-12-03 Thread Stefano Garzarella
The get_config callback can be used by the device to fill the
config structure.
The callback will be invoked in vdpasim_get_config() before copying
bytes into caller buffer.

Move vDPA-net config updates from vdpasim_set_features() in the
new vdpasim_net_get_config() callback.

Signed-off-by: Stefano Garzarella 
---
v3:
- checked if get_config callback is set before call it
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 35 +++-
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index fe71ed7890e1..f935ade0806b 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -60,6 +60,8 @@ struct vdpasim_virtqueue {
 #define VDPASIM_NET_FEATURES   (VDPASIM_FEATURES | \
 (1ULL << VIRTIO_NET_F_MAC))
 
+struct vdpasim;
+
 struct vdpasim_dev_attr {
u64 supported_features;
size_t config_size;
@@ -67,6 +69,7 @@ struct vdpasim_dev_attr {
u32 id;
 
work_func_t work_fn;
+   void (*get_config)(struct vdpasim *vdpasim, void *config);
 };
 
 /* State of each vdpasim device */
@@ -522,8 +525,6 @@ static u64 vdpasim_get_features(struct vdpa_device *vdpa)
 static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features)
 {
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
-   struct virtio_net_config *config =
-   (struct virtio_net_config *)vdpasim->config;
 
/* DMA mapping must be done by driver */
if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)))
@@ -531,16 +532,6 @@ static int vdpasim_set_features(struct vdpa_device *vdpa, 
u64 features)
 
vdpasim->features = features & vdpasim->dev_attr.supported_features;
 
-   /* We generally only know whether guest is using the legacy interface
-* here, so generally that's the earliest we can set config fields.
-* Note: We actually require VIRTIO_F_ACCESS_PLATFORM above which
-* implies VIRTIO_F_VERSION_1, but let's not try to be clever here.
-*/
-
-   config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
-   config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
-   memcpy(config->mac, macaddr_buf, ETH_ALEN);
-
return 0;
 }
 
@@ -595,8 +586,13 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, 
unsigned int offset,
 {
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
 
-   if (offset + len < vdpasim->dev_attr.config_size)
-   memcpy(buf, vdpasim->config + offset, len);
+   if (offset + len > vdpasim->dev_attr.config_size)
+   return;
+
+   if (vdpasim->dev_attr.get_config)
+   vdpasim->dev_attr.get_config(vdpasim, vdpasim->config);
+
+   memcpy(buf, vdpasim->config + offset, len);
 }
 
 static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset,
@@ -739,6 +735,16 @@ static const struct vdpa_config_ops 
vdpasim_batch_config_ops = {
.free   = vdpasim_free,
 };
 
+static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
+{
+   struct virtio_net_config *net_config =
+   (struct virtio_net_config *)config;
+
+   net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
+   net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
+   memcpy(net_config->mac, macaddr_buf, ETH_ALEN);
+}
+
 static int __init vdpasim_dev_init(void)
 {
struct vdpasim_dev_attr dev_attr = {};
@@ -747,6 +753,7 @@ static int __init vdpasim_dev_init(void)
dev_attr.supported_features = VDPASIM_NET_FEATURES;
dev_attr.nvqs = VDPASIM_VQ_NUM;
dev_attr.config_size = sizeof(struct virtio_net_config);
+   dev_attr.get_config = vdpasim_net_get_config;
dev_attr.work_fn = vdpasim_net_work;
 
vdpasim_dev = vdpasim_create(_attr);
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 12/19] vdpa_sim: make 'config' generic and usable for any device type

2020-12-03 Thread Stefano Garzarella
Add new 'config_size' attribute in 'vdpasim_dev_attr' and allocates
'config' dynamically to support any device types.

Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 949f4231d08a..fe71ed7890e1 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -62,6 +62,7 @@ struct vdpasim_virtqueue {
 
 struct vdpasim_dev_attr {
u64 supported_features;
+   size_t config_size;
int nvqs;
u32 id;
 
@@ -76,7 +77,8 @@ struct vdpasim {
struct vdpasim_dev_attr dev_attr;
/* spinlock to synchronize virtqueue state */
spinlock_t lock;
-   struct virtio_net_config config;
+   /* virtio config according to device type */
+   void *config;
struct vhost_iotlb *iommu;
void *buffer;
u32 status;
@@ -376,6 +378,10 @@ static struct vdpasim *vdpasim_create(struct 
vdpasim_dev_attr *dev_attr)
goto err_iommu;
set_dma_ops(dev, _dma_ops);
 
+   vdpasim->config = kzalloc(dev_attr->config_size, GFP_KERNEL);
+   if (!vdpasim->config)
+   goto err_iommu;
+
vdpasim->vqs = kcalloc(dev_attr->nvqs, sizeof(struct vdpasim_virtqueue),
   GFP_KERNEL);
if (!vdpasim->vqs)
@@ -516,7 +522,8 @@ static u64 vdpasim_get_features(struct vdpa_device *vdpa)
 static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features)
 {
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
-   struct virtio_net_config *config = >config;
+   struct virtio_net_config *config =
+   (struct virtio_net_config *)vdpasim->config;
 
/* DMA mapping must be done by driver */
if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)))
@@ -588,8 +595,8 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, 
unsigned int offset,
 {
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
 
-   if (offset + len < sizeof(struct virtio_net_config))
-   memcpy(buf, (u8 *)>config + offset, len);
+   if (offset + len < vdpasim->dev_attr.config_size)
+   memcpy(buf, vdpasim->config + offset, len);
 }
 
 static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset,
@@ -676,6 +683,7 @@ static void vdpasim_free(struct vdpa_device *vdpa)
if (vdpasim->iommu)
vhost_iotlb_free(vdpasim->iommu);
kfree(vdpasim->vqs);
+   kfree(vdpasim->config);
 }
 
 static const struct vdpa_config_ops vdpasim_config_ops = {
@@ -738,6 +746,7 @@ static int __init vdpasim_dev_init(void)
dev_attr.id = VIRTIO_ID_NET;
dev_attr.supported_features = VDPASIM_NET_FEATURES;
dev_attr.nvqs = VDPASIM_VQ_NUM;
+   dev_attr.config_size = sizeof(struct virtio_net_config);
dev_attr.work_fn = vdpasim_net_work;
 
vdpasim_dev = vdpasim_create(_attr);
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 11/19] vdpa_sim: store parsed MAC address in a buffer

2020-12-03 Thread Stefano Garzarella
As preparation for the next patches, we store the MAC address,
parsed during the vdpasim_create(), in a buffer that will be used
to fill 'config' together with other configurations.

Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index e7d366f63090..949f4231d08a 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -32,6 +32,8 @@ static char *macaddr;
 module_param(macaddr, charp, 0);
 MODULE_PARM_DESC(macaddr, "Ethernet MAC address");
 
+u8 macaddr_buf[ETH_ALEN];
+
 struct vdpasim_virtqueue {
struct vringh vring;
struct vringh_kiov iov;
@@ -388,13 +390,13 @@ static struct vdpasim *vdpasim_create(struct 
vdpasim_dev_attr *dev_attr)
goto err_iommu;
 
if (macaddr) {
-   mac_pton(macaddr, vdpasim->config.mac);
-   if (!is_valid_ether_addr(vdpasim->config.mac)) {
+   mac_pton(macaddr, macaddr_buf);
+   if (!is_valid_ether_addr(macaddr_buf)) {
ret = -EADDRNOTAVAIL;
goto err_iommu;
}
} else {
-   eth_random_addr(vdpasim->config.mac);
+   eth_random_addr(macaddr_buf);
}
 
for (i = 0; i < dev_attr->nvqs; i++)
@@ -530,6 +532,8 @@ static int vdpasim_set_features(struct vdpa_device *vdpa, 
u64 features)
 
config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
+   memcpy(config->mac, macaddr_buf, ETH_ALEN);
+
return 0;
 }
 
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 08/19] vdpa_sim: add device id field in vdpasim_dev_attr

2020-12-03 Thread Stefano Garzarella
Remove VDPASIM_DEVICE_ID macro and add 'id' field in vdpasim_dev_attr,
that will be returned by vdpasim_get_device_id().

Use VIRTIO_ID_NET for vDPA-net simulator device id.

Co-developed-by: Max Gurtovoy 
Signed-off-by: Max Gurtovoy 
Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index e132b886cb84..3d97bc709fb9 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -47,7 +47,6 @@ struct vdpasim_virtqueue {
 
 #define VDPASIM_QUEUE_ALIGN PAGE_SIZE
 #define VDPASIM_QUEUE_MAX 256
-#define VDPASIM_DEVICE_ID 0x1
 #define VDPASIM_VENDOR_ID 0
 #define VDPASIM_VQ_NUM 0x2
 #define VDPASIM_NAME "vdpasim-netdev"
@@ -59,6 +58,7 @@ static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) |
 
 struct vdpasim_dev_attr {
int nvqs;
+   u32 id;
 };
 
 /* State of each vdpasim device */
@@ -538,7 +538,9 @@ static u16 vdpasim_get_vq_num_max(struct vdpa_device *vdpa)
 
 static u32 vdpasim_get_device_id(struct vdpa_device *vdpa)
 {
-   return VDPASIM_DEVICE_ID;
+   struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
+
+   return vdpasim->dev_attr.id;
 }
 
 static u32 vdpasim_get_vendor_id(struct vdpa_device *vdpa)
@@ -721,6 +723,7 @@ static int __init vdpasim_dev_init(void)
 {
struct vdpasim_dev_attr dev_attr = {};
 
+   dev_attr.id = VIRTIO_ID_NET;
dev_attr.nvqs = VDPASIM_VQ_NUM;
 
vdpasim_dev = vdpasim_create(_attr);
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 10/19] vdpa_sim: add work_fn in vdpasim_dev_attr

2020-12-03 Thread Stefano Garzarella
Rename vdpasim_work() in vdpasim_net_work() and add it to
the vdpasim_dev_attr structure.

Co-developed-by: Max Gurtovoy 
Signed-off-by: Max Gurtovoy 
Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 569c5213ee01..e7d366f63090 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -62,6 +62,8 @@ struct vdpasim_dev_attr {
u64 supported_features;
int nvqs;
u32 id;
+
+   work_func_t work_fn;
 };
 
 /* State of each vdpasim device */
@@ -155,7 +157,7 @@ static void vdpasim_reset(struct vdpasim *vdpasim)
++vdpasim->generation;
 }
 
-static void vdpasim_work(struct work_struct *work)
+static void vdpasim_net_work(struct work_struct *work)
 {
struct vdpasim *vdpasim = container_of(work, struct
 vdpasim, work);
@@ -362,7 +364,7 @@ static struct vdpasim *vdpasim_create(struct 
vdpasim_dev_attr *dev_attr)
goto err_alloc;
 
vdpasim->dev_attr = *dev_attr;
-   INIT_WORK(>work, vdpasim_work);
+   INIT_WORK(>work, dev_attr->work_fn);
spin_lock_init(>lock);
spin_lock_init(>iommu_lock);
 
@@ -732,6 +734,7 @@ static int __init vdpasim_dev_init(void)
dev_attr.id = VIRTIO_ID_NET;
dev_attr.supported_features = VDPASIM_NET_FEATURES;
dev_attr.nvqs = VDPASIM_VQ_NUM;
+   dev_attr.work_fn = vdpasim_net_work;
 
vdpasim_dev = vdpasim_create(_attr);
 
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 09/19] vdpa_sim: add supported_features field in vdpasim_dev_attr

2020-12-03 Thread Stefano Garzarella
Introduce a new VDPASIM_FEATURES macro with the generic features
supported by the vDPA simulator, and VDPASIM_NET_FEATURES macro with
vDPA-net features.

Add 'supported_features' field in vdpasim_dev_attr, to allow devices
to specify their features.

Co-developed-by: Max Gurtovoy 
Signed-off-by: Max Gurtovoy 
Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 29 ++---
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 3d97bc709fb9..569c5213ee01 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -51,12 +51,15 @@ struct vdpasim_virtqueue {
 #define VDPASIM_VQ_NUM 0x2
 #define VDPASIM_NAME "vdpasim-netdev"
 
-static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) |
- (1ULL << VIRTIO_F_VERSION_1)  |
- (1ULL << VIRTIO_F_ACCESS_PLATFORM) |
- (1ULL << VIRTIO_NET_F_MAC);
+#define VDPASIM_FEATURES   ((1ULL << VIRTIO_F_ANY_LAYOUT) | \
+(1ULL << VIRTIO_F_VERSION_1)  | \
+(1ULL << VIRTIO_F_ACCESS_PLATFORM))
+
+#define VDPASIM_NET_FEATURES   (VDPASIM_FEATURES | \
+(1ULL << VIRTIO_NET_F_MAC))
 
 struct vdpasim_dev_attr {
+   u64 supported_features;
int nvqs;
u32 id;
 };
@@ -114,7 +117,7 @@ static void vdpasim_queue_ready(struct vdpasim *vdpasim, 
unsigned int idx)
 {
struct vdpasim_virtqueue *vq = >vqs[idx];
 
-   vringh_init_iotlb(>vring, vdpasim_features,
+   vringh_init_iotlb(>vring, vdpasim->dev_attr.supported_features,
  VDPASIM_QUEUE_MAX, false,
  (struct vring_desc *)(uintptr_t)vq->desc_addr,
  (struct vring_avail *)
@@ -123,7 +126,8 @@ static void vdpasim_queue_ready(struct vdpasim *vdpasim, 
unsigned int idx)
  (uintptr_t)vq->device_addr);
 }
 
-static void vdpasim_vq_reset(struct vdpasim_virtqueue *vq)
+static void vdpasim_vq_reset(struct vdpasim *vdpasim,
+struct vdpasim_virtqueue *vq)
 {
vq->ready = false;
vq->desc_addr = 0;
@@ -131,8 +135,8 @@ static void vdpasim_vq_reset(struct vdpasim_virtqueue *vq)
vq->device_addr = 0;
vq->cb = NULL;
vq->private = NULL;
-   vringh_init_iotlb(>vring, vdpasim_features, VDPASIM_QUEUE_MAX,
- false, NULL, NULL, NULL);
+   vringh_init_iotlb(>vring, vdpasim->dev_attr.supported_features,
+ VDPASIM_QUEUE_MAX, false, NULL, NULL, NULL);
 }
 
 static void vdpasim_reset(struct vdpasim *vdpasim)
@@ -140,7 +144,7 @@ static void vdpasim_reset(struct vdpasim *vdpasim)
int i;
 
for (i = 0; i < vdpasim->dev_attr.nvqs; i++)
-   vdpasim_vq_reset(>vqs[i]);
+   vdpasim_vq_reset(vdpasim, >vqs[i]);
 
spin_lock(>iommu_lock);
vhost_iotlb_reset(vdpasim->iommu);
@@ -500,7 +504,9 @@ static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa)
 
 static u64 vdpasim_get_features(struct vdpa_device *vdpa)
 {
-   return vdpasim_features;
+   struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
+
+   return vdpasim->dev_attr.supported_features;
 }
 
 static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features)
@@ -512,7 +518,7 @@ static int vdpasim_set_features(struct vdpa_device *vdpa, 
u64 features)
if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)))
return -EINVAL;
 
-   vdpasim->features = features & vdpasim_features;
+   vdpasim->features = features & vdpasim->dev_attr.supported_features;
 
/* We generally only know whether guest is using the legacy interface
 * here, so generally that's the earliest we can set config fields.
@@ -724,6 +730,7 @@ static int __init vdpasim_dev_init(void)
struct vdpasim_dev_attr dev_attr = {};
 
dev_attr.id = VIRTIO_ID_NET;
+   dev_attr.supported_features = VDPASIM_NET_FEATURES;
dev_attr.nvqs = VDPASIM_VQ_NUM;
 
vdpasim_dev = vdpasim_create(_attr);
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 07/19] vdpa_sim: add struct vdpasim_dev_attr for device attributes

2020-12-03 Thread Stefano Garzarella
vdpasim_dev_attr will contain device specific attributes. We starting
moving the number of virtqueues (i.e. nvqs) to vdpasim_dev_attr.

vdpasim_create() creates a new vDPA simulator following the device
attributes defined in the vdpasim_dev_attr parameter.

Co-developed-by: Max Gurtovoy 
Signed-off-by: Max Gurtovoy 
Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 625e0f46b672..e132b886cb84 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -57,11 +57,16 @@ static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) 
|
  (1ULL << VIRTIO_F_ACCESS_PLATFORM) |
  (1ULL << VIRTIO_NET_F_MAC);
 
+struct vdpasim_dev_attr {
+   int nvqs;
+};
+
 /* State of each vdpasim device */
 struct vdpasim {
struct vdpa_device vdpa;
struct vdpasim_virtqueue *vqs;
struct work_struct work;
+   struct vdpasim_dev_attr dev_attr;
/* spinlock to synchronize virtqueue state */
spinlock_t lock;
struct virtio_net_config config;
@@ -70,7 +75,6 @@ struct vdpasim {
u32 status;
u32 generation;
u64 features;
-   int nvqs;
/* spinlock to synchronize iommu table */
spinlock_t iommu_lock;
 };
@@ -135,7 +139,7 @@ static void vdpasim_reset(struct vdpasim *vdpasim)
 {
int i;
 
-   for (i = 0; i < vdpasim->nvqs; i++)
+   for (i = 0; i < vdpasim->dev_attr.nvqs; i++)
vdpasim_vq_reset(>vqs[i]);
 
spin_lock(>iommu_lock);
@@ -336,7 +340,7 @@ static const struct dma_map_ops vdpasim_dma_ops = {
 static const struct vdpa_config_ops vdpasim_config_ops;
 static const struct vdpa_config_ops vdpasim_batch_config_ops;
 
-static struct vdpasim *vdpasim_create(void)
+static struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr)
 {
const struct vdpa_config_ops *ops;
struct vdpasim *vdpasim;
@@ -348,11 +352,12 @@ static struct vdpasim *vdpasim_create(void)
else
ops = _config_ops;
 
-   vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, 
VDPASIM_VQ_NUM);
+   vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops,
+   dev_attr->nvqs);
if (!vdpasim)
goto err_alloc;
 
-   vdpasim->nvqs = VDPASIM_VQ_NUM;
+   vdpasim->dev_attr = *dev_attr;
INIT_WORK(>work, vdpasim_work);
spin_lock_init(>lock);
spin_lock_init(>iommu_lock);
@@ -363,7 +368,7 @@ static struct vdpasim *vdpasim_create(void)
goto err_iommu;
set_dma_ops(dev, _dma_ops);
 
-   vdpasim->vqs = kcalloc(vdpasim->nvqs, sizeof(struct vdpasim_virtqueue),
+   vdpasim->vqs = kcalloc(dev_attr->nvqs, sizeof(struct vdpasim_virtqueue),
   GFP_KERNEL);
if (!vdpasim->vqs)
goto err_iommu;
@@ -386,7 +391,7 @@ static struct vdpasim *vdpasim_create(void)
eth_random_addr(vdpasim->config.mac);
}
 
-   for (i = 0; i < vdpasim->nvqs; i++)
+   for (i = 0; i < dev_attr->nvqs; i++)
vringh_set_iotlb(>vqs[i].vring, vdpasim->iommu);
 
vdpasim->vdpa.dma_dev = dev;
@@ -714,7 +719,11 @@ static const struct vdpa_config_ops 
vdpasim_batch_config_ops = {
 
 static int __init vdpasim_dev_init(void)
 {
-   vdpasim_dev = vdpasim_create();
+   struct vdpasim_dev_attr dev_attr = {};
+
+   dev_attr.nvqs = VDPASIM_VQ_NUM;
+
+   vdpasim_dev = vdpasim_create(_attr);
 
if (!IS_ERR(vdpasim_dev))
return 0;
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 06/19] vdpa_sim: rename vdpasim_config_ops variables

2020-12-03 Thread Stefano Garzarella
These variables store generic callbacks used by the vDPA simulator
core, so we can remove the 'net' word in their names.

Co-developed-by: Max Gurtovoy 
Signed-off-by: Max Gurtovoy 
Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 688aceaa6543..625e0f46b672 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -333,8 +333,8 @@ static const struct dma_map_ops vdpasim_dma_ops = {
.free = vdpasim_free_coherent,
 };
 
-static const struct vdpa_config_ops vdpasim_net_config_ops;
-static const struct vdpa_config_ops vdpasim_net_batch_config_ops;
+static const struct vdpa_config_ops vdpasim_config_ops;
+static const struct vdpa_config_ops vdpasim_batch_config_ops;
 
 static struct vdpasim *vdpasim_create(void)
 {
@@ -344,9 +344,9 @@ static struct vdpasim *vdpasim_create(void)
int i, ret = -ENOMEM;
 
if (batch_mapping)
-   ops = _net_batch_config_ops;
+   ops = _batch_config_ops;
else
-   ops = _net_config_ops;
+   ops = _config_ops;
 
vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, 
VDPASIM_VQ_NUM);
if (!vdpasim)
@@ -659,7 +659,7 @@ static void vdpasim_free(struct vdpa_device *vdpa)
kfree(vdpasim->vqs);
 }
 
-static const struct vdpa_config_ops vdpasim_net_config_ops = {
+static const struct vdpa_config_ops vdpasim_config_ops = {
.set_vq_address = vdpasim_set_vq_address,
.set_vq_num = vdpasim_set_vq_num,
.kick_vq= vdpasim_kick_vq,
@@ -686,7 +686,7 @@ static const struct vdpa_config_ops vdpasim_net_config_ops 
= {
.free   = vdpasim_free,
 };
 
-static const struct vdpa_config_ops vdpasim_net_batch_config_ops = {
+static const struct vdpa_config_ops vdpasim_batch_config_ops = {
.set_vq_address = vdpasim_set_vq_address,
.set_vq_num = vdpasim_set_vq_num,
.kick_vq= vdpasim_kick_vq,
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 05/19] vdpa_sim: remove the limit of IOTLB entries

2020-12-03 Thread Stefano Garzarella
The simulated devices can support multiple queues, so this limit
should be defined according to the number of queues supported by
the device.

Since we are in a simulator, let's simply remove that limit.

Suggested-by: Jason Wang 
Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
v3:
- used VHOST_IOTLB_UNLIMITED macro [Jason]
v2:
- added VDPASIM_IOTLB_LIMIT macro [Jason]
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 295a770caac0..688aceaa6543 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -368,7 +368,7 @@ static struct vdpasim *vdpasim_create(void)
if (!vdpasim->vqs)
goto err_iommu;
 
-   vdpasim->iommu = vhost_iotlb_alloc(2048, 0);
+   vdpasim->iommu = vhost_iotlb_alloc(VHOST_IOTLB_UNLIMITED, 0);
if (!vdpasim->iommu)
goto err_iommu;
 
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 04/19] vhost/iotlb: add VHOST_IOTLB_UNLIMITED macro

2020-12-03 Thread Stefano Garzarella
It's possible to allocate an unlimited IOTLB calling
vhost_iotlb_alloc() with 'limit' = 0.

Add a new macro (VHOST_IOTLB_UNLIMITED) for this case and document
it in the vhost_iotlb_alloc() documentation block.

Suggested-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 include/linux/vhost_iotlb.h | 2 ++
 drivers/vhost/iotlb.c   | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/linux/vhost_iotlb.h b/include/linux/vhost_iotlb.h
index 6b09b786a762..47019f97f795 100644
--- a/include/linux/vhost_iotlb.h
+++ b/include/linux/vhost_iotlb.h
@@ -4,6 +4,8 @@
 
 #include 
 
+#define VHOST_IOTLB_UNLIMITED 0
+
 struct vhost_iotlb_map {
struct rb_node rb;
struct list_head link;
diff --git a/drivers/vhost/iotlb.c b/drivers/vhost/iotlb.c
index 0fd3f87e913c..80fdde78ee5a 100644
--- a/drivers/vhost/iotlb.c
+++ b/drivers/vhost/iotlb.c
@@ -100,7 +100,8 @@ EXPORT_SYMBOL_GPL(vhost_iotlb_del_range);
 
 /**
  * vhost_iotlb_alloc - add a new vhost IOTLB
- * @limit: maximum number of IOTLB entries
+ * @limit: maximum number of IOTLB entries (use VHOST_IOTLB_UNLIMITED for an
+ * unlimited IOTLB)
  * @flags: VHOST_IOTLB_FLAG_XXX
  *
  * Returns an error is memory allocation fails
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 03/19] vdpa_sim: remove hard-coded virtq count

2020-12-03 Thread Stefano Garzarella
From: Max Gurtovoy 

Add a new attribute that will define the number of virt queues to be
created for the vdpasim device.

Signed-off-by: Max Gurtovoy 
[sgarzare: replace kmalloc_array() with kcalloc()]
Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
v1:
- use kcalloc() instead of kmalloc_array() since some function expects
  variables initialized to zero
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index b08f28d20d8d..295a770caac0 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -60,7 +60,7 @@ static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) |
 /* State of each vdpasim device */
 struct vdpasim {
struct vdpa_device vdpa;
-   struct vdpasim_virtqueue vqs[VDPASIM_VQ_NUM];
+   struct vdpasim_virtqueue *vqs;
struct work_struct work;
/* spinlock to synchronize virtqueue state */
spinlock_t lock;
@@ -70,6 +70,7 @@ struct vdpasim {
u32 status;
u32 generation;
u64 features;
+   int nvqs;
/* spinlock to synchronize iommu table */
spinlock_t iommu_lock;
 };
@@ -134,7 +135,7 @@ static void vdpasim_reset(struct vdpasim *vdpasim)
 {
int i;
 
-   for (i = 0; i < VDPASIM_VQ_NUM; i++)
+   for (i = 0; i < vdpasim->nvqs; i++)
vdpasim_vq_reset(>vqs[i]);
 
spin_lock(>iommu_lock);
@@ -340,7 +341,7 @@ static struct vdpasim *vdpasim_create(void)
const struct vdpa_config_ops *ops;
struct vdpasim *vdpasim;
struct device *dev;
-   int ret = -ENOMEM;
+   int i, ret = -ENOMEM;
 
if (batch_mapping)
ops = _net_batch_config_ops;
@@ -351,6 +352,7 @@ static struct vdpasim *vdpasim_create(void)
if (!vdpasim)
goto err_alloc;
 
+   vdpasim->nvqs = VDPASIM_VQ_NUM;
INIT_WORK(>work, vdpasim_work);
spin_lock_init(>lock);
spin_lock_init(>iommu_lock);
@@ -361,6 +363,11 @@ static struct vdpasim *vdpasim_create(void)
goto err_iommu;
set_dma_ops(dev, _dma_ops);
 
+   vdpasim->vqs = kcalloc(vdpasim->nvqs, sizeof(struct vdpasim_virtqueue),
+  GFP_KERNEL);
+   if (!vdpasim->vqs)
+   goto err_iommu;
+
vdpasim->iommu = vhost_iotlb_alloc(2048, 0);
if (!vdpasim->iommu)
goto err_iommu;
@@ -379,8 +386,8 @@ static struct vdpasim *vdpasim_create(void)
eth_random_addr(vdpasim->config.mac);
}
 
-   vringh_set_iotlb(>vqs[0].vring, vdpasim->iommu);
-   vringh_set_iotlb(>vqs[1].vring, vdpasim->iommu);
+   for (i = 0; i < vdpasim->nvqs; i++)
+   vringh_set_iotlb(>vqs[i].vring, vdpasim->iommu);
 
vdpasim->vdpa.dma_dev = dev;
ret = vdpa_register_device(>vdpa);
@@ -649,6 +656,7 @@ static void vdpasim_free(struct vdpa_device *vdpa)
kfree(vdpasim->buffer);
if (vdpasim->iommu)
vhost_iotlb_free(vdpasim->iommu);
+   kfree(vdpasim->vqs);
 }
 
 static const struct vdpa_config_ops vdpasim_net_config_ops = {
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 01/19] vdpa: remove unnecessary 'default n' in Kconfig entries

2020-12-03 Thread Stefano Garzarella
'default n' is not necessary since it is already the default when
nothing is specified.

Suggested-by: Jason Wang 
Acked-by: Jason Wang 
Signed-off-by: Stefano Garzarella 
---
 drivers/vdpa/Kconfig | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/vdpa/Kconfig b/drivers/vdpa/Kconfig
index 6caf539091e5..2c892e890b9e 100644
--- a/drivers/vdpa/Kconfig
+++ b/drivers/vdpa/Kconfig
@@ -14,7 +14,6 @@ config VDPA_SIM
select DMA_OPS
select VHOST_RING
select GENERIC_NET_UTILS
-   default n
help
  vDPA networking device simulator which loop TX traffic back
  to RX. This device is used for testing, prototyping and
@@ -23,7 +22,6 @@ config VDPA_SIM
 config IFCVF
tristate "Intel IFC VF vDPA driver"
depends on PCI_MSI
-   default n
help
  This kernel module can drive Intel IFC VF NIC to offload
  virtio dataplane traffic to hardware.
@@ -42,7 +40,6 @@ config MLX5_VDPA_NET
tristate "vDPA driver for ConnectX devices"
select MLX5_VDPA
depends on MLX5_CORE
-   default n
help
  VDPA network driver for ConnectX6 and newer. Provides offloading
  of virtio net datapath such that descriptors put on the ring will
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 02/19] vdpa_sim: remove unnecessary headers inclusion

2020-12-03 Thread Stefano Garzarella
Some headers are not necessary, so let's remove them to do
some cleaning.

Signed-off-by: Stefano Garzarella 
---
v3:
- avoided to remove some headers with structures and functions directly
  used (device.h, slab.h, virtio_byteorder.h)[Jason]
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 6a90fdb9cbfc..b08f28d20d8d 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -7,20 +7,10 @@
  *
  */
 
-#include 
 #include 
 #include 
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v3 00/19] vdpa: generalize vdpa simulator

2020-12-03 Thread Stefano Garzarella
This series moves the network device simulator in a new module
(vdpa_sim_net) and leaves the generic functions in the vdpa_sim core
module, allowing the possibility to add new vDPA device simulators.

For now I removed the vdpa-blk simulator patches, since I'm still working
on them and debugging the iotlb issues.

Thanks to Max that started this work! I took his patches and extended a bit.

v1: 
https://lists.linuxfoundation.org/pipermail/virtualization/2020-November/050677.html
v2: 
https://lists.linuxfoundation.org/pipermail/virtualization/2020-November/051036.html

v3:
 - avoided to remove some headers with structures and functions directly
   used [Jason]
 - defined VHOST_IOTLB_UNLIMITED macro in vhost_iotlb.h [Jason]
 - added set_config callback in vdpasim_dev_attr [Jason]
 - cleared notify during reset [Jason]

Max Gurtovoy (2):
  vdpa_sim: remove hard-coded virtq count
  vdpa: split vdpasim to core and net modules

Stefano Garzarella (17):
  vdpa: remove unnecessary 'default n' in Kconfig entries
  vdpa_sim: remove unnecessary headers inclusion
  vhost/iotlb: add VHOST_IOTLB_UNLIMITED macro
  vdpa_sim: remove the limit of IOTLB entries
  vdpa_sim: rename vdpasim_config_ops variables
  vdpa_sim: add struct vdpasim_dev_attr for device attributes
  vdpa_sim: add device id field in vdpasim_dev_attr
  vdpa_sim: add supported_features field in vdpasim_dev_attr
  vdpa_sim: add work_fn in vdpasim_dev_attr
  vdpa_sim: store parsed MAC address in a buffer
  vdpa_sim: make 'config' generic and usable for any device type
  vdpa_sim: add get_config callback in vdpasim_dev_attr
  vdpa_sim: add set_config callback in vdpasim_dev_attr
  vdpa_sim: set vringh notify callback
  vdpa_sim: use kvmalloc to allocate vdpasim->buffer
  vdpa_sim: make vdpasim->buffer size configurable
  vdpa_sim: split vdpasim_virtqueue's iov field in out_iov and in_iov

 drivers/vdpa/vdpa_sim/vdpa_sim.h | 105 ++
 include/linux/vhost_iotlb.h  |   2 +
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 301 +++
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 171 +++
 drivers/vhost/iotlb.c|   3 +-
 drivers/vdpa/Kconfig |  16 +-
 drivers/vdpa/vdpa_sim/Makefile   |   1 +
 7 files changed, 368 insertions(+), 231 deletions(-)
 create mode 100644 drivers/vdpa/vdpa_sim/vdpa_sim.h
 create mode 100644 drivers/vdpa/vdpa_sim/vdpa_sim_net.c

-- 
2.26.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH 14/15] drm/vmwgfx: Remove references to struct drm_device.pdev

2020-12-03 Thread Daniel Vetter
On Thu, Dec 03, 2020 at 03:06:20AM +, Zack Rusin wrote:
> 
> 
> > On Dec 2, 2020, at 11:03, Daniel Vetter  wrote:
> > 
> > On Wed, Dec 2, 2020 at 4:37 PM Zack Rusin  wrote:
> >> 
> >> 
> >> 
> >>> On Dec 2, 2020, at 09:27, Thomas Zimmermann  wrote:
> >>> 
> >>> Hi
> >>> 
> >>> Am 02.12.20 um 09:01 schrieb Thomas Zimmermann:
>  Hi
>  Am 30.11.20 um 21:59 schrieb Zack Rusin:
> > 
> > 
> >> On Nov 24, 2020, at 06:38, Thomas Zimmermann  
> >> wrote:
> >> 
> >> Using struct drm_device.pdev is deprecated. Convert vmwgfx to struct
> >> drm_device.dev. No functional changes.
> >> 
> >> Signed-off-by: Thomas Zimmermann 
> >> Cc: Roland Scheidegger 
> >> ---
> >> drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c |  8 
> >> drivers/gpu/drm/vmwgfx/vmwgfx_drv.c| 27 +-
> >> drivers/gpu/drm/vmwgfx/vmwgfx_fb.c |  2 +-
> > 
> > Reviewed-by: Zack Rusin 
>  Could you add this patch to the vmwgfx tree?
> >>> 
> >>> AMD devs indicated that they'd prefer to merge the patchset trough 
> >>> drm-misc-next. If you're OK with that, I'd merge the vmwgfx patch through 
> >>> drm-misc-next as well.
> >> 
> >> Sounds good. I’ll make sure to rebase our latest patch set on top of it 
> >> when it’s in. Thanks!
> > 
> > btw if you want to avoid multi-tree coordination headaches, we can
> > also manage vmwgfx in drm-misc and give you & Roland commit rights
> > there. Up to you. There is some scripting involved for now (but I hope
> > whenever we move to gitlab we could do the checks server-side):
> 
> I’d be happy to take you up on that. I would like to move a lot more of
> our development into public repos and reducing the burden of maintaining
> multiple trees would help. Is there a lot of changes to drm core that
> doesn’t go through drm-misc? Or alternatively is drm-misc often pulling
> from Linus’ master? I’m trying to figure out how much would our need to
> rebase/merge be reduced if we just used drm-misc-next/drm-misc-fixes
> because that would also allow me to point some internal testing
> infrastructure at it as well.

I think nowadays pretty much all the cross-driver work lands through
drm-misc. Exception is just new stuff that's only used by a single driver.

For testing there's also drm-tip, which tries to pull it all together (but
you might still want to point your CI at branches).

Also note that drm-misc-next doesn't have a merge window freeze period
(with have the drm-misc-next-fixes branch during that time for merge
window fixes), so you can treat it like a main development branch like
e.g. in mesa, with the -fixes branches as the release branches. Only
difference is that we don't cherry pick patches from the main branch to
the release branches (at least not as the normal flow).

If you do need a backmerge for patches from Linus to drm-misc-next because
of some feature work (or conflicts with other stuff in general) drm-misc
maintainers do that. Usually happens every few weeks.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH] vdpa/mlx5: Use random MAC for the vdpa net instance

2020-12-03 Thread Michael S. Tsirkin
On Thu, Dec 03, 2020 at 02:09:29PM +0200, Eli Cohen wrote:
> On Thu, Dec 03, 2020 at 05:44:17AM -0500, Michael S. Tsirkin wrote:
> > On Thu, Dec 03, 2020 at 08:49:28AM +0200, Eli Cohen wrote:
> > > On Wed, Dec 02, 2020 at 05:00:22PM -0500, Michael S. Tsirkin wrote:
> > > > On Wed, Dec 02, 2020 at 09:48:25PM +0800, Jason Wang wrote:
> > > > > 
> > > > > On 2020/12/2 下午5:23, Michael S. Tsirkin wrote:
> > > > > > On Wed, Dec 02, 2020 at 07:57:14AM +0200, Eli Cohen wrote:
> > > > > > > On Wed, Dec 02, 2020 at 12:18:36PM +0800, Jason Wang wrote:
> > > > > > > > On 2020/12/1 下午5:23, Cindy Lu wrote:
> > > > > > > > > On Mon, Nov 30, 2020 at 11:33 PM Michael S. 
> > > > > > > > > Tsirkin  wrote:
> > > > > > > > > > On Mon, Nov 30, 2020 at 06:41:45PM +0800, Cindy Lu wrote:
> > > > > > > > > > > On Mon, Nov 30, 2020 at 5:33 PM Michael S. 
> > > > > > > > > > > Tsirkin  wrote:
> > > > > > > > > > > > On Mon, Nov 30, 2020 at 11:27:59AM +0200, Eli Cohen 
> > > > > > > > > > > > wrote:
> > > > > > > > > > > > > On Mon, Nov 30, 2020 at 04:00:51AM -0500, Michael S. 
> > > > > > > > > > > > > Tsirkin wrote:
> > > > > > > > > > > > > > On Mon, Nov 30, 2020 at 08:27:46AM +0200, Eli Cohen 
> > > > > > > > > > > > > > wrote:
> > > > > > > > > > > > > > > On Sun, Nov 29, 2020 at 03:08:22PM -0500, Michael 
> > > > > > > > > > > > > > > S. Tsirkin wrote:
> > > > > > > > > > > > > > > > On Sun, Nov 29, 2020 at 08:43:51AM +0200, Eli 
> > > > > > > > > > > > > > > > Cohen wrote:
> > > > > > > > > > > > > > > > > We should not try to use the VF MAC address 
> > > > > > > > > > > > > > > > > as that is used by the
> > > > > > > > > > > > > > > > > regular (e.g. mlx5_core) NIC implementation. 
> > > > > > > > > > > > > > > > > Instead, use a random
> > > > > > > > > > > > > > > > > generated MAC address.
> > > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > > Suggested by: Cindy Lu
> > > > > > > > > > > > > > > > > Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA 
> > > > > > > > > > > > > > > > > driver for supported mlx5 devices")
> > > > > > > > > > > > > > > > > Signed-off-by: Eli Cohen
> > > > > > > > > > > > > > > > I didn't realise it's possible to use VF in two 
> > > > > > > > > > > > > > > > ways
> > > > > > > > > > > > > > > > with and without vdpa.
> > > > > > > > > > > > > > > Using a VF you can create quite a few resources, 
> > > > > > > > > > > > > > > e.g. send queues
> > > > > > > > > > > > > > > recieve queues, virtio_net queues etc. So you can 
> > > > > > > > > > > > > > > possibly create
> > > > > > > > > > > > > > > several instances of vdpa net devices and nic net 
> > > > > > > > > > > > > > > devices.
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > Could you include a bit more description on the 
> > > > > > > > > > > > > > > > failure
> > > > > > > > > > > > > > > > mode?
> > > > > > > > > > > > > > > Well, using the MAC address of the nic vport is 
> > > > > > > > > > > > > > > wrong since that is the
> > > > > > > > > > > > > > > MAC of the regular NIC implementation of 
> > > > > > > > > > > > > > > mlx5_core.
> > > > > > > > > > > > > > Right but ATM it doesn't coexist with vdpa so 
> > > > > > > > > > > > > > what's the problem?
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > This call is wrong:  
> > > > > > > > > > > > > mlx5_query_nic_vport_mac_address()
> > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > Is switching to a random mac for such an unusual
> > > > > > > > > > > > > > > > configuration really justified?
> > > > > > > > > > > > > > > Since I can't use the NIC's MAC address, I have 
> > > > > > > > > > > > > > > two options:
> > > > > > > > > > > > > > > 1. To get the MAC address as was chosen by the 
> > > > > > > > > > > > > > > user administering the
> > > > > > > > > > > > > > >  NIC. This should invoke the set_config 
> > > > > > > > > > > > > > > callback. Unfortunately this
> > > > > > > > > > > > > > >  is not implemented yet.
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > 2. Use a random MAC address. This is OK since if 
> > > > > > > > > > > > > > > (1) is implemented it
> > > > > > > > > > > > > > >  can always override this random 
> > > > > > > > > > > > > > > configuration.
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > It looks like changing a MAC could break some 
> > > > > > > > > > > > > > > > guests,
> > > > > > > > > > > > > > > > can it not?
> > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > No, it will not. The current version of mlx5 VDPA 
> > > > > > > > > > > > > > > does not allow regular
> > > > > > > > > > > > > > > NIC driver and VDPA to co-exist. I have patches 
> > > > > > > > > > > > > > > ready that enable that
> > > > > > > > > > > > > > > from steering point of view. I will post them 
> > > > > > > > > > > > > > > here once other patches on
> > > > > > > > > > > > > > > which they depend will be merged.
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > 

Re: [PATCH] vdpa/mlx5: Use random MAC for the vdpa net instance

2020-12-03 Thread Michael S. Tsirkin
On Thu, Dec 03, 2020 at 08:49:28AM +0200, Eli Cohen wrote:
> On Wed, Dec 02, 2020 at 05:00:22PM -0500, Michael S. Tsirkin wrote:
> > On Wed, Dec 02, 2020 at 09:48:25PM +0800, Jason Wang wrote:
> > > 
> > > On 2020/12/2 下午5:23, Michael S. Tsirkin wrote:
> > > > On Wed, Dec 02, 2020 at 07:57:14AM +0200, Eli Cohen wrote:
> > > > > On Wed, Dec 02, 2020 at 12:18:36PM +0800, Jason Wang wrote:
> > > > > > On 2020/12/1 下午5:23, Cindy Lu wrote:
> > > > > > > On Mon, Nov 30, 2020 at 11:33 PM Michael S. 
> > > > > > > Tsirkin  wrote:
> > > > > > > > On Mon, Nov 30, 2020 at 06:41:45PM +0800, Cindy Lu wrote:
> > > > > > > > > On Mon, Nov 30, 2020 at 5:33 PM Michael S. 
> > > > > > > > > Tsirkin  wrote:
> > > > > > > > > > On Mon, Nov 30, 2020 at 11:27:59AM +0200, Eli Cohen wrote:
> > > > > > > > > > > On Mon, Nov 30, 2020 at 04:00:51AM -0500, Michael S. 
> > > > > > > > > > > Tsirkin wrote:
> > > > > > > > > > > > On Mon, Nov 30, 2020 at 08:27:46AM +0200, Eli Cohen 
> > > > > > > > > > > > wrote:
> > > > > > > > > > > > > On Sun, Nov 29, 2020 at 03:08:22PM -0500, Michael S. 
> > > > > > > > > > > > > Tsirkin wrote:
> > > > > > > > > > > > > > On Sun, Nov 29, 2020 at 08:43:51AM +0200, Eli Cohen 
> > > > > > > > > > > > > > wrote:
> > > > > > > > > > > > > > > We should not try to use the VF MAC address as 
> > > > > > > > > > > > > > > that is used by the
> > > > > > > > > > > > > > > regular (e.g. mlx5_core) NIC implementation. 
> > > > > > > > > > > > > > > Instead, use a random
> > > > > > > > > > > > > > > generated MAC address.
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > Suggested by: Cindy Lu
> > > > > > > > > > > > > > > Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver 
> > > > > > > > > > > > > > > for supported mlx5 devices")
> > > > > > > > > > > > > > > Signed-off-by: Eli Cohen
> > > > > > > > > > > > > > I didn't realise it's possible to use VF in two ways
> > > > > > > > > > > > > > with and without vdpa.
> > > > > > > > > > > > > Using a VF you can create quite a few resources, e.g. 
> > > > > > > > > > > > > send queues
> > > > > > > > > > > > > recieve queues, virtio_net queues etc. So you can 
> > > > > > > > > > > > > possibly create
> > > > > > > > > > > > > several instances of vdpa net devices and nic net 
> > > > > > > > > > > > > devices.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > > Could you include a bit more description on the 
> > > > > > > > > > > > > > failure
> > > > > > > > > > > > > > mode?
> > > > > > > > > > > > > Well, using the MAC address of the nic vport is wrong 
> > > > > > > > > > > > > since that is the
> > > > > > > > > > > > > MAC of the regular NIC implementation of mlx5_core.
> > > > > > > > > > > > Right but ATM it doesn't coexist with vdpa so what's 
> > > > > > > > > > > > the problem?
> > > > > > > > > > > > 
> > > > > > > > > > > This call is wrong:  mlx5_query_nic_vport_mac_address()
> > > > > > > > > > > 
> > > > > > > > > > > > > > Is switching to a random mac for such an unusual
> > > > > > > > > > > > > > configuration really justified?
> > > > > > > > > > > > > Since I can't use the NIC's MAC address, I have two 
> > > > > > > > > > > > > options:
> > > > > > > > > > > > > 1. To get the MAC address as was chosen by the user 
> > > > > > > > > > > > > administering the
> > > > > > > > > > > > >  NIC. This should invoke the set_config callback. 
> > > > > > > > > > > > > Unfortunately this
> > > > > > > > > > > > >  is not implemented yet.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > 2. Use a random MAC address. This is OK since if (1) 
> > > > > > > > > > > > > is implemented it
> > > > > > > > > > > > >  can always override this random configuration.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > > It looks like changing a MAC could break some 
> > > > > > > > > > > > > > guests,
> > > > > > > > > > > > > > can it not?
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > No, it will not. The current version of mlx5 VDPA 
> > > > > > > > > > > > > does not allow regular
> > > > > > > > > > > > > NIC driver and VDPA to co-exist. I have patches ready 
> > > > > > > > > > > > > that enable that
> > > > > > > > > > > > > from steering point of view. I will post them here 
> > > > > > > > > > > > > once other patches on
> > > > > > > > > > > > > which they depend will be merged.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > https://patchwork.ozlabs.org/project/netdev/patch/20201120230339.651609-12-sae...@nvidia.com/
> > > > > > > > > > > > Could you be more explicit on the following points:
> > > > > > > > > > > > - which configuration is broken ATM (as in, two device 
> > > > > > > > > > > > have identical
> > > > > > > > > > > > macs? any other issues)?
> > > > > > > > > > > The only wrong thing is the call to  
> > > > > > > > > > > mlx5_query_nic_vport_mac_address().
> > > > > > > > > > > It's not breaking anything yet is wrong. The random MAC 
> > > > > > > > > > > address setting
> > > > > > > > > >