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: <659bf414.050a0220.32376.5383@mx.google.com>
Date: Mon, 8 Jan 2024 14:09:10 +0100
From: Christian Marangi <ansuelsmth@...il.com>
To: Luiz Angelo Daros de Luca <luizluca@...il.com>
Cc: linus.walleij@...aro.org, alsi@...g-olufsen.dk, andrew@...n.ch,
	f.fainelli@...il.com, olteanv@...il.com, davem@...emloft.net,
	edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
	arinc.unal@...nc9.com, netdev@...r.kernel.org
Subject: Re: [RFC net-next 0/2] net: dsa: realtek: fix LED support for
 rtl8366rb

On Mon, Jan 08, 2024 at 02:47:22AM -0300, Luiz Angelo Daros de Luca wrote:
> > > Hi Christian,
> > >
> > > I tried to implement something close to your work with qca8k and LED
> > > hw control. However, I couldn't find a solution that would work with
> > > the existing API. The HW led configuration in realtek switches is
> > > shared with all LEDs in a group. Before activating the hw control, all
> > > LEDs in the same group must share the same netdev trigger config, use
> > > the correct device and also use a compatible netdev trigger settings.
> > > In order to check that, I would need to expose some internal netdev
> > > trigger info that is only available through sysfs (and I believe sysfs
> > > is not suitable to be used from the kernel). Even if I got all LEDs
> > > with the correct settings, I would need to atomicly switch all LEDs to
> > > use the hw control or, at least, I would need to stop all update jobs
> > > because if the OS changes a LED brightness, it might be interpreted as
> > > the OS disabling the hw control:
> > >
> >
> > Saddly we still don't have the concept of LED groups, but from what I
> > notice 99% of the time switch have limitation of HW control but single
> > LED can still be controlled separately.
>
> Individually, I can only turn them on/off. That is enough for software
> control but not for hardware control. When you set a LED group to
> blink on link activity, all LEDs will be affected.
>

Assuming we have the same 2005 datasheet, yes the LED situation is
complex for this switch. (If you have something better please link)

> > With this limitation you can use the is_supported function and some priv
> > struct to enforce and reject unsupported configuration.
> > netdev trigger will then fallback to software in this case. (I assume on
> > real world scenario to have all the LED in the group to be set to the
> > common rule set resulting in is_supported never rejecting it)
> 
> Maybe I wasn't clear enough about what the HW provides me. I have 4
> 16-bit registers:
> 
> REG1: a single blink rate used by all LEDs in all groups
> REG2: configures the trigger for each group, 4-bit each, with one
> special 4-bit value being "fixed", equivalent to "none" in Linux LED
> trigger
> REG3: bitmap to manually control LEDs in group 0 and 1 only when their
> group trigger is configured as fixed.
> REG3: bitmap to manually control LEDs in group 2 and 3 only when their
> group trigger is configured as fixed.
> 
> And that's it.
> 
> I can keep track of the netdev trigger form calls to "is_supported
> function". I can also check if all LEDs are still using the netdev
> trigger. However, I cannot detect if the user changed the device to
> something else not related to the corresponding port as the netdev
> trigger will not check the compatibility if the device does not match.
> I would still need to expose at least some of the netdev trigger
> internal data.
> 

We can make some assumption and use refcount tho. For very exotic
configuration it will always fallback to software (and make hw control
impossible) but for more generic one we can benefit of it.

- We can only enable HW control on the LED group.

This means that for the group we need to make sure that:
1. We have the correct device set to each LED
2. We have an acceptable mode requesterd.

With these 2 prereq, we can correctly enable HW control for the LED
group.

HW control is enable only IF the device netdev currently set match what
hw_control_get_device returns. With this, we can assume for HW control
request the correct netdev is always set.

We also use refcount to check how many LED are actually ""enabled"".
With this count we can understand if we can enable HW control for the
LED group or return false from is_supported.

And with HW control enabled, we would reject all kind of invalid
settings and print a warning to alert the user of the limitation and
maybe how to remove it.

> > Also consider this situation, it's the first LED touched that enables HW
> > control that drive everything. LED configuration are not enabled all at
> > once. You can totally introduce a priv struct that cache the current
> > modes and on the other LEDs make sure the requested mode match the cache
> > one.
> 
> Considering that I can externally check that all LEDs have a netdev
> trigger settings compatible with the HW control, once the last LED is
> configured, I could return true for the hw_control_is_supported. When
> hw_control_set is called, I could configure the hardware accordingly,
> which would affect all LEDs in that group. However, the OS will still
> use the software control for the other LEDs in that same group. That
> way, once a netdev event turns off one LED, that message is the same
> clue the LED driver receives to disable the hardware control. It will
> undo the hardware change I just made. I could use
> led_brightness_set(OFF) on those other LEDs during hw_control_set to
> disable their software controlled triggers (actually changing the
> trigger to "none"), but it might be a race condition of who stops the
> other. And even then, the other LEDs will keep an inconsistent
> configuration state, with "none" as their trigger.
> 
> I need:
> 1) expose the required info or allow an external caller to test a LED
> configuration for compatibility (avoiding recursion).
> 2) something from hw_control_set() that stops the software triggers in
> other LEDs without destroying their configuration.
> 3) something that could enable hw_control on those other LEDs
> 

I think it would be problematic for other LED to do changes. I need to
check how LED multicolor work... In a sense they are LED group so maybe
in LED core we have a way to group LED and share some info with the
others.

> > And I guess this limitation should be printed and documented in DT.
> >
> > > /*
> > > ...
> > > * Deactivate hardware blink control by setting brightness to LED_OFF via
> > > * the brightness_set() callback.
> > > *
> > > ...
> > > */
> > > int (*hw_control_set)(struct led_classdev *led_cdev,
> > >  unsigned long flags);
> > >
> > > Do you have any idea how to implement it?
> > >
> > > BTW, during my tests with a single LED, ignoring the LED group
> > > situation, I noticed that the OS was sending a brightness_set(LED_OFF)
> > > after I changed the trigger to netdev, a moment after hw_control_set
> > > was called. It doesn't make sense to enable hw control just to disable
> > > it afterwards. The call came from set_brightness_delayed(). Maybe it
> > > is because my test device is pretty slow and the previous trigger
> > > event always gets queued. Touching any settings after that worked as
> > > expected without the spurious brightness_set(LED_OFF). Did you see
> > > something like this?
> > >
> >
> > Consider that brightness_set is called whatever a trigger is changed,
> > the logic is in the generic LED handling. Setting OFF and then enabling
> > hw control should not change a thing. In other driver tho I notice an
> > extra measure is needed to reset any HW control rule already applied by
> > default.
> 
> It would be OK to call brightness_set(LED_OFF) if that is guaranteed
> to happen before hw_control_set(). The problem is that the
> brightness_set(LED_OFF) happens *after* hw_control_set() was called.
> It looks like a race condition.
> 

Totally require some further investigation, it seems strange tho that
the your system is that slow.

-- 
	Ansuel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ