Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp284894rdb; Thu, 22 Feb 2024 03:51:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU7NcUsJ0Cn+SC0sf6AoLm5F54HmMuPHt+3RTVH+AyxUfIOaRLwCnlJUyKHVqesTd93kJWHC3/FkdgRG3/8u7d4cHCuwu2u3/8MS+yfnw== X-Google-Smtp-Source: AGHT+IFPuWcT8dPNdGt+6MWg+4lHYAxnSL5zjZP3zLBQA2gquamVxM4I6tsRa9LQDGDtP3iLtfFz X-Received: by 2002:a17:90a:304f:b0:299:17dc:ba26 with SMTP id q15-20020a17090a304f00b0029917dcba26mr15955395pjl.32.1708602682446; Thu, 22 Feb 2024 03:51:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708602682; cv=pass; d=google.com; s=arc-20160816; b=iwdcdNVoVFk7LOvKLwqgSHOj2fDHV7aKqEpeumyZScgBX5irj9D6B7I/YeZN919IoS UeMmNy/ce2yAUjK7b+1YzdiOz960ruzjL4zeWAdkUc/jhylVwHXrIVtnIkOulFWOTgPQ Ig5HyitY2i51cIvIsN7DeJ7i99a8GrzQXF1Nf/vaMU7HmtOjlMSaKVTkKHk5T0+sYdcn u8kmN8MoNIf8Kv1iSJisxWLXD8YE9nHYq/QTAKoccKLx3KWGkQFnDOQWB5ag3M+Y2Y7j /3iIKrNWu18ZBeOzTUUadauFUQ4iL28ycvIzlnEp1HahPk6TUp7NDyyuvuyEB4rK0kNq 8mTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=ldC5iLR/TjfHxpr5I8kE+2L9PTCMZ2jj1k9txMQpdfM=; fh=ru9tFtJeNdV9n4uPsMMvrkmBPnU9nIov2fZIKelnDhw=; b=KvaTC3y0os8H/sAHnDWrsQC7CPgNfAmzX8z6+KA1raDBDadQyJTNIFTXtnu2aFYK1f LQaGtQD9Iu/CsQYRwhmT5QgDa5zTIlBwtHym7sz2m2NDg4uYkh5PrZ/za3yn9jxnq1nT 4ZaQHCDSZwvJQ2EA6/BdRD4rx1bF7xHZBqi/wfRTRi1i3ciDYDVWW1TQOvjx5eF0HsVx ctaRMUhBVS6+hzfptCKSoxW4ICptrB2r96nUqMFs/S1hApc554alrhTW8JNrgLiWRCZj 6S+WKAwzJTGHfswKmEV6+mkLxQTd2r3ZReppGZKZp1PwA+mLSyc2+jnfU2Ky810CeolP 85TA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LNHlvWpD; 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-76446-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76446-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id nu11-20020a17090b1b0b00b002993e504be9si8693938pjb.183.2024.02.22.03.51.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:51:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76446-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LNHlvWpD; 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-76446-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76446-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 3513C286E88 for ; Thu, 22 Feb 2024 11:50:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB12147A73; Thu, 22 Feb 2024 11:50:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LNHlvWpD" 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 75F8E47781 for ; Thu, 22 Feb 2024 11:50:18 +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=1708602620; cv=none; b=AXwafH/2aoaPLX1CNQJb93H1TOZDYldTZqlM3dRi4NYF8kWs4jShGJhWsA7Ko7b0TOcVf9wHfDHNGiJM0ik/P9BG4DrGYlf4YDdLt6yO8mm5Ljd6UhVxkYCxuqP0iNAPisS6gfTd0A2lPON9tcRDT38ElY32n4ZSFsFUoUNOt1U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708602620; c=relaxed/simple; bh=ma9DfQIGiAa5vr3ks75PfINXo2TPrC0w7A/88yi8pA8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=VmJZJTnW6kkpzpuRhVpEqDaS2EMygcF5SvOkR5ZdQzegPV2avFddb3oJ33WHQYGgdyKLhmjOUNIEJ9MH0Gu+5lmNCvNpsDZ6USyC12nmw2ZYpui+nBgdQNmQBIfgIxiCC+CRZ3I6+kN29DhlJ+eQZiwQQqZTDxvrNP/354N8R84= 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=LNHlvWpD; 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=1708602617; 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: in-reply-to:in-reply-to:references:references; bh=ldC5iLR/TjfHxpr5I8kE+2L9PTCMZ2jj1k9txMQpdfM=; b=LNHlvWpDPvqy6mIpfwQBe7iBjXqd28ML5ZmGBOpEMRu1nPlpHyWxgNMk6N4czt4mPdsSNw EkNAUkQeAsQWv+W58bVedLlLGDy8CWVecJCD/r19DIyPYLNKVp7pOJHqgDh2NCRfiiGFCg XRwa7yM8XhJhwk95PwaQFQbgc+ynhvA= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-g0UZMkfeNbWkzyUAlnhfUA-1; Thu, 22 Feb 2024 06:50:16 -0500 X-MC-Unique: g0UZMkfeNbWkzyUAlnhfUA-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a3bdd99a243so79437866b.0 for ; Thu, 22 Feb 2024 03:50:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708602614; x=1709207414; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ldC5iLR/TjfHxpr5I8kE+2L9PTCMZ2jj1k9txMQpdfM=; b=N05hOo/rwTMB8aJAy+VgoGPlXQdvKYxP01tFucyh8frQHj+tD4mBIJZa9ZRYQlGZnP Ss+YYl1m71XZ9X+RY5G4i9/HtggsIUs9qgxh72gyt5nMD8Zo6eQwZTnAghFofrZpl8FT EEH8KCbUe2nytdP9rVPtd4IstJIuQ+Dkqqx7CmGyaGETbdcwB+x60lxkUJXiJEu21OEg lBYh2sW+RgXjZ9ixBq2eY65+GsjnMyMJwcXnuas/omGSqcaQUIb20QUeTk8UsjpJgMFK HHFMAEwwJFbjOtV6pdYbY238SfUIA57VlSpesg97nyryl7tB8O1hCxuk64pZGaEz9zqr lyiQ== X-Forwarded-Encrypted: i=1; AJvYcCV+LncBH7w6LI2ooI6en8FVK9nQT9aW+G2bdK4DqVJb9zNQucRIS1Acm1KV+/KeIFOT0ZDdC/xYcClJKbTdcbGTucGV7r/44EbpWJU2 X-Gm-Message-State: AOJu0YxKeyW09EiVvnhX1TaPMT9pLeArrB/rlc3a0k67QOaG/bvVRMZB 3tiN2As9u5RMR1rZ3SZT14zK/rP1JrCmPBDrWyQ8pNK/6NC4ugLwfzk0q8Q8pBWHEtXe1+fzKST /C4lJSBi62Cmv6Vr3xTjGdXzra2P3xKH8W34QTpxgfmKrMkAUHThvCLttMUReHMUSD7wseA== X-Received: by 2002:a17:906:393:b0:a3f:4ca8:f93e with SMTP id b19-20020a170906039300b00a3f4ca8f93emr2003789eja.24.1708602614217; Thu, 22 Feb 2024 03:50:14 -0800 (PST) X-Received: by 2002:a17:906:393:b0:a3f:4ca8:f93e with SMTP id b19-20020a170906039300b00a3f4ca8f93emr2003757eja.24.1708602613833; Thu, 22 Feb 2024 03:50:13 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id h10-20020a170906398a00b00a3f99497456sm259912eje.90.2024.02.22.03.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:50:13 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 63345112DEFE; Thu, 22 Feb 2024 12:50:12 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: 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 , Benjamin Tissoires , Jonathan Corbet , Shuah Khan Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires Subject: Re: [PATCH RFC bpf-next v3 04/16] bpf/helpers: introduce sleepable bpf_timers In-Reply-To: <20240221-hid-bpf-sleepable-v3-4-1fb378ca6301@kernel.org> References: <20240221-hid-bpf-sleepable-v3-0-1fb378ca6301@kernel.org> <20240221-hid-bpf-sleepable-v3-4-1fb378ca6301@kernel.org> X-Clacks-Overhead: GNU Terry Pratchett Date: Thu, 22 Feb 2024 12:50:12 +0100 Message-ID: <87le7chg5n.fsf@toke.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Benjamin Tissoires writes: > @@ -1245,6 +1294,7 @@ BPF_CALL_3(bpf_timer_set_callback, struct bpf_timer_kern *, timer, void *, callb > ret = -EPERM; > goto out; > } > + down(&t->sleepable_lock); > prev = t->prog; > if (prev != prog) { > /* Bump prog refcnt once. Every bpf_timer_set_callback() > @@ -1261,6 +1311,7 @@ BPF_CALL_3(bpf_timer_set_callback, struct bpf_timer_kern *, timer, void *, callb > t->prog = prog; > } > rcu_assign_pointer(t->callback_fn, callback_fn); > + up(&t->sleepable_lock); > out: > __bpf_spin_unlock_irqrestore(&timer->lock); > return ret; > @@ -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); > out: > __bpf_spin_unlock_irqrestore(&timer->lock); > return ret; I think it's a little weird to just ignore the timeout parameter when called with the sleepable flag. But I guess it can work at least as a first pass; however, in that case we should enforce that the caller passes in a timeout of 0, so that if we do add support for a timeout for sleepable timers in the future, callers will be able to detect this. -Toke