From patchwork Thu Dec 2 17:10:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12694539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D00C2C433F5 for ; Thu, 2 Dec 2021 17:12:25 +0000 (UTC) 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DH1TFTJqK2ce2oyLyyTZN00xXQSI0Fdp9DvidtGc5gc=; b=zjUN386dM38CW1 jjHQqwWLILfMwWk1td2IFsWw8gGIOiQhgda03v3DtSNA7Mg4K3X+p0UdalhJlMa2Rqx4pqtbmFbOa Kf3E7tuRkYLBRyaRlmBRoUdaSEGuMZHTBl5W+IvdNgHQihMfFrRvDiNFrP0Eiv1/S0LbUggE2ho/q VmbkkJhnaT4GZmaI8ygY2NgcNULuucW86XFO/lveQKzY5chm+LTQhNT9SJ6kUs1mZPBnKyGPq3bdx bXZUmo2qqFlKKB4tzRWeDa+xQDhhidqSJ4Zr35xuFiTivkGZLrE8z1yQ88eAywXYWHCAlYRgbSL7n EOwa0+0OE2kI8SkQapRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mspbx-00D78u-DF; Thu, 02 Dec 2021 17:11:09 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mspbl-00D75j-1M for linux-arm-kernel@lists.infradead.org; Thu, 02 Dec 2021 17:10:58 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9B51E624DD; Thu, 2 Dec 2021 17:10:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D80AC53FCF; Thu, 2 Dec 2021 17:10:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638465056; bh=g1EJWBrySQ+lD+cn+Gm8JLLcRf3oBr2bg8d/dO69wDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nTDXeXkFFKk2Nfaqs6qfZr/PA3tOSNM0Uj5gs06/um9kg5goxsKZn0sFOGGkb6sAe 5J7EghA9llGtY08nnBh3iKZL/z7AwFmlgujX8HEBsrw2t/pqOHk7rtoy/6GRjWX9Vi IxofJvA2VQCexFHv+GVtO9coopAe25VJ9kf+mlV2X1lYP8UXvsBd/Syam2PYuAXNjD qZEGlpFq+OpD/Bo/oNCB+c1g8CGlC2H9ta4qBasHIrTdToektouP78pffthiAdjKQH e/dDdcCyk5yarG6B6T87BPZRZnwclM73Ix0h6KHIgQKqyshJI+37AxFyhasRmgJnmn nuBNGGK3uvhFA== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, Will Deacon , Alexandru Elisei , James Morse , Quentin Perret , Suzuki K Poulose , Fuad Tabba , Marc Zyngier Subject: [PATCH 1/3] arm64: Add missing include of asm/cpufeature.h to asm/mmu.h Date: Thu, 2 Dec 2021 17:10:46 +0000 Message-Id: <20211202171048.26924-2-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211202171048.26924-1-will@kernel.org> References: <20211202171048.26924-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_091057_137070_2ABB3557 X-CRM114-Status: GOOD ( 10.05 ) 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 asm/mmu.h refers to cpus_have_const_cap() in the definition of arm64_kernel_unmapped_at_el0() so include asm/cpufeature.h directly rather than force all users of the header to do it themselves. Signed-off-by: Will Deacon Tested-by: Fuad Tabba Reviewed-by: Fuad Tabba --- arch/arm64/include/asm/mmu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h index e9c30859f80c..48f8466a4be9 100644 --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -15,6 +15,7 @@ #ifndef __ASSEMBLY__ #include +#include typedef struct { atomic64_t id; From patchwork Thu Dec 2 17:10:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12694540 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 42163C433F5 for ; Thu, 2 Dec 2021 17:12:36 +0000 (UTC) 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vamUxz2l42kyWMQLqPygTMilNk6Ye/WfDaFPfO3kP7Y=; b=h4zhji/FfjQAWH UJUEHwCFGuRiFwRMDMec7WmGKBNwRmhMTJG2L9SttryP5Ugx/3UduqXRj3hLkA8omC25X6AVpmx3Q NQ9goGvj/2XY5HDlgf8blta0ZhzxjgmHMjMNd9mm5PgiBpEcBuhlOPq+v6DYYt/e58NFQ7JUQFZIG qdMj+Rp3KiKiNLZjsEi91RoC0F471tdUImto2SKEMjBZ7n2ODQmLflslj1Gm3favjOO989peHFAzH g3XG+d2IPoPAxy9Vk4i3uPKPsPgybALHj+RpQjXSaTkVrPy625jiUhESTEnpnb4kpUIIM3uEpsPaj x90fiwudYSQs5FhJ5Lig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mspc8-00D7B2-AI; Thu, 02 Dec 2021 17:11:20 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mspbo-00D76b-Pj for linux-arm-kernel@lists.infradead.org; Thu, 02 Dec 2021 17:11:02 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 78CA4B82243; Thu, 2 Dec 2021 17:10:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EBC4C53FD1; Thu, 2 Dec 2021 17:10:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638465058; bh=v3zl9mHxxg1HALqob7r/4qFX7wNgjAZhwam6ujRoXYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IhMSRBAC31b3M+uR2h6BUgD6dSBtG1h5jvckFUOwNENqL8n76zA2hnSIeclNfhBXb 24N1A9Ss8+584XOuZociC2uOnIJKgUS3iu1JRhJ6efa7CFa730fK6cG9amcmggx8Jj 61m41BMVHMmb2sf+Z4w9OHdYVQjndSjzbJ4ff2tApzu1ACjz2sCyeMTGLqzI69pcfZ MAGqo4U++zEp+70th2kq0jrDS2LQkN3ZHPMLNigLUZqWI5XXvHqwjySd5dtNAVBA+v Y7XHquVEX7OcGHW8DXWetBrRF2EzAlpbtXxwpTwn1KebzdtrbMB4muWCEgt3Y6tCJk gIeuZYCKTB3Qg== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, Will Deacon , Alexandru Elisei , James Morse , Quentin Perret , Suzuki K Poulose , Fuad Tabba , Marc Zyngier Subject: [PATCH 2/3] KVM: arm64: Generate hyp_constants.h for the host Date: Thu, 2 Dec 2021 17:10:47 +0000 Message-Id: <20211202171048.26924-3-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211202171048.26924-1-will@kernel.org> References: <20211202171048.26924-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_091101_015200_93AFB150 X-CRM114-Status: GOOD ( 14.43 ) 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 In order to avoid exposing hypervisor (EL2) data structures directly to the host, generate hyp_constants.h to provide constants such as structure sizes to the host without dragging in the definitions themselves. Signed-off-by: Will Deacon Tested-by: Fuad Tabba Reviewed-by: Fuad Tabba --- arch/arm64/kvm/.gitignore | 2 ++ arch/arm64/kvm/Makefile | 16 ++++++++++++++++ arch/arm64/kvm/hyp/hyp-constants.c | 10 ++++++++++ 3 files changed, 28 insertions(+) create mode 100644 arch/arm64/kvm/.gitignore create mode 100644 arch/arm64/kvm/hyp/hyp-constants.c diff --git a/arch/arm64/kvm/.gitignore b/arch/arm64/kvm/.gitignore new file mode 100644 index 000000000000..6182aefb8302 --- /dev/null +++ b/arch/arm64/kvm/.gitignore @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +hyp_constants.h diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile index 989bb5dad2c8..0b561752f8d8 100644 --- a/arch/arm64/kvm/Makefile +++ b/arch/arm64/kvm/Makefile @@ -25,3 +25,19 @@ kvm-y := $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o \ vgic/vgic-its.o vgic/vgic-debug.o kvm-$(CONFIG_HW_PERF_EVENTS) += pmu-emul.o + +always-y := hyp_constants.h hyp-constants.s + +define rule_gen_hyp_constants + $(call filechk,offsets,__HYP_CONSTANTS_H__) +endef + +CFLAGS_hyp-constants.o = -I $(srctree)/$(src)/hyp/include +$(obj)/hyp-constants.s: $(src)/hyp/hyp-constants.c FORCE + $(call if_changed_dep,cc_s_c) + +$(obj)/hyp_constants.h: $(obj)/hyp-constants.s FORCE + $(call if_changed_rule,gen_hyp_constants) + +obj-kvm := $(addprefix $(obj)/, $(kvm-y)) +$(obj-kvm): $(obj)/hyp_constants.h diff --git a/arch/arm64/kvm/hyp/hyp-constants.c b/arch/arm64/kvm/hyp/hyp-constants.c new file mode 100644 index 000000000000..b3742a6691e8 --- /dev/null +++ b/arch/arm64/kvm/hyp/hyp-constants.c @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +int main(void) +{ + DEFINE(STRUCT_HYP_PAGE_SIZE, sizeof(struct hyp_page)); + return 0; +} From patchwork Thu Dec 2 17:10:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12694541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BA9F5C433EF for ; Thu, 2 Dec 2021 17:12:49 +0000 (UTC) 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f2wx/8nzxpDJnRVylFVbpiOKwSP/fH7w29N4A/PHUrA=; b=g8U2W+6L5NSNi9 BGcmVS5N7+omm7p8PRAd/gGALBiwd9gkpZuTBNqrYPdUJ1odQ+c4VqcaSyYk1T2cRHUAIpG3zOQJG tZzUPiQbGUcFY7PqXk9AbjSIGEGby+IbT1TfFBa3hOZu06IOdINuqETgw7grDOP25DGFegjYyPYPG kmZPOEJOYuKXxLOwk9PU+cC9KFJEbPT/ZLuW7yd8xeacqF6zFFmrabYbdMAM7o5CbqOoUL461nk/F asq2oiBT4Qsn7hlEBtlk7z7ej/qiXxg/qOlpkfncRrPAixOggPaMxOJoI7xfyLlHC0DMttdojqWds Kavt6927ZwPjqExH7ONw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mspcI-00D7E7-8B; Thu, 02 Dec 2021 17:11:30 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mspbr-00D77I-57 for linux-arm-kernel@lists.infradead.org; Thu, 02 Dec 2021 17:11:05 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9D583B82428; Thu, 2 Dec 2021 17:11:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB508C53FCB; Thu, 2 Dec 2021 17:10:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638465060; bh=SRBdC/8OTcJxtoyQgOXVMr/P8KKoOzMIfY8JKeFSS8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E3Rt9sGCebuBJ9wvPFriws/HK6eWxMIGWSrR8T0PqzbzvzwFAEVJPik45O2ENbNTZ PdWE/fsg5TjoacPGVQ99fYA9y9E3fhb3K2POoEZAlsbWv0D200F1TNcD++kxW2zp7J 8dpgOTVfKQgZ0UKTkSogpLx89eWO1XGL0Qnp3EUpSS7wRmxPsF+tFhcdGuYV5a3l7J TJbPvRU0wpss5jHJWr10NGmv06lq0c0N5Kt6bJbwdEuAX21PXAtBKyJnSudqyIYQUW YLlMbth3s09qvfS4L4hWDHqfM4qPxgXAx0inbEIMKwDlsNpMDdI3NQSWFjlRtdpZwO vQmfdv6Q2rx/g== From: Will Deacon To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, Will Deacon , Alexandru Elisei , James Morse , Quentin Perret , Suzuki K Poulose , Fuad Tabba , Marc Zyngier Subject: [PATCH 3/3] KVM: arm64: Move host EL1 code out of hyp/ directory Date: Thu, 2 Dec 2021 17:10:48 +0000 Message-Id: <20211202171048.26924-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211202171048.26924-1-will@kernel.org> References: <20211202171048.26924-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_091103_510737_9ADE9407 X-CRM114-Status: GOOD ( 23.34 ) 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 kvm/hyp/reserved_mem.c contains host code executing at EL1 and is not linked into the hypervisor object. Move the file into kvm/pkvm.c and rework the headers so that the definitions shared between the host and the hypervisor live in asm/kvm_pkvm.h. Signed-off-by: Will Deacon Tested-by: Fuad Tabba Reviewed-by: Fuad Tabba --- arch/arm64/include/asm/kvm_pkvm.h | 71 +++++++++++++++++++ arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/hyp/Makefile | 2 +- arch/arm64/kvm/hyp/include/nvhe/mm.h | 57 --------------- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 1 + arch/arm64/kvm/hyp/nvhe/mm.c | 1 + arch/arm64/kvm/hyp/nvhe/setup.c | 1 + arch/arm64/kvm/{hyp/reserved_mem.c => pkvm.c} | 8 +-- 8 files changed, 80 insertions(+), 63 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_pkvm.h rename arch/arm64/kvm/{hyp/reserved_mem.c => pkvm.c} (94%) diff --git a/arch/arm64/include/asm/kvm_pkvm.h b/arch/arm64/include/asm/kvm_pkvm.h new file mode 100644 index 000000000000..9f4ad2a8df59 --- /dev/null +++ b/arch/arm64/include/asm/kvm_pkvm.h @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 - Google LLC + * Author: Quentin Perret + */ +#ifndef __ARM64_KVM_PKVM_H__ +#define __ARM64_KVM_PKVM_H__ + +#include +#include + +#define HYP_MEMBLOCK_REGIONS 128 + +extern struct memblock_region kvm_nvhe_sym(hyp_memory)[]; +extern unsigned int kvm_nvhe_sym(hyp_memblock_nr); + +static inline unsigned long __hyp_pgtable_max_pages(unsigned long nr_pages) +{ + unsigned long total = 0, i; + + /* Provision the worst case scenario */ + for (i = 0; i < KVM_PGTABLE_MAX_LEVELS; i++) { + nr_pages = DIV_ROUND_UP(nr_pages, PTRS_PER_PTE); + total += nr_pages; + } + + return total; +} + +static inline unsigned long __hyp_pgtable_total_pages(void) +{ + unsigned long res = 0, i; + + /* Cover all of memory with page-granularity */ + for (i = 0; i < kvm_nvhe_sym(hyp_memblock_nr); i++) { + struct memblock_region *reg = &kvm_nvhe_sym(hyp_memory)[i]; + 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_pgtable_pages(void) +{ + unsigned long res; + + /* + * Include an extra 16 pages to safely upper-bound the worst case of + * concatenated pgds. + */ + res = __hyp_pgtable_total_pages() + 16; + + /* Allow 1 GiB for MMIO mappings */ + res += __hyp_pgtable_max_pages(SZ_1G >> PAGE_SHIFT); + + return res; +} + +#endif /* __ARM64_KVM_PKVM_H__ */ diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile index 0b561752f8d8..8ca8cf6f5619 100644 --- a/arch/arm64/kvm/Makefile +++ b/arch/arm64/kvm/Makefile @@ -15,7 +15,7 @@ kvm-y := $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o \ arm.o mmu.o mmio.o psci.o perf.o hypercalls.o pvtime.o \ inject_fault.o va_layout.o handle_exit.o \ guest.o debug.o reset.o sys_regs.o \ - vgic-sys-reg-v3.o fpsimd.o pmu.o \ + vgic-sys-reg-v3.o fpsimd.o pmu.o pkvm.o \ arch_timer.o trng.o\ vgic/vgic.o vgic/vgic-init.o \ vgic/vgic-irqfd.o vgic/vgic-v2.o \ diff --git a/arch/arm64/kvm/hyp/Makefile b/arch/arm64/kvm/hyp/Makefile index b726332eec49..687598e41b21 100644 --- a/arch/arm64/kvm/hyp/Makefile +++ b/arch/arm64/kvm/hyp/Makefile @@ -10,4 +10,4 @@ subdir-ccflags-y := -I$(incdir) \ -DDISABLE_BRANCH_PROFILING \ $(DISABLE_STACKLEAK_PLUGIN) -obj-$(CONFIG_KVM) += vhe/ nvhe/ pgtable.o reserved_mem.o +obj-$(CONFIG_KVM) += vhe/ nvhe/ pgtable.o diff --git a/arch/arm64/kvm/hyp/include/nvhe/mm.h b/arch/arm64/kvm/hyp/include/nvhe/mm.h index c9a8f535212e..ef6a58a04235 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mm.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mm.h @@ -10,9 +10,6 @@ #include #include -#define HYP_MEMBLOCK_REGIONS 128 -extern struct memblock_region kvm_nvhe_sym(hyp_memory)[]; -extern unsigned int kvm_nvhe_sym(hyp_memblock_nr); extern struct kvm_pgtable pkvm_pgtable; extern hyp_spinlock_t pkvm_pgd_lock; extern struct hyp_pool hpool; @@ -39,58 +36,4 @@ static inline void hyp_vmemmap_range(phys_addr_t phys, unsigned long size, *end = ALIGN(*end, PAGE_SIZE); } -static inline unsigned long __hyp_pgtable_max_pages(unsigned long nr_pages) -{ - unsigned long total = 0, i; - - /* Provision the worst case scenario */ - for (i = 0; i < KVM_PGTABLE_MAX_LEVELS; i++) { - nr_pages = DIV_ROUND_UP(nr_pages, PTRS_PER_PTE); - total += nr_pages; - } - - return total; -} - -static inline unsigned long __hyp_pgtable_total_pages(void) -{ - unsigned long res = 0, i; - - /* Cover all of memory with page-granularity */ - for (i = 0; i < kvm_nvhe_sym(hyp_memblock_nr); i++) { - struct memblock_region *reg = &kvm_nvhe_sym(hyp_memory)[i]; - 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_pgtable_pages(void) -{ - unsigned long res; - - /* - * Include an extra 16 pages to safely upper-bound the worst case of - * concatenated pgds. - */ - res = __hyp_pgtable_total_pages() + 16; - - /* Allow 1 GiB for MMIO mappings */ - res += __hyp_pgtable_max_pages(SZ_1G >> PAGE_SHIFT); - - return res; -} - #endif /* __KVM_HYP_MM_H */ diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index c1a90dd022b8..92262e89672d 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c index 2fabeceb889a..9e0ff5a700dd 100644 --- a/arch/arm64/kvm/hyp/nvhe/mm.c +++ b/arch/arm64/kvm/hyp/nvhe/mm.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 578f71798c2e..51e68a040d8a 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/arch/arm64/kvm/hyp/reserved_mem.c b/arch/arm64/kvm/pkvm.c similarity index 94% rename from arch/arm64/kvm/hyp/reserved_mem.c rename to arch/arm64/kvm/pkvm.c index 578670e3f608..ebecb7c045f4 100644 --- a/arch/arm64/kvm/hyp/reserved_mem.c +++ b/arch/arm64/kvm/pkvm.c @@ -8,10 +8,9 @@ #include #include -#include +#include -#include -#include +#include "hyp_constants.h" static struct memblock_region *hyp_memory = kvm_nvhe_sym(hyp_memory); static unsigned int *hyp_memblock_nr_ptr = &kvm_nvhe_sym(hyp_memblock_nr); @@ -82,7 +81,8 @@ void __init kvm_hyp_reserve(void) do { prev = nr_pages; nr_pages = hyp_mem_pages + prev; - nr_pages = DIV_ROUND_UP(nr_pages * sizeof(struct hyp_page), PAGE_SIZE); + nr_pages = DIV_ROUND_UP(nr_pages * STRUCT_HYP_PAGE_SIZE, + PAGE_SIZE); nr_pages += __hyp_pgtable_max_pages(nr_pages); } while (nr_pages != prev); hyp_mem_pages += nr_pages;