Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2801427lqz; Wed, 3 Apr 2024 09:00:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXz5bCEV2aelk7gTMKMWHg4/NmNV4w1aO+m+8FL5GiW2jWdaQ1xLDcNTaXE5kzhVuskK7nyVioPS1LhAQq8Qp/4fZdJbxqLlbpzzjNEA== X-Google-Smtp-Source: AGHT+IEQuT+qt4M3E81322BJf50bXz7FMAiExm1zTpJ3XSCL80BG8N4qFQIr4PpRgUbqXtPz3eCV X-Received: by 2002:a17:902:d4d1:b0:1e2:a31e:5e14 with SMTP id o17-20020a170902d4d100b001e2a31e5e14mr416056plg.13.1712160040901; Wed, 03 Apr 2024 09:00:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712160040; cv=pass; d=google.com; s=arc-20160816; b=Brj4gxb5w/+ydMlR50p7kOy9IiATYxC/cW2u5autGCUhHqDex2uhGm2BrgdIu5LmJf DPlHxQMaS40dxDuNxs81VqOj9m9tSuCHYCQ5HsiQ7r5inGtMuC0qL7h7PtscqET/KAgT ON9ekdEKohobsjMxounVem4LCLYvI+PQkyJd9rD5t/4gaZbeTidZhGwzA26ymaaFQy8j c05NZqwESU7hDZXuOfh0a4WKTl3wMmGRLN/rqyykZQQXXBBxf2YQbvmTXkJj++DIzneR HDDFnu/Iev8dNmugARkdeNtz0F5DyqvOIIw5HC/n4FoTBa0h5gOnykoIpKe5r/xKIv8x bWPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=LEM29//9PWH9+2k8SgrjQzlMlVMJZcFkdCQis3k3reQ=; fh=1eN+strsLnX8cuvE+uTff7wY1KiEAf1jFO97IDCVf3U=; b=M4/bixTkD1QGHi+W8azdh7rlP9OeeSvpbunGIM4mQzEfjOKveAvk5X7M03BCE8ikwG YrpDiLSSguKpJixjsjur+wI+8niDFgFzI6trBct3WYiJ/QdG0tf0g9aohZJRsCv3hzuk ihhqRJ6veCit+7p4p+AkJO8sls6ezpLO+qnzcRlDzgaJKTWuBoVMWivZShG4gI86IPlB ZoqGfdSueA3p3knrZT87n/0YpLAYsVCtV7OprmfVTMuNFx40+wFBuAV74PFO5MlAaEUE ksyJfpATxDdFNMP9uN6JNz/sGucDFNn0u3RF1jISh14GEybl56obPHb1eeBkwfIzvW9+ 9aFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=PvdkV5kN; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-130139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130139-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k11-20020a170902ce0b00b001dd4f7ca26bsi1134715plg.629.2024.04.03.09.00.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 09:00:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130139-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=@proton.me header.s=protonmail header.b=PvdkV5kN; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-130139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130139-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me 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 53AD1294640 for ; Wed, 3 Apr 2024 15:53:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 006DC14AD1A; Wed, 3 Apr 2024 15:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="PvdkV5kN" Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) (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 ECE1114AD04; Wed, 3 Apr 2024 15:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712159575; cv=none; b=kD3isNOpz1GXD1XDQZr1aupZ2VgKSeblqR5uHF+6wo/tyQqdMWYR8bHPAZZsNpH9vh6ccxoM5kSKbDxdpyxgtCVslCPwNgNLfKHFHbv/iK9drldbWe89Ri4dErWPTR8ltdvLdnf3KE4ppUDzYrwI8QBWk3HodyrPnCbT+O5DloM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712159575; c=relaxed/simple; bh=/vZX2get8gvrEKmp5nQhazHtD6ekfyGqU9MLUrfMpH8=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KrRQE7Ceka9tlEXy6qy4T/d3C6lzClBN5RL7oEpQOJU1tSbj/qV2PsB99g086C7EuCqzjdila88hEHtfD1C/+ZGIcjU8HLfzzXJwYq5Gt9mJwSZmvS1yFLm6VvNqZSRI9TK1uIIOMTTIblG7MqZGxkfxhFoP1M9aSpkHdpvdjEU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=PvdkV5kN; arc=none smtp.client-ip=185.70.40.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1712159569; x=1712418769; bh=LEM29//9PWH9+2k8SgrjQzlMlVMJZcFkdCQis3k3reQ=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=PvdkV5kNtHJJBOipgvrD3z+DNffsZR6IVqpZHOSc9EIbPWb4pRokHhh5n9l6DY7+E YEqNFAhpyOy4ZfAEKJVWnuj1q7LhmXWtgqf7BTy97a3QkZsX2mEbqICfeJgyzmJ+g4 mZpvRZpHLF+YXpaRgSJcnfsWujAPWxjoIAeIMLiAmZMU/jHSqhTkVRVbIQ89XwZyE7 f1tlIFCsaSMWLks0/OZ45FkHFkBadm6UReCBzEvIxcCTTMOjhfH5SjORrEwv/foLvr ZxFP54IGolbJa10O+va2oNYTtVLN/NSeyex7uNi7hikbrYlpeBHyDjEVYBSpCD/1/R 8b9OumxApYDHA== Date: Wed, 03 Apr 2024 15:52:45 +0000 To: Alice Ryhl , Miguel Ojeda , Andrew Morton From: Benno Lossin Cc: Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Marco Elver , Kees Cook , Coly Li , Paolo Abeni , Pierre Gondois , Ingo Molnar , Jakub Kicinski , Wei Yang , Matthew Wilcox , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH 2/9] rust: list: add tracking for ListArc Message-ID: <36306930-0390-4342-830d-03c11ec4a3a7@proton.me> In-Reply-To: <20240402-linked-list-v1-2-b1c59ba7ae3b@google.com> References: <20240402-linked-list-v1-0-b1c59ba7ae3b@google.com> <20240402-linked-list-v1-2-b1c59ba7ae3b@google.com> Feedback-ID: 71780778:user:proton 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=utf-8 Content-Transfer-Encoding: quoted-printable I think the commit one-line description sounds a bit strange, how about "rust: list: add ListArc tracking strategies"? On 02.04.24 14:16, Alice Ryhl wrote: > @@ -33,19 +34,64 @@ pub trait ListArcSafe { > unsafe fn on_drop_list_arc(&self); > } >=20 > +/// Declares that this type is able to safely attempt to create `ListArc= `s at any time. > +/// > +/// # Safety > +/// > +/// Implementers must ensure that `try_new_list_arc` does not return `tr= ue` if a `ListArc` already > +/// exists. > +pub unsafe trait TryNewListArc: ListArcSafe { > + /// Attempts to convert an `Arc` into an `ListArc`. Retu= rns `true` if the > + /// conversion was successful. > + fn try_new_list_arc(&self) -> bool; > +} > + > /// Declares that this type supports [`ListArc`]. > /// > -/// When using this macro, it will only be possible to create a [`ListAr= c`] from a [`UniqueArc`]. > +/// When using this macro, you may choose between the `untracked` strate= gy where it is not tracked > +/// whether a [`ListArc`] exists, and the `tracked_by` strategy where th= e tracking is deferred to a > +/// field of the struct. The `tracked_by` strategy can be combined with = a field of type > +/// [`AtomicListArcTracker`] to track whether a [`ListArc`] exists. > #[macro_export] > macro_rules! impl_list_arc_safe { > (impl$({$($generics:tt)*})? ListArcSafe<$num:tt> for $t:ty { untrack= ed; } $($rest:tt)*) =3D> { > - impl$(<$($generics)*>)? $crate::list::ListArcSafe<$num> for $t { > + impl$(<$($generics)*>)? ListArcSafe<$num> for $t { This change seems unintentional. > unsafe fn on_create_list_arc_from_unique(&mut self) {} > unsafe fn on_drop_list_arc(&self) {} > } > $crate::list::impl_list_arc_safe! { $($rest)* } > }; >=20 > + (impl$({$($generics:tt)*})? ListArcSafe<$num:tt> for $t:ty { > + tracked_by $field:ident : $fty:ty; > + } $($rest:tt)*) =3D> { > + impl$(<$($generics)*>)? ListArcSafe<$num> for $t { Here you also want to access `ListArcSafe` via `$crate::list::ListArcSafe`. > + unsafe fn on_create_list_arc_from_unique(&mut self) { > + let me =3D self as *mut Self; > + let field: *mut $fty =3D unsafe { ::core::ptr::addr_of_m= ut!((*me).$field) }; I think we should also have `SAFETY` comments in macros. Also why can't this be done using safe code?: let field: &mut $fty =3D &mut self.$field; > + unsafe { <$fty as $crate::list::ListArcSafe<$num>>::on_c= reate_list_arc_from_unique( > + &mut *field > + ) }; Formatting? rustfmt gives me this: unsafe { <$fty as $crate::list::ListArcSafe<$num>>::on_create_l= ist_arc_from_unique( &mut *field ) }; (maybe the `;` should be inside the `unsafe` block in this case?) --=20 Cheers, Benno > + } > + unsafe fn on_drop_list_arc(&self) { > + let me =3D self as *const Self; > + let field: *const $fty =3D unsafe { ::core::ptr::addr_of= !((*me).$field) }; > + unsafe { <$fty as $crate::list::ListArcSafe<$num>>::on_d= rop_list_arc(&*field) }; > + } > + } > + unsafe impl$(<$($generics)*>)? TryNewListArc<$num> for $t > + where > + $fty: TryNewListArc<$num>, > + { > + fn try_new_list_arc(&self) -> bool { > + let me =3D self as *const Self; > + let field: *const $fty =3D unsafe { ::core::ptr::addr_of= !((*me).$field) }; > + unsafe { <$fty as $crate::list::TryNewListArc<$num>>::tr= y_new_list_arc(&*field) } > + } > + } > + $crate::list::impl_list_arc_safe! { $($rest)* } > + }; > + > () =3D> {}; > } > pub use impl_list_arc_safe;