From: Quentin Perret <qperret@google.com>
To: David Brazdil <dbrazdil@google.com>
Cc: kvmarm@lists.cs.columbia.edu, Marc Zyngier <maz@kernel.org>,
James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: arm64: Minor optimization of range_is_memory
Date: Thu, 29 Jul 2021 18:00:23 +0100 [thread overview]
Message-ID: <YQLep2cwhyzWu2cL@google.com> (raw)
In-Reply-To: <20210728153232.1018911-3-dbrazdil@google.com>
On Wednesday 28 Jul 2021 at 15:32:32 (+0000), David Brazdil wrote:
> 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 <dbrazdil@google.com>
> ---
> arch/arm64/kvm/hyp/nvhe/mem_protect.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> index a6ce991b1467..37d73af69634 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> @@ -189,13 +189,18 @@ static bool find_mem_range(phys_addr_t addr, struct kvm_mem_range *range)
> return false;
> }
>
> +static bool is_in_mem_range(phys_addr_t addr, struct kvm_mem_range *range)
> +{
Nit: addr@ could be u64 for consistency -- struct kvm_mem_range holds
IPAs in general.
> + return range->start <= addr && addr < range->end;
> +}
> +
> static bool range_is_memory(u64 start, u64 end)
> {
> - struct kvm_mem_range r1, r2;
> + struct kvm_mem_range r;
>
> - if (!find_mem_range(start, &r1) || !find_mem_range(end - 1, &r2))
> + if (!find_mem_range(start, &r))
> return false;
> - if (r1.start != r2.start)
> + if (!is_in_mem_range(end - 1, &r))
> return false;
>
> return true;
Nit: maybe drop the second if and simplify to:
return is_in_mem_range(end - 1, &r);
With that:
Reviewed-by: Quentin Perret <qperret@google.com>
Thanks,
Quentin
next prev parent reply other threads:[~2021-07-29 17:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-28 15:32 [PATCH 0/2] Fix off-by-one in range_is_memory David Brazdil
2021-07-28 15:32 ` [PATCH 1/2] KVM: arm64: " David Brazdil
2021-07-29 16:52 ` Quentin Perret
2021-07-28 15:32 ` [PATCH 2/2] KVM: arm64: Minor optimization of range_is_memory David Brazdil
2021-07-29 17:00 ` Quentin Perret [this message]
2021-08-20 11:05 ` (subset) [PATCH 0/2] Fix off-by-one in range_is_memory Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YQLep2cwhyzWu2cL@google.com \
--to=qperret@google.com \
--cc=alexandru.elisei@arm.com \
--cc=catalin.marinas@arm.com \
--cc=dbrazdil@google.com \
--cc=james.morse@arm.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).