From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fout-a6-smtp.messagingengine.com (fout-a6-smtp.messagingengine.com [103.168.172.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DE331FAF1C; Tue, 15 Oct 2024 18:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729017278; cv=none; b=i0pwGxy156yBBf0gBA9u6QEiAA9CMXZaAp/3NzDXLWFI0rytRuoI2gNT/8pyEFFhQlCZcr3Y97mIwYS+ftGuVafwv80FoD7KWwiMQxS3OmkjOyj4P8Z1o1SgCjSQ9x9ZSun7xLgGmCcqKlt2vGdnvLH6yc8lmAhSEo/eurn/w98= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729017278; c=relaxed/simple; bh=5h4yJYD6mj749ehtFoj/pa6R5CAlrx/gSF34IkWjRkM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=cRaC8pq+SCTOBw4XMx6EizvmFxBPRlipAhNwxkOuK5GPaiypypmMF96Csi6fGyI5/fOxggg3Mj/Ue+B3EnQWFwb2d/92QkfyQLyy1fLQFRfHQnGdaIEBCOVREc8Oedl3HVQRFpvOHw32KlgVHlKUswEcE/t73o34PYPI/7YUjyU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ryhl.io; spf=pass smtp.mailfrom=ryhl.io; dkim=pass (2048-bit key) header.d=ryhl.io header.i=@ryhl.io header.b=tvfpz6Tu; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Nfuw7vZb; arc=none smtp.client-ip=103.168.172.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ryhl.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ryhl.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ryhl.io header.i=@ryhl.io header.b="tvfpz6Tu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Nfuw7vZb" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 93CBA138021E; Tue, 15 Oct 2024 14:34:35 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Tue, 15 Oct 2024 14:34:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1729017275; x=1729103675; bh=2ofm0Km157SSWcgNu+R/b0e4iC0q+FyX4UDhyX2UdbU=; b= tvfpz6TuGyrCZm7B2zCL38nXnJZE0OhzUTujPCRl5VsUpkKwnWAt4DxxYaoKMScu M40Cgq5qljrfecrxaUTPYdnuEt4t9gwMd6Lo1u0nAqbZSMqzChpnkrpkQ2xfHHsQ vHvbDbXNehsxSK3GxKhetg+Ww9eYKnV412qPBtTL0nHSFveEoUIUv3KYZYWS6mdr QbTOvmYeeD2aZ+/eQLRwhRH6LB8GNNMUHdCPN1YDgnTC9zYOh2ZUTspbhagjRcaR GB4CWu3glA+AHNhmXgnbyFn6DF2dQWy4stW6EjmGRuyCWjmq9ZAxbBVIp36N1YvV YYdEylVYXP32RUoWdYuoPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1729017275; x= 1729103675; bh=2ofm0Km157SSWcgNu+R/b0e4iC0q+FyX4UDhyX2UdbU=; b=N fuw7vZbh/PDW+w8I9GkfkLs64bs2Szvb6+KLGwEZiW5fPgzalTw9i43nlMFP1epA pp+uiqsjALa7rV0luFR3Zs38Gx/Y477soFQERgLmZgnr2riOjoaf2yoBLYiSH0XT 2bEFzPwBgU8nURBoErODisuZTtVo4LNlP7pzRgjEO1L3YZXP8Dg7Jx5zZkvUESEi rVhZFp1oKr6nysPre/Nh6B/y2Q455fwK27RO+3y/kTOtJIoICcRr7ihywei+pWeK 1sCf2kXWPzkun9iSwZwnxxnycDiLtajH2pZ0kmiLVE4Z10OLhA9oGXKp/+i6iwBa V8PziMjVswkw3lw5yid6Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdegjedguddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddv jeenucfhrhhomheptehlihgtvgcutfihhhhluceorghlihgtvgesrhihhhhlrdhioheqne cuggftrfgrthhtvghrnhepfefguefgtdeghfeuieduffejhfevueehueehkedvteefgfeh hedtffdutdfgudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomheprghlihgtvgesrhihhhhlrdhiohdpnhgspghrtghpthhtohepudehpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopegsohhquhhnrdhfvghnghesghhmrghilhdrtg homhdprhgtphhtthhopegrlhhitggvrhihhhhlsehgohhoghhlvgdrtghomhdprhgtphht thhopegsrhgruhhnvghrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehojhgvuggrse hkvghrnhgvlhdrohhrghdprhgtphhtthhopehvihhrohesiigvnhhivhdrlhhinhhugidr ohhrghdruhhkpdhrtghpthhtohepjhgrtghksehsuhhsvgdrtgiipdhrtghpthhtoheprg hlvgigrdhgrgihnhhorhesghhmrghilhdrtghomhdprhgtphhtthhopehgrghrhiesghgr rhihghhuohdrnhgvthdprhgtphhtthhopegsjhhorhhnfegpghhhsehprhhothhonhhmrg hilhdrtghomh X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Oct 2024 14:34:32 -0400 (EDT) Message-ID: <23a73a6f-160d-4d06-8d45-ec77293ff258@ryhl.io> Date: Tue, 15 Oct 2024 20:37:36 +0200 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] rust: task: adjust safety comments in Task methods To: Boqun Feng , Alice Ryhl Cc: Christian Brauner , Miguel Ojeda , Alexander Viro , Jan Kara , Alex Gaynor , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , linux-fsdevel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org References: <20241015-task-safety-cmnts-v1-1-46ee92c82768@google.com> Content-Language: en-US, da From: Alice Ryhl In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 10/15/24 8:24 PM, Boqun Feng wrote: > On Tue, Oct 15, 2024 at 02:02:12PM +0000, Alice Ryhl wrote: >> The `Task` struct has several safety comments that aren't so great. For >> example, the reason that it's okay to read the `pid` is that the field >> is immutable, so there is no data race, which is not what the safety >> comment says. >> >> Thus, improve the safety comments. Also add an `as_ptr` helper. This >> makes it easier to read the various accessors on Task, as `self.0` may >> be confusing syntax for new Rust users. >> >> Signed-off-by: Alice Ryhl >> --- >> This is based on top of vfs.rust.file as the file series adds some new >> task methods. Christian, can you take this through that tree? >> --- >> rust/kernel/task.rs | 43 ++++++++++++++++++++++++------------------- >> 1 file changed, 24 insertions(+), 19 deletions(-) >> >> diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs >> index 1a36a9f19368..080599075875 100644 >> --- a/rust/kernel/task.rs >> +++ b/rust/kernel/task.rs >> @@ -145,11 +145,17 @@ fn deref(&self) -> &Self::Target { >> } >> } >> >> + /// Returns a raw pointer to the task. >> + #[inline] >> + pub fn as_ptr(&self) -> *mut bindings::task_struct { > > FWIW, I think the name convention is `as_raw()` for a wrapper type of > `Opaque` to return `*mut T`, e.g. `kernel::device::Device`. > > Otherwise this looks good to me. Both names are in use. See e.g. Page and File that use as_ptr. In fact, I was asked to change the name on File *to* as_ptr. Alice