Re: [PATCH] uio_hv_generic: Close the channel on remove if it is still open
From: Yuho Choi
Date: Sun Nov 29 2026 - 18:25:34 EST
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.
I will send a v2 without the flag, incorporating your comments.
Thanks