Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+16 -1
+11
arch/powerpc/include/asm/sections.h
··· 39 39 (unsigned long)_stext < end; 40 40 } 41 41 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 + 42 53 #undef dereference_function_descriptor 43 54 static inline void *dereference_function_descriptor(void *ptr) 44 55 {
+1 -1
arch/powerpc/kernel/kvm.c
··· 74 74 #define KVM_INST_MTSRIN 0x7c0001e4 75 75 76 76 static bool kvm_patching_worked = true; 77 - static char kvm_tmp[1024 * 1024]; 77 + char kvm_tmp[1024 * 1024]; 78 78 static int kvm_tmp_index; 79 79 80 80 static inline void kvm_patch_ins(u32 *inst, u32 new_inst)
+4
arch/powerpc/mm/hash_utils_64.c
··· 207 207 if (overlaps_kernel_text(vaddr, vaddr + step)) 208 208 tprot &= ~HPTE_R_N; 209 209 210 + /* Make kvm guest trampolines executable */ 211 + if (overlaps_kvm_tmp(vaddr, vaddr + step)) 212 + tprot &= ~HPTE_R_N; 213 + 210 214 /* 211 215 * If relocatable, check if it overlaps interrupt vectors that 212 216 * are copied down to real 0. For relocatable kernel