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 D9FF3606A32C for ; Thu, 3 Dec 2026 17:12:48 +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=NCEmtCep Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZAM8-0000oC-56; Thu, 03 Dec 2026 12:12:30 -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 1xZALA-0008C4-28 for qemu-devel@nongnu.org; Thu, 03 Dec 2026 12:11:31 -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 1xZAL5-0006hA-DG for qemu-devel@nongnu.org; Thu, 03 Dec 2026 12:11:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796317883; 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=wOJUN4piCK7EB8QkM1DiPj1uiFGD+iq5U4afiSlOtbM=; b=NCEmtCepvvZeed79aOPKoUiZjh8Kpbx4Ot9/bAiA0fMjWWHyGgHH2lyfTuzBXHlisSUCNp jnGxuJST2FVIAVriU1EFKzVMI8cggutHp4NFlaENE8sG3JK7FD4jJUJkRg2HXjlFBniEy3 FtzBL5dtB4PJslXhLps9JDIjuq1ph/k= Received: from mx-prod-mc-03.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-463--8qSLvgVNH6heW4kfu7mrQ-1; Thu, 3 Dec 2026 17:11:19 +0000 X-MC-Unique: -8qSLvgVNH6heW4kfu7mrQ-1 X-Mimecast-MFC-AGG-ID: -8qSLvgVNH6heW4kfu7mrQ_1796317877 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 664C3188FE5D; Thu, 3 Dec 2026 17:11:11 +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 03D11195605B; Thu, 3 Dec 2026 17:11:07 +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 09/20] arm/kvm: Sync isar.idregs[] with all writable host ID regs on vcpu init Date: Thu, 3 Dec 2026 18:08:58 +0100 Message-ID: <20261203171020.2594683-10-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 Introduce a new helper that reads the values of all writable ID registers from a KVM vcpu and write them in their corresponding cpu->isar.idregs[] storage. The function is called once the cpu has been initialized. This will partially overwrite the values collected for a subset of them on kvm_arm_get_host_cpu_features() on the scratch "max" vcpu. Signed-off-by: Eric Auger Signed-off-by: Cornelia Huck --- v10 -> v11: - rename the function and call it on vcpu init instead of on kvm_arm_get_host_cpu_features() v9 -> v10: - get rid of spurious kvm_arm_writable_idregs_to_cpreg_list trace point - add a writable parameter to get_host_cpu_idregs - some code cleanup v8 -> v9: - improve the commit msg. Only initialize in this patch and move the write back to cpreg value list in a different patch. - Do not hack CLIDR here. The correct way to fix that temporarily is to do that in the machine instead. v7 -> v8 - fix indent and added Khushit's R-b v6 -> v7 - remove vcpu from prototypes (Khushit) v5 -> v6 - do not check writable_map anymore --- target/arm/kvm.c | 42 +++++++++++++++++++++++++++++++++++++++++ target/arm/trace-events | 1 + 2 files changed, 43 insertions(+) diff --git a/target/arm/kvm.c b/target/arm/kvm.c index af8b96f91d..762c384cce 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -44,6 +44,7 @@ #include "hw/acpi/ghes.h" #include "target/arm/gtimer.h" #include "migration/blocker.h" +#include "cpu-idregs.h" const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_INFO(DEVICE_CTRL), @@ -338,6 +339,41 @@ static int kvm_feature_idx_to_idregs_idx(int kidx) return get_sysreg_idx(sysreg); } +/* + * sync_vcpu_idregs_from_kvm: Read all writable ID register values + * from KVM vcpu and populate @vcpu->isar.idregs[] with those values + * + * Need to be called once the writable mask has been populated + * + * @cpu: vcpu + */ +static int sync_vcpu_idregs_from_kvm(ARMCPU *cpu) +{ + int fd = CPU(cpu)->kvm_fd; + + for (int i = 0; i < NUM_ID_IDX; i++) { + ARM64SysReg *sysregdesc = &arm64_id_regs[i]; + ARMSysRegs sysreg = id_register_sysreg[i]; + uint64_t *reg; + int ret; + + if (!sysregdesc->writable_mask) { + continue; + } + + reg = &cpu->isar.idregs[i]; + ret = read_sys_reg64(fd, reg, idregs_sysreg_to_kvm_reg(sysreg)); + if (ret) { + error_report("%s error reading value of host %s register (%m)", + __func__, sysregdesc->name); + + return ret; + } + trace_get_host_cpu_idregs(sysregdesc->name, *reg); + } + return 0; +} + /** * kvm_arm_get_host_cpu_features: * @ahcf: host CPU feature struct to populate @@ -2198,6 +2234,12 @@ int kvm_arch_init_vcpu(CPUState *cs, Error **errp) SET_IDREG(&cpu->isar, MPIDR, mpidr); cpu->mp_affinity = mpidr & ARM64_AFFINITY_MASK; + ret = sync_vcpu_idregs_from_kvm(cpu); + if (ret) { + error_setg(errp, "failed to sync ID registers"); + return ret; + } + return kvm_arm_init_cpreg_list(cpu, errp); } diff --git a/target/arm/trace-events b/target/arm/trace-events index 8502fb3265..8c7faf57c7 100644 --- a/target/arm/trace-events +++ b/target/arm/trace-events @@ -13,6 +13,7 @@ arm_gt_update_irq(int timer, int irqstate) "gt_update_irq: timer %d irqstate %d" # kvm.c kvm_arm_fixup_msi_route(uint64_t iova, uint64_t gpa) "MSI iova = 0x%"PRIx64" is translated into 0x%"PRIx64 +get_host_cpu_idregs(const char *name, uint64_t value) "scratch vcpu host value for %s is 0x%"PRIx64 # cpu.c arm_cpu_reset(uint64_t mp_aff) "cpu %" PRIu64 -- 2.56.1