From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60AEAC7EE26 for ; Tue, 23 May 2023 14:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230170AbjEWOAo (ORCPT ); Tue, 23 May 2023 10:00:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233519AbjEWOAk (ORCPT ); Tue, 23 May 2023 10:00:40 -0400 Received: from new1-smtp.messagingengine.com (new1-smtp.messagingengine.com [66.111.4.221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D872B1A1; Tue, 23 May 2023 07:00:07 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailnew.nyi.internal (Postfix) with ESMTP id 8CEBF580505; Tue, 23 May 2023 09:59:50 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Tue, 23 May 2023 09:59:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1684850390; x=1684857590; bh=gdE+dcQizuRxq92HvxIoxB/lQE+OMVaJSaN 1azoGowA=; b=gyq0KLu4ecjEB700eaXqIb0RGHwJwmYw3knHSbLSuHo5Ux+Bz9q NlDeyKsvMmROIO5uctFDUEVKCRg5uGopgOPJlKaDyGUNSOVAmvbGmb9SEXoiDk08 HRtVhZ7gHTgplc6CIVkWWWDcUZxD5s85YqOXqDpj/VEQpKQNwtGRMbX2UJ2FPBoC d/VqG1fejyo+H0bPP3cetk+uW/ETvSR80Kd2f2kgO2A7bcpkeoZ0+qNVv/yrJLsR +K1PsGNPeSxwgXH8MsqSW35WsbJybrbwtE/vbXq9OkZKSICOT8inMjDKLGhAE0wp y2n/NElZ0LrgXHSt+WgkRUk0sUkL+6PqDHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1684850390; x=1684857590; bh=gdE+dcQizuRxq92HvxIoxB/lQE+OMVaJSaN 1azoGowA=; b=Uw6UiliXmZiS8O9zPo71IzFPgJOg78eZm/2yzWHd3pryQlrC7Rq B3AxYa4rQKOd1icpu71L8vTiHyOxJ0M/ohRln51qcDgD5tAtn6G7oDOu3ZRYGvSd 17EiZEdvZ0J6KsJxgOzK+/PJN5ZnCx7Hpf1K4FWih01pyvD354DyoXCchuzGR1YA 2mja5nDjPZ8/2eB0Rtxqp2t89B/p1zhfOajiJkHiOpnGaFM6OHtEre6syavoGSQA 4wDDlWNivDl+nIdW7BL45HcxRAuxvq88yM+XENsY2SINaPemwB0qZDPNWa+L6oWl AFVYaT/ByGroxV+0zpCd5dJgHr3IPt0n1jg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejfedgieejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtgfesthhqredtreerjeenucfhrhhomhepfdet rhhnugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrg htthgvrhhnpeegfeejhedvledvffeijeeijeeivddvhfeliedvleevheejleetgedukedt gfejveenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grrhhnugesrghrnhgusgdruggv X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 716F3B6008D; Tue, 23 May 2023 09:59:49 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-441-ga3ab13cd6d-fm-20230517.001-ga3ab13cd Mime-Version: 1.0 Message-Id: <60d76601-de3a-498b-9ebd-e09add11f96f@app.fastmail.com> In-Reply-To: References: <20230517125617.931437-1-arnd@kernel.org> <20230517125617.931437-2-arnd@kernel.org> Date: Tue, 23 May 2023 15:59:27 +0200 From: "Arnd Bergmann" To: "Alexei Starovoitov" , "Arnd Bergmann" Cc: "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "John Fastabend" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "KP Singh" , "Stanislav Fomichev" , "Hao Luo" , "Jiri Olsa" , "Jason A . Donenfeld" , "Kumar Kartikeya Dwivedi" , "Delyan Kratunov" , "Ilya Leoshkevich" , "Menglong Dong" , "Yafang Shao" , bpf , LKML Subject: Re: [PATCH 2/2] bpf: add bpf_probe_read_kernel declaration Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 23, 2023, at 03:05, Alexei Starovoitov wrote: > On Wed, May 17, 2023 at 5:56=E2=80=AFAM Arnd Bergmann wrote: >> @@ -1635,11 +1635,14 @@ bool bpf_opcode_in_insntable(u8 code) >> } >> >> #ifndef CONFIG_BPF_JIT_ALWAYS_ON >> -u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *un= safe_ptr) >> +u64 bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_pt= r); >> +#ifndef CONFIG_BPF_EVENTS >> +u64 bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_pt= r) >> { >> memset(dst, 0, size); >> return -EFAULT; >> } > > This is not right, but you've spotted a bug. > bpf_probe_read_kernel > It should be BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size, > const void *, unsafe_ptr) > here in kernel/bpf/core.c as well otherwise bpf prog won't > pass the arguments correctly on 32-bit arches. I tried that before and again now, but could not figure out how to do this correctly though. With this patch on top: --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1635,9 +1635,8 @@ bool bpf_opcode_in_insntable(u8 code) } =20 #ifndef CONFIG_BPF_JIT_ALWAYS_ON -u64 bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr); #ifndef CONFIG_BPF_EVENTS -u64 bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr) +BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size, const void *,= unsafe_ptr) { memset(dst, 0, size); return -EFAULT; I see a ton of other build failures, for every function calling bpf_probe_read_kernel() from kernel/bpf: kernel/bpf/core.c: In function '___bpf_prog_run': kernel/bpf/core.c:1936:39: error: passing argument 1 of 'bpf_probe_read_= kernel' makes integer from pointer without a cast [-Werror=3Dint-convers= ion] 1936 | bpf_probe_read_kernel(&DST, sizeof(SIZE), = \ | ^ | | | u64 * {aka long long unsig= ned int *} kernel/bpf/core.c:1937:39: error: passing argument 3 of 'bpf_probe_read_= kernel' makes integer from pointer without a cast [-Werror=3Dint-convers= ion 1937 | (const void *)(long) (SRC = + insn->off)); \ Though the code from samples/bpf seems to be able to call this without problems. If you have a suggestion for how to do it correctly, can you send that as a patch yourself? Let me know if you'd like me to run that through my test builds. > The kconfig without CONFIG_BPF_EVENTS and with BPF_SYSCALL is very odd. > I suspect the progs will likely refuse to load, but still worth > fixing it correctly at least to document the calling convention. Do you think there should be a change to the Kconfig files as well then? I see a lot of features depend on BPF_SYSCALL but not BPF_EVENTS: HID_BPF, BPF_LIRC_MODE2, CGROUP_BPF, BPF_PRELOAD, DEBUG_INFO_BTF, BPF_STREAM_PARSER, AF_KCM, XDP_SOCKETS and NETFILTER_BPF_LINK. Right now, these can all be enabled when {KPROBE,UPROBE,PERF,BPF}_EVENTS are disabled. Arnd