[v2,2/4] vdpa: pass initial config to _vdpa_register_device()

Message ID 1666137032-28192-3-git-send-email-si-wei.liu@oracle.com
State New
Headers
Series vDPA: dev config export via "vdpa dev show" command |

Commit Message

Si-Wei Liu Oct. 18, 2022, 11:50 p.m. UTC
  Just as _vdpa_register_device taking @nvqs as the number of queues
to feed userspace inquery via vdpa_dev_fill(), we can follow the
same to stash config attributes in struct vdpa_device at the time
of vdpa registration.

Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
---
 drivers/vdpa/ifcvf/ifcvf_main.c      |  2 +-
 drivers/vdpa/mlx5/net/mlx5_vnet.c    |  2 +-
 drivers/vdpa/vdpa.c                  | 15 +++++++++++----
 drivers/vdpa/vdpa_sim/vdpa_sim_blk.c |  2 +-
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c |  2 +-
 drivers/vdpa/vdpa_user/vduse_dev.c   |  2 +-
 drivers/vdpa/virtio_pci/vp_vdpa.c    |  3 ++-
 include/linux/vdpa.h                 |  3 ++-
 8 files changed, 20 insertions(+), 11 deletions(-)
  

Comments

Jason Wang Oct. 20, 2022, 5:20 a.m. UTC | #1
On Wed, Oct 19, 2022 at 8:56 AM Si-Wei Liu <si-wei.liu@oracle.com> wrote:
>
> Just as _vdpa_register_device taking @nvqs as the number of queues

I wonder if it's better to embed nvqs in the config structure.

> to feed userspace inquery via vdpa_dev_fill(), we can follow the
> same to stash config attributes in struct vdpa_device at the time
> of vdpa registration.
>
> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
> ---
>  drivers/vdpa/ifcvf/ifcvf_main.c      |  2 +-
>  drivers/vdpa/mlx5/net/mlx5_vnet.c    |  2 +-
>  drivers/vdpa/vdpa.c                  | 15 +++++++++++----
>  drivers/vdpa/vdpa_sim/vdpa_sim_blk.c |  2 +-
>  drivers/vdpa/vdpa_sim/vdpa_sim_net.c |  2 +-
>  drivers/vdpa/vdpa_user/vduse_dev.c   |  2 +-
>  drivers/vdpa/virtio_pci/vp_vdpa.c    |  3 ++-
>  include/linux/vdpa.h                 |  3 ++-
>  8 files changed, 20 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
> index f9c0044..c54ab2c 100644
> --- a/drivers/vdpa/ifcvf/ifcvf_main.c
> +++ b/drivers/vdpa/ifcvf/ifcvf_main.c
> @@ -771,7 +771,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
>         else
>                 ret = dev_set_name(&vdpa_dev->dev, "vdpa%u", vdpa_dev->index);
>
> -       ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring);
> +       ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring, config);
>         if (ret) {
>                 put_device(&adapter->vdpa.dev);
>                 IFCVF_ERR(pdev, "Failed to register to vDPA bus");
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 9091336..376082e 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -3206,7 +3206,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>         mlx5_notifier_register(mdev, &ndev->nb);
>         ndev->nb_registered = true;
>         mvdev->vdev.mdev = &mgtdev->mgtdev;
> -       err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1);
> +       err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1, add_config);
>         if (err)
>                 goto err_reg;
>
> diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
> index febdc99..566c1c6 100644
> --- a/drivers/vdpa/vdpa.c
> +++ b/drivers/vdpa/vdpa.c
> @@ -215,11 +215,16 @@ static int vdpa_name_match(struct device *dev, const void *data)
>         return (strcmp(dev_name(&vdev->dev), data) == 0);
>  }
>
> -static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs)
> +static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs,
> +                                 const struct vdpa_dev_set_config *cfg)
>  {
>         struct device *dev;
>
>         vdev->nvqs = nvqs;
> +       if (cfg)
> +               vdev->vdev_cfg = *cfg;
> +       else
> +               vdev->vdev_cfg.mask = 0ULL;

I think it would be nice if we can convert eni to use netlink then we
don't need any workaround like this.

Thanks
  
Si-Wei Liu Oct. 20, 2022, 5:42 p.m. UTC | #2
On 10/19/2022 10:20 PM, Jason Wang wrote:
> On Wed, Oct 19, 2022 at 8:56 AM Si-Wei Liu <si-wei.liu@oracle.com> wrote:
>> Just as _vdpa_register_device taking @nvqs as the number of queues
> I wonder if it's better to embed nvqs in the config structure.
Hmmm, the config structure is mostly for containing the configurables 
specified in the 'vdpa dev add' command, while each field is 
conditionally set and guarded by a corresponding mask bit. If @nvqs 
needs to be folded into a structure, I feel it might be better to use 
another struct for holding the informational fields (i.e. those are 
read-only and always exist). But doing this would make @nvqs a weird 
solo member in that struct with no extra benefit, and all the other 
informational fields shown in the 'vdpa dev show' command would be 
gotten from the device through config_ops directly. Maybe do this until 
another read-only field comes around?

>
>> to feed userspace inquery via vdpa_dev_fill(), we can follow the
>> same to stash config attributes in struct vdpa_device at the time
>> of vdpa registration.
>>
>> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
>> ---
>>   drivers/vdpa/ifcvf/ifcvf_main.c      |  2 +-
>>   drivers/vdpa/mlx5/net/mlx5_vnet.c    |  2 +-
>>   drivers/vdpa/vdpa.c                  | 15 +++++++++++----
>>   drivers/vdpa/vdpa_sim/vdpa_sim_blk.c |  2 +-
>>   drivers/vdpa/vdpa_sim/vdpa_sim_net.c |  2 +-
>>   drivers/vdpa/vdpa_user/vduse_dev.c   |  2 +-
>>   drivers/vdpa/virtio_pci/vp_vdpa.c    |  3 ++-
>>   include/linux/vdpa.h                 |  3 ++-
>>   8 files changed, 20 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
>> index f9c0044..c54ab2c 100644
>> --- a/drivers/vdpa/ifcvf/ifcvf_main.c
>> +++ b/drivers/vdpa/ifcvf/ifcvf_main.c
>> @@ -771,7 +771,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
>>          else
>>                  ret = dev_set_name(&vdpa_dev->dev, "vdpa%u", vdpa_dev->index);
>>
>> -       ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring);
>> +       ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring, config);
>>          if (ret) {
>>                  put_device(&adapter->vdpa.dev);
>>                  IFCVF_ERR(pdev, "Failed to register to vDPA bus");
>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> index 9091336..376082e 100644
>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> @@ -3206,7 +3206,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>>          mlx5_notifier_register(mdev, &ndev->nb);
>>          ndev->nb_registered = true;
>>          mvdev->vdev.mdev = &mgtdev->mgtdev;
>> -       err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1);
>> +       err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1, add_config);
>>          if (err)
>>                  goto err_reg;
>>
>> diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
>> index febdc99..566c1c6 100644
>> --- a/drivers/vdpa/vdpa.c
>> +++ b/drivers/vdpa/vdpa.c
>> @@ -215,11 +215,16 @@ static int vdpa_name_match(struct device *dev, const void *data)
>>          return (strcmp(dev_name(&vdev->dev), data) == 0);
>>   }
>>
>> -static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs)
>> +static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs,
>> +                                 const struct vdpa_dev_set_config *cfg)
>>   {
>>          struct device *dev;
>>
>>          vdev->nvqs = nvqs;
>> +       if (cfg)
>> +               vdev->vdev_cfg = *cfg;
>> +       else
>> +               vdev->vdev_cfg.mask = 0ULL;
> I think it would be nice if we can convert eni to use netlink then we
> don't need any workaround like this.
Yes, Alibaba ENI is the only consumer of the old vdpa_register_device() 
API without being ported to the netlink API. Not sure what is needed but 
it seems another work to make netlink API committed to support a legacy 
compatible model?

-Siwei

>
> Thanks
>
  
Jason Wang Oct. 21, 2022, 2:51 a.m. UTC | #3
On Fri, Oct 21, 2022 at 2:45 AM Si-Wei Liu <si-wei.liu@oracle.com> wrote:
>
>
>
> On 10/19/2022 10:20 PM, Jason Wang wrote:
> > On Wed, Oct 19, 2022 at 8:56 AM Si-Wei Liu <si-wei.liu@oracle.com> wrote:
> >> Just as _vdpa_register_device taking @nvqs as the number of queues
> > I wonder if it's better to embed nvqs in the config structure.
> Hmmm, the config structure is mostly for containing the configurables
> specified in the 'vdpa dev add' command, while each field is
> conditionally set and guarded by a corresponding mask bit. If @nvqs
> needs to be folded into a structure, I feel it might be better to use
> another struct for holding the informational fields (i.e. those are
> read-only and always exist). But doing this would make @nvqs a weird
> solo member in that struct with no extra benefit, and all the other
> informational fields shown in the 'vdpa dev show' command would be
> gotten from the device through config_ops directly. Maybe do this until
> another read-only field comes around?

That's fine.

>
> >
> >> to feed userspace inquery via vdpa_dev_fill(), we can follow the
> >> same to stash config attributes in struct vdpa_device at the time
> >> of vdpa registration.
> >>
> >> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
> >> ---
> >>   drivers/vdpa/ifcvf/ifcvf_main.c      |  2 +-
> >>   drivers/vdpa/mlx5/net/mlx5_vnet.c    |  2 +-
> >>   drivers/vdpa/vdpa.c                  | 15 +++++++++++----
> >>   drivers/vdpa/vdpa_sim/vdpa_sim_blk.c |  2 +-
> >>   drivers/vdpa/vdpa_sim/vdpa_sim_net.c |  2 +-
> >>   drivers/vdpa/vdpa_user/vduse_dev.c   |  2 +-
> >>   drivers/vdpa/virtio_pci/vp_vdpa.c    |  3 ++-
> >>   include/linux/vdpa.h                 |  3 ++-
> >>   8 files changed, 20 insertions(+), 11 deletions(-)
> >>
> >> diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
> >> index f9c0044..c54ab2c 100644
> >> --- a/drivers/vdpa/ifcvf/ifcvf_main.c
> >> +++ b/drivers/vdpa/ifcvf/ifcvf_main.c
> >> @@ -771,7 +771,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
> >>          else
> >>                  ret = dev_set_name(&vdpa_dev->dev, "vdpa%u", vdpa_dev->index);
> >>
> >> -       ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring);
> >> +       ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring, config);
> >>          if (ret) {
> >>                  put_device(&adapter->vdpa.dev);
> >>                  IFCVF_ERR(pdev, "Failed to register to vDPA bus");
> >> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> >> index 9091336..376082e 100644
> >> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> >> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> >> @@ -3206,7 +3206,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
> >>          mlx5_notifier_register(mdev, &ndev->nb);
> >>          ndev->nb_registered = true;
> >>          mvdev->vdev.mdev = &mgtdev->mgtdev;
> >> -       err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1);
> >> +       err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1, add_config);
> >>          if (err)
> >>                  goto err_reg;
> >>
> >> diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
> >> index febdc99..566c1c6 100644
> >> --- a/drivers/vdpa/vdpa.c
> >> +++ b/drivers/vdpa/vdpa.c
> >> @@ -215,11 +215,16 @@ static int vdpa_name_match(struct device *dev, const void *data)
> >>          return (strcmp(dev_name(&vdev->dev), data) == 0);
> >>   }
> >>
> >> -static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs)
> >> +static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs,
> >> +                                 const struct vdpa_dev_set_config *cfg)
> >>   {
> >>          struct device *dev;
> >>
> >>          vdev->nvqs = nvqs;
> >> +       if (cfg)
> >> +               vdev->vdev_cfg = *cfg;
> >> +       else
> >> +               vdev->vdev_cfg.mask = 0ULL;
> > I think it would be nice if we can convert eni to use netlink then we
> > don't need any workaround like this.
> Yes, Alibaba ENI is the only consumer of the old vdpa_register_device()
> API without being ported to the netlink API. Not sure what is needed but
> it seems another work to make netlink API committed to support a legacy
> compatible model?

It's only about the provisioning (which is kind of out of the spec).
So if I was not wrong, it should be something similar like the work
that Cindy has done, (per VF mgmtdev):

commit ffbda8e9df10d1784d5427ec199e7d8308e3763f
Author: Cindy Lu <lulu@redhat.com>
Date:   Fri Apr 29 17:10:30 2022 +0800

    vdpa/vp_vdpa : add vdpa tool support in vp_vdpa

Thanks

>
> -Siwei
>
> >
> > Thanks
> >
>
  
Si-Wei Liu Oct. 22, 2022, 12:31 a.m. UTC | #4
On 10/20/2022 7:51 PM, Jason Wang wrote:
> On Fri, Oct 21, 2022 at 2:45 AM Si-Wei Liu <si-wei.liu@oracle.com> wrote:
>>
>>
>> On 10/19/2022 10:20 PM, Jason Wang wrote:
>>> On Wed, Oct 19, 2022 at 8:56 AM Si-Wei Liu <si-wei.liu@oracle.com> wrote:
>>>> Just as _vdpa_register_device taking @nvqs as the number of queues
>>> I wonder if it's better to embed nvqs in the config structure.
>> Hmmm, the config structure is mostly for containing the configurables
>> specified in the 'vdpa dev add' command, while each field is
>> conditionally set and guarded by a corresponding mask bit. If @nvqs
>> needs to be folded into a structure, I feel it might be better to use
>> another struct for holding the informational fields (i.e. those are
>> read-only and always exist). But doing this would make @nvqs a weird
>> solo member in that struct with no extra benefit, and all the other
>> informational fields shown in the 'vdpa dev show' command would be
>> gotten from the device through config_ops directly. Maybe do this until
>> another read-only field comes around?
> That's fine.
>
>>>> to feed userspace inquery via vdpa_dev_fill(), we can follow the
>>>> same to stash config attributes in struct vdpa_device at the time
>>>> of vdpa registration.
>>>>
>>>> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
>>>> ---
>>>>    drivers/vdpa/ifcvf/ifcvf_main.c      |  2 +-
>>>>    drivers/vdpa/mlx5/net/mlx5_vnet.c    |  2 +-
>>>>    drivers/vdpa/vdpa.c                  | 15 +++++++++++----
>>>>    drivers/vdpa/vdpa_sim/vdpa_sim_blk.c |  2 +-
>>>>    drivers/vdpa/vdpa_sim/vdpa_sim_net.c |  2 +-
>>>>    drivers/vdpa/vdpa_user/vduse_dev.c   |  2 +-
>>>>    drivers/vdpa/virtio_pci/vp_vdpa.c    |  3 ++-
>>>>    include/linux/vdpa.h                 |  3 ++-
>>>>    8 files changed, 20 insertions(+), 11 deletions(-)
>>>>
>>>> diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
>>>> index f9c0044..c54ab2c 100644
>>>> --- a/drivers/vdpa/ifcvf/ifcvf_main.c
>>>> +++ b/drivers/vdpa/ifcvf/ifcvf_main.c
>>>> @@ -771,7 +771,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
>>>>           else
>>>>                   ret = dev_set_name(&vdpa_dev->dev, "vdpa%u", vdpa_dev->index);
>>>>
>>>> -       ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring);
>>>> +       ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring, config);
>>>>           if (ret) {
>>>>                   put_device(&adapter->vdpa.dev);
>>>>                   IFCVF_ERR(pdev, "Failed to register to vDPA bus");
>>>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>>> index 9091336..376082e 100644
>>>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>>> @@ -3206,7 +3206,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>>>>           mlx5_notifier_register(mdev, &ndev->nb);
>>>>           ndev->nb_registered = true;
>>>>           mvdev->vdev.mdev = &mgtdev->mgtdev;
>>>> -       err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1);
>>>> +       err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1, add_config);
>>>>           if (err)
>>>>                   goto err_reg;
>>>>
>>>> diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
>>>> index febdc99..566c1c6 100644
>>>> --- a/drivers/vdpa/vdpa.c
>>>> +++ b/drivers/vdpa/vdpa.c
>>>> @@ -215,11 +215,16 @@ static int vdpa_name_match(struct device *dev, const void *data)
>>>>           return (strcmp(dev_name(&vdev->dev), data) == 0);
>>>>    }
>>>>
>>>> -static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs)
>>>> +static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs,
>>>> +                                 const struct vdpa_dev_set_config *cfg)
>>>>    {
>>>>           struct device *dev;
>>>>
>>>>           vdev->nvqs = nvqs;
>>>> +       if (cfg)
>>>> +               vdev->vdev_cfg = *cfg;
>>>> +       else
>>>> +               vdev->vdev_cfg.mask = 0ULL;
>>> I think it would be nice if we can convert eni to use netlink then we
>>> don't need any workaround like this.
>> Yes, Alibaba ENI is the only consumer of the old vdpa_register_device()
>> API without being ported to the netlink API. Not sure what is needed but
>> it seems another work to make netlink API committed to support a legacy
>> compatible model?
> It's only about the provisioning (which is kind of out of the spec).
> So if I was not wrong, it should be something similar like the work
> that Cindy has done, (per VF mgmtdev):
>
> commit ffbda8e9df10d1784d5427ec199e7d8308e3763f
> Author: Cindy Lu <lulu@redhat.com>
> Date:   Fri Apr 29 17:10:30 2022 +0800
>
>      vdpa/vp_vdpa : add vdpa tool support in vp_vdpa
OK, I was thinking of something else for e.g. support legacy driver 
changing the default MAC with VIRTIO_NET_F_MAC provisioned. Then it 
looks Alibaba eni_vdpa can only be provisioned without any config 
attribute specified, thus unable to enjoy the other benefit from the 
netlink API. Since it's kind of out of scope of my work, I'd like to 
have the author of this driver (cc'ed) to make decision for it.

-Siwei
>
> Thanks
>
>> -Siwei
>>
>>> Thanks
>>>
  

Patch

diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
index f9c0044..c54ab2c 100644
--- a/drivers/vdpa/ifcvf/ifcvf_main.c
+++ b/drivers/vdpa/ifcvf/ifcvf_main.c
@@ -771,7 +771,7 @@  static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
 	else
 		ret = dev_set_name(&vdpa_dev->dev, "vdpa%u", vdpa_dev->index);
 
-	ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring);
+	ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring, config);
 	if (ret) {
 		put_device(&adapter->vdpa.dev);
 		IFCVF_ERR(pdev, "Failed to register to vDPA bus");
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 9091336..376082e 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -3206,7 +3206,7 @@  static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	mlx5_notifier_register(mdev, &ndev->nb);
 	ndev->nb_registered = true;
 	mvdev->vdev.mdev = &mgtdev->mgtdev;
-	err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1);
+	err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1, add_config);
 	if (err)
 		goto err_reg;
 
diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index febdc99..566c1c6 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -215,11 +215,16 @@  static int vdpa_name_match(struct device *dev, const void *data)
 	return (strcmp(dev_name(&vdev->dev), data) == 0);
 }
 
-static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs)
+static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs,
+				  const struct vdpa_dev_set_config *cfg)
 {
 	struct device *dev;
 
 	vdev->nvqs = nvqs;
+	if (cfg)
+		vdev->vdev_cfg = *cfg;
+	else
+		vdev->vdev_cfg.mask = 0ULL;
 
 	lockdep_assert_held(&vdpa_dev_lock);
 	dev = bus_find_device(&vdpa_bus, NULL, dev_name(&vdev->dev), vdpa_name_match);
@@ -237,15 +242,17 @@  static int __vdpa_register_device(struct vdpa_device *vdev, u32 nvqs)
  * callback after setting up valid mgmtdev for this vdpa device.
  * @vdev: the vdpa device to be registered to vDPA bus
  * @nvqs: number of virtqueues supported by this device
+ * @cfg: initial config on vdpa device creation
  *
  * Return: Returns an error when fail to add device to vDPA bus
  */
-int _vdpa_register_device(struct vdpa_device *vdev, u32 nvqs)
+int _vdpa_register_device(struct vdpa_device *vdev, u32 nvqs,
+			  const struct vdpa_dev_set_config *cfg)
 {
 	if (!vdev->mdev)
 		return -EINVAL;
 
-	return __vdpa_register_device(vdev, nvqs);
+	return __vdpa_register_device(vdev, nvqs, cfg);
 }
 EXPORT_SYMBOL_GPL(_vdpa_register_device);
 
@@ -262,7 +269,7 @@  int vdpa_register_device(struct vdpa_device *vdev, u32 nvqs)
 	int err;
 
 	down_write(&vdpa_dev_lock);
-	err = __vdpa_register_device(vdev, nvqs);
+	err = __vdpa_register_device(vdev, nvqs, NULL);
 	up_write(&vdpa_dev_lock);
 	return err;
 }
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
index c6db1a1..5e1cebc 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
@@ -387,7 +387,7 @@  static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
 	if (IS_ERR(simdev))
 		return PTR_ERR(simdev);
 
-	ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_BLK_VQ_NUM);
+	ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_BLK_VQ_NUM, config);
 	if (ret)
 		goto put_dev;
 
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
index c3cb225..06ef5a0 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
@@ -260,7 +260,7 @@  static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
 
 	vdpasim_net_setup_config(simdev, config);
 
-	ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_NET_VQ_NUM);
+	ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_NET_VQ_NUM, config);
 	if (ret)
 		goto reg_err;
 
diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index 35dceee..6530fd2 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -1713,7 +1713,7 @@  static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
 	if (ret)
 		return ret;
 
-	ret = _vdpa_register_device(&dev->vdev->vdpa, dev->vq_num);
+	ret = _vdpa_register_device(&dev->vdev->vdpa, dev->vq_num, config);
 	if (ret) {
 		put_device(&dev->vdev->vdpa.dev);
 		return ret;
diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index d448db0..ffdc90e 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -538,7 +538,8 @@  static int vp_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	vp_vdpa->config_irq = VIRTIO_MSI_NO_VECTOR;
 
 	vp_vdpa->vdpa.mdev = &vp_vdpa_mgtdev->mgtdev;
-	ret = _vdpa_register_device(&vp_vdpa->vdpa, vp_vdpa->queues);
+	ret = _vdpa_register_device(&vp_vdpa->vdpa, vp_vdpa->queues,
+				    add_config);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to register to vdpa bus\n");
 		goto err;
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index f1838f5..b9d50e8 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -381,7 +381,8 @@  struct vdpa_device *__vdpa_alloc_device(struct device *parent,
 int vdpa_register_device(struct vdpa_device *vdev, u32 nvqs);
 void vdpa_unregister_device(struct vdpa_device *vdev);
 
-int _vdpa_register_device(struct vdpa_device *vdev, u32 nvqs);
+int _vdpa_register_device(struct vdpa_device *vdev, u32 nvqs,
+			  const struct vdpa_dev_set_config *cfg);
 void _vdpa_unregister_device(struct vdpa_device *vdev);
 
 /**