[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2025081410-salsa-alabaster-9294@gregkh>
Date: Thu, 14 Aug 2025 12:05:32 +0200
From: Greg KH <gregkh@...uxfoundation.org>
To: Tzung-Bi Shih <tzungbi@...nel.org>, Danilo Krummrich <dakr@...nel.org>
Cc: bleung@...omium.org, dawidn@...gle.com, chrome-platform@...ts.linux.dev,
akpm@...ux-foundation.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/3] lib: Add ref_proxy module
On Thu, Aug 14, 2025 at 09:10:18AM +0000, Tzung-Bi Shih wrote:
> Some resources can be removed asynchronously, for example, resources
> provided by a hot-pluggable device like USB. When holding a reference
> to such a resource, it's possible for the resource to be removed and
> its memory freed, leading to use-after-free errors on subsequent access.
>
> Introduce the ref_proxy library to establish weak references to such
> resources. It allows a resource consumer to safely attempt to access a
> resource that might be freed at any time by the resource provider.
>
> The implementation uses a provider/consumer model built on Sleepable
> RCU (SRCU) to guarantee safe memory access:
>
> - A resource provider allocates a struct ref_proxy_provider and
> initializes it with a pointer to the resource.
>
> - A resource consumer that wants to access the resource allocates a
> struct ref_proxy handle which holds a reference to the provider.
>
> - To access the resource, the consumer uses ref_proxy_get(). This
> function enters an SRCU read-side critical section and returns the
> pointer to the resource. If the provider has already freed the
> resource, it returns NULL. After use, the consumer calls
> ref_proxy_put() to exit the SRCU critical section. The
> REF_PROXY_GET() is a convenient helper for doing that.
>
> - When the provider needs to remove the resource, it calls
> ref_proxy_provider_free(). This function sets the internal resource
> pointer to NULL and then calls synchronize_srcu() to wait for all
> current readers to finish before the resource can be completely torn
> down.
I've added Danilo here, as hopefully this is doing much the same thing
that his rust code does, but I think it's using different names?
Danilo, any ideas if this matches up with what we have in the driver
core rust code now, and would it help out with the drm drivers as well?
thanks,
greg k-h
Powered by blists - more mailing lists