All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Mackerras <paulus@samba.org>
To: Alexander Graf <agraf@suse.de>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org
Subject: [PATCH 14/23] KVM: PPC: Book3S PR: Delay disabling relocation-on interrupts
Date: Tue, 6 Aug 2013 14:23:37 +1000	[thread overview]
Message-ID: <20130806042337.GT19254@iris.ozlabs.ibm.com> (raw)
In-Reply-To: <20130806041259.GF19254@iris.ozlabs.ibm.com>

When we are running a PR KVM guest on POWER8, we have to disable the
new POWER8 feature of taking interrupts with relocation on, that is,
of taking interrupts without disabling the MMU, because the SLB does
not contain the normal kernel SLB entries while in the guest.
Currently we disable relocation-on interrupts when a PR guest is
created, and leave it disabled until there are no more PR guests in
existence.

This defers the disabling of relocation-on interrupts until the first
time a PR KVM guest vcpu is run.  The reason is that in future we will
support both PR and HV guests in the same kernel, and this will avoid
disabling relocation-on interrupts unnecessarily for guests which turn
out to be HV guests, as we will not know at VM creation time whether
it will be a PR or a HV guest.

Signed-off-by: Paul Mackerras <paulus@samba.org>
---
 arch/powerpc/include/asm/kvm_host.h |  1 +
 arch/powerpc/kvm/book3s_pr.c        | 71 ++++++++++++++++++++++++++-----------
 2 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 4d83972..c012db2 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -264,6 +264,7 @@ struct kvm_arch {
 #endif /* CONFIG_KVM_BOOK3S_64_HV */
 #ifdef CONFIG_KVM_BOOK3S_PR
 	struct mutex hpt_mutex;
+	bool relon_disabled;
 #endif
 #ifdef CONFIG_PPC_BOOK3S_64
 	struct list_head spapr_tce_tables;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 5b06a70..2759ddc 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1197,6 +1197,47 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
 	kmem_cache_free(kvm_vcpu_cache, vcpu);
 }
 
+/*
+ * On POWER8, we have to disable relocation-on interrupts while
+ * we are in the guest, since the guest doesn't have the normal
+ * kernel SLB contents.  Since disabling relocation-on interrupts
+ * is a fairly heavy-weight operation, we do it once when starting
+ * the first guest vcpu and leave it disabled until the last guest
+ * has been destroyed.
+ */
+static unsigned int kvm_global_user_count = 0;
+static DEFINE_SPINLOCK(kvm_global_user_count_lock);
+
+static void disable_relon_interrupts(struct kvm *kvm)
+{
+	mutex_lock(&kvm->lock);
+	if (!kvm->arch.relon_disabled) {
+		if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
+			spin_lock(&kvm_global_user_count_lock);
+			if (++kvm_global_user_count == 1)
+				pSeries_disable_reloc_on_exc();
+			spin_unlock(&kvm_global_user_count_lock);
+		}
+		/* order disabling above with setting relon_disabled */
+		smp_mb();
+		kvm->arch.relon_disabled = true;
+	}
+	mutex_unlock(&kvm->lock);
+}
+
+static void enable_relon_interrupts(struct kvm *kvm)
+{
+	if (kvm->arch.relon_disabled &&
+	    firmware_has_feature(FW_FEATURE_SET_MODE)) {
+		spin_lock(&kvm_global_user_count_lock);
+		BUG_ON(kvm_global_user_count == 0);
+		if (--kvm_global_user_count == 0)
+			pSeries_enable_reloc_on_exc();
+		spin_unlock(&kvm_global_user_count_lock);
+	}
+	kvm->arch.relon_disabled = false;
+}
+
 int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 {
 	int ret;
@@ -1234,6 +1275,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 		goto out;
 	}
 
+	if (!vcpu->kvm->arch.relon_disabled)
+		disable_relon_interrupts(vcpu->kvm);
+
 	/* Save FPU state in stack */
 	if (current->thread.regs->msr & MSR_FP)
 		giveup_fpu(current);
@@ -1400,9 +1444,6 @@ void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
 {
 }
 
-static unsigned int kvm_global_user_count = 0;
-static DEFINE_SPINLOCK(kvm_global_user_count_lock);
-
 int kvmppc_core_init_vm(struct kvm *kvm)
 {
 #ifdef CONFIG_PPC64
@@ -1411,28 +1452,18 @@ int kvmppc_core_init_vm(struct kvm *kvm)
 #endif
 	mutex_init(&kvm->arch.hpt_mutex);
 
-	if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
-		spin_lock(&kvm_global_user_count_lock);
-		if (++kvm_global_user_count == 1)
-			pSeries_disable_reloc_on_exc();
-		spin_unlock(&kvm_global_user_count_lock);
-	}
+	/*
+	 * If we don't have relocation-on interrupts at all,
+	 * then we can consider them to be already disabled.
+	 */
+	kvm->arch.relon_disabled = !firmware_has_feature(FW_FEATURE_SET_MODE);
+
 	return 0;
 }
 
 void kvmppc_core_destroy_vm(struct kvm *kvm)
 {
-#ifdef CONFIG_PPC64
-	WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables));
-#endif
-
-	if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
-		spin_lock(&kvm_global_user_count_lock);
-		BUG_ON(kvm_global_user_count == 0);
-		if (--kvm_global_user_count == 0)
-			pSeries_enable_reloc_on_exc();
-		spin_unlock(&kvm_global_user_count_lock);
-	}
+	enable_relon_interrupts(kvm);
 }
 
 static int kvmppc_book3s_init(void)
-- 
1.8.3.1


WARNING: multiple messages have this Message-ID (diff)
From: Paul Mackerras <paulus@samba.org>
To: Alexander Graf <agraf@suse.de>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org
Subject: [PATCH 14/23] KVM: PPC: Book3S PR: Delay disabling relocation-on interrupts
Date: Tue, 06 Aug 2013 04:23:37 +0000	[thread overview]
Message-ID: <20130806042337.GT19254@iris.ozlabs.ibm.com> (raw)
In-Reply-To: <20130806041259.GF19254@iris.ozlabs.ibm.com>

When we are running a PR KVM guest on POWER8, we have to disable the
new POWER8 feature of taking interrupts with relocation on, that is,
of taking interrupts without disabling the MMU, because the SLB does
not contain the normal kernel SLB entries while in the guest.
Currently we disable relocation-on interrupts when a PR guest is
created, and leave it disabled until there are no more PR guests in
existence.

This defers the disabling of relocation-on interrupts until the first
time a PR KVM guest vcpu is run.  The reason is that in future we will
support both PR and HV guests in the same kernel, and this will avoid
disabling relocation-on interrupts unnecessarily for guests which turn
out to be HV guests, as we will not know at VM creation time whether
it will be a PR or a HV guest.

Signed-off-by: Paul Mackerras <paulus@samba.org>
---
 arch/powerpc/include/asm/kvm_host.h |  1 +
 arch/powerpc/kvm/book3s_pr.c        | 71 ++++++++++++++++++++++++++-----------
 2 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 4d83972..c012db2 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -264,6 +264,7 @@ struct kvm_arch {
 #endif /* CONFIG_KVM_BOOK3S_64_HV */
 #ifdef CONFIG_KVM_BOOK3S_PR
 	struct mutex hpt_mutex;
+	bool relon_disabled;
 #endif
 #ifdef CONFIG_PPC_BOOK3S_64
 	struct list_head spapr_tce_tables;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 5b06a70..2759ddc 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1197,6 +1197,47 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
 	kmem_cache_free(kvm_vcpu_cache, vcpu);
 }
 
+/*
+ * On POWER8, we have to disable relocation-on interrupts while
+ * we are in the guest, since the guest doesn't have the normal
+ * kernel SLB contents.  Since disabling relocation-on interrupts
+ * is a fairly heavy-weight operation, we do it once when starting
+ * the first guest vcpu and leave it disabled until the last guest
+ * has been destroyed.
+ */
+static unsigned int kvm_global_user_count = 0;
+static DEFINE_SPINLOCK(kvm_global_user_count_lock);
+
+static void disable_relon_interrupts(struct kvm *kvm)
+{
+	mutex_lock(&kvm->lock);
+	if (!kvm->arch.relon_disabled) {
+		if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
+			spin_lock(&kvm_global_user_count_lock);
+			if (++kvm_global_user_count = 1)
+				pSeries_disable_reloc_on_exc();
+			spin_unlock(&kvm_global_user_count_lock);
+		}
+		/* order disabling above with setting relon_disabled */
+		smp_mb();
+		kvm->arch.relon_disabled = true;
+	}
+	mutex_unlock(&kvm->lock);
+}
+
+static void enable_relon_interrupts(struct kvm *kvm)
+{
+	if (kvm->arch.relon_disabled &&
+	    firmware_has_feature(FW_FEATURE_SET_MODE)) {
+		spin_lock(&kvm_global_user_count_lock);
+		BUG_ON(kvm_global_user_count = 0);
+		if (--kvm_global_user_count = 0)
+			pSeries_enable_reloc_on_exc();
+		spin_unlock(&kvm_global_user_count_lock);
+	}
+	kvm->arch.relon_disabled = false;
+}
+
 int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 {
 	int ret;
@@ -1234,6 +1275,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 		goto out;
 	}
 
+	if (!vcpu->kvm->arch.relon_disabled)
+		disable_relon_interrupts(vcpu->kvm);
+
 	/* Save FPU state in stack */
 	if (current->thread.regs->msr & MSR_FP)
 		giveup_fpu(current);
@@ -1400,9 +1444,6 @@ void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
 {
 }
 
-static unsigned int kvm_global_user_count = 0;
-static DEFINE_SPINLOCK(kvm_global_user_count_lock);
-
 int kvmppc_core_init_vm(struct kvm *kvm)
 {
 #ifdef CONFIG_PPC64
@@ -1411,28 +1452,18 @@ int kvmppc_core_init_vm(struct kvm *kvm)
 #endif
 	mutex_init(&kvm->arch.hpt_mutex);
 
-	if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
-		spin_lock(&kvm_global_user_count_lock);
-		if (++kvm_global_user_count = 1)
-			pSeries_disable_reloc_on_exc();
-		spin_unlock(&kvm_global_user_count_lock);
-	}
+	/*
+	 * If we don't have relocation-on interrupts at all,
+	 * then we can consider them to be already disabled.
+	 */
+	kvm->arch.relon_disabled = !firmware_has_feature(FW_FEATURE_SET_MODE);
+
 	return 0;
 }
 
 void kvmppc_core_destroy_vm(struct kvm *kvm)
 {
-#ifdef CONFIG_PPC64
-	WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables));
-#endif
-
-	if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
-		spin_lock(&kvm_global_user_count_lock);
-		BUG_ON(kvm_global_user_count = 0);
-		if (--kvm_global_user_count = 0)
-			pSeries_enable_reloc_on_exc();
-		spin_unlock(&kvm_global_user_count_lock);
-	}
+	enable_relon_interrupts(kvm);
 }
 
 static int kvmppc_book3s_init(void)
-- 
1.8.3.1


  parent reply	other threads:[~2013-08-06  4:28 UTC|newest]

Thread overview: 136+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-06  4:12 [PATCH 00/23] Allow PR and HV KVM to coexist in one kernel Paul Mackerras
2013-08-06  4:12 ` Paul Mackerras
2013-08-06  4:13 ` [PATCH 01/23] KVM: PPC: Book3S: Fix compile error in XICS emulation Paul Mackerras
2013-08-06  4:13   ` Paul Mackerras
2013-08-28 22:51   ` Alexander Graf
2013-08-28 22:51     ` Alexander Graf
2013-08-06  4:14 ` [PATCH 02/23] KVM: PPC: Book3S PR: Don't corrupt guest state when kernel uses VMX Paul Mackerras
2013-08-06  4:14   ` Paul Mackerras
2013-08-08 15:49   ` Aneesh Kumar K.V
2013-08-08 15:49     ` Aneesh Kumar K.V
2013-08-28 22:51   ` Alexander Graf
2013-08-28 22:51     ` Alexander Graf
2013-08-06  4:15 ` [PATCH 03/23] KVM: PPC: Book3S PR: Make instruction fetch fallback work for system calls Paul Mackerras
2013-08-06  4:15   ` Paul Mackerras
2013-08-28 22:51   ` Alexander Graf
2013-08-28 22:51     ` Alexander Graf
2013-08-06  4:16 ` [PATCH 04/23] KVM: PPC: Book3S PR: Keep volatile reg values in vcpu rather than shadow_vcpu Paul Mackerras
2013-08-06  4:16   ` Paul Mackerras
2013-08-11 11:06   ` Aneesh Kumar K.V
2013-08-11 11:18     ` Aneesh Kumar K.V
2013-08-28 22:00   ` Alexander Graf
2013-08-28 22:00     ` Alexander Graf
2013-08-29  5:04     ` Paul Mackerras
2013-08-29  5:04       ` Paul Mackerras
2013-08-29 12:46       ` Alexander Graf
2013-08-29 12:46         ` Alexander Graf
2013-08-06  4:18 ` [PATCH 05/23] KVM: PPC: Book3S PR: Rework kvmppc_mmu_book3s_64_xlate() Paul Mackerras
2013-08-06  4:18   ` Paul Mackerras
2013-08-28 22:51   ` Alexander Graf
2013-08-28 22:51     ` Alexander Graf
2013-08-06  4:18 ` [PATCH 06/23] KVM: PPC: Book3S PR: Allow guest to use 64k pages Paul Mackerras
2013-08-06  4:18   ` Paul Mackerras
2013-08-28 22:56   ` Alexander Graf
2013-08-28 22:56     ` Alexander Graf
2013-08-29  5:17     ` Paul Mackerras
2013-08-29  5:17       ` Paul Mackerras
2013-08-29 12:48       ` Alexander Graf
2013-08-29 12:48         ` Alexander Graf
2013-08-06  4:19 ` [PATCH 07/23] KVM: PPC: Book3S PR: Use 64k host pages where possible Paul Mackerras
2013-08-06  4:19   ` Paul Mackerras
2013-08-28 23:24   ` Alexander Graf
2013-08-28 23:24     ` Alexander Graf
2013-08-29  5:23     ` Paul Mackerras
2013-08-29  5:23       ` Paul Mackerras
2013-08-29 12:43       ` Alexander Graf
2013-08-29 12:43         ` Alexander Graf
2013-08-06  4:20 ` [PATCH 08/23] KVM: PPC: Book3S PR: Handle PP0 page-protection bit in guest HPTEs Paul Mackerras
2013-08-06  4:20   ` Paul Mackerras
2013-08-06  4:20 ` [PATCH 09/23] KVM: PPC: Book3S PR: Correct errors in H_ENTER implementation Paul Mackerras
2013-08-06  4:20   ` Paul Mackerras
2013-08-06  4:21 ` [PATCH 10/23] KVM: PPC: Book3S PR: Make HPT accesses and updates SMP-safe Paul Mackerras
2013-08-06  4:21   ` Paul Mackerras
2013-08-06  4:21 ` [PATCH 11/23] KVM: PPC: Book3S PR: Allocate kvm_vcpu structs from kvm_vcpu_cache Paul Mackerras
2013-08-06  4:21   ` Paul Mackerras
2013-08-12 10:03   ` Aneesh Kumar K.V
2013-08-12 10:15     ` Aneesh Kumar K.V
2013-08-06  4:22 ` [PATCH 12/23] KVM: PPC: Book3S HV: Better handling of exceptions that happen in real mode Paul Mackerras
2013-08-06  4:22   ` Paul Mackerras
2013-08-06  4:22 ` [PATCH 13/23] KVM: PPC: Book3S: Move skip-interrupt handlers to common code Paul Mackerras
2013-08-06  4:22   ` Paul Mackerras
2013-08-06  4:23 ` Paul Mackerras [this message]
2013-08-06  4:23   ` [PATCH 14/23] KVM: PPC: Book3S PR: Delay disabling relocation-on interrupts Paul Mackerras
2013-08-30 16:30   ` Alexander Graf
2013-08-30 16:30     ` Alexander Graf
2013-08-30 22:55     ` Paul Mackerras
2013-08-30 22:55       ` Paul Mackerras
2013-08-30 23:13       ` Alexander Graf
2013-08-30 23:13         ` Alexander Graf
2013-08-31  5:42         ` Paul Mackerras
2013-08-31  5:42           ` Paul Mackerras
2013-08-06  4:24 ` [PATCH 15/23] KVM: PPC: Book3S: Rename symbols that exist in both PR and HV KVM Paul Mackerras
2013-08-06  4:24   ` Paul Mackerras
2013-08-06  4:24 ` [PATCH 16/23] KVM: PPC: Book3S: Merge implementations of KVM_PPC_GET_SMMU_INFO ioctl Paul Mackerras
2013-08-06  4:24   ` Paul Mackerras
2013-08-06  4:25 ` [PATCH 17/23] KVM: PPC: Book3S HV: Factorize kvmppc_core_vcpu_create_hv() Paul Mackerras
2013-08-06  4:25   ` Paul Mackerras
2013-08-06  4:25 ` [PATCH 18/23] KVM: PPC: Book3S: Allow both PR and HV KVM to be selected Paul Mackerras
2013-08-06  4:25   ` Paul Mackerras
2013-08-06  4:26 ` [PATCH 19/23] KVM: PPC: Book3S: Select PR vs HV separately for each guest Paul Mackerras
2013-08-06  4:26   ` Paul Mackerras
2013-09-12 22:56   ` Alexander Graf
2013-09-12 22:56     ` Alexander Graf
2013-09-13  0:17     ` Paul Mackerras
2013-09-13  0:17       ` Paul Mackerras
2013-09-13  1:31       ` Benjamin Herrenschmidt
2013-09-13  1:31         ` Benjamin Herrenschmidt
2013-09-13  4:18         ` Alexander Graf
2013-09-13  4:18           ` Alexander Graf
2013-09-14 18:33         ` Aneesh Kumar K.V
2013-09-14 18:45           ` Aneesh Kumar K.V
2013-09-14 20:22           ` Alexander Graf
2013-09-14 20:22             ` Alexander Graf
2013-09-15  9:16             ` Aneesh Kumar K.V
2013-09-15  9:28               ` Aneesh Kumar K.V
2013-09-15 11:55               ` Alexander Graf
2013-09-15 11:55                 ` Alexander Graf
2013-09-13  4:17       ` Alexander Graf
2013-09-13  4:17         ` Alexander Graf
2013-09-18 12:05         ` Paul Mackerras
2013-09-18 12:05           ` Paul Mackerras
2013-09-19  7:31           ` Alexander Graf
2013-09-19  7:31             ` Alexander Graf
2013-08-06  4:27 ` [PATCH 20/23] KVM: PPC: Book3S PR: Better handling of host-side read-only pages Paul Mackerras
2013-08-06  4:27   ` Paul Mackerras
2013-09-12 23:01   ` Alexander Graf
2013-09-12 23:01     ` Alexander Graf
2013-09-13  0:23     ` Paul Mackerras
2013-09-13  0:23       ` Paul Mackerras
2013-09-14  5:24     ` Paul Mackerras
2013-09-14  5:24       ` Paul Mackerras
2013-09-14 20:23       ` Alexander Graf
2013-09-14 20:23         ` Alexander Graf
2013-09-16  4:12         ` Paul Mackerras
2013-09-16  4:12           ` Paul Mackerras
2013-09-16 12:47           ` Alexander Graf
2013-09-16 12:47             ` Alexander Graf
2013-08-06  4:27 ` [PATCH 21/23] KVM: PPC: Book3S PR: Use mmu_notifier_retry() in kvmppc_mmu_map_page() Paul Mackerras
2013-08-06  4:27   ` Paul Mackerras
2013-08-07  4:13   ` Bhushan Bharat-R65777
2013-08-07  4:13     ` Bhushan Bharat-R65777
2013-08-07  4:28     ` Paul Mackerras
2013-08-07  4:28       ` Paul Mackerras
2013-08-07  5:18       ` Bhushan Bharat-R65777
2013-08-07  5:18         ` Bhushan Bharat-R65777
2013-08-07  5:17   ` Bhushan Bharat-R65777
2013-08-07  5:17     ` Bhushan Bharat-R65777
2013-08-07  8:27     ` Paul Mackerras
2013-08-07  8:27       ` Paul Mackerras
2013-08-07  8:31       ` Bhushan Bharat-R65777
2013-08-07  8:31         ` Bhushan Bharat-R65777
2013-08-08 12:06         ` Paul Mackerras
2013-08-08 12:06           ` Paul Mackerras
2013-08-06  4:27 ` [PATCH 22/23] KVM: PPC: Book3S PR: Mark pages accessed, and dirty if being written Paul Mackerras
2013-08-06  4:27   ` Paul Mackerras
2013-08-06  4:28 ` [PATCH 23/23] KVM: PPC: Book3S PR: Reduce number of shadow PTEs invalidated by MMU notifiers Paul Mackerras
2013-08-06  4:28   ` Paul Mackerras

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=20130806042337.GT19254@iris.ozlabs.ibm.com \
    --to=paulus@samba.org \
    --cc=agraf@suse.de \
    --cc=benh@kernel.crashing.org \
    --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.