lifetime of pwm devices
Hello,
currently PWM consumers (like for example a PWM fan) get a device link to the PWM device that ensures that if the PWM device goes away, the consumer is removed, too.
(This results in:
[ 67.234400] pwm-fan pwm-fan: Dropping the link to 3f20c000.pwm [ 67.234429] device: 'platform:3f20c000.pwm--platform:pwm-fan': device_unregister [ 67.234694] device: 'hwmon1': device_unregister [ 67.235384] device: 'pwmchip0': device_unregister [ 67.235488] device: 'pwmchip0': device_create_release
when I do
echo 3f20c000.pwm > /sys/bus/platform/drivers/bcm2835-pwm/unbind
on a rpi3 like device with a PWM fan and some debugging enabled.)
Before the device link was established in commit
b2c200e3f2fd ("pwm: Add consumer device link")
for v5.3-rc1 the machine was easy to crash after the PWM disappeared by making the consumer use the gone PWM.
Now I wonder if it is just harder to trigger such a crash or if the link is good enough to cover all corner cases.
I wonder if the pretty approach would be to ensure that the pwmchip's lifetime is tracked using a struct dev that ensures that the pwmchip doesn't go away until the consumer releases it. Is there an urge to address this?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Quoted 26 lines · Uwe Kleine-König
Hello,
currently PWM consumers (like for example a PWM fan) get a device link to the PWM device that ensures that if the PWM device goes away, the consumer is removed, too.
(This results in:
[ 67.234400] pwm-fan pwm-fan: Dropping the link to 3f20c000.pwm [ 67.234429] device: 'platform:3f20c000.pwm--platform:pwm-fan': device_unregister [ 67.234694] device: 'hwmon1': device_unregister [ 67.235384] device: 'pwmchip0': device_unregister [ 67.235488] device: 'pwmchip0': device_create_releasewhen I do
echo 3f20c000.pwm > /sys/bus/platform/drivers/bcm2835-pwm/unbindon a rpi3 like device with a PWM fan and some debugging enabled.)
Before the device link was established in commit
b2c200e3f2fd("pwm: Add consumer device link")for v5.3-rc1 the machine was easy to crash after the PWM disappeared by making the consumer use the gone PWM.
Quoted 7 lines
Now I wonder if it is just harder to trigger such a crash or if the link is good enough to cover all corner cases.
I wonder if the pretty approach would be to ensure that the pwmchip's lifetime is tracked using a struct dev that ensures that the pwmchip doesn't go away until the consumer releases it. Is there an urge to address this?
Preventing user-causable oopses is always good :)
The driver model should solve this, if it is used properly, why isn't the pwm layer using a struct device today?
thanks,
greg k-h
Hello,
Quoted 10 lines · Greg Kroah-Hartman
Quoted 7 lines · Uwe Kleine-König
Now I wonder if it is just harder to trigger such a crash or if the link is good enough to cover all corner cases.
I wonder if the pretty approach would be to ensure that the pwmchip's lifetime is tracked using a struct dev that ensures that the pwmchip doesn't go away until the consumer releases it. Is there an urge to address this?
Preventing user-causable oopses is always good :)
The key question is: Is the device link good enough to prevent all the nasty things. Or is there an urge to address problems?
Quoted 2 lines
The driver model should solve this, if it is used properly, why isn't the pwm layer using a struct device today?
I think this isn't used today because the PWM framework hasn't evolved enough. I tried to do this already but I don't understand the driver core and pwm code good enough yet to be done with that quickly. Ideally without changing the uservisible sysfs stuff.
Looking at different implementations I wonder: the i2c core uses a completion in the device release function. I assume this isn't what I need to do to win a prize?! Other subsystems use an alloc function to have the memory under framework control (e.g. spi_alloc_master, siox_master_alloc, alloc_etherdev_mqs etc) and to be able to kfree it in the release function. Is this the only clean way? What is the good framework to let me find some inspiration?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Quoted 12 lines · Uwe Kleine-König
Hello,
Quoted 9 lines · Greg Kroah-Hartman
Quoted 7 lines · Uwe Kleine-König
Now I wonder if it is just harder to trigger such a crash or if the link is good enough to cover all corner cases.
I wonder if the pretty approach would be to ensure that the pwmchip's lifetime is tracked using a struct dev that ensures that the pwmchip doesn't go away until the consumer releases it. Is there an urge to address this?
Quoted 4 lines
Quoted 1 line
Preventing user-causable oopses is always good :)
The key question is: Is the device link good enough to prevent all the nasty things. Or is there an urge to address problems?
Device links were specifically designed to address these problems, so yes, hopefully they are enough to prevent these issues.
Quoted 7 lines
Quoted 2 lines
The driver model should solve this, if it is used properly, why isn't the pwm layer using a struct device today?
I think this isn't used today because the PWM framework hasn't evolved enough. I tried to do this already but I don't understand the driver core and pwm code good enough yet to be done with that quickly. Ideally without changing the uservisible sysfs stuff.
It's not so much that the framework hasn't evolved enough. It's more that there was never a need for it, so there was never a need to evolve the framework. It was only until around the time when the need for device links was discovered that I realized PWM was in the same boat, but since device links were going to solve this anyway it didn't seem worth the effort to add a full-blown struct device to the framework.
I recall that I had briefly looked at implementing proper struct device and the associated reference counting, but once you get into the details it all gets very tricky real quickly. If I recall correctly the place where things stalled at the time was that you can't really prevent a device from being unbound (consider devices on a hotpluggable bus like USB - we don't have any PWM controller on USB, at least not yet, but any solution would have to support that use-case, or it wouldn't be any good). So while you could keep around a struct device reference for each consumer, you'd still have to figure out how to operate (or rather, not operate) on the backing devices that have physically disappeared. Essentially you'd have to refuse every subsystem-level operation on the objects because the hardware has gone and can no longer be accessed. Any consumers would also have to learn how to deal with that situation.
That's around the point where I reached out to Greg and Rafael at the time and Rafael came up with the idea (or had already been working on it, I don't recall exactly) for device links that would ensure that consumers would automatically be unbound when one of their resources goes away. It's a much more elegant solution, in my opinion, because it is both simpler and can be applied uniformly to a wide range of drivers and subsystems.
So unless you have a very pressing need that device links don't solve, I don't think this is a very good use of your time.
Thierry