Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1952823rbb; Tue, 27 Feb 2024 06:29:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqvaHrAB2LEZAa1/ZBOavxpAqC/ncsMcM4oaoG/zy5dbqGmgLGE/3X3AbyqKcLU+vuyFUmgOQZejGWTDGWD2H3C1/bJ93MkYA8pW7OfQ== X-Google-Smtp-Source: AGHT+IEasFYpS9L+UGXy2SuiykVBLek8l7sSDlhmZnVnnRwveWdKBxLtaxm7/FDBMlBg2otaWjIX X-Received: by 2002:a17:906:2e89:b0:a3f:1a48:3ad3 with SMTP id o9-20020a1709062e8900b00a3f1a483ad3mr6419844eji.18.1709044147946; Tue, 27 Feb 2024 06:29:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709044147; cv=pass; d=google.com; s=arc-20160816; b=sfehg5x4fQ6eRMLIgT9oBIc/4bnWZDXiIN8ewaftMhtSOWwGEvuR+fN8IA401rq3a0 OFvaJBhbcxKhbigrZ80Oe5u1naNXahdBSvpxrZZpXoe2p4DISI8NoU2wQW+4JkEr+DJp Wd36cFBP+rSmQ/CzyXav/VPviPs7UQlUXdB+6rnkq5QE0iVMtDi/Odi39KJEVsVUl6Qb UQsTzhd6S/s3m8Jh3wI/5S+OgB6TNz5o3JdTaxt+tP0WkfkqS7l4BVMxohU38Hhqrcpq PCCtYHNiQTlW8OF/y/jiOEs20FPEFP/xZ5BQ6JqMKQP196TWimy/QNhqdUdMtSvLyF12 i/OQ== 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=OpmBSGl1GAEw15+J5G3uPdFjUSqza5CrlCFN3z3ZGss=; fh=nRK4yoTKg1+cQ3tvzSbLaTNNdRWe7mZSggDF7kMMBLg=; b=TE2yU1YnhkVBegvQP0Y+AGK4E5DbsPrG7Pj+8isGwk5cMtBstY816NK6MKfni2j9WK 1ZxWm3fMM/KVjcrEP50x5DZqt+kKgcQK0r9UG7H+AxTlEgZo2ZMDiLwGFGRrU91kY33q XhX3OAFj2QhtJnXm/E/iLxGIiVZZGdCHi/KG5Nz0IJrQZRGByIOfMlBgfePi+KDfrqZt yLPUcbbTCOUl1dJNVo+6Uy2IcAjQT7FMQPfhFpkdsxR78IMlsFE2z256i8Zfch0raX+B 6+2GOoEZ43ZUa8xY/2gSZY/cxeKtH79tzY1x1h7wFW2yVNSetwzuV/j+xR7CQbEAWPV9 p7Vg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KtouzCBP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-83398-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83398-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c15-20020a170906694f00b00a4380e6d6cfsi797985ejs.37.2024.02.27.06.29.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 06:29:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83398-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KtouzCBP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-83398-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83398-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 878711F2CECF for ; Tue, 27 Feb 2024 14:29:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5248146909; Tue, 27 Feb 2024 14:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KtouzCBP" 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 CCEF4146008; Tue, 27 Feb 2024 14:27:50 +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=1709044070; cv=none; b=UD5KF89Q9M+Ad2RaSyD1QCWDXNgrW3D3dSg7VsCtgp9HMMtY/ZsFF9yoFw0NlDPwzXD9T++lUvawypa5nn0naO50GGKTG2QJNuGtihu5gLr2fQc/DAxrqut12Smgb3n8yottfL8bCCsS/Rl6UWlBWxzNngZPBhZVzwuSV7/9SXc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709044070; c=relaxed/simple; bh=vJ/n9mcTPOlux9gF800dhfBrTx6jxXg61HNCrSy8pyc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=amPdFoIGgaHLvSNKUn3oSGG6BUNv3Q4l+PekbEQyjGtFTIrsZYMswvy7Ar5W933tGy9aQTePZb0M+bfSy+UvvoP/ZUIee3LXU3NSTjhNYlUsjRLtaVGPyinou5F4CIkJkEwOq6CQ6I2bUT/dfoHN4EP4dNWFcNO6Fyvq59fxEpQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KtouzCBP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AF3EC433F1; Tue, 27 Feb 2024 14:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709044070; bh=vJ/n9mcTPOlux9gF800dhfBrTx6jxXg61HNCrSy8pyc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KtouzCBPEQ+Mnmh0hwnvSoMh31ymfs8np+NhfXaydpOPNJ3HZ8uSyFm0QiUm8WQjp V75YuTQUyun/ztJ/a+7b+TYSE2j7BnM2I72IzINHQBB3ZYWnA8yIFJEsO9wcbP5pYz q8hHbV9VH8xksKLBm+LtnWUgXMv3GMYqqfcn4UUPkCoCZGSqF6baai4Kf1rcT0mLW9 KOpqPlw0W3M+TP95P+DDT54nPwIQh4hOlpwOHii2XpjqWf6lw5nExc/6aD9WqgMlaG Wg6vW/xinP1ASs1vLgD1RYmsZMcnzaybixRMRWYTYD2a9qaPaybTcRV571NcaXrtB2 4K3cnzASZbNYw== Date: Tue, 27 Feb 2024 15:27:42 +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 04/16] bpf/helpers: introduce sleepable bpf_timers Message-ID: <3jtqytxfqymfx2fenqby2x3zzra63tj7jrxrmunqsk6l7dqyip@jt7kdhxeb4np> References: <20240221-hid-bpf-sleepable-v3-0-1fb378ca6301@kernel.org> <20240221-hid-bpf-sleepable-v3-4-1fb378ca6301@kernel.org> <818e43447651af1a659993897c14d05fec5038e4.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: <818e43447651af1a659993897c14d05fec5038e4.camel@gmail.com> On Feb 23 2024, Eduard Zingerman wrote: > On Wed, 2024-02-21 at 17:25 +0100, Benjamin Tissoires wrote: > > [...] > > > @@ -1282,7 +1333,7 @@ BPF_CALL_3(bpf_timer_start, struct bpf_timer_kern *, timer, u64, nsecs, u64, fla > > > > if (in_nmi()) > > return -EOPNOTSUPP; > > - if (flags & ~(BPF_F_TIMER_ABS | BPF_F_TIMER_CPU_PIN)) > > + if (flags & ~(BPF_F_TIMER_ABS | BPF_F_TIMER_CPU_PIN | BPF_F_TIMER_SLEEPABLE)) > > return -EINVAL; > > __bpf_spin_lock_irqsave(&timer->lock); > > t = timer->timer; > > @@ -1299,7 +1350,10 @@ BPF_CALL_3(bpf_timer_start, struct bpf_timer_kern *, timer, u64, nsecs, u64, fla > > if (flags & BPF_F_TIMER_CPU_PIN) > > mode |= HRTIMER_MODE_PINNED; > > > > - hrtimer_start(&t->timer, ns_to_ktime(nsecs), mode); > > + if (flags & BPF_F_TIMER_SLEEPABLE) > > + schedule_work(&t->work); > > + else > > + hrtimer_start(&t->timer, ns_to_ktime(nsecs), mode); > > It looks like nsecs is simply ignored for sleepable timers. > Should this be hrtimer_start() that waits nsecs and schedules work, > or schedule_delayed_work()? (but it takes delay in jiffies, which is > probably too coarse). Sorry if I miss something. Yeah, I agree it's confusing, but as mentioned by Toke in his reply, we should return -EINVAL if a timer value is provided (for now). Alexei mentioned[0] that he didn't want to mix delays in hrtimers with workqueue as they are non deterministic. So AFAIU, I should add the only guarantee we can provide: a sleepable context, and proper delays in sleepable contexts will be added once we have a better workqueue selection available. Cheers, Benjamin [0] https://lore.kernel.org/bpf/CAO-hwJKz+eRA+BFLANTrEqz2jQAOANTE3c7eqNJ6wDqJR7jMiQ@mail.gmail.com/T/#md15e431cbcddec9fcaddf1c305234523ed26f7ce