From: Scott Wood <scottwood@freescale.com>
To: kvm-ppc@vger.kernel.org
Subject: Re: Emulating lwarx and stwcx instructions in PowerPc BOOKE e500
Date: Mon, 05 Mar 2012 21:51:26 +0000 [thread overview]
Message-ID: <4F55355E.5020707@freescale.com> (raw)
In-Reply-To: <loom.20120305T212407-58@post.gmane.org>
On 03/05/2012 02:37 PM, Aashish Mittal wrote:
> Hi
> I'm working on powerpc booke architecture and my project requires me to remove
> read and write privileges on some pages. Due to this any instruction accessing
> these pages traps and i'm trying to emulate the behavior of these instructions.
>
> I've emulated lwarx and stwcx instruction but i think stwcx is not working
> correctly. The emulation i've written is written below
What is it you're emulating that needs lwarx/stwcx to work?
> case OP_31_XOP_LWARX:
> {
> ulong ret;
> ulong addr;
> int eh = inst & 0x00000001 ;
> kvm_gva_to_hva(vcpu,ea,&addr);
> /*lwarx RT RA RB EH*/
> if(eh = 0)
> __asm__ __volatile__("lwarx %0,0,%1,0; isync":"=r" (ret) :"r" (addr));
> else
> __asm__ __volatile__("lwarx %0,0,%1,1; isync":"=r" (ret) :"r" (addr));
>
> kvmppc_set_gpr(vcpu,rt,ret);
> }
>
> case OP_31_XOP_STWCX:
> {
> ulong tmp;
> ulong addr;
> ulong data;
> kvm_gva_to_hva(vcpu,ea,&addr);
> kvmppc_read_guest(vcpu,ea,&data,sizeof(data));
> __asm__ __volatile__("stwcx. %1,0,%2; isync"
> :"=r" (tmp):"r" (data),"r" (addr):"memory");
>
> }
>
> Here kvm_gva_to_hva function convrets a guest effective address to host virtual
> address .
>
> void kvm_gva_to_hva(struct kvm_vcpu *vcpu, ulong ea,ulong* hva)
> {
> gfn_t gfn;
> gpa_t gpa ;
> int gtlb_index;
> int offset;
> ulong addr;
> struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
>
> gtlb_index = kvmppc_mmu_itlb_index(vcpu, ea);
> gpa = kvmppc_mmu_xlate(vcpu,gtlb_index, ea);
> gfn = gpa >> PAGE_SHIFT;
> addr = (ulong)gfn_to_hva(vcpu_e500->vcpu.kvm, gfn);
> offset = offset_in_page(gpa);
>
> *hva = addr + offset;
> return;
> }
>
> The guest just hangs once it encounters a stwcx instruction. Does anybody have
> any idea why this is not working and what's wrong about the emulation code.
You're losing the reservation somewhere. Any lock or atomic operation
along the emulation path will do this.
Even if this didn't happen by accident, we really don't want to leave a
reservation when we return to the guest -- it could have belonged to a
previously running guest operating on shared memory, for example.
Perhaps we should have a dummy stwcx on KVM guest entry code, similar to
the one on interrupt return?
> Also i'm working on linux-3.0-rc4 kernel .
Why are you working on something other than the current code or a stable
release?
-Scott
next prev parent reply other threads:[~2012-03-05 21:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-05 20:37 Emulating lwarx and stwcx instructions in PowerPc BOOKE e500 Aashish Mittal
2012-03-05 21:51 ` Scott Wood [this message]
2012-03-06 14:46 ` Sethi Varun-B16395
2012-03-06 20:42 ` Aashish Mittal
2012-03-06 20:45 ` Scott Wood
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=4F55355E.5020707@freescale.com \
--to=scottwood@freescale.com \
--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.