From a54d1840b0fa2a7ab569049f831d43bf3460a59e Mon Sep 17 00:00:00 2001 From: panhengchang Date: Wed, 18 Jun 2025 22:49:56 +0800 Subject: [PATCH] QEMU update to version 8.2.0-37: - Add stub function for 'tmm_get_kae_num' if 'CONFIG_KVM' is not set. - qapi/misc-target: Add KVM option to isolate virtcca detection interface. - qapi/misc-target: Add Virtcca capability struct and query command. Signed-off-by: Panhengchang (cherry picked from commit 67f73b0136fff42cee12532e11708073321e91c7) --- ...n-for-tmm_get_kae_num-if-CONFIG_KVM-.patch | 30 ++++ ...-Add-KVM-option-to-isolate-virtcca-d.patch | 40 ++++++ ...-Add-Virtcca-capability-struct-and-q.patch | 132 ++++++++++++++++++ qemu.spec | 10 +- 4 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 Add-stub-function-for-tmm_get_kae_num-if-CONFIG_KVM-.patch create mode 100644 qapi-misc-target-Add-KVM-option-to-isolate-virtcca-d.patch create mode 100644 qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch diff --git a/Add-stub-function-for-tmm_get_kae_num-if-CONFIG_KVM-.patch b/Add-stub-function-for-tmm_get_kae_num-if-CONFIG_KVM-.patch new file mode 100644 index 0000000..95eda39 --- /dev/null +++ b/Add-stub-function-for-tmm_get_kae_num-if-CONFIG_KVM-.patch @@ -0,0 +1,30 @@ +From 69f44f27b30970cf19c0d5507a11852facace775 Mon Sep 17 00:00:00 2001 +From: panhengchang +Date: Tue, 24 Jun 2025 09:38:35 +0800 +Subject: [PATCH 2/2] Add stub function for 'tmm_get_kae_num' if 'CONFIG_KVM' + is not set. + +Signed-off-by: panghengchang +--- + target/arm/kvm_arm.h | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h +index 7613728..a29d454 100644 +--- a/target/arm/kvm_arm.h ++++ b/target/arm/kvm_arm.h +@@ -507,6 +507,11 @@ static inline void tmm_set_hpre_addr(hwaddr base, int num) + { + g_assert_not_reached(); + } ++ ++static inline int tmm_get_kae_num(void) ++{ ++ g_assert_not_reached(); ++} + #endif + + /** +-- +2.28.0.windows.1 + diff --git a/qapi-misc-target-Add-KVM-option-to-isolate-virtcca-d.patch b/qapi-misc-target-Add-KVM-option-to-isolate-virtcca-d.patch new file mode 100644 index 0000000..9086c35 --- /dev/null +++ b/qapi-misc-target-Add-KVM-option-to-isolate-virtcca-d.patch @@ -0,0 +1,40 @@ +From 555841f0b5d38681d5bec899cba9fc67d92d2a3a Mon Sep 17 00:00:00 2001 +From: panhengchang +Date: Mon, 23 Jun 2025 18:48:09 +0800 +Subject: [PATCH 1/2] qapi/misc-target: Add KVM option to isolate virtcca + detection interface. + +Add 'CONFIG_KVM' to isolate "VirtccaCapability" and +"query-virtcca-capabilities". + +Signed-off-by: panghengchang +--- + qapi/misc-target.json | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/qapi/misc-target.json b/qapi/misc-target.json +index 76ed52b..3df0062 100644 +--- a/qapi/misc-target.json ++++ b/qapi/misc-target.json +@@ -497,7 +497,8 @@ + ## + { 'struct': 'VirtccaCapability', + 'data': { 'enabled': 'bool' }, +- 'if': 'TARGET_AARCH64' } ++ 'if': { 'all': ['TARGET_AARCH64' , 'CONFIG_KVM'] } ++} + + ## + # @query-virtcca-capabilities: +@@ -515,4 +516,5 @@ + # <- { "return": { "enabled": true } } + ## + { 'command': 'query-virtcca-capabilities', 'returns': 'VirtccaCapability', +- 'if': 'TARGET_AARCH64' } +\ No newline at end of file ++ 'if': { 'all': ['TARGET_AARCH64' , 'CONFIG_KVM'] } ++} +\ No newline at end of file +-- +2.28.0.windows.1 + 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 0000000..248f3ce --- /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 8829145..76ed52b 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 ea6bcc0..d18ac10 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 2c15f60..df1f93e 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.28.0.windows.1 + diff --git a/qemu.spec b/qemu.spec index e33700c..03182ad 100644 --- a/qemu.spec +++ b/qemu.spec @@ -3,7 +3,7 @@ Name: qemu Version: 8.2.0 -Release: 36 +Release: 37 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 @@ -934,6 +934,9 @@ 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 +Patch0921: qapi-misc-target-Add-Virtcca-capability-struct-and-q.patch +Patch0922: qapi-misc-target-Add-KVM-option-to-isolate-virtcca-d.patch +Patch0923: Add-stub-function-for-tmm_get_kae_num-if-CONFIG_KVM-.patch BuildRequires: flex BuildRequires: gcc @@ -1536,6 +1539,11 @@ getent passwd qemu >/dev/null || \ %endif %changelog +* Wed Jun 18 2025 Panhengchang - 11:8.2.0-37 +- Add stub function for 'tmm_get_kae_num' if 'CONFIG_KVM' is not set. +- qapi/misc-target: Add KVM option to isolate virtcca detection interface. +- qapi/misc-target: Add Virtcca capability struct and query command. + * 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" -- Gitee