From 894ae0ca91278553de4a007dcb14e43c603fa5f4 Mon Sep 17 00:00:00 2001 From: Wojciech Ozga Date: Mon, 7 Oct 2024 09:49:43 -0500 Subject: [PATCH] Support CoVE local attestation by reserving memory in the kernel image for TVM Attestation Payload (TAP). Pass the physical address of the TAP when requesting to be promoted to a TVM. Signed-off-by: Wojciech Ozga --- arch/riscv/cove/core.c | 2 ++ arch/riscv/kernel/head.S | 1 + arch/riscv/kernel/vmlinux-xip.lds.S | 11 +++++++++++ arch/riscv/kernel/vmlinux.lds.S | 12 ++++++++++++ drivers/of/fdt.c | 2 ++ 5 files changed, 28 insertions(+) diff --git a/arch/riscv/cove/core.c b/arch/riscv/cove/core.c index 582feb1c6c8d3..16d6071133667 100644 --- a/arch/riscv/cove/core.c +++ b/arch/riscv/cove/core.c @@ -13,6 +13,8 @@ #include #include +extern char __cove_tap_start[]; + static bool is_tvm; bool is_cove_guest(void) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 4e1b341e0616f..bc7b9aacea51b 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -205,6 +205,7 @@ ENTRY(_start_kernel) li a7, COVE_PROMOTE_SBI_EXT_ID li a6, COVE_PROMOTE_SBI_FID mv a0, a1 + la a1, __cove_tap_start ecall mv a0, s1 mv a1, s2 diff --git a/arch/riscv/kernel/vmlinux-xip.lds.S b/arch/riscv/kernel/vmlinux-xip.lds.S index eab9edc3b6314..e8b14457d2beb 100644 --- a/arch/riscv/kernel/vmlinux-xip.lds.S +++ b/arch/riscv/kernel/vmlinux-xip.lds.S @@ -58,6 +58,17 @@ SECTIONS } _exiprom = .; /* End of XIP ROM area */ +#ifdef CONFIG_RISCV_COVE_GUEST + . = ALIGN(4096); + .cove_tvm_attestation_payload : { + __cove_tap_start = .; + LONG(0xace0ace0) + SHORT(0x0FFA) + FILL(0x00) + . += 4090; + __cove_tap_end = .; + } +#endif /* * From this point, stuff is considered writable and will be copied to RAM diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index 53a8ad65b255f..a2af65f95034e 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -113,6 +113,18 @@ SECTIONS } __init_end = .; +#ifdef CONFIG_RISCV_COVE_GUEST + . = ALIGN(4096); + .cove_tvm_attestation_payload : { + __cove_tap_start = .; + LONG(0xace0ace0) + SHORT(0x0FFA) + FILL(0x00) + . += 4090; + __cove_tap_end = .; + } +#endif + /* Start of data section */ _sdata = .; RO_DATA(SECTION_ALIGN) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index d1a68b6d03b3f..46e2ce22c729f 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1167,6 +1167,7 @@ int __init early_init_dt_scan_chosen(char *cmdline) early_init_dt_check_for_initrd(node); early_init_dt_check_for_elfcorehdr(node); +#ifndef CONFIG_RISCV_COVE_GUEST rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); if (rng_seed && l > 0) { add_bootloader_randomness(rng_seed, l); @@ -1178,6 +1179,7 @@ int __init early_init_dt_scan_chosen(char *cmdline) of_fdt_crc32 = crc32_be(~0, initial_boot_params, fdt_totalsize(initial_boot_params)); } +#endif /* Retrieve command line */ p = of_get_flat_dt_prop(node, "bootargs", &l);