All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: kvm-ppc@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 32/33] KVM: PPC: Handle NV registers in emulated critical sections
Date: Sun, 22 Jun 2014 23:23:36 +0200	[thread overview]
Message-ID: <1403472217-22263-33-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1403472217-22263-1-git-send-email-agraf@suse.de>

When we emulate instructions during our critical section emulation we may
overwrite non-volatile registers that the looping code would need to load
back in.

Notify the callers of prepare_to_enter() when we emulated code, so that they
can set enable NV restoration on their exit path.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/powerpc/kvm/book3s_pr.c | 16 +++++++++++++---
 arch/powerpc/kvm/booke.c     |  3 +++
 arch/powerpc/kvm/powerpc.c   |  6 +++++-
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 3b82e86..8cce531 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1174,10 +1174,20 @@ program_interrupt:
 		 * again due to a host external interrupt.
 		 */
 		s = kvmppc_prepare_to_enter(vcpu);
-		if (s <= 0)
+		switch (s) {
+		case -EINTR:
 			r = s;
-		else {
-			/* interrupts now hard-disabled */
+			break;
+		case 0:
+			/* Exit_reason is set, go to host */
+			r = RESUME_HOST;
+			break;
+		case 2:
+			/* Registers modified, reload then enter */
+			r = RESUME_GUEST_NV;
+			/* fall through */
+		case 1:
+			/* Interrupts now hard-disabled, enter guest */
 			kvmppc_fix_ee_before_entry();
 		}
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index c0a71ce..66718d4 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1216,6 +1216,9 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 		if (s <= 0)
 			r = (s << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
 		else {
+			if (s == 2)
+				r = RESUME_GUEST_NV;
+
 			/* interrupts now hard-disabled */
 			kvmppc_fix_ee_before_entry();
 		}
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 0a326e1..6757c47 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -103,12 +103,14 @@ static bool kvmppc_needs_emulation(struct kvm_vcpu *vcpu)
  *
  * returns:
  *
+ * == 2 if we're ready to go into guest state with NV registers restored
  * == 1 if we're ready to go into guest state
  * <= 0 if we need to go back to the host with return value
  */
 int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
 {
 	int r;
+	int enter_level = 1;
 
 	WARN_ON(irqs_disabled());
 	hard_irq_disable();
@@ -163,13 +165,15 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
 			r = kvmppc_emulate_any_instruction(vcpu);
 			if (r == EMULATE_DO_MMIO)
 				return 0;
+			if (r == EMULATE_DONE)
+				enter_level = 2;
 
 			hard_irq_disable();
 			continue;
 		}
 
 		kvm_guest_enter();
-		return 1;
+		return enter_level;
 	}
 
 	/* return to host */
-- 
1.8.1.4


WARNING: multiple messages have this Message-ID (diff)
From: Alexander Graf <agraf@suse.de>
To: kvm-ppc@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 32/33] KVM: PPC: Handle NV registers in emulated critical sections
Date: Sun, 22 Jun 2014 21:23:36 +0000	[thread overview]
Message-ID: <1403472217-22263-33-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1403472217-22263-1-git-send-email-agraf@suse.de>

When we emulate instructions during our critical section emulation we may
overwrite non-volatile registers that the looping code would need to load
back in.

Notify the callers of prepare_to_enter() when we emulated code, so that they
can set enable NV restoration on their exit path.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/powerpc/kvm/book3s_pr.c | 16 +++++++++++++---
 arch/powerpc/kvm/booke.c     |  3 +++
 arch/powerpc/kvm/powerpc.c   |  6 +++++-
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 3b82e86..8cce531 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1174,10 +1174,20 @@ program_interrupt:
 		 * again due to a host external interrupt.
 		 */
 		s = kvmppc_prepare_to_enter(vcpu);
-		if (s <= 0)
+		switch (s) {
+		case -EINTR:
 			r = s;
-		else {
-			/* interrupts now hard-disabled */
+			break;
+		case 0:
+			/* Exit_reason is set, go to host */
+			r = RESUME_HOST;
+			break;
+		case 2:
+			/* Registers modified, reload then enter */
+			r = RESUME_GUEST_NV;
+			/* fall through */
+		case 1:
+			/* Interrupts now hard-disabled, enter guest */
 			kvmppc_fix_ee_before_entry();
 		}
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index c0a71ce..66718d4 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1216,6 +1216,9 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 		if (s <= 0)
 			r = (s << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
 		else {
+			if (s = 2)
+				r = RESUME_GUEST_NV;
+
 			/* interrupts now hard-disabled */
 			kvmppc_fix_ee_before_entry();
 		}
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 0a326e1..6757c47 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -103,12 +103,14 @@ static bool kvmppc_needs_emulation(struct kvm_vcpu *vcpu)
  *
  * returns:
  *
+ * = 2 if we're ready to go into guest state with NV registers restored
  * = 1 if we're ready to go into guest state
  * <= 0 if we need to go back to the host with return value
  */
 int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
 {
 	int r;
+	int enter_level = 1;
 
 	WARN_ON(irqs_disabled());
 	hard_irq_disable();
@@ -163,13 +165,15 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
 			r = kvmppc_emulate_any_instruction(vcpu);
 			if (r = EMULATE_DO_MMIO)
 				return 0;
+			if (r = EMULATE_DONE)
+				enter_level = 2;
 
 			hard_irq_disable();
 			continue;
 		}
 
 		kvm_guest_enter();
-		return 1;
+		return enter_level;
 	}
 
 	/* return to host */
-- 
1.8.1.4


  parent reply	other threads:[~2014-06-22 21:23 UTC|newest]

Thread overview: 80+ 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
2014-06-22 21:23 ` [PATCH 01/33] KVM: PPC: Implement kvmppc_xlate for all targets Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 02/33] KVM: PPC: Move kvmppc_ld/st to common code Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 03/33] KVM: PPC: Remove kvmppc_bad_hva() Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 04/33] KVM: PPC: Propagate kvmppc_xlate errors properly Alexander Graf
2014-06-22 21:23   ` 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   ` 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   ` 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   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 08/33] KVM: PPC: Introduce emulation for unprivileged instructions Alexander Graf
2014-06-22 21:23   ` 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   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 10/33] KVM: PPC: Make critical section detection conditional Alexander Graf
2014-06-22 21:23   ` 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   ` 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   ` 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   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 14/33] KVM: PPC: Add std instruction emulation Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 15/33] KVM: PPC: Add stw " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 16/33] KVM: PPC: Add ld " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 17/33] KVM: PPC: Add lwz " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 18/33] KVM: PPC: Add mfcr " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 19/33] KVM: PPC: Add addis " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 20/33] KVM: PPC: Add ori " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 21/33] KVM: PPC: Add and " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 22/33] KVM: PPC: Add andi. " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 23/33] KVM: PPC: Add or " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 24/33] KVM: PPC: Add cmpwi/cmpdi " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 25/33] KVM: PPC: Add bc " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 26/33] KVM: PPC: Add mtcrf " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 27/33] KVM: PPC: Add xor " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 28/33] KVM: PPC: Add oris " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 29/33] KVM: PPC: Add rldicr/rldicl/rldic " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 30/33] KVM: PPC: Add rlwimi " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` [PATCH 31/33] KVM: PPC: Add rlwinm " Alexander Graf
2014-06-22 21:23   ` Alexander Graf
2014-06-22 21:23 ` Alexander Graf [this message]
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-22 21:23   ` Alexander Graf
2014-06-24 18:53 ` [PATCH 00/33] KVM: PPC: Fix IRQ race in magic page code Scott Wood
2014-06-24 18:53   ` Scott Wood
2014-06-24 22:41   ` Alexander Graf
2014-06-24 22:41     ` Alexander Graf
2014-06-24 23:15     ` Scott Wood
2014-06-24 23:15       ` Scott Wood
2014-06-24 23:40       ` Alexander Graf
2014-06-24 23:40         ` Alexander Graf
2014-06-25  0:21         ` Scott Wood
2014-06-25  0:21           ` Scott Wood
2014-07-28 14:10           ` Alexander Graf
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-33-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 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.