From patchwork Tue Feb 8 05:16:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738176 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E709C4167D for ; Tue, 8 Feb 2022 05:33:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231598AbiBHFdF (ORCPT ); Tue, 8 Feb 2022 00:33:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231826AbiBHFRH (ORCPT ); Tue, 8 Feb 2022 00:17:07 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40442C0401DC for ; Mon, 7 Feb 2022 21:17:06 -0800 (PST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2183kfFD024697; Tue, 8 Feb 2022 05:16:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=+LjoE0NZmu4eTgC5xdsneOk1/jfO4/mdoy6UnZQR+Ic=; b=g+W0u+8gnVA22WOwj2TlZTrSADsqgubramFzyA4CezgeNw3pydo6evhQr+4F2IYXMmHD cq783MSukwMk0qeGfDEpt3QAHIa5mA2OT04wc0DrAx2M5tBrflkGZlvmRuoh1U6K1SK0 3I6raDVrCV5IIUCyjM8zjjDsiSRfo1PLZLQzZX+sww55Stp2mgeiLpZ0YmNQY0WckUnt NsBJosIv/edBC3zuvCimh03C9XCN8By1Xq/RB35K37dV3aUYOFUt/3c2PyBy1e5wVCHN PM+PzMzbl//X9RNkEEW0vQe31w8X7+w0tEqVy/bsTBe3XA214FJqEudD2fJdjRWQrXg/ dQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22vm7jut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:46 +0000 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21856Rb2007777; Tue, 8 Feb 2022 05:16:46 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22vm7jua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:46 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185Cmb8027187; Tue, 8 Feb 2022 05:16:44 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04fra.de.ibm.com with ESMTP id 3e2ygq0a8x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:44 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21856Y8W33423648 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:06:34 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EC5B311C04A; Tue, 8 Feb 2022 05:16:38 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 627E111C050; Tue, 8 Feb 2022 05:16:38 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:38 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 01/14] selftests/bpf: Fix an endianness issue in bpf_syscall_macro test Date: Tue, 8 Feb 2022 06:16:22 +0100 Message-Id: <20220208051635.2160304-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Ksisi07XxLHbPAlOtypoxnTqCa43V7TW X-Proofpoint-ORIG-GUID: LDValFMcSf8JvQC1LJSYhuGLTurJnu17 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 bulkscore=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 phishscore=0 suspectscore=0 priorityscore=1501 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net bpf_syscall_macro reads a long argument into an int variable, which produces a wrong value on big-endian systems. Fix by reading the argument into an intermediate long variable first. Fixes: 77fc0330dfe5 ("selftests/bpf: Add a test to confirm PT_REGS_PARM4_SYSCALL") Signed-off-by: Ilya Leoshkevich --- tools/testing/selftests/bpf/progs/bpf_syscall_macro.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c b/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c index c8e60220cda8..f5c6ef2ff6d1 100644 --- a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c +++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c @@ -28,6 +28,7 @@ int BPF_KPROBE(handle_sys_prctl) { struct pt_regs *real_regs; pid_t pid = bpf_get_current_pid_tgid() >> 32; + unsigned long tmp; if (pid != filter_pid) return 0; @@ -35,7 +36,9 @@ int BPF_KPROBE(handle_sys_prctl) real_regs = (struct pt_regs *)PT_REGS_PARM1(ctx); /* test for PT_REGS_PARM */ - bpf_probe_read_kernel(&arg1, sizeof(arg1), &PT_REGS_PARM1_SYSCALL(real_regs)); + + bpf_probe_read_kernel(&tmp, sizeof(tmp), &PT_REGS_PARM1_SYSCALL(real_regs)); + arg1 = tmp; bpf_probe_read_kernel(&arg2, sizeof(arg2), &PT_REGS_PARM2_SYSCALL(real_regs)); bpf_probe_read_kernel(&arg3, sizeof(arg3), &PT_REGS_PARM3_SYSCALL(real_regs)); bpf_probe_read_kernel(&arg4_cx, sizeof(arg4_cx), &PT_REGS_PARM4(real_regs)); From patchwork Tue Feb 8 05:16:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738171 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F8F7C433FE for ; Tue, 8 Feb 2022 05:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245477AbiBHFcp (ORCPT ); Tue, 8 Feb 2022 00:32:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231859AbiBHFRI (ORCPT ); Tue, 8 Feb 2022 00:17:08 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 388FDC0401ED for ; Mon, 7 Feb 2022 21:17:07 -0800 (PST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21825G8B026074; Tue, 8 Feb 2022 05:16:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=3SxgNsDeQ7rBzsM6xPJZIocw9r9nx9vPWrpummsON18=; b=GTWRacssjebveXFaptOLwkFs96vkxo20khmM0IxxVC6+zROdTDy/FuopetG91QEuuQ1G kvIpxNKGr+SZhp8INkV2JbdbztCN7kYoc58lh/c7vibAD7oQXc676txY/Q8eZFG3U5FR jmwxR9wBh179x1AYxL4QQYKAauSDaH/7dG30N8KWus1Rppg4AXb7UPtlP/Q12T5+dq/u azfVHbPPNYN2mZ1uO5kd0Izp6QnF+9vl3KGa02klCeQle6xDoQ7cYd7TH2gS0xkKbi7f sfSCz4oo1M3FWofOd+Tody1RfLPD1J1NjpMSjXV0BI22vzpybwr6S3zGr7iGav7yODkj bQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e22m6fnum-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:49 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2184w8Oa016924; Tue, 8 Feb 2022 05:16:49 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e22m6fntu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:48 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185Ck8H000993; Tue, 8 Feb 2022 05:16:47 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma02fra.de.ibm.com with ESMTP id 3e1gv99bad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:46 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GeUs35193250 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:40 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1759A11C05C; Tue, 8 Feb 2022 05:16:40 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 69EE611C050; Tue, 8 Feb 2022 05:16:39 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:39 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 02/14] selftests/bpf: Fix a potential offsetofend redefinition in test_cls_redirect Date: Tue, 8 Feb 2022 06:16:23 +0100 Message-Id: <20220208051635.2160304-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 5Mi2AUc-EuK2PfwQ3Kzqa1_up7GEkgkx X-Proofpoint-ORIG-GUID: cRnFVHfDZo67QEsIq5wYdTMyLcYHHhFW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net If one of the included headers defines offsetofend macro, test_cls_redirect would fail to build. Wrap the offsetofend definition in #ifdef to avoid that. Signed-off-by: Ilya Leoshkevich --- tools/testing/selftests/bpf/progs/test_cls_redirect.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/test_cls_redirect.c b/tools/testing/selftests/bpf/progs/test_cls_redirect.c index 2833ad722cb7..ed1b9c90a66b 100644 --- a/tools/testing/selftests/bpf/progs/test_cls_redirect.c +++ b/tools/testing/selftests/bpf/progs/test_cls_redirect.c @@ -28,8 +28,10 @@ #define INLINING __always_inline #endif +#ifndef offsetofend #define offsetofend(TYPE, MEMBER) \ (offsetof(TYPE, MEMBER) + sizeof((((TYPE *)0)->MEMBER))) +#endif #define IP_OFFSET_MASK (0x1FFF) #define IP_MF (0x2000) From patchwork Tue Feb 8 05:16:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738181 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB5B7C433F5 for ; Tue, 8 Feb 2022 05:33:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231574AbiBHFcs (ORCPT ); Tue, 8 Feb 2022 00:32:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231844AbiBHFRI (ORCPT ); Tue, 8 Feb 2022 00:17:08 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92CC3C0401E9 for ; Mon, 7 Feb 2022 21:17:06 -0800 (PST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21844QNP024668; Tue, 8 Feb 2022 05:16:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=RlgzrrSc1bi6IEHhXxDTXeYaJzKc+9zY44gue3N+N6E=; b=HAYueCiNCHZL1hk2osoAXhIxmA1cpye+Lv55vw5NXdcAvJSeSWafHu9utUmFAAW1Nu9a nt5Oe+D8Wyd/dMIuBAyzNc3UeZnt4t6hXD9oOKas7gp/8aLaMryKjVWZr/WnHTGhiaCn XASMvmY1JvR0o9NkAjx071qmWQLMIOkuM+8H2MpKJbVeC9MrXwUHiac7wu3ZCDSLMGU2 i8fe56dmUmAM+jNWVtQqmK7cCo3eAVv+vWsgEgeGeopQsAu52fRkl5+i4kPdP/op3Ljp 04bsPn19EpuDOBMhERYafh/4C6hPHuUjJZZmgZBg7Lua4Y3jC/UZ78UtncbhLoBPUllJ +Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22vm7jvp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:48 +0000 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2185GmgL010569; Tue, 8 Feb 2022 05:16:48 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22vm7jv1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:47 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185Cpn9003673; Tue, 8 Feb 2022 05:16:46 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3e1gv92ean-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:46 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GfCh43843846 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:41 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2185F11C052; Tue, 8 Feb 2022 05:16:41 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 72E2211C04A; Tue, 8 Feb 2022 05:16:40 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:40 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 03/14] selftests/bpf: Compile bpf_syscall_macro test also with user headers Date: Tue, 8 Feb 2022 06:16:24 +0100 Message-Id: <20220208051635.2160304-4-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: RsqGNcD4z-O5-zK-zRvf2lhZr36q8bVA X-Proofpoint-ORIG-GUID: qsXDDj5rQX4kD3MbYG_kKz5kjZmSVUXs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 phishscore=0 suspectscore=0 priorityscore=1501 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Verify that using linux/ptrace.h instead of vmlinux.h works fine. Since without vmlinux.h and with CO-RE it's not possible to access the first syscall argument on arm64 and s390x, and any syscall arguments on Intel, skip the corresponding checks. Signed-off-by: Ilya Leoshkevich --- ...call_macro.c => test_bpf_syscall_macro_common.h} | 8 +++++++- .../bpf/prog_tests/test_bpf_syscall_macro_kernel.c | 13 +++++++++++++ .../bpf/prog_tests/test_bpf_syscall_macro_user.c | 13 +++++++++++++ ...f_syscall_macro.c => bpf_syscall_macro_common.h} | 8 ++++++-- .../selftests/bpf/progs/bpf_syscall_macro_kernel.c | 4 ++++ .../selftests/bpf/progs/bpf_syscall_macro_user.c | 10 ++++++++++ 6 files changed, 53 insertions(+), 3 deletions(-) rename tools/testing/selftests/bpf/prog_tests/{test_bpf_syscall_macro.c => test_bpf_syscall_macro_common.h} (89%) create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_kernel.c create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_user.c rename tools/testing/selftests/bpf/progs/{bpf_syscall_macro.c => bpf_syscall_macro_common.h} (87%) create mode 100644 tools/testing/selftests/bpf/progs/bpf_syscall_macro_kernel.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_syscall_macro_user.c diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_common.h similarity index 89% rename from tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c rename to tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_common.h index f5f4c8adf539..9f2a395abff7 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c +++ b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_common.h @@ -2,7 +2,6 @@ /* Copyright 2022 Sony Group Corporation */ #include #include -#include "bpf_syscall_macro.skel.h" void test_bpf_syscall_macro(void) { @@ -46,7 +45,13 @@ void test_bpf_syscall_macro(void) ASSERT_EQ(skel->bss->arg5, exp_arg5, "syscall_arg5"); /* check whether args of syscall are copied correctly for CORE variants */ +#if defined(__BPF_SYSCALL_MACRO_KERNEL_SKEL_H__) || \ + (!defined(__s390__) && !defined(__aarch64__) && \ + !defined(__i386__) && !defined(__x86_64__)) ASSERT_EQ(skel->bss->arg1_core, exp_arg1, "syscall_arg1_core_variant"); +#endif +#if defined(__BPF_SYSCALL_MACRO_KERNEL_SKEL_H__) || \ + (!defined(__i386__) && !defined(__x86_64__)) ASSERT_EQ(skel->bss->arg2_core, exp_arg2, "syscall_arg2_core_variant"); ASSERT_EQ(skel->bss->arg3_core, exp_arg3, "syscall_arg3_core_variant"); /* it cannot copy arg4 when uses PT_REGS_PARM4_CORE on x86_64 */ @@ -57,6 +62,7 @@ void test_bpf_syscall_macro(void) #endif ASSERT_EQ(skel->bss->arg4_core, exp_arg4, "syscall_arg4_core_variant"); ASSERT_EQ(skel->bss->arg5_core, exp_arg5, "syscall_arg5_core_variant"); +#endif cleanup: bpf_syscall_macro__destroy(skel); diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_kernel.c b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_kernel.c new file mode 100644 index 000000000000..7ceabd62bb0f --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_kernel.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "bpf_syscall_macro_kernel.skel.h" + +void test_bpf_syscall_macro_kernel(void); + +#define test_bpf_syscall_macro test_bpf_syscall_macro_kernel +#define bpf_syscall_macro bpf_syscall_macro_kernel +#define bpf_syscall_macro__open bpf_syscall_macro_kernel__open +#define bpf_syscall_macro__load bpf_syscall_macro_kernel__load +#define bpf_syscall_macro__attach bpf_syscall_macro_kernel__attach +#define bpf_syscall_macro__destroy bpf_syscall_macro_kernel__destroy + +#include "test_bpf_syscall_macro_common.h" diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_user.c b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_user.c new file mode 100644 index 000000000000..f31558f14e7e --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_user.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "bpf_syscall_macro_user.skel.h" + +void test_bpf_syscall_macro_user(void); + +#define test_bpf_syscall_macro test_bpf_syscall_macro_user +#define bpf_syscall_macro bpf_syscall_macro_user +#define bpf_syscall_macro__open bpf_syscall_macro_user__open +#define bpf_syscall_macro__load bpf_syscall_macro_user__load +#define bpf_syscall_macro__attach bpf_syscall_macro_user__attach +#define bpf_syscall_macro__destroy bpf_syscall_macro_user__destroy + +#include "test_bpf_syscall_macro_common.h" diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h similarity index 87% rename from tools/testing/selftests/bpf/progs/bpf_syscall_macro.c rename to tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h index f5c6ef2ff6d1..8717605358d3 100644 --- a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c +++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h @@ -1,7 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright 2022 Sony Group Corporation */ -#include - #include #include #include @@ -46,12 +44,18 @@ int BPF_KPROBE(handle_sys_prctl) bpf_probe_read_kernel(&arg5, sizeof(arg5), &PT_REGS_PARM5_SYSCALL(real_regs)); /* test for the CORE variant of PT_REGS_PARM */ +#if defined(__KERNEL__) || defined(__VMLINUX_H__) || \ + (!defined(bpf_target_s390) && !defined(bpf_target_arm64) && \ + !defined(bpf_target_x86)) arg1_core = PT_REGS_PARM1_CORE_SYSCALL(real_regs); +#endif +#if defined(__KERNEL__) || defined(__VMLINUX_H__) || !defined(bpf_target_x86) arg2_core = PT_REGS_PARM2_CORE_SYSCALL(real_regs); arg3_core = PT_REGS_PARM3_CORE_SYSCALL(real_regs); arg4_core_cx = PT_REGS_PARM4_CORE(real_regs); arg4_core = PT_REGS_PARM4_CORE_SYSCALL(real_regs); arg5_core = PT_REGS_PARM5_CORE_SYSCALL(real_regs); +#endif return 0; } diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro_kernel.c b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_kernel.c new file mode 100644 index 000000000000..1affac21266d --- /dev/null +++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_kernel.c @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +#include "bpf_syscall_macro_common.h" diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro_user.c b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_user.c new file mode 100644 index 000000000000..1c078d528e8c --- /dev/null +++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_user.c @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include + +#include "bpf_syscall_macro_common.h" + +#if defined(__KERNEL__) || defined(__VMLINUX_H__) +#error This test must be compiled with userspace headers +#endif From patchwork Tue Feb 8 05:16:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738169 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A78A3C43217 for ; Tue, 8 Feb 2022 05:32:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244638AbiBHFcl (ORCPT ); Tue, 8 Feb 2022 00:32:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231866AbiBHFRL (ORCPT ); Tue, 8 Feb 2022 00:17:11 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75813C0401DC for ; Mon, 7 Feb 2022 21:17:10 -0800 (PST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2182lK7G024652; Tue, 8 Feb 2022 05:16:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=hRGhBusMYA1VJZZij4qMfzQS9fs5tLGzmEf62qUqi+Q=; b=p6WAFGefZqmCGn63Jf63EqJEP+6B53PwBdvOHVoMhtQzGnnUsxqmxSkvg0Z13ixdo9KG SO4xi6rqRSKVP7qzAc/VQRkcsrUbKNDxsYsakHM4g37imeV9Xss06Cu9PnbT90382RlZ dulHfmCWjqo7SPZ+CuOk4nKSOGBDdNCtTmn+PH8S7l5Vcg5w5Sj5xfHvUMV9oQOFkv9A 9lmTyH5xaOS3/5071yWY7mow6A0UB+LreUYdRH1R7F7Zmji5nq2TiuGoBFJ39yJNDgh+ 6Sd2kKpSNDvziAmNhDzdH9N/fnz8ctGkcltgYB6NTfX1KxzrqoSexI4xZghE2XPo/UmP uQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22vm7jw7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:50 +0000 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2185AXH2025758; Tue, 8 Feb 2022 05:16:49 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22vm7jvt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:49 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185CbV3002902; Tue, 8 Feb 2022 05:16:48 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 3e1gv9ae67-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:47 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GgmH45679014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:42 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 154D811C04C; Tue, 8 Feb 2022 05:16:42 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 69DB711C04A; Tue, 8 Feb 2022 05:16:41 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:41 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 04/14] libbpf: Fix a typo in bpf_tracing.h Date: Tue, 8 Feb 2022 06:16:25 +0100 Message-Id: <20220208051635.2160304-5-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: N2OtRk3KvUE7_Hz3YOLlkixHpgyesD4n X-Proofpoint-ORIG-GUID: ePn9R5Iv60ro1Kx632Rb_2AUxWPEqSHC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 phishscore=0 suspectscore=0 priorityscore=1501 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net s/architecutres/architectures/ Signed-off-by: Ilya Leoshkevich --- tools/lib/bpf/bpf_tracing.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index 032ba809f3e5..da7e8d5c939c 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -219,7 +219,7 @@ struct pt_regs; -/* allow some architecutres to override `struct pt_regs` */ +/* allow some architectures to override `struct pt_regs` */ #ifndef __PT_REGS_CAST #define __PT_REGS_CAST(x) (x) #endif From patchwork Tue Feb 8 05:16:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738168 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C279AC433FE for ; Tue, 8 Feb 2022 05:32:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243960AbiBHFci (ORCPT ); Tue, 8 Feb 2022 00:32:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231909AbiBHFRP (ORCPT ); Tue, 8 Feb 2022 00:17:15 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46A76C0401ED for ; Mon, 7 Feb 2022 21:17:13 -0800 (PST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2182jWpY010661; Tue, 8 Feb 2022 05:16:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=9BV0umtU4uqmUlD8CjFKbc/UsAQ3TN3IGw58+vupHC4=; b=kQ6sLKaWIern85/1ublYPyvFEe5jDLZY6itXG/KrEeQ6gYLDVTHTyND7IhEpyWynDvaq zrwmeTb1qnts6cgWjrv4NoXHaneUA62QMr/MgAZ3mrjP+jEqEmoFKKHPjcz289JJ0tgU CLO308HYhqbIY46r5xFpgDp14iVIQwjsuba1vT62Arz74xhg8Wtd9Tcr9F/+PZggM8zS odQoqfw0MK6MIGoitvxpNke/MfbMvByIsKwpBx82TSDpcDjcxjda1NTsjfeilq4EL8jd 8S5e1Sx1xQ7LfOCsOUk5WnffUsJFmBTWUUHIglPQU4zZK+AHpV7RTLjNBVzBLQCt5IW+ 8w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22qf868g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:55 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21856UCn023865; Tue, 8 Feb 2022 05:16:55 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22qf867v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:54 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185EEMF029344; Tue, 8 Feb 2022 05:16:52 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06fra.de.ibm.com with ESMTP id 3e1ggj1g6a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:52 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GhSc48497046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:43 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E26B11C04A; Tue, 8 Feb 2022 05:16:43 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6C21711C052; Tue, 8 Feb 2022 05:16:42 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:42 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 05/14] libbpf: Generalize overriding syscall parameter access macros Date: Tue, 8 Feb 2022 06:16:26 +0100 Message-Id: <20220208051635.2160304-6-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ZmSsgwT3gMQEz2tVgYzrf_LClhSuCsJq X-Proofpoint-GUID: kSmJ0LR4A8BbUq0O4n4Ggt6dyrLbCpJk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 clxscore=1015 suspectscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Instead of conditionally overriding PT_REGS_PARM4_SYSCALL, provide default fallbacks for all __PT_PARMn_REG_SYSCALL macros, so that architectures can simply override a specific syscall parameter macro. Also allow completely overriding PT_REGS_PARM1_SYSCALL for non-trivial access sequences. Co-developed-by: Naveen N. Rao Signed-off-by: Naveen N. Rao Signed-off-by: Ilya Leoshkevich --- tools/lib/bpf/bpf_tracing.h | 48 +++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index da7e8d5c939c..82f1e935d549 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -265,25 +265,43 @@ struct pt_regs; #endif -#define PT_REGS_PARM1_SYSCALL(x) PT_REGS_PARM1(x) -#define PT_REGS_PARM2_SYSCALL(x) PT_REGS_PARM2(x) -#define PT_REGS_PARM3_SYSCALL(x) PT_REGS_PARM3(x) -#ifdef __PT_PARM4_REG_SYSCALL +#ifndef __PT_PARM1_REG_SYSCALL +#define __PT_PARM1_REG_SYSCALL __PT_PARM1_REG +#endif +#ifndef __PT_PARM2_REG_SYSCALL +#define __PT_PARM2_REG_SYSCALL __PT_PARM2_REG +#endif +#ifndef __PT_PARM3_REG_SYSCALL +#define __PT_PARM3_REG_SYSCALL __PT_PARM3_REG +#endif +#ifndef __PT_PARM4_REG_SYSCALL +#define __PT_PARM4_REG_SYSCALL __PT_PARM4_REG +#endif +#ifndef __PT_PARM5_REG_SYSCALL +#define __PT_PARM5_REG_SYSCALL __PT_PARM5_REG +#endif + +#ifndef PT_REGS_PARM1_SYSCALL +#define PT_REGS_PARM1_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM1_REG_SYSCALL) +#endif +#ifndef PT_REGS_PARM2_SYSCALL +#define PT_REGS_PARM2_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM2_REG_SYSCALL) +#endif +#ifndef PT_REGS_PARM3_SYSCALL +#define PT_REGS_PARM3_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM3_REG_SYSCALL) +#endif +#ifndef PT_REGS_PARM4_SYSCALL #define PT_REGS_PARM4_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM4_REG_SYSCALL) -#else /* __PT_PARM4_REG_SYSCALL */ -#define PT_REGS_PARM4_SYSCALL(x) PT_REGS_PARM4(x) #endif -#define PT_REGS_PARM5_SYSCALL(x) PT_REGS_PARM5(x) +#ifndef PT_REGS_PARM5_SYSCALL +#define PT_REGS_PARM5_SYSCALL(x) (__PT_REGS_CAST(x)->__PT_PARM5_REG_SYSCALL) +#endif -#define PT_REGS_PARM1_CORE_SYSCALL(x) PT_REGS_PARM1_CORE(x) -#define PT_REGS_PARM2_CORE_SYSCALL(x) PT_REGS_PARM2_CORE(x) -#define PT_REGS_PARM3_CORE_SYSCALL(x) PT_REGS_PARM3_CORE(x) -#ifdef __PT_PARM4_REG_SYSCALL +#define PT_REGS_PARM1_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM1_REG_SYSCALL) +#define PT_REGS_PARM2_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM2_REG_SYSCALL) +#define PT_REGS_PARM3_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM3_REG_SYSCALL) #define PT_REGS_PARM4_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM4_REG_SYSCALL) -#else /* __PT_PARM4_REG_SYSCALL */ -#define PT_REGS_PARM4_CORE_SYSCALL(x) PT_REGS_PARM4_CORE(x) -#endif -#define PT_REGS_PARM5_CORE_SYSCALL(x) PT_REGS_PARM5_CORE(x) +#define PT_REGS_PARM5_CORE_SYSCALL(x) BPF_CORE_READ(__PT_REGS_CAST(x), __PT_PARM5_REG_SYSCALL) #else /* defined(bpf_target_defined) */ From patchwork Tue Feb 8 05:16:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738173 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52A3BC433EF for ; Tue, 8 Feb 2022 05:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231675AbiBHFdE (ORCPT ); Tue, 8 Feb 2022 00:33:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231886AbiBHFRO (ORCPT ); Tue, 8 Feb 2022 00:17:14 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8615DC0401DC for ; Mon, 7 Feb 2022 21:17:12 -0800 (PST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2182NtgB004648; Tue, 8 Feb 2022 05:16:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=tatvCcJMb5MAKykIB7N4AT8vsCZ5ASy49zIrBpgM7gE=; b=I/Jj7kSAOV00CNg0FXdCAjbIaiO539AocFsRCGzny+Flb2N9Yv764io2C2tpsYLtP+im H+k2iFDw19obn83zH9fPI3N9l3mjj1EgX6Ln4+007Cos4r5qpRB6c2tBQ3knLZJ5KZqU BOXVMStlZoiSQTUf1lfL3/zfsfv7RV2o2C68cdWQ5lcLh4eo4bBaFmIMjU9oCML6SsJW MDsOzMgjQlUVCEWta7cYAZRKESMMfo7mPpZWgl7sMLI3Ljv/N8qV+M27X+6LvkdLqPjC 2vJzMafhKJOjdwyhgDtvlbCli4lQW6m8ajRjFcdw/dYW3YJbQJLtksjtibhig1kz+rUC qA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22stg35r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:51 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2185FurH027220; Tue, 8 Feb 2022 05:16:51 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22stg34s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:51 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185CWgi002870; Tue, 8 Feb 2022 05:16:48 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03ams.nl.ibm.com with ESMTP id 3e1gv9ae6b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:48 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GiTN41419070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:44 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F395711C04A; Tue, 8 Feb 2022 05:16:43 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5CDF511C04C; Tue, 8 Feb 2022 05:16:43 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:43 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 06/14] libbpf: Add PT_REGS_SYSCALL_REGS macro Date: Tue, 8 Feb 2022 06:16:27 +0100 Message-Id: <20220208051635.2160304-7-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: at3DYpWTiPsqG8HhA1Y83T4MfdWzw_ti X-Proofpoint-ORIG-GUID: 8-75i-M9NQNR_q9e3Lkp70m4TMthJFUN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 spamscore=0 suspectscore=0 malwarescore=0 mlxscore=0 mlxlogscore=989 impostorscore=0 bulkscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Depending on whether or not an arch has ARCH_HAS_SYSCALL_WRAPPER, syscall arguments must be accessed through a different set of registers. Provide PT_REGS_SYSCALL_REGS macro to abstract away that difference. Reported-by: Heiko Carstens Co-developed-by: Naveen N. Rao Signed-off-by: Naveen N. Rao Signed-off-by: Ilya Leoshkevich --- tools/lib/bpf/bpf_tracing.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index 82f1e935d549..7a015ee8fb11 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -64,6 +64,8 @@ #if defined(bpf_target_x86) +#define __BPF_ARCH_HAS_SYSCALL_WRAPPER + #if defined(__KERNEL__) || defined(__VMLINUX_H__) #define __PT_PARM1_REG di @@ -114,6 +116,8 @@ #elif defined(bpf_target_s390) +#define __BPF_ARCH_HAS_SYSCALL_WRAPPER + /* s390 provides user_pt_regs instead of struct pt_regs to userspace */ #define __PT_REGS_CAST(x) ((const user_pt_regs *)(x)) #define __PT_PARM1_REG gprs[2] @@ -142,6 +146,8 @@ #elif defined(bpf_target_arm64) +#define __BPF_ARCH_HAS_SYSCALL_WRAPPER + /* arm64 provides struct user_pt_regs instead of struct pt_regs to userspace */ #define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x)) #define __PT_PARM1_REG regs[0] @@ -344,6 +350,17 @@ struct pt_regs; #endif /* defined(bpf_target_defined) */ +/* + * When invoked from a syscall handler BPF_KPROBE, returns a pointer to a + * struct pt_regs containing syscall arguments, that is suitable for passing to + * PT_REGS_PARMn_SYSCALL() and PT_REGS_PARMn_CORE_SYSCALL(). + */ +#ifdef __BPF_ARCH_HAS_SYSCALL_WRAPPER +#define PT_REGS_SYSCALL_REGS(ctx) ((struct pt_regs *)PT_REGS_PARM1(ctx)) +#else +#define PT_REGS_SYSCALL_REGS(ctx) ctx +#endif + #ifndef ___bpf_concat #define ___bpf_concat(a, b) a ## b #endif From patchwork Tue Feb 8 05:16:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738175 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5850AC4167B for ; Tue, 8 Feb 2022 05:33:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235383AbiBHFdF (ORCPT ); Tue, 8 Feb 2022 00:33:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231919AbiBHFRP (ORCPT ); Tue, 8 Feb 2022 00:17:15 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63900C0401EE for ; Mon, 7 Feb 2022 21:17:13 -0800 (PST) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2182IG2M021390; Tue, 8 Feb 2022 05:16:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=HR4g4dcgdAOIxXBvfmG4lQLe6l4SHdf1pDAgzAmfyqo=; b=KjpdEBt91RVCHvx2/EDbXNBCetMfz9lQVtpANt+q9dAbwKEy2plKIqhuP5Cl1eqtLFpD fEZaL9tW/pu4X0zNn6wrSYfCkFq2xhO4SOF1tYMJ6e0Cn2RGlr2qEOzIvf+prb1fBSrn Y9iY7h4LNhbuTmPIeNnKDPwddW44IHRyPNdxVuHtidEdUUaJYXZui0evw94fEUWIEw9S gRoYUND5aE4K6L+jMd7NhCyYNJbmtDFGoEbc/sDym903OKj0vKr4GlEnD6q6wm6QA118 JBFBS4+Rdc4lS/iyi56gja++7HzvIB4QyNk+UZ5ofHN/RX1XDrAep3Jxn0XENwwoplw0 RA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e3fm4js4u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:55 +0000 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2185GtuH021148; Tue, 8 Feb 2022 05:16:55 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e3fm4js40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:55 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185CCNI019236; Tue, 8 Feb 2022 05:16:53 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 3e1gv99dk7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:53 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GjD643581820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:45 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EBE6711C04A; Tue, 8 Feb 2022 05:16:44 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 500E111C052; Tue, 8 Feb 2022 05:16:44 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:44 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 07/14] selftests/bpf: Use PT_REGS_SYSCALL_REGS in bpf_syscall_macro Date: Tue, 8 Feb 2022 06:16:28 +0100 Message-Id: <20220208051635.2160304-8-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: vYdPpaRmaNJdZHYxS4rIzt-_FE4PCI0X X-Proofpoint-GUID: bjMZQ5rEt0XQI7DspuIakKIdjmYSZ3TO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 spamscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Ensure that PT_REGS_SYSCALL_REGS works correctly, and also remove some duplication. Signed-off-by: Ilya Leoshkevich --- tools/testing/selftests/bpf/progs/bpf_misc.h | 4 ---- .../selftests/bpf/progs/bpf_syscall_macro_common.h | 2 +- tools/testing/selftests/bpf/progs/test_probe_user.c | 8 +------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h index 5bb11fe595a4..9f2937b5e819 100644 --- a/tools/testing/selftests/bpf/progs/bpf_misc.h +++ b/tools/testing/selftests/bpf/progs/bpf_misc.h @@ -3,16 +3,12 @@ #define __BPF_MISC_H__ #if defined(__TARGET_ARCH_x86) -#define SYSCALL_WRAPPER 1 #define SYS_PREFIX "__x64_" #elif defined(__TARGET_ARCH_s390) -#define SYSCALL_WRAPPER 1 #define SYS_PREFIX "__s390x_" #elif defined(__TARGET_ARCH_arm64) -#define SYSCALL_WRAPPER 1 #define SYS_PREFIX "__arm64_" #else -#define SYSCALL_WRAPPER 0 #define SYS_PREFIX "__se_" #endif diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h index 8717605358d3..95c2f1904f81 100644 --- a/tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h +++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h @@ -31,7 +31,7 @@ int BPF_KPROBE(handle_sys_prctl) if (pid != filter_pid) return 0; - real_regs = (struct pt_regs *)PT_REGS_PARM1(ctx); + real_regs = PT_REGS_SYSCALL_REGS(ctx); /* test for PT_REGS_PARM */ diff --git a/tools/testing/selftests/bpf/progs/test_probe_user.c b/tools/testing/selftests/bpf/progs/test_probe_user.c index 702578a5e496..b2531f587c87 100644 --- a/tools/testing/selftests/bpf/progs/test_probe_user.c +++ b/tools/testing/selftests/bpf/progs/test_probe_user.c @@ -14,18 +14,12 @@ static struct sockaddr_in old; SEC("kprobe/" SYS_PREFIX "sys_connect") int BPF_KPROBE(handle_sys_connect) { -#if SYSCALL_WRAPPER == 1 struct pt_regs *real_regs; -#endif struct sockaddr_in new; void *ptr; -#if SYSCALL_WRAPPER == 0 - ptr = (void *)PT_REGS_PARM2(ctx); -#else - real_regs = (struct pt_regs *)PT_REGS_PARM1(ctx); + real_regs = PT_REGS_SYSCALL_REGS(ctx); bpf_probe_read_kernel(&ptr, sizeof(ptr), &PT_REGS_PARM2(real_regs)); -#endif bpf_probe_read_user(&old, sizeof(old), ptr); __builtin_memset(&new, 0xab, sizeof(new)); From patchwork Tue Feb 8 05:16:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738177 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5E81C433EF for ; Tue, 8 Feb 2022 05:33:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347095AbiBHFcw (ORCPT ); Tue, 8 Feb 2022 00:32:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231868AbiBHFRO (ORCPT ); Tue, 8 Feb 2022 00:17:14 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 864C9C0401E9 for ; Mon, 7 Feb 2022 21:17:12 -0800 (PST) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2182I3PN021119; Tue, 8 Feb 2022 05:16:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=9Qd6UpMF3oJo+XUqq9Ez4PY7I6X62OEtlCTwwlWOB3I=; b=nwCku9xjRGXgwN9cGN2IG959S9UuW1/G6ZC3CgudbWZeV5wFUiqRMSu6vRuGa+F6avfC OVr68f0scV0REGuOawAeiTrcCJc79CfIpzytiSR4IafzAXP2eg0YaCt8EhbHcozd7T4Z VbOMvPgGcpW/Sp0rgdG/vG58h5ZHcmSZBUUDE0ed2X/xJN1ll4lmjE5GbZEA5Aj2sQbj 8Jqs/qtMn7QPfow09y1wY4IT6j0BrrfSvszQ2ZDnpuDEgMsfugUr0mZ+Ien2Hfiwn9Vo ma/79Ok776mldpxxp1hjJu3zZRWYIXJ6A3SE/FwcEd3TL8B42lNWh3Dwsty67cRagot7 8A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e3fm4js41-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:54 +0000 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2185GTbp016590; Tue, 8 Feb 2022 05:16:53 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e3fm4js3a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:53 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185COoq022043; Tue, 8 Feb 2022 05:16:52 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06ams.nl.ibm.com with ESMTP id 3e1ggjtf3n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:51 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GjeM46268712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:45 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D933111C04C; Tue, 8 Feb 2022 05:16:45 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 41A8011C069; Tue, 8 Feb 2022 05:16:45 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:45 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 08/14] libbpf: Use struct pt_regs when compiling with kernel headers Date: Tue, 8 Feb 2022 06:16:29 +0100 Message-Id: <20220208051635.2160304-9-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Uet0BPsgthsOvfvki21-hFZj0xGK88zb X-Proofpoint-GUID: 7F8L9nOuqSz32NoUU9HEfKsKY0fKKrrV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 spamscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 phishscore=0 mlxlogscore=921 clxscore=1015 adultscore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Andrii says: "... with CO-RE and vmlinux.h it would be more reliable and straightforward to just stick to kernel-internal struct pt_regs everywhere ...". Actually, if vmlinux.h is available, then it's ok to do so for both CO-RE and non-CO-RE cases, since the beginning of struct pt_regs must match (struct) user_pt_regs, which must never change. Implement this by not defining __PT_REGS_CAST if the user included vmlinux.h. Signed-off-by: Ilya Leoshkevich --- tools/lib/bpf/bpf_tracing.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index 7a015ee8fb11..07e291d77e83 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -118,8 +118,11 @@ #define __BPF_ARCH_HAS_SYSCALL_WRAPPER +#if !defined(__KERNEL__) && !defined(__VMLINUX_H__) /* s390 provides user_pt_regs instead of struct pt_regs to userspace */ #define __PT_REGS_CAST(x) ((const user_pt_regs *)(x)) +#endif + #define __PT_PARM1_REG gprs[2] #define __PT_PARM2_REG gprs[3] #define __PT_PARM3_REG gprs[4] @@ -148,8 +151,11 @@ #define __BPF_ARCH_HAS_SYSCALL_WRAPPER +#if !defined(__KERNEL__) && !defined(__VMLINUX_H__) /* arm64 provides struct user_pt_regs instead of struct pt_regs to userspace */ #define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x)) +#endif + #define __PT_PARM1_REG regs[0] #define __PT_PARM2_REG regs[1] #define __PT_PARM3_REG regs[2] @@ -207,7 +213,10 @@ #elif defined(bpf_target_riscv) +#if !defined(__KERNEL__) && !defined(__VMLINUX_H__) #define __PT_REGS_CAST(x) ((const struct user_regs_struct *)(x)) +#endif + #define __PT_PARM1_REG a0 #define __PT_PARM2_REG a1 #define __PT_PARM3_REG a2 From patchwork Tue Feb 8 05:16:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738170 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2DD8C433EF for ; Tue, 8 Feb 2022 05:32:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244158AbiBHFcj (ORCPT ); Tue, 8 Feb 2022 00:32:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231917AbiBHFRP (ORCPT ); Tue, 8 Feb 2022 00:17:15 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B62F6C0401EF for ; Mon, 7 Feb 2022 21:17:13 -0800 (PST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2185G9ag016682; Tue, 8 Feb 2022 05:16:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=9qFY7+b5+VeIgi3fIOY1RuDxBqifZBH0qwVTD/cvXTY=; b=lmn/W95INcsTcoBWn3Y+24t2z4FrnOkp8VUvKXnQ2qIiQxXMOoy39vNGYAu97mRo204G 8/GO6RChZsLuqXFJcD6/4wLPjlpQtx4vKzqolKZyJUs93dLjgMS0tGOL+VNjwOxT7rO6 EdNMCEszUoKhvW9qQ/NW+C4eSWVEaKrir3xjPBLF4KYMBuVBRrnBas/ZVAyNIbrNTjTW gUM/37AcS+c9izggh1WWSx6BtBYNH3p2N5s0FrwP4v+wAVcvsF5ZmYUg+lZNddritnYa sNWhxUNV2Gcx/kErEKBfGI+sMtH7qsID2N0lvjdElJHPuQzIXKqS03OF8bjtrEgFXNkp vQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e3e1tctsr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:55 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21850E30033429; Tue, 8 Feb 2022 05:16:54 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e3e1tctry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:54 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185Co0h003657; Tue, 8 Feb 2022 05:16:52 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 3e1gv92eb2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:52 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21856gbA48103832 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:06:42 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C67CF11C050; Tue, 8 Feb 2022 05:16:46 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 272DB11C052; Tue, 8 Feb 2022 05:16:46 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:46 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 09/14] libbpf: Fix riscv register names Date: Tue, 8 Feb 2022 06:16:30 +0100 Message-Id: <20220208051635.2160304-10-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 62AxabGiWr3uptoMhlwvvnQuJ48ULsJW X-Proofpoint-ORIG-GUID: Wznu5utY2mbVb9lL2nwuk2oBTpvxBgb8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 phishscore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net struct pt_regs and struct user_regs_struct have different names for the program counter: epc and pc respectively. Also, the frame pointer is called s0, not fp. Reported-by: Heiko Carstens Signed-off-by: Ilya Leoshkevich --- tools/lib/bpf/bpf_tracing.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index 07e291d77e83..88ed5ba9510c 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -213,8 +213,11 @@ #elif defined(bpf_target_riscv) -#if !defined(__KERNEL__) && !defined(__VMLINUX_H__) +#if defined(__KERNEL__) || defined(__VMLINUX_H__) +#define __PT_IP_REG epc +#else #define __PT_REGS_CAST(x) ((const struct user_regs_struct *)(x)) +#define __PT_IP_REG pc #endif #define __PT_PARM1_REG a0 @@ -223,10 +226,9 @@ #define __PT_PARM4_REG a3 #define __PT_PARM5_REG a4 #define __PT_RET_REG ra -#define __PT_FP_REG fp +#define __PT_FP_REG s0 #define __PT_RC_REG a5 #define __PT_SP_REG sp -#define __PT_IP_REG epc #endif From patchwork Tue Feb 8 05:16:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738172 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DCB4C433FE for ; Tue, 8 Feb 2022 05:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346974AbiBHFcq (ORCPT ); Tue, 8 Feb 2022 00:32:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231899AbiBHFRP (ORCPT ); Tue, 8 Feb 2022 00:17:15 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F32D4C0401EA for ; Mon, 7 Feb 2022 21:17:12 -0800 (PST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2181Ldw1025943; Tue, 8 Feb 2022 05:16:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=3EvM/rCmWiuVwBkzj6vPS6ZG0crmPQkuKBSqKxfzS3E=; b=BLyP61LStaXJiAx6fTMIVOn6IbeckCpv+x47H4QbTFfS0HbjLFcXdE3+tk5ACdt102Q7 SLD4LMIbWQERv3AvuwqKHiTTldERn+CrJ3a8dVwWkMldkhbPgtq8CzGLUILt/oQpo3z/ DoD5kGGGgUUcKA7VosbwYrPQ2b2Ayod7/o4CWNSo8WYk9lj6PO7br0u7W/O/IryFra41 dfqikmNjAKvJ0Awf3fBoLhFSXmvp/SAfYNXRZdMWbfVRaN7qNz1IjTnMwlropJOTo885 //7Cisnfzvfi9CATbknHfz9CvBm6CGnS3PBccz2dRkHEWxrmrF3zWg1esxM7FoF0FA69 hQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e22m6fnww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:55 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2185Dc1D005149; Tue, 8 Feb 2022 05:16:55 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e22m6fnwf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:54 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185EDB7029315; Tue, 8 Feb 2022 05:16:53 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06fra.de.ibm.com with ESMTP id 3e1ggj1g6c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:52 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GlPW38601110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:47 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A24AC11C04A; Tue, 8 Feb 2022 05:16:47 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0DC5911C04C; Tue, 8 Feb 2022 05:16:47 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:46 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 10/14] libbpf: Move data structure manipulation macros to bpf_common_helpers.h Date: Tue, 8 Feb 2022 06:16:31 +0100 Message-Id: <20220208051635.2160304-11-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: iaYnX2_5Oy0urX8XKbhvjQBev_xaWupT X-Proofpoint-ORIG-GUID: DMz5srp1Q7EcldplnN2X3QxzJAmdr0T3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net These macros are useful for both libbpf and bpf progs, so put them into a separate header dedicated to this use case. Signed-off-by: Ilya Leoshkevich --- tools/lib/bpf/Makefile | 2 +- tools/lib/bpf/bpf_common_helpers.h | 30 ++++++++++++++++++++++++++ tools/lib/bpf/bpf_helpers.h | 15 +------------ tools/testing/selftests/bpf/bpf_util.h | 10 +-------- 4 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 tools/lib/bpf/bpf_common_helpers.h diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index b8b37fe76006..60b06c22e0a1 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile @@ -239,7 +239,7 @@ install_lib: all_cmd SRC_HDRS := bpf.h libbpf.h btf.h libbpf_common.h libbpf_legacy.h xsk.h \ bpf_helpers.h bpf_tracing.h bpf_endian.h bpf_core_read.h \ - skel_internal.h libbpf_version.h + skel_internal.h libbpf_version.h bpf_common_helpers.h GEN_HDRS := $(BPF_GENERATED) INSTALL_PFX := $(DESTDIR)$(prefix)/include/bpf diff --git a/tools/lib/bpf/bpf_common_helpers.h b/tools/lib/bpf/bpf_common_helpers.h new file mode 100644 index 000000000000..79db303b6ae2 --- /dev/null +++ b/tools/lib/bpf/bpf_common_helpers.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ +#ifndef __BPF_COMMON_HELPERS__ +#define __BPF_COMMON_HELPERS__ + +/* + * Helper macros that can be used both by libbpf and bpf progs. + */ + +#ifndef offsetof +#define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER) +#endif + +#ifndef sizeof_field +#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) +#endif + +#ifndef offsetofend +#define offsetofend(TYPE, MEMBER) \ + (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER)) +#endif + +#ifndef container_of +#define container_of(ptr, type, member) \ + ({ \ + void *__mptr = (void *)(ptr); \ + ((type *)(__mptr - offsetof(type, member))); \ + }) +#endif + +#endif diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h index 44df982d2a5c..1e8b609c1000 100644 --- a/tools/lib/bpf/bpf_helpers.h +++ b/tools/lib/bpf/bpf_helpers.h @@ -2,6 +2,7 @@ #ifndef __BPF_HELPERS__ #define __BPF_HELPERS__ +#include "bpf_common_helpers.h" /* * Note that bpf programs need to include either * vmlinux.h (auto-generated from BTF) or linux/types.h @@ -61,20 +62,6 @@ #define KERNEL_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + ((c) > 255 ? 255 : (c))) #endif -/* - * Helper macros to manipulate data structures - */ -#ifndef offsetof -#define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER) -#endif -#ifndef container_of -#define container_of(ptr, type, member) \ - ({ \ - void *__mptr = (void *)(ptr); \ - ((type *)(__mptr - offsetof(type, member))); \ - }) -#endif - /* * Helper macro to throw a compilation error if __bpf_unreachable() gets * built into the resulting code. This works given BPF back end does not diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h index a3352a64c067..bc0b741b1eef 100644 --- a/tools/testing/selftests/bpf/bpf_util.h +++ b/tools/testing/selftests/bpf/bpf_util.h @@ -6,6 +6,7 @@ #include #include #include +#include #include /* libbpf_num_possible_cpus */ static inline unsigned int bpf_num_possible_cpus(void) @@ -31,13 +32,4 @@ static inline unsigned int bpf_num_possible_cpus(void) # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #endif -#ifndef sizeof_field -#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) -#endif - -#ifndef offsetofend -#define offsetofend(TYPE, MEMBER) \ - (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER)) -#endif - #endif /* __BPF_UTIL__ */ From patchwork Tue Feb 8 05:16:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738180 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0ECDC43219 for ; Tue, 8 Feb 2022 05:33:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347259AbiBHFc4 (ORCPT ); Tue, 8 Feb 2022 00:32:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231938AbiBHFRW (ORCPT ); Tue, 8 Feb 2022 00:17:22 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42F60C0401DC for ; Mon, 7 Feb 2022 21:17:21 -0800 (PST) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2183qQYv011129; Tue, 8 Feb 2022 05:16:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=lJqfHEfM8MX5+Yw3Kw2gURq7wH1XqjIsrdpgbIZGrlE=; b=cYA1Ycklvx09V4hsausD40hlWcV5g3GvoAFSOGuprOWTMEKCMYRtULpoMO7LPzELDowH RwedU/07AUCjnxpQkLWpZ1Dw56cqMb5DaVBtQDkW+wliFRIbS5NH4/iDSgcrnaaU532I 6knZ79PszTCbsAkzphHwwIUf4UOjcsXEMU3j+GmBPR/vIr3Frfyl+l5fHfgC7Ynsn068 4GI5hnSxaALcCP9jjO45wWwgCwVCpc/yMMBldIFgml0Gkkfw0BsoypY5ly8/cHbdkTK2 yervdQVMoQPPUCe3ctA2YQQzcrSyA3UPb8AL3rpzLPtUgLOgV1ywmivL9QqdTFNtX1I/ Wg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e22nkqh40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:58 +0000 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21852hOl025243; Tue, 8 Feb 2022 05:16:57 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 3e22nkqh2p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:56 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185Cc2I002911; Tue, 8 Feb 2022 05:16:54 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03ams.nl.ibm.com with ESMTP id 3e1gv9ae6k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:53 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GmiK38600994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:48 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A82BF11C04A; Tue, 8 Feb 2022 05:16:48 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 04D9F11C04C; Tue, 8 Feb 2022 05:16:48 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:47 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich , Andrii Nakryiko Subject: [PATCH bpf-next v4 11/14] libbpf: Fix accessing the first syscall argument on s390 Date: Tue, 8 Feb 2022 06:16:32 +0100 Message-Id: <20220208051635.2160304-12-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: oLFjtIm_eVraQyewtjXc7EyRcWWnnyuB X-Proofpoint-ORIG-GUID: 2zMH8xtgr2TbetzB-djjM5ou3dMoMUIZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 impostorscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net On s390, the first syscall argument should be accessed via orig_gpr2 (see arch/s390/include/asm/syscall.h). Currently gpr[2] is used instead, leading to bpf_syscall_macro test failure. Note that this is unfixable for CO-RE when vmlinux.h is not included. Simply fail the build in this case. Reported-by: Andrii Nakryiko Signed-off-by: Ilya Leoshkevich --- tools/lib/bpf/bpf_tracing.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index 88ed5ba9510c..5911b177728f 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -2,6 +2,8 @@ #ifndef __BPF_TRACING_H__ #define __BPF_TRACING_H__ +#include + /* Scan the ARCH passed in from ARCH env variable (see Makefile) */ #if defined(__TARGET_ARCH_x86) #define bpf_target_x86 @@ -118,9 +120,20 @@ #define __BPF_ARCH_HAS_SYSCALL_WRAPPER -#if !defined(__KERNEL__) && !defined(__VMLINUX_H__) +#if defined(__KERNEL__) || defined(__VMLINUX_H__) +#define __PT_PARM1_REG_SYSCALL orig_gpr2 +#else /* s390 provides user_pt_regs instead of struct pt_regs to userspace */ #define __PT_REGS_CAST(x) ((const user_pt_regs *)(x)) +/* + * struct pt_regs.orig_gpr2 is not exposed through user_pt_regs, and the ABI + * prohibits extending user_pt_regs. In non-CO-RE case, make use of the fact + * that orig_gpr2 comes right after gprs in struct pt_regs. CO-RE does not + * allow such hacks, so there is no way to access orig_gpr2. + */ +#define PT_REGS_PARM1_SYSCALL(x) \ + (*(unsigned long *)(((char *)(x) + offsetofend(user_pt_regs, gprs)))) +#define __PT_PARM1_REG_SYSCALL __unsupported__ #endif #define __PT_PARM1_REG gprs[2] From patchwork Tue Feb 8 05:16:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738178 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6524C433F5 for ; Tue, 8 Feb 2022 05:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347053AbiBHFc7 (ORCPT ); Tue, 8 Feb 2022 00:32:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231920AbiBHFRP (ORCPT ); Tue, 8 Feb 2022 00:17:15 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CC1AC0401F0 for ; Mon, 7 Feb 2022 21:17:15 -0800 (PST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21858jmQ015969; Tue, 8 Feb 2022 05:16:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=dMbyH2Z4ecASSiIwPCMuVBECi5JSlT96nxGowBgANpk=; b=QhZa59ldmzH98C5RViHitlK5AlAGa6iUv+bTKvntu+t4WM72VCugcvyLOC0JTE6Pr/Ce 6xurVxmKbmfKFmOXjxFdBXnUAGXxRdDoE87pJDERl6J/5crOCPP8GYROE9hQJl9ImlxK CNE9BroBUQnXTDlkyGRRmYO2l2C6DiMKuZERWCuCGMgBSfFTbFStmdo8vjGNFgyRKT8/ P7IMY7Z5cOLSGcx6YniPc4CDgOFQZNghNWnqiAUFl9z3GIKvrPjg0zXYZlnvzLI5zYjS k05cPJzLI9pwmm1BZyQ1rsj5pa8gsl4i3lggZkb67YX7a2gFevjqLm9TeeIIRBXeT5PE rQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e3e1tcttq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:57 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2184s8hI017160; Tue, 8 Feb 2022 05:16:57 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e3e1tctsw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:57 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185CTfb022070; Tue, 8 Feb 2022 05:16:54 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3e1ggjtf41-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:54 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GnmT37290272 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:49 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C39DD11C058; Tue, 8 Feb 2022 05:16:49 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2328811C04A; Tue, 8 Feb 2022 05:16:49 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:49 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 12/14] s390: add a comment that warns that orig_gpr2 should not be moved Date: Tue, 8 Feb 2022 06:16:33 +0100 Message-Id: <20220208051635.2160304-13-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 7gz8XkxM81BmU8iKLsbEDvyb-cEltnpf X-Proofpoint-ORIG-GUID: EVftoteCgMrTMzDMF4dn9NRm4iBKZkG7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 phishscore=0 spamscore=0 mlxlogscore=876 lowpriorityscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net orig_gpr2's location is used by libbpf tracing macros, therefore it should not be moved. Suggested-by: Andrii Nakryiko Signed-off-by: Ilya Leoshkevich --- arch/s390/include/asm/ptrace.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/s390/include/asm/ptrace.h b/arch/s390/include/asm/ptrace.h index 4ffa8e7f0ed3..3c356ec59abc 100644 --- a/arch/s390/include/asm/ptrace.h +++ b/arch/s390/include/asm/ptrace.h @@ -85,6 +85,10 @@ struct pt_regs { unsigned long gprs[NUM_GPRS]; }; }; + /* + * orig_gpr2 is not exposed via user_pt_regs, but its location is + * assumed by libbpf's tracing macros, so it should not be moved. + */ unsigned long orig_gpr2; union { struct { From patchwork Tue Feb 8 05:16:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738182 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46FC4C433EF for ; Tue, 8 Feb 2022 05:33:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347338AbiBHFdI (ORCPT ); Tue, 8 Feb 2022 00:33:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231926AbiBHFRS (ORCPT ); Tue, 8 Feb 2022 00:17:18 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C9DC0401DC for ; Mon, 7 Feb 2022 21:17:16 -0800 (PST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2181obCW004640; Tue, 8 Feb 2022 05:16:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=1rW88tU+Ha5Z0/Dg5rn4OK7ebDpmGFHBsJE/vvEfDdU=; b=rd61lKK1Q2cKRxgE5l0txaOLBjUl4ya0LfByLhPLUa4FDRl8bJItt+OO7Fc3rxaGqERa oxJva1ooay0N4Or8ZurxlaqX/2ZUwREBVvdRsJjZ4DMZdA1FxZPdbkhfTbyLZ1XiPd5f w1X82JHrgmLc8Cs4eBoXNZKT0MDJvmXJAWU7w8qd7GZY8/vvM10l86hEJ/HJ9NubX7Fg V7ig6PJzByzhf7vqSflhH/NNmED6re/Jg7UBPCu/cHiocu01xl2oTY3txuagFX5K/e+8 OBS4xzhlSuvxsFFpNHH3L3dbdY0rZA6UOEzMZuTnslioMTPfS9L3ucuTg3GTNQ5CSl/d 5A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22stg39s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:59 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2185GwSn029085; Tue, 8 Feb 2022 05:16:58 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22stg38m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:58 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185CmIC003124; Tue, 8 Feb 2022 05:16:56 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3e1gv92eb8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:56 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GoSo42467750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:51 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DA75111C052; Tue, 8 Feb 2022 05:16:50 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D80511C054; Tue, 8 Feb 2022 05:16:50 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:50 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 13/14] libbpf: Fix accessing the first syscall argument on arm64 Date: Tue, 8 Feb 2022 06:16:34 +0100 Message-Id: <20220208051635.2160304-14-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: EM2ojSjthAcEwj4ojp5mYzS0JnC59jgl X-Proofpoint-ORIG-GUID: BpBM9i0zDpB7bK4hZNs6erjDnp-71XEU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 spamscore=0 suspectscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 bulkscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net On arm64, the first syscall argument should be accessed via orig_x0 (see arch/arm64/include/asm/syscall.h). Currently regs[0] is used instead, leading to bpf_syscall_macro test failure. Note that this is unfixable for CO-RE when vmlinux.h is not included. Simply fail the build in this case. Reported-by: Heiko Carstens Signed-off-by: Ilya Leoshkevich --- tools/lib/bpf/bpf_tracing.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index 5911b177728f..f5541add5880 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -164,9 +164,21 @@ #define __BPF_ARCH_HAS_SYSCALL_WRAPPER -#if !defined(__KERNEL__) && !defined(__VMLINUX_H__) +#if defined(__KERNEL__) || defined(__VMLINUX_H__) +#define __PT_PARM1_REG_SYSCALL orig_x0 +#else /* arm64 provides struct user_pt_regs instead of struct pt_regs to userspace */ #define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x)) +/* + * struct pt_regs.orig_x0 is not exposed through struct user_pt_regs, and the + * ABI prohibits extending struct user_pt_regs. In non-CO-RE case, make use of + * the fact that orig_x0 comes right after pstate in struct pt_regs. CO-RE does + * not allow such hacks, so there is no way to access orig_x0. + */ +#define PT_REGS_PARM1_SYSCALL(x) \ + (*(unsigned long *)(((char *)(x) + \ + offsetofend(struct user_pt_regs, pstate)))) +#define __PT_PARM1_REG_SYSCALL __unsupported__ #endif #define __PT_PARM1_REG regs[0] From patchwork Tue Feb 8 05:16:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 12738174 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 778D2C433FE for ; Tue, 8 Feb 2022 05:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347311AbiBHFdC (ORCPT ); Tue, 8 Feb 2022 00:33:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbiBHFRT (ORCPT ); Tue, 8 Feb 2022 00:17:19 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06D4CC0401E9 for ; Mon, 7 Feb 2022 21:17:18 -0800 (PST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2182vtBu025085; Tue, 8 Feb 2022 05:16:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=OfZ2A8pNBUxjU7a573k+SrAK7tklcNFpvz8Dy+qmXxg=; b=plojP7d+CDDbHXx1vZ40Bq5G2NbZXEwxcoa6Ju8T+nXl4C2DWrHZGZgZPq4vRFr2dAtY gjUa6CQ4MmOxXseK4PlxIbBMYYAWe8G6wvWCElfB1bBrG+9jgRQxBPU00gGBTcYV3UL1 MVQX34slOCkI57cos6dz9kmU27dE/4b6nyfURi2ZLFGImKmkR/DT417d1OKCM/KEh34j LIGhrQdb5+UG6jrbfhR3aJH2FPjDuyG5SSDUIAtBYcoyVHM5b09XgPv+eZdybVgDWplj /Q2+ulE5N9DFU2kVo1UIV8IhvzFYaNnq/EV6nKooW37bP+QrxjuFnMcpo1QLlK3TLlW4 Kw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22tr82ns-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:59 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2184tgIw029292; Tue, 8 Feb 2022 05:16:59 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22tr82mj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:58 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2185CRio022062; Tue, 8 Feb 2022 05:16:56 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06ams.nl.ibm.com with ESMTP id 3e1ggjtf45-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 05:16:56 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2185GqXZ44630360 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Feb 2022 05:16:52 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D38A11C04C; Tue, 8 Feb 2022 05:16:52 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 947C711C05E; Tue, 8 Feb 2022 05:16:51 +0000 (GMT) Received: from heavy.lan (unknown [9.171.78.41]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Feb 2022 05:16:51 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Catalin Marinas , Michael Ellerman , Paul Walmsley , "Naveen N . Rao" , Mark Rutland Cc: bpf@vger.kernel.org, Ilya Leoshkevich Subject: [PATCH bpf-next v4 14/14] arm64: add a comment that warns that orig_x0 should not be moved Date: Tue, 8 Feb 2022 06:16:35 +0100 Message-Id: <20220208051635.2160304-15-iii@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208051635.2160304-1-iii@linux.ibm.com> References: <20220208051635.2160304-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: u7QAttY4CSw2Aae2-pKpJ8QkLlbubvmE X-Proofpoint-GUID: JekFZZVgywvkQ5RZ4S1qWww6fZxDAPpn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_01,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=983 impostorscore=0 phishscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080025 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net orig_x0's location is used by libbpf tracing macros, therefore it should not be moved. Suggested-by: Andrii Nakryiko Signed-off-by: Ilya Leoshkevich --- arch/arm64/include/asm/ptrace.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h index 41b332c054ab..7e34c3737839 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -185,6 +185,10 @@ struct pt_regs { u64 pstate; }; }; + /* + * orig_x0 is not exposed via struct user_pt_regs, but its location is + * assumed by libbpf's tracing macros, so it should not be moved. + */ u64 orig_x0; #ifdef __AARCH64EB__ u32 unused2;