KVM: PPC: paravirt: Avoid patching paravirt template code
Subsystems (2)
PATCH 1/1 KVM: PPC: paravirt: Avoid patching paravirt template code
Currently we patch the whole code include paravirt template code. This doesn't lead into issue for now,
but it makes some previlege instructions branch to paravirt code twice.
--- arch/powerpc/kernel/kvm.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
arch/powerpc/kernel/kvm.c +17 -0
@@ -171,6 +171,10 @@ static void kvm_patch_ins_mtmsrd(u32 *inst, u32 rt)if (!p)return ; +if ((inst > kvm_emulate_mtmsrd) && + (inst < kvm_emulate_mtmsrd + kvm_emulate_mtmsrd_len)) +return ; +/* Find out where we are and put everything there */ distance_start = (ulong )p - (ulong )inst; next_inst = ((ulong )inst +4 );
@@ -220,6 +224,11 @@ static void kvm_patch_ins_mtmsr(u32 *inst, u32 rt)int distance_end;ulong next_inst; +if ((inst > kvm_emulate_mtmsr) && + (inst < kvm_emulate_mtmsr + kvm_emulate_mtmsr_len)) +return ; + + p =kvm_alloc (kvm_emulate_mtmsr_len *4 );if (!p)return ;
@@ -281,6 +290,10 @@ static void kvm_patch_ins_wrtee(u32 *inst, u32 rt, int imm_one)int distance_end;ulong next_inst; +if ((inst > kvm_emulate_wrtee) && + (inst < kvm_emulate_wrtee + kvm_emulate_wrtee_len)) +return ; + p =kvm_alloc (kvm_emulate_wrtee_len *4 );if (!p)return ;
@@ -338,6 +351,10 @@ static void kvm_patch_ins_wrteei_0(u32 *inst)int distance_end;ulong next_inst; +if ((inst > kvm_emulate_wrteei_0) && + (inst < kvm_emulate_wrteei_0 + kvm_emulate_wrteei_0_len)) +return ; + p =kvm_alloc (kvm_emulate_wrteei_0_len *4 );if (!p)return ;
Signature · 1 line
1.6.4
Re: [PATCH] KVM: PPC: paravirt: Avoid patching paravirt template
Quoted 3 lines · Liu Yu
Currently we patch the whole code include paravirt template code. This doesn't lead into issue for now,
but it makes some previlege instructions branch to paravirt code twice.
Ouch. This will do bad things to the scratch area.
Quoted 44 lines
Signed-off-by Liu Yu <[email protected]>--- arch/powerpc/kernel/kvm.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)arch/powerpc/kernel/kvm.c +13
-0@@ -171,6 +171,10 @@ static void kvm_patch_ins_mtmsrd(u32 *inst, u32 rt)if (!p)return ; +if ((inst > kvm_emulate_mtmsrd) && + (inst < kvm_emulate_mtmsrd + kvm_emulate_mtmsrd_len)) +return ; +/* Find out where we are and put everything there */ distance_start = (ulong )p - (ulong )inst; next_inst = ((ulong )inst +4 );@@ -220,6 +224,11 @@ static void kvm_patch_ins_mtmsr(u32 *inst, u32 rt)int distance_end;ulong next_inst; +if ((inst > kvm_emulate_mtmsr) && + (inst < kvm_emulate_mtmsr + kvm_emulate_mtmsr_len)) +return ; + + p =kvm_alloc (kvm_emulate_mtmsr_len *4 );if (!p)return ;@@ -281,6 +290,10 @@ static void kvm_patch_ins_wrtee(u32 *inst, u32 rt, int imm_one)int distance_end;ulong next_inst; +if ((inst > kvm_emulate_wrtee) && + (inst < kvm_emulate_wrtee + kvm_emulate_wrtee_len)) +return ; + p =kvm_alloc (kvm_emulate_wrtee_len *4 );if (!p)return ;
arch/powerpc/kernel/kvm.c static void kvm_patch_ins_wrteei_0(u32 *inst) · line 360
Quoted 10 lines
arch/powerpc/kernel/kvm.c +4
-0@@ -338,6 +351,10 @@ static void kvm_patch_ins_wrteei_0(u32 *inst)int distance_end;ulong next_inst; +if ((inst > kvm_emulate_wrteei_0) && + (inst < kvm_emulate_wrteei_0 + kvm_emulate_wrteei_0_len)) +return ; + p =kvm_alloc (kvm_emulate_wrteei_0_len *4 );if (!p)return ;
Instead of excluding only the template code for the instruction type being patched, we should exclude the entire template region in the main loop.
-Scott