public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: "kvm@vger.kernel.org mailing list" <kvm@vger.kernel.org>
Cc: kvm-ppc@vger.kernel.org, Gleb Natapov <gleb@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Paul Mackerras <paulus@samba.org>
Subject: [PULL 02/51] KVM: PPC: Book3S HV: Save/restore SIAR and SDAR along with other PMU registers
Date: Thu, 31 Oct 2013 22:17:47 +0100	[thread overview]
Message-ID: <1383254316-11243-3-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1383254316-11243-1-git-send-email-agraf@suse.de>

From: Paul Mackerras <paulus@samba.org>

Currently we are not saving and restoring the SIAR and SDAR registers in
the PMU (performance monitor unit) on guest entry and exit.  The result
is that performance monitoring tools in the guest could get false
information about where a program was executing and what data it was
accessing at the time of a performance monitor interrupt.  This fixes
it by saving and restoring these registers along with the other PMU
registers on guest entry/exit.

This also provides a way for userspace to access these values for a
vcpu via the one_reg interface.

Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/powerpc/include/asm/kvm_host.h     |  2 ++
 arch/powerpc/kernel/asm-offsets.c       |  2 ++
 arch/powerpc/kvm/book3s_hv.c            | 12 ++++++++++++
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |  8 ++++++++
 4 files changed, 24 insertions(+)

diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 0866230..d9b21af 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -493,6 +493,8 @@ struct kvm_vcpu_arch {
 
 	u64 mmcr[3];
 	u32 pmc[8];
+	u64 siar;
+	u64 sdar;
 
 #ifdef CONFIG_KVM_EXIT_TIMING
 	struct mutex exit_timing_lock;
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index d8958be..19e699d 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -508,6 +508,8 @@ int main(void)
 	DEFINE(VCPU_PRODDED, offsetof(struct kvm_vcpu, arch.prodded));
 	DEFINE(VCPU_MMCR, offsetof(struct kvm_vcpu, arch.mmcr));
 	DEFINE(VCPU_PMC, offsetof(struct kvm_vcpu, arch.pmc));
+	DEFINE(VCPU_SIAR, offsetof(struct kvm_vcpu, arch.siar));
+	DEFINE(VCPU_SDAR, offsetof(struct kvm_vcpu, arch.sdar));
 	DEFINE(VCPU_SLB, offsetof(struct kvm_vcpu, arch.slb));
 	DEFINE(VCPU_SLB_MAX, offsetof(struct kvm_vcpu, arch.slb_max));
 	DEFINE(VCPU_SLB_NR, offsetof(struct kvm_vcpu, arch.slb_nr));
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 62a2b5a..45a9b87 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -749,6 +749,12 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
 		i = id - KVM_REG_PPC_PMC1;
 		*val = get_reg_val(id, vcpu->arch.pmc[i]);
 		break;
+	case KVM_REG_PPC_SIAR:
+		*val = get_reg_val(id, vcpu->arch.siar);
+		break;
+	case KVM_REG_PPC_SDAR:
+		*val = get_reg_val(id, vcpu->arch.sdar);
+		break;
 #ifdef CONFIG_VSX
 	case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
 		if (cpu_has_feature(CPU_FTR_VSX)) {
@@ -833,6 +839,12 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
 		i = id - KVM_REG_PPC_PMC1;
 		vcpu->arch.pmc[i] = set_reg_val(id, *val);
 		break;
+	case KVM_REG_PPC_SIAR:
+		vcpu->arch.siar = set_reg_val(id, *val);
+		break;
+	case KVM_REG_PPC_SDAR:
+		vcpu->arch.sdar = set_reg_val(id, *val);
+		break;
 #ifdef CONFIG_VSX
 	case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
 		if (cpu_has_feature(CPU_FTR_VSX)) {
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 294b7af..541aea0 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -200,8 +200,12 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
 	ld	r3, VCPU_MMCR(r4)
 	ld	r5, VCPU_MMCR + 8(r4)
 	ld	r6, VCPU_MMCR + 16(r4)
+	ld	r7, VCPU_SIAR(r4)
+	ld	r8, VCPU_SDAR(r4)
 	mtspr	SPRN_MMCR1, r5
 	mtspr	SPRN_MMCRA, r6
+	mtspr	SPRN_SIAR, r7
+	mtspr	SPRN_SDAR, r8
 	mtspr	SPRN_MMCR0, r3
 	isync
 
@@ -1134,9 +1138,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
 	std	r3, VCPU_MMCR(r9)	/* if not, set saved MMCR0 to FC */
 	b	22f
 21:	mfspr	r5, SPRN_MMCR1
+	mfspr	r7, SPRN_SIAR
+	mfspr	r8, SPRN_SDAR
 	std	r4, VCPU_MMCR(r9)
 	std	r5, VCPU_MMCR + 8(r9)
 	std	r6, VCPU_MMCR + 16(r9)
+	std	r7, VCPU_SIAR(r9)
+	std	r8, VCPU_SDAR(r9)
 	mfspr	r3, SPRN_PMC1
 	mfspr	r4, SPRN_PMC2
 	mfspr	r5, SPRN_PMC3
-- 
1.8.1.4

  parent reply	other threads:[~2013-10-31 21:17 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-31 21:17 [PULL 00/51] ppc patch queue 2013-10-31 Alexander Graf
2013-10-31 21:17 ` [PULL 01/51] KVM: PPC: Book3S HV: Reserve POWER8 space in get/set_one_reg Alexander Graf
2013-10-31 21:17 ` Alexander Graf [this message]
2013-10-31 21:17 ` [PULL 03/51] KVM: PPC: Book3S HV: Implement timebase offset for guests Alexander Graf
2013-10-31 21:17 ` [PULL 04/51] KVM: PPC: Book3S: Add GET/SET_ONE_REG interface for VRSAVE Alexander Graf
2013-10-31 21:17 ` [PULL 05/51] KVM: PPC: Book3S HV: Implement H_CONFER Alexander Graf
2013-10-31 21:17 ` [PULL 06/51] KVM: PPC: Book3S HV: Restructure kvmppc_hv_entry to be a subroutine Alexander Graf
2013-10-31 21:17 ` [PULL 07/51] KVM: PPC: Book3S HV: Pull out interrupt-reading code into " Alexander Graf
2013-10-31 21:17 ` [PULL 08/51] KVM: PPC: Book3S HV: Avoid unbalanced increments of VPA yield count Alexander Graf
2013-10-31 21:17 ` [PULL 09/51] KVM: PPC: BookE: Add GET/SET_ONE_REG interface for VRSAVE Alexander Graf
2013-10-31 21:17 ` [PULL 10/51] KVM: PPC: Book3S HV: Store LPCR value for each virtual core Alexander Graf
2013-10-31 21:17 ` [PULL 11/51] KVM: PPC: Book3S HV: Add support for guest Program Priority Register Alexander Graf
2013-10-31 21:17 ` [PULL 12/51] KVM: PPC: Book3S HV: Support POWER6 compatibility mode on POWER7 Alexander Graf
2013-10-31 21:17 ` [PULL 13/51] KVM: PPC: Book3S HV: Don't crash host on unknown guest interrupt Alexander Graf
2013-10-31 21:17 ` [PULL 14/51] KVM: PPC: Book3S PR: Fix compilation without CONFIG_ALTIVEC Alexander Graf
2013-10-31 21:18 ` [PULL 15/51] KVM: PPC: Book3S PR: Keep volatile reg values in vcpu rather than shadow_vcpu Alexander Graf
2013-10-31 21:18 ` [PULL 16/51] KVM: PPC: Book3S PR: Allow guest to use 64k pages Alexander Graf
2013-10-31 21:18 ` [PULL 17/51] KVM: PPC: Book3S PR: Use 64k host pages where possible Alexander Graf
2013-10-31 21:18 ` [PULL 18/51] KVM: PPC: Book3S PR: Handle PP0 page-protection bit in guest HPTEs Alexander Graf
2013-10-31 21:18 ` [PULL 19/51] KVM: PPC: Book3S PR: Correct errors in H_ENTER implementation Alexander Graf
2013-10-31 21:18 ` [PULL 20/51] KVM: PPC: Book3S PR: Make HPT accesses and updates SMP-safe Alexander Graf
2013-10-31 21:18 ` [PULL 21/51] KVM: PPC: Book3S PR: Allocate kvm_vcpu structs from kvm_vcpu_cache Alexander Graf
2013-10-31 21:18 ` [PULL 22/51] KVM: PPC: Book3S: Move skip-interrupt handlers to common code Alexander Graf
2013-10-31 21:18 ` [PULL 23/51] KVM: PPC: Book3S PR: Better handling of host-side read-only pages Alexander Graf
2013-10-31 21:18 ` [PULL 24/51] KVM: PPC: Book3S PR: Use mmu_notifier_retry() in kvmppc_mmu_map_page() Alexander Graf
2013-10-31 21:18 ` [PULL 25/51] KVM: PPC: Book3S PR: Mark pages accessed, and dirty if being written Alexander Graf
2013-10-31 21:18 ` [PULL 26/51] KVM: PPC: Book3S PR: Reduce number of shadow PTEs invalidated by MMU notifiers Alexander Graf
2013-10-31 21:18 ` [PULL 27/51] kvm: powerpc: book3s hv: Fix vcore leak Alexander Graf
2013-10-31 21:18 ` [PULL 28/51] KVM: PPC: Book3S HV: Better handling of exceptions that happen in real mode Alexander Graf
2013-10-31 21:18 ` [PULL 29/51] powerpc: book3e: _PAGE_LENDIAN must be _PAGE_ENDIAN Alexander Graf
2013-10-31 21:18 ` [PULL 30/51] kvm: powerpc: allow guest control "E" attribute in mas2 Alexander Graf
2013-10-31 21:18 ` [PULL 31/51] kvm: powerpc: allow guest control "G" " Alexander Graf
2013-10-31 21:18 ` [PULL 32/51] kvm: powerpc: e500: mark page accessed when mapping a guest page Alexander Graf
2013-10-31 21:18 ` [PULL 33/51] powerpc: remove unnecessary line continuations Alexander Graf
2013-10-31 21:18 ` [PULL 34/51] powerpc: move debug registers in a structure Alexander Graf
2013-11-03 14:30   ` Gleb Natapov
2013-11-03 20:56     ` Benjamin Herrenschmidt
2013-11-04  0:03       ` Scott Wood
2013-11-04  6:43         ` Alexander Graf
2013-11-04  6:51           ` Benjamin Herrenschmidt
2013-10-31 21:18 ` [PULL 35/51] powerpc: export debug registers save function for KVM Alexander Graf
2013-10-31 21:18 ` [PULL 36/51] KVM: PPC: E500: exit to user space on "ehpriv 1" instruction Alexander Graf
2013-10-31 21:18 ` [PULL 37/51] KVM: PPC: E500: Using "struct debug_reg" Alexander Graf
2013-10-31 21:18 ` [PULL 38/51] KVM: PPC: E500: Add userspace debug stub support Alexander Graf
2013-10-31 21:18 ` [PULL 39/51] kvm: powerpc: book3s: remove kvmppc_handler_highmem label Alexander Graf
2013-10-31 21:18 ` [PULL 40/51] kvm: powerpc: book3s: move book3s_64_vio_hv.c into the main kernel binary Alexander Graf
2013-10-31 21:18 ` [PULL 41/51] kvm: powerpc: book3s: pr: Rename KVM_BOOK3S_PR to KVM_BOOK3S_PR_POSSIBLE Alexander Graf
2013-10-31 21:18 ` [PULL 42/51] kvm: powerpc: book3s: Add a new config variable CONFIG_KVM_BOOK3S_HV_POSSIBLE Alexander Graf
2013-10-31 21:18 ` [PULL 43/51] kvm: powerpc: Add kvmppc_ops callback Alexander Graf
2013-10-31 21:18 ` [PULL 44/51] kvm: powerpc: book3s: Cleanup interrupt handling code Alexander Graf
2013-10-31 21:18 ` [PULL 45/51] kvm: powerpc: book3s: Add is_hv_enabled to kvmppc_ops Alexander Graf
2013-10-31 21:18 ` [PULL 46/51] kvm: powerpc: book3s: pr: move PR related tracepoints to a separate header Alexander Graf
2013-10-31 21:18 ` [PULL 47/51] kvm: powerpc: booke: Move booke related tracepoints to " Alexander Graf
2013-10-31 21:18 ` [PULL 48/51] kvm: powerpc: book3s: Support building HV and PR KVM as module Alexander Graf
2013-10-31 21:18 ` [PULL 49/51] kvm: Add struct kvm arg to memslot APIs Alexander Graf
2013-10-31 21:18 ` [PULL 50/51] kvm: powerpc: book3s: Allow the HV and PR selection per virtual machine Alexander Graf
2013-10-31 21:18 ` [PULL 51/51] kvm: powerpc: book3s: drop is_hv_enabled 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=1383254316-11243-3-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=gleb@redhat.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=pbonzini@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox