All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: <linuxppc-dev@ozlabs.org>
Cc: bsingharora@gmail.com, duwe@lst.de,
	<linux-kernel@vger.kernel.org>,
	rostedt@goodmis.org, kamalesh@linux.vnet.ibm.com,
	pmladek@suse.com, jeyu@redhat.com, jikos@kernel.org,
	live-patching@vger.kernel.org, mbenes@suse.cz
Subject: [PATCH 4/5] powerpc/livepatch: Add livepatch stack to struct thread_info
Date: Wed, 13 Apr 2016 22:53:22 +1000	[thread overview]
Message-ID: <1460552003-15409-5-git-send-email-mpe@ellerman.id.au> (raw)
In-Reply-To: <1460552003-15409-1-git-send-email-mpe@ellerman.id.au>

In order to support live patching we need to maintain an alternate
stack of TOC & LR values. We use the base of the stack for this, and
store the "live patch stack pointer" in struct thread_info.

Unlike the other fields of thread_info, we can not statically initialise
that value, so it must be done at run time.

This patch just adds the code to support that, it is not enabled until
the next patch which actually adds live patch support.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Acked-by: Balbir Singh <bsingharora@gmail.com>
---
 arch/powerpc/include/asm/livepatch.h   |  8 ++++++++
 arch/powerpc/include/asm/thread_info.h |  4 +++-
 arch/powerpc/kernel/irq.c              |  3 +++
 arch/powerpc/kernel/process.c          |  6 +++++-
 arch/powerpc/kernel/setup_64.c         | 17 ++++++++++-------
 5 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/include/asm/livepatch.h b/arch/powerpc/include/asm/livepatch.h
index ad36e8e34fa1..a402f7f94896 100644
--- a/arch/powerpc/include/asm/livepatch.h
+++ b/arch/powerpc/include/asm/livepatch.h
@@ -49,6 +49,14 @@ static inline unsigned long klp_get_ftrace_location(unsigned long faddr)
 	 */
 	return ftrace_location_range(faddr, faddr + 16);
 }
+
+static inline void klp_init_thread_info(struct thread_info *ti)
+{
+	/* + 1 to account for STACK_END_MAGIC */
+	ti->livepatch_sp = (unsigned long *)(ti + 1) + 1;
+}
+#else
+static void klp_init_thread_info(struct thread_info *ti) { }
 #endif /* CONFIG_LIVEPATCH */
 
 #endif /* _ASM_POWERPC_LIVEPATCH_H */
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index 7efee4a3240b..8febc3f66d53 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -43,7 +43,9 @@ struct thread_info {
 	int		preempt_count;		/* 0 => preemptable,
 						   <0 => BUG */
 	unsigned long	local_flags;		/* private flags for thread */
-
+#ifdef CONFIG_LIVEPATCH
+	unsigned long *livepatch_sp;
+#endif
 	/* low level flags - has atomic operations done on it */
 	unsigned long	flags ____cacheline_aligned_in_smp;
 };
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index 290559df1e8b..3cb46a3b1de7 100644
--- a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ -66,6 +66,7 @@
 #include <asm/udbg.h>
 #include <asm/smp.h>
 #include <asm/debug.h>
+#include <asm/livepatch.h>
 
 #ifdef CONFIG_PPC64
 #include <asm/paca.h>
@@ -607,10 +608,12 @@ void irq_ctx_init(void)
 		memset((void *)softirq_ctx[i], 0, THREAD_SIZE);
 		tp = softirq_ctx[i];
 		tp->cpu = i;
+		klp_init_thread_info(tp);
 
 		memset((void *)hardirq_ctx[i], 0, THREAD_SIZE);
 		tp = hardirq_ctx[i];
 		tp->cpu = i;
+		klp_init_thread_info(tp);
 	}
 }
 
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index b8500b4ac7fe..2a9280b945e0 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -55,6 +55,8 @@
 #include <asm/firmware.h>
 #endif
 #include <asm/code-patching.h>
+#include <asm/livepatch.h>
+
 #include <linux/kprobes.h>
 #include <linux/kdebug.h>
 
@@ -1400,13 +1402,15 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 	extern void ret_from_kernel_thread(void);
 	void (*f)(void);
 	unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
+	struct thread_info *ti = task_thread_info(p);
+
+	klp_init_thread_info(ti);
 
 	/* Copy registers */
 	sp -= sizeof(struct pt_regs);
 	childregs = (struct pt_regs *) sp;
 	if (unlikely(p->flags & PF_KTHREAD)) {
 		/* kernel thread */
-		struct thread_info *ti = (void *)task_stack_page(p);
 		memset(childregs, 0, sizeof(struct pt_regs));
 		childregs->gpr[1] = sp + sizeof(struct pt_regs);
 		/* function */
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index f98be8383a39..96d4a2b23d0f 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -69,6 +69,7 @@
 #include <asm/kvm_ppc.h>
 #include <asm/hugetlb.h>
 #include <asm/epapr_hcalls.h>
+#include <asm/livepatch.h>
 
 #ifdef DEBUG
 #define DBG(fmt...) udbg_printf(fmt)
@@ -667,16 +668,16 @@ static void __init emergency_stack_init(void)
 	limit = min(safe_stack_limit(), ppc64_rma_size);
 
 	for_each_possible_cpu(i) {
-		unsigned long sp;
-		sp  = memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit);
-		sp += THREAD_SIZE;
-		paca[i].emergency_sp = __va(sp);
+		struct thread_info *ti;
+		ti = __va(memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit));
+		klp_init_thread_info(ti);
+		paca[i].emergency_sp = (void *)ti + THREAD_SIZE;
 
 #ifdef CONFIG_PPC_BOOK3S_64
 		/* emergency stack for machine check exception handling. */
-		sp  = memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit);
-		sp += THREAD_SIZE;
-		paca[i].mc_emergency_sp = __va(sp);
+		ti = __va(memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit));
+		klp_init_thread_info(ti);
+		paca[i].mc_emergency_sp = (void *)ti + THREAD_SIZE;
 #endif
 	}
 }
@@ -700,6 +701,8 @@ void __init setup_arch(char **cmdline_p)
 	if (ppc_md.panic)
 		setup_panic();
 
+	klp_init_thread_info(&init_thread_info);
+
 	init_mm.start_code = (unsigned long)_stext;
 	init_mm.end_code = (unsigned long) _etext;
 	init_mm.end_data = (unsigned long) _edata;
-- 
2.5.0

  parent reply	other threads:[~2016-04-13 12:53 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-13 12:53 [PATCH 0/5] Live patching for powerpc Michael Ellerman
2016-04-13 12:53 ` [PATCH 1/5] ftrace: Make ftrace_location_range() global Michael Ellerman
2016-04-19 10:16   ` [1/5] " Michael Ellerman
2016-04-13 12:53 ` [PATCH 2/5] livepatch: Allow architectures to specify an alternate ftrace location Michael Ellerman
2016-04-14 12:01   ` Miroslav Benes
2016-04-14 13:06     ` Michael Ellerman
2016-04-14 13:06       ` Michael Ellerman
2016-04-14 14:06       ` Miroslav Benes
2016-04-19 10:16   ` [2/5] " Michael Ellerman
2016-04-13 12:53 ` [PATCH 3/5] powerpc/livepatch: Add livepatch header Michael Ellerman
2016-04-14 12:18   ` Miroslav Benes
2016-04-14 12:23     ` Miroslav Benes
2016-04-14 13:12       ` Michael Ellerman
2016-04-14 13:12         ` Michael Ellerman
2016-04-19 10:16   ` [3/5] " Michael Ellerman
2016-04-13 12:53 ` Michael Ellerman [this message]
2016-04-19 10:16   ` [4/5] powerpc/livepatch: Add livepatch stack to struct thread_info Michael Ellerman
2016-04-13 12:53 ` [PATCH 5/5] powerpc/livepatch: Add live patching support on ppc64le Michael Ellerman
2016-04-19 10:16   ` [5/5] " Michael Ellerman
2016-04-13 13:01 ` [PATCH 0/5] Live patching for powerpc Miroslav Benes
2016-04-13 13:22   ` Jiri Kosina
2016-04-14  6:49     ` Michael Ellerman
2016-04-14  6:49       ` Michael Ellerman
2016-04-14 12:57       ` Torsten Duwe
2016-04-14 13:08         ` Michael Ellerman
2016-04-14 13:08           ` Michael Ellerman
2016-04-14 15:20           ` Torsten Duwe
2016-04-14 16:41             ` Josh Poimboeuf
2016-04-15 11:22               ` Michael Ellerman
2016-04-15 11:22                 ` Michael Ellerman
2016-04-15 12:59                 ` Josh Poimboeuf
2016-04-15 13:21                   ` Michael Ellerman
2016-04-15 13:21                     ` Michael Ellerman
2016-04-14 14:34         ` Jiri Kosina
2016-04-15 12:24           ` Michael Ellerman
2016-04-15 15:07       ` Jiri Kosina
2016-04-19 21:42         ` Balbir Singh
2016-04-19 21:52           ` Jiri Kosina
2016-04-13 18:22   ` Jessica Yu
2016-04-14 13:28     ` Miroslav Benes
2016-04-14 19:20       ` Jessica Yu
2016-04-15  8:28         ` Miroslav Benes
2016-04-15 10:01           ` Michael Ellerman
2016-04-15 10:01             ` Michael Ellerman

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=1460552003-15409-5-git-send-email-mpe@ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=bsingharora@gmail.com \
    --cc=duwe@lst.de \
    --cc=jeyu@redhat.com \
    --cc=jikos@kernel.org \
    --cc=kamalesh@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.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.