lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <95381a84-0fd0-4f57-88e4-1ed31d282eee@kernel.org>
Date: Tue, 21 Nov 2023 23:15:51 +0100
From: Krzysztof Kozlowski <krzk@...nel.org>
To: Luiz Angelo Daros de Luca <luizluca@...il.com>
Cc: Vladimir Oltean <olteanv@...il.com>, netdev@...r.kernel.org,
 linus.walleij@...aro.org, alsi@...g-olufsen.dk, andrew@...n.ch,
 f.fainelli@...il.com, davem@...emloft.net, edumazet@...gle.com,
 kuba@...nel.org, pabeni@...hat.com, arinc.unal@...nc9.com
Subject: Re: [net-next 2/2] net: dsa: realtek: load switch variants on demand

On 21/11/2023 15:40, Luiz Angelo Daros de Luca wrote:
> Hi Krzysztof,
> 
>>> On Mon, Nov 20, 2023 at 10:20:13AM +0100, Krzysztof Kozlowski wrote:
>>>> No, why do you need it? You should not need MODULE_ALIAS() in normal
>>>> cases. If you need it, usually it means your device ID table is wrong
>>>> (e.g. misses either entries or MODULE_DEVICE_TABLE()). MODULE_ALIAS() is
>>>> not a substitute for incomplete ID table.
>>>>
>>>> Entire abstraction/macro is pointless and make the code less readable.
>>>
>>> Are you saying that the line
>>>
>>> MODULE_DEVICE_TABLE(of, realtek_common_of_match);
>>>
>>> should be put in all of realtek-mdio.c, realtek-smi.c, rtl8365mb.c and
>>> rtl8366rb.c, but not in realtek-common.c?
>>
>> Driver should use MODULE_DEVICE_TABLE() for the table not MODULE_ALIAS()
>> for each entry. I don't judge where should it be put. I just dislike
>> usage of aliases as a incomplete-substitute of proper table.
> 
> MODULE_ALIAS() is in use here because of its relation with modprobe,
> not inside the kernel.

The same as MODULE_DEVICE_TABLE.

> MODULE_DEVICE_TABLE is also in use but it does not seem to generate
> any information usable by modprobe.

It does, exactly the same from functional point of view... which
information are you missing?

> 
>>>
>>> There are 5 kernel modules involved, 2 for interfaces and 2 for switches.
>>>
>>> Even if the same OF device ID table could be used to load multiple
>>> modules, I'm not sure
>>> (a) how to avoid loading the interface driver which will not be used
>>>     (SMI if it's a MDIO-connected switch, or MDIO if it's an SMI
>>>     connected switch)
>>> (b) how to ensure that the drivers are loaded in the right order, i.e.
>>>     the switch drivers are loaded before the interface drivers
>>
>> I am sorry, I do not understand the problem. The MODULE_DEVICE_TABLE and
>> MODULE_ALIAS create exactly the same behavior. How any of above would
>> happen with table but not with alias having exactly the same compatibles?
> 
> Realtek switches can be managed through different interfaces. In the
> current kernel implementation, there is an MDIO driver (realtek-mdio)
> for switches connected to the MDIO bus, and a platform driver
> implementing the SMI protocol (a simple GPIO bit-bang).
> 
> The actual switch logic is implemented in two different switch
> family/variant modules: rtl8365mb and rtl8366 (currently only for
> rtl8366rb). As of today, both Realtek interface modules directly
> reference each switch variant symbol, creating a hard dependency and
> forcing the interface module to load both switch family variants. Each
> interface module provides the same compatible strings for both
> variants, but I haven't investigated whether this is problematic or
> not. It appears that there is no mechanism to autoload modules based
> on compatible strings from the device tree, and each interface module
> is a different type of driver.

??? So entire Linux kernel is broken? Somehow autoloading modules based
on compatible strings from the device tree works for every other driver
properly using tables... So again, I am repeating:
stop using MODULE_ALIAS for missing/incomplete tables

> 
> This patch set accomplishes two things: it moves some shared code to a

Which should not... One thing per patch.


> new Realtek common module and changes the hard dependency between
> interface and variant modules into a more dynamic relation. Each
> variant module registers itself in realtek-common, and interface
> modules look for the appropriate variant. However, as interface
> modules do not directly depend on variant modules, they might not have
> been loaded yet, causing the driver probe to fail.
> 
> The solution I opted for was to request the module during the
> interface probe (similar to what happens with DSA tag modules),
> triggering a userland "modprobe XXXX." Even without the variant module
> loaded, we know the compatible string that matched the interface
> driver. We can also have some extra info from match data, but I chose
> to simply keep using the compatible string. The issue is how to get

How is this even related to the problem? Please respond with concise
messages.

> the "XXXX" for modprobe. For DSA tags, module names are generated
> according to a fixed rule based on the tag name. However, the switch
> variants do not have a fixed relation between module name and switch
> families (actually, there is not even a switch family name). I could
> (and did in a previous RFC) use the match data to inform each module
> name. However, it adds a non-obvious relation between the module name
> (defined in Makefile) and a string in code. I was starting to
> implement a lookup table to match compatible strings to their module
> names when I realized that I was just mapping a string to a module
> name, something like what module alias already does. That's when the
> MODULE_ALIAS("<the compatible string>") was introduced.
> 
> After this discussion, I have some questions:
> 
> I'm declaring the of_device_id match table in realtek-common as it is
> the same for both interfaces. I also moved MODULE_DEVICE_TABLE(of,
> realtek_common_of_match) to realtek-common. Should I keep the
> MODULE_DEVICE_TABLE() on each interface module (referencing the same
> table), or is it okay to keep it in the realtek-common module? If I

Why would you have the same compatible entries in different modules? You
do understand that device node will become populated on first bind (bind
of the first device)?

> need to move it to each interface module, can I reuse a shared
> of_device_id match table declared in realtek-common?
> 
> If MODULE_ALIAS is not an acceptable solution, what would be the right
> one? Go back to the static mapping between the compatible string and
> the module name or is there a better solution?


Best regards,
Krzysztof


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ