Skip to content

Commit

Permalink
plat/kvm/arm: Add pagetables for Firecracker
Browse files Browse the repository at this point in the history
The memory map of Firecracker on Arm64 is:

0x0000000000000000 - 0x000000007fffffff     Devices:     0 -    2GiB
0x0000000080000000 - 0x000000ffffffffff     DRAM:     2GiB - 1024GiB

https://github.com/firecracker-microvm/firecracker
441fc98a src/vmm/src/arch/aarch64/layout.rs

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
  • Loading branch information
michpappas committed Aug 11, 2023
1 parent 47f5056 commit 97a4187
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 109 deletions.
108 changes: 0 additions & 108 deletions plat/kvm/arm/bpt64.S → plat/common/include/arm/arm64/pagetable.S
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <uk/config.h>
#include <uk/arch/lcpu.h>
#include <uk/arch/paging.h>
#include <uk/asm.h>
#include <uk/reloc.h>

#define PTE_BLOCK_DEVICE_nGnRnE (PTE_ATTR_DEVICE_nGnRnE + PTE_TYPE_BLOCK)
#define PTE_BLOCK_DEVICE_nGnRE (PTE_ATTR_DEVICE_nGnRE + PTE_TYPE_BLOCK)
Expand Down Expand Up @@ -100,109 +98,3 @@
.fill \pages, 0x8, 0
.endm

/* ----------------------- KVM MEMORY MAP (QEMU virt) ---------------------
*
* 0x0000000000000000 - 0x0000000007ffffff Hole: 0 - 128MiB
* 0x0000000008000000 - 0x000000003fffffff Devices: 128MiB - 1GiB
* 0x0000000040000000 - 0x0000007fffffffff Kernel: 1GiB - 512GiB
* 0x0000008000000000 - 0x000000ffffffffff PCIe hi mem: 512GiB - 1TiB
*
* Notice: The page tables below use the Unikraft indexing convention (x86).
*/
.section .data
.align 4
.global bpt_unmap_mrd
bpt_unmap_mrd:
.quad 0x0000000040000000 /* 1 GiB */
.quad 0x0000000040000000 /* 1 GiB */
/* QEMU-VIRT's legacy RAM max is 255 GiB, but it can also depend on the
* settings, see QEMU upstream commit:
* 50a17297e2f0c ("hw/arm/virt: Bump the 255GB initial RAM limit").
* In our case, here we assume that the RAM can only go up to the PCIe
* high memory.
*/
.quad (255 - 1) * 0x0000000040000000
.short 0x0000000000000000
.short 0x0000000000000010 /* UKPLAT_MEMRF_UNMAP */
.space 36

.global arm64_bpt_l3_pt0

/* L3: 0 - 2TiB (512GiB / entry)
*
* 0x0000000000000000 - 0x0000007fffffffff Table descriptor to l2_pt0
* 0x0000008000000000 - 0x000000ffffffffff Table descriptor to l2_pt1
* 0x0000010000000000 - 0x0000ff7fffffffff Unmapped
* 0x0000ff8000000000 - 0x0000ffffffffffff Table descriptor to l2_pt511
*/
.align 12
arm64_bpt_l3_pt0:
ur_pte arm64_bpt_l2_pt0, PTE_TYPE_TABLE
ur_pte arm64_bpt_l2_pt1, PTE_TYPE_TABLE
pte_zero , 509
#ifdef CONFIG_PAGING
ur_pte arm64_bpt_l2_pt511, PTE_TYPE_TABLE
#else
pte_zero , 1
#endif /* CONFIG_PAGING */

/* L2: 0 - 512GiB (1GiB / entry)
*
* 0x0000000000000000 - 0x000000003fffffff Table descriptor to l1_pt0
* 0x0000000040000000 - 0x000000007fffffff Table descriptor to l1_pt1
* 0x0000000080000000 - 0x000000003fffffff RAM @ 2GiB
* 0x0000000400000000 - 0x0000007fffffffff PCIe ECAM @ 256GiB
*/
.align 12
arm64_bpt_l2_pt0:
ur_pte arm64_bpt_l1_pt0, PTE_TYPE_TABLE
ur_pte arm64_bpt_l1_pt1, PTE_TYPE_TABLE
pte_fill 0x0000000080000000, 254, 2, PTE_BLOCK_NORMAL_RW
pte_fill 0x0000004000000000, 256, 2, PTE_BLOCK_DEVICE_nGnRnE

/* L2: 512GiB - 1TiB (1GiB / entry)
*
* 0x0000008000000000 - 0x000000ffffffffff PCIe hi-mem @ 512GiB
*/
.align 12
arm64_bpt_l2_pt1:
pte_fill 0x0000008000000000, 512, 2, PTE_BLOCK_DEVICE_nGnRE

#ifdef CONFIG_PAGING
/* L2: 255.5 TiB - 256TiB (1GiB / entry)
*
* 0x0000ff8000000000 - 0x0000ffffffffffff Direct-mapped
*/
.align 12
arm64_bpt_l2_pt511:
pte_fill 0x0000000000000000, 512, 2, PTE_BLOCK_NORMAL_RW
#endif /* CONFIG_PAGING */

/* L1: 0 - 1GiB (2MiB / entry)
*
* 0x0000000000000000 - 0x0000000007ffffff Hole: @ 0
* 0x0000000008000000 - 0x000000003fffffff Devices @ 128MiB
*/
.align 12
arm64_bpt_l1_pt0:
pte_zero 0x0000000000000000, 64
pte_fill 0x0000000008000000, 448, 1, PTE_BLOCK_DEVICE_nGnRE

/* L1: 1GiB - 2GiB (2MiB / entry)
*
* 0x0000000000000000 - 0x00000000001fffff Table descriptor to l0_pt0
* 0x0000000040200000 - 0x000000007fffffff RAM @ 1.2GiB
*/
.align 12
arm64_bpt_l1_pt1:
ur_pte arm64_bpt_l0_pt0, PTE_TYPE_TABLE
pte_fill 0x0000000040200000, 511, 1, PTE_BLOCK_NORMAL_RWX

/* L0: 1GiB - 1.2GiB (4KiB / entry)
*
* 0x0000000040000000 - 0x00000000401fffff Kernel @ 1GiB
*/
.align 12
.globl arm64_bpt_l0_pt0
arm64_bpt_l0_pt0:
pte_fill 0x0000000040000000, 512, 0, PTE_PAGE_NORMAL_RWX
7 changes: 6 additions & 1 deletion plat/kvm/Makefile.uk
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ LIBKVMPLAT_SRCS-$(CONFIG_FPSIMD) += $(UK_PLAT_COMMON_BASE)/arm/fp_arm64.c|i
ifeq ($(CONFIG_HAVE_SMP),y)
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(UK_PLAT_COMMON_BASE)/arm/lcpu_start.S
endif
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/bpt64.S|arm
ifeq ($(CONFIG_KVM_VMM_QEMU),y)
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/qemu_bpt64.S|arm
endif
ifeq ($(CONFIG_KVM_VMM_FIRECRACKER),y)
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/firecracker_bpt64.S|arm
endif
ifeq ($(CONFIG_KVM_BOOT_PROTO_EFI_STUB),y)
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/efi_post.c
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/efi_entry64.S|arm
Expand Down
98 changes: 98 additions & 0 deletions plat/kvm/arm/firecracker_bpt64.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
* Licensed under the BSD-3-Clause License (the "License").
* You may not use this file except in compliance with the License.
*/

#include <arm/arm64/pagetable.S>

#include <uk/config.h>
#include <uk/reloc.h>

/* ------------------- Memory Map of Firecracker on Arm64 -----------------
*
* 0x0000000000000000 - 0x000000007fffffff Devices: 0 - 2GiB
* 0x0000000080000000 - 0x000000ffffffffff DRAM: 2GiB - 1024GiB
*
* Notice: The page tables below use the Unikraft indexing convention (x86).
*/
.section .data
.align 4
.global bpt_unmap_mrd
bpt_unmap_mrd:
.quad 0x0000000080000000 /* 1 GiB */
.quad 0x0000000080000000 /* 1 GiB */
/* FIXME: Unmap to 1TiB */
.quad (255 - 1) * 0x0000000080000000
.short 0x0000000000000000
.short 0x0000000000000010 /* UKPLAT_MEMRF_UNMAP */
.space 36

.global arm64_bpt_l3_pt0

/* L3: 0 - 2TiB (512GiB / entry)
*
* 0x0000000000000000 - 0x0000007fffffffff Table descriptor to l2_pt0
* 0x0000008000000000 - 0x000000ffffffffff Table descriptor to l2_pt1
* 0x0000010000000000 - 0x0000ff7fffffffff Unmapped
* 0x0000ff8000000000 - 0x0000ffffffffffff Table descriptor to l2_pt511
*/
.align 12
arm64_bpt_l3_pt0:
ur_pte arm64_bpt_l2_pt0, PTE_TYPE_TABLE
ur_pte arm64_bpt_l2_pt1, PTE_TYPE_TABLE
pte_zero , 509
#if CONFIG_PAGING
ur_pte arm64_bpt_l2_pt511, PTE_TYPE_TABLE
#else /* !CONFIG_PAGING */
pte_zero , 1
#endif /* !CONFIG_PAGING */

/* L2: 0 - 512GiB (1GiB / entry)
*
* 0x0000000000000000 - 0x000000007fffffff Devices
* 0x0000000080000000 - 0x00000000bfffffff Table descriptor to l1_pt1
* 0x00000000c0000000 - 0x0000007fffffffff RAM @ 3GiB
*/
.align 12
arm64_bpt_l2_pt0:
pte_fill 0x0000000000000000, 2, 2, PTE_BLOCK_DEVICE_nGnRnE
ur_pte arm64_bpt_l1_pt0, PTE_TYPE_TABLE
pte_fill 0x00000000c0000000, 509, 2, PTE_BLOCK_NORMAL_RW

/* L2: 512GiB - 1TiB (1GiB / entry)
*
* 0x0000008000000000 - 0x000000ffffffffff RAM @ 512GiB
*/
.align 12
arm64_bpt_l2_pt1:
pte_fill 0x0000008000000000, 512, 2, PTE_BLOCK_NORMAL_RW

#if CONFIG_PAGING
/* L2: 255.5 TiB - 256TiB (1GiB / entry)
*
* 0x0000ff8000000000 - 0x0000ffffffffffff Direct-mapped
*/
.align 12
arm64_bpt_l2_pt511:
pte_fill 0x0000000000000000, 512, 2, PTE_BLOCK_NORMAL_RW
#endif /* CONFIG_PAGING */

/* L1: 2GiB - 3GiB (2MiB / entry)
*
* 0x0000000080000000 - 0x00000000801fffff Table descriptor to l0_pt0
* 0x0000000080200000 - 0x00000000bfffffff RAM @ 2.2GiB
*/
.align 12
arm64_bpt_l1_pt0:
ur_pte arm64_bpt_l0_pt0, PTE_TYPE_TABLE
pte_fill 0x0000000080200000, 511, 1, PTE_BLOCK_NORMAL_RWX

/* L0: 2GiB - 2.2GiB (4KiB / entry)
*
* 0x0000000080000000 - 0x00000000801fffff RAM @ 2GiB
*/
.align 12
.globl arm64_bpt_l0_pt0
arm64_bpt_l0_pt0:
pte_fill 0x0000000080000000, 512, 0, PTE_PAGE_NORMAL_RWX
117 changes: 117 additions & 0 deletions plat/kvm/arm/qemu_bpt64.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
* Licensed under the BSD-3-Clause License (the "License").
* You may not use this file except in compliance with the License.
*/

#include <arm/arm64/pagetable.S>

#include <uk/config.h>
#include <uk/reloc.h>

/* ------------------------- Memory Map of QEMU virt -----------------------
*
* 0x0000000000000000 - 0x0000000007ffffff Hole: 0 - 128MiB
* 0x0000000008000000 - 0x000000003fffffff Devices: 128MiB - 1GiB
* 0x0000000040000000 - 0x0000007fffffffff Kernel: 1GiB - 512GiB
* 0x0000008000000000 - 0x000000ffffffffff PCIe hi mem: 512GiB - 1TiB
*
* Notice: The page tables below use the Unikraft indexing convention (x86).
*/
.section .data
.align 4
.global bpt_unmap_mrd
bpt_unmap_mrd:
.quad 0x0000000040000000 /* 1 GiB */
.quad 0x0000000040000000 /* 1 GiB */
/* QEMU-VIRT's legacy RAM max is 255 GiB, but it can also depend on the
* settings, see QEMU upstream commit:
* 50a17297e2f0c ("hw/arm/virt: Bump the 255GB initial RAM limit").
* In our case, here we assume that the RAM can only go up to the PCIe
* high memory.
*/
.quad (255 - 1) * 0x0000000040000000
.short 0x0000000000000000
.short 0x0000000000000010 /* UKPLAT_MEMRF_UNMAP */
.space 36

.global arm64_bpt_l3_pt0

/* L3: 0 - 2TiB (512GiB / entry)
*
* 0x0000000000000000 - 0x0000007fffffffff Table descriptor to l2_pt0
* 0x0000008000000000 - 0x000000ffffffffff Table descriptor to l2_pt1
* 0x0000010000000000 - 0x0000ff7fffffffff Unmapped
* 0x0000ff8000000000 - 0x0000ffffffffffff Table descriptor to l2_pt511
*/
.align 12
arm64_bpt_l3_pt0:
ur_pte arm64_bpt_l2_pt0, PTE_TYPE_TABLE
ur_pte arm64_bpt_l2_pt1, PTE_TYPE_TABLE
pte_zero , 509
#if CONFIG_PAGING
ur_pte arm64_bpt_l2_pt511, PTE_TYPE_TABLE
#else /* !CONFIG_PAGING */
pte_zero , 1
#endif /* !CONFIG_PAGING */

/* L2: 0 - 512GiB (1GiB / entry)
*
* 0x0000000000000000 - 0x000000003fffffff Table descriptor to l1_pt0
* 0x0000000040000000 - 0x000000007fffffff Table descriptor to l1_pt1
* 0x0000000080000000 - 0x000000003fffffff RAM @ 2GiB
* 0x0000000400000000 - 0x0000007fffffffff PCIe ECAM @ 256GiB
*/
.align 12
arm64_bpt_l2_pt0:
ur_pte arm64_bpt_l1_pt0, PTE_TYPE_TABLE
ur_pte arm64_bpt_l1_pt1, PTE_TYPE_TABLE
pte_fill 0x0000000080000000, 254, 2, PTE_BLOCK_NORMAL_RW
pte_fill 0x0000004000000000, 256, 2, PTE_BLOCK_DEVICE_nGnRnE

/* L2: 512GiB - 1TiB (1GiB / entry)
*
* 0x0000008000000000 - 0x000000ffffffffff PCIe hi-mem @ 512GiB
*/
.align 12
arm64_bpt_l2_pt1:
pte_fill 0x0000008000000000, 512, 2, PTE_BLOCK_DEVICE_nGnRE

#if CONFIG_PAGING
/* L2: 255.5 TiB - 256TiB (1GiB / entry)
*
* 0x0000ff8000000000 - 0x0000ffffffffffff Direct-mapped
*/
.align 12
arm64_bpt_l2_pt511:
pte_fill 0x0000000000000000, 512, 2, PTE_BLOCK_NORMAL_RW
#endif /* CONFIG_PAGING */

/* L1: 0 - 1GiB (2MiB / entry)
*
* 0x0000000000000000 - 0x0000000007ffffff Hole: @ 0
* 0x0000000008000000 - 0x000000003fffffff Devices @ 128MiB
*/
.align 12
arm64_bpt_l1_pt0:
pte_zero 0x0000000000000000, 64
pte_fill 0x0000000008000000, 448, 1, PTE_BLOCK_DEVICE_nGnRE

/* L1: 1GiB - 2GiB (2MiB / entry)
*
* 0x0000000000000000 - 0x00000000001fffff Table descriptor to l0_pt0
* 0x0000000040200000 - 0x000000007fffffff RAM @ 1.2GiB
*/
.align 12
arm64_bpt_l1_pt1:
ur_pte arm64_bpt_l0_pt0, PTE_TYPE_TABLE
pte_fill 0x0000000040200000, 511, 1, PTE_BLOCK_NORMAL_RWX

/* L0: 1GiB - 1.2GiB (4KiB / entry)
*
* 0x0000000040000000 - 0x00000000401fffff Kernel @ 1GiB
*/
.align 12
.globl arm64_bpt_l0_pt0
arm64_bpt_l0_pt0:
pte_fill 0x0000000040000000, 512, 0, PTE_PAGE_NORMAL_RWX
4 changes: 4 additions & 0 deletions plat/kvm/include/kvm-arm64/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#ifndef __KVM_ARM64_IMAGE_H__
#define __KVM_ARM64_IMAGE_H__

#if CONFIG_KVM_VMM_QEMU
#define RAM_BASE_ADDR 0x40000000
#elif CONFIG_KVM_VMM_FIRECRACKER
#define RAM_BASE_ADDR 0x80000000
#endif /* CONFIG_KVM_VMM_FIRECRACKER */

#define DTB_RESERVED_SIZE 0x100000

Expand Down

0 comments on commit 97a4187

Please sign in to comment.