Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 54989351C2B; Tue, 3 Mar 2026 18:11:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772561462; cv=none; b=GlguUukGcO2h2QezQct+L5weHMq33jAy5imwAOxU7qx3VRLrrBJ5O5BoyvPLWjtrVWEd09pYTVaMk3/DoedopRnrZlxcnaDCdrAW5hG5kkNnugJfxBw/LAjh525C8fg5A0jw205p4uTxIUNw462w9RuCjGfZtFYkBh1lbtR113A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772561462; c=relaxed/simple; bh=1731mYAiauXYMwG2IkxHMB7ML8u4OYoDTuTPIN4hzz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L0nVXsyDbDmlLYJHt3zkgF8+QAK8plPIndYQsadzA7mCezQf2gLXcDN62KxgpsKNIhZNlEECTeOEgejqENJ0Y3w3ZnFZ5ifrBdafH8pZ/0yFjqTvLpU7ZsgP716nG6LYATrA/ZPBSXCIk9I9XrbTwUgZS10eMM/gRNeKlSkFeps= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=SNi9UmcP; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="SNi9UmcP" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6236XO3w2187914; Tue, 3 Mar 2026 18:10:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=dAK54XFIR96iSXMBm b2UkdI3qVzIQAjEXQuI3WWOgB8=; b=SNi9UmcPvzIMbtFc0uM/umbyBza2w+UQv sQNGirjDvPrQ1K8ZiHJWIhRURnjjmB/yHuZkwgFYdtbRHeS/dgx8YIz8Ie5fUk33 zk+E/w2sgwNDz8atueC+u6f4Ffxc2XatNhyagxdymjsiS/73x8CmcuaGmMXLXCGy fgnsZFdPcUHFA+R4wLBgSzYdo3rUH/kacaHGP++a0S47LcJSWum02Mo+jMvOywDR 6B4S2iD2uC9Fw3DuoX/lvm4m2QcqGqf+2Cy/kVckkhsIrTogTwj8KI97hkl4bxBO OHwD96V4B8nWBEXMO8XucDbBREPpTmNr2+7l1vrgd+ztZfLgvxyIA== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4cksk3v086-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Mar 2026 18:10:44 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 623E5Dkx016397; Tue, 3 Mar 2026 18:10:43 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4cmbpn3fqs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Mar 2026 18:10:43 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 623IAdwh61735350 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Mar 2026 18:10:39 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 82E2E20040; Tue, 3 Mar 2026 18:10:39 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 35D4720043; Tue, 3 Mar 2026 18:10:37 +0000 (GMT) Received: from li-bd3f974c-2712-11b2-a85c-df1cec4d728e.ibm.com.com (unknown [9.43.53.81]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 3 Mar 2026 18:10:36 +0000 (GMT) From: Hari Bathini To: linuxppc-dev Cc: bpf@vger.kernel.org, Madhavan Srinivasan , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Saket Kumar Bhaskar , Abhishek Dubey , Venkat Rao Bagalkote , stable@vger.kernel.org Subject: [PATCH v4 2/6] powerpc64/bpf: fix the address returned by bpf_get_func_ip Date: Tue, 3 Mar 2026 23:40:26 +0530 Message-ID: <20260303181031.390073-3-hbathini@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260303181031.390073-1-hbathini@linux.ibm.com> References: <20260303181031.390073-1-hbathini@linux.ibm.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: kn2YKCYil4vbbqHFRkHb-kdLlM0hDkMF X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzAzMDE0NiBTYWx0ZWRfXzmmNsh//tuzt 7TBHysG90J1SF393We1V/WMot5+ProjoUpd7EdEy4tm/eBP3atQPGOsVMfMKTWtLoRNQOox1QhC uHdeXicRr17C5QKiZ2QOmCkRsWjZzR0jikmZI0JCOvl09SyJRrPdcnHJ+1hkLfy9eHPOhqjWwM2 yTg2GIjep4mHuOvhaAJ2xKJzVqVtDViFQ9MHYI7hs227WZfU7oWPu7p0yNv7dJuLYxcUJn20p0a zEdCESzGsa9/MRTLJd5se/X0Yvh8nXvl3Ud5Uy9bHfqUgA4WNzmK/Bp39Q7YcLHUJcXAQrPKLMp KxdAuz9+riggj0Jm4cxIxXdabLUZKj5UTlRpHXo3pUVySI/t9XfTUpyUuZz7QaBQV4epRBIhT7a CB8gadN1j87zwzU2IrBla9XihzM8SXmg4pJs0xfKCM5lW5FIGYVzKUzdTVpxTmX43ryw7PHjNOr jlV3hCe6McsCNei6Prw== X-Authority-Analysis: v=2.4 cv=csCWUl4i c=1 sm=1 tr=0 ts=69a72424 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=VwQbUJbxAAAA:8 a=dqEaXb2bD6BGsTbsOCIA:9 X-Proofpoint-GUID: kn2YKCYil4vbbqHFRkHb-kdLlM0hDkMF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-03_02,2026-03-03_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 adultscore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2603030146 bpf_get_func_ip() helper function returns the address of the traced function. It relies on the IP address stored at ctx - 16 by the bpf trampoline. On 64-bit powerpc, this address is recovered from LR accounting for OOL trampoline. But the address stored here was off by 4-bytes. Ensure the address is the actual start of the traced function. Reported-by: Abhishek Dubey Fixes: d243b62b7bd3 ("powerpc64/bpf: Add support for bpf trampolines") Cc: stable@vger.kernel.org Tested-by: Venkat Rao Bagalkote Signed-off-by: Hari Bathini --- * No changes in v4. Changes in v3: - Added Tested-by tag from Venkat. - Updated comments based on suggestions from Abhishek. arch/powerpc/net/bpf_jit_comp.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index 52162e4a7f84..95f208229b09 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -785,9 +785,9 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im * retval_off [ return value ] * [ reg argN ] * [ ... ] - * regs_off [ reg_arg1 ] prog ctx context - * nregs_off [ args count ] - * ip_off [ traced function ] + * regs_off [ reg_arg1 ] prog_ctx + * nregs_off [ args count ] ((u64 *)prog_ctx)[-1] + * ip_off [ traced function ] ((u64 *)prog_ctx)[-2] * [ ... ] * run_ctx_off [ bpf_tramp_run_ctx ] * [ reg argN ] @@ -895,7 +895,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im bpf_trampoline_save_args(image, ctx, func_frame_offset, nr_regs, regs_off); - /* Save our return address */ + /* Save our LR/return address */ EMIT(PPC_RAW_MFLR(_R3)); if (IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE)) EMIT(PPC_RAW_STL(_R3, _R1, alt_lr_off)); @@ -903,24 +903,34 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im EMIT(PPC_RAW_STL(_R3, _R1, bpf_frame_size + PPC_LR_STKOFF)); /* - * Save ip address of the traced function. - * We could recover this from LR, but we will need to address for OOL trampoline, - * and optional GEP area. + * Derive IP address of the traced function. + * In case of CONFIG_PPC_FTRACE_OUT_OF_LINE or BPF program, LR points to the instruction + * after the 'bl' instruction in the OOL stub. Refer to ftrace_init_ool_stub() and + * bpf_arch_text_poke() for OOL stub of kernel functions and bpf programs respectively. + * Relevant stub sequence: + * + * bl + * LR (R3) => mtlr r0 + * b + * + * Recover kernel function/bpf program address from the unconditional + * branch instruction at the end of OOL stub. */ if (IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE) || flags & BPF_TRAMP_F_IP_ARG) { EMIT(PPC_RAW_LWZ(_R4, _R3, 4)); EMIT(PPC_RAW_SLWI(_R4, _R4, 6)); EMIT(PPC_RAW_SRAWI(_R4, _R4, 6)); EMIT(PPC_RAW_ADD(_R3, _R3, _R4)); - EMIT(PPC_RAW_ADDI(_R3, _R3, 4)); } if (flags & BPF_TRAMP_F_IP_ARG) EMIT(PPC_RAW_STL(_R3, _R1, ip_off)); - if (IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE)) + if (IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE)) { /* Fake our LR for unwind */ + EMIT(PPC_RAW_ADDI(_R3, _R3, 4)); EMIT(PPC_RAW_STL(_R3, _R1, bpf_frame_size + PPC_LR_STKOFF)); + } /* Save function arg count -- see bpf_get_func_arg_cnt() */ EMIT(PPC_RAW_LI(_R3, nr_regs)); -- 2.53.0