Skip to content

Commit b18db0b

Browse files
committed
KVM guest: Make pv trampoline code executable
Our PV guest patching code assembles chunks of instructions on the fly when it encounters more complicated instructions to hijack. These instructions need to live in a section that we don't mark as non-executable, as otherwise we fault when jumping there. Right now we put it into the .bss section where it automatically gets marked as non-executable. Add a check to the NX setting function to ensure that we leave these particular pages executable. Signed-off-by: Alexander Graf <agraf@suse.de>
1 parent ab78475 commit b18db0b

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎arch/powerpc/include/asm/sections.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ static inline int overlaps_kernel_text(unsigned long start, unsigned long end)
3939
(unsigned long)_stext < end;
4040
}
4141

42+
static inline int overlaps_kvm_tmp(unsigned long start, unsigned long end)
43+
{
44+
#ifdef CONFIG_KVM_GUEST
45+
extern char kvm_tmp[];
46+
return start < (unsigned long)kvm_tmp &&
47+
(unsigned long)&kvm_tmp[1024 * 1024] < end;
48+
#else
49+
return 0;
50+
#endif
51+
}
52+
4253
#undef dereference_function_descriptor
4354
static inline void *dereference_function_descriptor(void *ptr)
4455
{

‎arch/powerpc/kernel/kvm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
#define KVM_INST_MTSRIN 0x7c0001e4
7575

7676
static bool kvm_patching_worked = true;
77-
static char kvm_tmp[1024 * 1024];
77+
char kvm_tmp[1024 * 1024];
7878
static int kvm_tmp_index;
7979

8080
static inline void kvm_patch_ins(u32 *inst, u32 new_inst)

‎arch/powerpc/mm/hash_utils_64.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
207207
if (overlaps_kernel_text(vaddr, vaddr + step))
208208
tprot &= ~HPTE_R_N;
209209

210+
/* Make kvm guest trampolines executable */
211+
if (overlaps_kvm_tmp(vaddr, vaddr + step))
212+
tprot &= ~HPTE_R_N;
213+
210214
/*
211215
* If relocatable, check if it overlaps interrupt vectors that
212216
* are copied down to real 0. For relocatable kernel

0 commit comments

Comments
 (0)