iommu/amd: Misc cleanup and trivial fixes
Subsystems (2)
Vasant Hegde
maintainercover iommu/amd: Misc cleanup and trivial fixes
This series contains misc cleanup and trivial fixes.
This series is based on top of iommu/next branch.
-Vasant
Vasant Hegde (8):
iommu/amd: Update event log pointer as soon as processing is complete iommu/amd: Make amd_iommu_is_attach_deferred() static iommu/amd: Remove unused DTE_GCR3_INDEX_* macros iommu/amd: Handle error path in amd_iommu_probe_device() iommu/amd: Make amd_iommu_dev_flush_pasid_all() static iommu/amd: Make amd_iommu_domain_flush_complete() static iommu/amd: Rework amd_iommu_update_and_flush_device_table() iommu/amd: Make amd_iommu_dev_update_dte() static
drivers/iommu/amd/amd_iommu.h | 5 -- drivers/iommu/amd/amd_iommu_types.h | 4 -- drivers/iommu/amd/io_pgtable.c | 1 - drivers/iommu/amd/iommu.c | 87 ++++++++++++++--------------- 4 files changed, 41 insertions(+), 56 deletions(-)
base-commit: 0e922e0fecffdb8e0f5ea9c00754f65a17e5a535
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 1/8 iommu/amd: Update event log pointer as soon as processing is complete
Update event buffer head pointer once driver completes processing. So that IOMMU can write new log without waiting for driver to complete processing all event logs.
--- drivers/iommu/amd/iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +3 -1
@@ -825,10 +825,12 @@ static void iommu_poll_events(struct amd_iommu *iommu)while (head != tail) {iommu_print_event (iommu, iommu->evt_buf + head); + +/* Update head pointer of hardware ring-buffer */ head = (head +EVENT_ENTRY_SIZE ) %EVT_BUFFER_SIZE ; +writel (head, iommu->mmio_base +MMIO_EVT_HEAD_OFFSET ); } -writel (head, iommu->mmio_base +MMIO_EVT_HEAD_OFFSET ); }#ifdef CONFIG_IRQ_REMAP
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 2/8 iommu/amd: Make amd_iommu_is_attach_deferred() static
In reply to Vasant Hegdeamd_iommu_is_attach_deferred() is a callback function called by iommu_ops. Make it as static.
No functional changes intended.
--- drivers/iommu/amd/amd_iommu.h | 1 - drivers/iommu/amd/iommu.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/amd/amd_iommu.h +0 -1
@@ -180,7 +180,6 @@ static inline struct protection_domain *to_pdomain(struct iommu_domain *dom) }bool translation_pre_enabled (struct amd_iommu *iommu); -bool amd_iommu_is_attach_deferred (struct device *dev);int __init add_special_device (u8 type,u8 id,u32 *devid,bool cmd_line);#ifdef CONFIG_DMI
drivers/iommu/amd/iommu.c +1 -1
@@ -2785,7 +2785,7 @@ static void amd_iommu_get_resv_regions(struct device *dev,list_add_tail (®ion->list, head); } -bool amd_iommu_is_attach_deferred (struct device *dev) +static bool amd_iommu_is_attach_deferred (struct device *dev) {struct iommu_dev_data *dev_data =dev_iommu_priv_get (dev);
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 3/8 iommu/amd: Remove unused DTE_GCR3_INDEX_* macros
In reply to Vasant HegdeIt was added in commit 52815b75682e ("iommu/amd: Add support for IOMMUv2 domain mode"), but never used it. Hence remove these unused macros.
--- drivers/iommu/amd/amd_iommu_types.h | 4 ---- 1 file changed, 4 deletions(-)
drivers/iommu/amd/amd_iommu_types.h +0 -4
@@ -415,10 +415,6 @@#define DTE_GCR3_VAL_B (x) (((x) >> 15) & 0x0ffffULL)#define DTE_GCR3_VAL_C (x) (((x) >> 31) & 0x1fffffULL) -#define DTE_GCR3_INDEX_A 0 -#define DTE_GCR3_INDEX_B 1 -#define DTE_GCR3_INDEX_C 1 -#define DTE_GCR3_SHIFT_A 58#define DTE_GCR3_SHIFT_B 16#define DTE_GCR3_SHIFT_C 43
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 4/8 iommu/amd: Handle error path in amd_iommu_probe_device()
In reply to Vasant HegdeDo not try to set max_pasids in error path as dev_data is not allocated.
--- drivers/iommu/amd/iommu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/iommu/amd/iommu.c +7 -5
@@ -2187,11 +2187,12 @@ static struct iommu_device *amd_iommu_probe_device(struct device *dev)dev_err (dev,"Failed to initialize - trying to proceed anyway\n" ); iommu_dev =ERR_PTR (ret);iommu_ignore_device (iommu, dev); - }else { -amd_iommu_set_pci_msi_domain (dev, iommu); - iommu_dev = &iommu->iommu; + goto out_err; } +amd_iommu_set_pci_msi_domain (dev, iommu); + iommu_dev = &iommu->iommu; +/* * If IOMMU and device supports PASID then it will contain max * supported PASIDs, else it will be zero.
@@ -2203,11 +2204,12 @@ static struct iommu_device *amd_iommu_probe_device(struct device *dev) pci_max_pasids(to_pci_dev(dev))); } -iommu_completion_wait (iommu); -if (dev_is_pci (dev))pci_prepare_ats (to_pci_dev (dev),PAGE_SHIFT ); +out_err: +iommu_completion_wait (iommu); +return iommu_dev; }
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 5/8 iommu/amd: Make amd_iommu_dev_flush_pasid_all() static
In reply to Vasant HegdeAs its not used outside iommu.c. Also rename it as dev_flush_pasid_all().
No functional change intended.
--- drivers/iommu/amd/amd_iommu.h | 2 -- drivers/iommu/amd/iommu.c | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/iommu/amd/amd_iommu.h +0 -2
@@ -93,8 +93,6 @@ void amd_iommu_domain_flush_pages(struct protection_domain *domain, u64 address, size_t size);void amd_iommu_dev_flush_pasid_pages (struct iommu_dev_data *dev_data,ioasid_t pasid,u64 address,size_t size); -void amd_iommu_dev_flush_pasid_all (struct iommu_dev_data *dev_data, -ioasid_t pasid);#ifdef CONFIG_IRQ_REMAP int amd_iommu_create_irq_domain (struct amd_iommu *iommu);
drivers/iommu/amd/iommu.c +3 -3
@@ -1551,8 +1551,8 @@ void amd_iommu_dev_flush_pasid_pages(struct iommu_dev_data *dev_data,iommu_completion_wait (iommu); } -void amd_iommu_dev_flush_pasid_all (struct iommu_dev_data *dev_data, -ioasid_t pasid) +static void dev_flush_pasid_all (struct iommu_dev_data *dev_data, +ioasid_t pasid) {amd_iommu_dev_flush_pasid_pages (dev_data,0 ,CMD_INV_IOMMU_ALL_PAGES_ADDRESS , pasid);
@@ -1818,7 +1818,7 @@ static int update_gcr3(struct iommu_dev_data *dev_data,else *pte =0 ; -amd_iommu_dev_flush_pasid_all (dev_data, pasid); +dev_flush_pasid_all (dev_data, pasid);return 0 ; }
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 6/8 iommu/amd: Make amd_iommu_domain_flush_complete() static
In reply to Vasant HegdeAMD driver uses amd_iommu_domain_flush_complete() function to make sure IOMMU processed invalidation commands before proceeding. Ideally this should be called from functions which updates DTE/invalidates caches. There is no need to call this function explicitly. This patches makes below changes :
- Rename amd_iommu_domain_flush_complete() -> domain_flush_complete() and make it as static function.
- Rearrage domain_flush_complete() to avoid forward declaration.
- Update amd_iommu_update_and_flush_device_table() to call domain_flush_complete().
--- drivers/iommu/amd/amd_iommu.h | 1 - drivers/iommu/amd/io_pgtable.c | 1 - drivers/iommu/amd/iommu.c | 37 +++++++++++++++++----------------- 3 files changed, 19 insertions(+), 20 deletions(-)
drivers/iommu/amd/amd_iommu.h +0 -1
@@ -88,7 +88,6 @@ void amd_iommu_flush_all_caches(struct amd_iommu *iommu);void amd_iommu_update_and_flush_device_table (struct protection_domain *domain);void amd_iommu_domain_update (struct protection_domain *domain);void amd_iommu_dev_update_dte (struct iommu_dev_data *dev_data,bool set); -void amd_iommu_domain_flush_complete (struct protection_domain *domain);void amd_iommu_domain_flush_pages (struct protection_domain *domain,u64 address,size_t size); void amd_iommu_dev_flush_pasid_pages(struct iommu_dev_data *dev_data,
drivers/iommu/amd/io_pgtable.c +0 -1
@@ -175,7 +175,6 @@ static bool increase_address_space(struct protection_domain *domain, domain->iop.root = pte; domain->iop.mode +=1 ;amd_iommu_update_and_flush_device_table (domain); -amd_iommu_domain_flush_complete (domain);/* * Device Table needs to be updated and flushed before the new root can
drivers/iommu/amd/iommu.c +19 -18
@@ -1249,6 +1249,22 @@ static int iommu_completion_wait(struct amd_iommu *iommu)return ret; } +static void domain_flush_complete (struct protection_domain *domain) +{ +int i; + +for (i =0 ; i <amd_iommu_get_num_iommus (); ++i) { +if (domain && !domain->dev_iommu[i]) +continue ; + +/* +* Devices of this domain are behind this IOMMU +* We need to wait for completion of all commands. +*/ +iommu_completion_wait (amd_iommus[i]); + } +} +static int iommu_flush_dte (struct amd_iommu *iommu,u16 devid) {struct iommu_cmd cmd;
@@ -1485,7 +1501,7 @@ void amd_iommu_domain_flush_pages(struct protection_domain *domain,__domain_flush_pages (domain, address, size);/* Wait until IOMMU TLB and all device IOTLB flushes are complete */ -amd_iommu_domain_flush_complete (domain); +domain_flush_complete (domain);return ; }
@@ -1525,7 +1541,7 @@ void amd_iommu_domain_flush_pages(struct protection_domain *domain, }/* Wait until IOMMU TLB and all device IOTLB flushes are complete */ -amd_iommu_domain_flush_complete (domain); +domain_flush_complete (domain); }/* Flush the whole IO/TLB for a given protection domain - including PDE */
@@ -1558,22 +1574,6 @@ static void dev_flush_pasid_all(struct iommu_dev_data *dev_data, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, pasid); } -void amd_iommu_domain_flush_complete (struct protection_domain *domain) -{ -int i; - -for (i =0 ; i <amd_iommu_get_num_iommus (); ++i) { -if (domain && !domain->dev_iommu[i]) -continue ; - -/* -* Devices of this domain are behind this IOMMU -* We need to wait for completion of all commands. -*/ -iommu_completion_wait (amd_iommus[i]); - } -} -/* Flush the not present cache if it exists */ static void domain_flush_np_cache (struct protection_domain *domain,dma_addr_t iova,size_t size)
@@ -1615,6 +1615,7 @@ void amd_iommu_update_and_flush_device_table(struct protection_domain *domain) {update_device_table (domain);domain_flush_devices (domain); +domain_flush_complete (domain); }void amd_iommu_domain_update (struct protection_domain *domain)
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 7/8 iommu/amd: Rework amd_iommu_update_and_flush_device_table()
In reply to Vasant HegdeRemove separate function to update and flush the device table as only amd_iommu_update_and_flush_device_table() calls these functions.
No functional changes intended.
--- drivers/iommu/amd/iommu.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/iommu/amd/iommu.c +4 -14
@@ -1591,15 +1591,7 @@ static void domain_flush_np_cache(struct protection_domain *domain,/* * This function flushes the DTEs for all devices in domain */ -static void domain_flush_devices (struct protection_domain *domain) -{ -struct iommu_dev_data *dev_data; - -list_for_each_entry (dev_data, &domain->dev_list, list) -device_flush_dte (dev_data); -} - -static void update_device_table (struct protection_domain *domain) +void amd_iommu_update_and_flush_device_table (struct protection_domain *domain) {struct iommu_dev_data *dev_data;
@@ -1609,12 +1601,10 @@ static void update_device_table(struct protection_domain *domain)set_dte_entry (iommu, dev_data);clone_aliases (iommu, dev_data->dev); } -} -void amd_iommu_update_and_flush_device_table (struct protection_domain *domain) -{ -update_device_table (domain); -domain_flush_devices (domain); +list_for_each_entry (dev_data, &domain->dev_list, list) +device_flush_dte (dev_data); +domain_flush_complete (domain); }
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 8/8 iommu/amd: Make amd_iommu_dev_update_dte() static
In reply to Vasant HegdeAs its used inside iommu.c only. Also rename function to dev_update_dte() as its static function.
No functional changes intended.
--- drivers/iommu/amd/amd_iommu.h | 1 - drivers/iommu/amd/iommu.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/iommu/amd/amd_iommu.h +0 -1
@@ -87,7 +87,6 @@ int amd_iommu_complete_ppr(struct device *dev, u32 pasid, int status, int tag);void amd_iommu_flush_all_caches (struct amd_iommu *iommu);void amd_iommu_update_and_flush_device_table (struct protection_domain *domain);void amd_iommu_domain_update (struct protection_domain *domain); -void amd_iommu_dev_update_dte (struct iommu_dev_data *dev_data,bool set);void amd_iommu_domain_flush_pages (struct protection_domain *domain,u64 address,size_t size); void amd_iommu_dev_flush_pasid_pages(struct iommu_dev_data *dev_data,
drivers/iommu/amd/iommu.c +4 -4
@@ -1955,7 +1955,7 @@ static void clear_dte_entry(struct amd_iommu *iommu, u16 devid) }/* Update and flush DTE for the given device */ -void amd_iommu_dev_update_dte (struct iommu_dev_data *dev_data,bool set) +static void dev_update_dte (struct iommu_dev_data *dev_data,bool set) {struct amd_iommu *iommu =get_amd_iommu_from_dev (dev_data->dev);
@@ -2055,7 +2055,7 @@ static void do_detach(struct iommu_dev_data *dev_data)struct amd_iommu *iommu =get_amd_iommu_from_dev_data (dev_data);/* Clear DTE and flush the entry */ -amd_iommu_dev_update_dte (dev_data, false); +dev_update_dte (dev_data, false);/* Flush IOTLB and wait for the flushes to finish */ amd_iommu_domain_flush_all (domain);
@@ -2470,7 +2470,7 @@ static int blocked_domain_attach_device(struct iommu_domain *domain,/* Clear DTE and flush the entry */ spin_lock (&dev_data->lock); -amd_iommu_dev_update_dte (dev_data, false); +dev_update_dte (dev_data, false);spin_unlock (&dev_data->lock);return 0 ;
@@ -2538,7 +2538,7 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, }/* Update device table */ -amd_iommu_dev_update_dte (dev_data, true); +dev_update_dte (dev_data, true);return ret; }
Signature · 1 line
2.31.1
Quoted 9 lines · Vasant Hegde
Vasant Hegde (8):
iommu/amd: Update event log pointer as soon as processing is complete iommu/amd: Makeamd_iommu_is_attach_deferred()static iommu/amd: Remove unused DTE_GCR3_INDEX_* macros iommu/amd: Handle error path inamd_iommu_probe_device()iommu/amd: Makeamd_iommu_dev_flush_pasid_all()static iommu/amd: Makeamd_iommu_domain_flush_complete()static iommu/amd: Reworkamd_iommu_update_and_flush_device_table()iommu/amd: Makeamd_iommu_dev_update_dte()static
Applied, thanks.