Patch "iommu/vt-d: Support enforce_cache_coherency only for empty domains" has been added to the 6.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    iommu/vt-d: Support enforce_cache_coherency only for empty domains

to the 6.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     iommu-vt-d-support-enforce_cache_coherency-only-for-.patch
and it can be found in the queue-6.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 02d31a50994079cc278a191ffc74c44ead0f9378
Author: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
Date:   Wed Nov 22 11:26:02 2023 +0800

    iommu/vt-d: Support enforce_cache_coherency only for empty domains
    
    [ Upstream commit e645c20e8e9cde549bc233435d3c1338e1cd27fe ]
    
    The enforce_cache_coherency callback ensures DMA cache coherency for
    devices attached to the domain.
    
    Intel IOMMU supports enforced DMA cache coherency when the Snoop
    Control bit in the IOMMU's extended capability register is set.
    Supporting it differs between legacy and scalable modes.
    
    In legacy mode, it's supported page-level by setting the SNP field
    in second-stage page-table entries. In scalable mode, it's supported
    in PASID-table granularity by setting the PGSNP field in PASID-table
    entries.
    
    In legacy mode, mappings before attaching to a device have SNP
    fields cleared, while mappings after the callback have them set.
    This means partial DMAs are cache coherent while others are not.
    
    One possible fix is replaying mappings and flipping SNP bits when
    attaching a domain to a device. But this seems to be over-engineered,
    given that all real use cases just attach an empty domain to a device.
    
    To meet practical needs while reducing mode differences, only support
    enforce_cache_coherency on a domain without mappings if SNP field is
    used.
    
    Fixes: fc0051cb9590 ("iommu/vt-d: Check domain force_snooping against attached devices")
    Signed-off-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
    Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20231114011036.70142-1-baolu.lu@xxxxxxxxxxxxxxx
    Signed-off-by: Joerg Roedel <jroedel@xxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 4c3707384bd92..744e4e6b8d72d 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2204,6 +2204,8 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
 			attr |= DMA_FL_PTE_DIRTY;
 	}
 
+	domain->has_mappings = true;
+
 	pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | attr;
 
 	while (nr_pages > 0) {
@@ -4309,7 +4311,8 @@ static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
 		return true;
 
 	spin_lock_irqsave(&dmar_domain->lock, flags);
-	if (!domain_support_force_snooping(dmar_domain)) {
+	if (!domain_support_force_snooping(dmar_domain) ||
+	    (!dmar_domain->use_first_level && dmar_domain->has_mappings)) {
 		spin_unlock_irqrestore(&dmar_domain->lock, flags);
 		return false;
 	}
diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h
index 7dac94f62b4ec..e6a3e70656166 100644
--- a/drivers/iommu/intel/iommu.h
+++ b/drivers/iommu/intel/iommu.h
@@ -592,6 +592,9 @@ struct dmar_domain {
 					 * otherwise, goes through the second
 					 * level.
 					 */
+	u8 has_mappings:1;		/* Has mappings configured through
+					 * iommu_map() interface.
+					 */
 
 	spinlock_t lock;		/* Protect device tracking lists */
 	struct list_head devices;	/* all devices' list */




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux