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 8FAE2C3DA64 for ; Thu, 1 Aug 2024 15:54:20 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From: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=qxMVmggrdfcSkc0GYmhQi9RF2Yt6L4/MjPRax4Wgrwo=; b=Bnd11M6Xs3smjkkqst2Mx7YKPI mQ05jRqvH9L60Ocb86HILvWI2hHd1iN7zeqnFovEt7FXbFkYYfb/6nwONrfgecie58bLSPzm95UAD Vh3zokMEZhjFXuPG7eDWFBe30KXuP+UL33sO8y5IC5iFQZAblSZq/zNDohK/7t3wtUofPPdGjn5Be GtKoc5sReouTsl7MMvWy3DRpPr8wFXrG/QzErw5bzCLR5FikAr4ZGnZ4ElTOEvXxSp/maXJ308jPT Cjr+cEq0GDWDrfKyviCYU1nGnJIXfCgSf4HxX9DYKS5cdFG6KfE+qeEBvJoib6PviDGMDsoWAa2bL 4GLFsmNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZY80-00000005vrq-0ag6; Thu, 01 Aug 2024 15:54:08 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZY7W-00000005vo6-12T2 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2024 15:53:39 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B66FD6288B; Thu, 1 Aug 2024 15:53:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E056C4AF0D; Thu, 1 Aug 2024 15:53:36 +0000 (UTC) Date: Thu, 1 Aug 2024 16:53:33 +0100 From: Catalin Marinas To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Alexander Potapenko , Mark Rutland , Marc Zyngier Subject: Re: [RFC PATCH] arm64: jump_label: Ensure patched jump_labels are visible to all CPUs Message-ID: References: <20240731133601.3073-1-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240731133601.3073-1-will@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_085338_363740_4BC762DC X-CRM114-Status: GOOD ( 26.26 ) 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, Jul 31, 2024 at 02:36:01PM +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 We need to keep an eye so that the patch is not picked up for 4.19 (the fixed commit) as it doesn't have the arm_arch_timer fix, nor the batch jump label support. LTS 5.4 is fine though, it has both. If we want it in -stable, we can explicitly mention the version in the Cc line. The patch looks good to me. Reviewed-by: Catalin Marinas