KVM: arm64: Introduce a BSS section for use at Hyp
Currently, the hyp code cannot make full use of a bss, as the kernel section is mapped read-only. While this mapping could simply be changed to read-write, it would intermingle even more the hyp and kernel state than they currently are. Instead, introduce a __hyp_bss section, that uses reserved pages, and create the appropriate RW hyp mappings during KVM init. Acked-by: Will Deacon <will@kernel.org> Signed-off-by: Quentin Perret <qperret@google.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20210319100146.1149909-8-qperret@google.com
This commit is contained in:
parent
7aef0cbcdc
commit
380e18ade4
4 changed files with 49 additions and 19 deletions
|
@ -13,6 +13,7 @@ extern char __hyp_idmap_text_start[], __hyp_idmap_text_end[];
|
||||||
extern char __hyp_text_start[], __hyp_text_end[];
|
extern char __hyp_text_start[], __hyp_text_end[];
|
||||||
extern char __hyp_rodata_start[], __hyp_rodata_end[];
|
extern char __hyp_rodata_start[], __hyp_rodata_end[];
|
||||||
extern char __hyp_reloc_begin[], __hyp_reloc_end[];
|
extern char __hyp_reloc_begin[], __hyp_reloc_end[];
|
||||||
|
extern char __hyp_bss_start[], __hyp_bss_end[];
|
||||||
extern char __idmap_text_start[], __idmap_text_end[];
|
extern char __idmap_text_start[], __idmap_text_end[];
|
||||||
extern char __initdata_begin[], __initdata_end[];
|
extern char __initdata_begin[], __initdata_end[];
|
||||||
extern char __inittext_begin[], __inittext_end[];
|
extern char __inittext_begin[], __inittext_end[];
|
||||||
|
|
|
@ -5,24 +5,7 @@
|
||||||
* Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
|
* Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define RO_EXCEPTION_TABLE_ALIGN 8
|
|
||||||
#define RUNTIME_DISCARD_EXIT
|
|
||||||
|
|
||||||
#include <asm-generic/vmlinux.lds.h>
|
|
||||||
#include <asm/cache.h>
|
|
||||||
#include <asm/hyp_image.h>
|
#include <asm/hyp_image.h>
|
||||||
#include <asm/kernel-pgtable.h>
|
|
||||||
#include <asm/memory.h>
|
|
||||||
#include <asm/page.h>
|
|
||||||
|
|
||||||
#include "image.h"
|
|
||||||
|
|
||||||
OUTPUT_ARCH(aarch64)
|
|
||||||
ENTRY(_text)
|
|
||||||
|
|
||||||
jiffies = jiffies_64;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_KVM
|
#ifdef CONFIG_KVM
|
||||||
#define HYPERVISOR_EXTABLE \
|
#define HYPERVISOR_EXTABLE \
|
||||||
. = ALIGN(SZ_8); \
|
. = ALIGN(SZ_8); \
|
||||||
|
@ -51,13 +34,43 @@ jiffies = jiffies_64;
|
||||||
__hyp_reloc_end = .; \
|
__hyp_reloc_end = .; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BSS_FIRST_SECTIONS \
|
||||||
|
__hyp_bss_start = .; \
|
||||||
|
*(HYP_SECTION_NAME(.bss)) \
|
||||||
|
. = ALIGN(PAGE_SIZE); \
|
||||||
|
__hyp_bss_end = .;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We require that __hyp_bss_start and __bss_start are aligned, and enforce it
|
||||||
|
* with an assertion. But the BSS_SECTION macro places an empty .sbss section
|
||||||
|
* between them, which can in some cases cause the linker to misalign them. To
|
||||||
|
* work around the issue, force a page alignment for __bss_start.
|
||||||
|
*/
|
||||||
|
#define SBSS_ALIGN PAGE_SIZE
|
||||||
#else /* CONFIG_KVM */
|
#else /* CONFIG_KVM */
|
||||||
#define HYPERVISOR_EXTABLE
|
#define HYPERVISOR_EXTABLE
|
||||||
#define HYPERVISOR_DATA_SECTIONS
|
#define HYPERVISOR_DATA_SECTIONS
|
||||||
#define HYPERVISOR_PERCPU_SECTION
|
#define HYPERVISOR_PERCPU_SECTION
|
||||||
#define HYPERVISOR_RELOC_SECTION
|
#define HYPERVISOR_RELOC_SECTION
|
||||||
|
#define SBSS_ALIGN 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define RO_EXCEPTION_TABLE_ALIGN 8
|
||||||
|
#define RUNTIME_DISCARD_EXIT
|
||||||
|
|
||||||
|
#include <asm-generic/vmlinux.lds.h>
|
||||||
|
#include <asm/cache.h>
|
||||||
|
#include <asm/kernel-pgtable.h>
|
||||||
|
#include <asm/memory.h>
|
||||||
|
#include <asm/page.h>
|
||||||
|
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
|
OUTPUT_ARCH(aarch64)
|
||||||
|
ENTRY(_text)
|
||||||
|
|
||||||
|
jiffies = jiffies_64;
|
||||||
|
|
||||||
#define HYPERVISOR_TEXT \
|
#define HYPERVISOR_TEXT \
|
||||||
/* \
|
/* \
|
||||||
* Align to 4 KB so that \
|
* Align to 4 KB so that \
|
||||||
|
@ -276,7 +289,7 @@ SECTIONS
|
||||||
__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
|
__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
|
||||||
_edata = .;
|
_edata = .;
|
||||||
|
|
||||||
BSS_SECTION(0, 0, 0)
|
BSS_SECTION(SBSS_ALIGN, 0, 0)
|
||||||
|
|
||||||
. = ALIGN(PAGE_SIZE);
|
. = ALIGN(PAGE_SIZE);
|
||||||
init_pg_dir = .;
|
init_pg_dir = .;
|
||||||
|
@ -324,6 +337,9 @@ ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
|
||||||
ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
|
ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
|
||||||
"Entry trampoline text too big")
|
"Entry trampoline text too big")
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef CONFIG_KVM
|
||||||
|
ASSERT(__hyp_bss_start == __bss_start, "HYP and Host BSS are misaligned")
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* If padding is applied before .head.text, virt<->phys conversions will fail.
|
* If padding is applied before .head.text, virt<->phys conversions will fail.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1775,7 +1775,19 @@ static int init_hyp_mode(void)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = create_hyp_mappings(kvm_ksym_ref(__bss_start),
|
/*
|
||||||
|
* .hyp.bss is guaranteed to be placed at the beginning of the .bss
|
||||||
|
* section thanks to an assertion in the linker script. Map it RW and
|
||||||
|
* the rest of .bss RO.
|
||||||
|
*/
|
||||||
|
err = create_hyp_mappings(kvm_ksym_ref(__hyp_bss_start),
|
||||||
|
kvm_ksym_ref(__hyp_bss_end), PAGE_HYP);
|
||||||
|
if (err) {
|
||||||
|
kvm_err("Cannot map hyp bss section: %d\n", err);
|
||||||
|
goto out_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = create_hyp_mappings(kvm_ksym_ref(__hyp_bss_end),
|
||||||
kvm_ksym_ref(__bss_stop), PAGE_HYP_RO);
|
kvm_ksym_ref(__bss_stop), PAGE_HYP_RO);
|
||||||
if (err) {
|
if (err) {
|
||||||
kvm_err("Cannot map bss section\n");
|
kvm_err("Cannot map bss section\n");
|
||||||
|
|
|
@ -25,4 +25,5 @@ SECTIONS {
|
||||||
BEGIN_HYP_SECTION(.data..percpu)
|
BEGIN_HYP_SECTION(.data..percpu)
|
||||||
PERCPU_INPUT(L1_CACHE_BYTES)
|
PERCPU_INPUT(L1_CACHE_BYTES)
|
||||||
END_HYP_SECTION
|
END_HYP_SECTION
|
||||||
|
HYP_SECTION(.bss)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue