From nobody Sun Dec 14 12:13:37 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 313342472BB; Fri, 12 Dec 2025 09:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765530703; cv=none; b=qqKtulCU+Hvo+fknLhceSTITxetQ1Q1DSTo53qlinm7qfMybmwDfIL5WvHN0PHIZExi7xI0eKdrMVIrqiot2nVwQzXMvkFmHtVfLKOeVJlg/WmWcFFlFi6IujrnPA0xeOl2qHREVE0ggdHac1pOXf4HVGz2/IyMWZTTU6TmPeeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765530703; c=relaxed/simple; bh=YZxv64z8zfjwzPiaNGn9d7vJpexUUc1szKq1qYZqUm4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=qKZ9IqV8ts3Bj5SX1kROes0AZwhOMY9Xuyqxl4IM9eegC1hS2+Z1E7tLAV/OZbCmHnT2S8gzpnTL5XXCByRslt8dbdFvd4QvDYJm5gLHfKboLLw3UQe4mGi5hyRUyzMvhb83tEPbBxgwqFgXwJenwlrkmHvVHSHyshmrdSXuDOM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 8e8df06cd73a11f0a38c85956e01ac42-20251212 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NO_NAME, HR_CTE_8B, HR_CTT_TXT HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME, HR_SJ_DIGIT_LEN HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM, HR_SJ_PHRASE HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT, HR_TO_NO_NAME IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_EXISTED, SN_EXISTED SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.6,REQID:b5724c42-6bbf-46da-af32-6faa38d1c5d1,IP:10,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:-5,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:5 X-CID-INFO: VERSION:1.3.6,REQID:b5724c42-6bbf-46da-af32-6faa38d1c5d1,IP:10,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:-5,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:5 X-CID-META: VersionHash:a9d874c,CLOUDID:cf15b60178dee43c82a92e6904d1af61,BulkI D:2512121711352WU4DBTV,BulkQuantity:0,Recheck:0,SF:17|19|38|66|78|81|82|10 2|127|850|898,TC:nil,Content:0|15|50,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bu lk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR: 0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 8e8df06cd73a11f0a38c85956e01ac42-20251212 X-User: duanchenghao@kylinos.cn Received: from localhost.localdomain [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1394514414; Fri, 12 Dec 2025 17:11:34 +0800 From: Chenghao Duan To: yangtiezhu@loongson.cn, hengqi.chen@gmail.com, chenhuacai@kernel.org Cc: kernel@xen0n.name, zhangtianyang@loongson.cn, masahiroy@kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, bpf@vger.kernel.org, duanchenghao@kylinos.cn, youling.tang@linux.dev, jianghaoran@kylinos.cn, vincent.mc.li@gmail.com Subject: [PATCH v2 4/4] LoongArch: BPF: Enable BPF exception fixup for specific ADE subcode Date: Fri, 12 Dec 2025 17:11:03 +0800 Message-Id: <20251212091103.1247753-5-duanchenghao@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251212091103.1247753-1-duanchenghao@kylinos.cn> References: <20251212091103.1247753-1-duanchenghao@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This patch allows the LoongArch BPF JIT to handle recoverable memory access errors generated by BPF_PROBE_MEM* instructions. When a BPF program performs memory access operations, the instructions it executes may trigger ADEM exceptions. The kernel=E2=80=99s built-in BPF exception table mechanism (EX_TYPE_BPF) will generate corresponding exception fixup entries in the JIT compilation phase; however, the architecture-specific trap handling function needs to proactively call the common fixup routine to achieve exception recovery. do_ade(): fix EX_TYPE_BPF memory access exceptions for BPF programs, ensure safe execution. Signed-off-by: Chenghao Duan --- arch/loongarch/kernel/traps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/kernel/traps.c b/arch/loongarch/kernel/traps.c index da5926fead4a..4cf72e0af6a3 100644 --- a/arch/loongarch/kernel/traps.c +++ b/arch/loongarch/kernel/traps.c @@ -534,7 +534,13 @@ asmlinkage void noinstr do_fpe(struct pt_regs *regs, u= nsigned long fcsr) =20 asmlinkage void noinstr do_ade(struct pt_regs *regs) { - irqentry_state_t state =3D irqentry_enter(regs); + irqentry_state_t state; + unsigned int esubcode =3D FIELD_GET(CSR_ESTAT_ESUBCODE, regs->csr_estat); + + if ((esubcode =3D=3D EXSUBCODE_ADEM) && fixup_exception(regs)) + return; + + state =3D irqentry_enter(regs); =20 die_if_kernel("Kernel ade access", regs); force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)regs->csr_badvaddr); --=20 2.25.1