From patchwork Fri Jan 8 12:14:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12006547 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=-12.0 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,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 25AECC433E0 for ; Fri, 8 Jan 2021 12:18:03 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 A725D2388B for ; Fri, 8 Jan 2021 12:18:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A725D2388B 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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id: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=c3EO8SWccgx4DVjMz21AN5sL2ZrHReD4y5/WkqGaPfg=; b=Jpge+5V3ZXRP4nNb+ZCuVf01cK hViRZTS5UxioHS5xcOqYCrobvCL/8HIKBBmvoisHvFrSU1aF5g+0d9N4wrMQCSkV5TX6Q+16GcAGy N/3QAXQY2J3Oke1PbyRSDJ7v68orFKTQC1tNWdkEjM0V8LQRn67vGDJfQdSX0c03Y8yAFv8QbVabo KaZe+lOZpWSRIvTjnSE5kEjMBaPcLB8GMSTkMYRdiK7DGL/MonTcW2aNyBT+LIr8pEqbKAJ5SsMZv 3PObAFreQv/y/phAEfHhIn3J2YpbhpQ7lSzrl7hqBs4/mUrJL0uyWLK9wIY4jCNxaCzxtFEPBOYik 0ewv3F+w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kxqgP-0006fz-JX; Fri, 08 Jan 2021 12:15:57 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kxqfx-0006dN-Bm for linux-arm-kernel@lists.infradead.org; Fri, 08 Jan 2021 12:15:30 +0000 Received: by mail-wr1-x449.google.com with SMTP id w5so4048458wrl.9 for ; Fri, 08 Jan 2021 04:15:27 -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=8jWtBJc1CFcZb+VXrXLCFTBvH9ZyJNX9qmbOUYXXGY0=; b=keePsNtl1E9gJ3ZSMLecqwf/miasl2f7G9Qw05xGjoSrd1phO1u0M4d0sD5gNWCwL3 IfBOoKkoYFErlFOZyuJxN6wX+NukPTNuI4IJ3fFJlV5UvFdOBEkiVdVzLmeqGsNGQMLv Bzr1AVeWxssYqd7azGxpM14RQdhSiD+Avc6I29t/i3hH7HW4xBbAaSPO8SvQxT+ocep7 4rKmwedbo/QeoMedDSlXM8ZHpNoBqGlOvWi6UfcDIe4eP1CI8y2K3jv7IE9KLnkjkpnF abRO3MCs96CHqdlUmHw4pgCBCTMpEe4Jwvt/Dt8S0BDkLff5f66rb5FDGRHmVVqRVmH+ xPZw== 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=8jWtBJc1CFcZb+VXrXLCFTBvH9ZyJNX9qmbOUYXXGY0=; b=PMj5OJCYfK+ftDkATddFDyDz6Se3HYtOC7Uf6uirxrlYVxPjuXKqOLbQsy38prVLuU ckD9cZLf0Wu5KWRKldlATlkalRdN9FA6aHMZC2cj9gOHGlgCxnaDHp3aJOJuwfwPeArw KmkL/oal3LVOf0BPqlB4qU/gb1D93g/+lw4Sf+8ADFNS08/BuhZYUzyJo8Sisn2GWE/G QLx3OXnNYWMSemnVIYmoHKljdlNDZVkhOjURJWUFANUi0Bwtjnr78/Ip8jv18XTiiUKl 1tfL8eahaDO8QR1GV3HQJaXlUWOTCOXbUBl6W9rM6ZAbRh62Ea1LKnNTapGHRsGmFhk5 OumQ== X-Gm-Message-State: AOAM5304DqBYr4p87WQizGgmsHSTT5OnJlCRS+NGJUrW6ZDBAaK855J/ jizH2fDJ0fY5rMQIRwJByl30r1bQ2t47 X-Google-Smtp-Source: ABdhPJwI2qadtflNq64nGgHy8mDYMmobmhMLyzB308p1S4AbE2li7Ch6Zqf20u6+ktNgGnvmYe+pC6V4Gd15 X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a7b:cc94:: with SMTP id p20mr2807021wma.22.1610108126249; Fri, 08 Jan 2021 04:15:26 -0800 (PST) Date: Fri, 8 Jan 2021 12:14:58 +0000 Message-Id: <20210108121524.656872-1-qperret@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [RFC PATCH v2 00/26] KVM/arm64: A stage 2 for the host From: Quentin Perret To: Catalin Marinas , Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Rob Herring , Frank Rowand X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210108_071529_480019_4C7B4D9D X-CRM114-Status: GOOD ( 19.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, android-kvm@google.com, linux-kernel@vger.kernel.org, Fuad Tabba , David Brazdil , kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi all, This is the v2 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]. In short, the changes since v1 include: - Renamed most pkvm-specific pgtable functions as pkvm_* to avoid confusion with the host's (Fuad) - Added an IC flush when switching pgtables (Fuad, Mark) - Cleaned-up the PI aliasing in image-vars.h (David) - Added a TLB flush when enabling the host stage 2 to avoid stale TLBs from bootloader - Fixed the early memory reservation by using NR_CPUS instead of num_possible_cpus() (which is always 1 that early) - Added missing preempt_{dis,en}able() guards in kvm_hyp_enable_protection() - Rebased on latest kvmarm/next And if you'd like a branch that has all the goodies, there it is: https://android-kvm.googlesource.com/linux qperret/host-stage2-v2 Thanks! Quentin [1] https://youtu.be/54q6RzS9BpQ?t=10859 [2] https://kvmforum2020.sched.com/event/eE24/virtualization-for-the-masses-exposing-kvm-on-android-will-deacon-google Quentin Perret (23): 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 of/fdt: Introduce early_init_dt_add_memory_hyp() KVM: arm64: Prepare Hyp memory protection KVM: arm64: Elevate Hyp 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: Wrap the host with a stage 2 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 | 7 + arch/arm64/include/asm/kvm_cpufeature.h | 19 ++ arch/arm64/include/asm/kvm_host.h | 16 +- arch/arm64/include/asm/kvm_hyp.h | 8 + arch/arm64/include/asm/kvm_mmu.h | 69 +++++- arch/arm64/include/asm/kvm_pgtable.h | 41 +++- arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/asm-offsets.c | 3 + arch/arm64/kernel/cpufeature.c | 12 + arch/arm64/kernel/image-vars.h | 33 +++ arch/arm64/kernel/vmlinux.lds.S | 7 + arch/arm64/kvm/arm.c | 144 ++++++++++-- arch/arm64/kvm/hyp/Makefile | 2 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 36 +-- arch/arm64/kvm/hyp/include/nvhe/early_alloc.h | 14 ++ arch/arm64/kvm/hyp/include/nvhe/gfp.h | 32 +++ arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 33 +++ arch/arm64/kvm/hyp/include/nvhe/memory.h | 55 +++++ arch/arm64/kvm/hyp/include/nvhe/mm.h | 107 +++++++++ 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 | 60 +++++ arch/arm64/kvm/hyp/nvhe/hyp-init.S | 41 ++++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 48 ++++ arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 191 ++++++++++++++++ arch/arm64/kvm/hyp/nvhe/mm.c | 174 ++++++++++++++ arch/arm64/kvm/hyp/nvhe/page_alloc.c | 185 +++++++++++++++ arch/arm64/kvm/hyp/nvhe/psci-relay.c | 4 +- arch/arm64/kvm/hyp/nvhe/setup.c | 214 ++++++++++++++++++ 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 | 98 ++++---- arch/arm64/kvm/hyp/reserved_mem.c | 104 +++++++++ arch/arm64/kvm/mmu.c | 114 +++++++++- arch/arm64/kvm/reset.c | 42 +--- arch/arm64/lib/clear_page.S | 4 +- arch/arm64/lib/copy_page.S | 4 +- arch/arm64/mm/init.c | 3 + drivers/of/fdt.c | 5 + 45 files changed, 1954 insertions(+), 145 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