From patchwork Tue May 29 12:36:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Naveen N. Rao" X-Patchwork-Id: 922052 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40wCyT4fP0z9s0y for ; Tue, 29 May 2018 22:41:21 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40wCyT2vmKzDr5J for ; Tue, 29 May 2018 22:41:21 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=naveen.n.rao@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40wCrr0WSzzDr4q for ; Tue, 29 May 2018 22:36:27 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4TCYpSl084531 for ; Tue, 29 May 2018 08:36:26 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j95avcpuf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 May 2018 08:36:25 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 May 2018 13:36:23 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 29 May 2018 13:36:20 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4TCaJiu15204446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 May 2018 12:36:19 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 148F84C044; Tue, 29 May 2018 13:27:51 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 923454C04E; Tue, 29 May 2018 13:27:49 +0100 (BST) Received: from naverao1-tp.ibm.com (unknown [9.124.216.146]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 29 May 2018 13:27:49 +0100 (BST) From: "Naveen N. Rao" To: Ingo Molnar , Michael Ellerman , Masami Hiramatsu , Josef Bacik Subject: [PATCH 1/2] error-injection: Simplify arch specific helpers Date: Tue, 29 May 2018 18:06:02 +0530 X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: X-TM-AS-GCONF: 00 x-cbid: 18052912-0040-0000-0000-0000045E87CE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052912-0041-0000-0000-00002102F8E8 Message-Id: <8f4883f08feaf6e040255015af2da7bbc7741e41.1527596631.git.naveen.n.rao@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-29_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805290144 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" We already have an arch-independent way to set the instruction pointer with instruction_pointer_set(). Using this allows us to get rid of the need for override_function_with_return() that each architecture has to implement. Furthermore, just_return_func() only has to encode arch-specific assembly instructions to return from a function. Introduce a macro ARCH_FUNC_RET to provide the arch-specific instruction and move over just_return_func() to generic code. With these changes, architectures that already support kprobes, only just need to ensure they provide regs_set_return_value(), GET_IP() (for instruction_pointer_set()), and ARCH_FUNC_RET to support error injection. Signed-off-by: Naveen N. Rao --- arch/x86/include/asm/error-injection.h | 6 +----- arch/x86/lib/Makefile | 1 - arch/x86/lib/error-inject.c | 20 -------------------- include/asm-generic/error-injection.h | 6 ++++++ include/linux/error-injection.h | 1 + kernel/fail_function.c | 2 +- kernel/trace/bpf_trace.c | 2 +- lib/error-inject.c | 8 ++++++++ 8 files changed, 18 insertions(+), 28 deletions(-) delete mode 100644 arch/x86/lib/error-inject.c diff --git a/arch/x86/include/asm/error-injection.h b/arch/x86/include/asm/error-injection.h index 47b7a1296245..f3f22e237b86 100644 --- a/arch/x86/include/asm/error-injection.h +++ b/arch/x86/include/asm/error-injection.h @@ -2,12 +2,8 @@ #ifndef _ASM_ERROR_INJECTION_H #define _ASM_ERROR_INJECTION_H -#include -#include -#include #include -asmlinkage void just_return_func(void); -void override_function_with_return(struct pt_regs *regs); +#define ARCH_FUNC_RET "ret" #endif /* _ASM_ERROR_INJECTION_H */ diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index 25a972c61b0a..f23934bbaf4e 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -26,7 +26,6 @@ lib-y += memcpy_$(BITS).o lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o insn-eval.o lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o -lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o lib-$(CONFIG_RETPOLINE) += retpoline.o obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o diff --git a/arch/x86/lib/error-inject.c b/arch/x86/lib/error-inject.c deleted file mode 100644 index 3cdf06128d13..000000000000 --- a/arch/x86/lib/error-inject.c +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#include -#include - -asmlinkage void just_return_func(void); - -asm( - ".type just_return_func, @function\n" - ".globl just_return_func\n" - "just_return_func:\n" - " ret\n" - ".size just_return_func, .-just_return_func\n" -); - -void override_function_with_return(struct pt_regs *regs) -{ - regs->ip = (unsigned long)&just_return_func; -} -NOKPROBE_SYMBOL(override_function_with_return); diff --git a/include/asm-generic/error-injection.h b/include/asm-generic/error-injection.h index 296c65442f00..8ac152cc204a 100644 --- a/include/asm-generic/error-injection.h +++ b/include/asm-generic/error-injection.h @@ -3,6 +3,9 @@ #define _ASM_GENERIC_ERROR_INJECTION_H #if defined(__KERNEL__) && !defined(__ASSEMBLY__) +#include +#include + enum { EI_ETYPE_NONE, /* Dummy value for undefined case */ EI_ETYPE_NULL, /* Return NULL if failure */ @@ -27,6 +30,9 @@ static struct error_injection_entry __used \ .addr = (unsigned long)fname, \ .etype = EI_ETYPE_##_etype, \ }; + +asmlinkage void just_return_func(void); + #else #define ALLOW_ERROR_INJECTION(fname, _etype) #endif diff --git a/include/linux/error-injection.h b/include/linux/error-injection.h index 280c61ecbf20..f4a0b23423d2 100644 --- a/include/linux/error-injection.h +++ b/include/linux/error-injection.h @@ -4,6 +4,7 @@ #ifdef CONFIG_FUNCTION_ERROR_INJECTION +#include #include extern bool within_error_injection_list(unsigned long addr); diff --git a/kernel/fail_function.c b/kernel/fail_function.c index 1d5632d8bbcc..0ae2ca4a29e8 100644 --- a/kernel/fail_function.c +++ b/kernel/fail_function.c @@ -183,7 +183,7 @@ static int fei_kprobe_handler(struct kprobe *kp, struct pt_regs *regs) if (should_fail(&fei_fault_attr, 1)) { regs_set_return_value(regs, attr->retval); - override_function_with_return(regs); + instruction_pointer_set(regs, (unsigned long)&just_return_func); /* Kprobe specific fixup */ reset_current_kprobe(); preempt_enable_no_resched(); diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 56ba0f2a01db..23f1f4ffda6c 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -84,7 +84,7 @@ EXPORT_SYMBOL_GPL(trace_call_bpf); BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc) { regs_set_return_value(regs, rc); - override_function_with_return(regs); + instruction_pointer_set(regs, (unsigned long)&just_return_func); return 0; } diff --git a/lib/error-inject.c b/lib/error-inject.c index c0d4600f4896..7fdc92b5babc 100644 --- a/lib/error-inject.c +++ b/lib/error-inject.c @@ -20,6 +20,14 @@ struct ei_entry { void *priv; }; +asm( + ".type just_return_func, @function\n" + ".globl just_return_func\n" + "just_return_func:\n" + ARCH_FUNC_RET "\n" + ".size just_return_func, .-just_return_func\n" +); + bool within_error_injection_list(unsigned long addr) { struct ei_entry *ent; From patchwork Tue May 29 12:36:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Naveen N. Rao" X-Patchwork-Id: 922057 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40wD123f1Lz9s0y for ; Tue, 29 May 2018 22:43:34 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40wD121Px7zDr4q for ; Tue, 29 May 2018 22:43:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=naveen.n.rao@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40wCrv2NBfzDr4h for ; Tue, 29 May 2018 22:36:30 +1000 (AEST) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4TCZ2Hj126352 for ; Tue, 29 May 2018 08:36:28 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0b-001b2d01.pphosted.com with ESMTP id 2j95wquc78-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 May 2018 08:36:27 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 May 2018 13:36:26 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 29 May 2018 13:36:23 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4TCaMAt21102790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 May 2018 12:36:22 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF4204C050; Tue, 29 May 2018 13:27:53 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A8764C040; Tue, 29 May 2018 13:27:52 +0100 (BST) Received: from naverao1-tp.ibm.com (unknown [9.124.216.146]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 29 May 2018 13:27:52 +0100 (BST) From: "Naveen N. Rao" To: Ingo Molnar , Michael Ellerman , Masami Hiramatsu , Josef Bacik Subject: [PATCH 2/2] powerpc: Add support for function error injection Date: Tue, 29 May 2018 18:06:03 +0530 X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: X-TM-AS-GCONF: 00 x-cbid: 18052912-0012-0000-0000-000005DBA950 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052912-0013-0000-0000-000019590CFB Message-Id: <5ad23690185a90a887514d702ecb45783090d7c0.1527596631.git.naveen.n.rao@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-29_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805290144 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Signed-off-by: Naveen N. Rao Acked-by: Michael Ellerman --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/error-injection.h | 9 +++++++++ arch/powerpc/include/asm/ptrace.h | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 arch/powerpc/include/asm/error-injection.h diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 23247fa551e7..ed1ab693f945 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -194,6 +194,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..b596eca04ef9 --- /dev/null +++ b/arch/powerpc/include/asm/error-injection.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ERROR_INJECTION_H +#define _ASM_ERROR_INJECTION_H + +#include + +#define ARCH_FUNC_RET "blr" + +#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