mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: Lu Baolu <baolu.lu@linux.intel.com>,
	Joerg Roedel <joro@8bytes.org>, "Will Deacon" <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Aditya Garg <gargaditya08@live.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	kobarity <kobarity@gmail.com>
Cc: <iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] iommu/vt-d: Restore context entry setup order for aliased devices
Date: Fri, 16 May 2025 14:11:50 +0800	[thread overview]
Message-ID: <1826e96b-15bd-472d-b535-c72b58e06561@intel.com> (raw)
In-Reply-To: <20250514060523.2862195-1-baolu.lu@linux.intel.com>

Hi Baolu,

On 2025/5/14 14:05, Lu Baolu wrote:
> Commit 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
> changed the context entry setup during domain attachment from a
> set-and-check policy to a clear-and-reset approach. This inadvertently
> introduced a regression affecting PCI aliased devices behind PCIe-to-PCI
> bridges.

I got what the patch does. But just bit confused on the above description.
I didn't see the commit 2031c469f816 mentioned any policy thing on the
context entry setup.  To me, the problem looks to be that the info->domain
is no more accurate to be used for checking if any domain is attached after
the above commit. Maybe I missed something. feel free correct me.

> Specifically, keyboard and touchpad stopped working on several Apple
> Macbooks with below messages:
> 
>   kernel: platform pxa2xx-spi.3: Adding to iommu group 20
>   kernel: input: Apple SPI Keyboard as
>   /devices/pci0000:00/0000:00:1e.3/pxa2xx-spi.3/spi_master/spi2/spi-APP000D:00/input/input0
>   kernel: DMAR: DRHD: handling fault status reg 3
>   kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr
>   0xffffa000 [fault reason 0x06] PTE Read access is not set
>   kernel: DMAR: DRHD: handling fault status reg 3
>   kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr
>   0xffffa000 [fault reason 0x06] PTE Read access is not set
>   kernel: applespi spi-APP000D:00: Error writing to device: 01 0e 00 00
>   kernel: DMAR: DRHD: handling fault status reg 3
>   kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr
>   0xffffa000 [fault reason 0x06] PTE Read access is not set
>   kernel: DMAR: DRHD: handling fault status reg 3
>   kernel: applespi spi-APP000D:00: Error writing to device: 01 0e 00 00
> 
> Fix this by restoring the previous context setup order.
> 
> Fixes: 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
> Closes: https://lore.kernel.org/all/4dada48a-c5dd-4c30-9c85-5b03b0aa01f0@bfh.ch/
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---
>   drivers/iommu/intel/iommu.c  | 11 +++++++++++
>   drivers/iommu/intel/iommu.h  |  1 +
>   drivers/iommu/intel/nested.c |  4 ++--
>   3 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index 49530d5d8c85..7aa3932251b2 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -1809,6 +1809,7 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
>   		return ret;
>   
>   	info->domain = domain;
> +	info->domain_attached = true;
>   	spin_lock_irqsave(&domain->lock, flags);
>   	list_add(&info->link, &domain->devices);
>   	spin_unlock_irqrestore(&domain->lock, flags);
> @@ -3206,6 +3207,10 @@ void device_block_translation(struct device *dev)
>   	struct intel_iommu *iommu = info->iommu;
>   	unsigned long flags;
>   
> +	/* Device in DMA blocking state. Noting to do. */
> +	if (!info->domain_attached)
> +		return;
> +
>   	if (info->domain)
>   		cache_tag_unassign_domain(info->domain, dev, IOMMU_NO_PASID);
>   
> @@ -3217,6 +3222,9 @@ void device_block_translation(struct device *dev)
>   			domain_context_clear(info);
>   	}
>   
> +	/* Device now in DMA blocking state. */
> +	info->domain_attached = false;
> +
>   	if (!info->domain)
>   		return;
>   
> @@ -4302,6 +4310,9 @@ static int identity_domain_attach_dev(struct iommu_domain *domain, struct device
>   	else
>   		ret = device_setup_pass_through(dev);
>   
> +	if (!ret)
> +		info->domain_attached = true;
> +
>   	return ret;
>   }
>   
> diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h
> index cbfb8bb4c94a..3ddbcc603de2 100644
> --- a/drivers/iommu/intel/iommu.h
> +++ b/drivers/iommu/intel/iommu.h
> @@ -774,6 +774,7 @@ struct device_domain_info {
>   	u8 ats_supported:1;
>   	u8 ats_enabled:1;
>   	u8 dtlb_extra_inval:1;	/* Quirk for devices need extra flush */
> +	u8 domain_attached:1;	/* Device has domain attached */
>   	u8 ats_qdep;
>   	unsigned int iopf_refcount;
>   	struct device *dev; /* it's NULL for PCIe-to-PCI bridge */
> diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c
> index d2a94025d0a0..fc312f649f9e 100644
> --- a/drivers/iommu/intel/nested.c
> +++ b/drivers/iommu/intel/nested.c
> @@ -27,8 +27,7 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,
>   	unsigned long flags;
>   	int ret = 0;
>   
> -	if (info->domain)
> -		device_block_translation(dev);
> +	device_block_translation(dev);

good catch. :)

>   	if (iommu->agaw < dmar_domain->s2_domain->agaw) {
>   		dev_err_ratelimited(dev, "Adjusted guest address width not compatible\n");
> @@ -66,6 +65,7 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,
>   		goto disable_iopf;
>   
>   	info->domain = dmar_domain;
> +	info->domain_attached = true;
>   	spin_lock_irqsave(&dmar_domain->lock, flags);
>   	list_add(&info->link, &dmar_domain->devices);
>   	spin_unlock_irqrestore(&dmar_domain->lock, flags);

LGTM.

Reviewed-by: Yi Liu <yi.l.liu@intel.com>


Regards,
Yi Liu

  parent reply	other threads:[~2025-05-16  6:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14  6:05 Lu Baolu
2025-05-15  8:28 ` Tian, Kevin
2025-05-16  6:11 ` Yi Liu [this message]
2025-05-16  6:15   ` Baolu Lu
2025-05-20  7:58 [PATCH 0/1][PULL REQUEST] iommu/vt-d: Fixes for v6.16-rc1 Lu Baolu
2025-05-20  7:58 ` [PATCH 1/1] iommu/vt-d: Restore context entry setup order for aliased devices Lu Baolu

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=1826e96b-15bd-472d-b535-c72b58e06561@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gargaditya08@live.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kobarity@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /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

all inboxes | Powered by JetHome®