linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jinyang He <hejinyang@loongson.cn>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>,
	Xuefeng Li <lixuefeng@loongson.cn>,
	linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
	live-patching@vger.kernel.org
Subject: [PATCH RFC] MIPS: livepatch: Add LIVEPATCH basic code
Date: Mon,  1 Mar 2021 19:30:01 +0800	[thread overview]
Message-ID: <1614598201-17858-1-git-send-email-hejinyang@loongson.cn> (raw)

Add the basic code of livepatch. livepatch is temporarily unavailable.
Two core functions are missing, one is DYNAMIC_FTRACE_WITH_REGS, and
another is save_stack_trace_tsk_reliable().
`Huang Pei <huangpei@loongson.cn>` is doing for ftrace. He will use
`-fpatchable-function-entry` to achieve more complete ftrace.
save_stack_trace_tsk_reliable() currently has difficulties. This function
may be improved in the future, but that seems to be a long time away.
This is also the reason for delivering this RFC. Hope to get any help.

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/Kconfig                   |  1 +
 arch/mips/include/asm/livepatch.h   | 28 ++++++++++++++++++++++++++++
 arch/mips/include/asm/thread_info.h |  1 +
 arch/mips/kernel/mcount.S           |  9 +++++++++
 4 files changed, 39 insertions(+)
 create mode 100644 arch/mips/include/asm/livepatch.h

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 47715cb..8ef92dd 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -478,6 +478,7 @@ config MACH_LOONGSON64
 	select CEVT_R4K
 	select CPU_HAS_WB
 	select FORCE_PCI
+	select HAVE_LIVEPATCH
 	select ISA
 	select I8259
 	select IRQ_MIPS_CPU
diff --git a/arch/mips/include/asm/livepatch.h b/arch/mips/include/asm/livepatch.h
new file mode 100644
index 0000000..26e1212
--- /dev/null
+++ b/arch/mips/include/asm/livepatch.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * livepatch.h - mips-specific Kernel Live Patching Core
+ */
+
+#ifndef _ASM_MIPS_LIVEPATCH_H
+#define _ASM_MIPS_LIVEPATCH_H
+
+#include <linux/ftrace.h>
+#include <linux/kallsyms.h>
+
+static inline void klp_arch_set_pc(struct ftrace_regs *fregs, unsigned long ip)
+{
+	struct pt_regs *regs = ftrace_get_regs(fregs);
+
+	regs->regs[31] = ip;
+}
+
+#define klp_get_ftrace_location klp_get_ftrace_location
+static inline unsigned long klp_get_ftrace_location(unsigned long faddr)
+{
+	unsigned long func_size, offset;
+
+	kallsyms_lookup_size_offset(faddr, &func_size, &offset);
+	return ftrace_location_range(faddr, faddr + func_size);
+}
+
+#endif
diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
index e2c352d..1e78359 100644
--- a/arch/mips/include/asm/thread_info.h
+++ b/arch/mips/include/asm/thread_info.h
@@ -117,6 +117,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_UPROBE		6	/* breakpointed or singlestepping */
 #define TIF_NOTIFY_SIGNAL	7	/* signal notifications exist */
 #define TIF_RESTORE_SIGMASK	9	/* restore signal mask in do_signal() */
+#define TIF_PATCH_PENDING	10	/* pending live patching update */
 #define TIF_USEDFPU		16	/* FPU was used by this task this quantum (SMP) */
 #define TIF_MEMDIE		18	/* is terminating due to OOM killer */
 #define TIF_NOHZ		19	/* in adaptive nohz mode */
diff --git a/arch/mips/kernel/mcount.S b/arch/mips/kernel/mcount.S
index cff52b2..8bf4c6a 100644
--- a/arch/mips/kernel/mcount.S
+++ b/arch/mips/kernel/mcount.S
@@ -113,6 +113,15 @@ ftrace_stub:
 	RETURN_BACK
 	END(ftrace_caller)
 
+#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
+NESTED(ftrace_regs_caller, PT_SIZE, ra)
+/* ftrace_regs_caller body */
+#ifdef CONFIG_LIVEPATCH
+/* Restore sp register */
+#endif
+	RETURN_BACK
+	END(ftrace_regs_caller)
+#endif
 #else	/* ! CONFIG_DYNAMIC_FTRACE */
 
 NESTED(_mcount, PT_SIZE, ra)
-- 
2.1.0


             reply	other threads:[~2021-03-01 11:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 11:30 Jinyang He [this message]
2021-03-10  8:18 ` [PATCH RFC] MIPS: livepatch: Add LIVEPATCH basic code Miroslav Benes
2021-03-10  8:56   ` Jinyang He

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=1614598201-17858-1-git-send-email-hejinyang@loongson.cn \
    --to=hejinyang@loongson.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=lixuefeng@loongson.cn \
    --cc=tsbogend@alpha.franken.de \
    --cc=yangtiezhu@loongson.cn \
    /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).