• Quentin Perret's avatar
    KVM: arm64: Prepare the creation of s1 mappings at EL2 · f320bc74
    Quentin Perret authored
    When memory protection is enabled, the EL2 code needs the ability to
    create and manage its own page-table. To do so, introduce a new set of
    hypercalls to bootstrap a memory management system at EL2.
    
    This leads to the following boot flow in nVHE Protected mode:
    
     1. the host allocates memory for the hypervisor very early on, using
        the memblock API;
    
     2. the host creates a set of stage 1 page-table for EL2, installs the
        EL2 vectors, and issues the __pkvm_init hypercall;
    
     3. during __pkvm_init, the hypervisor re-creates its stage 1 page-table
        and stores it in the memory pool provided by the host;
    
     4. the hypervisor then extends its stage 1 mappings to include a
        vmemmap in the EL2 VA space, hence allowing to use the buddy
        allocator introduced in a previous patch;
    
     5. the hypervisor jumps back in the idmap page, switches from the
        host-provided page-table to the new one, and wraps up its
        initialization by enabling the new allocator, before returning to
        the host.
    
     6. the host can free the now unused page-table created for EL2, and
        will now need to issue hypercalls to make changes to the EL2 stage 1
        mappings instead of modifying them directly.
    
    Note that for the sake of simplifying the review, this patch focuses on
    the hypervisor side of things. In other words, this only implements the
    new hypercalls, but does not make use of them from the host yet. The
    host-side changes will follow in a subsequent patch.
    
    Credits to Will for __pkvm_init_switch_pgd.
    Acked-by: default avatarWill Deacon <will@kernel.org>
    Co-authored-by: default avatarWill Deacon <will@kernel.org>
    Signed-off-by: default avatarWill Deacon <will@kernel.org>
    Signed-off-by: default avatarQuentin Perret <qperret@google.com>
    Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
    Link: https://lore.kernel.org/r/20210319100146.1149909-18-qperret@google.com
    f320bc74
mm.c 3.95 KB