From mboxrd@z Thu Jan 1 00:00:00 1970 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 3FE1A1E5B95; Wed, 10 Dec 2025 05:43:38 +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=1765345422; cv=none; b=Ax9+n7xtyeWmPIY2lEMuzi8I41wyrGk5MmGWXp7BHo0oh2lQ+TbNxfI+GGkU4xZrKIbwzzV/2IGbjfLcZH1ACvHYlSi26Ul+fhUgNgmV9VtkOpS8frzgK1E7X+FqLZEsnelvalL2JM0zyL7hQPYfHtzAVdnRnh+lNKRe6hLZ0g8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765345422; c=relaxed/simple; bh=qNZoakO16U34wR01PB4Qg01/NlG/0VnmWLcWkwOYTBs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u3SKBId7BrwJYo+DSp0mhQqjyNcOFnGJ4mZkJQ1rJguI41kLVNDLNDPo+qtdKGq6NVCXxa5SuX+0E4xxU9OhOvq7lhP6ycfKV/aD6MCQDHHj+sL9L8/bUdAiVHQMJ9e4pfoT4PSNBZ43+cycvwAAHpmFiT+i1mEEUktFakdOtsU= 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: 2967c218d58b11f0a38c85956e01ac42-20251210 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.6,REQID:eca14760-0523-4915-b2d0-318f6e88b630,IP:0,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:0 X-CID-META: VersionHash:a9d874c,CLOUDID:ea89d2c3f60e015b46fb4611da50d23c,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:80|81|82|83|102|850|898,TC:nil,Content:0 |15|50,EDM:-3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,O SI: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_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 2967c218d58b11f0a38c85956e01ac42-20251210 X-User: duanchenghao@kylinos.cn Received: from localhost [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1727498568; Wed, 10 Dec 2025 13:43:32 +0800 Date: Wed, 10 Dec 2025 13:43:29 +0800 From: Chenghao Duan To: Hengqi Chen Cc: yangtiezhu@loongson.cn, chenhuacai@kernel.org, kernel@xen0n.name, zhangtianyang@loongson.cn, masahiroy@kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, bpf@vger.kernel.org, guodongtai@kylinos.cn, youling.tang@linux.dev, jianghaoran@kylinos.cn, vincent.mc.li@gmail.com Subject: Re: [PATCH v1 2/2] LoongArch: Enable BPF exception fixup for specific ADE subcode Message-ID: <20251210054329.GA691118@chenghao-pc> References: <20251209093405.1309253-1-duanchenghao@kylinos.cn> <20251209093405.1309253-3-duanchenghao@kylinos.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Dec 10, 2025 at 01:20:12PM +0800, Hengqi Chen wrote: > On Tue, Dec 9, 2025 at 5:34 PM Chenghao Duan wrote: > > > > 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’s 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. > > > > Which bpf prog triggers this code path ? Why didn't we trigger it before ? module_attach and subprogs_extable trigger ADE exception via illegal address access in BPF programs, leading to kernel panic without this patch. > > > Signed-off-by: Chenghao Duan > > --- > > arch/loongarch/kernel/traps.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/arch/loongarch/kernel/traps.c b/arch/loongarch/kernel/traps.c > > index da5926fead4a..9ca8aacc82b8 100644 > > --- a/arch/loongarch/kernel/traps.c > > +++ b/arch/loongarch/kernel/traps.c > > @@ -534,8 +534,13 @@ asmlinkage void noinstr do_fpe(struct pt_regs *regs, unsigned long fcsr) > > > > asmlinkage void noinstr do_ade(struct pt_regs *regs) > > { > > - irqentry_state_t state = irqentry_enter(regs); > > + irqentry_state_t state; > > + unsigned int esubcode = FIELD_GET(CSR_ESTAT_ESUBCODE, regs->csr_estat); > > + > > + if ((esubcode == 1) && fixup_exception(regs)) > > + return; > > > > + state = irqentry_enter(regs); > > die_if_kernel("Kernel ade access", regs); > > force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)regs->csr_badvaddr); > > > > -- > > 2.25.1 > >