From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796276003; b=JgWwEt0tJJiajbsvXj6bZ5M9r9IXUyrSaTfAcCZKuVrW4fqwt48qu2urRycwnyL8DMsT H+MiHs+g/8x2ByK11acto4lP0uc+G3ZgCYlN7POyJTbUDbPSaFrka/1tB7NY23mCktrhI YsYHcF3gZXoNstH8c7nXY1QytXY2wiVj99p5C+/o29yylr/GvxmPxypcTVGgsxtm7MnSO ot2yxKzUOyw7vBVvBy2PwOS2tNtGkBEe43GlKCRs3aOt6Y5E2mSJ0EOYniTypunE4tgDC PuiBwo7GdnB63Q2m5Pv7ZCFXNhqpj1uxdrT4psdVbI4meiRg0Wg9/NUOkTIImjbhyFA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796276003; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=a7BbT6N9T3Zud+RCGvT+xNQ3fvfaJQd1fCoWAQMgvyk=; b=TLUa0GgGZsSeuNn3B8tdIeiRue7e4gsNrXF0/J/1zh5Q4sUpV8zuJpw7n2zE9KOil2R9 y5UX7H+OIdmLwhw11esTrmybWgquJH0ci99BavEbLkfIrYjvtEyKxKJo4dAqeivmez6zy ELIBgtAFCVW0CGsO7KifkvuYgLcG2joKvpF4AVsvTpHMd0CvnTEBedrcuvtSLw5GShrV7 LpHn5nUSQsNLonN0gsrHKQJC5uKWYbdBJRqhw6X9rb/EviLZoMvn76LRiNGMBy6ubLJ6w nddWlwoLB46qcJEhLrATM+PR+kpJxti5OmSjmJL4uM4kwqjQ3LD6Hson/fnQcefRTiw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Xd2Q0p+M; arc=none smtp.remote-ip=74.125.229.9 Received: from mail-dy2-f9.google.com (mail-dy2-f9.google.com [74.125.229.9]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3445606A322 for ; Thu, 3 Dec 2026 05:33:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B3445606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Xd2Q0p+M Received: by mail-dy2-f9.google.com with SMTP id 5a478bee46e88-377157fde7bso4199682eec.0 for ; Wed, 02 Dec 2026 21:33:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796276002; x=1796880802; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=a7BbT6N9T3Zud+RCGvT+xNQ3fvfaJQd1fCoWAQMgvyk=; b=Xd2Q0p+MKGvZh2VXP1fvXzoF6tQtObWdN/XYk8/1u9VOdw/GBxOVkPsNWwwOxTTM+D H8ROGQSWYfmZoAlvIj8/Ob8fi/tzY0yfdwJLTRVgzB/MLm+tDRHjFYWmbo94l39QllLH 9BDsAYyL0zIE+1VWTPIWrFPenIBJoyFZiGaTETJQ449BSY+sR0lDfoBdmVVlxdEyDI0x BGg31v/nDfMTJJTVeORBIYv/7vyZ8oncmAos94bbJIkT4ahicdVV0SwntZY/l0CfW5kU pJ1bjmhDg8cXCDeKNJkE82CD3wKWAxARQ9cPjA9Iul4k81vwxoWNtp4N/U/CKu+THA3E 6Qig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796276002; x=1796880802; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=a7BbT6N9T3Zud+RCGvT+xNQ3fvfaJQd1fCoWAQMgvyk=; b=U+CM5nPMalUrM03I8LE2To6A7SXazJcFVAbpjWRjtqMRlZjh1C85VFZPwMPb0D83uf 7hxDiilYTO5c7f9z69Uph2b6k5DdCxheHRrf5nq02fl/avlsneQhqVfw/DBvZoyhNU32 yYkeyCUBGRVxf7enI4dbG8MujQbm8oOJ1elvhvYOjCeULMilGuF9aQBil/+dyxOpYhQh 3oR/5y0vL7jIV1BFByh83gvjOIj16hLcJ5qHJ9riVmtuDzmbxXwc73xYQwfLuCansyxG cm0ZetXlL6pvvcU/GrsxXTqUZxqIjZb7peJ5EfrxvcB8enR6J2jakg9nTHnz/6ZlDq6S qsRw== X-Forwarded-Encrypted: i=1; AL+hErHTGXyK44oKNa2jlEhsVBs4bTQW12FzWAvj+wR42b4TBi1k3yOgvhmz53noWLbfbQjy3MCvGUz1KIITZyk=@vger.kernel.org X-Gm-Message-State: APuU4Z85mcGhxyuaRKa0d81R7k+b0rHFLKBqTxtrsmswWLY91qv27/l8 h8dN19svPPUbBtMAYAy0x6EQoZT8Kpf+g1lVhmA5T7gGHuerF/jzfto5 X-Gm-Gg: AZFdTZe0HbWpmVhDjGZUzb1I9pQNuJuVBppgAEX4twhDhDhgvVkuFU0Xzo0qQSo018i Zf8Z7MrXZnz/Y456Wkho4x7iv2Wu6T/QN/aEw5sa34lHMIuBPuvl9wlktT5GP7EyGlzi8aqEih/ h3dXMeYTp0JG2GTEQ6+dbakRP1VP4hBk/LlyaMhxN1rb9n9MsTAO30gY0PKSNojpjCPskdkZcsO 5fBZWXO/VPFfdWPX9pCxcuaSRmChUQuvNUK2ibYhdaDQszlMsrb5zV3iAfjgDNyrypFS/y5ZB5X MywvtnsNBEgre7ev5uuMuCv9CDvsJMWGd92TFgcRXgt4XZMud6icomneaZYiSKunl0q/ktYN+Xm BA5fECU4VHhgNqQxDpgOrMxZvrjf9/hgQbj5gM81qOoebFtMUxhqqsfZlq8UTUHlRFdTdCZWuI9 jJ2qoqCkdPyOm+W9QlhWlbP4bWH2Sh3ho/hW+VEiPnS9LZ6q1Zua8WIp9KIMsUAR8M1B10X60ee pd8BHLJmeFxNni1T5QMWmPf0jGtFIzqMaCVYVMWNzQY9l3asEB2YRQqjLl6jFByKjPFfRA6VOXu R+qFRJVCAphlKPN+atyglTGywJuZ05TdhKJxsQI92/L723UniaZ5h8TdYmqPgACSIokb/kCMmBx 0xnjym8Q= X-Received: by 2002:a05:693c:8211:b0:36f:202c:48 with SMTP id 5a478bee46e88-3857045092emr44175118eec.14.1796276001548; Wed, 02 Dec 2026 21:33:21 -0800 (PST) Received: from zihui.lxd ([137.132.218.135]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38567cafec4sm137284782eec.26.2026.12.02.21.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 21:33:21 -0800 (PST) From: Zihui Guo To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Alexandre Ghiti , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: misaligned: Do not decode cm.push as c.fsdsp without Zcd Date: Thu, 3 Dec 2026 05:33:17 +0000 Message-ID: <20261203053317.24927-1-youzih27@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The misaligned store emulation decodes the c.fsdsp encoding without checking for Zcd. Zcmp and Zcmt reuse that encoding for cm.push, cm.pop, cm.popret, cm.popretz, cm.mvsa01, cm.mva01s, cm.jt and cm.jalt, and both extensions are incompatible with Zcd. On a hart with Zcmp, a cm.push with a misaligned sp traps and is emulated as c.fsdsp: eight bytes of a floating-point register are stored instead of the register list, sp is not adjusted, and the task continues with the wrong stack contents. Only accept the c.fsdsp encoding when Zcd is present. Otherwise the store is not emulated and the task gets SIGBUS, as for any other store the emulator does not handle. Fixes: 7c586a555a48 ("riscv: add floating point insn support to misaligned access emulation") Signed-off-by: Zihui Guo --- Tested on Spike (rv64imafd_zicsr_zifencei_zicntr_zihpm_zca_zcmp, no C or Zcd) with OpenSBI master, and Linux built with RISCV_ISA_C=n and RISCV_SBI_FWFT_DELEGATE_MISALIGNED=y, so that misaligned stores are emulated by the kernel ("SBI misaligned access exception delegation ok"). A user process executes cm.push {ra}, -16 (0xb842) with sp = 4 mod 8. Before: the store is emulated as c.fsdsp. sp is unchanged, the value of f16 is written at sp-8, and the process continues without a signal. After: the process gets SIGBUS (BUS_ADRALN). With an aligned sp, cm.push behaves correctly on both kernels. Not tested on hardware; the test program is available on request. Assisted-by: Claude:claude-opus-5-5 arch/riscv/kernel/traps_misaligned.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c index 6e8ae6c66322..4e5d1d09a71e 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -387,7 +387,9 @@ static int handle_scalar_misaligned_store(struct pt_regs *regs) fp = 1; len = 8; val.data_u64 = GET_F64_RS2S(insn, regs); - } else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP) { + } else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP && + riscv_has_extension_unlikely(RISCV_ISA_EXT_ZCD)) { + /* Without Zcd, this encoding is cm.push, cm.jt and the like */ fp = 1; len = 8; val.data_u64 = GET_F64_RS2C(insn, regs); base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d -- 2.43.0