From patchwork Fri Dec 2 08:48:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 28775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp715996wrr; Fri, 2 Dec 2022 00:34:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Fes8WodAcrA6IcWhyLYkX0pR9meKtF2v/Z7bxqWDuMAD/kpI/T34+dqQkOvsMmf1UW62Q X-Received: by 2002:a05:6a00:2908:b0:56b:d738:9b with SMTP id cg8-20020a056a00290800b0056bd738009bmr51054937pfb.61.1669970090350; Fri, 02 Dec 2022 00:34:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669970090; cv=none; d=google.com; s=arc-20160816; b=r5N8+aGPEd8wLg6Ah0JzDV6Qgo5saU7fguYf84EJeQmgy6kr0cxpZK0QOiBX9G4v0I KBIh+7EcGsJ2UjWCIoXql5/PHhOH5LaAO20Vuth5XFaJcR8l6PzWKvpqm2a7KPovyKUi Y/VxUzWjCuVYLy8gIpTcfnqS8Z87S5nBIsYNQwY97JE3KHBUY8Ja3SOtbwYbCtK2OPd3 1TecsNt7+iVuUnlpRh6m3Z72qb66WKxz2L2hEwJPqra507bXP7QuKGfWmAoipJMDOWnD Igw88AEJBeRlEM49pqGYyGFnnpzdjhcHR1f08QkK11WPmvDrHuxlG5D6Plpjpa1mWxBp P3LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ZD58Y9C1uQfvDw/Q9zeeauGFzC/cAp8Pl/CT7wiCfEg=; b=ITeo0pjG9w+YoqtREysGOuUcjDoDAQoK/Qj7j/9S8JHxhVG/ldKwXFxYVaxIYaYB1S UyHpkUq/H2Z0X2GMAog3wh94t4TkRFHSt37yccS7zsRxypegDZ1f/6n14JGrJ+OVWX/p W0azC7LsV+e3kp6z6IIcs1fcvPP5Z51kcTgOGN7749gunqMHz/xoJJrpmAtMwkgRO6xM SexR0I2HichqGtV2Y0gi37WkuIcJLfroVdgBe03uJumXrWDdtAfv33pOsZg3O+R3fVsU 7qUtdPiaCHP0lDWF1KFQWgwBA9t/NfVDhcl0Sy90ks0AUU4xTFVTxkKvZOwjZp9wt/HC XRBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e1-20020a170902744100b00189b15ea35bsi4489855plt.208.2022.12.02.00.34.37; Fri, 02 Dec 2022 00:34:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232854AbiLBIdj (ORCPT + 99 others); Fri, 2 Dec 2022 03:33:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232884AbiLBIcc (ORCPT ); Fri, 2 Dec 2022 03:32:32 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B01BBC3FC1 for ; Fri, 2 Dec 2022 00:30:54 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NNmN231dDz15NKk; Fri, 2 Dec 2022 16:30:10 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 2 Dec 2022 16:30:52 +0800 From: Kefeng Wang To: Russell King , CC: , Kefeng Wang Subject: [PATCH] ARM: support function error injection Date: Fri, 2 Dec 2022 16:48:07 +0800 Message-ID: <20221202084807.76817-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751090557465453034?= X-GMAIL-MSGID: =?utf-8?q?1751090557465453034?= This enables HAVE_FUNCTION_ERROR_INJECTION by adding necessary regs_set_return_value() and override_function_with_return(). Simply tested according to Documentation/fault-injection/fault-injection.rst. Signed-off-by: Kefeng Wang --- arch/arm/Kconfig | 1 + arch/arm/include/asm/ptrace.h | 4 ++++ arch/arm/lib/Makefile | 2 ++ arch/arm/lib/error-inject.c | 10 ++++++++++ 4 files changed, 17 insertions(+) create mode 100644 arch/arm/lib/error-inject.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index a08c9d092a33..9092b68541f1 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -95,6 +95,7 @@ config ARM select HAVE_EXIT_THREAD select HAVE_FAST_GUP if ARM_LPAE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL + select HAVE_FUNCTION_ERROR_INJECTION select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER if !XIP_KERNEL select HAVE_GCC_PLUGINS diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h index 1408a6a15d0e..483b8ddfcb82 100644 --- a/arch/arm/include/asm/ptrace.h +++ b/arch/arm/include/asm/ptrace.h @@ -163,6 +163,10 @@ static inline unsigned long user_stack_pointer(struct pt_regs *regs) ((current_stack_pointer | (THREAD_SIZE - 1)) - 7) - 1; \ }) +static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc) +{ + regs->ARM_r0 = rc; +} /* * Update ITSTATE after normal execution of an IT block instruction. diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index 6d2ba454f25b..f2c2ef94b74d 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -48,3 +48,5 @@ ifeq ($(CONFIG_KERNEL_MODE_NEON),y) CFLAGS_xor-neon.o += $(NEON_FLAGS) obj-$(CONFIG_XOR_BLOCKS) += xor-neon.o endif + +obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o diff --git a/arch/arm/lib/error-inject.c b/arch/arm/lib/error-inject.c new file mode 100644 index 000000000000..5a5b405792ba --- /dev/null +++ b/arch/arm/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->ARM_lr); +} +NOKPROBE_SYMBOL(override_function_with_return);