From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1EFE02E3361; Tue, 22 Jul 2025 12:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753188579; cv=none; b=dbai6WvVwm2TdDZwFRqxpNQaT1Bb8U1dQ05iooLBUn8u1z+ueQaT478g6pKUiQRz7RMyKdIkh4HBwFPPwGdUkR8U08vuoj+r1NMLexW3cAtG5EGSr0Ym//FdwxViV7FvOA1lSZRNnIV0T6cmZcIjHTN52p+C7X+mIo7DC2MQ2FY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753188579; c=relaxed/simple; bh=oNwMiBXgoxAtXhsHS6DKVIyV2eUv8rV5AOhnRZAWJ2E=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=R9/oWEtuC+O1J2GUwem6W9lV2d6liskg3RvH+czQTeeXi/6cvs6hPwfjXK3QFhqUcNYT763CNYLm3RECocAxCqgz7hxnKBP/IHxtxd26AIa6nqe0waTwHIjd4SLZ1/i7otDauXRB5bLn0SYOakSqVLNpFZPv5uZqdJgQR8ceKJY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JtyPEni2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JtyPEni2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15FF1C4CEEB; Tue, 22 Jul 2025 12:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753188578; bh=oNwMiBXgoxAtXhsHS6DKVIyV2eUv8rV5AOhnRZAWJ2E=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=JtyPEni2pn3zIZBbMRXsPZRCZxDuIZH+7lkzf9SixKAErZdKqkxbHXKyC5BNPKQrQ jKcmHIlHtAAEvKsGQEtFbKESYHoFWSsZIbWVUGGknV0ZGcDJw1Mfjd6F/GwFd+ub6+ 4G0cpruII5Etz3YAjHMXvaGJGkxlWT2cbx1FLzpUC8J8vx5QQP9cpwHqxj1a+9eJ4k dArNEBEpCx3acyQ15vyMWH4FadVVBoekvdVSKnWlL+nbsNqOsd0g6LDLakRgPRLi/t McOzDVtORpMv7PMbqlwkgi+qmETPr/PeZzklNhZKsn+2mvf6WDybNFBg2UnDYDJlUt h3F9uOCTLxSBQ== 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 Date: Tue, 22 Jul 2025 14:49:33 +0200 Message-Id: Subject: Re: [PATCH v2 1/2] rust: Update PCI binding safety comments and add inline compiler hint Cc: "Alice Ryhl" , "Alistair Popple" , , "Bjorn Helgaas" , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Andreas Hindborg" , "Trevor Gross" , "Greg Kroah-Hartman" , "Rafael J. Wysocki" , "John Hubbard" , "Alexandre Courbot" , , To: "Benno Lossin" From: "Danilo Krummrich" References: <20250710022415.923972-1-apopple@nvidia.com> In-Reply-To: On Tue Jul 22, 2025 at 2:08 PM CEST, Benno Lossin wrote: > On Tue Jul 22, 2025 at 1:35 PM CEST, Alice Ryhl wrote: >> On Tue, Jul 22, 2025 at 12:57=E2=80=AFPM Benno Lossin wrote: >>> >>> On Tue Jul 22, 2025 at 11:51 AM CEST, Danilo Krummrich wrote: >>> > I think they're good, but we're pretty late in the cycle now. That sh= ould be >>> > fine though, we can probably take them through the nova tree, or in t= he worst >>> > case share a tag, if needed. >>> > >>> > Given that, it would probably be good to add the Guarantee section on= as_raw(), >>> > as proposed by Benno, right away. >>> > >>> > @Benno: Any proposal on what this section should say? >>> >>> At a minimum I'd say "The returned pointer is valid.", but that doesn't >>> really say for what it's valid... AFAIK you're mostly using this pointe= r >>> to pass it to the C side, in that case, how about: >>> >>> /// # Guarantees >>> /// >>> /// The returned pointer is valid for reads and writes from the C s= ide for as long as `self` exists. >>> >>> Maybe we need to change it a bit more, but let's just start with this. >>> >>> (If you're also using the pointer from Rust, then we need to make >>> changes) >> >> Honestly I think this is a bit over the top. I wouldn't bother adding >> a section like that to every single as_raw() method out there. > > Hmm. And then just assume that these kinds of functions return valid > pointers? I get that this is annoying to put on every function... > > Another option would be to have a `Ptr<'a, T>` type that is a valid > pointer, but doesn't allow writing/reading safely (you need to justify > why it's not a data race). And for FFI there could be an `as_ptr` > function. I don't understand where's the difference between the two. For FFI calls we= 'd also have to justify it's not a data race, no? The only guarantee we take as granted from as_raw() is that it returns a ra= w pointer to the wrapped FFI type in Self, i.e. it points to valid memory. An= y additional guarantees may come from the context where the pointer is used a= nd which specific fields it is used to access.