Skip to content

Commit 7ae31ce

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu/iova: Add rbtree entry helper
Repeating the rb_entry() boilerplate all over the place gets old fast. Before adding yet more instances, add a little hepler to tidy it up. Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/03931d86c0ad71f44b29394e3a8d38bfc32349cd.1614962123.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent 3542dcb commit 7ae31ce

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

drivers/iommu/iova.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ static void fq_destroy_all_entries(struct iova_domain *iovad);
2727
static void fq_flush_timeout(struct timer_list *t);
2828
static void free_global_cached_iovas(struct iova_domain *iovad);
2929

30+
static struct iova *to_iova(struct rb_node *node)
31+
{
32+
return rb_entry(node, struct iova, node);
33+
}
34+
3035
void
3136
init_iova_domain(struct iova_domain *iovad, unsigned long granule,
3237
unsigned long start_pfn)
@@ -136,15 +141,15 @@ __cached_rbnode_delete_update(struct iova_domain *iovad, struct iova *free)
136141
{
137142
struct iova *cached_iova;
138143

139-
cached_iova = rb_entry(iovad->cached32_node, struct iova, node);
144+
cached_iova = to_iova(iovad->cached32_node);
140145
if (free == cached_iova ||
141146
(free->pfn_hi < iovad->dma_32bit_pfn &&
142147
free->pfn_lo >= cached_iova->pfn_lo)) {
143148
iovad->cached32_node = rb_next(&free->node);
144149
iovad->max32_alloc_size = iovad->dma_32bit_pfn;
145150
}
146151

147-
cached_iova = rb_entry(iovad->cached_node, struct iova, node);
152+
cached_iova = to_iova(iovad->cached_node);
148153
if (free->pfn_lo >= cached_iova->pfn_lo)
149154
iovad->cached_node = rb_next(&free->node);
150155
}
@@ -159,7 +164,7 @@ iova_insert_rbtree(struct rb_root *root, struct iova *iova,
159164
new = (start) ? &start : &(root->rb_node);
160165
/* Figure out where to put new node */
161166
while (*new) {
162-
struct iova *this = rb_entry(*new, struct iova, node);
167+
struct iova *this = to_iova(*new);
163168

164169
parent = *new;
165170

@@ -198,7 +203,7 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad,
198203
goto iova32_full;
199204

200205
curr = __get_cached_rbnode(iovad, limit_pfn);
201-
curr_iova = rb_entry(curr, struct iova, node);
206+
curr_iova = to_iova(curr);
202207
retry_pfn = curr_iova->pfn_hi + 1;
203208

204209
retry:
@@ -207,15 +212,15 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad,
207212
new_pfn = (high_pfn - size) & align_mask;
208213
prev = curr;
209214
curr = rb_prev(curr);
210-
curr_iova = rb_entry(curr, struct iova, node);
215+
curr_iova = to_iova(curr);
211216
} while (curr && new_pfn <= curr_iova->pfn_hi && new_pfn >= low_pfn);
212217

213218
if (high_pfn < size || new_pfn < low_pfn) {
214219
if (low_pfn == iovad->start_pfn && retry_pfn < limit_pfn) {
215220
high_pfn = limit_pfn;
216221
low_pfn = retry_pfn;
217222
curr = &iovad->anchor.node;
218-
curr_iova = rb_entry(curr, struct iova, node);
223+
curr_iova = to_iova(curr);
219224
goto retry;
220225
}
221226
iovad->max32_alloc_size = size;
@@ -331,7 +336,7 @@ private_find_iova(struct iova_domain *iovad, unsigned long pfn)
331336
assert_spin_locked(&iovad->iova_rbtree_lock);
332337

333338
while (node) {
334-
struct iova *iova = rb_entry(node, struct iova, node);
339+
struct iova *iova = to_iova(node);
335340

336341
if (pfn < iova->pfn_lo)
337342
node = node->rb_left;
@@ -617,7 +622,7 @@ static int
617622
__is_range_overlap(struct rb_node *node,
618623
unsigned long pfn_lo, unsigned long pfn_hi)
619624
{
620-
struct iova *iova = rb_entry(node, struct iova, node);
625+
struct iova *iova = to_iova(node);
621626

622627
if ((pfn_lo <= iova->pfn_hi) && (pfn_hi >= iova->pfn_lo))
623628
return 1;
@@ -685,7 +690,7 @@ reserve_iova(struct iova_domain *iovad,
685690
spin_lock_irqsave(&iovad->iova_rbtree_lock, flags);
686691
for (node = rb_first(&iovad->rbroot); node; node = rb_next(node)) {
687692
if (__is_range_overlap(node, pfn_lo, pfn_hi)) {
688-
iova = rb_entry(node, struct iova, node);
693+
iova = to_iova(node);
689694
__adjust_overlap_range(iova, &pfn_lo, &pfn_hi);
690695
if ((pfn_lo >= iova->pfn_lo) &&
691696
(pfn_hi <= iova->pfn_hi))

0 commit comments

Comments
 (0)