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 3A6BCC433F5 for ; Mon, 13 Dec 2021 13:28:40 +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=gyuOpyxb2HRlLlGz5KUTe+hhTPsPSk/00ksUSAXxU7A=; b=SJSnmdV6n0SMH/ wjQThxe4kiCBDLthpbuAb9pKQ7Ck1GnAlxMazVG3uYMeqA83neN8gpEnE+R5n8DcY2RHyvQct6hXY 7j3RiJY+dayKtk9qYaM4GL4XQ3FMiTbgPBnIH2U8BAuT4ZVF3Oy0VJ36cxglWjzU/yEfE/eOzjh5a NJ/Y73aquX8pweUFNWHwIWHcUs57J/1393OSru6TxmeWr9L2JdMurQ/xoUMNNeSfvAWEoJbF0yIFZ rPQ9f+sBUt7FQS2NN1yjGoTqUgaeDxBshR1fhubpBJ50n8mJN2hN1+l0EAYo/95j4gYCOPILdWd06 dbULSOa8M2KGxoVRFa8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwlMR-009g5o-Q4; Mon, 13 Dec 2021 13:27:23 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwlMN-009g3l-5i for linux-arm-kernel@lists.infradead.org; Mon, 13 Dec 2021 13:27:20 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id E513AB80EC1; Mon, 13 Dec 2021 13:27:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 195BFC34602; Mon, 13 Dec 2021 13:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639402036; bh=Xt1OSc9B4wbqDA9mEo36+OXhA31oSH7jIFj8MLm6aVM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SyAHDYiyVdo7mRL2e7sBhdbwyQ7MeoZ9aaiLVtuFMRIOtShtSUEiyBQIgP/OkZdYi 1X/YhEcq/PZOrM1gnuGhIzgwUj4b9fo45NANK+VANuNL/xQI/v37taiafkSFov4/E6 G1CVJ6+gl+Bu49uSEuxU1muKkeE2jyVWfBIUcLX+PPCVdX0WZYaJsOErU3h4+sgH67 QYC7BHUt373thTblc8hVvq1S/UbiAQTf6NuP+CZbmwv523HDaNRgOdINAxCO+utR1x 6Mk6XB7gvz2sHzOvjssLmq52FpQwyC+F7QWKCkJeZIgsAvdsm+7qI+uDvkvGjLXdUY skbgWHtrXUemg== Date: Mon, 13 Dec 2021 13:27:11 +0000 From: Will Deacon To: Mark Rutland Cc: Catalin Marinas , 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 Subject: Re: [PATCH 1/4] arm64: alternative: wait for other CPUs before patching Message-ID: <20211213132711.GA11570@willie-the-truck> 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: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211213_052719_522643_517D171B X-CRM114-Status: GOOD ( 30.15 ) 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 Mon, Dec 13, 2021 at 01:01:25PM +0000, Mark Rutland wrote: > 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. I remember looking at this when I added the current polling loop for arm64 and, at the time, the loop around the state machine in multi_cpu_stop() was straightforward enough that it wasn't a problem. Since then, however, it appears to have grown a READ_ONCE(), so it looks like we'll need to so something. I'll have a look at your patches. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel