Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1475508lqo; Sun, 12 May 2024 04:26:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWY3G/x0XLo5d86aTiPaKDACpr4ZJDS1ai9ngWva5Er2uVIECZqsQ40m8biN1LUnjRgtRTXcJ04i+xfxiCfXdIRDcelBZcPAf5rzWNBZw== X-Google-Smtp-Source: AGHT+IH/MbaaR1x9tyhcaFJdNQTStbtfSOPhtu2w/FYb64NOo8j4Jl6vCdGLtFgkyXIyyI5XB85x X-Received: by 2002:a05:6e02:16cd:b0:36c:c69d:1871 with SMTP id e9e14a558f8ab-36cc69d249cmr108098295ab.8.1715513189073; Sun, 12 May 2024 04:26:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715513189; cv=pass; d=google.com; s=arc-20160816; b=JgGbgq1uGUcyB5+Lw4b9bVT7zvLZOlHlQsoPNRlOdt2heMs1OPrnTvmXo7tKdynYbH KIzzd23QxSy+kpvsWMhWXUFftzqjadhNhg/sj3r4fvc5/1in3+qcamkprBnsvIZxwmgr eDIEHcjpcfRiGCjaozNIlhCgSNJeB6m/ic6nmxn8zUW+xnj2DXIYSTpC3CeFKAuPBnVT fWjyrBG9ht7TnvAw+jrkC94sJjeAAgNmUqaO2GjZHVaCFDl+ovKGOHAQmH5Y70uwm72h Q9O6G/ctb2ww5NqYxrwYtCK0vnVq6tayseeNVywX2GNZrVMS89Or4D9BZzT1VfP2COhB BTXw== 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=WUR0UZti1lE2smopgq2+r8fhUDTBOIVHzU3OV21Q2YA=; fh=QhT8pEQzdJzkvKD2hsR9RqV/gqnP1UcYgrD4qpr0d2g=; b=YMPjVRARBLEVgK2j0CuusedViDnWujBZaE8HJw2V1neGX/U5LK07PjWqdpSM1P2LRs KadYpug729AZwxsFQaKSdJdzN6UCd0kHmz/Zc3qUQPjeTSscjAbQDqp4NnlSBgUkdbaV kdjxp+Me28lGx5v7C0OwJoBy8HWODdIXUeXS3n3Q4u32IHPJZa0BHniPdjsGDD/hJJTz YkYOXdP/ykCAzXy4EVehEQPu8xpRyrXkYKeGOljNWx4IXg09o2qhGKaLSwiP4pOvYOCP if7yTZG7OQ6CHeGeY+DxyyLAzZ+4xyorS9lkJKx5TWo7ZRIjQ7RKpTENWDMADhcHNvyX n0eg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RC7wpxE3; 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-176859-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176859-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 41be03b00d2f7-63412e1efc7si7266038a12.769.2024.05.12.04.26.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 04:26:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176859-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=RC7wpxE3; 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-176859-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176859-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 AB9FA28173B for ; Sun, 12 May 2024 11:26:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF11F20322; Sun, 12 May 2024 11:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RC7wpxE3" 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 A930BF9F7 for ; Sun, 12 May 2024 11:26:21 +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=1715513183; cv=none; b=oOal/Fb4CwmFoGblwwx0iDd/7eH6XBOypqOVJSQVBPYtLhDqDzQ8vV1xHFZb4O6klPHqMb1DDQEu5i+ITQPbe0dv8+Vx2EqEKFfJqiVcEBrRy/AJuGgoqYGaitAKvIeSzOraCxyG53dq5FPHem0LzP/6HS0kL2O/S/iIz/h6cjU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715513183; c=relaxed/simple; bh=oi4tXNBwdMWHpwao/JpAnY5vRdxyZ7Hdoa62eDg5XYw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f8aD2SslRZ+y7bQF3w0Q55dNN65r2L/9o290TkKB4hMGZEFI+BWHbKAMXYz//AJJBip5TT8hruXIWJbPKi5r+RxdQtzReRXrlq+9xOqI456yyYsb/d5Gg1AmnqdtIGoXzjdS/G0g7tfipEjxJg/YZAV60PHoG5wW4q82eSVAh34= 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=RC7wpxE3; 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=1715513180; 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=WUR0UZti1lE2smopgq2+r8fhUDTBOIVHzU3OV21Q2YA=; b=RC7wpxE3jxJL7LeaMLP2ZzXVgSDFuJVV9M8qkgLMT2qgjlwsfTZJpfsEU86cWbRVuNLDmU nVtUMd6MJkhjTLdUOQIhZkcY5Npswio4CdPojwBclSZoINWkXbd6czRYRFH+3ujhyXwMV8 1MN117zEjp0c1/mmWQfRXUrSf5lfecs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-_QPEU4ZWM6-50bohXRkLWQ-1; Sun, 12 May 2024 07:21:18 -0400 X-MC-Unique: _QPEU4ZWM6-50bohXRkLWQ-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 2E278380008B; Sun, 12 May 2024 11:21:18 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.31]) by smtp.corp.redhat.com (Postfix) with SMTP id 4BB182026D68; Sun, 12 May 2024 11:21:15 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 12 May 2024 13:19:52 +0200 (CEST) Date: Sun, 12 May 2024 13:19:48 +0200 From: Oleg Nesterov To: "Uladzislau Rezki (Sony)" , "Paul E . McKenney" Cc: RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Oleksiy Avramchenko , Frederic Weisbecker , Peter Zijlstra Subject: [PATCH] rcu/sync: don't read rcu_sync->gp_count lockless Message-ID: <20240512111948.GC7541@redhat.com> 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> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 rcu_sync->gp_count is updated under the protection of ->rss_lock but read locklessly by the WARN_ON() checks, and KCSAN noted the data race. Move these WARN_ON_ONCE()'s under the lock and remove the no longer needed READ_ONCE(). Reported-by: "Paul E. McKenney" Signed-off-by: Oleg Nesterov --- kernel/rcu/sync.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/sync.c b/kernel/rcu/sync.c index 86df878a2fee..b50fde082198 100644 --- a/kernel/rcu/sync.c +++ b/kernel/rcu/sync.c @@ -152,9 +152,9 @@ void rcu_sync_enter(struct rcu_sync *rsp) void rcu_sync_exit(struct rcu_sync *rsp) { 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); + WARN_ON_ONCE(rsp->gp_count == 0); if (!--rsp->gp_count) { if (rsp->gp_state == GP_PASSED) { WRITE_ONCE(rsp->gp_state, GP_EXIT); @@ -174,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 != 0); if (rsp->gp_state == GP_REPLAY) WRITE_ONCE(rsp->gp_state, GP_EXIT); gp_state = rsp->gp_state; -- 2.25.1.362.g51ebf55