From patchwork Wed Jul 28 15:32:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 12406197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D91BC4338F for ; Wed, 28 Jul 2021 15:35:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3138460F91 for ; Wed, 28 Jul 2021 15:35:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3138460F91 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=DCW/LfphghUV3zP8AgcQR0BuTV9zuqp55k9EFZTkGoQ=; b=y2DJi//o8QYwcdxRo2uMr6+mOM pN62/n8TaJlq0DTJFohsadsy2vhNm+cQZUnzLLHEGAn+HmW0ewde2cwI6QODSH2WED8JFO1RR5/rc Tvt04A+kh8Oj/Adt5E04COxk5Fd9Y411tNP7mVBzJlLRSo0Rz1OgmGSd7o2f7yslviHj0LDzNCmsx cZceLNSe56tJAnN43739CsfR4NwwS9xClPgIcqf3CPw9N0V+CKb+TcxWcukV9fzIlxvWXbELTyLja WPjkb4pk0NFEfodsdoapt5lzWwbQOqOQcHTpdBD38SeKs3LuaqENnFlfzkT7VAXrlR1FJTqlAEJx0 Z3MCYNQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8lYX-001KAh-0j; Wed, 28 Jul 2021 15:33:13 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8lY6-001K2O-Ft for linux-arm-kernel@lists.infradead.org; Wed, 28 Jul 2021 15:32:47 +0000 Received: by mail-wr1-x449.google.com with SMTP id n1-20020a5d59810000b029013cd60e9baaso1077635wri.7 for ; Wed, 28 Jul 2021 08:32:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qzw4XcX4w+ny84Qln9d15Ry0/+5tfssrXUUN0rRDVVc=; b=G3I/3fhsNE6Og2SNbp7xijYfhxbbi8EEXzZO7tjVLLwHEwaGAf2WH4WDSAI9RuBK2v y7MINQTjeOU9oU90HjjguDGAwa4tof8t/8vq/m2JE5pv2a/YNi09Y4IPEqg/Mq+fBEPD Z0d/8fw19uWXRPZVYkNEbf40fgTfDWXSKtSXKuEpcdnImMph1V/8lTDcxryYsvCOGEJx bdhwsqESBm+n86hEdsfP11ImWIAtFpMKBxxxA86Z4l4ZbGbeKxemOU97Z+VC4VrnXV3V xL3tHvSnAfmB7Ax5kGhpV8zZqSzrsqsT6CwvAXBclwHpCvv307H5rs9J7qPyzU9u9jLx Izwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qzw4XcX4w+ny84Qln9d15Ry0/+5tfssrXUUN0rRDVVc=; b=XbnEmPU5C9baYxDlRVN54RrElHci27mXuAz7csQRchXF22S97e0hYxTjXbSqhiB6rF fo76fR7HlJDZSiIb5woOAcFiDPm2JDqign4G76r8VVokYS4g0RuEJHO94Ch8YCj6Tj2o hVEaSxu7+KmJ179m+8oAomtpJwv1CYQRvtuIV8zMDFLfgjz09eCJw3xK5oYvjMclnxIt pz4DkgzLoPWpo2aGxJmNpGUuAM99YEscGxTMmFMbL9QHPrn9bDtecsSrgbA2kQw7d9+q xiN2JI9VdA/vWyfsMBrsE9SnFWIMKZzHO2i7+szW69Vs/xyUzBTNV0S4GyYzdesdOrG9 YOjA== X-Gm-Message-State: AOAM533ray6sbXvs10gRExt28VYN3MLULuTneqFSbD8WaA6hZF/vd+z2 1o4nmZqDogqnKIL2Urpiz5H6Pjmh6Or4CQ== X-Google-Smtp-Source: ABdhPJx3RYSTCqCub5lOGXrHgg5jPvAqfn3GPah0zCRIxkTx6aci9KeM6XDoX5DGxOYQRxwXx1QUpmsxtpyJMg== X-Received: from dbrazdil.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:7f9b]) (user=dbrazdil job=sendgmr) by 2002:a05:600c:4101:: with SMTP id j1mr308618wmi.110.1627486363975; Wed, 28 Jul 2021 08:32:43 -0700 (PDT) Date: Wed, 28 Jul 2021 15:32:32 +0000 In-Reply-To: <20210728153232.1018911-1-dbrazdil@google.com> Message-Id: <20210728153232.1018911-3-dbrazdil@google.com> Mime-Version: 1.0 References: <20210728153232.1018911-1-dbrazdil@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH 2/2] KVM: arm64: Minor optimization of range_is_memory From: David Brazdil To: kvmarm@lists.cs.columbia.edu Cc: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Quentin Perret , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, David Brazdil X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210728_083246_561074_94F677FB X-CRM114-Status: GOOD ( 12.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Quentin Perret --- 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) +{ + 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;