Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/pseries/iommu: Fix the VFIO_IOMMU_SPAPR_TCE_GET_INFO ioctl output

The ioctl VFIO_IOMMU_SPAPR_TCE_GET_INFO is not reporting the
actuals on the platform as not all the details are correctly
collected during the platform probe/scan into the iommu_table_group.

Collect the information during the device setup time as the DMA
window property is already looked up on parent nodes anyway.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/171923271138.1397.7908302630061814623.stgit@linux.ibm.com

authored by

Shivaprasad G Bhat and committed by
Michael Ellerman
6af67f2d b09c031d

+67 -14
+67 -14
arch/powerpc/platforms/pseries/iommu.c
··· 865 865 be32_to_cpu(prop.tce_shift), NULL, 866 866 &iommu_table_lpar_multi_ops); 867 867 868 - /* Only for normal boot with default window. Doesn't matter even 869 - * if we set these with DDW which is 64bit during kdump, since 870 - * these will not be used during kdump. 871 - */ 872 - ppci->table_group->tce32_start = be64_to_cpu(prop.dma_base); 873 - ppci->table_group->tce32_size = 1 << be32_to_cpu(prop.window_shift); 874 - 875 868 if (!iommu_init_table(tbl, ppci->phb->node, 0, 0)) 876 869 panic("Failed to initialize iommu table"); 877 870 ··· 1651 1658 return direct_mapping; 1652 1659 } 1653 1660 1661 + static __u64 query_page_size_to_mask(u32 query_page_size) 1662 + { 1663 + const long shift[] = { 1664 + (SZ_4K), (SZ_64K), (SZ_16M), 1665 + (SZ_32M), (SZ_64M), (SZ_128M), 1666 + (SZ_256M), (SZ_16G), (SZ_2M) 1667 + }; 1668 + int i, ret = 0; 1669 + 1670 + for (i = 0; i < ARRAY_SIZE(shift); i++) { 1671 + if (query_page_size & (1 << i)) 1672 + ret |= shift[i]; 1673 + } 1674 + 1675 + return ret; 1676 + } 1677 + 1678 + static void spapr_tce_init_table_group(struct pci_dev *pdev, 1679 + struct device_node *pdn, 1680 + struct dynamic_dma_window_prop prop) 1681 + { 1682 + struct iommu_table_group *table_group = PCI_DN(pdn)->table_group; 1683 + u32 ddw_avail[DDW_APPLICABLE_SIZE]; 1684 + 1685 + struct ddw_query_response query; 1686 + int ret; 1687 + 1688 + /* Only for normal boot with default window. Doesn't matter during 1689 + * kdump, since these will not be used during kdump. 1690 + */ 1691 + if (is_kdump_kernel()) 1692 + return; 1693 + 1694 + if (table_group->max_dynamic_windows_supported != 0) 1695 + return; /* already initialized */ 1696 + 1697 + table_group->tce32_start = be64_to_cpu(prop.dma_base); 1698 + table_group->tce32_size = 1 << be32_to_cpu(prop.window_shift); 1699 + 1700 + if (!of_find_property(pdn, "ibm,dma-window", NULL)) 1701 + dev_err(&pdev->dev, "default dma window missing!\n"); 1702 + 1703 + ret = of_property_read_u32_array(pdn, "ibm,ddw-applicable", 1704 + &ddw_avail[0], DDW_APPLICABLE_SIZE); 1705 + if (ret) { 1706 + table_group->max_dynamic_windows_supported = -1; 1707 + return; 1708 + } 1709 + 1710 + ret = query_ddw(pdev, ddw_avail, &query, pdn); 1711 + if (ret) { 1712 + dev_err(&pdev->dev, "%s: query_ddw failed\n", __func__); 1713 + table_group->max_dynamic_windows_supported = -1; 1714 + return; 1715 + } 1716 + 1717 + if (query.windows_available == 0) 1718 + table_group->max_dynamic_windows_supported = 1; 1719 + else 1720 + table_group->max_dynamic_windows_supported = IOMMU_TABLE_GROUP_MAX_TABLES; 1721 + 1722 + table_group->max_levels = 1; 1723 + table_group->pgsizes |= query_page_size_to_mask(query.page_size); 1724 + } 1725 + 1654 1726 static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev) 1655 1727 { 1656 1728 struct device_node *pdn, *dn; ··· 1755 1697 be32_to_cpu(prop.tce_shift), NULL, 1756 1698 &iommu_table_lpar_multi_ops); 1757 1699 1758 - /* Only for normal boot with default window. Doesn't matter even 1759 - * if we set these with DDW which is 64bit during kdump, since 1760 - * these will not be used during kdump. 1761 - */ 1762 - pci->table_group->tce32_start = be64_to_cpu(prop.dma_base); 1763 - pci->table_group->tce32_size = 1 << be32_to_cpu(prop.window_shift); 1764 - 1765 1700 iommu_init_table(tbl, pci->phb->node, 0, 0); 1766 1701 iommu_register_group(pci->table_group, 1767 1702 pci_domain_nr(pci->phb->bus), 0); ··· 1762 1711 } else { 1763 1712 pr_debug(" found DMA window, table: %p\n", pci->table_group); 1764 1713 } 1714 + 1715 + spapr_tce_init_table_group(dev, pdn, prop); 1765 1716 1766 1717 set_iommu_table_base(&dev->dev, pci->table_group->tables[0]); 1767 1718 iommu_add_device(pci->table_group, &dev->dev);