From nobody Thu Dec 18 00:20:51 2025 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CE63288C80; Wed, 23 Apr 2025 16:30:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425817; cv=none; b=t8EVQbnJsAJ2po8Fi8vgOocm3LmllVrLqNRuD6MFDnl2ZjZxM87Xx7AKdFV9Uj29s8rn3mRccTFTEMMFVFzLoUrf8BvZbKf7zzO0amOiA9VyrkzDNY8NRceU3KDqA50ZSMgESsQvY9heLbIkDoppYv3OlA6wp35awOewpENlkxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425817; c=relaxed/simple; bh=DFFkISZ+wsor0lGXgM1JwIFeqscLbz0j3F8wFkfSE04=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rfG5yH+c5UDyRPB0dvcJkTZXU11TIx35v4C0t3WcCxMhFgNsl59T1Gj0t9Ey5+hP43SBPqoLlAmyGdUTO2INLH2JOEKL6xJp1ixwDl7Nq4UP/OHMsq0Rj663pDsEEgl/Y5rxeTpFm9at5skCGNdQDx86jwNXg3BkJuuXqSqlSlg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=POP75IdI; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="POP75IdI" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7c9376c4dbaso8904985a.0; Wed, 23 Apr 2025 09:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745425814; x=1746030614; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=z0ja/1pV62iEC0nEku9AQfzl6u3YciLHVA48FbywNX0=; b=POP75IdIsAqLdw2pCXZeBex+4HNrD6SyyMmiSgJaxDV06UXtiNPuRfRFiN3Tn2t6JZ lwwVApG25CgTRbezbBbu/VtV1TJmPpl/gmnzBsWyZ3NfQ/0en6tfdVcCy76UDLrbYd0e vl+TzAaB+86ANuvEMof2rz5LLBwRqcSLPx9eLZ+QByr9vq9mcm7OkiLRy7pwDrwCu89Q LnGv+o6p4PX6NgAN6e0I/PP4f+i7c7StpqNo0QskZoOw/qz6ivU+C/w4TdYJQq2nQ5WL 6oEu6Mi3npxhbabepjaPKmwjqC1QARBzpJ6tiMyHxzNVwaHOd5mzO+BTdgQexOzPj3NR Dk3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745425814; x=1746030614; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z0ja/1pV62iEC0nEku9AQfzl6u3YciLHVA48FbywNX0=; b=Wlxv+i66iCWyZen06MStBsZxsORXW5HnaGjQtiV3fgiV1T9bMdrJb0JH/S0I8NG37q OlG/VxwEHcVWOd197zNVookcmaGZ0WZ/wqc6jhTkiKXVrduHWuL+ngA3Y6GOtmigZOhS yNqxjCGmsJAD8tOF8AFiK6QXr27S9kFU5pt6ZJffbwHMSsqhKSnL1XaE6QSO3t0r/f6g l9YhbzOp5GL/W51psSbPjwT8tsw3AFiynLgfQSmOe4rhxFvNKKXIfUWfvl6clfx3onfc N3syMSYPizBgEP6zRVqdiRh6YIJstwtx6+HNrQ3Lb269B+FOjMmCaIMgj6eTR7Eg9/b1 AgjA== X-Forwarded-Encrypted: i=1; AJvYcCVk2/xW+xWclkeOdHdhvmKeBsT6JaH5egkiXBGx8mxbrTAlFF/0dVTPAoV0hOizVs+POSoCxtJlZH+0@vger.kernel.org, AJvYcCX0WPRJo2rkmuEABT/l/1Kr6+qlvcRa3ZGN6baHD2d4KOhSYefs6B6soiDcxRxRCrd56Pf/nZl8xWly4Ks=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1ng6rAkQHJvyWax4LV9HLnEs04jVFGx7XUCJOvqyAz6nKvd+X 9SyZmUz94z4uVqJsvjDICIVN79L7rRkbFNnt8KCMSzWcrpq56BBEkVBgfOADc94= X-Gm-Gg: ASbGncvgxoVGOmRXHNlJQ10GSPdfN6Ikg9E8Dugj2N11HQvVefU+ex29rte6mdmLHRD KX5Bg4tySqqfctd48GUMfDD4z7R9ANLY3GL0eJrvoafaMqSao74VZ5ULZ3RlXG4Uwwqb0C1gTok kAjaofqXObzAQgVmbGJa7D0a5g0XMEqNp9N5fPxOsRN0jnsKYB2Od7fHEtZA3g8kaoHcxoccTDM G8peyJ///g7sZsDhLr1gG4jE68R73ZkCgwOsY2j36ArpwvlxaVAglpWI0Hcs5O4njJKuomc8Drm 0ZBVEU7q8xhwmDEc2Q7ZR0R1mA6b7ivV8/Yfg64lnZo+Fu1Vx0/tgmt7ZTG7wPcqrorVLiTmu4/ cd+JUE2Fq9p/zoEqDtzbpaaVWShGmqzu4OS2IMo55NqfI2Mw4sw== X-Google-Smtp-Source: AGHT+IF5nP6uIzCJ30umK2Oe32c6tsM0b+7FfAl7tqdWBVvzvhSqUHfBW0bTdBQ9UcSX5b5SX5lr1A== X-Received: by 2002:a05:620a:290d:b0:7c9:1c6f:b4c8 with SMTP id af79cd13be357-7c94d847c9cmr636861085a.15.1745425814007; Wed, 23 Apr 2025 09:30:14 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([2620:10d:c091:600::1:e2b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c925b4dac4sm698031885a.86.2025.04.23.09.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 09:30:13 -0700 (PDT) From: Tamir Duberstein Date: Wed, 23 Apr 2025 12:30:02 -0400 Subject: [PATCH v3 1/6] rust: list: simplify macro capture 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 Message-Id: <20250423-list-no-offset-v3-1-9d0c2b89340e@gmail.com> References: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> In-Reply-To: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev Avoid manually capturing generics; use `ty` to capture the whole type instead. Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Tested-by: Alice Ryhl --- rust/kernel/list/impl_list_item_mod.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index a0438537cee1..5ed66fdce953 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -43,7 +43,7 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut List= Links { macro_rules! impl_has_list_links { ($(impl$(<$($implarg:ident),*>)? HasListLinks$(<$id:tt>)? - for $self:ident $(<$($selfarg:ty),*>)? + for $self:ty { self$(.$field:ident)* } )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the @@ -51,9 +51,7 @@ macro_rules! impl_has_list_links { // // The behavior of `raw_get_list_links` is not changed since the `= addr_of_mut!` macro is // equivalent to the pointer offset operation in the trait definit= ion. - unsafe impl$(<$($implarg),*>)? $crate::list::HasListLinks$(<$id>)?= for - $self $(<$($selfarg),*>)? - { + unsafe impl$(<$($implarg),*>)? $crate::list::HasListLinks$(<$id>)?= for $self { const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; =20 #[inline] @@ -85,18 +83,14 @@ pub unsafe trait HasSelfPtr macro_rules! impl_has_list_links_self_ptr { ($(impl$({$($implarg:tt)*})? HasSelfPtr<$item_type:ty $(, $id:tt)?> - for $self:ident $(<$($selfarg:ty),*>)? + for $self:ty { self.$field:ident } )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the // right type. - unsafe impl$(<$($implarg)*>)? $crate::list::HasSelfPtr<$item_type = $(, $id)?> for - $self $(<$($selfarg),*>)? - {} + unsafe impl$(<$($implarg)*>)? $crate::list::HasSelfPtr<$item_type = $(, $id)?> for $self {} =20 - unsafe impl$(<$($implarg)*>)? $crate::list::HasListLinks$(<$id>)? = for - $self $(<$($selfarg),*>)? - { + unsafe impl$(<$($implarg)*>)? $crate::list::HasListLinks$(<$id>)? = for $self { const OFFSET: usize =3D ::core::mem::offset_of!(Self, $field) = as usize; =20 #[inline] --=20 2.49.0 From nobody Thu Dec 18 00:20:51 2025 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B86A288C9A; Wed, 23 Apr 2025 16:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425819; cv=none; b=AhB6fy5Tn2Izab9Gx/purRDU5XiO8UBK0zUny7D0NdB90y0/nR4t2Epb6jLuisyv9KHZ60pnd6Wcanl7NFdTju8o/smD4l6wJWnKnqd2QnGkz6WuZFluH7OGrJzWL+FvvlZFxqC7omUDRlnGCru4C3FFz1HwkeO3P8AT9FCdNhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425819; c=relaxed/simple; bh=cxq8SQPIttegAQ/VdXTVQPKMu7L6YbwbWuqPynYdF28=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QmVTaexD1z9B7XkMNq+EhuVQMh32PJ3c6werqqDD2feDNwGXMdaTLUOIC4UM6E6/QZZHnK5tigncJs3dN86JVu976EiOL95Wc095l8adtejCuU8zDDhyaLZLlJFktcAwt0Pn8hHqKI0UKEkqiwVuGZlM1jzHOM3zzR0d79ugPsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IIVehaMh; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IIVehaMh" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7c560c55bc1so736985a.1; Wed, 23 Apr 2025 09:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745425816; x=1746030616; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7OzkWd7763iU7orIo6m7aRkDgbxfxBvtpXsSVHS4Bj8=; b=IIVehaMhx1NmWJ3wSD/QwDC28TqHL63XgffwGOQLDpR3lZrRToK5uC//8TuUsrkmAt cDpxt8Amso8QOiEsWxF27meQLSZPkeu3TT6vcQBTy6mpW8n9afoTwBcQ+Bc7z9nKpLaZ hboY3Q9EzV5f8pLkGSq6BtBtYpLuwUZoQfOYen8ArZz+8g3b+SqOKeLgTLLI1q/rXqL2 eQma9bGQPd2NP2d8D7JfMJqSUsvYGMZJp4V09Gn6IH5j/TNtMHkLS46xqMdFwTibSkPG 4DpckiaRKuGlQ1LvdW4lriT+wFIh/toJv51ezqG6gz4jNVwJ35zdWQncg31pVlnissXH ngPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745425816; x=1746030616; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7OzkWd7763iU7orIo6m7aRkDgbxfxBvtpXsSVHS4Bj8=; b=vG88HictbgZnPoKTTVg77B8MT+LXO9erfTI3nrxr3e/Nrczer2vHgkUkRzU5h8GtYd 6E3mhIZC2P5b1dJmvc3AyHfYSun8UzvO9IY0TbW4g3bx7U2yXUBMZ3yuWPmhgO3YOXrz uF58pURb+ACI+jvqMTcw0Koi9ETCHbP/Yby4CkD4KMxAHfGBk2l5K+I0vaeOIRRz9gJe rhRBa6EEwFv4fUpKRfzJFmAdD/Sd/U5paLkPWJgPsbd/FmL421MGMIxTBhk6hXxYaJz+ UU5LFqlpPjlS2WNIBIW25l1LHrMjTZ78t7HwkYyaRrLbDH+ubU8eFHC5YB86ZMrOha8q cPzA== X-Forwarded-Encrypted: i=1; AJvYcCU2tYLuuutc+B+VoMPkr3bhFtth02IG8+nH1GYXCkG9yu5WY+Wq/O4/ZildLWd7sAcH4U2sHXYTJ57I@vger.kernel.org, AJvYcCVnJzDAb/DuDXor1yE/Xon4mqGJBQ4gPdI0xEXC6rzU3SGuowpgaopM+xle4qd2RRyOl8nQIT4zezqr4GI=@vger.kernel.org X-Gm-Message-State: AOJu0YwwxQPUycN8cEUpkUX7LTDRQ4mQqqaUHzUymKhR7fL9DBXJWKms HJbBN0OYhvHxcrS6n2jP9zzXOVYybmS7yRNqjgES2XMq0i/cHcVY X-Gm-Gg: ASbGnctVX+/n7fDYqmHmMuGagV86MJ/MXkr0Masy50TyD7uBno4hraljBYambg0wlQG UW+v1qfC1UKz4YeBgvJp3/29OrRF3QsNJneYiVhLP+yyc1VJAMV3waL890GQcVvtfSSnBlPpktT yUeNoWIERAflzK9dTQD89d9m/jEr4qGTl0NOI2H7U9hy6Kk0hIC3/xFSpd9Nm6xcv6UH25kz+mT o7YcjXq7vYEfHlczhjycv+YCd0AczuAUiW9wpsUH+LuY4wX4iZVM7G+l1WMft2LNhfb0CsWrT1W GHgaxq0wtingH7CrwoQr7GKCedA4g+9OHbB97/GAmRX8OgEG4UMNpoA39NV2ZlobI7qLV1N2R2Z MlClQFQpe+ur6+ptsKBbkYwD8LV9qdP/DhC3MCUftqdPMcCnFztkCZBGdfyqX X-Google-Smtp-Source: AGHT+IHd54GP84hEi7muy02a3dkpCB1UaHkY3LKmMK+FWfm1/jROl/vYID1fEQeR9RjJbDXGy7hOTQ== X-Received: by 2002:a05:620a:28ca:b0:7c5:94b2:99da with SMTP id af79cd13be357-7c955dc3934mr35101185a.28.1745425815793; Wed, 23 Apr 2025 09:30:15 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([2620:10d:c091:600::1:e2b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c925b4dac4sm698031885a.86.2025.04.23.09.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 09:30:14 -0700 (PDT) From: Tamir Duberstein Date: Wed, 23 Apr 2025 12:30:03 -0400 Subject: [PATCH v3 2/6] rust: list: use consistent type parameter style 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 Message-Id: <20250423-list-no-offset-v3-2-9d0c2b89340e@gmail.com> References: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> In-Reply-To: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev Refer to the type parameters of `impl_has_list_links{,_self_ptr}!` by the same name used in `impl_list_item!`. Capture type parameters of `impl_list_item!` as `tt` using `{}` to match the style of all other macros that work with generics. Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Tested-by: Alice Ryhl --- rust/kernel/list/impl_list_item_mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index 5ed66fdce953..49f5af12e796 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -41,7 +41,7 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut List= Links { /// Implements the [`HasListLinks`] trait for the given type. #[macro_export] macro_rules! impl_has_list_links { - ($(impl$(<$($implarg:ident),*>)? + ($(impl$({$($generics:tt)*})? HasListLinks$(<$id:tt>)? for $self:ty { self$(.$field:ident)* } @@ -51,7 +51,7 @@ macro_rules! impl_has_list_links { // // The behavior of `raw_get_list_links` is not changed since the `= addr_of_mut!` macro is // equivalent to the pointer offset operation in the trait definit= ion. - unsafe impl$(<$($implarg),*>)? $crate::list::HasListLinks$(<$id>)?= for $self { + unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; =20 #[inline] @@ -81,16 +81,16 @@ pub unsafe trait HasSelfPtr /// Implements the [`HasListLinks`] and [`HasSelfPtr`] traits for the give= n type. #[macro_export] macro_rules! impl_has_list_links_self_ptr { - ($(impl$({$($implarg:tt)*})? + ($(impl$({$($generics:tt)*})? HasSelfPtr<$item_type:ty $(, $id:tt)?> for $self:ty { self.$field:ident } )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the // right type. - unsafe impl$(<$($implarg)*>)? $crate::list::HasSelfPtr<$item_type = $(, $id)?> for $self {} + unsafe impl$(<$($generics)*>)? $crate::list::HasSelfPtr<$item_type= $(, $id)?> for $self {} =20 - unsafe impl$(<$($implarg)*>)? $crate::list::HasListLinks$(<$id>)? = for $self { + unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { const OFFSET: usize =3D ::core::mem::offset_of!(Self, $field) = as usize; =20 #[inline] --=20 2.49.0 From nobody Thu Dec 18 00:20:51 2025 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD8322820D8; Wed, 23 Apr 2025 16:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425820; cv=none; b=S27Z6G6SxjOG/gKr/cfKz/WIXXfEYQppWzQYoAYujgDAEOLxxaKKzOa2k7Vj7Dhb4rDpzbJ54OrygwyCVXbe8nVKYIF8Q6HriMHcpmb8cJriUkyphNDw0FjlsZpysFjgBhm5nnOyi6OYx6T4ZdHvoeuMkHUffubVRsrPF/wNaCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425820; c=relaxed/simple; bh=I3LhX3RHJuENzMWjOlJ7uQw/9Iqe+uTziMBBRl5iv9Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Twi/jFICnMiLn8RJQB6ldtSYbf+c8dPO3xrCzFS2kXK+qtLtNQi88m/nAbXU4JFdI4qseQgY3AXwHUNA6efcgeMXzFhpsN/h5ok+V85/O7u6kLCHDnA7ggkeJzGqc6NDievgpjJbnjD5VbAzBW+liMbdm+LZ4wdeJrm6XvE2Ceo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KEvw+WfU; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KEvw+WfU" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7c58974ed57so53885a.2; Wed, 23 Apr 2025 09:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745425818; x=1746030618; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=R6KDpG33HnsnAHaUls9M6YMElozMNYMw1uYDLkzYs8I=; b=KEvw+WfU2RDgcqiz8UmFTEsIUcKUljFWH0KBk5/phWBXzatOur6s229FemIV+4Pd34 mJG53rEUUqorHP+hCkRlts1vdzvWiUsSaKS4vK5/E8gYheE0XXu/vvOkAKA/dSUY8F76 FOGHJuKKUbU8h6uGVN4osdSM6wJSgXmNG37TKVkpNbj8dAjz3cueSUGEsJUY12u9QMFE 6BnRbI2T5jYPYmJluRAcw38ViaJVR4ucBVXKgh9txzixSMIbUxw2QgcVIhek0zQPnSIi abZOFpy5hS9h8kQ8/PjZIsk4vzjXm/qsWJdqmT0hjEdD5xXWc/QTsQG62mjjWF++ONRV 07Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745425818; x=1746030618; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R6KDpG33HnsnAHaUls9M6YMElozMNYMw1uYDLkzYs8I=; b=asLRTIjT7RwEmaFHpGHe63IVkeXIlIuH9oxe+QLJC+xWMdAh9MZcF7MqiZwiidXGc+ Y5nAHbpJz6lr7S/M6zdVsd9JH3mbwJdHZhaOKMbBaHmr5HrpFEGWi+2Nb4Cuyt6er4Rz 6i0BLHg7PYIRV8fwCB1F6TqfwUHJMPj/0N/43JtcLvT8QsSSMInDNh0v+wya059Pi6IK m0w49RWgJa11EsdDNwQKXmpYdp3r/ZKTBUCCbkaJxNMTh/uwG4hCx31vcAmQs9EK9yTU DVZ5C28fwW29oLydKYHpc4jl/RDtQsRiQO4x3cqIKOtMlmcMZR9YsXl4JHtH91DJwhRW 6z6Q== X-Forwarded-Encrypted: i=1; AJvYcCUm5JfXm/EIZ3qBOkFretn8FDQj0GRSQY8DuaeeB9RsVD/5wSPCpjmCm0CkLGhbkixuvOt1aG2raw9Zwjk=@vger.kernel.org, AJvYcCXqnrVU4PgPIMFypXegQyutEUn+URe5fyFA/V7+7ud68Lq0RtnZflMH9LmbiXrtwBB8ET8rtxXOBUKF@vger.kernel.org X-Gm-Message-State: AOJu0YwgYQYk6JlZ3SZR+PgZdgpH/MNr3CU1mcG5zxtX8plA50xM5y17 FCbJuW1sVdye+81xSyC4tLtKWxZwdH3KKlJnh5wfpmDhDBSzp7v2 X-Gm-Gg: ASbGncuae4GO02b15JGTV8xuehiDiY1MbfyLPxI7YxgXq+xCPwdX0vcqHq18SNchQFl VZicz+Q7gbTPMuOAmVcNo0qaTpeIUaBANXuKS3AwCZiGcY+D0LefQ9X/JUuBscfqOY2wG3g1fPg O5VyqeaiJ8P6FS649b8PgNeJWssG36HM4tqot/MpW22wJ/hxDeebUa2VgFypEjsHxlDexV36ath scn2+mdL/3Th9ND5t0CmWAAdbFdCYPkC4ckoQxZTnhNdfbglFp5lnyKxOoAIcjgr0KbteKcTRqU +FLOcFhkzLpO6KRvS8UjMPRAjT8TqW1Baaww5W3dfF4ijl6J4GArusY9bag+u2WPxfskzp2gTXt 88eAaCHbISt3hBIIzqT2cw/LSGHhWJNrGL5rtHCasSb+US1+lhQ== X-Google-Smtp-Source: AGHT+IGFwowwvobb+M40ZUbTBkk5Ue3MbBo/otwh2KFEhB1oNBH1LDMMzoKmKv0VK5INNPKg/cEGuw== X-Received: by 2002:a05:620a:3707:b0:7c9:443e:7026 with SMTP id af79cd13be357-7c955d9f5camr51955085a.8.1745425817349; Wed, 23 Apr 2025 09:30:17 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([2620:10d:c091:600::1:e2b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c925b4dac4sm698031885a.86.2025.04.23.09.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 09:30:16 -0700 (PDT) From: Tamir Duberstein Date: Wed, 23 Apr 2025 12:30:04 -0400 Subject: [PATCH v3 3/6] rust: list: use consistent self parameter name 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 Message-Id: <20250423-list-no-offset-v3-3-9d0c2b89340e@gmail.com> References: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> In-Reply-To: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev Refer to the self parameter of `impl_list_item!` by the same name used in `impl_has_list_links{,_self_ptr}!`. Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Tested-by: Alice Ryhl --- rust/kernel/list/impl_list_item_mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index 49f5af12e796..d79bebb363ce 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -114,12 +114,12 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut = $crate::list::ListLinks$(<$ #[macro_export] macro_rules! impl_list_item { ( - $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $t:ty { + $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $self:ty { using ListLinks; })* ) =3D> {$( // SAFETY: See GUARANTEES comment on each method. - unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $t= { + unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $s= elf { // GUARANTEES: // * This returns the same pointer as `prepare_to_insert` beca= use `prepare_to_insert` // is implemented in terms of `view_links`. @@ -178,12 +178,12 @@ unsafe fn post_remove(me: *mut $crate::list::ListLink= s<$num>) -> *const Self { )*}; =20 ( - $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $t:ty { + $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $self:ty { using ListLinksSelfPtr; })* ) =3D> {$( // SAFETY: See GUARANTEES comment on each method. - unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $t= { + unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $s= elf { // GUARANTEES: // This implementation of `ListItem` will not give out exclusi= ve access to the same // `ListLinks` several times because calls to `prepare_to_inse= rt` and `post_remove` --=20 2.49.0 From nobody Thu Dec 18 00:20:51 2025 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 142FE28A1E8; Wed, 23 Apr 2025 16:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425822; cv=none; b=Vl2OQHoe9wjeQn2MdyiS0fOva/aB+6MAzO30TM8/RZDa5RHGNw0JyPOnN2iMxsVwIQG/QoVTrr89VxCTAbF9BHkDM1a65RzXSVyi3WMJnRtHWzmr+78L6p2mwEd6+CGFXoffwiN/mfVT7GspTjn6Cttj1FoPsUK9HP8n6g8vnkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425822; c=relaxed/simple; bh=2DwSldyn2g2bf3cIIGysBmEmLfEvp5QhtgywZpbH7Jg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nhQjDsJmPKZHxEHD4OQ/Gjv7EOicPXk8TbF++4cQSsJx00+UuDQy5oK6phal17emybb5dvFcq0lmf6QfzBhtVaKUkiQHfN95ASfEYQrJML9Bpob3+RIuSuCuN2+sCBQTkm1qIU8PhVxbd5JIpVvgMGZBU2i+NvxhzsWLc+QDQWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cBC+81GD; arc=none smtp.client-ip=209.85.222.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cBC+81GD" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7c9376c4dbaso8913285a.0; Wed, 23 Apr 2025 09:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745425819; x=1746030619; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JfIBCYWp6gLKc89yTU14vp4KvdB6Ey4V2d9LREVNw0o=; b=cBC+81GDZyVn0SeItgzk5G9tgoX0uSQAdFa59A6xsutxJzYgWOz6isMpB362Zc6elx yVT0ZNYuD9x4Lr2NYhermBS1/bVizDfaoqDJXln6tquvXLKsF0KFyXmMSuugTmGdtq5+ 5YmIzDgmzt7v2pqf01HRYUWesiRV5kwL21xqUndSh0bkXw08FeGLfSsBNK31cUVy2WuW aXuDuwN/fLlgnytqGDEcKoSZQIZ2E3ikKA9wR+vBtIoIfvGSwtFy4fc3DSCkEo6R1hzP nopjWiv3NH6a4kqLTc19Z/cWBd15jK+BTni0ZucH8Yhik+6Zt97k8V88XrD9wNv0Wluv z4Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745425819; x=1746030619; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JfIBCYWp6gLKc89yTU14vp4KvdB6Ey4V2d9LREVNw0o=; b=rTePTUwkDjmDiGwL+dgfbDN4ZLkS0WREOvRtUB/HOiQG0FEJ2Vegkf1nCKApFhCdlB oSDmQ37psek8idYk2H6NmXFYB4F+x6s2JdSOP3Vl/GzOYDmquM2RQCyHYtuFGS1mnj8E pOa7A06khi5As2dbzcRQfcyq0pz2qvm3Icn69hYqHnNQEatWYX9NVAfxDksG5BLunh+R qutJsSZPsN1ojeSydo/caGh5Tpt1dqTGasX26qIYRuUYTaF22tkKxqfQsxEMl8SWsSlH qLO4OIpVqF3fpRw9Hr6f11kmtra1OBBrK86/cZwqB/7TaoCkujOMA0+8/y9CqyPuJbfn 3kbQ== X-Forwarded-Encrypted: i=1; AJvYcCW/0Ldn5A3R0KB/YvoF+IJvIJCHlVQbef3KzXxoa4cx3/YariIzRHQZ/pExQIwRJ4klt5KQHFIFTXnB0gM=@vger.kernel.org, AJvYcCWU17Xrv2Y0yUE6ux38p5VMjlb7ueNn/dCI3aQcU7nUNKeiHq1md2goPDowirZDTaVtiwrEh6x9CaYM@vger.kernel.org X-Gm-Message-State: AOJu0YxZVQ4O4tS2WON3lPGe4ajV3I7YFEhpdfJV9bACxdq5UTDZSePf Zds+waGl5sJlEE35A6F41gAnFM8BI6rw70rkXcePquhfTHJK9m8K X-Gm-Gg: ASbGncsLPYqyxjDA5S78Vyyxuu3jsL76Lj2jeLoPUR2JhDYlp2A2vQ3Melq0y8GW/iq AK0tPFgoPElelbhwJISOPsQLd41Wou534hhOgvPeSkZ+yX0mFRtOOv8jfu+DS0dBVG1imSHgtK0 Q6NB7qVAWzLZc1F3THk3Dg+ySmD6DIiheV3wwDBe4ZDZLVwvKLBmYtT6WSpOnaWKjYrp7hrRkDc HOwzK3KixXE9ia/mt/AFBXZ8QAyphFrpiKTfc9+XtClW3DVhLY8Qn67H2Uo/HHB0/IMgJ7MDXiE Anzchc4usYOLsnYAEpmrR8evEkpsyzLpUgM41Lnvq0VLZcxiqy2E6pT0AZ5+BoFpKe/Vv7/AWwn 37GDXT/UZQtoqxVvOk0cMJfg53WJxof4zn0mPM69waPkK8u8NfA== X-Google-Smtp-Source: AGHT+IF5r/0Ij/BQ+LtpZ4kxi2aLxCs2O3cDLnfKvN7jmzxD7sJ0n17zDnYKsBZK3tS/qukXc9ue4w== X-Received: by 2002:a05:620a:1d92:b0:7c4:bca3:6372 with SMTP id af79cd13be357-7c94d75ee3fmr450770985a.0.1745425818677; Wed, 23 Apr 2025 09:30:18 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([2620:10d:c091:600::1:e2b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c925b4dac4sm698031885a.86.2025.04.23.09.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 09:30:17 -0700 (PDT) From: Tamir Duberstein Date: Wed, 23 Apr 2025 12:30:05 -0400 Subject: [PATCH v3 4/6] rust: list: use fully qualified path 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 Message-Id: <20250423-list-no-offset-v3-4-9d0c2b89340e@gmail.com> References: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> In-Reply-To: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev Use a fully qualified path rooted at `$crate` rather than relying on imports in the invoking scope. Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Tested-by: Alice Ryhl --- rust/kernel/list/impl_list_item_mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index d79bebb363ce..3f6cd1b090a7 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -4,8 +4,6 @@ =20 //! Helpers for implementing list traits safely. =20 -use crate::list::ListLinks; - /// Declares that this type has a `ListLinks` field at a fixed offset. /// /// This trait is only used to help implement `ListItem` safely. If `ListI= tem` is implemented @@ -27,14 +25,14 @@ pub unsafe trait HasListLinks { /// /// The provided pointer must point at a valid struct of type `Self`. /// - /// [`ListLinks`]: ListLinks + /// [`ListLinks`]: crate::list::ListLinks // We don't really need this method, but it's necessary for the implem= entation of // `impl_has_list_links!` to be correct. #[inline] - unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut ListLinks { + unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut crate::list::List= Links { // SAFETY: The caller promises that the pointer is valid. The impl= ementer promises that the // `OFFSET` constant is correct. - unsafe { (ptr as *mut u8).add(Self::OFFSET) as *mut ListLinks } + unsafe { (ptr as *mut u8).add(Self::OFFSET) as *mut crate::list::L= istLinks } } } =20 @@ -222,7 +220,9 @@ unsafe fn prepare_to_insert(me: *const Self) -> *mut $c= rate::list::ListLinks<$nu // this value is not in a list. unsafe fn view_links(me: *const Self) -> *mut $crate::list::Li= stLinks<$num> { // SAFETY: The caller promises that `me` points at a valid= value of type `Self`. - unsafe { >::raw_get_list_links(= me.cast_mut()) } + unsafe { + >::raw_get_li= st_links(me.cast_mut()) + } } =20 // This function is also used as the implementation of `post_r= emove`, so the caller --=20 2.49.0 From nobody Thu Dec 18 00:20:51 2025 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5454228A400; Wed, 23 Apr 2025 16:30:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425823; cv=none; b=U1FUCtaNOV65x7OzmBRpM+e/A9fKN0f5fm3VtSxeTya3/iLCm+wMpdkRpZIeyL/bWwYyQ+rEkLV6typ+Ez8XIlroSr1NYRTDdktTAjt125lwX9LkdtK8gSJVDcA1AAwnOcWPFRQfwROpL2AFQmegWg0edKbe/vvJCxyQEnCastw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425823; c=relaxed/simple; bh=oC9GSUWu8OINt1fRsLE6aTBmh2JsdHw6jkuHGO53X10=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UQcy3JYOXRelci2TDGy0ezo1HtqsVSt+3mqVnemF03ZfgexGE98YEjPl1O/v/NLq5mH3GY5LdPqmoFJi39lysr4ddz+Q/EmZmFd7cfD8NmOWz5mdDfXLcZqwWO5YfI5dXcvyRNEeRAfUaFSiRT3TCbEuwHFD0hu62U2J+7jGggU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k7GtwgMY; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k7GtwgMY" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7c5b8d13f73so4153985a.0; Wed, 23 Apr 2025 09:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745425820; x=1746030620; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=mGa2aKYjlBBrJsbYdL5QXxnaufaMMv87SoV2X8XBVkE=; b=k7GtwgMY/7J36sHdIKpHZOKG3FsrjKfT/lCIFkhzQp8/vgityumBCttHUtTKEMUndF rkvunjZz+PmFZ9ZdkTsIT3bsGEM9/3iEn03mUAptu/GGwqYFIk8CuHYgxOr2O5Dez+0E bDn5i5umyRPwpjk28F0gBlrkFqNfwzTD6aSjorc9LsnvROMl1Ftna9hPHIajv51VGthH +/RgP2R+2K0KtlA+hQkXVScVPECeDDc0IC/3XQ27c+E9G0TRcax+kue5GfZfq+TIYWng r9//Z+pXN/W3r4PfbW4Ivy5ImaKAOKO7dvMDWEU5G2f6Vzg0C/L1n6rPqeYCM+zvB5iP auPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745425820; x=1746030620; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mGa2aKYjlBBrJsbYdL5QXxnaufaMMv87SoV2X8XBVkE=; b=qaFMu/AgJscCEVDvzhsyeVhrZ5IJL290D14PuyU6AQKJx4MAatBvNYCD/FF3gcM5wM GLLQwYfEZIEn9P5bwOwhHxe1d8a8m3q2G9IujSqw5+n6gDkGf/k8Sd1fSLhhACQSHuul L/0+FLJWtW5jR/4h+LgjevCEFDkjlM/PEosHTuyFaWbqLHd1rbpIbcPcOFhwB8d8L8lm R0Y2ZYbH0pdjGkJmUWOwUYmiyXjDG+zssDsp4F4mK4uyQhrUPYvsXvWSC+KULYSn5jQx Z6bAzOkNFEu4Y/UtOzPoquYY+SI/q8vMy9uGigBOF51P0SX7UIFQkOztwN9A+Cqg2DrM EZxQ== X-Forwarded-Encrypted: i=1; AJvYcCVHXgBKpWZBgJG7NFQWTcywC9TM7BJM76R3qtoJT1JAcOWR+ShHYh9mR3hBJ/mHxj+Xh++6sKEErHqh@vger.kernel.org, AJvYcCXnSHAlEONhE7uJ09ogCv6hWFEEEIBEnauVjnC4qG2PbilkMKu5HHb6VqpkplVKifwVRPlfAKjfwiqaKeg=@vger.kernel.org X-Gm-Message-State: AOJu0YzT7DTvZl+grDrFXAc6wu2JDhxrkhDw/BxuDdlPUUTSRG48B43e AYVKlSDPIzgrzL3BNsjz0LFKZl+75B5D4SC36Z4T0pX1ncHovDul X-Gm-Gg: ASbGncs3SKBmPCjXbrMTQ/pf9g5VAwGmmwkcGVmuX6jgJWKq7v/aVVADcUfyaMsFRuJ wLFWPYAjYbCv/4xbg+0tjWrqlhFBmvOM79yWFjlQb8dPWSGrkcuWEPSGcKqkAeYxxc8OKZ/PNu8 zL3zl1cSEmnjONswF4sW2+5T5caVbnJTvb7L4FBRMnsM9UKNrFTF80bA2nhbxNgLLm/P51Wy6wM 4SVJmPF4Zg80qvrUlPICH+vnnOa6jLAlbnAfa5EJHpewlOOl1B+E2GCqEWsuEG2cI/Ndew+0ZtJ 6ulpjvTE/gHy39QKXAzdsnzV3OSUYjCn6TLTKxlRnLhXvw9/J7ShqQxMn4A7Z9i4siIMm/xGsPT G+hmfuEHNEdRpHdnQTDoMIikhNh6u9z6SU1JHcRfFNjJ5H7zHmOtFlQo70xh5 X-Google-Smtp-Source: AGHT+IH3vxVwQbj0XnI60Kc3pobJn8GMeusMuZFoprPcIJo4uYmT99dJlqh1I5bFE1s4YoHZSqb4eQ== X-Received: by 2002:a05:620a:288b:b0:7c7:5b32:1af9 with SMTP id af79cd13be357-7c927fa1549mr3517656985a.25.1745425819777; Wed, 23 Apr 2025 09:30:19 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([2620:10d:c091:600::1:e2b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c925b4dac4sm698031885a.86.2025.04.23.09.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 09:30:19 -0700 (PDT) From: Tamir Duberstein Date: Wed, 23 Apr 2025 12:30:06 -0400 Subject: [PATCH v3 5/6] rust: list: add `impl_list_item!` examples 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 Message-Id: <20250423-list-no-offset-v3-5-9d0c2b89340e@gmail.com> References: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> In-Reply-To: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev There's a comprehensive example in `rust/kernel/list.rs` but it doesn't exercise the `using ListLinksSelfPtr` variant nor the generic cases. Add that here. Generalize `impl_has_list_links_self_ptr` to handle nested fields in the same manner as `impl_has_list_links`. Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Tested-by: Alice Ryhl --- rust/kernel/list/impl_list_item_mod.rs | 96 ++++++++++++++++++++++++++++++= ++-- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index 3f6cd1b090a7..df21070e1cf6 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -82,20 +82,20 @@ macro_rules! impl_has_list_links_self_ptr { ($(impl$({$($generics:tt)*})? HasSelfPtr<$item_type:ty $(, $id:tt)?> for $self:ty - { self.$field:ident } + { self$(.$field:ident)* } )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the // right type. unsafe impl$(<$($generics)*>)? $crate::list::HasSelfPtr<$item_type= $(, $id)?> for $self {} =20 unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { - const OFFSET: usize =3D ::core::mem::offset_of!(Self, $field) = as usize; + const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; =20 #[inline] unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $crate::l= ist::ListLinks$(<$id>)? { // SAFETY: The caller promises that the pointer is not dan= gling. let ptr: *mut $crate::list::ListLinksSelfPtr<$item_type $(= , $id)?> =3D - unsafe { ::core::ptr::addr_of_mut!((*ptr).$field) }; + unsafe { ::core::ptr::addr_of_mut!((*ptr)$(.$field)*) = }; ptr.cast() } } @@ -109,6 +109,96 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $= crate::list::ListLinks$(<$ /// implement that trait. /// /// [`ListItem`]: crate::list::ListItem +/// +/// # Examples +/// +/// ``` +/// #[pin_data] +/// struct SimpleListItem { +/// value: u32, +/// #[pin] +/// links: kernel::list::ListLinks, +/// } +/// +/// kernel::list::impl_has_list_links! { +/// impl HasListLinks<0> for SimpleListItem { self.links } +/// } +/// +/// kernel::list::impl_list_arc_safe! { +/// impl ListArcSafe<0> for SimpleListItem { untracked; } +/// } +/// +/// kernel::list::impl_list_item! { +/// impl ListItem<0> for SimpleListItem { using ListLinks; } +/// } +/// +/// struct ListLinksHolder { +/// inner: kernel::list::ListLinks, +/// } +/// +/// #[pin_data] +/// struct ComplexListItem { +/// value: Result, +/// #[pin] +/// links: ListLinksHolder, +/// } +/// +/// kernel::list::impl_has_list_links! { +/// impl{T, U} HasListLinks<0> for ComplexListItem { self.links.= inner } +/// } +/// +/// kernel::list::impl_list_arc_safe! { +/// impl{T, U} ListArcSafe<0> for ComplexListItem { untracked; } +/// } +/// +/// kernel::list::impl_list_item! { +/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= ; } +/// } +/// ``` +/// +/// ``` +/// #[pin_data] +/// struct SimpleListItem { +/// value: u32, +/// #[pin] +/// links: kernel::list::ListLinksSelfPtr, +/// } +/// +/// kernel::list::impl_list_arc_safe! { +/// impl ListArcSafe<0> for SimpleListItem { untracked; } +/// } +/// +/// kernel::list::impl_has_list_links_self_ptr! { +/// impl HasSelfPtr for SimpleListItem { self.links } +/// } +/// +/// kernel::list::impl_list_item! { +/// impl ListItem<0> for SimpleListItem { using ListLinksSelfPtr; } +/// } +/// +/// struct ListLinksSelfPtrHolder { +/// inner: kernel::list::ListLinksSelfPtr>, +/// } +/// +/// #[pin_data] +/// struct ComplexListItem { +/// value: Result, +/// #[pin] +/// links: ListLinksSelfPtrHolder, +/// } +/// +/// kernel::list::impl_list_arc_safe! { +/// impl{T, U} ListArcSafe<0> for ComplexListItem { untracked; } +/// } +/// +/// kernel::list::impl_has_list_links_self_ptr! { +/// impl{T, U} HasSelfPtr> for ComplexListItem { self.links.inner } +/// } +/// +/// kernel::list::impl_list_item! { +/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= SelfPtr; } +/// } +/// ``` #[macro_export] macro_rules! impl_list_item { ( --=20 2.49.0 From nobody Thu Dec 18 00:20:51 2025 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 391A728B50A; Wed, 23 Apr 2025 16:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425825; cv=none; b=QTGIbQtoKvP4CiPElbUYQ1D2AahYWNcMkVHN5qG/7LaCcKtdquW3nV0d84y2Cve/saR32FQ3HOvW5xetzdI/zoH3oCeR8CLKWZST+4dU7no9sZ29RnObw2otyBabR3xJx/WMYAt3HKRXSL/v20MrODtbt4vgyqarbRJ0NDkEYTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745425825; c=relaxed/simple; bh=QOFtrk4mPiISzVcwFepGbMeCVCsnQ81uNGz0Gwr0Xao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ye39UtLy1YC5YvK1mQ9AYqjr/FtzD/QARc9piTkn1iqoounAn1AO4V7GigreAWqQpPK1FrZ22DnpnVLUXzXj2iTAmqVRyR3FiE6LDX46MgBUYWA6sDU587rI/GsBN8ge3+RKT9oVUu3kaRn/l68qmxfqz5003rH5WV7Jnffk27w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HIhjLfUz; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HIhjLfUz" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7c9376c4dbaso8917385a.0; Wed, 23 Apr 2025 09:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745425822; x=1746030622; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=X/NHzNltxictK6KUUanFwOVZlo833y+o2VYI4YRagD0=; b=HIhjLfUzy6P/BGEf+qVmonFW6SwEKuVXW9P3oHXUzqfdwvcvuv8huTp9K/K1JT+lcQ gwS/3yTWr6Bx8uK6cNv7HVFwIDeA2UkAi5OB18arrmV6g2YupW2TPn42s/BxVTj5gf7g 39eVT6ZxRr4xSh3TkGx9LqNuMgZOXTqubSW+/zHZ0qZxfzAAokgXs6MUeISpCtL5u1Rj msSeyBzTa6Y81DytDUYnx/1Jvw+sM1e1JsPxNIKNdK/vfGiSceg1wNnzLaO95qfh4FXY dd4d44jpj3J8DPzzBRw7OZUyXtOsZcy39BtAMH62lfuCMv2liTmIwtylcyO6JATk1Gpc ogKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745425822; x=1746030622; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X/NHzNltxictK6KUUanFwOVZlo833y+o2VYI4YRagD0=; b=UDLF59aG8KaYzMk5dB7h9R0CrFRRUFSrzGCyV294PHo7OPHqIb8sa1Sl1KeOQnDCte lG8Qo7nwAU3HfCVONLRh2gyGh5n1EIMSG7UaiGwX4WMQNGyMM4FWE5DsK0sTzryKv3O6 lvWxWSbC8PaohSXjbuRY0Hx6pZy3Kyv6NO1xKJ7Q3LIahuQenVnl2N0uO3ixIfTmVUcD SwHR/b65EWj+TMQhoicoFF9Yb1tB3YPCnnlpy1+8AkUrIABbNCbhydYx8KqKXZNsX08m aI5Uxj45qbJftlJ68detXN9sjPGSDxDmun7s5WzMdoba7et5PErTqrVFxeb+yuArxXsq PbkA== X-Forwarded-Encrypted: i=1; AJvYcCU6QWbhXSvxlvzNgha0KWrgfkYTXbAvKMKAbzBhQo7o29ay5lyrvy9fTRWZQeVjmJbSMnfQLlrDILx+adA=@vger.kernel.org, AJvYcCXwRE8QRRLqgaRHwponqZH0jSbOTHcaw+1Zm/IcWPSczvB10RzC/0iP14JDEhZGlij6R6vhdVCZbdlS@vger.kernel.org X-Gm-Message-State: AOJu0YzcxGVU7NzToCXwlmy8ljdsj/GDXAnZMI5QjR+tFeTDcW9eE6p2 yNJROj9faYWFr/47yOqeaQ1eTAy6Qly7vQalyXZFRtANx2TjGrkE X-Gm-Gg: ASbGncvuELiW55VNf2bQYkuW6Asl4LjVE5XNcY9m8I8/p03hR3JZ1YoEZBCjyox2o9U EVZ5lt2u+rrZUgNIkqnfLZ1qlG9FZxmXTYcQgiS83XRuvBMETemYonAuWzVRyfMI+EGHfbx84RW KKSYOU1axLmtClc4UUoLYIjBHV838Ubj8XX5JoSIuAEbQY3yjVumRSCxmIN6AFsGhISq0x7MqWc f5EmhAoQqN8rpbS+zVEZVtEgSASJklmcFqb/AxFfzUdG3940pm1qNVLjJDsryhIQGf4UlMjedu7 MSKOtF6/R1wqfpPJR43VCMyU7PE686Z8M/0UXiXW8YcDcd3q79UjIk7BOtQbCWcaadjsLrLeeaO idg3fF3U4/yclIFLg1f/ZH8NZJr574gOrPs2LBvkRyD/gRT1NjA55s/9RuW7t X-Google-Smtp-Source: AGHT+IHPF0GSPsbo9HFqFM+znCucIBCU/4XXXoaXFiT1bvAXD3Fo9dIu+J3jh2Miqx+kvTe1BlA53g== X-Received: by 2002:a05:620a:414e:b0:7c5:6a40:6a7a with SMTP id af79cd13be357-7c94d80dedbmr630628685a.6.1745425821706; Wed, 23 Apr 2025 09:30:21 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([2620:10d:c091:600::1:e2b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c925b4dac4sm698031885a.86.2025.04.23.09.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 09:30:21 -0700 (PDT) From: Tamir Duberstein Date: Wed, 23 Apr 2025 12:30:07 -0400 Subject: [PATCH v3 6/6] rust: list: remove OFFSET constants 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 Message-Id: <20250423-list-no-offset-v3-6-9d0c2b89340e@gmail.com> References: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> In-Reply-To: <20250423-list-no-offset-v3-0-9d0c2b89340e@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev Replace `ListLinksSelfPtr::LIST_LINKS_SELF_PTR_OFFSET` with `unsafe fn raw_get_self_ptr` which returns a pointer to the field rather than requiring the caller to do pointer arithmetic. Implement `HasListLinks::raw_get_list_links` in `impl_has_list_links!`, narrowing the interface of `HasListLinks` and replacing pointer arithmetic with `container_of!`. Modify `impl_list_item` to also invoke `impl_has_list_links!` or `impl_has_list_links_self_ptr!`. This is necessary to allow `impl_list_item` to see more of the tokens used by `impl_has_list_links{,_self_ptr}!`. A similar API change was discussed on the hrtimer series[1]. Link: https://lore.kernel.org/all/20250224-hrtimer-v3-v6-12-rc2-v9-1-5bd3bf= 0ce6cc@kernel.org/ [1] Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Tested-by: Alice Ryhl --- rust/kernel/list.rs | 18 +++-- rust/kernel/list/impl_list_item_mod.rs | 143 +++++++++++++++--------------= ---- 2 files changed, 78 insertions(+), 83 deletions(-) diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs index a335c3b1ff5e..9017164c4556 100644 --- a/rust/kernel/list.rs +++ b/rust/kernel/list.rs @@ -212,9 +212,6 @@ unsafe impl Send for L= istLinksSelfPtr {} unsafe impl Sync for ListLinksSelfPtr {} =20 impl ListLinksSelfPtr { - /// The offset from the [`ListLinks`] to the self pointer field. - pub const LIST_LINKS_SELF_PTR_OFFSET: usize =3D core::mem::offset_of!(= Self, self_ptr); - /// Creates a new initializer for this type. pub fn new() -> impl PinInit { // INVARIANT: Pin-init initializers can't be used on an existing `= Arc`, so this value will @@ -229,6 +226,16 @@ pub fn new() -> impl PinInit { self_ptr: Opaque::uninit(), } } + + /// Returns a pointer to the self pointer. + /// + /// # Safety + /// + /// The provided pointer must point at a valid struct of type `Self`. + pub unsafe fn raw_get_self_ptr(me: *const Self) -> *const Opaque<*cons= t T> { + // SAFETY: The caller promises that the pointer is valid. + unsafe { ptr::addr_of!((*me).self_ptr) } + } } =20 impl, const ID: u64> List { @@ -603,14 +610,11 @@ fn next(&mut self) -> Option> { /// } /// } /// -/// kernel::list::impl_has_list_links! { -/// impl HasListLinks<0> for ListItem { self.links } -/// } /// kernel::list::impl_list_arc_safe! { /// impl ListArcSafe<0> for ListItem { untracked; } /// } /// kernel::list::impl_list_item! { -/// impl ListItem<0> for ListItem { using ListLinks; } +/// impl ListItem<0> for ListItem { using ListLinks { self.links }; } /// } /// /// // Use a cursor to remove the first element with the given value. diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index df21070e1cf6..927f7f52db69 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -4,21 +4,18 @@ =20 //! Helpers for implementing list traits safely. =20 -/// Declares that this type has a `ListLinks` field at a fixed offset. +/// Declares that this type has a [`ListLinks`] field. /// -/// This trait is only used to help implement `ListItem` safely. If `ListI= tem` is implemented +/// This trait is only used to help implement [`ListItem`] safely. If [`Li= stItem`] is implemented /// manually, then this trait is not needed. Use the [`impl_has_list_links= !`] macro to implement /// this trait. /// /// # Safety /// -/// All values of this type must have a `ListLinks` field at the given= offset. +/// The methods on this trait must have exactly the behavior that the defi= nitions given below have. /// -/// The behavior of `raw_get_list_links` must not be changed. +/// [`ListItem`]: crate::list::ListItem pub unsafe trait HasListLinks { - /// The offset of the `ListLinks` field. - const OFFSET: usize; - /// Returns a pointer to the [`ListLinks`] field. /// /// # Safety @@ -26,14 +23,7 @@ pub unsafe trait HasListLinks { /// The provided pointer must point at a valid struct of type `Self`. /// /// [`ListLinks`]: crate::list::ListLinks - // We don't really need this method, but it's necessary for the implem= entation of - // `impl_has_list_links!` to be correct. - #[inline] - unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut crate::list::List= Links { - // SAFETY: The caller promises that the pointer is valid. The impl= ementer promises that the - // `OFFSET` constant is correct. - unsafe { (ptr as *mut u8).add(Self::OFFSET) as *mut crate::list::L= istLinks } - } + unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut crate::list::List= Links; } =20 /// Implements the [`HasListLinks`] trait for the given type. @@ -46,14 +36,15 @@ macro_rules! impl_has_list_links { )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the // right type. - // - // The behavior of `raw_get_list_links` is not changed since the `= addr_of_mut!` macro is - // equivalent to the pointer offset operation in the trait definit= ion. unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { - const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; - #[inline] unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $crate::l= ist::ListLinks$(<$id>)? { + // Statically ensure that `$(.field)*` doesn't follow any = pointers. + // + // Cannot be `const` because `$self` may contain generics = and E0401 says constants + // "can't use {`Self`,generic parameters} from outer item". + if false { let _: usize =3D ::core::mem::offset_of!(Self, = $($field).*); } + // SAFETY: The caller promises that the pointer is not dan= gling. We know that this // expression doesn't follow any pointers, as the `offset_= of!` invocation above // would otherwise not compile. @@ -64,12 +55,15 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $c= rate::list::ListLinks$(<$ } pub use impl_has_list_links; =20 -/// Declares that the `ListLinks` field in this struct is inside a `Li= stLinksSelfPtr`. +/// Declares that the [`ListLinks`] field in this struct is inside a +/// [`ListLinksSelfPtr`]. /// /// # Safety /// -/// The `ListLinks` field of this struct at the offset `HasListLinks::OFFSET` must be -/// inside a `ListLinksSelfPtr`. +/// The [`ListLinks`] field of this struct at [`HasListLinks::raw_= get_list_links`] must be +/// inside a [`ListLinksSelfPtr`]. +/// +/// [`ListLinksSelfPtr`]: crate::list::ListLinksSelfPtr pub unsafe trait HasSelfPtr where Self: HasListLinks, @@ -89,8 +83,6 @@ macro_rules! impl_has_list_links_self_ptr { unsafe impl$(<$($generics)*>)? $crate::list::HasSelfPtr<$item_type= $(, $id)?> for $self {} =20 unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { - const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; - #[inline] unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $crate::l= ist::ListLinks$(<$id>)? { // SAFETY: The caller promises that the pointer is not dan= gling. @@ -120,16 +112,12 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut = $crate::list::ListLinks$(<$ /// links: kernel::list::ListLinks, /// } /// -/// kernel::list::impl_has_list_links! { -/// impl HasListLinks<0> for SimpleListItem { self.links } -/// } -/// /// kernel::list::impl_list_arc_safe! { /// impl ListArcSafe<0> for SimpleListItem { untracked; } /// } /// /// kernel::list::impl_list_item! { -/// impl ListItem<0> for SimpleListItem { using ListLinks; } +/// impl ListItem<0> for SimpleListItem { using ListLinks { self.links= }; } /// } /// /// struct ListLinksHolder { @@ -143,16 +131,12 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut = $crate::list::ListLinks$(<$ /// links: ListLinksHolder, /// } /// -/// kernel::list::impl_has_list_links! { -/// impl{T, U} HasListLinks<0> for ComplexListItem { self.links.= inner } -/// } -/// /// kernel::list::impl_list_arc_safe! { /// impl{T, U} ListArcSafe<0> for ComplexListItem { untracked; } /// } /// /// kernel::list::impl_list_item! { -/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= ; } +/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= { self.links.inner }; } /// } /// ``` /// @@ -168,12 +152,8 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $= crate::list::ListLinks$(<$ /// impl ListArcSafe<0> for SimpleListItem { untracked; } /// } /// -/// kernel::list::impl_has_list_links_self_ptr! { -/// impl HasSelfPtr for SimpleListItem { self.links } -/// } -/// /// kernel::list::impl_list_item! { -/// impl ListItem<0> for SimpleListItem { using ListLinksSelfPtr; } +/// impl ListItem<0> for SimpleListItem { using ListLinksSelfPtr { sel= f.links }; } /// } /// /// struct ListLinksSelfPtrHolder { @@ -191,21 +171,23 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut = $crate::list::ListLinks$(<$ /// impl{T, U} ListArcSafe<0> for ComplexListItem { untracked; } /// } /// -/// kernel::list::impl_has_list_links_self_ptr! { -/// impl{T, U} HasSelfPtr> for ComplexListItem { self.links.inner } -/// } -/// /// kernel::list::impl_list_item! { -/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= SelfPtr; } +/// impl{T, U} ListItem<0> for ComplexListItem { +/// using ListLinksSelfPtr { self.links.inner }; +/// } /// } /// ``` #[macro_export] macro_rules! impl_list_item { ( $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $self:ty { - using ListLinks; + using ListLinks { self$(.$field:ident)* }; })* ) =3D> {$( + $crate::list::impl_has_list_links! { + impl$({$($generics)*})? HasListLinks<$num> for $self { self$(.= $field)* } + } + // SAFETY: See GUARANTEES comment on each method. unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $s= elf { // GUARANTEES: @@ -221,20 +203,19 @@ unsafe fn view_links(me: *const Self) -> *mut $crate:= :list::ListLinks<$num> { } =20 // GUARANTEES: - // * `me` originates from the most recent call to `prepare_to_= insert`, which just added - // `offset` to the pointer passed to `prepare_to_insert`. Th= is method subtracts - // `offset` from `me` so it returns the pointer originally p= assed to - // `prepare_to_insert`. + // * `me` originates from the most recent call to `prepare_to_= insert`, which calls + // `raw_get_list_link`, which is implemented using `addr_of_= mut!((*self)$(.$field)*)`. + // This method uses `container_of` to perform the inverse op= eration, so it returns the + // pointer originally passed to `prepare_to_insert`. // * The pointer remains valid until the next call to `post_re= move` because the caller // of the most recent call to `prepare_to_insert` promised t= o retain ownership of the // `ListArc` containing `Self` until the next call to `post_= remove`. The value cannot // be destroyed while a `ListArc` reference exists. unsafe fn view_value(me: *mut $crate::list::ListLinks<$num>) -= > *const Self { - let offset =3D >:= :OFFSET; // SAFETY: `me` originates from the most recent call to `p= repare_to_insert`, so it - // points at the field at offset `offset` in a value of ty= pe `Self`. Thus, - // subtracting `offset` from `me` is still in-bounds of th= e allocation. - unsafe { (me as *const u8).sub(offset) as *const Self } + // points at the field `$field` in a value of type `Self`.= Thus, reversing that + // operation is still in-bounds of the allocation. + $crate::container_of!(me, Self, $($field).*) } =20 // GUARANTEES: @@ -251,25 +232,28 @@ unsafe fn prepare_to_insert(me: *const Self) -> *mut = $crate::list::ListLinks<$nu } =20 // GUARANTEES: - // * `me` originates from the most recent call to `prepare_to_= insert`, which just added - // `offset` to the pointer passed to `prepare_to_insert`. Th= is method subtracts - // `offset` from `me` so it returns the pointer originally p= assed to - // `prepare_to_insert`. + // * `me` originates from the most recent call to `prepare_to_= insert`, which calls + // `raw_get_list_link`, which is implemented using `addr_of_= mut!((*self)$(.$field)*)`. + // This method uses `container_of` to perform the inverse op= eration, so it returns the + // pointer originally passed to `prepare_to_insert`. unsafe fn post_remove(me: *mut $crate::list::ListLinks<$num>) = -> *const Self { - let offset =3D >:= :OFFSET; // SAFETY: `me` originates from the most recent call to `p= repare_to_insert`, so it - // points at the field at offset `offset` in a value of ty= pe `Self`. Thus, - // subtracting `offset` from `me` is still in-bounds of th= e allocation. - unsafe { (me as *const u8).sub(offset) as *const Self } + // points at the field `$field` in a value of type `Self`.= Thus, reversing that + // operation is still in-bounds of the allocation. + $crate::container_of!(me, Self, $($field).*) } } )*}; =20 ( $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $self:ty { - using ListLinksSelfPtr; + using ListLinksSelfPtr { self$(.$field:ident)* }; })* ) =3D> {$( + $crate::list::impl_has_list_links_self_ptr! { + impl$({$($generics)*})? HasSelfPtr<$self> for $self { self$(.$= field)* } + } + // SAFETY: See GUARANTEES comment on each method. unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $s= elf { // GUARANTEES: @@ -284,13 +268,15 @@ unsafe fn prepare_to_insert(me: *const Self) -> *mut = $crate::list::ListLinks<$nu // SAFETY: The caller promises that `me` points at a valid= value of type `Self`. let links_field =3D unsafe { >::view_links(me) }; =20 - let spoff =3D $crate::list::ListLinksSelfPtr::= ::LIST_LINKS_SELF_PTR_OFFSET; - // Goes via the offset as the field is private. - // - // SAFETY: The constant is equal to `offset_of!(ListLinksS= elfPtr, self_ptr)`, so - // the pointer stays in bounds of the allocation. - let self_ptr =3D unsafe { (links_field as *const u8).add(s= poff) } - as *const $crate::types::Opaque<*const Self>; + let container =3D $crate::container_of!( + links_field, $crate::list::ListLinksSelfPtr, inner, + ); + + // SAFETY: By the same reasoning above, `links_field` is a= valid pointer. + let self_ptr =3D unsafe { + $crate::list::ListLinksSelfPtr::raw_get_self_ptr(conta= iner) + }; + let cell_inner =3D $crate::types::Opaque::raw_get(self_ptr= ); =20 // SAFETY: This value is not accessed in any other places = than `prepare_to_insert`, @@ -331,12 +317,17 @@ unsafe fn view_links(me: *const Self) -> *mut $crate:= :list::ListLinks<$num> { // `ListArc` containing `Self` until the next call to `post_= remove`. The value cannot // be destroyed while a `ListArc` reference exists. unsafe fn view_value(links_field: *mut $crate::list::ListLinks= <$num>) -> *const Self { - let spoff =3D $crate::list::ListLinksSelfPtr::= ::LIST_LINKS_SELF_PTR_OFFSET; - // SAFETY: The constant is equal to `offset_of!(ListLinksS= elfPtr, self_ptr)`, so - // the pointer stays in bounds of the allocation. - let self_ptr =3D unsafe { (links_field as *const u8).add(s= poff) } - as *const ::core::cell::UnsafeCell<*const Self>; - let cell_inner =3D ::core::cell::UnsafeCell::raw_get(self_= ptr); + let container =3D $crate::container_of!( + links_field, $crate::list::ListLinksSelfPtr, inner, + ); + + // SAFETY: By the same reasoning above, `links_field` is a= valid pointer. + let self_ptr =3D unsafe { + $crate::list::ListLinksSelfPtr::raw_get_self_ptr(conta= iner) + }; + + let cell_inner =3D $crate::types::Opaque::raw_get(self_ptr= ); + // SAFETY: This is not a data race, because the only funct= ion that writes to this // value is `prepare_to_insert`, but by the safety require= ments the // `prepare_to_insert` method may not be called in paralle= l with `view_value` or --=20 2.49.0