Skip to content

Commit a7f1bc2

Browse files
misalehjoergroedel
authored andcommitted
iommu: debug-pagealloc: Use page_ext_get_from_phys()
Instead of calling pfn_valid() and then getting the page, call the newly added function page_ext_get_from_phys(), which would also check for MMIO and offline memory and return NULL in that case. Signed-off-by: Mostafa Saleh <smostafa@google.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
1 parent d414b83 commit a7f1bc2

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

drivers/iommu/iommu-debug-pagealloc.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,33 @@ struct page_ext_operations page_iommu_debug_ops = {
3030
.need = need_iommu_debug,
3131
};
3232

33-
static struct page_ext *get_iommu_page_ext(phys_addr_t phys)
34-
{
35-
struct page *page = phys_to_page(phys);
36-
struct page_ext *page_ext = page_ext_get(page);
37-
38-
return page_ext;
39-
}
40-
4133
static struct iommu_debug_metadata *get_iommu_data(struct page_ext *page_ext)
4234
{
4335
return page_ext_data(page_ext, &page_iommu_debug_ops);
4436
}
4537

4638
static void iommu_debug_inc_page(phys_addr_t phys)
4739
{
48-
struct page_ext *page_ext = get_iommu_page_ext(phys);
49-
struct iommu_debug_metadata *d = get_iommu_data(page_ext);
40+
struct page_ext *page_ext = page_ext_from_phys(phys);
41+
struct iommu_debug_metadata *d;
42+
43+
if (!page_ext)
44+
return;
5045

46+
d = get_iommu_data(page_ext);
5147
WARN_ON(atomic_inc_return_relaxed(&d->ref) <= 0);
5248
page_ext_put(page_ext);
5349
}
5450

5551
static void iommu_debug_dec_page(phys_addr_t phys)
5652
{
57-
struct page_ext *page_ext = get_iommu_page_ext(phys);
58-
struct iommu_debug_metadata *d = get_iommu_data(page_ext);
53+
struct page_ext *page_ext = page_ext_from_phys(phys);
54+
struct iommu_debug_metadata *d;
55+
56+
if (!page_ext)
57+
return;
5958

59+
d = get_iommu_data(page_ext);
6060
WARN_ON(atomic_dec_return_relaxed(&d->ref) < 0);
6161
page_ext_put(page_ext);
6262
}
@@ -104,11 +104,8 @@ void __iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t siz
104104
if (WARN_ON(!phys || check_add_overflow(phys, size, &end)))
105105
return;
106106

107-
for (off = 0 ; off < size ; off += page_size) {
108-
if (!pfn_valid(__phys_to_pfn(phys + off)))
109-
continue;
107+
for (off = 0 ; off < size ; off += page_size)
110108
iommu_debug_inc_page(phys + off);
111-
}
112109
}
113110

114111
static void __iommu_debug_update_iova(struct iommu_domain *domain,
@@ -123,7 +120,7 @@ static void __iommu_debug_update_iova(struct iommu_domain *domain,
123120
for (off = 0 ; off < size ; off += page_size) {
124121
phys_addr_t phys = iommu_iova_to_phys(domain, iova + off);
125122

126-
if (!phys || !pfn_valid(__phys_to_pfn(phys)))
123+
if (!phys)
127124
continue;
128125

129126
if (inc)

0 commit comments

Comments
 (0)