diff mbox series

[v3,6/7] vhost_net: Add NetClientInfo prepare callback

Message ID 20220803171821.481336-7-eperezma@redhat.com
State New
Headers show
Series ASID support in vhost-vdpa net | expand

Commit Message

Eugenio Perez Martin Aug. 3, 2022, 5:18 p.m. UTC
This is used by the backend to perform actions before the device is
started.

In particular, vdpa will use it to isolate CVQ in its own ASID if
possible, and start SVQ unconditionally only in CVQ.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 include/net/net.h  | 2 ++
 hw/net/vhost_net.c | 4 ++++
 2 files changed, 6 insertions(+)

Comments

Jason Wang Aug. 4, 2022, 4:45 a.m. UTC | #1
在 2022/8/4 01:18, Eugenio Pérez 写道:
> This is used by the backend to perform actions before the device is
> started.
>
> In particular, vdpa will use it to isolate CVQ in its own ASID if
> possible, and start SVQ unconditionally only in CVQ.
>
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
>   include/net/net.h  | 2 ++
>   hw/net/vhost_net.c | 4 ++++
>   2 files changed, 6 insertions(+)
>
> diff --git a/include/net/net.h b/include/net/net.h
> index a8d47309cd..efa6448886 100644
> --- a/include/net/net.h
> +++ b/include/net/net.h
> @@ -44,6 +44,7 @@ typedef struct NICConf {
>   
>   typedef void (NetPoll)(NetClientState *, bool enable);
>   typedef bool (NetCanReceive)(NetClientState *);
> +typedef void (NetPrepare)(NetClientState *);
>   typedef int (NetLoad)(NetClientState *);
>   typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t);
>   typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);
> @@ -72,6 +73,7 @@ typedef struct NetClientInfo {
>       NetReceive *receive_raw;
>       NetReceiveIOV *receive_iov;
>       NetCanReceive *can_receive;
> +    NetPrepare *prepare;
>       NetLoad *load;
>       NetCleanup *cleanup;
>       LinkStatusChanged *link_status_changed;
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index a9bf72dcda..bbbb6d759b 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -244,6 +244,10 @@ static int vhost_net_start_one(struct vhost_net *net,
>       struct vhost_vring_file file = { };
>       int r;
>   
> +    if (net->nc->info->prepare) {
> +        net->nc->info->prepare(net->nc);
> +    }


Any chance we can reuse load()?

Thanks


> +
>       r = vhost_dev_enable_notifiers(&net->dev, dev);
>       if (r < 0) {
>           goto fail_notifiers;
Eugenio Perez Martin Aug. 4, 2022, 7:51 a.m. UTC | #2
On Thu, Aug 4, 2022 at 6:46 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> 在 2022/8/4 01:18, Eugenio Pérez 写道:
> > This is used by the backend to perform actions before the device is
> > started.
> >
> > In particular, vdpa will use it to isolate CVQ in its own ASID if
> > possible, and start SVQ unconditionally only in CVQ.
> >
> > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > ---
> >   include/net/net.h  | 2 ++
> >   hw/net/vhost_net.c | 4 ++++
> >   2 files changed, 6 insertions(+)
> >
> > diff --git a/include/net/net.h b/include/net/net.h
> > index a8d47309cd..efa6448886 100644
> > --- a/include/net/net.h
> > +++ b/include/net/net.h
> > @@ -44,6 +44,7 @@ typedef struct NICConf {
> >
> >   typedef void (NetPoll)(NetClientState *, bool enable);
> >   typedef bool (NetCanReceive)(NetClientState *);
> > +typedef void (NetPrepare)(NetClientState *);
> >   typedef int (NetLoad)(NetClientState *);
> >   typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t);
> >   typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);
> > @@ -72,6 +73,7 @@ typedef struct NetClientInfo {
> >       NetReceive *receive_raw;
> >       NetReceiveIOV *receive_iov;
> >       NetCanReceive *can_receive;
> > +    NetPrepare *prepare;
> >       NetLoad *load;
> >       NetCleanup *cleanup;
> >       LinkStatusChanged *link_status_changed;
> > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> > index a9bf72dcda..bbbb6d759b 100644
> > --- a/hw/net/vhost_net.c
> > +++ b/hw/net/vhost_net.c
> > @@ -244,6 +244,10 @@ static int vhost_net_start_one(struct vhost_net *net,
> >       struct vhost_vring_file file = { };
> >       int r;
> >
> > +    if (net->nc->info->prepare) {
> > +        net->nc->info->prepare(net->nc);
> > +    }
>
>
> Any chance we can reuse load()?
>

We would be setting the ASID of CVQ after DRIVER_OK, vring
addresses... if we move to load.

Thanks!

> Thanks
>
>
> > +
> >       r = vhost_dev_enable_notifiers(&net->dev, dev);
> >       if (r < 0) {
> >           goto fail_notifiers;
>
Jason Wang Aug. 4, 2022, 7:53 a.m. UTC | #3
On Thu, Aug 4, 2022 at 3:52 PM Eugenio Perez Martin <eperezma@redhat.com> wrote:
>
> On Thu, Aug 4, 2022 at 6:46 AM Jason Wang <jasowang@redhat.com> wrote:
> >
> >
> > 在 2022/8/4 01:18, Eugenio Pérez 写道:
> > > This is used by the backend to perform actions before the device is
> > > started.
> > >
> > > In particular, vdpa will use it to isolate CVQ in its own ASID if
> > > possible, and start SVQ unconditionally only in CVQ.
> > >
> > > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > > ---
> > >   include/net/net.h  | 2 ++
> > >   hw/net/vhost_net.c | 4 ++++
> > >   2 files changed, 6 insertions(+)
> > >
> > > diff --git a/include/net/net.h b/include/net/net.h
> > > index a8d47309cd..efa6448886 100644
> > > --- a/include/net/net.h
> > > +++ b/include/net/net.h
> > > @@ -44,6 +44,7 @@ typedef struct NICConf {
> > >
> > >   typedef void (NetPoll)(NetClientState *, bool enable);
> > >   typedef bool (NetCanReceive)(NetClientState *);
> > > +typedef void (NetPrepare)(NetClientState *);
> > >   typedef int (NetLoad)(NetClientState *);
> > >   typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t);
> > >   typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);
> > > @@ -72,6 +73,7 @@ typedef struct NetClientInfo {
> > >       NetReceive *receive_raw;
> > >       NetReceiveIOV *receive_iov;
> > >       NetCanReceive *can_receive;
> > > +    NetPrepare *prepare;
> > >       NetLoad *load;
> > >       NetCleanup *cleanup;
> > >       LinkStatusChanged *link_status_changed;
> > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> > > index a9bf72dcda..bbbb6d759b 100644
> > > --- a/hw/net/vhost_net.c
> > > +++ b/hw/net/vhost_net.c
> > > @@ -244,6 +244,10 @@ static int vhost_net_start_one(struct vhost_net *net,
> > >       struct vhost_vring_file file = { };
> > >       int r;
> > >
> > > +    if (net->nc->info->prepare) {
> > > +        net->nc->info->prepare(net->nc);
> > > +    }
> >
> >
> > Any chance we can reuse load()?
> >
>
> We would be setting the ASID of CVQ after DRIVER_OK, vring
> addresses... if we move to load.

Ok, then this patch should be fine.

Thanks

>
> Thanks!
>
> > Thanks
> >
> >
> > > +
> > >       r = vhost_dev_enable_notifiers(&net->dev, dev);
> > >       if (r < 0) {
> > >           goto fail_notifiers;
> >
>
diff mbox series

Patch

diff --git a/include/net/net.h b/include/net/net.h
index a8d47309cd..efa6448886 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -44,6 +44,7 @@  typedef struct NICConf {
 
 typedef void (NetPoll)(NetClientState *, bool enable);
 typedef bool (NetCanReceive)(NetClientState *);
+typedef void (NetPrepare)(NetClientState *);
 typedef int (NetLoad)(NetClientState *);
 typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t);
 typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);
@@ -72,6 +73,7 @@  typedef struct NetClientInfo {
     NetReceive *receive_raw;
     NetReceiveIOV *receive_iov;
     NetCanReceive *can_receive;
+    NetPrepare *prepare;
     NetLoad *load;
     NetCleanup *cleanup;
     LinkStatusChanged *link_status_changed;
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index a9bf72dcda..bbbb6d759b 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -244,6 +244,10 @@  static int vhost_net_start_one(struct vhost_net *net,
     struct vhost_vring_file file = { };
     int r;
 
+    if (net->nc->info->prepare) {
+        net->nc->info->prepare(net->nc);
+    }
+
     r = vhost_dev_enable_notifiers(&net->dev, dev);
     if (r < 0) {
         goto fail_notifiers;