Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5211C348C5B for ; Tue, 19 May 2026 13:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779197470; cv=none; b=DNNwu8W0fhJJmiFzeZiC0s8V+/2xoaW9ekbO6V8lWhoLxtwR/7dQobY6z8aTrfw7eH8Q5tR03idTJx4I3yNvLrSKEG5F8FqhmyR+160z3VHFbMXKDbT2WS4oLYr4j2ud0jjsS6ywjPPuwarCDMecBp29ZyGcMfWHuytOF0cmAlI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779197470; c=relaxed/simple; bh=EM38d8mgljuL3PGLmrZI9WmIZsHlGQwJh7WC8lWx0js=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=L3AIwkr5z93idic8NZlhavKL49v3aDZzBkaOVrvLzZPqFmlM2CH/tAn2yQL+h7yA1Rvv4VAjlt1tEHuyuPnumZHAeCgKQ9iPgRdrWpAylaKRCL/TYfsbs2/I6oVi6QhHjIcS+jpqbJgPjyqsPmFwd3bLbx/Vca1pONBsgyeALE0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GcKzmcVH; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GcKzmcVH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779197468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AqN7LyQkpVzsmK2HDdemrDuDRczsABmmtqsqw6bIJnM=; b=GcKzmcVHuw76a0q62ZVSpJ7vQanusAUl+Zl8iElHACLfzTRYQVarblxWDd13B+f1XEHsdG y8rlSVTH4vbo5Cc45ZMKdtaIuOfumPgV5itXZaof9PCMzzuGq0GRM7NPCdzWYufRlFN6O8 bbWZJsuoBbvFPPRrmM3+rq2ccLOLXKc= 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-96-1otgUIMGMAW_t3_jJjq3pQ-1; Tue, 19 May 2026 09:31:03 -0400 X-MC-Unique: 1otgUIMGMAW_t3_jJjq3pQ-1 X-Mimecast-MFC-AGG-ID: 1otgUIMGMAW_t3_jJjq3pQ_1779197460 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 BDA3919560B3; Tue, 19 May 2026 13:31:00 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.44.49.207]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 12A02180034E; Tue, 19 May 2026 13:30:54 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, kvmarm@lists.linux.dev, peter.maydell@linaro.org, shaju.abraham@nutanix.com, khushit.shah@nutanix.com, yangjinqian1@huawei.com, cohuck@redhat.com, richard.henderson@linaro.org, sebott@redhat.com, skolothumtho@nvidia.com, philmd@linaro.org Cc: maz@kernel.org, oliver.upton@linux.dev, pbonzini@redhat.com, armbru@redhat.com, berrange@redhat.com, abologna@redhat.com, jdenemar@redhat.com Subject: [PATCH v5 16/18] target/arm/cpu: Expose writable ID reg field properties on the kvm host vcpu model Date: Tue, 19 May 2026 15:27:30 +0200 Message-ID: <20260519132905.145643-17-eric.auger@redhat.com> In-Reply-To: <20260519132905.145643-1-eric.auger@redhat.com> References: <20260519132905.145643-1-eric.auger@redhat.com> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-MFC-PROC-ID: VnqjvlHmoo1zLYXPftfA-s6gLOp_86-U8ZmU9H6l2mM_1779197460 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true If the host supports KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES and KVM_ARM_GET_REG_WRITABLE_MASKS ioctl successfully retrieved the mask of writable fields for all ID regs, expose uint64 SYSREG properties for all the writable ID reg fields exposed by the host kernel which can be matched in target/arm/cpu-idregs.h.inc. Properties are named SYSREG__ with REG and FIELD being those used ARCHMRS Registers.json. When such properties are set, they override the default field value retrieved from the host and reinjected into KVM. Then the actual value being applied at KVM depends on the register, ie. it can be sanitized. In case the field value is rejected by KVM, the vpcu init fails. Anyway there is a first attempt to write back this value into KVM. Then legacy CPU options (virtualization, secure, ...) can still override the previous value. So low level IDREG field properties apply before the legacy ones. An example of invocation is: -cpu host,SYSREG_ID_AA64MMFR0_EL1_ECV=0x0 which sets ECV field of ID_AA64MMFR0_EL1 to 0 (enhanced counter virtualization). Signed-off-by: Eric Auger Signed-off-by: Cornelia Huck --- v4 -> v5: - get rid of ret local variable, dynamically allocate and free writable_map here --- target/arm/cpu64.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index f2edbfc437..e0e1ff6cfb 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -37,6 +37,7 @@ #include "hw/core/qdev-properties.h" #include "internals.h" #include "cpu-features.h" +#include "cpu-idregs.h" /* convert between _IDX and SYS_ */ #define DEF(NAME, OP0, OP1, CRN, CRM, OP2) \ @@ -851,7 +852,6 @@ static void kvm_arm_set_cpreg_mig_tolerances(ARMCPU *cpu) static void aarch64_host_initfn(Object *obj) { ARMCPU *cpu = ARM_CPU(obj); - int ret; #if defined(CONFIG_NITRO) if (nitro_enabled()) { @@ -865,13 +865,18 @@ static void aarch64_host_initfn(Object *obj) cpu->writable_map = g_new(uint64_t, KVM_ARM_FEATURE_ID_RANGE_SIZE); - ret = kvm_arm_get_writable_id_regs(cpu->writable_map); - if (ret) { + if (kvm_arm_get_writable_id_regs(cpu->writable_map)) { g_free(cpu->writable_map); cpu->writable_map = NULL; } kvm_arm_set_cpu_features_from_host(cpu); aarch64_add_sve_properties(obj); + + if (cpu->writable_map) { + /* generate SYSREG properties according to writable masks */ + kvm_arm_expose_idreg_properties(cpu, arm64_id_regs); + } + #elif defined(CONFIG_HVF) hvf_arm_set_cpu_features_from_host(cpu); #elif defined(CONFIG_WHPX) -- 2.53.0