Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2502044rdb; Fri, 8 Dec 2023 09:53:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbDxGz/LROUORv3Tr/UDprr0v0xg6AO5Dpy06lv9cQbRofhhZldTSqtl3uWWRV3GAhmVvR X-Received: by 2002:a17:90b:1190:b0:288:7921:a745 with SMTP id gk16-20020a17090b119000b002887921a745mr468025pjb.15.1702058030209; Fri, 08 Dec 2023 09:53:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702058030; cv=none; d=google.com; s=arc-20160816; b=DU+GN2oCMkZBcMeAIbRy/ARTwRuqWcsViOF/pLCPAwRFlS8S9lbNDeFbP0aqz6yJOS rE9JqMOzkbByY/XyE92hIhui9RbqIn0AQH/O2kn9eChMrPOs+Txyl0SNbs9Tc9OLnXaR ZLlwzy29YB1tI8wbhKNM0sKFBxvd9HVeodZvtYNImK5PO8ZeasDVnCcWCubo4LKwXnXw ujHv2g2+7pMC/q3uiB0dhNa36rzfKNpvbPbvL5xRaznp1Z7fSWqxuiDK/29uxqk/1Xwf imzubsBsiRoo/xsdRR3mxbSuE2wWWabsVH+Hzw0z3lGKOd44/+zD61s6hlo9otNCVNyU Exhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=hVJsuEvFyRzSwsIFDjR8bBfXvfqQalvBoy1pmXp64qw=; fh=yGC6hLtEKxG/qAMK6tCmLY72Pr3WjPw6U6qgCoktHOQ=; b=SSmhjdg5PHrEyGjHdrveVWQC1ABDbbAicZpGFhsV4qO2izQA5do3k+wgsilBpf3WMl wTF8CbPTS6q9wzm6L/LpZRnW60m/ff0qoBNH1jP7b3xQIa77N0JaJDkaya76MsENnbja m2CTTWLebkeWFxJUuid8/G0EMgwvo38K4dCDGspvq+Zvzp5Szcx/tqsDH9x1FX2jxqMq ku0OAnX+rv8TnDJzoamNXcgH1NqxyoqK7Wm/CT384odBBsO+HpvlSyNhXl9KoyJQzttc Urrwjs108ak4Qn+4zpfLeyTEc8PYGY35hgNmUvK75QL059pRp5pyfRtWohT6DcVUzSEu ru3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=qfmys4whkrbxhizugrkv3fumau.protonmail header.b=mE9EkolL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id x14-20020a17090a46ce00b002867eb143afsi3250203pjg.133.2023.12.08.09.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 09:53:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=qfmys4whkrbxhizugrkv3fumau.protonmail header.b=mE9EkolL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 62E76808D8ED; Fri, 8 Dec 2023 09:53:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574525AbjLHRxT (ORCPT + 99 others); Fri, 8 Dec 2023 12:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1574537AbjLHRxR (ORCPT ); Fri, 8 Dec 2023 12:53:17 -0500 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7300A1999 for ; Fri, 8 Dec 2023 09:53:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=qfmys4whkrbxhizugrkv3fumau.protonmail; t=1702058001; x=1702317201; bh=hVJsuEvFyRzSwsIFDjR8bBfXvfqQalvBoy1pmXp64qw=; 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=mE9EkolL56rnQaDX118ZC8Qv3X5TZeYrKUwaDSEIQn+WhbP1IxA31PBFYX1w4PEfm tbDUzGQDgCFongIl664Rpjt0Q6D4+Ta/SBJvda/xqssrHxUAN/jDW+M0rZ26/jZ7bF hndgRizrrT3D+EtySJ7XnPTGMg1V4oE9UN6NpZai6CunjP+grH/LbKkJTx9or3kn/u 7Y7h499dZSav1SYvkjLVnEWc7pPhiT0gxp7UgDLVBq3paoIX/LqcVWwVN/TqHRmJOF h6esC13pxSSp19Splgu14PaV0+GojhlmckFGZ9EGMD53F1Wblwgy4oTz1b5PPNmmgL L+R1EmlgGTGvA== Date: Fri, 08 Dec 2023 17:53:08 +0000 To: Alice Ryhl From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Peter Zijlstra , Alexander Viro , Christian Brauner , Greg Kroah-Hartman , =?utf-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Dan Williams , Kees Cook , Matthew Wilcox , Thomas Gleixner , Daniel Xu , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2 7/7] rust: file: add abstraction for `poll_table` Message-ID: In-Reply-To: <20231206-alice-file-v2-7-af617c0d9d94@google.com> References: <20231206-alice-file-v2-0-af617c0d9d94@google.com> <20231206-alice-file-v2-7-af617c0d9d94@google.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 08 Dec 2023 09:53:47 -0800 (PST) On 12/6/23 12:59, Alice Ryhl wrote: > diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs > index 9bcbea04dac3..eeb291cc60db 100644 > --- a/rust/bindings/lib.rs > +++ b/rust/bindings/lib.rs > @@ -51,3 +51,4 @@ mod bindings_helper { >=20 > pub const GFP_KERNEL: gfp_t =3D BINDINGS_GFP_KERNEL; > pub const __GFP_ZERO: gfp_t =3D BINDINGS___GFP_ZERO; > +pub const POLLFREE: __poll_t =3D BINDINGS_POLLFREE; You are no longer using this constant, should this still exist? [...] > + fn get_qproc(&self) -> bindings::poll_queue_proc { > + let ptr =3D self.0.get(); > + // SAFETY: The `ptr` is valid because it originates from a refer= ence, and the `_qproc` > + // field is not modified concurrently with this call since we ha= ve an immutable reference. This needs an invariant on `PollTable` (i.e. `self.0` is valid). > + unsafe { (*ptr)._qproc } > + } > + > + /// Register this [`PollTable`] with the provided [`PollCondVar`], s= o that it can be notified > + /// using the condition variable. > + pub fn register_wait(&mut self, file: &File, cv: &PollCondVar) { > + if let Some(qproc) =3D self.get_qproc() { > + // SAFETY: The pointers to `self` and `file` are valid becau= se they are references. What about cv.wait_list... > + // > + // Before the wait list is destroyed, the destructor of `Pol= lCondVar` will clear > + // everything in the wait list, so the wait list is not used= after it is freed. > + unsafe { qproc(file.as_ptr() as _, cv.wait_list.get(), self.= 0.get()) }; > + } > + } > +} > + > +/// A wrapper around [`CondVar`] that makes it usable with [`PollTable`]= . > +/// > +/// # Invariant > +/// > +/// If `needs_synchronize_rcu` is false, then there is nothing registere= d with `register_wait`. Not able to find `needs_synchronize_rcu` anywhere else, should this be here? > +/// > +/// [`CondVar`]: crate::sync::CondVar > +#[pin_data(PinnedDrop)] > +pub struct PollCondVar { > + #[pin] > + inner: CondVar, > +} [..] > +#[pinned_drop] > +impl PinnedDrop for PollCondVar { > + fn drop(self: Pin<&mut Self>) { > + // Clear anything registered using `register_wait`. > + // > + // SAFETY: The pointer points at a valid wait list. I was a bit confused by "wait list", since the C type is named `wait_queue_head`, maybe just use the type name? --=20 Cheers, Benno > + unsafe { bindings::__wake_up_pollfree(self.inner.wait_list.get()= ) }; > + > + // Wait for epoll items to be properly removed. > + // > + // SAFETY: Just an FFI call. > + unsafe { bindings::synchronize_rcu() }; > + } > +}