From patchwork Thu Dec 19 21:08:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Levy X-Patchwork-Id: 13915781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C05F7E77184 for ; Thu, 19 Dec 2024 21:08:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 378556B0085; Thu, 19 Dec 2024 16:08:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 300856B0088; Thu, 19 Dec 2024 16:08:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DE7C6B008A; Thu, 19 Dec 2024 16:08:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DF9AF6B0085 for ; Thu, 19 Dec 2024 16:08:50 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 910B9C0329 for ; Thu, 19 Dec 2024 21:08:50 +0000 (UTC) X-FDA: 82912946676.27.1909C63 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf18.hostedemail.com (Postfix) with ESMTP id 5F3E91C000F for ; Thu, 19 Dec 2024 21:08:33 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LlCd2BlZ; spf=pass (imf18.hostedemail.com: domain of levymitchell0@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=levymitchell0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734642505; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=x9QXxVgtSe8H/UdvxZZA8sF6VvONdQXEw9VUMmlZNJA=; b=GuI70qZ2ODvPzHMjy84Nuhtt1/HEkqIavWhP/4eRWguUe9xd/M9XCW21Cy33IXwLV0XhbV 2S88cyfmrRGlb8T/AyxqtkLi3LYCOeaSGxR1fr4qpIR16NhXEf2vc0qDz3Af2yooCnwAAl snRcSsitW/Oidw0HQdCtzcKNo3IQXw0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LlCd2BlZ; spf=pass (imf18.hostedemail.com: domain of levymitchell0@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=levymitchell0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734642505; a=rsa-sha256; cv=none; b=akNu9UQJNjsEyaXrU9pol40BwkrR5/96uqjVWPivzst8Z6MavQEbu+gHKgOQe4vO2ajnk2 OaAfukwLDMpohs13HSXLNCuTB+EYy/nJRiAjRHodu/eThSeYpnlWxy1xNbPD7bjexXHkov c33lUQTcCpOyC8CGu29GcDScaeVA+vc= Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-216426b0865so11705115ad.0 for ; Thu, 19 Dec 2024 13:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734642527; x=1735247327; darn=kvack.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=x9QXxVgtSe8H/UdvxZZA8sF6VvONdQXEw9VUMmlZNJA=; b=LlCd2BlZm4Gt97GIYuHCTxCveobuikk5JAZEeeWNiyUMp6SRxdxGpJNk0dFH5dYQ7r +wuDjaBQ3SlkLNAgqClDwgE4MyrkOdRNYWNTf6A+n/kErQkmItk1vmOnlL802LdYgY1w 7oDmfrqrtYsByhqRH3zccuvtLNzFL8MnZYhOMwLKSDbPdxovLKtNKK9MfibnImPXJp9L GMPwKgZmVuXnXlSA/aRLvgj0Ey+BOS5IexDk5MUTlGpWPLPllceczPrrefksxJkBCIZi rEkqpJIJ3YcLnqaafsPWJKK0hXG4HFJ16gr4nPEadngLe7kXK7d9u/EtK7Mj5B0W47Ih oM/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734642527; x=1735247327; 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=x9QXxVgtSe8H/UdvxZZA8sF6VvONdQXEw9VUMmlZNJA=; b=QR0daR6ZHT5JXABrS0/qa89gHMo+JNzjmKBEjpvt40onn7MB8MowUVcmPO5m80gnf6 BdVpnDUbIgccj+Oa3ZHE+9/jOHuGXRxDVoKFRXF4EdL0mHpEil5g3QWfFEORgCPD9UnX 593hg5DVMAQHGXN12oOCXM2iCWjrsj5OUG4tyP7PoTq9yAyWFt7UUxZA974DgQwrlbwO DJO1OdvAXtyqFTaFEWScoETIEostf57K3sfoDBcSTQqE++ZpM60N1eCHnI0ZeoJwqTLQ G1PesUj0LE11puZbbdy1xyWj6kFOooGWj3ZoI981b7o+VqiFwVqITizK/g+JSa9t5TIW RJGA== X-Forwarded-Encrypted: i=1; AJvYcCUwp2R8PTgcghqshPVHahMfc6rJcyy1mxbCStIbAUE0tSPVorNINpkIBHfSWHuqPZoy9/lU5q1nIA==@kvack.org X-Gm-Message-State: AOJu0Yxhr5Y/ljAD/rME/hA50gDLHaudnF82b2JhDnINQW/KTE+hU1CB zBKMLtmqGGySFqmQ0MlcH+u9gp2Yl8Njop+mnsrC/9khPWdolVkR X-Gm-Gg: ASbGncv7S/cONLI2fL760+ylMjDW0sxiuyBiwidgNzeAtv89J/hjA03XnrluSWsAQgi oFp9ZfXlpPdsPL+z9Ks/tiZ59VUSoh9o7ZvZLOEGQKkqB1wcy3x4w09eswyYsuFHRfGpfBTP2M6 gpQOB/KWJQd4szIUw8hm/15Q1eqBYoJIFJ6In+UuyvHcICLv5pFcb/JKKjVhZHi/2jIUyz6bAoh QilXngbDyyZ2JQ1WgPuCLyTRPVJsHEIzX2pGUC4AW8LQ94th40T5AbGfNLhpZXYiQ== X-Google-Smtp-Source: AGHT+IGz0Q+3DpfXii21esDiAC06Fva51alHJG6cESFMtMV5fGT0zFttkPVJt7mH0xNMF9ojhQsEbA== X-Received: by 2002:a17:902:f607:b0:212:5786:7bbe with SMTP id d9443c01a7336-219e6ea1baamr2967705ad.24.1734642527196; Thu, 19 Dec 2024 13:08:47 -0800 (PST) Received: from mitchelllevy. ([174.127.224.194]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc962cc3sm16831755ad.28.2024.12.19.13.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 13:08:46 -0800 (PST) From: Mitchell Levy Date: Thu, 19 Dec 2024 13:08:26 -0800 Subject: [PATCH RFC 1/3] rust: percpu: introduce a rust API for per-CPU variables MIME-Version: 1.0 Message-Id: <20241219-rust-percpu-v1-1-209117e822b1@gmail.com> References: <20241219-rust-percpu-v1-0-209117e822b1@gmail.com> In-Reply-To: <20241219-rust-percpu-v1-0-209117e822b1@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 , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Mitchell Levy X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734642524; l=9725; i=levymitchell0@gmail.com; s=20240719; h=from:subject:message-id; bh=/ikI70Vx9VTFvUYOPIJla9o/5OEbZwWpK+cUvQgY7gU=; b=xAlZKloO7jsOKjUts/I2F2rmsZdyqA6z5zN+M95gp6DPAS4r3zekMmTKtwUJ4JUDfydbIxXyf 1eSJ1IX89SzAF7KNMdQ14WNrPwGjDOzG/6mUKhoDSddY6GeZ337Ivqm X-Developer-Key: i=levymitchell0@gmail.com; a=ed25519; pk=n6kBmUnb+UNmjVkTnDwrLwTJAEKUfs2e8E+MFPZI93E= X-Rspamd-Server: rspam05 X-Stat-Signature: c1qzbt7aeuiyesqxnypk9pj18cf5ra9c X-Rspamd-Queue-Id: 5F3E91C000F X-Rspam-User: X-HE-Tag: 1734642513-149513 X-HE-Meta: U2FsdGVkX1/S6on+iI9JCB4a9S8fKu5hL2xAiZYp2XuzB56J6UlqA6UaIKJTXFfaPEWe9WKOZcfytTGZRRRO4NQfvgInXn3tDpF7X6Ees/4sHgjwvARxOrFhf4+JxYq0mi9M7/yWdoK7AqWZOXP3Qwb+Ts1+K7BpOWz7vitb2CNrbe/RuuE09l6KyMErctkrQKXK48h9r1PG3hIyn1Oze/+GmQgeKXTGFkIJ06/Q6kWT6PO/tXQMYcpjEGQHYD5Do1gsvS2x4NLUbp5sjiifVReOe8HUaYuk15FyY1RHSEjtSh6oTJ3SSsEOneYs/pCyGuOSH897dVsIZc0yUBxH9SKw7M4h8oRUZ4yZlNTuVj0DPlC9bP43J9vU3NTISsrUn/sf9thBtXeCj1X8eIC5NMonGPO5lCcPUSWMjNlcalm9bahHaQezMknfR715DIwkwUOulCiYl5LZRYlDSJtK/WZSZUKxL6nm3eznWRzV20D7gstvnCfXtuVPqlMbOoa8bMZwLnFETGrrWi3eJbWQT9NFTIrVfBf02HGQMj7CzdG33Yf4mnoW9hhnSNGmMJ3r+UthNIERa1h3LQgT2vJTTplYPV425KlvQAggqT0JNf5yrjUyoLolZFFrWGXgh5MXhvTrY/osyubMAGxaizG2Hr5jSntU1W7Cm3oulcJcwGatMFHhjYodVCGveH8aBZdhvFCy78T8sOcWnUOUjUzFYX2Q+sqm1savXnQk8JBinzcIje960IknjsmXYVOJuMr/3EcmIiS5SWKdZUbN5ppw6FLpqZG6vIxtJq0clTJDeY6PZ8BoSvt/MypxE7Df13+qJJ4PTAnuHjQwtPzKJ2ys4s3V2Tn4R8JHZeD8+hfFY5LCbarugsnGdhfq7m6jAkz51lOYHL6sNeGCHFWnBA5DZMBa+x+ZVuMjd1zbenNG6vo2vYKMvDGcBv+nZMf1vMXMFgjOT5J3Kvak1coTXna 6q+n97NC oe6iBrwcufI3yqYAg7x9Lhqt9NMdGUHmXkI7JhLsK97NpjHigm5obCdBMie4BNM70OML+A9cFymU1CgZvzeJuDUE8ey8ErKen287RfGzDhUKvOGT0PdVGNdqptYUScUUfBEjFY19HTZ8D+X7CqMzAFFm5q0pZ8iwDErVCKnV0wl5BCPdBnIeVvVVwJsECkMaqWFcBuSX7ADpE6Kwf3tJo4w/0zr48hswdTdGPCkgNEmdFygC/ehSI0sV0eBOOcoW2An0yESWWXMib3q5HvnJyHaOuwbtQCnoRdJzgR4FUi2TXG6qmZ/aFVoMfXMFC1GpvogdS+fTPvwDE9l3SDpvPipLw3SVWe4er2j0VHTFsX8oPPrPF8hbTfadTwEFpQov0lL2qgabuEkwwycXLz+magY5svUyATS6I2DSlyA9r3DFwjMdZLjoTFV6oWOc1VZxlgNHQ1qjNHLWPFoE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.419677, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a CpuGuard type that disables preemption for its lifetime. Add a PerCpuVariable type used for declaring per-CPU variables and a declare_per_cpu! macro for its use. Add a PerCpuRef that allows actual use of the per-CPU variable and an usafe_get_per_cpu_ref! helper macro to convert PerCpuVariable to PerCpuRef. Signed-off-by: Mitchell Levy --- rust/helpers/helpers.c | 1 + rust/helpers/preempt.c | 14 ++++ rust/kernel/lib.rs | 3 + rust/kernel/percpu.rs | 161 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/percpu/cpu_guard.rs | 29 ++++++++ 5 files changed, 208 insertions(+) diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index dcf827a61b52..1db0dcd8f11f 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -19,6 +19,7 @@ #include "mutex.c" #include "page.c" #include "pid_namespace.c" +#include "preempt.c" #include "rbtree.c" #include "refcount.c" #include "security.c" diff --git a/rust/helpers/preempt.c b/rust/helpers/preempt.c new file mode 100644 index 000000000000..2c7529528ddd --- /dev/null +++ b/rust/helpers/preempt.c @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +void rust_helper_preempt_disable(void) +{ + preempt_disable(); +} + +void rust_helper_preempt_enable(void) +{ + preempt_enable(); +} + diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index e1065a7551a3..3634e1412d60 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -49,6 +49,9 @@ #[cfg(CONFIG_NET)] pub mod net; pub mod page; +// Only x86_64 is supported by percpu for now +#[cfg(CONFIG_X86_64)] +pub mod percpu; pub mod pid_namespace; pub mod prelude; pub mod print; diff --git a/rust/kernel/percpu.rs b/rust/kernel/percpu.rs new file mode 100644 index 000000000000..08fcc8797078 --- /dev/null +++ b/rust/kernel/percpu.rs @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-2.0 +//! This module contains abstractions for creating and using per-CPU variables from Rust. In +//! particular, see the define_per_cpu! and unsafe_get_per_cpu_ref! macros. +pub mod cpu_guard; + +use crate::percpu::cpu_guard::CpuGuard; +use crate::unsafe_get_per_cpu_ref; + +use core::arch::asm; +use core::marker::PhantomData; +use core::ops::{Deref, DerefMut}; + +/// A PerCpuRef is obtained by the unsafe_get_per_cpu_ref! macro used on a PerCpuVariable defined +/// via the define_per_cpu! macro. +/// +/// This type will transparently deref(mut) into a &(mut) T referencing this CPU's instance of the +/// underlying variable. +pub struct PerCpuRef { + offset: usize, + deref_type: PhantomData, + _guard: CpuGuard, +} + +/// A wrapper used for declaring static per-cpu variables. These symbols are "virtual" in that the +/// linker uses them to generate offsets into each cpu's per-cpu area, but shouldn't be read +/// from/written to directly. The fact that the statics are immutable prevents them being written +/// to (generally), this struct having _val be non-public prevents reading from them. +/// +/// The end-user of the per-CPU API should make use of the define_per_cpu! macro instead of +/// declaring variables of this type directly. +#[repr(transparent)] +pub struct PerCpuVariable { + _val: T, // generate a correctly sized type +} + +impl PerCpuRef { + /// You should be using the unsafe_get_per_cpu! macro instead + /// + /// # Safety + /// offset must be a valid offset into the per cpu area + pub unsafe fn new(offset: usize, guard: CpuGuard) -> Self { + PerCpuRef { + offset, + deref_type: PhantomData, + _guard: guard, + } + } + + /// Computes this_cpu_ptr as a usize, ignoring issues of ownership and borrowing + fn this_cpu_ptr_usize(&self) -> usize { + // SAFETY: this_cpu_off is read only as soon as the per-CPU subsystem is initialized + let off: PerCpuRef = unsafe { unsafe_get_per_cpu_ref!(this_cpu_off, CpuGuard::new()) }; + let mut this_cpu_area: usize; + // SAFETY: gs + off_val is guaranteed to be a valid pointer by the per-CPU subsystem and + // the invariants guaranteed by PerCpuRef (i.e., off.offset is valid) + unsafe { + asm!( + // For some reason, the asm! parser doesn't like + // mov {out}, [gs:{off_val}] + // so we use the less intuitive prefix version instead + "gs mov {out}, [{off_val}]", + off_val = in(reg) off.offset, + out = out(reg) this_cpu_area, + ) + }; + this_cpu_area + self.offset + } + + /// Returns a pointer to self's associated per-CPU variable. Logically equivalent to C's + /// this_cpu_ptr + pub fn this_cpu_ptr(&self) -> *const T { + self.this_cpu_ptr_usize() as *const T + } + + /// Returns a mut pointer to self's associated per-CPU variable. Logically equivalent to C's + /// this_cpu_ptr + pub fn this_cpu_ptr_mut(&mut self) -> *mut T { + self.this_cpu_ptr_usize() as *mut T + } +} + +impl Deref for PerCpuRef { + type Target = T; + fn deref(&self) -> &Self::Target { + // SAFETY: By the contract of unsafe_get_per_cpu_ref!, we know that self is the only + // PerCpuRef associated with the underlying per-CPU variable and that the underlying + // variable is not mutated outside of rust. + unsafe { &*(self.this_cpu_ptr()) } + } +} + +impl DerefMut for PerCpuRef { + fn deref_mut(&mut self) -> &mut Self::Target { + // SAFETY: By the contract of unsafe_get_per_cpu_ref!, we know that self is the only + // PerCpuRef associated with the underlying per-CPU variable and that the underlying + // variable is not mutated outside of rust. + unsafe { &mut *(self.this_cpu_ptr_mut()) } + } +} + +/// define_per_cpu! is analogous to the C DEFINE_PER_CPU macro in that it lets you create a +/// statically allocated per-CPU variable. +/// +/// # Example +/// ``` +/// use kernel::define_per_cpu; +/// use kernel::percpu::PerCpuVariable; +/// +/// define_per_cpu!(pub MY_PERCPU: u64 = 0); +/// ``` +#[macro_export] +macro_rules! define_per_cpu { + ($vis:vis $id:ident: $ty:ty = $expr:expr) => { + $crate::macros::paste! { + // Expand $expr outside of the unsafe block to avoid silently allowing unsafe code to be + // used without a user-facing unsafe block + static [<__init_ $id>]: $ty = $expr; + + // SAFETY: PerCpuVariable is #[repr(transparent)], so we can freely convert from T + #[link_section = ".data..percpu"] + $vis static $id: PerCpuVariable<$ty> = unsafe { + core::mem::transmute::<$ty, PerCpuVariable<$ty>>([<__init_ $id>]) + }; + } + }; +} + +/// Goes from a PerCpuVariable to a usable PerCpuRef. $id is the identifier of the PerCpuVariable +/// and $guard is an expression that evaluates to a CpuGuard. +/// +/// # Safety +/// Don't create two PerCpuRef that point at the same per-cpu variable, as this would allow you to +/// accidentally break aliasing rules. Unless T is Sync, the returned PerCpuRef should not be used +/// from interrupt contexts. +/// +/// If $id is `extern "C"` (i.e., declared via declare_extern_per_cpu!) then the underlying per-CPU +/// variable must not be written from C code while a PerCpuRef exists in Rust. That is, the +/// underlying per-CPU variable must not be written in any IRQ context (unless the user ensures +/// IRQs are disabled) and no FFI calls can be made to C functions that may write the per-CPU +/// variable. The underlying PerCpuVariable created via declare_extern_per_cpu must also have the +/// correct type. +#[macro_export] +macro_rules! unsafe_get_per_cpu_ref { + ($id:ident, $guard:expr) => {{ + let off = core::ptr::addr_of!($id); + PerCpuRef::new(off as usize, $guard) + }}; +} + +/// Declares a PerCpuVariable corresponding to a per-CPU variable defined in C. Be sure to read the +/// safety requirements of unsafe_get_per_cpu_ref!. +#[macro_export] +macro_rules! declare_extern_per_cpu { + ($id:ident: $ty:ty) => { + extern "C" { + static $id: PerCpuVariable<$ty>; + } + }; +} + +declare_extern_per_cpu!(this_cpu_off: u64); diff --git a/rust/kernel/percpu/cpu_guard.rs b/rust/kernel/percpu/cpu_guard.rs new file mode 100644 index 000000000000..6f7d320a5c9a --- /dev/null +++ b/rust/kernel/percpu/cpu_guard.rs @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +//! Contains abstractions for disabling CPU preemption. See CpuGuard. + +/// A RAII guard for bindings::preempt_disable and bindings::preempt_enable. Guarantees preemption +/// is disabled for as long as this object exists. +pub struct CpuGuard { + // Don't make one without using new() + _phantom: (), +} + +impl CpuGuard { + /// Create a new CpuGuard. Disables preemption for its lifetime. + pub fn new() -> Self { + // SAFETY: There are no preconditions required to call preempt_disable + unsafe { + bindings::preempt_disable(); + } + CpuGuard { _phantom: () } + } +} + +impl Drop for CpuGuard { + fn drop(&mut self) { + // SAFETY: There are no preconditions required to call preempt_enable + unsafe { + bindings::preempt_enable(); + } + } +} From patchwork Thu Dec 19 21:08:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Levy X-Patchwork-Id: 13915782 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95D4FE7718A for ; Thu, 19 Dec 2024 21:08:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B5206B0088; Thu, 19 Dec 2024 16:08:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 241336B008A; Thu, 19 Dec 2024 16:08:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 043DB6B008C; Thu, 19 Dec 2024 16:08:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CAA3D6B0088 for ; Thu, 19 Dec 2024 16:08:51 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 83AB443155 for ; Thu, 19 Dec 2024 21:08:51 +0000 (UTC) X-FDA: 82912947684.28.16C9250 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf15.hostedemail.com (Postfix) with ESMTP id CFB57A000B for ; Thu, 19 Dec 2024 21:07:58 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VM782LVx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of levymitchell0@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=levymitchell0@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734642513; a=rsa-sha256; cv=none; b=0WP5JZDsMQSx3P1F+XKSZODj69RcpiTMwHT3ZA6rtqmig2TFYCLxhgzDAvvX6jXKDuT8xM e3lkrxxgB2/MkII4D3lRWxJwkzujyqL2i3iUCAu/iqbxP9C+3gVhwH/Iv1gk7XqBhuHnHR FZ22iaxkBVycNQZBov8PSN915MPLkIo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VM782LVx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of levymitchell0@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=levymitchell0@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734642513; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SeeL6HPCkGqR+iss0d46HW94C36VOktwSeHKqW1zTWU=; b=7l1mW1/RpgBP4LmF5NFol7sQo3WIxQuiZ+/w9q0IbwTs+1ADjfy2qUY+z9PsQaVoQ4EEgD PU80RTXy1J/6mBnrM08KxPkp1teTb+NBo3mrnadQYrpL30Q4C1XLwspllqCbHYrU0fku0l 1AB0+lwO9YxiOdfcdrhADa0WWuj6QKs= Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-21669fd5c7cso12013415ad.3 for ; Thu, 19 Dec 2024 13:08:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734642528; x=1735247328; darn=kvack.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=SeeL6HPCkGqR+iss0d46HW94C36VOktwSeHKqW1zTWU=; b=VM782LVxx/4axVTdCXse/Vu7dcf1zHtwgo9IMoecal4VT7mqsrHKoRMhbl8587Hdyb jRemeqOf5K+K5r+5rM9GQo7SVAdWvM3ycqW1pgLs37KryQLMA0o6sgbWZISGdeXc+6f2 TNx/Lrbd4MqZKnlIsdbgxI24ZEG12+nTs2naQVGTR+CoALWOF75zo17AZi1KUdhOGDWU d6OWNa9NWmMJOAWhhrZkBKhPhJnbxbzijxl4STyjPImbwY0c2AAgnp/LCInfb9Q7O1UD IcFjUvJSIfWOsZ89dMtBTNL7tjmLO+sQRwWTrQ21E6KyNQ0Jvz1aomdmv163PCj+/3HG 2GbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734642528; x=1735247328; 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=SeeL6HPCkGqR+iss0d46HW94C36VOktwSeHKqW1zTWU=; b=DrZzjrqFft0WmHdnbQ6OWLnLnjfhyAXXb8NIgdspdsQ+30ca2kC/xAG0xDcQ/EKk8D gp+DV6LWHN9gvikvUVlmtDHTG5mafCEhHu/3qMWjgKvTpHA7qceP4ZcRwLaWxCdy4B89 bDyLRG1/2cS/a+PpFuaN2/gVPU49DxSmoHIYGU+UanYHJbbHPCK6y0Q4ixOwgxxKJpu5 rUi0hJWpoOyVqbxAxQ0E5Mfo+SfmRX5S+Gn227uRca70girorEJgW83Gg3Sy7m3zQw3f NGw4LnO1fuKC8tJ+03b4dsr44dOzYGIS553FnARg/qjY4Cq+3WMICGoSvsraVErZcD7t 5DpQ== X-Forwarded-Encrypted: i=1; AJvYcCVla2wpTcYr+PKflOycASy/pc7oxttj67mEAh1i/oNCuXtNd05V/QDLnQnwmovu+my0VwJifjMmhg==@kvack.org X-Gm-Message-State: AOJu0Yx6JvVaSOXNrUi0xicUS5ytNdNPQGsfQy/Y+Knk72nLuz+Zl0o2 IgZpDW6uf5vyu0eSr95tMEBv9KZ6S05jW5cG64qxy+txZ5gmmYwr X-Gm-Gg: ASbGncsd0QJUoDw7edCCrZXtn5GGinDY+OJj9IM66cO4Y8OhpRKSOoZYzhsTrY1eP1l eqd9WuFgbgGBniDAZkmzbQrwGA7fv5sAzBM+hYDwf7RqbKln1fm0wpFpEuMUALuxagqvL4LQcC2 pakf53PmdVaF1t6yBwigYN0OdlhQGrzHhq5OjwIqo32i9Zad6ymPCcrFfOos2CLoJy9GOa87wQS EPMXYkw6rO1Dj/ZL1SHMKC7TooNGfgVYW3ozgy+b5hZMe5FU9qofb62hlfTRza2Wg== X-Google-Smtp-Source: AGHT+IF/1tM3WCgqS4vfhViKK0R9nsVTEMtAfdNwyZiWjLZy3SwsOJSvD1LICQhf2BHaA/XvshYH/Q== X-Received: by 2002:a17:902:ebc6:b0:216:1cf8:8b8 with SMTP id d9443c01a7336-219e6ebe15emr3313535ad.27.1734642528276; Thu, 19 Dec 2024 13:08:48 -0800 (PST) Received: from mitchelllevy. ([174.127.224.194]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc962cc3sm16831755ad.28.2024.12.19.13.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 13:08:47 -0800 (PST) From: Mitchell Levy Date: Thu, 19 Dec 2024 13:08:27 -0800 Subject: [PATCH RFC 2/3] rust: rust-analyzer: add lib to dirs searched for crates MIME-Version: 1.0 Message-Id: <20241219-rust-percpu-v1-2-209117e822b1@gmail.com> References: <20241219-rust-percpu-v1-0-209117e822b1@gmail.com> In-Reply-To: <20241219-rust-percpu-v1-0-209117e822b1@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 , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Mitchell Levy X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734642524; l=916; i=levymitchell0@gmail.com; s=20240719; h=from:subject:message-id; bh=lY27LEhr/RrYnOIR8z3fQ4J3MpeoCX1CqLVxrfhFCU8=; b=mwtTmJIpnuguPatbGcieMpjbUb5v3yLgy1KPUvNYJhpLHNbxO1HwQtsnaFhqxc/yuAMoKljZH own5+keq+syBDNH0fM3Z66LWAo5xjtxa2gnmh6vJFnKBtyFvvi40Xs9 X-Developer-Key: i=levymitchell0@gmail.com; a=ed25519; pk=n6kBmUnb+UNmjVkTnDwrLwTJAEKUfs2e8E+MFPZI93E= X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: CFB57A000B X-Stat-Signature: kbsriqjwroz84xw4h317iza37kos8xai X-HE-Tag: 1734642478-210238 X-HE-Meta: U2FsdGVkX1802X6d6gib1Uni6urZ5btXJMhTUUt3vDMer4wo11tmQ3texAq4gpEVdPB/OPtTn9xvQpY7THJbvVUJjqbjTihwbwfXgR4Kf5dQUAYvHF+09KqK/4XKDWG8quHsZQspousPlk77zAtHVqEeaHP3iVJ0SjyQFDvCs6nnMyVe7E4dANzw1mUlrGqR7cUjnuhyCtY68tQ8Pe/2XcbJnBGJHWX9izSi2l2E3joK+dHcItMP4zEj7clnDGVoxn9CuecW1zXLtFEyrOG1oXONP8IbBxFZPiU2LnV95hOmoMTREjDZ6VnNCcvWj97/4DhxvwW7fyAbMipgdVheDoRCV/Uoeh1KfuEC71rpudujiImKBL3YX+IsPa/pE7JgsGt8+NPBgRef6Aul0gsMAg/wYUSbNPNHIaIlRFlXGbftILeQjo63bgpW6EDPmxoG6KL11VnPwQG9WmmXZ0rPnsffta3b5TqsAKRgX7OeCg3pPGHBVaIl+8P8OA8gpHf/3MCMXTWHgwRJ0r7lf2GMNOPRkUcraILpZwXEgmJEFcb5Aj+50YCR34PT1utW+z3Kwe/JhUCmGcAIgfI9lmXZVAdd+PUslnAnkaGQ3oZkhFqcACANJm3DGwBRp2FINjn5BZQatKjUrbo/G5iNT09QL3UtWRzvfQetw2bIA4fWZHGM9fnoCbu5wIlG8AXwlh0RaP+YrnzI4Y5HlpqDiXLi3KGq4ddQfMcaniMgGhqz1kuNjgiQmCCH9mXAfZ4QBmua3gqDIbzlQNmRmb6k9do/STqZZtjE74ipjeIhrgWz8Knm1eSmS+X/QaesExsSMq5VXgM16pF8bccCoM3arBqqzhpaENHANxUpKM7Z492m8bY2RMdEOv/a4Nnqf+JenidVykfiFSZvWkmWkXCCe/VGNBaRiuW9CltPoV8RtKFN5jxZ0iYRg64fEAxBH8yPFKuRiyv26CYrGI+yNrJg7Ph kVkg2NvS xDPnTrI90dGGuZYyhBPLdchzkAIy2vp06k3iF7vmnN2MdC1PE9TXg36TI1dzFU+TxRbXgbhQHi2rDxw5vN/tpX9Z5zwD0KIz/iVVjqwUHteQMM89jEPgDwL3RKGCB8UgUKsG8diP3TvV6MYRKQgKtjAiS77lcqqQMO9GlZBcQQlbdMUb2vq67vhgpMhzLXGXN5RgtHM9hw1NhVknuecDhGhdDfI9+vQkc3fEN9osqBsU3yd4dqQ7Fqa5pcPHorwawEphe5Ga4w7mFpPI/oeMR7UuQfxbdCRvNrxxy5yF/5U5QfO4MwdHwZRdw3uffpn+ep4A1kouDKeIt5HYKGiX+IlkdrTEp/FmmQITnJYDWBsQ8TIcY8l0D/EY7UhoJRoE3z0A243eewE/phLpM//3omaXmlJ3Kxdk3s0BIjM0fD6vF68chA8SAiMtA9YkuG5eeBBwrkrFNrHSLJm0= X-Bogosity: Unsure, tests=bogofilter, spamicity=0.500000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When generating rust-project.json, also include crates in lib/ Signed-off-by: Mitchell Levy --- scripts/generate_rust_analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py index 09e1d166d8d2..7d7ffb45fc0c 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -109,7 +109,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): # Then, the rest outside of `rust/`. # # We explicitly mention the top-level folders we want to cover. - extra_dirs = map(lambda dir: srctree / dir, ("samples", "drivers")) + extra_dirs = map(lambda dir: srctree / dir, ("samples", "drivers", "lib")) if external_src is not None: extra_dirs = [external_src] for folder in extra_dirs: From patchwork Thu Dec 19 21:08:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Levy X-Patchwork-Id: 13915783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 050C5E7718B for ; Thu, 19 Dec 2024 21:08:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E267C6B008C; Thu, 19 Dec 2024 16:08:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DAF766B0092; Thu, 19 Dec 2024 16:08:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A561D6B0093; Thu, 19 Dec 2024 16:08:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7F6816B008C for ; Thu, 19 Dec 2024 16:08:53 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0396E431B9 for ; Thu, 19 Dec 2024 21:08:53 +0000 (UTC) X-FDA: 82912947726.28.79456FC Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf02.hostedemail.com (Postfix) with ESMTP id 006178000E for ; Thu, 19 Dec 2024 21:07:46 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nExRnxk5; spf=pass (imf02.hostedemail.com: domain of levymitchell0@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=levymitchell0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734642493; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8a+U3PThiCkoSQIjCSeZhobcfZFrIgDLb2tUjSaHx4Y=; b=VqmCQYRQHPQzQgpQAlVkP2J4EgUS7/OvrMxsL1BvYPsWx8J8gokX4jvsQO7BN6XBqeKP8l u6ZprElNQxR5+Ortgif2KqcM/TKuFZdUpaaDn7JGCjukfo4VOkdR4BEmtHAsMTM5bclI1D 8n4fQ+iGxsUdN+kQ0Y4K3QCuDbpisKI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734642493; a=rsa-sha256; cv=none; b=HgQopojiXGxFHUivHzY5HAcepQinpQpA3uiOxJ6iKjuRw9wAPIxUJSoJGEYFpF+S80pOl1 jrc7Y7OI6BfHO1YHO/8SeRzZbbdEEo7b107qOjN9Kk0A/C6QGX6VAzN9exSJZcgcDDVir0 1KLNsAL/He7bTsEB0uo+L4wx4YxACTs= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nExRnxk5; spf=pass (imf02.hostedemail.com: domain of levymitchell0@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=levymitchell0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2165cb60719so12343455ad.0 for ; Thu, 19 Dec 2024 13:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734642530; x=1735247330; darn=kvack.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=8a+U3PThiCkoSQIjCSeZhobcfZFrIgDLb2tUjSaHx4Y=; b=nExRnxk5mZAo+mIU+npPuFApy430I3lMIudJtoCXU7M4D2jUMyq+of/y1/QDxqgWpU HlchMKznmCjLSqrVQZ0Q++65ORXwHZqcWO5DOjg5VSZ8ZKwpKI3buba2wY8Ua3jNSroo PKwx8aGVqqG7TUEkF/+MNmOiUgtMNr6Ke4w8kjJtuOQ0EdUKtBLtCyMJbUTDCCgblGmo qFs+HSoUPO7xBVVNjUt6tHxTPVd3ln9EOPpjvdNAv+q+bx2mr28jjeSqkLIjEcdXkEcR 1NTGynZkoTCmfifHN5WGUqatg306DbZ7tht3j7rB3b1xCW9A9ozUISEawiwNYUfRpgAS SH5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734642530; x=1735247330; 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=8a+U3PThiCkoSQIjCSeZhobcfZFrIgDLb2tUjSaHx4Y=; b=UbKbPJDU+oVb6WE5awJ/GokRK5iTP5MUnBPH8gQXE+XvWBZZM2UNVZs9H4G+dDjgNG /3sXzEDWUnS/eMXmqzz+kqrMBoy/Pj6NTPM1FHiD5LytqBkrTMwNTDPdDJ4P/74XhDjE 5d5WwJQ85MinuKYIqtO2iqMFtLQEDb++vaql/LsGqmnhrlEFAUuY2Et3LlkOyTR1Zyrs oPhxqGuQ1fXYnF/riHqTl8sRwErlHm3d47PMvVO29IAnJOVzH4j5TkzMGodrqY0MbR7a aD9oLKss/Ghp6AiI1QwfqI9zUDZicK5fc6ba3PQXmYMnbZplxbE4Kp87W87srqI0r/AZ zh/w== X-Forwarded-Encrypted: i=1; AJvYcCXq38lz3/81Vb+z/qFhq2ZFaaRfm/ksQOlOw0IXJeeAVLwMz1rB8YFcgrwBgGopHY6KBURWpfpfGw==@kvack.org X-Gm-Message-State: AOJu0Yw24j7/0/AS/GKN7jXUh+tLKI+b3oJFwG0a9Pt9BwwLvdK1rFJT CMUSvwr9ZKG6DsD/z1vkSUDES4ft2JOjVJCT4EyD/x3Igr8AbmFi X-Gm-Gg: ASbGncsoPRpe3ZZecF5J5u7AuHEoHjfGYbWuLRi9k1DcXYrOE02XZa97EM+KO9W1O0K MOeUonRVrjnnpzCFoNv4AtFRerAwwVcqaiKwwv7rlcotX787a5KxLsQtF11kiKf56pDhbVvbxfj Ot+Kp8gqMCzv7spPAt3WYc39mfLGDIhTtizeGmtOLwYDuzZ1Ilb9jLL9UPWVz+63PUDYB1RwkYv iLPAtaOFuFd5quxgwRaUK14yt5e/TQzDnNeQaT8+cbO3eGDUQW2TPbm86PK3mQ06w== X-Google-Smtp-Source: AGHT+IFlNR+5xs9cq8NpBSRrS++zF1DZpmnXPo5bkWp0elc/Vz4dUHAxNDYhcGSHRx+In+/jxMSo4Q== X-Received: by 2002:a17:902:e5c7:b0:215:19ae:77bf with SMTP id d9443c01a7336-219e6e9df25mr3132215ad.19.1734642529695; Thu, 19 Dec 2024 13:08:49 -0800 (PST) Received: from mitchelllevy. ([174.127.224.194]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc962cc3sm16831755ad.28.2024.12.19.13.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 13:08:49 -0800 (PST) From: Mitchell Levy Date: Thu, 19 Dec 2024 13:08:28 -0800 Subject: [PATCH RFC 3/3] rust: percpu: add a rust per-CPU variable test MIME-Version: 1.0 Message-Id: <20241219-rust-percpu-v1-3-209117e822b1@gmail.com> References: <20241219-rust-percpu-v1-0-209117e822b1@gmail.com> In-Reply-To: <20241219-rust-percpu-v1-0-209117e822b1@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 , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Mitchell Levy X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734642524; l=3571; i=levymitchell0@gmail.com; s=20240719; h=from:subject:message-id; bh=Fg46h50fzfyqtIe9aDLmvc/Zzgw12ckY/xFnT5ZEMe0=; b=gRK8pwjQ4BF4Qdvi0zi3CaQNn7uKJ8Q0n/gQMpX5Cf5J3e0PE0ANTZflDXvPIbayToRUWQhb6 +IFU6CcSailB8h8pm97y0hJlg8MH3QTdhZycACwBxubTmMZBxvl+/zV X-Developer-Key: i=levymitchell0@gmail.com; a=ed25519; pk=n6kBmUnb+UNmjVkTnDwrLwTJAEKUfs2e8E+MFPZI93E= X-Rspamd-Queue-Id: 006178000E X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 8rdbqawxici4pw7oxp5nsj98aobbzf64 X-HE-Tag: 1734642466-310925 X-HE-Meta: U2FsdGVkX19rAXVWsBfczeYUBIfRO9ap+RllLDOvKz8wBA0N94jdAruxdsHScDUwpSOqYwBZDm0v672bmjHYk7Hu+xh8W1Bsw9GoNUNzkRH+jhOQuTrezepojjL119YZh3YmFBH7ll+npqguBSIJyxtzxUbnUjJGFi04S2sTJRT28jZDUV4MAopp/0K6UC1Lk+pQbDeU0QBwOoimz29KVWiA9V0II22XpBnsp5c9Tzntrty+QwZ/M10yvWiMnNiV5nxHgY4lHJuMLPq1LWssvAAs+PtsqeuIp2iuA29Y4/itqkaWYJtW9dnI7PM8M7dDE4kJHFZBWlAeKcdo3CCn4m6Vfbllrt/kC6xIbrnF3G3PlQ2TXAsZrTj8a5oRbBuBm3JAQTdP0fZXWZrXmlGVivz5GeyA/SnQgLVT9v5sz6he2prgGcjj0ns9iiHOag1DI5oNQOoiMXXACAvJ+RrcwwcYOai1EVtI3MHCZbeogcaIrlPq5l350B9kIe98yvLCPjqsnoYHQCDUj7YB6qy88sBOYOhU/QFtRFHI7sFQ0mFxxstOUVdIcy3enQ5PrB4DMdE4b1TZfhhDT4NBfJMVYBkkXeEVhO+okk6UbBcqflDIYVAn5Q/vf/fyayn2wyTSfxkyMHeTFY5p4ywAAjXlTTRpFkNN08bJwwS0KYv8hCGCj5XSqIxRVTnxegMlkzUhUsUmui9P4W76qNGujyX8ifTdXbBgr1wL75nSXvs3dyGxeqxRBOm50jVhSzwblZErU8OnJB3bSovHOeFiLD2gwFo3+XeA9+HO1DKZ6RkmBklqB6/DFQhaMAi3l+kYX4PqeZT/lg1/UUrfQ/pyPJMkBJqvioQJQjoYIryDWS17u4D7zuhoISRtYfGVSariwqThvuBDO4dB4Zlq1gVJq7Lf0E4EiH8ERVOSMCHxjfuWv5/or/OttnNdsajI+tgx3J3G2JFakBhQ2gF8Zvs0kRA PuD7iU49 yKNK0oweL1FDoWYGK7W2r3f8N2Yx/5DTc+GWKLxcx3X1bTN+CwRPjoSgu9DMW/CyPPCpjL3VKF0POW10P27t9Usyvnt0Htw5h9WmY7ro6u3lmnTyDZ+XWatKzVotN1mNlCfn6y/CLjnWkoftY4YIPusJPAXoqLR52piqE0QyBwtXvEA+D5GhYpPYY/dI1lo4nH+kewiTJZQ1BZsWH29blymOhrOuNu0Q4E2Aqige9cmRiMUmHF+OuknRUMweHti8JE0458EvKm6BLBHuDS6Aol77tskUOMv+C5j74Z8vamFphg1eYEbc479BdcqDwcUZM/v7oh+JbxYlC5hy/ehSvmNwQbwrYQBpUj01BVqDDLDcO+EoJZZjPSVXe8SY71HjCmtEeOe4Cb8tJMcQNSVh897m+Tgakkcmmzod0ItlR2Dm9LTCLb8tPrBoE+73Rf8T9oa4QFc8QSsHsO5U= X-Bogosity: Unsure, tests=bogofilter, spamicity=0.499991, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a short exercise for Rust's per-CPU variable API, modelled after lib/percpu_test.c Signed-off-by: Mitchell Levy --- lib/Kconfig.debug | 9 +++++++ lib/Makefile | 1 + lib/percpu_test_rust.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index f3d723705879..75a91f1766ce 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2404,6 +2404,15 @@ config PERCPU_TEST If unsure, say N. +config PERCPU_TEST_RUST + tristate "Rust per cpu operations test" + depends on m && DEBUG_KERNEL && RUST + help + Enable this option to build a test module which validates Rust per-cpu + operations. + + If unsure, say N. + config ATOMIC64_SELFTEST tristate "Perform an atomic64_t self-test" help diff --git a/lib/Makefile b/lib/Makefile index a8155c972f02..0ea8d414763c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -301,6 +301,7 @@ obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o obj-$(CONFIG_PERCPU_TEST) += percpu_test.o +obj-$(CONFIG_PERCPU_TEST_RUST) += percpu_test_rust.o obj-$(CONFIG_ASN1) += asn1_decoder.o obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o diff --git a/lib/percpu_test_rust.rs b/lib/percpu_test_rust.rs new file mode 100644 index 000000000000..60df44332d7a --- /dev/null +++ b/lib/percpu_test_rust.rs @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 +//! A simple self test for the rust per-CPU API. +use kernel::{ + define_per_cpu, percpu::cpu_guard::*, percpu::*, pr_info, prelude::*, unsafe_get_per_cpu_ref, +}; + +module! { + type: PerCpuTestModule, + name: "percpu_test_rust", + author: "Mitchell Levy", + description: "Test code to exercise the Rust Per CPU variable API", + license: "GPL v2", +} + +struct PerCpuTestModule; + +define_per_cpu!(PERCPU: i64 = 0); +define_per_cpu!(UPERCPU: u64 = 0); + +impl kernel::Module for PerCpuTestModule { + fn init(_module: &'static ThisModule) -> Result { + pr_info!("rust percpu test start\n"); + + let mut native: i64 = 0; + let mut pcpu: PerCpuRef = unsafe { unsafe_get_per_cpu_ref!(PERCPU, CpuGuard::new()) }; + + native += -1; + *pcpu += -1; + assert!(native == *pcpu && native == -1); + + native += 1; + *pcpu += 1; + assert!(native == *pcpu && native == 0); + + let mut unative: u64 = 0; + let mut upcpu: PerCpuRef = + unsafe { unsafe_get_per_cpu_ref!(UPERCPU, CpuGuard::new()) }; + + unative += 1; + *upcpu += 1; + assert!(unative == *upcpu && unative == 1); + + unative = unative.wrapping_add((-1i64) as u64); + *upcpu = upcpu.wrapping_add((-1i64) as u64); + assert!(unative == *upcpu && unative == 0); + + unative = unative.wrapping_add((-1i64) as u64); + *upcpu = upcpu.wrapping_add((-1i64) as u64); + assert!(unative == *upcpu && unative == (-1i64) as u64); + + unative = 0; + *upcpu = 0; + + unative = unative.wrapping_sub(1); + *upcpu = upcpu.wrapping_sub(1); + assert!(unative == *upcpu && unative == (-1i64) as u64); + assert!(unative == *upcpu && unative == u64::MAX); + + pr_info!("rust percpu test done\n"); + + // Return Err to unload the module + Result::Err(EINVAL) + } +} +