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 3F742C433EF for ; Mon, 13 Dec 2021 13:02:54 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=M/6Cdj9NuDBJ9wHNGFHdh1S32zb7DDfFPvzD2MWUb7s=; b=PDPGwqqmRW7o1F QwP9ef/wHiDnWs5b35IAKWQ6vb8zDW7uJIa0TdaWyXrCKeVEEl3uGH3G4uRrOj2z5o0OE0uSE75Xx Q78Un7frQGjUgCJDlClTuV2k9YnOqiewHiIaoeW7Le9RxYOjqwul9zEKWTsMKhRT89dtyVC9jQfk7 Ef+DXFdQv0Bbzl6kgG5vEASRSWkG6InTYR91Fx2gJi0ro9ZG44X0T1Lw8ZSNJ+HG6cIW7fdVIJtbv 2g7yg2VkkZD4oa1cCltxA89DKf53k8hp9hxuvyMvWuFXgemVRwztBwtTpiiM+p6tFLEwI6+jtJCKu pAZkXgzDSYMc+EFb7oDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkxX-009b0l-5u; Mon, 13 Dec 2021 13:01:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkxS-009azH-PO for linux-arm-kernel@lists.infradead.org; Mon, 13 Dec 2021 13:01:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 043E01FB; Mon, 13 Dec 2021 05:01:30 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.67.68]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 98C143F793; Mon, 13 Dec 2021 05:01:28 -0800 (PST) Date: Mon, 13 Dec 2021 13:01:25 +0000 From: Mark Rutland To: Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org, andre.przywara@arm.com, ardb@kernel.org, james.morse@arm.com, joey.gouly@arm.com, suzuki.poulose@arm.com, will@kernel.org Subject: Re: [PATCH 1/4] arm64: alternative: wait for other CPUs before patching Message-ID: References: <20211203104723.3412383-1-mark.rutland@arm.com> <20211203104723.3412383-2-mark.rutland@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211213_050134_900219_DF74EFE4 X-CRM114-Status: GOOD ( 21.05 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Dec 10, 2021 at 02:49:59PM +0000, Catalin Marinas wrote: > On Fri, Dec 03, 2021 at 10:47:20AM +0000, Mark Rutland wrote: > > In __apply_alternatives_multi_stop() we have a "really simple polling > > protocol" to avoid patching code that is concurrently executed on other > > CPUs. Secondary CPUs wait for the boot CPU to signal that patching is > > complete, but the boot CPU doesn't wait for secondaries to enter the > > polling loop, and it's possible that patching starts while secondaries > > are still within the stop_machine logic. > > > > Let's fix this by adding a vaguely simple polling protocol where the > > boot CPU waits for secondaries to signal that they have entered the > > unpatchable stop function. We can use the arch_atomic_*() functions for > > this, as they are not patched with alternatives. > > > > At the same time, let's make `all_alternatives_applied` local to > > __apply_alternatives_multi_stop(), since it is only used there, and this > > makes the code a little clearer. > > Doesn't the stop_machine() mechanism wait for the CPUs to get in the > same state before calling our function or we need another stop at a > lower level in the arch code? The stop_machine() logic doesn't wait on the way in; it queues some work on each CPU sequentially to *enter* the stop function (in this case __apply_alternatives_multi_stop()), but there's no existing logic to ensrue that all CPUs have entered by some point. On the way out, stop_machine() waits for all CPUs to *exit* the stop function before returning. We need to synchronize on the way into __apply_alternatives_multi_stop() to be sure that no CPUs are executing bits which might be patched -- portions of stop_machine() itself, anything necessary to dequeue the work, or anything that might be running before the CPU spots the queued work. Thanks, Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel