From patchwork Wed Mar 10 17:57:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12128937 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.0 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 8C504C433E0 for ; Wed, 10 Mar 2021 18:10:21 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 B4E6464FB2 for ; Wed, 10 Mar 2021 18:10:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B4E6464FB2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=Kze//MFsyT3Rtg1i+50RQX1iypYzGC7rkSMrsAIfqXM=; b=f+TBLkRzx2injF ILZWm/ihPSPa2Eqyy3T3Pct8jYAOt2bG2cu25/PPO2UnorvNr2XvWvhJpQnO6GFZow6Bw8eN11mpX ww0bccOrYcZKxQmSwXBfbtv5QMUb5rW17q/BhDHQFpA+l2JUyFcVj2K3g2Mpz+AlgJL6ulWmjZmac vgYz2GYEbzGHL7F61C2eIYz1VWbL7ovEmASHXlxzwnRUzfLaKtbu6iKrbQc9IE8oVHUrqrkHcnSeU LCEsAymW3oefFqu+UP79NVMpETMw1lY5H7naaRBZV8FIDKRVMe1HvgmK5kj9DGxfVAUrZU6KDTFs4 sUhoeys+b2Oul6gbzrZw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lK3Fe-007SBI-RK; Wed, 10 Mar 2021 18:08:07 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lK36j-007ORI-Mv for linux-arm-kernel@lists.infradead.org; Wed, 10 Mar 2021 17:58:56 +0000 Received: by mail-qt1-x849.google.com with SMTP id l63so10081425qtd.23 for ; Wed, 10 Mar 2021 09:58:53 -0800 (PST) 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=qkIv/Dj8eNtVWTw/hqhsYIXxQswk0/NCtZ2mXt61vt4=; b=Yd6qXdpHhKJCGS2nS6b73itvEp4TXHoB4WqOXle6O5tLkJBJPw/XtiPR/uKeu43swS 2hvS/aF6Anvw1YMOPyb5/0LqiiPvfB0aL64RNhlAz42c75kMdBUkplEzK+yFBXNQ6fyQ J/nbBIcWvsjxT1kGPNG/ru1ol04BtoCNsl4j5yN3RA+BegfK37UCg92KsBMRdyqOwIKd jYHjj6ABnTFkH96MW2j3xNeVLtIeiTKy+FdXKciOBIb7A4k5eusNa3eNL2V3Pe6/NjVY Cfa4vxJHinlwjdhhlyquWiYMJZUzIssWJwFW9dFCLf208MYkzWGv7Z4GyP9hNnulY8Hr GKdQ== 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=qkIv/Dj8eNtVWTw/hqhsYIXxQswk0/NCtZ2mXt61vt4=; b=s16ozOmYCYNQ+nl6yq2Pzkj9/B3Fj5SH0Tp65qXe3AGLLiVlrdFRNtJVBnd+8VI+66 C0TT3YeJaczurlU5TUtRP3wjP7SLFwv/9bUUiOr5SqBhq2sei3NEHv2TS+AWA8SgdQlY AQeuYymm2/fST66eESJ9nBZUjIfPnQhUn+yFsFB6vJOdl1C/UiDwvkMLM6+n8VjqycBa GDXg5p/Sl+VX4JI3WwKrZm+e420OO8/jVIfrf2pmBJPXtEkRS8haCw+0/saOStdZVVhL fPmaqdLbQg0Xh7tTft8ds+b5D75S+fsWCG9T9LOrAQMU4rScR7AlIGw8xbH6D/X0amZ9 krBA== X-Gm-Message-State: AOAM530bnjERZc/otLlORay14X3+267CRpiR/BcNnm9ZVvyZTWOm3j3T lWrcw1X4Dr8pH4igaYyBzZrZjehbjJad X-Google-Smtp-Source: ABdhPJxlCTx9p7rzRSKY5hPCMXHH9PbCR3/vxNwiQaM6JpLBZ/W3y1yrQSuLj+BwkUwpvNqFCqkE++nkXuKm X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a05:6214:1909:: with SMTP id er9mr4159347qvb.5.1615399132338; Wed, 10 Mar 2021 09:58:52 -0800 (PST) Date: Wed, 10 Mar 2021 17:57:43 +0000 In-Reply-To: <20210310175751.3320106-1-qperret@google.com> Message-Id: <20210310175751.3320106-27-qperret@google.com> Mime-Version: 1.0 References: <20210310175751.3320106-1-qperret@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v4 26/34] KVM: arm64: Sort the hypervisor memblocks From: Quentin Perret To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Cc: android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, qperret@google.com, robh+dt@kernel.org, ardb@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210310_175854_078877_E543F25D X-CRM114-Status: GOOD ( 12.20 ) 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 We will soon need to check if a Physical Address belongs to a memblock at EL2, so make sure to sort them so this can be done efficiently. Acked-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/reserved_mem.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/arm64/kvm/hyp/reserved_mem.c b/arch/arm64/kvm/hyp/reserved_mem.c index fd42705a3c26..83ca23ac259b 100644 --- a/arch/arm64/kvm/hyp/reserved_mem.c +++ b/arch/arm64/kvm/hyp/reserved_mem.c @@ -6,6 +6,7 @@ #include #include +#include #include @@ -18,6 +19,23 @@ static unsigned int *hyp_memblock_nr_ptr = &kvm_nvhe_sym(hyp_memblock_nr); phys_addr_t hyp_mem_base; phys_addr_t hyp_mem_size; +static int cmp_hyp_memblock(const void *p1, const void *p2) +{ + const struct memblock_region *r1 = p1; + const struct memblock_region *r2 = p2; + + return r1->base < r2->base ? -1 : (r1->base > r2->base); +} + +static void __init sort_memblock_regions(void) +{ + sort(hyp_memory, + *hyp_memblock_nr_ptr, + sizeof(struct memblock_region), + cmp_hyp_memblock, + NULL); +} + static int __init register_memblock_regions(void) { struct memblock_region *reg; @@ -29,6 +47,7 @@ static int __init register_memblock_regions(void) hyp_memory[*hyp_memblock_nr_ptr] = *reg; (*hyp_memblock_nr_ptr)++; } + sort_memblock_regions(); return 0; }