From: Danilo Krummrich <dakr@kernel.org>
To: 崔光博 <2407018371@qq.com>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
Alice Ryhl <aliceryhl@google.com>,
daniel.almeida@collabora.com, a.hindborg@kernel.org,
alex.gaynor@gmail.com, benno.lossin@proton.me,
bjorn3_gh@protonmail.mco, boqun.feng@gmail.com,
boris.brezillon@collabora.com, gary@garyguo.net,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
ojeda@kernel.org, rafael@kernel.org, robh@kernel.org,
rust-for-linux@vger.kernel.org, tmgross@umich.edu
Subject: Re: [PATCH v6 2/3] rust: io: mem: add a generic iomem abstraction
Date: Thu, 6 Feb 2025 18:13:03 +0100 [thread overview]
Message-ID: <Z6Ttn83DQ_8asHXl@cassiopeiae> (raw)
In-Reply-To: <tencent_E1DC219DB45DC03A8454E2124D238DCEC705@qq.com>
On Fri, Feb 07, 2025 at 12:40:14AM +0800, 崔光博 wrote:
>
>
> > 2025年2月7日 00:11,Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> 写道:
> >
> > On Thu, Feb 6, 2025 at 4:59 PM Guangbo Cui <2407018371@qq.com> wrote:
> >>
> >> With CONFIG_RUST_BUILD_ASSERT_ALLOW=y enabled, this compilation succeeds.
> >
> > Yes, that is expected too (but note that the config option is there
> > just in case -- it should not happen that it is needed in normal
> > builds).
> >
> >> Even if the size is determined at compile time, the compilation will still fail
> >> if CONFIG_RUST_BUILD_ASSERT_ALLOW is not enabled.
> >
> > Yes, that is expected -- the idea is that you cannot make the mistake
> > of calling those.
> >
> > I think you are suggesting only exposing the methods in the case where
> > calling them would work? That would be great if a design allows for
> > it, of course.
>
> Yes, if the methods could not work, we should not expose them.
>
> > By the way, Daniel, in patch 3/3 there is this comment:
> >
> > + /// // Unlike `ioremap_resource_sized`, here the size of the
> > memory region
> > + /// // is not known at compile time, so only the `try_read*`
> > and `try_write*`
> > + /// // family of functions are exposed, leading to runtime
> > checks on every
> > + /// // access.
> >
> > Is the "only ... are exposed" correct? i.e. are they exposed? / is
> > this potentially confusing?
>
> They are exposed. If size is not known at compile time, calling the `read`
> and `write` will never compile failed. Example:
That's two different things here. Miguel questions whether the comment is
correct. And I think it's not, they are indeed exposed.
>
> ```C
> let raw_io: IoRaw<0> = IoRaw::new(0, 8)?;
> let io = unsafe { Io::from_raw(&raw_io) };
> io.writeb(0xff, 0xffff);
> ```
> If I make any mistakes, please correct me. Thanks!
This behavior is on purpose.
IoRaw::new() is equivalent to IoRaw::<0>::new(), which means that you set the
compile time validated size of the I/O region to zero.
Hence, calling writeb() fails, because every operation exeeds the boundary of
zero.
In your case the runtime boundary is 8, hence the following calls do succeed.
try_readb(0);
try_readb(7);
Whereas the following would fail on runtime.
try_readb(8);
>
> Best regards,
> Guangbo Cui
>
next prev parent reply other threads:[~2025-02-06 17:13 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 22:05 [PATCH v6 0/3] rust: platform: add Io support Daniel Almeida
2025-01-30 22:05 ` [PATCH v6 1/3] rust: io: add resource abstraction Daniel Almeida
2025-01-31 10:02 ` Daniel Sedlak
2025-02-09 11:45 ` Guangbo Cui
2025-01-30 22:05 ` [PATCH v6 2/3] rust: io: mem: add a generic iomem abstraction Daniel Almeida
2025-01-31 10:09 ` Daniel Sedlak
2025-02-02 22:45 ` Asahi Lina
2025-02-03 9:26 ` Alice Ryhl
2025-02-03 14:14 ` Asahi Lina
2025-02-03 9:32 ` Alice Ryhl
2025-02-05 14:56 ` Guangbo Cui
2025-02-06 15:43 ` Alice Ryhl
2025-02-06 15:58 ` Miguel Ojeda
2025-02-06 15:58 ` Guangbo Cui
2025-02-06 16:11 ` Miguel Ojeda
[not found] ` <tencent_E1DC219DB45DC03A8454E2124D238DCEC705@qq.com>
2025-02-06 17:13 ` Danilo Krummrich [this message]
2025-02-07 13:25 ` Daniel Almeida
2025-02-06 15:57 ` Daniel Almeida
2025-02-06 16:05 ` Miguel Ojeda
2025-04-01 15:57 ` Joel Fernandes
2025-04-01 16:44 ` Danilo Krummrich
2025-04-01 17:07 ` Joel Fernandes
2025-01-30 22:05 ` [PATCH v6 3/3] rust: platform: allow ioremap of platform resources Daniel Almeida
2025-01-31 10:19 ` Daniel Sedlak
2025-01-31 11:36 ` Alice Ryhl
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=Z6Ttn83DQ_8asHXl@cassiopeiae \
--to=dakr@kernel.org \
--cc=2407018371@qq.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.mco \
--cc=boqun.feng@gmail.com \
--cc=boris.brezillon@collabora.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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).