IOMMU Fixes for Linux v3.16-rc5

A couple of fixes for the Freescale PAMU driver queued up:
 
       * Fix PAMU window size check.
       * Fix the device domain attach condition.
       * Fix the error condition during iommu group
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABAgAGBQJTySEjAAoJECvwRC2XARrjgqYP/0sndB7nTd3qXQX64eY8aGZJ
 3NpZPeiBXIqI04HHkkqA+cGMIHVXluI18tqGC8XpW0oV4pVYfgPv645VuNRu7DtJ
 SEO0LECLkPJFqsRdWqasJezGGl7xEYVLtJasbF2SSXzrbaaEuqQGCpwh6hJ8dehX
 EU3qEMIt1wslVszFwHRAiPefONl4+Oa7DLWZOZ9+0cnylLFVtljGKfk599yO/jXL
 2Gq1ehJCOzDfBnpzD95P6wnMdRk5aBid9AbPKl9jzzTmBm5puEYkDY+hpFNGXmz0
 VUnSe3Jnh7B9TcKG6xv4GjAoraGeofQxNNl8HOjxGzAUERaadKXXA0kF4tPURTwm
 OWFpuz/fpLvruDRg0eBZ/FVnup2USNSy4Dr4VG0Zf/FZfRzaWOur1LnAOgFxga9h
 zcWJG2bfN/UiIRkh1ntTyjI2pAlEFc3Hm0bCG81+S/Fza6AM70iX/KSmjcb3RxWm
 Tv//ie5tABxgBoVJz7itYmC2JHsNp2bbKfuijbpOs8tEe6bLZjTMOM6qtbxOJ9JG
 J9gomxE612lt+Zm78rWt2PEuSqohX7zVJntSTrqk6wTmgO20trb+H7ASl6G11lCj
 LgJmyHRgrjVa8+EviWz9IkWh4pgvsr/HHngvNGXNl1cg+6DDypLO6QnrWEqcAqNK
 pNAvi5w/ZGuhPrPXxpWY
 =Xvdu
 -----END PGP SIGNATURE-----

Merge tag 'iommu-fixes-v3.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu

Pull iommu fixes from Joerg Roedel:
 "A couple of fixes for the Freescale PAMU driver queued up:

   - fix PAMU window size check.
   - fix the device domain attach condition.
   - fix the error condition during iommu group"

* tag 'iommu-fixes-v3.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu:
  iommu/fsl: Fix the error condition during iommu group
  iommu/fsl: Fix the device domain attach condition.
  iommu/fsl: Fix PAMU window size check.
This commit is contained in:
Linus Torvalds 2014-07-18 20:36:13 -10:00
commit 0bae49b24c
2 changed files with 12 additions and 14 deletions

View File

@ -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;
}

View File

@ -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;
}
@ -335,11 +335,6 @@ static struct fsl_dma_domain *iommu_alloc_dma_domain(void)
return domain;
}
static inline struct device_domain_info *find_domain(struct device *dev)
{
return dev->archdata.iommu_domain;
}
static void remove_device_ref(struct device_domain_info *info, u32 win_cnt)
{
unsigned long flags;
@ -380,7 +375,7 @@ static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d
* Check here if the device is already attached to domain or not.
* If the device is already attached to a domain detach it.
*/
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);
@ -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;
spin_unlock_irqrestore(&device_domain_lock, flags);
@ -1042,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;
@ -1070,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);