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]