iommu/fsl: Fixes for the PAMU driver.
cover iommu/fsl: Fixes for the PAMU driver.
This patch set contains fixes for the PAMU driver. The patches are based on 3.16-rc1.
Varun Sethi (3):
Fix PAMU window size check.
Fix the device domain attach condition.
Fix the error condition during iommu group creation.
drivers/iommu/fsl_pamu.c | 8 ++++---- drivers/iommu/fsl_pamu_domain.c | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/3 iommu/fsl: Fix PAMU window size check.
is_power_of_2 requires an unsigned long parameter which would lead to truncation of 64 bit values on 32 bit architectures.
__ffs also expects an unsigned long parameter thus won't work for 64 bit values on 32 bit architectures.
--- drivers/iommu/fsl_pamu.c | 8 ++++---- drivers/iommu/fsl_pamu_domain.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/iommu/fsl_pamu.c +4 -4
@@ -170,10 +170,10 @@ int pamu_disable_liodn(int liodn)static unsigned int map_addrspace_size_to_wse (phys_addr_t addrspace_size) {/* Bug if not a power of 2 */ -BUG_ON (!is_power_of_2 (addrspace_size)); +BUG_ON ((addrspace_size & (addrspace_size -1 )));/* window size is 2^(WSE+1) bytes */ -return __ffs (addrspace_size) -1 ; +return fls64 (addrspace_size) -2 ; }/* Derive the PAACE window count encoding for the subwindow count */
@@ -351,7 +351,7 @@ int pamu_config_ppaace(int liodn, phys_addr_t win_addr, phys_addr_t win_size,struct paace *ppaace;unsigned long fspi; -if (!is_power_of_2 (win_size) || win_size <PAMU_PAGE_SIZE ) { +if ((win_size & (win_size -1 )) || win_size <PAMU_PAGE_SIZE ) {pr_debug ("window size too small or not a power of two %llx\n" , win_size);return -EINVAL ; }
@@ -464,7 +464,7 @@ int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 subwin,return -ENOENT ; } -if (!is_power_of_2 (subwin_size) || subwin_size <PAMU_PAGE_SIZE ) { +if ((subwin_size & (subwin_size -1 )) || subwin_size <PAMU_PAGE_SIZE ) {pr_debug ("subwindow size out of range, or not a power of 2\n" );return -EINVAL ; }
drivers/iommu/fsl_pamu_domain.c +1 -1
@@ -301,7 +301,7 @@ static int check_size(u64 size, dma_addr_t iova)* Size must be a power of two and at least be equal * to PAMU page size. */ -if (!is_power_of_2 (size) || size <PAMU_PAGE_SIZE ) { +if ((size & (size -1 )) || size <PAMU_PAGE_SIZE ) {pr_debug ("%s: size too small or not a power of two\n" , __func__);return -EINVAL ; }
Signature · 1 line
1.7.9.5
PATCH 2/3 iommu/fsl: Fix the device domain attach condition.
In reply to Varun SethiPATCH 3/3 iommu/fsl: Fix the error condition during iommu group
In reply to Varun SethiEarlier PTR_ERR was being returned even if group was set to null. Now, we explicitly set an ERR_PTR value in case the group pointer is NULL.
--- drivers/iommu/fsl_pamu_domain.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iommu/fsl_pamu_domain.c +5 -2
@@ -1037,12 +1037,15 @@ root_bus: group =get_shared_pci_device_group (pdev); } +if (!group) + group =ERR_PTR (-ENODEV ); +return group; }static int fsl_pamu_add_device (struct device *dev) { -struct iommu_group *group =NULL ; +struct iommu_group *group =ERR_PTR (-ENODEV );struct pci_dev *pdev;const u32 *prop;int ret, len;
@@ -1065,7 +1068,7 @@ static int fsl_pamu_add_device(struct device *dev) group =get_device_iommu_group (dev); } -if (!group ||IS_ERR (group)) +if (IS_ERR (group))return PTR_ERR (group); ret =iommu_group_add_device (group, dev);
Signature · 1 line
1.7.9.5
Emil Medve
Tested-byRe: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.
In reply to a message not in the archiveQuoted 11 lines · Varun Sethi
is_power_of_2requires an unsigned long parameter which would lead to truncation of 64 bit values on 32 bit architectures.
__ffsalso expects an unsigned long parameter thus won't work for 64 bit values on 32 bit architectures.Signed-off-by Varun Sethi <[email protected]>--- drivers/iommu/fsl_pamu.c | 8 ++++---- drivers/iommu/fsl_pamu_domain.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
On a P4080 DS (i.e. 32-bit SoC)
Cheers,
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
RE: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.
Thanks Emil.
Quoted 27 lines
-----Original Message-----
From: Emil Medve [mailto:[email protected]]
Sent: Wednesday, July 02, 2014 1:16 PM
To: Sethi Varun-B16395; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; [email protected]; [email protected]; linuxppc- dev-uLR06cmDAlY/[email protected]; [email protected]
Subject: Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.Quoted 11 lines · Varun Sethi
is_power_of_2requires an unsigned long parameter which would lead to truncation of 64 bit values on 32 bit architectures.
__ffsalso expects an unsigned long parameter thus won't work for 64 bit values on 32 bit architectures.Signed-off-by Varun Sethi <[email protected]>--- drivers/iommu/fsl_pamu.c | 8 ++++---- drivers/iommu/fsl_pamu_domain.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)Tested-by Emil Medve <[email protected]>On a P4080 DS (i.e. 32-bit SoC)
Cheers,
Joerg Roedel
maintainerRe: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.
In reply to Varun Sethidrivers/iommu/fsl_pamu.c int pamu_disable_liodn(int liodn) · line 176
Quoted 3 lines · Varun Sethi
drivers/iommu/fsl_pamu.c +1
-1/* window size is 2^(WSE+1) bytes */ -return __ffs (addrspace_size) -1 ; +return fls64 (addrspace_size) -2 ;
This looks bogus, why do you replace ffs (find-first-bit) by fls (find-last-bit)?
Joerg
Joerg Roedel
maintainerRe: [PATCH 2/3] iommu/fsl: Fix the device domain attach condition.
In reply to Varun SethiHmm,
Review
Quoted 5 lines · Varun Sethi
(quoted diff) +1
-1- old_domain_info = find_domain(dev); + old_domain_info = dev->archdata.iommu_domain; if (old_domain_info && old_domain_info->domain != dma_domain) { spin_unlock_irqrestore(&device_domain_lock, flags); detach_device(dev, old_domain_info->domain);
Wouldn't this set dev->archdata.iommu_domain to NULL anyway, so that ...
Review static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d · line 398
Quoted 7 lines
(quoted diff) +1
-1@@ -399,7 +394,7 @@ static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d * the info for the first LIODN as all * LIODNs share the same domain */ - if (!old_domain_info) + if (!dev->archdata.iommu_domain) dev->archdata.iommu_domain = info;
We already know that it _must_ be NULL here?
Review static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d · line 399
Quoted 1 line
(quoted diff) +0
-0spin_unlock_irqrestore(&device_domain_lock, flags);
This would shrink down the patch to:
drivers/iommu/fsl_pamu_domain.c +1 -2
@@ -399,8 +399,7 @@ static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d* the info for the first LIODN as all * LIODNs share the same domain */ -if (!old_domain_info) - dev->archdata.iommu_domain = info; + dev->archdata.iommu_domain = info;spin_unlock_irqrestore (&device_domain_lock, flags); }
RE: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.
In reply to Joerg RoedelQuoted 10 lines
-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Friday, July 04, 2014 4:15 PM
To: Sethi Varun-B16395
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; [email protected]; linuxppc-dev-uLR06cmDAlY/[email protected]; [email protected]
Subject: Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.
Quoted 8 lines
drivers/iommu/fsl_pamu.c int pamu_disable_liodn(int liodn) · line 176
Quoted 3 lines · Varun Sethi
drivers/iommu/fsl_pamu.c +1
-1/* window size is 2^(WSE+1) bytes */ -return __ffs (addrspace_size) -1 ; +return fls64 (addrspace_size) -2 ;This looks bogus, why do you replace ffs (find-first-bit) by fls (find- last-bit)?
Address space size is always a power of 2. This change was required to handle address sizes > 32bit width on 32 bit architectures.
-Varun
RE: [PATCH 2/3] iommu/fsl: Fix the device domain attach condition.
In reply to Joerg RoedelQuoted 13 lines
-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Friday, July 04, 2014 4:25 PM
To: Sethi Varun-B16395
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; [email protected]; linuxppc-dev-uLR06cmDAlY/[email protected]; [email protected]
Subject: Re: [PATCH 2/3] iommu/fsl: Fix the device domain attach
condition.Hmm,
Quoted 9 lines
Review
Quoted 5 lines · Varun Sethi
(quoted diff) +1
-1- old_domain_info = find_domain(dev); + old_domain_info = dev->archdata.iommu_domain; if (old_domain_info && old_domain_info->domain != dma_domain) { spin_unlock_irqrestore(&device_domain_lock, flags); detach_device(dev, old_domain_info->domain);Wouldn't this set
dev->archdata.iommu_domainto NULL anyway, so that ...
Not for the case where device has multiple LIODNs.
Quoted 11 lines
Review static void attach_device(struct fsl_dma_domain
Quoted 1 line
(quoted diff) +0
-0@@ -399,7 +394,7 @@ static void attach_device(struct fsl_dma_domain
*dma_domain, int liodn, struct ddrivers/iommu/fsl_pamu_domain.c static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d
Quoted 6 lines
drivers/iommu/fsl_pamu_domain.c +1
-1* the info for the first LIODN as all * LIODNs share the same domain */ -if (!old_domain_info) +if (!dev->archdata.iommu_domain) dev->archdata.iommu_domain = info;We already know that it _must_ be NULL here?
That won't be true for devices having multiple LIODNs
Quoted 9 lines
drivers/iommu/fsl_pamu_domain.c static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d · line 403
Quoted 1 line
drivers/iommu/fsl_pamu_domain.c +0
-0spin_unlock_irqrestore (&device_domain_lock, flags);This would shrink down the patch to:
(quoted diff) +0
-0
b/drivers/iommu/fsl_pamu_domain.cindex 93072ba..d21b554 100644
drivers/iommu/fsl_pamu_domain.c static void attach_device(struct fsl_dma_domain · line 403
Quoted 7 lines
drivers/iommu/fsl_pamu_domain.c +1
-2@@ -399,8 +399,7 @@ static void attach_device(struct fsl_dma_domain*dma_domain, int liodn, struct d * the info for the first LIODN as all * LIODNs share the same domain */ -if (!old_domain_info) - dev->archdata.iommu_domain = info; + dev->archdata.iommu_domain = info;
For devices having multiple LIODNs, we don't want to overwrite the info.
-Varun
Quoted 11 lines · Varun Sethi
This patch set contains fixes for the PAMU driver. The patches are based on 3.16-rc1.
Varun Sethi (3):
Fix PAMU window size check.
Fix the device domain attach condition.
Fix the error condition during iommu group creation.drivers/iommu/fsl_pamu.c | 8 ++++---- drivers/iommu/fsl_pamu_domain.c | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-)
Applied to iommu/fixes, thanks.
Thanks Joerg.
Quoted 23 lines
-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Monday, July 07, 2014 2:02 PM
To: Sethi Varun-B16395
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; [email protected]; linuxppc-dev-uLR06cmDAlY/[email protected]; [email protected]
Subject: Re: [PATCH 0/3] iommu/fsl: Fixes for the PAMU driver.Quoted 11 lines · Varun Sethi
This patch set contains fixes for the PAMU driver. The patches are based on 3.16-rc1.
Varun Sethi (3):
Fix PAMU window size check.
Fix the device domain attach condition.
Fix the error condition during iommu group creation.drivers/iommu/fsl_pamu.c | 8 ++++---- drivers/iommu/fsl_pamu_domain.c | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-)Applied to iommu/fixes, thanks.