Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2022483rbb; Tue, 27 Feb 2024 08:18:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW+fgLVXyypj88CkJFrb2eDsIjaeYalV7jQJVNCXCmY8v0Dknb6jyQgnuKqpK6D0TE3LLY9zo6FJpsOdDJ5pyBZURHFE8Id+mmq8pAf9A== X-Google-Smtp-Source: AGHT+IHwDrkt2hs0nD1nAOPjCx/Q+TBwcGUpccQc0kasiA/oPxppXnEh7JRtLGgozmazeX3PjOZL X-Received: by 2002:a17:902:9683:b0:1db:ceb0:2022 with SMTP id n3-20020a170902968300b001dbceb02022mr9955729plp.27.1709050718454; Tue, 27 Feb 2024 08:18:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709050718; cv=pass; d=google.com; s=arc-20160816; b=zFvFrcIB7OidgCq5PcOKbQOJxh8Ap39WrmYilo73Xvu2YnPWSvwpBJezpO+IMMnz6A c2xjgWNFNPj7kENPHgRIhBLicrV3e1Uh79J8j41pduUN25fLul/2acaWJF/F65rIH3qj COO+1m9rjlx5abri4KUpBE3v7YI5qg+KD3+7Vxg+gO3Px67a0cdOUc3H12OLVGxwDtDC qvPVG9ufk7exP9kqC2w8ohfN9lNjRdob0iuxdfRdvCDdJVpMoDp7WuX8Wjv23C/eihVs ai1nPiAVWtXE/DmQ3aX13qcWa4FbvlOEGl/s+2fpy+XHOYzaTHmO5b5BmbNJOdgH6ytX /EFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1/m9/LqtdCRbXI2nBLjiPiC94m6CsXp72hoYSiA33hU=; fh=nRK4yoTKg1+cQ3tvzSbLaTNNdRWe7mZSggDF7kMMBLg=; b=VYh5dDihpWaiTckQVlDHguNAAYp/TUIi8pzh7IIh+DGBfXn1oQDm4D0EyFWLffIGS+ UtpkVjawhGvW/cQD+W8AZIvQ4G6+OCJEgrzPG9S31b8PYzVlU9kY86Ced0YvMwzOIXn3 91GYJwOeG+gETtMWKsSAGhgsQ7lbxh9TMED8GAs2VKGVGk2JV1MdgsZ0/KQj7Z6X2Lmv gcH6bTRXCVyoPx9rAl6dNgdIHn7+qaJgFGDFzj35uP1AUUpFX39PtH9RIv8/6xsn5jeV KOOY00lLtp2z3FeFYPxLkqmnfkPC2yU6llSwPyDZkVeAXRcO/1DjMQ8c7cSDg9xUrvg2 cvZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dnLbJFsR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-83585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ay12-20020a1709028b8c00b001d8ca62ce0fsi1538913plb.637.2024.02.27.08.18.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 08:18:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83585-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=@kernel.org header.s=k20201202 header.b=dnLbJFsR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-83585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 EA24428827E for ; Tue, 27 Feb 2024 16:18:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3C9B1487D3; Tue, 27 Feb 2024 16:18:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dnLbJFsR" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BFDA91482F5; Tue, 27 Feb 2024 16:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709050706; cv=none; b=DfmlKcOsjgtYNOtC2uDGaSvYeQD15AydW7N+gV31yU/oL3OnvP/ITxtUH501M+Lpe/zARUqMpgLwp2v4QUDw1nOaQpF1m/qQ8fmSt2qGxo8VhmCbRYgWJrLmAEBQlDJ8Ti4pKfS4WrcO/2SFFgzPyFm6fNuCb0m4dMVA6AhQSSg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709050706; c=relaxed/simple; bh=S3QekCPGG3TBM+vOEI8NezVuo8KDNDTXQNBL2mYsxQw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pVlVfBYvr2QNWJLp4KDY0/VnmQ2oBSRfrLP0Kg2xmlQDM/n86TUJo995xvJTf55oNLz6cI+iYLivtY/wTqZMHfi3iZr55p9QMSqGmtyPbLrCV9DyIgWIYjuolZ0b978RKHqvn57n0LbgBGKy3o2uM0Xcrlm9M1i021byXu2VIjk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dnLbJFsR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27F03C433C7; Tue, 27 Feb 2024 16:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709050706; bh=S3QekCPGG3TBM+vOEI8NezVuo8KDNDTXQNBL2mYsxQw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dnLbJFsREb6KPExRQSL+P4hCQKpjoKhmFKNpqGZA9HBj8Wc9uWWHr6bBpF6CERK1q W/6afuHi18HSZ/JKNaEYicNaQDMjMA+H8Aos7xrYY7EVjpwCh4wvT8jCjqTKii+yDg i0/uGS5YMnSrGqVpPBF7T7U4sNmzB7eSRt5s1MVBDPzMhW65lwAPeTvk/MiHFcuPhP prH8iPPTuQ6UrcrcbrJQI3FFGowe3SMLWDpe4pzFd61XM5VrL5MM1qOuuG/Uqxw+Xb 1L732slS1bPopC5DOnnbfooGjkdAdlFdCABORCJKPB2qQCAoZraSrYLPj0/yw/yIou mddSw63BaXFdw== Date: Tue, 27 Feb 2024 17:18:19 +0100 From: Benjamin Tissoires To: Eduard Zingerman Cc: 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 , Benjamin Tissoires , 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 Subject: Re: [PATCH RFC bpf-next v3 08/16] bpf/verifier: do_misc_fixups for is_bpf_timer_set_sleepable_cb_kfunc Message-ID: References: <20240221-hid-bpf-sleepable-v3-0-1fb378ca6301@kernel.org> <20240221-hid-bpf-sleepable-v3-8-1fb378ca6301@kernel.org> <55177311ccdc24a74811d4a291ee1880044a5227.camel@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55177311ccdc24a74811d4a291ee1880044a5227.camel@gmail.com> On Feb 23 2024, Eduard Zingerman wrote: > On Wed, 2024-02-21 at 17:25 +0100, Benjamin Tissoires wrote: > > This is still a WIP, but I think this can be dropped as we never > > get to this instruction. So what should we do here? > > As Alexei replied in a separate sub-thread you probably want this > for sleepable timers. Here is full source code block: > > if (insn->imm == BPF_FUNC_timer_set_callback || > is_bpf_timer_set_sleepable_cb_kfunc(insn->imm)) { > ... > struct bpf_insn ld_addrs[2] = { > BPF_LD_IMM64(BPF_REG_3, (long)prog->aux), > }; > > insn_buf[0] = ld_addrs[0]; > insn_buf[1] = ld_addrs[1]; > insn_buf[2] = *insn; > cnt = 3; > > new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt); > ... > } > > Effectively, it sets up third function call parameter (R3) > for timer_set_callback() to be prog->aux. > E.g. before bpf_patch_insn_data(): > > r1 = ... timer ... > r2 = ... callback address ... > call timer_set_callback > > After bpf_patch_insn_data(): > > r1 = ... timer ... > r2 = ... callback address ... > r3 = prog->aux ll > call timer_set_callback > > This way it won't be necessary to walk stack in search for ctx.aux > in bpf_timer_set_sleepable_cb(). 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 it in my bpf program, or I get the following: # libbpf: extern (func ksym) 'bpf_timer_set_sleepable_cb': func_proto [264] incompatible with vmlinux [18151] And if I declare it, then I don't know what to pass, given that this 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 struct with scalar Maybe I should teach the verifier that this kfunc only takes 2 arguments, and the third one is virtual, but that also means that when the kfunc definitions are to be included in vmlinux.h, they would also have this special case. (I just tried with a blank u64 instead of the struct bpf_prog_aux*, but it crashes with KASAN complaining). Cheers, Benjamin