All of lore.kernel.org
 help / color / mirror / Atom feed
* Patching guest kernel code for better performance from HOST
@ 2011-04-05  8:59 Dushyant Bansal
  2011-04-05  9:09 ` Alexander Graf
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Dushyant Bansal @ 2011-04-05  8:59 UTC (permalink / raw)
  To: kvm-ppc

[-- Attachment #1: Type: text/plain, Size: 2185 bytes --]

Hi all,

     I understand that in order to improve performance by reducing vm 
exits, kvm uses one shared page between kvm and guest. Now, guest tells 
the host to map the magic page to '-4096'.

How does kvm make sure that guest will not use this address ( -4096) for 
other purpose?

Then, guest itself patches its kernel.
I am trying to patch guest from host. So far, I have tried to patch 
MFMSR instruction. Patching is done when kvm tries to emulate MFMSR. 
Mechanism used to generate new instruction is same as used by guest in 
"arch/powerpc/kernel/kvm.c"

--- a/arch/powerpc/kvm/book3s_emulate.c
+++ b/arch/powerpc/kvm/book3s_emulate.c
@@ -88,6 +88,23 @@ int kvmppc_core_emulate_op(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
                 case OP_31_XOP_MFMSR:
                         kvmppc_set_gpr(vcpu, get_rt(inst),
                                        vcpu->arch.shared->msr);
+
+                       pc = kvmppc_get_pc(vcpu);
+
+                       //if pte.may_write==false then, kvmppc_st will 
not work
+                       kvmppc_xlate(vcpu,pc,false, &pte);
+                       pte.may_write=true;
+
+                       //Generate new instruction
+                       addr= (-4096L) + offsetof(struct 
kvm_vcpu_arch_shared, msr);
+                       u32 rt1 = inst & 0x03e00000;
+                       u32 new_inst=0x80000000 | rt1 | ((addr + 4) & 
0x0000fffc);
+
+                       //patch only if magic page is mapped; try 
patching only for 0x7c0000a6 inst
+                       if (vcpu->arch.magic_page_pa==0xfffff000 && 
inst==0x7c0000a6) {
+                                       
kvmppc_st(vcpu,&pc,sizeof(u32),&new_inst,true);
+                                       }
+
                         break;
                 case OP_31_XOP_MTMSRD:
                 {


But, the problem is guest hangs during boot. I have attached the 
screenshot of the guest. I am not able to figure out the problem. Is 
there something wrong with the approach?

I have checked that new_inst generated corresponding to 0x7c0000a6 
instruction matches with the instruction that is generated when guest 
patches itself.


Thanks,
Dushyant

[-- Attachment #2: Screenshot.png --]
[-- Type: image/png, Size: 25341 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-05-19 11:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-05  8:59 Patching guest kernel code for better performance from HOST Dushyant Bansal
2011-04-05  9:09 ` Alexander Graf
2011-04-05 13:42 ` Dushyant Bansal
2011-04-05 13:56 ` Alexander Graf
2011-04-29 22:34 ` Dushyant Bansal
2011-05-07 20:44 ` Dushyant Bansal
2011-05-07 20:52 ` Alexander Graf
2011-05-09 10:38 ` Alexander Graf
2011-05-09 10:46 ` Dushyant Bansal
2011-05-19 11:28 ` Dushyant Bansal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.