From nobody Fri Nov 14 20:43:45 2025 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1760473256; cv=none; d=zohomail.com; s=zohoarc; b=gZQsqkrzvVKh0s4hYbv5jaLUzHHkecXFy2a4HWG2s1TtT/pe6yzSGJtAizLhL+nebQcy285JoQ32PwWmtyDG0Ov4FZxF5TXBYGGHC7IevtHrWLHOIhuq3v0mZDeXO/BTDxxzo0Rh3yUOd95LQ/9cBQ243XFNKomVqtoZGrvPLW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760473256; h=Content-Transfer-Encoding:Cc:Cc: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; bh=/5btMPkNJDkRLOMsyDK95md6xOaMjB+VfIt/mT/S7SM=; b=aQMzaw1YTOhwRBOL4PCjW7+N7G8HuRdHIlFnT7y3mDBCa51E+e1iYOuLH1TQWEAPqlCdynYAwfdObYHJqWyu+4edDt+YiD52VS8gmxlCUw9PPMvIh1jVvlzw62FmCs5B3zRBrQ2BG8NkZDFTLcU5IpBr9pFCb3BOvKBRtv/bHa8= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760473256450943.648163214082; Tue, 14 Oct 2025 13:20:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v8lJt-0002Vi-Oh; Tue, 14 Oct 2025 16:08:29 -0400 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 1v8lJX-0002IS-GI for qemu-devel@nongnu.org; Tue, 14 Oct 2025 16:08:13 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v8lIy-0005LW-4O for qemu-devel@nongnu.org; Tue, 14 Oct 2025 16:08:06 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-28832ad6f64so64880365ad.1 for ; Tue, 14 Oct 2025 13:07:30 -0700 (PDT) Received: from stoup.. ([71.212.157.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29034f93ea2sm172100975ad.126.2025.10.14.13.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Oct 2025 13:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1760472448; x=1761077248; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/5btMPkNJDkRLOMsyDK95md6xOaMjB+VfIt/mT/S7SM=; b=VOgNbad4f/ALi6Y5YFy96wYYKo7MgBRd7hbhU7BVZ6voVcu/MF8ZojTUzzWN3Jwe/9 D9su6d5oNEejJubClI7AzAmBsQDzLP+QcWvg/XUPDZ6BAEm5HTgyFs5upnxMp1n31yw3 5khGftQIvuSDycWYLmz4s20pzhNS4/mTPQQ8gOkY2FpQN59xsR6MK5pL8izWj34WDQbq OA94mfnt0GXhKPDglxMhuEG1Gxi1qYazzQKqIckanh5CC828eGZNj9n8lCerfXfLhG3n B6IKPdnjwOWvVOQXXwZI3M0GEGaObwuIcmxSokdsoH2D19aH5yxR/Y4QaZna4Od8Idod IMOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760472448; x=1761077248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/5btMPkNJDkRLOMsyDK95md6xOaMjB+VfIt/mT/S7SM=; b=wHwEEKn56hy7uFMNiCWeLkEzJYYbBu0RO4UV/ISAL+rHrSg8S76qZNIMYZbl8ljfYC yxWXrJtqC7hF9I0pShCCmnj0a7M3NJek9nTtzBA97BP0nUZ/auz4opcbf6j3KR+6nXlW VWCinBk300MHsl142doXM3h4A7BqnM8K720XFWCIwa0rWTuAgAkIQbJ8tyM6gpqPhfAi Q7L88iC/tdLcYt1M8PDH4I5W0uyeS4bCY3rLlZaHDycs8n81TjHkQRITHCqhp2gJwjf1 Cn/chw/y8Eap53ezhiLRVNktLBr6UiEr8ozjL4X3AlKBM+KGHsire0TUmQamThhWGiL6 tMQA== X-Gm-Message-State: AOJu0Yw7JuXrW/5spdSV7K+ufPJUwwvy0GPS6502pj3/iCE8CcjGIBkP WxI9rqZDT2XJ/IqP3bSu4JqGJKhBTaFIN+VaYKij5lYw3f24K9CBKdEzdA/sIxiMH+s4cIQZiVk seZXebQ4= X-Gm-Gg: ASbGncvrKAlRlOtYdjR/HpH4T3YXG2cL8IjfaTaItb42NCZqQvx5YdFWNlIRqiDhFAA /zfOGLcL3seATeZprwk7b0WCv6tDTEOjTUgDR8fEeLMrOyBdWPSj37XDFOUHKdmlzPhXzZ/fVUi 3yS/IhnU/pAw87rK2XU3E73Xim/4pfuJpPOYdOw1uIMYNvC5Oq2vvmJqWDGNUFNYX9EIHPnWH0S CgxZyWj7SfhemFeefsx3u9bks0txOFJ/xDVVn7C0Ki/JGKbjNl4KbsC0D26iNAQ3iT+N8s8FqKe WNLuJqYjaX3Njb0nZnpxUW3uHYI8mjtKGqDu7NtEx1xebQ0M4kMRU1tki3UnYdNaAPUgkWI2ibD 39Y1rna0LFs2geoZRhjh+J8n9+/lQqLKp4gHYOoOWcGuVxrSjd3s= X-Google-Smtp-Source: AGHT+IEY/yq2MXLBnNiJVS+zsoolOlLuGEATos/veulfUZhThjphSNKNH627vQjUU+Kbztgd7sZSsA== X-Received: by 2002:a17:903:19e8:b0:28e:ccd7:dd61 with SMTP id d9443c01a7336-29027305380mr313511235ad.57.1760472447532; Tue, 14 Oct 2025 13:07:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 12/37] target/arm: Put 128-bit sysregs into a separate list Date: Tue, 14 Oct 2025 13:06:53 -0700 Message-ID: <20251014200718.422022-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251014200718.422022-1-richard.henderson@linaro.org> References: <20251014200718.422022-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @linaro.org) X-ZM-MESSAGEID: 1760473257448158500 Content-Type: text/plain; charset="utf-8" Duplicate the cpreg_{indexes,values,array_len} array as cpreg128_{indexes,values,array_len}. Similarly for cpreg_vmstate_{indexes,values,array_len}. Split the values between the two arrays during write_cpustate_to_list, write_list_to_cpustate, count_cpreg, and add_cpreg_to_list. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/cpu.h | 19 +++++-- target/arm/helper.c | 125 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 116 insertions(+), 28 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index e21612b898..a030539488 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -918,25 +918,36 @@ struct ArchCPU { =20 /* Coprocessor information */ GHashTable *cp_regs; - /* For marshalling (mostly coprocessor) register state between the + /* + * For marshalling (mostly coprocessor) register state between the * kernel and QEMU (for KVM) and between two QEMUs (for migration), * we use these arrays. */ - /* List of register indexes managed via these arrays; (full KVM style - * 64 bit indexes, not CPRegInfo 32 bit indexes) + /* + * List of register indexes managed via these arrays (full KVM style + * 64 bit indexes, not CPRegInfo 32 bit indexes). The registers are + * segregated by size, with 64-bit registers in cpreg_indexes and + * 128-bit registers in cpreg128_indexes. */ uint64_t *cpreg_indexes; + uint64_t *cpreg128_indexes; /* Values of the registers (cpreg_indexes[i]'s value is cpreg_values[i= ]) */ uint64_t *cpreg_values; + Int128 *cpreg128_values; /* Length of the indexes, values, reset_values arrays */ int32_t cpreg_array_len; - /* These are used only for migration: incoming data arrives in + int32_t cpreg128_array_len; + /* + * These are used only for migration: incoming data arrives in * these fields and is sanity checked in post_load before copying * to the working data structures above. */ uint64_t *cpreg_vmstate_indexes; + uint64_t *cpreg128_vmstate_indexes; uint64_t *cpreg_vmstate_values; + Int128 *cpreg128_vmstate_values; int32_t cpreg_vmstate_array_len; + int32_t cpreg128_vmstate_array_len; =20 DynamicGDBFeatureInfo dyn_sysreg_feature; DynamicGDBFeatureInfo dyn_svereg_feature; diff --git a/target/arm/helper.c b/target/arm/helper.c index d9d8ae56e8..d3a425e259 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -217,10 +217,11 @@ static bool raw_accessors_invalid(const ARMCPRegInfo = *ri) bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync) { /* Write the coprocessor state from cpu->env to the (index,value) list= . */ - int i; + int i, n; bool ok =3D true; =20 - for (i =3D 0; i < cpu->cpreg_array_len; i++) { + n =3D cpu->cpreg_array_len; + for (i =3D 0; i < n; i++) { uint32_t regidx =3D kvm_to_cpreg_id(cpu->cpreg_indexes[i]); const ARMCPRegInfo *ri; uint64_t newval; @@ -230,6 +231,10 @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync) ok =3D false; continue; } + if (ri->type & ARM_CP_128BIT) { + ok =3D false; + continue; + } if (ri->type & ARM_CP_NO_RAW) { continue; } @@ -257,35 +262,77 @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_syn= c) } cpu->cpreg_values[i] =3D newval; } - return ok; -} =20 -bool write_list_to_cpustate(ARMCPU *cpu) -{ - int i; - bool ok =3D true; + n =3D cpu->cpreg128_array_len; + if (n =3D=3D 0) { + return ok; + } + assert(!kvm_sync); =20 - for (i =3D 0; i < cpu->cpreg_array_len; i++) { - uint32_t regidx =3D kvm_to_cpreg_id(cpu->cpreg_indexes[i]); - uint64_t v =3D cpu->cpreg_values[i]; - const ARMCPRegInfo *ri; + for (i =3D 0; i < n; i++) { + uint32_t regidx =3D kvm_to_cpreg_id(cpu->cpreg128_indexes[i]); + const ARMCPRegInfo *ri =3D get_arm_cp_reginfo(cpu->cp_regs, regidx= ); =20 - ri =3D get_arm_cp_reginfo(cpu->cp_regs, regidx); if (!ri) { ok =3D false; continue; } + if (!(ri->type & ARM_CP_128BIT)) { + ok =3D false; + continue; + } if (ri->type & ARM_CP_NO_RAW) { continue; } - /* - * Write value and confirm it reads back as written - * (to catch read-only registers and partially read-only - * registers where the incoming migration value doesn't match) - */ - write_raw_cp_reg(&cpu->env, ri, v); - if (read_raw_cp_reg(&cpu->env, ri) !=3D v) { + + cpu->cpreg128_values[i] =3D read_raw_cp_reg128(&cpu->env, ri); + } + return ok; +} + +bool write_list_to_cpustate(ARMCPU *cpu) +{ + int i, n; + bool ok =3D true; + + n =3D cpu->cpreg_array_len; + for (i =3D 0; i < n; i++) { + uint32_t regidx =3D kvm_to_cpreg_id(cpu->cpreg_indexes[i]); + const ARMCPRegInfo *ri =3D get_arm_cp_reginfo(cpu->cp_regs, regidx= ); + + if (!ri) { ok =3D false; + } else if (ri->type & ARM_CP_128BIT) { + ok =3D false; + } else if (!(ri->type & ARM_CP_NO_RAW)) { + /* + * Write value and confirm it reads back as written + * (to catch read-only registers and partially read-only + * registers where the incoming migration value doesn't match) + */ + uint64_t v =3D cpu->cpreg_values[i]; + write_raw_cp_reg(&cpu->env, ri, v); + if (read_raw_cp_reg(&cpu->env, ri) !=3D v) { + ok =3D false; + } + } + } + + n =3D cpu->cpreg128_array_len; + for (i =3D 0; i < n; i++) { + uint32_t regidx =3D kvm_to_cpreg_id(cpu->cpreg128_indexes[i]); + const ARMCPRegInfo *ri =3D get_arm_cp_reginfo(cpu->cp_regs, regidx= ); + + if (!ri) { + ok =3D false; + } else if (!(ri->type & ARM_CP_128BIT)) { + ok =3D false; + } else if (!(ri->type & ARM_CP_NO_RAW)) { + Int128 v =3D cpu->cpreg128_values[i]; + write_raw_cp_reg128(&cpu->env, ri, v); + if (int128_ne(read_raw_cp_reg128(&cpu->env, ri), v)) { + ok =3D false; + } } } return ok; @@ -298,9 +345,14 @@ static void add_cpreg_to_list(gpointer key, gpointer v= alue, gpointer opaque) const ARMCPRegInfo *ri =3D value; =20 if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_ALIAS))) { - cpu->cpreg_indexes[cpu->cpreg_array_len] =3D cpreg_to_kvm_id(regid= x); + uint64_t idx =3D cpreg_to_kvm_id(regidx); + /* The value array need not be initialized at this point */ - cpu->cpreg_array_len++; + if (ri->type & ARM_CP_128BIT) { + cpu->cpreg128_indexes[cpu->cpreg128_array_len++] =3D idx; + } else { + cpu->cpreg_indexes[cpu->cpreg_array_len++] =3D idx; + } } } =20 @@ -310,7 +362,11 @@ static void count_cpreg(gpointer key, gpointer value, = gpointer opaque) const ARMCPRegInfo *ri =3D value; =20 if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_ALIAS))) { - cpu->cpreg_array_len++; + if (ri->type & ARM_CP_128BIT) { + cpu->cpreg128_array_len++; + } else { + cpu->cpreg_array_len++; + } } } =20 @@ -320,9 +376,10 @@ void init_cpreg_list(ARMCPU *cpu) * Initialise the cpreg_tuples[] array based on the cp_regs hash. * Note that we require cpreg_tuples[] to be sorted by key ID. */ - int arraylen; + int arraylen, array128len; =20 cpu->cpreg_array_len =3D 0; + cpu->cpreg128_array_len =3D 0; g_hash_table_foreach(cpu->cp_regs, count_cpreg, cpu); =20 arraylen =3D cpu->cpreg_array_len; @@ -340,13 +397,33 @@ void init_cpreg_list(ARMCPU *cpu) cpu->cpreg_vmstate_array_len =3D arraylen; cpu->cpreg_array_len =3D 0; =20 + array128len =3D cpu->cpreg128_array_len; + if (array128len) { + cpu->cpreg128_indexes =3D g_new(uint64_t, array128len); + cpu->cpreg128_values =3D g_new(Int128, array128len); + cpu->cpreg128_vmstate_indexes =3D g_new(uint64_t, array128len); + cpu->cpreg128_vmstate_values =3D g_new(Int128, array128len); + } else { + cpu->cpreg128_indexes =3D NULL; + cpu->cpreg128_values =3D NULL; + cpu->cpreg128_vmstate_indexes =3D NULL; + cpu->cpreg128_vmstate_values =3D NULL; + } + cpu->cpreg128_vmstate_array_len =3D array128len; + cpu->cpreg128_array_len =3D 0; + g_hash_table_foreach(cpu->cp_regs, add_cpreg_to_list, cpu); =20 assert(cpu->cpreg_array_len =3D=3D arraylen); + assert(cpu->cpreg128_array_len =3D=3D array128len); =20 if (arraylen) { qsort(cpu->cpreg_indexes, arraylen, sizeof(uint64_t), compare_u64); } + if (array128len) { + qsort(cpu->cpreg128_indexes, array128len, + sizeof(uint64_t), compare_u64); + } } =20 bool arm_pan_enabled(CPUARMState *env) --=20 2.43.0