Skip to content

Commit 6f4e140

Browse files
rth7680pm215
authored andcommitted
hw/arm/virt: Enable MTE via a machine property
Control this cpu feature via a machine property, much as we do with secure=on, since both require specialized support in the machine setup to be functional. Default MTE to off, since this feature implies extra overhead. Signed-off-by: Richard Henderson <[email protected]> Message-id: [email protected] Reviewed-by: Peter Maydell <[email protected]> Signed-off-by: Peter Maydell <[email protected]>
1 parent 873ec69 commit 6f4e140

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

hw/arm/virt.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,12 +1837,19 @@ static void machvirt_init(MachineState *machine)
18371837
OBJECT(secure_sysmem), &error_abort);
18381838
}
18391839

1840-
/*
1841-
* The cpu adds the property if and only if MemTag is supported.
1842-
* If it is, we must allocate the ram to back that up.
1843-
*/
1844-
if (object_property_find(cpuobj, "tag-memory", NULL)) {
1840+
if (vms->mte) {
1841+
/* Create the memory region only once, but link to all cpus. */
18451842
if (!tag_sysmem) {
1843+
/*
1844+
* The property exists only if MemTag is supported.
1845+
* If it is, we must allocate the ram to back that up.
1846+
*/
1847+
if (!object_property_find(cpuobj, "tag-memory", NULL)) {
1848+
error_report("MTE requested, but not supported "
1849+
"by the guest CPU");
1850+
exit(1);
1851+
}
1852+
18461853
tag_sysmem = g_new(MemoryRegion, 1);
18471854
memory_region_init(tag_sysmem, OBJECT(machine),
18481855
"tag-memory", UINT64_MAX / 32);
@@ -2061,6 +2068,20 @@ static void virt_set_ras(Object *obj, bool value, Error **errp)
20612068
vms->ras = value;
20622069
}
20632070

2071+
static bool virt_get_mte(Object *obj, Error **errp)
2072+
{
2073+
VirtMachineState *vms = VIRT_MACHINE(obj);
2074+
2075+
return vms->mte;
2076+
}
2077+
2078+
static void virt_set_mte(Object *obj, bool value, Error **errp)
2079+
{
2080+
VirtMachineState *vms = VIRT_MACHINE(obj);
2081+
2082+
vms->mte = value;
2083+
}
2084+
20642085
static char *virt_get_gic_version(Object *obj, Error **errp)
20652086
{
20662087
VirtMachineState *vms = VIRT_MACHINE(obj);
@@ -2481,6 +2502,14 @@ static void virt_instance_init(Object *obj)
24812502
"Set on/off to enable/disable reporting host memory errors "
24822503
"to a KVM guest using ACPI and guest external abort exceptions");
24832504

2505+
/* MTE is disabled by default. */
2506+
vms->mte = false;
2507+
object_property_add_bool(obj, "mte", virt_get_mte, virt_set_mte);
2508+
object_property_set_description(obj, "mte",
2509+
"Set on/off to enable/disable emulating a "
2510+
"guest CPU which implements the ARM "
2511+
"Memory Tagging Extension");
2512+
24842513
vms->irqmap = a15irqmap;
24852514

24862515
virt_flash_create(vms);

include/hw/arm/virt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ typedef struct {
140140
bool its;
141141
bool virt;
142142
bool ras;
143+
bool mte;
143144
OnOffAuto acpi;
144145
VirtGICType gic_version;
145146
VirtIOMMUType iommu;

target/arm/cpu.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
16981698
cpu->id_pfr1 &= ~0xf000;
16991699
}
17001700

1701+
#ifndef CONFIG_USER_ONLY
1702+
if (cpu->tag_memory == NULL && cpu_isar_feature(aa64_mte, cpu)) {
1703+
/*
1704+
* Disable the MTE feature bits if we do not have tag-memory
1705+
* provided by the machine.
1706+
*/
1707+
cpu->isar.id_aa64pfr1 =
1708+
FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 0);
1709+
}
1710+
#endif
1711+
17011712
/* MPU can be configured out of a PMSA CPU either by setting has-mpu
17021713
* to false or by setting pmsav7-dregion to 0.
17031714
*/
@@ -1787,14 +1798,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
17871798
cpu_address_space_init(cs, ARMASIdx_TagS, "cpu-tag-memory",
17881799
cpu->secure_tag_memory);
17891800
}
1790-
} else if (cpu_isar_feature(aa64_mte, cpu)) {
1791-
/*
1792-
* Since there is no tag memory, we can't meaningfully support MTE
1793-
* to its fullest. To avoid problems later, when we would come to
1794-
* use the tag memory, downgrade support to insns only.
1795-
*/
1796-
cpu->isar.id_aa64pfr1 =
1797-
FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 1);
17981801
}
17991802

18001803
cpu_address_space_init(cs, ARMASIdx_NS, "cpu-memory", cs->memory);

target/arm/cpu64.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,9 @@ static void aarch64_max_initfn(Object *obj)
646646
t = cpu->isar.id_aa64pfr1;
647647
t = FIELD_DP64(t, ID_AA64PFR1, BT, 1);
648648
/*
649-
* Begin with full support for MTE; will be downgraded to MTE=1
650-
* during realize if the board provides no tag memory.
649+
* Begin with full support for MTE. This will be downgraded to MTE=0
650+
* during realize if the board provides no tag memory, much like
651+
* we do for EL2 with the virtualization=on property.
651652
*/
652653
t = FIELD_DP64(t, ID_AA64PFR1, MTE, 2);
653654
cpu->isar.id_aa64pfr1 = t;

0 commit comments

Comments
 (0)