Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1610122lqo; Sun, 12 May 2024 09:57:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbES92mtU7OoYzfSTikt65OD03j2uSDJnkw5KmzsP7sU7IacOIPBNJwP8p7NIQnZ8S6jsfxw0K4Mvb9tPET39mMsn6h/1KyPU+EhwTXg== X-Google-Smtp-Source: AGHT+IHIbMfOr+V65TlbhzXLRlwrO2xxmWx/VdGTy41qqLF2JRjH3YwTnmLBnjBvU3WKnl3GVjH8 X-Received: by 2002:a17:902:780d:b0:1e4:b051:f870 with SMTP id d9443c01a7336-1ef43d2e98amr86214815ad.24.1715533031821; Sun, 12 May 2024 09:57:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715533031; cv=pass; d=google.com; s=arc-20160816; b=uDdpVyRWRFWxa6PZV9lDjyKiT/yHKdSET4FvUs0or1TVHzSDawIGCNy5T/VlSlHpMZ 2LdpEymMM6CJpucfynu/ja++L0dlaVRpi+xpUOIlTxA7i0lsnGlhN/z5p0PPZ9fZzaP3 1JwP4Dzkd2U6z7xXT06v3hg0JO161mKFyqAykQOf4FoRkLVY0O42jV9d5VBaIaL6zLtE nKZ6dkvyu9kdUkhRaUZvpodCD5pzq6JHBclgk7aLT1s26E1Hm55dQqdxazbHeHFZDkZI 260AwZONZnUGIZ1Qo600OEor2R/mDueBJHOcQEJj4rQL8sx1Fzs9fNxlkQP+LFU37Uwy 2pQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent: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=zkQu673XHiZsZ2LC3p7p7WgDWXyU8Quk0ZhICioaz88=; fh=LMiQG8eTLzf1SyU4W+POK32JVDLYXD5v2M9mE6EPfzs=; b=hbftksFg6n5vszyiy6FyLrRP9ucNV4SVXm3I38bHNrfESRY3bF1CvpKQbj2/sjNQW1 VvlwGkiu53w4zXTieHUa6p11QQrsX6E/y/Cii0rtMWtVckmCqsQK/agDF2aZmLv9jT9R HGhOlrwJJEmAvshHKJNLhRRDoaVqnSQiPeMY2vwJGpRu4g69Z6mkVYO9OpwgFY9jTywC x7iskETjHrVMCoh4WqdyfF3kJvWlGRPTYgWVeSXjbRnHaEeB+IdN8v7GGsLolG0/lmP+ Stf/XXZIsr5r4kEwO9+HJezVJLzAig4j7zVQaq444xPBUn9sW2i+FZCP1oCrrpkI2N8a lSyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QJkNXZOe; 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-176942-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176942-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 98e67ed59e1d1-2b670f4e136si7591053a91.49.2024.05.12.09.57.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 09:57:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176942-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=QJkNXZOe; 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-176942-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176942-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 66E7228135E for ; Sun, 12 May 2024 16:57:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACE5C4CDF9; Sun, 12 May 2024 16:57:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QJkNXZOe" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 37A404B5A6 for ; Sun, 12 May 2024 16:57:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715533025; cv=none; b=kONetc6H5qkqaANw7hDRMvikoyPcnoUggPHQCF0zgqHJP8f5mvpVG2AYkza4QlliCjW0PRNerhwDCpzx5MvXKfi1ZQ7G4vyPtgm22bKmy8WfXtC0jxittbbMJytaUzKcu5Q8oCvtSmRnXnyiwxm5cBW7M660GEiZKgM+wLMgd0E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715533025; c=relaxed/simple; bh=kdXFdul21W1vhNDP10fjF3wHDYrB+OIdo2J4mUdXdPU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bz+D51TvzmMsU63HDAZagAEsR+7iYjoKkgKE67Ubo0vWyE9HaUJHBvcHvRQPIvAOTUrZq7THYI/1ChzjTh5IAPa/1EPQYVI2fGdDkMylRCud9lLTy5grk5ZeJN2ryx2mQQFOZXKLyosJ5O4AGKTUkW4IptyyqvQ1K4Y5l5n/dfw= 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=QJkNXZOe; arc=none smtp.client-ip=170.10.129.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=1715533023; 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=zkQu673XHiZsZ2LC3p7p7WgDWXyU8Quk0ZhICioaz88=; b=QJkNXZOeecHHwMNfvsyc2iFxfCISFj3kmtydKm4rBRQhzqHJtEqp8f+Bwxr24POwAuv1d8 l69VMO65h4tBddcuiME2AZMosDfcSD7aKaJOEHaulbbzqxYHdpzr2RepRILKjjE8ELGy6H BX8Xtp3vs0ThC2y6HSIQSfwjfvWLSWw= 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-649-OwKcqLnDNBCkBGKdABtTZg-1; Sun, 12 May 2024 12:56:59 -0400 X-MC-Unique: OwKcqLnDNBCkBGKdABtTZg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 1B324185A780; Sun, 12 May 2024 16:56:59 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.31]) by smtp.corp.redhat.com (Postfix) with SMTP id 766F72026D6E; Sun, 12 May 2024 16:56:56 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 12 May 2024 18:55:33 +0200 (CEST) Date: Sun, 12 May 2024 18:55:29 +0200 From: Oleg Nesterov To: "Paul E. McKenney" Cc: "Uladzislau Rezki (Sony)" , RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Oleksiy Avramchenko , Frederic Weisbecker , Peter Zijlstra Subject: Re: [PATCH] rcu/sync: don't read rcu_sync->gp_count lockless Message-ID: <20240512165529.GD7541@redhat.com> References: <20240507093530.3043-1-urezki@gmail.com> <20240507093530.3043-26-urezki@gmail.com> <20240512111948.GC7541@redhat.com> <550cf35c-4fb3-4f06-95b2-9206425d74cc@paulmck-laptop> 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: <550cf35c-4fb3-4f06-95b2-9206425d74cc@paulmck-laptop> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 On 05/12, Paul E. McKenney wrote: > > --- a/kernel/rcu/sync.c > +++ b/kernel/rcu/sync.c > @@ -151,15 +151,11 @@ 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); > - gpc = rsp->gp_count - 1; > - WRITE_ONCE(rsp->gp_count, gpc); > - if (!gpc) { > + WARN_ON_ONCE(rsp->gp_count == 0); > + if (!--rsp->gp_count) { > if (rsp->gp_state == GP_PASSED) { > WRITE_ONCE(rsp->gp_state, GP_EXIT); > rcu_sync_call(rsp); > @@ -178,10 +174,10 @@ void rcu_sync_dtor(struct rcu_sync *rsp) > { > int gp_state; > > - WARN_ON_ONCE(READ_ONCE(rsp->gp_count)); > WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_PASSED); > > spin_lock_irq(&rsp->rss_lock); > + WARN_ON_ONCE(rsp->gp_count); > if (rsp->gp_state == GP_REPLAY) > WRITE_ONCE(rsp->gp_state, GP_EXIT); > gp_state = rsp->gp_state; Thanks Paul! But then I think this change can also revert this chunk from the previous patch: @@ -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) { Thanks again, Oleg.