From patchwork Thu Dec 8 09:12:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 31245 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp89065wrr; Thu, 8 Dec 2022 01:15:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Egnwatf1XGlO7hEj/1JBoM7kLlJfb/jGHUbUMTivW8fbETlyDrLiV1ODfyi9U/+vbsk2w X-Received: by 2002:a17:902:cccd:b0:186:fd58:c706 with SMTP id z13-20020a170902cccd00b00186fd58c706mr8982126ple.4.1670490926922; Thu, 08 Dec 2022 01:15:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670490926; cv=none; d=google.com; s=arc-20160816; b=d4+FjhIjiHdJwmDsB+rFEeHH9ftdJihS0tdMwQGNJmqzpyJes9AmduOTfJyTCwOqXd NxATb6fqXkVyKQIotnN9+N4bkA8xQLq2IlmScEH2QwQ//wQzkU4rEuf4Ox2NDie5RYKs lAqyuEvg+sTmQ9PrNJWjkybsMJBYxkYdsyGHnRXHlOggPXop1ZGS6k/2hrti35YI71ho nPyV7B15hDMPYeCGQki9g8Ua55t9B7rfxSWcYwkBvApbAfvUb2AjbpcPju4kPczo5VQe 8KvqMWojH+rQKSGYutGYVxqnX0E/2HG0Ogia1u/EIsDFsQYKQ3MBtycUeMMfKuxLrI+m qNGg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fFvcRXWkcWa6nR2tlky9PIxvoz/0HaEozJ01/BEjYVk=; b=o3LaN1GMnzrfQiX3CQNAQJTZEXFCKsSp30of7NR8pRM1yYnGwnpomWtkJaq/2lbGWc vPBJKJY9UYoFTOnRb3slGK4GBFnpIkHDd/ITKWfiuRfNCvvnXFwLMF0dX319rW3Dyv6Z x09Eq+Yh63VM8CQ67M/UgI4l718nGbU1THC51gt/ERi0p05jStp1BKzM6kz4V4actZk1 /I1h9qKDKZ45dq6RQy/8B3YvCg6rHdMmOPfuQhNkfI+k+idQqNfz5vd64oCBK8ICYdvI KX5DriICf4Mh9oPIVR7N7kZBdP7GOwFPhYgHzdpGUGFnnlZkbFjx8rUYSG2E71NSVCl9 5MRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NfiR0RbR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t22-20020a634456000000b00461f71a53e1si23197690pgk.505.2022.12.08.01.15.10; Thu, 08 Dec 2022 01:15:26 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NfiR0RbR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230270AbiLHJOt (ORCPT + 99 others); Thu, 8 Dec 2022 04:14:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230269AbiLHJOD (ORCPT ); Thu, 8 Dec 2022 04:14:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E6807B4DC for ; Thu, 8 Dec 2022 01:13:01 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D378861E2A for ; Thu, 8 Dec 2022 09:13:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 809B5C433B5; Thu, 8 Dec 2022 09:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670490780; bh=zRX1WGkq5/5rOqQYIfz6c61zn3GcrYwh7ZPLZK+zvJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NfiR0RbRNujAJ6K1X6TnXkZZ3/Zc948Rt6E/c2FoHT0/JlFXrz3mk8DsAZUVgbScl LsLungth7n/AAli5J7gfhOr9cMB4UTifgzUBxMK2atbX4y9JGccdx80AYpKHjWWfz4 WiG2bIa3b//o8VZxlajkRnI4ckwQZebBmxf9S4vwB1aMXj8cH5EPTNtN+/nIHUow/3 fwvJ6sNYYhz0xUAZv5Ko8KGii7pPzH6T7FAOLLat9bzxBQuNRjT6pEYisMlHPCRIqg dQCFtbQEW9qtDQ6OpFMrMH1ik0S3baKq5S72jYEiv+4WLpFQhlfpU4FSYjJBWgj48H 2mDtaPJ47KaQw== From: guoren@kernel.org To: anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, conor.dooley@microchip.com, heiko@sntech.de, rostedt@goodmis.org, mhiramat@kernel.org, jolsa@redhat.com, bp@suse.de, jpoimboe@kernel.org, suagrfillet@gmail.com, andy.chiu@sifive.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Guo Ren Subject: [PATCH -next V5 1/7] riscv: ftrace: Fixup panic by disabling preemption Date: Thu, 8 Dec 2022 04:12:38 -0500 Message-Id: <20221208091244.203407-2-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221208091244.203407-1-guoren@kernel.org> References: <20221208091244.203407-1-guoren@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1751636694184534980?= X-GMAIL-MSGID: =?utf-8?q?1751636694184534980?= From: Andy Chiu In RISCV, we must use an AUIPC + JALR pair to encode an immediate, forming a jump that jumps to an address over 4K. This may cause errors if we want to enable kernel preemption and remove dependency from patching code with stop_machine(). For example, if a task was switched out on auipc. And, if we changed the ftrace function before it was switched back, then it would jump to an address that has updated 11:0 bits mixing with previous XLEN:12 part. p: patched area performed by dynamic ftrace ftrace_prologue: p| REG_S ra, -SZREG(sp) p| auipc ra, 0x? ------------> preempted ... change ftrace function ... p| jalr -?(ra) <------------- switched back p| REG_L ra, -SZREG(sp) func: xxx ret Fixes: afc76b8b8011 ("riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT") Signed-off-by: Andy Chiu Signed-off-by: Guo Ren --- @Andy, could you give the patch a Signed-off-by? I just copy your most important comment, so the first author should be you. First, let's fix the problem caused by my previous patch, and you can continue your ftrace preemption work. --- arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index ef8d66de5f38..da59182cb5f1 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -136,7 +136,7 @@ config RISCV select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_GRAPH_TRACER - select HAVE_FUNCTION_TRACER if !XIP_KERNEL + select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION config ARCH_MMAP_RND_BITS_MIN default 18 if 64BIT