Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4528006rdb; Tue, 12 Dec 2023 02:00:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQV64FMwiNHcVFCRgSixG3SuAy6o9f5bUALA9v0vL630pWTvTzMj1y04rF9XpysqAA4GBq X-Received: by 2002:a17:90b:23c9:b0:28a:cdca:df92 with SMTP id md9-20020a17090b23c900b0028acdcadf92mr64824pjb.38.1702375214038; Tue, 12 Dec 2023 02:00:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702375213; cv=none; d=google.com; s=arc-20160816; b=MeB9F/mAtuotKkfZzfpChpT9YJFRnljb8AirklfkgB5Dq55Q1x5HDV+J3+YTCPm2AS /Bu5AdtW1ixVtklDu+sNMYCD/HRrZy7x65redT33j+HRKQLLT4DbOEnvAyHsvsgcZPX1 724GEWleu8VVab70l3KSy9eK0MbHz2fIbV18rue6yAZPBuywGXFRFuEwp7R9CVj0K71q wGcVZkcNV57C7giqvDOcTdTo00gjZFDP+s7rg9Gi4cZ2ASg1RrH/pMPVRhU826xRhQsE 4x0egOn8QDg5OFxSupDjnC3aPWxTu163NWq31j4cKAclvOF+wL+C7c8+rSviUFxj3BcR Pxug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=JMGbv/XdWHrVqK7oSPhh0cmVjs8GCEDKwCdy5CLJlsU=; fh=6wBG0zffrG67hu7SekXXuIsofnkmIt/kVC0pxVbw5v4=; b=MQd4KOxzBNAunJjjD0tNG0+qloiC3r3uhniItYN0rB1J0tV4nGYLVJ3mutstf9pbTo YsYcO+NsWbUwohWCF+MXneWIpBx+ZJX7Q/08XThJ0SuQiNyY0LAk5cwQJy1x7KFgOcXp j9mCduqRkaBUPrsM5COtUmh/clkWoi8WzwclqephcNk9S0FoPMFOvOM4yEWtQ9RKlqJV sdvGOX+FjmgonO+zLliyHGwBmGnu6aj2wWSUq7MIETx19wEEtsPngi9825C+Yg94r9Cc cwF9wHpJ7CL6D6FSnTm2oy6DynCKnWeRQgFPoTC98C1S/lLufTApQ4gGTEt74YdAQXLY KmRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=auvRWkHa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id h22-20020a17090adb9600b00286fbb3a174si7640198pjv.181.2023.12.12.02.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 02:00:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=auvRWkHa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E01A680CF506; Tue, 12 Dec 2023 02:00:02 -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 S230042AbjLLJ7r (ORCPT + 99 others); Tue, 12 Dec 2023 04:59:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231440AbjLLJ7l (ORCPT ); Tue, 12 Dec 2023 04:59:41 -0500 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E78113A for ; Tue, 12 Dec 2023 01:59:46 -0800 (PST) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3b9e6262fccso3337276b6e.3 for ; Tue, 12 Dec 2023 01:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702375185; x=1702979985; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JMGbv/XdWHrVqK7oSPhh0cmVjs8GCEDKwCdy5CLJlsU=; b=auvRWkHaXuSi9lUfLE2Ju1mbC6HAW5cO9QurxiQZWdrnh+XjdrIN+tmCiLMvtytLjV UQi5Ql4EirrFbH/PLI1RCZVWoKR3/z9AOafcKCbj/flM4HtFt9JI/IegDbRPHC0yJpCS cD9Cv95OpG+EOhggCJNmnVWwPZGZKSnlmCO4moK9Th28Wg+lMjOEJ6uo9CGQ1J/GygLb Yee1TuqOJHRwl9H/SZlYgP+3llwxsOJJo9NkMJlvRVIXaiI5fq1Pv03z7E4hjSjqoVGB GLrwkOLfUrum0yGu5VVxn3NN1P+/cUZDVTkESsqiflzcu4/5MXFsi/ETD/smcUMDq8FJ 9aKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702375185; x=1702979985; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JMGbv/XdWHrVqK7oSPhh0cmVjs8GCEDKwCdy5CLJlsU=; b=eRWn1S/8UQGzPh6LjJRVTkP4DL3CRJ9Wt/zZUeOmKP89raY+MAp2XMGagjxP5Taohl aWyMfKrghXPXqDzzwIBLaHqXfztIhedRXTvR/MzHtAWuqZ43U7qdBgW/STEYbwNV7pnH GYJEr19C0Td/bAqQWyCEUdOntj2/xA0z8bR+n9m1wN01oPverYXhW23NYxnuZzLBDG9+ qx19/89+skC0raxV4CTwU3cs3UTJsqTyn7HoosPkhZ+NIITYVQI80WHJt+0LgrnfLTV1 UDtDOn1ltja/s7AuNJpNaP9gLojwmoVNo/V0ZdIYD/pg0P0cAugonGRCmRw1mlATFnEX Y+KQ== X-Gm-Message-State: AOJu0Yx1VAu2k5rGGWY7ndtaW2xrAGMXN19S7Fa2X3yGOuyirvA5JEcY 5jfYza1V/CtsJ6eYdMLNwCHRF3H25U615sod83n+zA== X-Received: by 2002:a05:6808:1817:b0:3b9:f016:fb89 with SMTP id bh23-20020a056808181700b003b9f016fb89mr8589210oib.53.1702375183991; Tue, 12 Dec 2023 01:59:43 -0800 (PST) MIME-Version: 1.0 References: <20231206-alice-file-v2-0-af617c0d9d94@google.com> <20231206-alice-file-v2-7-af617c0d9d94@google.com> In-Reply-To: From: Alice Ryhl Date: Tue, 12 Dec 2023 10:59:32 +0100 Message-ID: Subject: Re: [PATCH v2 7/7] rust: file: add abstraction for `poll_table` To: 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?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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]); Tue, 12 Dec 2023 02:00:03 -0800 (PST) On Fri, Dec 8, 2023 at 6:53=E2=80=AFPM Benno Lossin wrote: > > 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 { > > > > 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? Nice catch, thanks! > > + fn get_qproc(&self) -> bindings::poll_queue_proc { > > + let ptr =3D self.0.get(); > > + // SAFETY: The `ptr` is valid because it originates from a ref= erence, and the `_qproc` > > + // field is not modified concurrently with this call since we = have an immutable reference. > > This needs an invariant on `PollTable` (i.e. `self.0` is valid). How would you phrase it? > > + unsafe { (*ptr)._qproc } > > + } > > + > > + /// Register this [`PollTable`] with the provided [`PollCondVar`],= so 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 bec= ause they are references. > > What about cv.wait_list... I can add it to the list of things that are valid due to references. > > + // > > + // Before the wait list is destroyed, the destructor of `P= ollCondVar` will clear > > + // everything in the wait list, so the wait list is not us= ed after it is freed. > > + unsafe { qproc(file.as_ptr() as _, cv.wait_list.get(), sel= f.0.get()) }; > > + } > > + } > > +} > > + > > +/// A wrapper around [`CondVar`] that makes it usable with [`PollTable= `]. > > +/// > > +/// # Invariant > > +/// > > +/// If `needs_synchronize_rcu` is false, then there is nothing registe= red with `register_wait`. > > Not able to find `needs_synchronize_rcu` anywhere else, should this be > here? Sorry, this shouldn't be there. It was something I experimented with, but gave up on. > > +#[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? I will update all instances of "wait list" to "wait_queue_head". It's because I incorrectly remembered the C type name to be "wait_list". Alice