--- 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;
The pte struct here is write-only from xlate's point of view. Any
modification to it doesn't get reflected to the real translation
layer. But your guess is good, I'd also assume that you're hitting a
read-only page.
Yes, you are right. Thanks for catching this.
So, if it is a read-only page,
'kvmppc_st(vcpu,&pc,sizeof(u32),&new_inst,true)' will not write
anything. Then, there is no reason for guest to hang. Right?
Oh? It should inject a page fault. Maybe it doesn't, but then it
behaves badly :).
Either way - just enable the debug tracepoints and check the exits you
get right after you hit an mfmsr emulation. That should give you hints
on what's going wrong.
I tried a couple of things. But I am still having trouble getting this
to work.
It seems to me that problem lies in my method of shared page mapping.
Before patching any instruction, shared page needs to be mapped to guest
effective address. I think, this is all that we need for mapping.
+ struct kvmppc_pte pte;
+ vcpu->arch.mmu.xlate(vcpu,vcpu->arch.magic_page_ea,&pte,true);
+ kvmppc_mmu_map_page(vcpu,&pte);
And, then we can start with patching.
--- 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);
+ //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);
+ }
+
Thanks,
Dushyant
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html