public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Laurent Pinchart" <laurent.pinchart@ideasonboard.com>
Cc: "Bartosz Golaszewski" <brgl@kernel.org>,
	"Johan Hovold" <johan@kernel.org>,
	"Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	"Tzung-Bi Shih" <tzungbi@kernel.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <shuah@kernel.org>,
	"Wolfram Sang" <wsa+renesas@sang-engineering.com>,
	"Simona Vetter" <simona.vetter@ffwll.ch>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"Jason Gunthorpe" <jgg@nvidia.com>, <linux-doc@vger.kernel.org>,
	<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 0/3] Revert "revocable: Revocable resource management"
Date: Thu, 29 Jan 2026 23:00:21 +0100	[thread overview]
Message-ID: <DG1ET3ZMX3LK.QKKLPFK1424M@kernel.org> (raw)
In-Reply-To: <20260129144906.GE3327197@killaraus>

On Thu Jan 29, 2026 at 3:49 PM CET, Laurent Pinchart wrote:
> On Thu, Jan 29, 2026 at 08:50:30AM -0500, Bartosz Golaszewski wrote:
>> On Thu, 29 Jan 2026 11:56:34 +0100, Laurent Pinchart said:
>> > On Thu, Jan 29, 2026 at 10:11:46AM +0100, Bartosz Golaszewski wrote:
>> >>
>> >> For I2C both the problem is different (subsystem waiting forever for
>> >> consumers to release all references) and the culprit: memory used to
>> >> hold the reference-counted struct device is released the supplier
>> >> unbind unconditionally. Unfortunately there's no way around it other
>> >> than to first move it into a separate chunk managed by i2c core.
>> >
>> > Isn't there ? Can't the driver-specific data structure be
>> > reference-counted instead of unconditionally freed at unbind time ?
>> 
>> Oh, for sure, if we did from the start. But we did not and there are now
>> hundreds of i2c drivers that do:
>> 
>> struct my_i2c_drv_data {
>> 	struct i2c_adapter adap;
>> 	int my_other_drv_data;
>> };
>> 
>> and in probe:
>> 
>> struct my_i2c_drv_data *data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
>> 
>> (or just kzalloc() with kfree() in remove, it doesn't matter)
>> 
>> and the ownership of that data belongs to the driver. There's no way we could
>> address it now so the next best thing is to work towards moving the ownership
>> of struct i2c_adapter to the i2c core and make it reference counted using the
>> internal kobject of the associated struct device.
>
> What I'm reading here is essentially that we rolled out devm_kzalloc() too
> quickly without understanding the consequences, and it has spread so much that
> it can't be fixed properly now, so we need to find a workaround.

I'm pretty sure I don't have all the details about the problem with the
i2c_adapter, but from what I read here briefly the problem simply seems to be
that currently the driver providing the i2c_adapter frees the i2c_adapter on
driver unbind unconditionally.

I would argue that this is a violation of the driver core design anyways. I
mean, in the end an i2c_adapter is the same type of device as any other bus
device (platform, PCI, etc.).

For instance, when the physical device that is represented by a PCI device is
removed from the machine, the corresponding struct pci_dev is not forcefully
freed either, it stays around as long as there are references to the device.

So, I fail to see how devm_kmalloc() and frieds are the root cause of the
i2c_adapter lifetime problem?

> And now we're trying to work around the problem by rolling out a revocable API
> that has barely seen any testing, and is known to have design issues. Does any
> one else see the irony ? :-)

I don't think anyone is trying to work around problems with devm_kmalloc() and
friends. It's just system memory, i.e. nothing that needs to be revoked. We can
just not use devm_kmalloc() and friends if we need the memory to outlive driver
unbind for some reason. The problem is about real device resources, such as I/O
memory mappings that *must* be released when a driver is unbound from its
device. So, revocable is clearly not a fix for devm_kmalloc() et al.

  reply	other threads:[~2026-01-29 22:00 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-24 17:05 [PATCH 0/3] Revert "revocable: Revocable resource management" Johan Hovold
2026-01-24 17:05 ` [PATCH 1/3] Revert "selftests: revocable: Add kselftest cases" Johan Hovold
2026-01-24 17:05 ` [PATCH 2/3] Revert "revocable: Add Kunit test cases" Johan Hovold
2026-01-24 17:05 ` [PATCH 3/3] Revert "revocable: Revocable resource management" Johan Hovold
2026-01-24 17:37   ` Johan Hovold
2026-01-24 17:46   ` Danilo Krummrich
2026-01-26 13:20     ` Johan Hovold
2026-01-27 15:57       ` Tzung-Bi Shih
2026-01-24 18:42 ` [PATCH 0/3] " Laurent Pinchart
2026-01-24 19:08 ` Danilo Krummrich
2026-01-25 12:47   ` Greg Kroah-Hartman
2026-01-25 13:22     ` Laurent Pinchart
2026-01-25 14:07       ` Danilo Krummrich
2026-01-29  1:09         ` Laurent Pinchart
2026-01-25 13:24     ` Laurent Pinchart
2026-01-25 17:53     ` Danilo Krummrich
2026-01-26  0:07       ` Jason Gunthorpe
2026-01-26 16:08         ` Danilo Krummrich
2026-01-26 17:07           ` Jason Gunthorpe
2026-01-26 22:36             ` Danilo Krummrich
2026-01-28 23:40             ` Laurent Pinchart
2026-01-26 13:50     ` Johan Hovold
2026-01-27 21:18       ` Bartosz Golaszewski
2026-01-27 23:52         ` Jason Gunthorpe
2026-01-28  9:40           ` Bartosz Golaszewski
2026-01-28 10:01             ` Wolfram Sang
2026-01-28 15:05               ` Jason Gunthorpe
2026-01-28 15:20                 ` Bartosz Golaszewski
2026-01-28 16:01                   ` Jason Gunthorpe
2026-01-30 11:27                     ` Bartosz Golaszewski
2026-01-28 16:58                 ` Wolfram Sang
2026-01-29  1:08           ` Laurent Pinchart
2026-01-29  1:23             ` Jason Gunthorpe
2026-01-29  3:42               ` dan.j.williams
2026-01-29  9:56                 ` Danilo Krummrich
2026-01-29 10:43                   ` Laurent Pinchart
2026-01-30  0:36                   ` dan.j.williams
2026-01-29 10:38               ` Laurent Pinchart
2026-01-29 13:34                 ` Jason Gunthorpe
2026-01-29 14:52                   ` Laurent Pinchart
2026-01-29 22:29             ` Danilo Krummrich
2026-01-30  9:10               ` Laurent Pinchart
2026-02-03  9:10                 ` Maxime Ripard
2026-02-03 13:59                   ` Laurent Pinchart
2026-01-28 15:48         ` Johan Hovold
2026-01-29  9:11           ` Bartosz Golaszewski
2026-01-29 10:56             ` Laurent Pinchart
2026-01-29 13:50               ` Bartosz Golaszewski
2026-01-29 14:28                 ` Jason Gunthorpe
2026-01-29 14:45                   ` Laurent Pinchart
2026-01-29 14:49                 ` Laurent Pinchart
2026-01-29 22:00                   ` Danilo Krummrich [this message]
2026-01-30 11:19                   ` Bartosz Golaszewski
2026-01-29 13:27           ` Linus Walleij
2026-02-03 12:15       ` Johan Hovold
2026-02-03 12:26         ` Greg Kroah-Hartman
2026-02-03 12:30           ` [PATCH] driver core: disable revocable code from build Greg Kroah-Hartman
2026-02-03 13:20             ` Danilo Krummrich
2026-02-04  2:14             ` Tzung-Bi Shih
2026-02-04  5:28               ` [PATCH] selftests: Disable " Tzung-Bi Shih
2026-02-04  8:21                 ` Greg Kroah-Hartman
2026-02-03 13:57           ` [PATCH 0/3] Revert "revocable: Revocable resource management" Laurent Pinchart
2026-02-03 15:44             ` Greg Kroah-Hartman
2026-02-04 14:36           ` Johan Hovold
2026-01-27 15:57 ` Tzung-Bi Shih
2026-01-28 14:23   ` Johan Hovold
2026-01-28 23:28     ` Laurent Pinchart
2026-01-29 15:01   ` Tzung-Bi Shih
2026-01-30  9:12     ` Laurent Pinchart
2026-01-30 17:41       ` Danilo Krummrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DG1ET3ZMX3LK.QKKLPFK1424M@kernel.org \
    --to=dakr@kernel.org \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=brgl@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dan.j.williams@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jgg@nvidia.com \
    --cc=johan@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linusw@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=shuah@kernel.org \
    --cc=simona.vetter@ffwll.ch \
    --cc=tzungbi@kernel.org \
    --cc=wsa+renesas@sang-engineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox