From nobody Sat Feb 7 05:37:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742024729666694.5612093223942; Sat, 15 Mar 2025 00:45:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ttMCG-0004vl-Of; Sat, 15 Mar 2025 03:44:43 -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 1ttMC9-0004eO-2n; Sat, 15 Mar 2025 03:44:33 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ttMC6-00050Q-4C; Sat, 15 Mar 2025 03:44:31 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id D3452FFB09; Sat, 15 Mar 2025 10:41:55 +0300 (MSK) Received: from gandalf.tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with ESMTP id C20791CACD3; Sat, 15 Mar 2025 10:42:49 +0300 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id 8A43F559FE; Sat, 15 Mar 2025 10:42:49 +0300 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Bibo Mao , Michael Tokarev Subject: [Stable-8.2.10 21/42] target/loongarch/gdbstub: Fix gdbstub incorrectly handling some registers Date: Sat, 15 Mar 2025 10:42:23 +0300 Message-Id: <20250315074249.634718-21-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: 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=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-ZM-MESSAGEID: 1742024731970019100 Content-Type: text/plain; charset="utf-8" From: Bibo Mao Write operation with R32 (orig_a0) and R34 (CSR_BADV) is discarded on gdbstub implementation for LoongArch system. And return value should be register size rather than 0, since it is used to calculate offset of next register such as R33 (PC) in function handle_write_all_regs(). Cc: qemu-stable@nongnu.org Fixes: ca61e75071c6 ("target/loongarch: Add gdb support.") Signed-off-by: Bibo Mao Reviewed-by: Bibo Mao (cherry picked from commit 7bd4eaa847fcdbc4505d9ab95dafa21791d8302a) (Mjt: context fix due to missing v9.1.0-913-g2a99b2af2c "target/loongarch: Use explicit little-endian LD/ST API") Signed-off-by: Michael Tokarev diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c index 5fc2f19e96..320a6f2fcc 100644 --- a/target/loongarch/gdbstub.c +++ b/target/loongarch/gdbstub.c @@ -63,23 +63,24 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint= 8_t *mem_buf, int n) LoongArchCPU *cpu =3D LOONGARCH_CPU(cs); CPULoongArchState *env =3D &cpu->env; target_ulong tmp; - int read_length; int length =3D 0; =20 + if (n < 0 || n > 34) { + return 0; + } + if (is_la64(env)) { tmp =3D ldq_p(mem_buf); - read_length =3D 8; + length =3D 8; } else { tmp =3D ldl_p(mem_buf); - read_length =3D 4; + length =3D 4; } =20 if (0 <=3D n && n < 32) { env->gpr[n] =3D tmp; - length =3D read_length; } else if (n =3D=3D 33) { set_pc(env, tmp); - length =3D read_length; } return length; } --=20 2.39.5