From: Dushyant Bansal <cs5070214@cse.iitd.ac.in>
To: kvm-ppc@vger.kernel.org
Subject: Re: Patching guest kernel code for better performance from HOST
Date: Fri, 29 Apr 2011 22:34:12 +0000 [thread overview]
Message-ID: <4DBB3A14.2040602@cse.iitd.ac.in> (raw)
In-Reply-To: <4D9AD9E7.20904@cse.iitd.ac.in>
>>>> --- 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
next prev parent reply other threads:[~2011-04-29 22:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DBB3A14.2040602@cse.iitd.ac.in \
--to=cs5070214@cse.iitd.ac.in \
--cc=kvm-ppc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.