Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93770606A322 for ; Thu, 3 Dec 2026 17:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YueyLUXC Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZAMr-0003mH-9X; Thu, 03 Dec 2026 12:13:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZALQ-0008KH-77 for qemu-devel@nongnu.org; Thu, 03 Dec 2026 12:11:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZALO-0006lg-2W for qemu-devel@nongnu.org; Thu, 03 Dec 2026 12:11:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796317902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=28JFGDEiGG5FLyOwaHwfnlln8k8WoOjBK+ghu4X99Zk=; b=YueyLUXCWSZYFPgtzdibsfkrB9yjICBtH+/jZER98TOyW3NjLHFYRvr//1tUNbR0y0Wc+s 9fvgaiCBO0H67aB2nLXWNbH7xgfk5I/dm0ZKAeTQvEfFzghKLpMshx/D7snblGCQlWUDrw g2JwkdceBwuwtWedM8y7W+qBBiMcQw8= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-XKaGmAuyPI6nLvMAYIaPHw-1; Thu, 3 Dec 2026 17:11:35 +0000 X-MC-Unique: XKaGmAuyPI6nLvMAYIaPHw-1 X-Mimecast-MFC-AGG-ID: XKaGmAuyPI6nLvMAYIaPHw_1796317894 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D6A3218BEE6F; Thu, 3 Dec 2026 17:11:33 +0000 (UTC) Received: from eauger-thinkpadp1gen8.rmtfr.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C977195605B; Thu, 3 Dec 2026 17:11:30 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, shaju.abraham@nutanix.com, khushit.shah@nutanix.com, richard.henderson@linaro.org, pbonzini@redhat.com, skolothumtho@nvidia.com, philmd@oss.qualcomm.com Cc: armbru@redhat.com, mbawa@redhat.com, cohuck@redhat.com Subject: [PATCH v11 15/20] target/arm/kvm: Add consistency checking for SYSREG props Date: Thu, 3 Dec 2026 18:09:04 +0100 Message-ID: <20261203171020.2594683-16-eric.auger@redhat.com> In-Reply-To: <20261203171020.2594683-1-eric.auger@redhat.com> References: <20261203171020.2594683-1-eric.auger@redhat.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass client-ip=170.10.129.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 3 X-Spam_score: 0.3 X-Spam_bar: / X-Spam_report: (0.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Since legacy composite options (such as SVE, virtualization, ...) and new SYSREG props coexist, add some basic consistency checks. Those checks are performed in kvm_arch_init_vcpu() before applying the SYSREG props at the end of the initialization chain. Some ID reg fields corresponding to legacy composite option scope are not (yet) writable (MTE, SVE, ...). As such they are not supposed to be exposed through SYSREG properties. However in the hypothesis they would become writable, and thus would be exposed and attempted to be set, we need to reject any setting because no consistency check is implemented yet. The function is exported because it will be used on the qmp expansion path too. Signed-off-by: Eric Auger --- v10 -> v11 - Revert the aarch64_sysreg_prop_skipped approach. In case those fields become writable they will be exposed but the end user will be prevented from setting them as in v9. - add check for ID_AA64PFR0_EL1_EL3 which is actually writable v9 -> v10 - improve commit description - fix return in !arm_feature(&cpu->env, ARM_FEATURE_AARCH64) block - removed cpu_isar_feature(aa64_sve, cpu) && value == 0 check --- target/arm/cpu-idregs.h | 17 +++++++ target/arm/cpu64.c | 99 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/target/arm/cpu-idregs.h b/target/arm/cpu-idregs.h index ed1883b7fa..d3c8c8af74 100644 --- a/target/arm/cpu-idregs.h +++ b/target/arm/cpu-idregs.h @@ -58,4 +58,21 @@ int arm_cpu_apply_sysreg_props(ARMCPU *cpu, ARMSysregPropApplyFn accel_set_idreg_field_fn, Error **errp); +/** + * arm_cpu_validate_sysreg_prop: + * + * accelerator agnostic validation of a field value (especially regarding + * the consistency with legacy composite options such as virtualization, pmu, + * sve ...) + * + * @cpu: vcpu the field value is validated against + * @field: field the value is applied to + * @value: field value to be validated + * @errp: error handle set if validation fails + * + * returns true if validation succeeds + */ +bool arm_cpu_validate_sysreg_prop(ARMCPU *cpu, ARM64SysRegField *field, + uint64_t value, Error **errp); + #endif diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 38964e5341..5f07af288f 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -835,6 +835,101 @@ static ARM64SysRegField *arm_sysreg_get_field(ARM64SysReg *reg, int bit) return NULL; } +/* + * SYSREG properties that are not exposed yet because the fields + * are not yet writable and which are known to conflict with legacy + * composite options (EL3, MTE, SVE, pauth, ...). In case they get + * exposed by the kernel we will mention qemu is not ready to support + * them + */ +static const char * const aarch64_sysreg_prop_not_fully_handled[] = { + "SYSREG_ID_AA64PFR1_EL1_MTE", + "SYSREG_ID_AA64PFR0_EL1_SVE", + "SYSREG_ID_AA64ISAR1_EL1_APA", + "SYSREG_ID_AA64ISAR1_EL1_API", + "SYSREG_ID_AA64ISAR1_EL1_GPA", + "SYSREG_ID_AA64ISAR1_EL1_GPI", + "SYSREG_ID_AA64ISAR2_EL1_APA3", + "SYSREG_ID_AA64ISAR2_EL1_GPA3", +}; + +static bool +aarch64_sysreg_prop_is_not_fully_handled(const char *prop_name) +{ + for (int i = 0; i < ARRAY_SIZE(aarch64_sysreg_prop_not_fully_handled); i++) { + if (g_str_equal(prop_name, aarch64_sysreg_prop_not_fully_handled[i])) { + return true; + } + } + return false; +} + +/** + * arm_cpu_validate_sysreg_prop: + * + * Validate a SYSREG field value against legacy composite options + * (virtualization, pmu, sve, aarch64, ...) + */ +bool arm_cpu_validate_sysreg_prop(ARMCPU *cpu, ARM64SysRegField *field, + uint64_t value, Error **errp) +{ + ARM64SysReg *sysregdesc = &arm64_id_regs[field->index]; + g_autofree char *propname = + g_strdup_printf("SYSREG_%s_%s", sysregdesc->name, field->name); + + /* virtualization */ + if (!strcmp(propname, "SYSREG_ID_AA64PFR0_EL1_EL2")) { + if (cpu->has_el2 && value == 0) { + error_setg(errp, + "Inconsistent -machine virtualization=on and %s=0", + propname); + return false; + } else if (!cpu->has_el2 && value > 0) { + error_setg(errp, + "Inconsistent -machine virtualization=off and %s > 0", + propname); + return false; + } + } else if (!strcmp(propname, "SYSREG_ID_AA64PFR0_EL1_EL3")) { + if (!cpu->has_el3 && value) { + error_setg(errp, + "Inconsistent -machine secure=off and %s > 0", + propname); + return false; + } + } else if (!strcmp(propname, "SYSREG_ID_AA64ZFR0_EL1_SVEver")) { + if (!cpu_isar_feature(aa64_sve, cpu) && value > 0) { + error_setg(errp, "sve is not set but %s is greater than 0", + propname); + return false; + } + /* PMU */ + } else if (!strcmp(propname, "SYSREG_ID_AA64DFR0_EL1_PMUVer")) { + if (cpu->has_pmu && value == 0) { + error_setg(errp, "%s is 0 whereas pmu is set", propname); + return false; + } else if (!cpu->has_pmu && value) { + error_setg(errp, "%s is non null whereas pmu is unset", propname); + return false; + } + /* aarch64=off */ + } else if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { + if ((!strcmp(propname, "SYSREG_ID_AA64PFR0_EL1_EL0") || + !strcmp(propname, "SYSREG_ID_AA64PFR0_EL1_EL1") || + !strcmp(propname, "SYSREG_ID_AA64PFR0_EL1_EL2")) && value < 2) { + error_setg(errp, "%s is < 2 while aarch64 is set to off", + propname); + return false; + } + } + if (aarch64_sysreg_prop_is_not_fully_handled(propname)) { + error_setg(errp, "%s is now exposed but qemu is not ready to support it", + propname); + return false; + } + return true; +} + /** * arm_cpu_apply_sysreg_props: * @@ -866,6 +961,10 @@ int arm_cpu_apply_sysreg_props(ARMCPU *cpu, return -EINVAL; } + if (!arm_cpu_validate_sysreg_prop(cpu, field, newfv, errp)) { + return -EINVAL; + } + ret = accel_set_idreg_field_fn(cpu, field, newfv, &appliedfv, errp); if (ret) { return ret; -- 2.56.1