Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1821706rwb; Fri, 2 Dec 2022 01:22:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf5QbTm9/lIs1IgZFwBn0kjOpi3u0c/xUyQWnSbULkCEPZ+ZX6EI9VRXvRZmg+EkhDvMlsID X-Received: by 2002:a17:902:bf01:b0:186:8bca:1d50 with SMTP id bi1-20020a170902bf0100b001868bca1d50mr53206091plb.158.1669972940354; Fri, 02 Dec 2022 01:22:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669972940; cv=none; d=google.com; s=arc-20160816; b=C1m1Q98yNSj06LCSMpmZ/GGY19J7rbhE6BvRkQ0UGEd6zTJsI99hcoq5x32PeY1s0P g/sLzEqRHJwe9pLpPW1epVCCEzamg36G9ERm3YMsyt8DhCmHOMpXvHbna12GOUsZQIra e4BiR3tRX7+6XlorP/gtaQICKoIONBqJOF4PqgnJQLNYuoyHhgXlcLk7STRZJe8wADnO GOSa7qzgVF/mUEgedNkBx2tP3+UtsyiL1oa+3zQGZR+k6sjq3LfkSNS9SslgJGueKUWM JWjTMFXcTcKg7h8xP19MM49gEj7ydi4G40srW2+3eZ0aBNHIibcXAuqfFciXSyzqxRxL hFNQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a17090311d000b00188baabb422si7481722plh.487.2022.12.02.01.22.10; Fri, 02 Dec 2022 01:22:20 -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 + 82 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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); -- 2.27.0