Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp484819rdb; Thu, 30 Nov 2023 09:42:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJV54Dk7Ap41mrB/WZkoOcp+VHcZcVxSUIZm6aFqySveFIJzTl9dJ147/n4E0vi270k5Ex X-Received: by 2002:a05:6a20:8e26:b0:18c:abeb:b0db with SMTP id y38-20020a056a208e2600b0018cabebb0dbmr15236591pzj.49.1701366178586; Thu, 30 Nov 2023 09:42:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701366178; cv=none; d=google.com; s=arc-20160816; b=UpeKuebCoLGk6eP+7ruHn8+OrzzCh3FgbzKnuRwB6ZdDTjZl+WtKkx2kXchpwsVb2J RUGfPns1szE4B7/4P8JvsZk+Dj2DaBp5yKRdjRRFg/Pd6Jzr8nPQu3kZS6ao5+oECZfJ c5Gw3mSn7CA9ZnaOVMXTnsHE8s93hU7807hvOMsMgSsY1cwZRxEM1242coplRnuoq0Un lZiR2gA7rvJJbOY/nlY5Pu1UKYoMUvt1Us9KtCx0IThoes/0uaE89xQxHVYDY/N7NN2V RUL2JRlvF20JI1SGDJOsYSnVOV32S8eiHsQnNwvYIXK+F1PXjH8+jMOqfZsK/GJbiO6R u1lw== 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=jHvQDQIsGh7IZyuZ4Z71fkUJ7lN6fsPyLlI85ioCOd4=; fh=yGC6hLtEKxG/qAMK6tCmLY72Pr3WjPw6U6qgCoktHOQ=; b=Tcwkl6ru5owWcsE/u3KDO0qSqrH51Tq2Iq5ZCfMRZj/yZSFq+GbOmNIxd2ADRJjpKB iYpaYcriE56l4CL+uBHwiM2Y+J42jltM4jAp74eLrow6kJuFo7v4H5AzMC+M96HatwYU lBDiQo+UGDJJN/fHZnqtVYXb1cpilOaEVGqHc4yIvsXiaXMXQ93BYWVXamzH5S6pHAh/ iFaS4qKFbizwu6m/ujY3qflHlTWNrfsnfFSWf9c4Uee/P5uNU36VAPLvxonsE7dY38sT rts774bVqEXnGdRddt0gE1xlRQFM2TMhef9mIyupkC/zySDUqmGnQUHSOkIjoTnGpH01 uWvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=aoBbVk9A; 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 hq23-20020a056a00681700b006cddab7cc30si1600627pfb.388.2023.11.30.09.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 09:42:58 -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=protonmail header.b=aoBbVk9A; 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 B390982CB85D; Thu, 30 Nov 2023 09:42:55 -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 S1345951AbjK3Rmf (ORCPT + 99 others); Thu, 30 Nov 2023 12:42:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235209AbjK3Rme (ORCPT ); Thu, 30 Nov 2023 12:42:34 -0500 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B93A110E5 for ; Thu, 30 Nov 2023 09:42:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1701366156; x=1701625356; bh=jHvQDQIsGh7IZyuZ4Z71fkUJ7lN6fsPyLlI85ioCOd4=; 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=aoBbVk9ACHHmxS9v/zNi4r1IrszVrrEk+96u5Vbtx6tteI/l/ac1n2/OtSshr4kLK EtjFckFu529Q2h8xsOmq48yhhbDu+Sr3EX4FQVVtgyhDiXj0PXlhm9K+GWiJdS7VCW ESJPd7VJ8D45YK2SLUCaIYtZryFEMHp+heEc/ds6S02yMmUwN+BM4Sz5rZ6AggisTi 9Vurh4mtyuMBwd2Qp8bdoizuqGa5xEUuoX0bx68Q//tiWARi7paf3A+CDovtRku+Za uvcHJ7cGTuJdI7J7WbjXkbcg+dXM6rRi49cBqvwyNvF8/QilOGxuOScBWxA3hB/SF6 9xqIzvRSaRGiw== Date: Thu, 30 Nov 2023 17:42:06 +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 7/7] rust: file: add abstraction for `poll_table` Message-ID: In-Reply-To: <20231129-alice-file-v1-7-f81afe8c7261@google.com> References: <20231129-alice-file-v1-0-f81afe8c7261@google.com> <20231129-alice-file-v1-7-f81afe8c7261@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]); Thu, 30 Nov 2023 09:42:55 -0800 (PST) On 11/29/23 14:12, Alice Ryhl wrote: > diff --git a/rust/kernel/file.rs b/rust/kernel/file.rs > index 578ee307093f..35576678c993 100644 > --- a/rust/kernel/file.rs > +++ b/rust/kernel/file.rs > @@ -14,6 +14,9 @@ > use alloc::boxed::Box; > use core::{alloc::AllocError, marker::PhantomData, mem, ptr}; >=20 > +mod poll_table; > +pub use self::poll_table::{PollCondVar, PollTable}; I think it makes more sense to put it under `rust/kernel/sync/`. > + 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. What ensures this? Maybe use a type invariant? > + unsafe { (*ptr)._qproc } > + } [...] > +impl PollCondVar { > + /// Constructs a new condvar initialiser. > + #[allow(clippy::new_ret_no_self)] This is no longer needed, as Gary fixed this, see [1]. [1]: https://github.com/rust-lang/rust-clippy/issues/7344 > + pub fn new(name: &'static CStr, key: &'static LockClassKey) -> impl = PinInit { > + pin_init!(Self { > + inner <- CondVar::new(name, key), > + }) > + } > +} > + > +// Make the `CondVar` methods callable on `PollCondVar`. > +impl Deref for PollCondVar { > + type Target =3D CondVar; > + > + fn deref(&self) -> &CondVar { > + &self.inner > + } > +} > + > +#[pinned_drop] > +impl PinnedDrop for PollCondVar { > + fn drop(self: Pin<&mut Self>) { > + // Clear anything registered using `register_wait`. > + self.inner.notify(1, bindings::POLLHUP | bindings::POLLFREE); Isn't notifying only a single thread problematic, since a user could misuse the `PollCondVar` (since all functions of `CondVar` are also accessible) and also `.wait()` on the condvar? When dropping a `PollCondVar` it might notify only the user `.wait()`, but not the `PollTable`. Or am I missing something? --=20 Cheers, Benno > + // Wait for epoll items to be properly removed. > + // > + // SAFETY: Just an FFI call. > + unsafe { bindings::synchronize_rcu() }; > + } > +}