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 09/10] vfio: Refactor dma APIs for emulated devices
Date: Thu, 24 Nov 2022 11:05:07 +0800	[thread overview]
Message-ID: <8b247f62-f41c-2256-9e9b-e2995956481b@intel.com> (raw)
In-Reply-To: <Y35PjWQbzRy+oMi7@nvidia.com>

On 2022/11/24 00:51, Jason Gunthorpe wrote:
> On Wed, Nov 23, 2022 at 07:01:12AM -0800, Yi Liu wrote:
>> To use group helpers instead of opening group related code in the
>> API. This prepares moving group specific code out of vfio_main.c.
>>
>> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
>> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
>> ---
>>   drivers/vfio/container.c | 20 +++++++++++++-------
>>   drivers/vfio/vfio.h      | 32 ++++++++++++++++----------------
>>   drivers/vfio/vfio_main.c | 26 +++++++++++++++-----------
>>   3 files changed, 44 insertions(+), 34 deletions(-)
>>
>> diff --git a/drivers/vfio/container.c b/drivers/vfio/container.c
>> index 6b362d97d682..e0d11ab7229a 100644
>> --- a/drivers/vfio/container.c
>> +++ b/drivers/vfio/container.c
>> @@ -540,11 +540,13 @@ void vfio_group_unuse_container(struct vfio_group *group)
>>   	fput(group->opened_file);
>>   }
>>   
>> -int vfio_container_pin_pages(struct vfio_container *container,
>> -			     struct iommu_group *iommu_group, dma_addr_t iova,
>> -			     int npage, int prot, struct page **pages)
>> +int vfio_group_container_pin_pages(struct vfio_group *group,
>> +				   dma_addr_t iova, int npage,
>> +				   int prot, struct page **pages)
>>   {
>> +	struct vfio_container *container = group->container;
>>   	struct vfio_iommu_driver *driver = container->iommu_driver;
>> +	struct iommu_group *iommu_group = group->iommu_group;
>>   
>>   	if (npage > VFIO_PIN_PAGES_MAX_ENTRIES)
>>   		return -E2BIG;
>> @@ -555,9 +557,11 @@ int vfio_container_pin_pages(struct vfio_container *container,
>>   				      npage, prot, pages);
>>   }
>>   
>> -void vfio_container_unpin_pages(struct vfio_container *container,
>> -				dma_addr_t iova, int npage)
>> +void vfio_group_container_unpin_pages(struct vfio_group *group,
>> +				      dma_addr_t iova, int npage)
>>   {
>> +	struct vfio_container *container = group->container;
>> +
>>   	if (WARN_ON(npage <= 0 || npage > VFIO_PIN_PAGES_MAX_ENTRIES))
>>   		return;
>>   
>> @@ -565,9 +569,11 @@ void vfio_container_unpin_pages(struct vfio_container *container,
>>   						  npage);
>>   }
>>   
>> -int vfio_container_dma_rw(struct vfio_container *container, dma_addr_t iova,
>> -			  void *data, size_t len, bool write)
>> +int vfio_group_container_dma_rw(struct vfio_group *group,
>> +				dma_addr_t iova, void *data,
>> +				size_t len, bool write)
>>   {
>> +	struct vfio_container *container = group->container;
>>   	struct vfio_iommu_driver *driver = container->iommu_driver;
>>   
>>   	if (unlikely(!driver || !driver->ops->dma_rw))
>> diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h
>> index 3378714a7462..d6b6bc20406b 100644
>> --- a/drivers/vfio/vfio.h
>> +++ b/drivers/vfio/vfio.h
>> @@ -122,13 +122,14 @@ int vfio_container_attach_group(struct vfio_container *container,
>>   void vfio_group_detach_container(struct vfio_group *group);
>>   void vfio_device_container_register(struct vfio_device *device);
>>   void vfio_device_container_unregister(struct vfio_device *device);
>> -int vfio_container_pin_pages(struct vfio_container *container,
>> -			     struct iommu_group *iommu_group, dma_addr_t iova,
>> -			     int npage, int prot, struct page **pages);
>> -void vfio_container_unpin_pages(struct vfio_container *container,
>> -				dma_addr_t iova, int npage);
>> -int vfio_container_dma_rw(struct vfio_container *container, dma_addr_t iova,
>> -			  void *data, size_t len, bool write);
>> +int vfio_group_container_pin_pages(struct vfio_group *group,
>> +				   dma_addr_t iova, int npage,
>> +				   int prot, struct page **pages);
>> +void vfio_group_container_unpin_pages(struct vfio_group *group,
>> +				      dma_addr_t iova, int npage);
>> +int vfio_group_container_dma_rw(struct vfio_group *group,
>> +				dma_addr_t iova, void *data,
>> +				size_t len, bool write);
>>   
>>   int __init vfio_container_init(void);
>>   void vfio_container_cleanup(void);
>> @@ -166,22 +167,21 @@ static inline void vfio_device_container_unregister(struct vfio_device *device)
>>   {
>>   }
>>   
>> -static inline int vfio_container_pin_pages(struct vfio_container *container,
>> -					   struct iommu_group *iommu_group,
>> -					   dma_addr_t iova, int npage, int prot,
>> -					   struct page **pages)
>> +static inline int vfio_group_container_pin_pages(struct vfio_group *group,
>> +						 dma_addr_t iova, int npage,
>> +						 int prot, struct page **pages)
>>   {
>>   	return -EOPNOTSUPP;
>>   }
>>   
>> -static inline void vfio_container_unpin_pages(struct vfio_container *container,
>> -					      dma_addr_t iova, int npage)
>> +static inline void vfio_group_container_unpin_pages(struct vfio_group *group,
>> +						    dma_addr_t iova, int npage)
>>   {
>>   }
>>   
>> -static inline int vfio_container_dma_rw(struct vfio_container *container,
>> -					dma_addr_t iova, void *data, size_t len,
>> -					bool write)
>> +static inline int vfio_group_container_dma_rw(struct vfio_group *group,
>> +					      dma_addr_t iova, void *data,
>> +					      size_t len, bool write)
>>   {
>>   	return -EOPNOTSUPP;
>>   }
>> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
>> index cde258f4ea17..b6d3cb35a523 100644
>> --- a/drivers/vfio/vfio_main.c
>> +++ b/drivers/vfio/vfio_main.c
>> @@ -1925,6 +1925,11 @@ int vfio_set_irqs_validate_and_prepare(struct vfio_irq_set *hdr, int num_irqs,
>>   }
>>   EXPORT_SYMBOL(vfio_set_irqs_validate_and_prepare);
>>   
>> +static bool vfio_group_has_container(struct vfio_group *group)
>> +{
>> +	return group->container;
>> +}
> 
> This should probably be
>   
>    vfio_device_has_container(struct vfio_device  *device)
> 
> And it just returns false if the group code is compiled out

sure.

-- 
Regards,
Yi Liu

  reply	other threads:[~2022-11-24  3:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 15:01 [RFC 00/10] Move group specific code into group.c Yi Liu
2022-11-23 15:01 ` [RFC 01/10] vfio: Simplify vfio_create_group() Yi Liu
2022-11-23 15:01 ` [RFC 02/10] vfio: Move the sanity check of the group to vfio_create_group() Yi Liu
2022-11-23 15:01 ` [RFC 03/10] vfio: Wrap group codes to be helpers for __vfio_register_dev() and unregister Yi Liu
2022-11-23 15:01 ` [RFC 04/10] vfio: Make vfio_device_open() group agnostic Yi Liu
2022-11-23 15:01 ` [RFC 05/10] vfio: Move device open/close code to be helpfers Yi Liu
2022-11-23 15:01 ` [RFC 06/10] vfio: Swap order of vfio_device_container_register() and open_device() Yi Liu
2022-11-23 15:01 ` [RFC 07/10] vfio: Refactor vfio_device_first_open() and _last_close() Yi Liu
2022-11-23 15:01 ` [RFC 08/10] vfio: Wrap vfio group module init/clean code into helpers Yi Liu
2022-11-23 15:01 ` [RFC 09/10] vfio: Refactor dma APIs for emulated devices Yi Liu
2022-11-23 16:51   ` Jason Gunthorpe
2022-11-24  3:05     ` Yi Liu [this message]
2022-11-23 15:01 ` [RFC 10/10] vfio: Move vfio group specific code into group.c Yi Liu
2022-11-23 18:37   ` Jason Gunthorpe
2022-11-24  3:06     ` Yi Liu
2022-11-23 18:41 ` [RFC 00/10] Move " Jason Gunthorpe
2022-11-24  3:15   ` Yi Liu

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=8b247f62-f41c-2256-9e9b-e2995956481b@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.