From nobody Sun Feb 8 05:35:46 2026 Received: from Atcsqr.andestech.com (unknown [60.248.187.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7795121A92F for ; Thu, 5 Feb 2026 05:54:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.248.187.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770270879; cv=none; b=PkYxqeNPr1n8TppgtUdYPbXW4xxKdBU7yUbzlByjuCR8GTf3wLIFV4RDwsGYiyFtlMvXvX9RKABHvMUUiWxjkkGXPVsdG92HWRDXj4z9NL78fBG16SY6W7Q2thWCy3NQ2Ug9irQrsWZgZ5iFBSxPVa9dRfqYFlF89txwlK7enVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770270879; c=relaxed/simple; bh=McLg2wq3xpfcgCfp4ZdSWwYLSUL9JyZG1flL4n8eiMU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=AcORx+G2Yw6cRzvBBkvGRGzymlBF1/scB4/u+YXW/YIyScF03cY8/+R4mZBdF1Y2YuUFW6KgRbSy+rsWl0NfHI55JXvdGTi6tI7fq2Gv4LMUJlQSzngPDmQwDI/V7IvsXHP2BPS15Bsnf3hkXiBUBnvs5nSAlFwRy6OG31RdqL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=permerror header.from=andestech.com; spf=pass smtp.mailfrom=andestech.com; arc=none smtp.client-ip=60.248.187.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=permerror header.from=andestech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=andestech.com Received: from mail.andestech.com (ATCPCS34.andestech.com [10.0.1.134]) by Atcsqr.andestech.com with ESMTP id 6155s2Bu011477; Thu, 5 Feb 2026 13:54:02 +0800 (+08) (envelope-from minachou@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS34.andestech.com (10.0.1.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 5 Feb 2026 13:54:02 +0800 From: Hui Min Mina Chou To: , , , , , CC: , , , , Charles Ci-Jyun Wu Subject: [PATCH] riscv: fpu: refine FPU save flow Date: Thu, 5 Feb 2026 13:53:42 +0800 Message-ID: <20260205055342.572379-1-minachou@andestech.com> X-Mailer: git-send-email 2.34.1 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-ClientProxiedBy: ATCPCS33.andestech.com (10.0.1.100) To ATCPCS34.andestech.com (10.0.1.134) X-DKIM-Results: atcpcs34.andestech.com; dkim=none; X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 6155s2Bu011477 Content-Type: text/plain; charset="utf-8" From: Charles Ci-Jyun Wu When Kernel first time run to arch_dup_task_struct(), it will check if sstatus.FS is dirty. If it is dirty, then it will do FPU save flow. But this field is floating currently. Meanwhile if the combination between platform(HW) and Kernel(SW) about FPU configuration is mismatch. eq: The platform is without FPU and Kernel is with FPU. Then Kernel may trigger illegal instruction here. Hence it shall check by has_fpu before do FPU save flow in arch_dup_task_struct(). Signed-off-by: Rick Chen Signed-off-by: Charles Ci-Jyun Wu --- arch/riscv/kernel/process.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 31a392993cb4..a27c21c7d9c6 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -199,7 +199,8 @@ void arch_release_task_struct(struct task_struct *tsk) =20 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) { - fstate_save(src, task_pt_regs(src)); + if (has_fpu()) + fstate_save(src, task_pt_regs(src)); *dst =3D *src; /* clear entire V context, including datap for a new task */ memset(&dst->thread.vstate, 0, sizeof(struct __riscv_v_ext_state)); --=20 2.34.1