[v3,0/3] drivers: base: Add tests showing devm handling inconsistencies

Message ID 20230720-kunit-devm-inconsistencies-test-v3-0-6aa7e074f373@kernel.org
Headers
Series drivers: base: Add tests showing devm handling inconsistencies |

Message

Maxime Ripard July 20, 2023, 12:45 p.m. UTC
  Hi,

This follows the discussion here:
https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/

This shows a couple of inconsistencies with regard to how device-managed
resources are cleaned up. Basically, devm resources will only be cleaned up
if the device is attached to a bus and bound to a driver. Failing any of
these cases, a call to device_unregister will not end up in the devm
resources being released.

We had to work around it in DRM to provide helpers to create a device for
kunit tests, but the current discussion around creating similar, generic,
helpers for kunit resumed interest in fixing this.

This can be tested using the command:
./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/

I added the fix David suggested back in that discussion which does fix
the tests. The SoB is missing, since David didn't provide it back then.

Let me know what you think,
Maxime

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
Changes in v3:
- Reworded the commit logs according to David's feedback
- Rebased on current next
- Link to v2: https://lore.kernel.org/r/20230329-kunit-devm-inconsistencies-test-v2-0-19feb71e864b@kernel.org

Changes in v2:
- Use an init function
- Document the tests
- Add a fix for the bugs
- Link to v1: https://lore.kernel.org/r/20230329-kunit-devm-inconsistencies-test-v1-0-c33127048375@cerno.tech

---
David Gow (1):
      drivers: base: Free devm resources when unregistering a device

Maxime Ripard (2):
      drivers: base: Add basic devm tests for root devices
      drivers: base: Add basic devm tests for platform devices

 drivers/base/core.c                      |  11 ++
 drivers/base/test/.kunitconfig           |   2 +
 drivers/base/test/Kconfig                |   4 +
 drivers/base/test/Makefile               |   3 +
 drivers/base/test/platform-device-test.c | 220 +++++++++++++++++++++++++++++++
 drivers/base/test/root-device-test.c     | 108 +++++++++++++++
 6 files changed, 348 insertions(+)
---
base-commit: c58c49dd89324b18a812762a2bfa5a0458e4f252
change-id: 20230329-kunit-devm-inconsistencies-test-5e5a7d01e60d

Best regards,
  

Comments

Maxime Ripard July 31, 2023, 6:34 a.m. UTC | #1
On Thu, Jul 20, 2023 at 02:45:06PM +0200, Maxime Ripard wrote:
> Hi,
> 
> This follows the discussion here:
> https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/
> 
> This shows a couple of inconsistencies with regard to how device-managed
> resources are cleaned up. Basically, devm resources will only be cleaned up
> if the device is attached to a bus and bound to a driver. Failing any of
> these cases, a call to device_unregister will not end up in the devm
> resources being released.
> 
> We had to work around it in DRM to provide helpers to create a device for
> kunit tests, but the current discussion around creating similar, generic,
> helpers for kunit resumed interest in fixing this.
> 
> This can be tested using the command:
> ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/
> 
> I added the fix David suggested back in that discussion which does fix
> the tests. The SoB is missing, since David didn't provide it back then.
> 
> Let me know what you think,
> Maxime
> 
> Signed-off-by: Maxime Ripard <mripard@kernel.org>

Ping?

Maxime
  
Greg KH July 31, 2023, 7:28 a.m. UTC | #2
On Mon, Jul 31, 2023 at 08:34:03AM +0200, Maxime Ripard wrote:
> On Thu, Jul 20, 2023 at 02:45:06PM +0200, Maxime Ripard wrote:
> > Hi,
> > 
> > This follows the discussion here:
> > https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/
> > 
> > This shows a couple of inconsistencies with regard to how device-managed
> > resources are cleaned up. Basically, devm resources will only be cleaned up
> > if the device is attached to a bus and bound to a driver. Failing any of
> > these cases, a call to device_unregister will not end up in the devm
> > resources being released.
> > 
> > We had to work around it in DRM to provide helpers to create a device for
> > kunit tests, but the current discussion around creating similar, generic,
> > helpers for kunit resumed interest in fixing this.
> > 
> > This can be tested using the command:
> > ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/
> > 
> > I added the fix David suggested back in that discussion which does fix
> > the tests. The SoB is missing, since David didn't provide it back then.
> > 
> > Let me know what you think,
> > Maxime
> > 
> > Signed-off-by: Maxime Ripard <mripard@kernel.org>
> 
> Ping?

It's in my review queue, still trying to catch up...
  
Greg KH Aug. 4, 2023, 3:01 p.m. UTC | #3
On Mon, Jul 31, 2023 at 09:28:47AM +0200, Greg Kroah-Hartman wrote:
> On Mon, Jul 31, 2023 at 08:34:03AM +0200, Maxime Ripard wrote:
> > On Thu, Jul 20, 2023 at 02:45:06PM +0200, Maxime Ripard wrote:
> > > Hi,
> > > 
> > > This follows the discussion here:
> > > https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/
> > > 
> > > This shows a couple of inconsistencies with regard to how device-managed
> > > resources are cleaned up. Basically, devm resources will only be cleaned up
> > > if the device is attached to a bus and bound to a driver. Failing any of
> > > these cases, a call to device_unregister will not end up in the devm
> > > resources being released.
> > > 
> > > We had to work around it in DRM to provide helpers to create a device for
> > > kunit tests, but the current discussion around creating similar, generic,
> > > helpers for kunit resumed interest in fixing this.
> > > 
> > > This can be tested using the command:
> > > ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/
> > > 
> > > I added the fix David suggested back in that discussion which does fix
> > > the tests. The SoB is missing, since David didn't provide it back then.
> > > 
> > > Let me know what you think,
> > > Maxime
> > > 
> > > Signed-off-by: Maxime Ripard <mripard@kernel.org>
> > 
> > Ping?
> 
> It's in my review queue, still trying to catch up...

I didn't make it here this week, sorry.  I kind of worry about encoding
the current "odd" functionality in a test as being the correct thing,
but will look at it closer next week.

thanks,

greg k-h
  
Maxime Ripard Aug. 7, 2023, 6:54 a.m. UTC | #4
Hi,

On Fri, Aug 04, 2023 at 05:01:50PM +0200, Greg Kroah-Hartman wrote:
> On Mon, Jul 31, 2023 at 09:28:47AM +0200, Greg Kroah-Hartman wrote:
> > On Mon, Jul 31, 2023 at 08:34:03AM +0200, Maxime Ripard wrote:
> > > On Thu, Jul 20, 2023 at 02:45:06PM +0200, Maxime Ripard wrote:
> > > > Hi,
> > > > 
> > > > This follows the discussion here:
> > > > https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/
> > > > 
> > > > This shows a couple of inconsistencies with regard to how device-managed
> > > > resources are cleaned up. Basically, devm resources will only be cleaned up
> > > > if the device is attached to a bus and bound to a driver. Failing any of
> > > > these cases, a call to device_unregister will not end up in the devm
> > > > resources being released.
> > > > 
> > > > We had to work around it in DRM to provide helpers to create a device for
> > > > kunit tests, but the current discussion around creating similar, generic,
> > > > helpers for kunit resumed interest in fixing this.
> > > > 
> > > > This can be tested using the command:
> > > > ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/
> > > > 
> > > > I added the fix David suggested back in that discussion which does fix
> > > > the tests. The SoB is missing, since David didn't provide it back then.
> > > > 
> > > > Let me know what you think,
> > > > Maxime
> > > > 
> > > > Signed-off-by: Maxime Ripard <mripard@kernel.org>
> > > 
> > > Ping?
> > 
> > It's in my review queue, still trying to catch up...
> 
> I didn't make it here this week, sorry.

np, I just don't want that patch to disappear into the ether :)

> I kind of worry about encoding the current "odd" functionality in a
> test as being the correct thing, but will look at it closer next week.

I don't think I'm doing that? The tests we've added are all how we think
it should behave, the broken ones being skipped to avoid any failures.

The last patch drops the kunit_skip() to make sure that it's tested
going forward.

So we shouldn't encode the odd behaviour anywhere in this series, unless
I got you wrong?

Maxime
  
Greg KH Aug. 12, 2023, 11:07 a.m. UTC | #5
On Mon, Aug 07, 2023 at 08:54:08AM +0200, Maxime Ripard wrote:
> Hi,
> 
> On Fri, Aug 04, 2023 at 05:01:50PM +0200, Greg Kroah-Hartman wrote:
> > On Mon, Jul 31, 2023 at 09:28:47AM +0200, Greg Kroah-Hartman wrote:
> > > On Mon, Jul 31, 2023 at 08:34:03AM +0200, Maxime Ripard wrote:
> > > > On Thu, Jul 20, 2023 at 02:45:06PM +0200, Maxime Ripard wrote:
> > > > > Hi,
> > > > > 
> > > > > This follows the discussion here:
> > > > > https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/
> > > > > 
> > > > > This shows a couple of inconsistencies with regard to how device-managed
> > > > > resources are cleaned up. Basically, devm resources will only be cleaned up
> > > > > if the device is attached to a bus and bound to a driver. Failing any of
> > > > > these cases, a call to device_unregister will not end up in the devm
> > > > > resources being released.
> > > > > 
> > > > > We had to work around it in DRM to provide helpers to create a device for
> > > > > kunit tests, but the current discussion around creating similar, generic,
> > > > > helpers for kunit resumed interest in fixing this.
> > > > > 
> > > > > This can be tested using the command:
> > > > > ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/
> > > > > 
> > > > > I added the fix David suggested back in that discussion which does fix
> > > > > the tests. The SoB is missing, since David didn't provide it back then.
> > > > > 
> > > > > Let me know what you think,
> > > > > Maxime
> > > > > 
> > > > > Signed-off-by: Maxime Ripard <mripard@kernel.org>
> > > > 
> > > > Ping?
> > > 
> > > It's in my review queue, still trying to catch up...
> > 
> > I didn't make it here this week, sorry.
> 
> np, I just don't want that patch to disappear into the ether :)
> 
> > I kind of worry about encoding the current "odd" functionality in a
> > test as being the correct thing, but will look at it closer next week.
> 
> I don't think I'm doing that? The tests we've added are all how we think
> it should behave, the broken ones being skipped to avoid any failures.
> 
> The last patch drops the kunit_skip() to make sure that it's tested
> going forward.
> 
> So we shouldn't encode the odd behaviour anywhere in this series, unless
> I got you wrong?

No you are correct, I was mis-remembering things.

This looks good, thanks for sticking with it, all now applied to my
tree.

greg k-h