Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2617145rdb; Mon, 12 Feb 2024 10:21:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVu1jgjqsGfHUcUEzBYIVjiVQiCKelhbKYO65KZNqNlWziSQvTgWJOg3u+wraperLkYA7KqWVpshiDsjrFz69oN7y2zgnVRFEWFTNsrCg== X-Google-Smtp-Source: AGHT+IGQdRgc/crbZxSSA1yZybdENurJe87yZM08pk5Pld84qGN4phjOr2/3ZtPubez8gtALdYZu X-Received: by 2002:a05:6a00:80c7:b0:6e0:e539:4a23 with SMTP id ei7-20020a056a0080c700b006e0e5394a23mr2160162pfb.12.1707762083684; Mon, 12 Feb 2024 10:21:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707762083; cv=pass; d=google.com; s=arc-20160816; b=U1BLcnABeLAxceUMxagnZu45AsbQblFwhWRY2RSnPA/M98R4oLMrCOOinMDp3/FkoR 2NoBNt47RhnjyL9LxSgi/v6dHpHo2xGG8HBeZVvAsmlaN28vr49FNzhmjHQhdQa8Uwhp rvB4i+IBDfC2ERGx0V4RAvw+6L+yUYFgli53btUJTvFHH9wnaN/oA3qVx7cKXcBbxPxw z3/+ehn+s9sZAGW0ZzfytMcrJxYLbjsWGFn5akyrBYSYe3LAGLRobCA7Yha79tTFYsLT gW3Thh7TfD2ghzAnovxuEa641/T8cmFycHDNPS4hCppNPn0H7CDU/epmSbl8FA5zJIqa 8Ujw== 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=Quv90+T3dAOOagaLIeJ9QrwDVUG7gl85SK8F/SFSmzs=; fh=juiqTqbU0ecU7nHIDvxEPGq+Tu4KsjE98p6hdCcwNSk=; b=mqGsdTPWIxNXzd0HpHCI8tVxmy7yLpUmWxcfYS5lWKe7wRGteY0Kggu6KgN5M4hCfR HE+vjmYhl2uZ1+DhZQ8HsiMA3YZp2WNQSOMjOAqHWQcsDMZ8LhfEu4wdsNrhmQ6OKj4E zL/maMhM576xcufc7A6bjxrIdBcOsLmN2+3e29XbS1BtBd7Ethws6oAW+q+kTJOYEGsA RV92/9f8bOzH9+mOje4rLd//JOKqdoaWhjsJGXQuerC8ym/vS47PiAIniaFB3P7pbzFB CM3z0rjnBjVGUVjSfDrrGA6s79/aP7GQXQr9pd4JO/KEloFOke0h/ctVTbvTlSwDMlnH mxEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KQiKOKhv; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-62170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62170-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCXbYWOy5NWeg7I56/76MpY5bKZqyYfHjeJ5SDbmGSSI3ue8/fu7yaLgFaHKhlGPAdbNtmKdnWbn7ktEaf0v0vzcilC5YdWWD5DqKr4vNg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ld16-20020a056a004f9000b006e082230abesi5362743pfb.49.2024.02.12.10.21.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 10:21:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KQiKOKhv; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-62170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62170-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BD28F2833E9 for ; Mon, 12 Feb 2024 18:21:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 122083FE31; Mon, 12 Feb 2024 18:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KQiKOKhv" 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 946173FB2E for ; Mon, 12 Feb 2024 18:21:09 +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=1707762071; cv=none; b=OnKh8rSm/fQYJhReIzhmftg4t6iEezFRgCZsk+VuUOMncvh2+W5ZPO8JJGq3kj4352eCV39Hb5/ieTKMiiHj2PKK4T+BEj2tZv4U2u2sPsSZjdE3eausrRuel05LYFMPpBlpBWMpA5slEKEfIREwBqfbZ9y5eYhkkHHqjnf2nVE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707762071; c=relaxed/simple; bh=Quv90+T3dAOOagaLIeJ9QrwDVUG7gl85SK8F/SFSmzs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=J4dgo7A8a1sgQWhSpRC4m3aSGMb8WniEiKu5urdbNDgE+v6aBK19wB4AsoWybZ2K+HnUs/tH+XZdplikI4fUxcTFgPNQkfUfzh+xqo6dOj3GHO+Z+5Po44Feg86oo7HVWrF9zLuEkijK403QFw3eIcSrzl8R9zopfJXuNP8b8t0= 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=KQiKOKhv; 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=1707762068; 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=Quv90+T3dAOOagaLIeJ9QrwDVUG7gl85SK8F/SFSmzs=; b=KQiKOKhvLEjKM/85IY1noRxaFvvrK/LhrGmf+tlsqAB7bfRWsexvi7ogTiQS0pLOVz20wy 0M9wvJYGeEjfkRYi/8CeY6t59CD0u1nT268sDCmnPtC3nN121hREFJEjpR90zeBHXoM2ER f0fDf0xT0IZtyyAnjw/MryJPaKYWjG4= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-2AqerxGeOOGffMnXnBlYwQ-1; Mon, 12 Feb 2024 13:21:07 -0500 X-MC-Unique: 2AqerxGeOOGffMnXnBlYwQ-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2d0a0bd3ebaso37215591fa.2 for ; Mon, 12 Feb 2024 10:21:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707762065; x=1708366865; 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=Quv90+T3dAOOagaLIeJ9QrwDVUG7gl85SK8F/SFSmzs=; b=RAxFaDdvytk75ZoDfargig8NiQ+4u1+LlwMVhpsAZ4Styw4cwp10YiADxZs+gYyo62 7n69JIC+6HfAbgC+EBGk0FW1iwSvNl4Zd9Nc66Ywc2XHyxC99KaUF8min1VqEJA3w2bR AWfUDVSDz/jNj2pgoG+kZVxGTSVJmzzT5GLf6rRRbZX+BotWo55ip1bzoxySA7QjIJG3 A8cejrJUt8eY2nITBuc0IT6HGrp6GaY+fVwduybY7uhQxRcmT3pZgi9uyGhY4JCXEQ1p HFf9+BgU5pBFLkIykH8Eztts7UPb4Vb6Ar4GSwrIWL2eMV2KkFJ/eg181iG0XPuK/Gs1 uXsQ== X-Forwarded-Encrypted: i=1; AJvYcCWhhriCzqM/wPtE9RW0M8YCCom46KMusE4uQJKKWbzNpxC8e0hZhzyDpeTSgIqHxiVNOwoMNcuOWwfrn8fcfkgDd9VWB4ulBgxuNgKm X-Gm-Message-State: AOJu0YyEevaTJt/nGSt4FELXb5MzLjogwOeytYFoqyraH8HoxkgCGtAs RjvYgn/Z//DwYSXabeJOOEc2+qNBFqF42Vo9Hy45MusltP6cWavermeKA1NWH4ALGpBmm+b7ZN1 adjwfWbwSmL/kbk5Sq57MYNiEXJN2OvYbox9qWOay41r+nsPdmjDboboncTJt7RzlQi2+vw84Lm q+VlRO9JdyggJxGInzKS2caMenwaTyrFt8lQuQ X-Received: by 2002:a2e:9d02:0:b0:2d0:cc80:dcad with SMTP id t2-20020a2e9d02000000b002d0cc80dcadmr5146934lji.7.1707762065702; Mon, 12 Feb 2024 10:21:05 -0800 (PST) X-Received: by 2002:a2e:9d02:0:b0:2d0:cc80:dcad with SMTP id t2-20020a2e9d02000000b002d0cc80dcadmr5146906lji.7.1707762065378; Mon, 12 Feb 2024 10:21:05 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240209-hid-bpf-sleepable-v1-0-4cc895b5adbd@kernel.org> <87bk8pve2z.fsf@toke.dk> <875xyxva9u.fsf@toke.dk> <87r0hhfudh.fsf@toke.dk> In-Reply-To: <87r0hhfudh.fsf@toke.dk> From: Benjamin Tissoires Date: Mon, 12 Feb 2024 19:20:53 +0100 Message-ID: Subject: Re: [PATCH RFC bpf-next 0/9] allow HID-BPF to do device IOs To: =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= Cc: Benjamin Tissoires , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jiri Kosina , Jonathan Corbet , Shuah Khan , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 12, 2024 at 6:46=E2=80=AFPM Toke H=C3=B8iland-J=C3=B8rgensen wrote: > > Benjamin Tissoires writes: > > [...] > >> IIUC, the bpf_timer callback is just a function (subprog) from the > >> verifier PoV, so it is verified as whatever program type is creating t= he > >> timer. So in other words, as long as you setup the timer from inside a > >> tracing prog type, you should have access to all the same kfuncs, I > >> think? > > > > Yep, you are correct. But as mentioned above, I am now in trouble with > > the sleepable state: > > - I need to call timer_start() from a non sleepable tracing function > > (I'm in hard IRQ when dealing with a physical device) > > - but then, ideally, the callback function needs to be tagged as a > > sleepable one, so I can export my kfuncs which are doing kzalloc and > > device IO as such. > > > > However, I can not really teach the BPF verifier to do so: > > - it seems to check for the callback first when it is loaded, and > > there is no SEC() equivalent for static functions > > - libbpf doesn't have access to the callback as a prog as it has to be > > a static function, and thus isn't exported as a full-blown prog. > > - the verifier only checks for the callback when dealing with > > BPF_FUNC_timer_set_callback, which doesn't have a "flag" argument > > (though the validation of the callback has already been done while > > checking it first, so we are already too late to change the sleppable > > state of the callback) > > > > Right now, the only OK-ish version I have is declaring the kfunc as > > non-sleepable, but checking that we are in a different context than > > the IRQ of the initial event. This way, I am not crashing if this > > function is called from the initial IRQ, but will still crash if used > > outside of the hid context. > > > > This is not satisfactory, but I feel like it's going to be hard to > > teach the verifier that the callback function is sleepable in that > > case (maybe we could suffix the callback name, like we do for > > arguments, but this is not very clean either). > > The callback is only set once when the timer is first setup; I *think* > it works to do the setup (bpf_timer_init() and bpf_timer_set_callback()) > in the context you need (from a sleepable prog), but do the arming > (bpf_timer_start()) from a different program that is not itself sleepable= ? > Genius! It works, and I can just keep having them declared as a syscall kfunc, not as a tracing kfunc. But isn't this an issue outside of my use case? I mean, if the callback is assuming the environment for when it is set up but can be called from any context there seems to be a problem when 2 contexts are not equivalent, no?