Re: [RFC PATCH v5 23/26] util: Add iova_tree_alloc

2021-11-01 Thread Jason Wang


在 2021/10/30 上午2:35, Eugenio Pérez 写道:

This iova tree function allows it to look for a hole in allocated
regions and return a totally new translation for a given translated
address.

It's usage is mainly to allow devices to access qemu address space,
remapping guest's one into a new iova space where qemu can add chunks of
addresses.

Signed-off-by: Eugenio Pérez 
---
  include/qemu/iova-tree.h |  17 +
  util/iova-tree.c | 139 +++
  2 files changed, 156 insertions(+)

diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h
index 8249edd764..33f9b2e13f 100644
--- a/include/qemu/iova-tree.h
+++ b/include/qemu/iova-tree.h
@@ -29,6 +29,7 @@
  #define  IOVA_OK   (0)
  #define  IOVA_ERR_INVALID  (-1) /* Invalid parameters */
  #define  IOVA_ERR_OVERLAP  (-2) /* IOVA range overlapped */
+#define  IOVA_ERR_NOMEM(-3) /* Cannot allocate */



I think we need a better name other than "NOMEM", since it's actually 
means there's no sufficient hole for the range?



  
  typedef struct IOVATree IOVATree;

  typedef struct DMAMap {
@@ -119,6 +120,22 @@ const DMAMap *iova_tree_find_address(const IOVATree *tree, 
hwaddr iova);
   */
  void iova_tree_foreach(IOVATree *tree, iova_tree_iterator iterator);
  
+/**

+ * iova_tree_alloc:
+ *
+ * @tree: the iova tree to allocate from
+ * @map: the new map (as translated addr & size) to allocate in iova region
+ * @iova_begin: the minimum address of the allocation
+ * @iova_end: the maximum addressable direction of the allocation
+ *
+ * Allocates a new region of a given size, between iova_min and iova_max.
+ *
+ * Return: Same as iova_tree_insert, but cannot overlap and can be out of
+ * free contiguous range. Caller can get the assigned iova in map->iova.
+ */
+int iova_tree_alloc(IOVATree *tree, DMAMap *map, hwaddr iova_begin,
+hwaddr iova_end);
+



"iova_tree_alloc_map" seems better.



  /**
   * iova_tree_destroy:
   *
diff --git a/util/iova-tree.c b/util/iova-tree.c
index 23ea35b7a4..27c921c4e2 100644
--- a/util/iova-tree.c
+++ b/util/iova-tree.c
@@ -16,6 +16,36 @@ struct IOVATree {
  GTree *tree;
  };
  
+/* Args to pass to iova_tree_alloc foreach function. */

+struct IOVATreeAllocArgs {
+/* Size of the desired allocation */
+size_t new_size;
+
+/* The minimum address allowed in the allocation */
+hwaddr iova_begin;
+
+/* The last addressable allowed in the allocation */
+hwaddr iova_last;
+
+/* Previously-to-last iterated map, can be NULL in the first node */
+const DMAMap *hole_left;
+
+/* Last iterated map */
+const DMAMap *hole_right;



Any reason we can move those to IOVATree structure, it can simplify a 
lot of things.




+};
+
+/**
+ * Iterate args to tne next hole
+ *
+ * @args  The alloc arguments
+ * @next  The next mapping in the tree. Can be NULL to signal the last one
+ */
+static void iova_tree_alloc_args_iterate(struct IOVATreeAllocArgs *args,
+ const DMAMap *next) {
+args->hole_left = args->hole_right;
+args->hole_right = next;
+}
+
  static int iova_tree_compare(gconstpointer a, gconstpointer b, gpointer data)
  {
  const DMAMap *m1 = a, *m2 = b;
@@ -107,6 +137,115 @@ int iova_tree_remove(IOVATree *tree, const DMAMap *map)
  return IOVA_OK;
  }
  
+/**

+ * Try to accomodate a map of size ret->size in a hole between
+ * max(end(hole_left), iova_start).
+ *
+ * @args Arguments to allocation
+ */
+static bool iova_tree_alloc_map_in_hole(const struct IOVATreeAllocArgs *args)
+{
+const DMAMap *left = args->hole_left, *right = args->hole_right;
+uint64_t hole_start, hole_last;
+
+if (right && right->iova + right->size < args->iova_begin) {
+return false;
+}
+
+if (left && left->iova > args->iova_last) {
+return false;
+}
+
+hole_start = MAX(left ? left->iova + left->size + 1 : 0, args->iova_begin);
+hole_last = MIN(right ? right->iova : HWADDR_MAX, args->iova_last);
+
+if (hole_last - hole_start > args->new_size) {
+/* We found a valid hole. */
+return true;
+}
+
+/* Keep iterating */
+return false;
+}
+
+/**
+ * Foreach dma node in the tree, compare if there is a hole wit its previous
+ * node (or minimum iova address allowed) and the node.
+ *
+ * @key   Node iterating
+ * @value Node iterating
+ * @pargs Struct to communicate with the outside world
+ *
+ * Return: false to keep iterating, true if needs break.
+ */
+static gboolean iova_tree_alloc_traverse(gpointer key, gpointer value,
+ gpointer pargs)
+{
+struct IOVATreeAllocArgs *args = pargs;
+DMAMap *node = value;
+
+assert(key == value);
+
+iova_tree_alloc_args_iterate(args, node);
+if (args->hole_left && args->hole_left->iova > args->iova_last) {
+return true;
+}
+
+if (iova_tree_alloc_map_in_hole(args)) {
+return true;
+}
+
+return false;
+}

Re: [RFC PATCH v5 12/26] vhost: Route guest->host notification through shadow virtqueue

2021-11-01 Thread Jason Wang


在 2021/10/30 上午2:35, Eugenio Pérez 写道:

+/**
+ * Enable or disable shadow virtqueue in a vhost vdpa device.
+ *
+ * This function is idempotent, to call it many times with the same value for
+ * enable_svq will simply return success.
+ *
+ * @v   Vhost vdpa device
+ * @enable  True to set SVQ mode
+ * @errpError pointer
+ */
+void vhost_vdpa_enable_svq(struct vhost_vdpa *v, bool enable, Error **errp)
+{



What happens if vhost_vpda is not stated when we try to enable svq? 
Another note is that, the vhost device could be stopped and started 
after svq is enabled/disabled. We need to deal with them.


Thanks

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

Re: [RFC PATCH v5 21/26] vhost: Add vhost_svq_valid_guest_features to shadow vq

2021-11-01 Thread Jason Wang
On Sat, Oct 30, 2021 at 2:44 AM Eugenio Pérez  wrote:
>
> This allows it to test if the guest has aknowledge an invalid transport
> feature for SVQ. This will include packed vq layout or event_idx,
> where VirtIO device needs help from SVQ.
>
> There is not needed at this moment, but since SVQ will not re-negotiate
> features again with the guest, a failure in acknowledge them is fatal
> for SVQ.
>

It's not clear to me why we need this. Maybe you can give me an
example. E.g isn't it sufficient to filter out the device with
event_idx?

Thanks

> Signed-off-by: Eugenio Pérez 
> ---
>  hw/virtio/vhost-shadow-virtqueue.h | 1 +
>  hw/virtio/vhost-shadow-virtqueue.c | 6 ++
>  2 files changed, 7 insertions(+)
>
> diff --git a/hw/virtio/vhost-shadow-virtqueue.h 
> b/hw/virtio/vhost-shadow-virtqueue.h
> index 946b2c6295..ac55588009 100644
> --- a/hw/virtio/vhost-shadow-virtqueue.h
> +++ b/hw/virtio/vhost-shadow-virtqueue.h
> @@ -16,6 +16,7 @@
>  typedef struct VhostShadowVirtqueue VhostShadowVirtqueue;
>
>  bool vhost_svq_valid_device_features(uint64_t *features);
> +bool vhost_svq_valid_guest_features(uint64_t *features);
>
>  void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd);
>  void vhost_svq_set_guest_call_notifier(VhostShadowVirtqueue *svq, int 
> call_fd);
> diff --git a/hw/virtio/vhost-shadow-virtqueue.c 
> b/hw/virtio/vhost-shadow-virtqueue.c
> index 6e0508a231..cb9ffcb015 100644
> --- a/hw/virtio/vhost-shadow-virtqueue.c
> +++ b/hw/virtio/vhost-shadow-virtqueue.c
> @@ -62,6 +62,12 @@ bool vhost_svq_valid_device_features(uint64_t 
> *dev_features)
>  return true;
>  }
>
> +/* If the guest is using some of these, SVQ cannot communicate */
> +bool vhost_svq_valid_guest_features(uint64_t *guest_features)
> +{
> +return true;
> +}
> +
>  /* Forward guest notifications */
>  static void vhost_handle_guest_kick(EventNotifier *n)
>  {
> --
> 2.27.0
>

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

Re: [RFC PATCH v5 03/26] virtio: Add VIRTIO_F_QUEUE_STATE

2021-11-01 Thread Jason Wang
On Sat, Oct 30, 2021 at 2:36 AM Eugenio Pérez  wrote:
>
> Implementation of RFC of device state capability:
> https://lists.oasis-open.org/archives/virtio-comment/202012/msg5.html

Considering this still requires time to be done, we need to think of a
way to go without this.

Thanks



>
> With this capability, vdpa device can reset it's index so it can start
> consuming from guest after disabling shadow virtqueue (SVQ), with state
> not 0.
>
> The use case is to test SVQ with virtio-pci vdpa (vp_vdpa) with nested
> virtualization. Spawning a L0 qemu with a virtio-net device, use
> vp_vdpa driver to handle it in the guest, and then spawn a L1 qemu using
> that vdpa device. When L1 qemu calls device to set a new state though
> vdpa ioctl, vp_vdpa should set each queue state though virtio
> VIRTIO_PCI_COMMON_Q_AVAIL_STATE.
>
> Since this is only for testing vhost-vdpa, it's added here before of
> proposing to kernel code. No effort is done for checking that device
> can actually change its state, its layout, or if the device even
> supports to change state at all. These will be added in the future.
>
> Also, a modified version of vp_vdpa that allows to set these in PCI
> config is needed.
>
> TODO: Check for feature enabled and split in virtio pci config
>
> Signed-off-by: Eugenio Pérez 
> ---
>  hw/virtio/virtio-pci.h | 1 +
>  include/hw/virtio/virtio.h | 4 +++-
>  include/standard-headers/linux/virtio_config.h | 3 +++
>  include/standard-headers/linux/virtio_pci.h| 2 ++
>  hw/virtio/virtio-pci.c | 9 +
>  5 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
> index 2446dcd9ae..019badbd7c 100644
> --- a/hw/virtio/virtio-pci.h
> +++ b/hw/virtio/virtio-pci.h
> @@ -120,6 +120,7 @@ typedef struct VirtIOPCIQueue {
>uint32_t desc[2];
>uint32_t avail[2];
>uint32_t used[2];
> +  uint16_t state;
>  } VirtIOPCIQueue;
>
>  struct VirtIOPCIProxy {
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index 8bab9cfb75..5fe575b8f0 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -289,7 +289,9 @@ typedef struct VirtIORNGConf VirtIORNGConf;
>  DEFINE_PROP_BIT64("iommu_platform", _state, _field, \
>VIRTIO_F_IOMMU_PLATFORM, false), \
>  DEFINE_PROP_BIT64("packed", _state, _field, \
> -  VIRTIO_F_RING_PACKED, false)
> +  VIRTIO_F_RING_PACKED, false), \
> +DEFINE_PROP_BIT64("save_restore_q_state", _state, _field, \
> +  VIRTIO_F_QUEUE_STATE, true)
>
>  hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n);
>  bool virtio_queue_enabled_legacy(VirtIODevice *vdev, int n);
> diff --git a/include/standard-headers/linux/virtio_config.h 
> b/include/standard-headers/linux/virtio_config.h
> index 22e3a85f67..59fad3eb45 100644
> --- a/include/standard-headers/linux/virtio_config.h
> +++ b/include/standard-headers/linux/virtio_config.h
> @@ -90,4 +90,7 @@
>   * Does the device support Single Root I/O Virtualization?
>   */
>  #define VIRTIO_F_SR_IOV37
> +
> +/* Device support save and restore virtqueue state */
> +#define VIRTIO_F_QUEUE_STATE40
>  #endif /* _LINUX_VIRTIO_CONFIG_H */
> diff --git a/include/standard-headers/linux/virtio_pci.h 
> b/include/standard-headers/linux/virtio_pci.h
> index db7a8e2fcb..c8d9802a87 100644
> --- a/include/standard-headers/linux/virtio_pci.h
> +++ b/include/standard-headers/linux/virtio_pci.h
> @@ -164,6 +164,7 @@ struct virtio_pci_common_cfg {
> uint32_t queue_avail_hi;/* read-write */
> uint32_t queue_used_lo; /* read-write */
> uint32_t queue_used_hi; /* read-write */
> +   uint16_t queue_avail_state; /* read-write */
>  };
>
>  /* Fields in VIRTIO_PCI_CAP_PCI_CFG: */
> @@ -202,6 +203,7 @@ struct virtio_pci_cfg_cap {
>  #define VIRTIO_PCI_COMMON_Q_AVAILHI44
>  #define VIRTIO_PCI_COMMON_Q_USEDLO 48
>  #define VIRTIO_PCI_COMMON_Q_USEDHI 52
> +#define VIRTIO_PCI_COMMON_Q_AVAIL_STATE56
>
>  #endif /* VIRTIO_PCI_NO_MODERN */
>
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 750aa47ec1..d7bb549033 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -1244,6 +1244,9 @@ static uint64_t virtio_pci_common_read(void *opaque, 
> hwaddr addr,
>  case VIRTIO_PCI_COMMON_Q_USEDHI:
>  val = proxy->vqs[vdev->queue_sel].used[1];
>  break;
> +case VIRTIO_PCI_COMMON_Q_AVAIL_STATE:
> +val = virtio_queue_get_last_avail_idx(vdev, vdev->queue_sel);
> +break;
>  default:
>  val = 0;
>  }
> @@ -1330,6 +1333,8 @@ static void virtio_pci_common_write(void *opaque, 
> hwaddr addr,
> proxy->vqs[vdev->queue_sel].avail[0],
> ((uint64_t)proxy->vqs[vdev->queue_sel].

Re: [PATCH 2/2] i2c: virtio: fix completion handling

2021-11-01 Thread Viresh Kumar
On 19-10-21, 09:46, Vincent Whitchurch wrote:
> The driver currently assumes that the notify callback is only received
> when the device is done with all the queued buffers.
> 
> However, this is not true, since the notify callback could be called
> without any of the queued buffers being completed (for example, with
> virtio-pci and shared interrupts) or with only some of the buffers being
> completed (since the driver makes them available to the device in
> multiple separate virtqueue_add_sgs() calls).
> 
> This can lead to incorrect data on the I2C bus or memory corruption in
> the guest if the device operates on buffers which are have been freed by
> the driver.  (The WARN_ON in the driver is also triggered.)
> 
>  BUG kmalloc-128 (Tainted: GW): Poison overwritten
>  First byte 0x0 instead of 0x6b
>  Allocated in i2cdev_ioctl_rdwr+0x9d/0x1de age=243 cpu=0 pid=28
>   memdup_user+0x2e/0xbd
>   i2cdev_ioctl_rdwr+0x9d/0x1de
>   i2cdev_ioctl+0x247/0x2ed
>   vfs_ioctl+0x21/0x30
>   sys_ioctl+0xb18/0xb41
>  Freed in i2cdev_ioctl_rdwr+0x1bb/0x1de age=68 cpu=0 pid=28
>   kfree+0x1bd/0x1cc
>   i2cdev_ioctl_rdwr+0x1bb/0x1de
>   i2cdev_ioctl+0x247/0x2ed
>   vfs_ioctl+0x21/0x30
>   sys_ioctl+0xb18/0xb41
> 
> Fix this by calling virtio_get_buf() from the notify handler like other
> virtio drivers and by actually waiting for all the buffers to be
> completed.
> 

Add a fixes tag here please, so it can get picked to the buggy kernel
version as well.

> Signed-off-by: Vincent Whitchurch 

Acked-by: Viresh Kumar 

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


Re: [RFC PATCH v5 00/26] vDPA shadow virtqueue

2021-11-01 Thread Jason Wang


在 2021/10/30 上午2:34, Eugenio Pérez 写道:

This series enable shadow virtqueue (SVQ) for vhost-vdpa devices. This
is intended as a new method of tracking the memory the devices touch
during a migration process: Instead of relay on vhost device's dirty
logging capability, SVQ intercepts the VQ dataplane forwarding the
descriptors between VM and device. This way qemu is the effective
writer of guests memory, like in qemu's virtio device operation.

When SVQ is enabled qemu offers a new virtual address space to the
device to read and write into, and it maps new vrings and the guest
memory in it. SVQ also intercepts kicks and calls between the device
and the guest. Used buffers relay would cause dirty memory being
tracked, but at this RFC SVQ is not enabled on migration automatically.

Thanks of being a buffers relay system, SVQ can be used also to
communicate devices and drivers with different capabilities, like
devices that only supports packed vring and not split and old guest
with no driver packed support.

It is based on the ideas of DPDK SW assisted LM, in the series of
DPDK's https://patchwork.dpdk.org/cover/48370/ . However, these does
not map the shadow vq in guest's VA, but in qemu's.

For qemu to use shadow virtqueues the guest virtio driver must not use
features like event_idx.

SVQ needs to be enabled with QMP command:

{ "execute": "x-vhost-set-shadow-vq",
   "arguments": { "name": "vhost-vdpa0", "enable": true } }

This series includes some patches to delete in the final version that
helps with its testing. The first two of the series have been sent
sepparately but they haven't been included in qemu main branch.

The two after them adds the feature to stop the device and be able to
set and get its status. It's intended to be used with vp_vpda driver in
a nested environment, so they are also external to this series. The
vp_vdpa driver also need modifications to forward the new status bit,
they will be proposed sepparately

Patches 5-12 prepares the SVQ and QMP command to support guest to host
notifications forwarding. If the SVQ is enabled with these ones
applied and the device supports it, that part can be tested in
isolation (for example, with networking), hopping through SVQ.

Same thing is true with patches 13-17, but with device to guest
notifications.

Based on them, patches from 18 to 22 implement the actual buffer
forwarding, using some features already introduced in previous.
However, they will need a host device with no iommu, something that
is not available at the moment.

The last part of the series uses properly the host iommu, so the driver
can access this new virtual address space created.

Comments are welcome.



I think we need do some benchmark to see the performance impact.

Thanks




TODO:
* Event, indirect, packed, and others features of virtio.
* To sepparate buffers forwarding in its own AIO context, so we can
   throw more threads to that task and we don't need to stop the main
   event loop.
* Support multiqueue virtio-net vdpa.
* Proper documentation.

Changes from v4 RFC:
* Support of allocating / freeing iova ranges in IOVA tree. Extending
   already present iova-tree for that.
* Proper validation of guest features. Now SVQ can negotiate a
   different set of features with the device when enabled.
* Support of host notifiers memory regions
* Handling of SVQ full queue in case guest's descriptors span to
   different memory regions (qemu's VA chunks).
* Flush pending used buffers at end of SVQ operation.
* QMP command now looks by NetClientState name. Other devices will need
   to implement it's way to enable vdpa.
* Rename QMP command to set, so it looks more like a way of working
* Better use of qemu error system
* Make a few assertions proper error-handling paths.
* Add more documentation
* Less coupling of virtio / vhost, that could cause friction on changes
* Addressed many other small comments and small fixes.

Changes from v3 RFC:
   * Move everything to vhost-vdpa backend. A big change, this allowed
 some cleanup but more code has been added in other places.
   * More use of glib utilities, especially to manage memory.
v3 link:
https://lists.nongnu.org/archive/html/qemu-devel/2021-05/msg06032.html

Changes from v2 RFC:
   * Adding vhost-vdpa devices support
   * Fixed some memory leaks pointed by different comments
v2 link:
https://lists.nongnu.org/archive/html/qemu-devel/2021-03/msg05600.html

Changes from v1 RFC:
   * Use QMP instead of migration to start SVQ mode.
   * Only accepting IOMMU devices, closer behavior with target devices
 (vDPA)
   * Fix invalid masking/unmasking of vhost call fd.
   * Use of proper methods for synchronization.
   * No need to modify VirtIO device code, all of the changes are
 contained in vhost code.
   * Delete superfluous code.
   * An intermediate RFC was sent with only the notifications forwarding
 changes. It can be seen in
 https://patchew.org/QEMU/20210129205415.876290-1-epere...@redhat.com/
v1 li

Re: [PATCH V5 1/4] virtio_ring: validate used buffer length

2021-11-01 Thread Jason Wang
On Tue, Nov 2, 2021 at 11:22 AM Xuan Zhuo  wrote:
>
> On Wed, 27 Oct 2021 10:21:04 +0800, Jason Wang  wrote:
> > This patch validate the used buffer length provided by the device
> > before trying to use it. This is done by record the in buffer length
> > in a new field in desc_state structure during virtqueue_add(), then we
> > can fail the virtqueue_get_buf() when we find the device is trying to
> > give us a used buffer length which is greater than the in buffer
> > length.
> >
> > Since some drivers have already done the validation by themselves,
> > this patch tries to makes the core validation optional. For the driver
> > that doesn't want the validation, it can set the
> > suppress_used_validation to be true (which could be overridden by
> > force_used_validation module parameter). To be more efficient, a
> > dedicate array is used for storing the validate used length, this
> > helps to eliminate the cache stress if validation is done by the
> > driver.
> >
> > Signed-off-by: Jason Wang 
> > ---
> >  drivers/virtio/virtio_ring.c | 60 
> >  include/linux/virtio.h   |  2 ++
> >  2 files changed, 62 insertions(+)
> >
> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > index 4c0ec82cef56..a6e5a3b94337 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -14,6 +14,9 @@
> >  #include 
> >  #include 
> >
> > +static bool force_used_validation = false;
> > +module_param(force_used_validation, bool, 0444);
> > +
> >  #ifdef DEBUG
> >  /* For development, we want to crash whenever the ring is screwed. */
> >  #define BAD_RING(_vq, fmt, args...)  \
> > @@ -182,6 +185,9 @@ struct vring_virtqueue {
> >   } packed;
> >   };
> >
> > + /* Per-descriptor in buffer length */
> > + u32 *buflen;
> > +
> >   /* How to notify other side. FIXME: commonalize hcalls! */
> >   bool (*notify)(struct virtqueue *vq);
> >
> > @@ -490,6 +496,7 @@ static inline int virtqueue_add_split(struct virtqueue 
> > *_vq,
> >   unsigned int i, n, avail, descs_used, prev, err_idx;
> >   int head;
> >   bool indirect;
> > + u32 buflen = 0;
> >
> >   START_USE(vq);
> >
> > @@ -571,6 +578,7 @@ static inline int virtqueue_add_split(struct virtqueue 
> > *_vq,
> >VRING_DESC_F_NEXT |
> >VRING_DESC_F_WRITE,
> >indirect);
> > + buflen += sg->length;
> >   }
> >   }
> >   /* Last one doesn't continue. */
> > @@ -610,6 +618,10 @@ static inline int virtqueue_add_split(struct virtqueue 
> > *_vq,
> >   else
> >   vq->split.desc_state[head].indir_desc = ctx;
> >
> > + /* Store in buffer length if necessary */
> > + if (vq->buflen)
> > + vq->buflen[head] = buflen;
> > +
> >   /* Put entry in available array (but don't update avail->idx until 
> > they
> >* do sync). */
> >   avail = vq->split.avail_idx_shadow & (vq->split.vring.num - 1);
> > @@ -784,6 +796,11 @@ static void *virtqueue_get_buf_ctx_split(struct 
> > virtqueue *_vq,
> >   BAD_RING(vq, "id %u is not a head!\n", i);
> >   return NULL;
> >   }
> > + if (vq->buflen && unlikely(*len > vq->buflen[i])) {
> > + BAD_RING(vq, "used len %d is larger than in buflen %u\n",
> > + *len, vq->buflen[i]);
> > + return NULL;
> > + }
> >
> >   /* detach_buf_split clears data, so grab it now. */
> >   ret = vq->split.desc_state[i].data;
> > @@ -1062,6 +1079,7 @@ static int virtqueue_add_indirect_packed(struct 
> > vring_virtqueue *vq,
> >   unsigned int i, n, err_idx;
> >   u16 head, id;
> >   dma_addr_t addr;
> > + u32 buflen = 0;
> >
> >   head = vq->packed.next_avail_idx;
> >   desc = alloc_indirect_packed(total_sg, gfp);
> > @@ -1091,6 +1109,8 @@ static int virtqueue_add_indirect_packed(struct 
> > vring_virtqueue *vq,
> >   desc[i].addr = cpu_to_le64(addr);
> >   desc[i].len = cpu_to_le32(sg->length);
> >   i++;
> > + if (n >= out_sgs)
> > + buflen += sg->length;
> >   }
> >   }
> >
> > @@ -1144,6 +1164,10 @@ static int virtqueue_add_indirect_packed(struct 
> > vring_virtqueue *vq,
> >   vq->packed.desc_state[id].indir_desc = desc;
> >   vq->packed.desc_state[id].last = id;
> >
> > + /* Store in buffer length if necessary */
> > + if (vq->buflen)
> > + vq->buflen[id] = buflen;
> > +
> >   vq->num_added += 1;
> >
> >   pr_debug("Added buffer head %i to %p\n", head, vq);
> > @@ -1179,6 +1203,7 @@ static inline int virtqueue_add_packed(struct 
> > virtqueue *_vq,
> >   __le16 head_flags, flags;
> >   u16 head, i

Re: [PATCH V9 7/9] vhost: introduce vDPA-based backend

2021-11-01 Thread Jason Wang
On Mon, Nov 1, 2021 at 10:11 PM Jason Gunthorpe  wrote:
>
> On Thu, Mar 26, 2020 at 10:01:23PM +0800, Jason Wang wrote:
> > From: Tiwei Bie 
> >
> > This patch introduces a vDPA-based vhost backend. This backend is
> > built on top of the same interface defined in virtio-vDPA and provides
> > a generic vhost interface for userspace to accelerate the virtio
> > devices in guest.
> >
> > This backend is implemented as a vDPA device driver on top of the same
> > ops used in virtio-vDPA. It will create char device entry named
> > vhost-vdpa-$index for userspace to use. Userspace can use vhost ioctls
> > on top of this char device to setup the backend.
> >
> > Vhost ioctls are extended to make it type agnostic and behave like a
> > virtio device, this help to eliminate type specific API like what
> > vhost_net/scsi/vsock did:
> >
> > - VHOST_VDPA_GET_DEVICE_ID: get the virtio device ID which is defined
> >   by virtio specification to differ from different type of devices
> > - VHOST_VDPA_GET_VRING_NUM: get the maximum size of virtqueue
> >   supported by the vDPA device
> > - VHSOT_VDPA_SET/GET_STATUS: set and get virtio status of vDPA device
> > - VHOST_VDPA_SET/GET_CONFIG: access virtio config space
> > - VHOST_VDPA_SET_VRING_ENABLE: enable a specific virtqueue
> >
> > For memory mapping, IOTLB API is mandated for vhost-vDPA which means
> > userspace drivers are required to use
> > VHOST_IOTLB_UPDATE/VHOST_IOTLB_INVALIDATE to add or remove mapping for
> > a specific userspace memory region.
> >
> > The vhost-vDPA API is designed to be type agnostic, but it allows net
> > device only in current stage. Due to the lacking of control virtqueue
> > support, some features were filter out by vhost-vdpa.
> >
> > We will enable more features and devices in the near future.
>
> [..]
>
> > +static int vhost_vdpa_alloc_domain(struct vhost_vdpa *v)
> > +{
> > + struct vdpa_device *vdpa = v->vdpa;
> > + const struct vdpa_config_ops *ops = vdpa->config;
> > + struct device *dma_dev = vdpa_get_dma_dev(vdpa);
> > + struct bus_type *bus;
> > + int ret;
> > +
> > + /* Device want to do DMA by itself */
> > + if (ops->set_map || ops->dma_map)
> > + return 0;
> > +
> > + bus = dma_dev->bus;
> > + if (!bus)
> > + return -EFAULT;
> > +
> > + if (!iommu_capable(bus, IOMMU_CAP_CACHE_COHERENCY))
> > + return -ENOTSUPP;
> > +
> > + v->domain = iommu_domain_alloc(bus);
> > + if (!v->domain)
> > + return -EIO;
> > +
> > + ret = iommu_attach_device(v->domain, dma_dev);
> > + if (ret)
> > + goto err_attach;
> >
>
> I've been looking at the security of iommu_attach_device() users, and
> I wonder if this is safe?
>
> The security question is if userspace is able to control the DMA
> address the devices uses? Eg if any of the cpu to device ring's are in
> userspace memory?
>
> For instance if userspace can tell the device to send a packet from an
> arbitrary user controlled address.

The map is validated via pin_user_pages() which guarantees that the
address is not arbitrary and must belong to userspace?

Thanks

>
> Thanks,
> Jason
>

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


Re: [PATCH] virtio_gpio: drop packed attribute

2021-11-01 Thread Viresh Kumar
On 01-11-21, 05:11, Michael S. Tsirkin wrote:
> Declaring the struct packed here is mostly harmless,
> but gives a bad example for people to copy.
> As the struct is packed and aligned manually,
> let's just drop the attribute.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  include/uapi/linux/virtio_gpio.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/virtio_gpio.h 
> b/include/uapi/linux/virtio_gpio.h
> index 0445f905d8cc..25c95a034674 100644
> --- a/include/uapi/linux/virtio_gpio.h
> +++ b/include/uapi/linux/virtio_gpio.h
> @@ -25,7 +25,7 @@ struct virtio_gpio_config {
>   __le16 ngpio;
>   __u8 padding[2];
>   __le32 gpio_names_size;
> -} __packed;
> +};

Acked-by: Viresh Kumar 

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


Re: [PATCH] i2c: virtio: update the maintainer to Conghui

2021-11-01 Thread Viresh Kumar
On 01-11-21, 13:24, Jie Deng wrote:
> Due to changes in my work, I'm passing the virtio-i2c driver
> maintenance to Conghui.
> 
> Signed-off-by: Jie Deng 
> ---
>  MAINTAINERS | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 3b79fd4..8c9a677 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -19944,7 +19944,7 @@ F:include/uapi/linux/virtio_snd.h
>  F:   sound/virtio/*
>  
>  VIRTIO I2C DRIVER
> -M:   Jie Deng 
> +M:   Conghui Chen 
>  M:   Viresh Kumar 
>  L:   linux-...@vger.kernel.org
>  L:   virtualization@lists.linux-foundation.org

Acked-by: Viresh Kumar 

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


Re: [PATCH V5 1/4] virtio_ring: validate used buffer length

2021-11-01 Thread Xuan Zhuo
On Wed, 27 Oct 2021 10:21:04 +0800, Jason Wang  wrote:
> This patch validate the used buffer length provided by the device
> before trying to use it. This is done by record the in buffer length
> in a new field in desc_state structure during virtqueue_add(), then we
> can fail the virtqueue_get_buf() when we find the device is trying to
> give us a used buffer length which is greater than the in buffer
> length.
>
> Since some drivers have already done the validation by themselves,
> this patch tries to makes the core validation optional. For the driver
> that doesn't want the validation, it can set the
> suppress_used_validation to be true (which could be overridden by
> force_used_validation module parameter). To be more efficient, a
> dedicate array is used for storing the validate used length, this
> helps to eliminate the cache stress if validation is done by the
> driver.
>
> Signed-off-by: Jason Wang 
> ---
>  drivers/virtio/virtio_ring.c | 60 
>  include/linux/virtio.h   |  2 ++
>  2 files changed, 62 insertions(+)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 4c0ec82cef56..a6e5a3b94337 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -14,6 +14,9 @@
>  #include 
>  #include 
>
> +static bool force_used_validation = false;
> +module_param(force_used_validation, bool, 0444);
> +
>  #ifdef DEBUG
>  /* For development, we want to crash whenever the ring is screwed. */
>  #define BAD_RING(_vq, fmt, args...)  \
> @@ -182,6 +185,9 @@ struct vring_virtqueue {
>   } packed;
>   };
>
> + /* Per-descriptor in buffer length */
> + u32 *buflen;
> +
>   /* How to notify other side. FIXME: commonalize hcalls! */
>   bool (*notify)(struct virtqueue *vq);
>
> @@ -490,6 +496,7 @@ static inline int virtqueue_add_split(struct virtqueue 
> *_vq,
>   unsigned int i, n, avail, descs_used, prev, err_idx;
>   int head;
>   bool indirect;
> + u32 buflen = 0;
>
>   START_USE(vq);
>
> @@ -571,6 +578,7 @@ static inline int virtqueue_add_split(struct virtqueue 
> *_vq,
>VRING_DESC_F_NEXT |
>VRING_DESC_F_WRITE,
>indirect);
> + buflen += sg->length;
>   }
>   }
>   /* Last one doesn't continue. */
> @@ -610,6 +618,10 @@ static inline int virtqueue_add_split(struct virtqueue 
> *_vq,
>   else
>   vq->split.desc_state[head].indir_desc = ctx;
>
> + /* Store in buffer length if necessary */
> + if (vq->buflen)
> + vq->buflen[head] = buflen;
> +
>   /* Put entry in available array (but don't update avail->idx until they
>* do sync). */
>   avail = vq->split.avail_idx_shadow & (vq->split.vring.num - 1);
> @@ -784,6 +796,11 @@ static void *virtqueue_get_buf_ctx_split(struct 
> virtqueue *_vq,
>   BAD_RING(vq, "id %u is not a head!\n", i);
>   return NULL;
>   }
> + if (vq->buflen && unlikely(*len > vq->buflen[i])) {
> + BAD_RING(vq, "used len %d is larger than in buflen %u\n",
> + *len, vq->buflen[i]);
> + return NULL;
> + }
>
>   /* detach_buf_split clears data, so grab it now. */
>   ret = vq->split.desc_state[i].data;
> @@ -1062,6 +1079,7 @@ static int virtqueue_add_indirect_packed(struct 
> vring_virtqueue *vq,
>   unsigned int i, n, err_idx;
>   u16 head, id;
>   dma_addr_t addr;
> + u32 buflen = 0;
>
>   head = vq->packed.next_avail_idx;
>   desc = alloc_indirect_packed(total_sg, gfp);
> @@ -1091,6 +1109,8 @@ static int virtqueue_add_indirect_packed(struct 
> vring_virtqueue *vq,
>   desc[i].addr = cpu_to_le64(addr);
>   desc[i].len = cpu_to_le32(sg->length);
>   i++;
> + if (n >= out_sgs)
> + buflen += sg->length;
>   }
>   }
>
> @@ -1144,6 +1164,10 @@ static int virtqueue_add_indirect_packed(struct 
> vring_virtqueue *vq,
>   vq->packed.desc_state[id].indir_desc = desc;
>   vq->packed.desc_state[id].last = id;
>
> + /* Store in buffer length if necessary */
> + if (vq->buflen)
> + vq->buflen[id] = buflen;
> +
>   vq->num_added += 1;
>
>   pr_debug("Added buffer head %i to %p\n", head, vq);
> @@ -1179,6 +1203,7 @@ static inline int virtqueue_add_packed(struct virtqueue 
> *_vq,
>   __le16 head_flags, flags;
>   u16 head, id, prev, curr, avail_used_flags;
>   int err;
> + u32 buflen = 0;
>
>   START_USE(vq);
>
> @@ -1258,6 +1283,8 @@ static inline int virtqueue_add_packed(struct virtqueue 
> *_vq,
>   1 << VRING_PACKED_DESC_F_AVAIL |
>   1 <<

Re: [PATCH v2 01/12] kexec: Allow architecture code to opt-out at runtime

2021-11-01 Thread Eric W. Biederman
Borislav Petkov  writes:

> On Mon, Sep 13, 2021 at 05:55:52PM +0200, Joerg Roedel wrote:
>> From: Joerg Roedel 
>> 
>> Allow a runtime opt-out of kexec support for architecture code in case
>> the kernel is running in an environment where kexec is not properly
>> supported yet.
>> 
>> This will be used on x86 when the kernel is running as an SEV-ES
>> guest. SEV-ES guests need special handling for kexec to hand over all
>> CPUs to the new kernel. This requires special hypervisor support and
>> handling code in the guest which is not yet implemented.
>> 
>> Cc: sta...@vger.kernel.org # v5.10+
>> Signed-off-by: Joerg Roedel 
>> ---
>>  include/linux/kexec.h |  1 +
>>  kernel/kexec.c| 14 ++
>>  kernel/kexec_file.c   |  9 +
>>  3 files changed, 24 insertions(+)
>
> I guess I can take this through the tip tree along with the next one.

I seem to remember the consensus when this was reviewed that it was
unnecessary and there is already support for doing something like
this at a more fine grained level so we don't need a new kexec hook.

Eric

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


Re: [PATCH 03/11] dax: simplify the dax_device <-> gendisk association

2021-11-01 Thread Mike Snitzer
On Mon, Oct 18 2021 at 12:40P -0400,
Christoph Hellwig  wrote:

> Replace the dax_host_hash with an xarray indexed by the pointer value
> of the gendisk, and require explicitl calls from the block drivers that
> want to associate their gendisk with a dax_device.
> 
> Signed-off-by: Christoph Hellwig 

...

> diff --git a/drivers/md/dm.c b/drivers/md/dm.c
> index 79737aee516b1..a0a4703620650 100644
> --- a/drivers/md/dm.c
> +++ b/drivers/md/dm.c
> @@ -1683,6 +1683,7 @@ static void cleanup_mapped_device(struct mapped_device 
> *md)
>   bioset_exit(&md->io_bs);
>  
>   if (md->dax_dev) {
> + dax_remove_host(md->disk);
>   kill_dax(md->dax_dev);
>   put_dax(md->dax_dev);
>   md->dax_dev = NULL;
> @@ -1784,10 +1785,11 @@ static struct mapped_device *alloc_dev(int minor)
>   sprintf(md->disk->disk_name, "dm-%d", minor);
>  
>   if (IS_ENABLED(CONFIG_FS_DAX)) {
> - md->dax_dev = alloc_dax(md, md->disk->disk_name,
> - &dm_dax_ops, 0);
> + md->dax_dev = alloc_dax(md, &dm_dax_ops, 0);
>   if (IS_ERR(md->dax_dev))
>   goto bad;
> + if (dax_add_host(md->dax_dev, md->disk))
> + goto bad;
>   }
>  
>   format_dev_t(md->name, MKDEV(_major, minor));

Acked-by: Mike Snitzer 

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


Re: [PATCH 10/11] dm-stripe: add a stripe_dax_pgoff helper

2021-11-01 Thread Mike Snitzer
On Wed, Oct 27 2021 at  9:41P -0400,
Dan Williams  wrote:

> On Sun, Oct 17, 2021 at 9:41 PM Christoph Hellwig  wrote:
> >
> > Add a helper to perform the entire remapping for DAX accesses.  This
> > helper open codes bdev_dax_pgoff given that the alignment checks have
> > already been done by the submitting file system and don't need to be
> > repeated.
> 
> Again, looks good. Kind of embarrassing when the open-coded version is
> less LOC than using the helper.
> 
> Mike, ack?

Acked-by: Mike Snitzer 

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


Re: [PATCH 09/11] dm-log-writes: add a log_writes_dax_pgoff helper

2021-11-01 Thread Mike Snitzer
On Wed, Oct 27 2021 at  9:36P -0400,
Dan Williams  wrote:

> On Sun, Oct 17, 2021 at 9:41 PM Christoph Hellwig  wrote:
> >
> > Add a helper to perform the entire remapping for DAX accesses.  This
> > helper open codes bdev_dax_pgoff given that the alignment checks have
> > already been done by the submitting file system and don't need to be
> > repeated.
> 
> Looks good.
> 
> Mike, ack?
> 

Acked-by: Mike Snitzer 

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


Re: [PATCH 08/11] dm-linear: add a linear_dax_pgoff helper

2021-11-01 Thread Mike Snitzer
On Wed, Oct 27 2021 at  9:32P -0400,
Dan Williams  wrote:

> On Sun, Oct 17, 2021 at 9:41 PM Christoph Hellwig  wrote:
> >
> > Add a helper to perform the entire remapping for DAX accesses.  This
> > helper open codes bdev_dax_pgoff given that the alignment checks have
> > already been done by the submitting file system and don't need to be
> > repeated.
> 
> Looks good.
> 
> Mike, ack?

Acked-by: Mike Snitzer 

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


Re: [PATCH 07/11] dax: remove dax_capable

2021-11-01 Thread Mike Snitzer
On Wed, Oct 27 2021 at  8:16P -0400,
Dan Williams  wrote:

> I am going to change the subject of this patch to:
> 
> dax: remove ->dax_supported()
> 
> On Sun, Oct 17, 2021 at 9:41 PM Christoph Hellwig  wrote:
> >
> 
> I'll add a bit more background to help others review this.
> 
> The ->dax_supported() operation arranges for a stack of devices to
> each answer the question "is dax operational". That request routes to
> generic_fsdax_supported() at last level device and that attempted an
> actual dax_direct_access() call and did some sanity checks. However,
> those sanity checks can be validated in other ways and with those
> removed the only question to answer is "has each block device driver
> in the stack performed dax_add_host()". That can be validated without
> a dax_operation. So, just open code the block size and dax_dev == NULL
> checks in the callers, and delete ->dax_supported().
> 
> Mike, let me know if you have any concerns.

Thanks for your additional background, it helped.


> 
> > Just open code the block size and dax_dev == NULL checks in the callers.
> >
> > Signed-off-by: Christoph Hellwig 
> > ---
> >  drivers/dax/super.c  | 36 
> >  drivers/md/dm-table.c| 22 +++---
> >  drivers/md/dm.c  | 21 -
> >  drivers/md/dm.h  |  4 
> >  drivers/nvdimm/pmem.c|  1 -
> >  drivers/s390/block/dcssblk.c |  1 -
> >  fs/erofs/super.c | 11 +++
> >  fs/ext2/super.c  |  6 --
> >  fs/ext4/super.c  |  9 ++---
> >  fs/xfs/xfs_super.c   | 21 -
> >  include/linux/dax.h  | 14 --
> >  11 files changed, 36 insertions(+), 110 deletions(-)
> >
> > diff --git a/drivers/dax/super.c b/drivers/dax/super.c
> > index 482fe775324a4..803942586d1b6 100644
> > --- a/drivers/dax/super.c
> > +++ b/drivers/dax/super.c
> > @@ -108,42 +108,6 @@ struct dax_device *fs_dax_get_by_bdev(struct 
> > block_device *bdev)
> > return dax_dev;
> >  }
> >  EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);
> > -
> > -bool generic_fsdax_supported(struct dax_device *dax_dev,
> > -   struct block_device *bdev, int blocksize, sector_t start,
> > -   sector_t sectors)
> > -{
> > -   if (blocksize != PAGE_SIZE) {
> > -   pr_info("%pg: error: unsupported blocksize for dax\n", 
> > bdev);
> > -   return false;
> > -   }
> > -
> > -   if (!dax_dev) {
> > -   pr_debug("%pg: error: dax unsupported by block device\n", 
> > bdev);
> > -   return false;
> > -   }
> > -
> > -   return true;
> > -}
> > -EXPORT_SYMBOL_GPL(generic_fsdax_supported);
> > -
> > -bool dax_supported(struct dax_device *dax_dev, struct block_device *bdev,
> > -   int blocksize, sector_t start, sector_t len)
> > -{
> > -   bool ret = false;
> > -   int id;
> > -
> > -   if (!dax_dev)
> > -   return false;
> > -
> > -   id = dax_read_lock();
> > -   if (dax_alive(dax_dev) && dax_dev->ops->dax_supported)
> > -   ret = dax_dev->ops->dax_supported(dax_dev, bdev, blocksize,
> > - start, len);
> > -   dax_read_unlock(id);
> > -   return ret;
> > -}
> > -EXPORT_SYMBOL_GPL(dax_supported);
> >  #endif /* CONFIG_BLOCK && CONFIG_FS_DAX */
> >
> >  enum dax_device_flags {
> > diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
> > index 1fa4d5582dca5..4ae671c2168ea 100644
> > --- a/drivers/md/dm-table.c
> > +++ b/drivers/md/dm-table.c
> > @@ -807,12 +807,14 @@ void dm_table_set_type(struct dm_table *t, enum 
> > dm_queue_mode type)
> >  EXPORT_SYMBOL_GPL(dm_table_set_type);
> >
> >  /* validate the dax capability of the target device span */
> > -int device_not_dax_capable(struct dm_target *ti, struct dm_dev *dev,
> > +static int device_not_dax_capable(struct dm_target *ti, struct dm_dev *dev,
> > sector_t start, sector_t len, void *data)
> >  {
> > -   int blocksize = *(int *) data;
> > +   if (dev->dax_dev)
> > +   return false;
> >
> > -   return !dax_supported(dev->dax_dev, dev->bdev, blocksize, start, 
> > len);
> > +   pr_debug("%pg: error: dax unsupported by block device\n", 
> > dev->bdev);

Would prefer the use of DMDEBUG() here (which doesn't need trailing \n)

But otherwise:
Acked-by: Mike Snitzer 

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


Re: [PATCH 01/11] dm: make the DAX support dependend on CONFIG_FS_DAX

2021-11-01 Thread Mike Snitzer
On Wed, Oct 27 2021 at  4:53P -0400,
Dan Williams  wrote:

> On Sun, Oct 17, 2021 at 9:41 PM Christoph Hellwig  wrote:
> >
> > The device mapper DAX support is all hanging off a block device and thus
> > can't be used with device dax.  Make it depend on CONFIG_FS_DAX instead
> > of CONFIG_DAX_DRIVER.  This also means that bdev_dax_pgoff only needs to
> > be built under CONFIG_FS_DAX now.
> 
> Looks good.
> 
> Mike, can I get an ack to take this through nvdimm.git? (you'll likely
> see me repeat this question on subsequent patches in this series).

Sorry for late reply, but I see you punted on pushing for 5.16 merge
anyway (I'm sure my lack of response didn't help, sorry about that).

Acked-by: Mike Snitzer 

Thanks!

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


Re: [PATCH v2 01/12] kexec: Allow architecture code to opt-out at runtime

2021-11-01 Thread Borislav Petkov
On Mon, Sep 13, 2021 at 05:55:52PM +0200, Joerg Roedel wrote:
> From: Joerg Roedel 
> 
> Allow a runtime opt-out of kexec support for architecture code in case
> the kernel is running in an environment where kexec is not properly
> supported yet.
> 
> This will be used on x86 when the kernel is running as an SEV-ES
> guest. SEV-ES guests need special handling for kexec to hand over all
> CPUs to the new kernel. This requires special hypervisor support and
> handling code in the guest which is not yet implemented.
> 
> Cc: sta...@vger.kernel.org # v5.10+
> Signed-off-by: Joerg Roedel 
> ---
>  include/linux/kexec.h |  1 +
>  kernel/kexec.c| 14 ++
>  kernel/kexec_file.c   |  9 +
>  3 files changed, 24 insertions(+)

I guess I can take this through the tip tree along with the next one.

Eric?

-- 
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v2 4/9] drm/format-helper: Rework format-helper conversion functions

2021-11-01 Thread Thomas Zimmermann
Move destination-buffer clipping from all format-helper conversion
functions into callers. Support destination-buffer pitch. Only
distinguish between system and I/O memory, but use same logic
everywhere.

Simply harmonize the interface and semantics of the existing code.
Not all conversion helpers support all combinations of parameters.
We have to add additional features when we need them.

v2:
* fix default destination pitch in drm_fb_xrgb_to_gray8()
  (Noralf)

Signed-off-by: Thomas Zimmermann 
Tested-by: Noralf Trønnes 
Reviewed-by: Noralf Trønnes 
---
 drivers/gpu/drm/drm_format_helper.c | 131 +++-
 drivers/gpu/drm/drm_mipi_dbi.c  |   2 +-
 drivers/gpu/drm/gud/gud_pipe.c  |  10 +--
 drivers/gpu/drm/tiny/cirrus.c   |  10 +--
 drivers/gpu/drm/tiny/repaper.c  |   2 +-
 drivers/gpu/drm/tiny/st7586.c   |   2 +-
 include/drm/drm_format_helper.h |  30 +++
 7 files changed, 97 insertions(+), 90 deletions(-)

diff --git a/drivers/gpu/drm/drm_format_helper.c 
b/drivers/gpu/drm/drm_format_helper.c
index dac355320287..0c8933390fdd 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -165,7 +165,7 @@ void drm_fb_swab(void *dst, unsigned int dst_pitch, const 
void *src,
 }
 EXPORT_SYMBOL(drm_fb_swab);
 
-static void drm_fb_xrgb_to_rgb332_line(u8 *dbuf, __le32 *sbuf, unsigned 
int pixels)
+static void drm_fb_xrgb_to_rgb332_line(u8 *dbuf, const __le32 *sbuf, 
unsigned int pixels)
 {
unsigned int x;
u32 pix;
@@ -181,23 +181,24 @@ static void drm_fb_xrgb_to_rgb332_line(u8 *dbuf, 
__le32 *sbuf, unsigned int
 /**
  * drm_fb_xrgb_to_rgb332 - Convert XRGB to RGB332 clip buffer
  * @dst: RGB332 destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
  * @src: XRGB source buffer
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
  *
  * Drivers can use this function for RGB332 devices that don't natively 
support XRGB.
- *
- * This function does not apply clipping on dst, i.e. the destination is a 
small buffer
- * containing the clip rect only.
  */
-void drm_fb_xrgb_to_rgb332(void *dst, void *src, struct drm_framebuffer 
*fb,
-  struct drm_rect *clip)
+void drm_fb_xrgb_to_rgb332(void *dst, unsigned int dst_pitch, const void 
*src,
+  const struct drm_framebuffer *fb, const struct 
drm_rect *clip)
 {
size_t width = drm_rect_width(clip);
size_t src_len = width * sizeof(u32);
unsigned int y;
void *sbuf;
 
+   if (!dst_pitch)
+   dst_pitch = width;
+
/* Use a buffer to speed up access on buffers with uncached read 
mapping (i.e. WC) */
sbuf = kmalloc(src_len, GFP_KERNEL);
if (!sbuf)
@@ -208,14 +209,14 @@ void drm_fb_xrgb_to_rgb332(void *dst, void *src, 
struct drm_framebuffer *fb,
memcpy(sbuf, src, src_len);
drm_fb_xrgb_to_rgb332_line(dst, sbuf, width);
src += fb->pitches[0];
-   dst += width;
+   dst += dst_pitch;
}
 
kfree(sbuf);
 }
 EXPORT_SYMBOL(drm_fb_xrgb_to_rgb332);
 
-static void drm_fb_xrgb_to_rgb565_line(u16 *dbuf, u32 *sbuf,
+static void drm_fb_xrgb_to_rgb565_line(u16 *dbuf, const u32 *sbuf,
   unsigned int pixels,
   bool swab)
 {
@@ -236,6 +237,7 @@ static void drm_fb_xrgb_to_rgb565_line(u16 *dbuf, u32 
*sbuf,
 /**
  * drm_fb_xrgb_to_rgb565 - Convert XRGB to RGB565 clip buffer
  * @dst: RGB565 destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
  * @vaddr: XRGB source buffer
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
@@ -243,13 +245,10 @@ static void drm_fb_xrgb_to_rgb565_line(u16 *dbuf, u32 
*sbuf,
  *
  * Drivers can use this function for RGB565 devices that don't natively
  * support XRGB.
- *
- * This function does not apply clipping on dst, i.e. the destination
- * is a small buffer containing the clip rect only.
  */
-void drm_fb_xrgb_to_rgb565(void *dst, void *vaddr,
-  struct drm_framebuffer *fb,
-  struct drm_rect *clip, bool swab)
+void drm_fb_xrgb_to_rgb565(void *dst, unsigned int dst_pitch, const void 
*vaddr,
+  const struct drm_framebuffer *fb, const struct 
drm_rect *clip,
+  bool swab)
 {
size_t linepixels = clip->x2 - clip->x1;
size_t src_len = linepixels * sizeof(u32);
@@ -257,6 +256,9 @@ void drm_fb_xrgb_to_rgb565(void *dst, void *vaddr,
unsigned y, lines = clip->y2 - clip->y1;
void *sbuf;
 
+   if (!dst_pitch)
+   dst_pitch = dst_len;
+
/*
 * The cma memory is write-combined so reads are uncached.
  

[PATCH v2 9/9] drm: Clarify semantics of struct drm_mode_config.{min, max}_{width, height}

2021-11-01 Thread Thomas Zimmermann
Add additional information on the semantics of the size fields in
struct drm_mode_config. Also add a TODO to review all driver for
correct usage of these fields.

Signed-off-by: Thomas Zimmermann 
---
 Documentation/gpu/todo.rst| 15 +++
 include/drm/drm_mode_config.h | 13 +
 2 files changed, 28 insertions(+)

diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
index 60d1d7ee0719..f4e1d72149f7 100644
--- a/Documentation/gpu/todo.rst
+++ b/Documentation/gpu/todo.rst
@@ -463,6 +463,21 @@ Contact: Thomas Zimmermann , 
Christian König, Daniel Vette
 
 Level: Intermediate
 
+Review all drivers for setting struct drm_mode_config.{max_width,max_height} 
correctly
+--
+
+The values in struct drm_mode_config.{max_width,max_height} describe the
+maximum supported framebuffer size. It's the virtual screen size, but many
+drivers treat it like limitations of the physical resolution.
+
+The maximum width depends on the hardware's maximum scanline pitch. The
+maximum height depends on the amount of addressable video memory. Review all
+drivers to initialize the fields to the correct values.
+
+Contact: Thomas Zimmermann 
+
+Level: Intermediate
+
 
 Core refactorings
 =
diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h
index 48b7de80daf5..91ca575a78de 100644
--- a/include/drm/drm_mode_config.h
+++ b/include/drm/drm_mode_config.h
@@ -359,6 +359,19 @@ struct drm_mode_config_funcs {
  * Core mode resource tracking structure.  All CRTC, encoders, and connectors
  * enumerated by the driver are added here, as are global properties.  Some
  * global restrictions are also here, e.g. dimension restrictions.
+ *
+ * Framebuffer sizes refer to the virtual screen that can be displayed by
+ * the CRTC. This can be different from the physical resolution programmed.
+ * The minimum width and height, stored in @min_width and @min_height,
+ * describe the smallest size of the framebuffer. It correlates to the
+ * minimum programmable resolution.
+ * The maximum width, stored in @max_width, is typically limited by the
+ * maximum pitch between two adjacent scanlines. The maximum height, stored
+ * in @max_height, is usually only limited by the amount of addressable video
+ * memory. For hardware that has no real maximum, drivers should pick a
+ * reasonable default.
+ *
+ * See also @DRM_SHADOW_PLANE_MAX_WIDTH and @DRM_SHADOW_PLANE_MAX_HEIGHT.
  */
 struct drm_mode_config {
/**
-- 
2.33.1

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

[PATCH v2 3/9] drm/format-helper: Add destination-buffer pitch to drm_fb_swab()

2021-11-01 Thread Thomas Zimmermann
Add destination-buffer pitch as argument to drm_fb_swab(). Done for
consistency with the rest of the interface.

v2:
* update documentation (Noralf)

Signed-off-by: Thomas Zimmermann 
Tested-by: Noralf Trønnes 
Reviewed-by: Noralf Trønnes 
---
 drivers/gpu/drm/drm_format_helper.c | 21 -
 drivers/gpu/drm/drm_mipi_dbi.c  |  2 +-
 drivers/gpu/drm/gud/gud_pipe.c  |  2 +-
 include/drm/drm_format_helper.h |  5 +++--
 4 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/drm_format_helper.c 
b/drivers/gpu/drm/drm_format_helper.c
index fac37c697d8b..dac355320287 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -101,6 +101,7 @@ EXPORT_SYMBOL(drm_fb_memcpy_toio);
 /**
  * drm_fb_swab - Swap bytes into clip buffer
  * @dst: Destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
  * @src: Source buffer
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
@@ -110,21 +111,27 @@ EXPORT_SYMBOL(drm_fb_memcpy_toio);
  * time to speed up slow uncached reads.
  *
  * This function does not apply clipping on dst, i.e. the destination
- * is a small buffer containing the clip rect only.
+ * is at the top-left corner.
  */
-void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
-struct drm_rect *clip, bool cached)
+void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src,
+const struct drm_framebuffer *fb, const struct drm_rect *clip,
+bool cached)
 {
u8 cpp = fb->format->cpp[0];
size_t len = drm_rect_width(clip) * cpp;
-   u16 *src16, *dst16 = dst;
-   u32 *src32, *dst32 = dst;
+   const u16 *src16;
+   const u32 *src32;
+   u16 *dst16;
+   u32 *dst32;
unsigned int x, y;
void *buf = NULL;
 
if (WARN_ON_ONCE(cpp != 2 && cpp != 4))
return;
 
+   if (!dst_pitch)
+   dst_pitch = len;
+
if (!cached)
buf = kmalloc(len, GFP_KERNEL);
 
@@ -140,6 +147,9 @@ void drm_fb_swab(void *dst, void *src, struct 
drm_framebuffer *fb,
src32 = src;
}
 
+   dst16 = dst;
+   dst32 = dst;
+
for (x = clip->x1; x < clip->x2; x++) {
if (cpp == 4)
*dst32++ = swab32(*src32++);
@@ -148,6 +158,7 @@ void drm_fb_swab(void *dst, void *src, struct 
drm_framebuffer *fb,
}
 
src += fb->pitches[0];
+   dst += dst_pitch;
}
 
kfree(buf);
diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c
index c09df8b06c7a..7ce89917d761 100644
--- a/drivers/gpu/drm/drm_mipi_dbi.c
+++ b/drivers/gpu/drm/drm_mipi_dbi.c
@@ -211,7 +211,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
switch (fb->format->format) {
case DRM_FORMAT_RGB565:
if (swap)
-   drm_fb_swab(dst, src, fb, clip, !gem->import_attach);
+   drm_fb_swab(dst, 0, src, fb, clip, !gem->import_attach);
else
drm_fb_memcpy(dst, 0, src, fb, clip);
break;
diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
index a92112ffd37a..e0b117b2559f 100644
--- a/drivers/gpu/drm/gud/gud_pipe.c
+++ b/drivers/gpu/drm/gud/gud_pipe.c
@@ -201,7 +201,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct 
drm_framebuffer *fb,
len = gud_xrgb_to_color(buf, format, vaddr, fb, 
rect);
}
} else if (gud_is_big_endian() && format->cpp[0] > 1) {
-   drm_fb_swab(buf, vaddr, fb, rect, !import_attach);
+   drm_fb_swab(buf, 0, vaddr, fb, rect, !import_attach);
} else if (compression && !import_attach && pitch == fb->pitches[0]) {
/* can compress directly from the framebuffer */
buf = vaddr + rect->y1 * pitch;
diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
index 1fc3ba7b6060..ddcba5abe306 100644
--- a/include/drm/drm_format_helper.h
+++ b/include/drm/drm_format_helper.h
@@ -17,8 +17,9 @@ void drm_fb_memcpy(void *dst, unsigned int dst_pitch, const 
void *vaddr,
   const struct drm_framebuffer *fb, const struct drm_rect 
*clip);
 void drm_fb_memcpy_toio(void __iomem *dst, unsigned int dst_pitch, const void 
*vaddr,
const struct drm_framebuffer *fb, const struct drm_rect 
*clip);
-void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
-struct drm_rect *clip, bool cached);
+void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src,
+const struct drm_framebuffer *fb, const struct drm_rect *clip,
+bool cached);
 void drm_fb_xrgb_to_rgb332(void *dst, void *vaddr, struct drm

[PATCH v2 8/9] drm/simpledrm: Support virtual screen sizes

2021-11-01 Thread Thomas Zimmermann
Add constants for the maximum size of the shadow-plane surface
size. Useful for shadow planes with virtual screen sizes. The
current sizes are 4096 scanlines with 4096 pixels each. This
seems reasonable for current hardware, but can be increased as
necessary.

In simpledrm, set the maximum framebuffer size from the constants
for shadow planes. Implements support for virtual screen sizes and
page flipping on the fbdev console.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/tiny/simpledrm.c|  9 +++--
 include/drm/drm_gem_atomic_helper.h | 18 ++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c
index e872121e9fb0..e42ae1c6ebcd 100644
--- a/drivers/gpu/drm/tiny/simpledrm.c
+++ b/drivers/gpu/drm/tiny/simpledrm.c
@@ -2,6 +2,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -776,6 +777,7 @@ static int simpledrm_device_init_modeset(struct 
simpledrm_device *sdev)
struct drm_display_mode *mode = &sdev->mode;
struct drm_connector *connector = &sdev->connector;
struct drm_simple_display_pipe *pipe = &sdev->pipe;
+   unsigned long max_width, max_height;
const uint32_t *formats;
size_t nformats;
int ret;
@@ -784,10 +786,13 @@ static int simpledrm_device_init_modeset(struct 
simpledrm_device *sdev)
if (ret)
return ret;
 
+   max_width = max_t(unsigned long, mode->hdisplay, 
DRM_SHADOW_PLANE_MAX_WIDTH);
+   max_height = max_t(unsigned long, mode->vdisplay, 
DRM_SHADOW_PLANE_MAX_HEIGHT);
+
dev->mode_config.min_width = mode->hdisplay;
-   dev->mode_config.max_width = mode->hdisplay;
+   dev->mode_config.max_width = max_width;
dev->mode_config.min_height = mode->vdisplay;
-   dev->mode_config.max_height = mode->vdisplay;
+   dev->mode_config.max_height = max_height;
dev->mode_config.prefer_shadow_fbdev = true;
dev->mode_config.preferred_depth = sdev->format->cpp[0] * 8;
dev->mode_config.funcs = &simpledrm_mode_config_funcs;
diff --git a/include/drm/drm_gem_atomic_helper.h 
b/include/drm/drm_gem_atomic_helper.h
index 48222a107873..54983ecf641a 100644
--- a/include/drm/drm_gem_atomic_helper.h
+++ b/include/drm/drm_gem_atomic_helper.h
@@ -22,6 +22,24 @@ int drm_gem_simple_display_pipe_prepare_fb(struct 
drm_simple_display_pipe *pipe,
  * Helpers for planes with shadow buffers
  */
 
+/**
+ * DRM_SHADOW_PLANE_MAX_WIDTH - Maximum width of a plane's shadow buffer in 
pixels
+ *
+ * For drivers with shadow planes, the maximum width of the framebuffer is
+ * usually independent from hardware limitations. Drivers can initialize struct
+ * drm_mode_config.max_width from DRM_SHADOW_PLANE_MAX_WIDTH.
+ */
+#define DRM_SHADOW_PLANE_MAX_WIDTH (1ul << 12)
+
+/**
+ * DRM_SHADOW_PLANE_MAX_HEIGHT - Maximum height of a plane's shadow buffer in 
scanlines
+ *
+ * For drivers with shadow planes, the maximum height of the framebuffer is
+ * usually independent from hardware limitations. Drivers can initialize struct
+ * drm_mode_config.max_height from DRM_SHADOW_PLANE_MAX_HEIGHT.
+ */
+#define DRM_SHADOW_PLANE_MAX_HEIGHT(1ul << 12)
+
 /**
  * struct drm_shadow_plane_state - plane state for planes with shadow buffers
  *
-- 
2.33.1

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


[PATCH v2 7/9] drm/simpledrm: Enable FB_DAMAGE_CLIPS property

2021-11-01 Thread Thomas Zimmermann
Enable the FB_DAMAGE_CLIPS property to reduce display-update
overhead. Also fixes a warning in the kernel log.

  simple-framebuffer simple-framebuffer.0: [drm] 
drm_plane_enable_fb_damage_clips() not called

Fix the computation of the blit rectangle. This wasn't an issue so
far, as simpledrm always blitted the full framebuffer. The code now
supports damage clipping and virtual screen sizes.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/tiny/simpledrm.c | 30 ++
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c
index 571f716ff427..e872121e9fb0 100644
--- a/drivers/gpu/drm/tiny/simpledrm.c
+++ b/drivers/gpu/drm/tiny/simpledrm.c
@@ -642,7 +642,7 @@ simpledrm_simple_display_pipe_enable(struct 
drm_simple_display_pipe *pipe,
void *vmap = shadow_plane_state->data[0].vaddr; /* TODO: Use mapping 
abstraction */
struct drm_device *dev = &sdev->dev;
void __iomem *dst = sdev->screen_base;
-   struct drm_rect clip;
+   struct drm_rect src_clip, dst_clip;
int idx;
 
if (!fb)
@@ -651,10 +651,14 @@ simpledrm_simple_display_pipe_enable(struct 
drm_simple_display_pipe *pipe,
if (!drm_dev_enter(dev, &idx))
return;
 
-   drm_rect_init(&clip, 0, 0, fb->width, fb->height);
+   drm_rect_fp_to_int(&src_clip, &plane_state->src);
 
-   dst += drm_fb_clip_offset(sdev->pitch, sdev->format, &clip);
-   drm_fb_blit_toio(dst, sdev->pitch, sdev->format->format, vmap, fb, 
&clip);
+   dst_clip = plane_state->dst;
+   if (!drm_rect_intersect(&dst_clip, &src_clip))
+   return;
+
+   dst += drm_fb_clip_offset(sdev->pitch, sdev->format, &dst_clip);
+   drm_fb_blit_toio(dst, sdev->pitch, sdev->format->format, vmap, fb, 
&src_clip);
 
drm_dev_exit(idx);
 }
@@ -686,20 +690,28 @@ simpledrm_simple_display_pipe_update(struct 
drm_simple_display_pipe *pipe,
struct drm_framebuffer *fb = plane_state->fb;
struct drm_device *dev = &sdev->dev;
void __iomem *dst = sdev->screen_base;
-   struct drm_rect clip;
+   struct drm_rect damage_clip, src_clip, dst_clip;
int idx;
 
if (!fb)
return;
 
-   if (!drm_atomic_helper_damage_merged(old_plane_state, plane_state, 
&clip))
+   if (!drm_atomic_helper_damage_merged(old_plane_state, plane_state, 
&damage_clip))
+   return;
+
+   drm_rect_fp_to_int(&src_clip, &plane_state->src);
+   if (!drm_rect_intersect(&src_clip, &damage_clip))
+   return;
+
+   dst_clip = plane_state->dst;
+   if (!drm_rect_intersect(&dst_clip, &src_clip))
return;
 
if (!drm_dev_enter(dev, &idx))
return;
 
-   dst += drm_fb_clip_offset(sdev->pitch, sdev->format, &clip);
-   drm_fb_blit_toio(dst, sdev->pitch, sdev->format->format, vmap, fb, 
&clip);
+   dst += drm_fb_clip_offset(sdev->pitch, sdev->format, &dst_clip);
+   drm_fb_blit_toio(dst, sdev->pitch, sdev->format->format, vmap, fb, 
&src_clip);
 
drm_dev_exit(idx);
 }
@@ -794,6 +806,8 @@ static int simpledrm_device_init_modeset(struct 
simpledrm_device *sdev)
if (ret)
return ret;
 
+   drm_plane_enable_fb_damage_clips(&pipe->plane);
+
drm_mode_config_reset(dev);
 
return 0;
-- 
2.33.1

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


[PATCH v2 2/9] drm/format-helper: Rework format-helper memcpy functions

2021-11-01 Thread Thomas Zimmermann
Move destination-buffer clipping from all format-helper memcpy
function into callers. Support destination-buffer pitch. Only
distinguish between system and I/O memory, but use same logic
everywhere.

Signed-off-by: Thomas Zimmermann 
Tested-by: Noralf Trønnes 
Reviewed-by: Noralf Trønnes 
---
 drivers/gpu/drm/drm_format_helper.c | 35 -
 drivers/gpu/drm/drm_mipi_dbi.c  |  2 +-
 drivers/gpu/drm/gud/gud_pipe.c  |  2 +-
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c |  5 ++-
 drivers/gpu/drm/mgag200/mgag200_mode.c  |  4 ++-
 drivers/gpu/drm/tiny/cirrus.c   | 14 +
 include/drm/drm_format_helper.h |  9 +++---
 7 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/drm_format_helper.c 
b/drivers/gpu/drm/drm_format_helper.c
index 677e62e39f72..fac37c697d8b 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -41,58 +41,62 @@ EXPORT_SYMBOL(drm_fb_clip_offset);
 /**
  * drm_fb_memcpy - Copy clip buffer
  * @dst: Destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
  * @vaddr: Source buffer
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
  *
  * This function does not apply clipping on dst, i.e. the destination
- * is a small buffer containing the clip rect only.
+ * is at the top-left corner.
  */
-void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
-  struct drm_rect *clip)
+void drm_fb_memcpy(void *dst, unsigned int dst_pitch, const void *vaddr,
+  const struct drm_framebuffer *fb, const struct drm_rect 
*clip)
 {
unsigned int cpp = fb->format->cpp[0];
size_t len = (clip->x2 - clip->x1) * cpp;
unsigned int y, lines = clip->y2 - clip->y1;
 
+   if (!dst_pitch)
+   dst_pitch = len;
+
vaddr += clip_offset(clip, fb->pitches[0], cpp);
for (y = 0; y < lines; y++) {
memcpy(dst, vaddr, len);
vaddr += fb->pitches[0];
-   dst += len;
+   dst += dst_pitch;
}
 }
 EXPORT_SYMBOL(drm_fb_memcpy);
 
 /**
- * drm_fb_memcpy_dstclip - Copy clip buffer
+ * drm_fb_memcpy_toio - Copy clip buffer
  * @dst: Destination buffer (iomem)
  * @dst_pitch: Number of bytes between two consecutive scanlines within dst
  * @vaddr: Source buffer
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
  *
- * This function applies clipping on dst, i.e. the destination is a
- * full (iomem) framebuffer but only the clip rect content is copied over.
+ * This function does not apply clipping on dst, i.e. the destination
+ * is at the top-left corner.
  */
-void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch,
-  void *vaddr, struct drm_framebuffer *fb,
-  struct drm_rect *clip)
+void drm_fb_memcpy_toio(void __iomem *dst, unsigned int dst_pitch, const void 
*vaddr,
+   const struct drm_framebuffer *fb, const struct drm_rect 
*clip)
 {
unsigned int cpp = fb->format->cpp[0];
-   unsigned int offset = clip_offset(clip, dst_pitch, cpp);
size_t len = (clip->x2 - clip->x1) * cpp;
unsigned int y, lines = clip->y2 - clip->y1;
 
-   vaddr += offset;
-   dst += offset;
+   if (!dst_pitch)
+   dst_pitch = len;
+
+   vaddr += clip_offset(clip, fb->pitches[0], cpp);
for (y = 0; y < lines; y++) {
memcpy_toio(dst, vaddr, len);
vaddr += fb->pitches[0];
dst += dst_pitch;
}
 }
-EXPORT_SYMBOL(drm_fb_memcpy_dstclip);
+EXPORT_SYMBOL(drm_fb_memcpy_toio);
 
 /**
  * drm_fb_swab - Swap bytes into clip buffer
@@ -481,7 +485,8 @@ int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned 
int dst_pitch,
dst_format = DRM_FORMAT_XRGB;
 
if (dst_format == fb_format) {
-   drm_fb_memcpy_dstclip(dst, dst_pitch, vmap, fb, clip);
+   dst += clip_offset(clip, dst_pitch, fb->format->cpp[0]);
+   drm_fb_memcpy_toio(dst, dst_pitch, vmap, fb, clip);
return 0;
 
} else if (dst_format == DRM_FORMAT_RGB565) {
diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c
index 71b646c4131f..c09df8b06c7a 100644
--- a/drivers/gpu/drm/drm_mipi_dbi.c
+++ b/drivers/gpu/drm/drm_mipi_dbi.c
@@ -213,7 +213,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
if (swap)
drm_fb_swab(dst, src, fb, clip, !gem->import_attach);
else
-   drm_fb_memcpy(dst, src, fb, clip);
+   drm_fb_memcpy(dst, 0, src, fb, clip);
break;
case DRM_FORMAT_XRGB:
drm_fb_xrgb_to_rgb565(dst, src, fb, clip, swap);
diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
index daf7

[PATCH v2 5/9] drm/format-helper: Streamline blit-helper interface

2021-11-01 Thread Thomas Zimmermann
Move destination-buffer clipping from format-helper blit function into
caller. Rename drm_fb_blit_rect_dstclip() to drm_fb_blit_toio(). Done for
consistency with the rest of the interface. Remove drm_fb_blit_dstclip(),
which isn't required.

Signed-off-by: Thomas Zimmermann 
Reviewed-by: Noralf Trønnes 
---
 drivers/gpu/drm/drm_format_helper.c | 51 -
 drivers/gpu/drm/tiny/simpledrm.c| 14 +---
 include/drm/drm_format_helper.h | 10 ++
 3 files changed, 19 insertions(+), 56 deletions(-)

diff --git a/drivers/gpu/drm/drm_format_helper.c 
b/drivers/gpu/drm/drm_format_helper.c
index 0c8933390fdd..2fd5098d5b55 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -472,7 +472,7 @@ void drm_fb_xrgb_to_gray8(void *dst, unsigned int 
dst_pitch, const void *vad
 EXPORT_SYMBOL(drm_fb_xrgb_to_gray8);
 
 /**
- * drm_fb_blit_rect_dstclip - Copy parts of a framebuffer to display memory
+ * drm_fb_blit_toio - Copy parts of a framebuffer to display memory
  * @dst:   The display memory to copy to
  * @dst_pitch: Number of bytes between two consecutive scanlines within dst
  * @dst_format:FOURCC code of the display's color format
@@ -484,17 +484,14 @@ EXPORT_SYMBOL(drm_fb_xrgb_to_gray8);
  * formats of the display and the framebuffer mismatch, the blit function
  * will attempt to convert between them.
  *
- * Use drm_fb_blit_dstclip() to copy the full framebuffer.
- *
  * Returns:
  * 0 on success, or
  * -EINVAL if the color-format conversion failed, or
  * a negative error code otherwise.
  */
-int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned int dst_pitch,
-uint32_t dst_format, void *vmap,
-struct drm_framebuffer *fb,
-struct drm_rect *clip)
+int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t 
dst_format,
+const void *vmap, const struct drm_framebuffer *fb,
+const struct drm_rect *clip)
 {
uint32_t fb_format = fb->format->format;
 
@@ -505,20 +502,16 @@ int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned 
int dst_pitch,
dst_format = DRM_FORMAT_XRGB;
 
if (dst_format == fb_format) {
-   dst += clip_offset(clip, dst_pitch, fb->format->cpp[0]);
drm_fb_memcpy_toio(dst, dst_pitch, vmap, fb, clip);
return 0;
 
} else if (dst_format == DRM_FORMAT_RGB565) {
if (fb_format == DRM_FORMAT_XRGB) {
-   dst += clip_offset(clip, dst_pitch, fb->format->cpp[0]);
-   drm_fb_xrgb_to_rgb565_toio(dst, dst_pitch, vmap, 
fb, clip,
-  false);
+   drm_fb_xrgb_to_rgb565_toio(dst, dst_pitch, vmap, 
fb, clip, false);
return 0;
}
} else if (dst_format == DRM_FORMAT_RGB888) {
if (fb_format == DRM_FORMAT_XRGB) {
-   dst += clip_offset(clip, dst_pitch, fb->format->cpp[0]);
drm_fb_xrgb_to_rgb888_toio(dst, dst_pitch, vmap, 
fb, clip);
return 0;
}
@@ -526,36 +519,4 @@ int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned 
int dst_pitch,
 
return -EINVAL;
 }
-EXPORT_SYMBOL(drm_fb_blit_rect_dstclip);
-
-/**
- * drm_fb_blit_dstclip - Copy framebuffer to display memory
- * @dst:   The display memory to copy to
- * @dst_pitch: Number of bytes between two consecutive scanlines within dst
- * @dst_format:FOURCC code of the display's color format
- * @vmap:  The framebuffer memory to copy from
- * @fb:The framebuffer to copy from
- *
- * This function copies a full framebuffer to display memory. If the formats
- * of the display and the framebuffer mismatch, the copy function will
- * attempt to convert between them.
- *
- * See drm_fb_blit_rect_dstclip() for more information.
- *
- * Returns:
- * 0 on success, or a negative error code otherwise.
- */
-int drm_fb_blit_dstclip(void __iomem *dst, unsigned int dst_pitch,
-   uint32_t dst_format, void *vmap,
-   struct drm_framebuffer *fb)
-{
-   struct drm_rect fullscreen = {
-   .x1 = 0,
-   .x2 = fb->width,
-   .y1 = 0,
-   .y2 = fb->height,
-   };
-   return drm_fb_blit_rect_dstclip(dst, dst_pitch, dst_format, vmap, fb,
-   &fullscreen);
-}
-EXPORT_SYMBOL(drm_fb_blit_dstclip);
+EXPORT_SYMBOL(drm_fb_blit_toio);
diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c
index 481b48bde047..571f716ff427 100644
--- a/drivers/gpu/drm/tiny/simpledrm.c
+++ b/drivers/gpu/drm/tiny/simpledrm.c
@@ -641,6 +641,8 @@ simpledrm_simple_display_pipe_enable(struct 
drm_simple_display_pipe *pipe,
 

[PATCH v2 6/9] drm/fb-helper: Allocate shadow buffer of surface height

2021-11-01 Thread Thomas Zimmermann
Allocating a shadow buffer of the height of the buffer object does
not support fbdev overallocation. Use surface height instead.

Signed-off-by: Thomas Zimmermann 
Reviewed-by: Noralf Trønnes 
---
 drivers/gpu/drm/drm_fb_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 8e7a124d6c5a..9727a59d35fd 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -2338,7 +2338,7 @@ static int drm_fb_helper_generic_probe(struct 
drm_fb_helper *fb_helper,
return PTR_ERR(fbi);
 
fbi->fbops = &drm_fbdev_fb_ops;
-   fbi->screen_size = fb->height * fb->pitches[0];
+   fbi->screen_size = sizes->surface_height * fb->pitches[0];
fbi->fix.smem_len = fbi->screen_size;
 
drm_fb_helper_fill_info(fbi, fb_helper, sizes);
-- 
2.33.1

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

[PATCH v2 0/9] drm/simpledrm: Enable damage clips and virtual screens

2021-11-01 Thread Thomas Zimmermann
Enable FB_DAMAGE_CLIPS with simpledrm for improved performance and/or
less overhead. With this in place, add support for virtual screens
(i.e., framebuffers that are larger than the display resolution). This
also enables fbdev panning and page flipping.

After the discussion and bug fixing wrt to fbdev overallocation, I
decided to add full support for this to simpledrm. Patches #1 to #5
change the format-helper functions accordingly. Destination buffers
are now clipped by the caller and all functions support a similar
feature set. This has some fallout in various drivers.

Patch #6 change fbdev emulation to support overallocation with
shadow buffers, even if the hardware buffer would be too small.

Patch #7 and #8 update simpledrm to enable damage clipping and virtual
screen sizes. Both features go hand in hand, sort of. For shadow-
buffered planes, the DRM framebuffer lives in system memory. So the
maximum size of the virtual screen is somewhat arbitrary. We add two
constants for resonable maximum width and height of 4096 each.

Patch #9 adds documentation and a TODO item.

Tested with simpledrm. I also ran the recently posted fbdev panning
tests to make sure that the fbdev overallocation works correctly. [1]

v2:
* add missing docs (Sam)
* return unsigned int from drm_fb_clip_offset() (Sam, Noralf)
* fix OOB access in drm_fb_xrgb_to_gray8() (Noralf)

[1] https://lists.freedesktop.org/archives/igt-dev/2021-October/036642.html

Thomas Zimmermann (9):
  drm/format-helper: Export drm_fb_clip_offset()
  drm/format-helper: Rework format-helper memcpy functions
  drm/format-helper: Add destination-buffer pitch to drm_fb_swab()
  drm/format-helper: Rework format-helper conversion functions
  drm/format-helper: Streamline blit-helper interface
  drm/fb-helper: Allocate shadow buffer of surface height
  drm/simpledrm: Enable FB_DAMAGE_CLIPS property
  drm/simpledrm: Support virtual screen sizes
  drm: Clarify semantics of struct
drm_mode_config.{min,max}_{width,height}

 Documentation/gpu/todo.rst  |  15 ++
 drivers/gpu/drm/drm_fb_helper.c |   2 +-
 drivers/gpu/drm/drm_format_helper.c | 247 ++--
 drivers/gpu/drm/drm_mipi_dbi.c  |   6 +-
 drivers/gpu/drm/gud/gud_pipe.c  |  14 +-
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c |   5 +-
 drivers/gpu/drm/mgag200/mgag200_mode.c  |   4 +-
 drivers/gpu/drm/tiny/cirrus.c   |  24 +-
 drivers/gpu/drm/tiny/repaper.c  |   2 +-
 drivers/gpu/drm/tiny/simpledrm.c|  41 +++-
 drivers/gpu/drm/tiny/st7586.c   |   2 +-
 include/drm/drm_format_helper.h |  58 ++---
 include/drm/drm_gem_atomic_helper.h |  18 ++
 include/drm/drm_mode_config.h   |  13 ++
 14 files changed, 264 insertions(+), 187 deletions(-)

--
2.33.1

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


[PATCH v2 1/9] drm/format-helper: Export drm_fb_clip_offset()

2021-11-01 Thread Thomas Zimmermann
Provide a function that computes the offset into a blit destination
buffer. This will allow to move destination-buffer clipping into the
format-helper callers.

v2:
* provide documentation (Sam)
* return 'unsigned int' (Sam, Noralf)

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/drm_format_helper.c | 19 +--
 include/drm/drm_format_helper.h |  4 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_format_helper.c 
b/drivers/gpu/drm/drm_format_helper.c
index 69fde60e36b3..677e62e39f72 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -17,12 +17,27 @@
 #include 
 #include 
 
-static unsigned int clip_offset(struct drm_rect *clip,
-   unsigned int pitch, unsigned int cpp)
+static unsigned int clip_offset(const struct drm_rect *clip, unsigned int 
pitch, unsigned int cpp)
 {
return clip->y1 * pitch + clip->x1 * cpp;
 }
 
+/**
+ * drm_fb_clip_offset - Returns the clipping rectangles byte-offset in a 
frambuffer
+ * pitch: Frambuffer line pitch in byte
+ * format: Frambuffer format
+ * clip: Clip rectangle
+ *
+ * Returns:
+ * The byte offset of the clip rectangle's top-left corner within the 
framebuffer.
+ */
+unsigned int drm_fb_clip_offset(unsigned int pitch, const struct 
drm_format_info *format,
+   const struct drm_rect *clip)
+{
+   return clip_offset(clip, pitch, format->cpp[0]);
+}
+EXPORT_SYMBOL(drm_fb_clip_offset);
+
 /**
  * drm_fb_memcpy - Copy clip buffer
  * @dst: Destination buffer
diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
index e86925cf07b9..f5a8b334b18d 100644
--- a/include/drm/drm_format_helper.h
+++ b/include/drm/drm_format_helper.h
@@ -6,9 +6,13 @@
 #ifndef __LINUX_DRM_FORMAT_HELPER_H
 #define __LINUX_DRM_FORMAT_HELPER_H
 
+struct drm_format_info;
 struct drm_framebuffer;
 struct drm_rect;
 
+unsigned int drm_fb_clip_offset(unsigned int pitch, const struct 
drm_format_info *format,
+   const struct drm_rect *clip);
+
 void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
   struct drm_rect *clip);
 void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void 
*vaddr,
-- 
2.33.1

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


Re: [PATCH 4/9] drm/format-helper: Rework format-helper conversion functions

2021-11-01 Thread Thomas Zimmermann

Hi

Am 24.10.21 um 13:32 schrieb Noralf Trønnes:



Den 22.10.2021 15.28, skrev Thomas Zimmermann:

Move destination-buffer clipping from all format-helper conversion
functions into callers. Support destination-buffer pitch. Only
distinguish between system and I/O memory, but use same logic
everywhere.

Simply harmonize the interface and semantics of the existing code.
Not all conversion helpers support all combinations of parameters.
We have to add additional features when we need them.

Signed-off-by: Thomas Zimmermann 
---



  /**
   * drm_fb_xrgb_to_gray8 - Convert XRGB to grayscale
   * @dst: 8-bit grayscale destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
   * @vaddr: XRGB source buffer
   * @fb: DRM framebuffer
   * @clip: Clip rectangle area to copy
@@ -415,16 +417,21 @@ EXPORT_SYMBOL(drm_fb_xrgb_to_rgb888_dstclip);
   *
   * ITU BT.601 is used for the RGB -> luma (brightness) conversion.
   */
-void drm_fb_xrgb_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
-  struct drm_rect *clip)
+void drm_fb_xrgb_to_gray8(void *dst, unsigned int dst_pitch, const void 
*vaddr,
+ const struct drm_framebuffer *fb, const struct 
drm_rect *clip)
  {
unsigned int len = (clip->x2 - clip->x1) * sizeof(u32);
unsigned int x, y;
void *buf;
-   u32 *src;
+   u8 *dst8;
+   u32 *src32;
  
  	if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB))

return;
+
+   if (!dst_pitch)


len is source length (should really have been named src_len) which
results in a kernel crash:


+   dst_pitch = len;


This works:

dst_pitch = drm_rect_width(clip);


Fixed in the next revision. Thank you so much!

Best regards
Thomas



With that fixed:

Tested-by: Noralf Trønnes 
Reviewed-by: Noralf Trønnes 


+
/*
 * The cma memory is write-combined so reads are uncached.
 * Speed up by fetching one line at a time.
@@ -433,20 +440,22 @@ void drm_fb_xrgb_to_gray8(u8 *dst, void *vaddr, 
struct drm_framebuffer *fb,
if (!buf)
return;
  
+	vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));

for (y = clip->y1; y < clip->y2; y++) {
-   src = vaddr + (y * fb->pitches[0]);
-   src += clip->x1;
-   memcpy(buf, src, len);
-   src = buf;
+   dst8 = dst;
+   src32 = memcpy(buf, vaddr, len);
for (x = clip->x1; x < clip->x2; x++) {
-   u8 r = (*src & 0x00ff) >> 16;
-   u8 g = (*src & 0xff00) >> 8;
-   u8 b =  *src & 0x00ff;
+   u8 r = (*src32 & 0x00ff) >> 16;
+   u8 g = (*src32 & 0xff00) >> 8;
+   u8 b =  *src32 & 0x00ff;
  
  			/* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */

-   *dst++ = (3 * r + 6 * g + b) / 10;
-   src++;
+   *dst8++ = (3 * r + 6 * g + b) / 10;
+   src32++;
}
+
+   vaddr += fb->pitches[0];
+   dst += dst_pitch;
}
  
  	kfree(buf);


--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev


OpenPGP_signature
Description: OpenPGP digital signature
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH v7 0/9] vDPA driver for Alibaba ENI

2021-11-01 Thread Michael S. Tsirkin
On Mon, Nov 01, 2021 at 04:11:59PM +0800, Wu Zongyong wrote:
> On Mon, Nov 01, 2021 at 03:02:52PM +0800, Jason Wang wrote:
> > On Mon, Nov 1, 2021 at 2:23 PM Wu Zongyong  
> > wrote:
> > >
> > > On Mon, Nov 01, 2021 at 11:31:15AM +0800, Jason Wang wrote:
> > > > On Fri, Oct 29, 2021 at 5:15 PM Wu Zongyong
> > > >  wrote:
> > > > >
> > > > > This series implements the vDPA driver for Alibaba ENI (Elastic 
> > > > > Network
> > > > > Interface) which is built based on virtio-pci 0.9.5 specification.
> > > >
> > > > It looks to me Michael has applied the patches, if this is the case,
> > > > we probably need to send patches on top.
> > >
> > > What do you mean by saying "send patches on top"?
> > > Sorry, I'm a newbie to contribute for kernel, could you please explain
> > > it in detail?
> > 
> > I meant you probably need to send incremental patch on top of:
> > 
> > git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next.
> 
> Get it.
> 
> Thanks

No need, I rebased.

> > 
> > Thanks
> > 
> > 
> > >
> > > Thanks
> > > > Thanks
> > > >
> > > > >
> > > > > Changes since V6:
> > > > > - set default min vq size to 1 intead of 0
> > > > > - enable eni vdpa driver only on X86 hosts
> > > > > - fix some typos
> > > > >
> > > > > Changes since V5:
> > > > > - remove unused codes
> > > > >
> > > > > Changes since V4:
> > > > > - check return values of get_vq_num_{max,min} when probing devices
> > > > > - disable the driver on BE host via Kconfig
> > > > > - add missing commit message
> > > > >
> > > > > Changes since V3:
> > > > > - validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
> > > > > - present F_ORDER_PLATFORM in get_features
> > > > > - remove endian check since ENI always use litter endian
> > > > >
> > > > > Changes since V2:
> > > > > - add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead
> > > > >   VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue
> > > > >   size as suggested by Jason Wang
> > > > > - present ACCESS_PLATFORM in get_features callback as suggested by 
> > > > > Jason
> > > > >   Wang
> > > > > - disable this driver on Big Endian host as suggested by Jason Wang
> > > > > - fix a typo
> > > > >
> > > > > Changes since V1:
> > > > > - add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether
> > > > >   the vdpa device is legacy
> > > > > - implement dedicated driver for Alibaba ENI instead a legacy 
> > > > > virtio-pci
> > > > >   driver as suggested by Jason Wang
> > > > > - some bugs fixed
> > > > >
> > > > > Wu Zongyong (9):
> > > > >   virtio-pci: introduce legacy device module
> > > > >   vdpa: fix typo
> > > > >   vp_vdpa: add vq irq offloading support
> > > > >   vdpa: add new callback get_vq_num_min in vdpa_config_ops
> > > > >   vdpa: min vq num of vdpa device cannot be greater than max vq num
> > > > >   virtio_vdpa: setup correct vq size with callbacks 
> > > > > get_vq_num_{max,min}
> > > > >   vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
> > > > >   eni_vdpa: add vDPA driver for Alibaba ENI
> > > > >   eni_vdpa: alibaba: fix Kconfig typo
> > > > >
> > > > >  drivers/vdpa/Kconfig   |   8 +
> > > > >  drivers/vdpa/Makefile  |   1 +
> > > > >  drivers/vdpa/alibaba/Makefile  |   3 +
> > > > >  drivers/vdpa/alibaba/eni_vdpa.c| 553 
> > > > > +
> > > > >  drivers/vdpa/vdpa.c|  13 +
> > > > >  drivers/vdpa/virtio_pci/vp_vdpa.c  |  12 +
> > > > >  drivers/virtio/Kconfig |  10 +
> > > > >  drivers/virtio/Makefile|   1 +
> > > > >  drivers/virtio/virtio_pci_common.c |  10 +-
> > > > >  drivers/virtio/virtio_pci_common.h |   9 +-
> > > > >  drivers/virtio/virtio_pci_legacy.c | 101 ++---
> > > > >  drivers/virtio/virtio_pci_legacy_dev.c | 220 ++
> > > > >  drivers/virtio/virtio_vdpa.c   |  16 +-
> > > > >  include/linux/vdpa.h   |   6 +-
> > > > >  include/linux/virtio_pci_legacy.h  |  42 ++
> > > > >  include/uapi/linux/vdpa.h  |   1 +
> > > > >  16 files changed, 917 insertions(+), 89 deletions(-)
> > > > >  create mode 100644 drivers/vdpa/alibaba/Makefile
> > > > >  create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
> > > > >  create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
> > > > >  create mode 100644 include/linux/virtio_pci_legacy.h
> > > > >
> > > > > --
> > > > > 2.31.1
> > > > >
> > >

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


[PATCH] virtio_gpio: drop packed attribute

2021-11-01 Thread Michael S. Tsirkin
Declaring the struct packed here is mostly harmless,
but gives a bad example for people to copy.
As the struct is packed and aligned manually,
let's just drop the attribute.

Signed-off-by: Michael S. Tsirkin 
---
 include/uapi/linux/virtio_gpio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/virtio_gpio.h b/include/uapi/linux/virtio_gpio.h
index 0445f905d8cc..25c95a034674 100644
--- a/include/uapi/linux/virtio_gpio.h
+++ b/include/uapi/linux/virtio_gpio.h
@@ -25,7 +25,7 @@ struct virtio_gpio_config {
__le16 ngpio;
__u8 padding[2];
__le32 gpio_names_size;
-} __packed;
+};
 
 /* Virtio GPIO Request / Response */
 struct virtio_gpio_request {
-- 
MST

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


Re: [PATCH 7/9] drm/simpledrm: Enable FB_DAMAGE_CLIPS property

2021-11-01 Thread Thomas Zimmermann

Hi

Am 24.10.21 um 17:20 schrieb Noralf Trønnes:



Den 22.10.2021 15.28, skrev Thomas Zimmermann:

Enable the FB_DAMAGE_CLIPS property to reduce display-update
overhead. Also fixes a warning in the kernel log.

   simple-framebuffer simple-framebuffer.0: [drm] 
drm_plane_enable_fb_damage_clips() not called

Fix the computation of the blit rectangle. This wasn't an issue so
far, as simpledrm always blitted the full framebuffer. The code now
supports damage clipping and virtual screen sizes.

Signed-off-by: Thomas Zimmermann 
---
  drivers/gpu/drm/tiny/simpledrm.c | 30 ++
  1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c
index 571f716ff427..e872121e9fb0 100644
--- a/drivers/gpu/drm/tiny/simpledrm.c
+++ b/drivers/gpu/drm/tiny/simpledrm.c
@@ -642,7 +642,7 @@ simpledrm_simple_display_pipe_enable(struct 
drm_simple_display_pipe *pipe,
void *vmap = shadow_plane_state->data[0].vaddr; /* TODO: Use mapping 
abstraction */
struct drm_device *dev = &sdev->dev;
void __iomem *dst = sdev->screen_base;
-   struct drm_rect clip;
+   struct drm_rect src_clip, dst_clip;
int idx;
  
  	if (!fb)

@@ -651,10 +651,14 @@ simpledrm_simple_display_pipe_enable(struct 
drm_simple_display_pipe *pipe,
if (!drm_dev_enter(dev, &idx))
return;
  
-	drm_rect_init(&clip, 0, 0, fb->width, fb->height);

+   drm_rect_fp_to_int(&src_clip, &plane_state->src);
  
-	dst += drm_fb_clip_offset(sdev->pitch, sdev->format, &clip);

-   drm_fb_blit_toio(dst, sdev->pitch, sdev->format->format, vmap, fb, 
&clip);
+   dst_clip = plane_state->dst;
+   if (!drm_rect_intersect(&dst_clip, &src_clip))
+   return;
+
+   dst += drm_fb_clip_offset(sdev->pitch, sdev->format, &dst_clip);
+   drm_fb_blit_toio(dst, sdev->pitch, sdev->format->format, vmap, fb, 
&src_clip);
  
  	drm_dev_exit(idx);

  }
@@ -686,20 +690,28 @@ simpledrm_simple_display_pipe_update(struct 
drm_simple_display_pipe *pipe,
struct drm_framebuffer *fb = plane_state->fb;
struct drm_device *dev = &sdev->dev;
void __iomem *dst = sdev->screen_base;
-   struct drm_rect clip;
+   struct drm_rect damage_clip, src_clip, dst_clip;
int idx;
  
  	if (!fb)

return;
  
-	if (!drm_atomic_helper_damage_merged(old_plane_state, plane_state, &clip))

+   if (!drm_atomic_helper_damage_merged(old_plane_state, plane_state, 
&damage_clip))
+   return;
+


I'm afraid I don't understand what's going on here, but isn't it
possible to put this logic into drm_atomic_helper_damage_merged()?


The code above gets the damage rectangle (i.e., the plane's area that 
needs to be updated). The code below get's the framebuffer area. If they 
don't overlap, return. (I think this can really only fail with the next 
patch in the series, which adds virtual screens.)




Noralf.


+   drm_rect_fp_to_int(&src_clip, &plane_state->src);
+   if (!drm_rect_intersect(&src_clip, &damage_clip))
+   return;
+
+   dst_clip = plane_state->dst;
+   if (!drm_rect_intersect(&dst_clip, &src_clip))
return;


And here we check if the updated plane/framebuffer area is actually 
visible on screen; otherwise return. It could be in an area that is 
off-screen. (Again, this probably only fails with the virtual-screen patch.)


I don't think this is all generic enough to be within 
drm_atomic_helper_damage_merged(). But once we have multiple SHMEM-based 
drivers with virtual screens, we can move it into a helper for 
shadow-buffered planes. Your gud driver would be a candidate for this 
feature as well.


Best regards
Thomas

  
  	if (!drm_dev_enter(dev, &idx))

return;
  
-	dst += drm_fb_clip_offset(sdev->pitch, sdev->format, &clip);

-   drm_fb_blit_toio(dst, sdev->pitch, sdev->format->format, vmap, fb, 
&clip);
+   dst += drm_fb_clip_offset(sdev->pitch, sdev->format, &dst_clip);
+   drm_fb_blit_toio(dst, sdev->pitch, sdev->format->format, vmap, fb, 
&src_clip);
  
  	drm_dev_exit(idx);

  }
@@ -794,6 +806,8 @@ static int simpledrm_device_init_modeset(struct 
simpledrm_device *sdev)
if (ret)
return ret;
  
+	drm_plane_enable_fb_damage_clips(&pipe->plane);

+
drm_mode_config_reset(dev);
  
  	return 0;




--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev


OpenPGP_signature
Description: OpenPGP digital signature
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [RFC PATCH 2/4] drivers/net/virtio_net: Changed mergeable buffer length calculation.

2021-11-01 Thread Michael S. Tsirkin
On Sun, Oct 31, 2021 at 06:59:57AM +0200, Andrew Melnychenko wrote:
> Now minimal virtual header length is may include the entire v1 header
> if the hash report were populated.
> 
> Signed-off-by: Andrew Melnychenko 

subject isn't really descriptive. changed it how?

And I couldn't really decypher what this log entry means either.

> ---
>  drivers/net/virtio_net.c | 8 +---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index b72b21ac8ebd..abca2e93355d 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -393,7 +393,9 @@ static struct sk_buff *page_to_skb(struct virtnet_info 
> *vi,
>   hdr_p = p;
>  
>   hdr_len = vi->hdr_len;
> - if (vi->mergeable_rx_bufs)
> + if (vi->has_rss_hash_report)
> + hdr_padded_len = sizeof(struct virtio_net_hdr_v1_hash);
> + else if (vi->mergeable_rx_bufs)
>   hdr_padded_len = sizeof(*hdr);
>   else
>   hdr_padded_len = sizeof(struct padded_vnet_hdr);
> @@ -1252,7 +1254,7 @@ static unsigned int get_mergeable_buf_len(struct 
> receive_queue *rq,
> struct ewma_pkt_len *avg_pkt_len,
> unsigned int room)
>  {
> - const size_t hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf);
> + const size_t hdr_len = ((struct virtnet_info 
> *)(rq->vq->vdev->priv))->hdr_len;
>   unsigned int len;
>  
>   if (room)

Is this pointer chasing the best we can do?

> @@ -2817,7 +2819,7 @@ static void virtnet_del_vqs(struct virtnet_info *vi)
>   */
>  static unsigned int mergeable_min_buf_len(struct virtnet_info *vi, struct 
> virtqueue *vq)
>  {
> - const unsigned int hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf);
> + const unsigned int hdr_len = vi->hdr_len;
>   unsigned int rq_size = virtqueue_get_vring_size(vq);
>   unsigned int packet_len = vi->big_packets ? IP_MAX_MTU : 
> vi->dev->max_mtu;
>   unsigned int buf_len = hdr_len + ETH_HLEN + VLAN_HLEN + packet_len;
> -- 
> 2.33.1

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


Re: [PATCH 1/9] drm/format-helper: Export drm_fb_clip_offset()

2021-11-01 Thread Thomas Zimmermann

Hi

Am 23.10.21 um 09:49 schrieb Sam Ravnborg:

Hi Thomas,

On Fri, Oct 22, 2021 at 03:28:21PM +0200, Thomas Zimmermann wrote:

Provide a function that computes the offset into a blit destination
buffer. This will allow to move destination-buffer clipping into the
format-helper callers.

Signed-off-by: Thomas Zimmermann 
---
  drivers/gpu/drm/drm_format_helper.c | 10 --
  include/drm/drm_format_helper.h |  4 
  2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_format_helper.c 
b/drivers/gpu/drm/drm_format_helper.c
index 69fde60e36b3..28e9d0d89270 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -17,12 +17,18 @@
  #include 
  #include 
  
-static unsigned int clip_offset(struct drm_rect *clip,

-   unsigned int pitch, unsigned int cpp)
+static unsigned int clip_offset(const struct drm_rect *clip, unsigned int 
pitch, unsigned int cpp)
  {
return clip->y1 * pitch + clip->x1 * cpp;
  }
  
+unsigned long drm_fb_clip_offset(unsigned int pitch, const struct drm_format_info *format,

+const struct drm_rect *clip)
+{
+   return clip_offset(clip, pitch, format->cpp[0]);
+}
+EXPORT_SYMBOL(drm_fb_clip_offset);


Exported functions are expected to have kernel-doc documentation.
Just copy more or less from the changelog I think.


That's an oversight. Sorry.



Anywhere else (I looked in struct drm_framebuffer) we only need unsigned
int for offsets and width/length - so I cannot see why we do an unsigned
int => unsigned long conversion here.


On ancient platforms, int was 16 bit wide. So for values that are array 
indices or buffer indices, I naturally use long, which is 32-bit at 
least. Never mind, it's not relevant any longer. I'll convert this code 
to unsigned int.


Best regards
Thomas



Sam


+
  /**
   * drm_fb_memcpy - Copy clip buffer
   * @dst: Destination buffer
diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
index e86925cf07b9..90b9bd9ecb83 100644
--- a/include/drm/drm_format_helper.h
+++ b/include/drm/drm_format_helper.h
@@ -6,9 +6,13 @@
  #ifndef __LINUX_DRM_FORMAT_HELPER_H
  #define __LINUX_DRM_FORMAT_HELPER_H
  
+struct drm_format_info;

  struct drm_framebuffer;
  struct drm_rect;
  
+unsigned long drm_fb_clip_offset(unsigned int pitch, const struct drm_format_info *format,

+const struct drm_rect *clip);
+
  void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
   struct drm_rect *clip);
  void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void 
*vaddr,
--
2.33.0


--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev


OpenPGP_signature
Description: OpenPGP digital signature
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [RFC PATCH 1/4] drivers/net/virtio_net: Fixed vheader to use v1.

2021-11-01 Thread Michael S. Tsirkin
On Sun, Oct 31, 2021 at 06:59:56AM +0200, Andrew Melnychenko wrote:
> The header v1 provides additional info about RSS.
> Added changes to computing proper header length.
> In the next patches, the header may contain RSS hash info
> for the hash population.
> 
> Signed-off-by: Andrew Melnychenko 
> ---
>  drivers/net/virtio_net.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 4ad25a8b0870..b72b21ac8ebd 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -240,13 +240,13 @@ struct virtnet_info {
>  };
>  
>  struct padded_vnet_hdr {
> - struct virtio_net_hdr_mrg_rxbuf hdr;
> + struct virtio_net_hdr_v1_hash hdr;
>   /*
>* hdr is in a separate sg buffer, and data sg buffer shares same page
>* with this header sg. This padding makes next sg 16 byte aligned
>* after the header.
>*/
> - char padding[4];
> + char padding[12];
>  };
>  
>  static bool is_xdp_frame(void *ptr)


This is not helpful as a separate patch, just reserving extra space.
better squash with the patches making use of the change.

> @@ -1636,7 +1636,7 @@ static int xmit_skb(struct send_queue *sq, struct 
> sk_buff *skb)
>   const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
>   struct virtnet_info *vi = sq->vq->vdev->priv;
>   int num_sg;
> - unsigned hdr_len = vi->hdr_len;
> + unsigned int hdr_len = vi->hdr_len;
>   bool can_push;


if we want this, pls make it a separate patch.


>  
>   pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest);
> -- 
> 2.33.1

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


Re: [PATCH v2 1/3] virtio: cache indirect desc for split

2021-11-01 Thread Michael S. Tsirkin
On Thu, Oct 28, 2021 at 06:49:17PM +0800, Xuan Zhuo wrote:
> In the case of using indirect, indirect desc must be allocated and
> released each time, which increases a lot of cpu overhead.
> 
> Here, a cache is added for indirect. If the number of indirect desc to be
> applied for is less than VIRT_QUEUE_CACHE_DESC_NUM, the desc array with
> the size of VIRT_QUEUE_CACHE_DESC_NUM is fixed and cached for reuse.
> 
> Signed-off-by: Xuan Zhuo 
> ---
>  drivers/virtio/virtio.c  |  6 +++
>  drivers/virtio/virtio_ring.c | 77 
>  include/linux/virtio.h   | 14 +++
>  3 files changed, 89 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index 0a5b54034d4b..1047149ac2a4 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -431,6 +431,12 @@ bool is_virtio_device(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(is_virtio_device);
>  
> +void virtio_set_desc_cache(struct virtio_device *dev, u32 thr)
> +{
> + dev->desc_cache_thr = thr;
> +}
> +EXPORT_SYMBOL_GPL(virtio_set_desc_cache);
> +
>  void unregister_virtio_device(struct virtio_device *dev)
>  {
>   int index = dev->index; /* save for after device release */
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index dd95dfd85e98..0ebcd4f12d3b 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -117,6 +117,15 @@ struct vring_virtqueue {
>   /* Hint for event idx: already triggered no need to disable. */
>   bool event_triggered;
>  
> + /* desc cache threshold
> +  *0   - disable desc cache
> +  *> 0 - enable desc cache. As the threshold of the desc cache.
> +  */
> + u32 desc_cache_thr;
> +
> + /* desc cache chain */
> + struct list_head desc_cache;
> +
>   union {
>   /* Available for split ring */
>   struct {
> @@ -423,7 +432,53 @@ static unsigned int vring_unmap_one_split(const struct 
> vring_virtqueue *vq,
>   return extra[i].next;
>  }
>  
> -static struct vring_desc *alloc_indirect_split(struct virtqueue *_vq,
> +static void desc_cache_free(struct list_head *head)
> +{
> + struct list_head *n, *pos;
> +
> + BUILD_BUG_ON(sizeof(struct list_head) > sizeof(struct vring_desc));
> + BUILD_BUG_ON(sizeof(struct list_head) > sizeof(struct 
> vring_packed_desc));
> +
> + list_for_each_prev_safe(pos, n, head)
> + kfree(pos);
> +}
> +
> +static void __desc_cache_put(struct vring_virtqueue *vq,
> +  struct list_head *node, int n)
> +{
> + if (n <= vq->desc_cache_thr)
> + list_add(node, &vq->desc_cache);
> + else
> + kfree(node);
> +}
> +
> +#define desc_cache_put(vq, desc, n) \
> + __desc_cache_put(vq, (struct list_head *)desc, n)
> +
> +static void *desc_cache_get(struct vring_virtqueue *vq,
> + int size, int n, gfp_t gfp)
> +{
> + struct list_head *node;
> +
> + if (n > vq->desc_cache_thr)
> + return kmalloc_array(n, size, gfp);
> +
> + if (!list_empty(&vq->desc_cache)) {
> + node = vq->desc_cache.next;
> + list_del(node);
> + return node;
> + }
> +
> + return kmalloc_array(vq->desc_cache_thr, size, gfp);
> +}
> +
> +#define _desc_cache_get(vq, n, gfp, tp) \
> + ((tp *)desc_cache_get(vq, (sizeof(tp)), n, gfp))
> +
> +#define desc_cache_get_split(vq, n, gfp) \
> + _desc_cache_get(vq, n, gfp, struct vring_desc)
> +
> +static struct vring_desc *alloc_indirect_split(struct vring_virtqueue *vq,
>  unsigned int total_sg,
>  gfp_t gfp)
>  {
> @@ -437,12 +492,12 @@ static struct vring_desc *alloc_indirect_split(struct 
> virtqueue *_vq,
>*/
>   gfp &= ~__GFP_HIGHMEM;
>  
> - desc = kmalloc_array(total_sg, sizeof(struct vring_desc), gfp);
> + desc = desc_cache_get_split(vq, total_sg, gfp);
>   if (!desc)
>   return NULL;
>  
>   for (i = 0; i < total_sg; i++)
> - desc[i].next = cpu_to_virtio16(_vq->vdev, i + 1);
> + desc[i].next = cpu_to_virtio16(vq->vq.vdev, i + 1);
>   return desc;
>  }
>  
> @@ -508,7 +563,7 @@ static inline int virtqueue_add_split(struct virtqueue 
> *_vq,
>   head = vq->free_head;
>  
>   if (virtqueue_use_indirect(_vq, total_sg))
> - desc = alloc_indirect_split(_vq, total_sg, gfp);
> + desc = alloc_indirect_split(vq, total_sg, gfp);
>   else {
>   desc = NULL;
>   WARN_ON_ONCE(total_sg > vq->split.vring.num && !vq->indirect);
> @@ -652,7 +707,7 @@ static inline int virtqueue_add_split(struct virtqueue 
> *_vq,
>   }
>  
>   if (indirect)
> - kfree(desc);
> + desc_cache_put(vq, desc, total_sg);
>  
>   END_USE(vq);
>   return -ENOMEM;
> @@ -717,7 +772,7 @@ static

Re: [PATCH v2 3/3] virtio-net: enable virtio indirect cache

2021-11-01 Thread Michael S. Tsirkin
On Thu, Oct 28, 2021 at 06:49:19PM +0800, Xuan Zhuo wrote:
> If the VIRTIO_RING_F_INDIRECT_DESC negotiation succeeds, and the number
> of sgs used for sending packets is greater than 1. We must constantly
> call __kmalloc/kfree to allocate/release desc.
> 
> In the case of extremely fast package delivery, the overhead cannot be
> ignored:
> 
>   27.46%  [kernel]  [k] virtqueue_add
>   16.66%  [kernel]  [k] detach_buf_split
>   16.51%  [kernel]  [k] virtnet_xsk_xmit
>   14.04%  [kernel]  [k] virtqueue_add_outbuf
>5.18%  [kernel]  [k] __kmalloc
>4.08%  [kernel]  [k] kfree
>2.80%  [kernel]  [k] virtqueue_get_buf_ctx
>2.22%  [kernel]  [k] xsk_tx_peek_desc
>2.08%  [kernel]  [k] memset_erms
>0.83%  [kernel]  [k] virtqueue_kick_prepare
>0.76%  [kernel]  [k] virtnet_xsk_run
>0.62%  [kernel]  [k] __free_old_xmit_ptr
>0.60%  [kernel]  [k] vring_map_one_sg
>0.53%  [kernel]  [k] native_apic_mem_write
>0.46%  [kernel]  [k] sg_next
>0.43%  [kernel]  [k] sg_init_table
>0.41%  [kernel]  [k] kmalloc_slab
> 
> Compared to not using virtio indirect cache, virtio-net can get a 16%
> performance improvement when using indirect desc cache.
> 
> In the test case, the CPU where the package is sent has reached 100%.
> The following are the PPS in two cases:
> 
> indirect desc cache  | no cache
> 3074658  | 2685132
> 3111866  | 2666118
> 3152527  | 2653632
> 3125867  | 2669820
> 3027147  | 2644464
> 3069211  | 2669777
> 3038522  | 2675645
> 3034507  | 2671302
> 3102257  | 2685504
> 3083712  | 2692800
> 3051771  | 2676928
> 3080684  | 2695040
> 3147816  | 2720876
> 3123887  | 2705492
> 3180963  | 2699520
> 3191579  | 2676480
> 3161670  | 2686272
> 3189768  | 2692588
> 3174272  | 2686692
> 3143434  | 2682416
> 
> Signed-off-by: Xuan Zhuo 
> ---
>  drivers/net/virtio_net.c | 12 
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 4ad25a8b0870..e1ade176ab46 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -31,6 +31,13 @@ module_param(csum, bool, 0444);
>  module_param(gso, bool, 0444);
>  module_param(napi_tx, bool, 0644);
>  
> +/**
> + * Because virtio desc cache will increase memory overhead, users can turn it
> + * off or select an acceptable value. The maximum value is 2 + MAX_SKB_FRAGS.
> + */

Maybe add code to validate it and cap it at acceptable values then.

> +static u32 virtio_desc_cache_thr = 4;

Wouldn't something like CACHE_LINE_SIZE make more sense here?

> +module_param(virtio_desc_cache_thr, uint, 0644);
> +
>  /* FIXME: MTU in config. */
>  #define GOOD_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
>  #define GOOD_COPY_LEN128


> @@ -3214,6 +3221,11 @@ static int virtnet_probe(struct virtio_device *vdev)
>   vi->curr_queue_pairs = num_online_cpus();
>   vi->max_queue_pairs = max_queue_pairs;
>  
> + if (virtio_desc_cache_thr > 2 + MAX_SKB_FRAGS)
> + virtio_set_desc_cache(vdev, 2 + MAX_SKB_FRAGS);
> + else
> + virtio_set_desc_cache(vdev, virtio_desc_cache_thr);
> +
>   /* Allocate/initialize the rx/tx queues, and invoke find_vqs */
>   err = init_vqs(vi);
>   if (err)
> -- 
> 2.31.0

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


Re: [PATCH v7 0/9] vDPA driver for Alibaba ENI

2021-11-01 Thread Michael S. Tsirkin
On Fri, Oct 29, 2021 at 05:14:41PM +0800, Wu Zongyong wrote:
> This series implements the vDPA driver for Alibaba ENI (Elastic Network
> Interface) which is built based on virtio-pci 0.9.5 specification.

In the future pls do not send v7 as a reply to v6.
Start a new thread with each version.

> Changes since V6:
> - set default min vq size to 1 intead of 0
> - enable eni vdpa driver only on X86 hosts
> - fix some typos
> 
> Changes since V5:
> - remove unused codes
> 
> Changes since V4:
> - check return values of get_vq_num_{max,min} when probing devices
> - disable the driver on BE host via Kconfig
> - add missing commit message
> 
> Changes since V3:
> - validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
> - present F_ORDER_PLATFORM in get_features
> - remove endian check since ENI always use litter endian
> 
> Changes since V2:
> - add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead
>   VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue
>   size as suggested by Jason Wang
> - present ACCESS_PLATFORM in get_features callback as suggested by Jason
>   Wang
> - disable this driver on Big Endian host as suggested by Jason Wang
> - fix a typo
> 
> Changes since V1:
> - add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether
>   the vdpa device is legacy
> - implement dedicated driver for Alibaba ENI instead a legacy virtio-pci
>   driver as suggested by Jason Wang
> - some bugs fixed
> 
> Wu Zongyong (9):
>   virtio-pci: introduce legacy device module
>   vdpa: fix typo
>   vp_vdpa: add vq irq offloading support
>   vdpa: add new callback get_vq_num_min in vdpa_config_ops
>   vdpa: min vq num of vdpa device cannot be greater than max vq num
>   virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
>   vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
>   eni_vdpa: add vDPA driver for Alibaba ENI
>   eni_vdpa: alibaba: fix Kconfig typo
> 
>  drivers/vdpa/Kconfig   |   8 +
>  drivers/vdpa/Makefile  |   1 +
>  drivers/vdpa/alibaba/Makefile  |   3 +
>  drivers/vdpa/alibaba/eni_vdpa.c| 553 +
>  drivers/vdpa/vdpa.c|  13 +
>  drivers/vdpa/virtio_pci/vp_vdpa.c  |  12 +
>  drivers/virtio/Kconfig |  10 +
>  drivers/virtio/Makefile|   1 +
>  drivers/virtio/virtio_pci_common.c |  10 +-
>  drivers/virtio/virtio_pci_common.h |   9 +-
>  drivers/virtio/virtio_pci_legacy.c | 101 ++---
>  drivers/virtio/virtio_pci_legacy_dev.c | 220 ++
>  drivers/virtio/virtio_vdpa.c   |  16 +-
>  include/linux/vdpa.h   |   6 +-
>  include/linux/virtio_pci_legacy.h  |  42 ++
>  include/uapi/linux/vdpa.h  |   1 +
>  16 files changed, 917 insertions(+), 89 deletions(-)
>  create mode 100644 drivers/vdpa/alibaba/Makefile
>  create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
>  create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
>  create mode 100644 include/linux/virtio_pci_legacy.h
> 
> -- 
> 2.31.1

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


Re: [PATCH v7 9/9] eni_vdpa: alibaba: fix Kconfig typo

2021-11-01 Thread Michael S. Tsirkin
On Fri, Oct 29, 2021 at 05:14:50PM +0800, Wu Zongyong wrote:
> The Kconfig symbol was misspelled, which leads to randconfig link
> failures:
> 
> ld.lld: error: undefined symbol: vp_legacy_probe
> >>> referenced by eni_vdpa.c
> >>>   vdpa/alibaba/eni_vdpa.o:(eni_vdpa_probe) in archive 
> >>> drivers/built-in.a
> 
> Fixes: 6a9f32c00609 ("eni_vdpa: add vDPA driver for Alibaba ENI")
> Signed-off-by: Arnd Bergmann 
> Reviewed-by: Stefano Garzarella 
> Signed-off-by: Wu Zongyong 

This one I'll squash into the previous one. That commit hash is not
going to match anything useful.

> ---
>  drivers/vdpa/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/vdpa/Kconfig b/drivers/vdpa/Kconfig
> index 07b0c73212aa..50f45d037611 100644
> --- a/drivers/vdpa/Kconfig
> +++ b/drivers/vdpa/Kconfig
> @@ -80,7 +80,7 @@ config VP_VDPA
>  
>  config ALIBABA_ENI_VDPA
>   tristate "vDPA driver for Alibaba ENI"
> - select VIRTIO_PCI_LEGACY_LIB
> + select VIRTIO_PCI_LIB_LEGACY
>   depends on PCI_MSI && X86
>   help
> VDPA driver for Alibaba ENI (Elastic Network Interface) which is 
> built upon
> -- 
> 2.31.1

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


Re: [PATCH] i2c: virtio: update the maintainer to Conghui

2021-11-01 Thread Michael S. Tsirkin
On Mon, Nov 01, 2021 at 01:24:50PM +0800, Jie Deng wrote:
> Due to changes in my work, I'm passing the virtio-i2c driver
> maintenance to Conghui.
> 
> Signed-off-by: Jie Deng 

Seeing as Conghui co-developed the driver, seems reasonable.

Acked-by: Michael S. Tsirkin 

> ---
>  MAINTAINERS | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 3b79fd4..8c9a677 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -19944,7 +19944,7 @@ F:include/uapi/linux/virtio_snd.h
>  F:   sound/virtio/*
>  
>  VIRTIO I2C DRIVER
> -M:   Jie Deng 
> +M:   Conghui Chen 
>  M:   Viresh Kumar 
>  L:   linux-...@vger.kernel.org
>  L:   virtualization@lists.linux-foundation.org
> -- 
> 2.7.4

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


Re: [PATCH v7 0/9] vDPA driver for Alibaba ENI

2021-11-01 Thread Jason Wang
On Mon, Nov 1, 2021 at 2:23 PM Wu Zongyong  wrote:
>
> On Mon, Nov 01, 2021 at 11:31:15AM +0800, Jason Wang wrote:
> > On Fri, Oct 29, 2021 at 5:15 PM Wu Zongyong
> >  wrote:
> > >
> > > This series implements the vDPA driver for Alibaba ENI (Elastic Network
> > > Interface) which is built based on virtio-pci 0.9.5 specification.
> >
> > It looks to me Michael has applied the patches, if this is the case,
> > we probably need to send patches on top.
>
> What do you mean by saying "send patches on top"?
> Sorry, I'm a newbie to contribute for kernel, could you please explain
> it in detail?

I meant you probably need to send incremental patch on top of:

git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next.

Thanks


>
> Thanks
> > Thanks
> >
> > >
> > > Changes since V6:
> > > - set default min vq size to 1 intead of 0
> > > - enable eni vdpa driver only on X86 hosts
> > > - fix some typos
> > >
> > > Changes since V5:
> > > - remove unused codes
> > >
> > > Changes since V4:
> > > - check return values of get_vq_num_{max,min} when probing devices
> > > - disable the driver on BE host via Kconfig
> > > - add missing commit message
> > >
> > > Changes since V3:
> > > - validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
> > > - present F_ORDER_PLATFORM in get_features
> > > - remove endian check since ENI always use litter endian
> > >
> > > Changes since V2:
> > > - add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead
> > >   VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue
> > >   size as suggested by Jason Wang
> > > - present ACCESS_PLATFORM in get_features callback as suggested by Jason
> > >   Wang
> > > - disable this driver on Big Endian host as suggested by Jason Wang
> > > - fix a typo
> > >
> > > Changes since V1:
> > > - add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether
> > >   the vdpa device is legacy
> > > - implement dedicated driver for Alibaba ENI instead a legacy virtio-pci
> > >   driver as suggested by Jason Wang
> > > - some bugs fixed
> > >
> > > Wu Zongyong (9):
> > >   virtio-pci: introduce legacy device module
> > >   vdpa: fix typo
> > >   vp_vdpa: add vq irq offloading support
> > >   vdpa: add new callback get_vq_num_min in vdpa_config_ops
> > >   vdpa: min vq num of vdpa device cannot be greater than max vq num
> > >   virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
> > >   vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
> > >   eni_vdpa: add vDPA driver for Alibaba ENI
> > >   eni_vdpa: alibaba: fix Kconfig typo
> > >
> > >  drivers/vdpa/Kconfig   |   8 +
> > >  drivers/vdpa/Makefile  |   1 +
> > >  drivers/vdpa/alibaba/Makefile  |   3 +
> > >  drivers/vdpa/alibaba/eni_vdpa.c| 553 +
> > >  drivers/vdpa/vdpa.c|  13 +
> > >  drivers/vdpa/virtio_pci/vp_vdpa.c  |  12 +
> > >  drivers/virtio/Kconfig |  10 +
> > >  drivers/virtio/Makefile|   1 +
> > >  drivers/virtio/virtio_pci_common.c |  10 +-
> > >  drivers/virtio/virtio_pci_common.h |   9 +-
> > >  drivers/virtio/virtio_pci_legacy.c | 101 ++---
> > >  drivers/virtio/virtio_pci_legacy_dev.c | 220 ++
> > >  drivers/virtio/virtio_vdpa.c   |  16 +-
> > >  include/linux/vdpa.h   |   6 +-
> > >  include/linux/virtio_pci_legacy.h  |  42 ++
> > >  include/uapi/linux/vdpa.h  |   1 +
> > >  16 files changed, 917 insertions(+), 89 deletions(-)
> > >  create mode 100644 drivers/vdpa/alibaba/Makefile
> > >  create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
> > >  create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
> > >  create mode 100644 include/linux/virtio_pci_legacy.h
> > >
> > > --
> > > 2.31.1
> > >
>

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