From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D12FCC54F5F for ; Fri, 20 Feb 2026 06:40:13 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4fHLGB6HDnz3blq; Fri, 20 Feb 2026 17:40:02 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1771569602; cv=none; b=Si4Q1Ta5wA6DvK2VpZ040CLRtAPprqsr73JqGsPWrS8LqauFfaeQr9ZolU5pxaQVGRJRu0E4Z0UAt3Moy7c70nKGCPMexggceiPkXT+voUUtqK2ern+s7I8P6vnqZX5mgpSJMCSHKk0qtl7S3K0vgiboZMOtInOHK3j0qshB8Vf4f0uqeFObZ4266H0xOlA3rxg7NWQTaiXtWSl/tCgKbaUQcFHO1VBtv4pP49vJDDfqVYTz13l5oCi1glRDdQNmKRHRoivhO4MqhkZ4fHcy/pJz3CcSh3vRxi3pXOE22uAT2GOENNrMxgef9h6ozqkjzUQWk53lRCMNOwAE8c90XA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1771569602; c=relaxed/relaxed; bh=Bq8IG/eAD9NL91GRpyrsVgxA2NfICIGiZH9MeDSpdIc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HvEFle4q4wq7pFyvVHqOTff9HYRc2fEa3LETuonzXxwOnwVJAJkWYagIHrefSeBAvAExbehSjYsFBHoxWA1t53G3LB+uRjha4aGQfJXEIEjOGIUy/2aRIHN9OD2oHzBQrsTZji8nyzWeJYr+712icSJ18sTIpG1HSi61thQ6lnRTkFOdR8VUSAFCqGI8VFORDXpPtTL5c0ixTUYkC6vvGovVm/snMV/h+mEvoK4vU39QXJZVF9+kis7ebn+kRh5KupPxxp7llc8GTpi/nSgRe6R5Db9VPm7D7iMKMWIJ/B9guI1q9neBfO8gdTsjUMqqOfnMMY8Haqg1T4WpPhSzGQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=AQ9+JGvL; dkim-atps=neutral; spf=pass (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=hbathini@linux.ibm.com; receiver=lists.ozlabs.org) smtp.mailfrom=linux.ibm.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=AQ9+JGvL; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=hbathini@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4fHLG95M0pz2yrl for ; Fri, 20 Feb 2026 17:40:01 +1100 (AEDT) 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> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list 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