diff --git a/0001-add-virtcca-capability-detection.patch b/0001-add-virtcca-capability-detection.patch new file mode 100644 index 0000000000000000000000000000000000000000..b94db4cf516e0dcc4b502d8e24567920758c446b --- /dev/null +++ b/0001-add-virtcca-capability-detection.patch @@ -0,0 +1,142 @@ +From b65eab7e0936fb54e5dd43bf7cd80493a6358a83 Mon Sep 17 00:00:00 2001 +From: panhengchang +Date: Thu, 5 Jun 2025 10:05:11 +0800 +Subject: [PATCH] add virtcca capability detection + +--- + qapi/misc-target.json | 29 +++++++++++++++++++++++++++++ + target/arm/kvm-tmm.c | 33 +++++++++++++++++++++++++++++++++ + target/arm/kvm_arm.h | 5 +++++ + tests/qtest/qmp-cmd-test.c | 1 + + 4 files changed, 68 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/target/arm/kvm_arm.h b/target/arm/kvm_arm.h +index 76137289df..a29d4548f4 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 + + /** +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.28.0.windows.1 + diff --git a/qemu.spec b/qemu.spec index e33700c2d84e44935658300b3731ff542b6251bf..9ca21196849173939d80d39b3446edc915d91a25 100644 --- a/qemu.spec +++ b/qemu.spec @@ -934,6 +934,7 @@ 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: 0001-add-virtcca-capability-detection.patch BuildRequires: flex BuildRequires: gcc @@ -1536,6 +1537,9 @@ getent passwd qemu >/dev/null || \ %endif %changelog +* Tus Jun 17 2025 Panhengchang - 11:8.2.0-37 +- Fix error in virtCCA CoDA scenario. + * 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"