Re: [PATCH v5 02/20] rust: io: add missing safety requirement in `IoCapable` methods

From: Gary Guo

Date: Sun Jul 05 2026 - 12:45:27 EST


On Sun Jul 5, 2026 at 2:59 PM BST, Alexandre Courbot wrote:
> On Fri Jul 3, 2026 at 10:49 PM JST, Gary Guo wrote:
>> On Fri Jul 3, 2026 at 2:09 PM BST, Alexandre Courbot wrote:
>>> On Fri Jul 3, 2026 at 9:35 PM JST, Gary Guo wrote:
>>>> On Fri Jul 3, 2026 at 3:57 AM BST, Alexandre Courbot wrote:
>>>>> On Fri Jun 26, 2026 at 11:45 PM JST, Gary Guo wrote:
>>>>> <...>
>>>>>> @@ -309,7 +312,11 @@ pub trait Io {
>>>>>> // Always inline to optimize out error path of `build_assert`.
>>>>>> #[inline(always)]
>>>>>> fn io_addr_assert<U>(&self, offset: usize) -> usize {
>>>>>> - build_assert!(offset_valid::<U>(offset, Self::Target::MIN_SIZE));
>>>>>> + // We cannot check alignment with `offset_valid` using `self.addr()`. So set 0 for it and
>>>>>> + // ensure alignment by checking that the alignment of `U` is smaller or equal to the
>>>>>> + // alignment of `Self::Target`.
>>>>>> + const_assert!(Alignment::of::<U>().as_usize() <= Self::Target::MIN_ALIGN.as_usize());
>>>>>
>>>>> With `Region::MIN_ALIGN` being `4`, my understanding is that this will
>>>>> make `read64` and other infallible 64-bit accessors unusable on untyped
>>>>> I/O regions?
>>>>
>>>> That's correct.
>>>
>>> Isn't that a limitation we may want to eventually address? The fallible
>>> accessors are still usable, but it seems arbitrary that the non-fallible
>>> ones stop at 32 bits...
>>
>> It'd probably be solved by having typed regions. 32-bit is the most common
>> alignment for I/O memory, so that's chosen.
>>
>> None of the existing Rust drivers require 64-bit accessors yet.
>
> Mmm I'd like to see whether we can't make it work for untyped regions as
> well, but since we don't have many users (nor do we expect many to come
> I guess) this can be a follow-up.
>
> Reviewed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>

See https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Generic.20I.2FO.20backends/near/601402429

However, I'd prefer we eventually use typed regions.

Best,
Gary