From: Alexander Graf <agraf@suse.de>
To: kvm-ppc@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 01/33] KVM: PPC: Implement kvmppc_xlate for all targets
Date: Sun, 22 Jun 2014 21:23:05 +0000 [thread overview]
Message-ID: <1403472217-22263-2-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1403472217-22263-1-git-send-email-agraf@suse.de>
We have a nice API to find the translated GPAs of a GVA including protection
flags. So far we only use it on Book3S, but there's no reason the same shouldn't
be used on BookE as well.
Implement a kvmppc_xlate() version for BookE and clean it up to make it more
readable in general.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
arch/powerpc/include/asm/kvm_ppc.h | 13 ++++++++++
arch/powerpc/kvm/book3s.c | 12 ++++++---
arch/powerpc/kvm/booke.c | 51 ++++++++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index 9c89cdd..837533a 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -47,6 +47,16 @@ enum emulation_result {
EMULATE_EXIT_USER, /* emulation requires exit to user-space */
};
+enum xlate_instdata {
+ XLATE_INST, /* translate instruction address */
+ XLATE_DATA /* translate data address */
+};
+
+enum xlate_readwrite {
+ XLATE_READ, /* check for read permissions */
+ XLATE_WRITE /* check for write permissions */
+};
+
extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
extern void kvmppc_handler_highmem(void);
@@ -86,6 +96,9 @@ extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index,
gva_t eaddr);
extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu);
extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu);
+extern int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr,
+ enum xlate_instdata xlid, enum xlate_readwrite xlrw,
+ struct kvmppc_pte *pte);
extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm,
unsigned int id);
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 90aa5c7..b644f51 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -368,9 +368,11 @@ pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, bool writing,
}
EXPORT_SYMBOL_GPL(kvmppc_gfn_to_pfn);
-static int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, bool data,
- bool iswrite, struct kvmppc_pte *pte)
+int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, enum xlate_instdata xlid,
+ enum xlate_readwrite xlrw, struct kvmppc_pte *pte)
{
+ bool data = (xlid = XLATE_DATA);
+ bool iswrite = (xlrw = XLATE_WRITE);
int relocated = (kvmppc_get_msr(vcpu) & (data ? MSR_DR : MSR_IR));
int r;
@@ -421,7 +423,8 @@ int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
vcpu->stat.st++;
- if (kvmppc_xlate(vcpu, *eaddr, data, true, &pte))
+ if (kvmppc_xlate(vcpu, *eaddr, data ? XLATE_DATA : XLATE_INST,
+ XLATE_WRITE, &pte))
return -ENOENT;
*eaddr = pte.raddr;
@@ -444,7 +447,8 @@ int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
vcpu->stat.ld++;
- if (kvmppc_xlate(vcpu, *eaddr, data, false, &pte))
+ if (kvmppc_xlate(vcpu, *eaddr, data ? XLATE_DATA : XLATE_INST,
+ XLATE_READ, &pte))
goto nopte;
*eaddr = pte.raddr;
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index ab62109..58d9b6c 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1788,6 +1788,57 @@ void kvm_guest_protect_msr(struct kvm_vcpu *vcpu, ulong prot_bitmap, bool set)
#endif
}
+int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, enum xlate_instdata xlid,
+ enum xlate_readwrite xlrw, struct kvmppc_pte *pte)
+{
+ int gtlb_index;
+ gpa_t gpaddr;
+
+#ifdef CONFIG_KVM_E500V2
+ if (!(vcpu->arch.shared->msr & MSR_PR) &&
+ (eaddr & PAGE_MASK) = vcpu->arch.magic_page_ea) {
+ pte->eaddr = eaddr;
+ pte->raddr = (vcpu->arch.magic_page_pa & PAGE_MASK) |
+ (eaddr & ~PAGE_MASK);
+ pte->vpage = eaddr >> PAGE_SHIFT;
+ pte->may_read = true;
+ pte->may_write = true;
+ pte->may_execute = true;
+
+ return 0;
+ }
+#endif
+
+ /* Check the guest TLB. */
+ switch (xlid) {
+ case XLATE_INST:
+ gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr);
+ break;
+ case XLATE_DATA:
+ gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr);
+ break;
+ default:
+ BUG();
+ }
+
+ /* Do we have a TLB entry at all? */
+ if (gtlb_index < 0)
+ return -ENOENT;
+
+ gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
+
+ pte->eaddr = eaddr;
+ pte->raddr = (gpaddr & PAGE_MASK) | (eaddr & ~PAGE_MASK);
+ pte->vpage = eaddr >> PAGE_SHIFT;
+
+ /* XXX read permissions from the guest TLB */
+ pte->may_read = true;
+ pte->may_write = true;
+ pte->may_execute = true;
+
+ return 0;
+}
+
int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
struct kvm_guest_debug *dbg)
{
--
1.8.1.4
next prev parent reply other threads:[~2014-06-22 21:23 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-22 21:23 [PATCH 00/33] KVM: PPC: Fix IRQ race in magic page code Alexander Graf
2014-06-22 21:23 ` Alexander Graf [this message]
2014-06-22 21:23 ` [PATCH 02/33] KVM: PPC: Move kvmppc_ld/st to common code Alexander Graf
2014-06-22 21:23 ` [PATCH 03/33] KVM: PPC: Remove kvmppc_bad_hva() Alexander Graf
2014-06-22 21:23 ` [PATCH 04/33] KVM: PPC: Propagate kvmppc_xlate errors properly Alexander Graf
2014-06-22 21:23 ` [PATCH 05/33] KVM: PPC: Use kvm_read_guest in kvmppc_ld Alexander Graf
2014-06-22 21:23 ` [PATCH 06/33] KVM: PPC: Handle magic page in kvmppc_ld/st Alexander Graf
2014-06-22 21:23 ` [PATCH 07/33] KVM: PPC: Separate loadstore emulation from priv emulation Alexander Graf
2014-06-22 21:23 ` [PATCH 08/33] KVM: PPC: Introduce emulation for unprivileged instructions Alexander Graf
2014-06-22 21:23 ` [PATCH 09/33] KVM: PPC: Move critical section detection to common code Alexander Graf
2014-06-22 21:23 ` [PATCH 10/33] KVM: PPC: Make critical section detection conditional Alexander Graf
2014-06-22 21:23 ` [PATCH 11/33] KVM: PPC: BookE: Use common critical section helper Alexander Graf
2014-06-22 21:23 ` [PATCH 12/33] KVM: PPC: Emulate critical sections when we hit them Alexander Graf
2014-06-22 21:23 ` [PATCH 13/33] KVM: PPC: Expose helper functions for data/inst faults Alexander Graf
2014-06-22 21:23 ` [PATCH 14/33] KVM: PPC: Add std instruction emulation Alexander Graf
2014-06-22 21:23 ` [PATCH 15/33] KVM: PPC: Add stw " Alexander Graf
2014-06-22 21:23 ` [PATCH 16/33] KVM: PPC: Add ld " Alexander Graf
2014-06-22 21:23 ` [PATCH 17/33] KVM: PPC: Add lwz " Alexander Graf
2014-06-22 21:23 ` [PATCH 18/33] KVM: PPC: Add mfcr " Alexander Graf
2014-06-22 21:23 ` [PATCH 19/33] KVM: PPC: Add addis " Alexander Graf
2014-06-22 21:23 ` [PATCH 20/33] KVM: PPC: Add ori " Alexander Graf
2014-06-22 21:23 ` [PATCH 21/33] KVM: PPC: Add and " Alexander Graf
2014-06-22 21:23 ` [PATCH 22/33] KVM: PPC: Add andi. " Alexander Graf
2014-06-22 21:23 ` [PATCH 23/33] KVM: PPC: Add or " Alexander Graf
2014-06-22 21:23 ` [PATCH 24/33] KVM: PPC: Add cmpwi/cmpdi " Alexander Graf
2014-06-22 21:23 ` [PATCH 25/33] KVM: PPC: Add bc " Alexander Graf
2014-06-22 21:23 ` [PATCH 26/33] KVM: PPC: Add mtcrf " Alexander Graf
2014-06-22 21:23 ` [PATCH 27/33] KVM: PPC: Add xor " Alexander Graf
2014-06-22 21:23 ` [PATCH 28/33] KVM: PPC: Add oris " Alexander Graf
2014-06-22 21:23 ` [PATCH 29/33] KVM: PPC: Add rldicr/rldicl/rldic " Alexander Graf
2014-06-22 21:23 ` [PATCH 30/33] KVM: PPC: Add rlwimi " Alexander Graf
2014-06-22 21:23 ` [PATCH 31/33] KVM: PPC: Add rlwinm " Alexander Graf
2014-06-22 21:23 ` [PATCH 32/33] KVM: PPC: Handle NV registers in emulated critical sections Alexander Graf
2014-06-22 21:23 ` [PATCH 33/33] KVM: PPC: Enable critical section emulation Alexander Graf
2014-06-24 18:53 ` [PATCH 00/33] KVM: PPC: Fix IRQ race in magic page code Scott Wood
2014-06-24 22:41 ` Alexander Graf
2014-06-24 23:15 ` Scott Wood
2014-06-24 23:40 ` Alexander Graf
2014-06-25 0:21 ` Scott Wood
2014-07-28 14:10 ` Alexander Graf
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=1403472217-22263-2-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox