From nobody Mon Apr 6 19:45:50 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1773830053; cv=none; d=zohomail.com; s=zohoarc; b=nf381LXaZqRHTTfZE4r5Hqem1fWvMd/sHMNUOMImxU7YDEWSbIFPMr7nlNgkQI8p/Pva7a8nzdDxc+ZeAbOJKbSBMRAuekMwY487WVwYaIDCPPhpBMSkcw9E6Sf+PnBt8z9tsYtzMkyp/VJASbwN2a8C+43FJH8l+Fs2zTzJCZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773830053; 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=n2Sgkb6N71I15zCHePybcfBnW8R6vfuIZgllQvpx1Uc=; b=YaHFRUtG1CrMBBqf2CfUl2OL805dFC+W+pV1CrP4su6fwfnppD0Oi2XjLgKwg8m/Yqbu2XNXG0AXkMzNjiF4j/Puz4c3RnKpq3bYuuZezudb+tGSLsqX0uHvAU/BbHoSx+QkXPPoH07v4H6vXxdJCzrrwNgYvRKS9aY2nVUvUjs= 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 1773830053440657.209796018257; Wed, 18 Mar 2026 03:34:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2oDH-0003lX-O2; Wed, 18 Mar 2026 06:33:19 -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 1w2oDF-0003gI-I3 for qemu-devel@nongnu.org; Wed, 18 Mar 2026 06:33:17 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w2oDE-0002YW-18 for qemu-devel@nongnu.org; Wed, 18 Mar 2026 06:33:17 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-43b4fd681c2so1250513f8f.3 for ; Wed, 18 Mar 2026 03:33:15 -0700 (PDT) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b5189971asm6778525f8f.30.2026.03.18.03.33.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 18 Mar 2026 03:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1773829994; x=1774434794; 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=n2Sgkb6N71I15zCHePybcfBnW8R6vfuIZgllQvpx1Uc=; b=GkkJ4TDnF9A87W6rNQdnATqlDm3l5jlXP6PMIH2+xqzgEdHtKLQH3S0OyDGfG9qa91 aPjzfKrxECWCoOXoLluhAT3HhI1qHB4BFYAxSPFbRMS1eqBnX8b8ATwsmnIy2ZPVatyM A5zssta5AIw0LLzXco/Jn2Fl0fvyrr3Z7hAIna8jKJB/2BwjJmJy2yRHDJ/mqWSRbUHZ we1L3Xd3NbvPHi/ocAtJQO1CiJv2MLzLc8LE5H0djaQRVb0HjCcZB6AH5RYguGFKwt2I mAy8GfGvEnQBfKpWQV9u0l8Fz21gngrAjOcOqEeNJVloOJoCYqDrK9k/++5Y/F+3zGgy YCfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773829994; x=1774434794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=n2Sgkb6N71I15zCHePybcfBnW8R6vfuIZgllQvpx1Uc=; b=lSmgj+N4tlhKnlX67NwGoEzKgxVlAKjv0bYmJSPMLb7vopQeNDJ9f3PJ8baYjhbX85 jWPXilEKONJEeDUTv25tv5rgqtSxTp4Zns+n+dTM3fe1Wp1VAIVefZs2uNUDwtZDsbRk zl7LGixhZOBAmZUmQ5mo4LmKcGKvVp0mj3kBG+eF/bmVxwAKtE+KxOBLQiV46MTIOUVx Lf9v8kP0tqNUmD6/d9NsyYqpoExKgA9OiAC1HBrHFmHRsPsJQAWWanBzr1/Dw8TtajKO nXoriSGS215AeMUPvodPK+ajrMWW5SedTeGrPRv1CgbBppN0pL2jsXxr8SmBXBnidFu1 TBZw== X-Gm-Message-State: AOJu0YzvkU8J1gzgKNEoMK04ZkNLl0RJEdrsfykPx/m+S2t47YCUxJ7N Ismf/OmsvCesdBqC7PVpi6bnGaGL7j/v0iZ+BE04qFtC0YH4XxbPeRH0NJc7El2hr0/Emz7sez+ UM4ATbVA= X-Gm-Gg: ATEYQzxy2yo9rfOgoamAhkOAbqL/RCMNsXts2PCh/xiLoWZvqEV9vEOeEQ0EWCnYWTI roH8pP1ISMyL0LCr3eBag6Dpi6SrHPeu8V4VGYHC9QTKDuPftYstniSBOAKu4qNrkyCEa+f/2Ar u3Bzir3JrI+J81KPh3xrGrbXkeH7OzwFUL8iQUJKk4Vqe6a/w0GpNIrTaOB6RL9rtw5iyxKiSQy gP0kEYztWiODq80V4UMXam1boyd2qz4WRvN5ZEbJwyfrC2XQbbfEiZPqd0kGEYjn4RAGQusItUn VNZg8ZdXLnLAAXPF/Dxekt5i36HJAUZvaAF/8Oc5vg8pybTQS3IzFZIFYFLjUQPrgl6IiKQW7im zBK1Iv12YeNXqNAeImpLFXqLw/kuOKEUU87JsHT8RfwMMZCzFNt/PoYo6J2Ooj4yc3BPxS4g9u4 Dds4E1324ENab+D5ckrFEgFJ2MKCx7YDT3oGFP5kmNS5nlqyy6AxqQ31Vu25VFhG2sLGJGGRrm X-Received: by 2002:a05:6000:24c3:b0:439:b55d:b0e5 with SMTP id ffacd0b85a97d-43b527c4301mr4406646f8f.28.1773829994167; Wed, 18 Mar 2026 03:33:14 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Weiwei Li , Pierrick Bouvier , Warner Losh , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9trot?= , Vijai Kumar K , Anton Johansson , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Alistair Francis , Palmer Dabbelt , Jiaxun Yang , Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis , Liu Zhiwei , Djordje Todorovic Subject: [PATCH-for-11.1 15/16] target/riscv: Use MO_LE for instruction fetch Date: Wed, 18 Mar 2026 11:31:20 +0100 Message-ID: <20260318103122.97244-16-philmd@linaro.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260318103122.97244-1-philmd@linaro.org> References: <20260318103122.97244-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::42a; envelope-from=philmd@linaro.org; helo=mail-wr1-x42a.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, SPF_PASS=-0.001 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: 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 @linaro.org) X-ZM-MESSAGEID: 1773830054165158500 From: Djordje Todorovic RISC-V instructions are always little-endian regardless of the data endianness mode configured via mstatus SBE/MBE/UBE bits. Currently, instruction fetches in decode_opc() and the page boundary check use mo_endian(ctx), which returns MO_TE. This happens to work today because RISC-V targets are little-endian only, but is semantically incorrect and will break once mo_endian() is updated to respect runtime data endianness for big-endian support. Use MO_LE explicitly for all instruction fetch paths. Data memory operations (AMOs, loads/stores via mxl_memop) continue to use mo_endian(ctx) as they should respect the configured data endianness. Not-Signed-off-by: Djordje Todorovic Reviewed-by: Alistair Francis Message-ID: <20260311115910.564481-3-djordje.todorovic@htecgroup.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- target/riscv/translate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 6f8b8e9d19a..5df5b738495 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1255,7 +1255,7 @@ static void decode_opc(CPURISCVState *env, DisasConte= xt *ctx) * additional page fault. */ opcode =3D translator_ldl_end(env, &ctx->base, ctx->base.pc_next, - mo_endian(ctx)); + MO_LE); } else { /* * For unaligned pc, instruction preload may trigger additional @@ -1263,7 +1263,7 @@ static void decode_opc(CPURISCVState *env, DisasConte= xt *ctx) */ opcode =3D (uint32_t) translator_lduw_end(env, &ctx->base, ctx->base.pc_next, - mo_endian(ctx)); + MO_LE); } ctx->ol =3D ctx->xl; =20 @@ -1285,7 +1285,7 @@ static void decode_opc(CPURISCVState *env, DisasConte= xt *ctx) opcode =3D deposit32(opcode, 16, 16, translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 2, - mo_endian(ctx))); + MO_LE)); } ctx->opcode =3D opcode; =20 @@ -1401,7 +1401,7 @@ static void riscv_tr_translate_insn(DisasContextBase = *dcbase, CPUState *cpu) if (page_ofs > TARGET_PAGE_SIZE - MAX_INSN_LEN) { uint16_t next_insn =3D translator_lduw_end(env, &ctx->base, ctx->base.pc_next, - mo_endian(ctx)); + MO_LE); int len =3D insn_len(next_insn); =20 if (!translator_is_same_page(&ctx->base, ctx->base.pc_next= + len - 1)) { --=20 2.53.0