Re: [PATCH 5/5] iommu/tegra-smmu: Add pagetable mappings to debugfs

Dmitry Osipenko
2020-09-26T21:41:57Z

26.09.2020 23:47, Nicolin Chen пишет:
...
>>> + for (pd_index = 0; pd_index < SMMU_NUM_PDE; pd_index++) {
>>> + struct page *pt;
>>> + u32 *addr;
>>> +
>>> + if (!as->count[pd_index] || !pd[pd_index])
>>> + continue;
>>> +
>>> + pde_count++;
>>> + pte_count += as->count[pd_index];
>>> + seq_printf(s, "\t[%d] 0x%x (%d)\n",
>>> + pd_index, pd[pd_index], as->count[pd_index]);
>>> + pt = as->pts[pd_index];
>>> + addr = page_address(pt);
>>
>> This needs as->lock protection.
>
> Will add that.
>
>>> + seq_puts(s, "\t{\n");
>>> + seq_printf(s, "\t\t%-5s %-4s %12s %12s\n", "PDE", "ATTR", "PHYS", "IOVA");
>>> + for (pt_index = 0; pt_index < SMMU_NUM_PTE; pt_index++) {
>>> + u64 iova;
>>> +
>>> + if (!addr[pt_index])
>>> + continue;
>>> +
>>> + iova = ((dma_addr_t)pd_index & (SMMU_NUM_PDE - 1)) << SMMU_PDE_SHIFT;
>>> + iova |= ((dma_addr_t)pt_index & (SMMU_NUM_PTE - 1)) << SMMU_PTE_SHIFT;
>>> +
>>> + seq_printf(s, "\t\t#%-4d 0x%-4x 0x%-12llx 0x%-12llx\n",
>>> + pt_index, addr[pt_index] >> SMMU_PTE_ATTR_SHIFT,
>>> + SMMU_PFN_PHYS(addr[pt_index] & ~SMMU_PTE_ATTR), iova);

Please also note that the addr[pt_index] needs to be protected as well.
Perhaps you could temporally bump the as->count.