Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust_binder: Switch to kernel::sync atomic primitives

Convert uses of AtomicBool, AtomicUsize, and AtomicU32.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Acked-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://patch.msgid.link/20251230093718.1852322-4-fujita.tomonori@gmail.com

authored by

FUJITA Tomonori and committed by
Boqun Feng
7f4c8b4d 323e4bfc

+32 -36
+9 -11
drivers/android/binder/rust_binder_main.rs
··· 18 18 prelude::*, 19 19 seq_file::SeqFile, 20 20 seq_print, 21 + sync::atomic::{ordering::Relaxed, Atomic}, 21 22 sync::poll::PollTable, 22 23 sync::Arc, 23 24 task::Pid, ··· 29 28 30 29 use crate::{context::Context, page_range::Shrinker, process::Process, thread::Thread}; 31 30 32 - use core::{ 33 - ptr::NonNull, 34 - sync::atomic::{AtomicBool, AtomicUsize, Ordering}, 35 - }; 31 + use core::ptr::NonNull; 36 32 37 33 mod allocation; 38 34 mod context; ··· 88 90 } 89 91 90 92 fn next_debug_id() -> usize { 91 - static NEXT_DEBUG_ID: AtomicUsize = AtomicUsize::new(0); 93 + static NEXT_DEBUG_ID: Atomic<usize> = Atomic::new(0); 92 94 93 - NEXT_DEBUG_ID.fetch_add(1, Ordering::Relaxed) 95 + NEXT_DEBUG_ID.fetch_add(1, Relaxed) 94 96 } 95 97 96 98 /// Provides a single place to write Binder return values via the ··· 213 215 214 216 struct DeliverCode { 215 217 code: u32, 216 - skip: AtomicBool, 218 + skip: Atomic<bool>, 217 219 } 218 220 219 221 kernel::list::impl_list_arc_safe! { ··· 224 226 fn new(code: u32) -> Self { 225 227 Self { 226 228 code, 227 - skip: AtomicBool::new(false), 229 + skip: Atomic::new(false), 228 230 } 229 231 } 230 232 ··· 233 235 /// This is used instead of removing it from the work list, since `LinkedList::remove` is 234 236 /// unsafe, whereas this method is not. 235 237 fn skip(&self) { 236 - self.skip.store(true, Ordering::Relaxed); 238 + self.skip.store(true, Relaxed); 237 239 } 238 240 } 239 241 ··· 243 245 _thread: &Thread, 244 246 writer: &mut BinderReturnWriter<'_>, 245 247 ) -> Result<bool> { 246 - if !self.skip.load(Ordering::Relaxed) { 248 + if !self.skip.load(Relaxed) { 247 249 writer.write_code(self.code)?; 248 250 } 249 251 Ok(true) ··· 257 259 258 260 fn debug_print(&self, m: &SeqFile, prefix: &str, _tprefix: &str) -> Result<()> { 259 261 seq_print!(m, "{}", prefix); 260 - if self.skip.load(Ordering::Relaxed) { 262 + if self.skip.load(Relaxed) { 261 263 seq_print!(m, "(skipped) "); 262 264 } 263 265 if self.code == defs::BR_TRANSACTION_COMPLETE {
+4 -4
drivers/android/binder/stats.rs
··· 5 5 //! Keep track of statistics for binder_logs. 6 6 7 7 use crate::defs::*; 8 - use core::sync::atomic::{AtomicU32, Ordering::Relaxed}; 8 + use kernel::sync::atomic::{ordering::Relaxed, Atomic}; 9 9 use kernel::{ioctl::_IOC_NR, seq_file::SeqFile, seq_print}; 10 10 11 11 const BC_COUNT: usize = _IOC_NR(BC_REPLY_SG) as usize + 1; ··· 14 14 pub(crate) static GLOBAL_STATS: BinderStats = BinderStats::new(); 15 15 16 16 pub(crate) struct BinderStats { 17 - bc: [AtomicU32; BC_COUNT], 18 - br: [AtomicU32; BR_COUNT], 17 + bc: [Atomic<u32>; BC_COUNT], 18 + br: [Atomic<u32>; BR_COUNT], 19 19 } 20 20 21 21 impl BinderStats { 22 22 pub(crate) const fn new() -> Self { 23 23 #[expect(clippy::declare_interior_mutable_const)] 24 - const ZERO: AtomicU32 = AtomicU32::new(0); 24 + const ZERO: Atomic<u32> = Atomic::new(0); 25 25 26 26 Self { 27 27 bc: [ZERO; BC_COUNT],
+11 -13
drivers/android/binder/thread.rs
··· 15 15 security, 16 16 seq_file::SeqFile, 17 17 seq_print, 18 + sync::atomic::{ordering::Relaxed, Atomic}, 18 19 sync::poll::{PollCondVar, PollTable}, 19 20 sync::{Arc, SpinLock}, 20 21 task::Task, ··· 35 34 BinderReturnWriter, DArc, DLArc, DTRWrap, DeliverCode, DeliverToRead, 36 35 }; 37 36 38 - use core::{ 39 - mem::size_of, 40 - sync::atomic::{AtomicU32, Ordering}, 41 - }; 37 + use core::mem::size_of; 42 38 43 39 /// Stores the layout of the scatter-gather entries. This is used during the `translate_objects` 44 40 /// call and is discarded when it returns. ··· 271 273 impl InnerThread { 272 274 fn new() -> Result<Self> { 273 275 fn next_err_id() -> u32 { 274 - static EE_ID: AtomicU32 = AtomicU32::new(0); 275 - EE_ID.fetch_add(1, Ordering::Relaxed) 276 + static EE_ID: Atomic<u32> = Atomic::new(0); 277 + EE_ID.fetch_add(1, Relaxed) 276 278 } 277 279 278 280 Ok(Self { ··· 1535 1537 1536 1538 #[pin_data] 1537 1539 struct ThreadError { 1538 - error_code: AtomicU32, 1540 + error_code: Atomic<u32>, 1539 1541 #[pin] 1540 1542 links_track: AtomicTracker, 1541 1543 } ··· 1543 1545 impl ThreadError { 1544 1546 fn try_new() -> Result<DArc<Self>> { 1545 1547 DTRWrap::arc_pin_init(pin_init!(Self { 1546 - error_code: AtomicU32::new(BR_OK), 1548 + error_code: Atomic::new(BR_OK), 1547 1549 links_track <- AtomicTracker::new(), 1548 1550 })) 1549 1551 .map(ListArc::into_arc) 1550 1552 } 1551 1553 1552 1554 fn set_error_code(&self, code: u32) { 1553 - self.error_code.store(code, Ordering::Relaxed); 1555 + self.error_code.store(code, Relaxed); 1554 1556 } 1555 1557 1556 1558 fn is_unused(&self) -> bool { 1557 - self.error_code.load(Ordering::Relaxed) == BR_OK 1559 + self.error_code.load(Relaxed) == BR_OK 1558 1560 } 1559 1561 } 1560 1562 ··· 1564 1566 _thread: &Thread, 1565 1567 writer: &mut BinderReturnWriter<'_>, 1566 1568 ) -> Result<bool> { 1567 - let code = self.error_code.load(Ordering::Relaxed); 1568 - self.error_code.store(BR_OK, Ordering::Relaxed); 1569 + let code = self.error_code.load(Relaxed); 1570 + self.error_code.store(BR_OK, Relaxed); 1569 1571 writer.write_code(code)?; 1570 1572 Ok(true) 1571 1573 } ··· 1581 1583 m, 1582 1584 "{}transaction error: {}\n", 1583 1585 prefix, 1584 - self.error_code.load(Ordering::Relaxed) 1586 + self.error_code.load(Relaxed) 1585 1587 ); 1586 1588 Ok(()) 1587 1589 }
+8 -8
drivers/android/binder/transaction.rs
··· 2 2 3 3 // Copyright (C) 2025 Google LLC. 4 4 5 - use core::sync::atomic::{AtomicBool, Ordering}; 6 5 use kernel::{ 7 6 prelude::*, 8 7 seq_file::SeqFile, 9 8 seq_print, 9 + sync::atomic::{ordering::Relaxed, Atomic}, 10 10 sync::{Arc, SpinLock}, 11 11 task::Kuid, 12 12 time::{Instant, Monotonic}, ··· 33 33 pub(crate) to: Arc<Process>, 34 34 #[pin] 35 35 allocation: SpinLock<Option<Allocation>>, 36 - is_outstanding: AtomicBool, 36 + is_outstanding: Atomic<bool>, 37 37 code: u32, 38 38 pub(crate) flags: u32, 39 39 data_size: usize, ··· 105 105 offsets_size: trd.offsets_size as _, 106 106 data_address, 107 107 allocation <- kernel::new_spinlock!(Some(alloc.success()), "Transaction::new"), 108 - is_outstanding: AtomicBool::new(false), 108 + is_outstanding: Atomic::new(false), 109 109 txn_security_ctx_off, 110 110 oneway_spam_detected, 111 111 start_time: Instant::now(), ··· 145 145 offsets_size: trd.offsets_size as _, 146 146 data_address: alloc.ptr, 147 147 allocation <- kernel::new_spinlock!(Some(alloc.success()), "Transaction::new"), 148 - is_outstanding: AtomicBool::new(false), 148 + is_outstanding: Atomic::new(false), 149 149 txn_security_ctx_off: None, 150 150 oneway_spam_detected, 151 151 start_time: Instant::now(), ··· 215 215 216 216 pub(crate) fn set_outstanding(&self, to_process: &mut ProcessInner) { 217 217 // No race because this method is only called once. 218 - if !self.is_outstanding.load(Ordering::Relaxed) { 219 - self.is_outstanding.store(true, Ordering::Relaxed); 218 + if !self.is_outstanding.load(Relaxed) { 219 + self.is_outstanding.store(true, Relaxed); 220 220 to_process.add_outstanding_txn(); 221 221 } 222 222 } ··· 227 227 // destructor, which is guaranteed to not race with any other operations on the 228 228 // transaction. It also cannot race with `set_outstanding`, since submission happens 229 229 // before delivery. 230 - if self.is_outstanding.load(Ordering::Relaxed) { 231 - self.is_outstanding.store(false, Ordering::Relaxed); 230 + if self.is_outstanding.load(Relaxed) { 231 + self.is_outstanding.store(false, Relaxed); 232 232 self.to.drop_outstanding_txn(); 233 233 } 234 234 }