From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Bartosz Golaszewski <brgl@kernel.org>
Cc: Benson Leung <bleung@chromium.org>,
linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev,
driver-core@lists.linux.dev, linux-doc@vger.kernel.org,
linux-gpio@vger.kernel.org,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Jason Gunthorpe <jgg@nvidia.com>, Johan Hovold <johan@kernel.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
Dan Williams <dan.j.williams@intel.com>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Linus Walleij <linusw@kernel.org>
Subject: Re: [PATCH v9 1/9] revocable: Revocable resource management
Date: Thu, 7 May 2026 22:03:03 +0800 [thread overview]
Message-ID: <afybl1LWaESdtX5U@tzungbi-laptop> (raw)
In-Reply-To: <CAMRc=McG41iHWfY+3U4Xp6YNFCwbt_zAUE-2417LrQVrTfdWjA@mail.gmail.com>
On Tue, May 05, 2026 at 05:55:40AM -0700, Bartosz Golaszewski wrote:
> On Mon, 27 Apr 2026 15:58:33 +0200, Tzung-Bi Shih <tzungbi@kernel.org> said:
> > diff --git a/include/linux/revocable.h b/include/linux/revocable.h
> > new file mode 100644
> > index 000000000000..2bcf23f01ace
> > --- /dev/null
> > +++ b/include/linux/revocable.h
> > @@ -0,0 +1,214 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Copyright 2026 Google LLC
> > + */
> > +
> > +#ifndef __LINUX_REVOCABLE_H
> > +#define __LINUX_REVOCABLE_H
> > +
> > +#include <linux/cleanup.h>
> > +#include <linux/compiler.h>
>
> I don't think you need this header.
Ack, will remove it in the next version.
>
> > +#include <linux/kref.h>
> > +#include <linux/srcu.h>
> > +
> > +/**
> > + * enum revocable_alloc_type - The allocation method for a revocable provider.
> > + * @REVOCABLE_DYNAMIC: The struct revocable was dynamically allocated using
> > + * revocable_alloc() and its lifetime is managed by
> > + * reference counting.
> > + * @REVOCABLE_EMBEDDED: The struct revocable is embedded within another
> > + * structure. Its lifetime is tied to the parent
> > + * structure and is not reference counted.
> > + */
> > +enum revocable_alloc_type {
> > + REVOCABLE_DYNAMIC,
> > + REVOCABLE_EMBEDDED,
> > +};
>
> Maybe we don't need this public enum at all, we could just use a different
> release callback for kref_put() depending on how the revocable was allocated?
>
> The enum is not used elsewhere so it doesn't make sense to document it as if it
> was part of the revocable API.
>
> > +
> > +/**
> > + * struct revocable - A handle for resource provider.
> > + * @srcu: The SRCU to protect the resource.
> > + * @res: The pointer of resource. It can point to anything.
> > + * @kref: The refcount for this handle.
> > + * @alloc_type: The memory allocation type.
> > + */
> > +struct revocable {
> > + struct srcu_struct srcu;
> > + void __rcu *res;
> > + struct kref kref;
> > + enum revocable_alloc_type alloc_type;
>
> This could be replaced with the pointer to the release callback, assigned
> by revocable_alloc()/revocable_init() respectively.
>
Ack, will remove the enum. A boolean is sufficient given that the
allocation type is binary.
> > +};
> > +
> > +/**
> > + * struct revocable_consumer - A handle for resource consumer.
> > + * @rev: The pointer of resource provider.
> > + * @idx: The index for the SRCU critical section.
>
> Should any of these be accessed directly by the user? Maybe document them
> as __private?
I don't think that is necessary. All members in both struct revocable and
struct revocable_consumer are intended to be opaque and should not be
accessed directly by users. However, I made them public structures
because:
- The try_access_* macros need to allocate a struct revocable_consumer
locally.
- KUnit tests require access to these members for verification.
I can add a comment to the structure definitions noting that they should
be treated as private. Does it make sense?
>
> > + */
> > +struct revocable_consumer {
> > + struct revocable *rev;
> > + int idx;
> > +};
>
> I'd rename it to struct revocable_handle which indicates better what it is:
> it's a handle *owned* by the consumer.
Ack, will rename it.
>
> > +
> > +void revocable_get(struct revocable *rev);
> > +void revocable_put(struct revocable *rev);
> > +
> > +struct revocable *revocable_alloc(void *res);
> > +void revocable_revoke(struct revocable *rev);
> > +int revocable_embed_init(struct revocable *rev, void *res);
> > +void revocable_embed_destroy(struct revocable *rev);
> > +
> > +void revocable_init(struct revocable *rev, struct revocable_consumer *rc);
> > +void revocable_deinit(struct revocable_consumer *rc);
>
> If we hid the release logic, we could drop revocable_embed_destroy() and use
> the same refcounting functions for both variants. I'd suggest the following:
>
> For refcounting (same for both variants):
>
> void revocable_get(struct revocable *rev);
> void revocable_put(struct revocable *rev);
>
> For dynamic variant:
>
> struct revocable *revocable_alloc(void *res);
>
> For embedded:
>
> int revocable_init(struct revocable *rev, void *res);
>
> For handles:
>
> void revocable_handle_init(struct revocable *rev, struct
> revocable_consumer *rc);
> void revocable_handle_deinit(struct revocable_consumer *rc);
>
> Does it make sense?
That makes sense. I'll fix this in the next version.
next prev parent reply other threads:[~2026-05-07 14:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 13:58 [PATCH v9 0/9] drivers/base: Introduce revocable Tzung-Bi Shih
2026-04-27 13:58 ` [PATCH v9 1/9] revocable: Revocable resource management Tzung-Bi Shih
2026-05-05 12:55 ` Bartosz Golaszewski
2026-05-07 14:03 ` Tzung-Bi Shih [this message]
2026-04-27 13:58 ` [PATCH v9 2/9] revocable: Add KUnit test cases Tzung-Bi Shih
2026-04-27 13:58 ` [PATCH v9 3/9] gpio: Add revocable provider handle for struct gpio_chip Tzung-Bi Shih
2026-04-27 13:58 ` [PATCH v9 4/9] gpio: cdev: Leverage revocable for accessing " Tzung-Bi Shih
2026-04-27 13:58 ` [PATCH v9 5/9] gpio: Remove gpio_chip_guard by using revocable Tzung-Bi Shih
2026-04-27 13:58 ` [PATCH v9 6/9] gpio: Leverage revocable for accessing struct gpio_chip Tzung-Bi Shih
2026-04-27 13:58 ` [PATCH v9 7/9] gpio: Remove unused `chip` and `srcu` in struct gpio_device Tzung-Bi Shih
2026-04-27 13:58 ` [PATCH v9 8/9] platform/chrome: Protect cros_ec_device lifecycle with revocable Tzung-Bi Shih
2026-04-27 13:58 ` [PATCH v9 9/9] platform/chrome: cros_ec_chardev: Consume cros_ec_device via revocable Tzung-Bi Shih
2026-04-28 8:16 ` [PATCH v9 0/9] drivers/base: Introduce revocable Bartosz Golaszewski
2026-04-28 8:18 ` Bartosz Golaszewski
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=afybl1LWaESdtX5U@tzungbi-laptop \
--to=tzungbi@kernel.org \
--cc=arnd@arndb.de \
--cc=bleung@chromium.org \
--cc=brgl@kernel.org \
--cc=chrome-platform@lists.linux.dev \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=driver-core@lists.linux.dev \
--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-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=rafael@kernel.org \
--cc=shuah@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