Re: [PATCH] uio_hv_generic: Close the channel on remove if it is still open
From: Greg Kroah-Hartman
Date: Mon Nov 30 2026 - 01:36:23 EST
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@xxxxxxxxxxxxxxxxxxx> 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