[1/1] iommu/vt-d: Make context clearing consistent with context mapping

Message ID 20231114011036.70142-4-baolu.lu@linux.intel.com
State New
Headers
Series [1/1] iommu/vt-d: Make context clearing consistent with context mapping |

Commit Message

Baolu Lu Nov. 14, 2023, 1:10 a.m. UTC
  In the iommu probe_device path, domain_context_mapping() allows setting
up the context entry for a non-PCI device. However, in the iommu
release_device path, domain_context_clear() only clears context entries
for PCI devices.

Make domain_context_clear() behave consistently with
domain_context_mapping() by clearing context entries for both PCI and
non-PCI devices.

Fixes: 579305f75d34 ("iommu/vt-d: Update to use PCI DMA aliases")
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Tian, Kevin Nov. 14, 2023, 3:20 a.m. UTC | #1
> From: Lu Baolu <baolu.lu@linux.intel.com>
> Sent: Tuesday, November 14, 2023 9:11 AM
> 
> In the iommu probe_device path, domain_context_mapping() allows setting
> up the context entry for a non-PCI device. However, in the iommu
> release_device path, domain_context_clear() only clears context entries
> for PCI devices.
> 
> Make domain_context_clear() behave consistently with
> domain_context_mapping() by clearing context entries for both PCI and
> non-PCI devices.
> 
> Fixes: 579305f75d34 ("iommu/vt-d: Update to use PCI DMA aliases")
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>

The code before the fix tag also has the same problem. If we really want
backport then let's find out the very first commit which exhibits this
problem.

But I wonder the actual impact w/o such fix. If there is no hot-remove
possible for those non-PCI devices the context entry will be leaved
enabled until the machine is off. Then this fix is nice-to-have then
probably no need to backport?
  
Baolu Lu Nov. 14, 2023, 3:22 a.m. UTC | #2
On 11/14/23 11:20 AM, Tian, Kevin wrote:
>> From: Lu Baolu <baolu.lu@linux.intel.com>
>> Sent: Tuesday, November 14, 2023 9:11 AM
>>
>> In the iommu probe_device path, domain_context_mapping() allows setting
>> up the context entry for a non-PCI device. However, in the iommu
>> release_device path, domain_context_clear() only clears context entries
>> for PCI devices.
>>
>> Make domain_context_clear() behave consistently with
>> domain_context_mapping() by clearing context entries for both PCI and
>> non-PCI devices.
>>
>> Fixes: 579305f75d34 ("iommu/vt-d: Update to use PCI DMA aliases")
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> 
> The code before the fix tag also has the same problem. If we really want
> backport then let's find out the very first commit which exhibits this
> problem.

Commit 579305f75d34 allows non-PCI devices.

+       if (!dev_is_pci(dev))
+               return domain_context_mapping_one(domain, iommu, bus, devfn,
                                                   translation);
+
+       data.domain = domain;
+       data.iommu = iommu;
+       data.translation = translation;
+
+       return pci_for_each_dma_alias(to_pci_dev(dev),
+                                     &domain_context_mapping_cb, &data);

But it forgot to update the domain_context_clear() helper. So this is
actually a fix for that commit.

> 
> But I wonder the actual impact w/o such fix. If there is no hot-remove
> possible for those non-PCI devices the context entry will be leaved
> enabled until the machine is off. Then this fix is nice-to-have then
> probably no need to backport?

It doesn't cause real issues as far as I can see. So there's no need to
back port it to stable kernels. That's the reason I didn't add cc-stable
tag. But we still need a fix tag as it's actually a fix.

Best regards,
baolu
  
Tian, Kevin Nov. 14, 2023, 4:46 a.m. UTC | #3
> From: Baolu Lu <baolu.lu@linux.intel.com>
> Sent: Tuesday, November 14, 2023 11:22 AM
> 
> On 11/14/23 11:20 AM, Tian, Kevin wrote:
> >> From: Lu Baolu <baolu.lu@linux.intel.com>
> >> Sent: Tuesday, November 14, 2023 9:11 AM
> >>
> >> In the iommu probe_device path, domain_context_mapping() allows
> setting
> >> up the context entry for a non-PCI device. However, in the iommu
> >> release_device path, domain_context_clear() only clears context entries
> >> for PCI devices.
> >>
> >> Make domain_context_clear() behave consistently with
> >> domain_context_mapping() by clearing context entries for both PCI and
> >> non-PCI devices.
> >>
> >> Fixes: 579305f75d34 ("iommu/vt-d: Update to use PCI DMA aliases")
> >> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> >
> > The code before the fix tag also has the same problem. If we really want
> > backport then let's find out the very first commit which exhibits this
> > problem.
> 
> Commit 579305f75d34 allows non-PCI devices.
> 
> +       if (!dev_is_pci(dev))
> +               return domain_context_mapping_one(domain, iommu, bus, devfn,
>                                                    translation);
> +
> +       data.domain = domain;
> +       data.iommu = iommu;
> +       data.translation = translation;
> +
> +       return pci_for_each_dma_alias(to_pci_dev(dev),
> +                                     &domain_context_mapping_cb, &data);
> 
> But it forgot to update the domain_context_clear() helper. So this is
> actually a fix for that commit.

thanks. I didn't note that side effect from commit msg.

> 
> >
> > But I wonder the actual impact w/o such fix. If there is no hot-remove
> > possible for those non-PCI devices the context entry will be leaved
> > enabled until the machine is off. Then this fix is nice-to-have then
> > probably no need to backport?
> 
> It doesn't cause real issues as far as I can see. So there's no need to
> back port it to stable kernels. That's the reason I didn't add cc-stable
> tag. But we still need a fix tag as it's actually a fix.
> 

make sense.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
  

Patch

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index c3ec09118ab1..061df1b68ff7 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3931,8 +3931,8 @@  static int domain_context_clear_one_cb(struct pci_dev *pdev, u16 alias, void *op
  */
 static void domain_context_clear(struct device_domain_info *info)
 {
-	if (!info->iommu || !info->dev || !dev_is_pci(info->dev))
-		return;
+	if (!dev_is_pci(info->dev))
+		domain_context_clear_one(info, info->bus, info->devfn);
 
 	pci_for_each_dma_alias(to_pci_dev(info->dev),
 			       &domain_context_clear_one_cb, info);