From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 2112C224B00 for ; Tue, 8 Jul 2025 15:04:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751987059; cv=none; b=bkjwsrynlMkxZC1blRUevPj+QS01KD3IEucKMOTd1mM8NYWb55RvfoQoPSrVDid6B+doK1r6HBY1UH7JuTx3PjILcsmQGv7IzKiO9+VjLxItv6v8dxG0Xyo7zNQXbbPIFg2QAZAUlkWNUKjQZea/8nvaYEUNVl7rI4l3GUKtBks= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751987059; c=relaxed/simple; bh=WK0WbKAepmJH2IHvMqiUX75fgCZn9Ax6+qg1K5L/nMQ=; h=Mime-Version:Content-Type:Date:Message-Id:From:To:Subject: References:In-Reply-To; b=VsjzfKz65OgBm13qwzWT0hyfp9xqdHxr1QgYxWk2B24DJNvi+3KbXSykx35RO0YL/VDDhj4/3etg2jbRzU8GFaBtkJwGKs8coyA8Wsa6b7ztVWM+zcPX2GvUA4eDWe/IFC44YGpLlARTCaqOtZmbe57d1lY1ZwnmHdFOOcFtq1w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bbkZoa/s; arc=none smtp.client-ip=140.211.166.138 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bbkZoa/s" Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id BC59D820C1 for ; Tue, 8 Jul 2025 15:04:17 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org X-Spam-Flag: NO X-Spam-Score: -2.101 X-Spam-Level: Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id MlwysOe33-rT for ; Tue, 8 Jul 2025 15:04:17 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=lossin@kernel.org; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 2334581E1D Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 2334581E1D Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=bbkZoa/s Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) by smtp1.osuosl.org (Postfix) with ESMTPS id 2334581E1D for ; Tue, 8 Jul 2025 15:04:16 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id E041340C20; Tue, 8 Jul 2025 15:04:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B06AC4CEED; Tue, 8 Jul 2025 15:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751987055; bh=WK0WbKAepmJH2IHvMqiUX75fgCZn9Ax6+qg1K5L/nMQ=; h=Date:From:To:Subject:References:In-Reply-To:From; b=bbkZoa/sbwIMOy03ni80VuY1+6JGD0ly+qZjpHuulHsFY95hFd2Z2ydG4zKzcr1Z7 A7lSz+hAHpWp7kUk76YNyYfg6vHJ9BdRIlKu7jccl5kY3KrFRkzCaQnPw0o+gVEiDd X6j+qVdh4QoRzmHBvrGUUS/OBAhixZDj+tfIYkeKG2z5jhLiwJYJY1OFaE9MFgqtpD FbyQADheR7y3uk7IfPh33cuPj/xGcC6NSefEbFGdG39+4+AckFxfME5UuA7PKEtxFz GG9z3KPrTIcl4JIjTUAp3o0GjpuFov7BckDqT8YVX4wppSQJvQAAICjUXT2otxq7n4 Nx765leT7WpEA== Precedence: bulk X-Mailing-List: linux-kernel-mentees@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 08 Jul 2025 17:04:12 +0200 Message-Id: From: "Benno Lossin" To: "Marcelo Moreira" , , , , , , , <~lkcamp/patches@lists.sr.ht> Subject: Re: [PATCH v6 3/3] rust: revocable: Document RevocableGuard invariants and refine Deref safety X-Mailer: aerc 0.20.1 References: <20250708003428.76783-1-marcelomoreira1905@gmail.com> <20250708003428.76783-4-marcelomoreira1905@gmail.com> In-Reply-To: <20250708003428.76783-4-marcelomoreira1905@gmail.com> On Tue Jul 8, 2025 at 2:33 AM CEST, Marcelo Moreira wrote: > Improves the `RevocableGuard` documentation by explicitly stating that > its `data_ref` member is a valid pointer as an invariant. Additionally, > the `Deref` implementation's `SAFETY` comment is refined to justify > the `unsafe` dereference based on this new invariant and the > `_rcu_guard` ensuring data accessibility. > > These changes address feedback regarding the clarity and completeness > of `RevocableGuard`'s safety guarantees. > > Signed-off-by: Marcelo Moreira > --- > rust/kernel/revocable.rs | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/rust/kernel/revocable.rs b/rust/kernel/revocable.rs > index 6d8e9237dbdf..64fe44b4f5a3 100644 > --- a/rust/kernel/revocable.rs > +++ b/rust/kernel/revocable.rs > @@ -233,7 +233,8 @@ fn drop(self: Pin<&mut Self>) { > /// > /// # Invariants > /// > -/// The RCU read-side lock is held while the guard is alive. > +/// - `data_ref` is a valid pointer to a `T` object for the entire lifet= ime of this guard. This should be: /// - `data_ref` is a valid pointer for as long as the RCU read-side lo= ck is held. > +/// - The RCU read-side lock is held while the guard is alive. And this invariant is unnecessary. > pub struct RevocableGuard<'a, T> { > // This can't use the `&'a T` type because references that appear in= function arguments must > // not become dangling during the execution of the function, which c= an happen if the > @@ -258,8 +259,8 @@ impl Deref for RevocableGuard<'_, T> { > type Target =3D T; > =20 > fn deref(&self) -> &Self::Target { > - // SAFETY: By the type invariants, we hold the rcu read-side loc= k, so the object is > - // guaranteed to remain valid. > + // SAFETY: `self.data_ref` is valid for writes because of `Self`= 's type invariants, > + // and `_rcu_guard` ensures the data's accessibility for the lif= etime of this guard. This also needs to be adjusted. Also this patch should fix any invariant comments needed to construct `RevocableGuard`. --- Cheers, Benno > unsafe { &*self.data_ref } > } > }