Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1968392lqb; Mon, 27 May 2024 03:48:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUP+zINyAnZFvVIEs071L+l/dvc2jSE5M1tY4ZX0CefGsl+4O4toO5+yWRJRxrrmSP6VcL6ZmYID0VkcWicHl3Q8cb4OEcYtvwPijMS9Q== X-Google-Smtp-Source: AGHT+IFlopwJXtX2gCXKPSJSXEmJhcAILQg0SjBd+8IgxBW2eQffnTS7V0TyOAFRGi7XoDj/faO4 X-Received: by 2002:a05:6830:2b0a:b0:6f1:33da:3cec with SMTP id 46e09a7af769-6f8d0b23372mr12551776a34.29.1716806906080; Mon, 27 May 2024 03:48:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716806906; cv=pass; d=google.com; s=arc-20160816; b=b7RhOIhnXG3PoYdib8OGaCeB/Fa2sgMTIckjtOlc5aGrZBcJrutgZgLtkONcd7LlFP fsgdDba5gOysx8gD4ZZya9bVllmjBFzgXJ3mDN8AKeajpEv1HLvpzEhRTRyhGdTd6xA2 CCm0rpXcYvQA9tP4AMI2198TYkP8zTuA7uv1X+qOeH52TDz/WIYCBpvWYSBmNjTwvMSj EXFYbJaWBTil2G92BEqrhn3DlKLN+7h7baStFt4EXBJl4LR4wDHYks2zATBZ4Mfcatn7 MMDhSiYLJP6kJP+3lqPLvt5P2wOLsVhsQVJ+AU7Nc3qvl9S44MoxjixdjBKj9RkN3p+M pF8w== 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=xmJd03Rx3Rsva29jvNtokJfKBgBZOsRKCO2bIGkI074=; fh=1eN+strsLnX8cuvE+uTff7wY1KiEAf1jFO97IDCVf3U=; b=BxCjOhiVKdQezSe4uhF9LTvJ/wzyP4oUpO25t+NdqwU5CM52sQA1yEAKWs/MEvLef3 /+m9zleDsVupKJFAIjJCP6qBYjVvMVbKeW1Ce00z99CyRzC+qKtt7JeNtFgKUvbYl8V5 nB00AOZqTOTH9o6kz6OSU8ruvcM+ZhG9UD3sWcwa/C7Eb5taRR5bXA/bCQ9oF3d6Sn6y dKAVXik5qCAUymozo6k9m1UXNh8RRseCRvY7GsnuHvV6ah8rQrCjuDoFMDgG0zqLA5vP 4hHFvrCoM8Xveh69YUd+VjaIrbc8LR6P/Jx6T5+R1sl0qXNXLO9MGWWL7OzLziMjV0P1 9+Bw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=ZNAifA0D; 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-190437-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190437-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 41be03b00d2f7-682288e6592si6227479a12.465.2024.05.27.03.48.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 03:48:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190437-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=ZNAifA0D; 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-190437-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190437-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 7744BB21C39 for ; Mon, 27 May 2024 10:37:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9CC313B5A8; Mon, 27 May 2024 10:37:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="ZNAifA0D" 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 6E0F213B285; Mon, 27 May 2024 10:37:43 +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=1716806265; cv=none; b=mleMOHJaYHFkOxPVQXRhQ+xJ5QJgcU6lr2L/vmbbOTqAccdlUkIRMtt1VKYDadsNAIvm+8/YhG3bonLlM7yBGe9ID/6BcgYxZuMG3fICTZ3SSIBuHDhO+ABgCcizjt/IxaR2o1g+Oezkunat29Xnld7UIzP55ZbeS8y9PQ7eVk4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716806265; c=relaxed/simple; bh=/l5XUuv8nQtGDLPCUzrTecaodGAdXukMy8bIzHTUU0A=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K4B31M76Jo8+vWCPC/YhsT1cva9u/33a5/m7rzVYVQ9fR9+E34wytwTUqsP5FMsJN1s4OJAaeJh0jJ09Xwo7b9NhYZWZQbocBIPL4Mz4dlcO6f4v5p0aCsFqImUR92Jrg7LMYUhw9oE1LmITux10tKsCYwfmWEhz1ZAems8y3xg= 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=ZNAifA0D; 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=1716806260; x=1717065460; bh=xmJd03Rx3Rsva29jvNtokJfKBgBZOsRKCO2bIGkI074=; 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=ZNAifA0DNvB75SPNd8q/OstLXxVN1gU+9xJQepeuD8bPcnGzLxu6M52SGX2WfzwyR L3YdxmFiL/efVGjkvX0JSPPxX5aHhHVB8sNn/7BJSwSEMV0Sh6LYsVGqo8P/zc1SE4 /4/FnwkHA7cvXezmCdpgeXGtXHCI2B6bqmr/oeL2SWmKnnIDFhNFh0Hf8SHMVBnF5U sWbMAyOjffKa/ZP9r4Y0qhcq49DCysKklCRW+ZjGnelDU9ZuuegnSJnNwSqSb0cIPG J+ZFVTL1d78lg5OgaqIk3aB22lxZv2qbt4oAeACgHHXoDRPMYNZQQmHHZBTDSId02z cB3e5wfc6VZKw== Date: Mon, 27 May 2024 10:37:34 +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 7/9] rust: list: add cursor Message-ID: In-Reply-To: <20240506-linked-list-v2-7-7b910840c91f@google.com> References: <20240506-linked-list-v2-0-7b910840c91f@google.com> <20240506-linked-list-v2-7-7b910840c91f@google.com> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: bac6eefd646ce6bbb8fb40143a92647993893885 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: > The cursor is very similar to the list iterator, but it has one > important feature that the iterator doesn't: it can be used to remove > items from the linked list. >=20 > This feature cannot be added to the iterator because the references you > get from the iterator are considered borrows of the original list, > rather than borrows of the iterator. This means that there's no way to > prevent code like this: >=20 > let item =3D iter.next(); > iter.remove(); > use(item); >=20 > If `iter` was a cursor instead of an iterator, then `item` will be > considered a borrow of `iter`. Since `remove` destroys `iter`, this > means that the borrow-checker will prevent uses of `item` after the call > to `remove`. >=20 > So there is a trade-off between supporting use in traditional for loops, > and supporting removal of elements as you iterate. Iterators and cursors > represents two different choices on that spectrum. >=20 > Rust Binder needs cursors for the list of death notifications that a > process is currently handling. When userspace tells Binder that it has > finished processing the death notification, Binder will iterate the list > to search for the relevant item and remove it. >=20 > Signed-off-by: Alice Ryhl > --- > rust/kernel/list.rs | 82 +++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 82 insertions(+) Reviewed-by: Benno Lossin --- Cheers, Benno