From patchwork Tue Mar 2 14:59:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12113725 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, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 E1AF8C433DB for ; Wed, 3 Mar 2021 15:37:51 +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 79A7464EBD for ; Wed, 3 Mar 2021 15:37:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79A7464EBD 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=89RjxyvnkF/UhMl19r1m3pQFlY4R8n+F+b3F6c1uDwI=; b=GkzxC4cGnmVp5Q rjUFSrDTRKiCFdNfVfhbMlbh284cP2tBuw6T0XbdR2isuqUCdJcwN/tpPBiiG0/qJiTqQDQtv4y0r zw/7WWZyNDyuDwxjvCfWfTWKT8EpSOR2p+zeSQeCzZfupN7uNKpbUTIowjYkYpGe/pFrsCrqrFu27 yHi8mo6PjhGBh2aw0S2si1KENn28L+NVS0famvlnFAbiHTftvcAU63YdkoaF8NBXh5iDJMf87JALr fBTklTUpj4d2RJ3os9lvZDAawAKPobjkffnZ5EoYroV+aOtFrfodslqH5xaSzYm1FWqUNbFLfJCeo 1Mhv27VxU2r00eRp/PDg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHTXA-005PUm-LS; Wed, 03 Mar 2021 15:35:32 +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 1lHSUX-0058BQ-VJ for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 14:28:46 +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=ul+o/tKmUBDOvYf9j24b0RRB4JIOz9FDoTsxVSxSXxM=; b=T0r4g2U+5VlFj5oR8Fxn5K4+XY kWLKgxt/b9rubA0Cq9utFhfw7eodgKwDlxNQWDwMC1EPsXDKtoxEQOjODXWjC8uL8DBZyhZ+X//+2 qui1g0hkwO9jeCV0QpZQQSqCRK0Npxmlw/LmG6OE2BT0YYuxuDDtIKDOhmsLZdeQBtCOa768y7Pyl HUfNC8sAjOxbdZsRTIvSGuovHG7VhtNkbhNok9AWKOy8Gv2novP5dCTY/6y4nNKpBmIqi7UXLQPhy Tu5XhYASZclS7Cj23EXGMSgRRaSMP9mr7ylg495iSiqwlDAXWQ3Xlji+GeQmiQ0refQHlLkq2/Z6L YhJVzFiw==; Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lH6XT-00HJLY-Fr for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 15:02:22 +0000 Received: by mail-qt1-x849.google.com with SMTP id h13so13305990qti.21 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=ul+o/tKmUBDOvYf9j24b0RRB4JIOz9FDoTsxVSxSXxM=; b=pW+u784h5cAco+WjZOeMEiOygQj1G34XbUjvs4ZXhx71GX9qwAHjt8XzF6oHZuDXwa wgH83z4PpOrQySx6tyjngu/mMG9opxnaGjMuW8fPgRw9ksCt32BlXarMT6Il7ZiaqZpn 7mUiXkToZK1hphH6grtrtlOBQCywTGirf+rTHNtbVoZP+um/QY9vdrNEQNwSj0MNJiS+ MIfwIQ4+QJGxoFsu7TAUOUcWNUeh+1aslU2OU1gnPefp+jW4YYjwrcvgJL0BBeFgLTJt L9uyxaiydQT4m4S48zXW72AmDfQx9xnJu2HB5JldL4/g248HlHOYz2ya1frny7PUEufs S6Og== 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=ul+o/tKmUBDOvYf9j24b0RRB4JIOz9FDoTsxVSxSXxM=; b=iTncnmOp/zGm8rakFUhmiEdoquBZvsgJKdSZUb8nB4kRf+zm0bGWIGE//f39DwqyQi r66/a6se3snRMEcSRzm2M9DuT4I9mPXu5XxEAXKyiREnuRlV21cJG/jN1s9K7Jm4bU1F Ex7l+NCKLeckO3zOncUYovJPSXA1s99riV61IbIjFfKpAZZBRtQoDg1SyJplhgPmkHI6 ftUsBC6tXersL2PFd9Sh676NCk2kjcCyTRj0bu64CUXUZ+Pwd7vOJKOxyuJn4zFnovEC KYNxTkSh9Ss0Et7Tg37SwudkFlTQPKrHUaFlpXC1yHnGR9kmGvg5l4sGl4xUKttkTgRK 4rgw== X-Gm-Message-State: AOAM5335Lb1bBkfZSsZhcI94y/Pei5H0kXfOl22L9963gmmc/oRUB4Tt aov1A+oBesbh6fKOM3O75f55w7jja4+u X-Google-Smtp-Source: ABdhPJximV251/TA30yUjyxYuWzjKdxc4ib1kbnL5JjOJcV3XkuAkOyM4ZeRll9baZr9V40/GNB29ZHFcFmT X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a0c:b59f:: with SMTP id g31mr19967030qve.28.1614697260716; Tue, 02 Mar 2021 07:01:00 -0800 (PST) Date: Tue, 2 Mar 2021 14:59:54 +0000 In-Reply-To: <20210302150002.3685113-1-qperret@google.com> Message-Id: <20210302150002.3685113-25-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 24/32] KVM: arm64: Reserve memory for host stage 2 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_150222_237369_0EF559C6 X-CRM114-Status: GOOD ( 14.26 ) 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 Extend the memory pool allocated for the hypervisor to include enough pages to map all of memory at page granularity for the host stage 2. While at it, also reserve some memory for device mappings. Signed-off-by: Quentin Perret Acked-by: Will Deacon --- arch/arm64/kvm/hyp/include/nvhe/mm.h | 23 ++++++++++++++++++++++- arch/arm64/kvm/hyp/nvhe/setup.c | 12 ++++++++++++ arch/arm64/kvm/hyp/reserved_mem.c | 2 ++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mm.h b/arch/arm64/kvm/hyp/include/nvhe/mm.h index ac0f7fcffd08..411a35db949c 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mm.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mm.h @@ -53,7 +53,7 @@ static inline unsigned long __hyp_pgtable_max_pages(unsigned long nr_pages) return total; } -static inline unsigned long hyp_s1_pgtable_pages(void) +static inline unsigned long __hyp_pgtable_total_pages(void) { unsigned long res = 0, i; @@ -63,9 +63,30 @@ static inline unsigned long hyp_s1_pgtable_pages(void) res += __hyp_pgtable_max_pages(reg->size >> PAGE_SHIFT); } + return res; +} + +static inline unsigned long hyp_s1_pgtable_pages(void) +{ + unsigned long res; + + res = __hyp_pgtable_total_pages(); + /* Allow 1 GiB for private mappings */ res += __hyp_pgtable_max_pages(SZ_1G >> PAGE_SHIFT); return res; } + +static inline unsigned long host_s2_mem_pgtable_pages(void) +{ + return __hyp_pgtable_total_pages() + 16; +} + +static inline unsigned long host_s2_dev_pgtable_pages(void) +{ + /* Allow 1 GiB for private mappings */ + return __hyp_pgtable_max_pages(SZ_1G >> PAGE_SHIFT); +} + #endif /* __KVM_HYP_MM_H */ diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 178ec06f2b49..7e923b25271c 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -24,6 +24,8 @@ unsigned long hyp_nr_cpus; static void *vmemmap_base; static void *hyp_pgt_base; +static void *host_s2_mem_pgt_base; +static void *host_s2_dev_pgt_base; static int divide_memory_pool(void *virt, unsigned long size) { @@ -42,6 +44,16 @@ static int divide_memory_pool(void *virt, unsigned long size) if (!hyp_pgt_base) return -ENOMEM; + nr_pages = host_s2_mem_pgtable_pages(); + host_s2_mem_pgt_base = hyp_early_alloc_contig(nr_pages); + if (!host_s2_mem_pgt_base) + return -ENOMEM; + + nr_pages = host_s2_dev_pgtable_pages(); + host_s2_dev_pgt_base = hyp_early_alloc_contig(nr_pages); + if (!host_s2_dev_pgt_base) + return -ENOMEM; + return 0; } diff --git a/arch/arm64/kvm/hyp/reserved_mem.c b/arch/arm64/kvm/hyp/reserved_mem.c index 9bc6a6d27904..fd42705a3c26 100644 --- a/arch/arm64/kvm/hyp/reserved_mem.c +++ b/arch/arm64/kvm/hyp/reserved_mem.c @@ -52,6 +52,8 @@ void __init kvm_hyp_reserve(void) } hyp_mem_pages += hyp_s1_pgtable_pages(); + hyp_mem_pages += host_s2_mem_pgtable_pages(); + hyp_mem_pages += host_s2_dev_pgtable_pages(); /* * The hyp_vmemmap needs to be backed by pages, but these pages