2014-06-24 14:16:24

by Varun Sethi

[permalink] [raw]
Subject: [PATCH 0/3] 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(-)

--
1.7.9.5


2014-06-24 17:17:20

by Varun Sethi

[permalink] [raw]
Subject: [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.

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(-)

diff --git a/drivers/iommu/fsl_pamu.c b/drivers/iommu/fsl_pamu.c
index b99dd88..bb446d7 100644
--- a/drivers/iommu/fsl_pamu.c
+++ b/drivers/iommu/fsl_pamu.c
@@ -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;
}
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 93072ba..3dd0b8e 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -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;
}
--
1.7.9.5

2014-06-24 18:31:05

by Varun Sethi

[permalink] [raw]
Subject: [PATCH 3/3] iommu/fsl: Fix the error condition during iommu group

Earlier 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.

Signed-off-by: Varun Sethi <[email protected]>
---
drivers/iommu/fsl_pamu_domain.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 54060d1..af47648 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -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);
--
1.7.9.5

2014-07-02 07:56:40

by Emil Medve

[permalink] [raw]
Subject: Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.

On 06/24/2014 08:57 AM, Varun Sethi wrote:
> 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.
>
> 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,

2014-07-02 08:59:40

by Varun Sethi

[permalink] [raw]
Subject: RE: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.

Thanks Emil.

> -----Original Message-----
> From: Emil Medve [mailto:[email protected]]
> Sent: Wednesday, July 02, 2014 1:16 PM
> To: Sethi Varun-B16395; [email protected];
> [email protected]; [email protected]; linuxppc-
> [email protected]; [email protected]
> Subject: Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.
>
> On 06/24/2014 08:57 AM, Varun Sethi wrote:
> > 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.
> >
> > 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,
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2014-07-04 10:44:34

by Joerg Roedel

[permalink] [raw]
Subject: Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.

On Tue, Jun 24, 2014 at 07:27:15PM +0530, Varun Sethi wrote:
> /* 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

2014-07-04 10:54:36

by Joerg Roedel

[permalink] [raw]
Subject: Re: [PATCH 2/3] iommu/fsl: Fix the device domain attach condition.

Hmm,

On Tue, Jun 24, 2014 at 07:27:16PM +0530, Varun Sethi wrote:
> - 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 ...

> @@ -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?

> spin_unlock_irqrestore(&device_domain_lock, flags);

This would shrink down the patch to:

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 93072ba..d21b554 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -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);

}

2014-07-04 12:47:50

by Varun Sethi

[permalink] [raw]
Subject: RE: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.



> -----Original Message-----
> From: Joerg Roedel [mailto:[email protected]]
> Sent: Friday, July 04, 2014 4:15 PM
> To: Sethi Varun-B16395
> Cc: [email protected]; [email protected];
> [email protected]; [email protected]
> Subject: Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.
>
> On Tue, Jun 24, 2014 at 07:27:15PM +0530, Varun Sethi wrote:
> > /* 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

2014-07-04 12:50:32

by Varun Sethi

[permalink] [raw]
Subject: RE: [PATCH 2/3] iommu/fsl: Fix the device domain attach condition.



> -----Original Message-----
> From: Joerg Roedel [mailto:[email protected]]
> Sent: Friday, July 04, 2014 4:25 PM
> To: Sethi Varun-B16395
> Cc: [email protected]; [email protected];
> [email protected]; [email protected]
> Subject: Re: [PATCH 2/3] iommu/fsl: Fix the device domain attach
> condition.
>
> Hmm,
>
> On Tue, Jun 24, 2014 at 07:27:16PM +0530, Varun Sethi wrote:
> > - 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 ...
>
Not for the case where device has multiple LIODNs.

> > @@ -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?
>

That won't be true for devices having multiple LIODNs

> > spin_unlock_irqrestore(&device_domain_lock, flags);
>
> This would shrink down the patch to:
>
> diff --git a/drivers/iommu/fsl_pamu_domain.c
> b/drivers/iommu/fsl_pamu_domain.c index 93072ba..d21b554 100644
> --- a/drivers/iommu/fsl_pamu_domain.c
> +++ b/drivers/iommu/fsl_pamu_domain.c
> @@ -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

2014-07-07 08:32:22

by Joerg Roedel

[permalink] [raw]
Subject: Re: [PATCH 0/3] iommu/fsl: Fixes for the PAMU driver.

On Tue, Jun 24, 2014 at 07:27:14PM +0530, Varun Sethi wrote:
> 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.

2014-07-07 08:55:20

by Varun Sethi

[permalink] [raw]
Subject: RE: [PATCH 0/3] iommu/fsl: Fixes for the PAMU driver.

Thanks Joerg.

> -----Original Message-----
> From: Joerg Roedel [mailto:[email protected]]
> Sent: Monday, July 07, 2014 2:02 PM
> To: Sethi Varun-B16395
> Cc: [email protected]; [email protected];
> [email protected]; [email protected]
> Subject: Re: [PATCH 0/3] iommu/fsl: Fixes for the PAMU driver.
>
> On Tue, Jun 24, 2014 at 07:27:14PM +0530, Varun Sethi wrote:
> > 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.
>