RE: [PATCH linux-next v3 6/6] vdpa_sim_net: Add support for user supported devices

2021-01-14 Thread Parav Pandit


> From: Jason Wang 
> Sent: Friday, January 15, 2021 11:09 AM
> 
> 
> On 2021/1/14 下午3:58, Parav Pandit wrote:
> >
> >> From: Jason Wang 
> >> Sent: Thursday, January 14, 2021 9:48 AM
> >>
> >> On 2021/1/7 上午11:48, Parav Pandit wrote:
>  From: Michael S. Tsirkin 
>  Sent: Tuesday, January 5, 2021 6:53 PM
> 
>  On Tue, Jan 05, 2021 at 12:30:15PM +, Parav Pandit wrote:
> >> From: Michael S. Tsirkin 
> >> Sent: Tuesday, January 5, 2021 5:45 PM
> >>
> >> On Tue, Jan 05, 2021 at 12:02:33PM +, Parav Pandit wrote:
>  From: Michael S. Tsirkin 
>  Sent: Tuesday, January 5, 2021 5:19 PM
> 
>  On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote:
> > Enable user to create vdpasim net simulate devices.
> >
> >
> > $ vdpa dev add mgmtdev vdpasim_net name foo2
> >
> > Show the newly created vdpa device by its name:
> > $ vdpa dev show foo2
> > foo2: type network mgmtdev vdpasim_net vendor_id 0
> max_vqs 2
> > max_vq_size 256
> >
> > $ vdpa dev show foo2 -jp
> > {
> >   "dev": {
> >   "foo2": {
> >   "type": "network",
> >   "mgmtdev": "vdpasim_net",
> >   "vendor_id": 0,
> >   "max_vqs": 2,
> >   "max_vq_size": 256
> >   }
> >   }
> > }
>  I'd like an example of how do device specific (e.g. net
>  specific) interfaces tie in to this.
> >>> Not sure I follow your question.
> >>> Do you mean how to set mac address or mtu of this vdpa device of
> >>> type
> >> net?
> >>> If so, dev add command will be extended shortly in subsequent
> >>> series to
> >> set this net specific attributes.
> >>> (I did mention in the next steps in cover letter).
> >>>
> > +static int __init vdpasim_net_init(void) {
> > +   int ret;
> > +
> > +   if (macaddr) {
> > +   mac_pton(macaddr, macaddr_buf);
> > +   if (!is_valid_ether_addr(macaddr_buf))
> > +   return -EADDRNOTAVAIL;
> > +   } else {
> > +   eth_random_addr(macaddr_buf);
> > }
>  Hmm so all devices start out with the same MAC until changed?
>  And how is the change effected?
> >>> Post this patchset and post we have iproute2 vdpa in the tree,
> >>> will add the
> >> mac address as the input attribute during "vdpa dev add" command.
> >>> So that each different vdpa device can have user specified
> >>> (different) mac
> >> address.
> >>
> >> For now maybe just avoid VIRTIO_NET_F_MAC then for new devices
>  then?
> > That would require book keeping existing net vdpa_sim devices
> > created to
>  avoid setting VIRTIO_NET_F_MAC.
> > Such book keeping code will be short lived anyway.
> > Not sure if its worth it.
> > Until now only one device was created. So not sure two vdpa
> > devices with
>  same mac address will be a real issue.
> > When we add mac address attribute in add command, at that point
> > also
>  remove the module parameter macaddr.
> 
>  Will that be mandatory? I'm not to happy with a UAPI we intend to
>  break straight away ...
> >>> No. Specifying mac address shouldn't be mandatory. UAPI wont' be
> >> broken.
> >>
> >>
> >> If it's not mandatory. Does it mean the vDPA parent need to use its
> >> own logic to generate a validate mac? I'm not sure this is what
> >> management (libvirt want).
> >>
> > There are few use cases that I see with PFs, VFs and SFs supporting vdpa
> devices.
> >
> > 1. User wants to use the VF only for vdpa purpose. Here user got the VF
> which was pre-setup by the sysadmin.
> > In this case whatever MAC assigned to the VF can be used by its vdpa
> device.
> > Here, user doesn't need to pass the mac address during vdpa device
> creation time.
> > This is done as the same MAC has been setup in the ACL rules on the switch
> side.
> > Non VDPA users of a VF typically use the VF this way for Netdev and rdma
> functionality.
> > They might continue same way for vdpa application as well.
> > Here VF mac is either set using
> > (a) devlink port function set hw_addr command or using
> > (b) ip link set vf mac
> > So vdpa tool didn't pass the mac. (optional).
> > Though VIRTIO_NET_F_MAC is still valid.
> >
> > 2. User may want to create one or more vdpa device out of the mgmt.
> device.
> > Here user wants to more/full control of all features, overriding what
> sysadmin has setup as MAC of the VF/SF.
> > In this case user will specify the MAC via mgmt tool.
> > (a) This is also used by those vdpa devices which doesn't have eswitch
> offloads.
> > (b) This will work with eswitch offloads as well who does source learning.
> > (c) User chose to 

Re: [PATCH net-next v7] vhost_net: avoid tx queue stuck when sendmsg fails

2021-01-14 Thread Jason Wang


On 2021/1/15 下午12:46, wangyunjian wrote:

From: Yunjian Wang 

Currently the driver doesn't drop a packet which can't be sent by tun
(e.g bad packet). In this case, the driver will always process the
same packet lead to the tx queue stuck.

To fix this issue:
1. in the case of persistent failure (e.g bad packet), the driver
can skip this descriptor by ignoring the error.
2. in the case of transient failure (e.g -ENOBUFS, -EAGAIN and -ENOMEM),
the driver schedules the worker to try again.

Signed-off-by: Yunjian Wang 



Acked-by: Jason Wang 



---
v7:
* code rebase
v6:
* update code styles and commit log
---
  drivers/vhost/net.c | 26 ++
  1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 3b744031ec8f..df82b124170e 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -828,14 +828,15 @@ static void handle_tx_copy(struct vhost_net *net, struct 
socket *sock)
msg.msg_flags &= ~MSG_MORE;
}
  
-		/* TODO: Check specific error and bomb out unless ENOBUFS? */

err = sock->ops->sendmsg(sock, , len);
if (unlikely(err < 0)) {
-   vhost_discard_vq_desc(vq, 1);
-   vhost_net_enable_vq(net, vq);
-   break;
-   }
-   if (err != len)
+   if (err == -EAGAIN || err == -ENOMEM || err == 
-ENOBUFS) {
+   vhost_discard_vq_desc(vq, 1);
+   vhost_net_enable_vq(net, vq);
+   break;
+   }
+   pr_debug("Fail to send packet: err %d", err);
+   } else if (unlikely(err != len))
pr_debug("Truncated TX packet: len %d != %zd\n",
 err, len);
  done:
@@ -924,7 +925,6 @@ static void handle_tx_zerocopy(struct vhost_net *net, 
struct socket *sock)
msg.msg_flags &= ~MSG_MORE;
}
  
-		/* TODO: Check specific error and bomb out unless ENOBUFS? */

err = sock->ops->sendmsg(sock, , len);
if (unlikely(err < 0)) {
if (zcopy_used) {
@@ -933,11 +933,13 @@ static void handle_tx_zerocopy(struct vhost_net *net, 
struct socket *sock)
nvq->upend_idx = ((unsigned)nvq->upend_idx - 1)
% UIO_MAXIOV;
}
-   vhost_discard_vq_desc(vq, 1);
-   vhost_net_enable_vq(net, vq);
-   break;
-   }
-   if (err != len)
+   if (err == -EAGAIN || err == -ENOMEM || err == 
-ENOBUFS) {
+   vhost_discard_vq_desc(vq, 1);
+   vhost_net_enable_vq(net, vq);
+   break;
+   }
+   pr_debug("Fail to send packet: err %d", err);
+   } else if (unlikely(err != len))
pr_debug("Truncated TX packet: "
 " len %d != %zd\n", err, len);
if (!zcopy_used)


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

Re: [PATCH linux-next v3 6/6] vdpa_sim_net: Add support for user supported devices

2021-01-14 Thread Jason Wang


On 2021/1/14 下午3:58, Parav Pandit wrote:



From: Jason Wang 
Sent: Thursday, January 14, 2021 9:48 AM

On 2021/1/7 上午11:48, Parav Pandit wrote:

From: Michael S. Tsirkin 
Sent: Tuesday, January 5, 2021 6:53 PM

On Tue, Jan 05, 2021 at 12:30:15PM +, Parav Pandit wrote:

From: Michael S. Tsirkin 
Sent: Tuesday, January 5, 2021 5:45 PM

On Tue, Jan 05, 2021 at 12:02:33PM +, Parav Pandit wrote:

From: Michael S. Tsirkin 
Sent: Tuesday, January 5, 2021 5:19 PM

On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote:

Enable user to create vdpasim net simulate devices.


$ vdpa dev add mgmtdev vdpasim_net name foo2

Show the newly created vdpa device by its name:
$ vdpa dev show foo2
foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2
max_vq_size 256

$ vdpa dev show foo2 -jp
{
  "dev": {
  "foo2": {
  "type": "network",
  "mgmtdev": "vdpasim_net",
  "vendor_id": 0,
  "max_vqs": 2,
  "max_vq_size": 256
  }
  }
}

I'd like an example of how do device specific (e.g. net
specific) interfaces tie in to this.

Not sure I follow your question.
Do you mean how to set mac address or mtu of this vdpa device of
type

net?

If so, dev add command will be extended shortly in subsequent
series to

set this net specific attributes.

(I did mention in the next steps in cover letter).


+static int __init vdpasim_net_init(void) {
+   int ret;
+
+   if (macaddr) {
+   mac_pton(macaddr, macaddr_buf);
+   if (!is_valid_ether_addr(macaddr_buf))
+   return -EADDRNOTAVAIL;
+   } else {
+   eth_random_addr(macaddr_buf);
}

Hmm so all devices start out with the same MAC until changed?
And how is the change effected?

Post this patchset and post we have iproute2 vdpa in the tree,
will add the

mac address as the input attribute during "vdpa dev add" command.

So that each different vdpa device can have user specified
(different) mac

address.

For now maybe just avoid VIRTIO_NET_F_MAC then for new devices

then?

That would require book keeping existing net vdpa_sim devices
created to

avoid setting VIRTIO_NET_F_MAC.

Such book keeping code will be short lived anyway.
Not sure if its worth it.
Until now only one device was created. So not sure two vdpa devices
with

same mac address will be a real issue.

When we add mac address attribute in add command, at that point also

remove the module parameter macaddr.

Will that be mandatory? I'm not to happy with a UAPI we intend to
break straight away ...

No. Specifying mac address shouldn't be mandatory. UAPI wont' be

broken.


If it's not mandatory. Does it mean the vDPA parent need to use its own logic
to generate a validate mac? I'm not sure this is what management (libvirt
want).


There are few use cases that I see with PFs, VFs and SFs supporting vdpa 
devices.

1. User wants to use the VF only for vdpa purpose. Here user got the VF which 
was pre-setup by the sysadmin.
In this case whatever MAC assigned to the VF can be used by its vdpa device.
Here, user doesn't need to pass the mac address during vdpa device creation 
time.
This is done as the same MAC has been setup in the ACL rules on the switch side.
Non VDPA users of a VF typically use the VF this way for Netdev and rdma 
functionality.
They might continue same way for vdpa application as well.
Here VF mac is either set using
(a) devlink port function set hw_addr command or using
(b) ip link set vf mac
So vdpa tool didn't pass the mac. (optional).
Though VIRTIO_NET_F_MAC is still valid.

2. User may want to create one or more vdpa device out of the mgmt. device.
Here user wants to more/full control of all features, overriding what sysadmin 
has setup as MAC of the VF/SF.
In this case user will specify the MAC via mgmt tool.
(a) This is also used by those vdpa devices which doesn't have eswitch offloads.
(b) This will work with eswitch offloads as well who does source learning.
(c) User chose to use the vdpa device of a VF while VF Netdev and rdma device 
are used by hypervisor for something else as well.
VIRTIO_NET_F_MAC remains valid in all 2.{a,b,c}.

3. A  vendor mgmt. device always expects it user to provide mac for its vdpa 
devices.
So when it is not provided, it can fail with error message string in extack or 
clear the VIRTIO_NET_F_MAC and let it work using virtio spec's 5.1.5 point 5 to 
proceed.

As common denominator of all above cases, if QEMU or user pass the MAC during 
creation, it will almost always work.
Advance user and QEMU with switchdev mode support who has done 1.a/1.b, will 
omit it.
I do not know how deep integration of QEMU exist with the switchdev mode 
support.

With that mac, mtu as optional input fields provide the necessary flexibility 
for different stacks to take appropriate shape as they desire.



Thanks for the clarification. I think we'd better document the above in 
the patch that introduces the mac setting 

[PATCH RESEND v3] virtio-input: add multi-touch support

2021-01-14 Thread Vasyl Vavrychuk
From: Mathias Crombez 

Without multi-touch slots allocated, ABS_MT_SLOT events will be lost by
input_handle_abs_event.

Implementation is based on uinput_create_device.

Signed-off-by: Mathias Crombez 
Co-developed-by: Vasyl Vavrychuk 
Signed-off-by: Vasyl Vavrychuk 
---
v2: fix patch corrupted by corporate email server
v3: use number of slots from the host

Resend since to feedback.

 drivers/virtio/virtio_input.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
index f1f6208edcf5..f643536807dd 100644
--- a/drivers/virtio/virtio_input.c
+++ b/drivers/virtio/virtio_input.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 
 struct virtio_input {
struct virtio_device   *vdev;
@@ -204,7 +205,7 @@ static int virtinput_probe(struct virtio_device *vdev)
struct virtio_input *vi;
unsigned long flags;
size_t size;
-   int abs, err;
+   int abs, err, nslots;
 
if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1))
return -ENODEV;
@@ -289,6 +290,13 @@ static int virtinput_probe(struct virtio_device *vdev)
continue;
virtinput_cfg_abs(vi, abs);
}
+
+   if (test_bit(ABS_MT_SLOT, vi->idev->absbit)) {
+   nslots = input_abs_get_max(vi->idev, ABS_MT_SLOT) + 1;
+   err = input_mt_init_slots(vi->idev, nslots, 0);
+   if (err)
+   goto err_mt_init_slots;
+   }
}
 
virtio_device_ready(vdev);
@@ -304,6 +312,7 @@ static int virtinput_probe(struct virtio_device *vdev)
spin_lock_irqsave(>lock, flags);
vi->ready = false;
spin_unlock_irqrestore(>lock, flags);
+err_mt_init_slots:
input_free_device(vi->idev);
 err_input_alloc:
vdev->config->del_vqs(vdev);
-- 
2.20.1


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