Linux IOMMU Development
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Vasant Hegde <vasant.hegde@amd.com>
Cc: iommu@lists.linux.dev, joro@8bytes.org,
	suravee.suthikulpanit@amd.com, wei.huang2@amd.com,
	jsnitsel@redhat.com
Subject: Re: [PATCH v6 17/17] iommu/amd: Introduce per-device domain ID to workaround potential TLB aliasing issue
Date: Thu, 1 Feb 2024 14:51:21 -0400	[thread overview]
Message-ID: <20240201185121.GO50608@ziepe.ca> (raw)
In-Reply-To: <20240125121135.8217-18-vasant.hegde@amd.com>

On Thu, Jan 25, 2024 at 12:11:35PM +0000, Vasant Hegde wrote:

> Hence, avoid the TLB aliasing issue with v2 page table by allocating unique
> domain ID for each device even when multiple devices are sharing the same v1
> page table. Please note that this workaround would result in multiple
> INVALIDATE_IOMMU_PAGES commands (one per domain id) when unmapping a
> translation.

I think the bigger downside is that it causes V2 domains to become
IOTLB unsharable even in simple cases with no possible PASID.

BTW "workaround" is not quite right, this is "fix", and it is a
security problem to get this wrong.

Anyhow:

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

> diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
> index 79a07a2e4bec..d5786c33aee6 100644
> --- a/drivers/iommu/amd/amd_iommu_types.h
> +++ b/drivers/iommu/amd/amd_iommu_types.h
> @@ -536,6 +536,7 @@ struct gcr3_tbl_info {
>  	u64	*gcr3_tbl;	/* Guest CR3 table */
>  	int	glx;		/* Number of levels for GCR3 table */
>  	u32	pasid_cnt;	/* Track attached PASIDs */
> +	u16	domid;		/* Per device domain ID */

It is minor, but per-table domain ID, not per device.

Same-gcr3 tables can always safely share the domain id.

> -static void __domain_flush_pages(struct protection_domain *domain,
> +static int domain_flush_pages_v2(struct protection_domain *pdom,
>  				 u64 address, size_t size)
>  {
>  	struct iommu_dev_data *dev_data;
>  	struct iommu_cmd cmd;
> -	int ret = 0, i;
> -	ioasid_t pasid = IOMMU_NO_PASID;
> -	bool gn = false;
> +	int ret = 0;
>  
> -	if (pdom_is_v2_pgtbl_mode(domain))
> -		gn = true;
> +	list_for_each_entry(dev_data, &pdom->dev_list, list) {

Suggest a future patch to add

lockdep_assert_held(&pdom->lock);

To all functions touching dev_list.. That locking is a bit obscure.
Also, I'm not sure using a spinlock with such a wide scope makes
sense. :|

Jason

  reply	other threads:[~2024-02-01 18:51 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-25 12:11 [PATCH v6 00/17] iommu/amd: SVA Support (part 3) - refactor support for GCR3 table Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 01/17] iommu/amd: Pass struct iommu_dev_data to set_dte_entry() Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 02/17] iommu/amd: Enable Guest Translation before registering devices Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 03/17] iommu/amd: Introduce get_amd_iommu_from_dev() Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 04/17] iommu/amd: Introduce struct protection_domain.pd_mode Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 05/17] iommu/amd: Introduce per-device GCR3 table Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 06/17] iommu/amd: Use protection_domain.flags to check page table mode Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 07/17] iommu/amd: Add support for device based TLB invalidation Vasant Hegde
2024-02-01 17:38   ` Jason Gunthorpe
2024-01-25 12:11 ` [PATCH v6 08/17] iommu/amd: Rearrange GCR3 table setup code Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 09/17] iommu: Introduce iommu_group_mutex_assert() Vasant Hegde
2024-02-01 17:26   ` Jason Gunthorpe
2024-02-05 10:22     ` Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 10/17] iommu/amd: Refactor helper function for setting / clearing GCR3 Vasant Hegde
2024-02-01 17:35   ` Jason Gunthorpe
2024-02-05 10:22     ` Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 11/17] iommu/amd: Refactor attaching / detaching device functions Vasant Hegde
2024-02-01 17:43   ` Jason Gunthorpe
2024-01-25 12:11 ` [PATCH v6 12/17] iommu/amd: Refactor protection_domain helper functions Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 13/17] iommu/amd: Refactor GCR3 table " Vasant Hegde
2024-02-01 18:02   ` Jason Gunthorpe
2024-01-25 12:11 ` [PATCH v6 14/17] iommu/amd: Remove unused flush pasid functions Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 15/17] iommu/amd: Rearrange device flush code Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 16/17] iommu/amd: Remove unused GCR3 table parameters from struct protection_domain Vasant Hegde
2024-01-25 12:11 ` [PATCH v6 17/17] iommu/amd: Introduce per-device domain ID to workaround potential TLB aliasing issue Vasant Hegde
2024-02-01 18:51   ` Jason Gunthorpe [this message]
2024-02-05 10:18     ` Vasant Hegde

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=20240201185121.GO50608@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=jsnitsel@redhat.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=vasant.hegde@amd.com \
    --cc=wei.huang2@amd.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