Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2476737rbb; Wed, 28 Feb 2024 03:08:07 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUW2oCn6siQQtwoswceRdAKXBv8MQdKPZE2ctN2fT8kr5ThutaZbd9VRSK/C6ZeqUfw+6C9Rxr+Y6qlW6+oOiTJIHgY+xDsQ5ZGWdXaBA== X-Google-Smtp-Source: AGHT+IFXR0cdrQCa2YFZuskkCA6bd20hl4usfMXpbwdcVhgRXE1IqLUz1Ee97kTII8YawYOItARw X-Received: by 2002:a05:6a21:3482:b0:1a1:101c:7c70 with SMTP id yo2-20020a056a21348200b001a1101c7c70mr3745158pzb.59.1709118487361; Wed, 28 Feb 2024 03:08:07 -0800 (PST) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r142-20020a632b94000000b005d8c18c7c65si7122850pgr.671.2024.02.28.03.08.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:08:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@redhat.com header.s=mimecast20190719 header.b=D2+SL82W; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-84846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84846-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 48152B2274B for ; Wed, 28 Feb 2024 11:01:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1247912BF15; Wed, 28 Feb 2024 11:01:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="D2+SL82W" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44792129A96 for ; Wed, 28 Feb 2024 11:01:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709118101; cv=none; b=QTIH0OSHfA7viLXjFNyVLLxXUXX40YDiAyU03MpnwyP2J8AUHoPaCLP/oWfPogL0ZkHF0eKnLSEbbEPguRlVZALKdUs7piVJFBqO74Q5BUiFH+wZdVGmobXmtfE0ZRZZ0HrPaLZO5w7i97P2XFziuUMXxeeej3Q7vFZz7tAMWNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709118101; c=relaxed/simple; bh=8OgkdCAnRjKaw3j4wSYcHFa/xxgMjTCLQm7+X/e43Tc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=dBYAkZ33PN4nIpDKDhjVpEpdqKr23qRT7u+8J1TdvYoT9o98RwnS9Qg2I7UQfCQap70ZYU4Uea4eREefeCT+wBDwkc5xPn3KQi5T/SuS7ybFvJLmW0VYa/1209nbxcd09hIVyy4j/0oYVViAQTzj2yFvh10N46BAKE9PpTHjRLc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=D2+SL82W; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709118098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KHUgioFTWud+yVu8FFp4Z9cGICZSxHxVkQZdXkVKoZc=; b=D2+SL82WvSHLJ1dVq1XVDX1hBr7rGoggsxClyk1BmcHnrW/8WiRA6T9Hml3PukRuvMKbjT Tqqc7NKU2o4i3/reYgLquOOGYgeXxrR0WHAPTSUynvJKcVo/WUrpDevYrH8hJ0XJINw3bi r2MVrnObelOXG8fc7rRX2HNxHfrsbUA= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-IcMtDDVwMaCcgGAR-QAASg-1; Wed, 28 Feb 2024 06:01:37 -0500 X-MC-Unique: IcMtDDVwMaCcgGAR-QAASg-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a4314ed2638so188717966b.3 for ; Wed, 28 Feb 2024 03:01:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709118096; x=1709722896; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KHUgioFTWud+yVu8FFp4Z9cGICZSxHxVkQZdXkVKoZc=; b=NJh7ELseLEcWfyrHa2vysxADaXTdJ84MaZhfK12EabQe18hcQ+aitoZOS9lZSpJPby XMWNeh+p0ksQCukgxbnJwW1znZl00Re5PI3p4Tc3sDrpVY/w/Sb4ubxHy7WT1tjaIQVt ftlCVb9BS8XWQcYOdgYir3MFoP7n1W0X9kWR0RgXI9rauclycBKBl65fzaiBFCEeYuCc 3iBk3Tu99ta//LiKm+GaYVl47DWPJZJ9wIEydpNks58ef+eT+QlmSBzvnxm8O8bgXXh8 1m0NlRe4+m5g/FeKcuTvOF+rvArfWos0a/368WEgBcm5LEIj3nRZJhYPB2qHRhnxom4o SnOQ== X-Forwarded-Encrypted: i=1; AJvYcCXqUcO5asv4rD9f4jwhlTg9en5A2rmbkL8WqeF9xnznltVuMEww3kELkPuLi6cMi2F3SP5iEWCpqpwQYkVGvfH2J4wQ/XQf0xvaR4+I X-Gm-Message-State: AOJu0YyygqzODVdmRaLOjuw9W/kokZ/P51eZeFe8NWC0wqsNDVJCfS/G fd7bVIyKuKDuhZdrTESdt/pU7wpPFSqaPDnGZllcPlVG1JwArFQzE8sRI1AY00xHyFYnOqZ7eY8 75wXcsS3D+GokIheJGqcZ58YoJxf3CLQ6e2amMzOEmF2sqhXQlpO3M0OytT/ED5RWsms4s/94xQ bZHbnhwTMGnXfyWgHLqvP7xZDlL6cJRw7SneDe X-Received: by 2002:a17:906:1450:b0:a3f:c6a6:3b79 with SMTP id q16-20020a170906145000b00a3fc6a63b79mr8266996ejc.6.1709118095846; Wed, 28 Feb 2024 03:01:35 -0800 (PST) X-Received: by 2002:a17:906:1450:b0:a3f:c6a6:3b79 with SMTP id q16-20020a170906145000b00a3fc6a63b79mr8266966ejc.6.1709118095447; Wed, 28 Feb 2024 03:01:35 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240221-hid-bpf-sleepable-v3-0-1fb378ca6301@kernel.org> <20240221-hid-bpf-sleepable-v3-8-1fb378ca6301@kernel.org> <55177311ccdc24a74811d4a291ee1880044a5227.camel@gmail.com> <9a35a53a1887fb664fd540ec7e272cb3ea63f799.camel@gmail.com> In-Reply-To: From: Benjamin Tissoires Date: Wed, 28 Feb 2024 12:01:23 +0100 Message-ID: Subject: Re: [PATCH RFC bpf-next v3 08/16] bpf/verifier: do_misc_fixups for is_bpf_timer_set_sleepable_cb_kfunc To: Alexei Starovoitov Cc: Eduard Zingerman , Benjamin Tissoires , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jiri Kosina , Jonathan Corbet , Shuah Khan , bpf , LKML , "open list:HID CORE LAYER" , "open list:DOCUMENTATION" , "open list:KERNEL SELFTEST FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 28, 2024 at 2:49=E2=80=AFAM Alexei Starovoitov wrote: > > On Tue, Feb 27, 2024 at 8:51=E2=80=AFAM Benjamin Tissoires > wrote: > > > > On Tue, Feb 27, 2024 at 5:36=E2=80=AFPM Eduard Zingerman wrote: > > > > > > On Tue, 2024-02-27 at 17:18 +0100, Benjamin Tissoires wrote: > > > [...] > > > > > > > Hmm, I must still be missing a piece of the puzzle: > > > > if I declare bpf_timer_set_sleepable_cb() to take a third "aux" > > > > argument, given that it is declared as kfunc, I also must declare i= t in > > > > my bpf program, or I get the following: > > > > > > > > # libbpf: extern (func ksym) 'bpf_timer_set_sleepable_cb': func_pro= to [264] incompatible with vmlinux [18151] > > > > > > > > And if I declare it, then I don't know what to pass, given that thi= s is > > > > purely added by the verifier: > > > > > > > > 43: (85) call bpf_timer_set_sleepable_cb#18152 > > > > arg#2 pointer type STRUCT bpf_prog_aux must point to scalar, or str= uct with scalar > > > > > > Right, something has to be done about number of arguments and we don'= t > > > have a convenient mechanism for this afaik. > > > > > > The simplest way would be to have two kfuncs: > > > - one with 2 arguments, used form bpf program; > > > - another with 3 arguments, used at runtime; > > > - replace former by latter during rewrite. > > > > It's hacky but seems interesting enough to be tested :) > > Too hacky imo :) > > Let's follow the existing pattern. > See: > __bpf_kfunc void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign) > > __ign suffix tells the verifier to ignore it. > > Then we do: > #define bpf_obj_new(type) \ > ((type *)bpf_obj_new_impl(bpf_core_type_id_local(type), NULL)) > > and later the verifier replaces arg2 with the correct pointer. \o/ Thanks, it works :) > > > We also could use the suffix (like __uninit, __k, etc...), but it > > might introduce more headaches than the 2 kfuncs you are proposing. > > Only one kfunc pls. Let's not make it more complex than necessary. > > We cannot easily add a suffix to tell libbpf to ignore that arg, > since bpf_core_types_are_compat() compares types and there are > no argument names in the types. > So it will be a significant surgery for libbpf to find the arg name > in vmlinux BTF and strcmp the suffix. Yeah, I guessed so. Having a single #define is fine, especially given that there are already a lot of them for the same purpose. > > > > > > > > > Could you please provide more details on what exactly it complains ab= out? > > > > > > > Well, there is a simple reason: that code is never reached because, in > > that function, there is a `if (insn->src_reg =3D=3D > > BPF_PSEUDO_KFUNC_CALL)` above that unconditionally terminates with a > > `continue`. So basically this part of the code is never hit. > > > > I'll include that new third argument and the dual kfunc call in > > fixup_kfunc_call() and report if it works from here. > > Something is wrong. fixup_kfunc_call() can rewrite args with whatever > it wants. > Are you sure you've added bpf_timer_set_sleepable_cb to special_kfunc_lis= t ? > Yeah, but as I mentioned, I wasn't hacking at the correct place. I was not doing the changes in the fixup_kfunc_call() but in the helper processing, so that path was not hit. But with your instructions it works. I have a couple of changes to do and the selftests to add and the series will be ready. Cheers, Benjamin