virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Parav Pandit <parav@nvidia.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: Yongji Xie <xieyongji@bytedance.com>,
	"lingshan.zhu@intel.com" <lingshan.zhu@intel.com>,
	"virtualization@lists.linux-foundation.org"
	<virtualization@lists.linux-foundation.org>,
	Eli Cohen <elic@nvidia.com>, "mst@redhat.com" <mst@redhat.com>
Subject: Re: [PATCH v2 2/3] vdpa: Add a device object for vdpa management device
Date: Wed, 18 May 2022 16:31:32 +0800	[thread overview]
Message-ID: <28a689dc-a9de-ca1f-6b9f-26c735e96781@redhat.com> (raw)
In-Reply-To: <PH0PR12MB54819F4E48BE36460BC89457DCCE9@PH0PR12MB5481.namprd12.prod.outlook.com>


在 2022/5/18 07:03, Parav Pandit 写道:
>>> And regarding vduse_dev_release() and existing empty release function,
>> they can be dynamically allocated.
>>> This is because they are really the struct device.
>> I do not understand this statement, sorry.
> It was bad sentence, my bad.
>
> What I wanted to say is, probably better explained with real patch below.
> In context of [1], struct vduse_mgmtdev empty release function can be avoided by below inline patch [2].
>
> [1]https://www.spinics.net/lists/linux-virtualization/msg56371.html
>
> [2] patch:


Ok, if we go this way (looks more like mdev_parent). I think we need at 
least rename the vdpa_mgmt_device, maybe vdpa_parent (like mdev_parent)?

Thanks


>
>  From f87d557fe939a1632473dd11526a87301adbab8d Mon Sep 17 00:00:00 2001
> From: Parav Pandit<parav@nvidia.com>
> Date: Wed, 18 May 2022 01:22:21 +0300
> Subject: [PATCH] vduse: Tie vduse mgmtdev and its device
>
> vduse management device is not backed by any real device such as PCI. Hence it
> doesn't have any parent device linked to it.
>
> Kernel driver model in [1] suggests avoiding an empty device release callback.
>
> Hence tie the mgmtdevice object's life cycle to an allocate dummy struct
> device instead of having it static.
>
> [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/core-api/kobject.rst?h=v5.18-rc7#n284
>
> Signed-off-by: Parav Pandit<parav@nvidia.com>
> ---
>   drivers/vdpa/vdpa_user/vduse_dev.c | 60 ++++++++++++++++++------------
>   1 file changed, 37 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index f85d1a08ed87..ebe272575fb8 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -1475,16 +1475,12 @@ static char *vduse_devnode(struct device *dev, umode_t *mode)
>   	return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
>   }
>   
> -static void vduse_mgmtdev_release(struct device *dev)
> -{
> -}
> -
> -static struct device vduse_mgmtdev = {
> -	.init_name = "vduse",
> -	.release = vduse_mgmtdev_release,
> +struct vduse_mgmt_dev {
> +	struct vdpa_mgmt_dev mgmt_dev;
> +	struct device dev;
>   };
>   
> -static struct vdpa_mgmt_dev mgmt_dev;
> +static struct vduse_mgmt_dev *vduse_mgmt;
>   
>   static int vduse_dev_init_vdpa(struct vduse_dev *dev, const char *name)
>   {
> @@ -1509,7 +1505,7 @@ static int vduse_dev_init_vdpa(struct vduse_dev *dev, const char *name)
>   	}
>   	set_dma_ops(&vdev->vdpa.dev, &vduse_dev_dma_ops);
>   	vdev->vdpa.dma_dev = &vdev->vdpa.dev;
> -	vdev->vdpa.mdev = &mgmt_dev;
> +	vdev->vdpa.mdev = &vduse_mgmt->mgmt_dev;
>   
>   	return 0;
>   }
> @@ -1555,34 +1551,52 @@ static struct virtio_device_id id_table[] = {
>   	{ 0 },
>   };
>   
> -static struct vdpa_mgmt_dev mgmt_dev = {
> -	.device = &vduse_mgmtdev,
> -	.id_table = id_table,
> -	.ops = &vdpa_dev_mgmtdev_ops,
> -};
> +static void vduse_mgmtdev_release(struct device *dev)
> +{
> +	struct vduse_mgmt_dev *mgmt_dev;
> +
> +	mgmt_dev = container_of(dev, struct vduse_mgmt_dev, dev);
> +	kfree(mgmt_dev);
> +}
>   
>   static int vduse_mgmtdev_init(void)
>   {
>   	int ret;
>   
> -	ret = device_register(&vduse_mgmtdev);
> -	if (ret)
> +	vduse_mgmt = kzalloc(sizeof(*vduse_mgmt), GFP_KERNEL);
> +	if (!vduse_mgmt)
> +		return -ENOMEM;
> +
> +	ret = dev_set_name(&vduse_mgmt->dev, "vduse-la");
> +	if (ret) {
> +		kfree(vduse_mgmt);
>   		return ret;
> +	}
>   
> -	ret = vdpa_mgmtdev_register(&mgmt_dev);
> +	vduse_mgmt->dev.release = vduse_mgmtdev_release;
> +
> +	ret = device_register(&vduse_mgmt->dev);
>   	if (ret)
> -		goto err;
> +		goto dev_reg_err;
>   
> -	return 0;
> -err:
> -	device_unregister(&vduse_mgmtdev);
> +	vduse_mgmt->mgmt_dev.id_table = id_table;
> +	vduse_mgmt->mgmt_dev.ops = &vdpa_dev_mgmtdev_ops;
> +	vduse_mgmt->mgmt_dev.device = &vduse_mgmt->dev;
> +	ret = vdpa_mgmtdev_register(&vduse_mgmt->mgmt_dev);
> +	if (ret)
> +		device_unregister(&vduse_mgmt->dev);
> +
> +	return ret;
> +
> +dev_reg_err:
> +	put_device(&vduse_mgmt->dev);
>   	return ret;
>   }
>   
>   static void vduse_mgmtdev_exit(void)
>   {
> -	vdpa_mgmtdev_unregister(&mgmt_dev);
> -	device_unregister(&vduse_mgmtdev);
> +	vdpa_mgmtdev_unregister(&vduse_mgmt->mgmt_dev);
> +	device_unregister(&vduse_mgmt->dev);
>   }
>   
>   static int vduse_init(void)
> -- 2.26.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  reply	other threads:[~2022-05-18  8:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220516060342.106-1-xieyongji@bytedance.com>
2022-05-16  6:13 ` [PATCH v2 1/3] vduse: Pass management device pointer to vduse_dev_init_vdpa() Greg KH
     [not found] ` <20220516060342.106-3-xieyongji@bytedance.com>
2022-05-16  6:14   ` [PATCH v2 3/3] Docs/ABI/testing: Add VDUSE sysfs interface ABI document Greg KH
2022-05-16  8:33 ` [PATCH v2 1/3] vduse: Pass management device pointer to vduse_dev_init_vdpa() Michael S. Tsirkin
     [not found] ` <20220516060342.106-2-xieyongji@bytedance.com>
2022-05-16  6:13   ` [PATCH v2 2/3] vdpa: Add a device object for vdpa management device Greg KH
2022-05-16  8:32   ` Michael S. Tsirkin
2022-05-16  9:14   ` Jason Wang
     [not found]     ` <CACycT3uoWjYjogi0H4yrA7GuKnY=djt6BmafoRB-rbmz+8Y4BA@mail.gmail.com>
2022-05-16  9:54       ` Michael S. Tsirkin
     [not found]         ` <CACycT3sqEJ7JSYV646m6CLVH5tKpfbTUV4Oz+XcfXTe4ApEE1w@mail.gmail.com>
2022-05-16 10:34           ` Michael S. Tsirkin
2022-05-16 11:54             ` Greg KH
2022-05-17  6:29               ` Jason Wang
2022-05-17  6:38                 ` Greg KH
2022-05-16 20:06   ` Parav Pandit via Virtualization
     [not found]     ` <CACycT3sRc4bk+3oq7FLzpBMCG_XRN7tOaeEAtNg69o3h8c3=EA@mail.gmail.com>
2022-05-17 12:21       ` Parav Pandit via Virtualization
2022-05-17 13:54         ` gregkh
2022-05-17 23:03           ` Parav Pandit via Virtualization
2022-05-18  8:31             ` Jason Wang [this message]
2022-05-23  2:00               ` Parav Pandit via Virtualization
2022-05-23  3:41                 ` Jason Wang
2022-05-24  1:07                   ` Parav Pandit via Virtualization

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28a689dc-a9de-ca1f-6b9f-26c735e96781@redhat.com \
    --to=jasowang@redhat.com \
    --cc=elic@nvidia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=lingshan.zhu@intel.com \
    --cc=mst@redhat.com \
    --cc=parav@nvidia.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xieyongji@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).