From mboxrd@z Thu Jan 1 00:00:00 1970 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 DCCEF32D7C7; Fri, 20 Feb 2026 06:40:03 +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=1771569605; cv=none; b=MidYF+ninlMRBZOLZPusCpBq1GXTgJToO6IX65gkKCuVuwTx2bRRaKR2wOnT6nXwrs5mn+C1gosF6Ru0Ckgn70ymkDeX1zDRaMbZ28cFy5Pv/Q9HRZAtl8KuSGCFQz+xaoiyFHKm6UAdW08HXs5XkASQHOvfqo4jA0BhIYoXXS4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771569605; c=relaxed/simple; bh=HrFJXHomVLDXIjck8cDzRJTBqLW6msrBn8ODXp4jAi4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oMpHhyI5iOtG2hbIk1pDrl0YTCC9z2DY7kM1fjq7qCDUWbsifQoCTpfV/eODMCZXVVrEprkqT37uxXny6O1saJOk+KqZJwzFto4PyGBJMcrgQZoZamWh4Q99zBdGM9JFASoSfXle8jYRv9qlkkajXlzDA0GjmHq6BHFHzPAliro= 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=AQ9+JGvL; 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="AQ9+JGvL" 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 61JKwYdc1294743; Fri, 20 Feb 2026 06:39:47 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=Bq8IG/eAD9NL91GRp yrsVgxA2NfICIGiZH9MeDSpdIc=; b=AQ9+JGvLB9EoUf9YiGV1/MYc/Mcd3aPZ2 SE3NNl4w89JmjhFh6mWp92UDMyLnj633fbvxK2wN7+odIywnW3ASzsb02zjPkiuN NgNS4OVvYraUE6+BGXGCQ9oOXaBmsMR+oGKk9Cn6APcfbRC6hyulV81eGyYGDdZ4 FiJ9kGpgo7Ehynp8dxgNVF/nsf4J7z6j36p3bb2554Fg56zy0inagb0VKMewuHJi eWAsA9c+gmSHBfoPtyvaYVhNUy+tBUSHN5Zc9YiVrt+oVDDX4MssYUyjvbb/yPiC +xwj8MszEWMJuvbj8entGpMADYr0gLaKLmHv+yQs7AEICnSRmMZ/Q== 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 4caj64gbsb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Feb 2026 06:39:47 +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 61K2uUma011906; Fri, 20 Feb 2026 06:39:46 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ccb277eaa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Feb 2026 06:39:46 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 61K6dgFM23003858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Feb 2026 06:39:42 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ABF7520040; Fri, 20 Feb 2026 06:39:42 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3A04B20043; Fri, 20 Feb 2026 06:39:40 +0000 (GMT) Received: from li-bd3f974c-2712-11b2-a85c-df1cec4d728e.ibm.com.com (unknown [9.43.64.63]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 20 Feb 2026 06:39:39 +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 v2 2/5] powerpc64/bpf: fix the address returned by bpf_get_func_ip Date: Fri, 20 Feb 2026 12:09:30 +0530 Message-ID: <20260220063933.196141-3-hbathini@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260220063933.196141-1-hbathini@linux.ibm.com> References: <20260220063933.196141-1-hbathini@linux.ibm.com> Precedence: bulk X-Mailing-List: stable@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: DryYHn0EyWsviBqyFwg0kus7AZMLUi5f X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjIwMDA1MiBTYWx0ZWRfX6MyV3XxF4M9W bI436LnL7SpZ4vhOx2J4vTzJMVVlMfNgEmp5p5kx5+QYVfAC8Q75YLTf4mxOeaipK5woh26dkO4 nGwHvvJKSYSJmhprJ1GOxAMtvSUuqNHpRYpkGmgquOR9UYBzuy6sHbe8JlYFyyiCMgcoVNZs/OR zGmMMOThGS8huEHT2jqpvDDkMCbC8yvQyr/bV5tJRzxpfU7zkql9UppyKEBRRSrWWYycObPOvqZ 5yOBsr/YgtRAY8KtLzdMIPU2Sd/Wb2YEV1dVpAy3v96cfTDRuGDcVJ81SMmc4tMcb7cfxhSlVkF cE+Eu6cQLKDR/rVLzvmKUCi/0yMTUaCzjKWaRbO4aeFet+0E9dgJoJUH3LK1d985a1MZkfvODBj wiU1fOlZgBAMgQJVUxLE4xBQjDFLS9QJBRZIeB0FYPvl30RH2puTqarnGe0GKmJDuf4OCbVayyg BMbdHWFfKYiZHF+aV6g== X-Proofpoint-GUID: DryYHn0EyWsviBqyFwg0kus7AZMLUi5f X-Authority-Analysis: v=2.4 cv=U+mfzOru c=1 sm=1 tr=0 ts=699801b3 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=VnNF1IyMAAAA:8 a=VwQbUJbxAAAA:8 a=SO5buJ7TJInmnl-hmdUA:9 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-02-19_06,2026-02-20_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 impostorscore=0 malwarescore=0 spamscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602200052 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 Signed-off-by: Hari Bathini --- * No changes since v1. arch/powerpc/net/bpf_jit_comp.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index 987cd9fb0f37..fb6cc1f832a8 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -786,8 +786,8 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im * [ reg argN ] * [ ... ] * regs_off [ reg_arg1 ] prog ctx context - * nregs_off [ args count ] - * ip_off [ traced function ] + * 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,29 @@ 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. + * Get 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. + * 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