From patchwork Tue Mar 2 14:59:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12114163 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=-16.8 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, 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 81D71C433DB for ; Wed, 3 Mar 2021 19:52:35 +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 F2D5864EBA for ; Wed, 3 Mar 2021 19:52:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2D5864EBA 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=HIsgB0QaNX35kdh9UYNCfS2ACfudaPbPyL5eQHEGyKU=; b=gf4bZnIVXdzp1d 3+oqAJaD18gOwJulR0alHWH0hXbIAO74p5oSb3ZlYvzSru48Xm7kAtDfu+YWPZyy3OKPO44j/5PRQ 4ldM6uF9HYyuGGG2fUMwULB2ejpYOX0jUY2F1TIXa9Zt+L/XzqZXw5S2oLzLnb+rr9fawxqcRapyK 2kAUWRPfyL4MJdfC+2+CYBPjWlaIKd2St6EhRbasx1ZphJBRaNhhCpl7AGJRVwH9FrIqhC/u4cT9m C9xFQ9QV7FMpGtlMnDIa7V7Fki9ttaUQdKAaTJAG0d5v6a8VTudLkkQpt5q4bY6qGZUciGTYkvlVq Sh7ITCbTslHpEWs3+Bzg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHXVM-006IDI-2i; Wed, 03 Mar 2021 19:49:56 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHT4R-005INy-KT for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 15:05:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0DGi8WZ41csXemjNsmACrndajQddZ4pCIIm4i2MnuBE=; b=i8Ib93cvwz/FA54q0mN+dP6GAk WS5mkB6GJ/WpKoPr68ePPDvJDi4NA80HNRgAe5Gm2sqGSQDIDkb+VtwoQhro7nE//RVrcEmbh9g6/ ae8puTlkXTKCJsBdJXQ/zJELP6ROWRv5M/M/YgzjBAkYOoMzYJpgc97RUsz3OsorqW5+tRIl4obam nP6l0h186WIvRSkQ6S6WAV7FXwt7PoN/ulMd1sbV/eX9Kwlxn7bgPcaTElUwgEwmvcwLiht08BkC6 sR50VbSqdPZwY6mYW8NgGaNHLzXoAXPmqfmS1391/gCb5J5DbhwgoJkbUm1/Kuc63QcHfVvoh+tCS X/WYP2Nw==; Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lH6XU-00HJLZ-Uf for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 15:02:25 +0000 Received: by mail-qt1-x84a.google.com with SMTP id a41so13354306qtk.0 for ; Tue, 02 Mar 2021 07:02:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=0DGi8WZ41csXemjNsmACrndajQddZ4pCIIm4i2MnuBE=; b=NE6Q1GAgjfYI2WSnlZK6ccjnYEU6vpTfApOHpsJa8pc8twhDpFxuOBo32r89W8t2Kc YIB2XzSRTuyKBC2SBUZYIpJ7X4Lwzup0jJUpmkpiEcqkF3y7b0xBe/fYkbHGMCWJVaUl +pZoQqqiNkX+eDaJA/FSLnqVZb4bFe+3fBD3LjgG7dXQpUDq1BampNoAf4Yqpv6jDuu2 qsKdLOcxfPInMZ+6hngaTT3gdvCEg2NqfDhIB467NAn1rkMN9qG1UhjNDSuKBp35gTvX Z0FQb+JQ83j4h0wmWUQ5CY9BbZ2yBx+w4CwV0O68SlSrz6GTdXVcdwtswSt+dQHcseV+ WnsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0DGi8WZ41csXemjNsmACrndajQddZ4pCIIm4i2MnuBE=; b=iQ7kfO2G9xC7kugTrGtSSJOdYrlZrVJdkzEHS+zklbwcNNAdK1rqQBPnszGjcOkUHr 29SFq9FUiuNMmkVSLAwbOUuxs/XqZUj6OJbdTxqbZfUS6VRXcthPuCogmbtROYkA8sVX 34mFWeugFD0XpXseKZEzn00+nU3kKG28qlXX9+8wQfFtk21eBgQ5EGlSCyaV3KH+X/SW ILOXke5kyC4LvL3HK0lUhv5wggGd4/P0FaM0mpv3Jlwp3c6Nh+dZBvLjc4YbyyXtDUsW 2KaYBvI4pgCI2SfCtxsr2KO6+H5ySJV/QA7DXjIzB1gZZsjbno7hZ4pc3vbUEoAo7RtX yLuA== X-Gm-Message-State: AOAM53362B6buxoEsORPW4taqETeZTcWz9mcV5yVfbIoKg/AeTzThVDe iyhpRcYlPn7QbcCDZPNTmPmksgzu0Xce X-Google-Smtp-Source: ABdhPJxW29HrCwNVsnKe95k20fj29Sf36Q0W3cKnVBDqrtxU2VNcdgoeoSV78CPoA72FRV1PB5O9++BrTYke X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a0c:ed45:: with SMTP id v5mr19863045qvq.13.1614697263353; Tue, 02 Mar 2021 07:01:03 -0800 (PST) Date: Tue, 2 Mar 2021 14:59:55 +0000 In-Reply-To: <20210302150002.3685113-1-qperret@google.com> Message-Id: <20210302150002.3685113-26-qperret@google.com> Mime-Version: 1.0 References: <20210302150002.3685113-1-qperret@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v3 25/32] 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_150225_013050_BF15FCD6 X-CRM114-Status: GOOD ( 11.88 ) 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. Signed-off-by: Quentin Perret Acked-by: Will Deacon --- 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; }