[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a0a24765-8981-497c-a499-4dcf71897fda@lunn.ch>
Date: Mon, 9 Oct 2023 16:13:17 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: FUJITA Tomonori <fujita.tomonori@...il.com>, netdev@...r.kernel.org,
rust-for-linux@...r.kernel.org, miguel.ojeda.sandonis@...il.com,
greg@...ah.com, tmgross@...ch.edu
Subject: Re: [PATCH net-next v3 1/3] rust: core abstractions for network PHY
drivers
> > Locking has been discussed a number of times already. What do you mean
> > by timing?
>
> A few different things:
> - atomic/raw atomic context
PHY drivers need to access a slow MDIO bus, so you are always in
thread context which can sleep. Even the interrupt handler is in
thread context, and the device lock is held.
> >>> +macro_rules! module_phy_driver {
> >>> + (@replace_expr $_t:tt $sub:expr) => {$sub};
> >>> +
> >>> + (@count_devices $($x:expr),*) => {
> >>> + 0usize $(+ $crate::module_phy_driver!(@replace_expr $x 1usize))*
> >>> + };
> >>> +
> >>> + (@device_table [$($dev:expr),+]) => {
> >>> + #[no_mangle]
> >>> + static __mod_mdio__phydev_device_table: [
> >>
> >> Shouldn't this have a unique name? If we define two different
> >> phy drivers with this macro we would have a symbol collision?
> >
> > I assume these are the equivalent of C static. It is not visible
> > outside the scope of this object file. The kernel has lots of tables
> > and they are mostly of very limited visibility scope, because only the
> > method registering/unregistering the table needs to see it.
> The `#[no_mangle]` attribute in Rust disables standard symbol name
> mangling, see [2]. So if this macro is invoked twice, it will result
> in a compile error.
Invoked twice in what context? Within one object file? That i would
say is O.K. In practice, you only every have one table per driver.
As i said, i expect these symbols are static, so not seen outside the
object file. So if it is involved twice by different PHY drivers, that
should not matter, they are not global symbols, so the linker will not
complain about them. Also, in the Linux world, symbols are not visible
outside of a kernel module unless there is an EXPORT_SYMBOL_GPL() on
the symbol. So even if two kernel drivers do have global scope tables
with the same name, they are still invisible to each other when built
into the kernel, or loaded at runtime.
Andrew
Powered by blists - more mailing lists