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

iommu/io-pgtable-arm: Fix table descriptor paddr formatting

Table descriptors were being installed without properly formatting the
address using paddr_to_iopte, which does not match up with the
iopte_deref in __arm_lpae_map. This is incorrect for the LPAE pte
format, as it does not handle the high bits properly.

This was found on Apple T6000 DARTs, which require a new pte format
(different shift); adding support for that to
paddr_to_iopte/iopte_to_paddr caused it to break badly, as even <48-bit
addresses would end up incorrect in that case.

Fixes: 6c89928ff7a0 ("iommu/io-pgtable-arm: Support 52-bit physical address")
Acked-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Hector Martin <marcan@marcan.st>
Link: https://lore.kernel.org/r/20211120031343.88034-1-marcan@marcan.st
Signed-off-by: Joerg Roedel <jroedel@suse.de>

authored by

Hector Martin and committed by
Joerg Roedel
9abe2ac8 556f99ac

+5 -4
+5 -4
drivers/iommu/io-pgtable-arm.c
··· 315 315 static arm_lpae_iopte arm_lpae_install_table(arm_lpae_iopte *table, 316 316 arm_lpae_iopte *ptep, 317 317 arm_lpae_iopte curr, 318 - struct io_pgtable_cfg *cfg) 318 + struct arm_lpae_io_pgtable *data) 319 319 { 320 320 arm_lpae_iopte old, new; 321 + struct io_pgtable_cfg *cfg = &data->iop.cfg; 321 322 322 - new = __pa(table) | ARM_LPAE_PTE_TYPE_TABLE; 323 + new = paddr_to_iopte(__pa(table), data) | ARM_LPAE_PTE_TYPE_TABLE; 323 324 if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_NS) 324 325 new |= ARM_LPAE_PTE_NSTABLE; 325 326 ··· 381 380 if (!cptep) 382 381 return -ENOMEM; 383 382 384 - pte = arm_lpae_install_table(cptep, ptep, 0, cfg); 383 + pte = arm_lpae_install_table(cptep, ptep, 0, data); 385 384 if (pte) 386 385 __arm_lpae_free_pages(cptep, tblsz, cfg); 387 386 } else if (!cfg->coherent_walk && !(pte & ARM_LPAE_PTE_SW_SYNC)) { ··· 593 592 __arm_lpae_init_pte(data, blk_paddr, pte, lvl, 1, &tablep[i]); 594 593 } 595 594 596 - pte = arm_lpae_install_table(tablep, ptep, blk_pte, cfg); 595 + pte = arm_lpae_install_table(tablep, ptep, blk_pte, data); 597 596 if (pte != blk_pte) { 598 597 __arm_lpae_free_pages(tablep, tablesz, cfg); 599 598 /*