From: "Danilo Krummrich" <dakr@kernel.org>
To: "Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>,
"Marko Turk" <mt@markoturk.info>
Cc: "Dirk Behme" <dirk.behme@de.bosch.com>, <bhelgaas@google.com>,
<kwilczynski@kernel.org>, <linux-pci@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH] samples: rust: fix endianness issue in rust_driver_pci
Date: Thu, 13 Nov 2025 19:36:43 +1100 [thread overview]
Message-ID: <DE7FHUVN5QE0.3ECM9JKXUNWFW@kernel.org> (raw)
In-Reply-To: <DE7F6RR1NAKW.3DJYO44O73941@kernel.org>
On Thu Nov 13, 2025 at 7:22 PM AEDT, Danilo Krummrich wrote:
> On Wed Nov 12, 2025 at 8:56 PM AEDT, Miguel Ojeda wrote:
>> I guess we could potentially consider something like returning a
>> wrapper to force us to explicitly pick either LE or BE to prevent
>> things like this.
>
> In general, the I/O backend (e.g. MMIO, I2C, etc.) is supposed to take care
> of endianness.
>
> In the case of MMIO we (currently) always assume that the device is
> little-endian; this is also what the C functions used to implement the MMIO
> backend (e.g. readl()) assume, i.e. they always convert from little-endian to
> CPU endianness.
I.e. if we'd support a big-endian architecture in Rust
u32::from_le(bar.read32())
would be a bug.
> I don't think we should do anything else; the cases where we need to deal with
> big-endian devices for MMIO should be extremely rare -- rare enough that there
> aren't even corresponding *_be() implementations for all architectures.
>
> Given that, I think the proper fix is to drop the existing u32::from_le() call
> (that ended up in the sample driver by accident) and properly document the
> little-endian assumption of the MMIO backend.
>
> (Currently, this simply is the Io structure, but there is a patch series [1]
> from Zhi splitting things up, so we can start supporting arbitrary I/O
> backends.)
>
> @Marko: Two separate patches for this would be very welcome. :)
>
> [1] https://lore.kernel.org/all/20251110204119.18351-1-zhiw@nvidia.com/
next prev parent reply other threads:[~2025-11-13 8:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20251101214629.10718-1-mt@markoturk.info>
2025-11-12 8:45 ` [PATCH] samples: rust: fix endianness issue in rust_driver_pci Marko Turk
2025-11-12 9:37 ` Miguel Ojeda
2025-11-12 9:56 ` Miguel Ojeda
2025-11-13 8:22 ` Danilo Krummrich
2025-11-13 8:27 ` Miguel Ojeda
2025-11-13 8:36 ` Danilo Krummrich [this message]
2025-11-12 10:16 ` Dirk Behme
2025-11-12 10:24 ` Marko Turk
2025-11-12 10:24 ` Miguel Ojeda
2025-11-13 5:48 ` Dirk Behme
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=DE7FHUVN5QE0.3ECM9JKXUNWFW@kernel.org \
--to=dakr@kernel.org \
--cc=bhelgaas@google.com \
--cc=dirk.behme@de.bosch.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=mt@markoturk.info \
--cc=rust-for-linux@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).