From nobody Sun Apr 5 16:30:29 2026 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E89B63C5DD6 for ; Mon, 23 Mar 2026 17:29:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286983; cv=none; b=ejHs1/hb92VWVwc3cDBbv6gXoWF9L6DXixdipU37KypoeQkWAOZBc/QU2DP0HKY9KQCTx5DIpJQgWTBoUyXFZG9qQrvD5YBIhRc871SoTiLM+UH47ZMipFPfyQ/rWh6sCHBxh/kzR89xIK0aZ5rNuvST4PK3iyOfnwfTKtDsXGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286983; c=relaxed/simple; bh=ZP0GgxUb0X9HJeWaCzCm4aZsvRfNesx/QZt9I52Fi6g=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bc8McvZv5rVIujuzx/dAZTRjwHW+nSPC1MT8+abSMkpZahAWMnDEbXB0SZYvsiDvTK0LAjldWFfZzrB4r6BvUuoj/zBZJBSHoYXX7o/dd1jQUz0nJunl6IbmmPsYwnR/LJTiLSoekxA8fBOClY7BbvdT4xDU7f+4mN1zPFZlybQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from yzs (unknown [115.192.255.131]) by APP-01 (Coremail) with SMTP id qwCowADnj2tueMFpkovqCg--.13525S2; Tue, 24 Mar 2026 01:29:18 +0800 (CST) From: Zishun Yi To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Alexandre Ghiti , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Andrew Jones , Charlie Jenkins , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Zishun Yi Subject: [PATCH] riscv: misaligned: Restore epc in error path Date: Tue, 24 Mar 2026 01:28:26 +0800 Message-ID: <20260323172826.69428-1-vulab@iscas.ac.cn> X-Mailer: git-send-email 2.51.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qwCowADnj2tueMFpkovqCg--.13525S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uFy5ZFy8Kry3Kry7JF15XFb_yoW8ZF45pF 47G39ayrWxt3W2qF4avr4vgFWfZwn3uryxJrsrG34rCF45XryrX395u3Z0vry0gFykWr48 KFWYqF43WFs8A3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9014x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8JV W8Jr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1lc7CjxVAaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x 0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2 zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF 4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWU CwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIda VFxhVjvjDU0xZFpf9x0JUd-B_UUUUU= X-CM-SenderInfo: pyxotu46lvutnvoduhdfq/1tbiBgwPA2nBLYtDnwABsV Content-Type: text/plain; charset="utf-8" In handle_scalar_misaligned_{store, load}, regs->epc is temporarily set to 0. While it is properly restored in the instruction decoding error path, it is not restored in the subsequent error paths. This causes the epc to be corrupted. Fix this by restoring regs->epc in the unsupported fp and copy_{from,to}_user error paths. Fixes: 7c586a555a48 ("riscv: add floating point insn support to misaligned = access emulation") Fixes: 441381506ba7 ("riscv: misaligned: remove CONFIG_RISCV_M_MODE specifi= c code") Signed-off-by: Zishun Yi --- To be honest, I am not entirely sure about the purpose of setting regs->epc =3D 0 early in these functions. I suspect that simply removing this line might be a better fix. arch/riscv/kernel/traps_misaligned.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps= _misaligned.c index 2a27d3ff4ac6..24f898853bba 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -307,13 +307,17 @@ static int handle_scalar_misaligned_load(struct pt_re= gs *regs) return -1; } =20 - if (!IS_ENABLED(CONFIG_FPU) && fp) + if (!IS_ENABLED(CONFIG_FPU) && fp) { + regs->epc =3D epc; return -EOPNOTSUPP; + } =20 val.data_u64 =3D 0; if (user_mode(regs)) { - if (copy_from_user(&val, (u8 __user *)addr, len)) + if (copy_from_user(&val, (u8 __user *)addr, len)) { + regs->epc =3D epc; return -1; + } } else { memcpy(&val, (u8 *)addr, len); } @@ -409,12 +413,16 @@ static int handle_scalar_misaligned_store(struct pt_r= egs *regs) return -1; } =20 - if (!IS_ENABLED(CONFIG_FPU) && fp) + if (!IS_ENABLED(CONFIG_FPU) && fp) { + regs->epc =3D epc; return -EOPNOTSUPP; + } =20 if (user_mode(regs)) { - if (copy_to_user((u8 __user *)addr, &val, len)) + if (copy_to_user((u8 __user *)addr, &val, len)) { + regs->epc =3D epc; return -1; + } } else { memcpy((u8 *)addr, &val, len); } --=20 2.51.2