From patchwork Wed Oct 4 13:10:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13408783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 296EDE7B60F for ; Wed, 4 Oct 2023 13:10:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=IlcqwAesteoMcjgVjXnPtF99VU0EXVLZ/st5cfmnCPA=; b=whn/5Ix1DMgZML cK0K3sANLraO4dx8BRJ/QCDoxEdgpm1aBelYTcM2ciUTolQIUZB5k/V8j+KkSvR88afC7MJ1RpHJ+ xg4UZLsgeNDuK/Rbj1cxm5rlS8Vbw7au6tnNEl7B1NTT5+AnY2ZZyx1dGdx6F2Lu2+6vc+djGwGlm IojCNyrB4m1mdWWO6sgeazHQwC1w61KTd3lcx+7yEamMHm44JxAVE4k6nRskS+oKYZqdlaxWbbiY+ Oq09rqKUjl8EsSniWZkEc1cvFJdob76jiNf6oq+41W/NbuTR9ynV7iB32hLSzg+fb/GCKHwmqI2Je 2YQOiqbllJZUziAislcA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qo1e9-0005SM-13; Wed, 04 Oct 2023 13:10:37 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qo1e3-0005Rh-2P for linux-riscv@lists.infradead.org; Wed, 04 Oct 2023 13:10:35 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-406532c49dcso4704595e9.0 for ; Wed, 04 Oct 2023 06:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1696425028; x=1697029828; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=z15iGiezxYK5XcqIfgGulDEdBAkSg8R0+TumWNSNnqo=; b=f8GU09IB4t5MYfCS1fQ1jk8SJ45pPm349jGHoT7zGQc5lbjHwMtnIdGa85Am5VYTSd qBD/ec1MFzHNm2KrZnn725mJmnzikLL7T4Ngrx2CN0GJfYGE3O784ns3dwd1T6ujpkog oxoDbNiEsVOdwK02QsWwH4CtbX0NLYsjGRnHu5HHwiiBhfGh40Fpqc8c468WlaI6PNpY kRIpuEMP7zrBNIBS346SxsSLUoii9otwRLpaEbRNeVdoSeRoCgu6qq1DjlxH63OY35oL XJa1BS/vPA4+BBHQwBDyFRezvxwSe+3xQ2TehgfM0hzmwH8YWY9zhkv+NOFV88bZWhUc LUuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696425028; x=1697029828; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=z15iGiezxYK5XcqIfgGulDEdBAkSg8R0+TumWNSNnqo=; b=u+RYH9WN8JRQsg8Vf6Z0wm4glLIGMUd8PgApz2E+ZAnhmUIemgvufofnHhFf4438ZO hl27Nvpb7qqh3+8i4i3x474moUSweoGxMpFuEwdFZHXvKwezhrlTtVD7YtmUOqDp6UjG cbuU+8RbWqZrtbC5NOl5981F7k79HvaezYnZxJ6NBqLCVVwNrGXERlYBxa0bq2AI0JGd F3L1KvKyLkze3UpWiJYGlaSDbfIARcvWGe3Ujqw4LVpDiUANVIJB7XblURwkzANq7yJn 582lndVpnaA+93+ReQsxg1rxyy68tc/9tZjMEVFk3erb6vHYi9PtKGLq6sFKXtIEYMcd RJBQ== X-Gm-Message-State: AOJu0YwK3DQ6buPe6UKyndrp1i6F09Qwe6tduI8hZ2xRUQwPHVUFZVnV ku5qvfaDdkL7tBfYhA0rIZifhA== X-Google-Smtp-Source: AGHT+IFnbZnW549ZWt1PzlFvEq2ZFwMTlc5GL20gDuzsNXnx6EeJFuLFcPl6tcuFSBDuZ7Gy71wyWw== X-Received: by 2002:a7b:ca59:0:b0:3fe:d637:7b25 with SMTP id m25-20020a7bca59000000b003fed6377b25mr2345430wml.0.1696425027197; Wed, 04 Oct 2023 06:10:27 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:9474:8d75:5115:42cb]) by smtp.gmail.com with ESMTPSA id m10-20020a7bce0a000000b00405953973c3sm1497074wmc.6.2023.10.04.06.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 06:10:26 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: blacklist assembly symbols for kprobe Date: Wed, 4 Oct 2023 15:10:09 +0200 Message-ID: <20231004131009.409193-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231004_061032_030383_3DB49F59 X-CRM114-Status: UNSURE ( 9.34 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Adding kprobes on some assembly functions (mainly exception handling) will result in crashes (either recursive trap or panic). To avoid such errors, add ASM_NOKPROBE() macro which allow adding specific symbols into the __kprobe_blacklist section and use to blacklist the following symbols that showed to be problematic: - handle_exception() - ret_from_exception() - handle_kernel_stack_overflow() Signed-off-by: Clément Léger Reviewed-by: Charlie Jenkins --- arch/riscv/include/asm/asm.h | 10 ++++++++++ arch/riscv/kernel/entry.S | 3 +++ 2 files changed, 13 insertions(+) diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h index 114bbadaef41..9194e334de15 100644 --- a/arch/riscv/include/asm/asm.h +++ b/arch/riscv/include/asm/asm.h @@ -142,6 +142,16 @@ REG_L x31, PT_T6(sp) .endm +/* Annotate a function as being unsuitable for kprobes. */ +#ifdef CONFIG_KPROBES +#define ASM_NOKPROBE(name) \ + .pushsection "_kprobe_blacklist", "aw"; \ + RISCV_PTR name; \ + .popsection +#else +#define ASM_NOKPROBE(name) +#endif + #endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_ASM_H */ diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 143a2bb3e697..f24bc4eeedde 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -101,6 +101,7 @@ _save_context: 1: tail do_trap_unknown SYM_CODE_END(handle_exception) +ASM_NOKPROBE(handle_exception) /* * The ret_from_exception must be called with interrupt disabled. Here is the @@ -167,6 +168,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception) sret #endif SYM_CODE_END(ret_from_exception) +ASM_NOKPROBE(ret_from_exception) #ifdef CONFIG_VMAP_STACK SYM_CODE_START_LOCAL(handle_kernel_stack_overflow) @@ -254,6 +256,7 @@ restore_caller_reg: move a0, sp tail handle_bad_stack SYM_CODE_END(handle_kernel_stack_overflow) +ASM_NOKPROBE(handle_kernel_stack_overflow) #endif SYM_CODE_START(ret_from_fork)