On Mon, May 29, 2023 at 3:18 PM Hawkins Jiawei <yin31...@gmail.com> wrote: > > This patch introduces vhost_vdpa_net_load_offloads() to > restore offloads state at device's startup. > > Signed-off-by: Hawkins Jiawei <yin31...@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 >