Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5384326pxu; Thu, 22 Oct 2020 00:16:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRIBJF8VPXkgxdmjmQh/0mKRSacod+9So+b/tPeIcGS+Cx8VcuiEUrPyCHiALdpo2cOfhw X-Received: by 2002:aa7:d2d5:: with SMTP id k21mr954479edr.62.1603351013603; Thu, 22 Oct 2020 00:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603351013; cv=none; d=google.com; s=arc-20160816; b=FAQR/iY8HQxuh7x858HCOA1IqHguPJOciRRgUiuNU3yJiSOv60pk/v/c4Q+IlbEftl wpKrjL8Nr2xUDDCmge09T0KFEsZ9LJBpSWV0hmMOQHlXBgyclWuRZnPVm04GxMEbsK/6 W49pdC+s9HXA/uzK+6p0rRIfyDPuHBZd/YvUGUa3yR0307VAa7PPpypnUvL7LkDTu0Nf AJS8I49J3Ghh8X32ktfgY+GFOMTW4FLS6G2gfit+p7dC2Winp9hJFwLoy5jKfwnt+g0K RzF6UT9zx2rl/lzUTZ3oQWbFfTLPhun8uZOr5WTYgFwk1HmtQHzr+gnzuP2PgfqKsidy nxIA== 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:dkim-signature; bh=mqSNNzB7lssXCj8sEhBKiWxJjJgHNRF59rUM8nPxOZQ=; b=XqlZkNrA+1w37pCdzRBxB4zcN0Zwz5nwe4jIKmZVItttZRfH23Turl4Ct7Q12eJQkr lXftIqXv7ehLdyFN8GDTq93/7dFpIzZpcCI9BVn92DA/iG3ImBpkWqdJwMBP+rj9NjsM UuQ5V6B0KRYpXYtYxQKG7AsYvx2uSpj/8RJa9mzhzR42H2lV6KpxoTyvAQD8UwsSFKIG 1xPrigqK1DjlCSnZ24HDX0U7s2jLMTc5tFlWsnGMQTbyLOdiijxVshMRMBTq+tmCj0q2 jGP95Nt8AMGIxC3ZDOX2LAwko99jEqZc4OpwrSqvr4Fe/Im3dMwOCwoa08r9FBAOA3w7 vKNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uAu0US1D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r13si447394edb.164.2020.10.22.00.16.31; Thu, 22 Oct 2020 00:16:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uAu0US1D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2505960AbgJUVQs (ORCPT + 99 others); Wed, 21 Oct 2020 17:16:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:40606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2505955AbgJUVQr (ORCPT ); Wed, 21 Oct 2020 17:16:47 -0400 Received: from localhost (cha74-h07-176-172-165-167.dsl.sta.abo.bbox.fr [176.172.165.167]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DA2A924198; Wed, 21 Oct 2020 21:16:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603315006; bh=bOHoiYFZ+xyJgLQtXuLgV3l45KEiMTOiKzJhlF/pyQQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uAu0US1Dgp1dTdHuMFxmsvdz8SKGoYc/C6M6PJjSHlApjf2EOiu7O74o7vutUMNJ8 WUAw05TEbMZXEif9lA4bfO9U0d9ypzZMCojpcXfM4rYH/aWiLdg1sc5wJo3emGrRb6 O3pt2NWWPo0MFKDQaS8bK0WY5peOAXRzfAJqHclc= Date: Wed, 21 Oct 2020 23:16:43 +0200 From: Frederic Weisbecker To: Joel Fernandes Cc: LKML , Ingo Molnar , Josh Triplett , Lai Jiangshan , Marco Elver , Mathieu Desnoyers , "Paul E. McKenney" , rcu , Steven Rostedt , "Uladzislau Rezki (Sony)" , Frederic Weisbecker , Neeraj upadhyay , Alan Stern Subject: Re: [PATCH v7 6/6] rcu/segcblist: Add additional comments to explain smp_mb() Message-ID: <20201021211643.GA78735@lothringen> References: <20201015002301.101830-1-joel@joelfernandes.org> <20201015002301.101830-7-joel@joelfernandes.org> <20201015133511.GB127222@lothringen> <20201017012753.GB4015033@google.com> <20201017031941.GD4015033@google.com> <20201017132954.GA15657@lothringen> <20201018003556.GA1034551@google.com> <20201019123730.GA34192@lothringen> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 21, 2020 at 11:57:04AM -0700, Joel Fernandes wrote: > On Mon, Oct 19, 2020 at 5:37 AM Frederic Weisbecker wrote: > > Now, reading the documentation of rcu_barrier() (thanks to you!): > > > > Pseudo-code using rcu_barrier() is as follows: > > > > 1. Prevent any new RCU callbacks from being posted. > > 2. Execute rcu_barrier(). > > 3. Allow the module to be unloaded. > > > > Basically, you are saying that if all CPUs agree that len == 0 > henceforth (through other memory barriers), then callback enqueuing > does not need a memory barrier before setting length to 0. I think setting length to 0 isn't much an issue. At worst we send a useless IPI and queue a needless callback. But incrementing from 0 to 1 is precisely what we don't want to miss. > I think that makes sense but is it worth removing the memory barrier > before WRITE(len, 1) and hoping after #1, the caller would have > ensured things are fine? Also I am not sure if the above is the only > usecase for rcu_barrier(). I'm not sure either. Also I need to check your scenario again. > > cancel_work_sync() also seem to really sync as well. I'm less sure about del_timer_sync(). > > > > Say we have: > > > > expire_timers (CPU 0) CPU 1 > > ------------- ----------- > > detach_timer(timer) > > raw_spin_unlock(&base->lock); > > call_timer_fn(timer, fn, baseclk); > > -> enqueue callback > > //would need at least smp_wmb() here Aah, my bad, the smp_mb() after inc_len does that. > > base->running_timer = NULL; > > > > del_timer_sync() { > > raw_spin_lock(&base->lock); > > if (base->running_timer != timer) > > ret = detach_if_pending(timer, base, true); > > if (!timer_pending()) > > return 0; > > raw_spin_unlock(&base->lock); > > } > > //would need at least smp_rmb() here And rcu_seq_start() implies that, although I'm not sure that's what was intended. So we are good. > > Regarding "would need at least smp_rmb.." : > But the rcu_barrier() has the control dependency we discussed in last > emails, between READ(len) and whatever follows the rcu_barrier(). > That itself will provide the ordering right? I'm not sure that was enough. The len itself has to be synchronized against whatever callback enqueuer that got stopped. > I could be missing something too :-/. But I'll include this patch in > my next posting anyway and let us also maybe see if Paul disagrees. Ok. Thanks!