From nobody Fri Dec 19 17:00:03 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 57E4A335087 for ; Mon, 15 Dec 2025 18:03:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765821833; cv=none; b=iYFmHdIdPpHZQe8QzIADHToaKLR82zOCUyf7lwwOJDiYz7+yrTYNA7dsb1CpvT9kCkANR86KAgTWfuXrgMjt95gHKbKlQI3fXD+WsZCU4Z68peZsp0wyvlPEY9EfsCs6HT5oNzNFWz9qVCus8jpzIRyff5fwjvTMCjQoGILH+XM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765821833; c=relaxed/simple; bh=0EDtGy67sbcMtonwjGxPUyf4fnAu6cVCFLi68oUxz6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qCqN7Ib+7KegMjmiNmNX0iQvhcJhoy66zpvaxSqU6uwCug+kb3XrwMxg5cAikC6ntbYBB1XGJSUjANQE/kEmQb+uTLeX9ugwtlf6FVmsHTjILf22hD8ELELxe4h/izKO5cg6OarmcWH4V/VyPuvWfcVITzX4sYh7V00hIvbL9rQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BoWKmGL1; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BoWKmGL1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765821827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NPXbpVkoQILJpCk9IhXa/hmpE7g50auFpY6RHrWLkQE=; b=BoWKmGL1u6VnHP5vBXEqrXn4bxpxFnkKnqY6esoULlTPeOwD1JasWHB4Ye7/+wcaol9Liv AYOwik4+7Gimw4H/YShWJOfLjUoemF7IN4XtBe7KlMpBx7iIaF/IYJphlT6+r+gdZD1Z2a ilGWNrnEvBEZFVeglQ2VJ4BXaWl5IiE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-ZtwmeZ5MMDCsUmMMwVvWFw-1; Mon, 15 Dec 2025 13:03:16 -0500 X-MC-Unique: ZtwmeZ5MMDCsUmMMwVvWFw-1 X-Mimecast-MFC-AGG-ID: ZtwmeZ5MMDCsUmMMwVvWFw_1765821768 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 757C618868BB; Mon, 15 Dec 2025 17:59:11 +0000 (UTC) Received: from chopper.lan (unknown [10.22.81.30]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3E524180044F; Mon, 15 Dec 2025 17:59:07 +0000 (UTC) From: Lyude Paul To: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner Cc: Boqun Feng , Daniel Almeida , Miguel Ojeda , Alex Gaynor , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Andrew Morton , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long Subject: [PATCH v16 12/17] rust: sync: lock/global: Rename B to G in trait bounds Date: Mon, 15 Dec 2025 12:57:59 -0500 Message-ID: <20251215175806.102713-13-lyude@redhat.com> In-Reply-To: <20251215175806.102713-1-lyude@redhat.com> References: <20251215175806.102713-1-lyude@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" Due to the introduction of Backend::BackendInContext, if we want to be able support Lock types with a Context we need to be able to handle the fact that the Backend for a returned Guard may not exactly match the Backend for the lock. Before we add this though, rename B to G in all of our trait bounds to make sure things don't become more difficult to understand once we add a Backend bound. There should be no functional changes in this patch. Signed-off-by: Lyude Paul --- rust/kernel/sync/atomic.rs | 2 +- rust/kernel/sync/lock/global.rs | 58 ++++++++++++++++----------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/rust/kernel/sync/atomic.rs b/rust/kernel/sync/atomic.rs index 3afc376be42d9..c07a53f8360b4 100644 --- a/rust/kernel/sync/atomic.rs +++ b/rust/kernel/sync/atomic.rs @@ -21,8 +21,8 @@ mod predefine; =20 pub use internal::AtomicImpl; -pub use ordering::{Acquire, Full, Relaxed, Release}; pub(crate) use internal::{AtomicArithmeticOps, AtomicBasicOps, AtomicExcha= ngeOps}; +pub use ordering::{Acquire, Full, Relaxed, Release}; =20 use crate::build_error; use internal::AtomicRepr; diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global= .rs index 7030a47bc0ad1..06d62ad02f90d 100644 --- a/rust/kernel/sync/lock/global.rs +++ b/rust/kernel/sync/lock/global.rs @@ -33,18 +33,18 @@ pub trait GlobalLockBackend { /// Type used for global locks. /// /// See [`global_lock!`] for examples. -pub struct GlobalLock { - inner: Lock, +pub struct GlobalLock { + inner: Lock, } =20 -impl GlobalLock { +impl GlobalLock { /// Creates a global lock. /// /// # Safety /// /// * Before any other method on this lock is called, [`Self::init`] m= ust be called. - /// * The type `B` must not be used with any other lock. - pub const unsafe fn new(data: B::Item) -> Self { + /// * The type `G` must not be used with any other lock. + pub const unsafe fn new(data: G::Item) -> Self { Self { inner: Lock { state: Opaque::uninit(), @@ -68,23 +68,23 @@ pub unsafe fn init(&'static self) { // `init` before using any other methods. As `init` can only be ca= lled once, all other // uses of this lock must happen after this call. unsafe { - B::Backend::init( + G::Backend::init( self.inner.state.get(), - B::NAME.as_char_ptr(), - B::get_lock_class().as_ptr(), + G::NAME.as_char_ptr(), + G::get_lock_class().as_ptr(), ) } } =20 /// Lock this global lock. - pub fn lock(&'static self) -> GlobalGuard { + pub fn lock(&'static self) -> GlobalGuard { GlobalGuard { inner: self.inner.lock(), } } =20 /// Try to lock this global lock. - pub fn try_lock(&'static self) -> Option> { + pub fn try_lock(&'static self) -> Option> { Some(GlobalGuard { inner: self.inner.try_lock()?, }) @@ -94,21 +94,21 @@ pub fn try_lock(&'static self) -> Option= > { /// A guard for a [`GlobalLock`]. /// /// See [`global_lock!`] for examples. -pub struct GlobalGuard { - inner: Guard<'static, B::Item, B::Backend>, +pub struct GlobalGuard { + inner: Guard<'static, G::Item, G::Backend>, } =20 -impl core::ops::Deref for GlobalGuard { - type Target =3D B::Item; +impl core::ops::Deref for GlobalGuard { + type Target =3D G::Item; =20 fn deref(&self) -> &Self::Target { &self.inner } } =20 -impl core::ops::DerefMut for GlobalGuard +impl core::ops::DerefMut for GlobalGuard where - B::Item: Unpin, + G::Item: Unpin, { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner @@ -118,33 +118,33 @@ fn deref_mut(&mut self) -> &mut Self::Target { /// A version of [`LockedBy`] for a [`GlobalLock`]. /// /// See [`global_lock!`] for examples. -pub struct GlobalLockedBy { - _backend: PhantomData, +pub struct GlobalLockedBy { + _backend: PhantomData, value: UnsafeCell, } =20 // SAFETY: The same thread-safety rules as `LockedBy` apply to `GlobalLock= edBy`. -unsafe impl Send for GlobalLockedBy +unsafe impl Send for GlobalLockedBy where T: ?Sized, - B: GlobalLockBackend, - LockedBy: Send, + G: GlobalLockBackend, + LockedBy: Send, { } =20 // SAFETY: The same thread-safety rules as `LockedBy` apply to `GlobalLock= edBy`. -unsafe impl Sync for GlobalLockedBy +unsafe impl Sync for GlobalLockedBy where T: ?Sized, - B: GlobalLockBackend, - LockedBy: Sync, + G: GlobalLockBackend, + LockedBy: Sync, { } =20 -impl GlobalLockedBy { +impl GlobalLockedBy { /// Create a new [`GlobalLockedBy`]. /// - /// The provided value will be protected by the global lock indicated = by `B`. + /// The provided value will be protected by the global lock indicated = by `G`. pub fn new(val: T) -> Self { Self { value: UnsafeCell::new(val), @@ -153,11 +153,11 @@ pub fn new(val: T) -> Self { } } =20 -impl GlobalLockedBy { +impl GlobalLockedBy { /// Access the value immutably. /// /// The caller must prove shared access to the lock. - pub fn as_ref<'a>(&'a self, _guard: &'a GlobalGuard) -> &'a T { + pub fn as_ref<'a>(&'a self, _guard: &'a GlobalGuard) -> &'a T { // SAFETY: The lock is globally unique, so there can only be one g= uard. unsafe { &*self.value.get() } } @@ -165,7 +165,7 @@ pub fn as_ref<'a>(&'a self, _guard: &'a GlobalGuard)= -> &'a T { /// Access the value mutably. /// /// The caller must prove shared exclusive to the lock. - pub fn as_mut<'a>(&'a self, _guard: &'a mut GlobalGuard) -> &'a mut= T { + pub fn as_mut<'a>(&'a self, _guard: &'a mut GlobalGuard) -> &'a mut= T { // SAFETY: The lock is globally unique, so there can only be one g= uard. unsafe { &mut *self.value.get() } } --=20 2.52.0