Re: [External] Re: virtio_pci: Question about virtio_pci kernel module refcnt
From: Jason Wang <hidden>
Date: 2025-10-24 04:01:06
Also in:
lkml
On Fri, Oct 24, 2025 at 10:34 AM Zhang Tianci [off-list ref] wrote:
Hi, thanks for your reply On Fri, Oct 24, 2025 at 9:53 AM Jason Wang [off-list ref] wrote:quoted
On Thu, Oct 23, 2025 at 10:34 AM Zhang Tianci [off-list ref] wrote:quoted
Hi, thank you for your reply, but I still have a few questions: On Wed, Oct 22, 2025 at 7:31 PM Michael S. Tsirkin [off-list ref] wrote:quoted
On Wed, Oct 22, 2025 at 07:21:45PM +0800, Zhang Tianci wrote:quoted
Hi, I noticed that the reference count of the virtio_pci kernel module in the VM is always 0, even though there are at least two virtio block devices and one virtiofs device in the VM. Using rmmod virtio_pci can unload the virtio_pci module, but this renders the virtio block devices unusable.it removes them. you can put it back in and you will get devices again.But I can't do it anymore because the rootfs is no longer available, or rather, the OS is no longer available.quoted
quoted
I wonder if this result is expected? Why don't the virtio block devices and virtiofs device hold a reference count to the virtio_pci kernel module?because they don't have to.Is it due to design reasons or implementation reasons? Is it because the semantics of kernel module refcnt does not include such logical dependency?Note that virito has a bus so it follows the device/driver model so if I was not wrong the refcnt was handled by the driver core.Let's look at an example: $ lsmod | grep virtio virtio_balloon 20480 0 virtio_console 40960 1 virtiofs 32768 1 <- one virtiofs fuse 172032 2 virtiofs virtio_net 73728 0 net_failover 20480 1 virtio_net virtio_blk 32768 2 <- two block devices virtio_pci 24576 0 virtio_pci_legacy_dev 16384 1 virtio_pci virtio_pci_modern_dev 16384 1 virtio_pci virtio 16384 6 virtio_console,virtio_balloon,virtiofs,virtio_pci,virtio_blk,virtio_net virtio_ring 49152 6 virtio_console,virtio_balloon,virtiofs,virtio_pci,virtio_blk,virtio_net There are two virtio_blk devices which are vda and vdb, and one virtiofs device. We can find the block device and fs instance are holding virtio_blk and virtiofs' refcnts. But they don't hold virtio_pci(pci bus) or virtio(virtio bus) refcnts even though they logically depend on them.
My understanding is the driver must be unregistered while the device is being unregistered.
So I might need to consult the driver core maintainers?(I have cc'd them in this email.) Thanks, Tianci
Thanks