From d086d324e0b17ae54e3d6129095fff27a7fb3edd Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 14 Apr 2026 16:19:46 +0800 Subject: [PATCH 1/7] kata-types: Introduce independent IO thread for virtio-blk devices The 'indep_iothreads' field is introduced in Hypervisor to make it configurable for number of independent IO threads for virtio-blk devices. When set to a value greater than 0, creates independent IO threads that can be attached to virtio-blk devices during hotplug. Note that it requires 'enable_iothreads' to be true for virtio-blk devices to use these threads. Signed-off-by: Alex Lyn --- src/libs/kata-types/src/config/hypervisor/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/kata-types/src/config/hypervisor/mod.rs b/src/libs/kata-types/src/config/hypervisor/mod.rs index 8edfeaacd7..13dcb42254 100644 --- a/src/libs/kata-types/src/config/hypervisor/mod.rs +++ b/src/libs/kata-types/src/config/hypervisor/mod.rs @@ -1720,11 +1720,19 @@ pub struct Hypervisor { /// Enables the use of iothreads (data-plane). /// - /// When enabled, I/O operations are handled in a separate I/O thread. - /// This is currently only implemented for SCSI devices. + /// This is currently implemented for SCSI devices and for virtio-blk + /// hotplug when `indep_iothreads` is greater than 0. #[serde(default)] pub enable_iothreads: bool, + /// Number of independent IO threads for virtio-blk-pci devices. + /// + /// When set to a value greater than 0, creates independent IO threads + /// that can be attached to virtio-blk-pci devices during hotplug. + /// Requires enable_iothreads to be true for virtio-blk-pci devices to use these threads. + #[serde(default)] + pub indep_iothreads: u32, + /// Block device configuration information. #[serde(default, flatten)] pub blockdev_info: BlockDeviceInfo, From bdc57b16e5321e2a3fd1a3a738b1c28d4fc5c21f Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 14 Apr 2026 16:25:36 +0800 Subject: [PATCH 2/7] runtime-rs: Add configurable indep_iothreads in configurations It's useful and helpful to set indep_iothreads with enable_iothreads for high IO performance. And we need provide an entry for people to set it if needed. This commit will introduce two configurable items: - Makefile: DEFINDEPIOTHREADS when make build. - configurations: indep_iothreads for people to set. Signed-off-by: Alex Lyn --- src/runtime-rs/Makefile | 2 ++ .../configuration-qemu-coco-dev-runtime-rs.toml.in | 12 ++++++++++-- .../configuration-qemu-nvidia-gpu-runtime-rs.toml.in | 12 ++++++++++-- ...figuration-qemu-nvidia-gpu-snp-runtime-rs.toml.in | 12 ++++++++++-- ...figuration-qemu-nvidia-gpu-tdx-runtime-rs.toml.in | 12 ++++++++++-- .../config/configuration-qemu-runtime-rs.toml.in | 12 ++++++++++-- .../config/configuration-qemu-se-runtime-rs.toml.in | 12 ++++++++++-- .../config/configuration-qemu-snp-runtime-rs.toml.in | 12 ++++++++++-- .../config/configuration-qemu-tdx-runtime-rs.toml.in | 10 +++++++++- 9 files changed, 81 insertions(+), 15 deletions(-) diff --git a/src/runtime-rs/Makefile b/src/runtime-rs/Makefile index de0cc88878..ade064d12b 100644 --- a/src/runtime-rs/Makefile +++ b/src/runtime-rs/Makefile @@ -204,6 +204,7 @@ DEFVIRTIOFSQUEUESIZE ?= 1024 # Make sure you quote args. DEFVIRTIOFSEXTRAARGS ?= [\"--thread-pool-size=1\", \"-o\", \"announce_submounts\"] DEFENABLEIOTHREADS := false +DEFINDEPIOTHREADS := 0 DEFENABLEVHOSTUSERSTORE := false DEFVHOSTUSERSTOREPATH := $(PKGRUNDIR)/vhost-user DEFVALIDVHOSTUSERSTOREPATHS := [\"$(DEFVHOSTUSERSTOREPATH)\"] @@ -710,6 +711,7 @@ USER_VARS += DEFVIRTIOFSEXTRAARGS USER_VARS += DEFENABLEANNOTATIONS USER_VARS += DEFENABLEANNOTATIONS_COCO USER_VARS += DEFENABLEIOTHREADS +USER_VARS += DEFINDEPIOTHREADS USER_VARS += DEFSECCOMPSANDBOXPARAM USER_VARS += DEFENABLEVHOSTUSERSTORE USER_VARS += DEFVHOSTUSERSTOREPATH diff --git a/src/runtime-rs/config/configuration-qemu-coco-dev-runtime-rs.toml.in b/src/runtime-rs/config/configuration-qemu-coco-dev-runtime-rs.toml.in index 814f6682e5..494746bcb2 100644 --- a/src/runtime-rs/config/configuration-qemu-coco-dev-runtime-rs.toml.in +++ b/src/runtime-rs/config/configuration-qemu-coco-dev-runtime-rs.toml.in @@ -271,11 +271,19 @@ block_device_logical_sector_size = 0 block_device_physical_sector_size = 0 # Enable iothreads (data-plane) to be used. This causes IO to be -# handled in a separate IO thread. This is currently only implemented -# for SCSI. +# handled in a separate IO thread. This is currently implemented +# for virtio-scsi. For virtio-blk-pci hotplug, use indep_iothreads instead. # enable_iothreads = @DEFENABLEIOTHREADS@ +# Number of independent IO threads for virtio-blk-pci devices. +# When set to a value greater than 0, creates dedicated IO threads +# that are attached to virtio-blk-pci devices during hotplug. +# Requires enable_iothreads = true; has no effect otherwise. +# Default 0 (disabled). +# +indep_iothreads = @DEFINDEPIOTHREADS@ + # Enable pre allocation of VM RAM, default false # Enabling this will result in lower container density # as all of the memory will be allocated and locked diff --git a/src/runtime-rs/config/configuration-qemu-nvidia-gpu-runtime-rs.toml.in b/src/runtime-rs/config/configuration-qemu-nvidia-gpu-runtime-rs.toml.in index 0edc10ba5e..08a9a512bd 100644 --- a/src/runtime-rs/config/configuration-qemu-nvidia-gpu-runtime-rs.toml.in +++ b/src/runtime-rs/config/configuration-qemu-nvidia-gpu-runtime-rs.toml.in @@ -259,11 +259,19 @@ block_device_cache_direct = false block_device_cache_noflush = false # Enable iothreads (data-plane) to be used. This causes IO to be -# handled in a separate IO thread. This is currently only implemented -# for SCSI. +# handled in a separate IO thread. This is currently implemented +# for virtio-scsi. For virtio-blk-pci hotplug, use indep_iothreads instead. # enable_iothreads = @DEFENABLEIOTHREADS@ +# Number of independent IO threads for virtio-blk-pci devices. +# When set to a value greater than 0, creates dedicated IO threads +# that are attached to virtio-blk-pci devices during hotplug. +# Requires enable_iothreads = true; has no effect otherwise. +# Default 0 (disabled). +# +indep_iothreads = @DEFINDEPIOTHREADS@ + # Virtio queue size. Size: byte. default 128 queue_size = 128 diff --git a/src/runtime-rs/config/configuration-qemu-nvidia-gpu-snp-runtime-rs.toml.in b/src/runtime-rs/config/configuration-qemu-nvidia-gpu-snp-runtime-rs.toml.in index b24664366f..a2da3b79d5 100644 --- a/src/runtime-rs/config/configuration-qemu-nvidia-gpu-snp-runtime-rs.toml.in +++ b/src/runtime-rs/config/configuration-qemu-nvidia-gpu-snp-runtime-rs.toml.in @@ -300,11 +300,19 @@ block_device_cache_direct = false block_device_cache_noflush = false # Enable iothreads (data-plane) to be used. This causes IO to be -# handled in a separate IO thread. This is currently only implemented -# for SCSI. +# handled in a separate IO thread. This is currently implemented +# for virtio-scsi. For virtio-blk-pci hotplug, use indep_iothreads instead. # enable_iothreads = @DEFENABLEIOTHREADS@ +# Number of independent IO threads for virtio-blk-pci devices. +# When set to a value greater than 0, creates dedicated IO threads +# that are attached to virtio-blk-pci devices during hotplug. +# Requires enable_iothreads = true; has no effect otherwise. +# Default 0 (disabled). +# +indep_iothreads = @DEFINDEPIOTHREADS@ + # Virtio queue size. Size: byte. default 128 queue_size = 128 diff --git a/src/runtime-rs/config/configuration-qemu-nvidia-gpu-tdx-runtime-rs.toml.in b/src/runtime-rs/config/configuration-qemu-nvidia-gpu-tdx-runtime-rs.toml.in index ab24baf8ee..89a2d522fe 100644 --- a/src/runtime-rs/config/configuration-qemu-nvidia-gpu-tdx-runtime-rs.toml.in +++ b/src/runtime-rs/config/configuration-qemu-nvidia-gpu-tdx-runtime-rs.toml.in @@ -276,11 +276,19 @@ block_device_cache_direct = false block_device_cache_noflush = false # Enable iothreads (data-plane) to be used. This causes IO to be -# handled in a separate IO thread. This is currently only implemented -# for SCSI. +# handled in a separate IO thread. This is currently implemented +# for virtio-scsi. For virtio-blk-pci hotplug, use indep_iothreads instead. # enable_iothreads = @DEFENABLEIOTHREADS@ +# Number of independent IO threads for virtio-blk-pci devices. +# When set to a value greater than 0, creates dedicated IO threads +# that are attached to virtio-blk-pci devices during hotplug. +# Requires enable_iothreads = true; has no effect otherwise. +# Default 0 (disabled). +# +indep_iothreads = @DEFINDEPIOTHREADS@ + # Virtio queue size. Size: byte. default 128 queue_size = 128 diff --git a/src/runtime-rs/config/configuration-qemu-runtime-rs.toml.in b/src/runtime-rs/config/configuration-qemu-runtime-rs.toml.in index 4ed8d3ba38..70bae0be0d 100644 --- a/src/runtime-rs/config/configuration-qemu-runtime-rs.toml.in +++ b/src/runtime-rs/config/configuration-qemu-runtime-rs.toml.in @@ -256,11 +256,19 @@ block_device_logical_sector_size = 0 block_device_physical_sector_size = 0 # Enable iothreads (data-plane) to be used. This causes IO to be -# handled in a separate IO thread. This is currently only implemented -# for SCSI. +# handled in a separate IO thread. This is currently implemented +# for virtio-scsi. For virtio-blk-pci hotplug, use indep_iothreads instead. # enable_iothreads = @DEFENABLEIOTHREADS@ +# Number of independent IO threads for virtio-blk-pci devices. +# When set to a value greater than 0, creates dedicated IO threads +# that are attached to virtio-blk-pci devices during hotplug. +# Requires enable_iothreads = true; has no effect otherwise. +# Default 0 (disabled). +# +indep_iothreads = @DEFINDEPIOTHREADS@ + # Virtio queue size. Size: byte. default 128 queue_size = 128 diff --git a/src/runtime-rs/config/configuration-qemu-se-runtime-rs.toml.in b/src/runtime-rs/config/configuration-qemu-se-runtime-rs.toml.in index 014ba59d8a..91e7695882 100644 --- a/src/runtime-rs/config/configuration-qemu-se-runtime-rs.toml.in +++ b/src/runtime-rs/config/configuration-qemu-se-runtime-rs.toml.in @@ -255,11 +255,19 @@ block_device_logical_sector_size = 0 block_device_physical_sector_size = 0 # Enable iothreads (data-plane) to be used. This causes IO to be -# handled in a separate IO thread. This is currently only implemented -# for SCSI. +# handled in a separate IO thread. This is currently implemented +# for virtio-scsi. For virtio-blk-pci hotplug, use indep_iothreads instead. # enable_iothreads = @DEFENABLEIOTHREADS@ +# Number of independent IO threads for virtio-blk-pci devices. +# When set to a value greater than 0, creates dedicated IO threads +# that are attached to virtio-blk-pci devices during hotplug. +# Requires enable_iothreads = true; has no effect otherwise. +# Default 0 (disabled). +# +indep_iothreads = @DEFINDEPIOTHREADS@ + # Virtio queue size. Size: byte. default 128 queue_size = 128 diff --git a/src/runtime-rs/config/configuration-qemu-snp-runtime-rs.toml.in b/src/runtime-rs/config/configuration-qemu-snp-runtime-rs.toml.in index 59731bb3c8..66956a0409 100644 --- a/src/runtime-rs/config/configuration-qemu-snp-runtime-rs.toml.in +++ b/src/runtime-rs/config/configuration-qemu-snp-runtime-rs.toml.in @@ -292,11 +292,19 @@ block_device_logical_sector_size = 0 block_device_physical_sector_size = 0 # Enable iothreads (data-plane) to be used. This causes IO to be -# handled in a separate IO thread. This is currently only implemented -# for SCSI. +# handled in a separate IO thread. This is currently implemented +# for virtio-scsi. For virtio-blk-pci hotplug, use indep_iothreads instead. # enable_iothreads = @DEFENABLEIOTHREADS@ +# Number of independent IO threads for virtio-blk-pci devices. +# When set to a value greater than 0, creates dedicated IO threads +# that are attached to virtio-blk-pci devices during hotplug. +# Requires enable_iothreads = true; has no effect otherwise. +# Default 0 (disabled). +# +indep_iothreads = @DEFINDEPIOTHREADS@ + # Enable pre allocation of VM RAM, default false # Enabling this will result in lower container density # as all of the memory will be allocated and locked diff --git a/src/runtime-rs/config/configuration-qemu-tdx-runtime-rs.toml.in b/src/runtime-rs/config/configuration-qemu-tdx-runtime-rs.toml.in index 5a242c5145..485d042d61 100644 --- a/src/runtime-rs/config/configuration-qemu-tdx-runtime-rs.toml.in +++ b/src/runtime-rs/config/configuration-qemu-tdx-runtime-rs.toml.in @@ -270,10 +270,18 @@ block_device_physical_sector_size = 0 # Enable iothreads (data-plane) to be used. This causes IO to be # handled in a separate IO thread. This is currently implemented -# for virtio-scsi and virtio-blk. +# for virtio-scsi. For virtio-blk-pci hotplug, use indep_iothreads instead. # enable_iothreads = @DEFENABLEIOTHREADS@ +# Number of independent IO threads for virtio-blk-pci devices. +# When set to a value greater than 0, creates dedicated IO threads +# that are attached to virtio-blk-pci devices during hotplug. +# Requires enable_iothreads = true; has no effect otherwise. +# Default 0 (disabled). +# +indep_iothreads = @DEFINDEPIOTHREADS@ + # Enable pre allocation of VM RAM, default false # Enabling this will result in lower container density # as all of the memory will be allocated and locked From 86d165c0cc35b47e9f4663ad8d1c7c0b76f48a39 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 14 Apr 2026 16:30:03 +0800 Subject: [PATCH 3/7] kata-types: Introduce a dedicated annotation for indep_iothreads To make it more flexible when users want to set this feature, one more way to make it valid is via annotations. The dedicated annnotation of "io.katacontainers.config.hypervisor.indep_iothreads" is introduced within k8s clusters. Signed-off-by: Alex Lyn --- src/libs/kata-types/src/annotations/mod.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libs/kata-types/src/annotations/mod.rs b/src/libs/kata-types/src/annotations/mod.rs index 271872d78a..3e83864602 100644 --- a/src/libs/kata-types/src/annotations/mod.rs +++ b/src/libs/kata-types/src/annotations/mod.rs @@ -99,9 +99,14 @@ pub const KATA_ANNO_CFG_HYPERVISOR_JAILER_PATH: &str = pub const KATA_ANNO_CFG_HYPERVISOR_JAILER_HASH: &str = "io.katacontainers.config.hypervisor.jailer_hash"; /// A sandbox annotation to enable IO to be processed in a separate thread. -/// Supported currently for virtio-scsi driver. +/// Supported for the virtio-scsi driver, and also used for virtio-blk-pci when +/// combined with `KATA_ANNO_CFG_HYPERVISOR_INDEP_IO_THREADS`. pub const KATA_ANNO_CFG_HYPERVISOR_ENABLE_IO_THREADS: &str = "io.katacontainers.config.hypervisor.enable_iothreads"; +/// A sandbox annotation to specify the number of independent IO threads. +/// Used for virtio-blk-pci devices during hotplug. +pub const KATA_ANNO_CFG_HYPERVISOR_INDEP_IO_THREADS: &str = + "io.katacontainers.config.hypervisor.indep_iothreads"; /// The hash type used for assets verification pub const KATA_ANNO_CFG_HYPERVISOR_ASSET_HASH_TYPE: &str = "io.katacontainers.config.hypervisor.asset_hash_type"; @@ -570,6 +575,18 @@ impl Annotation { return Err(bool_err); } }, + KATA_ANNO_CFG_HYPERVISOR_INDEP_IO_THREADS => match self.get_value::(key) { + Ok(r) => { + let indep_iothreads = r.unwrap_or_default(); + hv.indep_iothreads = indep_iothreads; + } + Err(_e) => { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "failed to parse indep_iothreads", + )); + } + }, // Hypervisor Block Device related annotations KATA_ANNO_CFG_HYPERVISOR_BLOCK_DEV_DRIVER => { hv.blockdev_info.block_device_driver = value.to_string(); From 36e626649d16d8b54dbb75ef37ce402b6a886734 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 14 Apr 2026 16:35:42 +0800 Subject: [PATCH 4/7] runtime-rs: Add support independent IO threads in qemu cmdline To make it work well for independent IO threads for virtio-blk devices. A new method for independent IO threads for virtio-blk hotplug devices within qemu command line. Note that as ObjectIoThread has been done for days, it can be directly reused in this case. Signed-off-by: Alex Lyn --- .../hypervisor/src/qemu/cmdline_generator.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs index 997f708205..9e4668f0e7 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs @@ -2631,6 +2631,9 @@ impl<'a> QemuCmdLine<'a> { qemu_cmd_line.add_scsi_controller(); } + // Add independent IO threads for virtio-blk hotplug devices + qemu_cmd_line.add_indep_iothreads(); + if config.device_info.reclaim_guest_freed_memory { qemu_cmd_line.add_virtio_balloon(); } @@ -2738,6 +2741,19 @@ impl<'a> QemuCmdLine<'a> { self.devices.push(Box::new(virtio_scsi)); } + /// Add independent IO threads for virtio-blk devices. + /// These threads can be attached to virtio-blk devices during hotplug. + fn add_indep_iothreads(&mut self) { + // Only create independent IO threads if enable_iothreads is true and indep_iothreads > 0 + if self.config.enable_iothreads && self.config.indep_iothreads > 0 { + for i in 0..self.config.indep_iothreads { + let iothread_id = format!("indep_iothread_{}", i); + let iothread = ObjectIoThread::new(&iothread_id); + self.devices.push(Box::new(iothread)); + } + } + } + pub fn add_virtiofs_share( &mut self, virtiofsd_socket_path: &str, From 980ecfdd9665a9dd43fc1e84375e0b2e26362416 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 14 Apr 2026 17:10:46 +0800 Subject: [PATCH 5/7] runtime-rs: Add support iodependent iothreads within virtio-blk 1. Determine iothread for virtio-blk devices, only attach iothread when: (1) enable_iothreads is true (2) indep_iothreads > 0 (3) block driver is not virtio-scsi (i.e., it's virtio-blk) And for more complex cases, some enhancements will be done in future 2. Add iothread parameter for virtio-blk devices if specified. If iothreads set and passed, we will have to set it correctly for virtio-blk devices via qmp with device_add arguments. Signed-off-by: Alex Lyn --- .../crates/hypervisor/src/qemu/inner.rs | 18 ++++++++++++++++++ .../crates/hypervisor/src/qemu/qmp.rs | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs index 87abdb505e..87e1f40fd4 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs @@ -949,6 +949,23 @@ impl QemuInner { } DeviceType::Block(mut block_device) => { let block_driver = &self.config.blockdev_info.block_device_driver; + + // Determine iothread for virtio-blk devices + // Only attach iothread when: + // 1. enable_iothreads is true + // 2. indep_iothreads > 0 + // 3. block driver is not virtio-scsi (i.e., it's virtio-blk) + // 4. TODO: for more complex cases + let iothread = if self.config.enable_iothreads + && self.config.indep_iothreads > 0 + && *block_driver != kata_types::config::hypervisor::VIRTIO_SCSI + { + // Use the first independent iothread (indep_iothread_0) + Some("indep_iothread_0") + } else { + None + }; + let (pci_path, addr_str) = qmp .hotplug_block_device( block_driver, @@ -966,6 +983,7 @@ impl QemuInner { block_device.config.logical_sector_size, block_device.config.physical_sector_size, &block_device.config.format, + iothread, ) .context("hotplug block device")?; diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/qmp.rs b/src/runtime-rs/crates/hypervisor/src/qemu/qmp.rs index c107a6fb85..d6ada37fbd 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/qmp.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/qmp.rs @@ -688,6 +688,7 @@ impl Qmp { logical_block_size: u32, physical_block_size: u32, format: &BlockDeviceFormat, + iothread: Option<&str>, ) -> Result<(Option, Option)> { // `blockdev-add` let node_name = format!("drive-{index}"); @@ -893,6 +894,15 @@ impl Qmp { blkdev_add_args.insert("share-rw".to_string(), true.into()); } + // Add iothread parameter for virtio-blk devices if specified + if let Some(iothread_id) = iothread { + info!( + sl!(), + "hotplug_block_device(): attaching to iothread: {}", iothread_id + ); + blkdev_add_args.insert("iothread".to_owned(), iothread_id.to_string().into()); + } + info!( sl!(), "hotplug_block_device(): device_add arguments: bus: {}, id: {}, driver: {}, blkdev_add_args: {:#?}", From b0ebbc685d7c666041bffa1bae082f29d60c0d62 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Mon, 8 Jun 2026 14:25:49 +0800 Subject: [PATCH 6/7] runtime-rs: Add support for independent iothreads for virtio blk devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As independent iothreads can work in both virtio-scsi and virtio-blk devices, this commit aims to enable such feature in virtio-blk-pci devices. Signed-off-by: Fabiano FidĂȘncio Signed-off-by: Alex Lyn --- .../crates/hypervisor/src/qemu/cmdline_generator.rs | 12 +++++++----- src/runtime-rs/crates/hypervisor/src/qemu/inner.rs | 9 +++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs index 9e4668f0e7..7fc991d107 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs @@ -15,7 +15,7 @@ use std::borrow::Cow; use anyhow::{anyhow, Context, Result}; use async_trait::async_trait; -use kata_types::config::hypervisor::VIRTIO_SCSI; +use kata_types::config::hypervisor::{VIRTIO_BLK_PCI, VIRTIO_SCSI}; use kata_types::rootless::is_rootless; use serde::{Deserialize, Serialize}; use serde_json; @@ -2631,8 +2631,10 @@ impl<'a> QemuCmdLine<'a> { qemu_cmd_line.add_scsi_controller(); } - // Add independent IO threads for virtio-blk hotplug devices - qemu_cmd_line.add_indep_iothreads(); + // Add independent IO threads only when hotplug uses virtio-blk-pci. + if config.blockdev_info.block_device_driver == VIRTIO_BLK_PCI { + qemu_cmd_line.add_indep_iothreads(); + } if config.device_info.reclaim_guest_freed_memory { qemu_cmd_line.add_virtio_balloon(); @@ -2741,8 +2743,8 @@ impl<'a> QemuCmdLine<'a> { self.devices.push(Box::new(virtio_scsi)); } - /// Add independent IO threads for virtio-blk devices. - /// These threads can be attached to virtio-blk devices during hotplug. + /// Add independent IO threads for virtio-blk-pci devices. + /// These threads can be attached to virtio-blk-pci devices during hotplug. fn add_indep_iothreads(&mut self) { // Only create independent IO threads if enable_iothreads is true and indep_iothreads > 0 if self.config.enable_iothreads && self.config.indep_iothreads > 0 { diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs index 87e1f40fd4..655de37d69 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs @@ -25,7 +25,7 @@ use anyhow::{anyhow, Context, Result}; use async_trait::async_trait; use kata_sys_util::netns::NetnsGuard; use kata_types::build_path; -use kata_types::config::hypervisor::{RootlessUser, VIRTIO_BLK_CCW}; +use kata_types::config::hypervisor::{RootlessUser, VIRTIO_BLK_CCW, VIRTIO_BLK_PCI}; use kata_types::rootless::is_rootless; use kata_types::{ capabilities::{Capabilities, CapabilityBits}, @@ -950,15 +950,15 @@ impl QemuInner { DeviceType::Block(mut block_device) => { let block_driver = &self.config.blockdev_info.block_device_driver; - // Determine iothread for virtio-blk devices + // Determine iothread for hotplugged virtio-blk-pci devices. // Only attach iothread when: // 1. enable_iothreads is true // 2. indep_iothreads > 0 - // 3. block driver is not virtio-scsi (i.e., it's virtio-blk) + // 3. block driver is virtio-blk-pci // 4. TODO: for more complex cases let iothread = if self.config.enable_iothreads && self.config.indep_iothreads > 0 - && *block_driver != kata_types::config::hypervisor::VIRTIO_SCSI + && block_driver == VIRTIO_BLK_PCI { // Use the first independent iothread (indep_iothread_0) Some("indep_iothread_0") @@ -1066,6 +1066,7 @@ impl QemuInner { logical_sector_size, physical_sector_size, &BlockDeviceFormat::default(), + None, ) .context("hotplug block device")?; From 854e76fb477e83f615456a3e9ff3d2f4a90472cc Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Mon, 8 Jun 2026 14:28:35 +0800 Subject: [PATCH 7/7] kata-types: Enhance related stuff for independent io threads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor comments and tests stuff for independent iothreads. Signed-off-by: Fabiano FidĂȘncio Signed-off-by: Alex Lyn --- src/libs/kata-types/src/annotations/mod.rs | 5 +---- .../kata-types/src/config/hypervisor/mod.rs | 5 +++-- src/libs/kata-types/tests/test_config.rs | 19 ++++++++++++------- .../tests/texture/configuration-anno-0.toml | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/libs/kata-types/src/annotations/mod.rs b/src/libs/kata-types/src/annotations/mod.rs index 3e83864602..b2b2cad6cb 100644 --- a/src/libs/kata-types/src/annotations/mod.rs +++ b/src/libs/kata-types/src/annotations/mod.rs @@ -581,10 +581,7 @@ impl Annotation { hv.indep_iothreads = indep_iothreads; } Err(_e) => { - return Err(io::Error::new( - io::ErrorKind::InvalidData, - "failed to parse indep_iothreads", - )); + return Err(u32_err); } }, // Hypervisor Block Device related annotations diff --git a/src/libs/kata-types/src/config/hypervisor/mod.rs b/src/libs/kata-types/src/config/hypervisor/mod.rs index 13dcb42254..6ff534c2be 100644 --- a/src/libs/kata-types/src/config/hypervisor/mod.rs +++ b/src/libs/kata-types/src/config/hypervisor/mod.rs @@ -1720,8 +1720,9 @@ pub struct Hypervisor { /// Enables the use of iothreads (data-plane). /// - /// This is currently implemented for SCSI devices and for virtio-blk - /// hotplug when `indep_iothreads` is greater than 0. + /// This is currently implemented for SCSI devices and for virtio-blk-pci devices + /// that support hotplug when `indep_iothreads` is greater than 0. + /// When enabled, I/O operations are handled in a separate I/O thread. #[serde(default)] pub enable_iothreads: bool, diff --git a/src/libs/kata-types/tests/test_config.rs b/src/libs/kata-types/tests/test_config.rs index 6752a32e0f..8a670ae492 100644 --- a/src/libs/kata-types/tests/test_config.rs +++ b/src/libs/kata-types/tests/test_config.rs @@ -14,12 +14,13 @@ mod tests { KATA_ANNO_CFG_HYPERVISOR_DEFAULT_VCPUS, KATA_ANNO_CFG_HYPERVISOR_ENABLE_GUEST_SWAP, KATA_ANNO_CFG_HYPERVISOR_ENABLE_HUGEPAGES, KATA_ANNO_CFG_HYPERVISOR_ENABLE_IO_THREADS, KATA_ANNO_CFG_HYPERVISOR_FILE_BACKED_MEM_ROOT_DIR, - KATA_ANNO_CFG_HYPERVISOR_GUEST_HOOK_PATH, KATA_ANNO_CFG_HYPERVISOR_JAILER_PATH, - KATA_ANNO_CFG_HYPERVISOR_KERNEL_PATH, KATA_ANNO_CFG_HYPERVISOR_MEMORY_PREALLOC, - KATA_ANNO_CFG_HYPERVISOR_MEMORY_SLOTS, KATA_ANNO_CFG_HYPERVISOR_PATH, - KATA_ANNO_CFG_HYPERVISOR_VHOSTUSER_STORE_PATH, KATA_ANNO_CFG_HYPERVISOR_VIRTIO_FS_DAEMON, - KATA_ANNO_CFG_HYPERVISOR_VIRTIO_FS_EXTRA_ARGS, KATA_ANNO_CFG_HYPERVISOR_VIRTIO_MEM, - KATA_ANNO_CFG_KERNEL_MODULES, KATA_ANNO_CFG_RUNTIME_NAME, + KATA_ANNO_CFG_HYPERVISOR_GUEST_HOOK_PATH, KATA_ANNO_CFG_HYPERVISOR_INDEP_IO_THREADS, + KATA_ANNO_CFG_HYPERVISOR_JAILER_PATH, KATA_ANNO_CFG_HYPERVISOR_KERNEL_PATH, + KATA_ANNO_CFG_HYPERVISOR_MEMORY_PREALLOC, KATA_ANNO_CFG_HYPERVISOR_MEMORY_SLOTS, + KATA_ANNO_CFG_HYPERVISOR_PATH, KATA_ANNO_CFG_HYPERVISOR_VHOSTUSER_STORE_PATH, + KATA_ANNO_CFG_HYPERVISOR_VIRTIO_FS_DAEMON, KATA_ANNO_CFG_HYPERVISOR_VIRTIO_FS_EXTRA_ARGS, + KATA_ANNO_CFG_HYPERVISOR_VIRTIO_MEM, KATA_ANNO_CFG_KERNEL_MODULES, + KATA_ANNO_CFG_RUNTIME_NAME, }; use kata_types::config::KataConfig; use kata_types::config::{QemuConfig, TomlConfig}; @@ -122,6 +123,10 @@ mod tests { KATA_ANNO_CFG_HYPERVISOR_ENABLE_IO_THREADS.to_string(), "false".to_string(), ); + anno_hash.insert( + KATA_ANNO_CFG_HYPERVISOR_INDEP_IO_THREADS.to_string(), + "3".to_string(), + ); anno_hash.insert( KATA_ANNO_CFG_HYPERVISOR_ENABLE_IO_THREADS.to_string(), "false".to_string(), @@ -192,7 +197,7 @@ mod tests { assert!(!hv.memory_info.enable_guest_swap); assert_eq!(hv.memory_info.default_memory, 100); assert!(!hv.enable_iothreads); - assert!(!hv.enable_iothreads); + assert_eq!(hv.indep_iothreads, 3); assert_eq!( hv.memory_info.file_mem_backend, "./test_file_backend_mem_root" diff --git a/src/libs/kata-types/tests/texture/configuration-anno-0.toml b/src/libs/kata-types/tests/texture/configuration-anno-0.toml index dbc165731f..a9ee7b3d69 100644 --- a/src/libs/kata-types/tests/texture/configuration-anno-0.toml +++ b/src/libs/kata-types/tests/texture/configuration-anno-0.toml @@ -19,7 +19,7 @@ default_maxvcpus = 64 machine_type = "q35" confidential_guest = true rootless = true -enable_annotations = ["shared_fs","path", "ctlpath","jailer_path","enable_iothreads","default_memory","memory_slots","enable_mem_prealloc","enable_hugepages","file_mem_backend","enable_virtio_mem","enable_guest_swap","default_vcpus","virtio_fs_extra_args","block_device_driver","vhost_user_store_path","kernel","guest_hook_path","block_device_cache_noflush","virtio_fs_daemon","blk_logical_sector_size","blk_physical_sector_size"] +enable_annotations = ["shared_fs","path", "ctlpath","jailer_path","enable_iothreads","indep_iothreads","default_memory","memory_slots","enable_mem_prealloc","enable_hugepages","file_mem_backend","enable_virtio_mem","enable_guest_swap","default_vcpus","virtio_fs_extra_args","block_device_driver","vhost_user_store_path","kernel","guest_hook_path","block_device_cache_noflush","virtio_fs_daemon","blk_logical_sector_size","blk_physical_sector_size"] machine_accelerators="noapic" default_bridges = 2 default_memory = 128