Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp224424lqo; Tue, 7 May 2024 19:03:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXA50YmwjBYnocuw3/Ma9UvsWX7uRCY92jKPKlDlDW1JrwP/CarK0/7ArRfmIxWAsJo3FkfAvDD2KbTJ7xfDBBRNI/QIhdjyLAOe5e7nw== X-Google-Smtp-Source: AGHT+IHn2vmia/sl/gAclnLWW3vEDM8r7OI8tE88kMaXpOuaQCUUU/4v1duMzkjo3f3J++zZdeTy X-Received: by 2002:aa7:cfd2:0:b0:571:bc22:e32 with SMTP id 4fb4d7f45d1cf-573110235e3mr3849406a12.8.1715133817154; Tue, 07 May 2024 19:03:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715133817; cv=pass; d=google.com; s=arc-20160816; b=xs7+6rK4EwxQ2O33ina0u4yzqt1FxvwB3fIVUhemS7hHZ/l6jKFYinZbcWPAuH7EDe GE8V+LI1fx2tjxI68vzfzaYP7vA4F3DNSc5V6aUs7yU0sOlkvJZxa7rE4N3cqLajoMVk bBdHprIrE9NPAEoso53fUG87HDCwaIVoVEPiEI9ZNYK9EW532baC8a1nRVZM4pp6YvlP 9d2y4rXifTOgmbWiOVpg3PvvvKxiZWUUxORyPxwTP4iUXrYLCd46OdwY5T1beLhYx/a9 GAdvWsS7lZ5JBjbGIDRZE72PqQNVWmHLtC8781JU5+U/rSAwsUSVwMF7rtjR1Ubj2eha IWQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=W9c1/LUlqt+J7rmgnVdnVICk6caTmrVCrm7z1rP5LHs=; fh=01Mrc1GaFWIjCnNBc5wZ8+yEwpZXxyi5Iu72ThBzPQg=; b=cnt6/c+1Y5v5Ibk2B2QcLxDgm2y4c+EDGVZmTVMcWruYjWBMDayYweRx85Qqqvv0rJ Nw0B2G4kyQMqmwRGfzp6S9NYvJwHMjSrGQNpvbXtxLQfxfg41qrSYVSNbqCWq8/soNn1 Fe62Ze5kjibJn7Pl83Kbt0vlN4HJ0HKyDOLw0Tcd37rDJhHK4aAtvmG0i2GXfkFH8Oeh 4xnZZYKf9D1MVd5P3rUJBQcbNQkefzwNy0IdR/rxW/B5jUsiM397HvCwTH7CQq8MeuP8 SngyKumIggLJhK4LK2aAS2kWJlZQCbJyytiXEJ4i2pMu+6V6D56OKgPp83/tEWuechz2 ycBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=C412zg8X; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-172617-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172617-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t25-20020a50d719000000b00572bb71d128si6539385edi.57.2024.05.07.19.03.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 19:03:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172617-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=C412zg8X; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-172617-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172617-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id AD0C31F25351 for ; Wed, 8 May 2024 02:03:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF59CAD51; Wed, 8 May 2024 02:03:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C412zg8X" Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AA5D8F4E; Wed, 8 May 2024 02:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715133805; cv=none; b=dV3M1PRpdPcofD7Isp3xeWVsrwOvGNxiEr2i4BmYZhB75XWe4vYUGVFqaIrzUtv9pUP5IxLxIMuuBZQU0QxyfuQgm/Dxwf1hZNFjOeoeBZduND8H995+3jm9viAsNom30VY/64AhsVqDDwpweD8akW8SerLB0GU7XgeFFP9FRx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715133805; c=relaxed/simple; bh=W9c1/LUlqt+J7rmgnVdnVICk6caTmrVCrm7z1rP5LHs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Qeg4uLiJnQXVX1In/QwgRRn0DPYEwrvLS3Abf2Wsi2nYJ73kyG4Pc4J/PH3VQtorf6o0qPl9b1hRixvz6QDZeShiEL42OmrLliwhNm35n6pIcpqgtir5J4lprPB/a/SNmgpPGzFnF1dsk5jGWIVnaKBMZOQRHNcaFBNy9Rmd9lc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C412zg8X; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-41dc9c83e57so1708585e9.0; Tue, 07 May 2024 19:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715133803; x=1715738603; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=W9c1/LUlqt+J7rmgnVdnVICk6caTmrVCrm7z1rP5LHs=; b=C412zg8Xt8F2OPhxzBV7YlWybAFpT9q/QIUEy+DznUdO8w67kUODVlW8i1g71OH7gy u/87nzk+fZZf1qLRmh3tyOBH7JI5olnWdWB/HUgmdci3S0nXuP/2NVg5iFdpta05L6YL LIp0L7U8swahezseHS4986SQKq6QF1Y8HNe2t4ZaK6TA8B2PNwx/wjj2nCfShS1cH9f2 wrM4c1UvNoYT8+QP20auZvHrRdJFcdC9ncZdcbh5o86E5rNseZK2oCROU7REjlgQDVFL 4dbC8KW6XD7xFrMwv1guWKapg8chQ75ClkRpPj6YZ0B+rQ1igRnulV1qRt8iQVYhuLei meXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715133803; x=1715738603; 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=W9c1/LUlqt+J7rmgnVdnVICk6caTmrVCrm7z1rP5LHs=; b=NO6+k87HNlDVO1zTPgBYoqyvA6DOCrQ/R5CwpR6KT9Z3bODFQDmZ1vbiHihJdjlgAU wXNJVheP5eDQ+YQNKo6UkIIB13RGCFcYQ1lR82Qynzk+yQRc8VVVwgEX8doSV/ZWnsCo yQJ+x3MtWsmOMWj26iUSf3DcMbkxiUMBuRUIMrtcZ9O+R+rIAT5GXzRzELsKN8lBYxH7 7mTXU67JudIk1OEI+sEdzD1AOMGdp+iXCZ3goh6aKhBPhChc4qNi0ZtPrdw1vLlQ4MaO 0TyJGoLlpkX7ZPciomkYC5xnnvkcR3WwkUWwUxIt/sRgidzuqcD6Ls2j83dBk5XDElkF 9nAA== X-Forwarded-Encrypted: i=1; AJvYcCWu99o4MxHNVelNK71xLWRje7vSOmBsOyy7gOzK2LAYgBPEVnF+V1GK1xJE2VGDxG2LffF3/luGuYwu5vmfiTI9w5MZFv3NVr1fl484UHNx7cMDJGAZxTBPlIMiMxZzfSzk X-Gm-Message-State: AOJu0YwMIp9eh0tkA9+7fgF4c6ntraUf4TecPV9yUTM+4ZvF296dWod4 NcZFltMP/+Z78uMG/AzbjgJpJb85/0CBXpGLXimo15aaIxFzSyasjjxCMDEk1ViJcuZqYrgHvaj lh9Q7qWrNT1f4i5da1MFJT6PoxgQ= X-Received: by 2002:a05:6000:d8b:b0:34e:8a10:3c2 with SMTP id ffacd0b85a97d-34fca90a7ecmr1140017f8f.24.1715133802457; Tue, 07 May 2024 19:03:22 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240422-sleepable_array_progs-v1-1-7c46ccbaa6e2@kernel.org> <7344022a-6f59-7cbf-ee45-6b7d59114be6@iogearbox.net> <35nbgxc7hqyef3iobfvhbftxtbxb3dfz574gbba4kwvbo6os4v@sya7ul5i6mmd> In-Reply-To: From: Alexei Starovoitov Date: Tue, 7 May 2024 19:03:10 -0700 Message-ID: Subject: Re: [PATCH] bpf: verifier: allow arrays of progs to be used in sleepable context To: Benjamin Tissoires Cc: Daniel Borkmann , Alexei Starovoitov , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 7, 2024 at 6:32=E2=80=AFAM Benjamin Tissoires wrote: > > Yes, exactly that. See [0] for my current WIP. I've just sent it, not > for reviews, but so you see what I meant here. The patches helped to understand, for sure, and on surface they kind of make sense, but without seeing what is that hid specific kfunc that will use it it's hard to make a call. The (u64)(long) casting concerns and prog lifetime are difficult to get right. The verifier won't help and it all will fall on code reviews. So I'd rather not go this route. Let's explore first what exactly the goal here. We've talked about sleepable tail_calls, this async callbacks from hid kfuncs, and struct-ops. Maybe none of them fit well and we need something else. Could you please explain (maybe once again) what is the end goal? > Last time I checked, I thought struct_ops were only for defining one set > of operations. And you could overwrite them exactly once. > But after reading more carefully how it was used in tcp_cong.c, it seems > we can have multiple programs which define the same struct_ops, and then > it's the kernel which will choose which one needs to be run. struct-ops is pretty much a mechanism for kernel to define a set of callbacks and bpf prog to provide implementation for these callbacks. The kernel choses when to call them. tcp-bpf is one such user. sched_ext is another and more advanced. Currently struct-ops bpf prog loading/attaching mechanism only specifies the struct-ops. There is no device-id argument, but that can be extended and kernel can keep per-device a set of bpf progs. struct-ops is a bit of overkill if you have only one callback. It's typically for a set of callbacks. > Last, I'm not entirely sure how I can specify which struct_ops needs to b= e > attached to which device, but it's worth a shot. I've already realized > that I would probably have to drop the current way of HID-BPF is running, > so now it's just technical bits to assemble :) You need to call different bpf progs per device, right? If indirect call is fine from performance pov, then tailcall or struct_ops+device_argument might fit. If you want max perf with direct calls then we'd need to generalize xdp dispatcher. So far it sounds that tailcalls might be the best actually, since prog lifetime is handled by prog array map. Maybe instead of bpf_tail_call helper we should add a kfunc that will operate on prog array differently? (if current bpf_tail_call semantics don't fit).