Message ID | afa2e25ae333dba5867e3d839fba785d5d3508c0.1685623090.git.yin31149@gmail.com |
---|---|
State | New |
Headers | show |
Series | Vhost-vdpa Shadow Virtqueue Offloads support | expand |
On Thu, Jun 1, 2023 at 3:49 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 | 38 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) > > diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c > index e907a3c792..0e647886d1 100644 > --- a/net/vhost-vdpa.c > +++ b/net/vhost-vdpa.c > @@ -678,6 +678,40 @@ 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 offloads; > + ssize_t dev_written; > + > + if (!virtio_vdev_has_feature(&n->parent_obj, > + VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) { > + return 0; > + } > + > + offloads = cpu_to_le64(n->curr_guest_offloads); n->curr_guest_offloads is already stored in CPU order, we should only byte-swap it by the time of sending. Thanks! > + > + if (offloads == virtio_net_supported_guest_offloads(n)) { > + /* > + * According to VirtIO standard, "Upon feature negotiation > + * corresponding offload gets enabled to preserve > + * backward compatibility." > + * So we do not need to send this CVQ command if the guest > + * also enables all supported offloads. > + */ > + return 0; > + } > + > + 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); > @@ -700,6 +734,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 >
On 2023/6/1 22:12, Eugenio Perez Martin wrote: > On Thu, Jun 1, 2023 at 3:49 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 | 38 ++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 38 insertions(+) >> >> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c >> index e907a3c792..0e647886d1 100644 >> --- a/net/vhost-vdpa.c >> +++ b/net/vhost-vdpa.c >> @@ -678,6 +678,40 @@ 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 offloads; >> + ssize_t dev_written; >> + >> + if (!virtio_vdev_has_feature(&n->parent_obj, >> + VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) { >> + return 0; >> + } >> + >> + offloads = cpu_to_le64(n->curr_guest_offloads); > > n->curr_guest_offloads is already stored in CPU order, we should only > byte-swap it by the time of sending. Yes, you are right. I will correct it in the v4 patch. Thanks! > > Thanks! > >> + >> + if (offloads == virtio_net_supported_guest_offloads(n)) { >> + /* >> + * According to VirtIO standard, "Upon feature negotiation >> + * corresponding offload gets enabled to preserve >> + * backward compatibility." >> + * So we do not need to send this CVQ command if the guest >> + * also enables all supported offloads. >> + */ >> + return 0; >> + } >> + >> + 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); >> @@ -700,6 +734,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 >> >
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index e907a3c792..0e647886d1 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -678,6 +678,40 @@ 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 offloads; + ssize_t dev_written; + + if (!virtio_vdev_has_feature(&n->parent_obj, + VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) { + return 0; + } + + offloads = cpu_to_le64(n->curr_guest_offloads); + + if (offloads == virtio_net_supported_guest_offloads(n)) { + /* + * According to VirtIO standard, "Upon feature negotiation + * corresponding offload gets enabled to preserve + * backward compatibility." + * So we do not need to send this CVQ command if the guest + * also enables all supported offloads. + */ + return 0; + } + + 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); @@ -700,6 +734,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; }
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 | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)