Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp578650lqh; Tue, 7 May 2024 07:58:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAuoU9hV3+ZNVgNgDxG/QiAWKUGVe7f2SPxAQdGpWmZCdx3SRs/Ji/ua04lJIQzr1zHKGxALHLPkOEBm/NDU1b27viuAP/Zc8crRownw== X-Google-Smtp-Source: AGHT+IEosHiinoyTRqXJXRbGz8/ktIAgfUh2iXqzuKhyaFu62RglqPj3X1Wq5/Q8fWh1aomexJm+ X-Received: by 2002:a17:902:cec3:b0:1eb:57cb:4c69 with SMTP id d3-20020a170902cec300b001eb57cb4c69mr13855878plg.45.1715093929217; Tue, 07 May 2024 07:58:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715093929; cv=pass; d=google.com; s=arc-20160816; b=aWH/+67HeaWnxCVPGzuLwa3eeJgnShrBxRBtRmtD3qOyEOKK1DvT2nMUqPkuI+oPwe hLmHGRiY+jG/JGPQTKAzVEevG3is9OIGuIkieIBzPj00pEZFaBp3ZzAcu5yBfAY6Ua05 nT2FjyW3Si/gcmm+VjvcCgD5KnvkovLN2Y4O0hC4wSCuZDyM+VDaw0RU9hP71dwVyUhz zoFHFWC15isMd12g4Zl5OoNuRWvKh9ItDT+5i2lS+wQHPZCoaWnRY88T9A3576moc18F 7cN8WEGb9DVhypfxaqlwVfOaXIv2fzDkKBYGpyqtDeq4LOeG/czc9BvxkiaoBi+PMZfz LBWQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=L5Q00hDqz0kX8rmCO430SmGXckCysDjESYgq4a/xGRA=; fh=R69Sp5knFRmw6/OpzjXmaD85SdKnfklGyAs7i/wDAew=; b=SYeKk1WVd6hknQ26F/XesH+2vc1uxhG9sOFZua+IvuBD9OYPAXgnkqDKNtwcNzFms0 qEtAOWLJX//RO3T5u1vW8cSyWDCH1K8KHBwdFzjVB9QKUONKx3eb4jLHyIC30dgQTHIZ GHpDL+b/a1QFR1LMVXTirpYeXXb/cuw+FfYhzXc8h76YO/MHL7jmuAZDoZQv5B2fCBis EYDrAoGsQncIajTTHsWUI4SY7PlE/RQ/43Rh0lXEB9q7JWRdmG1oTT4QReosKktJgkEf I+PFZSPyRNuwDuskxPeE7gysx2Rj88ZF2XWmwkMB0vSsboeG/ShtAiGl9WOWbcTshCaV ulPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E11HEBKP; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-171630-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171630-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j18-20020a170903029200b001ec2b95b420si8193967plr.519.2024.05.07.07.58.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:58:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171630-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E11HEBKP; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-171630-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171630-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5F3E92845E7 for ; Tue, 7 May 2024 14:54:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA72E1607B3; Tue, 7 May 2024 14:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E11HEBKP" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7253615FCFC for ; Tue, 7 May 2024 14:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715093690; cv=none; b=t7yiZV3YoB9mGs+uQINMl/98kuOBafrEehsihyVravej4PoPnCgQ7L4okK5qTq0aDtorB39jdBxfC1NwP82MOd/1swxf8LPjP0TIM8Qj/G9zWeECaKxKBs50ogQBEYkCpsFOAXq3MjZE32LhtJpM9JWtRa8wu3OCtnwPaqzMaxI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715093690; c=relaxed/simple; bh=x1ynqQFHOK413TFZ0OfYJH7ssjMEsPRE5/yFxBbEta0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eqpPw5Ay1nxgYfhNU5v/2qj0KBCZH+mWftBAMOu6eoce9KfF3cem9cK+hSAqaEvrPPezXeW0FClYAMCJaDx1KdSg0WUNZrrgrh4kdxBk0H3As5jsLKCbaHeFHXCUdyIo3yZ+ky961TezasDlP4pJGTMpHXlQqN1WRN07Na/44ho= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=E11HEBKP; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715093688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=L5Q00hDqz0kX8rmCO430SmGXckCysDjESYgq4a/xGRA=; b=E11HEBKPQUbfHt5UTDBPMzW8CrOsCCRTABigKPfPxPY9ofhPWmcjfVPZiYa50IKSllkArA j11BnybtRlPC1DtqxN83U7QiswnY96HYmOKPlwuwyG0XisX9337YYyiFPO4MF/Fr7el8jl O7tLWSEAUKE1LM+IImBvEfzaL4Lm1vo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-vZjh9jiYNri97qvEKcuSaQ-1; Tue, 07 May 2024 10:54:45 -0400 X-MC-Unique: vZjh9jiYNri97qvEKcuSaQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7B821185A783; Tue, 7 May 2024 14:54:44 +0000 (UTC) Received: from fedora (unknown [10.39.192.225]) by smtp.corp.redhat.com (Postfix) with SMTP id 1CA37492CAA; Tue, 7 May 2024 14:54:41 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 May 2024 10:54:44 -0400 (EDT) Date: Tue, 7 May 2024 10:54:41 -0400 From: Oleg Nesterov To: "Uladzislau Rezki (Sony)" Cc: "Paul E . McKenney" , RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Oleksiy Avramchenko , Frederic Weisbecker , Peter Zijlstra Subject: Re: [PATCH 25/48] rcu: Mark writes to rcu_sync ->gp_count field Message-ID: References: <20240507093530.3043-1-urezki@gmail.com> <20240507093530.3043-26-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240507093530.3043-26-urezki@gmail.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Hello, I feel I don't really like this patch but I am travelling without my working laptop, can't read the source code ;) Quite possibly I am wrong, I'll return to this when I get back on May 10. Oleg. On 05/07, Uladzislau Rezki (Sony) wrote: > > From: "Paul E. McKenney" > > The rcu_sync structure's ->gp_count field is updated under the protection > of ->rss_lock, but read locklessly, and KCSAN noted the data race. > This commit therefore uses WRITE_ONCE() to do this update to clearly > document its racy nature. > > Signed-off-by: Paul E. McKenney > Cc: Oleg Nesterov > Cc: Peter Zijlstra > Signed-off-by: Uladzislau Rezki (Sony) > --- > kernel/rcu/sync.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/kernel/rcu/sync.c b/kernel/rcu/sync.c > index 86df878a2fee..6c2bd9001adc 100644 > --- a/kernel/rcu/sync.c > +++ b/kernel/rcu/sync.c > @@ -122,7 +122,7 @@ void rcu_sync_enter(struct rcu_sync *rsp) > * we are called at early boot time but this shouldn't happen. > */ > } > - rsp->gp_count++; > + WRITE_ONCE(rsp->gp_count, rsp->gp_count + 1); > spin_unlock_irq(&rsp->rss_lock); > > if (gp_state == GP_IDLE) { > @@ -151,11 +151,15 @@ void rcu_sync_enter(struct rcu_sync *rsp) > */ > void rcu_sync_exit(struct rcu_sync *rsp) > { > + int gpc; > + > WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_IDLE); > WARN_ON_ONCE(READ_ONCE(rsp->gp_count) == 0); > > spin_lock_irq(&rsp->rss_lock); > - if (!--rsp->gp_count) { > + gpc = rsp->gp_count - 1; > + WRITE_ONCE(rsp->gp_count, gpc); > + if (!gpc) { > if (rsp->gp_state == GP_PASSED) { > WRITE_ONCE(rsp->gp_state, GP_EXIT); > rcu_sync_call(rsp); > -- > 2.39.2 >