iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Vivek Kumar Gautam <vivek.gautam@arm.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
	Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: "jean-philippe@linaro.org" <jean-philippe@linaro.org>,
	"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
	"mst@redhat.com" <mst@redhat.com>,
	"will.deacon@arm.com" <will.deacon@arm.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"virtualization@lists.linux-foundation.org"
	<virtualization@lists.linux-foundation.org>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"robin.murphy@arm.com" <robin.murphy@arm.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH RFC v1 12/15] iommu/virtio: Add support for INVALIDATE request
Date: Thu, 4 Mar 2021 11:46:40 +0530	[thread overview]
Message-ID: <92b6384b-29ff-ed15-ce65-02c18eefc5b8@arm.com> (raw)
In-Reply-To: <MWHPR11MB1886860008D526446026E7E58C979@MWHPR11MB1886.namprd11.prod.outlook.com>

Hi Jacob, Kevin,


On 3/4/21 11:28 AM, Tian, Kevin wrote:
>> From: Jacob Pan <jacob.jun.pan@linux.intel.com>
>> Sent: Thursday, March 4, 2021 2:29 AM
>>
>> Hi Vivek,
>>
>> On Fri, 15 Jan 2021 17:43:39 +0530, Vivek Gautam <vivek.gautam@arm.com>
>> wrote:
>>
>>> From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
>>>
>>> Add support for tlb invalidation ops that can send invalidation
>>> requests to back-end virtio-iommu when stage-1 page tables are
>>> supported.
>>>
>> Just curious if it possible to reuse the iommu uapi for invalidation and others.
>> When we started out designing the iommu uapi, the intention was to support
>> both emulated and virtio iommu.
> 
> IIUC this patch is about the protocol between virtio-iommu frontend and backend.
> After the virtio-iommu backend receives invalidation ops, it then needs to
> forward the request to the host IOMMU driver through the existing iommu
> uapi that you referred to, as a emulated VT-d or SMMU would do.

Thanks a lot for looking at the patch.

Yes this patch is to provide the front-end virtio interface for 
invalidation requests during map/unmap and when flushing the pasid 
tables when virtio-iommu requested pasid table (in other words cd tables 
for arm-smmu-v3) from the iommu-pasid-table library.
The kvmtool back-end virtio driver forwards these requests to vfio 
driver which then makes use of iommu uapi to finally request host iommu 
driver for handling these invalidations.

Regards
Vivek

> 
> Thanks
> Kevin
> 
>>
>>> Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
>>> [Vivek: Refactoring the iommu_flush_ops, and adding only one pasid sync
>>>          op that's needed with current iommu-pasid-table infrastructure.
>>> 	Also updating uapi defines as required by latest changes]
>>> Signed-off-by: Vivek Gautam <vivek.gautam@arm.com>
>>> Cc: Joerg Roedel <joro@8bytes.org>
>>> Cc: Will Deacon <will.deacon@arm.com>
>>> Cc: Michael S. Tsirkin <mst@redhat.com>
>>> Cc: Robin Murphy <robin.murphy@arm.com>
>>> Cc: Jean-Philippe Brucker <jean-philippe@linaro.org>
>>> Cc: Eric Auger <eric.auger@redhat.com>
>>> Cc: Alex Williamson <alex.williamson@redhat.com>
>>> Cc: Kevin Tian <kevin.tian@intel.com>
>>> Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
>>> Cc: Liu Yi L <yi.l.liu@intel.com>
>>> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>>> Cc: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
>>> ---
>>>   drivers/iommu/virtio-iommu.c | 95
>> ++++++++++++++++++++++++++++++++++++
>>>   1 file changed, 95 insertions(+)
>>>
>>> diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
>>> index ae5dfd3f8269..004ea94e3731 100644
>>> --- a/drivers/iommu/virtio-iommu.c
>>> +++ b/drivers/iommu/virtio-iommu.c
>>> @@ -13,6 +13,7 @@
>>>   #include <linux/freezer.h>
>>>   #include <linux/interval_tree.h>
>>>   #include <linux/iommu.h>
>>> +#include <linux/io-pgtable.h>
>>>   #include <linux/module.h>
>>>   #include <linux/of_iommu.h>
>>>   #include <linux/of_platform.h>
>>> @@ -63,6 +64,8 @@ struct viommu_mapping {
>>>   };
>>>
>>>   struct viommu_mm {
>>> +	int				pasid;
>>> +	u64				archid;
>>>   	struct io_pgtable_ops		*ops;
>>>   	struct viommu_domain		*domain;
>>>   };
>>> @@ -692,6 +695,98 @@ static void viommu_event_handler(struct
>> virtqueue
>>> *vq) virtqueue_kick(vq);
>>>   }
>>>
>>> +/* PASID and pgtable APIs */
>>> +
>>> +static void __viommu_flush_pasid_tlb_all(struct viommu_domain
>> *vdomain,
>>> +					 int pasid, u64 arch_id, int
>>> type) +{
>>> +	struct virtio_iommu_req_invalidate req = {
>>> +		.head.type	= VIRTIO_IOMMU_T_INVALIDATE,
>>> +		.inv_gran	=
>>> cpu_to_le32(VIRTIO_IOMMU_INVAL_G_PASID),
>>> +		.flags		=
>>> cpu_to_le32(VIRTIO_IOMMU_INVAL_F_PASID),
>>> +		.inv_type	= cpu_to_le32(type),
>>> +
>>> +		.domain		= cpu_to_le32(vdomain->id),
>>> +		.pasid		= cpu_to_le32(pasid),
>>> +		.archid		= cpu_to_le64(arch_id),
>>> +	};
>>> +
>>> +	if (viommu_send_req_sync(vdomain->viommu, &req, sizeof(req)))
>>> +		pr_debug("could not send invalidate request\n");
>>> +}
>>> +
>>> +static void viommu_flush_tlb_add(struct iommu_iotlb_gather *gather,
>>> +				 unsigned long iova, size_t granule,
>>> +				 void *cookie)
>>> +{
>>> +	struct viommu_mm *viommu_mm = cookie;
>>> +	struct viommu_domain *vdomain = viommu_mm->domain;
>>> +	struct iommu_domain *domain = &vdomain->domain;
>>> +
>>> +	iommu_iotlb_gather_add_page(domain, gather, iova, granule);
>>> +}
>>> +
>>> +static void viommu_flush_tlb_walk(unsigned long iova, size_t size,
>>> +				  size_t granule, void *cookie)
>>> +{
>>> +	struct viommu_mm *viommu_mm = cookie;
>>> +	struct viommu_domain *vdomain = viommu_mm->domain;
>>> +	struct virtio_iommu_req_invalidate req = {
>>> +		.head.type	= VIRTIO_IOMMU_T_INVALIDATE,
>>> +		.inv_gran	= cpu_to_le32(VIRTIO_IOMMU_INVAL_G_VA),
>>> +		.inv_type	=
>> cpu_to_le32(VIRTIO_IOMMU_INV_T_IOTLB),
>>> +		.flags		=
>>> cpu_to_le32(VIRTIO_IOMMU_INVAL_F_ARCHID), +
>>> +		.domain		= cpu_to_le32(vdomain->id),
>>> +		.pasid		= cpu_to_le32(viommu_mm->pasid),
>>> +		.archid		= cpu_to_le64(viommu_mm->archid),
>>> +		.virt_start	= cpu_to_le64(iova),
>>> +		.nr_pages	= cpu_to_le64(size / granule),
>>> +		.granule	= ilog2(granule),
>>> +	};
>>> +
>>> +	if (viommu_add_req(vdomain->viommu, &req, sizeof(req)))
>>> +		pr_debug("could not add invalidate request\n");
>>> +}
>>> +
>>> +static void viommu_flush_tlb_all(void *cookie)
>>> +{
>>> +	struct viommu_mm *viommu_mm = cookie;
>>> +
>>> +	if (!viommu_mm->archid)
>>> +		return;
>>> +
>>> +	__viommu_flush_pasid_tlb_all(viommu_mm->domain,
>> viommu_mm->pasid,
>>> +				     viommu_mm->archid,
>>> +				     VIRTIO_IOMMU_INV_T_IOTLB);
>>> +}
>>> +
>>> +static struct iommu_flush_ops viommu_flush_ops = {
>>> +	.tlb_flush_all		= viommu_flush_tlb_all,
>>> +	.tlb_flush_walk		= viommu_flush_tlb_walk,
>>> +	.tlb_add_page		= viommu_flush_tlb_add,
>>> +};
>>> +
>>> +static void viommu_flush_pasid(void *cookie, int pasid, bool leaf)
>>> +{
>>> +	struct viommu_domain *vdomain = cookie;
>>> +	struct virtio_iommu_req_invalidate req = {
>>> +		.head.type	= VIRTIO_IOMMU_T_INVALIDATE,
>>> +		.inv_gran	=
>>> cpu_to_le32(VIRTIO_IOMMU_INVAL_G_PASID),
>>> +		.inv_type	=
>> cpu_to_le32(VIRTIO_IOMMU_INV_T_PASID),
>>> +		.flags		=
>>> cpu_to_le32(VIRTIO_IOMMU_INVAL_F_PASID), +
>>> +		.domain		= cpu_to_le32(vdomain->id),
>>> +		.pasid		= cpu_to_le32(pasid),
>>> +	};
>>> +
>>> +	if (leaf)
>>> +		req.flags	|=
>>> cpu_to_le32(VIRTIO_IOMMU_INVAL_F_LEAF); +
>>> +	if (viommu_send_req_sync(vdomain->viommu, &req, sizeof(req)))
>>> +		pr_debug("could not send invalidate request\n");
>>> +}
>>> +
>>>   /* IOMMU API */
>>>
>>>   static struct iommu_domain *viommu_domain_alloc(unsigned type)
>>
>>
>> Thanks,
>>
>> Jacob
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2021-03-04  6:17 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 12:13 [PATCH RFC v1 00/15] iommu/virtio: Nested stage support with Arm Vivek Gautam
2021-01-15 12:13 ` [PATCH RFC v1 01/15] iommu/arm-smmu-v3: Create a Context Descriptor library Vivek Gautam
2021-01-15 12:13 ` [PATCH RFC v1 02/15] iommu: Add a simple PASID table library Vivek Gautam
2021-03-03 17:11   ` Jean-Philippe Brucker
2021-03-12 12:47     ` Vivek Kumar Gautam
2021-03-29 16:25       ` Jean-Philippe Brucker
2021-01-15 12:13 ` [PATCH RFC v1 03/15] iommu/arm-smmu-v3: Update drivers to work with iommu-pasid-table Vivek Gautam
2021-01-15 12:13 ` [PATCH RFC v1 04/15] iommu/arm-smmu-v3: Update CD base address info for user-space Vivek Gautam
2021-03-03 17:14   ` Jean-Philippe Brucker
2021-03-12 12:31     ` Vivek Kumar Gautam
2021-01-15 12:13 ` [PATCH RFC v1 05/15] iommu/arm-smmu-v3: Set sync op from consumer driver of cd-lib Vivek Gautam
2021-03-03 17:15   ` Jean-Philippe Brucker
2021-03-12 12:49     ` Vivek Kumar Gautam
2021-01-15 12:13 ` [PATCH RFC v1 06/15] iommu/virtio: Add headers for table format probing Vivek Gautam
2021-03-03 17:17   ` Jean-Philippe Brucker
2021-03-12 12:54     ` Vivek Kumar Gautam
2021-01-15 12:13 ` [PATCH RFC v1 07/15] iommu/virtio: Add " Vivek Gautam
2021-01-15 12:13 ` [PATCH RFC v1 08/15] iommu: Add asid_bits to arm smmu-v3 stage1 table info Vivek Gautam
2021-03-03 17:18   ` Jean-Philippe Brucker
2021-03-12 12:57     ` Vivek Kumar Gautam
2021-01-15 12:13 ` [PATCH RFC v1 09/15] iommu/virtio: Update table format probing header Vivek Gautam
2021-03-03 17:21   ` Jean-Philippe Brucker
2021-03-12 12:58     ` Vivek Kumar Gautam
2021-01-15 12:13 ` [PATCH RFC v1 10/15] iommu/virtio: Prepare to add attach pasid table infrastructure Vivek Gautam
2021-01-15 12:13 ` [PATCH RFC v1 11/15] iommu/virtio: Add headers for binding pasid table in iommu Vivek Gautam
2021-01-15 12:13 ` [PATCH RFC v1 12/15] iommu/virtio: Add support for INVALIDATE request Vivek Gautam
2021-03-03 18:28   ` Jacob Pan
2021-03-04  5:58     ` Tian, Kevin
2021-03-04  6:16       ` Vivek Kumar Gautam [this message]
2021-01-15 12:13 ` [PATCH RFC v1 13/15] iommu/virtio: Attach Arm PASID tables when available Vivek Gautam
2021-03-03 17:25   ` Jean-Philippe Brucker
2021-03-12 13:29     ` Vivek Kumar Gautam
2021-03-29 16:21       ` Jean-Philippe Brucker
2021-01-15 12:13 ` [PATCH RFC v1 14/15] iommu/virtio: Add support for Arm LPAE page table format Vivek Gautam
2021-01-15 12:13 ` [PATCH RFC v1 15/15] iommu/virtio: Update fault type and reason info for viommu fault Vivek Gautam
2021-03-03 17:25   ` Jean-Philippe Brucker
2021-03-12 13:09     ` Vivek Kumar Gautam
2021-03-29 16:23       ` Jean-Philippe Brucker
2021-04-06  6:24         ` Vivek Kumar Gautam
2021-01-19  9:03 ` [PATCH RFC v1 00/15] iommu/virtio: Nested stage support with Arm Auger Eric
2021-01-21 17:34   ` Vivek Kumar Gautam
2021-01-22 15:49     ` Shameerali Kolothum Thodi
2021-01-25 12:55       ` Vivek Kumar Gautam
2021-01-25  8:43     ` Auger Eric

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=92b6384b-29ff-ed15-ce65-02c18eefc5b8@arm.com \
    --to=vivek.gautam@arm.com \
    --cc=alex.williamson@redhat.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=jean-philippe@linaro.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=robin.murphy@arm.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=will.deacon@arm.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).