Re: [PATCH v2 17/17] vdpa: split vdpasim to core and net modules

2020-11-30 Thread Stefano Garzarella

On Mon, Nov 30, 2020 at 11:31:43AM +0800, Jason Wang wrote:


On 2020/11/26 下午10:49, Stefano Garzarella wrote:

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 | 103 +
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 222 +--
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 171 +
 drivers/vdpa/Kconfig |  13 +-
 drivers/vdpa/vdpa_sim/Makefile   |   1 +
 5 files changed, 290 insertions(+), 220 deletions(-)
 create mode 100644 drivers/vdpa/vdpa_sim/vdpa_sim.h
 create mode 100644 drivers/vdpa/vdpa_sim/vdpa_sim_net.c



Looks good, consider there are some still some questions left. I will 
probably ack for the next version.




Sure, thanks for your feedback!

Stefano

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

Re: [PATCH v2 17/17] vdpa: split vdpasim to core and net modules

2020-11-29 Thread Jason Wang


On 2020/11/26 下午10:49, Stefano Garzarella wrote:

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 | 103 +
  drivers/vdpa/vdpa_sim/vdpa_sim.c | 222 +--
  drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 171 +
  drivers/vdpa/Kconfig |  13 +-
  drivers/vdpa/vdpa_sim/Makefile   |   1 +
  5 files changed, 290 insertions(+), 220 deletions(-)
  create mode 100644 drivers/vdpa/vdpa_sim/vdpa_sim.h
  create mode 100644 drivers/vdpa/vdpa_sim/vdpa_sim_net.c



Looks good, consider there are some still some questions left. I will 
probably ack for the next version.


Thanks

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

[PATCH v2 17/17] vdpa: split vdpasim to core and net modules

2020-11-26 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 | 103 +
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 222 +--
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 171 +
 drivers/vdpa/Kconfig |  13 +-
 drivers/vdpa/vdpa_sim/Makefile   |   1 +
 5 files changed, 290 insertions(+), 220 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 ..1662f3bf3eac
--- /dev/null
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h
@@ -0,0 +1,103 @@
+/* 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 
+
+#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);
+};
+
+/* 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 f8ee261ef4ae..cbdd419de1ef 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 
@@ -9,106 +9,22 @@
 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+
+#include "vdpa_sim.h"
 
 #define DRV_VERSION  "0.1"
 #define DRV_AUTHOR   "Jason Wang "
-#define DRV_DESC