Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1803446rda; Tue, 24 Oct 2023 04:01:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFb7p7olXrORDSEhBOPZ28Kc+hchsFhU4FUNBa/YsT2+YkFJhcGmTrobtr1aiTO3xIwDLCd X-Received: by 2002:a05:6a20:914e:b0:159:f71f:4083 with SMTP id x14-20020a056a20914e00b00159f71f4083mr2380712pzc.6.1698145280581; Tue, 24 Oct 2023 04:01:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698145280; cv=none; d=google.com; s=arc-20160816; b=SNGRJLhhHNG58vih7DUaSf1ggR3Jnp+qbm9Gaoj2QqWYJZcreUn9d4eXUhf0AVCASU EAOS1PHmvFrF38UM+wadDPlcMKZqc3CB6CeLMZT05IVWR1NvAhXRzMO9wN9K03s7A2GZ IGmhii2yLkmstFB3uPj7b7z3S/nqGijUfoJwSYPkJOGwYPphzkuhC5lCpGbjXL+zDMjN ritUpb4FXlIdbPqLloW/jtY1asN6Gfaf8twQ4TKRRV+jllPsZtDkK0kE+/zxQe97qVm5 X2ty3zVhjaSMNp25Jdsn6KAUrAHswIkOdVGyIc8CKTWzxO7QIs17Zgzsf/xIO8Abgt4o 2M9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=qZe6L0wtKlI2heSPaGEf3+y2SBi7oeGlrMNQ9PHnkuI=; fh=hSDCOF2WNG7hU+a7KWSOa8QJ+0fbytqLa7KRVqIFRU8=; b=WajdodphevJ+E7Kkhfjgi37BBhifY7HUXgfrJki2LoadhytzfoFqWkFxEFbs2qiH4P YZSO469pH1ihQCeKACa1I8sXJUlny20jcuLpvAYOmYoLw9hVAL9d8IzAf67gsx0Ekiqa ejlRfGToqU0qxOLd3sPxopUzcYfswpP5yDObm4lMMleaj85uGrsfWuEPqJgIGSOYRKEu fpW5zmldBDl91Oh9x0UWeIfQNa5PMOhDX0aIJqAnqyyChfo1p2lDygKF6ZQFjTPJou+F 4+Nc9PLp1pw68Csapg5TsrnTNKBaa70ihmiJWCtFRh9y1FeBa70NwsX1D8aejZNtt11C KMnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x11-20020a634a0b000000b005b82de74216si7949322pga.901.2023.10.24.04.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 04:01:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B3FC880C1137; Tue, 24 Oct 2023 04:01:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231433AbjJXLBN (ORCPT + 99 others); Tue, 24 Oct 2023 07:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230421AbjJXLBM (ORCPT ); Tue, 24 Oct 2023 07:01:12 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9CEEFFE for ; Tue, 24 Oct 2023 04:01:09 -0700 (PDT) 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 678A12F4; Tue, 24 Oct 2023 04:01:50 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.68.12]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 211A33F64C; Tue, 24 Oct 2023 04:01:07 -0700 (PDT) Date: Tue, 24 Oct 2023 12:01:05 +0100 From: Mark Rutland To: Rong Tao , peterz@infradead.org Cc: elver@google.com, linux-kernel@vger.kernel.org, peterz@infradead.org, rongtao@cestc.cn, tglx@linutronix.de Subject: Re: [PATCH 2/2] stop_machine: Apply smp_store_release() to multi_stop_data::state Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 04:01:19 -0700 (PDT) On Fri, Oct 20, 2023 at 10:43:34PM +0800, Rong Tao wrote: > From: Rong Tao > > Replace smp_wmb()+WRITE_ONCE() with smp_store_release() and add comment. > > Signed-off-by: Rong Tao > --- > kernel/stop_machine.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c > index 268c2e581698..cdf4a3fe0348 100644 > --- a/kernel/stop_machine.c > +++ b/kernel/stop_machine.c > @@ -183,8 +183,10 @@ static void set_state(struct multi_stop_data *msdata, > { > /* Reset ack counter. */ > atomic_set(&msdata->thread_ack, msdata->num_threads); > - smp_wmb(); > - WRITE_ONCE(msdata->state, newstate); > + /* This smp_store_release() pair with READ_ONCE() in multi_cpu_stop(). > + * Avoid potential access multi_stop_data::state race behaviour. > + */ > + smp_store_release(&msdata->state, newstate); This doesn't match coding style: /* * Block comments should look like this, with a leading '/*' line * before the text and a traling '*/' line afterwards. */ See https://www.kernel.org/doc/html/v4.10/process/coding-style.html#commenting I don't think the "Avoid potential access multi_stop_data::state race behaviour." text is all that helpful, and I think we can drop that. In general, it's unusual to pair a smp_store_release() with READ_ONCE(), and for that to work it relies on dependency ordering and/or hazarding on the reader side (e.g. the atomic_dec_and_test() is ordered after the READ_ONCE() since it's an RMW and there's a control dependency, but a plain read could be reordered w.r.t. the READ_ONCE()). So we probably need to explain that if we're going to comment on that smp_store_release(). Peter, might it be worth replacing the READ_ONCE() with smp_load_acquire() at the same time? I know it's not strictly necessary given the ordering we have today, but it would at least be obvious. Mark. > } > > /* Last one to ack a state moves to the next state. */ > -- > 2.41.0 >