All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: <alex.williamson@redhat.com>, <kevin.tian@intel.com>,
	<eric.auger@redhat.com>, <cohuck@redhat.com>,
	<nicolinc@nvidia.com>, <yi.y.sun@linux.intel.com>,
	<chao.p.peng@linux.intel.com>, <mjrosato@linux.ibm.com>,
	<kvm@vger.kernel.org>
Subject: Re: [RFC v2 03/11] vfio: Set device->group in helper function
Date: Thu, 24 Nov 2022 21:50:14 +0800	[thread overview]
Message-ID: <fcb43043-0547-e368-f8a4-a396bf7c7390@intel.com> (raw)
In-Reply-To: <Y39u3446TXjcxkUz@nvidia.com>

On 2022/11/24 21:17, Jason Gunthorpe wrote:
> On Thu, Nov 24, 2022 at 04:26:54AM -0800, Yi Liu wrote:
>> This avoids referencing device->group in __vfio_register_dev()
>>
>> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
>> ---
>>   drivers/vfio/vfio_main.c | 52 +++++++++++++++++++++++++---------------
>>   1 file changed, 33 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
>> index 7a78256a650e..4980b8acf5d3 100644
>> --- a/drivers/vfio/vfio_main.c
>> +++ b/drivers/vfio/vfio_main.c
>> @@ -503,10 +503,15 @@ static struct vfio_group *vfio_group_find_or_alloc(struct device *dev)
>>   	return group;
>>   }
>>   
>> -static int __vfio_register_dev(struct vfio_device *device,
>> -		struct vfio_group *group)
>> +static int vfio_device_set_group(struct vfio_device *device,
>> +				 enum vfio_group_type type)
>>   {
>> -	int ret;
>> +	struct vfio_group *group;
>> +
>> +	if (type == VFIO_IOMMU)
>> +		group = vfio_group_find_or_alloc(device->dev);
>> +	else
>> +		group = vfio_noiommu_group_alloc(device->dev, type);
>>   
>>   	/*
>>   	 * In all cases group is the output of one of the group allocation
> 
> This comment should be deleted

ok.

>> @@ -515,6 +520,16 @@ static int __vfio_register_dev(struct vfio_device *device,
>>   	if (IS_ERR(group))
>>   		return PTR_ERR(group);
>>   
>> +	/* Our reference on group is moved to the device */
>> +	device->group = group;
>> +	return 0;
>> +}
>> +
>> +static int __vfio_register_dev(struct vfio_device *device,
>> +			       enum vfio_group_type type)
>> +{
>> +	int ret;
>> +
>>   	if (WARN_ON(device->ops->bind_iommufd &&
>>   		    (!device->ops->unbind_iommufd ||
>>   		     !device->ops->attach_ioas)))
>> @@ -527,34 +542,33 @@ static int __vfio_register_dev(struct vfio_device *device,
>>   	if (!device->dev_set)
>>   		vfio_assign_device_set(device, device);
>>   
>> -	/* Our reference on group is moved to the device */
>> -	device->group = group;
>> -
>>   	ret = dev_set_name(&device->device, "vfio%d", device->index);
>>   	if (ret)
>> -		goto err_out;
>> +		return ret;
>>   
>> -	ret = device_add(&device->device);
>> +	ret = vfio_device_set_group(device, type);
>>   	if (ret)
>> -		goto err_out;
>> +		return ret;
>> +
>> +	ret = device_add(&device->device);
>> +	if (ret) {
>> +		vfio_device_remove_group(device);
>> +		return ret;
> 
> You could probably keep the goto

after the change, only this branch will use the err_out; may be not 
necessary to use goto. but keep goto may have less changes in patch
file. e.g. I'm ok to keep goto.

@@ -527,12 +542,13 @@ static int __vfio_register_dev(struct vfio_device 
*device,
         if (!device->dev_set)
                 vfio_assign_device_set(device, device);

-       /* Our reference on group is moved to the device */
-       device->group = group;
-
         ret = dev_set_name(&device->device, "vfio%d", device->index);
         if (ret)
-               goto err_out;
+               return ret;
+
+       ret = vfio_device_set_group(device, type);
+       if (ret)
+               return ret;

         ret = device_add(&device->device);
         if (ret)


-- 
Regards,
Yi Liu

  reply	other threads:[~2022-11-24 13:49 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24 12:26 [RFC v2 00/11] Move group specific code into group.c Yi Liu
2022-11-24 12:26 ` [RFC v2 01/11] vfio: Simplify vfio_create_group() Yi Liu
2022-11-28  7:57   ` Tian, Kevin
2022-11-24 12:26 ` [RFC v2 02/11] vfio: Move the sanity check of the group to vfio_create_group() Yi Liu
2022-11-28  8:05   ` Tian, Kevin
2022-11-24 12:26 ` [RFC v2 03/11] vfio: Set device->group in helper function Yi Liu
2022-11-24 13:17   ` Jason Gunthorpe
2022-11-24 13:50     ` Yi Liu [this message]
2022-11-28  8:08   ` Tian, Kevin
2022-11-28  9:17     ` Yi Liu
2022-11-29  2:04       ` Tian, Kevin
2022-11-29 13:27         ` Jason Gunthorpe
2022-11-30  7:09           ` Yi Liu
2022-11-24 12:26 ` [RFC v2 04/11] vfio: Wrap group codes to be helpers for __vfio_register_dev() and unregister Yi Liu
2022-11-28  8:11   ` Tian, Kevin
2022-11-28  9:17     ` Yi Liu
2022-11-24 12:26 ` [RFC v2 05/11] vfio: Make vfio_device_open() group agnostic Yi Liu
2022-11-28  8:17   ` Tian, Kevin
2022-11-28  9:19     ` Yi Liu
2022-12-01  7:08       ` Yi Liu
2022-12-01 12:48         ` Jason Gunthorpe
2022-11-24 12:26 ` [RFC v2 06/11] vfio: Move device open/close code to be helpfers Yi Liu
2022-11-28  8:21   ` Tian, Kevin
2022-11-28  9:27     ` Yi Liu
2022-11-24 12:26 ` [RFC v2 07/11] vfio: Swap order of vfio_device_container_register() and open_device() Yi Liu
2022-11-28  8:27   ` Tian, Kevin
2022-11-28  9:28     ` Yi Liu
2022-11-24 12:26 ` [RFC v2 08/11] vfio: Refactor vfio_device_first_open() and _last_close() Yi Liu
2022-11-24 14:56   ` Jason Gunthorpe
2022-11-25  8:57     ` Yi Liu
2022-11-25 12:37       ` Jason Gunthorpe
2022-11-25 14:06         ` Yi Liu
2022-11-25 14:15           ` Jason Gunthorpe
2022-11-25 14:33             ` Yi Liu
2022-11-28  8:31   ` Tian, Kevin
2022-11-24 12:27 ` [RFC v2 09/11] vfio: Wrap vfio group module init/clean code into helpers Yi Liu
2022-11-28  8:36   ` Tian, Kevin
2022-11-24 12:27 ` [RFC v2 10/11] vfio: Refactor dma APIs for emulated devices Yi Liu
2022-11-24 22:05   ` kernel test robot
2022-11-28  8:42   ` Tian, Kevin
2022-11-24 12:27 ` [RFC v2 11/11] vfio: Move vfio group specific code into group.c Yi Liu
2022-11-24 14:36   ` Jason Gunthorpe
2022-11-25  8:45     ` Yi Liu
2022-11-28 21:21   ` kernel test robot

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=fcb43043-0547-e368-f8a4-a396bf7c7390@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=cohuck@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=nicolinc@nvidia.com \
    --cc=yi.y.sun@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.