Skip to content

Commit 74b13d5

Browse files
David BrazdilMarc Zyngier
authored andcommitted
KVM: arm64: Add .hyp.data section
The hypervisor has not needed its own .data section because all globals were either .rodata or .bss. To avoid having to initialize future data-structures at run-time, let's introduce add a .data section to the hypervisor. Signed-off-by: David Brazdil <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 9c32cda commit 74b13d5

File tree

7 files changed

+32
-3
lines changed

7 files changed

+32
-3
lines changed

arch/arm64/include/asm/sections.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern char __alt_instructions[], __alt_instructions_end[];
1111
extern char __hibernate_exit_text_start[], __hibernate_exit_text_end[];
1212
extern char __hyp_idmap_text_start[], __hyp_idmap_text_end[];
1313
extern char __hyp_text_start[], __hyp_text_end[];
14+
extern char __hyp_data_start[], __hyp_data_end[];
1415
extern char __hyp_rodata_start[], __hyp_rodata_end[];
1516
extern char __hyp_reloc_begin[], __hyp_reloc_end[];
1617
extern char __hyp_bss_start[], __hyp_bss_end[];

arch/arm64/kernel/image-vars.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ KVM_NVHE_ALIAS(__hyp_text_start);
131131
KVM_NVHE_ALIAS(__hyp_text_end);
132132
KVM_NVHE_ALIAS(__hyp_bss_start);
133133
KVM_NVHE_ALIAS(__hyp_bss_end);
134+
KVM_NVHE_ALIAS(__hyp_data_start);
135+
KVM_NVHE_ALIAS(__hyp_data_end);
134136
KVM_NVHE_ALIAS(__hyp_rodata_start);
135137
KVM_NVHE_ALIAS(__hyp_rodata_end);
136138

arch/arm64/kernel/vmlinux.lds.S

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*(__kvm_ex_table) \
1414
__stop___kvm_ex_table = .;
1515

16-
#define HYPERVISOR_DATA_SECTIONS \
16+
#define HYPERVISOR_RODATA_SECTIONS \
1717
HYP_SECTION_NAME(.rodata) : { \
1818
. = ALIGN(PAGE_SIZE); \
1919
__hyp_rodata_start = .; \
@@ -23,6 +23,15 @@
2323
__hyp_rodata_end = .; \
2424
}
2525

26+
#define HYPERVISOR_DATA_SECTION \
27+
HYP_SECTION_NAME(.data) : { \
28+
. = ALIGN(PAGE_SIZE); \
29+
__hyp_data_start = .; \
30+
*(HYP_SECTION_NAME(.data)) \
31+
. = ALIGN(PAGE_SIZE); \
32+
__hyp_data_end = .; \
33+
}
34+
2635
#define HYPERVISOR_PERCPU_SECTION \
2736
. = ALIGN(PAGE_SIZE); \
2837
HYP_SECTION_NAME(.data..percpu) : { \
@@ -51,7 +60,8 @@
5160
#define SBSS_ALIGN PAGE_SIZE
5261
#else /* CONFIG_KVM */
5362
#define HYPERVISOR_EXTABLE
54-
#define HYPERVISOR_DATA_SECTIONS
63+
#define HYPERVISOR_RODATA_SECTIONS
64+
#define HYPERVISOR_DATA_SECTION
5565
#define HYPERVISOR_PERCPU_SECTION
5666
#define HYPERVISOR_RELOC_SECTION
5767
#define SBSS_ALIGN 0
@@ -190,7 +200,7 @@ SECTIONS
190200
/* everything from this point to __init_begin will be marked RO NX */
191201
RO_DATA(PAGE_SIZE)
192202

193-
HYPERVISOR_DATA_SECTIONS
203+
HYPERVISOR_RODATA_SECTIONS
194204

195205
.got : { *(.got) }
196206
/*
@@ -295,6 +305,8 @@ SECTIONS
295305
_sdata = .;
296306
RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
297307

308+
HYPERVISOR_DATA_SECTION
309+
298310
/*
299311
* Data written with the MMU off but read with the MMU on requires
300312
* cache lines to be invalidated, discarding up to a Cache Writeback

arch/arm64/kvm/arm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,13 @@ static int __init init_hyp_mode(void)
26042604
goto out_err;
26052605
}
26062606

2607+
err = create_hyp_mappings(kvm_ksym_ref(__hyp_data_start),
2608+
kvm_ksym_ref(__hyp_data_end), PAGE_HYP);
2609+
if (err) {
2610+
kvm_err("Cannot map .hyp.data section\n");
2611+
goto out_err;
2612+
}
2613+
26072614
err = create_hyp_mappings(kvm_ksym_ref(__hyp_rodata_start),
26082615
kvm_ksym_ref(__hyp_rodata_end), PAGE_HYP_RO);
26092616
if (err) {

arch/arm64/kvm/hyp/nvhe/hyp.lds.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ SECTIONS {
2525
BEGIN_HYP_SECTION(.data..percpu)
2626
PERCPU_INPUT(L1_CACHE_BYTES)
2727
END_HYP_SECTION
28+
2829
HYP_SECTION(.bss)
30+
HYP_SECTION(.data)
2931
}

arch/arm64/kvm/hyp/nvhe/setup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ static int recreate_hyp_mappings(phys_addr_t phys, unsigned long size,
119119
if (ret)
120120
return ret;
121121

122+
ret = pkvm_create_mappings(__hyp_data_start, __hyp_data_end, PAGE_HYP);
123+
if (ret)
124+
return ret;
125+
122126
ret = pkvm_create_mappings(__hyp_rodata_start, __hyp_rodata_end, PAGE_HYP_RO);
123127
if (ret)
124128
return ret;

arch/arm64/kvm/pkvm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ static int __init finalize_pkvm(void)
262262
* at, which would end badly once inaccessible.
263263
*/
264264
kmemleak_free_part(__hyp_bss_start, __hyp_bss_end - __hyp_bss_start);
265+
kmemleak_free_part(__hyp_data_start, __hyp_data_end - __hyp_data_start);
265266
kmemleak_free_part(__hyp_rodata_start, __hyp_rodata_end - __hyp_rodata_start);
266267
kmemleak_free_part_phys(hyp_mem_base, hyp_mem_size);
267268

0 commit comments

Comments
 (0)