Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp711574lqt; Fri, 19 Apr 2024 08:15:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUjsjAP/O85NatPHt+z29+J3e+Ir5v3oMQ9cevB0OWdueRKndMftB5Y4iatskJaVjrJbf9VDcGXhWEEZEhSVd/Y+R8cMZwuxalNliV6UQ== X-Google-Smtp-Source: AGHT+IGyC5A87xG4gHS1P9Dqla0GscmgCuBhR2rnVR594TRZlN6HZi3FB8KXxbbSBtLmDokZQJsl X-Received: by 2002:a05:622a:14e:b0:438:42c9:a923 with SMTP id v14-20020a05622a014e00b0043842c9a923mr1642094qtw.68.1713539707250; Fri, 19 Apr 2024 08:15:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713539707; cv=pass; d=google.com; s=arc-20160816; b=BS6WHJY3qnNOwvHprwkm5DBzwBtl0rGYEHAhHCPr+hhTx5A/w3NLAMToyQWjh+5xkV 10y/Zo7G4tOOo0UP+hq+Pyz1YEFJw2OFQ/YgAOFnZHUE8vJOSwVvTzaMLn0pH0ruLJEB zSzEjNv/aSK05x+unQj200ZqbUTBimIS+I53pe9yPzNQ7Tqdt7YHPa9tuWgRZqtm3N64 FKcJrxhYRtbLpJCxbNtYK8OGgQoR3cLUsLWKsegCe4CbLKJdbr/zNuVZvw1Vr1BV0kJj AiFMMmATeBQtrridEGiWTKV8GEwLlVXdzlzMaVjfRFeg9V0aENtcCDRmkbZtX3T35/E0 /43w== 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=qGmwq41s9YMq16ePS3CZou4TbJV70JWKZp8MhWFHm0U=; fh=ZjSMVuHf+kY8uNFRfIseyZmEo87DPFM/TlOGgk+oQbY=; b=i1u+pWqapkVEZBKIWmdwz6LjRn0SQZAJWAFGY96aSE/OBI7EYlwttMq34z9+3XYtj+ 5m3QOOwOFGuTkVzMsd1bRiIy3usS38uVhZD/+l3HbWw9H60jIbZ1ecvdkZnyrZMgyObQ F3W0jIm/4I1H9g2W8MLYqxwtGxAGahNyiHOR4pgBz3IAiGzsqxHmjiJG/4KzAqZgWDYh 676Cj0rcOgnNvmiKGFzY0tn8+ixX0EFJ1M4jRsE5Fc6JLoz+EHO9HHU1wFEUWl2yqSng /k81wg6Rqw3SDr7kV91MHQFSHhlKNPIe1ZeL/xI0jJrLqcZ8gQ56k0PJ0HeWIONBeU9f op3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NzjkWeY3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151643-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151643-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q12-20020a05622a04cc00b004368612a9ebsi4215693qtx.266.2024.04.19.08.15.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 08:15:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151643-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NzjkWeY3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151643-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151643-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 01DDC1C2180C for ; Fri, 19 Apr 2024 15:15:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DA3F12F5A4; Fri, 19 Apr 2024 15:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NzjkWeY3" 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 90AB42B2D7; Fri, 19 Apr 2024 15:14:59 +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=1713539699; cv=none; b=ZGfcrqxQe0Z1PeibCRDWKqjX/QywAqCS1QmXYEtV2YtTVJl2VYuNvKMGX7uEixz+OeEpxRhqr3T/+r7kXpr3BhEYzG8Weyh+xUKI23Cy2sCDgRiSjw9SakkKgfv5HJdpnUBRH08w1yVOR6XNAWUB8xqW8+iZNlge0BlA0ge47pc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713539699; c=relaxed/simple; bh=RbyWP0TRgV3mD89DqjmdySW1rSrRZFZkoQUyjq1dfO4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mlPsOh+mP4mqVk1vzm+0+pqcIZNmkTSRYtn115Lp9LDvsa+EOWgStoTiCHlmMtfVe2OFKXZTqsPC5hVMCKd7/AEuQf7umW/oNrLUPr7YlwLHt7PMm1+lGO+/B2C7astDnplnFMzXrAAa3FFoTHlw1efa++q+sh/C9xuEV8vH5OQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NzjkWeY3; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73120C072AA; Fri, 19 Apr 2024 15:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713539699; bh=RbyWP0TRgV3mD89DqjmdySW1rSrRZFZkoQUyjq1dfO4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NzjkWeY3E3ceLeVDDaH+oxCjkJllJ7gNkGHkG++1Eq9xeu4vgA+BrPIEKUq+Jd2cR 0vw/RKvVQriu/0URyABZP8j4f+1zGHixQhGjYZIVOVn4OKO75+9PLeE3mzJGZM5OU1 +dYyqt3DmIwUOGFLwRjXJxtUvctFQ9oqbFwLgXVacTKld3OvWr/AhYw+dqWC0icBNU kYTDnTGZf3jid570L2JBCZb0L95Nh8RB9wsCAsv9pOpjv96ZdICDdXW6c+5QlIA5sd DQBWM/Yo/2OQ7SzbecA2ppawI3p1bGVZK+Fngme5to2NXk8lesN5PNQAetqhzUjJig u3HTOsiuGNHNA== Date: Fri, 19 Apr 2024 17:14:52 +0200 From: Benjamin Tissoires To: Alexei Starovoitov 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@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH bpf-next 17/18] bpf: add bpf_wq_start Message-ID: References: <20240416-bpf_wq-v1-0-c9e66092f842@kernel.org> <20240416-bpf_wq-v1-17-c9e66092f842@kernel.org> 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: On Apr 18 2024, Alexei Starovoitov wrote: > On Tue, Apr 16, 2024 at 04:08:30PM +0200, Benjamin Tissoires wrote: > > again, copy/paste from bpf_timer_start(). > > > > Signed-off-by: Benjamin Tissoires > > --- > > kernel/bpf/helpers.c | 24 ++++++++++++++++++++++++ > > 1 file changed, 24 insertions(+) > > > > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > > index e5c8adc44619..ed5309a37eda 100644 > > --- a/kernel/bpf/helpers.c > > +++ b/kernel/bpf/helpers.c > > @@ -2728,6 +2728,29 @@ __bpf_kfunc int bpf_wq_init(struct bpf_wq *wq, void *map, unsigned int flags) > > return __bpf_async_init(async, map, flags, BPF_ASYNC_TYPE_WQ); > > } > > > > +__bpf_kfunc int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) > > +{ > > + struct bpf_async_kern *async = (struct bpf_async_kern *)wq; > > + struct bpf_work *w; > > + int ret = 0; > > + > > + if (in_nmi()) > > + return -EOPNOTSUPP; > > + if (flags) > > + return -EINVAL; > > + __bpf_spin_lock_irqsave(&async->lock); > > + w = async->work; > > + if (!w || !w->cb.prog) { > > + ret = -EINVAL; > > + goto out; > > + } > > + > > + schedule_work(&w->work); > > +out: > > + __bpf_spin_unlock_irqrestore(&async->lock); > > Looks like you're not adding wq_cancel kfunc in this patch set and > it's probably a good thing not to expose async cancel to bpf users, > since it's a foot gun. Honestly I just felt the patch series was big enough for a PoC and comparison with sleepable bpf_timer. But if we think this needs not to be added, I guess that works too :) > Even when we eventually add wq_cancel_sync kfunc it will not be > removing a callback. Yeah, I understood that bit :) > So we can drop spinlock here. > READ_ONCE of w and cb would be enough. > Since they cannot get back to NULL once init-ed and cb is set. Great, thanks for the review (and the other patches). I'll work toward v2. Cheers, Benjamin