From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796346505; b=S55+gmGvmNYICbUdVClwQdz1bZuvJMFsDaZ4QV7ZIgd0SE+kJOnxHCU4ZgvHzzLcJ3mr wP2RQKZUtCAW5IyjpqnaRpK20ep+vdfzlpgHoQ4EtwLChiK7YuosH7EOn7fkcmBGYFQsh 3mXlVY+Lz7suW8ZgrOdFxcEdbqtVplAGTCHt1arpb8mgclBNcASH4yje55DRdXhxWkGds urTw2bnTotI+0w6ECnmskB1pNnti/Co8+h3iAbr6T5K7lEwL5h9tWUyaEUHVnQob+BaY2 VyU14cXlpTYWfa7ugiEUZAfpUDSW9YnFlNigPfL+Majabv7IP4sJZfUG5JaVvO3pmTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796346505; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=1lF9cv805vjOLRqLUbeTIQ94WIicHnGJ10hpN4CyWnk=; b=26hir6VKqluzRo0Zg2fe9kcIDgQS1pOZ69lA93wiu/SUnj/K3jxh1SUW2SL/hbdceZIr +85KMXhbAsj2FRoI96iB8Dk2vhU8AoJXpur4KhrBgV7cCuov9fqAbWkv7ZR6WcYip4skD gSLZmSk6se/5ZChmCHIZbDwIruoK6t435j2aOvg7d6cSbRofHbIZO/pIaj3q5cIST8YFf 4rbnGjF6pTVlgaJpG2CxWQFgHoM4//8Ugji6j59VMzyCABLmJ1kO416K/ZOicVDVNhFlS CyzoxR4hfbXjURNd8pbddpM6ALZvTnN8E0LCyPIrDtFeWselg6Hvvj7iLq0lmn+rtQg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=uci.edu; spf=pass smtp.mailfrom=uci.edu; dkim=pass header.d=uci.edu header.i=@uci.edu header.a=rsa-sha256 header.s=google header.b=EsdJYc4i; arc=none smtp.remote-ip=74.125.82.175 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D822606A32C for ; Fri, 4 Dec 2026 01:08:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6D822606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uci.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uci.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=uci.edu header.i=@uci.edu header.a=rsa-sha256 header.s=google header.b=EsdJYc4i Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-3866a784546so532766eec.0 for ; Thu, 03 Dec 2026 17:08:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uci.edu; s=google; t=1796346504; x=1796951304; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=1lF9cv805vjOLRqLUbeTIQ94WIicHnGJ10hpN4CyWnk=; b=EsdJYc4i+F8Ub7i/7NJNr24+3okZi3B7eIYkrqIM8BtIBF+2UUhy0Jyu4zGOE7v/FU dD/8OOsDaIr5vqgqJvz9wYwvW3r+Eg1516+YYWdRVnZK8JzibmJWcmZbgzsMrNWCm5AY T+efG2IqhnApWAZIg2vltyoWWr1+aG0d5/tSRE3Ettc+DHVO5n8Jqck/ovKoNEy7Suac sT6/jI/KOvv+pbYkDiCjg54yaVIZYV2wTYWq/DUyGCpXWGus6VjX3dn/w19GbB1JxxqX 47N3rF3XLQ1S8o1ounB0StSwZWUB+CwGM4pOd5XkYfKori5XD5BcoG3tK7t6oZlPEy1Q aaxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796346504; x=1796951304; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1lF9cv805vjOLRqLUbeTIQ94WIicHnGJ10hpN4CyWnk=; b=w0QpGBPija8svvyZY6s/jsG5TeL6tDRY8DE4HfKpX/403EWCaurk/I37zsUiF0pVCq 2AUGmMSdT9I0i4NIO0tN3f8HGomKkY5FuSo3KNqz4RvEQGZ59l6EyO9dzBNfG8ecY2cA /s/KgUZSpWgwGSO1OzD5xbimmkzLSPWf4hS656DBSjhdv90fWNjNIU67173vGKYS4EAi qVaSmHEByziy6SmrfESA29oLuXJlhjW9rlYbOoyTx1Wb8T98tLzdIqIkzHMvfwQvuO5M dmhyg3Ff5QD26HwR3S7zUDFcHLB4USj5bxKuMLif5DNhvtqww4JKJ+4qeVyEeTElLd7Y nv7A== X-Gm-Message-State: APuU4Z9HyyorvRIoU++H8zYjLsDKs+5s7AtztG14lfM/ienua5nLKg+5 M30FbVmxZFzuivSFWnqiGkjiPVY1drNrT9AyYLMx6liVgUdRJRiapOTa+VQhMnmLRYWmzpYyhxi XQK/gM33GFg== X-Gm-Gg: AZFdTZeOoRpt2U2TRX+Tl1lljXJoCRhdz5d+9ASeiEpD9ywqNwbURO+Wpvbsv8WXHxY B6kGLJIVzpf/fTUGE/5/u26LE48xv8Jqbc4ItKvxMOMhlVDqr+FQjBLdIU4LIN5KwuRxzEpNyMn DrJi2Bdhs3QgLZaBboGAu0hSpb7R27m5UaPyUZNQWHilLkO39650YSq3T+ZXLneIjRl01gVy3fL bEX3fiY6sAByqj4VlHiCwvlTW8ZUX0uqn5rJ9ApLm/WlY/gzF6OsBixkIOdayGFQqloOZiahJgs rkJ1re+J2/Yr+wlCXZDaHNSWC4f/sLV6nwCASCbFvPZwY0Li92yDBvmH6eADQPXdlObEkcZRTHH 3wD0WvVgJ2pVqZSeVGmpx5YZn7PT8u9ncMEkUg3X4PlQt1Sn9m5k4agXUcbRPDOTOcAhVxzXTPI 3Qinnig0gGOqBy/BPc0qMKywq/4NgzDVq26sgTiAp8JFoAKNcgMG0UAQalsdwYqxQlZGdJQIK0I 7doIlDT6n0750NIdVueT1ARwHfhDzNOsTonFrFN24kSMWq13WEj1v/kLEjPw7Ujp8eUWnBt6D3Y AWO2s+Dj1me6E76WPCa7ed4eZva5YtgUFcON4XmckksJ3wkr2O+G5VYaoCqHEkqh287FQZAZ0RF mv6fK7iE0ATo3ng== X-Received: by 2002:a05:7300:cf87:b0:385:4608:5679 with SMTP id 5a478bee46e88-3875217d82fmr450824eec.40.1796346504416; Thu, 03 Dec 2026 17:08:24 -0800 (PST) Received: from guest1.. (charm.ics.uci.edu. [128.195.4.118]) by smtp.googlemail.com with ESMTPSA id 5a478bee46e88-387521bb368sm1914910eec.10.2026.12.03.17.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 17:08:24 -0800 (PST) From: Priya Bala Govindasamy To: rafael@kernel.org, viresh.kumar@linaro.org, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, daniel.almeida@collabora.com, tamird@kernel.org, acourbot@nvidia.com, work@onurozkan.dev, nm@ti.com, sboyd@kernel.org, zhongqiu.han@oss.qualcomm.com Cc: linux-pm@vger.kernel.org, rust-for-linux@vger.kernel.org, ardalan@uci.edu, zhiyunq@cs.ucr.edu, dzueck@uci.edu, pgovind2@uci.edu Subject: [PATCH v2] rust: cpufreq: Add `Send` and `Sync` bounds for `Driver::PData` Date: Fri, 4 Dec 2026 01:08:23 +0000 Message-Id: <20261204010823.10596-1-pgovind2@uci.edu> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit `Driver::PData` is required to implement `ForeignOwnable`, but currently is not required to implement `Send` and `Sync`. Driver callbacks can obtain shared references to `PData` via Policy::data() and these callbacks could occur concurrently on different threads. Additionally, `PData` can be moved across threads through `init_callback` and `exit_callback` which transfer ownership to and from the C cpufreq core. Therefore, `PData`, a type which may not implement `Send` or `Sync`, could be accessed from different threads. This is a soundness issue and no known failure is currently triggered by any in-tree users. Fix this by requiring that `Driver::PData` implement `Send` and `Sync`. Additionally, for rcpufreq_dt, remove the unused `CpumaskVar` and implement `Send` and `Sync` for `FreqTable`. Fixes: 6ebdd7c93177 ("rust: cpufreq: Extend abstractions for policy and driver ops") Reported-by: Dylan Zueck Signed-off-by: Priya Bala Govindasamy --- This issue was detected by FerroLens, an LLM-assisted analysis tool. Changes since v1: - Add `Send` and `Sync` bounds for `Driver::PData` instead of just `Send`. - Implement `Sync` for `FreqTable`. Link to v1: https://lore.kernel.org/all/10e19c83b81a221cfe2f01b3756e530b9742bf84.1796073594.git.pgovind2@uci.edu/ drivers/cpufreq/rcpufreq_dt.rs | 2 -- rust/kernel/cpufreq.rs | 10 +++++++--- rust/kernel/opp.rs | 9 +++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs index 2b1f18b7a1e7..0479f6d3ade7 100644 --- a/drivers/cpufreq/rcpufreq_dt.rs +++ b/drivers/cpufreq/rcpufreq_dt.rs @@ -45,7 +45,6 @@ fn find_supply_names(dev: &Device, cpu: cpu::CpuId) -> Option> { struct CPUFreqDTDevice { opp_table: opp::Table, freq_table: opp::FreqTable, - _mask: CpumaskVar, _token: Option, _clk: Clk, } @@ -146,7 +145,6 @@ fn init(policy: &mut cpufreq::Policy) -> Result { CPUFreqDTDevice { opp_table, freq_table, - _mask: mask, _token: token, _clk: clk, }, diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs index f31671129c98..2a65dafc5f23 100644 --- a/rust/kernel/cpufreq.rs +++ b/rust/kernel/cpufreq.rs @@ -746,9 +746,13 @@ pub trait Driver { /// Policy specific data. /// - /// Require that `PData` implements `ForeignOwnable`. We guarantee to never move the underlying - /// wrapped data structure. - type PData: ForeignOwnable; + /// Require that `PData` implements `ForeignOwnable` so that ownership can be transferred + /// to the C `cpufreq_policy`. + /// Require that `PData` implements `Send` and `Sync` because `PData` may be accessed + /// from multiple threads concurrently. + /// We guarantee to never move the underlying wrapped data structure while it is owned + /// by the C `cpufreq_policy`. + type PData: ForeignOwnable + Send + Sync; /// Driver's `init` callback. fn init(policy: &mut Policy) -> Result; diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs index 62e44676125d..5d35a3433d1a 100644 --- a/rust/kernel/opp.rs +++ b/rust/kernel/opp.rs @@ -35,6 +35,15 @@ pub struct FreqTable { ptr: *mut bindings::cpufreq_frequency_table, } + // SAFETY: `FreqTable` owns the allocation referenced by `ptr`. The allocation + // may be freed from any thread. + // `dev` is an `ARef`, which is `Send`. + unsafe impl Send for FreqTable {} + + // SAFETY: The allocation referenced by `ptr` remains alive while `FreqTable` is borrowed. + // `dev` is `Sync`. Safe access to shared references of `FreqTable` does not permit writes. + unsafe impl Sync for FreqTable {} + impl FreqTable { /// Creates a new instance of [`FreqTable`] from [`Table`]. pub(crate) fn new(table: &Table) -> Result { -- 2.34.1