Skip to content

Commit d009607

Browse files
pm215rth7680
authored andcommitted
Revert "arm/kvm: add support for MTE"
This reverts commit b320e21, which accidentally broke TCG, because it made the TCG -cpu max report the presence of MTE to the guest even if the board hadn't enabled MTE by wiring up the tag RAM. This meant that if the guest then tried to use MTE QEMU would segfault accessing the non-existent tag RAM: ==346473==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address (pc 0x55f328952a4a bp 0x00000213a400 sp 0x7f7871859b80 T346476) ==346473==The signal is caused by a READ memory access. ==346473==Hint: this fault was caused by a dereference of a high value address (see register values below). Disassemble the provided pc to learn which register was used. #0 0x55f328952a4a in address_space_to_flatview /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/exec/memory.h:1108:12 #1 0x55f328952a4a in address_space_translate /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/exec/memory.h:2797:31 qemu#2 0x55f328952a4a in allocation_tag_mem /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-clang/../../target/arm/tcg/mte_helper.c:176:10 qemu#3 0x55f32895366c in helper_stgm /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-clang/../../target/arm/tcg/mte_helper.c:461:15 qemu#4 0x7f782431a293 (<unknown module>) It's also not clear that the KVM logic is correct either: MTE defaults to on there, rather than being only on if the board wants it on. Revert the whole commit for now so we can sort out the issues. (We didn't catch this in CI because we have no test cases in avocado that use guests with MTE support.) Signed-off-by: Peter Maydell <[email protected]> Message-Id: <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent 449d6d9 commit d009607

File tree

6 files changed

+34
-107
lines changed

6 files changed

+34
-107
lines changed

hw/arm/virt.c

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ static void machvirt_init(MachineState *machine)
21462146
exit(1);
21472147
}
21482148

2149-
if (vms->mte && hvf_enabled()) {
2149+
if (vms->mte && (kvm_enabled() || hvf_enabled())) {
21502150
error_report("mach-virt: %s does not support providing "
21512151
"MTE to the guest CPU",
21522152
current_accel_name());
@@ -2216,48 +2216,39 @@ static void machvirt_init(MachineState *machine)
22162216
}
22172217

22182218
if (vms->mte) {
2219-
if (tcg_enabled()) {
2220-
/* Create the memory region only once, but link to all cpus. */
2221-
if (!tag_sysmem) {
2222-
/*
2223-
* The property exists only if MemTag is supported.
2224-
* If it is, we must allocate the ram to back that up.
2225-
*/
2226-
if (!object_property_find(cpuobj, "tag-memory")) {
2227-
error_report("MTE requested, but not supported "
2228-
"by the guest CPU");
2229-
exit(1);
2230-
}
2231-
2232-
tag_sysmem = g_new(MemoryRegion, 1);
2233-
memory_region_init(tag_sysmem, OBJECT(machine),
2234-
"tag-memory", UINT64_MAX / 32);
2235-
2236-
if (vms->secure) {
2237-
secure_tag_sysmem = g_new(MemoryRegion, 1);
2238-
memory_region_init(secure_tag_sysmem, OBJECT(machine),
2239-
"secure-tag-memory",
2240-
UINT64_MAX / 32);
2241-
2242-
/* As with ram, secure-tag takes precedence over tag. */
2243-
memory_region_add_subregion_overlap(secure_tag_sysmem,
2244-
0, tag_sysmem, -1);
2245-
}
2219+
/* Create the memory region only once, but link to all cpus. */
2220+
if (!tag_sysmem) {
2221+
/*
2222+
* The property exists only if MemTag is supported.
2223+
* If it is, we must allocate the ram to back that up.
2224+
*/
2225+
if (!object_property_find(cpuobj, "tag-memory")) {
2226+
error_report("MTE requested, but not supported "
2227+
"by the guest CPU");
2228+
exit(1);
22462229
}
22472230

2248-
object_property_set_link(cpuobj, "tag-memory",
2249-
OBJECT(tag_sysmem), &error_abort);
2231+
tag_sysmem = g_new(MemoryRegion, 1);
2232+
memory_region_init(tag_sysmem, OBJECT(machine),
2233+
"tag-memory", UINT64_MAX / 32);
2234+
22502235
if (vms->secure) {
2251-
object_property_set_link(cpuobj, "secure-tag-memory",
2252-
OBJECT(secure_tag_sysmem),
2253-
&error_abort);
2254-
}
2255-
} else if (kvm_enabled()) {
2256-
if (!kvm_arm_mte_supported()) {
2257-
error_report("MTE requested, but not supported by KVM");
2258-
exit(1);
2236+
secure_tag_sysmem = g_new(MemoryRegion, 1);
2237+
memory_region_init(secure_tag_sysmem, OBJECT(machine),
2238+
"secure-tag-memory", UINT64_MAX / 32);
2239+
2240+
/* As with ram, secure-tag takes precedence over tag. */
2241+
memory_region_add_subregion_overlap(secure_tag_sysmem, 0,
2242+
tag_sysmem, -1);
22592243
}
2260-
kvm_arm_enable_mte(cpuobj, &error_abort);
2244+
}
2245+
2246+
object_property_set_link(cpuobj, "tag-memory", OBJECT(tag_sysmem),
2247+
&error_abort);
2248+
if (vms->secure) {
2249+
object_property_set_link(cpuobj, "secure-tag-memory",
2250+
OBJECT(secure_tag_sysmem),
2251+
&error_abort);
22612252
}
22622253
}
22632254

target/arm/cpu.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,6 @@ void arm_cpu_post_init(Object *obj)
14801480
qdev_prop_allow_set_link_before_realize,
14811481
OBJ_PROP_LINK_STRONG);
14821482
}
1483-
cpu->has_mte = true;
14841483
}
14851484
#endif
14861485
}
@@ -1617,7 +1616,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
16171616
}
16181617
if (cpu->tag_memory) {
16191618
error_setg(errp,
1620-
"Cannot enable %s when guest CPUs has tag memory enabled",
1619+
"Cannot enable %s when guest CPUs has MTE enabled",
16211620
current_accel_name());
16221621
return;
16231622
}
@@ -1997,10 +1996,10 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
19971996
}
19981997

19991998
#ifndef CONFIG_USER_ONLY
2000-
if (!cpu->has_mte && cpu_isar_feature(aa64_mte, cpu)) {
1999+
if (cpu->tag_memory == NULL && cpu_isar_feature(aa64_mte, cpu)) {
20012000
/*
2002-
* Disable the MTE feature bits if we do not have the feature
2003-
* setup by the machine.
2001+
* Disable the MTE feature bits if we do not have tag-memory
2002+
* provided by the machine.
20042003
*/
20052004
cpu->isar.id_aa64pfr1 =
20062005
FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 0);

target/arm/cpu.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,6 @@ struct ArchCPU {
935935
*/
936936
uint32_t psci_conduit;
937937

938-
/* CPU has Memory Tag Extension */
939-
bool has_mte;
940-
941938
/* For v8M, initial value of the Secure VTOR */
942939
uint32_t init_svtor;
943940
/* For v8M, initial value of the Non-secure VTOR */
@@ -1056,7 +1053,6 @@ struct ArchCPU {
10561053
bool prop_pauth;
10571054
bool prop_pauth_impdef;
10581055
bool prop_lpa2;
1059-
OnOffAuto prop_mte;
10601056

10611057
/* DCZ blocksize, in log_2(words), ie low 4 bits of DCZID_EL0 */
10621058
uint32_t dcz_blocksize;

target/arm/kvm.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "hw/boards.h"
3232
#include "hw/irq.h"
3333
#include "qemu/log.h"
34-
#include "migration/blocker.h"
3534

3635
const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
3736
KVM_CAP_LAST_INFO
@@ -1065,37 +1064,3 @@ bool kvm_arch_cpu_check_are_resettable(void)
10651064
void kvm_arch_accel_class_init(ObjectClass *oc)
10661065
{
10671066
}
1068-
1069-
void kvm_arm_enable_mte(Object *cpuobj, Error **errp)
1070-
{
1071-
static bool tried_to_enable;
1072-
static bool succeeded_to_enable;
1073-
Error *mte_migration_blocker = NULL;
1074-
int ret;
1075-
1076-
if (!tried_to_enable) {
1077-
/*
1078-
* MTE on KVM is enabled on a per-VM basis (and retrying doesn't make
1079-
* sense), and we only want a single migration blocker as well.
1080-
*/
1081-
tried_to_enable = true;
1082-
1083-
ret = kvm_vm_enable_cap(kvm_state, KVM_CAP_ARM_MTE, 0);
1084-
if (ret) {
1085-
error_setg_errno(errp, -ret, "Failed to enable KVM_CAP_ARM_MTE");
1086-
return;
1087-
}
1088-
1089-
/* TODO: add proper migration support with MTE enabled */
1090-
error_setg(&mte_migration_blocker,
1091-
"Live migration disabled due to MTE enabled");
1092-
if (migrate_add_blocker(mte_migration_blocker, errp)) {
1093-
error_free(mte_migration_blocker);
1094-
return;
1095-
}
1096-
succeeded_to_enable = true;
1097-
}
1098-
if (succeeded_to_enable) {
1099-
object_property_set_bool(cpuobj, "has_mte", true, NULL);
1100-
}
1101-
}

target/arm/kvm64.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,11 +756,6 @@ bool kvm_arm_steal_time_supported(void)
756756
return kvm_check_extension(kvm_state, KVM_CAP_STEAL_TIME);
757757
}
758758

759-
bool kvm_arm_mte_supported(void)
760-
{
761-
return kvm_check_extension(kvm_state, KVM_CAP_ARM_MTE);
762-
}
763-
764759
QEMU_BUILD_BUG_ON(KVM_ARM64_SVE_VQ_MIN != 1);
765760

766761
uint32_t kvm_arm_sve_get_vls(CPUState *cs)

target/arm/kvm_arm.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,6 @@ bool kvm_arm_pmu_supported(void);
313313
*/
314314
bool kvm_arm_sve_supported(void);
315315

316-
/**
317-
* kvm_arm_mte_supported:
318-
*
319-
* Returns: true if KVM can enable MTE, and false otherwise.
320-
*/
321-
bool kvm_arm_mte_supported(void);
322-
323316
/**
324317
* kvm_arm_get_max_vm_ipa_size:
325318
* @ms: Machine state handle
@@ -384,8 +377,6 @@ void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa);
384377

385378
int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level);
386379

387-
void kvm_arm_enable_mte(Object *cpuobj, Error **errp);
388-
389380
#else
390381

391382
/*
@@ -412,11 +403,6 @@ static inline bool kvm_arm_steal_time_supported(void)
412403
return false;
413404
}
414405

415-
static inline bool kvm_arm_mte_supported(void)
416-
{
417-
return false;
418-
}
419-
420406
/*
421407
* These functions should never actually be called without KVM support.
422408
*/
@@ -465,11 +451,6 @@ static inline uint32_t kvm_arm_sve_get_vls(CPUState *cs)
465451
g_assert_not_reached();
466452
}
467453

468-
static inline void kvm_arm_enable_mte(Object *cpuobj, Error **errp)
469-
{
470-
g_assert_not_reached();
471-
}
472-
473454
#endif
474455

475456
static inline const char *gic_class_name(void)

0 commit comments

Comments
 (0)