From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DD2E19004B for ; Mon, 27 Jan 2025 18:45:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738003554; cv=none; b=tsISIc1fudg9BNbo3q+5r9+NyvqjnrUsTzK4aNsQHtXTy9PWZZmzeFA/NFZehkt8f64RFs6DbP/RPBNJ4r7a/fYZqSrSy9YH6JM/7Z/XuTPrzcgcXTtD2ca2QdfUVIFwCWhHG/n6WoeNjAdeI5o/fKVoB5cVA00uCQ4/pJvnvKM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738003554; c=relaxed/simple; bh=b1HZcN4tBc20/gZMDiVH0q+E1uh5y+bhg5IP2X8/0ts=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=nFAAOkozX5wIpaaz6ejaFDEWrB9lBnMSJgKsPOjBamypNJZ8xNDQN5Fvg1YpEdCXzcbnCd3K9NuCNLfTpNHdisf7kNnp4nf2QMIc+lh3MGO0VMQPMNOAeP+6Hkjyx3yaSjaQcExs94JC3mXk+GOglOt4m3CmSB8FZiMYQQvLt3s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org; spf=pass smtp.mailfrom=joelfernandes.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b=AGmKwhxU; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=joelfernandes.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="AGmKwhxU" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3863703258fso3676636f8f.1 for ; Mon, 27 Jan 2025 10:45:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1738003550; x=1738608350; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6PwzVk8i9K2zGAyqPPcOMZEsWc1d4G5fLm6dwU600kU=; b=AGmKwhxUpqPlkkvH1Eii8xTDHCyFRbMb1Yl2bplBjyjjMdHl4LJyWrWH6/ZQhgRK2g g8qwTZawskV3d8yey9lQ5VNMCrOrn1DV9v4lZg3/WP91elGWM47/+TS1IpO9pEcnOapP Gu6Lv6TOD9YNwYRt3wfrVlfuvatXyFzJgPweQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738003550; x=1738608350; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6PwzVk8i9K2zGAyqPPcOMZEsWc1d4G5fLm6dwU600kU=; b=fmshhDHs/TGUyJIuZzK0yotUmnAHTM6uZQQmAISeii6b56+jJJiGDjFH/zqNwczKTo qlyCOyDpAFWv7wZz7qr2krDh+GpPqElT6u3v0Smz7elHEqlnJKQE+BpbI7HOkXWDhkia /M//4m+bIVVVT4iNiPaRPDCcQ23KouEQooKBPgj/a0tKFz/uFjVMmju1/gELvUcmWy68 dN31obIWUwgSaggFTpHJd6amXbJzX7yu3BVuyEg1FtlwMEWMxxNF3O60nzcR6nu/KT24 JVNHj7rclqowabT2sCPGhdn6oGVKTMcbcmxqz81tdPWQjfQ27MF0r8pHgAiuEVtwdVG/ bhrQ== X-Forwarded-Encrypted: i=1; AJvYcCXHQ8cFR/U4qEFBIim06KgN2WS+aQxyDtCeGTKqgmgYBFMAJ72CR4Ejdc07Mj4xEIFg2/LzjgoZbQb5K9U=@vger.kernel.org X-Gm-Message-State: AOJu0YwrnqQiU3JMqWuACf/l1NvCKL5XxSisLPYTtyvGby/hmT3/ZdME Rb85+hkJoctXLqpUHbO4Uc1gKv4gxy751ClZYahD7z0KqUS7SzQp70Ju87uHsxS1aDTm+mJDhYJ f3QpkDDKjvC9N5jOsyeIqFTFX6rl0R1hGS9SKiD8+oxgczQM6 X-Gm-Gg: ASbGncu7E4kHIK4L3NMbwcrGcNohSNTywyjjLm8zUeTw0WQsPhSpJynekatw0TSVZWq fdk9sjNjMo03fa1eZy+XZsKSLVmpdMagI7ESi8huFih4OGAG236JPpJC1oIksdYmdJWFfTypRlA == X-Google-Smtp-Source: AGHT+IEiYZxWKw1f4jZlkCoTxbq4GRIK7zA831OCCqdR61OlHR13txvYf/Gcc6R/OYOteXkKArSnlxHyOp93E0RzE/0= X-Received: by 2002:a5d:598e:0:b0:38c:24c6:5bdc with SMTP id ffacd0b85a97d-38c49a1cf43mr426563f8f.4.1738003549735; Mon, 27 Jan 2025 10:45:49 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <83f5a3ff-8f89-4994-844f-b7eb9e80b16d@paulmck-laptop> <76ea9e49-c8d9-4ddf-8dd5-65ba4096e242@paulmck-laptop> In-Reply-To: <76ea9e49-c8d9-4ddf-8dd5-65ba4096e242@paulmck-laptop> From: Joel Fernandes Date: Mon, 27 Jan 2025 13:45:34 -0500 X-Gm-Features: AWEUYZlg7acBQEhSxUf_ASQiMZ_jsAmHwHh_IhpAlcjR5FqdJd15nPDfUILw4qg Message-ID: Subject: Re: [PATCH RFC v2 rcu] Fix get_state_synchronize_rcu_full() GP-start detection To: paulmck@kernel.org Cc: Frederic Weisbecker , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 27, 2025 at 11:49=E2=80=AFAM Paul E. McKenney wrote: > > On Sun, Jan 26, 2025 at 09:58:11PM -0500, Joel Fernandes wrote: > > On Sun, Jan 26, 2025 at 9:55=E2=80=AFPM Joel Fernandes wrote: > > > > > > On Sun, Jan 26, 2025 at 9:03=E2=80=AFPM Paul E. McKenney wrote: > > > > > > > > On Sun, Jan 26, 2025 at 08:22:23PM -0500, Joel Fernandes wrote: > > > > > On Sun, Jan 26, 2025 at 8:13=E2=80=AFPM Joel Fernandes wrote: > > > > > > > > > > > > Hi, Paul and Frederic, > > > > > > > > > > > > [...] > > > > > > > > > On Sat, Jan 25, 2025 at 12:03:58AM +0100, Frederic Weisbe= cker wrote: > > > > > > > > > > Le Fri, Dec 13, 2024 at 11:49:49AM -0800, Paul E. McKen= ney a =C3=A9crit : > > > > > > > > > > > diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h > > > > > > > > > > > index 2f9c9272cd486..d2a91f705a4ab 100644 > > > > > > > > > > > --- a/kernel/rcu/rcu.h > > > > > > > > > > > +++ b/kernel/rcu/rcu.h > > > > > > > > > > > @@ -162,7 +162,7 @@ static inline bool rcu_seq_done_e= xact(unsigned long *sp, unsigned long s) > > > > > > > > > > > { > > > > > > > > > > > unsigned long cur_s =3D READ_ONCE(*sp); > > > > > > > > > > > > > > > > > > > > > > - return ULONG_CMP_GE(cur_s, s) || ULONG_CMP_LT= (cur_s, s - (2 * RCU_SEQ_STATE_MASK + 1)); > > > > > > > > > > > + return ULONG_CMP_GE(cur_s, s) || ULONG_CMP_LT= (cur_s, s - (3 * RCU_SEQ_STATE_MASK + 1)); > > > > > > > > > > > > > > > > [...] > > > > > > > > > > The way I understand it is that rcu_state.gp_seq might = be seen started while > > > > > > > > > > root_rnp->gp_seq is not. So rcu_seq_snap() on the start= ed rcu_state.gp_seq > > > > > > > > > > may return maximum 2 full GPs ahead of root_rnp->gp_seq= . And therefore it takes below > > > > > > > > > > 2 GPs to safely deduce we wrapped around. > > > > > > > > > > > > > > > > > > Exactly! > > > > > > > > > > > > > > > > > > > Should it be ULONG_CMP_LT(cur_s, s - (2 * (RCU_SEQ_STAT= E_MASK + 1))) ? > > > > > > > > > > > > > > > > > > Quite possibly. I freely admit that I allowed a bit of s= lop because > > > > > > > > > time was of the essence (holidays and all that) and also = it does not > > > > > > > > > hurt much to lose a couple of counts out of a 2^32 cycle,= to say nothing > > > > > > > > > of the common-case 2^64 cycle. It would not hurt to be e= xact, but it > > > > > > > > > would be necessary to convince ourselves that we were not= off by one in > > > > > > > > > the wrong direction. > > > > > > > > > > > > > > > > > > I would be happy to see a patch, as long as it was suffic= iently > > > > > > > > > convincing. > > > > > > > > > > > > > > > > I'm not so much concerned about being exact but rather abou= t making > > > > > > > > sure we still understand what we did within one year. We ca= n leave one > > > > > > > > more grace period than what we expect out of paranoia but, = the most > > > > > > > > important is that we comment about what we expect and why. = Let me > > > > > > > > prepare a patch for that. > > > > > > > > > > > > > > Even better! > > > > > > > > > > > > Do we really have users who could pass such a huge delta wrappe= d > > > > > > around value to poll() i.e > ULONG_MAX/2 ? For 32-bit, that wo= uld be > > > > > > 2 billion count since the get() (500 million GPs on 32-bit?). I= am > > > > > > curious if such a scenario should be a WARN() because also: If = more > > > > > > than ULONG_MAX/2 values are possible after get(), then a full o= r > > > > > > multiple ULONG_MAX wraparound is also possible. This means then= both > > > > > > rcu_seq_done() and rcu_seq_done_exact() become unreliable anywa= y for > > > > > > such stale get() values. > > > > > > > > > > > > I do agree with both your points on the side effect of the patc= h to > > > > > > rcu_seq_done_exact(), but I am not fully convinced myself about > > > > > > utility of rcu_seq_done_exact() versus the rcu_seq_done() but I= could > > > > > > be missing something. > > > > > > > > > > I want to modify my comment on reliability. rcu_seq_done_exact() = is > > > > > certainly more "reliable" than rcu_seq_done() for wraparound delt= a > > > > > > ULONG_MAX/2. Still with such a huge wrap around it is not fail pr= oof > > > > > if it lands within the "3 Grace period" window, so if it is not s= uper > > > > > reliable and if the user should not rely on it, then I wonder if = it is > > > > > better to not do it and instead warn the user they are playing wi= th > > > > > fire. But a counter-argument might be, landing within the 3 GP wi= ndow > > > > > is quite low probability... > > > > > > > > It is also a harmless false negative. And another poll within a fe= w > > > > hundred milliseconds will set things straight. In contrast, if we > > > > used rcu_seq_done(), it would be a good long time before we got out= of > > > > false-negative territory. > > > > > > True! > > > > > > > On a 32-bit system, if there was an expedited grace period every 10 > > > > microseconds (just barely possible on small systems), then a 32-bit > > > > counter would wrap in about 12 hours. So there would be a six-hour > > > > false-negative zone. > > > > > > > > So an expedited grace period every 10 microseconds combined with > > > > a six-hour polling delay is unlikely, but not out of the realm of > > > > possibility. > > > > > > Assuming that every 10 microsecond of the entire 6 hours is used for > > > an expedited GP, but I agree with your point. > > > > > > > Please feel free to nominate a comment. > > > > > > Ok thanks, I'll see what Frederic comes up with and can take it from = there. > > > > I forgot to ask is the reason for keeping rcu_seq_done_exact() to have > > more complexity only when needed, or does it make sense to rename > > rcu_seq_done_exact() as rcu_seq_done_done() and get rid of the old > > rcu_seq_done()? > > We might well be able to use the rcu_seq_done_exact() algorithm for > all the uses, but that will require very careful review and testing. > Please keep in mind that there are quite a few uses, that the benefit > is small, and I was lazy. ;-) > > The difference with the polling APIs is that a user might well > legitimately hang onto a cookie for six hours, for example, by having > used it to tag a data structure in a block cache or similar. Thanks for clarification. I will work on a patch along these lines and see if it is worth doing. - Joel