linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Michael Neuling <mikey@neuling.org>
To: Michael Ellerman <mpe@ellerman.id.au>, Jack Miller <jack@codezen.org>
Cc: linuxppc-dev@lists.ozlabs.org, anton@samba.org, mikey@neuling.org
Subject: [PATCH v5 2/3] powerpc: Load Monitor Register Support
Date: Fri,  6 May 2016 12:30:21 +1000	[thread overview]
Message-ID: <1462501822-11262-3-git-send-email-mikey@neuling.org> (raw)
In-Reply-To: <1462501822-11262-1-git-send-email-mikey@neuling.org>

From: Jack Miller <jack@codezen.org>

This enables new registers, LMRR and LMSER, that can trigger an EBB in
userspace code when a monitored load (via the new ldmx instruction)
loads memory from a monitored space. This facility is controlled by a
new FSCR bit, LM.

This patch disables the FSCR LM control bit on task init and enables
that bit when a load monitor facility unavailable exception is taken
for using it. On context switch, this bit is then used to determine
whether the two relevant registers are saved and restored. This is
done lazily for performance reasons.

Signed-off-by: Jack Miller <jack@codezen.org>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/include/asm/processor.h |  2 ++
 arch/powerpc/include/asm/reg.h       |  5 +++++
 arch/powerpc/kernel/process.c        | 19 +++++++++++++++++++
 arch/powerpc/kernel/traps.c          |  4 ++++
 4 files changed, 30 insertions(+)

diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
index 009fab1..2bb822b 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -314,6 +314,8 @@ struct thread_struct {
 	unsigned long	mmcr2;
 	unsigned 	mmcr0;
 	unsigned 	used_ebb;
+	unsigned long	lmrr;
+	unsigned long	lmser;
 #endif
 };
 
diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index c1e82e9..2e906ec 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -282,6 +282,8 @@
 #define SPRN_HRMOR	0x139	/* Real mode offset register */
 #define SPRN_HSRR0	0x13A	/* Hypervisor Save/Restore 0 */
 #define SPRN_HSRR1	0x13B	/* Hypervisor Save/Restore 1 */
+#define SPRN_LMRR	0x32D	/* Load Monitor Region Register */
+#define SPRN_LMSER	0x32E	/* Load Monitor Section Enable Register */
 #define SPRN_IC		0x350	/* Virtual Instruction Count */
 #define SPRN_VTB	0x351	/* Virtual Time Base */
 #define SPRN_LDBAR	0x352	/* LD Base Address Register */
@@ -291,6 +293,7 @@
 #define SPRN_PMCR	0x374	/* Power Management Control Register */
 
 /* HFSCR and FSCR bit numbers are the same */
+#define FSCR_LM_LG	11	/* Enable Load Monitor Registers */
 #define FSCR_TAR_LG	8	/* Enable Target Address Register */
 #define FSCR_EBB_LG	7	/* Enable Event Based Branching */
 #define FSCR_TM_LG	5	/* Enable Transactional Memory */
@@ -300,10 +303,12 @@
 #define FSCR_VECVSX_LG	1	/* Enable VMX/VSX  */
 #define FSCR_FP_LG	0	/* Enable Floating Point */
 #define SPRN_FSCR	0x099	/* Facility Status & Control Register */
+#define   FSCR_LM	__MASK(FSCR_LM_LG)
 #define   FSCR_TAR	__MASK(FSCR_TAR_LG)
 #define   FSCR_EBB	__MASK(FSCR_EBB_LG)
 #define   FSCR_DSCR	__MASK(FSCR_DSCR_LG)
 #define SPRN_HFSCR	0xbe	/* HV=1 Facility Status & Control Register */
+#define   HFSCR_LM	__MASK(FSCR_LM_LG)
 #define   HFSCR_TAR	__MASK(FSCR_TAR_LG)
 #define   HFSCR_EBB	__MASK(FSCR_EBB_LG)
 #define   HFSCR_TM	__MASK(FSCR_TM_LG)
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index e934677..cbcf922 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1009,6 +1009,14 @@ static inline void save_sprs(struct thread_struct *t)
 		 */
 		t->tar = mfspr(SPRN_TAR);
 	}
+
+	if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+		/* Conditionally save Load Monitor registers, if enabled */
+		if (t->fscr & FSCR_LM) {
+			t->lmrr = mfspr(SPRN_LMRR);
+			t->lmser = mfspr(SPRN_LMSER);
+		}
+	}
 #endif
 }
 
@@ -1044,6 +1052,16 @@ static inline void restore_sprs(struct thread_struct *old_thread,
 		if (old_thread->tar != new_thread->tar)
 			mtspr(SPRN_TAR, new_thread->tar);
 	}
+
+	if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+		/* Conditionally restore Load Monitor registers, if enabled */
+		if (new_thread->fscr & FSCR_LM) {
+			if (old_thread->lmrr != new_thread->lmrr);
+				mtspr(SPRN_LMRR, new_thread->lmrr);
+			if (old_thread->lmser != new_thread->lmser);
+				mtspr(SPRN_LMSER, new_thread->lmser);
+		}
+	}
 #endif
 }
 
@@ -1393,6 +1411,7 @@ void init_fscr(struct task_struct *tsk)
 	tsk->thread.fscr = FSCR_TAR|FSCR_EBB;
 	if (current->thread.dscr_inherit)
 		tsk->thread.fscr |= FSCR_DSCR;
+	tsk->thread.fscr &= ~FSCR_LM;
 }
 #endif
 
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 9229ba6..93ff3ac 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -1376,6 +1376,7 @@ void facility_unavailable_exception(struct pt_regs *regs)
 		[FSCR_TM_LG] = "TM",
 		[FSCR_EBB_LG] = "EBB",
 		[FSCR_TAR_LG] = "TAR",
+		[FSCR_LM_LG] = "LM",
 	};
 	char *facility = "unknown";
 	u64 value;
@@ -1432,6 +1433,9 @@ void facility_unavailable_exception(struct pt_regs *regs)
 			emulate_single_step(regs);
 		}
 		return;
+	} else if ((status == FSCR_LM_LG) && cpu_has_feature(CPU_FTR_ARCH_300)) {
+		mtspr(SPRN_FSCR, value | FSCR_LM);
+		return;
 	}
 
 	if ((status < ARRAY_SIZE(facility_strings)) &&
-- 
2.7.4

  parent reply	other threads:[~2016-05-06  2:30 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-18 19:07 [v2] P9 ldmx support Jack Miller
2016-04-18 19:08 ` [PATCH 1/3] powerpc: Complete FSCR context switch Jack Miller
2016-04-18 19:08 ` [PATCH 2/3] powerpc: Load Monitor Register Support Jack Miller
2016-04-18 20:47   ` kbuild test robot
2016-04-18 21:08     ` [v3] P9 ldmx support Jack Miller
2016-04-18 21:08       ` [PATCH 1/3] powerpc: Complete FSCR context switch Jack Miller
2016-05-04 11:16         ` [PATCH v4] " Michael Neuling
2016-05-06  2:30           ` [PATCH v5 0/3] POWER9 Load Monitor Support Michael Neuling
2016-05-06  2:30             ` [PATCH v5 1/3] powerpc: Improve FSCR init and context switching Michael Neuling
2016-05-06  2:30             ` Michael Neuling [this message]
2016-05-06  2:30             ` [PATCH v5 3/3] powerpc: Load Monitor Register Tests Michael Neuling
2016-06-08 10:38             ` [PATCH v6 0/3] POWER9 Load Monitor Support Michael Neuling
2016-06-08 10:38               ` [PATCH v6 1/3] powerpc: Improve FSCR init and context switching Michael Neuling
2016-06-08 10:38               ` [PATCH v6 2/3] powerpc: Load Monitor Register Support Michael Neuling
2016-06-08 10:38               ` [PATCH v6 3/3] powerpc: Load Monitor Register Tests Michael Neuling
2016-06-09  2:31               ` [PATCH v7 0/3] POWER9 Load Monitor Support Michael Neuling
2016-06-09  2:31                 ` [PATCH v7 1/3] powerpc: Improve FSCR init and context switching Michael Neuling
2016-06-21 12:27                   ` [v7,1/3] " Michael Ellerman
2016-06-09  2:31                 ` [PATCH v7 2/3] powerpc: Load Monitor Register Support Michael Neuling
2016-06-21 12:27                   ` [v7,2/3] " Michael Ellerman
2016-06-09  2:31                 ` [PATCH v7 3/3] powerpc: Load Monitor Register Tests Michael Neuling
2016-06-21 12:27                   ` [v7,3/3] " Michael Ellerman
2016-04-18 21:08       ` [PATCH 2/3] powerpc: Load Monitor Register Support Jack Miller
2016-04-18 21:08       ` [PATCH 3/3] powerpc: Load Monitor Register Tests Jack Miller
2016-05-04 10:43         ` Michael Neuling
2016-05-04 11:31           ` Michael Ellerman
2016-05-04 11:41             ` Michael Neuling
2016-04-18 19:08 ` Jack Miller

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=1462501822-11262-3-git-send-email-mikey@neuling.org \
    --to=mikey@neuling.org \
    --cc=anton@samba.org \
    --cc=jack@codezen.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    /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;
as well as URLs for NNTP newsgroup(s).