Skip to content

Commit 14ecf07

Browse files
David BrazdilMarc Zyngier
authored andcommitted
KVM: arm64: Minor optimization of range_is_memory
Currently range_is_memory finds the corresponding struct memblock_region for both the lower and upper bounds of the given address range with two rounds of binary search, and then checks that the two memblocks are the same. Simplify this by only doing binary search on the lower bound and then checking that the upper bound is in the same memblock. Signed-off-by: David Brazdil <[email protected]> Reviewed-by: Quentin Perret <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fb1c16c commit 14ecf07

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

arch/arm64/kvm/hyp/nvhe/mem_protect.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,19 @@ bool addr_is_memory(phys_addr_t phys)
204204
return find_mem_range(phys, &range);
205205
}
206206

207+
static bool is_in_mem_range(u64 addr, struct kvm_mem_range *range)
208+
{
209+
return range->start <= addr && addr < range->end;
210+
}
211+
207212
static bool range_is_memory(u64 start, u64 end)
208213
{
209-
struct kvm_mem_range r1, r2;
214+
struct kvm_mem_range r;
210215

211-
if (!find_mem_range(start, &r1) || !find_mem_range(end - 1, &r2))
212-
return false;
213-
if (r1.start != r2.start)
216+
if (!find_mem_range(start, &r))
214217
return false;
215218

216-
return true;
219+
return is_in_mem_range(end - 1, &r);
217220
}
218221

219222
static inline int __host_stage2_idmap(u64 start, u64 end,

0 commit comments

Comments
 (0)