From: Trevor Gross <tmgross@umich.edu>
To: Andrew Lunn <andrew@lunn.ch>
Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>,
rust-for-linux@vger.kernel.org
Subject: Re: [RFC PATCH v1 1/4] rust: core abstractions for network PHY drivers
Date: Sun, 17 Sep 2023 20:49:12 -0400 [thread overview]
Message-ID: <CALNs47sRKxnD1NhJZaoorEZ2xyLjAse23RmkacoPuCiD7Enq=g@mail.gmail.com> (raw)
In-Reply-To: <f55a3e84-3865-432b-b009-c4051f9a3b0b@lunn.ch>
On Sun, Sep 17, 2023 at 3:08 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Sun, Sep 17, 2023 at 02:42:02PM -0400, Trevor Gross wrote:
> > On Sun, Sep 17, 2023 at 11:07 AM Andrew Lunn <andrew@lunn.ch> wrote:
> > > [...]
> > > > If abstraction code just declare a function, a driver always need to
> > > > implement that function.
> > >
> > > Ah, that is not going to scale well. There is something like 250
> > > struct phy_driver at the moment. We keep adding new ops to that
> > > structure. I really don't want to have to modify all 250 of those
> > > structures when i add a new op which only one or two drivers need.
> >
> > This concern is about adding a function pointer field to the C struct
> > without needing to update all future Rust drivers, correct?
>
> Partially. Assuming Rust is successful, and in 10 years time we have
> 250 devices supported by Rust, i also don't want to have to edit all
> 250 entries when a new member is added to the Rust version of struct
> phy_driver.
> [...]
> O.K, that is the behaviour we want, in terms of NULL, or a driver
> specific function pointer.
Currently if you add a field to the struct in C, everything in Rust
will continue to work without changes. If you want to be able to use
it in the Rust side, you need to update both the `Driver` trait and
`fn driver(&self) -> bindings::phy_driver` [1] but none of the
implementations.
> A follow up question to this. This currently does not apply to PHY
> drivers, but the concept of a structure of function pointers and maybe
> a few other data fields exists all over the kernel. There has been an
> effort to make them all const, so the C compiler puts them in the
> .rodata section. The kernel then uses the MMU to protect it, so it
> really is read only. That protects from a class to attacks where a
> function pointer gets overwritten and then jumped through.
>
> Can Rust create these structures read only in the .rodata section? Can
> this driver actually do this, which would be an improvement over the
> current C PHY drivers?
>
> Andrew
Generally, this should be possible. Any function marked `const` can be
assigned to a static:
const fn make_device() -> Device {
todo!()
}
#[no_mangle]
static _some_driver: Device = make_device();
That function can only call other const functions, but I don't think
that is a problem here. A caveat is that in a simple test I'm trying,
anything that contains a function pointer seems to go into `.data`
instead of `.rodata`. I'm trying to figure out why this but will have
to get back about it.
Is that something you would be interested in for the `phy_driver`? I
may be able to try it out if so, unless Fujita would like to.
`phy_driver_register` doesn't seem to take a pointer to const data,
but I assume it doesn't do any modification?
[1]: Updating `Driver` but not the mapping function would mean that
the default function in `Driver` may get called, but this would
generally be incorrect. That is why I suggested making them default to
something that `BUG()`s, but I'm also not sure what policy is on this.
next prev parent reply other threads:[~2023-09-18 0:49 UTC|newest]
Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 13:36 [RFC PATCH v1 0/4] Rust abstractions for network PHY drivers FUJITA Tomonori
2023-09-13 13:36 ` [RFC PATCH v1 1/4] rust: core " FUJITA Tomonori
2023-09-13 20:11 ` Andrew Lunn
2023-09-13 20:49 ` Boqun Feng
2023-09-13 21:05 ` Andrew Lunn
2023-09-13 21:32 ` Boqun Feng
2023-09-14 4:10 ` Trevor Gross
2023-09-13 22:14 ` Miguel Ojeda
2023-09-14 0:30 ` Andrew Lunn
2023-09-14 11:03 ` Miguel Ojeda
2023-09-14 12:24 ` Andrew Lunn
2023-09-17 9:44 ` FUJITA Tomonori
2023-09-17 10:17 ` FUJITA Tomonori
2023-09-17 15:06 ` Andrew Lunn
2023-09-17 18:42 ` Trevor Gross
2023-09-17 19:08 ` Andrew Lunn
2023-09-18 0:49 ` Trevor Gross [this message]
2023-09-18 1:18 ` Andrew Lunn
2023-09-18 2:22 ` Trevor Gross
2023-09-18 3:44 ` FUJITA Tomonori
2023-09-18 13:13 ` Andrew Lunn
2023-09-18 6:01 ` FUJITA Tomonori
2023-09-14 5:47 ` Trevor Gross
2023-09-14 10:17 ` Jarkko Sakkinen
2023-09-14 19:46 ` Trevor Gross
2023-09-14 12:39 ` Andrew Lunn
2023-09-14 19:42 ` Trevor Gross
2023-09-14 19:53 ` Trevor Gross
2023-09-18 9:56 ` Finn Behrens
2023-09-18 13:22 ` Andrew Lunn
2023-09-18 10:22 ` Benno Lossin
2023-09-18 13:09 ` FUJITA Tomonori
2023-09-18 15:20 ` Benno Lossin
2023-09-19 10:26 ` FUJITA Tomonori
2023-09-20 13:24 ` Benno Lossin
2023-09-13 13:36 ` [RFC PATCH v1 2/4] rust: phy: add module device table support FUJITA Tomonori
2023-09-14 6:26 ` Trevor Gross
2023-09-14 7:23 ` Trevor Gross
2023-09-17 6:30 ` FUJITA Tomonori
2023-09-17 15:13 ` Andrew Lunn
2023-09-13 13:36 ` [RFC PATCH v1 3/4] MAINTAINERS: add Rust PHY abstractions file to the ETHERNET PHY LIBRARY FUJITA Tomonori
2023-09-13 18:57 ` Andrew Lunn
2023-09-17 12:32 ` FUJITA Tomonori
2023-09-19 12:06 ` Miguel Ojeda
2023-09-19 16:33 ` Andrew Lunn
2023-09-22 23:17 ` Trevor Gross
2023-09-23 0:05 ` Miguel Ojeda
2023-09-23 1:36 ` Andrew Lunn
2023-09-23 10:19 ` Miguel Ojeda
2023-09-23 14:42 ` Andrew Lunn
2023-10-09 12:26 ` Miguel Ojeda
2023-09-13 13:36 ` [RFC PATCH v1 4/4] sample: rust: add Asix PHY driver FUJITA Tomonori
2023-09-13 14:11 ` Andrew Lunn
2023-09-13 16:53 ` Greg KH
2023-09-13 18:50 ` Andrew Lunn
2023-09-13 18:59 ` Greg KH
2023-09-13 20:20 ` Andrew Lunn
2023-09-13 20:38 ` Greg KH
2023-09-13 16:56 ` Greg KH
2023-09-13 18:43 ` Andrew Lunn
2023-09-13 19:15 ` Andrew Lunn
2023-09-17 11:28 ` FUJITA Tomonori
2023-09-17 15:46 ` Andrew Lunn
2023-09-18 8:35 ` FUJITA Tomonori
2023-09-18 13:37 ` Andrew Lunn
2023-09-24 9:12 ` FUJITA Tomonori
2023-09-24 9:59 ` Miguel Ojeda
2023-09-24 15:31 ` Andrew Lunn
2023-09-24 17:31 ` Miguel Ojeda
2023-09-24 17:44 ` Andrew Lunn
2023-09-24 18:44 ` Miguel Ojeda
2023-09-18 22:23 ` [RFC PATCH v1 0/4] Rust abstractions for network PHY drivers Trevor Gross
2023-09-18 22:48 ` Andrew Lunn
2023-09-18 23:46 ` Trevor Gross
2023-09-19 6:24 ` FUJITA Tomonori
2023-09-19 7:41 ` Trevor Gross
2023-09-19 16:12 ` Andrew Lunn
2023-09-19 6:16 ` FUJITA Tomonori
2023-09-19 8:05 ` Trevor Gross
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='CALNs47sRKxnD1NhJZaoorEZ2xyLjAse23RmkacoPuCiD7Enq=g@mail.gmail.com' \
--to=tmgross@umich.edu \
--cc=andrew@lunn.ch \
--cc=fujita.tomonori@gmail.com \
--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).