Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1684347ybh; Tue, 14 Jul 2020 04:43:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzX1Z5YH+Khn3lTEde/Qnt5JuNp2GpSUQ0tLbTzAuyZXWmbj7Pi1br3wWhgrpRNV0gGGCm7 X-Received: by 2002:a05:6402:1d35:: with SMTP id dh21mr4185380edb.186.1594727038368; Tue, 14 Jul 2020 04:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594727038; cv=none; d=google.com; s=arc-20160816; b=zlpdY0QYb3Pzuq3m7bPOFhdrUV3Q1iPEZRFA4TnhQ1mg0h9So735xI7NRCCB3HsQ0c ZxX8HhEfPUBT8RVOSQJyHttsakq1EU7y8ns+h15jtiwv7pGBv1Wyl4yI8Fwh1yXEjX9Z FhLLeru1EYFhPCYWaJ1nB/QrNY2uHEmt+AWig3v9CHAa0TvRNOfB1cHpcdZQbL3sFl+O otaPAytX8OXR9II7zUvnr92hYawxFSiFl28MGlm5soPywM6xvs/subiugJze2yi2BvE+ Yk4FL5xiNefJAmSRlKg6ypoXS04kKncSLIxohatTTJbDolKLRuhbmucP4Nb+Ukziw3o5 pNiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=M+6Pnsqgs89KTEDlJlt3WaUmjnNTj7zMY2RieyG+BXM=; b=aAAkvJlZIErEaQBElMKWfiHXuSRhqn2p4tAeoIaEnzZ4sUlVLi6yQV+FJVU6pwAFFb tktJ3IIIUYJbVaXtfM3PLhrRP9w/RrEhfROBZbgMxj+ukws+2szQMVhtEB7jjlgyStVG 85mO+vSRQkPnQFrXwBmad0JHsc3MxJpNLToc9WAichGZeoleo+Zc492DSrMLLV3LUG3R 8l51xbu74IVWBppd9cPLnJEVqfZZRojZyVs71PUbQDRTeljMOzEg8IIOQ6HtlRZIduxr AydH/YIRdsVJYJD4Uf/Fa4TRPGdvYoLaL+8wKQi1JjKto4uNpCPhQI3ySiY5yw9Wf0PZ Y0rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tE0u9TlA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 17si10777014ejw.686.2020.07.14.04.43.34; Tue, 14 Jul 2020 04:43:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tE0u9TlA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728047AbgGNLnN (ORCPT + 99 others); Tue, 14 Jul 2020 07:43:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:55078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728018AbgGNLnL (ORCPT ); Tue, 14 Jul 2020 07:43:11 -0400 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9958D20BED; Tue, 14 Jul 2020 11:43:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594726990; bh=cVmijVoFVzbUvu8fDT/dJyJnUDFjkjRUgn8Ctil7QrQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tE0u9TlAoXY3svJF3yeRIYYYcEzsS2duKcVk5vMd62IsQrVixbg63cI1xTh0aCFYA UtbBHxPX6ThWFG2vjLypD7C+yUbAG0G9qL4NbODpZdsdLrr575vmJILb7RwZGW0Eus EeWMpfWFpBnKNVCZkWWALc57eUAzndusdm8nSojk= Date: Tue, 14 Jul 2020 20:43:05 +0900 From: Masami Hiramatsu To: guoren@kernel.org Cc: palmerdabbelt@google.com, paul.walmsley@sifive.com, oleg@redhat.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, anup@brainfault.org, linux-csky@vger.kernel.org, greentime.hu@sifive.com, zong.li@sifive.com, me@packi.ch, bjorn.topel@gmail.com, Guo Ren Subject: Re: [PATCH v3 7/7] riscv: Add support for function error injection Message-Id: <20200714204305.89ee1183f7c3fc4400e6d7c6@kernel.org> In-Reply-To: <1594683562-68149-8-git-send-email-guoren@kernel.org> References: <1594683562-68149-1-git-send-email-guoren@kernel.org> <1594683562-68149-8-git-send-email-guoren@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Guo, On Mon, 13 Jul 2020 23:39:22 +0000 guoren@kernel.org wrote: > From: Guo Ren > > Inspired by the commit 42d038c4fb00 ("arm64: Add support for function > error injection"), this patch supports function error injection for > riscv. > > This patch mainly support two functions: one is regs_set_return_value() > which is used to overwrite the return value; the another function is > override_function_with_return() which is to override the probed > function returning and jump to its caller. > > Test log: > cd /sys/kernel/debug/fail_function > echo sys_clone > inject > echo 100 > probability > echo 1 > interval > ls / > [ 313.176875] FAULT_INJECTION: forcing a failure. > [ 313.176875] name fail_function, interval 1, probability 100, space 0, times 1 > [ 313.184357] CPU: 0 PID: 87 Comm: sh Not tainted 5.8.0-rc5-00007-g6a758cc #117 > [ 313.187616] Call Trace: > [ 313.189100] [] walk_stackframe+0x0/0xc2 > [ 313.191626] [] show_stack+0x40/0x4c > [ 313.193927] [] dump_stack+0x7c/0x96 > [ 313.194795] [] should_fail+0x140/0x142 > [ 313.195923] [] fei_kprobe_handler+0x2c/0x5a > [ 313.197687] [] kprobe_breakpoint_handler+0xb4/0x18a > [ 313.200054] [] do_trap_break+0x36/0xca > [ 313.202147] [] ret_from_exception+0x0/0xc > [ 313.204556] [] ret_from_syscall+0x0/0x2 > -sh: can't fork: Invalid argument OK, this looks good to me. Reviewed-by: Masami Hiramatsu Thank you, > > Signed-off-by: Guo Ren > Cc: Masami Hiramatsu > Cc: Palmer Dabbelt > Cc: Paul Walmsley > --- > arch/riscv/Kconfig | 1 + > arch/riscv/include/asm/ptrace.h | 6 ++++++ > arch/riscv/lib/Makefile | 2 ++ > arch/riscv/lib/error-inject.c | 10 ++++++++++ > 4 files changed, 19 insertions(+) > create mode 100644 arch/riscv/lib/error-inject.c > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 0e9f5eb..ad73174 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -58,6 +58,7 @@ config RISCV > select HAVE_DMA_CONTIGUOUS if MMU > select HAVE_EBPF_JIT if MMU > select HAVE_FUTEX_CMPXCHG if FUTEX > + select HAVE_FUNCTION_ERROR_INJECTION > select HAVE_GENERIC_VDSO if MMU && 64BIT > select HAVE_KPROBES > select HAVE_KPROBES_ON_FTRACE > diff --git a/arch/riscv/include/asm/ptrace.h b/arch/riscv/include/asm/ptrace.h > index 23372bb..cb4abb6 100644 > --- a/arch/riscv/include/asm/ptrace.h > +++ b/arch/riscv/include/asm/ptrace.h > @@ -109,6 +109,12 @@ static inline unsigned long regs_return_value(struct pt_regs *regs) > return regs->a0; > } > > +static inline void regs_set_return_value(struct pt_regs *regs, > + unsigned long val) > +{ > + regs->a0 = val; > +} > + > extern int regs_query_register_offset(const char *name); > extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, > unsigned int n); > diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile > index 0d0db80..04baa93 100644 > --- a/arch/riscv/lib/Makefile > +++ b/arch/riscv/lib/Makefile > @@ -4,3 +4,5 @@ lib-y += memcpy.o > lib-y += memset.o > lib-y += uaccess.o > lib-$(CONFIG_64BIT) += tishift.o > + > +obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o > diff --git a/arch/riscv/lib/error-inject.c b/arch/riscv/lib/error-inject.c > new file mode 100644 > index 00000000..d667ade > --- /dev/null > +++ b/arch/riscv/lib/error-inject.c > @@ -0,0 +1,10 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include > +#include > + > +void override_function_with_return(struct pt_regs *regs) > +{ > + instruction_pointer_set(regs, regs->ra); > +} > +NOKPROBE_SYMBOL(override_function_with_return); > -- > 2.7.4 > -- Masami Hiramatsu