From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.220 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796323152; b=e9B1qnzEdq7Qwp+4aHnRVZJI8Y+fpc+5hCilpWLeQvIJfH1UJvsDO8ygYNsi8SGdh7Pv ajX2DpRRMIaF8nrAjWOUhuPOkHVUIUxCoK1FQkC4inFETTE0A1KdiqyFk4/Slx8ciI/mX 1Fl/rDHdi1p8fhbjhjPwWXPDVJlBvxRoXqRb1Cd8JDsIzg3gkja712fDjS81B6l67SjYb Q3mu97RDljnFs9O/sUh5jBqt3YZs1xu6ZdBcF0b+OuRlcMVXB+vKdLn2UsIHy9aAJh+JE kTB1ppI5ZVWyyivgu/IOxN7V3PYdmeNpRsk9aQ5Pfj//1xRWHz1B+Vl4UzDC1I/gFXw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796323152; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: From:Subject:To:Cc:References:Content-Language:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=KMGzzdjsETWSvZRVyuCTDivJuztNelmPJZ3G86LEjZM=; b=Q+uuS5Nw2Aiy4BdWO4H3zoCbWdZ8H0T8tj6EhOSLMo9y/XjLJe1xr5EIS2ErLa9DXPcB xguERpFEbZ3BLnIDhbZTZTiGVICYhyG9o0cPcench9FVbfpm6MfJ4QL8xONN4bzXzwsnJ jS4+VUOAHrVm0jOUQLNj0FImdRYpYDpgt1oLRSYU8HKioI8jyLMaLR5zFgTeb3VcGnyV1 JkfF/C7MiJFS5TaCzE1sFZ1ofATZCcDsEe52Tteii3ugIq6/OxIrm2u7IBzsa02Qqtpy0 wXlJTxTIRHsJCiFa1mEnYzTz0hDfyW7mPeHv0WD0GUO5Wa1B2dzXpvqv5MQyLLCLaQw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Kuy8HBcV; arc=none smtp.remote-ip=95.215.58.220 Received: from mta1.migadu.com (out-220.mta1.migadu.com [95.215.58.220]) (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 E692E606A32F for ; Thu, 3 Dec 2026 18:39:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E692E606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Kuy8HBcV X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=WiM/ohxt6cIGJCFOXUQHomeZbGlcNUlgA1uRAZKW95g=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796323148; v=1; x=1796927948; b=Kuy8HBcVfx6SbUWdl2agRgbbd/jtlSLpqo9qL5pvmKjqsxwujmEDwkXe3dRVf+F8Z3lv4BvB mABWS77CEDxN4WPaNbEYW+pzmRzNaIm52+aaXEIeMP64AB1BwE5IzOrKMb6ZxuLciQJjdkUYO9b gELMdisfdjVa4dzcuxyLPQ6A= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 95b865984a24dcc8; Thu, 03 Dec 2026 18:39:08 +0000 X-Mizu-Trace-ID: 95b865984a24dcc8 X-Migadu-Flow: FLOW_OUT Message-ID: <8e9e1b6e-239d-43f4-a6dd-8834acc60788@linux.dev> Date: Thu, 3 Dec 2026 19:39:06 +0100 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 User-Agent: Mozilla Thunderbird From: Clement Leger Subject: Re: [PATCH] riscv: misaligned: Do not decode cm.push as c.fsdsp without Zcd To: Zihui Guo , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20261203053317.24927-1-youzih27@gmail.com> Content-Language: en-US In-Reply-To: <20261203053317.24927-1-youzih27@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/3/26 06:33, Zihui Guo wrote: > 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. Hi Zihui, Could you add the reproducer as a selftest if possible ? > > Assisted-by: Claude:claude-opus-5-5 I think the consensus is that this line can now be omitted. > > 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 */ I wouldn't bother with the comment. Otherwise, looks good to me (with a test added in selftests). Thanks, Clément > fp = 1; > len = 8; > val.data_u64 = GET_F64_RS2C(insn, regs); > > base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d