From nobody Thu Sep 24 13:44:22 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0948943744F for ; Wed, 23 Sep 2026 05:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142914; cv=none; b=YByIH9s5hacfe03jRB50JeqhU8BAFQ7wNbZkjJpPHpSy2yaVA+RMDjy1nGpMyQbfoHwt4lvcy0WyY+p1wJbWhgXqM5ffwJfXwiLlBP6sLbvRopFsDpxFLJkXJoVpeNqCN0/PWWY8aCINj5muB2ffJjU2Zg/cskkFYu5gt1zHTMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142914; c=relaxed/simple; bh=i+XbG0C3Y1Z14Pm7tlM7Ix5h4dqleLfbW9K5xjNIP+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DbRbhLS0OptoODXzNvyybmppWEZyA+UyoLiuFmuLPw9mzGaTuzges3gi8httfeJ9ku5uAr7nQp+h/5E1RKDvBlL3/61mZ7UfSFWTC/jk864GI4k3bFY7KSfzxaJ3G8ZjN0WfbCzaQusFDUP5F7A868B4D0CkiltHpy9l2ukMRi8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [123.138.236.242]) by gateway (Coremail) with SMTP id _____8Ax29G9abNqj+0OAA--.43861S3; Wed, 23 Sep 2026 13:55:09 +0800 (CST) Received: from linux.localdomain (unknown [123.138.236.242]) by front1 (Coremail) with SMTP id qMiowJCx9cy7abNqphMkAA--.48859S3; Wed, 23 Sep 2026 13:55:09 +0800 (CST) From: Tiezhu Yang To: Huacai Chen Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/7] LoongArch: Fix bitmask corruption in update_bp_registers() Date: Wed, 23 Sep 2026 13:55:00 +0800 Message-ID: <20260923055506.29221-2-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260923055506.29221-1-yangtiezhu@loongson.cn> References: <20260923055506.29221-1-yangtiezhu@loongson.cn> 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: qMiowJCx9cy7abNqphMkAA--.48859S3 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7tFWfKw15JF1fKF1ruF4ftFc_yoW8Zw15pr 17uF4kGF4UWa13Xasrtr1kCr43Gw4Duw47Z3WfK34rtwn8CrnYvwnYgF9xXayUGw4fJ3WI vF1Fgr90vanrAwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8niSPUUUUU== Content-Type: text/plain; charset="utf-8" In update_bp_registers(), when disabling a LOAD or STORE watchpoint, the code attempts to clear the bit of LoadEn or StoreEn by using the standard bit-clearing pattern. However, due to the omission of parentheses, the bitwise NOT operator '~' takes higher precedence than the left shift operator '<<'. Then: (1) ~0x1 << MWPnCFG3_LoadEn evaluates to "(~0x1) << 8 =3D 0xFFFFFE00", (2) ~0x1 << MWPnCFG3_StoreEn evaluates to "(~0x1) << 9 =3D 0xFFFFFC00", that incorrectly clears all configuration fields in the lower 8 bits. These fields in the lower 8 bits contain critical configurations such as DSOnly (bit 0), PLV0-PLV3 privilege levels (bits 1-4), and LCL (bit 7). Writing back these corrupted values severely breaks configuration isolation and ruins the hardware watchpoint states. Add parentheses to ensure the correct evaluation order, so that only the targeted LoadEn/StoreEn bit is cleared while preserving the other crucial configuration bits in the lower 8 bits. Fixes: edffa33c7bb5 ("LoongArch: Add hardware breakpoints/watchpoints suppo= rt") Cc: stable@vger.kernel.org Signed-off-by: Tiezhu Yang --- arch/loongarch/kernel/hw_breakpoint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/loongarch/kernel/hw_breakpoint.c b/arch/loongarch/kernel/= hw_breakpoint.c index c35f9bf38033..6ba7315852f3 100644 --- a/arch/loongarch/kernel/hw_breakpoint.c +++ b/arch/loongarch/kernel/hw_breakpoint.c @@ -469,9 +469,9 @@ static void update_bp_registers(struct pt_regs *regs, i= nt enable, int type) } else { ctrl =3D read_wb_reg(CSR_CFG_CTRL, i, 1); if (info->ctrl.type =3D=3D LOONGARCH_BREAKPOINT_LOAD) - ctrl &=3D ~0x1 << MWPnCFG3_LoadEn; + ctrl &=3D ~(0x1 << MWPnCFG3_LoadEn); if (info->ctrl.type =3D=3D LOONGARCH_BREAKPOINT_STORE) - ctrl &=3D ~0x1 << MWPnCFG3_StoreEn; + ctrl &=3D ~(0x1 << MWPnCFG3_StoreEn); write_wb_reg(CSR_CFG_CTRL, i, 1, ctrl); } regs->csr_prmd &=3D ~CSR_PRMD_PWE; --=20 2.42.0 From nobody Thu Sep 24 13:44:22 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 097B243A7F5 for ; Wed, 23 Sep 2026 05:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142916; cv=none; b=GxYpiUwfnmokL5RwBezbjxJZDzlyAg1Tdks3PceasT6vs81QHA42S7YnzXcXxricXMTxOb2tP7joV+7uSKN7BdOZxh9rxrTv249ONuj8ja9Zy4N5HzOR7wGipZLkzmbVK/fxhItL4qo759q8qlOiDpM85LeOrVHHOOrP8ZC/HCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142916; c=relaxed/simple; bh=LoTeSF2Sp5RJBvRuP5z73LifGbx6GY6oYSFnURWYf3s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hdbbiom+bkLEhCthNcLkc9z2OAviYCJO2mEFEj21J60hHtUVe31HZXiYQNdO4TtwdvCwAVsytWsqzcbn7oDfUq6FVH4dqKz7mAPrp5/heOCxhDW3jP8Z2ZEyFUI6P+13lmwrN8ySJVHzQ3VPrnvA20/ZAPKov2m3c0z3kI2ohFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [123.138.236.242]) by gateway (Coremail) with SMTP id _____8CxPtO9abNqku0OAA--.43584S3; Wed, 23 Sep 2026 13:55:09 +0800 (CST) Received: from linux.localdomain (unknown [123.138.236.242]) by front1 (Coremail) with SMTP id qMiowJCx9cy7abNqphMkAA--.48859S4; Wed, 23 Sep 2026 13:55:09 +0800 (CST) From: Tiezhu Yang To: Huacai Chen Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/7] LoongArch: Remove redundant call in update_bp_registers() Date: Wed, 23 Sep 2026 13:55:01 +0800 Message-ID: <20260923055506.29221-3-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260923055506.29221-1-yangtiezhu@loongson.cn> References: <20260923055506.29221-1-yangtiezhu@loongson.cn> 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: qMiowJCx9cy7abNqphMkAA--.48859S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7Kw4xKw1DKw1UXFWxAw4UWrX_yoW8JFWxpr yY9FZ5Kr4DGF4kC3ZrKF93ZryUGF9ru392vw4Fkay3twnxWr1rJ34UW3s3XFWYvw4fK34I grW5CFyYq3WUAacCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8niSPUUUUU== Content-Type: text/plain; charset="utf-8" In update_bp_registers(), there is a duplicate call to write_wb_reg() when enabling an execute breakpoint: write_wb_reg(CSR_CFG_CTRL, i, 0, CTRL_PLV_ENABLE); write_wb_reg(CSR_CFG_CTRL, i, 0, CTRL_PLV_ENABLE); The two lines are completely identical. Remove the redundant call to clean up the code and eliminate unnecessary register writes. Fixes: edffa33c7bb5 ("LoongArch: Add hardware breakpoints/watchpoints suppo= rt") Cc: stable@vger.kernel.org Signed-off-by: Tiezhu Yang --- arch/loongarch/kernel/hw_breakpoint.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/loongarch/kernel/hw_breakpoint.c b/arch/loongarch/kernel/= hw_breakpoint.c index 6ba7315852f3..bd891b3808a6 100644 --- a/arch/loongarch/kernel/hw_breakpoint.c +++ b/arch/loongarch/kernel/hw_breakpoint.c @@ -453,7 +453,6 @@ static void update_bp_registers(struct pt_regs *regs, i= nt enable, int type) if (enable) { if ((info->ctrl.type =3D=3D LOONGARCH_BREAKPOINT_EXECUTE) && (type =3D= =3D 0)) { write_wb_reg(CSR_CFG_CTRL, i, 0, CTRL_PLV_ENABLE); - write_wb_reg(CSR_CFG_CTRL, i, 0, CTRL_PLV_ENABLE); } else { ctrl =3D read_wb_reg(CSR_CFG_CTRL, i, 1); if (info->ctrl.type =3D=3D LOONGARCH_BREAKPOINT_LOAD) --=20 2.42.0 From nobody Thu Sep 24 13:44:22 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 095E943991A for ; Wed, 23 Sep 2026 05:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142916; cv=none; b=K0BlwKe/SQlmuO/y8NCjnYgS0R6299hPO5/YcBegwfAN82E8YHAKbhGdirt92xoqcHnpjUlMj7MfBCqO5II60xE2hrmhVSuKP4u30VjcQx6jisWwyBKLQZrfshMOCFsmgaBtUeeNu1tXDyxIafVavYa8nLk6Q+SzE+DDO83oDbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142916; c=relaxed/simple; bh=7udMkiSJsNGfAumk7yLV2lOLODDFfYghRIte5/70ZI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QMoTAt4qUWtGYXSpWBlLDVvStrAcZj9UEukMfaYGJv43E1+QEJBDxGD3v44OiAzrx1Ii0IAXtRxhyuqv4PyA9typsoMOQf6WXR8QD2L5+Il0QO4ERu/dJr84I/1uZFM+CC/wvLKblhw2MCYZ5ewGe/i2n/8j2TiY4da4SsSJHHY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [123.138.236.242]) by gateway (Coremail) with SMTP id _____8BxLtO+abNqle0OAA--.43721S3; Wed, 23 Sep 2026 13:55:10 +0800 (CST) Received: from linux.localdomain (unknown [123.138.236.242]) by front1 (Coremail) with SMTP id qMiowJCx9cy7abNqphMkAA--.48859S5; Wed, 23 Sep 2026 13:55:10 +0800 (CST) From: Tiezhu Yang To: Huacai Chen Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/7] LoongArch: Fix architectural naming typo for CSR_FWPS_SKIP Date: Wed, 23 Sep 2026 13:55:02 +0800 Message-ID: <20260923055506.29221-4-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260923055506.29221-1-yangtiezhu@loongson.cn> References: <20260923055506.29221-1-yangtiezhu@loongson.cn> 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: qMiowJCx9cy7abNqphMkAA--.48859S5 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxArWxJry5KF15AryxKw1fZrc_yoW5Zryrpr nrZF95GrW8WFs7Gan8ta1rur47tFZ7Gw429anYk3yS9F47X34rJF109rnrXF15Xw4rX34F qFnYkw1jgFyUA3XCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE 14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8l38UUUUUU== Content-Type: text/plain; charset="utf-8" According to the LoongArch Reference Manual, the single-step 'Skip' bit resides in the instruction breakpoint status register CSR.FWPS, rather than the configuration register CSR.FWPC. Furthermore, the kernel code comments also explicitly document it as "CSR.FWPS.Skip", yet the actual macro was erroneously defined as CSR_FWPC_SKIP and used as such in traps.c and hw_breakpoint.c. This mismatch creates architectural naming confusion. Fix this by renaming the macro from CSR_FWPC_SKIP to CSR_FWPS_SKIP to precisely match the manual and comments. Also, update all call sites to align with the rectified definition. Fixes: 424421a7f34c ("LoongArch: ptrace: Add hardware single step support") Cc: stable@vger.kernel.org Signed-off-by: Tiezhu Yang --- arch/loongarch/include/asm/loongarch.h | 4 ++-- arch/loongarch/kernel/hw_breakpoint.c | 2 +- arch/loongarch/kernel/traps.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/loongarch/include/asm/loongarch.h b/arch/loongarch/includ= e/asm/loongarch.h index 2a6bc99177d8..32bbff337c5c 100644 --- a/arch/loongarch/include/asm/loongarch.h +++ b/arch/loongarch/include/asm/loongarch.h @@ -1130,8 +1130,8 @@ #define LOONGARCH_CSR_DERA 0x501 /* debug era */ #define LOONGARCH_CSR_DESAVE 0x502 /* debug save */ =20 -#define CSR_FWPC_SKIP_SHIFT 16 -#define CSR_FWPC_SKIP (_ULCAST_(1) << CSR_FWPC_SKIP_SHIFT) +#define CSR_FWPS_SKIP_SHIFT 16 +#define CSR_FWPS_SKIP (_ULCAST_(1) << CSR_FWPS_SKIP_SHIFT) =20 /* * CSR_ECFG IM diff --git a/arch/loongarch/kernel/hw_breakpoint.c b/arch/loongarch/kernel/= hw_breakpoint.c index bd891b3808a6..7f69cf361a5e 100644 --- a/arch/loongarch/kernel/hw_breakpoint.c +++ b/arch/loongarch/kernel/hw_breakpoint.c @@ -550,7 +550,7 @@ void hw_breakpoint_thread_switch(struct task_struct *ne= xt) addr =3D read_wb_reg(CSR_CFG_ADDR, 0, 0); mask =3D read_wb_reg(CSR_CFG_MASK, 0, 0); if (!((regs->csr_era ^ addr) & ~mask)) - csr_write32(CSR_FWPC_SKIP, LOONGARCH_CSR_FWPS); + csr_write32(CSR_FWPS_SKIP, LOONGARCH_CSR_FWPS); regs->csr_prmd |=3D CSR_PRMD_PWE; } else { /* Update breakpoints */ diff --git a/arch/loongarch/kernel/traps.c b/arch/loongarch/kernel/traps.c index 776523747ea3..c4d7e55fb3ea 100644 --- a/arch/loongarch/kernel/traps.c +++ b/arch/loongarch/kernel/traps.c @@ -829,7 +829,7 @@ asmlinkage void noinstr do_watch(struct pt_regs *regs) * instruction. So don't clear llbit and reset CSR.FWPS.Skip until * the llsc execution is completed. */ - csr_write32(CSR_FWPC_SKIP, LOONGARCH_CSR_FWPS); + csr_write32(CSR_FWPS_SKIP, LOONGARCH_CSR_FWPS); csr_write32(CSR_LLBCTL_KLO, LOONGARCH_CSR_LLBCTL); goto out; } @@ -846,7 +846,7 @@ asmlinkage void noinstr do_watch(struct pt_regs *regs) * current pc, If yes, then we should not set the CSR.FWPS.SKIP * bit to break the original instruction stream. */ - csr_write32(CSR_FWPC_SKIP, LOONGARCH_CSR_FWPS); + csr_write32(CSR_FWPS_SKIP, LOONGARCH_CSR_FWPS); goto out; } } --=20 2.42.0 From nobody Thu Sep 24 13:44:22 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 300D743B6C9 for ; Wed, 23 Sep 2026 05:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142914; cv=none; b=QA+P4Nuwi1Tw7WZhSkiMFTO8gUsdjSp/PV02LZrOjCIPiq//V971Afqv7ywmOH57Ja7PtJJzVtcdzZtvShdNNb5Sef4dnT59bPES0vDiF++sikDPJjuWbK+8wsnx9TEv8EqVDSZm1sBTpVIWwjKlK67PnKk7sn1vdHUzu8pzXwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142914; c=relaxed/simple; bh=gP1hbo0fXBOIR/xuHFNmPZCAZbNpdADMI1YaB4qZt5I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OblV+8/iHjzjVyIFFYHDVtVSyFfX5BT0g/rAUZ/6DWFPbRtS35q/N8K6qOTNGTonHd1kBaSZFUPrLSWV1APz3mnKVTkIljc8HfAwdTk9dXMYBLo85w6rrxUIncyFQC4CdHXKOB8/6BTJKNtT2jY7KswHcBIExgAsUALN9otuxHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [123.138.236.242]) by gateway (Coremail) with SMTP id _____8DxpvC+abNqme0OAA--.43946S3; Wed, 23 Sep 2026 13:55:10 +0800 (CST) Received: from linux.localdomain (unknown [123.138.236.242]) by front1 (Coremail) with SMTP id qMiowJCx9cy7abNqphMkAA--.48859S6; Wed, 23 Sep 2026 13:55:10 +0800 (CST) From: Tiezhu Yang To: Huacai Chen Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/7] LoongArch: Only send SIGTRAP signal if necessary in do_watch() Date: Wed, 23 Sep 2026 13:55:03 +0800 Message-ID: <20260923055506.29221-5-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260923055506.29221-1-yangtiezhu@loongson.cn> References: <20260923055506.29221-1-yangtiezhu@loongson.cn> 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: qMiowJCx9cy7abNqphMkAA--.48859S6 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxXw45AF4xKry3uFyfJr4DJrc_yoWrtw48pF ZruFn3KrWDGr1ku3W3Gw4Dur43Grs5uw47u34Sy34F9rs0grWrJrn2yFnFqFW5W3s8Xa40 qF1Yq3WS9a1UXwbCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE 14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07j5l1kUUUUU= Content-Type: text/plain; charset="utf-8" In do_watch(), the kernel unconditionally forces a SIGTRAP signal at the end of the handler via force_sig(SIGTRAP). This is essential for ptrace operations, but it severely disrupts standard perf_event usage. Under normal perf usage, it is not necessary to force a SIGTRAP signal on every hit. Forcing it unnecessarily aborts the target process if no user-space signal handler is registered, which violates performance monitoring behaviors and injects context switch overheads. However, a conditional check using only 'current->ptrace' would block legitimate user-requested signals when a perf_event is configured with 'attr.sigtrap =3D 1' for asynchronous user-space tracking. Fix this by refactoring breakpoint_handler() and watchpoint_handler() to return a boolean status indicating whether any triggered breakpoint explicitly requires a signal notification. Update do_watch() to enforce the SIGTRAP signal only when the process is actively being debugged via ptrace, or when the underlying perf_event infrastructure specifically demands it via 'attr.sigtrap'. Fixes: 424421a7f34c ("LoongArch: ptrace: Add hardware single step support") Cc: stable@vger.kernel.org Signed-off-by: Tiezhu Yang --- arch/loongarch/include/asm/hw_breakpoint.h | 4 ++-- arch/loongarch/kernel/hw_breakpoint.c | 18 ++++++++++++++++-- arch/loongarch/kernel/traps.c | 8 +++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/arch/loongarch/include/asm/hw_breakpoint.h b/arch/loongarch/in= clude/asm/hw_breakpoint.h index 5faa97a87a9e..d202052df8a1 100644 --- a/arch/loongarch/include/asm/hw_breakpoint.h +++ b/arch/loongarch/include/asm/hw_breakpoint.h @@ -116,8 +116,8 @@ extern void arch_uninstall_hw_breakpoint(struct perf_ev= ent *bp); extern int hw_breakpoint_slots(int type); extern void hw_breakpoint_pmu_read(struct perf_event *bp); =20 -void breakpoint_handler(struct pt_regs *regs); -void watchpoint_handler(struct pt_regs *regs); +bool breakpoint_handler(struct pt_regs *regs); +bool watchpoint_handler(struct pt_regs *regs); =20 #ifdef CONFIG_HAVE_HW_BREAKPOINT extern void ptrace_hw_copy_thread(struct task_struct *task); diff --git a/arch/loongarch/kernel/hw_breakpoint.c b/arch/loongarch/kernel/= hw_breakpoint.c index 7f69cf361a5e..3683a52b2368 100644 --- a/arch/loongarch/kernel/hw_breakpoint.c +++ b/arch/loongarch/kernel/hw_breakpoint.c @@ -482,10 +482,11 @@ NOKPROBE_SYMBOL(update_bp_registers); /* * Debug exception handlers. */ -void breakpoint_handler(struct pt_regs *regs) +bool breakpoint_handler(struct pt_regs *regs) { int i; struct perf_event *bp, **slots; + bool need_sigtrap =3D false; =20 slots =3D this_cpu_ptr(bp_on_reg); =20 @@ -494,18 +495,25 @@ void breakpoint_handler(struct pt_regs *regs) bp =3D slots[i]; if (bp =3D=3D NULL) continue; + perf_bp_event(bp, regs); + if (bp->attr.sigtrap) + need_sigtrap =3D true; + csr_write32(0x1 << i, LOONGARCH_CSR_FWPS); update_bp_registers(regs, 0, 0); } } + + return need_sigtrap; } NOKPROBE_SYMBOL(breakpoint_handler); =20 -void watchpoint_handler(struct pt_regs *regs) +bool watchpoint_handler(struct pt_regs *regs) { int i; struct perf_event *wp, **slots; + bool need_sigtrap =3D false; =20 slots =3D this_cpu_ptr(wp_on_reg); =20 @@ -514,11 +522,17 @@ void watchpoint_handler(struct pt_regs *regs) wp =3D slots[i]; if (wp =3D=3D NULL) continue; + perf_bp_event(wp, regs); + if (wp->attr.sigtrap) + need_sigtrap =3D true; + csr_write32(0x1 << i, LOONGARCH_CSR_MWPS); update_bp_registers(regs, 0, 1); } } + + return need_sigtrap; } NOKPROBE_SYMBOL(watchpoint_handler); =20 diff --git a/arch/loongarch/kernel/traps.c b/arch/loongarch/kernel/traps.c index c4d7e55fb3ea..4cbf84b148cd 100644 --- a/arch/loongarch/kernel/traps.c +++ b/arch/loongarch/kernel/traps.c @@ -811,6 +811,7 @@ asmlinkage void noinstr do_bp(struct pt_regs *regs) asmlinkage void noinstr do_watch(struct pt_regs *regs) { irqentry_state_t state =3D irqentry_enter(regs); + bool need_sigtrap =3D !!current->ptrace; =20 #ifndef CONFIG_HAVE_HW_BREAKPOINT pr_warn("Hardware watch point handler not implemented!\n"); @@ -851,11 +852,12 @@ asmlinkage void noinstr do_watch(struct pt_regs *regs) } } } else { - breakpoint_handler(regs); - watchpoint_handler(regs); + need_sigtrap |=3D breakpoint_handler(regs); + need_sigtrap |=3D watchpoint_handler(regs); } =20 - force_sig(SIGTRAP); + if (need_sigtrap) + force_sig(SIGTRAP); out: #endif irqentry_exit(regs, state); --=20 2.42.0 From nobody Thu Sep 24 13:44:22 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 387D443C7B1 for ; Wed, 23 Sep 2026 05:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142915; cv=none; b=fYUwboquzpEwTLL5MXpAbtK3+eGBuUjm+6Wxck00ljGqoFUcIqXehvKfTJV3tGCafeVSMOkhl9UbxSJI4wxztcjktNlsKwQ7k7asGBMl1PavxI6WyVA9Msipib3PSSEfOt9aFcA3rWacZqAUvvQYiFsXWH3Z3B/LqZOrEDkPVZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142915; c=relaxed/simple; bh=H+qJAKye2VwOk6NjMOsoAlqoEDHxgsJEC/6qIC9WV5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jb4P4pn4IOdW3ISjVKGM4nk7MHPxFrIoXVI1jWzlfEoHtjYVoHemMsAm0xTigMSO6xM8HIKy+JUDp8yrBEWYgqunU/wkN6WID0n6NRlpS8yqDUJtP1eFfUBPxaJD106WcFb8ciclhIbPRCinVjjTpbYtTb5yUcTtS/+Cx/ALSnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [123.138.236.242]) by gateway (Coremail) with SMTP id _____8DxTNK_abNqnO0OAA--.43374S3; Wed, 23 Sep 2026 13:55:11 +0800 (CST) Received: from linux.localdomain (unknown [123.138.236.242]) by front1 (Coremail) with SMTP id qMiowJCx9cy7abNqphMkAA--.48859S7; Wed, 23 Sep 2026 13:55:11 +0800 (CST) From: Tiezhu Yang To: Huacai Chen Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/7] LoongArch: Fix perf hardware breakpoint failure via installation Date: Wed, 23 Sep 2026 13:55:04 +0800 Message-ID: <20260923055506.29221-6-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260923055506.29221-1-yangtiezhu@loongson.cn> References: <20260923055506.29221-1-yangtiezhu@loongson.cn> 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: qMiowJCx9cy7abNqphMkAA--.48859S7 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxJw1xGw13ZF13Ar4UKrWfWFX_yoW5Gw1Upr ZrAF1vqrW5J3y7G3Zrtan8Aw15JrZru3y7W34akrWYy3ZFvr13tFs29FnrXF18A39Yqa40 gr1kWr1SvF4UXabCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE 14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07josjUUUUUU= Content-Type: text/plain; charset="utf-8" In hw_breakpoint_control(), the logic to enable CSR_PRMD_PWE (global watchpoint enable) incorrectly relies on TIF_LOAD_WATCH. This thread flag is only set during ptrace operations, meaning that the standard hardware breakpoints created via perf_event_open() will never have this flag set. As a result, the CSR_PRMD_PWE switch is skipped, leaving the hardware breakpoint completely inactive in perf usage. Fix this by decoupling the CSR_PRMD_PWE from the ptrace specific flag TIF_LOAD_WATCH, which ensures that CSR_PRMD_PWE is enabled whenever a hardware breakpoint is installed. Here is a user-space reproducer to demonstrate the issue: (1) Test program (test_perf_install.c): #include #include #include #include #include #include static int var =3D 0; int main(void) { size_t count =3D 0; struct perf_event_attr attr =3D { .type =3D PERF_TYPE_BREAKPOINT, .size =3D sizeof(attr), .bp_type =3D HW_BREAKPOINT_W, .bp_addr =3D (unsigned long)&var, .bp_len =3D HW_BREAKPOINT_LEN_1, .exclude_kernel =3D 1, }; int fd =3D syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0); ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); asm volatile("st.b %1, %0" : "=3Dm"(var) : "r"(11) : "memory"); ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); read(fd, &count, sizeof(size_t)); printf("Watchpoint counts: expected =3D 1, actual =3D %zu\n", count); close(fd); return 0; } (2) Test steps: $ gcc test_perf_install.c -o test_perf_install $ ./test_perf_install (3) Test results: Without this patch: Watchpoint counts: expected =3D 1, actual =3D 0 With this patch: Watchpoint counts: expected =3D 1, actual =3D 1 Fixes: 3892b11eac5a ("LoongArch: Check TIF_LOAD_WATCH to enable user space = watchpoint") Cc: stable@vger.kernel.org Signed-off-by: Tiezhu Yang --- arch/loongarch/kernel/hw_breakpoint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/loongarch/kernel/hw_breakpoint.c b/arch/loongarch/kernel/= hw_breakpoint.c index 3683a52b2368..9dcb122218c2 100644 --- a/arch/loongarch/kernel/hw_breakpoint.c +++ b/arch/loongarch/kernel/hw_breakpoint.c @@ -233,7 +233,7 @@ static int hw_breakpoint_control(struct perf_event *bp, } enable =3D csr_read64(LOONGARCH_CSR_CRMD); csr_write64(CSR_CRMD_WE | enable, LOONGARCH_CSR_CRMD); - if (bp->hw.target && test_tsk_thread_flag(bp->hw.target, TIF_LOAD_WATCH)) + if (bp->hw.target) regs->csr_prmd |=3D CSR_PRMD_PWE; break; case HW_BREAKPOINT_UNINSTALL: --=20 2.42.0 From nobody Thu Sep 24 13:44:22 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8BB3243C7C2 for ; Wed, 23 Sep 2026 05:55:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142915; cv=none; b=KffzBCmeAFpzEmh+xprSnFcYjMj5cn0X0acPFGT3Lyj/40f8hyMv+oK5AKpfXNFzqjBSRUUXomjxeC1lIs0yS6lcwxJfRKpy3D6w9tCWowpm0ljK8ZqXcRK51arkBdQRCaFtGN1Uuqq7ri9WhOpv10/cvsSn81ZHX19c/infJVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142915; c=relaxed/simple; bh=ubI8nU68TcLfAsEaCAATmWbEBhfvxq+CKFd/wp8TRLM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Geq6AXaJItcJByUyGeBoF/ex/CSQ9GyRBgxHhG33fYBnpJ6vkhw+K0tb2d70bXpp2ZKppPQEMiMXQ7UISJEGjoBtwPtHwU33AC4gmBCubZajHzmzBA6MJlWqhyPdZu1V5lcTeuZkLwUtOTZfDZNhuSL4DhUkdCGtHFE7EU+0upw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [123.138.236.242]) by gateway (Coremail) with SMTP id _____8DxjdK_abNqn+0OAA--.43497S3; Wed, 23 Sep 2026 13:55:11 +0800 (CST) Received: from linux.localdomain (unknown [123.138.236.242]) by front1 (Coremail) with SMTP id qMiowJCx9cy7abNqphMkAA--.48859S8; Wed, 23 Sep 2026 13:55:11 +0800 (CST) From: Tiezhu Yang To: Huacai Chen Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/7] LoongArch: Fix thread_struct layout for hbp_break and hbp_watch Date: Wed, 23 Sep 2026 13:55:05 +0800 Message-ID: <20260923055506.29221-7-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260923055506.29221-1-yangtiezhu@loongson.cn> References: <20260923055506.29221-1-yangtiezhu@loongson.cn> 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: qMiowJCx9cy7abNqphMkAA--.48859S8 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxXF15KrW3ur47tFyrAw47GFX_yoWrtw4DpF 9rCw1ktr48Kr18uwnrJ3ykZr17trn7WF42ga43tayayr1qgw45XryvyFyDZFW5J3WF9a4I qrnIgws0ga1DAagCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1a6r1DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE 14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07Ul4E_UUUUU= Content-Type: text/plain; charset="utf-8" According to the architectural code comment in processor.h, FPU and vector registers must be located at the very end of the inherited context within struct thread_struct because they are conditionally copied during fork(). However, hbp_break and hbp_watch arrays were erroneously placed after the fpu and lbt fields. Due to the partial memcpy optimization which are used in arch_dup_task_struct(), the hardware breakpoint members were silently truncated and ignored during task duplication, accidentally relying on a subsequent ptrace_hw_copy_thread() to clear the uninitialized pointers with memset. Fix this by moving hbp_break and hbp_watch arrays up before the fpu field, strictly adhering to the established layout convention. This ensures state cloning boundaries via the native kernel memcpy. Then, remove the helper ptrace_hw_copy_thread() and its caller to clean up the code. Fixes: edffa33c7bb5 ("LoongArch: Add hardware breakpoints/watchpoints suppo= rt") Cc: stable@vger.kernel.org Signed-off-by: Tiezhu Yang --- arch/loongarch/include/asm/hw_breakpoint.h | 4 ---- arch/loongarch/include/asm/processor.h | 13 +++++++------ arch/loongarch/kernel/hw_breakpoint.c | 6 ------ arch/loongarch/kernel/process.c | 1 - 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/arch/loongarch/include/asm/hw_breakpoint.h b/arch/loongarch/in= clude/asm/hw_breakpoint.h index d202052df8a1..e7a6606c86cc 100644 --- a/arch/loongarch/include/asm/hw_breakpoint.h +++ b/arch/loongarch/include/asm/hw_breakpoint.h @@ -120,12 +120,8 @@ bool breakpoint_handler(struct pt_regs *regs); bool watchpoint_handler(struct pt_regs *regs); =20 #ifdef CONFIG_HAVE_HW_BREAKPOINT -extern void ptrace_hw_copy_thread(struct task_struct *task); extern void hw_breakpoint_thread_switch(struct task_struct *next); #else -static inline void ptrace_hw_copy_thread(struct task_struct *task) -{ -} static inline void hw_breakpoint_thread_switch(struct task_struct *next) { } diff --git a/arch/loongarch/include/asm/processor.h b/arch/loongarch/includ= e/asm/processor.h index ce8b953f8c79..94c5ce9b1d24 100644 --- a/arch/loongarch/include/asm/processor.h +++ b/arch/loongarch/include/asm/processor.h @@ -128,18 +128,19 @@ struct thread_struct { unsigned long trap_nr; unsigned long error_code; unsigned long single_step; /* Used by PTRACE_SINGLESTEP */ + struct loongarch_vdso_info *vdso; =20 + /* Hardware breakpoints pinned to this task. */ + struct perf_event *hbp_break[LOONGARCH_MAX_BRP]; + struct perf_event *hbp_watch[LOONGARCH_MAX_WRP]; + /* * FPU & vector registers, must be at the last of inherited * context because they are conditionally copied at fork(). */ struct loongarch_fpu fpu FPU_ALIGN; struct loongarch_lbt lbt; /* Also conditionally copied */ - - /* Hardware breakpoints pinned to this task. */ - struct perf_event *hbp_break[LOONGARCH_MAX_BRP]; - struct perf_event *hbp_watch[LOONGARCH_MAX_WRP]; }; =20 #define thread_saved_ra(tsk) (tsk->thread.sched_ra) @@ -173,6 +174,8 @@ struct thread_struct { */ \ .trap_nr =3D 0, \ .error_code =3D 0, \ + .hbp_break =3D {0}, \ + .hbp_watch =3D {0}, \ /* \ * FPU & vector registers \ */ \ @@ -182,8 +185,6 @@ struct thread_struct { .ftop =3D 0, \ .fpr =3D {{{0,},},}, \ }, \ - .hbp_break =3D {0}, \ - .hbp_watch =3D {0}, \ } =20 struct task_struct; diff --git a/arch/loongarch/kernel/hw_breakpoint.c b/arch/loongarch/kernel/= hw_breakpoint.c index 9dcb122218c2..1d881b2c2a50 100644 --- a/arch/loongarch/kernel/hw_breakpoint.c +++ b/arch/loongarch/kernel/hw_breakpoint.c @@ -154,12 +154,6 @@ static int hw_breakpoint_slot_setup(struct perf_event = **slots, int max_slots, return -ENOSPC; } =20 -void ptrace_hw_copy_thread(struct task_struct *tsk) -{ - memset(tsk->thread.hbp_break, 0, sizeof(tsk->thread.hbp_break)); - memset(tsk->thread.hbp_watch, 0, sizeof(tsk->thread.hbp_watch)); -} - /* * Unregister breakpoints from this task and reset the pointers in the thr= ead_struct. */ diff --git a/arch/loongarch/kernel/process.c b/arch/loongarch/kernel/proces= s.c index baa683fbfc53..199c951a2e27 100644 --- a/arch/loongarch/kernel/process.c +++ b/arch/loongarch/kernel/process.c @@ -226,7 +226,6 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) childregs->regs[2] =3D tls; =20 out: - ptrace_hw_copy_thread(p); clear_tsk_thread_flag(p, TIF_USEDFPU); clear_tsk_thread_flag(p, TIF_USEDSIMD); clear_tsk_thread_flag(p, TIF_USEDLBT); --=20 2.42.0 From nobody Thu Sep 24 13:44:22 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFEC943CE7F for ; Wed, 23 Sep 2026 05:55:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142916; cv=none; b=nBwNLYVfqwlvi4L6XrrtZBbo0h/J73tWNLLlf5uACs5rLFz+FSyjBH9f3/kJVtIh4QtYlpkyjIBSSG5wRXXk7GTM6NJcO3D01mfOP+s+uICfZMmck+8HOkEe+STEi/mIWlo1oWo67vMDcw6lmAmVmc1PSJl5CNF7mP55tbSjpQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790142916; c=relaxed/simple; bh=UpPsUD98cda34dA8MrwQ0wEf+kkVoVW2uvixgp8EJ78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sTZPj5S9JHPnYISV0L0Nrk4d3/Nm1He7bNqW1+dptqOi1Q0d082l3Oqd6sqrOUFCHBj4OhZP0GhZh3ZW/2nErKO2kOIQIUFnlRX5j5AjnUgOSwUc9CP3Vj8L0sUO5+xVwk8Tt6TKwIT6mbkfhj8tuw8P9LGD4docRQMnV93+zoA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [123.138.236.242]) by gateway (Coremail) with SMTP id _____8Bx79LAabNqou0OAA--.44098S3; Wed, 23 Sep 2026 13:55:12 +0800 (CST) Received: from linux.localdomain (unknown [123.138.236.242]) by front1 (Coremail) with SMTP id qMiowJCx9cy7abNqphMkAA--.48859S9; Wed, 23 Sep 2026 13:55:12 +0800 (CST) From: Tiezhu Yang To: Huacai Chen Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 7/7] LoongArch: Fix one-shot limitation for perf hardware breakpoints Date: Wed, 23 Sep 2026 13:55:06 +0800 Message-ID: <20260923055506.29221-8-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260923055506.29221-1-yangtiezhu@loongson.cn> References: <20260923055506.29221-1-yangtiezhu@loongson.cn> 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: qMiowJCx9cy7abNqphMkAA--.48859S9 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW3AF4fGr47Wr1xZF4DXw1kZwc_yoWfZFWrpF 9rAr1kKr40kr1fu3Zxtw4Dur43tFs7ua12qFyfKa4Syw1qgryfJFn2kF9rXFy5Xws5Wa4I qw1Skwsaga1UXabCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE 14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07josjUUUUUU= Content-Type: text/plain; charset="utf-8" In breakpoint_handler() and watchpoint_handler(), the code disables the hardware slot by executing update_bp_registers(regs, 0, ...). This design forces the active hardware breakpoint configuration to be wiped out upon its first hit, turning standard perf hardware breakpoints into "one-shot" events. Furthermore, while the ptrace single-step path in do_watch() executes a hardware single-step skip mechanism to advance the PC, the standard perf path lacks any mechanism to bypass the original triggering instruction. To maintain the long-term persistence of hardware breakpoints for perf usage, eliminate the disruptive calls to update_bp_registers() within the handler loops to keep the breakpoint configuration enabled. Concurrently, execute a single, unified register write outside the loop to atomize the state transition and explicitly enforce the hardware skip mechanism once per exception return, ensuring the processor safely steps forward without lockups. Meanwhile, in order to prevent status contamination during single-core context switches or cross-core thread migrations, the hardware register skip state of the previous thread is saved first. Then, the skip state is restored and its software skip flag is also cleared only if the next thread has the skip flag; otherwise, 0 is written to clear the FWPS and MWPS registers, which explicitly clears the skip bit according to the architectural specification. Additionally, explicitly clear hbp_break_skip and hbp_watch_skip inside copy_thread() during task creation. This guarantees that a newly cloned child task starts with a clean slate. Here is a user-space reproducer to demonstrate the issue. (1) Test program (test_perf_continuous.c): #include #include #include #include #include #include static int var =3D 0; int main(void) { size_t count =3D 0; struct perf_event_attr attr =3D { .type =3D PERF_TYPE_BREAKPOINT, .size =3D sizeof(attr), .bp_type =3D HW_BREAKPOINT_W, .bp_addr =3D (unsigned long)&var, .bp_len =3D HW_BREAKPOINT_LEN_1, .exclude_kernel =3D 1, }; int fd =3D syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0); ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); asm volatile("st.b %1, %0" : "=3Dm"(var) : "r"(11) : "memory"); asm volatile("st.b %1, %0" : "=3Dm"(var) : "r"(22) : "memory"); asm volatile("st.b %1, %0" : "=3Dm"(var) : "r"(33) : "memory"); ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); read(fd, &count, sizeof(size_t)); printf("Watchpoint counts: expected =3D 3, actual =3D %zu\n", count); close(fd); return 0; } (2) Test steps: $ gcc test_perf_continuous.c -o test_perf_continuous $ ./test_perf_continuous (3) Test results: Without this patch: Watchpoint counts: expected =3D 3, actual =3D 1 With this patch: Watchpoint counts: expected =3D 3, actual =3D 3 Fixes: 3eb2a8b23598 ("LoongArch: Fix multiple hardware watchpoint issues") Cc: stable@vger.kernel.org Signed-off-by: Tiezhu Yang --- arch/loongarch/include/asm/hw_breakpoint.h | 4 +-- arch/loongarch/include/asm/loongarch.h | 3 ++ arch/loongarch/include/asm/processor.h | 3 ++ arch/loongarch/include/asm/switch_to.h | 2 +- arch/loongarch/kernel/hw_breakpoint.c | 36 +++++++++++++++++++--- arch/loongarch/kernel/process.c | 3 ++ 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/arch/loongarch/include/asm/hw_breakpoint.h b/arch/loongarch/in= clude/asm/hw_breakpoint.h index e7a6606c86cc..16be0de90160 100644 --- a/arch/loongarch/include/asm/hw_breakpoint.h +++ b/arch/loongarch/include/asm/hw_breakpoint.h @@ -120,9 +120,9 @@ bool breakpoint_handler(struct pt_regs *regs); bool watchpoint_handler(struct pt_regs *regs); =20 #ifdef CONFIG_HAVE_HW_BREAKPOINT -extern void hw_breakpoint_thread_switch(struct task_struct *next); +extern void hw_breakpoint_thread_switch(struct task_struct *prev, struct t= ask_struct *next); #else -static inline void hw_breakpoint_thread_switch(struct task_struct *next) +static inline void hw_breakpoint_thread_switch(struct task_struct *prev, s= truct task_struct *next) { } #endif diff --git a/arch/loongarch/include/asm/loongarch.h b/arch/loongarch/includ= e/asm/loongarch.h index 32bbff337c5c..28eff8b49d1b 100644 --- a/arch/loongarch/include/asm/loongarch.h +++ b/arch/loongarch/include/asm/loongarch.h @@ -1133,6 +1133,9 @@ #define CSR_FWPS_SKIP_SHIFT 16 #define CSR_FWPS_SKIP (_ULCAST_(1) << CSR_FWPS_SKIP_SHIFT) =20 +#define CSR_MWPS_SKIP_SHIFT 16 +#define CSR_MWPS_SKIP (_ULCAST_(1) << CSR_MWPS_SKIP_SHIFT) + /* * CSR_ECFG IM */ diff --git a/arch/loongarch/include/asm/processor.h b/arch/loongarch/includ= e/asm/processor.h index 94c5ce9b1d24..cc1d1ed491eb 100644 --- a/arch/loongarch/include/asm/processor.h +++ b/arch/loongarch/include/asm/processor.h @@ -135,6 +135,9 @@ struct thread_struct { struct perf_event *hbp_break[LOONGARCH_MAX_BRP]; struct perf_event *hbp_watch[LOONGARCH_MAX_WRP]; =20 + bool hbp_break_skip; + bool hbp_watch_skip; + /* * FPU & vector registers, must be at the last of inherited * context because they are conditionally copied at fork(). diff --git a/arch/loongarch/include/asm/switch_to.h b/arch/loongarch/includ= e/asm/switch_to.h index 27acbf913774..ab9e0292c7f3 100644 --- a/arch/loongarch/include/asm/switch_to.h +++ b/arch/loongarch/include/asm/switch_to.h @@ -34,7 +34,7 @@ extern asmlinkage struct task_struct *__switch_to(struct = task_struct *prev, do { \ lose_fpu_inatomic(1, prev); \ lose_lbt_inatomic(1, prev); \ - hw_breakpoint_thread_switch(next); \ + hw_breakpoint_thread_switch(prev, next); \ set_current(next); \ (last) =3D __switch_to(prev, next, \ __builtin_return_address(0), __builtin_frame_address(0)); \ diff --git a/arch/loongarch/kernel/hw_breakpoint.c b/arch/loongarch/kernel/= hw_breakpoint.c index 1d881b2c2a50..3931a339ace6 100644 --- a/arch/loongarch/kernel/hw_breakpoint.c +++ b/arch/loongarch/kernel/hw_breakpoint.c @@ -481,6 +481,7 @@ bool breakpoint_handler(struct pt_regs *regs) int i; struct perf_event *bp, **slots; bool need_sigtrap =3D false; + unsigned int clear_mask =3D 0; =20 slots =3D this_cpu_ptr(bp_on_reg); =20 @@ -494,11 +495,13 @@ bool breakpoint_handler(struct pt_regs *regs) if (bp->attr.sigtrap) need_sigtrap =3D true; =20 - csr_write32(0x1 << i, LOONGARCH_CSR_FWPS); - update_bp_registers(regs, 0, 0); + clear_mask |=3D (0x1 << i); } } =20 + if (clear_mask) + csr_write32(clear_mask | CSR_FWPS_SKIP, LOONGARCH_CSR_FWPS); + return need_sigtrap; } NOKPROBE_SYMBOL(breakpoint_handler); @@ -508,6 +511,7 @@ bool watchpoint_handler(struct pt_regs *regs) int i; struct perf_event *wp, **slots; bool need_sigtrap =3D false; + unsigned int clear_mask =3D 0; =20 slots =3D this_cpu_ptr(wp_on_reg); =20 @@ -521,11 +525,13 @@ bool watchpoint_handler(struct pt_regs *regs) if (wp->attr.sigtrap) need_sigtrap =3D true; =20 - csr_write32(0x1 << i, LOONGARCH_CSR_MWPS); - update_bp_registers(regs, 0, 1); + clear_mask |=3D (0x1 << i); } } =20 + if (clear_mask) + csr_write32(clear_mask | CSR_MWPS_SKIP, LOONGARCH_CSR_MWPS); + return need_sigtrap; } NOKPROBE_SYMBOL(watchpoint_handler); @@ -549,7 +555,7 @@ static int __init arch_hw_breakpoint_init(void) } arch_initcall(arch_hw_breakpoint_init); =20 -void hw_breakpoint_thread_switch(struct task_struct *next) +void hw_breakpoint_thread_switch(struct task_struct *prev, struct task_str= uct *next) { u64 addr, mask; struct pt_regs *regs =3D task_pt_regs(next); @@ -561,6 +567,26 @@ void hw_breakpoint_thread_switch(struct task_struct *n= ext) csr_write32(CSR_FWPS_SKIP, LOONGARCH_CSR_FWPS); regs->csr_prmd |=3D CSR_PRMD_PWE; } else { + unsigned int fwps =3D csr_read32(LOONGARCH_CSR_FWPS); + unsigned int mwps =3D csr_read32(LOONGARCH_CSR_MWPS); + + prev->thread.hbp_break_skip =3D !!(fwps & CSR_FWPS_SKIP); + prev->thread.hbp_watch_skip =3D !!(mwps & CSR_MWPS_SKIP); + + if (next->thread.hbp_break_skip) { + csr_write32(CSR_FWPS_SKIP, LOONGARCH_CSR_FWPS); + next->thread.hbp_break_skip =3D 0; + } else { + csr_write32(0, LOONGARCH_CSR_FWPS); + } + + if (next->thread.hbp_watch_skip) { + csr_write32(CSR_MWPS_SKIP, LOONGARCH_CSR_MWPS); + next->thread.hbp_watch_skip =3D 0; + } else { + csr_write32(0, LOONGARCH_CSR_MWPS); + } + /* Update breakpoints */ update_bp_registers(regs, 1, 0); /* Update watchpoints */ diff --git a/arch/loongarch/kernel/process.c b/arch/loongarch/kernel/proces= s.c index 199c951a2e27..5e17e68e495a 100644 --- a/arch/loongarch/kernel/process.c +++ b/arch/loongarch/kernel/process.c @@ -226,6 +226,9 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) childregs->regs[2] =3D tls; =20 out: + p->thread.hbp_break_skip =3D 0; + p->thread.hbp_watch_skip =3D 0; + clear_tsk_thread_flag(p, TIF_USEDFPU); clear_tsk_thread_flag(p, TIF_USEDSIMD); clear_tsk_thread_flag(p, TIF_USEDLBT); --=20 2.42.0