From mboxrd@z Thu Jan 1 00:00:00 1970 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 D1075C3DA4A for ; Thu, 1 Aug 2024 16:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EHX0IKKEsv+OhA12xY502jouOg0R0McRSsDun8N3K3Q=; b=l+L5sRoy2Kcji6qNTpCKidTb9t 8Fa2vV7UN7y8F4IiihgI3n828HbjrTG1vGff8Pea6nFUodAZ0lWIZZNvhTXfrEBMIBkpJrzZuzlYE 3gLYWS8EJegQdYbTJHa+7/IFTb9HK/6RM0YeDYzMicGy/SKAHLMbUSrQGU7ir79yJ/feMkKJJfL/V ScqwTbE37Hk+/q/leYdFNsOvw5nB6MpbSB8Hxnp5FVXTJj2p8M2oGY+19vj6Yal2WX7lOM8rO3HUt oJ0wIwYd7cpHatRlL7mCeNh2H4biw9S14t6C6u6XBmJvsR1qDcN4l+WVQC/JxBkyXUXlXsmCnTwsF bQIVyRdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZYkh-0000000646h-3KVX; Thu, 01 Aug 2024 16:34:07 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZYkC-000000063y3-3o5A for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2024 16:33:38 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 335AD60EAD; Thu, 1 Aug 2024 16:33:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5B50C32786; Thu, 1 Aug 2024 16:33:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722530015; bh=li1sn9dqJ9KO+84oZ4OfIq4rehlc13/c5kyYQdHFJLQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iNWYrQ9BfX63mIQ6ZLf2UlsTZZMvVmAjRdi0RMxJADP+tdvQtMeBwdss43aqoKnBX yR1800Oba+VA8JeyMMqpozRamced3W/bJYmkrX9O2B35wtH4uqNkWyhYcq2Lh4a8Tp 57tFaZREe7+JqUIYtQ2CGE4Cp7l8WwCjY2Zv99kYGB3cJKSa0+DjZR4wVVtCq6mPnn +rbklJUoLWyE23LrT6FoqT0BV7mtzw7+iF3mTD8ue6/JZXYsrjlZl7/3qAC1jSJqHv +UgDz8I6zlzhF/qH3flaTX1bSb/n4DaWHW7jzK1m4ymDgQnwI2nrP8u/u16jMKum8O jdHfNMUF3bzEw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sZYk9-00HSyZ-FC; Thu, 01 Aug 2024 17:33:33 +0100 Date: Thu, 01 Aug 2024 17:33:32 +0100 Message-ID: <86mslw19ur.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Alexander Potapenko , Mark Rutland Subject: Re: [RFC PATCH] arm64: jump_label: Ensure patched jump_labels are visible to all CPUs In-Reply-To: <20240731133601.3073-1-will@kernel.org> References: <20240731133601.3073-1-will@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.3 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: will@kernel.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, glider@google.com, mark.rutland@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_093337_200830_45512A40 X-CRM114-Status: GOOD ( 30.93 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 31 Jul 2024 14:36:01 +0100, Will Deacon wrote: > > Although the Arm architecture permits concurrent modification and > execution of NOP and branch instructions, it still requires some > synchronisation to ensure that other CPUs consistently execute the newly > written instruction: > > > When the modified instructions are observable, each PE that is > > executing the modified instructions must execute an ISB or perform a > > context synchronizing event to ensure execution of the modified > > instructions > > Prior to commit f6cc0c501649 ("arm64: Avoid calling stop_machine() when > patching jump labels"), the arm64 jump_label patching machinery > performed synchronisation using stop_machine() after each modification, > however this was problematic when flipping static keys from atomic > contexts (namely, the arm_arch_timer CPU hotplug startup notifier) and > so we switched to the _nosync() patching routines to avoid "scheduling > while atomic" BUG()s during boot. > > In hindsight, the analysis of the issue in f6cc0c501649 isn't quite > right: it cites the use of IPIs in the default patching routines as the > cause of the lockup, whereas stop_machine() does not rely on IPIs and > the I-cache invalidation is performed using __flush_icache_range(), > which elides the call to kick_all_cpus_sync(). In fact, the blocking > wait for other CPUs is what triggers the BUG() and the problem remains > even after f6cc0c501649, for example because we could block on the > jump_label_mutex. Eventually, the arm_arch_timer driver was fixed to > avoid the static key entirely in commit a862fc2254bd > ("clocksource/arm_arch_timer: Remove use of workaround static key"). > > This all leaves the jump_label patching code in a funny situation on > arm64 as we do not synchronise with other CPUs to reduce the likelihood > of a bug which no longer exists. Consequently, toggling a static key on > one CPU cannot be assumed to take effect on other CPUs, leading to > potential issues, for example with missing preempt notifiers. > > Rather than revert f6cc0c501649 and go back to stop_machine() for each > patch site, implement arch_jump_label_transform_apply() and kick all > the other CPUs with an IPI at the end of patching. > > Cc: Catalin Marinas > Cc: Alexander Potapenko > Cc: Mark Rutland > Cc: Marc Zyngier > Fixes: f6cc0c501649 ("arm64: Avoid calling stop_machine() when patching jump labels") > Signed-off-by: Will Deacon > --- > arch/arm64/include/asm/jump_label.h | 1 + > arch/arm64/kernel/jump_label.c | 11 +++++++++-- > 2 files changed, 10 insertions(+), 2 deletions(-) Thanks for the detailed archaeology! This looks pretty reasonable to me. Reviewed-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible.