Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1966207lqb; Mon, 27 May 2024 03:42:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWXXElfMMKTb2xxBJFcpdtQ/G9j0zqlXLWJ7Bdpye0ncWhyUZXuqqkfhua2oQSZlSLbufSII9vCgXqpZpxkNRdAqxPQsvyrMnTgglpvVw== X-Google-Smtp-Source: AGHT+IGbwo5NMhnHG6RsRhW1rELYCnPree1w1VtWaXQ3Hhr8nTSBk9Z9sabyOe2l/FFiC1lyIup+ X-Received: by 2002:a17:903:1246:b0:1f3:b55:e247 with SMTP id d9443c01a7336-1f4497db569mr91087425ad.55.1716806555099; Mon, 27 May 2024 03:42:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716806555; cv=pass; d=google.com; s=arc-20160816; b=q/+2KcnnBRlxIBxa61xlwua8WP9lr2lhOVWqgKpDb2kHn3MBwBc1uoR6FgitR7FQhY fVorWkwr/oHpe15WHBtHcKeybQWEIysicrjCNhy6o57CJossVY8NWZhi+CHjRBtm3jPp UH986yhsmlNy8sh5tIJQHs0RWGl1ozOxUVm44WWdYO4HEng7/Ow38cuujLS0OWReBzKH tXU5oSUCsBoFEskAP+dFobKDUyliBywB3ED2emC10LKHAfPpFJziHc6LMS/LPuiptvVu nM5dJZ6q0+Qn3Qhj14+Tu7bKWtuupG6o7KywOsvmFQ5ZAYLAuXMbEIrnD1rGCl7yr+G2 /7Cg== 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=vwyP38HX9GqRLRmp9euL8DsYmRpssOoH8PmzQUaaO+s=; fh=1eN+strsLnX8cuvE+uTff7wY1KiEAf1jFO97IDCVf3U=; b=xc7brT9mAewlvaGSDeL34Svfjn0Pg9jPZgSXjNPvGipMOp8g6X2pIGCa0HbJsJs1rJ /FwjQCN09Ev1IB/G6nhp2auO4AG5mHocwVtpky7wM61QPoU8PrTDlJz6/EbQL6f55MtV 1cXVDA2w9+DBd7gTgetIsLfjU6hrr8wjXCSEw3bUVbrbD7X3zje5ICgUr2fv4ExkDT9i 3EtsBGZMdrQoOm0TQYCgLLLpGH2sEOqFw/iPBBed+75m8mlGtoAXZ2exLhbydvvMzf9f JNRgxWwLs4+RrDbgzugB3Qqzr801exOHgO6nVAg9BvSIq+QxWg5xFLz4YlvJgO69HHT8 8Sew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=Mptzl2WF; 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-190433-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190433-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f4b313424dsi5919045ad.627.2024.05.27.03.42.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 03:42:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190433-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=Mptzl2WF; 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-190433-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190433-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 07CB9B21C54 for ; Mon, 27 May 2024 10:31:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB5E013B2BC; Mon, 27 May 2024 10:31:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="Mptzl2WF" Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) (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 8F1BD79E1 for ; Mon, 27 May 2024 10:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716805906; cv=none; b=UTTomzpFKPtMmGdRwsC1V1wYACsMOw7OzeXluFGelMbwheyL0tNVfa78kjilXPiBf5ia4ue/aqLBYma1OaHMLT7bbGTkOPuDt+7AinVxeBOqph0T+gSl8aCz56f0MhvuTTmJyeJ8OGid6XUukWswf9iMl5w/ApmENdv4YsxvX2g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716805906; c=relaxed/simple; bh=5915iZqkJRQVbm8GLKDIhbeHZhz7RipJyJhqNV1k5cs=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iXgsgaBC/zGckkgrkKhbW+Vfaw7lIpPxzOFh58UNjhQ9l40YZUgAa5TktMos+B05XJbIGw32QTGK8kKt1oG4t1FDvr7kbk42yEzCnj6AGzgwMh8DMZ/+Bv4WmvMICqc4AI4HxLCR3f+iD/Bsz0jdWGC0ECHOcPMLgYRzouAXfiU= 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=Mptzl2WF; arc=none smtp.client-ip=185.70.40.131 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=1716805901; x=1717065101; bh=vwyP38HX9GqRLRmp9euL8DsYmRpssOoH8PmzQUaaO+s=; 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=Mptzl2WFBbWsnxY28V/bH4KkS5FCx7eed1sOrD9bVwxOb5gauTPm+QBvZ+vKGyBT6 lZLszxmRMgFA8sPMoS7cahy3bLiFB3BjLpaZOl4XDoLDmMDDLKsaWeUX7S6ERQ0vr9 yqStFnG2RVLb1OhUGYi3SD85hbUeYyICUerLOETKP6uwQPG7Kw7XPHaayQklNKMrRx YZGhrF79g27vdm4ZSLp3chR+wi+KHgj2YWfdYnHn07OLReR8t921An/jdNDyETbT27 R1VKWfN0KCdaqDDT+dpX4yjHH3LP5HksdUEvHLLWRDUVXYyov1oowgKq/guP//QKVY y0XOkqrx8jAXA== Date: Mon, 27 May 2024 10:31:35 +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 v2 6/9] rust: list: add iterators Message-ID: In-Reply-To: <20240506-linked-list-v2-6-7b910840c91f@google.com> References: <20240506-linked-list-v2-0-7b910840c91f@google.com> <20240506-linked-list-v2-6-7b910840c91f@google.com> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 7ca9ca532a66a67c1020f5d68da622eadad78e61 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 On 06.05.24 11:53, Alice Ryhl wrote: > Rust Binder has lists containing stuff such as all contexts or all > processes, and sometimes need to iterate over them. This patch enables typo: need -> needs > Rust Binder to do that using a normal for loop. >=20 > The iterator returns the ArcBorrow type, so it is possible to grab a > refcount to values while iterating. >=20 > Signed-off-by: Alice Ryhl Two documentation nits below, with those fixed: Reviewed-by: Benno Lossin > --- > rust/kernel/list.rs | 102 ++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 102 insertions(+) >=20 > diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs > index d0ff29a3e5d1..e36afc7ee44a 100644 > --- a/rust/kernel/list.rs > +++ b/rust/kernel/list.rs > @@ -5,7 +5,9 @@ > //! A linked list implementation. >=20 > use crate::init::PinInit; > +use crate::sync::ArcBorrow; > use crate::types::Opaque; > +use core::iter::{DoubleEndedIterator, FusedIterator}; > use core::marker::PhantomData; > use core::ptr; >=20 > @@ -435,6 +437,17 @@ pub fn push_all_back(&mut self, other: &mut List) { > // INVARIANT: The other list is now empty, so update its pointer= . > other.first =3D ptr::null_mut(); > } > + > + /// Creates an iterator over the list. > + pub fn iter(&self) -> Iter<'_, T, ID> { > + // INVARIANT: If the list is empty, both pointers are null. Othe= rwise, both pointers point > + // at the first element of the same list. > + Iter { > + current: self.first, > + stop: self.first, > + _ty: PhantomData, > + } > + } > } >=20 > impl, const ID: u64> Default for List { > @@ -450,3 +463,92 @@ fn drop(&mut self) { > } > } > } > + > +/// An iterator into a [`List`]. I would use "over" instead of "into". > +/// > +/// # Invariants > +/// > +/// * There must be a [`List`] that is immutably borrowed for the durati= on of `'a`. > +/// * The `current` pointer is null or points at a value in that [`List`= ]. > +/// * The `stop` pointer is equal to the `first` field of the [`List`]. the -> that --- Cheers, Benno > +#[derive(Clone)] > +pub struct Iter<'a, T: ?Sized + ListItem, const ID: u64 =3D 0> { > + current: *mut ListLinksFields, > + stop: *mut ListLinksFields, > + _ty: PhantomData<&'a ListArc>, > +}