From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 55C523DA7F4 for ; Fri, 10 Apr 2026 21:36:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775856986; cv=none; b=WvCt+4e6sUDHkh851YQ4CNi0wgVGVDPKiIcck+6T52E4AQGlcWNJ6SuNhZSF9BpwpRp3DQ9SZJ67ZpsK8oGaTHdK+01e/1i4/ALNK+ehYnafhhnfNUjUwrAg+XTKzZwJ3Wqv8Qu3wRhrAWUO9RlS2xSwdszL/l7Eq+zKvUdTR0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775856986; c=relaxed/simple; bh=nFa6XzGa0lobebiKoERWPKmf/z75UhcpF+sR2BSl5r8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p8VNvnFF1+yseoKYXL37stRbFwcXYC65Pjt/mzjhVGP2E3lCVkHw7ZPz5cMAsyK8y156/OrTkFVd5hBk5HNOTDqUL1SdHpaureBb4bUKRuPCeENA6AXaKHdQlpPWsv075UM1B8ynpBE9Qod522CJ0p7dIUwznNtCG1DTutWnnNc= 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=Vt36GyVA; arc=none smtp.client-ip=209.85.210.182 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="Vt36GyVA" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-82cdb4ab547so1339764b3a.2 for ; Fri, 10 Apr 2026 14:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775856983; x=1776461783; darn=vger.kernel.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=d/ZkXAjTN+MjWCqsB5McracnlHQTzul2ROdtvOpaZMM=; b=Vt36GyVAsPe2qsFibdE3FvvnN245tXrYImgt5Pn9F6X9vzohN1y1ZDGuw5okBh6ebg kRURf45/4xg1uKKWkHE93ZV64FNKcYjw2rXD/62bFO02VYSAGUJkAjxDExCwdbcw0aNc 0PMVPDoAwDfWfx3UAURVcXyRLqtg5zCeow07P8HxiDMGiwv6I7nHFUQ2BoO+uXdTHlg/ VCj6xI+lDw0FFeaRlRUDN1eKyL8YxppwcUWFo6H7zbK1kOslMXYpjEHf5XDS3Q2pTkOi +X3pWvhakX7Si6/tMB0jzA0w3URegYZTgp2fAaCotw2RO9oTnd1Hea3VsmfbORmSyO+d r1/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775856983; x=1776461783; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=d/ZkXAjTN+MjWCqsB5McracnlHQTzul2ROdtvOpaZMM=; b=Uu5TiQ5PwgPtMrjySLG2uWt/+jccUp6m7Ihj8M4MHK++4BSAgH+wIl6fLDeReVeOVI Xaq+hhDIS4OPfmRbmMWwFlF6CwHAqf/9M8WgHP80IXoT9zr8Kl2MHXhpWBAaZHuwP9tj De0OwW/E7Xmg+MP3ryOZWirm3yvgvAGDypFiHyoC5D9XOaX5mnx7x1wQC0azyvWi5Ztm gOxD/RKmJe5LArCueizNxzTiBnTzzeux209uSOyNqG9vj6Cz4bxA0D0HlMuXa/LcNiZx D7qlYPJZk8YOw+PWgmx/WQGeZAxvT8viHcf3du+6jJ80LEv6jf6lHt6CyZ7HCXX+2IcY yCdw== X-Forwarded-Encrypted: i=1; AJvYcCWyokLA3v1j1tcmy6kEDjwE6N1Vs0BQsH4U/CxvMb8K6HYPcJKUBkIJATP0uvj164zbyW3VQepnSt/Gt88=@vger.kernel.org X-Gm-Message-State: AOJu0YyiYAEUpCPPXRx2F5nv96/gmF9wtbJ4i8UUNHL5CUM5l2Ee3qjx Ij36qQVP/g5OkqZ95FTtKfaRd1pkEtYCqHo2ZstEk0P7eT41LRU5VH2k X-Gm-Gg: AeBDievI0l/x5ys9dEMDBe2b/vL0F6SCm8WD220AZMosQnpSRuhmCMyDuGvmejjlv14 +KLaYzcIy4bATVO0zwzOJ0kTF0LLj6Tv41B96LWk/t+nWAXlDOqlzaHkSFItQFqnXJR+Sk0pKNO bBQW7Lqk4Xv/Tj0mrRkdiaBJGOMzPs563P51NBntgIEfJBYiIEsB8K6J02DEflMVMFefKiN6vTl ULNUMzeJL/XpgBkGVDWYqYDCuN8jgVhE3uDfOt0FAjI3NVpIMTEvkX10RS2VZM8PAm7ZCgqStyz zC2i3X+wSuKVbS/l2KUTU7B28Wy9zxnmNk7OpZBevjB0ENdnoEGmnLXb8nOVLUVsjEB/3P1tExf DUfJ59tY09NK45Eol/k8ojhpUYXyjOicx/3rHP8TaNeoTTcLSCGjVbEbOrgvByu7hsdlXFGWB7k jftZYevWPcmFlRT5wAQDbHQvD3/wTFBwwRW0XOrGf53qzx X-Received: by 2002:a05:6a00:3a29:b0:82f:48e:241c with SMTP id d2e1a72fcca58-82f0c2c8063mr4788741b3a.23.1775856982403; Fri, 10 Apr 2026 14:36:22 -0700 (PDT) Received: from mitchelllevy.localdomain ([131.107.1.135]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f0c4e3d41sm5111551b3a.48.2026.04.10.14.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2026 14:36:22 -0700 (PDT) From: Mitchell Levy Date: Fri, 10 Apr 2026 14:35:32 -0700 Subject: [PATCH v5 2/8] rust: cpumask: Add getters for globally defined cpumasks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260410-rust-percpu-v5-2-4292380d7a41@gmail.com> References: <20260410-rust-percpu-v5-0-4292380d7a41@gmail.com> In-Reply-To: <20260410-rust-percpu-v5-0-4292380d7a41@gmail.com> To: Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Danilo Krummrich , Benno Lossin , Yury Norov , Viresh Kumar , Boqun Feng Cc: Tyler Hicks , Allen Pais , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Mitchell Levy X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775856978; l=3267; i=levymitchell0@gmail.com; s=20240719; h=from:subject:message-id; bh=nFa6XzGa0lobebiKoERWPKmf/z75UhcpF+sR2BSl5r8=; b=Ny8jZTTn2nKtMFz16cbqPqojORJoc5t7WJOTlcvhg5M1RO1POOoBpvS/N5eE8SvhWzbrrt1xm JYMPyeawyXqBUwkQqwAmSvTiNScQlLsQgAT/Ju6d08ZnAo5kY7HdGdW X-Developer-Key: i=levymitchell0@gmail.com; a=ed25519; pk=n6kBmUnb+UNmjVkTnDwrLwTJAEKUfs2e8E+MFPZI93E= Add getters for the global cpumasks documented in `include/linux/cpumask.h`, specifically: - cpu_possible_mask - cpu_online_mask - cpu_enabled_mask - cpu_present_mask - cpu_active_mask Acked-by: Viresh Kumar Suggested-by: Yury Norov Signed-off-by: Mitchell Levy --- rust/kernel/cpumask.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/rust/kernel/cpumask.rs b/rust/kernel/cpumask.rs index b74a3fccf4b4..2d61f1323837 100644 --- a/rust/kernel/cpumask.rs +++ b/rust/kernel/cpumask.rs @@ -80,6 +80,52 @@ pub unsafe fn from_raw<'a>(ptr: *const bindings::cpumask) -> &'a Self { unsafe { &*ptr.cast() } } + /// Get a CPU mask representing possible CPUs; has bit `cpu` set iff cpu is populatable + #[inline] + pub fn possible_cpus() -> &'static Self { + // SAFETY: `__cpu_possible_mask` is a valid global provided by the kernel that lives + // forever. + unsafe { Cpumask::from_raw(&raw const bindings::__cpu_possible_mask) } + } + + /// Get a CPU mask representing online CPUs; has bit `cpu` set iff cpu available to the + /// scheduler + #[inline] + pub fn online_cpus() -> &'static Self { + // SAFETY: `__cpu_online_mask` is a valid global provided by the kernel that lives forever. + // Since we wrap the returned pointer in an `Opaque`, it's ok that `__cpu_online_mask` + // may change its value. + unsafe { Cpumask::from_raw(&raw const bindings::__cpu_online_mask) } + } + + /// Get a CPU mask representing enabled CPUs; has bit `cpu` set iff cpu can be brought online + #[inline] + pub fn enabled_cpus() -> &'static Self { + // SAFETY: `__cpu_enabled_mask` is a valid global provided by the kernel that lives forever. + // Since we wrap the returned pointer in an `Opaque`, it's ok that `__cpu_enabled_mask` + // may change its value. + unsafe { Cpumask::from_raw(&raw const bindings::__cpu_enabled_mask) } + } + + /// Get a CPU mask representing present CPUs; has bit `cpu` set iff cpu is populated + #[inline] + pub fn present_cpus() -> &'static Self { + // SAFETY: `__cpu_present_mask` is a valid global provided by the kernel that lives + // forever. Since we wrap the returned pointer in an `Opaque`, it's ok that + // `__cpu_present_mask` may change its value. + unsafe { Cpumask::from_raw(&raw const bindings::__cpu_present_mask) } + } + + /// Get a CPU mask representing active CPUs; has bit `cpu` set iff cpu is available to + /// migration. + #[inline] + pub fn active_cpus() -> &'static Self { + // SAFETY: `__cpu_active_mask` is a valid global provided by the kernel that lives forever. + // Since we wrap the returned pointer in an `Opaque`, it's ok that `__cpu_active_mask` + // may change its value. + unsafe { Cpumask::from_raw(&raw const bindings::__cpu_active_mask) } + } + /// Obtain the raw `struct cpumask` pointer. pub fn as_raw(&self) -> *mut bindings::cpumask { let this: *const Self = self; -- 2.34.1