From nobody Sun Nov 24 06:09:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=os.amperecomputing.com); dmarc=pass(p=quarantine dis=none) header.from=os.amperecomputing.com ARC-Seal: i=2; a=rsa-sha256; t=1726132673; cv=pass; d=zohomail.com; s=zohoarc; b=Qd9NLwD+1Nv4qeWBDy+JOnjI0g6C6SONUal0iqrnQ6Z1IzFNzDWz92IUBC93sR6HsyB8kSwB80hnj0rUfjgeVj+lMzeratmDoBGwRKHQj5CR2bHPtoGKUV5FoakncV1DIdQqhZWWH7MqhFdRO7KLjUaM8ZoiGkzkPP4N3lwDN2c= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726132673; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5PZ2Ljq9RlDQ479G3NrzY6d7Nk0X8pFjpShv0Y69lZM=; b=iquqAEduc3NSVNNzL/KvKUbmefThY98jrrlu6L81qkeMUnZuh7s4b/WKyXyylJZRCbzDPVe/WcMnddHwPj+jSv5yHr+3qZHyCR9ng0VLzYeiYsKzOrllQr8CZCCvs5gJq08cAlwn92xYRCaFgfueV1BVBXW9j1g99khqErVCfVY= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=os.amperecomputing.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726132673237342.0689503728439; Thu, 12 Sep 2024 02:17:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sofwb-0007nu-SD; Thu, 12 Sep 2024 05:16:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sofwZ-0007mH-N9; Thu, 12 Sep 2024 05:16:51 -0400 Received: from mail-westusazlp170120002.outbound.protection.outlook.com ([2a01:111:f403:c001::2] helo=SJ2PR03CU001.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sofwX-00030K-Cn; Thu, 12 Sep 2024 05:16:51 -0400 Received: from SJ2PR01MB8101.prod.exchangelabs.com (2603:10b6:a03:4f6::10) by DS7PR01MB7782.prod.exchangelabs.com (2603:10b6:8:7d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.17; Thu, 12 Sep 2024 09:16:41 +0000 Received: from SJ2PR01MB8101.prod.exchangelabs.com ([fe80::292:6d9c:eb9a:95c9]) by SJ2PR01MB8101.prod.exchangelabs.com ([fe80::292:6d9c:eb9a:95c9%4]) with mapi id 15.20.7939.022; Thu, 12 Sep 2024 09:16:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Kbr/y6q89QyINxfMpx5H4yASwd5+R3soFAl2r6ieySkx/T380e8EpywH+JOHbLdOS8eD8RGY6higBSvFLpVI2OOQpN5azB4AHx9++TLl1b29L1UkPxi7YZqhQHoL0+Yi8o1F8BsOl42IwBBZw9ixrOTCeKqeLysV04F1FGRT6ZQe39V/oTT1qP/Ec7mtMDpBychClbhpN7KW3aZbwxFTY4OIm9ZAINpuG+2Ph77urywvWBy1Q+BV4gG4w2lX2vHly7OtCoXlO/Fjg5XEypz94mCPNaUn5GrRYu26KeWzyUDrZAj/941aiIJLwx9Rd1eVDZyDC/tnaACOidVyCafJkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5PZ2Ljq9RlDQ479G3NrzY6d7Nk0X8pFjpShv0Y69lZM=; b=jDQRn4fUxg17S22c3rSM0cAYuhpmeDVWhPx7R32jRRg7jd2591xNQED/J4XSGJccVQXLcQ5Yu7BFby61X3pvCysRth9UJgX+8d24vpEHS94YwMmq+gps7A3seVgWjsE8yKolb/OtFtRft7s5CL7CQPVfDo5fc3KVRWYwwNCT+20XVgmmy8YH/13RkXtWWHaA4em/+Kf8+EKRKIZLTANfksIObn/nrpPJVGX25f0nO4foOR9t4KUuOkF/sCr0o/iZTvjMtCVjDveDouGEN84sZXahINCCkRnpaW7YTlJ94sVR4l9Cg8GTkyw39BWECbF2ZiQgDInTfRP8BUwbFMxLDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5PZ2Ljq9RlDQ479G3NrzY6d7Nk0X8pFjpShv0Y69lZM=; b=Htmm0PGLsFuRmE1SG+uxZ7cJQTccQGb/NAUSNGZBhvYosM4hCWK/7ZNLJcEQe2J1NeYbuhW4wyrQqW3TtkJ65IzP/kGBGCowpKS7+Byd7SnNqSHmwfY3hTbRTH2XQXiZNiAjqcQVJOQG7rCIIxbz6lefh0GY2uryjr0kNRMgYm8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; From: Ganapatrao Kulkarni To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, richard.henderson@linaro.org, gustavo.romero@linaro.org, alex.bennee@linaro.org, darren@os.amperecomputing.com, gankulkarni@os.amperecomputing.com Subject: [PATCH V2] arm/kvm: add support for MTE Date: Thu, 12 Sep 2024 02:16:16 -0700 Message-Id: <20240912091616.393685-1-gankulkarni@os.amperecomputing.com> X-Mailer: git-send-email 2.40.1 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR04CA0043.namprd04.prod.outlook.com (2603:10b6:610:77::18) To SJ2PR01MB8101.prod.exchangelabs.com (2603:10b6:a03:4f6::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ2PR01MB8101:EE_|DS7PR01MB7782:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e9367bd-ac29-47ed-6332-08dcd30b9d1c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?EvC8rcE1KdBFDHpEMpLEU7Lv0vid5+TZjEcSlAMIk+c8kEAPGTsOeUzhZwBq?= =?us-ascii?Q?2zUJhtTvAjdYYK23PX20LfgmZdsrCoBIiWxBSq76p6LHEcHUmm1NueoNqVFv?= =?us-ascii?Q?dWZInh2nWbtM+zkPmYO0p7u8j0efmA6/Il2CiSljnnRh4bsal4SEYP6pAHZg?= =?us-ascii?Q?YIcnh8n4X3pRqATMaFZDgSeunAzaJjMlGok3XeKcx+vwyTM5h8U2elGBHjMw?= =?us-ascii?Q?tBJ9D7qmiYqXKpby4NeoJGIXanm/OqIPJ1wIAYdI6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PheyUTpQzcRk36S+4tnGhwLRWUwY4wN3FqPk7e74+e7yLJM?= =?us-ascii?Q?S12SEQeHofMZ8ym5K0Go+sVLJtvl27N//x832xcl1J0RBMX76L29N94Udepd?= =?us-ascii?Q?7sikGVIFR/ge9s+aLIsYIlFM6HQuPXNuwHbvcBHVOLgadkdQbE6Ah32/PECL?= =?us-ascii?Q?oCJDBlcBtoFJYIdTul39YexJ6FLG6WmLOBSC9EOT1/LoFQ+Nl2kLqECYO8hs?= =?us-ascii?Q?9ToUuwsE00Vq4KfMDnUeCvonI0O/8QmS5cU8tosl+qcqwAnvnQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ2PR01MB8101.prod.exchangelabs.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(52116014)(376014)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Fw/rw7SYMXaOhX64Ux7JRnPRLjn+Ug4cKasOzRfKEUy6nNpzWq4U80Jcsorx?= =?us-ascii?Q?zMMDX1hSPEDInIve76baT+DiTkPwcmCvRx8I7IWydl8xBGq9EehgZQ/SJRhH?= =?us-ascii?Q?MU2GGUvu4zrUbSHL2QeMtqusvEIE2POPJPNnEWwSR1mRH5UXL/jqaiwPEKty?= =?us-ascii?Q?WNyQRPWh72lQIocqAHRn7Xfa40m0R5+6UTRDy+NgCAOX6qIdja/JShKZqnBh?= =?us-ascii?Q?U1at6vPaXaVRIq1Si+U+hm+On60bd3ageUBCuKLaIWOXKLbJxGyv8vBdE61X?= =?us-ascii?Q?AvYzYaVUngw+JDNUDLiEcTiltunqSVp9mAZy8jNoX9FJ7W6THlQW5+lQDlO0?= =?us-ascii?Q?5NELRc6TPuvisPBx0vAi92/s6hmZtKsffLkQc/jQsCdRp9ND2VRMuGtIydjg?= =?us-ascii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uBA85?= =?us-ascii?Q?cXzmesRE5MjZbuGDhA0lXB6/Y2Ica0gKqDy8V6pZ9FKyEOAvGyBIH63Xv0Ya?= =?us-ascii?Q?Are+K1MBB4SVqEwLeruVpZ4/nH3JAmyl5Qv+edaSr6hAmWnJUNzFDkpAlau0?= =?us-ascii?Q?Up9fsUiDgYlctVlW+v1/dTFoh8I5sJ81gA4jo0nwZk9wKXLO4wF+eKVMEPje?= =?us-ascii?Q?k92ECPbROegTHWEUk7IdZ/hU2f9AfgaOoptCjlxZVLM4nXHeo6n49y7hWbso?= =?us-ascii?Q?uR0GhvIbH0kxzwz7WPN5rKOahQuASfpBjYqhoCXUrmiYM86nhqcgEFnJITnS?= =?us-ascii?Q?zsUiB1ztJR5aE/O5XaM3Y44=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e9367bd-ac29-47ed-6332-08dcd30b9d1c X-MS-Exchange-CrossTenant-AuthSource: SJ2PR01MB8101.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2024 09:16:41.5054 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Q7v4CdTUzfarri7L5dCRRA0+Xk6kpYIdIlg3akHgajSTzvxV+2L+wVz9TeTS5OsTXPz5VfWRPlumLIoI9IrQltCv4LhQ38/uUhj2HZopiRru06lhF7J9yVjP9A+Nnmya X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR01MB7782 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a01:111:f403:c001::2; envelope-from=gankulkarni@os.amperecomputing.com; helo=SJ2PR03CU001.outbound.protection.outlook.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @os.amperecomputing.com) X-ZM-MESSAGEID: 1726132673853116600 Content-Type: text/plain; charset="utf-8" Extend the 'mte' property for the virt machine to cover KVM as well. For KVM, we don't allocate tag memory, but instead enable the capability. If MTE has been enabled, we need to disable migration, as we do not yet have a way to migrate the tags as well. Therefore, MTE will stay off with KVM unless requested explicitly. This patch is rework of commit b320e21c48ce64853904bea6631c0158cc2ef227 which broke TCG since 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. Signed-off-by: Cornelia Huck Signed-off-by: Ganapatrao Kulkarni --- Changes since V1: Added code to enable MTE before reading register id_aa64pfr1 (unmasked MTE bits). This patch is boot tested on ARM64 with KVM and on X86 with TCG for mte=3Don and default case(i.e, no mte). hw/arm/virt.c | 72 ++++++++++++++++++++++++++------------------ target/arm/cpu.c | 7 +++-- target/arm/cpu.h | 2 ++ target/arm/kvm.c | 59 ++++++++++++++++++++++++++++++++++++ target/arm/kvm_arm.h | 19 ++++++++++++ 5 files changed, 126 insertions(+), 33 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 7934b23651..a33af7d996 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2211,7 +2211,7 @@ static void machvirt_init(MachineState *machine) exit(1); } =20 - if (vms->mte && (kvm_enabled() || hvf_enabled())) { + if (vms->mte && hvf_enabled()) { error_report("mach-virt: %s does not support providing " "MTE to the guest CPU", current_accel_name()); @@ -2281,39 +2281,51 @@ static void machvirt_init(MachineState *machine) } =20 if (vms->mte) { - /* Create the memory region only once, but link to all cpus. */ - if (!tag_sysmem) { - /* - * The property exists only if MemTag is supported. - * If it is, we must allocate the ram to back that up. - */ - if (!object_property_find(cpuobj, "tag-memory")) { - error_report("MTE requested, but not supported " - "by the guest CPU"); - exit(1); + if (tcg_enabled()) { + /* Create the memory region only once, but link to all cpu= s. */ + if (!tag_sysmem) { + /* + * The property exists only if MemTag is supported. + * If it is, we must allocate the ram to back that up. + */ + if (!object_property_find(cpuobj, "tag-memory")) { + error_report("MTE requested, but not supported " + "by the guest CPU"); + exit(1); + } + + tag_sysmem =3D g_new(MemoryRegion, 1); + memory_region_init(tag_sysmem, OBJECT(machine), + "tag-memory", UINT64_MAX / 32); + + if (vms->secure) { + secure_tag_sysmem =3D g_new(MemoryRegion, 1); + memory_region_init(secure_tag_sysmem, OBJECT(machi= ne), + "secure-tag-memory", + UINT64_MAX / 32); + + /* As with ram, secure-tag takes precedence over t= ag. */ + memory_region_add_subregion_overlap(secure_tag_sys= mem, + 0, tag_sysmem,= -1); + } } =20 - tag_sysmem =3D g_new(MemoryRegion, 1); - memory_region_init(tag_sysmem, OBJECT(machine), - "tag-memory", UINT64_MAX / 32); - + object_property_set_link(cpuobj, "tag-memory", + OBJECT(tag_sysmem), &error_abort); if (vms->secure) { - secure_tag_sysmem =3D g_new(MemoryRegion, 1); - memory_region_init(secure_tag_sysmem, OBJECT(machine), - "secure-tag-memory", UINT64_MAX / 3= 2); - - /* As with ram, secure-tag takes precedence over tag. = */ - memory_region_add_subregion_overlap(secure_tag_sysmem,= 0, - tag_sysmem, -1); + object_property_set_link(cpuobj, "secure-tag-memory", + OBJECT(secure_tag_sysmem), + &error_abort); } - } - - object_property_set_link(cpuobj, "tag-memory", OBJECT(tag_sysm= em), - &error_abort); - if (vms->secure) { - object_property_set_link(cpuobj, "secure-tag-memory", - OBJECT(secure_tag_sysmem), - &error_abort); + } else if (kvm_enabled()) { + if (!kvm_arm_mte_supported()) { + error_report("MTE requested, but not supported by KVM"= ); + exit(1); + } + kvm_arm_enable_mte(cpuobj, &error_abort); + } else { + error_report("MTE requested, but not supported "); + exit(1); } } =20 diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 19191c2391..a59417aac8 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2390,11 +2390,12 @@ static void arm_cpu_realizefn(DeviceState *dev, Err= or **errp) =20 #ifndef CONFIG_USER_ONLY /* - * If we do not have tag-memory provided by the machine, - * reduce MTE support to instructions enabled at EL0. + * If we do not have tag-memory provided by the TCG + * nor MTE at KVM enabled, reduce MTE support to + * instructions enabled at EL0. * This matches Cortex-A710 BROADCASTMTE input being LOW. */ - if (cpu->tag_memory =3D=3D NULL) { + if (cpu->tag_memory =3D=3D NULL && !cpu->kvm_mte) { cpu->isar.id_aa64pfr1 =3D FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 1); } diff --git a/target/arm/cpu.h b/target/arm/cpu.h index f065756c5c..8fc8b6398f 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -922,6 +922,8 @@ struct ArchCPU { =20 /* CPU has memory protection unit */ bool has_mpu; + /* CPU has MTE enabled in KVM mode */ + bool kvm_mte; /* PMSAv7 MPU number of supported regions */ uint32_t pmsav7_dregion; /* PMSAv8 MPU number of supported hyp regions */ diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 849e2e21b3..29865609fb 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -39,6 +39,7 @@ #include "hw/acpi/acpi.h" #include "hw/acpi/ghes.h" #include "target/arm/gtimer.h" +#include "migration/blocker.h" =20 const KVMCapabilityInfo kvm_arch_required_capabilities[] =3D { KVM_CAP_LAST_INFO @@ -119,6 +120,21 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *= cpus_to_try, if (vmfd < 0) { goto err; } + + /* + * MTE bits of register id_aa64pfr1 are masked if MTE is + * not enabled and required to enable before VCPU + * is created. Hence enable MTE(if supported) before VCPU + * is created to read unmasked MTE bits. + */ + if (kvm_arm_mte_supported()) { + KVMState kvm_state; + + kvm_state.fd =3D kvmfd; + kvm_state.vmfd =3D vmfd; + kvm_vm_enable_cap(&kvm_state, KVM_CAP_ARM_MTE, 0); + } + cpufd =3D ioctl(vmfd, KVM_CREATE_VCPU, 0); if (cpufd < 0) { goto err; @@ -1793,6 +1809,11 @@ bool kvm_arm_sve_supported(void) return kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE); } =20 +bool kvm_arm_mte_supported(void) +{ + return kvm_check_extension(kvm_state, KVM_CAP_ARM_MTE); +} + QEMU_BUILD_BUG_ON(KVM_ARM64_SVE_VQ_MIN !=3D 1); =20 uint32_t kvm_arm_sve_get_vls(ARMCPU *cpu) @@ -2417,3 +2438,41 @@ int kvm_arch_remove_sw_breakpoint(CPUState *cs, stru= ct kvm_sw_breakpoint *bp) } return 0; } + +void kvm_arm_enable_mte(Object *cpuobj, Error **errp) +{ + static bool tried_to_enable; + static bool succeeded_to_enable; + Error *mte_migration_blocker =3D NULL; + ARMCPU *cpu =3D ARM_CPU(cpuobj); + int ret; + + if (!tried_to_enable) { + /* + * MTE on KVM is enabled on a per-VM basis (and retrying doesn't m= ake + * sense), and we only want a single migration blocker as well. + */ + tried_to_enable =3D true; + + ret =3D kvm_vm_enable_cap(kvm_state, KVM_CAP_ARM_MTE, 0); + if (ret) { + error_setg_errno(errp, -ret, "Failed to enable KVM_CAP_ARM_MTE= "); + return; + } + + /* TODO: Add migration support with MTE enabled */ + error_setg(&mte_migration_blocker, + "Live migration disabled due to MTE enabled"); + if (migrate_add_blocker(&mte_migration_blocker, errp)) { + error_free(mte_migration_blocker); + return; + } + + succeeded_to_enable =3D true; + } + + if (succeeded_to_enable) { + cpu->kvm_mte =3D true; + } +} + diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index cfaa0d9bc7..4d293618a7 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -188,6 +188,13 @@ bool kvm_arm_pmu_supported(void); */ bool kvm_arm_sve_supported(void); =20 +/** + * kvm_arm_mte_supported: + * + * Returns: true if KVM can enable MTE, and false otherwise. + */ +bool kvm_arm_mte_supported(void); + /** * kvm_arm_get_max_vm_ipa_size: * @ms: Machine state handle @@ -214,6 +221,8 @@ void kvm_arm_pvtime_init(ARMCPU *cpu, uint64_t ipa); =20 int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level); =20 +void kvm_arm_enable_mte(Object *cpuobj, Error **errp); + #else =20 /* @@ -235,6 +244,11 @@ static inline bool kvm_arm_sve_supported(void) return false; } =20 +static inline bool kvm_arm_mte_supported(void) +{ + return false; +} + /* * These functions should never actually be called without KVM support. */ @@ -283,6 +297,11 @@ static inline uint32_t kvm_arm_sve_get_vls(ARMCPU *cpu) g_assert_not_reached(); } =20 +static inline void kvm_arm_enable_mte(Object *cpuobj, Error **errp) +{ + g_assert_not_reached(); +} + #endif =20 #endif --=20 2.44.0