Linux-HyperV List
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Yuho Choi <oss.patchbox@gmail.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
	Michael Kelley <mhklinux@outlook.com>,
	Emerson Busson <emersonbusson@gmail.com>,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] uio_hv_generic: Close the channel on remove if it is still open
Date: Mon, 30 Nov 2026 07:36:10 +0100	[thread overview]
Message-ID: <2026113020-parched-impeding-40b2@gregkh> (raw)
In-Reply-To: <CAGG=RgB-GKZFLsUSvDNO4ycRxfKhRPMT+10ecumpF3ZDHfR=yA@mail.gmail.com>

On Sun, Nov 29, 2026 at 06:25:13PM -0500, Yuho Choi wrote:
> Thank you for the review. I should have said this in the patch:
> I used an LLM to help write the patch and changelog. The test below the
> "---" was run as described.
> 
> On Sun, 29 Nov 2026 at 13:59, Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> >
> > > +     if (atomic_read(&pdata->refcnt)) {
> > > +             vmbus_disconnect_ring(dev->channel);
> > > +             pdata->keep_ring = true;
> >
> > What's to keep the refcnt from changing right after you read it?
> 
> It cannot change there. uio_unregister_device() clears idev->info under
> info_lock, and the uio core only calls ->open() and ->release() under
> that lock while info is set, so neither can run after it returns. I
> will add a comment.
> 
> > LLMs love to add boolean flags, are you sure you can't do it without it
> > and just properly use the reference count logic instead?
> 
> You are right, it is not needed. The refcnt check in hv_uio_remove() is
> enough, and I will drop the hv_uio_release() part, which I could not
> trigger.
> 
> > > +     }
> > > +     put_device(uio_dev);
> >
> > This feels wrong, how is this code working at all today without this
> > reference count decrement?
> 
> It pairs with the get_device() added above uio_unregister_device().
> hv_uio_channel_cb() uses info->uio_dev, and if the file is closed right
> after unregistering, uio_release() may free the uio device while the
> callback can still run. The reference keeps it until
> vmbus_disconnect_ring() returns.
> 
> > And why does pdata have a reference count independent of uio_dev?
> 
> It counts open files, so the channel is opened on the first open and
> closed on the last close (cdfa835c6e5e). The uio device's count also
> includes the registration, and the driver is not told when it drops.

Attempting to count open/close is a nightmare, I should have noticed
this in that patch.  A real object with a reference count should be used
instead of "open coding" a reference count like this.

thanks,

greg k-h

  reply	other threads:[~2026-11-30  6:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 18:38 [PATCH] uio_hv_generic: Close the channel on remove if it is still open Yuho Choi
2026-11-29 18:59 ` Greg Kroah-Hartman
2026-11-29 23:25   ` Yuho Choi
2026-11-30  6:36     ` Greg Kroah-Hartman [this message]
2026-11-29 19:05 ` sashiko-bot

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=2026113020-parched-impeding-40b2@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=decui@microsoft.com \
    --cc=emersonbusson@gmail.com \
    --cc=haiyangz@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=oss.patchbox@gmail.com \
    --cc=wei.liu@kernel.org \
    /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