From patchwork Tue Mar 2 14:59:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12114105 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_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,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 D83FEC433DB for ; Wed, 3 Mar 2021 19:02:41 +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 ACD1F64EEC for ; Wed, 3 Mar 2021 19:02:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ACD1F64EEC 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:Mime-Version:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=EAzekDCzhO4W0HROtVsk0aU0HI92uiSoTcqSBWNKNeY=; b=eDo49xUvsYhHZU1j6GqcOYvG4z 2MoS34L1cldUtT+8ht0CwC8JequlpKigZCwbRx62Z+ZHJ2og5RDy1OCyzhoKX2atHcSijmqlaJJZ3 XTIT5o4qN3PzQt7gOHV5p8VjxNWAU13ywbzcsMVOxnKMzBanPL4KA5+WTYT0NByPh+m4ysSVlfcmD GwrW7oxuK9IxL9ceY2lkLz9g5b6kJQrA67znuQLkdyls1jmket4JAHxzMAX/V84PZzNtn92y28JNb aY29O/eRZGUHS8fy5dhbYL46LvRbOxGPqSoglIZMXshpFCqMAvrm6B05l/+gcwqqbU16Eo+amEtKO 2oGkhPVw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHWj7-0067Wx-06; Wed, 03 Mar 2021 19:00:08 +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 1lHT2A-005Hca-9n for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 15:03:30 +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: Mime-Version:Message-Id:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=8cdx2cy8bS1Yk1hOvoxJoIxgvMKS4vuWA9cIA1RP624=; b=en5ud5u0BUuX4zS8eTAScjDkTf el+bKytpFSgs8SEdKdDNLoBbxSqqWTVWn3j+uj3FRSOgNXLSX8CkQOy3O1DvuCYaRt5wSFY/C1kGU oqSfAHXIhK/tn/xaNlNggY/4DYFOduSYOyakuUTR0prJCONf4EOObytCiQ62YgOp5o0ZJil/Cgwha x35m03RM+MAdFpdjRqWWZObHhfSBgFUi7t35TorT7NXvjkzMkuXUeoso05DsvIzmZFSnmnWZ/wyg5 xX8Nvr6Rfvw54f+8YqzW+ftZkjYrGEAQH4r6j8nU1//lYqdLcmGRzX8GyXuwKEbFq95R1v3gOadup 649BVl1A==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lH6WK-00HJ11-PI for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 15:01:16 +0000 Received: by mail-wm1-x349.google.com with SMTP id a63so691712wmd.8 for ; Tue, 02 Mar 2021 07:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=8cdx2cy8bS1Yk1hOvoxJoIxgvMKS4vuWA9cIA1RP624=; b=YjzVe3TPmAvkQCDj/HWux0EV0FszWglzZrY/X7sQ4PP1pehQ7BRIGiVyN3MLlMr3li huvMmx5Y3nArbKhf91/o25rYsgIu4x+kp2oJMolgK94RuxqGkONc30xK6IKkPeKdw+az 7Vctx4VxHYaXaENho0mlZ7QiMu85gh+Sh420ulaF3seaMGn2jIvBd8X8e+MqGmxTd2M6 1X5vt1fRx59Pb9zdTuS+WO8mkN0JUh4Cwzw9IM1gJ8xOhx9fWpOVEMqhRoA6KH8bDNf6 983WHMNuHeka5//hhYLYRrnsFZTkhhkGTnt5avmFO0K6/pTikDHYzM+l7KGykdTBPC8e FkSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=8cdx2cy8bS1Yk1hOvoxJoIxgvMKS4vuWA9cIA1RP624=; b=B/2Ibcdy4fb38AzOY1lbBrVbLXtKHIsI/Q3422RR2xj7JlHf31eEDLRqM9OHfujl4K X3MumNWw0AMX0pNwsA92o4oda7bskToXTY03NAsjcJC8jxt8CDtNOjVQ5370bo0TjPys L0KwFZyMBgGQSgBPCQK7veJ9H8nxfHPs9UGNud6HWzT0Zx05WSdBPVRZkRNWnrpugDe/ YM89THFvsc0sZ9tUoiG3gXmCiRVZxu/WKwywdqcvfeBHBba0dA1wHn/0yHW7Q3vCXACU iETkLZPpJU3kySkorjK+OlbH7dBMJC2KjxAp4j4K1Wki+yR5LPznSB+76SMhocjuUAZF nJNg== X-Gm-Message-State: AOAM532Vz63m7lwdage8sDJvXunxCB0PJ8/NSs+85Ya7Yv03uFi2rKpt f8rfyeW/4PDE41rc82pN15WqWly0wN+q X-Google-Smtp-Source: ABdhPJwDCkMLeCoT4sUtiPOZrUAgJEKZ4OzzcKOcwzE3U3mmOILtARNPs12yHIt3Rzw7l59VN19/YF8Gf5Xv X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a1c:f006:: with SMTP id a6mr4583157wmb.166.1614697206272; Tue, 02 Mar 2021 07:00:06 -0800 (PST) Date: Tue, 2 Mar 2021 14:59:30 +0000 Message-Id: <20210302150002.3685113-1-qperret@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v3 00/32] KVM: arm64: A stage 2 for the host 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_150116_619335_D42ADC67 X-CRM114-Status: GOOD ( 21.02 ) 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 Hi all, This is the v3 of the series previously posted here: https://lore.kernel.org/kvmarm/20201117181607.1761516-1-qperret@google.com/ This basically allows us to wrap the host with a stage 2 when running in nVHE, hence paving the way for protecting guest memory from the host in the future (among other use-cases). For more details about the motivation and the design angle taken here, I would recommend to have a look at the cover letter of v1, and/or to watch these presentations at LPC [1] and KVM forum 2020 [2]. V3 includes a bunch of clean-ups and small refactorings all over the place as well as a few new features. Specifically, this now allows us to remove memory pages from the host stage 2 cleanly, and this series does so for all the .hyp memory sections (which has uncovered existing bugs upstream and in v2 of this series -- see [3] and [4]). This also now makes good use of block mappings whenever that is possible, and has gotten a bit more testing on real hardware (which helped uncover other bugs [5]). The other changes to v3 include: - clean-ups, refactoring and extra comments all over the place (Will); - dropped fdt hook in favor of memblock API now that the relevant patches ([6]) are merged (Rob); - moved the CPU feature copy stuff to __init/__initdata (Marc); - fixed FWB support (Mate); - rebased on v5.12-rc1. This series depends on Will's vCPU context fix ([5]) and Marc's PMU fixes ([7]). And here's a branch with all the goodies applied: https://android-kvm.googlesource.com/linux qperret/host-stage2-v3 Thanks, Quentin [1] https://youtu.be/54q6RzS9BpQ?t=10859 [2] https://youtu.be/wY-u6n75iXc [3] https://lore.kernel.org/kvmarm/20210203141931.615898-1-qperret@google.com/ [4] https://lore.kernel.org/kvmarm/20210128173850.2478161-1-qperret@google.com/ [5] https://lore.kernel.org/kvmarm/20210226181211.14542-1-will@kernel.org/ [6] https://lore.kernel.org/lkml/20210115114544.1830068-1-qperret@google.com/ [7] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/pmu-undef-NV Quentin Perret (29): KVM: arm64: Initialize kvm_nvhe_init_params early KVM: arm64: Avoid free_page() in page-table allocator KVM: arm64: Factor memory allocation out of pgtable.c KVM: arm64: Introduce a BSS section for use at Hyp KVM: arm64: Make kvm_call_hyp() a function call at Hyp KVM: arm64: Allow using kvm_nvhe_sym() in hyp code KVM: arm64: Introduce an early Hyp page allocator KVM: arm64: Stub CONFIG_DEBUG_LIST at Hyp KVM: arm64: Introduce a Hyp buddy page allocator KVM: arm64: Enable access to sanitized CPU features at EL2 KVM: arm64: Factor out vector address calculation KVM: arm64: Prepare the creation of s1 mappings at EL2 KVM: arm64: Elevate hypervisor mappings creation at EL2 KVM: arm64: Use kvm_arch for stage 2 pgtable KVM: arm64: Use kvm_arch in kvm_s2_mmu KVM: arm64: Set host stage 2 using kvm_nvhe_init_params KVM: arm64: Refactor kvm_arm_setup_stage2() KVM: arm64: Refactor __load_guest_stage2() KVM: arm64: Refactor __populate_fault_info() KVM: arm64: Make memcache anonymous in pgtable allocator KVM: arm64: Reserve memory for host stage 2 KVM: arm64: Sort the hypervisor memblocks KVM: arm64: Introduce PROT_NONE mappings for stage 2 KVM: arm64: Refactor stage2_map_set_prot_attr() KVM: arm64: Add kvm_pgtable_stage2_idmap_greedy() KVM: arm64: Wrap the host with a stage 2 KVM: arm64: Page-align the .hyp sections KVM: arm64: Disable PMU support in protected mode KVM: arm64: Protect the .hyp sections from the host Will Deacon (3): arm64: lib: Annotate {clear,copy}_page() as position-independent KVM: arm64: Link position-independent string routines into .hyp.text arm64: kvm: Add standalone ticket spinlock implementation for use at hyp arch/arm64/include/asm/cpufeature.h | 1 + arch/arm64/include/asm/hyp_image.h | 7 + arch/arm64/include/asm/kvm_asm.h | 9 + arch/arm64/include/asm/kvm_cpufeature.h | 19 ++ arch/arm64/include/asm/kvm_host.h | 19 +- arch/arm64/include/asm/kvm_hyp.h | 8 + arch/arm64/include/asm/kvm_mmu.h | 23 +- arch/arm64/include/asm/kvm_pgtable.h | 117 ++++++- arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/asm-offsets.c | 3 + arch/arm64/kernel/cpufeature.c | 13 + arch/arm64/kernel/image-vars.h | 30 ++ arch/arm64/kernel/vmlinux.lds.S | 74 +++-- arch/arm64/kvm/arm.c | 199 ++++++++++-- arch/arm64/kvm/hyp/Makefile | 2 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 37 ++- arch/arm64/kvm/hyp/include/nvhe/early_alloc.h | 14 + arch/arm64/kvm/hyp/include/nvhe/gfp.h | 55 ++++ arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 36 +++ arch/arm64/kvm/hyp/include/nvhe/memory.h | 52 +++ arch/arm64/kvm/hyp/include/nvhe/mm.h | 92 ++++++ arch/arm64/kvm/hyp/include/nvhe/spinlock.h | 92 ++++++ arch/arm64/kvm/hyp/nvhe/Makefile | 9 +- arch/arm64/kvm/hyp/nvhe/cache.S | 13 + arch/arm64/kvm/hyp/nvhe/cpufeature.c | 8 + arch/arm64/kvm/hyp/nvhe/early_alloc.c | 54 ++++ arch/arm64/kvm/hyp/nvhe/hyp-init.S | 46 ++- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 69 ++++ arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 235 ++++++++++++++ arch/arm64/kvm/hyp/nvhe/mm.c | 173 ++++++++++ arch/arm64/kvm/hyp/nvhe/page_alloc.c | 195 ++++++++++++ arch/arm64/kvm/hyp/nvhe/psci-relay.c | 4 +- arch/arm64/kvm/hyp/nvhe/setup.c | 212 +++++++++++++ arch/arm64/kvm/hyp/nvhe/stub.c | 22 ++ arch/arm64/kvm/hyp/nvhe/switch.c | 12 +- arch/arm64/kvm/hyp/nvhe/tlb.c | 4 +- arch/arm64/kvm/hyp/pgtable.c | 298 ++++++++++++++---- arch/arm64/kvm/hyp/reserved_mem.c | 113 +++++++ arch/arm64/kvm/mmu.c | 115 ++++++- arch/arm64/kvm/perf.c | 3 +- arch/arm64/kvm/pmu.c | 8 +- arch/arm64/kvm/reset.c | 42 +-- arch/arm64/kvm/sys_regs.c | 21 ++ arch/arm64/lib/clear_page.S | 4 +- arch/arm64/lib/copy_page.S | 4 +- arch/arm64/mm/init.c | 3 + 47 files changed, 2356 insertions(+), 215 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_cpufeature.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/early_alloc.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/gfp.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/mem_protect.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/memory.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/mm.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/spinlock.h create mode 100644 arch/arm64/kvm/hyp/nvhe/cache.S create mode 100644 arch/arm64/kvm/hyp/nvhe/cpufeature.c create mode 100644 arch/arm64/kvm/hyp/nvhe/early_alloc.c create mode 100644 arch/arm64/kvm/hyp/nvhe/mem_protect.c create mode 100644 arch/arm64/kvm/hyp/nvhe/mm.c create mode 100644 arch/arm64/kvm/hyp/nvhe/page_alloc.c create mode 100644 arch/arm64/kvm/hyp/nvhe/setup.c create mode 100644 arch/arm64/kvm/hyp/nvhe/stub.c create mode 100644 arch/arm64/kvm/hyp/reserved_mem.c