From nobody Mon Feb 9 09:00:20 2026 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1768476253; cv=none; d=zohomail.com; s=zohoarc; b=BhVapwamuTM3EYUZk/4QDfoKN5HCOAHGL/S8IWRyLMcB6YTRKVZ8cXGXyfQiZaIrVadcvysElqFxEfQJ6Wp6NHc+uDxfd9iGRooivi8XMrLyyITFg/mMAYwf46zg+7R2lVobo0UB1UZGhF7eumkxqh2tmtTZ3NM7m21DCWYqZCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768476253; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=il2qWBDvGIIJSSXc4SUG8ytlI3OQMqpNIz1uXFR7Okg=; b=HLD/2DubNqjlUQYWPepzIm1Q9rb7kg1aPbZvp8yb45YI+91I8ytjUNLxySERIw9F2apZzvE8Dfd5I0qF1v9ktUI7AmLCYfhZuu/TOLi+eP+GbKb8J/KHFnH3bNkd7HwPQlgSQCZBLswVTy7qSh84DUWA9SqLfLnFlfFcvtlw50o= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768476253431848.118126903219; Thu, 15 Jan 2026 03:24:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vgLPC-0002MK-HR; Thu, 15 Jan 2026 06:20:46 -0500 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 1vgLP9-0002L2-9m for qemu-devel@nongnu.org; Thu, 15 Jan 2026 06:20:43 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vgLP5-00075h-Az for qemu-devel@nongnu.org; Thu, 15 Jan 2026 06:20:42 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-480142406b3so2742545e9.1 for ; Thu, 15 Jan 2026 03:20:38 -0800 (PST) Received: from [127.0.1.1] (ppp-2-86-214-23.home.otenet.gr. [2.86.214.23]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-434af64a778sm5302085f8f.3.2026.01.15.03.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 03:20:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1768476038; x=1769080838; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=il2qWBDvGIIJSSXc4SUG8ytlI3OQMqpNIz1uXFR7Okg=; b=sHv4GoOfujv26En2J0v+aKc32wzRB9WTWQw7KGHKnKDcDxP/k7kfSXnIL/xR1aVMR3 JVPCfnf6oJ4PlhQ6CGI9UehJq+VAKTdpAHbmeP+Fgj3FWPrstkgBmx2Gc3RaHHc7MWHR bC5m5jllNpSRupItK6DK5rvcIe5B7/UAzIlmO1r95tWGWPY7LA+qGOqkMNK+YfYJNBNp SFQncjFX1Iam3KoB2Q0maBMNztfp076PvmYVdqDcL22muMDP6Vz+WjOHTOkOwV/8X0hq aBpgut5XPwxVewLahQTcRGzWQG/kLEiKd+LlX2OL/73RLXSEehsbTCow91faY8O7Ewm1 lYpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768476038; x=1769080838; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=il2qWBDvGIIJSSXc4SUG8ytlI3OQMqpNIz1uXFR7Okg=; b=KmYXG+DmaCclT7oFLCMIww/3TWv35z9XkvIFEPQ8b5nb2YFZ5b0YI1aSxZ6N674VU5 DOoVpRZzn80Iu6dj82t843aThCjY3mLeB8QUaKEDCmIj+cHo+f+P6Mcy64bSHcWv/zCq kg8quI9lqZdy5sbNmqRdnVu3+WKCWo4WYTR/tT9Xq512QgFiQNJ2j1yrgV9N22MWBoM/ GnMhfHu8LsO8lRS0G9bno3MK7YVucryHPNWcjzMvZTGl4Z2KC2G6PiizjHYunEv2m5vB H9QUT26U+fLkU/pMzKXMjIPYGo98WE8rEFKTUuULkgtTgmnZuVuipwDt21y4LGos26jP di6w== X-Gm-Message-State: AOJu0YyeZhoM099TNzBQYmD6XKvQnBp0m0pnA4gxL748kLy0miaiLdQt 7RsUQD3ZoGqlTLcZNj4S+mca9H/bp9IJt3JVKOob91jWeaNLLSyaw2xdT9s2NsUZedY= X-Gm-Gg: AY/fxX44jp7EbMC/42RzQHq3flcQiRR08id1BRgQxJelxbDEJoXdFvLn6dB67xvyiHb VrN/tf7ZVsIQUlb4G2hIO8DHY55gD6i5OL6G1jOmgGMXoSG3T1HG/Z/B9LI8+fyXyRaejQJbLI9 vC3+P1NdiC3YZ4qv0J3zbt66+f92UVMHoW9BIrTIl3r/GcvQPdFcP53PXMBV6KDo/G1LF6cZd7X YrcKUTFY0KnmK4UtVCKQdBHYtOq+KcDSpMxk/umgfBVqkcWXkdVXBHes/07aXNeAiVPL3hH3zwY xvYd4GdQIdnlGoSlaWD/+0xb/VhuZEDjpqXOSFHRBgU/0JqvyQn5T66P8h0mQJk0Bp7bJXw4jt2 Xw0WmOyVFZ56w+dISDp9zFdRxNwGNn9WhDG36Dscz4vGuhDk0K/Qdb/TYxnsGpO9dwOElcFEVuB Taxh3Cz/bLSoDkYgEEuZ7C45BghHuk9avNBPUkJwcaP50taLRN17Q1E5yFyoMqcpdONN7gQAbtJ DQfn9velj8OVRxJ42Rnqer1ppiawmY+/S0= X-Received: by 2002:a05:600c:3e06:b0:47e:e2ec:9947 with SMTP id 5b1f17b1804b1-47ee483ef7bmr49812645e9.33.1768476037651; Thu, 15 Jan 2026 03:20:37 -0800 (PST) From: Manos Pitsidianakis Date: Thu, 15 Jan 2026 13:20:28 +0200 Subject: [PATCH v2 1/2] hvf/arm: handle FEAT_SME2 migration MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260115-sme2-hvf-v2-1-2eca481bd7ee@linaro.org> References: <20260115-sme2-hvf-v2-0-2eca481bd7ee@linaro.org> In-Reply-To: <20260115-sme2-hvf-v2-0-2eca481bd7ee@linaro.org> To: qemu-devel@nongnu.org Cc: Richard Henderson , =?utf-8?q?Phil_Mathieu-Daud=C3=A9?= , Alexander Graf , Mads Ynddal , Peter Maydell , qemu-arm@nongnu.org, Mohamed Mediouni , Manos Pitsidianakis X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=23074; i=manos.pitsidianakis@linaro.org; h=from:subject:message-id; bh=U6lUY/NjSlybCykSgdnt3kK4JdZeMKfcWtax+kXkMjk=; b=LS0tLS1CRUdJTiBQR1AgTUVTU0FHRS0tLS0tCgpvd0VCYlFLUy9aQU5Bd0FLQVhjcHgzQi9mZ 25RQWNzbVlnQnBhTTJDNEhTcmxncTZERDVrOE9kZXZBYVExNDdLCkx4K05IOXAxZWdqdDdsZ3p3 d3FKQWpNRUFBRUtBQjBXSVFUTVhCdE9SS0JXODRkd0hSQjNLY2R3ZjM0SjBBVUMKYVdqTmdnQUt DUkIzS2Nkd2YzNEowTTFERC85Z0VlQm5wRzNzMDlDY1hMNHR1UEJJMUFjNzB2NS9FMlAvb20rRg puVWtvZlNHQndJT25jK2ZVTmNnSkpJbWorMzZxaDZ4bUVNMjk5RFgzSVVwSGxVLzBGVWdHa0FGY 1dQd3A4Q3dPCmNkSEFWWDVzMnMwVEYxcFd1Mzd3b0Mvd1ZvVk12cmpGSGlPWVY4ZWxIOEVYV1Vi TVdjTENNWnBxL0x5REJZMXoKM0JjY1FFR3pQRnhYUW00YUZ0d0FlLzZpaUtBM3RmTG1OakE1aWd WMWg3azRiOGJuRW9vRzBDemRPQW5jYlcxSQpEV3ZHdTROT3BudHpDeTl0YUJTeVNyY0R4bWF5Qm 5WR1pHb1dmYUJPQ0d3TzJ4MVl2QXllN0pxRS9VWjBMTFI2CnpUMjU2SDNURHQ0enlxU0F2Zk5uZ 0p6S3FsL3BTT0dYTEM0Ull2cTBNSkJkdXVmQVVxS05ad294VUh2aytLZ1QKQTBKbStWU3Q4V3NX a2JlQ28yNlJGem1iWG1IVzAyRDB4QVBVYjFwZE1MM09HNjBDcSs3ZnVGVllINjJnY2dVRAprc1l sMk1MczFadGNvV0kvT1l5TWJkZkJZSXRMblgrNWZldUpaUWtvS1ZvRmtPQUo5Rk04L2F5MW91Ql RPYzZXCnhpSXVWL1B4Mk50dlYxcjRNckxFdDhDNGQ1Z3JjQkdhNUxDdmFWbFU0eldiVEhkM2lJY 3V0NDR3cnNxVzZzWWEKT2prb01TK1RMcHhKR1pWTXIvN1hCLzBMcEV5NGF1QUFpL0VwdUtWNW5K QXRUWlpGWXVPMEJubDRzZDhkVC9TawpCNWpiMHpqM2FSQ2luQnNDa3RDNkJ6WFpTbTNhVC90TDV Wanh2Y2NCSW55VVAxc0RUV1dqQk0vKy8vY3BabzY3CnVOdkNZZz09Cj1MV1pDCi0tLS0tRU5EIF BHUCBNRVNTQUdFLS0tLS0K X-Developer-Key: i=manos.pitsidianakis@linaro.org; a=openpgp; fpr=7C721DF9DB3CC7182311C0BF68BC211D47B421E1 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 (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=2a00:1450:4864:20::32b; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: qemu development 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 @linaro.org) X-ZM-MESSAGEID: 1768476254809158500 SME2 support adds the following state for HVF guests: - Vector registers Z0, ... , Z31 (introduced by FEAT_SVE but HVF does not support it) - Predicate registers P0, .., P15 (also FEAT_SVE) - ZA register - ZT0 register - PSTATE.{SM,ZA} bits (SVCR pseudo-register) - SMPRI_EL1 which handles the PE's priority in the SMCU - TPIDR2_EL0 the thread local ID register for SME Signed-off-by: Manos Pitsidianakis --- target/arm/hvf/hvf.c | 285 +++++++++++++++++++++++++++++++++++++= +++- target/arm/hvf/hvf_sme_stubs.h | 158 +++++++++++++++++++++++ target/arm/hvf/sysreg.c.inc | 8 ++ target/arm/hvf_arm.h | 41 ++++++ target/arm/machine.c | 2 +- 5 files changed, 491 insertions(+), 3 deletions(-) diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index fa26f63a61ad8fc2ffb675bd6d3c7fd21f1a9dae..6c5061742862635ae394f764188= 114f939259703 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -397,6 +397,60 @@ static const struct hvf_reg_match hvf_fpreg_match[] = =3D { { HV_SIMD_FP_REG_Q31, offsetof(CPUARMState, vfp.zregs[31]) }, }; =20 +static const struct hvf_reg_match hvf_sme2_zreg_match[] =3D { + { HV_SME_Z_REG_0, offsetof(CPUARMState, vfp.zregs[0]) }, + { HV_SME_Z_REG_1, offsetof(CPUARMState, vfp.zregs[1]) }, + { HV_SME_Z_REG_2, offsetof(CPUARMState, vfp.zregs[2]) }, + { HV_SME_Z_REG_3, offsetof(CPUARMState, vfp.zregs[3]) }, + { HV_SME_Z_REG_4, offsetof(CPUARMState, vfp.zregs[4]) }, + { HV_SME_Z_REG_5, offsetof(CPUARMState, vfp.zregs[5]) }, + { HV_SME_Z_REG_6, offsetof(CPUARMState, vfp.zregs[6]) }, + { HV_SME_Z_REG_7, offsetof(CPUARMState, vfp.zregs[7]) }, + { HV_SME_Z_REG_8, offsetof(CPUARMState, vfp.zregs[8]) }, + { HV_SME_Z_REG_9, offsetof(CPUARMState, vfp.zregs[9]) }, + { HV_SME_Z_REG_10, offsetof(CPUARMState, vfp.zregs[10]) }, + { HV_SME_Z_REG_11, offsetof(CPUARMState, vfp.zregs[11]) }, + { HV_SME_Z_REG_12, offsetof(CPUARMState, vfp.zregs[12]) }, + { HV_SME_Z_REG_13, offsetof(CPUARMState, vfp.zregs[13]) }, + { HV_SME_Z_REG_14, offsetof(CPUARMState, vfp.zregs[14]) }, + { HV_SME_Z_REG_15, offsetof(CPUARMState, vfp.zregs[15]) }, + { HV_SME_Z_REG_16, offsetof(CPUARMState, vfp.zregs[16]) }, + { HV_SME_Z_REG_17, offsetof(CPUARMState, vfp.zregs[17]) }, + { HV_SME_Z_REG_18, offsetof(CPUARMState, vfp.zregs[18]) }, + { HV_SME_Z_REG_19, offsetof(CPUARMState, vfp.zregs[19]) }, + { HV_SME_Z_REG_20, offsetof(CPUARMState, vfp.zregs[20]) }, + { HV_SME_Z_REG_21, offsetof(CPUARMState, vfp.zregs[21]) }, + { HV_SME_Z_REG_22, offsetof(CPUARMState, vfp.zregs[22]) }, + { HV_SME_Z_REG_23, offsetof(CPUARMState, vfp.zregs[23]) }, + { HV_SME_Z_REG_24, offsetof(CPUARMState, vfp.zregs[24]) }, + { HV_SME_Z_REG_25, offsetof(CPUARMState, vfp.zregs[25]) }, + { HV_SME_Z_REG_26, offsetof(CPUARMState, vfp.zregs[26]) }, + { HV_SME_Z_REG_27, offsetof(CPUARMState, vfp.zregs[27]) }, + { HV_SME_Z_REG_28, offsetof(CPUARMState, vfp.zregs[28]) }, + { HV_SME_Z_REG_29, offsetof(CPUARMState, vfp.zregs[29]) }, + { HV_SME_Z_REG_30, offsetof(CPUARMState, vfp.zregs[30]) }, + { HV_SME_Z_REG_31, offsetof(CPUARMState, vfp.zregs[31]) }, +}; + +static const struct hvf_reg_match hvf_sme2_preg_match[] =3D { + { HV_SME_P_REG_0, offsetof(CPUARMState, vfp.pregs[0]) }, + { HV_SME_P_REG_1, offsetof(CPUARMState, vfp.pregs[1]) }, + { HV_SME_P_REG_2, offsetof(CPUARMState, vfp.pregs[2]) }, + { HV_SME_P_REG_3, offsetof(CPUARMState, vfp.pregs[3]) }, + { HV_SME_P_REG_4, offsetof(CPUARMState, vfp.pregs[4]) }, + { HV_SME_P_REG_5, offsetof(CPUARMState, vfp.pregs[5]) }, + { HV_SME_P_REG_6, offsetof(CPUARMState, vfp.pregs[6]) }, + { HV_SME_P_REG_7, offsetof(CPUARMState, vfp.pregs[7]) }, + { HV_SME_P_REG_8, offsetof(CPUARMState, vfp.pregs[8]) }, + { HV_SME_P_REG_9, offsetof(CPUARMState, vfp.pregs[9]) }, + { HV_SME_P_REG_10, offsetof(CPUARMState, vfp.pregs[10]) }, + { HV_SME_P_REG_11, offsetof(CPUARMState, vfp.pregs[11]) }, + { HV_SME_P_REG_12, offsetof(CPUARMState, vfp.pregs[12]) }, + { HV_SME_P_REG_13, offsetof(CPUARMState, vfp.pregs[13]) }, + { HV_SME_P_REG_14, offsetof(CPUARMState, vfp.pregs[14]) }, + { HV_SME_P_REG_15, offsetof(CPUARMState, vfp.pregs[15]) }, +}; + /* * QEMU uses KVM system register ids in the migration format. * Conveniently, HVF uses the same encoding of the op* and cr* parameters @@ -408,22 +462,201 @@ static const struct hvf_reg_match hvf_fpreg_match[] = =3D { #define HVF_TO_KVMID(HVF) \ (CP_REG_ARM64 | CP_REG_SIZE_U64 | CP_REG_ARM64_SYSREG | (HVF)) =20 -/* Verify this at compile-time. */ +/* + * Verify this at compile-time. + * + * SME2 registers are guarded by a runtime availability attribute instead = of a + * compile-time def, so verify those at runtime in hvf_arch_init_vcpu() be= low. + */ =20 #define DEF_SYSREG(HVF_ID, ...) \ QEMU_BUILD_BUG_ON(HVF_ID !=3D KVMID_TO_HVF(KVMID_AA64_SYS_REG64(__VA_ARG= S__))); +#define DEF_SYSREG_15_02(...) =20 #include "sysreg.c.inc" =20 #undef DEF_SYSREG +#undef DEF_SYSREG_15_02 =20 #define DEF_SYSREG(HVF_ID, op0, op1, crn, crm, op2) HVF_ID, +#define DEF_SYSREG_15_02(...) =20 static const hv_sys_reg_t hvf_sreg_list[] =3D { #include "sysreg.c.inc" }; =20 #undef DEF_SYSREG +#undef DEF_SYSREG_15_02 + +#define DEF_SYSREG(...) +#define DEF_SYSREG_15_02(HVF_ID, op0, op1, crn, crm, op2) HVF_ID, + +API_AVAILABLE(macos(15.2)) +static const hv_sys_reg_t hvf_sreg_list_sme2[] =3D { +#include "sysreg.c.inc" +}; + +#undef DEF_SYSREG +#undef DEF_SYSREG_15_02 + +/* + * For FEAT_SME2 migration, we need to store PSTATE.{SM,ZA} bits which are + * accessible with the SVCR pseudo-register. However, in the HVF API this = is + * not exposed as a system-register (i.e. HVF_SYS_REG_SVCR) but a custom + * struct, hv_vcpu_sme_state_t. So we need to define our own KVMID in orde= r to + * store it in cpreg_values and make it migrateable. + */ +#define SVCR KVMID_AA64_SYS_REG64(3, 3, 4, 2, 2) + +API_AVAILABLE(macos(15.2)) +static void hvf_arch_put_sme(CPUState *cpu) +{ + ARMCPU *arm_cpu =3D ARM_CPU(cpu); + CPUARMState *env =3D &arm_cpu->env; + const size_t svl_bytes =3D hvf_arm_sme2_get_svl(); + const size_t z_size =3D svl_bytes; + const size_t preg_size =3D DIV_ROUND_UP(z_size, 8); + const size_t za_size =3D svl_bytes * svl_bytes; + hv_vcpu_sme_state_t sme_state =3D { 0 }; + hv_return_t ret; + uint64_t svcr; + int n; + + /* + * Set PSTATE.{SM,ZA} bits + */ + svcr =3D arm_cpu->cpreg_values[arm_cpu->cpreg_array_len - 1]; + env->svcr =3D svcr; + + /* + * Construct SVCR (PSTATE.{SM,ZA}) state to pass to HVF: + */ + sme_state.streaming_sve_mode_enabled =3D FIELD_EX64(env->svcr, SVCR, S= M) > 0; + sme_state.za_storage_enabled =3D FIELD_EX64(env->svcr, SVCR, ZA) > 0; + ret =3D hv_vcpu_set_sme_state(cpu->accel->fd, &sme_state); + assert_hvf_ok(ret); + + /* + * We only care about Z/P registers if we're in streaming SVE mode, i.= e. + * PSTATE.SM is set, because only then can instructions that access th= em be + * used. We don't care about the register values otherwise. This is be= cause + * when the processing unit exits/enters this mode, it zeroes out those + * registers. + */ + if (sme_state.streaming_sve_mode_enabled) { + for (n =3D 0; n < ARRAY_SIZE(hvf_sme2_zreg_match); ++n) { + ret =3D hv_vcpu_set_sme_z_reg(cpu->accel->fd, + hvf_sme2_zreg_match[n].reg, + (uint8_t *)&env->vfp.zregs[n].d[0], + z_size); + assert_hvf_ok(ret); + } + + for (n =3D 0; n < ARRAY_SIZE(hvf_sme2_preg_match); ++n) { + ret =3D hv_vcpu_set_sme_p_reg(cpu->accel->fd, + hvf_sme2_preg_match[n].reg, + (uint8_t *)&env->vfp.pregs[n].p[0], + preg_size); + assert_hvf_ok(ret); + } + } + + /* + * If PSTATE.ZA bit is set then ZA and ZT0 are valid, otherwise they a= re + * zeroed out. + */ + if (sme_state.za_storage_enabled) { + hv_sme_zt0_uchar64_t tmp =3D { 0 }; + + memcpy(&tmp, &env->za_state.zt0, 64); + ret =3D hv_vcpu_set_sme_zt0_reg(cpu->accel->fd, &tmp); + assert_hvf_ok(ret); + + ret =3D hv_vcpu_set_sme_za_reg(cpu->accel->fd, + (uint8_t *)&env->za_state.za, + za_size); + assert_hvf_ok(ret); + } + + return; +} + +API_AVAILABLE(macos(15.2)) +static void hvf_arch_get_sme(CPUState *cpu) +{ + ARMCPU *arm_cpu =3D ARM_CPU(cpu); + CPUARMState *env =3D &arm_cpu->env; + const size_t svl_bytes =3D hvf_arm_sme2_get_svl(); + const size_t z_size =3D svl_bytes; + const size_t preg_size =3D DIV_ROUND_UP(z_size, 8); + const size_t za_size =3D svl_bytes * svl_bytes; + hv_vcpu_sme_state_t sme_state =3D { 0 }; + hv_return_t ret; + uint64_t svcr; + int n; + + /* + * Get SVCR (PSTATE.{SM,ZA}) state from HVF: + */ + ret =3D hv_vcpu_get_sme_state(cpu->accel->fd, &sme_state); + assert_hvf_ok(ret); + + /* + * Set SVCR first because changing it will zero out Z/P regs + */ + svcr =3D + (sme_state.za_storage_enabled ? R_SVCR_ZA_MASK : 0) + | (sme_state.streaming_sve_mode_enabled ? R_SVCR_SM_MASK : 0); + + aarch64_set_svcr(env, svcr, R_SVCR_ZA_MASK | R_SVCR_SM_MASK); + arm_cpu->cpreg_values[arm_cpu->cpreg_array_len - 1] =3D svcr; + + /* + * We only care about Z/P registers if we're in streaming SVE mode, i.= e. + * PSTATE.SM is set, because only then can instructions that access th= em be + * used. We don't care about the register values otherwise. This is be= cause + * when the processing unit exits/enters this mode, it zeroes out those + * registers. + */ + if (sme_state.streaming_sve_mode_enabled) { + for (n =3D 0; n < ARRAY_SIZE(hvf_sme2_zreg_match); ++n) { + ret =3D hv_vcpu_get_sme_z_reg(cpu->accel->fd, + hvf_sme2_zreg_match[n].reg, + (uint8_t *)&env->vfp.zregs[n].d[0], + z_size); + assert_hvf_ok(ret); + } + + for (n =3D 0; n < ARRAY_SIZE(hvf_sme2_preg_match); ++n) { + ret =3D hv_vcpu_get_sme_p_reg(cpu->accel->fd, + hvf_sme2_preg_match[n].reg, + (uint8_t *)&env->vfp.pregs[n].p[0], + preg_size); + assert_hvf_ok(ret); + } + } + + /* + * If PSTATE.ZA bit is set then ZA and ZT0 are valid, otherwise they a= re + * zeroed out. + */ + if (sme_state.za_storage_enabled) { + hv_sme_zt0_uchar64_t tmp =3D { 0 }; + + /* Get ZT0 in a tmp vector, and then copy it to env.za_state.zt0 */ + ret =3D hv_vcpu_get_sme_zt0_reg(cpu->accel->fd, &tmp); + assert_hvf_ok(ret); + + memcpy(&env->za_state.zt0, &tmp, 64); + ret =3D hv_vcpu_get_sme_za_reg(cpu->accel->fd, + (uint8_t *)&env->za_state.za, + za_size); + assert_hvf_ok(ret); + + } + + return; +} =20 int hvf_arch_get_registers(CPUState *cpu) { @@ -465,6 +698,10 @@ int hvf_arch_get_registers(CPUState *cpu) uint64_t kvm_id =3D arm_cpu->cpreg_indexes[i]; int hvf_id =3D KVMID_TO_HVF(kvm_id); =20 + if (kvm_id =3D=3D HVF_TO_KVMID(SVCR)) { + continue; + } + if (cpu->accel->guest_debug_enabled) { /* Handle debug registers */ switch (hvf_id) { @@ -558,6 +795,11 @@ int hvf_arch_get_registers(CPUState *cpu) =20 arm_cpu->cpreg_values[i] =3D val; } + if (__builtin_available(macOS 15.2, *)) { + if (cpu_isar_feature(aa64_sme, arm_cpu)) { + hvf_arch_get_sme(cpu); + } + } assert(write_list_to_cpustate(arm_cpu)); =20 aarch64_restore_sp(env, arm_current_el(env)); @@ -603,6 +845,10 @@ int hvf_arch_put_registers(CPUState *cpu) uint64_t kvm_id =3D arm_cpu->cpreg_indexes[i]; int hvf_id =3D KVMID_TO_HVF(kvm_id); =20 + if (kvm_id =3D=3D HVF_TO_KVMID(SVCR)) { + continue; + } + if (cpu->accel->guest_debug_enabled) { /* Handle debug registers */ switch (hvf_id) { @@ -687,6 +933,11 @@ int hvf_arch_put_registers(CPUState *cpu) ret =3D hv_vcpu_set_vtimer_offset(cpu->accel->fd, hvf_state->vtimer_of= fset); assert_hvf_ok(ret); =20 + if (__builtin_available(macOS 15.2, *)) { + if (cpu_isar_feature(aa64_sme, arm_cpu)) { + hvf_arch_put_sme(cpu); + } + } return 0; } =20 @@ -909,6 +1160,18 @@ int hvf_arch_init_vcpu(CPUState *cpu) hv_return_t ret; int i; =20 + if (__builtin_available(macOS 15.2, *)) { + sregs_match_len +=3D ARRAY_SIZE(hvf_sreg_list_sme2) + 1; + +#define DEF_SYSREG_15_02(HVF_ID, ...) \ + g_assert(HVF_ID =3D=3D KVMID_TO_HVF(KVMID_AA64_SYS_REG64(__VA_ARGS= __))); +#define DEF_SYSREG(...) + +#include "sysreg.c.inc" + +#undef DEF_SYSREG +#undef DEF_SYSREG_15_02 + } env->aarch64 =3D true; asm volatile("mrs %0, cntfrq_el0" : "=3Dr"(arm_cpu->gt_cntfrq_hz)); =20 @@ -927,7 +1190,7 @@ int hvf_arch_init_vcpu(CPUState *cpu) memset(arm_cpu->cpreg_values, 0, sregs_match_len * sizeof(uint64_t)); =20 /* Populate cp list for all known sysregs */ - for (i =3D 0; i < sregs_match_len; i++) { + for (i =3D 0; i < ARRAY_SIZE(hvf_sreg_list); i++) { hv_sys_reg_t hvf_id =3D hvf_sreg_list[i]; uint64_t kvm_id =3D HVF_TO_KVMID(hvf_id); uint32_t key =3D kvm_to_cpreg_id(kvm_id); @@ -938,6 +1201,24 @@ int hvf_arch_init_vcpu(CPUState *cpu) arm_cpu->cpreg_indexes[sregs_cnt++] =3D kvm_id; } } + if (__builtin_available(macOS 15.2, *)) { + for (i =3D 0; i < ARRAY_SIZE(hvf_sreg_list_sme2); i++) { + hv_sys_reg_t hvf_id =3D hvf_sreg_list_sme2[i]; + uint64_t kvm_id =3D HVF_TO_KVMID(hvf_id); + uint32_t key =3D kvm_to_cpreg_id(kvm_id); + const ARMCPRegInfo *ri =3D get_arm_cp_reginfo(arm_cpu->cp_regs= , key); + + if (ri) { + assert(!(ri->type & ARM_CP_NO_RAW)); + arm_cpu->cpreg_indexes[sregs_cnt++] =3D kvm_id; + } + } + /* + * Add SVCR last. It is elsewhere assumed its index is after + * hvf_sreg_list and hvf_sreg_list_sme2. + */ + arm_cpu->cpreg_indexes[sregs_cnt++] =3D HVF_TO_KVMID(SVCR); + } arm_cpu->cpreg_array_len =3D sregs_cnt; arm_cpu->cpreg_vmstate_array_len =3D sregs_cnt; =20 diff --git a/target/arm/hvf/hvf_sme_stubs.h b/target/arm/hvf/hvf_sme_stubs.h new file mode 100644 index 0000000000000000000000000000000000000000..9c679b711017448681e532b88ce= 10a07ebfd5122 --- /dev/null +++ b/target/arm/hvf/hvf_sme_stubs.h @@ -0,0 +1,158 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +typedef int32_t hv_return_t; +typedef uint64_t hv_vcpu_t; + +static inline bool hvf_arm_sme2_supported(void) +{ + return false; +} + +static inline uint32_t hvf_arm_sme2_get_svl(void) +{ + g_assert_not_reached(); +} + +typedef enum hv_sme_p_reg_t { + HV_SME_P_REG_0, + HV_SME_P_REG_1, + HV_SME_P_REG_2, + HV_SME_P_REG_3, + HV_SME_P_REG_4, + HV_SME_P_REG_5, + HV_SME_P_REG_6, + HV_SME_P_REG_7, + HV_SME_P_REG_8, + HV_SME_P_REG_9, + HV_SME_P_REG_10, + HV_SME_P_REG_11, + HV_SME_P_REG_12, + HV_SME_P_REG_13, + HV_SME_P_REG_14, + HV_SME_P_REG_15, +} hv_sme_p_reg_t; + +typedef __attribute__((ext_vector_type(64))) uint8_t hv_sme_zt0_uchar64_t; + +typedef enum hv_sme_z_reg_t { + HV_SME_Z_REG_0, + HV_SME_Z_REG_1, + HV_SME_Z_REG_2, + HV_SME_Z_REG_3, + HV_SME_Z_REG_4, + HV_SME_Z_REG_5, + HV_SME_Z_REG_6, + HV_SME_Z_REG_7, + HV_SME_Z_REG_8, + HV_SME_Z_REG_9, + HV_SME_Z_REG_10, + HV_SME_Z_REG_11, + HV_SME_Z_REG_12, + HV_SME_Z_REG_13, + HV_SME_Z_REG_14, + HV_SME_Z_REG_15, + HV_SME_Z_REG_16, + HV_SME_Z_REG_17, + HV_SME_Z_REG_18, + HV_SME_Z_REG_19, + HV_SME_Z_REG_20, + HV_SME_Z_REG_21, + HV_SME_Z_REG_22, + HV_SME_Z_REG_23, + HV_SME_Z_REG_24, + HV_SME_Z_REG_25, + HV_SME_Z_REG_26, + HV_SME_Z_REG_27, + HV_SME_Z_REG_28, + HV_SME_Z_REG_29, + HV_SME_Z_REG_30, + HV_SME_Z_REG_31, +} hv_sme_z_reg_t; + +enum { + HV_SYS_REG_SMCR_EL1, + HV_SYS_REG_SMPRI_EL1, + HV_SYS_REG_TPIDR2_EL0, + HV_SYS_REG_ID_AA64ZFR0_EL1, + HV_SYS_REG_ID_AA64SMFR0_EL1, +}; + +typedef struct { + bool streaming_sve_mode_enabled; + bool za_storage_enabled; +} hv_vcpu_sme_state_t; + +static inline hv_return_t hv_sme_config_get_max_svl_bytes(size_t *value) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_get_sme_state(hv_vcpu_t vcpu, + hv_vcpu_sme_state_t *sme_s= tate) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_set_sme_state(hv_vcpu_t vcpu, + const hv_vcpu_sme_state_t = *sme_state) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_get_sme_z_reg(hv_vcpu_t vcpu, + hv_sme_z_reg_t reg, + uint8_t *value, + size_t length) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_set_sme_z_reg(hv_vcpu_t vcpu, + hv_sme_z_reg_t reg, + const uint8_t *value, + size_t length) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_get_sme_p_reg(hv_vcpu_t vcpu, + hv_sme_p_reg_t reg, + uint8_t *value, + size_t length) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_set_sme_p_reg(hv_vcpu_t vcpu, + hv_sme_p_reg_t reg, + const uint8_t *value, + size_t length) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_get_sme_za_reg(hv_vcpu_t vcpu, + uint8_t *value, + size_t length) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_set_sme_za_reg(hv_vcpu_t vcpu, + const uint8_t *value, + size_t length) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_get_sme_zt0_reg(hv_vcpu_t vcpu, + hv_sme_zt0_uchar64_t *va= lue) +{ + g_assert_not_reached(); +} + +static inline hv_return_t hv_vcpu_set_sme_zt0_reg(hv_vcpu_t vcpu, + const hv_sme_zt0_uchar64= _t *value) +{ + g_assert_not_reached(); +} diff --git a/target/arm/hvf/sysreg.c.inc b/target/arm/hvf/sysreg.c.inc index 067a8603fa785593ed0879cea26d036b0ec2823e..7a2f880f784b7610b14a6eb91fe= c1817e98bfd2e 100644 --- a/target/arm/hvf/sysreg.c.inc +++ b/target/arm/hvf/sysreg.c.inc @@ -145,3 +145,11 @@ DEF_SYSREG(HV_SYS_REG_TPIDRRO_EL0, 3, 3, 13, 0, 3) DEF_SYSREG(HV_SYS_REG_CNTV_CTL_EL0, 3, 3, 14, 3, 1) DEF_SYSREG(HV_SYS_REG_CNTV_CVAL_EL0, 3, 3, 14, 3, 2) DEF_SYSREG(HV_SYS_REG_SP_EL1, 3, 4, 4, 1, 0) + +DEF_SYSREG_15_02(HV_SYS_REG_SMCR_EL1, 3, 0, 1, 2, 6) +DEF_SYSREG_15_02(HV_SYS_REG_SMPRI_EL1, 3, 0, 1, 2, 4) +DEF_SYSREG_15_02(HV_SYS_REG_TPIDR2_EL0, 3, 3, 13, 0, 5) +DEF_SYSREG_15_02(HV_SYS_REG_ID_AA64ZFR0_EL1, 3, 0, 0, 4, 4) +DEF_SYSREG_15_02(HV_SYS_REG_ID_AA64SMFR0_EL1, 3, 0, 0, 4, 5) +DEF_SYSREG_15_02(HV_SYS_REG_SMPRI_EL1, 3, 0, 1, 2, 4) +DEF_SYSREG_15_02(HV_SYS_REG_SMCR_EL1, 3, 0, 1, 2, 6) diff --git a/target/arm/hvf_arm.h b/target/arm/hvf_arm.h index ea82f2691dfcce780d9ab7d580c8a7946e3abaa7..6b5db457259667dd97620aac76c= a0ab5c672fb04 100644 --- a/target/arm/hvf_arm.h +++ b/target/arm/hvf_arm.h @@ -25,4 +25,45 @@ void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu); uint32_t hvf_arm_get_default_ipa_bit_size(void); uint32_t hvf_arm_get_max_ipa_bit_size(void); =20 +/* + * We need access to types from macOS SDK >=3D15.2, so expose stubs if the + * headers are not available until we raise our minimum macOS version. + */ +#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED + #if (__MAC_OS_X_VERSION_MAX_ALLOWED >=3D 150200) + #include "system/hvf_int.h" + + static inline bool hvf_arm_sme2_supported(void) + { + if (__builtin_available(macOS 15.2, *)) { + size_t svl_bytes; + hv_return_t result =3D hv_sme_config_get_max_svl_bytes(&svl_by= tes); + if (result =3D=3D HV_UNSUPPORTED) { + return false; + } + assert_hvf_ok(result); + return svl_bytes > 0; + } else { + return false; + } + } + + static inline uint32_t hvf_arm_sme2_get_svl(void) + { + if (__builtin_available(macOS 15.2, *)) { + size_t svl_bytes; + hv_return_t result =3D hv_sme_config_get_max_svl_bytes(&svl_by= tes); + assert_hvf_ok(result); + return svl_bytes; + } else { + abort(); + } + } + #else /* (__MAC_OS_X_VERSION_MAX_ALLOWED >=3D 150200) */ + #include "hvf/hvf_sme_stubs.h" + #endif /* (__MAC_OS_X_VERSION_MAX_ALLOWED >=3D 150200) */ +#else /* ifdef __MAC_OS_X_VERSION_MAX_ALLOWED */ + #include "hvf/hvf_sme_stubs.h" +#endif /* ifdef __MAC_OS_X_VERSION_MAX_ALLOWED */ + #endif diff --git a/target/arm/machine.c b/target/arm/machine.c index 0befdb0b28ad3f45b0bd83575dd9fd4fecaf3db1..7e3339081bf1f9f57bb0514d795= c8a4254975c6a 100644 --- a/target/arm/machine.c +++ b/target/arm/machine.c @@ -231,7 +231,7 @@ static bool sve_needed(void *opaque) { ARMCPU *cpu =3D opaque; =20 - return cpu_isar_feature(aa64_sve, cpu); + return cpu_isar_feature(aa64_sve, cpu) || cpu_isar_feature(aa64_sme, c= pu); } =20 /* The first two words of each Zreg is stored in VFP state. */ --=20 2.47.3 From nobody Mon Feb 9 09:00:20 2026 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1768476235; cv=none; d=zohomail.com; s=zohoarc; b=C3gFo6OzVoxfYlmaaVueAK1RlYUQjDwqO4YD4vOWYpbkNaZA4EDcUTuea1L5fckJkh87WA247Qbl0duYM4vqZAXQfhPwpgEvJ6CeubbeRrl1BgHvVNWUmT3kHFdshOetrFIDVc7WtM2TlQ9Dlxf5Tqe6N3tyc8dgRk1+XEDb5tQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768476235; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gxdv/yxf7Gc06BBnTyaRhxTtJwT1Uo1vV5jtTthLm+g=; b=nZdxPxZDWhOCsCxkdAijSl1c78x39PNpfSATBedKH4cyRFzLaOqHWmiKhp2/F666BZmln+mi69CYcn/EE/MFirjtd6YffcJfuYUO47V+Mgz7offvpgkuQ9OrBUKqsGc/ucbj6oeXx5mKv9S6bqPywnYXtT7dU8lYwtQXDiHzUqg= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176847623574968.90249373321205; Thu, 15 Jan 2026 03:23:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vgLPB-0002Lx-HU; Thu, 15 Jan 2026 06:20:45 -0500 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 1vgLP9-0002Ks-43 for qemu-devel@nongnu.org; Thu, 15 Jan 2026 06:20:43 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vgLP6-00076D-Ee for qemu-devel@nongnu.org; Thu, 15 Jan 2026 06:20:42 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-432d2c96215so647237f8f.3 for ; Thu, 15 Jan 2026 03:20:40 -0800 (PST) Received: from [127.0.1.1] (ppp-2-86-214-23.home.otenet.gr. [2.86.214.23]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-434af64a778sm5302085f8f.3.2026.01.15.03.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 03:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1768476039; x=1769080839; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gxdv/yxf7Gc06BBnTyaRhxTtJwT1Uo1vV5jtTthLm+g=; b=qS7xQvlG09iPolSzKFa9wG+FO4M3svfLGuB7L7k2xfnFc6I9DJHJ4KzuN7dUrD88tC KuRUc6zFkLjS0CrPx5Ur9/mbnF2xCmTSeZ6YBuu7lwBMAT2ZB4zuoPEQHRi0hTOqFaeX AXKOMsWbiAanlVMMsD6wNY2S7iCx6RJFgQ2ozdqIW7YLP5yMT3KWgCHXsEqZcBEUuOad dkFcyGRPLAE/yXAn9cHr4KmEwVO7Jk2Wu7a2vLFLrcHvmv9FUKN5DpnNRcmYisVo326P RvLaxF+1caRAwfxNiwpXBZzdq2AzbDfBeXMoh8WKi087z8W1JcNwsm31JVlZ/ggvjyBP o67g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768476039; x=1769080839; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=gxdv/yxf7Gc06BBnTyaRhxTtJwT1Uo1vV5jtTthLm+g=; b=rrFGHAxrkPUPIAfkBFXAq2y43eB1juUxOYfNCb2ZXf6cO2VMACjhvXT9juGHyZQB0+ 7+zKT24qU5I9q0FXvsB0qvUPbubHsHyQAI/BTiAUec8Q0FEXr22jlu4BM9kD/9u90fyZ sbfHEGx9uxkJ5/lHYlUCww6gswSCl5bRqRnTmPS2VjEspGMqbiCULXXztewHSNYj9pEx 9E4hdPpxvrTQA/qxvE/TyIhSkKll4hyKWgAURA4ZtdIvcBkoWeEr335Ry6Lt4+6XMQ9x iiy8Z75b+lLaM4UDd4CkevQMv05IxDJNgvZKbzqdCoJnRDrelmTNqbn8aYO5UyoF8x4C ap1w== X-Gm-Message-State: AOJu0YwD5yUdXO+wr9AoU5kHNcqPCps1lpoq53SjGVROOhhC3KEStn+W yLG9N3y/yv8ICiLa01/cziKmMVVx9CD5Q20jBFzjKkS+L4wQoYl7lQmjWm0vL6MlGvk= X-Gm-Gg: AY/fxX6+N5EiqdI60BuXZs/qOj5r9WGA0o1q4XFyBDDZKDjJS52HbRTvF4ZrOr4qPsG otw2LdeGuLCFfsmkSbuvjaCtTc2/CpnzfmeBbcGTw68Tj+jCvtIyIg1w/ZrHA9E75FJI/n2uqh/ tpKuoWDYORiQ6WtDpmHV9FMZGes5AZFx0xo3ItViYjd/w5knvEAl8aFmkENbJkqnSBBKDBzlirW bE481CX5tGqyLEyZLYAfc6Ug45pFIOJ5vLU1cwcR19VZ4sS05F/0TTAg2m1GKhnq9Ztmf+wPd4N eN0bZRNTcJ+xWDoSsvWiouQntm8g6B1QcT4CfaWtRgjSTcAn/C9kPlaWIchjS51/lawoy5IsheM klVkETQnljsOF66FcwbO6DRBu6Mhrg1CaOZddaN3B5kt2zIMslp+eMIAPYZp5hUQ9bSC1FQM3YR bqiFpdcnjeETAq2VrkH0qiLM/OMkDxCB6hZp2RVhNJJTSlGkZRBkOJ4Cc429BKbeSwYfcaOOoU/ luZ6FoB4D5O/jtxiD5/rQwF X-Received: by 2002:a05:6000:438a:b0:431:35a:4a8f with SMTP id ffacd0b85a97d-4342d5ced24mr7738335f8f.47.1768476038866; Thu, 15 Jan 2026 03:20:38 -0800 (PST) From: Manos Pitsidianakis Date: Thu, 15 Jan 2026 13:20:29 +0200 Subject: [PATCH v2 2/2] hvf/arm: expose FEAT_SME2 to guest if available MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260115-sme2-hvf-v2-2-2eca481bd7ee@linaro.org> References: <20260115-sme2-hvf-v2-0-2eca481bd7ee@linaro.org> In-Reply-To: <20260115-sme2-hvf-v2-0-2eca481bd7ee@linaro.org> To: qemu-devel@nongnu.org Cc: Richard Henderson , =?utf-8?q?Phil_Mathieu-Daud=C3=A9?= , Alexander Graf , Mads Ynddal , Peter Maydell , qemu-arm@nongnu.org, Mohamed Mediouni , Manos Pitsidianakis X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3824; i=manos.pitsidianakis@linaro.org; h=from:subject:message-id; bh=X+YHhHK/0kmvaB/J4/1t1nqbn+MaGoCBFh2QSc+9wsw=; b=LS0tLS1CRUdJTiBQR1AgTUVTU0FHRS0tLS0tCgpvd0VCYlFLUy9aQU5Bd0FLQVhjcHgzQi9mZ 25RQWNzbVlnQnBhTTJDVS84ZldCWkNBa0FnTy9qWTNyM25qYWxTCkozUS9xMFoxZWtoQWJvUVNS Nk9KQWpNRUFBRUtBQjBXSVFUTVhCdE9SS0JXODRkd0hSQjNLY2R3ZjM0SjBBVUMKYVdqTmdnQUt DUkIzS2Nkd2YzNEowQ2FBRUFDSkNma2FkNm1BYXFXZjFaZFYrdnhmZ20rMzRWSHVWMXJJUTNZNg pTSWRROE4wOWRycHN3Kzh6NXhnSUdwaE9EamloVEZLTHh5M1FOSnppMGZvTkY4dlIvdlRHMmRpc WVTYjJlZHN6ClhzL1cvRHM5SDczM2JxMVR3T0tCTlB5bWFMSTdqN1ZmWkF5VEdTeEFRUG9EVmRB YzFpWndHWnRWVXlSRllleUgKQ1NIYTBsVS9TTkxFYzNCb01UV3p1UWx1ZjB0OU1VRERSbUp0WER xRlNnRU5CcXpsMnJQQjQ1SWd2aStSeXpISQpwMDBUekxqcU02OXhodURjNExGNDhBTnhHc1NaT0 crejhZSmFwRVA2ZDNOUlBxWkFMN09HNTA2OGJ4Y00xUFF2CjJUaDdtSFlTNlNnK3VTeUdaYkFET Dl2b2c1OWlnaXVLYWw4ZXAyc1JObEkxVzFsTFBEWk5vRTJPTU51T1EvdlAKeHpQWXliaTNwQ1lU cVc1dkpjN3ZEVTdyeE53RkVrME00UXZvZXlIWHNUL1FSWVBVWHZ1WmhMK1dCQTVVRUJNOQpIaWh EWVR3T2REOU14a0dRYkVHamNoc3BQcWpGZG8yNHRoRVZuZ0ZodnIwSE9NSjhmTjlZTzI4T2RRTy 9IQ0JCClNFckxBdUdXUGxSbEdaVGt1cXpCL2lZMzU0S0JhNGk1ZGtud3QxbU9wN2plMkJZUEY5O HhXejVxNEV4REtIckEKWmYwQWhFRGZLTVBsU1VlZ21jQXRwcG8ybDRrbUV1Z1hyTVRUcXNKL28y RHJrQ2hESWdUUXd5anRUcmt5Tk03ZQpIOHJrcTdpWnBtZXpxRzZObWFkWm1CejgyVGpzUFRhdlN 5TGZPdjFmZUNHaWxQejBWdkQwTU12OHM1bWFETW0vCjZYdURlQT09Cj1LU3dKCi0tLS0tRU5EIF BHUCBNRVNTQUdFLS0tLS0K X-Developer-Key: i=manos.pitsidianakis@linaro.org; a=openpgp; fpr=7C721DF9DB3CC7182311C0BF68BC211D47B421E1 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 (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=2a00:1450:4864:20::42b; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: qemu development 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 @linaro.org) X-ZM-MESSAGEID: 1768476236989158500 Starting from M4 cores and MacOS 15.2 SDK, HVF can virtualise FEAT_SME2. Reviewed-by: Mohamed Mediouni Signed-off-by: Manos Pitsidianakis --- target/arm/cpu.c | 4 +++- target/arm/cpu64.c | 13 ++++++++++++- target/arm/hvf/hvf.c | 25 +++++++++++++------------ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index caf7980b1fc5244c5c2f130e79ba869456c20c88..7f4ebfdf61217db6075495119c1= b642bc2abf295 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1577,7 +1577,9 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **e= rrp) * assumes it, so if the user asked for sve=3Doff then turn off SM= E also. * (KVM doesn't currently support SME at all.) */ - if (cpu_isar_feature(aa64_sme, cpu) && !cpu_isar_feature(aa64_sve,= cpu)) { + if (!hvf_enabled() + && cpu_isar_feature(aa64_sme, cpu) + && !cpu_isar_feature(aa64_sve, cpu)) { object_property_set_bool(OBJECT(cpu), "sme", false, &error_abo= rt); } =20 diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index bf303813701972648fa6751ffe352ba074ca6442..8dd9eb46c783a799a53891a6dda= d40b930e95eb4 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -329,9 +329,20 @@ void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp) { uint32_t vq_map =3D cpu->sme_vq.map; uint32_t vq_init =3D cpu->sme_vq.init; - uint32_t vq_supported =3D cpu->sme_vq.supported; + uint32_t vq_supported; uint32_t vq; =20 + if (hvf_enabled()) { + if (hvf_arm_sme2_supported()) { + vq_supported =3D hvf_arm_sme2_get_svl(); + } else { + assert(!cpu_isar_feature(aa64_sme, cpu)); + vq_supported =3D 0; + } + } else { + vq_supported =3D cpu->sme_vq.supported; + } + if (vq_map =3D=3D 0) { if (!cpu_isar_feature(aa64_sme, cpu)) { SET_IDREG(&cpu->isar, ID_AA64SMFR0, 0); diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index 6c5061742862635ae394f764188114f939259703..01bbb90b962156885021da75a0d= 62ae3c39ff5b0 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -1043,18 +1043,18 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCP= UFeatures *ahcf) =20 clamp_id_aa64mmfr0_parange_to_ipa_size(&host_isar); =20 - /* - * Disable SME, which is not properly handled by QEMU hvf yet. - * To allow this through we would need to: - * - make sure that the SME state is correctly handled in the - * get_registers/put_registers functions - * - get the SME-specific CPU properties to work with accelerators - * other than TCG - * - fix any assumptions we made that SME implies SVE (since - * on the M4 there is SME but not SVE) - */ - SET_IDREG(&host_isar, ID_AA64PFR1, - GET_IDREG(&host_isar, ID_AA64PFR1) & ~R_ID_AA64PFR1_SME_MASK= ); + if (hvf_arm_sme2_supported()) { + t =3D GET_IDREG(&host_isar, ID_AA64PFR1); + t =3D FIELD_DP64(t, ID_AA64PFR1, SME, 2); /* FEAT_SME2 */ + SET_IDREG(&host_isar, ID_AA64PFR1, t); + + t =3D GET_IDREG(&host_isar, ID_AA64SMFR0); + t =3D FIELD_DP64(t, ID_AA64SMFR0, SMEVER, 1); /* FEAT_SME2 */ + SET_IDREG(&host_isar, ID_AA64SMFR0, t); + } else { + SET_IDREG(&host_isar, ID_AA64PFR1, + GET_IDREG(&host_isar, ID_AA64PFR1) & ~R_ID_AA64PFR1_SME_MA= SK); + } =20 ahcf->isar =3D host_isar; =20 @@ -1252,6 +1252,7 @@ int hvf_arch_init_vcpu(CPUState *cpu) arm_cpu->isar.idregs[ID_AA64MMFR0_EL1_IDX]); assert_hvf_ok(ret); =20 + aarch64_add_sme_properties(OBJECT(cpu)); return 0; } =20 --=20 2.47.3