From mboxrd@z Thu Jan 1 00:00:00 1970 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 27B57346A0E for ; Sun, 11 Jan 2026 12:03:50 +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=1768133033; cv=none; b=Li0bB6hjOjsga4SY5cYi0GHPwgwimT2CwmAVa+nc6OjL4oQahI1CuNasG4tTf4WHMAlhiSyOBYV9iOu31l4vAhA/OTbqpKtwYVrkPFPFS8GXLreNkpYq+iYuerUijqNYxToH2fpYyguwbSnNo0zkXqy6PZF7sWUBRFVAoGA+ocw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768133033; c=relaxed/simple; bh=s8N4ZiJ/NTw5nCFolZ2qL520EQTDevyDNLvKPYHhOxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S6ESj5vbkKNPabvAdcItZov+BMQJQ7RF1ouzF1tvynExrQtC9Xs9bTqXuj9UlSbZyawzNUVQrfn2a5ErDQBE0C6TvL4eSsJKO/ck14ILfMXk6A77Osip6pepWyXn51nwTE2nIZpHcNrfNDGnYo5AeXSNGNLpujWXeaD4s0h7r9s= 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=dNavHVJV; 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="dNavHVJV" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-8c2f74ffd81so577177885a.1 for ; Sun, 11 Jan 2026 04:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768133029; x=1768737829; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=k0bZMcMbWrQBQFSEmsod610ePoTMj3P6f+YOc7ODi3w=; b=dNavHVJVcngTrU9Rp6M1PS976z3Sm6tbOmkYahLCANi1B99yV2/10+qnNLrXkjSRtp 7Y31VbD80e5cbDIfJZz+UCx4XtObamuaXExu2GjGLuNAgwV9BX9P1Dr17WYI5jW9SHFv xsAs194diH/4P5tWmNeZhqIANNA5ZlADok/Hj+zX4JXarNGzP0YglF/P2uDhMjEYoqk0 PbLShEUIDCkt+sBaY7iwbPUKQXixZ893wpm4NriU/VWxr8q8wCxRGUVUsf0yW7uxxHDK elv9DVosJ/mnQUTC1+dYsx1dA12z/mZ+30GPu2poEYskT/ZJ3x7SqAnQpG5LgzRBiW4B FWrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768133029; x=1768737829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=k0bZMcMbWrQBQFSEmsod610ePoTMj3P6f+YOc7ODi3w=; b=XH30xpuyMxjLVvOa1KHKJLbEj8ooQFEZL4fYu2RYfNEReLHGggl9rmwDuxCKFR0h5k aBpXWwbFIZTpZo+/3/EoAgcSc2elNWZrr5ORcOIR309JwU8hHFZusyARrmDbZwJhy48v XOn6Pddg/ltF+Yd4rMCRG9gDJuH6WHzXTiPQVj+cJZsryoSeELY+w8RXWKjBJyhTU6oQ l/HH5XJk2QVJ0nomSffHKIVHSSAvUSUV2b4ZizT0poWQ/L/H/NLp5evR3kWD+RomN7tB ite8uheYlyF8OhBZCWg2rK6c25dcHNOCxc8Lppk85Nqf2qcNpinWDVDgXyK9yw4otDgY aHPA== X-Forwarded-Encrypted: i=1; AJvYcCXpe/JDeUSqluzQf3i7c1PLdsUwI9YXnvUa9LmiOcf6J6kGbXabvQ+Eb2OFrraO1l7/4WAviFoQ3vHF0Mg=@vger.kernel.org X-Gm-Message-State: AOJu0YxuJRDbYV4epQycXvyPj6KyLn6HEoGPKNJvdJWAA5JHwiBRvfkw aYB/gNFdFgt1baNwtPdD+4pmDjoQhVZ7TFrPuGwVF1i4W5Zm5P8/DfBL X-Gm-Gg: AY/fxX5/1mJMxD0xngaUsaGcwHon1woqAtVIiQ6Rjd95V3EWnxOwbEgpkfMeUIGqNzY C0/BuiJFydh2uaRIh5jrtwtg5wBiG0iCNW6cdE/+YB0Ib2lTA740ECj/Tu5uImpOxiyoWFlfmwg 7JzYLmhXgSVa2hSKIBKdMWFJ2m323LFagTbIRnXtf+TyKENy7ruwO4VY0objlgGGYg6U8E/wXuu zlLoQrstjLcEQxIsi0lAyjJ54T/wH1UuHHHUOR0GQhgEvaseEolwU0ZNZpiPpOYQoYqwU6LZM35 ihojCxZH5qQ/zxge8iC0iGze9IsKtfGDaTrFVut52EHgSiZiv3+3Ryyax7nsKXvzy2iRex2E+VK 5FiA+zvPhOcX6hqomaDSibOj/NzNOnoHexa47tDZWuF/u/B1HCUWi5HyQDb9TLkAuqUNqBpApSS tveJ1VM1T+uQvVBSOHC1xySq3ZhYLkxcucEPtsBhyaruJpjm0wJCLD6CPUWRbI/aDYRgu/dkqDd CMSTFePlWa7iaY= X-Google-Smtp-Source: AGHT+IF5ftE08RXjLlbNoPp+Az1KvVdU3HySJevvvDjzTv59UekS/JjztS89lqrMGGkkDvv/jcfZIQ== X-Received: by 2002:a05:620a:410d:b0:892:ca0f:fc21 with SMTP id af79cd13be357-8c38939cf58mr2050163385a.40.1768133028929; Sun, 11 Jan 2026 04:03:48 -0800 (PST) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c37f4a63acsm1284207385a.6.2026.01.11.04.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jan 2026 04:03:48 -0800 (PST) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfauth.phl.internal (Postfix) with ESMTP id 2693FF40068; Sun, 11 Jan 2026 07:03:48 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Sun, 11 Jan 2026 07:03:48 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduudeghedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpeeugeeiffevuedvvddvfeejffekfedtvdevieehteehjeefkedtgfelvdelfefg ieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgpdhmshhgihgurdhlihhnkhdplhhotg hkrdgurghtrgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhr ohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvge ehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhm sehfihigmhgvrdhnrghmvgdpnhgspghrtghpthhtohepudehpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehpvghtvghriiesihhnfhhrrgguvggrugdrohhrghdprhgtphht thhopehmihhnghhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopehruhhsthdqfhhorh dqlhhinhhugiesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhig qdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopeifihhllh eskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrrhhkrdhruhhtlhgrnhgusegrrhhm rdgtohhmpdhrtghpthhtohepthhglhigsehlihhnuhhtrhhonhhigidruggvpdhrtghpth htohepohhjvggurgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghgrrhihsehgrghr hihguhhordhnvght X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 11 Jan 2026 07:03:47 -0500 (EST) From: Boqun Feng To: "Peter Zijlstra" , "Ingo Molnar" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, "Will Deacon" , "Mark Rutland" , "Thomas Gleixner" , "Miguel Ojeda" , "Gary Guo" , "Alice Ryhl" , "Andreas Hindborg" , "Benno Lossin" , "Danilo Krummrich" , Daniel Almeida , Boqun Feng Subject: [PATCH 36/36] rust: sync: Inline various lock related methods Date: Sun, 11 Jan 2026 20:02:09 +0800 Message-ID: <20260111120209.6133-34-boqun.feng@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260111120209.6133-1-boqun.feng@gmail.com> References: <20260111115808.5702-1-boqun.feng@gmail.com> <20260111120209.6133-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Alice Ryhl While debugging a different issue [1], the following relocation was noticed in the rust_binder.ko file: R_AARCH64_CALL26 _RNvXNtNtNtCsdfZWD8DztAw_6kernel4sync4lock8spinlockNtB2_15SpinLockBackendNtB4_7Backend6unlock This relocation (and a similar one for lock) occurred many times throughout the module. That is not really useful because all this function does is call spin_unlock(), so what we actually want here is that a call to spin_unlock() dirctly is generated in favor of this wrapper method. Thus, mark these methods inline. [boqun: Reword the commit message a bit] Link: https://lore.kernel.org/p/20251111-binder-fix-list-remove-v1-0-8ed14a0da63d@google.com Signed-off-by: Alice Ryhl Reviewed-by: Gary Guo Reviewed-by: Daniel Almeida Signed-off-by: Boqun Feng Link: https://patch.msgid.link/20251218-inline-lock-unlock-v2-1-fbadac8bd61b@google.com --- rust/kernel/sync/lock.rs | 7 +++++++ rust/kernel/sync/lock/global.rs | 2 ++ rust/kernel/sync/lock/mutex.rs | 5 +++++ rust/kernel/sync/lock/spinlock.rs | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index 46a57d1fc309..10b6b5e9b024 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -156,6 +156,7 @@ impl Lock<(), B> { /// the whole lifetime of `'a`. /// /// [`State`]: Backend::State + #[inline] pub unsafe fn from_raw<'a>(ptr: *mut B::State) -> &'a Self { // SAFETY: // - By the safety contract `ptr` must point to a valid initialised instance of `B::State` @@ -169,6 +170,7 @@ pub unsafe fn from_raw<'a>(ptr: *mut B::State) -> &'a Self { impl Lock { /// Acquires the lock and gives the caller access to the data protected by it. + #[inline] pub fn lock(&self) -> Guard<'_, T, B> { // SAFETY: The constructor of the type calls `init`, so the existence of the object proves // that `init` was called. @@ -182,6 +184,7 @@ pub fn lock(&self) -> Guard<'_, T, B> { /// Returns a guard that can be used to access the data protected by the lock if successful. // `Option` is not `#[must_use]` even if `T` is, thus the attribute is needed here. #[must_use = "if unused, the lock will be immediately unlocked"] + #[inline] pub fn try_lock(&self) -> Option> { // SAFETY: The constructor of the type calls `init`, so the existence of the object proves // that `init` was called. @@ -275,6 +278,7 @@ pub fn as_mut(&mut self) -> Pin<&mut T> { impl core::ops::Deref for Guard<'_, T, B> { type Target = T; + #[inline] fn deref(&self) -> &Self::Target { // SAFETY: The caller owns the lock, so it is safe to deref the protected data. unsafe { &*self.lock.data.get() } @@ -285,6 +289,7 @@ impl core::ops::DerefMut for Guard<'_, T, B> where T: Unpin, { + #[inline] fn deref_mut(&mut self) -> &mut Self::Target { // SAFETY: The caller owns the lock, so it is safe to deref the protected data. unsafe { &mut *self.lock.data.get() } @@ -292,6 +297,7 @@ fn deref_mut(&mut self) -> &mut Self::Target { } impl Drop for Guard<'_, T, B> { + #[inline] fn drop(&mut self) { // SAFETY: The caller owns the lock, so it is safe to unlock it. unsafe { B::unlock(self.lock.state.get(), &self.state) }; @@ -304,6 +310,7 @@ impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> { /// # Safety /// /// The caller must ensure that it owns the lock. + #[inline] pub unsafe fn new(lock: &'a Lock, state: B::GuardState) -> Self { // SAFETY: The caller can only hold the lock if `Backend::init` has already been called. unsafe { B::assert_is_held(lock.state.get()) }; diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global.rs index eab48108a4ae..aecbdc34738f 100644 --- a/rust/kernel/sync/lock/global.rs +++ b/rust/kernel/sync/lock/global.rs @@ -77,6 +77,7 @@ pub unsafe fn init(&'static self) { } /// Lock this global lock. + #[inline] pub fn lock(&'static self) -> GlobalGuard { GlobalGuard { inner: self.inner.lock(), @@ -84,6 +85,7 @@ pub fn lock(&'static self) -> GlobalGuard { } /// Try to lock this global lock. + #[inline] pub fn try_lock(&'static self) -> Option> { Some(GlobalGuard { inner: self.inner.try_lock()?, diff --git a/rust/kernel/sync/lock/mutex.rs b/rust/kernel/sync/lock/mutex.rs index 581cee7ab842..cda0203efefb 100644 --- a/rust/kernel/sync/lock/mutex.rs +++ b/rust/kernel/sync/lock/mutex.rs @@ -102,6 +102,7 @@ unsafe impl super::Backend for MutexBackend { type State = bindings::mutex; type GuardState = (); + #[inline] unsafe fn init( ptr: *mut Self::State, name: *const crate::ffi::c_char, @@ -112,18 +113,21 @@ unsafe fn init( unsafe { bindings::__mutex_init(ptr, name, key) } } + #[inline] unsafe fn lock(ptr: *mut Self::State) -> Self::GuardState { // SAFETY: The safety requirements of this function ensure that `ptr` points to valid // memory, and that it has been initialised before. unsafe { bindings::mutex_lock(ptr) }; } + #[inline] unsafe fn unlock(ptr: *mut Self::State, _guard_state: &Self::GuardState) { // SAFETY: The safety requirements of this function ensure that `ptr` is valid and that the // caller is the owner of the mutex. unsafe { bindings::mutex_unlock(ptr) }; } + #[inline] unsafe fn try_lock(ptr: *mut Self::State) -> Option { // SAFETY: The `ptr` pointer is guaranteed to be valid and initialized before use. let result = unsafe { bindings::mutex_trylock(ptr) }; @@ -135,6 +139,7 @@ unsafe fn try_lock(ptr: *mut Self::State) -> Option { } } + #[inline] unsafe fn assert_is_held(ptr: *mut Self::State) { // SAFETY: The `ptr` pointer is guaranteed to be valid and initialized before use. unsafe { bindings::mutex_assert_is_held(ptr) } diff --git a/rust/kernel/sync/lock/spinlock.rs b/rust/kernel/sync/lock/spinlock.rs index d7be38ccbdc7..ef76fa07ca3a 100644 --- a/rust/kernel/sync/lock/spinlock.rs +++ b/rust/kernel/sync/lock/spinlock.rs @@ -101,6 +101,7 @@ unsafe impl super::Backend for SpinLockBackend { type State = bindings::spinlock_t; type GuardState = (); + #[inline] unsafe fn init( ptr: *mut Self::State, name: *const crate::ffi::c_char, @@ -111,18 +112,21 @@ unsafe fn init( unsafe { bindings::__spin_lock_init(ptr, name, key) } } + #[inline] unsafe fn lock(ptr: *mut Self::State) -> Self::GuardState { // SAFETY: The safety requirements of this function ensure that `ptr` points to valid // memory, and that it has been initialised before. unsafe { bindings::spin_lock(ptr) } } + #[inline] unsafe fn unlock(ptr: *mut Self::State, _guard_state: &Self::GuardState) { // SAFETY: The safety requirements of this function ensure that `ptr` is valid and that the // caller is the owner of the spinlock. unsafe { bindings::spin_unlock(ptr) } } + #[inline] unsafe fn try_lock(ptr: *mut Self::State) -> Option { // SAFETY: The `ptr` pointer is guaranteed to be valid and initialized before use. let result = unsafe { bindings::spin_trylock(ptr) }; @@ -134,6 +138,7 @@ unsafe fn try_lock(ptr: *mut Self::State) -> Option { } } + #[inline] unsafe fn assert_is_held(ptr: *mut Self::State) { // SAFETY: The `ptr` pointer is guaranteed to be valid and initialized before use. unsafe { bindings::spin_assert_is_held(ptr) } -- 2.51.0