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 65FA6606A322 for ; Thu, 3 Dec 2026 17:12:42 +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=KO03z7Mh Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZAM3-0000Xm-9B; Thu, 03 Dec 2026 12:12:23 -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 1xZALE-0008Dr-LR for qemu-devel@nongnu.org; Thu, 03 Dec 2026 12:11:36 -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 1xZALC-0006iv-SS for qemu-devel@nongnu.org; Thu, 03 Dec 2026 12:11:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796317890; 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=oQgfpjjwkU3YkwKo29fK9ZCetHrrrO0vWk2EQgI1/Rk=; b=KO03z7Mh1fuEIMpY6AVe3K+WkpgDUqctBW0d8fqVGuh6zRQp13cckhz5pbOguC5GAmrfCD BOpR9nmYqq3WuRBra1TnS2qt/Yfxn+cU1PuLKSow31x5KyN2JrcOjIlG4ZT3FXHokxgWtK CM1D92N7dJz/Bm3dCmFZHB3EJ7BmTbc= 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-93-AMdDbpabNda5NCHghcP9xA-1; Thu, 3 Dec 2026 17:11:24 +0000 X-MC-Unique: AMdDbpabNda5NCHghcP9xA-1 X-Mimecast-MFC-AGG-ID: AMdDbpabNda5NCHghcP9xA_1796317883 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 D568618AA947; Thu, 3 Dec 2026 17:11:22 +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 02D6A1955F7D; Thu, 3 Dec 2026 17:11:18 +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 12/20] target/arm/cpu64: Introduce arm_cpu_apply_sysreg_props Date: Thu, 3 Dec 2026 18:09:01 +0100 Message-ID: <20261203171020.2594683-13-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 This helper walks through all SYSREG field values stored in the hash table and apply them on the vcpu. It uses an accelerator specific callback to apply the field value on the vcpu. If the value is successfully applied, the cpu->isar.idregs[] value is updated accordingly. Note this updated value is the one actually read from the vcpu after the override. This may differ from the value originally set, depending on the hypervisor layer. Signed-off-by: Eric Auger Suggested-by: Khushit Shah --- target/arm/cpu-idregs.h | 20 ++++++++++++++ target/arm/cpu64.c | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/target/arm/cpu-idregs.h b/target/arm/cpu-idregs.h index e0399e251b..ed1883b7fa 100644 --- a/target/arm/cpu-idregs.h +++ b/target/arm/cpu-idregs.h @@ -38,4 +38,24 @@ typedef struct ARM64SysReg { */ extern ARM64SysReg arm64_id_regs[NUM_ID_IDX]; +/* accelerator specific callback used to set a new idreg field value on a vcpu */ +typedef int (*ARMSysregPropApplyFn)(ARMCPU *cpu, ARM64SysRegField *field, + uint64_t newfv, uint64_t *appliedfv, + Error **errp); + +/** + * arm_cpu_apply_sysreg_props: + * + * Apply all SYSREG prop values + * @cpu: vcpu on which the values are applied + * @accel_set_idreg_field_fn: acceleration specific callback used to set + * an idreg field value + * @errp: error handle + * + * return 0 on sucess or negative value with errp set on failure + */ +int arm_cpu_apply_sysreg_props(ARMCPU *cpu, + ARMSysregPropApplyFn accel_set_idreg_field_fn, + Error **errp); + #endif diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index d53bd8f3ec..38964e5341 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -817,6 +817,65 @@ static void kvm_arm_set_cpreg_mig_tolerances(ARMCPU *cpu) #define IDREG_FIELD_KEY(reg_idx, field_shift) \ (((uint64_t)(reg_idx) << 8) | ((uint64_t)(field_shift) & 0xFF)) +#define IDREG_FIELD_KEY_TO_REG_IDX(key) \ + ((uint32_t)(((uint64_t)(key)) >> 8)) +#define IDREG_FIELD_KEY_TO_SHIFT(key) \ + ((uint8_t)(((uint64_t)(key)) & 0xFF)) + +static ARM64SysRegField *arm_sysreg_get_field(ARM64SysReg *reg, int bit) +{ + for (int f = 0; f < reg->fields_count; f++) { + ARM64SysRegField *field = ®->fields[f]; + int upper = field->shift + field->length - 1; + + if (bit >= field->shift && bit <= upper) { + return field; + } + } + return NULL; +} + +/** + * arm_cpu_apply_sysreg_props: + * + * Iterate over all SYSREG_* property overrides, and apply them on the vcpu + * using the accelerator specific @accel_set_idreg_field_fn callback. + */ +int arm_cpu_apply_sysreg_props(ARMCPU *cpu, + ARMSysregPropApplyFn accel_set_idreg_field_fn, + Error **errp) +{ + gpointer key_ptr, value_ptr; + GHashTableIter iter; + uint64_t appliedfv; + + g_hash_table_iter_init(&iter, cpu->sysreg_props); + + while (g_hash_table_iter_next(&iter, &key_ptr, &value_ptr)) { + uint64_t key = (uint64_t)key_ptr; + uint64_t newfv = (uint64_t)value_ptr; + uint32_t reg_idx = IDREG_FIELD_KEY_TO_REG_IDX(key); + uint8_t lower = IDREG_FIELD_KEY_TO_SHIFT(key); + ARM64SysReg *reg = &arm64_id_regs[reg_idx]; + ARM64SysRegField *field = arm_sysreg_get_field(reg, lower); + int ret; + + if (!field) { + error_setg(errp, "SYSREG property key 0x%" PRIx64 + " does not match any field of %s", key, reg->name); + return -EINVAL; + } + + ret = accel_set_idreg_field_fn(cpu, field, newfv, &appliedfv, errp); + if (ret) { + return ret; + } + cpu->isar.idregs[field->index] = + deposit64(cpu->isar.idregs[field->index], + field->shift, field->length, appliedfv); + } + return 0; +} static void set_sysreg_prop(Object *obj, Visitor *v, const char *name, void *opaque, -- 2.56.1