From nobody Sun Apr 12 00:55:10 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772447912; cv=none; d=zohomail.com; s=zohoarc; b=Zw1qdunBAe2XVQa37jLLLzfTM8eeENALfVt4BLE7v/ExVqBed9mbN3mJVvJrZtOA0AwhprP7W4SCSQKA66M+9QcL5d6rCxQrttWtlv36qUIG+0wuMua6t9cm5YnHJjvUqB4gAVjDyvM8PjLKj+KP4frqUqfsxzBaE/4gcOysvb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772447912; h=Content-Transfer-Encoding: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:Cc; bh=bo/UriJHsBloEjShz/XFZtX2zVln7mAsy/2g8XzXh1M=; b=JYFLrJbQuW33g58lsXypb6w01bfQoKcioiaGidUEVaAacHYeDci1y1n2MkWplox4YXj8F1blrGtgSgoojrmK6TURCISyO8fGAGTg2Z9feBiJT/f3HA4egooe4upcKUE+gsENlOTWy+eglN9T8AlFgoJz8l7Ig057HPFBzhsg+kQ= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772447912848645.9184248595641; Mon, 2 Mar 2026 02:38:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vx0eA-0002zn-O1; Mon, 02 Mar 2026 05:37:07 -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 1vx0e7-0002yL-GQ for qemu-devel@nongnu.org; Mon, 02 Mar 2026 05:37:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vx0e5-0001qv-Su for qemu-devel@nongnu.org; Mon, 02 Mar 2026 05:37:03 -0500 Received: from mx-prod-mc-01.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-354-C7q5wqodMyOKARmtj8RB8w-1; Mon, 02 Mar 2026 05:36:55 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AC0A41956050; Mon, 2 Mar 2026 10:36:54 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.44.32.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9DEEF180066A; Mon, 2 Mar 2026 10:36:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772447820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bo/UriJHsBloEjShz/XFZtX2zVln7mAsy/2g8XzXh1M=; b=Dg09XsVnKnJ9BmiHbAMWw0MbASl7smYGlIOYWTBrxrDYEtMzKVVMzL6AM1odOTUyUnDDUN zYqekZO72nTr2FY1l2OK0MICZTfLHybsSY+yPRkov3z53bxU3dDhJxap4qy0fe4coQen6g h3sUq3lLTrQdNFO3rBpfSEvVCdyvAMU= X-MC-Unique: C7q5wqodMyOKARmtj8RB8w-1 X-Mimecast-MFC-AGG-ID: C7q5wqodMyOKARmtj8RB8w_1772447814 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, cohuck@redhat.com, sebott@redhat.com, peterx@redhat.com, philmd@linaro.org, alex.bennee@linaro.org Subject: [PATCH v7 2/7] target/arm/cpu: Introduce the infrastructure for cpreg migration tolerances Date: Mon, 2 Mar 2026 11:35:24 +0100 Message-ID: <20260302103640.1362564-3-eric.auger@redhat.com> In-Reply-To: <20260302103640.1362564-1-eric.auger@redhat.com> References: <20260302103640.1362564-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=170.10.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.012, RCVD_IN_VALIDITY_RPBL_BLOCKED=1.188, 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-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 @redhat.com) X-ZM-MESSAGEID: 1772447914767158500 Content-Type: text/plain; charset="utf-8" We introduce a datatype for a tolerance with respect to a given cpreg migration issue. The tolerance applies to a given cpreg kvm index, and can be of different types: - ToleranceNotOnBothEnds (cpreg index is allowed to be only on one end) - ToleranceDiffInMask (value differences are allowed only within a mask) - ToleranceFieldLT (incoming field value must be less than a given value) - ToleranceFieldGT (incoming field value must be greater than a given value) A QLIST of such tolerances can be populated using a new helper: arm_register_cpreg_mig_tolerance() and arm_cpu_cpreg_has_mig_tolerance() allows to check whether a tolerance exists for a given kvm index. callers for those helpers will be introduced in subsequent patches. Signed-off-by: Eric Auger --- target/arm/cpu.h | 32 +++++++++++++++++++++ target/arm/cpu.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 657ff4ab20b..9dcc838f611 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -843,6 +843,21 @@ struct ARMELChangeHook { QLIST_ENTRY(ARMELChangeHook) node; }; =20 +typedef enum { + ToleranceNotOnBothEnds, + ToleranceDiffInMask, + ToleranceFieldLT, + ToleranceFieldGT, +} ARMCPUCPREGMigToleranceType; + +typedef struct ARMCPUCPREGMigTolerance { + uint64_t kvmidx; + uint64_t mask; + uint64_t value; + ARMCPUCPREGMigToleranceType type; + QLIST_ENTRY(ARMCPUCPREGMigTolerance) node; +} ARMCPUCPREGMigTolerance; + /* These values map onto the return values for * QEMU_PSCI_0_2_FN_AFFINITY_INFO */ typedef enum ARMPSCIState { @@ -1139,6 +1154,7 @@ struct ArchCPU { =20 QLIST_HEAD(, ARMELChangeHook) pre_el_change_hooks; QLIST_HEAD(, ARMELChangeHook) el_change_hooks; + QLIST_HEAD(, ARMCPUCPREGMigTolerance) cpreg_mig_tolerances; =20 int32_t node_id; /* NUMA node this CPU belongs to */ =20 @@ -2632,6 +2648,22 @@ void arm_register_pre_el_change_hook(ARMCPU *cpu, AR= MELChangeHookFn *hook, void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook, void *opaque); =20 +/** + * arm_register_cpreg_mig_tolerance: + * Register a migration tolerance wrt one given cpreg identified by its + * @kvmidx. Only one tolerance can be registered by kvm reg idx. + */ +void arm_register_cpreg_mig_tolerance(ARMCPU *cpu, uint64_t kvmidx, + uint64_t mask, uint64_t value, + ARMCPUCPREGMigToleranceType type); + +/** + * arm_cpu_cpreg_has_mig_tolerance: + * Check whether a tolerance of type @type exists for a given @kvmidx + */ +bool arm_cpu_cpreg_has_mig_tolerance(ARMCPU *cpu, uint64_t kvmidx, + uint64_t vmstate_value, uint64_t loca= l_value, + ARMCPUCPREGMigToleranceType type); /** * arm_rebuild_hflags: * Rebuild the cached TBFLAGS for arbitrary changed processor state. diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 10f8280eef2..167f78cee13 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -181,6 +181,75 @@ void arm_register_el_change_hook(ARMCPU *cpu, ARMELCha= ngeHookFn *hook, QLIST_INSERT_HEAD(&cpu->el_change_hooks, entry, node); } =20 +void arm_register_cpreg_mig_tolerance(ARMCPU *cpu, uint64_t kvmidx, + uint64_t mask, uint64_t value, + ARMCPUCPREGMigToleranceType type) +{ + ARMCPUCPREGMigTolerance *t, *entry; + + /* make sure the kvmidx has not tolerance already registered */ + QLIST_FOREACH(t, &cpu->cpreg_mig_tolerances, node) { + if (t->kvmidx =3D=3D kvmidx) { + g_assert_not_reached(); + } + } + entry =3D g_new0(ARMCPUCPREGMigTolerance, 1); + + entry->kvmidx =3D kvmidx; + entry->mask =3D mask; + entry->value =3D value; + entry->type =3D type; + + QLIST_INSERT_HEAD(&cpu->cpreg_mig_tolerances, entry, node); +} + +bool arm_cpu_cpreg_has_mig_tolerance(ARMCPU *cpu, uint64_t kvmidx, + uint64_t vmstate_value, uint64_t loca= l_value, + ARMCPUCPREGMigToleranceType type) +{ + ARMCPUCPREGMigTolerance *t; + uint64_t diff, diff_outside_mask, field; + bool found =3D false; + + QLIST_FOREACH(t, &cpu->cpreg_mig_tolerances, node) { + if (t->kvmidx =3D=3D kvmidx) { + found =3D true; + break; + } + } + if (!found) { + return false; + } + + /* we found one tolerance associated to the @kvmidx */ + + if (type =3D=3D ToleranceNotOnBothEnds) { + return true; + } + + /* Need to check mask */ + diff =3D vmstate_value ^ local_value; + diff_outside_mask =3D diff & ~t->mask; + + if (diff_outside_mask) { + /* there are differences outside of the mask */ + return false; + } + if (type =3D=3D ToleranceDiffInMask) { + /* differences only in the field, tolerance granted */ + return true; + } + /* need to compare field value against authorized ones */ + field =3D vmstate_value & t->mask; + if (type =3D=3D ToleranceFieldLT && (field < t->value)) { + return true; + } + if (type =3D=3D ToleranceFieldGT && (field > t->value)) { + return true; + } + return false; +} + static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque) { /* Reset a single ARMCPRegInfo register */ @@ -1106,6 +1175,7 @@ static void arm_cpu_initfn(Object *obj) =20 QLIST_INIT(&cpu->pre_el_change_hooks); QLIST_INIT(&cpu->el_change_hooks); + QLIST_INIT(&cpu->cpreg_mig_tolerances); =20 #ifdef CONFIG_USER_ONLY # ifdef TARGET_AARCH64 @@ -1548,6 +1618,7 @@ static void arm_cpu_finalizefn(Object *obj) { ARMCPU *cpu =3D ARM_CPU(obj); ARMELChangeHook *hook, *next; + ARMCPUCPREGMigTolerance *t, *n; =20 g_hash_table_destroy(cpu->cp_regs); =20 @@ -1559,6 +1630,10 @@ static void arm_cpu_finalizefn(Object *obj) QLIST_REMOVE(hook, node); g_free(hook); } + QLIST_FOREACH_SAFE(t, &cpu->cpreg_mig_tolerances, node, n) { + QLIST_REMOVE(t, node); + g_free(t); + } #ifndef CONFIG_USER_ONLY if (cpu->pmu_timer) { timer_free(cpu->pmu_timer); --=20 2.53.0