From nobody Sat Feb 7 08:02:28 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 153A64611CE for ; Wed, 21 Jan 2026 22:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769035252; cv=none; b=Ol1ceiLzZ/k2CzxqHaCI074D80l0nmWVn/U0d10dQGm+hgnOAbb/9moNjP9YMxsxfnMpn5LjvCWAeIFnij6IhkVAPJA8GbQDJL5qmeogCBObwq7coFlT0KOOwMchCC+q8Kk7TZNG8gDGpVGT08VXcOJ8M/BSnAtJOKXE3aXRlck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769035252; c=relaxed/simple; bh=EfTjFabigOiPBmC0Q/EuF/KG8Lc+JLukTQibKYqiIUU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hvQU7uyM5smN3Fu3pKayHQLOO5OPrXEqfLEdMeNdZd//5ILyMKa/ybaDMkyThgYrq55SxVaGR7wsB+3tL4dVNnIR1P59DRRt6BQNmj0VHGSKBxc8GelA14u1cHYRKjm/TgY/wooLrPyS+9YVndleJMSZdcYzDiKOmTmxrEjTJZ0= 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=aa79eB8t; arc=none smtp.client-ip=170.10.133.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="aa79eB8t" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769035243; 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=zmzTH+uv1hHz5wDlO82/nhHSVu/hhPAX/2Z+bLEiOKY=; b=aa79eB8t/PU0sZB9boc8coxY9YOMEspNIDjFYtGasF2ZKIzd8FuB1kHAaDMr2I5QFDTJBJ 0lHTlIlGtRgNNur/EKH46C8rwqqoPAG2BmgYSt+tNu4hQ9o29uUZ3/NU2Yak9izjRuOrnZ FJNddg6a7zfIpG4Z0/QurSIqcMF43+U= Received: from mx-prod-mc-01.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-492-4hwj1uCjOZuZt81eSDWtrw-1; Wed, 21 Jan 2026 17:40:39 -0500 X-MC-Unique: 4hwj1uCjOZuZt81eSDWtrw-1 X-Mimecast-MFC-AGG-ID: 4hwj1uCjOZuZt81eSDWtrw_1769035237 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 64F6919560A3; Wed, 21 Jan 2026 22:40:37 +0000 (UTC) Received: from GoldenWind.redhat.com (unknown [10.22.89.232]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C8F7719560AB; Wed, 21 Jan 2026 22:40:34 +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 v17 15/16] rust: sync: lock/global: Add ContextualBackend support to GlobalLock Date: Wed, 21 Jan 2026 17:39:18 -0500 Message-ID: <20260121223933.1568682-16-lyude@redhat.com> In-Reply-To: <20260121223933.1568682-1-lyude@redhat.com> References: <20260121223933.1568682-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.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Now that we have the ability to provide an explicit lifetime for a GlobalGuard and an explicit Backend for a GlobalGuard, we can finally implement lock_with() and try_lock_with(). Signed-off-by: Lyude Paul --- rust/kernel/sync/lock/global.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global= .rs index 94f6b3b21324f..cfc71af7482ed 100644 --- a/rust/kernel/sync/lock/global.rs +++ b/rust/kernel/sync/lock/global.rs @@ -6,7 +6,7 @@ =20 use crate::{ str::{CStr, CStrExt as _}, - sync::lock::{Backend, Guard, Lock}, + sync::lock::{Backend, BackendWithContext, Guard, Lock}, sync::{LockClassKey, LockedBy}, types::Opaque, }; @@ -89,6 +89,34 @@ pub fn try_lock(&'static self) -> Option> { inner: self.inner.try_lock()?, }) } + + /// Lock this global lock with the provided `context`. + pub fn lock_with<'a, B>( + &'static self, + context: ::Context<'a>, + ) -> GlobalGuard<'a, G, B> + where + G::Backend: BackendWithContext, + B: Backend, + { + GlobalGuard { + inner: self.inner.lock_with(context), + } + } + + /// Try to lock this global lock with the provided `context`. + pub fn try_lock_with<'a, B>( + &'static self, + context: ::Context<'a>, + ) -> Option> + where + G::Backend: BackendWithContext, + B: Backend, + { + Some(GlobalGuard { + inner: self.inner.try_lock_with(context)?, + }) + } } =20 /// A guard for a [`GlobalLock`]. --=20 2.52.0