public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Timur Tabi" <ttabi@nvidia.com>
Cc: "John Hubbard" <jhubbard@nvidia.com>,
	"gary@garyguo.net" <gary@garyguo.net>,
	"mmaurer@google.com" <mmaurer@google.com>,
	"rust-for-linux@vger.kernel.org" <rust-for-linux@vger.kernel.org>,
	"nouveau@lists.freedesktop.org" <nouveau@lists.freedesktop.org>,
	"dakr@kernel.org" <dakr@kernel.org>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"aliceryhl@google.com" <aliceryhl@google.com>
Subject: Re: [PATCH v8 3/7] rust: dma: implement BinaryWriter for CoherentAllocation<u8>
Date: Mon, 16 Mar 2026 12:44:39 +0900	[thread overview]
Message-ID: <DH3WB8IAXW6L.28B8V0DXXXU5G@nvidia.com> (raw)
In-Reply-To: <26a6d9f2f22603a71f36f73c98590aa1a0077a95.camel@nvidia.com>

On Mon Mar 16, 2026 at 3:57 AM JST, Timur Tabi wrote:
> On Sun, 2026-03-15 at 14:11 +0900, Alexandre Courbot wrote:
>> > Well, yes, but there's actually a bigger problem, now that you point this out.  If usize is
>> > 32
>> > bits, the try_into() could fail if *offset is too large.  In that case, it should return
>> > Ok(0)
>> > instead of EINVAL.
>> > 
>> > So actually, we need to keep the is_negative() check, but should modify the try_into() to
>> > return
>> > Ok(0) instead of EINVAL.
>> > 
>> > let Ok(offset_val) = usize::try_from(*offset) else {
>> >      return Ok(0);  // offset too large for usize = past EOF
>> > };
>> > 
>> > Are we going to assume CONFIG_64BIT forever, and just ignore any possible errors if usize is
>> > 32
>> > bits?
>> 
>> This is not Nova, so we cannot assume CONFIG_64BIT. I guess we have to
>> do as you described above.
>
> Yes, you're right.  I forgot that this was common code.  
>
> Still, I wonder.  It seems incongruous to me that, on a 32-bit platform, offsets (file::Offset)
> are 64-bit but sizes (usize) are only 32-bit. 

`file::Offset` maps to the C's `loff_t` which is a version of `off_t`
that is guaranteed to be 64-bit. The kernel core APIs (like
`file_operations` seem to all use `loff_t`, so it makes sense for Rust
to follow suit.

I suppose the kernel uses `loff_t` everywhere where files are involved
because without that it wouldn't be able to manage files larger than
2GB. With that in mind, the extra check when converting to a 32-bit
pointer makes more sense.

  reply	other threads:[~2026-03-16  3:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 21:59 [PATCH v8 0/7] gpu: nova-core: expose the logging buffers via debugfs Timur Tabi
2026-03-10 21:59 ` [PATCH v8 1/7] rust: device: add device name method Timur Tabi
2026-03-10 22:05   ` Alice Ryhl
2026-03-13  2:10   ` Alexandre Courbot
2026-03-10 21:59 ` [PATCH v8 2/7] rust: uaccess: add write_dma() for copying from DMA buffers to userspace Timur Tabi
2026-03-11  5:48   ` kernel test robot
2026-03-13  2:11   ` Alexandre Courbot
2026-03-10 21:59 ` [PATCH v8 3/7] rust: dma: implement BinaryWriter for CoherentAllocation<u8> Timur Tabi
2026-03-13  2:11   ` Alexandre Courbot
2026-03-14  2:05     ` Timur Tabi
2026-03-15  5:11       ` Alexandre Courbot
2026-03-15 18:57         ` Timur Tabi
2026-03-16  3:44           ` Alexandre Courbot [this message]
2026-03-10 21:59 ` [PATCH v8 4/7] gpu: nova-core: Replace module_pci_driver! with explicit module init Timur Tabi
2026-03-10 21:59 ` [PATCH v8 5/7] gpu: nova-core: use pin projection in method boot() Timur Tabi
2026-03-13  2:13   ` Alexandre Courbot
2026-03-14  2:20     ` Timur Tabi
2026-03-10 21:59 ` [PATCH v8 6/7] gpu: nova-core: create debugfs root in module init Timur Tabi
2026-03-10 22:00 ` [PATCH v8 7/7] gpu: nova-core: create GSP-RM logging buffers debugfs entries Timur Tabi
2026-03-10 22:20 ` [PATCH v8 0/7] gpu: nova-core: expose the logging buffers via debugfs John Hubbard
2026-03-12  3:50 ` John Hubbard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DH3WB8IAXW6L.28B8V0DXXXU5G@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=mmaurer@google.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=ttabi@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox