From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 0790C3B38B0; Fri, 26 Jun 2026 18:36:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782499001; cv=none; b=M5Sq96H8qiIMTaopQdcMZUzA5yZUkFwdnBGas5EXy8kvf3KZpoIdJoDfmEwdsfwgVjtc4MGSozL35s5Bk7U4t1An5KIK+yRSmDcJRZCMJtk/ze/c1mbCq8lZUjmMHT28nvcX2pd+1mOPrnIUPyBeq3LO4986tHAfuh5MdLzgE/c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782499001; c=relaxed/simple; bh=fargNlghZ/3htKgOlr4ecSSwYBEh7zEpFbePuaB9ivk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DAQkv4yrSaIXJyozjCalII0POWyvan/4DEYbIZuJyqekJOlZeOtr8TS7Ntf0UflR5quGUtgClySlzcQD+3uu3xT/Z3DvVl33eK9Uiu1IBzC/EPcXHxsCfRCBIN4yVKZTmtpY5qn9qo3EyyekHFC+g5iU6sSIbrzkHocOHiBa/4E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Aw4Gu7aO; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Aw4Gu7aO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E20321F000E9; Fri, 26 Jun 2026 18:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782498999; bh=4ohhSdR4uLkHiWRbMexAantHFBpBzZI6WmGjwL2KC3o=; h=From:To:Cc:Subject:Date; b=Aw4Gu7aOmaqbgsNADbHax24oeNXpOSXZx5SXpUdMyrGGeFHsWamP319IlTBhIGhJM cQOPs1aZriEKiCWZK+GufH1B9zF0XZDJXqg66mNdeWTpNtHQupGiP+98JQjBldBlWy LO7JMcjFU6VB1M3uyQvm0GzYFkYt8oqx3fDAjnIJG5N2JaIWy+JMH7Lq+RWsvUx+cR BfhqTJjLqL6FQd82v/zWPLZuEJQ+j2AU6/IwX2j8Aff3thBoLOWrm4pCDW5er7/1Ao pZFB69zwhfoVWmDtQZDhZUWGoriTiNJKzPAFB+AdHcDDjJruFkOuX/1XpAofcE+mhz t8M93MWjffiVg== From: Danilo Krummrich To: gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, acourbot@nvidia.com, ecourtney@nvidia.com, m.wilczynski@samsung.com, david.m.ertman@intel.com, ira.weiny@intel.com, leon@kernel.org, daniel.almeida@collabora.com, bhelgaas@google.com, kwilczynski@kernel.org Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-pwm@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [PATCH v4 0/7] ForLt/CovariantForLt split, auxiliary closure API and DevresLt Date: Fri, 26 Jun 2026 20:36:07 +0200 Message-ID: <20260626183630.2585057-1-dakr@kernel.org> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: driver-core@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The ForLt trait currently guarantees covariance, which allows safe lifetime shortening via cast_ref(). However, some types (e.g. those containing Mutex<&'bound T>) are invariant over their lifetime parameter and cannot safely use cast_ref(). This series splits ForLt into two traits: - ForLt: base trait for all lifetime-parameterized types, providing only the Of<'a> GAT. - CovariantForLt: unsafe subtrait that guarantees covariance, providing a safe cast_ref() method. For invariant types, a closure-based API (registration_data_with()) is added to the auxiliary subsystem. The closure's HRTB prevents the caller from choosing a concrete lifetime, which would be unsound for invariant types. On top of that, this series adds DevresLt, a thin wrapper around Devres> that shortens the stored 'static lifetime back to the caller's borrow scope. DevresLt provides both closure-based access (access_with/try_access_with for ForLt types) and direct reference access (access/try_access for CovariantForLt types). Also implement ForLt and CovariantForLt for Bar, IoMem and ExclusiveIoMem, and update their into_devres() methods to return DevresLt. Provide convenience type aliases DevresBar, DevresIoMem and DevresExclusiveIoMem. Changes in v4: - ForLt! macro: run the Prover and emit ProveWf structs for well-formedness checks - DevresLt: change Send bound from F::Of<'static>: Send to the correct for<'a> F::Of<'a>: Send - Add #[inline] to forwarding functions in registration_data_with, registration_data, and all DevresLt accessors Changes in v3: - Keep UnsafeForLtImpl as the shared helper for both ForLt! and CovariantForLt!, distinguished by const generic N - Remove cast_ref_unchecked() from ForLt; lifetime shortening is handled by borrowing with the target lifetime directly or by decoupling the HRTB from the outer reference lifetime Changes in v2: - Fold the ForLt -> CovariantForLt rename and the new ForLt base trait into this series - Add closure-based registration_data_with() for auxiliary ForLt types - Add auxiliary sample demonstrating ForLt with an invariant Mutex type - DevresLt: add closure-based access_with()/try_access_with() for ForLt types alongside direct access()/try_access() for CovariantForLt types - Make DevresLt::new() unsafe; callers must guarantee the data outlives the device binding - Implement both ForLt and CovariantForLt (previously just ForLt) for Bar, IoMem, ExclusiveIoMem - Various safety comment and documentation improvements Danilo Krummrich (7): rust: types: rename ForLt to CovariantForLt rust: types: introduce ForLt base trait for CovariantForLt rust: auxiliary: add registration_data_with() for ForLt types rust: auxiliary: sample: demonstrate ForLt with invariant Mutex type rust: devres: add DevresLt for ForLt-aware device resource access rust: pci: return DevresLt from Bar::into_devres() rust: io: mem: return DevresLt from IoMem/ExclusiveIoMem::into_devres() drivers/gpu/nova-core/driver.rs | 4 +- drivers/pwm/pwm_th1520.rs | 5 +- rust/kernel/auxiliary.rs | 78 ++++++++++++++----- rust/kernel/devres.rs | 106 ++++++++++++++++++++++++++ rust/kernel/io/mem.rs | 65 +++++++++++----- rust/kernel/pci.rs | 1 + rust/kernel/pci/io.rs | 37 ++++++--- rust/kernel/types.rs | 1 + rust/kernel/types/for_lt.rs | 95 ++++++++++++++++------- rust/macros/for_lt.rs | 72 +++++++++++------ rust/macros/lib.rs | 18 ++++- samples/rust/rust_driver_auxiliary.rs | 96 ++++++++++++++++------- 12 files changed, 447 insertions(+), 131 deletions(-) base-commit: 51cb1aa1250c36269474b8b6ca6b6319e170f5a5 -- 2.54.0