Bug 2128563

Summary: [RFE] Support to hotplug/hotunplug for usb controllers/hub/ccid/sata/virtio-serial controller
Product: Red Hat Enterprise Linux 9 Reporter: Han Han <hhan>
Component: libvirtAssignee: Virtualization Maintenance <virt-maint>
libvirt sub component: General QA Contact: Han Han <hhan>
Status: CLOSED MIGRATED Docs Contact:
Severity: unspecified    
Priority: low CC: lmen, meili, virt-maint, xuzhang, yalzhang, yduan, zhetang
Version: 9.2Keywords: FutureFeature, MigratedToJIRA, Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-07-07 20:34:13 UTC Type: Feature Request
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
the VM XML and hcis.sh none

Description Han Han 2022-09-21 04:27:53 UTC
Created attachment 1913243 [details]
the VM XML and hcis.sh

Description of problem:
Support hotplug/hotunplug to these USB controller/devices:
- nec-usb-xhci
- piix3-usb-uhci
- piix4-usb-uhci
- qemu-xhci
- usb-ehci
- usb-hub
- usb-ccid

Version-Release number of selected component (if applicable):
libvirt-8.7.0-1.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Start an VM
2. Try to attach USB nec-xhci controller/ccid controller/hub:
➜  ~ cat hub.xml 
<hub type='usb'/>
➜  ~ virsh attach-device rhel-9.2 hub.xml
error: Failed to attach device from hub.xml
error: Operation not supported: live attach of device 'hub' is not supported

➜  ~ cat nec-xhci.xml 
<controller type='usb' index='1' model='nec-xhci'/>
➜  ~ virsh attach-device rhel-9.2 nec-xhci.xml
error: Failed to attach device from nec-xhci.xml
error: Operation not supported: 'usb' controller cannot be hot plugged.

➜  ~ cat ccid.xml 
<controller type='ccid' index='0'/>
➜  ~ virsh attach-device rhel-9.2 ccid.xml
error: Failed to attach device from ccid.xml
error: Operation not supported: 'ccid' controller cannot be hot plugged.

In fact, hot-plug for these devices is supported in qemu:
➜  ~ virsh qemu-monitor-command rhel-9.2 '{"execute":"device_add","arguments":{"driver":"usb-hub","bus":"usb.0","port":5,"id":"usb-hub"}}'
{"return":{},"id":"libvirt-574"}
➜  ~ virsh qemu-monitor-command rhel-9.2 '{"execute":"device_del","arguments":{"id":"usb-hub"}}'                                          
{"return":{},"id":"libvirt-575"}

➜  ~ virsh qemu-monitor-command rhel-9.2 '{"execute":"device_add","arguments":{"driver":"usb-ccid","bus":"usb.0","port":5,"id":"usb-ccid"}}'
{"return":{},"id":"libvirt-576"}
➜  ~ virsh qemu-monitor-command rhel-9.2 '{"execute":"device_del","arguments":{"id":"usb-ccid"}}'                                           
{"return":{},"id":"libvirt-577"}

Run hcis.sh to get all the USB controllers with hot-plug/hot-unplug support:
➜  ~ bash /tmp/hcis.sh 
...
Hotplug/Hotunplug nec-usb-xhci
{"return":{},"id":"libvirt-594"}

{"return":{},"id":"libvirt-595"}

Hotplug/Hotunplug piix3-usb-uhci
{"return":{},"id":"libvirt-596"}

{"return":{},"id":"libvirt-597"}

Hotplug/Hotunplug piix4-usb-uhci
{"return":{},"id":"libvirt-598"}

{"return":{},"id":"libvirt-599"}

Hotplug/Hotunplug qemu-xhci
{"return":{},"id":"libvirt-600"}

{"return":{},"id":"libvirt-601"}

Hotplug/Hotunplug usb-ehci
{"return":{},"id":"libvirt-602"}

{"return":{},"id":"libvirt-603"}
 

Actual results:
As above

Expected results:
Support hotplug/hotunplug for the devices mentioned in the subject

Additional info:
See the VM XML and hcis.sh in the attachment

Comment 1 Han Han 2022-09-21 07:12:19 UTC
QEMU version: qemu-kvm-7.1.0-1.el9.x86_64

Comment 2 Han Han 2022-09-22 07:11:10 UTC
Support hot-plug/hot-unplug for virtio-serial/SATA as well:
virtio-serial:
➜  ~ cat serial.xml                         
<controller type='virtio-serial' index='0'/>
➜  ~ virsh attach-device rhel-9.2 serial.xml
error: Failed to attach device from serial.xml
error: Operation not supported: 'virtio-serial' controller cannot be hot plugged.

➜  ~ virsh qemu-monitor-command rhel-9.2 '{"execute":"device_add","arguments":{"driver":"virtio-serial-pci","id":"serial","bus":"pci.9"}}'
{"return":{},"id":"libvirt-609"}

(VM)[root@localhost ~]# lspci -s 09:00.0
09:00.0 Communication controller: Red Hat, Inc. Virtio console (rev 01)

➜  ~ virsh qemu-monitor-command rhel-9.2 --hmp info pci|grep serial -B6
  Bus  9, device   0, function 0:
    Class 1920: PCI device 1af4:1043
      PCI subsystem 1af4:1100
      IRQ 0, pin A
      BAR1: 32 bit memory at 0xfd800000 [0xfd800fff].
      BAR4: 64 bit prefetchable memory at 0xfba00000 [0xfba03fff].
      id "serial"
➜  ~ virsh qemu-monitor-command rhel-9.2 '{"execute":"device_del","arguments":{"id":"serial"}}'                                           
{"return":{},"id":"libvirt-619"}
(VM)[root@localhost ~]# lspci -s 09:00.0

➜  ~ virsh qemu-monitor-command rhel-9.2 --hmp info pci|grep serial -B6


SATA:
➜  ~ virsh qemu-monitor-command rhel-9.2 '{"execute":"device_add","arguments":{"driver":"ahci","id":"sata","bus":"pci.9"}}'
{"return":{},"id":"libvirt-666"}
(guest)[root@localhost ~]# lspci -s 09:00.0
09:00.0 SATA controller: Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 6 port SATA Controller [AHCI mode] (rev 02)

➜  ~ virsh qemu-monitor-command rhel-9.2 '{"execute":"device_del","arguments":{"id":"sata"}}'  
{"return":{},"id":"libvirt-668"}
[root@localhost ~]# lspci -s 09:00.0