* [PATCH v3] powerpc: Add support for function error injection
@ 2018-06-07 9:52 Naveen N. Rao
2018-06-08 6:52 ` Samuel Mendoza-Jonas
2018-10-22 9:34 ` [v3] " Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: Naveen N. Rao @ 2018-06-07 9:52 UTC (permalink / raw)
To: Michael Ellerman; +Cc: Segher Boessenkool, linuxppc-dev
We implement regs_set_return_value() and override_function_with_return()
for this purpose.
On powerpc, a return from a function (blr) just branches to the location
contained in the link register. So, we can just update pt_regs rather
than redirecting execution to a dummy function that returns.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
The only change is to add a comment in override_function_with_return()
to clarify that we don't need to worry about 32-bit userspace while
emulating 'blr'.
- Naveen
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/error-injection.h | 13 +++++++++++++
arch/powerpc/include/asm/ptrace.h | 5 +++++
arch/powerpc/lib/Makefile | 2 ++
arch/powerpc/lib/error-inject.c | 16 ++++++++++++++++
5 files changed, 37 insertions(+)
create mode 100644 arch/powerpc/include/asm/error-injection.h
create mode 100644 arch/powerpc/lib/error-inject.c
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 076fe3094856..00dad3c759a0 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -187,6 +187,7 @@ config PPC
select HAVE_EBPF_JIT if PPC64
select HAVE_EFFICIENT_UNALIGNED_ACCESS if !(CPU_LITTLE_ENDIAN && POWER7_CPU)
select HAVE_FTRACE_MCOUNT_RECORD
+ select HAVE_FUNCTION_ERROR_INJECTION
select HAVE_FUNCTION_GRAPH_TRACER
select HAVE_FUNCTION_TRACER
select HAVE_GCC_PLUGINS
diff --git a/arch/powerpc/include/asm/error-injection.h b/arch/powerpc/include/asm/error-injection.h
new file mode 100644
index 000000000000..740c3075bdf4
--- /dev/null
+++ b/arch/powerpc/include/asm/error-injection.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#ifndef _ASM_ERROR_INJECTION_H
+#define _ASM_ERROR_INJECTION_H
+
+#include <linux/compiler.h>
+#include <linux/linkage.h>
+#include <asm/ptrace.h>
+#include <asm-generic/error-injection.h>
+
+void override_function_with_return(struct pt_regs *regs);
+
+#endif /* _ASM_ERROR_INJECTION_H */
diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
index e4923686e43a..c0705296c2f0 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -101,6 +101,11 @@ static inline long regs_return_value(struct pt_regs *regs)
return -regs->gpr[3];
}
+static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
+{
+ regs->gpr[3] = rc;
+}
+
#ifdef __powerpc64__
#define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
#else
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index d0ca13ad8231..dd43c5a53396 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -14,6 +14,8 @@ obj-y += string.o alloc.o code-patching.o feature-fixups.o
obj-$(CONFIG_PPC32) += div64.o copy_32.o crtsavres.o
+obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
+
# See corresponding test in arch/powerpc/Makefile
# 64-bit linker creates .sfpr on demand for final link (vmlinux),
# so it is only needed for modules, and only for older linkers which
diff --git a/arch/powerpc/lib/error-inject.c b/arch/powerpc/lib/error-inject.c
new file mode 100644
index 000000000000..407b992fb02f
--- /dev/null
+++ b/arch/powerpc/lib/error-inject.c
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <linux/error-injection.h>
+#include <linux/kprobes.h>
+#include <linux/uaccess.h>
+
+void override_function_with_return(struct pt_regs *regs)
+{
+ /*
+ * Emulate 'blr'. 'regs' represents the state on entry of a predefined
+ * function in the kernel/module, captured on a kprobe. We don't need
+ * to worry about 32-bit userspace on a 64-bit kernel.
+ */
+ regs->nip = regs->link;
+}
+NOKPROBE_SYMBOL(override_function_with_return);
--
2.17.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] powerpc: Add support for function error injection
2018-06-07 9:52 [PATCH v3] powerpc: Add support for function error injection Naveen N. Rao
@ 2018-06-08 6:52 ` Samuel Mendoza-Jonas
2018-10-22 9:34 ` [v3] " Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Samuel Mendoza-Jonas @ 2018-06-08 6:52 UTC (permalink / raw)
To: Naveen N. Rao, Michael Ellerman; +Cc: linuxppc-dev
On Thu, 2018-06-07 at 15:22 +0530, Naveen N. Rao wrote:
> We implement regs_set_return_value() and override_function_with_return()
> for this purpose.
>
> On powerpc, a return from a function (blr) just branches to the location
> contained in the link register. So, we can just update pt_regs rather
> than redirecting execution to a dummy function that returns.
>
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> ---
> The only change is to add a comment in override_function_with_return()
> to clarify that we don't need to worry about 32-bit userspace while
> emulating 'blr'.
Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
>
> - Naveen
>
> arch/powerpc/Kconfig | 1 +
> arch/powerpc/include/asm/error-injection.h | 13 +++++++++++++
> arch/powerpc/include/asm/ptrace.h | 5 +++++
> arch/powerpc/lib/Makefile | 2 ++
> arch/powerpc/lib/error-inject.c | 16 ++++++++++++++++
> 5 files changed, 37 insertions(+)
> create mode 100644 arch/powerpc/include/asm/error-injection.h
> create mode 100644 arch/powerpc/lib/error-inject.c
>
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 076fe3094856..00dad3c759a0 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -187,6 +187,7 @@ config PPC
> select HAVE_EBPF_JIT if PPC64
> select HAVE_EFFICIENT_UNALIGNED_ACCESS if !(CPU_LITTLE_ENDIAN && POWER7_CPU)
> select HAVE_FTRACE_MCOUNT_RECORD
> + select HAVE_FUNCTION_ERROR_INJECTION
> select HAVE_FUNCTION_GRAPH_TRACER
> select HAVE_FUNCTION_TRACER
> select HAVE_GCC_PLUGINS
> diff --git a/arch/powerpc/include/asm/error-injection.h b/arch/powerpc/include/asm/error-injection.h
> new file mode 100644
> index 000000000000..740c3075bdf4
> --- /dev/null
> +++ b/arch/powerpc/include/asm/error-injection.h
> @@ -0,0 +1,13 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#ifndef _ASM_ERROR_INJECTION_H
> +#define _ASM_ERROR_INJECTION_H
> +
> +#include <linux/compiler.h>
> +#include <linux/linkage.h>
> +#include <asm/ptrace.h>
> +#include <asm-generic/error-injection.h>
> +
> +void override_function_with_return(struct pt_regs *regs);
> +
> +#endif /* _ASM_ERROR_INJECTION_H */
> diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
> index e4923686e43a..c0705296c2f0 100644
> --- a/arch/powerpc/include/asm/ptrace.h
> +++ b/arch/powerpc/include/asm/ptrace.h
> @@ -101,6 +101,11 @@ static inline long regs_return_value(struct pt_regs *regs)
> return -regs->gpr[3];
> }
>
> +static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
> +{
> + regs->gpr[3] = rc;
> +}
> +
> #ifdef __powerpc64__
> #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
> #else
> diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
> index d0ca13ad8231..dd43c5a53396 100644
> --- a/arch/powerpc/lib/Makefile
> +++ b/arch/powerpc/lib/Makefile
> @@ -14,6 +14,8 @@ obj-y += string.o alloc.o code-patching.o feature-fixups.o
>
> obj-$(CONFIG_PPC32) += div64.o copy_32.o crtsavres.o
>
> +obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
> +
> # See corresponding test in arch/powerpc/Makefile
> # 64-bit linker creates .sfpr on demand for final link (vmlinux),
> # so it is only needed for modules, and only for older linkers which
> diff --git a/arch/powerpc/lib/error-inject.c b/arch/powerpc/lib/error-inject.c
> new file mode 100644
> index 000000000000..407b992fb02f
> --- /dev/null
> +++ b/arch/powerpc/lib/error-inject.c
> @@ -0,0 +1,16 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#include <linux/error-injection.h>
> +#include <linux/kprobes.h>
> +#include <linux/uaccess.h>
> +
> +void override_function_with_return(struct pt_regs *regs)
> +{
> + /*
> + * Emulate 'blr'. 'regs' represents the state on entry of a predefined
> + * function in the kernel/module, captured on a kprobe. We don't need
> + * to worry about 32-bit userspace on a 64-bit kernel.
> + */
> + regs->nip = regs->link;
> +}
> +NOKPROBE_SYMBOL(override_function_with_return);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [v3] powerpc: Add support for function error injection
2018-06-07 9:52 [PATCH v3] powerpc: Add support for function error injection Naveen N. Rao
2018-06-08 6:52 ` Samuel Mendoza-Jonas
@ 2018-10-22 9:34 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2018-10-22 9:34 UTC (permalink / raw)
To: Naveen N. Rao; +Cc: linuxppc-dev
On Thu, 2018-06-07 at 09:52:02 UTC, "Naveen N. Rao" wrote:
> We implement regs_set_return_value() and override_function_with_return()
> for this purpose.
>
> On powerpc, a return from a function (blr) just branches to the location
> contained in the link register. So, we can just update pt_regs rather
> than redirecting execution to a dummy function that returns.
>
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/7cd01b08d35f1b7d55686ed8cd57c9
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-10-22 9:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-07 9:52 [PATCH v3] powerpc: Add support for function error injection Naveen N. Rao
2018-06-08 6:52 ` Samuel Mendoza-Jonas
2018-10-22 9:34 ` [v3] " Michael Ellerman
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).