From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796020573; b=vhQK0Y3g9nkiVK6p9r+Rcekyis0jBE/c/OI+hrHC/+bTdQgcmYLdDT/hhKxzCMUoBbth tHzDD6OJYetNwyE2kxl+QJ3bDLg8GaG1dWOdsqt8yhSxKBH7xcMqKgZfklKOXlu8jJS5J CMtR6xf0Ehp+GZmBeJs5/KlZwfl9bVkS/PwNVxwWDqAZ93qmB1KAamQP+2FYmRUYm1P0R rV44JFMX+Bvz/QSyvTWuSuVqhf4sOi1dLoO0pww7VbFY7n9wAYVOcfOwY7RaBp1AeWX0K 5mML1Fd3x9xIOgzyqFTyH2GceUtrQ4uxwtTEFLUrvivkIwcJ0JEawFqUmaz3QjVIcFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020573; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=9AGjZggtv5lPTFTnAkcRIBpXw+ZJW2C2PTjjOtnpM0U=; b=5LBHsVk3jwTaIdxq0856zQy70twy7IIvyhI0dTSpVuMftdbf6HqgiixjWLCFW3ciZs5Z kI23VVciw2iNOt+J5kUaq5H7fIMZ8wosfI6MRnGc97bsiOjSrZiHThuYVF50g3/iZKLSx XDSsp1m0ySpL2acwspF/SgpICoU0Nlzbnzlvkdi8DAjytmmDGwTJlVusIRlvfuPmBycGe 5GmWAox2wJMSu0lln7sn8ZH+Gf6eLqve3pzuOjqDWikOu3/LtTM+GGM9xgDnWspYuxiLj p/jSfF0F9ZkWjjCVgq5m+Lg3QiFa2OmWaludtMw3+5C05XYHCJaFEuEFEY/3V4luhTQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=D1n2v3VZ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AC76606A31C; Mon, 30 Nov 2026 06:36:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=D1n2v3VZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27F401F000C1; Mon, 30 Nov 2026 06:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796020572; bh=9AGjZggtv5lPTFTnAkcRIBpXw+ZJW2C2PTjjOtnpM0U=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=D1n2v3VZa23H7j0tGmmXUA3uQFZayZlsUmzIUlZaIM2uZ+AtubXW8qBsUyrgrI0wy RmGS7t1VWGE8YY5TI1tksJ1rmhymyFd9OehXBN0SXtScjF1483j0CJ6zQYuXT7mKAZ 5uhixaJdW3MWXt5pWcOIwTw3O0jB7gkvnf+D0f3U= Date: Mon, 30 Nov 2026 07:36:10 +0100 From: Greg Kroah-Hartman To: Yuho Choi Cc: Haiyang Zhang , Wei Liu , Dexuan Cui , Michael Kelley , Emerson Busson , 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 Message-ID: <2026113020-parched-impeding-40b2@gregkh> References: <20261129184024.1092604-2-oss.patchbox@gmail.com> <2026112954-oops-pretext-8feb@gregkh> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 > 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