mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Bence Csókás" <bence.csokas@arm.com>
To: Jan Kara <jack@suse.cz>
Cc: Christian Brauner <brauner@kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 0/2] Add scope-based cleanup capability to eventfd_ctx
Date: Fri, 6 Nov 2026 15:30:07 +0100	[thread overview]
Message-ID: <803191ed-6597-4b8d-af7d-812b1b494fee@arm.com> (raw)
In-Reply-To: <sp6gvawt6petvrlky7g6pqaqsp3jwouu6ixarevis5m5vd7fwe@xjxeakzi3nn3>

Hi,

On 2026. 11. 06. 15:13, Jan Kara wrote:
> Hi!
> 
> On Fri 06-11-26 10:31:58, Bence Csókás wrote:
>> On 2026. 11. 06. 10:05, Christian Brauner wrote:
>>> On Tue, Oct 27, 2026 at 05:22:00PM +0100, Bence Csokas wrote:
>>>> Add __free() support to eventfd and update drm_syncobj to use it as an
>>>> example consumer.
>>>>
>>>> A minor discrepancy I encountered is whether to put a semicolon after
>>>> DEFINE_FREE(). It seems some in-tree code does, some doesn't. In the end,
>>>> I followed the example set in core-api/cleanup.rst, and omitted it.
>>>>
>>>> Signed-off-by: Bence Csokas <bence.csokas@arm.com>
>>>> ---
>>>
>>> I'm really having trouble seeing how this improves anything
>>> significantly. Probably others have the same impression which is why
>>> this doesn't get a lot of review.
>>
>> The goal of the __free() API is to reduce the number of goto-based error
>> paths. Normally, you'd have to keep the state of every local in your head
>> for every early return. (Has it been initialized? Has it been consumed? Or
>> does it need to be freed?) Then you need to arrange your "goto tree" (error
>> labels) in a way that frees everything, and then for every early exit, jump
>> to the correct one. This can be quite complex for some functions. Look at
>> KVM or HyperV eventfd code, for example.
>>
>> By contrast, you just mark the local var with _free() and an appropriate
>> destructor snippet, and the consumption point (the point after which we
>> don't need to free it on a return) with no_free_ptr(), and the compiler
>> instruments every early return accordingly.
> 
> Sure, but there's also the other side about which you don't speak: unless
> the destructor is trivial (like kfree()), there are implications about
> locking, when resources (such as references held by the object) get
> released etc. So it can also be more complex to wrap your head around
> __free usage than around standard cleanup code.

Sure. Thankfully eventfd_ctx_put() is one of the pretty trivial ones, 
basically just calling kfree() on itself when the kref drops to 0.

> So unless __free is providing a noticeable simplification of some goto
> hell, cleanup in many functions or similar, I generally don't find it worth
> it...
> 
> 								Honza

Look into for instance mshv_irqfd_assign() and weep... And then imagine 
how much simpler it'd be if it were using __free() instead.

For the example in 2/2, I deliberately chose one callsite where it's 
trivial to deduce that behaviour is unchanged.

Bence

  reply	other threads:[~2026-11-06 14:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 16:22 Bence Csokas
2026-10-27 16:22 ` [PATCH v3 1/2] eventfd: Add scope-based cleanup capability Bence Csokas
2026-10-27 16:22 ` [PATCH v3 2/2] drm/syncobj: Use scope-based cleanup for eventfd_ctx Bence Csokas
2026-11-06  9:05 ` [PATCH v3 0/2] Add scope-based cleanup capability to eventfd_ctx Christian Brauner
2026-11-06  9:31   ` Bence Csókás
2026-11-06 14:13     ` Jan Kara
2026-11-06 14:30       ` Bence Csókás [this message]
2026-11-06 15:02         ` Jan Kara

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=803191ed-6597-4b8d-af7d-812b1b494fee@arm.com \
    --to=bence.csokas@arm.com \
    --cc=airlied@gmail.com \
    --cc=brauner@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®