Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp163160lqd; Tue, 23 Apr 2024 19:56:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWr8C5y+BGXYJ0kf9WYkRkiCi/C/YFd2lmPOteuEqjAyBzcaZgzd/e8L0+EjKnrcdFMVqKYaq16O1PkksraeACiWTYYb+JmSn/ZIOUcYg== X-Google-Smtp-Source: AGHT+IHFhMTVxyP/IJI7f9f64ms9t6GR4be9Ea+3bNFiksQjWAbQoebv9AhDvOY0xSsn2kNLQgQA X-Received: by 2002:a2e:9258:0:b0:2d4:6f14:53d5 with SMTP id v24-20020a2e9258000000b002d46f1453d5mr583415ljg.26.1713927396316; Tue, 23 Apr 2024 19:56:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713927396; cv=pass; d=google.com; s=arc-20160816; b=NUmk0i/T2LRbeiVlL1DLTDospmuH/dEfehfznGHjkC/PIN9XzZM6QqkiNhEbwYv9E5 7QLanjz7aUUG6E8FS8SSk099DYzoC8sNbMtjKN3KxsQI9EXUveeBFXQ69iv/zpYUZhyK jhAIC2MTke9bO5OPdtdtLnd+UeWBPmf9KV3I3FnG5R/4pbqf3X+42NNwIxrTmS2qcqUU MsPTdTpQskEcj4kqjKz5R39qHSALyQRUsX79UnPoWXCyX9hlHmLFjk9O0ZQHxs53a2SL lLuXMWiGIsL9cuS852gAjXn0iUxXF90ZFqw2ne9Qf1SSP0JXyScqi4vz/MpI22mT7MvK ky9A== 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=B917gxSMtiV9f/CrLtxYPwm85pplJTB5epaSS3BtCKg=; fh=5f5ep4Mofe84zj9Y2iATvxi+tw/CJ5Ho8+C8meJcGrI=; b=0h4CVBtFjzK5i7FNCpwhJMs0Oyc012MwUA65jTj1swy6rEAwDeHKoajR142qp+t+dJ AHxbveeHrd1LBcVGFxU3EIEXFGi0Impsv4WZVVQFHiueCaLRivG2oF9eAqYuGBNZPKPM Gi8+x4SiUa6g/urNjvDrB8UWxYhtal63EJYSw09JlL4PoCCTbNmtCVqjU1vovJaGkM5y FZvndenCNVN+hsVEZIRKIdGnTyiPsjA33ciLG/bIhEUTyCgvvbG7/aAHUchm1BAbsZN6 hMFVWxjHv9cQ6hBuNcJg4Ok+EVgp3ZLzmfxA70IsZVpJlzHoCQqXR5VmXKZQ3Zh9ARQd rILw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=N6kHTLcj; 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-156177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156177-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 v16-20020a509550000000b00571e95313cdsi5195313eda.625.2024.04.23.19.56.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 19:56:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156177-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=N6kHTLcj; 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-156177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156177-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 D9E241F21EE2 for ; Wed, 24 Apr 2024 02:56:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7135586254; Wed, 24 Apr 2024 02:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N6kHTLcj" Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 D783E171CC; Wed, 24 Apr 2024 02:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713927387; cv=none; b=tWAS3PeQTJ5Wd0kdqiEwMJB1stT+vYfoqoyz0rrSkLp9JPPWp+aTC0I/BLW+PvCON5IpgTadxSIXGcoiPUk1o3HsLFgGkPMmeBSPjOvIEJWiZ+WPv8ISrfN5JIa8SDNl/JGI7t7LPMI/X9MO4Ft5dSe4GuKWTJboFIikHMiBnXo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713927387; c=relaxed/simple; bh=3F8Ljp1pZPV1emCV1Jv8jlUViTo++vaW01K6L3+V/Gg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=RXC/IYCuMyrdQE9outf51WekzYUxqD5jonzhmjhPu/h14YpVFuKvtBkWUeJ2x2s4M0MuZjh/PCwNfHSx3b2nfmZ/nCIqTLLxtGcGE1W9ILsrUwjAmvvgg3lCCIRm7AZzLl/eaPNtVG7ffDlQLLkzuYilSSwgCGPr+8r1C42Sz74= 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=N6kHTLcj; arc=none smtp.client-ip=209.85.128.42 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-f42.google.com with SMTP id 5b1f17b1804b1-41a72f3a20dso20519165e9.0; Tue, 23 Apr 2024 19:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713927384; x=1714532184; 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=B917gxSMtiV9f/CrLtxYPwm85pplJTB5epaSS3BtCKg=; b=N6kHTLcjuzxm4wWk7PWe6KBAiqBmc3E1fSimVps6dgViVITTCDQqPPPHrro3hGLTZW MwtNtef42raDCpSA/D7rl/mrcW8Ro1Us71IGWsKO9Bh6t37IYbzRO2yQpINvG3wlp9QF fe2SZkhKAQoZpAwHYGJB4npn2cM5jhd3KssBkVX1nu6nxlqWOMBHyunw3QimxgmKIjuX 19OkUqxh/m1yK6Nhw0yqoz9bZpxTFE6r3VZQHS7mQTgFIoQH+T+H2IivC3hRGA6chM1U sP5E1aWzEeKgwtPxlh+XhiuoNAuymSaHKDAc1ZjGkCdDMawYFkaZmSmvhkhQ3FfH/l6o C4kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713927384; x=1714532184; 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=B917gxSMtiV9f/CrLtxYPwm85pplJTB5epaSS3BtCKg=; b=ESiqcSvD+IFjn0NEF0ezb1TT+j88u4F+kcOl90Xi568w4itdQRVj2cBoCjbCx45jJg KPsY37evdZKTviCuH+KL1tIe0CMaFS6MTyszs6l085qpNiTK76y8/0NIcyAocel7KWaA Zgxa6Ceb3wnFb3OQ9duEQlptAIJ/jkXADJJmi+KDnoDpqdLoe/MO8F4Msgt84VzCEmON WmLuP4rotB2IUSrpcCeCBvI/xSnuBL408u+ng8tdzZXnGr7M3TN3Wj+IZXYGJyBKkElb W9/pldUkf29UpTDhHVnxj+QC7Xe/yXQTpZkvo4H6f+lBKbiI7qpWXLoYVcnJCzJ1tOtx ZiQA== X-Forwarded-Encrypted: i=1; AJvYcCXHBkDfL+nseciS617Enym5o/qi6Sm1scuQI+fJ5WP11bFuoHh9jp5dxpFn5qwf4VXfwpdTw9e85jl8rsqfIh/Qh3eOy5FsxgBd76rghQYFa+3/vnAg3w+iWQmcImvFPJUPx/wbY2Q4vIYdeO2btoEujMDEiv/0BG1EPHM7xk/Uj21E X-Gm-Message-State: AOJu0Yy9PyCDNw2i83K5ycqgrb85b00QtDp2L/D26EOLjlatzHNgUQLK qbbSMiZSL3fFtdEUcPqWexXCRsUT3X6mbWUTTqbZ/zqCmsqhSBUtATKOMrghnLF66ksqujgU7jl 2ujSM1IydpIx6WBIVMS6RACH7yew= X-Received: by 2002:adf:ec49:0:b0:34b:e79:2677 with SMTP id w9-20020adfec49000000b0034b0e792677mr707877wrn.63.1713927383986; Tue, 23 Apr 2024 19:56:23 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240420-bpf_wq-v2-0-6c986a5a741f@kernel.org> <20240420-bpf_wq-v2-13-6c986a5a741f@kernel.org> In-Reply-To: <20240420-bpf_wq-v2-13-6c986a5a741f@kernel.org> From: Alexei Starovoitov Date: Tue, 23 Apr 2024 19:56:13 -0700 Message-ID: Subject: Re: [PATCH bpf-next v2 13/16] bpf: wq: add bpf_wq_set_callback_impl To: Benjamin Tissoires Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , bpf , LKML , "open list:KERNEL SELFTEST FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Apr 20, 2024 at 2:10=E2=80=AFAM Benjamin Tissoires wrote: > @@ -11018,6 +11027,7 @@ enum special_kfunc_type { > KF_bpf_percpu_obj_drop_impl, > KF_bpf_throw, > KF_bpf_iter_css_task_new, > + KF_bpf_wq_set_callback_impl, > }; > > BTF_SET_START(special_kfunc_set) > @@ -11044,6 +11054,7 @@ BTF_ID(func, bpf_throw) > #ifdef CONFIG_CGROUPS > BTF_ID(func, bpf_iter_css_task_new) > #endif > +BTF_ID(func, bpf_wq_set_callback_impl) > BTF_SET_END(special_kfunc_set) > > BTF_ID_LIST(special_kfunc_list) > @@ -11074,6 +11085,7 @@ BTF_ID(func, bpf_iter_css_task_new) > #else > BTF_ID_UNUSED > #endif > +BTF_ID(func, bpf_wq_set_callback_impl) This is broken on !CONFIG_CGROUPS. KF_bpf_wq_set_callback_impl in enum special_kfunc_type won't match special_kfunc_list. I moved this line up while applying. > > static bool is_kfunc_ret_null(struct bpf_kfunc_call_arg_meta *meta) > { > @@ -11402,12 +11414,28 @@ static bool is_sync_callback_calling_kfunc(u32 = btf_id) > return btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_add_impl]; > } > > +static bool is_async_callback_calling_kfunc(u32 btf_id) > +{ > + return btf_id =3D=3D special_kfunc_list[KF_bpf_wq_set_callback_im= pl]; > +} > + > static bool is_bpf_throw_kfunc(struct bpf_insn *insn) > { > return bpf_pseudo_kfunc_call(insn) && insn->off =3D=3D 0 && > insn->imm =3D=3D special_kfunc_list[KF_bpf_throw]; > } > > +static bool is_bpf_wq_set_callback_impl_kfunc(u32 btf_id) > +{ > + return btf_id =3D=3D special_kfunc_list[KF_bpf_wq_set_callback_im= pl]; > +} > + > +static bool is_callback_calling_kfunc(u32 btf_id) > +{ > + return is_sync_callback_calling_kfunc(btf_id) || > + is_async_callback_calling_kfunc(btf_id); > +} > + > static bool is_rbtree_lock_required_kfunc(u32 btf_id) > { > return is_bpf_rbtree_api_kfunc(btf_id); > @@ -12219,6 +12247,16 @@ static int check_kfunc_call(struct bpf_verifier_= env *env, struct bpf_insn *insn, > } > } > > + if (is_bpf_wq_set_callback_impl_kfunc(meta.func_id)) { > + err =3D push_callback_call(env, insn, insn_idx, meta.subp= rogno, > + set_timer_callback_state); > + if (err) { > + verbose(env, "kfunc %s#%d failed callback verific= ation\n", > + func_name, meta.func_id); > + return err; > + } > + } > + > rcu_lock =3D is_kfunc_bpf_rcu_read_lock(&meta); > rcu_unlock =3D is_kfunc_bpf_rcu_read_unlock(&meta); > > @@ -16982,6 +17020,9 @@ static bool states_equal(struct bpf_verifier_env = *env, > if (old->active_rcu_lock !=3D cur->active_rcu_lock) > return false; > > + if (old->in_sleepable !=3D cur->in_sleepable) > + return false; > + > /* for states to be equal callsites have to be the same > * and all frame states need to be equivalent > */ > @@ -19653,6 +19694,28 @@ static int fixup_kfunc_call(struct bpf_verifier_= env *env, struct bpf_insn *insn, > desc->func_id =3D=3D special_kfunc_list[KF_bpf_rdonly_= cast]) { > insn_buf[0] =3D BPF_MOV64_REG(BPF_REG_0, BPF_REG_1); > *cnt =3D 1; > + } else if (is_bpf_wq_set_callback_impl_kfunc(desc->func_id)) { > + /* The verifier will process callback_fn as many times as= necessary > + * with different maps and the register states prepared b= y > + * set_timer_callback_state will be accurate. > + * > + * The following use case is valid: > + * map1 is shared by prog1, prog2, prog3. > + * prog1 calls bpf_timer_init for some map1 elements > + * prog2 calls bpf_timer_set_callback for some map1 ele= ments. > + * Those that were not bpf_timer_init-ed will return = -EINVAL. > + * prog3 calls bpf_timer_start for some map1 elements. > + * Those that were not both bpf_timer_init-ed and > + * bpf_timer_set_callback-ed will return -EINVAL. > + */ Also removed this comment. It's not correct here. > + struct bpf_insn ld_addrs[2] =3D { > + BPF_LD_IMM64(BPF_REG_4, (long)env->prog->aux), > + }; > + > + insn_buf[0] =3D ld_addrs[0]; > + insn_buf[1] =3D ld_addrs[1]; > + insn_buf[2] =3D *insn; > + *cnt =3D 3; > } > return 0; > } > > -- > 2.44.0 >