* [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support
@ 2023-05-29 13:18 Hawkins Jiawei
2023-05-29 13:18 ` [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads Hawkins Jiawei
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Hawkins Jiawei @ 2023-05-29 13:18 UTC (permalink / raw)
To: eperezma; +Cc: yin31149, 18801353760, qemu-devel
This series enables shadowed CVQ to intercept Offloads commands
through shadowed CVQ, update the virtio NIC device model so qemu
send it in a migration, and the restore of that Offloads state
in the destination.
Hawkins Jiawei (2):
vdpa: Add vhost_vdpa_net_load_offloads
vdpa: Allow VIRTIO_NET_F_CTRL_GUEST_OFFLOADS in SVQ
net/vhost-vdpa.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
--
2.25.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads
2023-05-29 13:18 [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support Hawkins Jiawei
@ 2023-05-29 13:18 ` Hawkins Jiawei
2023-05-29 16:19 ` Eugenio Perez Martin
2023-05-31 1:47 ` Jason Wang
2023-05-29 13:18 ` [PATCH 2/2] vdpa: Allow VIRTIO_NET_F_CTRL_GUEST_OFFLOADS in SVQ Hawkins Jiawei
2023-05-29 16:55 ` [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support Eugenio Perez Martin
2 siblings, 2 replies; 12+ messages in thread
From: Hawkins Jiawei @ 2023-05-29 13:18 UTC (permalink / raw)
To: eperezma, Jason Wang; +Cc: yin31149, 18801353760, qemu-devel
This patch introduces vhost_vdpa_net_load_offloads() to
restore offloads state at device's startup.
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
---
net/vhost-vdpa.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 37cdc84562..682c749b19 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -680,6 +680,28 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
return *s->status != VIRTIO_NET_OK;
}
+static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
+ const VirtIONet *n)
+{
+ uint64_t features, offloads;
+ ssize_t dev_written;
+
+ features = n->parent_obj.guest_features;
+ if (!(features & BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))) {
+ return 0;
+ }
+
+ offloads = cpu_to_le64(n->curr_guest_offloads);
+ dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
+ VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
+ &offloads, sizeof(offloads));
+ if (unlikely(dev_written < 0)) {
+ return dev_written;
+ }
+
+ return *s->status != VIRTIO_NET_OK;
+}
+
static int vhost_vdpa_net_load(NetClientState *nc)
{
VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
@@ -702,6 +724,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)
if (unlikely(r)) {
return r;
}
+ r = vhost_vdpa_net_load_offloads(s, n);
+ if (unlikely(r)) {
+ return r;
+ }
return 0;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/2] vdpa: Allow VIRTIO_NET_F_CTRL_GUEST_OFFLOADS in SVQ
2023-05-29 13:18 [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support Hawkins Jiawei
2023-05-29 13:18 ` [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads Hawkins Jiawei
@ 2023-05-29 13:18 ` Hawkins Jiawei
2023-05-31 1:47 ` Jason Wang
2023-05-29 16:55 ` [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support Eugenio Perez Martin
2 siblings, 1 reply; 12+ messages in thread
From: Hawkins Jiawei @ 2023-05-29 13:18 UTC (permalink / raw)
To: eperezma, Jason Wang; +Cc: yin31149, 18801353760, qemu-devel
Enable SVQ with VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature.
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
---
net/vhost-vdpa.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 682c749b19..cc52b7f0ad 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -85,6 +85,7 @@ const int vdpa_feature_bits[] = {
static const uint64_t vdpa_svq_device_features =
BIT_ULL(VIRTIO_NET_F_CSUM) |
BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) |
+ BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) |
BIT_ULL(VIRTIO_NET_F_MTU) |
BIT_ULL(VIRTIO_NET_F_MAC) |
BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) |
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads
2023-05-29 13:18 ` [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads Hawkins Jiawei
@ 2023-05-29 16:19 ` Eugenio Perez Martin
2023-05-31 8:23 ` Hawkins Jiawei
2023-05-31 1:47 ` Jason Wang
1 sibling, 1 reply; 12+ messages in thread
From: Eugenio Perez Martin @ 2023-05-29 16:19 UTC (permalink / raw)
To: Hawkins Jiawei; +Cc: Jason Wang, 18801353760, qemu-devel
On Mon, May 29, 2023 at 3:18 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
>
> This patch introduces vhost_vdpa_net_load_offloads() to
> restore offloads state at device's startup.
>
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
> ---
> net/vhost-vdpa.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 37cdc84562..682c749b19 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -680,6 +680,28 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
> return *s->status != VIRTIO_NET_OK;
> }
>
> +static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
> + const VirtIONet *n)
> +{
> + uint64_t features, offloads;
> + ssize_t dev_written;
> +
> + features = n->parent_obj.guest_features;
> + if (!(features & BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))) {
> + return 0;
> + }
> +
Maybe we can avoid sending this CVQ command if the guest already uses
the default values?
By default all features are enabled if I'm not wrong. I think the best
way is to expose virtio_net_supported_guest_offloads or
virtio_net_guest_offloads_by_features and then check if
n->curr_guest_offloads is the same.
We should do the same with vhost_vdpa_net_load_mq, but that is out of
the scope of this series.
Thanks!
> + offloads = cpu_to_le64(n->curr_guest_offloads);
> + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
> + VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
> + &offloads, sizeof(offloads));
> + if (unlikely(dev_written < 0)) {
> + return dev_written;
> + }
> +
> + return *s->status != VIRTIO_NET_OK;
> +}
> +
> static int vhost_vdpa_net_load(NetClientState *nc)
> {
> VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
> @@ -702,6 +724,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)
> if (unlikely(r)) {
> return r;
> }
> + r = vhost_vdpa_net_load_offloads(s, n);
> + if (unlikely(r)) {
> + return r;
> + }
>
> return 0;
> }
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support
2023-05-29 13:18 [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support Hawkins Jiawei
2023-05-29 13:18 ` [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads Hawkins Jiawei
2023-05-29 13:18 ` [PATCH 2/2] vdpa: Allow VIRTIO_NET_F_CTRL_GUEST_OFFLOADS in SVQ Hawkins Jiawei
@ 2023-05-29 16:55 ` Eugenio Perez Martin
2023-05-30 7:20 ` Hawkins Jiawei
2 siblings, 1 reply; 12+ messages in thread
From: Eugenio Perez Martin @ 2023-05-29 16:55 UTC (permalink / raw)
To: Hawkins Jiawei; +Cc: 18801353760, qemu-devel, Michael Tsirkin, Jason Wang
On Mon, May 29, 2023 at 3:18 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
>
> This series enables shadowed CVQ to intercept Offloads commands
> through shadowed CVQ, update the virtio NIC device model so qemu
> send it in a migration, and the restore of that Offloads state
> in the destination.
>
> Hawkins Jiawei (2):
> vdpa: Add vhost_vdpa_net_load_offloads
> vdpa: Allow VIRTIO_NET_F_CTRL_GUEST_OFFLOADS in SVQ
>
> net/vhost-vdpa.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
CCing MST too.
Thanks!
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support
2023-05-29 16:55 ` [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support Eugenio Perez Martin
@ 2023-05-30 7:20 ` Hawkins Jiawei
0 siblings, 0 replies; 12+ messages in thread
From: Hawkins Jiawei @ 2023-05-30 7:20 UTC (permalink / raw)
To: Eugenio Perez Martin; +Cc: 18801353760, qemu-devel, Michael Tsirkin, Jason Wang
On 2023/5/30 0:55, Eugenio Perez Martin wrote:
> On Mon, May 29, 2023 at 3:18 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
>>
>> This series enables shadowed CVQ to intercept Offloads commands
>> through shadowed CVQ, update the virtio NIC device model so qemu
>> send it in a migration, and the restore of that Offloads state
>> in the destination.
>>
>> Hawkins Jiawei (2):
>> vdpa: Add vhost_vdpa_net_load_offloads
>> vdpa: Allow VIRTIO_NET_F_CTRL_GUEST_OFFLOADS in SVQ
>>
>> net/vhost-vdpa.c | 27 +++++++++++++++++++++++++++
>> 1 file changed, 27 insertions(+)
>>
>
> CCing MST too.
OK, I will cc MST in the future patches for this part.
Thanks!
>
> Thanks!
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads
2023-05-29 13:18 ` [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads Hawkins Jiawei
2023-05-29 16:19 ` Eugenio Perez Martin
@ 2023-05-31 1:47 ` Jason Wang
2023-05-31 6:37 ` Eugenio Perez Martin
1 sibling, 1 reply; 12+ messages in thread
From: Jason Wang @ 2023-05-31 1:47 UTC (permalink / raw)
To: Hawkins Jiawei; +Cc: eperezma, 18801353760, qemu-devel
On Mon, May 29, 2023 at 9:18 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
>
> This patch introduces vhost_vdpa_net_load_offloads() to
> restore offloads state at device's startup.
>
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
> ---
> net/vhost-vdpa.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 37cdc84562..682c749b19 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -680,6 +680,28 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
> return *s->status != VIRTIO_NET_OK;
> }
>
> +static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
> + const VirtIONet *n)
> +{
> + uint64_t features, offloads;
> + ssize_t dev_written;
> +
> + features = n->parent_obj.guest_features;
Any reason you need to do tricks like this instead of using
virtio_xxx_has_features()?
> + if (!(features & BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))) {
> + return 0;
> + }
> +
> + offloads = cpu_to_le64(n->curr_guest_offloads);
> + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
> + VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
> + &offloads, sizeof(offloads));
> + if (unlikely(dev_written < 0)) {
> + return dev_written;
> + }
> +
> + return *s->status != VIRTIO_NET_OK;
> +}
> +
> static int vhost_vdpa_net_load(NetClientState *nc)
> {
> VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
> @@ -702,6 +724,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)
> if (unlikely(r)) {
> return r;
> }
> + r = vhost_vdpa_net_load_offloads(s, n);
> + if (unlikely(r)) {
> + return r;
> + }
>
> return 0;
> }
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] vdpa: Allow VIRTIO_NET_F_CTRL_GUEST_OFFLOADS in SVQ
2023-05-29 13:18 ` [PATCH 2/2] vdpa: Allow VIRTIO_NET_F_CTRL_GUEST_OFFLOADS in SVQ Hawkins Jiawei
@ 2023-05-31 1:47 ` Jason Wang
0 siblings, 0 replies; 12+ messages in thread
From: Jason Wang @ 2023-05-31 1:47 UTC (permalink / raw)
To: Hawkins Jiawei; +Cc: eperezma, 18801353760, qemu-devel
On Mon, May 29, 2023 at 9:18 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
>
> Enable SVQ with VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature.
>
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
> ---
> net/vhost-vdpa.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 682c749b19..cc52b7f0ad 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -85,6 +85,7 @@ const int vdpa_feature_bits[] = {
> static const uint64_t vdpa_svq_device_features =
> BIT_ULL(VIRTIO_NET_F_CSUM) |
> BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) |
> + BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) |
> BIT_ULL(VIRTIO_NET_F_MTU) |
> BIT_ULL(VIRTIO_NET_F_MAC) |
> BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) |
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads
2023-05-31 1:47 ` Jason Wang
@ 2023-05-31 6:37 ` Eugenio Perez Martin
2023-05-31 8:27 ` Hawkins Jiawei
0 siblings, 1 reply; 12+ messages in thread
From: Eugenio Perez Martin @ 2023-05-31 6:37 UTC (permalink / raw)
To: Jason Wang; +Cc: Hawkins Jiawei, 18801353760, qemu-devel
On Wed, May 31, 2023 at 3:47 AM Jason Wang <jasowang@redhat.com> wrote:
>
> On Mon, May 29, 2023 at 9:18 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
> >
> > This patch introduces vhost_vdpa_net_load_offloads() to
> > restore offloads state at device's startup.
> >
> > Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
> > ---
> > net/vhost-vdpa.c | 26 ++++++++++++++++++++++++++
> > 1 file changed, 26 insertions(+)
> >
> > diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> > index 37cdc84562..682c749b19 100644
> > --- a/net/vhost-vdpa.c
> > +++ b/net/vhost-vdpa.c
> > @@ -680,6 +680,28 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
> > return *s->status != VIRTIO_NET_OK;
> > }
> >
> > +static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
> > + const VirtIONet *n)
> > +{
> > + uint64_t features, offloads;
> > + ssize_t dev_written;
> > +
> > + features = n->parent_obj.guest_features;
>
> Any reason you need to do tricks like this instead of using
> virtio_xxx_has_features()?
>
It can be replaced by virtio_vdev_has_feature, yes.
Current code of vhost_vdpa_net_load_mac and vhost_vdpa_net_load_mq
access to guest_features directly too, so I think we should change all
of them at once.
Thanks!
> > + if (!(features & BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))) {
> > + return 0;
> > + }
> > +
> > + offloads = cpu_to_le64(n->curr_guest_offloads);
> > + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
> > + VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
> > + &offloads, sizeof(offloads));
> > + if (unlikely(dev_written < 0)) {
> > + return dev_written;
> > + }
> > +
> > + return *s->status != VIRTIO_NET_OK;
> > +}
> > +
> > static int vhost_vdpa_net_load(NetClientState *nc)
> > {
> > VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
> > @@ -702,6 +724,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)
> > if (unlikely(r)) {
> > return r;
> > }
> > + r = vhost_vdpa_net_load_offloads(s, n);
> > + if (unlikely(r)) {
> > + return r;
> > + }
> >
> > return 0;
> > }
> > --
> > 2.25.1
> >
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads
2023-05-29 16:19 ` Eugenio Perez Martin
@ 2023-05-31 8:23 ` Hawkins Jiawei
2023-05-31 8:35 ` Eugenio Perez Martin
0 siblings, 1 reply; 12+ messages in thread
From: Hawkins Jiawei @ 2023-05-31 8:23 UTC (permalink / raw)
To: Eugenio Perez Martin; +Cc: Jason Wang, 18801353760, qemu-devel
On 2023/5/30 0:19, Eugenio Perez Martin wrote:
> On Mon, May 29, 2023 at 3:18 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
>>
>> This patch introduces vhost_vdpa_net_load_offloads() to
>> restore offloads state at device's startup.
>>
>> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
>> ---
>> net/vhost-vdpa.c | 26 ++++++++++++++++++++++++++
>> 1 file changed, 26 insertions(+)
>>
>> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
>> index 37cdc84562..682c749b19 100644
>> --- a/net/vhost-vdpa.c
>> +++ b/net/vhost-vdpa.c
>> @@ -680,6 +680,28 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
>> return *s->status != VIRTIO_NET_OK;
>> }
>>
>> +static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
>> + const VirtIONet *n)
>> +{
>> + uint64_t features, offloads;
>> + ssize_t dev_written;
>> +
>> + features = n->parent_obj.guest_features;
>> + if (!(features & BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))) {
>> + return 0;
>> + }
>> +
>
> Maybe we can avoid sending this CVQ command if the guest already uses
> the default values?
Hi Eugenio,
Thanks for the review. However, I'm curious why we don't need to send
this CVQ command if the guest is using the default values. Is it because
the device automatically applies these default offloads, when the
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature is negotiated and QEMU doesn't
send the CVQ command?
Thanks!
>
> By default all features are enabled if I'm not wrong. I think the best
> way is to expose virtio_net_supported_guest_offloads or
> virtio_net_guest_offloads_by_features and then check if
> n->curr_guest_offloads is the same.
>
> We should do the same with vhost_vdpa_net_load_mq, but that is out of
> the scope of this series.
>
> Thanks!
>
>> + offloads = cpu_to_le64(n->curr_guest_offloads);
>> + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
>> + VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
>> + &offloads, sizeof(offloads));
>> + if (unlikely(dev_written < 0)) {
>> + return dev_written;
>> + }
>> +
>> + return *s->status != VIRTIO_NET_OK;
>> +}
>> +
>> static int vhost_vdpa_net_load(NetClientState *nc)
>> {
>> VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
>> @@ -702,6 +724,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)
>> if (unlikely(r)) {
>> return r;
>> }
>> + r = vhost_vdpa_net_load_offloads(s, n);
>> + if (unlikely(r)) {
>> + return r;
>> + }
>>
>> return 0;
>> }
>> --
>> 2.25.1
>>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads
2023-05-31 6:37 ` Eugenio Perez Martin
@ 2023-05-31 8:27 ` Hawkins Jiawei
0 siblings, 0 replies; 12+ messages in thread
From: Hawkins Jiawei @ 2023-05-31 8:27 UTC (permalink / raw)
To: Eugenio Perez Martin, Jason Wang; +Cc: 18801353760, qemu-devel
On 2023/5/31 14:37, Eugenio Perez Martin wrote:
> On Wed, May 31, 2023 at 3:47 AM Jason Wang <jasowang@redhat.com> wrote:
>>
>> On Mon, May 29, 2023 at 9:18 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
>>>
>>> This patch introduces vhost_vdpa_net_load_offloads() to
>>> restore offloads state at device's startup.
>>>
>>> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
>>> ---
>>> net/vhost-vdpa.c | 26 ++++++++++++++++++++++++++
>>> 1 file changed, 26 insertions(+)
>>>
>>> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
>>> index 37cdc84562..682c749b19 100644
>>> --- a/net/vhost-vdpa.c
>>> +++ b/net/vhost-vdpa.c
>>> @@ -680,6 +680,28 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
>>> return *s->status != VIRTIO_NET_OK;
>>> }
>>>
>>> +static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
>>> + const VirtIONet *n)
>>> +{
>>> + uint64_t features, offloads;
>>> + ssize_t dev_written;
>>> +
>>> + features = n->parent_obj.guest_features;
>>
>> Any reason you need to do tricks like this instead of using
>> virtio_xxx_has_features()?
>>
>
> It can be replaced by virtio_vdev_has_feature, yes.
>
> Current code of vhost_vdpa_net_load_mac and vhost_vdpa_net_load_mq
> access to guest_features directly too, so I think we should change all
> of them at once.
Yes, I agree with you and Jason.
I will refactor the patch as you and Jason have suggested.
Thanks!
>
> Thanks!
>
>>> + if (!(features & BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))) {
>>> + return 0;
>>> + }
>>> +
>>> + offloads = cpu_to_le64(n->curr_guest_offloads);
>>> + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
>>> + VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
>>> + &offloads, sizeof(offloads));
>>> + if (unlikely(dev_written < 0)) {
>>> + return dev_written;
>>> + }
>>> +
>>> + return *s->status != VIRTIO_NET_OK;
>>> +}
>>> +
>>> static int vhost_vdpa_net_load(NetClientState *nc)
>>> {
>>> VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
>>> @@ -702,6 +724,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)
>>> if (unlikely(r)) {
>>> return r;
>>> }
>>> + r = vhost_vdpa_net_load_offloads(s, n);
>>> + if (unlikely(r)) {
>>> + return r;
>>> + }
>>>
>>> return 0;
>>> }
>>> --
>>> 2.25.1
>>>
>>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads
2023-05-31 8:23 ` Hawkins Jiawei
@ 2023-05-31 8:35 ` Eugenio Perez Martin
0 siblings, 0 replies; 12+ messages in thread
From: Eugenio Perez Martin @ 2023-05-31 8:35 UTC (permalink / raw)
To: Hawkins Jiawei; +Cc: Jason Wang, 18801353760, qemu-devel
On Wed, May 31, 2023 at 10:23 AM Hawkins Jiawei <yin31149@gmail.com> wrote:
>
> On 2023/5/30 0:19, Eugenio Perez Martin wrote:
> > On Mon, May 29, 2023 at 3:18 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
> >>
> >> This patch introduces vhost_vdpa_net_load_offloads() to
> >> restore offloads state at device's startup.
> >>
> >> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
> >> ---
> >> net/vhost-vdpa.c | 26 ++++++++++++++++++++++++++
> >> 1 file changed, 26 insertions(+)
> >>
> >> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> >> index 37cdc84562..682c749b19 100644
> >> --- a/net/vhost-vdpa.c
> >> +++ b/net/vhost-vdpa.c
> >> @@ -680,6 +680,28 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
> >> return *s->status != VIRTIO_NET_OK;
> >> }
> >>
> >> +static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
> >> + const VirtIONet *n)
> >> +{
> >> + uint64_t features, offloads;
> >> + ssize_t dev_written;
> >> +
> >> + features = n->parent_obj.guest_features;
> >> + if (!(features & BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))) {
> >> + return 0;
> >> + }
> >> +
> >
> > Maybe we can avoid sending this CVQ command if the guest already uses
> > the default values?
>
> Hi Eugenio,
>
> Thanks for the review. However, I'm curious why we don't need to send
> this CVQ command if the guest is using the default values. Is it because
> the device automatically applies these default offloads, when the
> VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature is negotiated and QEMU doesn't
> send the CVQ command?
>
Exactly. You can check that either by the standard text or (sometimes
easier) qemu virtio or virtio-net device code.
The standard text says that:
"Upon feature negotiation corresponding offload gets enabled to
preserve backward compatibility."
And you can check in the qemu code by
hw/net/virtio-net:virtio_net_set_features(vdev, features), this chunk
of code:
n->curr_guest_offloads = virtio_net_guest_offloads_by_features(features);
virtio_net_apply_guest_offloads(n);
Thanks!
> Thanks!
>
>
> >
> > By default all features are enabled if I'm not wrong. I think the best
> > way is to expose virtio_net_supported_guest_offloads or
> > virtio_net_guest_offloads_by_features and then check if
> > n->curr_guest_offloads is the same.
> >
> > We should do the same with vhost_vdpa_net_load_mq, but that is out of
> > the scope of this series.
> >
> > Thanks!
> >
> >> + offloads = cpu_to_le64(n->curr_guest_offloads);
> >> + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
> >> + VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
> >> + &offloads, sizeof(offloads));
> >> + if (unlikely(dev_written < 0)) {
> >> + return dev_written;
> >> + }
> >> +
> >> + return *s->status != VIRTIO_NET_OK;
> >> +}
> >> +
> >> static int vhost_vdpa_net_load(NetClientState *nc)
> >> {
> >> VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
> >> @@ -702,6 +724,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)
> >> if (unlikely(r)) {
> >> return r;
> >> }
> >> + r = vhost_vdpa_net_load_offloads(s, n);
> >> + if (unlikely(r)) {
> >> + return r;
> >> + }
> >>
> >> return 0;
> >> }
> >> --
> >> 2.25.1
> >>
> >
>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2023-05-31 8:36 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-29 13:18 [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support Hawkins Jiawei
2023-05-29 13:18 ` [PATCH 1/2] vdpa: Add vhost_vdpa_net_load_offloads Hawkins Jiawei
2023-05-29 16:19 ` Eugenio Perez Martin
2023-05-31 8:23 ` Hawkins Jiawei
2023-05-31 8:35 ` Eugenio Perez Martin
2023-05-31 1:47 ` Jason Wang
2023-05-31 6:37 ` Eugenio Perez Martin
2023-05-31 8:27 ` Hawkins Jiawei
2023-05-29 13:18 ` [PATCH 2/2] vdpa: Allow VIRTIO_NET_F_CTRL_GUEST_OFFLOADS in SVQ Hawkins Jiawei
2023-05-31 1:47 ` Jason Wang
2023-05-29 16:55 ` [PATCH 0/2] Vhost-vdpa Shadow Virtqueue Offloads support Eugenio Perez Martin
2023-05-30 7:20 ` Hawkins Jiawei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).