On 2023/5/31 14:37, Eugenio Perez Martin wrote: > On Wed, May 31, 2023 at 3:47 AM Jason Wang <jasow...@redhat.com> wrote: >> >> On Mon, May 29, 2023 at 9: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; >> >> 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 >>> >> >