From nobody Wed Oct 8 19:23:12 2025 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 EFD5186340; Wed, 25 Jun 2025 05:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750828527; cv=none; b=DVTiL+r/oNZFs20GMbEEWY4L93oW25UjESx5l9TPZdtNIVUCcptOxHF/0afCgHWwouTxTeAfvu5c1aYXGK5+qxNTbELO6ZcIG4bp1zAVCEcmA8c9a0GGta4yqKs1YxbJnBhmgEd0hi2b+Utxhk/QuHrLGnmD/4NLnz2JqlefUEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750828527; c=relaxed/simple; bh=lEdzcKED8dxibbdj4USCma8xOMOqMEjtizIV39k44XQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hxrIXhY6UYbev9xYwN6cnGIye+fR5i55UVNebbcVLffNvbGifxTsWjiPJKWi+V0ZrLUYEuC9T01lMpq2hiQ0HWlu92TEQ+zMhDld6jd3DLE5DtgBXLH6tkkLecDt3WmV6Xjxk1MdMSSCQTMquQ6SBPTR8QVqzsKW7ZYRdssIktM= 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=gUSZZ3vK; arc=none smtp.client-ip=209.85.160.180 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="gUSZZ3vK" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-4a6f0bcdf45so74120041cf.0; Tue, 24 Jun 2025 22:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750828525; x=1751433325; 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=7bZLeeq5Dz3WES+/TzaEncqzq5j376rFHhQoBFa1jdI=; b=gUSZZ3vKDiSvcKGamR4iZ1wC9172oJrUgnpROIoETUoY9SiM8YFJKZB/b9mWko/QgV j+k4SIrtD0tHKUWU47Sau7JvzIIDSHYYmHsEP+jnAKolHtgsRBjRAj0HsEJq9txMGnHz hpwITncNsT/Cg5/gCMKTwPrOLnIhFfTELx8MQKFinQOO7fXKWgUrG0oLSXxCLC8U27QF XE/Uwj11vt5ghQ51Fg5mborJ3a36LjHU7PKlzsvLQMKA6Qg4unLIotXVxb+8frl5XQ5j xOaJgPvcZLySjvHX0zPDCgGSpMcGyzTI+zoDWWj5OMS9YlGa9yKxHCmKSUvY6tGbRu5d 4JCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750828525; x=1751433325; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7bZLeeq5Dz3WES+/TzaEncqzq5j376rFHhQoBFa1jdI=; b=KT2huSjyLuSkeyciEpVH1Xh7a1uPwdm99J0RS5/ixIzaFaNxE5yuZYMONPDiOjhNog xhWZvKEQBCOCnhjyc4rfeyUb97ECmrO6oLJ47uD58ciWpkqhLFzaR0I50Qy7fXN8lWp5 TA1v+esHAXJ2K8cOfDf+5uRSHHjuhFFDXdu84jSoJelB6ZQ25ZHw3+fyc7muYf4eZZlF dxTeblskW6kInMjrlYk/RrG4z+XvMLSyfdbtI5OclKc0asSz8PaGyh4nW97sb2u9PlkW Tyg4g5nCocnZDUJPTEVJdxI4WB87y9FvlGITnIlG+e+HtiICIcucY8fyhgH7U0VYme1t 4VcQ== X-Forwarded-Encrypted: i=1; AJvYcCVgTqi8px1r0OOSy/uuEkWjsjYCURi4i1rnS3wqWn8FPrNGGMbXoAhhfzZhQ1nNObfhz6MJA6irt0/acaBs2FI=@vger.kernel.org, AJvYcCXtBp9CsPhvBqdNywhQp7wPvpAwmNBKy48nk+LU5e1UfejSr3ymHj7LjDl6wbn5stIm6E4AflLNoVC43pY=@vger.kernel.org X-Gm-Message-State: AOJu0Yzm0+mALRZpSicHgoDORwuyseCUCXrzEBAraC775GZsFhYjxh/k Uv/sa3C4t/bpaZxbPOEpIK/MftHECGN/cMgKSnlgYlB7xgIbwSrFlXVx X-Gm-Gg: ASbGncs2ADCVMCrIOFldGxNioftkjo3XwiL5LHo7iCQyGxassYJTfkrr8HWxiOS34I3 2J1089CFcjI6Y5w9+Rff/n9Y2Sr05DC6+YjH1ITdoMAO9UIbIJzr/Vp+p5ymY1fJ8FI2tKxwN4h mDJk09J+YlbRONahEb01nKuhgVUcBugWaMUYUpxE8Qzst9+FTLnnd5Mk7b6GkTdvomInog2rb50 4nNfOvQc7p5UhYAcuRCJpy3mSEVmiuseXih7m0wgPy0QfcX9bysFChvcmK7ejuACGz375ma2KmX Fvac/ZSyo5o8177rnYL0YoTvjxpHfTrGEDhOCC0vmC9Ec/ptDbTYyoZ9PorN45pDffOUTEj2Eh3 C24OR3Y0r9zN7t4cGZUjdyegYHWRiPw8ZJecWXBQANoNqHoHej85i X-Google-Smtp-Source: AGHT+IE2SfyLvxx5vwTElEiNwcIFf2JWsRpHU1DfZP76EL4jxeoF0N+a/gMV3qVAhjt9uTcdmO/yfQ== X-Received: by 2002:ac8:5ac9:0:b0:490:8ffd:8f02 with SMTP id d75a77b69052e-4a7c088b839mr29342211cf.37.1750828524322; Tue, 24 Jun 2025 22:15:24 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a779e910c8sm56018511cf.71.2025.06.24.22.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 22:15:23 -0700 (PDT) Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfauth.phl.internal (Postfix) with ESMTP id 0020AF40067; Wed, 25 Jun 2025 01:15:23 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Wed, 25 Jun 2025 01:15:23 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddvgddvudeludcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhepkeetteejgeduieekudejfedvvddtiefgieffffeljeefieehiefffedvfeffgfet necuffhomhgrihhnpehgihhthhhusgdrtghomhdpkhgvrhhnvghlrdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgv shhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehhe ehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv pdhnsggprhgtphhtthhopeefiedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepmh hinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgr uggvrggurdhorhhgpdhrtghpthhtohepmhhinhhgohesrhgvughhrghtrdgtohhmpdhrtg hpthhtohepjhhurhhirdhlvghllhhisehrvgguhhgrthdrtghomhdprhgtphhtthhopehv ihhntggvnhhtrdhguhhithhtohhtsehlihhnrghrohdrohhrghdprhgtphhtthhopeguih gvthhmrghrrdgvghhgvghmrghnnhesrghrmhdrtghomhdprhgtphhtthhopehrohhsthgv ughtsehgohhoughmihhsrdhorhhgpdhrtghpthhtohepsghsvghgrghllhesghhoohhglh gvrdgtohhmpdhrtghpthhtohepmhhgohhrmhgrnhesshhushgvrdguvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jun 2025 01:15:22 -0400 (EDT) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , FUJITA Tomonori , Tamir Duberstein , Kunwu Chan , Mitchell Levy , Martin Rodriguez Reboredo , Borys Tyran , Christian Brauner , Panagiotis Foliadis , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev, Grace Deng Subject: [PATCH v2 1/5] rust: sync: Mark CondVar::notify_*() inline Date: Tue, 24 Jun 2025 22:15:14 -0700 Message-Id: <20250625051518.15255-2-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250625051518.15255-1-boqun.feng@gmail.com> References: <20250625051518.15255-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kunwu Chan When build the kernel using the llvm-18.1.3-rust-1.85.0-x86_64 with ARCH=3Darm64, the following symbols are generated: $nm vmlinux | grep ' _R'.*CondVar | rustfilt ... T ::notify_all ... T ::notify_one ... T ::notify_sync ... These notify_*() symbols are trivial wrappers around the C functions __wake_up() and __wake_up_sync(). It doesn't make sense to go through a trivial wrapper for these functions, so mark them inline. [boqun: Reword the commit title for consistency and reformat the commit log.] Suggested-by: Alice Ryhl Link: https://github.com/Rust-for-Linux/linux/issues/1145 Co-developed-by: Grace Deng Signed-off-by: Grace Deng Signed-off-by: Kunwu Chan Reviewed-by: Benno Lossin Reviewed-by: Alice Ryhl Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250324061835.1693125-1-kunwu.chan@linux.d= ev --- rust/kernel/sync/condvar.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index caebf03f553b..c6ec64295c9f 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -216,6 +216,7 @@ fn notify(&self, count: c_int) { /// This method behaves like `notify_one`, except that it hints to the= scheduler that the /// current thread is about to go to sleep, so it should schedule the = target thread on the same /// CPU. + #[inline] pub fn notify_sync(&self) { // SAFETY: `wait_queue_head` points to valid memory. unsafe { bindings::__wake_up_sync(self.wait_queue_head.get(), TASK= _NORMAL) }; @@ -225,6 +226,7 @@ pub fn notify_sync(&self) { /// /// This is not 'sticky' in the sense that if no thread is waiting, th= e notification is lost /// completely (as opposed to automatically waking up the next waiter). + #[inline] pub fn notify_one(&self) { self.notify(1); } @@ -233,6 +235,7 @@ pub fn notify_one(&self) { /// /// This is not 'sticky' in the sense that if no thread is waiting, th= e notification is lost /// completely (as opposed to automatically waking up the next waiter). + #[inline] pub fn notify_all(&self) { self.notify(0); } --=20 2.39.5 (Apple Git-154) From nobody Wed Oct 8 19:23:12 2025 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (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 26712199FBA; Wed, 25 Jun 2025 05:15:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750828528; cv=none; b=CHve6kIlTzFbGbKchsslXJI435P7XAtm+LLqYcFP7L1LSDpXrbD0btR9MJBusGm8s5dtiFOMSOGrZpY1SwDp9ukajW64mBnZF26djxWNkvqz0xuoL8Ro4U/jH2qPHVJlyREyWNW7vnX81+786Vz1g/nK8ARjx0ZDjtjPm0c7we8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750828528; c=relaxed/simple; bh=DZPx48zTDYNX5AKa48yQp9oTWkNFvmRP5adzWyGYmmQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rOb2T7lhzsrVjsPAmhdSdXdoDsWnGhm68z4/yProq2ZhUouOymHPsBj+IecuSUt4Y578NJVHWUdL5yNsYjdx5eu4Sel0YzRLPWO/+bSg5gHAEe/BVmgeQe6U6m4hTp/ZFfDCEOfIhlWieHgjQbjaBRmQb7fr0zY34mqMWTt8Qhk= 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=TAzrOTxh; arc=none smtp.client-ip=209.85.219.46 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="TAzrOTxh" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6fada2dd785so78103986d6.2; Tue, 24 Jun 2025 22:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750828526; x=1751433326; 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=x0uhFJxbTknYVv8H2dzluonrWfElV8YvZk9w6Cc8W4w=; b=TAzrOTxhgWnF/AfbJfZFwomT9ljcmf+vkf2TR9kjUxvjOUIWopjWJZEPuVNUgnZ0HS sRSFaMfHaWPztxJnWDtbzQ62Mv7u5/Ht3pdYmvCAfWJsGUzE7XuGqiCuFwbt3LdvTz6a 4E9uF+UfpAzD/v3h3CI2VNmSaSbUZFzhNSc0PqR6z3epOhdBSSAxSWHGPlgyDhepwgXl 5cWcCJ+OnO1KYOhGid+Do9WLL4wH42RI/ZjSllWfdaRm0gRXkpr1Q/IwG7Ng6Lls3I55 2fs0TPACheps1c6b9k+/miAOF0BWjhZq71vLgOh3Q0cvKVWSFqkBlVVCPrjLvNsLQ9/F 8bYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750828526; x=1751433326; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=x0uhFJxbTknYVv8H2dzluonrWfElV8YvZk9w6Cc8W4w=; b=wkSyEYSIfIrUJDlt335gH8E1DC6c4hOI50vhWtvlPW0bDJETB461/CzT75J8hpw/TB g7g1oQMCfZLYroqH3Ehq8Zy2LtbxsKsEu6Y/iJF5awlZPfQw9OB9yjxgc8jSjOCTCGXm bqrJqmLwi8q01kBz1kCFxRuuJCNJOvouc31URrLu/duIDW/BYW/VvioADM85S73p09Di F/i8BA+mvSPM8QjjH2yTf/1G1UBmQenVH0kD2Ly6nnqWbhqoRjz20SfAcXJGz2wpEODK eQu0vOYK7iK9MtLwEQrMpYFIb1XIJTpm7Z6Br3XGWa0T7pGjvzLfkP8aEZh0PmEn0+bR lYKA== X-Forwarded-Encrypted: i=1; AJvYcCVOz9wn1O5yhm92NJdJ2babGvHSOZtuY38vqTPq5cQqaC2bKRpZy1uwBjNCFOfa1ryfYSM4FzQHAW8iCP8=@vger.kernel.org, AJvYcCXgy61Fw2J67BW9OlelTz1ChPC/Z3VITG6UaYoCVJKXPT9zhHekBS8L8V8EbrEfQ+JeKK/4V5gRQg5FrDKgywE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4LnLLu7cfaPFQSzFopbmTxcd2EYlyP059K5Lxo/YAE/A9A+zh XUW7S0QDOD2gDapsOoljF+UEmoDt+GP0bNiCFMq2wip/jbbUPsGfQBYp X-Gm-Gg: ASbGncts6f3C2y2kV+rsxGgv+hDNteAyFwDFv3SBJbXbq06M1lz/ejHY4rnTGLHv8VD 9h/m9EJfo1llDedmr+guZUC+69NM+5JF5l9/FjYLvps6ZHfF8yPBapCt3kRb9i1VY75DSX/IA8z C2p/x0wrgtCObK3Gh0TKz74Q6bGzy913zNR6TGnWMqWWPgN3gSVwG2lh2te5pGh9M4VzuA8ePgh 9t7HTLyH0/zriDi1GREsz+8A+P7dOrKXqsQKsVTIuYvlvFj/eW7ycicxUeJEmfTN74mz9lm05+V rW9wOUdj/gC3f86RheLhQDpsjoNmh7kaI4ldR3Wo35Go+UTGXnsxF2DG46FJZntNNavuvVc6nYs fnufqR6j4YBZ3KGBTEbpJ2kX+9XalYL7KPZvRUaaTxx86ojYv/hQ9 X-Google-Smtp-Source: AGHT+IEFTnqbuvaJX0Csg9cjWCqwK8O2gHdOMg3CTJHOajGqnck4hYJwCK/rV9J0qs08iUEap5Q+iA== X-Received: by 2002:a05:6214:570a:b0:6fa:cb72:955a with SMTP id 6a1803df08f44-6fd5ef2fccemr23474106d6.4.1750828525731; Tue, 24 Jun 2025 22:15:25 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fd09576766sm64178956d6.81.2025.06.24.22.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 22:15:25 -0700 (PDT) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfauth.phl.internal (Postfix) with ESMTP id 502DCF40068; Wed, 25 Jun 2025 01:15:24 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-10.internal (MEProxy); Wed, 25 Jun 2025 01:15:24 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddvgddvudeltdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhepkeetteejgeduieekudejfedvvddtiefgieffffeljeefieehiefffedvfeffgfet necuffhomhgrihhnpehgihhthhhusgdrtghomhdpkhgvrhhnvghlrdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgv shhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehhe ehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv pdhnsggprhgtphhtthhopeefiedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepmh hinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgr uggvrggurdhorhhgpdhrtghpthhtohepmhhinhhgohesrhgvughhrghtrdgtohhmpdhrtg hpthhtohepjhhurhhirdhlvghllhhisehrvgguhhgrthdrtghomhdprhgtphhtthhopehv ihhntggvnhhtrdhguhhithhtohhtsehlihhnrghrohdrohhrghdprhgtphhtthhopeguih gvthhmrghrrdgvghhgvghmrghnnhesrghrmhdrtghomhdprhgtphhtthhopehrohhsthgv ughtsehgohhoughmihhsrdhorhhgpdhrtghpthhtohepsghsvghgrghllhesghhoohhglh gvrdgtohhmpdhrtghpthhtohepmhhgohhrmhgrnhesshhushgvrdguvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jun 2025 01:15:23 -0400 (EDT) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , FUJITA Tomonori , Tamir Duberstein , Kunwu Chan , Mitchell Levy , Martin Rodriguez Reboredo , Borys Tyran , Christian Brauner , Panagiotis Foliadis , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev, Grace Deng Subject: [PATCH v2 2/5] rust: sync: Mark PollCondVar::drop() inline Date: Tue, 24 Jun 2025 22:15:15 -0700 Message-Id: <20250625051518.15255-3-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250625051518.15255-1-boqun.feng@gmail.com> References: <20250625051518.15255-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kunwu Chan When building the kernel using the llvm-18.1.3-rust-1.85.0-x86_64 with ARCH=3Darm64, the following symbols are generated: $nm vmlinux | grep ' _R'.*PollCondVar | rustfilt ... T ::drop ... This Rust symbol is trivial wrappers around the C functions __wake_up_pollfree() and synchronize_rcu(). It doesn't make sense to go through a trivial wrapper for its functions, so mark it inline. [boqun: Reword the commit title and re-format the commit log per tip tree's requirement, remove unnecessary information from "nm vmlinux" result.] Link: https://github.com/Rust-for-Linux/linux/issues/1145 Suggested-by: Alice Ryhl Co-developed-by: Grace Deng Signed-off-by: Grace Deng Signed-off-by: Kunwu Chan Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250317025205.2366518-1-kunwu.chan@linux.d= ev --- rust/kernel/sync/poll.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/kernel/sync/poll.rs b/rust/kernel/sync/poll.rs index d7e6e59e124b..7b973d72229b 100644 --- a/rust/kernel/sync/poll.rs +++ b/rust/kernel/sync/poll.rs @@ -107,6 +107,7 @@ fn deref(&self) -> &CondVar { =20 #[pinned_drop] impl PinnedDrop for PollCondVar { + #[inline] fn drop(self: Pin<&mut Self>) { // Clear anything registered using `register_wait`. // --=20 2.39.5 (Apple Git-154) From nobody Wed Oct 8 19:23:12 2025 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (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 77DB21E2834; Wed, 25 Jun 2025 05:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750828530; cv=none; b=l5YJ40aZfOxOhUAYZ5V8GC5LUaFw6f3OUsVqsSwTyyJ+2vW3JtKorSIubWhngyjjH9lhjgNArwHHrwaf5jn7fnUE4GaVxYaw9MRCG+2/TLYsDtKHGYq3B3b7a8YeMm1r1N/Ud6dd+9lYChPtH9WHZDiPbSsDu1Q3mX8CMfYRVg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750828530; c=relaxed/simple; bh=smxDLvsJze7SanW5jkLByGCvEyisY67nQWf9OhoWJVg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dXswy7t/ahZaK9Hsy09oiG54m9n9PFYXhMLwdy0cnXAl5NZVwGTRInuhDp+wWcRhRXx5lpDLT8XqsyysR5as94Bt9X/KEtdsLyO/mMmloR0g4XWmrwgYHbCCT8C0bqz9kzd4VK1WDjTrdB9rOG00YFFxOZTXbMzaBqz1s2lceoc= 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=IHe9YEGj; arc=none smtp.client-ip=209.85.222.171 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="IHe9YEGj" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7cadd46ea9aso946663385a.1; Tue, 24 Jun 2025 22:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750828527; x=1751433327; 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=+kICsOE0yg2BTiSdXOCgN6mz13mvo6la/kJ0XkefREQ=; b=IHe9YEGjGdVKtlBoGNV2rO6f1THz3g8uAkeKB1IRrDhtzhjhTA+nGHm0KJatWVYri2 jOSlD7ICMrm3ofGWZ9AKhSHm6E4AIUNN4cIl2NilBE+I2M2gX7rQs5DmcoWxg7Oayvcv 8g22OfAe7QgIZ82TE71YIhnFNPdyac4kOLBnAVJR4EV47a/U8d42HiOyTekXvIgj/sJH uEyz64im6TVPpa1KQpqD9CLyQNcM6XygQN41nPzOkQBP+N8JwT+arBWtYueOjuuNKQCj w/ItYZwd3/+G0dp2MVD/eH2mdBwW7ZqBQXkHHPX7yBesaRB36fsJ0jwikZE/PsTYbVby opwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750828527; x=1751433327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+kICsOE0yg2BTiSdXOCgN6mz13mvo6la/kJ0XkefREQ=; b=mL7vfB4uZe5P+YbzcZHafq+PcWAn1tK+QGA5ewGE/IKRcE2MRRalLM/yvUkpGrQPLK hggUNswPfLH7QI/KBtvbuIcv8fIoyzDhb2Z2Xi01qf6lKYwQ5inoDdMn1blFGTS+3M4L 7HMqKbYw7Ho3wflWQu3f7jLQrONA1bKRXKbmCgx438k2d+a0NcxfNApCOdu5PpTtIrLA MVB4UjkINdT/CGGfWx2Nd9r6BiopFltALcFydDdAQ9D9N0bTyj90SLcKYOZDQsacGUxo yWOOqXlJQ99/PEyuKbCKcEcXYqLgqcK36a3Bcgy+4zSCQbkSO55y8dp7uhATjzJllF1a 9rPA== X-Forwarded-Encrypted: i=1; AJvYcCUEIx2lITIseYZqPx7Q1oefFO308w84cDGuR0gQa+LBS6O2/0vSb7jaXIReJAQECcLPNq9DVTWQ2UJ+GJxI69g=@vger.kernel.org, AJvYcCXQAw4ymsVG1k8ooI4kkPo6dPcrEbswDgn6kbJfvSjytQOACLVPnD+ZZthkButqtkQ7rSN5gnVuS02F64o=@vger.kernel.org X-Gm-Message-State: AOJu0YyKyE8e/2NNdGfwda1mmEyVvPR494Gz1D2BZh6MJ3qP6KreBqcS btqpD2HAzOtRByGLsVpd6slAhm0LdveHwFxVF/06HQSYMmKs/GA5zD3Y X-Gm-Gg: ASbGncvv4VHfAzaimEDeIOl5gf5OUF4oURinDQfcf7pD2ImLCKCgvYQFW6fVdt3BH59 XZJsUJSbDSd5sBHtDhwSfa36crjxZR639bUizZMd93y/SbrEHMDsSNJ3KXc8aKekdjDQ1tfUXH3 4ya1Z7N66t8tj0X3mAzwt6LgQnhJEkAbRPimhz46lJvT4fCNULOj3T6JtDAj0WyRfsUykHi+c28 AmxlW7s4q1EqrhMOHIklEpscIe7xGPVLd0DROLo+oun1SVUHgYQrzrtwViHW1wQ6Vh6gcZH55gg DLYWwghYTVB2AQ2199AS0DNWuPMKMRadWGBnGP1qXAnIXiosBJ3L2XNgIdV4mvAahqbXlXgpQtD dBTuW0xugmwmYFIYwNKd2q2ESPMcRYDIlNLfIwy1B23kAFaPD9/hJ X-Google-Smtp-Source: AGHT+IF/eyqrfKOfuzaqpV3gyLsb6OnjZf7waUNYedNniJyI+yfxubomdyfc4MxIxfE5P6r1MYBDwA== X-Received: by 2002:a05:620a:40c2:b0:7d3:f193:6328 with SMTP id af79cd13be357-7d429797054mr285299885a.54.1750828527153; Tue, 24 Jun 2025 22:15:27 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d3f999c07bsm581667885a.4.2025.06.24.22.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 22:15:26 -0700 (PDT) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id A3EC1F40066; Wed, 25 Jun 2025 01:15:25 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 25 Jun 2025 01:15:25 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddvgddvudeltdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhepteejueeugeefiefhiefhtdeukeegvdekvdeufedvudehueegheelhfdvudeugeff necuffhomhgrihhnpehgihhthhhusgdrtghomhdpkhgvrhhnvghlrdhorhhgpdgtrghsth drrghsnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep sghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtie egqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhi gihmvgdrnhgrmhgvpdhnsggprhgtphhtthhopeefjedpmhhouggvpehsmhhtphhouhhtpd hrtghpthhtohepmhhinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgv rhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepmhhinhhgohesrhgvughhrg htrdgtohhmpdhrtghpthhtohepjhhurhhirdhlvghllhhisehrvgguhhgrthdrtghomhdp rhgtphhtthhopehvihhntggvnhhtrdhguhhithhtohhtsehlihhnrghrohdrohhrghdprh gtphhtthhopeguihgvthhmrghrrdgvghhgvghmrghnnhesrghrmhdrtghomhdprhgtphht thhopehrohhsthgvughtsehgohhoughmihhsrdhorhhgpdhrtghpthhtohepsghsvghgrg hllhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepmhhgohhrmhgrnhesshhushgvrdgu vg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jun 2025 01:15:25 -0400 (EDT) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , FUJITA Tomonori , Tamir Duberstein , Kunwu Chan , Mitchell Levy , Martin Rodriguez Reboredo , Borys Tyran , Christian Brauner , Panagiotis Foliadis , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev, Christian Schrefl , Charalampos Mitrodimas Subject: [PATCH v2 3/5] rust: task: Mark Task methods inline Date: Tue, 24 Jun 2025 22:15:16 -0700 Message-Id: <20250625051518.15255-4-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250625051518.15255-1-boqun.feng@gmail.com> References: <20250625051518.15255-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Panagiotis Foliadis When building the kernel using the llvm-18.1.3-rust-1.85.0-x86_64 toolchain provided by kernel.org, the following symbols are generated: $ nm vmlinux | grep ' _R'.*Task | rustfilt ... T ::get_pid_ns ... T ::tgid_nr_ns ... T ::current_pid_ns ... T ::signal_pending ... T ::uid ... T ::euid ... T ::current ... T ::wake_up ... T ::dec_ref ... T ::inc_ref These Rust symbols are trivial wrappers around the C functions. It doesn't make sense to go through a trivial wrapper for these functions, so mark them inline. [boqun: Capitalize the title, reword a bit to avoid listing all the C functions as the code already shows them and remove the addresses of the symbols in the commit log as they are different from build to build.] Link: https://github.com/Rust-for-Linux/linux/issues/1145 Reviewed-by: Benno Lossin Reviewed-by: Christian Schrefl Reviewed-by: Charalampos Mitrodimas Reviewed-by: Alice Ryhl Signed-off-by: Panagiotis Foliadis Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250315-inline-c-wrappers-v3-1-048e43fcef7= d@posteo.net --- rust/kernel/task.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs index 927413d85484..834368313088 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -173,6 +173,7 @@ pub fn current_raw() -> *mut bindings::task_struct { /// Callers must ensure that the returned object is only used to acces= s a [`CurrentTask`] /// within the task context that was active when this function was cal= led. For more details, /// see the invariants section for [`CurrentTask`]. + #[inline] pub unsafe fn current() -> impl Deref { struct TaskRef { task: *const CurrentTask, @@ -222,24 +223,28 @@ pub fn pid(&self) -> Pid { } =20 /// Returns the UID of the given task. + #[inline] pub fn uid(&self) -> Kuid { // SAFETY: It's always safe to call `task_uid` on a valid task. Kuid::from_raw(unsafe { bindings::task_uid(self.as_ptr()) }) } =20 /// Returns the effective UID of the given task. + #[inline] pub fn euid(&self) -> Kuid { // SAFETY: It's always safe to call `task_euid` on a valid task. Kuid::from_raw(unsafe { bindings::task_euid(self.as_ptr()) }) } =20 /// Determines whether the given task has pending signals. + #[inline] pub fn signal_pending(&self) -> bool { // SAFETY: It's always safe to call `signal_pending` on a valid ta= sk. unsafe { bindings::signal_pending(self.as_ptr()) !=3D 0 } } =20 /// Returns task's pid namespace with elevated reference count + #[inline] pub fn get_pid_ns(&self) -> Option> { // SAFETY: By the type invariant, we know that `self.0` is valid. let ptr =3D unsafe { bindings::task_get_pid_ns(self.as_ptr()) }; @@ -255,6 +260,7 @@ pub fn get_pid_ns(&self) -> Option> { =20 /// Returns the given task's pid in the provided pid namespace. #[doc(alias =3D "task_tgid_nr_ns")] + #[inline] pub fn tgid_nr_ns(&self, pidns: Option<&PidNamespace>) -> Pid { let pidns =3D match pidns { Some(pidns) =3D> pidns.as_ptr(), @@ -268,6 +274,7 @@ pub fn tgid_nr_ns(&self, pidns: Option<&PidNamespace>) = -> Pid { } =20 /// Wakes up the task. + #[inline] pub fn wake_up(&self) { // SAFETY: It's always safe to call `wake_up_process` on a valid t= ask, even if the task // running. @@ -341,11 +348,13 @@ pub fn active_pid_ns(&self) -> Option<&PidNamespace> { =20 // SAFETY: The type invariants guarantee that `Task` is always refcounted. unsafe impl crate::types::AlwaysRefCounted for Task { + #[inline] fn inc_ref(&self) { // SAFETY: The existence of a shared reference means that the refc= ount is nonzero. unsafe { bindings::get_task_struct(self.as_ptr()) }; } =20 + #[inline] unsafe fn dec_ref(obj: ptr::NonNull) { // SAFETY: The safety requirements guarantee that the refcount is = nonzero. unsafe { bindings::put_task_struct(obj.cast().as_ptr()) } --=20 2.39.5 (Apple Git-154) From nobody Wed Oct 8 19:23:12 2025 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 A33F71EF0A6; Wed, 25 Jun 2025 05:15:30 +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=1750828532; cv=none; b=Y9redG6vhuWNgRNBv1QznQ89z7pi4ZAXxAGMzNIx5ZaEylxCYoIkRqIeoxnlcnSovvopZloQITkR03A1/6IsyOvj6B48bWFgU7Dnz8PoNlU50UFL3ROM//xZ0tiGAPmPgQW/0J0KpeZLe9BnhwYD3aquODEwt4ruHVpHtcYINFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750828532; c=relaxed/simple; bh=7P9OHFktnHehT6/0WfESnN3+d/wQTpA8ehdmH59U66Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kckly70Rpy9tSx2qyzqxLvgsjcVkEcQP6pfWaeyazdHSVoZ/QdN2lxC/tdCrK2GfgHx47CujLX76k+qukWKA0h3ZZFYJgpA6nHtsGgf9MGopxiQUjHXSOZKYID1eSxZZd+wza2zML7OC+f/Y0cTf9GKzePan4UXTO3ql4gCwDqU= 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=HayMAqCH; 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="HayMAqCH" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7d38ddc198eso674873285a.1; Tue, 24 Jun 2025 22:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750828529; x=1751433329; 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=a7iMVxay3WmzLuCq2ZJestj5SyAiKNQShqHsp8//u9g=; b=HayMAqCHpOYz4Osvqeg9UsHSUMIj8wWexMJbNqZaAjucw2tGecmzlFh+r47oA3gRyQ Kj77alAZSBQuv9/LBY3C91zBfR7lLCJ7TzDf4aOUKdhPuzcrqGSj3PBv+yi9dNZSNXoN flgWntgQ0Ten11sO0xmykcSgG2wcEoc7F+yHRN3SNpYcCJPfqiVZR8nXXYbJMOTt5YNZ xdqErPqWYMz0EaS6VXIdca9HQvx11jRCE/EXYW3RkJuN0EITUvdh/K0B6K6t3bpTh7O+ DnNjQMkmA+ScFeD8pXER8Mz+Aar+/3uyghbtwH6fWyxa3LOOvvOugSN4P/tWFYw9jTQE D57A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750828529; x=1751433329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=a7iMVxay3WmzLuCq2ZJestj5SyAiKNQShqHsp8//u9g=; b=WP9r3ezmkYxdGK/2bAicq64UBYsuLlp1YZ2/w7MUN4oGTGQyykr7K5R3E+dsT/TsAK Hh1ULO6QahEOWc++UlQbPOuObdA7+jTCAIh/P5pMiuKnSOaQ7Y2s/vvBHpWNHs7itNef ecfXMGfnKUeUgW6VKexA7aFdJHG0S9LxHKe4INzPwsJIhPWG9TqzY5WqF/jS3D38bHP7 RR5mJks/5C2a6yadCzCXQDQ1JQ0Sh+6g0TzsO6WB6aAO7eQTB7VPNArbakCCBzJtjgST w9ewtmWZNybsq36TMe6YFcYa52SLLNLQef3w6nHCxzIb644DQKRpl9BN67Azuz5iOQy0 t88A== X-Forwarded-Encrypted: i=1; AJvYcCX0A8dvDTYl0AzqCiPyaaEL8v4k+OkpEA2Kvz38K5WCTTwTYkjATkN8mF6iKCWi+ftRR6iHHrlpnrZxlQp2HCw=@vger.kernel.org, AJvYcCXKFncpx4hyUyeg6pwlHB53h4Xh//dl6p7ufZPo5Rhrd3NLXmY1lOqoQrrlvKvM1KPv114gQXLv2BR7lVQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzCIpHwnbe0qLEhEUyYb/OnJ+Qn9WHo7XrnSqyQStDNIzKgOwE7 zTP7xWZuUFCVYYpAN8Z6nu4dEtTf3ptOmevWyUg7BoTgq8Pvsx6z0RFB X-Gm-Gg: ASbGncsjYiQpjfP1BxkOp12Tq/+PNBXjzIuNJ5GTV68493XvxfZw7C5XEgN8sxiz8i2 hfBFSXGwRzt4Mj1YJPM+Zlm1DPVaLHdesG7UG20h0ITkGOuiDToC/PoZi4VoR6qiGBxIke2NzAU ic0Bpxq6BnMSVjkGUmKvoTmfreEy8Jc9f1hgs9bLWsU1vgCgYmBxFq5jiEK+mjKntwSaKeyMK3b EbFtf1Go8rBMeQ6F4nQaOhgrnW22dX+GxnBLcYySv9aFS/F0C13445SoHth30snYmhtBi9I/aBU DJ9KEFIdxwfcx2QrQPwreNVJvERKqOCIpHNNgNa7QcR+5D1jgCv2ROJLFmHuV9Ox375+O6zPJtO 6gCOsnEot2ZbU/lDtecWa9dhQ143OtUG4CgTHzo4uGUjbCgkQONks X-Google-Smtp-Source: AGHT+IH5eh5NyDryLi2CVj0oAVK7jawM/QHsz+yh19M5+tyWzNSi5g3PazROuvwLLJau2orQReIvNg== X-Received: by 2002:a05:620a:801b:b0:7d3:f0a3:d8cc with SMTP id af79cd13be357-7d4297487dbmr254922785a.45.1750828529411; Tue, 24 Jun 2025 22:15:29 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fd095bc554sm64286026d6.117.2025.06.24.22.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 22:15:29 -0700 (PDT) Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfauth.phl.internal (Postfix) with ESMTP id 40EBEF40066; Wed, 25 Jun 2025 01:15:28 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Wed, 25 Jun 2025 01:15:28 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddvgddvudeltdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhepkeetteejgeduieekudejfedvvddtiefgieffffeljeefieehiefffedvfeffgfet necuffhomhgrihhnpehgihhthhhusgdrtghomhdpkhgvrhhnvghlrdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgv shhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehhe ehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv pdhnsggprhgtphhtthhopeefhedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepmh hinhhgoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgr uggvrggurdhorhhgpdhrtghpthhtohepmhhinhhgohesrhgvughhrghtrdgtohhmpdhrtg hpthhtohepjhhurhhirdhlvghllhhisehrvgguhhgrthdrtghomhdprhgtphhtthhopehv ihhntggvnhhtrdhguhhithhtohhtsehlihhnrghrohdrohhrghdprhgtphhtthhopeguih gvthhmrghrrdgvghhgvghmrghnnhesrghrmhdrtghomhdprhgtphhtthhopehrohhsthgv ughtsehgohhoughmihhsrdhorhhgpdhrtghpthhtohepsghsvghgrghllhesghhoohhglh gvrdgtohhmpdhrtghpthhtohepmhhgohhrmhgrnhesshhushgvrdguvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jun 2025 01:15:26 -0400 (EDT) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , FUJITA Tomonori , Tamir Duberstein , Kunwu Chan , Mitchell Levy , Martin Rodriguez Reboredo , Borys Tyran , Christian Brauner , Panagiotis Foliadis , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 4/5] rust: Introduce file_from_location() Date: Tue, 24 Jun 2025 22:15:17 -0700 Message-Id: <20250625051518.15255-5-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250625051518.15255-1-boqun.feng@gmail.com> References: <20250625051518.15255-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: quoted-printable Content-Type: text/plain; charset="utf-8" Most of kernel debugging facilities take a nul-terminated string for file names for a callsite (generated from __FILE__), however the Rust courterpart, Location, would return a Rust string (not nul-terminated) from method .file(). And such a string cannot be passed to C debugging function directly. There is ongoing work to support a Location::file_with_nul() [1], which returns a nul-terminated string from a Location. Since it's still working in progress, and it will take some time before the feature finally gets stabilized and the kernel's minimal rustc version might also take a while to bump to a version that at least has that feature, introduce a file_from_location() function, which returns a warning string if Location::file_with_nul() is not available. This should work in most cases because as for now the known usage of Location::file_with_nul() is only in debugging code (e.g. might_sleep()) and there might be other information reported by the debugging code that could help locate the problematic function, so missing the file name is fine at the moment. Link: https://github.com/rust-lang/rust/issues/141727 [1] Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250619151007.61767-2-boqun.feng@gmail.com --- init/Kconfig | 3 +++ rust/kernel/lib.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index af4c2f085455..6f4ec5633ffa 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -142,6 +142,9 @@ config RUSTC_HAS_SPAN_FILE config RUSTC_HAS_UNNECESSARY_TRANSMUTES def_bool RUSTC_VERSION >=3D 108800 =20 +config RUSTC_HAS_FILE_WITH_NUL + def_bool RUSTC_VERSION >=3D 108900 + config PAHOLE_VERSION int default $(shell,$(srctree)/scripts/pahole-version.sh $(PAHOLE)) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 6b4774b2b1c3..717a5b6160ca 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -40,6 +40,10 @@ #![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(coerce_unsized))] #![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(dispatch_from_dy= n))] #![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(unsize))] +// +// `feature(file_with_nul)` is expected to become stable. Before Rust 1.89= .0, it did not exist, so +// enable it conditionally. +#![cfg_attr(CONFIG_RUSTC_HAS_FILE_WITH_NUL, feature(file_with_nul))] =20 // Ensure conditional compilation based on the kernel configuration works; // otherwise we may silently break things like initcall handling. @@ -274,3 +278,47 @@ macro_rules! asm { ::core::arch::asm!( $($asm)*, $($rest)* ) }; } + +/// Gets the C string file name of a [`Location`]. +/// +/// If `file_with_nul()` is not available, returns a string that warns abo= ut it. +/// +/// [`Location`]: core::panic::Location +/// +/// # Examples +/// +/// ``` +/// # use kernel::file_from_location; +/// +/// #[track_caller] +/// fn foo() { +/// let caller =3D core::panic::Location::caller(); +/// +/// // Output: +/// // - A path like "rust/kernel/example.rs" if file_with_nul() is av= ailable. +/// // - "" otherwise. +/// let caller_file =3D file_from_location(caller); +/// +/// // Prints out the message with caller's file name. +/// pr_info!("foo() called in file {caller_file:?}\n"); +/// +/// # if cfg!(CONFIG_RUSTC_HAS_FILE_WITH_NUL) { +/// # assert_eq!(Ok(caller.file()), caller_file.to_str()); +/// # } +/// } +/// +/// # foo(); +/// ``` +#[inline] +pub fn file_from_location<'a>(loc: &'a core::panic::Location<'a>) -> &'a c= ore::ffi::CStr { + #[cfg(CONFIG_RUSTC_HAS_FILE_WITH_NUL)] + { + loc.file_with_nul() + } + + #[cfg(not(CONFIG_RUSTC_HAS_FILE_WITH_NUL))] + { + let _ =3D loc; + c"" + } +} --=20 2.39.5 (Apple Git-154) From nobody Wed Oct 8 19:23:12 2025 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (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 0C5FA1F5827; Wed, 25 Jun 2025 05:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750828535; cv=none; b=Beyurn/6aWdkHCh8uqg6HHHkMLPCCBGQhWm3lZdnNd+eB5NFO7OhxwbJHggvRoKhws4bFJUdS7IAIbCOYo1SOwxoLIdpaWfsYHJt8FzyA6r0HhDlDAvQySMQCUuA4pSGAXLnyaK7naJMSWKFC7BxAHq34C2gFIa76WRHuj6gQP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750828535; c=relaxed/simple; bh=VBOn77Pw4+tme4JesglES2sMUF30+bd7R7k26+boK2k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mnH6UVxaidFDUVUDSAuS+zyVUAVzxwORS7q74UHm/lj2CtCwgsKTKDtf18ekxp5ILN71QQc5stfC9ZEBRIKRGtN3U2zB3kK8QBIxHPRzgXPk8KUy0d5YAkAshJTsMHUbBMarXgRJQsQMqfXKWFVBQxVCQxUwtHG8DrxPq42P3gw= 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=HjkxyFau; arc=none smtp.client-ip=209.85.219.49 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="HjkxyFau" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6facc3b9559so95389286d6.0; Tue, 24 Jun 2025 22:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750828533; x=1751433333; 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=jPHPiLn+shRnXPTS0LeS5dHvFwnPQLKTW28CIznWwTs=; b=HjkxyFau48fihkAR62Y6uhrQs9FITGpIxMG65DHaBMCDasBSYgzLnMcbgdNUDyiqif YLPvIPaVogkPd2oRuVQw5GKfTI81nH4v5BT7zAHYyDYyriVp6en9RYQQIQVNKx5I+8CD 0KTSplj0Z2wjYLdVlyvLOQajkFXFVTxJ3I61Mmb5hs9mdXksuIUaTnGdEVeHQuuqd/xZ v2nLD3y/mZOJfsp9TcXuURINbltDEAN044tBs/MPT2T9PceTLGH9GWM0dZYLG93RBcyN PhSg0GFIqzZJhcS/EkysjehuBbd+T1Pu3EalfSSgXcc06r27VDhpgtBkWACtKAkZ2SZ3 XhLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750828533; x=1751433333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jPHPiLn+shRnXPTS0LeS5dHvFwnPQLKTW28CIznWwTs=; b=hQfz2cGn00OOkDSrQuK4zmP3KcWkLIKaTjHSqx8zTuMWtZEzQShl1lHaqQyTGXaBxp TJNXaEQtbUeChTCdIHNFSC0osaP+E4mHyfbCcddGh0/TbLwnszbP04fQLLGpSEft8fqp enXeq5nk4zaxT0wbwWe9YsU7ohJzid8BA/0ufdCXxM2roh/eUVpC7WAK2BZjWNsvEi/5 olRF4+tc8/fLnpFXjgtaJJFQfsFlsKqoy0pTVuku30ULM7YO7HYKGOnpJzIFTCg5nBbq vBu1IJQFVu1XNC10fsQF7O7WX2fMF+KIexBLFW0vS6jqGOWHWxMZ0Z1FIw533EBMzpPu 5Qmg== X-Forwarded-Encrypted: i=1; AJvYcCVJjQN6ABttNXtu7GpIaHIdHFF5lcXNzIS+fn2m0v65JcyOEvro4cNJmUelo+uexiUg6CWEkCp7+VUoaZQ=@vger.kernel.org, AJvYcCXwuBOyUaIffdgj9c3cS8Wpp3GmDpPN1ItXPYTduG8qEbfklECJ8c0d7p4xptclCMLDfwFOcTsproY7Ha81J80=@vger.kernel.org X-Gm-Message-State: AOJu0YzXDD/hFVM+AqkAEU/JkB0yHTGtg5dapgnteZKe/QJqRHtPMmdh DpiVS58x/26jaCxM5vTc2wniPDA/KTBygQQEgsErvYXWeMhOkwA6tDrz X-Gm-Gg: ASbGncuV8mUTbkMAZ8GbgcUm+ofPnFZj38uQ1p3tA6SBy5Vei9SPs+jywh/7xo/to1f xlbyalC/E8a4ROtBZNcywrQPrR63P7xtREfZqDRElTnzrpBWAfEGLgVnEsxcn3Cz6lGpH3zzzTU 30EY77P8ojA5O/JX55V7HNPt3FFGqt9+dcmSHcjUlykZi2VBqNAt9uu2ZzIE/jRPf74TYm08vE+ h0P0K1dQeZxZdWC0XXdVONpRCXzA3jlxcpYMOi1d9WD+Vf3Bz675QlGKeINdCheiaSbr8J1uSZ2 q6ZYq6wm4qyFGKgh0kJ6bpOIkjzmh9QQz0lTQp0kpV8R9u26459bUrHgQ0lrMwHJX05rOh4mA+k Vi+hrYY/AqAl8k1IRmpyaSMEKJWFaq4FU9e3sog1gQUUdW0684yjy X-Google-Smtp-Source: AGHT+IFait6Cui768Cq84nzBcA7GCns6Fe7QqQseb3Vb4z41dIqYjDzEjvA0QzsRI6znLXw9/crJRw== X-Received: by 2002:a05:6214:258f:b0:6fa:b42b:2bd9 with SMTP id 6a1803df08f44-6fd5efa0ff3mr27794456d6.37.1750828532649; Tue, 24 Jun 2025 22:15:32 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fd09578243sm64267716d6.91.2025.06.24.22.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 22:15:32 -0700 (PDT) Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfauth.phl.internal (Postfix) with ESMTP id 645C8F40066; Wed, 25 Jun 2025 01:15:31 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Wed, 25 Jun 2025 01:15:31 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddvgddvudeltdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhepgffhffevhffhvdfgjefgkedvlefgkeegveeuheelhfeivdegffejgfetuefgheei necuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghr shhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvg hngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvgdpnhgspghrtghpthhtohep feehpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehmihhnghhosehkvghrnhgvlh drohhrghdprhgtphhtthhopehpvghtvghriiesihhnfhhrrgguvggrugdrohhrghdprhgt phhtthhopehmihhnghhosehrvgguhhgrthdrtghomhdprhgtphhtthhopehjuhhrihdrlh gvlhhlihesrhgvughhrghtrdgtohhmpdhrtghpthhtohepvhhinhgtvghnthdrghhuihht thhotheslhhinhgrrhhordhorhhgpdhrtghpthhtohepughivghtmhgrrhdrvghgghgvmh grnhhnsegrrhhmrdgtohhmpdhrtghpthhtoheprhhoshhtvgguthesghhoohgumhhishdr ohhrghdprhgtphhtthhopegsshgvghgrlhhlsehgohhoghhlvgdrtghomhdprhgtphhtth hopehmghhorhhmrghnsehsuhhsvgdruggv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jun 2025 01:15:30 -0400 (EDT) From: Boqun Feng To: Ingo Molnar , Peter Zijlstra Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , FUJITA Tomonori , Tamir Duberstein , Kunwu Chan , Mitchell Levy , Martin Rodriguez Reboredo , Borys Tyran , Christian Brauner , Panagiotis Foliadis , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 5/5] rust: task: Add Rust version of might_sleep() Date: Tue, 24 Jun 2025 22:15:18 -0700 Message-Id: <20250625051518.15255-6-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250625051518.15255-1-boqun.feng@gmail.com> References: <20250625051518.15255-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: FUJITA Tomonori Add a helper function equivalent to the C's might_sleep(), which serves as a debugging aid and a potential scheduling point. Note that this function can only be used in a nonatomic context. This will be used by Rust version of read_poll_timeout(). [boqun: Use file_from_location() to get a C string instead of changing __might_sleep()] Signed-off-by: FUJITA Tomonori Reviewed-by: Alice Ryhl Signed-off-by: Boqun Feng Link: https://lore.kernel.org/r/20250619151007.61767-3-boqun.feng@gmail.com --- rust/helpers/task.c | 6 ++++++ rust/kernel/task.rs | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/rust/helpers/task.c b/rust/helpers/task.c index 31c33ea2dce6..2c85bbc2727e 100644 --- a/rust/helpers/task.c +++ b/rust/helpers/task.c @@ -1,7 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 =20 +#include #include =20 +void rust_helper_might_resched(void) +{ + might_resched(); +} + struct task_struct *rust_helper_get_current(void) { return current; diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs index 834368313088..7d0935bc325c 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -400,3 +400,27 @@ fn eq(&self, other: &Kuid) -> bool { } =20 impl Eq for Kuid {} + +/// Annotation for functions that can sleep. +/// +/// Equivalent to the C side [`might_sleep()`], this function serves as +/// a debugging aid and a potential scheduling point. +/// +/// This function can only be used in a nonatomic context. +/// +/// [`might_sleep()`]: https://docs.kernel.org/driver-api/basics.html#c.mi= ght_sleep +#[track_caller] +#[inline] +pub fn might_sleep() { + #[cfg(CONFIG_DEBUG_ATOMIC_SLEEP)] + { + let loc =3D core::panic::Location::caller(); + let file =3D kernel::file_from_location(loc); + + // SAFETY: `file.as_ptr()` is valid for reading and guaranteed to = be nul-terminated. + unsafe { crate::bindings::__might_sleep(file.as_ptr().cast(), loc.= line() as i32) } + } + + // SAFETY: Always safe to call. + unsafe { crate::bindings::might_resched() } +} --=20 2.39.5 (Apple Git-154)