From nobody Mon Feb 9 08:49:16 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=none dis=none) header.from=yeah.net ARC-Seal: i=1; a=rsa-sha256; t=1755287794; cv=none; d=zohomail.com; s=zohoarc; b=FiUnd/vog3WEnfHLsSqYjfSFRZHIAbVJthhon5bbOGJIuRKdAXA0Z/FqOsDGucuyVKuabrspVJTe5vI4nh6sm1ggJJwnNK7EwS+4TKry7ejtXThtgACiSN7K6g1hTHPe1FbgAAT9WaRuHYjIFtBlwCfhGDYtPfjt6IyRcUvKWS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755287794; h=Content-Type: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=1fiKA4dy0xdL90wRaaFduyn2+bDZ4La+jQDUFpYQD/Q=; b=bYHLDsHtlfOmHMGDEvrZDU8JhXpEDEn0ohqCTiZv/WxOae8QLkyR+LEb0ll01si1iVDMp6tsf2aR9CZu1eFmgZE+KvKqrGVy1hMru2tpQz0FKNE56oAzxnBH6ZtUOPA3+0R3AcskOAz+v+E6OHj46/g4QdYuR6KfEovQu+RMHyU= 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 1755287794157766.79366865663; Fri, 15 Aug 2025 12:56:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1un0XK-0003yW-Fm; Fri, 15 Aug 2025 15:56:26 -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 1un0XJ-0003yC-7H; Fri, 15 Aug 2025 15:56:25 -0400 Received: from mail-m16.yeah.net ([220.197.32.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1un0XF-0004r9-7n; Fri, 15 Aug 2025 15:56:24 -0400 Received: from ZEVORN-PC (unknown []) by gzsmtp1 (Coremail) with SMTP id Mc8vCgCHtrLGkJ9ocCKuAg--.20443S3; Sat, 16 Aug 2025 03:55:51 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yeah.net; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=1fiKA4dy0xdL90wRaaFduyn2+bDZ4La+jQDUFpYQD/Q=; b=HXldxkWnkTwEQQmjteNJMWWTwuPpZnzK3zaG2HnaZU9l00jyP9Rwp+YghF4Dlf 08D6/IFbQ5/o9IHYPvUnCCzKCqqj6G0s3YfG0v7G/yHCTZcgVEL6ZPf4Cme5Fnxw H1OnWsiANXe6dAF+vFjP7lI64cf4c5sIX2cgyOGL70ciM= From: Chao Liu To: paolo.savini@embecosm.com, dbarboza@ventanamicro.com, ebiggers@kernel.org, palmer@dabbelt.com, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com Cc: qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Chao Liu Subject: [PATCH v2 1/2] target/riscv: fix vector register address calculation in strided LD/ST Date: Sat, 16 Aug 2025 03:55:40 +0800 Message-ID: X-Mailer: git-send-email 2.50.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Mc8vCgCHtrLGkJ9ocCKuAg--.20443S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cw1UuF1xtr1DGFW5Xr13Jwb_yoW8ZFyrpr sYkry7Kr45WFWfZFZ2yr48JryYqayFgr4jkw4qgwn8XFW5Xr47tF4vga42kF18JrWxur12 9ayUuay5uw13uFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UaD73UUUUU= X-Originating-IP: [240e:b8f:29d6:3800:f820:962e:d888:73d] X-CM-SenderInfo: pfkd0hxolxq5hhdkh0dhw/1tbiIghYgGifkMgwkgAA3- 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=220.197.32.16; envelope-from=chao.liu@yeah.net; helo=mail-m16.yeah.net 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=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-ZohoMail-DKIM: pass (identity @yeah.net) X-ZM-MESSAGEID: 1755287795592116600 This patch fixes a critical bug in the RISC-V vector instruction translation that caused incorrect data handling in strided load operations (e.g., vlsseg8e32). Problem Description: The `get_log2` function in `trans_rvv.c.inc` returned a value 1 higher than the actual log2 value. For example, get_log2(4) incorrectly returned 3 instead of 2. This led to erroneous vector register offset calculations, resulting in data overlap where bytes 32-47 were incorrectly copied to positions 16-31 in ChaCha20 encryption code. rvv_test_func: vsetivli zero, 1, e32, m1, ta, ma li t0, 64 vlsseg8e32.v v0, (a0), t0 addi a0, a0, 32 vlsseg8e32.v v8, (a0), t0 vssseg8e32.v v0, (a1), t0 addi a1, a1, 32 vssseg8e32.v v8, (a1), t0 ret Analysis: The original implementation counted the number of right shifts until zero, including the final shift that reduced the value to zero: static inline uint32_t get_log2(uint32_t a) { uint32_t i =3D 0; for (; a > 0;) { a >>=3D 1; i++; } return i; // Returns 3 for a=3D4 (0b100 =E2=86=92 0b10 =E2=86=92 0b1 = =E2=86=92 0b0) } Fix: The corrected function stops shifting when only the highest bit remains and handles the special case of a=3D0: static inline uint32_t get_log2(uint32_t a) { uint32_t i =3D 0; if (a =3D=3D 0) { return i; // Handle edge case } for (; a > 1; a >>=3D 1) { i++; } return i; // Now returns 2 for a=3D4 } Fixes: 28c12c1f2f ("Generate strided vector loads/stores with tcg nodes.") Signed-off-by: Chao Liu Tested-by: Eric Biggers --- target/riscv/insn_trans/trans_rvv.c.inc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_tr= ans/trans_rvv.c.inc index 2b6077ac06..f50b62b1d8 100644 --- a/target/riscv/insn_trans/trans_rvv.c.inc +++ b/target/riscv/insn_trans/trans_rvv.c.inc @@ -877,7 +877,10 @@ static inline uint32_t MAXSZ(DisasContext *s) static inline uint32_t get_log2(uint32_t a) { uint32_t i =3D 0; - for (; a > 0;) { + if (a =3D=3D 0) { + return i; + } + for (; a > 1;) { a >>=3D 1; i++; } --=20 2.50.1