From a22220576c61c5922924904c35a3310f7722f58e Mon Sep 17 00:00:00 2001 From: zhangpengrui Date: Mon, 16 Jun 2025 12:09:20 +0800 Subject: [PATCH 1/2] QEMU update to version 8.2.0-36: - Revert "backends/iommufd: Make iommufd_backend_*() return bool" - qapi/misc-target: Add Virtcca capability struct and query command. Signed-off-by: zhangpengrui --- Fix-error-in-virtCCA-CoDA-scenario.patch | 28 ++++ ...iommufd-Make-iommufd_backend_-return.patch | 153 ++++++++++++++++++ ...-Add-Virtcca-capability-struct-and-q.patch | 132 +++++++++++++++ qemu.spec | 8 +- 4 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 Fix-error-in-virtCCA-CoDA-scenario.patch create mode 100644 Revert-backends-iommufd-Make-iommufd_backend_-return.patch create mode 100644 qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch diff --git a/Fix-error-in-virtCCA-CoDA-scenario.patch b/Fix-error-in-virtCCA-CoDA-scenario.patch new file mode 100644 index 00000000..d9da628c --- /dev/null +++ b/Fix-error-in-virtCCA-CoDA-scenario.patch @@ -0,0 +1,28 @@ +From f80776f3dfd1d05ef3328d5be9fe42df095f4bc1 Mon Sep 17 00:00:00 2001 +From: yxk +Date: Mon, 21 Apr 2025 04:00:46 -0400 +Subject: [PATCH] Fix error in virtCCA CoDA scenario. + +Add 'iommu_type' VFIO_TYPE1v2_S_IOMMU in vfio_get_iommu_class +to avoid error happens in virtCCA CoDA scenario. + +Signed-off-by: yxk +--- + hw/vfio/container.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/hw/vfio/container.c b/hw/vfio/container.c +index 64eacfd912..539cf34b20 100644 +--- a/hw/vfio/container.c ++++ b/hw/vfio/container.c +@@ -439,6 +439,7 @@ static const VFIOIOMMUClass *vfio_get_iommu_class(int iommu_type, Error **errp) + switch (iommu_type) { + case VFIO_TYPE1v2_IOMMU: + case VFIO_TYPE1_IOMMU: ++ case VFIO_TYPE1v2_S_IOMMU: + klass = object_class_by_name(TYPE_VFIO_IOMMU_LEGACY); + break; + case VFIO_SPAPR_TCE_v2_IOMMU: +-- +2.33.0 + diff --git a/Revert-backends-iommufd-Make-iommufd_backend_-return.patch b/Revert-backends-iommufd-Make-iommufd_backend_-return.patch new file mode 100644 index 00000000..1d952d3a --- /dev/null +++ b/Revert-backends-iommufd-Make-iommufd_backend_-return.patch @@ -0,0 +1,153 @@ +From 25c0fad8f9a2ac10f184d346f87da03506314ed6 Mon Sep 17 00:00:00 2001 +From: Zhou Wang +Date: Fri, 13 Jun 2025 11:26:54 +0800 +Subject: [PATCH] Revert "backends/iommufd: Make iommufd_backend_*() return + bool" + +Revert "backends/iommufd: Make iommufd_backend_*() return bool" and +fix the way of vdpa codes use related iommufd APIs. + +Signed-off-by: Zhou Wang +Signed-off-by: Jian Cai +--- + backends/iommufd.c | 29 ++++++++++++++++------------- + backends/trace-events | 4 ++-- + hw/virtio/vdpa-dev-iommufd.c | 6 +++--- + include/sysemu/iommufd.h | 6 +++--- + 4 files changed, 24 insertions(+), 21 deletions(-) + +diff --git a/backends/iommufd.c b/backends/iommufd.c +index 62df6e41f0..4446efaa32 100644 +--- a/backends/iommufd.c ++++ b/backends/iommufd.c +@@ -74,21 +74,23 @@ static void iommufd_backend_class_init(ObjectClass *oc, void *data) + object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd); + } + +-bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) ++int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) + { +- int fd; ++ int fd, ret = 0; + + if (be->owned && !be->users) { + fd = qemu_open("/dev/iommu", O_RDWR, errp); + if (fd < 0) { +- return false; ++ ret = fd; ++ goto out; + } + be->fd = fd; + } + be->users++; +- +- trace_iommufd_backend_connect(be->fd, be->owned, be->users); +- return true; ++out: ++ trace_iommufd_backend_connect(be->fd, be->owned, ++ be->users, ret); ++ return ret; + } + + void iommufd_backend_disconnect(IOMMUFDBackend *be) +@@ -105,24 +107,25 @@ out: + trace_iommufd_backend_disconnect(be->fd, be->users); + } + +-bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, +- Error **errp) ++int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, ++ Error **errp) + { +- int fd = be->fd; ++ int ret, fd = be->fd; + struct iommu_ioas_alloc alloc_data = { + .size = sizeof(alloc_data), + .flags = 0, + }; + +- if (ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data)) { ++ ret = ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data); ++ if (ret) { + error_setg_errno(errp, errno, "Failed to allocate ioas"); +- return false; ++ return ret; + } + + *ioas_id = alloc_data.out_ioas_id; +- trace_iommufd_backend_alloc_ioas(fd, *ioas_id); ++ trace_iommufd_backend_alloc_ioas(fd, *ioas_id, ret); + +- return true; ++ return ret; + } + + void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id) +diff --git a/backends/trace-events b/backends/trace-events +index 8fe77149b2..f8592a2711 100644 +--- a/backends/trace-events ++++ b/backends/trace-events +@@ -7,13 +7,13 @@ dbus_vmstate_loading(const char *id) "id: %s" + dbus_vmstate_saving(const char *id) "id: %s" + + # iommufd.c +-iommufd_backend_connect(int fd, bool owned, uint32_t users) "fd=%d owned=%d users=%d" ++iommufd_backend_connect(int fd, bool owned, uint32_t users, int ret) "fd=%d owned=%d users=%d (%d)" + iommufd_backend_disconnect(int fd, uint32_t users) "fd=%d users=%d" + iommu_backend_set_fd(int fd) "pre-opened /dev/iommu fd=%d" + iommufd_backend_map_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, void *vaddr, bool readonly, int ret) " iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" addr=%p readonly=%d (%d)" + iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int ret) " Unmap nonexistent mapping: iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" (%d)" + iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int ret) " iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" (%d)" +-iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=%d ioas=%d" ++iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas, int ret) " iommufd=%d ioas=%d (%d)" + iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id, uint32_t pt_id, uint32_t flags, uint32_t hwpt_type, uint32_t len, uint64_t data_ptr, uint32_t out_hwpt_id, int ret) " iommufd=%d dev_id=%u pt_id=%u flags=0x%x hwpt_type=%u len=%u data_ptr=0x%"PRIx64" out_hwpt=%u (%d)" + iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=%d id=%d (%d)" + iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int ret) " iommufd=%d hwpt=%u enable=%d (%d)" +diff --git a/hw/virtio/vdpa-dev-iommufd.c b/hw/virtio/vdpa-dev-iommufd.c +index 2b0498f9dc..f5718bae99 100644 +--- a/hw/virtio/vdpa-dev-iommufd.c ++++ b/hw/virtio/vdpa-dev-iommufd.c +@@ -186,12 +186,12 @@ static int vhost_vdpa_container_connect_iommufd(VDPAIOMMUFDContainer *container) + return -1; + } + +- if (!iommufd_backend_connect(iommufd, &err)) { ++ if (iommufd_backend_connect(iommufd, &err)) { + error_report_err(err); + return -1; + } + +- if (!iommufd_backend_alloc_ioas(iommufd, &ioas_id, &err)) { ++ if (iommufd_backend_alloc_ioas(iommufd, &ioas_id, &err)) { + error_report_err(err); + iommufd_backend_disconnect(iommufd); + return -1; +@@ -480,4 +480,4 @@ void vhost_vdpa_detach_container(VhostVdpaDevice *vdev) + vhost_vdpa_container_disconnect_iommufd(container); + + vhost_vdpa_destroy_container(container); +-} +\ No newline at end of file ++} +diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h +index 0531a4ad98..908c94d811 100644 +--- a/include/sysemu/iommufd.h ++++ b/include/sysemu/iommufd.h +@@ -43,11 +43,11 @@ typedef struct IOMMUFDViommu { + uint32_t viommu_id; + } IOMMUFDViommu; + +-bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); ++int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); + void iommufd_backend_disconnect(IOMMUFDBackend *be); + +-bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, +- Error **errp); ++int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, ++ Error **errp); + void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id); + int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova, + ram_addr_t size, void *vaddr, bool readonly); +-- +2.33.0 + diff --git a/qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch b/qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch new file mode 100644 index 00000000..35140210 --- /dev/null +++ b/qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch @@ -0,0 +1,132 @@ +From a06fe21504564a75d2cfdd3b133b67719edc78ec Mon Sep 17 00:00:00 2001 +From: panhengchang +Date: Thu, 5 Jun 2025 10:05:11 +0800 +Subject: [PATCH] qapi/misc-target: Add Virtcca capability struct and query + command. + +Introduce a new QAPI struct "VirtccaCapility" to represent the +VIRTCCA feature capability with a boolean "enabled" filed. +Add "query-virtcca-capabilties" command to retrieve this capability +information, which targeting HISI AARCH64 platforms. + +Signed-off-by: panghengchang +--- + qapi/misc-target.json | 29 +++++++++++++++++++++++++++++ + target/arm/kvm-tmm.c | 33 +++++++++++++++++++++++++++++++++ + tests/qtest/qmp-cmd-test.c | 1 + + 3 files changed, 63 insertions(+) + +diff --git a/qapi/misc-target.json b/qapi/misc-target.json +index 88291453ba..76ed52b65b 100644 +--- a/qapi/misc-target.json ++++ b/qapi/misc-target.json +@@ -487,3 +487,32 @@ + { 'command': 'xen-event-inject', + 'data': { 'port': 'uint32' }, + 'if': 'TARGET_I386' } ++ ++## ++# @VirtccaCapability: ++# ++# The struct describes capability for VIRTCCA feature. ++# ++# Since: 8.2.0 ++## ++{ 'struct': 'VirtccaCapability', ++ 'data': { 'enabled': 'bool' }, ++ 'if': 'TARGET_AARCH64' } ++ ++## ++# @query-virtcca-capabilities: ++# ++# This command is used to get the VIRTCCA capabilities, and is supported ++# on HISI AARCH64 platforms only. ++# ++# Returns: VirtccaCapability objects. ++# ++# Since: 8.2.0 ++# ++# Example: ++# ++# -> { "execute": "query-virtcca-capabilities" } ++# <- { "return": { "enabled": true } } ++## ++{ 'command': 'query-virtcca-capabilities', 'returns': 'VirtccaCapability', ++ 'if': 'TARGET_AARCH64' } +\ No newline at end of file +diff --git a/target/arm/kvm-tmm.c b/target/arm/kvm-tmm.c +index ea6bcc0f40..d18ac10896 100644 +--- a/target/arm/kvm-tmm.c ++++ b/target/arm/kvm-tmm.c +@@ -15,11 +15,13 @@ + #include "kvm_arm.h" + #include "migration/blocker.h" + #include "qapi/error.h" ++#include "qapi/qapi-commands-misc-target.h" + #include "qom/object_interfaces.h" + #include "sysemu/kvm.h" + #include "sysemu/runstate.h" + #include "hw/loader.h" + #include "linux-headers/asm-arm64/kvm.h" ++#include + + #define TYPE_TMM_GUEST "tmm-guest" + OBJECT_DECLARE_SIMPLE_TYPE(TmmGuest, TMM_GUEST) +@@ -27,6 +29,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(TmmGuest, TMM_GUEST) + #define TMM_PAGE_SIZE qemu_real_host_page_size() + #define TMM_MAX_PMU_CTRS 0x20 + #define TMM_MAX_CFG 6 ++#define TMM_MEMORY_INFO_SYSFS "/sys/kernel/tmm/memory_info" + + typedef struct { + uint32_t kae_vf_num; +@@ -406,3 +409,33 @@ static void tmm_register_types(void) + type_register_static(&tmm_guest_info); + } + type_init(tmm_register_types); ++ ++static VirtccaCapability *virtcca_get_capabilities(Error **errp) ++{ ++ VirtccaCapability *cap = NULL; ++ uint64_t tmi_version = 0; ++ int rc = 0; ++ ++ if (kvm_ioctl(kvm_state, KVM_GET_TMI_VERSION, &tmi_version) < 0) { ++ error_setg(errp, "VIRTCCA is not enabled in KVM"); ++ return NULL; ++ } ++ ++ rc = access(TMM_MEMORY_INFO_SYSFS, R_OK); ++ if (rc < 0) { ++ error_setg_errno(errp, errno, "VIRTCCA: Failed to read %s", ++ TMM_MEMORY_INFO_SYSFS); ++ return NULL; ++ } ++ ++ cap = g_new0(VirtccaCapability, 1); ++ ++ cap->enabled = true; ++ ++ return cap; ++} ++ ++VirtccaCapability *qmp_query_virtcca_capabilities(Error **errp) ++{ ++ return virtcca_get_capabilities(errp); ++} +\ No newline at end of file +diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c +index 2c15f60958..df1f93ea6a 100644 +--- a/tests/qtest/qmp-cmd-test.c ++++ b/tests/qtest/qmp-cmd-test.c +@@ -110,6 +110,7 @@ static bool query_is_ignored(const char *cmd) + "query-sev-capabilities", + "query-sgx", + "query-sgx-capabilities", ++ "query-virtcca-capabilities", + /* Success depends on enabling dirty page rate limit */ + "query-vcpu-dirty-limit", + NULL +-- +2.33.0 + diff --git a/qemu.spec b/qemu.spec index 5acda162..e33700c2 100644 --- a/qemu.spec +++ b/qemu.spec @@ -3,7 +3,7 @@ Name: qemu Version: 8.2.0 -Release: 35 +Release: 36 Epoch: 11 Summary: QEMU is a generic and open source machine emulator and virtualizer License: GPLv2 and BSD and MIT and CC-BY-SA-4.0 @@ -932,6 +932,8 @@ Patch0915: memory-Optimize-flatview-ioeventfd-processing.patch Patch0916: vdpa-iommufd-All-vdpa-devices-perform-only-one-log_s.patch Patch0917: Revert-target-arm-Change-arm_cpu_mp_affinity-when-en.patch Patch0918: target-arm-support-the-IPIV-feature.patch +Patch0919: Fix-error-in-virtCCA-CoDA-scenario.patch +Patch0920: Revert-backends-iommufd-Make-iommufd_backend_-return.patch BuildRequires: flex BuildRequires: gcc @@ -1534,6 +1536,10 @@ getent passwd qemu >/dev/null || \ %endif %changelog +* Mon Jun 16 2025 Pengrui Zhang - 11:8.2.0-36 +- Fix error in virtCCA CoDA scenario. +- Revert "backends/iommufd: Make iommufd_backend_*() return bool" + * Wed Jun 04 2025 Jason Zeng - 11:8.2.0-35 - Enable Intel qatzip and qpl acceleration for multifd live migration. -- Gitee From b2cfeafab2f821c653c002c01862934aac4375d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E7=91=9E?= Date: Mon, 16 Jun 2025 10:24:53 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20qapi?= =?UTF-8?q?-misc-target-Add-Virtcca-capability-struct-and-q.patch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...-Add-Virtcca-capability-struct-and-q.patch | 132 ------------------ 1 file changed, 132 deletions(-) delete mode 100644 qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch diff --git a/qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch b/qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch deleted file mode 100644 index 35140210..00000000 --- a/qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch +++ /dev/null @@ -1,132 +0,0 @@ -From a06fe21504564a75d2cfdd3b133b67719edc78ec Mon Sep 17 00:00:00 2001 -From: panhengchang -Date: Thu, 5 Jun 2025 10:05:11 +0800 -Subject: [PATCH] qapi/misc-target: Add Virtcca capability struct and query - command. - -Introduce a new QAPI struct "VirtccaCapility" to represent the -VIRTCCA feature capability with a boolean "enabled" filed. -Add "query-virtcca-capabilties" command to retrieve this capability -information, which targeting HISI AARCH64 platforms. - -Signed-off-by: panghengchang ---- - qapi/misc-target.json | 29 +++++++++++++++++++++++++++++ - target/arm/kvm-tmm.c | 33 +++++++++++++++++++++++++++++++++ - tests/qtest/qmp-cmd-test.c | 1 + - 3 files changed, 63 insertions(+) - -diff --git a/qapi/misc-target.json b/qapi/misc-target.json -index 88291453ba..76ed52b65b 100644 ---- a/qapi/misc-target.json -+++ b/qapi/misc-target.json -@@ -487,3 +487,32 @@ - { 'command': 'xen-event-inject', - 'data': { 'port': 'uint32' }, - 'if': 'TARGET_I386' } -+ -+## -+# @VirtccaCapability: -+# -+# The struct describes capability for VIRTCCA feature. -+# -+# Since: 8.2.0 -+## -+{ 'struct': 'VirtccaCapability', -+ 'data': { 'enabled': 'bool' }, -+ 'if': 'TARGET_AARCH64' } -+ -+## -+# @query-virtcca-capabilities: -+# -+# This command is used to get the VIRTCCA capabilities, and is supported -+# on HISI AARCH64 platforms only. -+# -+# Returns: VirtccaCapability objects. -+# -+# Since: 8.2.0 -+# -+# Example: -+# -+# -> { "execute": "query-virtcca-capabilities" } -+# <- { "return": { "enabled": true } } -+## -+{ 'command': 'query-virtcca-capabilities', 'returns': 'VirtccaCapability', -+ 'if': 'TARGET_AARCH64' } -\ No newline at end of file -diff --git a/target/arm/kvm-tmm.c b/target/arm/kvm-tmm.c -index ea6bcc0f40..d18ac10896 100644 ---- a/target/arm/kvm-tmm.c -+++ b/target/arm/kvm-tmm.c -@@ -15,11 +15,13 @@ - #include "kvm_arm.h" - #include "migration/blocker.h" - #include "qapi/error.h" -+#include "qapi/qapi-commands-misc-target.h" - #include "qom/object_interfaces.h" - #include "sysemu/kvm.h" - #include "sysemu/runstate.h" - #include "hw/loader.h" - #include "linux-headers/asm-arm64/kvm.h" -+#include - - #define TYPE_TMM_GUEST "tmm-guest" - OBJECT_DECLARE_SIMPLE_TYPE(TmmGuest, TMM_GUEST) -@@ -27,6 +29,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(TmmGuest, TMM_GUEST) - #define TMM_PAGE_SIZE qemu_real_host_page_size() - #define TMM_MAX_PMU_CTRS 0x20 - #define TMM_MAX_CFG 6 -+#define TMM_MEMORY_INFO_SYSFS "/sys/kernel/tmm/memory_info" - - typedef struct { - uint32_t kae_vf_num; -@@ -406,3 +409,33 @@ static void tmm_register_types(void) - type_register_static(&tmm_guest_info); - } - type_init(tmm_register_types); -+ -+static VirtccaCapability *virtcca_get_capabilities(Error **errp) -+{ -+ VirtccaCapability *cap = NULL; -+ uint64_t tmi_version = 0; -+ int rc = 0; -+ -+ if (kvm_ioctl(kvm_state, KVM_GET_TMI_VERSION, &tmi_version) < 0) { -+ error_setg(errp, "VIRTCCA is not enabled in KVM"); -+ return NULL; -+ } -+ -+ rc = access(TMM_MEMORY_INFO_SYSFS, R_OK); -+ if (rc < 0) { -+ error_setg_errno(errp, errno, "VIRTCCA: Failed to read %s", -+ TMM_MEMORY_INFO_SYSFS); -+ return NULL; -+ } -+ -+ cap = g_new0(VirtccaCapability, 1); -+ -+ cap->enabled = true; -+ -+ return cap; -+} -+ -+VirtccaCapability *qmp_query_virtcca_capabilities(Error **errp) -+{ -+ return virtcca_get_capabilities(errp); -+} -\ No newline at end of file -diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c -index 2c15f60958..df1f93ea6a 100644 ---- a/tests/qtest/qmp-cmd-test.c -+++ b/tests/qtest/qmp-cmd-test.c -@@ -110,6 +110,7 @@ static bool query_is_ignored(const char *cmd) - "query-sev-capabilities", - "query-sgx", - "query-sgx-capabilities", -+ "query-virtcca-capabilities", - /* Success depends on enabling dirty page rate limit */ - "query-vcpu-dirty-limit", - NULL --- -2.33.0 - -- Gitee