From patchwork Tue Mar 26 20:30:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13605079 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 AB533C54E67 for ; Tue, 26 Mar 2024 20:31:57 +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:References:In-Reply-To: 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: List-Owner; bh=vGhUx3WPMXe1D9XI3G2gC/oHVn9h+Za7IQP7Hl+CFaY=; b=tViEUgcXTFGnOd bLlc1oeSvzHo4WGzGC32TzbNZoq8ktJGPsQEIgSuugSkL2i9mfH6TNMY/U6R/iXdhK7ZGvSiKbnfe MlxNA8jsMimj6TdqGDY+bW8T5Zk+1tzz828kgBC9bzLG+vpCBSgdwjSko6zLXa/e144XRR7DEhSyl O2nHe2/UL7rkfnuX34rAuT4I1E2MevZY4XbBsBqr/S0ZimHsifnTcxdm/o7rwd4Ythhv1+nx22pRN ERIsgqZ5jKHJCD8BIQdyeqjJTmEHtrkz8aHKH5/NhJMGtO/+Gbz2JmhZaPLIgJyYES0q0721T7IV1 D+eOoeeQU3mQNVmqdrsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpDSW-00000006NJR-451K; Tue, 26 Mar 2024 20:31:49 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpDSS-00000006NEW-3yRE for linux-riscv@lists.infradead.org; Tue, 26 Mar 2024 20:31:47 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-565c6cf4819so296841a12.1 for ; Tue, 26 Mar 2024 13:31:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1711485095; x=1712089895; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/lh9U/vyewLtbDFJmjDS8r3hvigj8QyKr7Iw+wfw7H8=; b=dcYpGJdd0Jgqlzg5elOzbsQ7eP8haypYwdrVWgf4qj7BH3R29rofuquDv7M7hQ5ZSl fjJyzEV5RxsdSLGya8eXU3BX1NdAryE/pvlgJ003Ctz6Sq3ZDXlTNA1z1yNmMIi3saJB /tRxePwURkgvO0OpIZ+CbsV5cy4AAS71mPv+MZGxYYHh/1vmNLnFU3/qn3qNFioUcFKz Ps7aSbqLCrit8Pc1fb88dd9p7oALah1qL1QBWlDsSvCXlUK2l0Y1HpD8/W2IMdli4rj9 GejZiV/LAn9Zc1WMxa0qONyfXt37sDTZNkZJPYbsTfT42/Gnrkce5W6vTmNfW/OGY2LU B2WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711485095; x=1712089895; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/lh9U/vyewLtbDFJmjDS8r3hvigj8QyKr7Iw+wfw7H8=; b=nqN+DuJUgbFpbGTeJPD2mtRtYNFpH45UNSFGrpRXoK+dUm4DGKYbw2fAMYluBcKVCh hEHjBjXDGpra1coQvxSb7iLKP8UzcQ6Nmzf2XoLnyS4ocDQ5qaQRx7CFwilYNFMUD3h1 qIk8+nXFyfSIxT2VU12G4QGri1Ac9tJA0gm+JgP8tsgDEDfUQnYKHtWeo4LMMcG81cAK JZMCPi+WI/zLqDs2vuDoBd/FbsvxexbbLtewsGwFB1cLUd2VVvBBXTlC1/YCsQcbAWa8 xmuorfgBlGx411Ar799Ir1YZiBfrAMEYGNH1GpEMzMF5DtJxqAien6JyHPC2FV9FHgxC Dk0A== X-Forwarded-Encrypted: i=1; AJvYcCWHLrX1iZNjvzxuzy1GHBQosnpcR2rjZR66mtig8UWXgntkuHT/ZN6gWYgqxyfzyNv1dLpYgePsvCzxBlUJS+Yd3ej68rFPZLfcX6y+PNi7 X-Gm-Message-State: AOJu0YytzozYVb3R7tB1bxfRWkzT8/fVmXD5dTNHLV+7jzlvcuF5zTqh FOVCuGXTzORRoUR2DiCo6xJ6XWNPXdLmotDokgtYNmGngVxHJ7Bq8Fgg5Uv5RfZdMVLDVaSiYYG M X-Google-Smtp-Source: AGHT+IHn5ukEbrOXa/xSQN4+acm8vFx4OO0mc31kNe5p13cGaOnb1+adQLu+u+OBPHzLUDOI3daDvw== X-Received: by 2002:a17:907:7213:b0:a4d:fb90:4a4e with SMTP id dr19-20020a170907721300b00a4dfb904a4emr1302204ejc.2.1711485095264; Tue, 26 Mar 2024 13:31:35 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com ([2a02:8440:5240:d2b3:9657:7432:d88d:84a9]) by smtp.gmail.com with ESMTPSA id ae12-20020a17090725cc00b00a47522c193asm3273954ejc.196.2024.03.26.13.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 13:31:34 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Pu Lehui , Daniel Borkmann , Puranjay Mohan , Zong Li , Masami Hiramatsu , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Evgenii Shatokhin Subject: [PATCH 1/2] riscv: Fix warning by declaring arch_cpu_idle() as noinstr Date: Tue, 26 Mar 2024 21:30:16 +0100 Message-Id: <20240326203017.310422-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240326203017.310422-1-alexghiti@rivosinc.com> References: <20240326203017.310422-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240326_133145_124969_A110DB31 X-CRM114-Status: GOOD ( 10.21 ) 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 The following warning appears when using ftrace: [89855.443413] RCU not on for: arch_cpu_idle+0x0/0x1c [89855.445640] WARNING: CPU: 5 PID: 0 at include/linux/trace_recursion.h:162 arch_ftrace_ops_list_func+0x208/0x228 [89855.445824] Modules linked in: xt_conntrack(E) nft_chain_nat(E) xt_MASQUERADE(E) nf_conntrack_netlink(E) xt_addrtype(E) nft_compat(E) nf_tables(E) nfnetlink(E) br_netfilter(E) cfg80211(E) nls_iso8859_1(E) ofpart(E) redboot(E) cmdlinepart(E) cfi_cmdset_0001(E) virtio_net(E) cfi_probe(E) cfi_util(E) 9pnet_virtio(E) gen_probe(E) net_failover(E) virtio_rng(E) failover(E) 9pnet(E) physmap(E) map_funcs(E) chipreg(E) mtd(E) uio_pdrv_genirq(E) uio(E) dm_multipath(E) scsi_dh_rdac(E) scsi_dh_emc(E) scsi_dh_alua(E) drm(E) efi_pstore(E) backlight(E) ip_tables(E) x_tables(E) raid10(E) raid456(E) async_raid6_recov(E) async_memcpy(E) async_pq(E) async_xor(E) xor(E) async_tx(E) raid6_pq(E) raid1(E) raid0(E) virtio_blk(E) [89855.451563] CPU: 5 PID: 0 Comm: swapper/5 Tainted: G E 6.8.0-rc6ubuntu-defconfig #2 [89855.451726] Hardware name: riscv-virtio,qemu (DT) [89855.451899] epc : arch_ftrace_ops_list_func+0x208/0x228 [89855.452016] ra : arch_ftrace_ops_list_func+0x208/0x228 [89855.452119] epc : ffffffff8016b216 ra : ffffffff8016b216 sp : ffffaf808090fdb0 [89855.452171] gp : ffffffff827c7680 tp : ffffaf808089ad40 t0 : ffffffff800c0dd8 [89855.452216] t1 : 0000000000000001 t2 : 0000000000000000 s0 : ffffaf808090fe30 [89855.452306] s1 : 0000000000000000 a0 : 0000000000000026 a1 : ffffffff82cd6ac8 [89855.452423] a2 : ffffffff800458c8 a3 : ffffaf80b1870640 a4 : 0000000000000000 [89855.452646] a5 : 0000000000000000 a6 : 00000000ffffffff a7 : ffffffffffffffff [89855.452698] s2 : ffffffff82766872 s3 : ffffffff80004caa s4 : ffffffff80ebea90 [89855.452743] s5 : ffffaf808089bd40 s6 : 8000000a00006e00 s7 : 0000000000000008 [89855.452787] s8 : 0000000000002000 s9 : 0000000080043700 s10: 0000000000000000 [89855.452831] s11: 0000000000000000 t3 : 0000000000100000 t4 : 0000000000000064 [89855.452874] t5 : 000000000000000c t6 : ffffaf80b182dbfc [89855.452929] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003 [89855.453053] [] arch_ftrace_ops_list_func+0x208/0x228 [89855.453191] [] ftrace_call+0x8/0x22 [89855.453265] [] do_idle+0x24c/0x2ca [89855.453357] [] return_to_handler+0x0/0x26 [89855.453429] [] smp_callin+0x92/0xb6 [89855.453785] ---[ end trace 0000000000000000 ]--- To fix this, mark arch_cpu_idle() as noinstr, like it is done in commit a9cbc1b471d2 ("s390/idle: mark arch_cpu_idle() noinstr"). Reported-by: Evgenii Shatokhin Closes: https://lore.kernel.org/linux-riscv/51f21b87-ebed-4411-afbc-c00d3dea2bab@yadro.com/ Fixes: cfbc4f81c9d0 ("riscv: Select ARCH_WANTS_NO_INSTR") Signed-off-by: Alexandre Ghiti Reviewed-by: Andy Chiu Tested-by: Andy Chiu --- arch/riscv/kernel/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 92922dbd5b5c..6abeecbfc51d 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -37,7 +37,7 @@ EXPORT_SYMBOL(__stack_chk_guard); extern asmlinkage void ret_from_fork(void); -void arch_cpu_idle(void) +void noinstr arch_cpu_idle(void) { cpu_do_idle(); } From patchwork Tue Mar 26 20:30:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13605098 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 40D42C54E67 for ; Tue, 26 Mar 2024 20:33:00 +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:References:In-Reply-To: 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: List-Owner; bh=jOby5AKatMHXVEv5WhHPlHmxYjNldHn0umzV07W6lX4=; b=vssIECgxTPA/pd 7klDH/rkD7QhkN81vz8sCgp5ppDqzIHC26XhLlfnJje9abg+bkCL4cAJvB2Ir6CUYo7oI6H8HOacm 09ZR/K7V8h5YEp8pFm1RMmmx6Dxlvaw5trZdinlNyhJ0v2F7E2jRm9FEE5OiHiFHAIwNwt2oYMmgq CchUsVagoewbvd7Adncg51kUpQ2XQkFFbEiitMQr0nUvq6YBaY1U6wSk8aqGw+ateMVYPB3RzYgrp /Sq9JZjuTzqtttWEqwSTwUAx75EeEUjT9VTjdEHIccxAfEDBBS75F3b4ZzrAgyad8fYPbPo1kSGR0 iJBXT9oi2L7IxUDvFTuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpDTb-00000006NZS-2d2R; Tue, 26 Mar 2024 20:32:55 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpDTO-00000006NU1-0HEa for linux-riscv@lists.infradead.org; Tue, 26 Mar 2024 20:32:53 +0000 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-56c29599e0cso1545852a12.0 for ; Tue, 26 Mar 2024 13:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1711485158; x=1712089958; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SwoTWlECTszcl/qxdYVc4t6fpZ8kE/2UkB07bRVsSm8=; b=vHQPR0E5BqJK2/QxKOySsYLQBK9Fk1/ZE/HFT6Fw20Td4wepBGJ1eLwnx64DOoXp/u 6O8Ko2C4Nbelm1SuS20kqPix8mKezU7yyMKaf/RZ8LvOV9LxN9urWiRQUqEgsOYzuqWz xmpSJUSMCBayr7Y3RI7Do0gSfM14poSqV0luqLFtj07GTRTzkxN6SksnO0CWMgyBxlTS VGtmkpuAto89EeH9rAQL9Sl6fq6eTTPeWdyomxoAptsc5XwPUtJmBw86x1Ev5BDoaum3 7QJyvtsal1cQRDIGOq2PLBVpN2FmiG/q/WyVjUx4KFqZDz4oRSc3kEpOr9uotSS0ujhB NW+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711485158; x=1712089958; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SwoTWlECTszcl/qxdYVc4t6fpZ8kE/2UkB07bRVsSm8=; b=ODt4dEZ3qFgZALOWZE1/xLUr14c8E2qn46rfEBWqT27VbkaMvzIQxyoS1lZj921SGC UrG0FzzOCYHlNkQ0h2YBf2bggMt1q689W+SC0nJAEkhokxzseqRNWyjnWD7uLvF7Dk9O qpL73q++8THRadC5CStp6w5pD/bkaubSTbpZFi3fes0mbFhEExif8cCLsAHh8SNJ92qx GhSRYb2ZofHcRAMXSyNMR+XYMvrRixvwr3+099CwlHQXZY8oQyQKkr6ft62AvehK1VoT nEIVLw3SvDZ65dp6nfWRYrIVrI3z/mjdHC8zz/7Wi+O8bgwGi2BG+lC9XXRgmvla/ZVI oJKA== X-Forwarded-Encrypted: i=1; AJvYcCV+GV6Km0RpIgHty/6at5RH1Bl2Ucxcz5RAFywYuUJWRBhBsXIcLnna5bm3zFXc5rnZJdH4ao9bCPg8+PYitEwUGDx7ZejUWT/KivsH7cER X-Gm-Message-State: AOJu0YwGp+Ku3USbjsY6aKZQCL79FssHPoS4X2B9tffcm153U3aNHwk+ rLXo7+JrH5qp8HEdfaqGZTuU2jY58r+hlBqfwrULRJgUapOERVJdOLLVsQkVjsQ= X-Google-Smtp-Source: AGHT+IENt7YBLnNtoUOQOQp272wkaUn+XI5a9KNpsaZCh2RNyyuvnhB+Bx/GceA3IeXjeVnoNmMyRA== X-Received: by 2002:a50:8e12:0:b0:565:bb25:bb7a with SMTP id 18-20020a508e12000000b00565bb25bb7amr3175538edw.24.1711485157973; Tue, 26 Mar 2024 13:32:37 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com ([2a02:8440:5240:d2b3:9657:7432:d88d:84a9]) by smtp.gmail.com with ESMTPSA id da12-20020a056402176c00b0056b816e253esm4525782edb.13.2024.03.26.13.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 13:32:37 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Pu Lehui , Daniel Borkmann , Puranjay Mohan , Zong Li , Masami Hiramatsu , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrea Parri , Andy Chiu Subject: [PATCH 2/2] riscv: Disable preemption when using patch_map() Date: Tue, 26 Mar 2024 21:30:17 +0100 Message-Id: <20240326203017.310422-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240326203017.310422-1-alexghiti@rivosinc.com> References: <20240326203017.310422-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240326_133249_254884_950189A1 X-CRM114-Status: GOOD ( 11.62 ) 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 patch_map() uses fixmap mappings to circumvent the non-writability of the kernel text mapping. The __set_fixmap() function only flushes the current cpu tlb, it does not emit an IPI so we must make sure that while we use a fixmap mapping, the current task is not migrated on another cpu which could miss the newly introduced fixmap mapping. So in order to avoid any task migration, disable the preemption. Reported-by: Andrea Parri Closes: https://lore.kernel.org/all/ZcS+GAaM25LXsBOl@andrea/ Reported-by: Andy Chiu Closes: https://lore.kernel.org/linux-riscv/CABgGipUMz3Sffu-CkmeUB1dKVwVQ73+7=sgC45-m0AE9RCjOZg@mail.gmail.com/ Fixes: cad539baa48f ("riscv: implement a memset like function for text") Fixes: 0ff7c3b33127 ("riscv: Use text_mutex instead of patch_lock") Co-developed-by: Andy Chiu Signed-off-by: Andy Chiu Signed-off-by: Alexandre Ghiti --- arch/riscv/kernel/patch.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c index 37e87fdcf6a0..30e12b310cab 100644 --- a/arch/riscv/kernel/patch.c +++ b/arch/riscv/kernel/patch.c @@ -80,6 +80,8 @@ static int __patch_insn_set(void *addr, u8 c, size_t len) */ lockdep_assert_held(&text_mutex); + preempt_disable(); + if (across_pages) patch_map(addr + PAGE_SIZE, FIX_TEXT_POKE1); @@ -92,6 +94,8 @@ static int __patch_insn_set(void *addr, u8 c, size_t len) if (across_pages) patch_unmap(FIX_TEXT_POKE1); + preempt_enable(); + return 0; } NOKPROBE_SYMBOL(__patch_insn_set); @@ -122,6 +126,8 @@ static int __patch_insn_write(void *addr, const void *insn, size_t len) if (!riscv_patch_in_stop_machine) lockdep_assert_held(&text_mutex); + preempt_disable(); + if (across_pages) patch_map(addr + PAGE_SIZE, FIX_TEXT_POKE1); @@ -134,6 +140,8 @@ static int __patch_insn_write(void *addr, const void *insn, size_t len) if (across_pages) patch_unmap(FIX_TEXT_POKE1); + preempt_enable(); + return ret; } NOKPROBE_SYMBOL(__patch_insn_write);