All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bharat Bhushan <r65777@freescale.com>
To: <kvm@vger.kernel.org>, <kvm-ppc@vger.kernel.org>, <agraf@suse.de>,
	<scottwood@freescale.com>, <stuart.yoder@freescale.com>
Cc: Bharat Bhushan <Bharat.Bhushan@freescale.com>,
	Bharat Bhushan <bharat.bhushan@freescale.com>
Subject: [PATCH 2/5] booke: exit to guest userspace for unimplemented hcalls in kvm
Date: Mon, 15 Jul 2013 16:41:16 +0530	[thread overview]
Message-ID: <1373886679-19581-3-git-send-email-Bharat.Bhushan@freescale.com> (raw)
In-Reply-To: <1373886679-19581-1-git-send-email-Bharat.Bhushan@freescale.com>

Exit to guest user space if kvm does not implement the hcall.

Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
---
 arch/powerpc/kvm/booke.c   |   47 +++++++++++++++++++++++++++++++++++++------
 arch/powerpc/kvm/powerpc.c |    1 +
 include/uapi/linux/kvm.h   |    1 +
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 17722d8..c8b41b4 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1005,9 +1005,25 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 		break;
 
 #ifdef CONFIG_KVM_BOOKE_HV
-	case BOOKE_INTERRUPT_HV_SYSCALL:
+	case BOOKE_INTERRUPT_HV_SYSCALL: {
+		int i;
 		if (!(vcpu->arch.shared->msr & MSR_PR)) {
-			kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu));
+			r = kvmppc_kvm_pv(vcpu);
+			if (r != EV_UNIMPLEMENTED) {
+				/* except unimplemented return to guest */
+				kvmppc_set_gpr(vcpu, 3, r);
+				kvmppc_account_exit(vcpu, SYSCALL_EXITS);
+				r = RESUME_GUEST;
+				break;
+			}
+			/* Exit to userspace for unimplemented hcalls in kvm */
+			run->epapr_hcall.nr = kvmppc_get_gpr(vcpu, 11);
+			run->epapr_hcall.ret = 0;
+			for (i = 0; i < 8; i++)
+				run->epapr_hcall.args[i] = kvmppc_get_gpr(vcpu, 3 + i);
+			vcpu->arch.hcall_needed = 1;
+			kvmppc_account_exit(vcpu, SYSCALL_EXITS);
+			r = RESUME_HOST;
 		} else {
 			/*
 			 * hcall from guest userspace -- send privileged
@@ -1016,22 +1032,39 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 			kvmppc_core_queue_program(vcpu, ESR_PPR);
 		}
 
-		r = RESUME_GUEST;
+		run->exit_reason = KVM_EXIT_EPAPR_HCALL;
 		break;
+	}
 #else
-	case BOOKE_INTERRUPT_SYSCALL:
+	case BOOKE_INTERRUPT_SYSCALL: {
+		int i;
+		r = RESUME_GUEST;
 		if (!(vcpu->arch.shared->msr & MSR_PR) &&
 		    (((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) {
 			/* KVM PV hypercalls */
-			kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu));
-			r = RESUME_GUEST;
+			r = kvmppc_kvm_pv(vcpu);
+			if (r != EV_UNIMPLEMENTED) {
+				/* except unimplemented return to guest */
+				kvmppc_set_gpr(vcpu, 3, r);
+				kvmppc_account_exit(vcpu, SYSCALL_EXITS);
+				r = RESUME_GUEST;
+				break;
+			}
+			/* Exit to userspace for unimplemented hcalls in kvm */
+			run->epapr_hcall.nr = kvmppc_get_gpr(vcpu, 11);
+			run->epapr_hcall.ret = 0;
+			for (i = 0; i < 8; i++)
+				run->epapr_hcall.args[i] = kvmppc_get_gpr(vcpu, 3 + i);
+			vcpu->arch.hcall_needed = 1;
+			run->exit_reason = KVM_EXIT_EPAPR_HCALL;
+			r = RESUME_HOST;
 		} else {
 			/* Guest syscalls */
 			kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL);
 		}
 		kvmppc_account_exit(vcpu, SYSCALL_EXITS);
-		r = RESUME_GUEST;
 		break;
+	}
 #endif
 
 	case BOOKE_INTERRUPT_DTLB_MISS: {
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 4e05f8c..6c6199d 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -307,6 +307,7 @@ int kvm_dev_ioctl_check_extension(long ext)
 	case KVM_CAP_PPC_BOOKE_SREGS:
 	case KVM_CAP_PPC_BOOKE_WATCHDOG:
 	case KVM_CAP_PPC_EPR:
+	case KVM_CAP_EXIT_EPAPR_HCALL:
 #else
 	case KVM_CAP_PPC_SEGSTATE:
 	case KVM_CAP_PPC_HIOR:
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 01ee50e..b5266e5 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -674,6 +674,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_PPC_RTAS 91
 #define KVM_CAP_IRQ_XICS 92
 #define KVM_CAP_ARM_EL1_32BIT 93
+#define KVM_CAP_EXIT_EPAPR_HCALL 94
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
-- 
1.7.0.4



WARNING: multiple messages have this Message-ID (diff)
From: Bharat Bhushan <r65777@freescale.com>
To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, agraf@suse.de,
	scottwood@freescale.com, stuart.yoder@freescale.com
Cc: Bharat Bhushan <Bharat.Bhushan@freescale.com>,
	Bharat Bhushan <bharat.bhushan@freescale.com>
Subject: [PATCH 2/5] booke: exit to guest userspace for unimplemented hcalls in kvm
Date: Mon, 15 Jul 2013 11:23:16 +0000	[thread overview]
Message-ID: <1373886679-19581-3-git-send-email-Bharat.Bhushan@freescale.com> (raw)
In-Reply-To: <1373886679-19581-1-git-send-email-Bharat.Bhushan@freescale.com>

Exit to guest user space if kvm does not implement the hcall.

Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
---
 arch/powerpc/kvm/booke.c   |   47 +++++++++++++++++++++++++++++++++++++------
 arch/powerpc/kvm/powerpc.c |    1 +
 include/uapi/linux/kvm.h   |    1 +
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 17722d8..c8b41b4 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1005,9 +1005,25 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 		break;
 
 #ifdef CONFIG_KVM_BOOKE_HV
-	case BOOKE_INTERRUPT_HV_SYSCALL:
+	case BOOKE_INTERRUPT_HV_SYSCALL: {
+		int i;
 		if (!(vcpu->arch.shared->msr & MSR_PR)) {
-			kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu));
+			r = kvmppc_kvm_pv(vcpu);
+			if (r != EV_UNIMPLEMENTED) {
+				/* except unimplemented return to guest */
+				kvmppc_set_gpr(vcpu, 3, r);
+				kvmppc_account_exit(vcpu, SYSCALL_EXITS);
+				r = RESUME_GUEST;
+				break;
+			}
+			/* Exit to userspace for unimplemented hcalls in kvm */
+			run->epapr_hcall.nr = kvmppc_get_gpr(vcpu, 11);
+			run->epapr_hcall.ret = 0;
+			for (i = 0; i < 8; i++)
+				run->epapr_hcall.args[i] = kvmppc_get_gpr(vcpu, 3 + i);
+			vcpu->arch.hcall_needed = 1;
+			kvmppc_account_exit(vcpu, SYSCALL_EXITS);
+			r = RESUME_HOST;
 		} else {
 			/*
 			 * hcall from guest userspace -- send privileged
@@ -1016,22 +1032,39 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 			kvmppc_core_queue_program(vcpu, ESR_PPR);
 		}
 
-		r = RESUME_GUEST;
+		run->exit_reason = KVM_EXIT_EPAPR_HCALL;
 		break;
+	}
 #else
-	case BOOKE_INTERRUPT_SYSCALL:
+	case BOOKE_INTERRUPT_SYSCALL: {
+		int i;
+		r = RESUME_GUEST;
 		if (!(vcpu->arch.shared->msr & MSR_PR) &&
 		    (((u32)kvmppc_get_gpr(vcpu, 0)) = KVM_SC_MAGIC_R0)) {
 			/* KVM PV hypercalls */
-			kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu));
-			r = RESUME_GUEST;
+			r = kvmppc_kvm_pv(vcpu);
+			if (r != EV_UNIMPLEMENTED) {
+				/* except unimplemented return to guest */
+				kvmppc_set_gpr(vcpu, 3, r);
+				kvmppc_account_exit(vcpu, SYSCALL_EXITS);
+				r = RESUME_GUEST;
+				break;
+			}
+			/* Exit to userspace for unimplemented hcalls in kvm */
+			run->epapr_hcall.nr = kvmppc_get_gpr(vcpu, 11);
+			run->epapr_hcall.ret = 0;
+			for (i = 0; i < 8; i++)
+				run->epapr_hcall.args[i] = kvmppc_get_gpr(vcpu, 3 + i);
+			vcpu->arch.hcall_needed = 1;
+			run->exit_reason = KVM_EXIT_EPAPR_HCALL;
+			r = RESUME_HOST;
 		} else {
 			/* Guest syscalls */
 			kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL);
 		}
 		kvmppc_account_exit(vcpu, SYSCALL_EXITS);
-		r = RESUME_GUEST;
 		break;
+	}
 #endif
 
 	case BOOKE_INTERRUPT_DTLB_MISS: {
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 4e05f8c..6c6199d 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -307,6 +307,7 @@ int kvm_dev_ioctl_check_extension(long ext)
 	case KVM_CAP_PPC_BOOKE_SREGS:
 	case KVM_CAP_PPC_BOOKE_WATCHDOG:
 	case KVM_CAP_PPC_EPR:
+	case KVM_CAP_EXIT_EPAPR_HCALL:
 #else
 	case KVM_CAP_PPC_SEGSTATE:
 	case KVM_CAP_PPC_HIOR:
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 01ee50e..b5266e5 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -674,6 +674,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_PPC_RTAS 91
 #define KVM_CAP_IRQ_XICS 92
 #define KVM_CAP_ARM_EL1_32BIT 93
+#define KVM_CAP_EXIT_EPAPR_HCALL 94
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
-- 
1.7.0.4



  parent reply	other threads:[~2013-07-15 11:18 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-15 11:11 [PATCH 0/5] powerpc: implement reset/shutdown hcalls Bharat Bhushan
2013-07-15 11:23 ` Bharat Bhushan
2013-07-15 11:11 ` [PATCH 1/5] powerpc: define ePAPR hcall exit interface Bharat Bhushan
2013-07-15 11:23   ` Bharat Bhushan
2013-07-15 11:21   ` Alexander Graf
2013-07-15 11:21     ` Alexander Graf
2013-07-15 11:32     ` Bhushan Bharat-R65777
2013-07-15 11:11 ` Bharat Bhushan [this message]
2013-07-15 11:23   ` [PATCH 2/5] booke: exit to guest userspace for unimplemented hcalls in kvm Bharat Bhushan
2013-07-15 11:31   ` Alexander Graf
2013-07-15 11:31     ` Alexander Graf
2013-07-15 11:38     ` Bhushan Bharat-R65777
2013-07-15 11:38       ` Bhushan Bharat-R65777
2013-07-15 11:46       ` Alexander Graf
2013-07-15 11:46         ` Alexander Graf
2013-07-15 14:50         ` Bhushan Bharat-R65777
2013-07-15 14:56           ` Alexander Graf
2013-07-15 14:56             ` Alexander Graf
2013-07-15 15:13             ` Bhushan Bharat-R65777
2013-07-15 15:29               ` Alexander Graf
2013-07-15 15:29                 ` Alexander Graf
2013-07-15 15:35                 ` Bhushan Bharat-R65777
2013-07-15 15:38                   ` Alexander Graf
2013-07-15 15:38                     ` Alexander Graf
2013-07-15 18:07   ` Scott Wood
2013-07-15 18:07     ` Scott Wood
2013-07-16  4:46     ` Bhushan Bharat-R65777
2013-07-16  4:46       ` Bhushan Bharat-R65777
2013-07-15 11:11 ` [PATCH 3/5] booke: define reset and shutdown hcalls Bharat Bhushan
2013-07-15 11:23   ` Bharat Bhushan
2013-07-15 11:30   ` Gleb Natapov
2013-07-15 11:30     ` Gleb Natapov
2013-07-15 11:44     ` Alexander Graf
2013-07-15 11:44       ` Alexander Graf
2013-07-15 12:15       ` Gleb Natapov
2013-07-15 12:15         ` Gleb Natapov
2013-07-15 12:21         ` Alexander Graf
2013-07-15 12:21           ` Alexander Graf
2013-07-15 12:24           ` Gleb Natapov
2013-07-15 12:24             ` Gleb Natapov
2013-07-15 12:26             ` Alexander Graf
2013-07-15 12:26               ` Alexander Graf
2013-07-15 12:31               ` Gleb Natapov
2013-07-15 12:31                 ` Gleb Natapov
2013-07-15 18:17     ` Scott Wood
2013-07-15 18:17       ` Scott Wood
2013-07-16  6:35       ` Gleb Natapov
2013-07-16  6:35         ` Gleb Natapov
2013-07-16 23:04         ` Scott Wood
2013-07-16 23:04           ` Scott Wood
2013-07-17 11:00           ` Gleb Natapov
2013-07-17 11:00             ` Gleb Natapov
2013-07-17 12:19             ` Alexander Graf
2013-07-17 12:19               ` Alexander Graf
2013-07-17 15:19               ` Yoder Stuart-B08248
2013-07-17 15:21                 ` Alexander Graf
2013-07-17 15:21                   ` Alexander Graf
2013-07-17 15:36                   ` Yoder Stuart-B08248
2013-07-17 15:41                     ` Alexander Graf
2013-07-17 15:41                       ` Alexander Graf
2013-07-17 15:47                       ` Bhushan Bharat-R65777
2013-07-17 15:52                         ` Alexander Graf
2013-07-17 15:52                           ` Alexander Graf
2013-07-17 15:59                           ` Bhushan Bharat-R65777
2013-07-17 16:04                             ` Alexander Graf
2013-07-17 16:04                               ` Alexander Graf
2013-07-17 16:21                               ` Bhushan Bharat-R65777
2013-07-17 16:23                                 ` Alexander Graf
2013-07-17 16:23                                   ` Alexander Graf
2013-07-17 16:59                               ` Scott Wood
2013-07-17 16:59                                 ` Scott Wood
2013-07-17 17:05                                 ` Alexander Graf
2013-07-17 17:05                                   ` Alexander Graf
2013-07-17 17:09                                   ` Scott Wood
2013-07-17 17:09                                     ` Scott Wood
2013-07-15 11:11 ` [PATCH 4/5] powerpc: Resolve KVM_HC_FEATURES compilation dependeny Bharat Bhushan
2013-07-15 11:23   ` Bharat Bhushan
2013-07-15 11:46   ` Alexander Graf
2013-07-15 11:46     ` Alexander Graf
2013-07-15 11:11 ` [PATCH 5/5] powerpc: using reset hcall when kvm,has-reset Bharat Bhushan
2013-07-15 11:23   ` Bharat Bhushan
2013-07-15 11:50   ` Alexander Graf
2013-07-15 11:50     ` Alexander Graf
2013-07-15 15:05     ` Bhushan Bharat-R65777
2013-07-15 15:09       ` Alexander Graf
2013-07-15 15:09         ` Alexander Graf
2013-07-15 15:16         ` Bhushan Bharat-R65777
2013-07-15 18:21           ` Scott Wood
2013-07-15 18:21             ` Scott Wood
2013-07-15 20:28             ` Alexander Graf
2013-07-15 20:28               ` Alexander Graf
2013-07-15 20:52               ` Scott Wood
2013-07-15 20:52                 ` Scott Wood
2013-07-15 20:55                 ` Alexander Graf
2013-07-15 20:55                   ` Alexander Graf
2013-07-15 22:23                   ` Scott Wood
2013-07-15 22:23                     ` Scott Wood
2013-07-16 23:21                     ` Alexander Graf
2013-07-16 23:21                       ` Alexander Graf
2013-07-16 23:26                       ` Scott Wood
2013-07-16 23:26                         ` Scott Wood
2013-07-16 23:37                         ` Scott Wood
2013-07-16 23:37                           ` 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=1373886679-19581-3-git-send-email-Bharat.Bhushan@freescale.com \
    --to=r65777@freescale.com \
    --cc=Bharat.Bhushan@freescale.com \
    --cc=agraf@suse.de \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=scottwood@freescale.com \
    --cc=stuart.yoder@freescale.com \
    /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.