Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1487022lqe; Mon, 8 Apr 2024 10:08:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVpFgXODMp5Jyn6BqzMzDvuiFd6PD5MuVF7IJlRucJqj1O+JGywDRvXahzfV/H2jol2pTX/4YvGvJ340+C2L7lFYfNICFxC4NHWhXqkQA== X-Google-Smtp-Source: AGHT+IHH6dfarZhIZVheP0jlaK31OVCw1kTEkFzSkCdKYW7GIkEBdH/5YzPLyM6B1Za7XQ0/y5rU X-Received: by 2002:a05:6a21:7884:b0:1a3:bd97:4cab with SMTP id bf4-20020a056a21788400b001a3bd974cabmr471019pzc.6.1712596125482; Mon, 08 Apr 2024 10:08:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712596125; cv=pass; d=google.com; s=arc-20160816; b=v+IcpNpGPPlIoq3HJTLf8CWevTA1vLNdR9KIWPInn234dYlJk428m/w7Tqv3ADUfv3 gtgVYxQFQ1m+AxcRduD/14vMbR3FlqvmY2SpHVTqZIHWMzQivFBzaHm1xdE38AIZRRXz z5wOGCb+n4Ch7fYy67oaYvKb/pJhuc8cAX+b2qCwkqAmcJWnjhGAxavB+Mzw4+ltmmVX o/JvUoOPhAWzmOpbIEVZx9tAPbwEqJqb7ISI046KKDrwJV3Bn5nS+0z+SrapSVX0n+Zu TqTXFGM7k4RqbdzMYmpQ/+b/4CGEZ0LinWraUw9Lw5X4GqJoESGxPMeKqlpJTkzLaR8u 31YQ== 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 :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=3rblefnzDeUpBGRU9KzMwI/WwyErcHXFjWyidNir4MI=; fh=UGZeh+PgCyHddHPjFKxYIWgD2USNC3JYg43V5jSrYaw=; b=jbde1U6uQzCXcH+IUayl3RcJJfJFElBA/C0kGLNqeyhisCr17q+2xVBexH0tlhTrP+ ibD7wzTG5ThePO1FiKQXAYQLrs5N2rBv94OD3rS0jq7ocOW5xskIDFKO2cSwDo39J4Hy Xmd+lXL6JLGz1Ts0tYrCgOqRc5AYLlKRRVdchnMn14UA5PApSKkEi7Oi936huhwrVDPP CwTtdYl9+dUTrdJVrq2maxAUBc7XrIYHAJ8cu3fuHVGb7GemdVTvoysV4niWyzKg8k0n luZRlwiO5GpIhM4+mpVdCetWo7tHp7LFOIR06zY4Sp85GfbEsaGpIckSl3A/NRggWzXW 4BRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=N1tlSgsr; 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-135726-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135726-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h8-20020a631208000000b005dc50696f28si6668894pgl.725.2024.04.08.10.08.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 10:08:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135726-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=@gmail.com header.s=20230601 header.b=N1tlSgsr; 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-135726-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135726-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D6F832832B3 for ; Mon, 8 Apr 2024 17:08:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A803143882; Mon, 8 Apr 2024 17:08:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N1tlSgsr" Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 151ED142E85; Mon, 8 Apr 2024 17:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712596082; cv=none; b=ZxMRnFfYWcZag0C5UubHtTLeA+CMG4dcqVgvgCmbEDHM1RklPPxtrNmMmlRKKq9KDXT0QyEMV6NPeaS8oQXqLu6O5fnqlQ3/fsErp9G6m15E5IGB4hFjXky/dzERk7I1E/aZ85OrwOB3iZELKyhlqGkIj5mjF9jhcuACPBSZtm8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712596082; c=relaxed/simple; bh=8AXBpkc9DmcdVZTxpjLc5ajKXA0N+5NVVl+9uENqQ1o=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=WO7AuzpMd9QhZUqO7+Csoe7AIo/kI0JVj/ZJ/Y4u7t+mJyc1TFkZNd7R+csHynUcjZo2So/PDP8tDq0hnq4xVRTVxA2cBbwvcd615zeRV9Rz0mwn4bVgNxiZJld+rVZsanDy6oj30gc4PCtIytjF0nl2PehN83UOZ1Zg1i9PQ4M= 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=N1tlSgsr; arc=none smtp.client-ip=209.85.208.53 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-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-56e47843cc7so1839872a12.0; Mon, 08 Apr 2024 10:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712596079; x=1713200879; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=3rblefnzDeUpBGRU9KzMwI/WwyErcHXFjWyidNir4MI=; b=N1tlSgsrvISy6khV/A+21P8mYaij+xiIVejUn+VuAgT4fO5NfccHuj/p8qv++bwuZZ J7DGJTbUV0dfpDowDMfbuJjVPDOV+vZr8PTAPXmr4u5eN1lodwSMh2fACQgtk+CI5fCW auTDjHAhCechFJWnrg4nQMriCIVcqlqDnX+/Mu0B9hFGp31rbAwRPI9PazxMkXqSknQ3 HnLPvwVPAv7D12mhdC8btGUiIwi86PRSR/e/PUIr8NrWfN0uRJYcDE7r1/f3ecQahhRN UeiuRv8kCaK9WWeJ71jvz8qGKr6T6/TU7dAX4Mpq08kNM45rRiV5h2gmwCfepcE1YxNq NhoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712596079; x=1713200879; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3rblefnzDeUpBGRU9KzMwI/WwyErcHXFjWyidNir4MI=; b=qjkMQpPTP5By10/c38x3Zz2ANi2RkcTgsfMAKymWkU8L3BhgRoI+882MPew2y9pvuC LWtCakw/ckcXZSYwF3ZrqGppHYlUcK0Jqjm7P06DHD7xP5Q01zdmBdJfbqI3LXNsGyQ/ y3z2g4KVwY8J+1KCLo5F4Z7cbFfRJ3T95pwil5VGD+qILn7NdgERHfyAyGWkb0Ztr57+ xkV0yiabokP9I9K8C5Foah9dIpr0wEClHvNx8+4OuRcH9Xwx9naoI1xUBYferTHcf2T6 jZUwxSaoSLt6HpmtqRarPNjlCi7POuFtkifM20PYibtbc2/b2Z4imecFmzii1MODzVrI LtCQ== X-Forwarded-Encrypted: i=1; AJvYcCV0DAvWsDay1mZYx1rj81IAUZPr+y0fyvs72sSmvbbiPIR2uiHaIo9bOo8j5HReyEXsfYZx4wfqUyn1ChOI0KguFkxfCCIxr0fcwd0uzN4VMShxN4t+fBCM1olfg0eQqRNY9AzS4Gfr79exvtJF X-Gm-Message-State: AOJu0YwEDjBw7Kp/9dbU5hyt0SmCyI9Tzv+8eObw4eYXb16P9531jSLh S3vZwqMK9yBiKWHiyOsY4XtNam8BP6j3G5pACA4/zMC22Y1S2ux8 X-Received: by 2002:a50:c04c:0:b0:56d:c40d:b921 with SMTP id u12-20020a50c04c000000b0056dc40db921mr6356885edd.20.1712596079128; Mon, 08 Apr 2024 10:07:59 -0700 (PDT) Received: from [192.168.100.206] ([89.28.99.140]) by smtp.gmail.com with ESMTPSA id h1-20020a0564020e8100b005682a0e915fsm4280069eda.76.2024.04.08.10.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 10:07:58 -0700 (PDT) Message-ID: <65c249a6af45bfa5fe0f6c2331dcc1771a6f0b05.camel@gmail.com> Subject: Re: [PATCH RFC bpf-next v6 1/6] bpf/helpers: introduce sleepable bpf_timers From: Eduard Zingerman To: Benjamin Tissoires , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Date: Mon, 08 Apr 2024 20:07:56 +0300 In-Reply-To: <20240408-hid-bpf-sleepable-v6-1-0499ddd91b94@kernel.org> References: <20240408-hid-bpf-sleepable-v6-0-0499ddd91b94@kernel.org> <20240408-hid-bpf-sleepable-v6-1-0499ddd91b94@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2024-04-08 at 10:09 +0200, Benjamin Tissoires wrote: [...] > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > index 9234174ccb21..fd05d4358b31 100644 > --- a/kernel/bpf/helpers.c > +++ b/kernel/bpf/helpers.c > @@ -1096,12 +1096,19 @@ const struct bpf_func_proto bpf_snprintf_proto = =3D { > * freeing the timers when inner map is replaced or deleted by user spac= e. > */ > struct bpf_hrtimer { > - struct hrtimer timer; > + union { > + struct hrtimer timer; > + struct work_struct work; > + }; > struct bpf_map *map; > struct bpf_prog *prog; > void __rcu *callback_fn; > void *value; > - struct rcu_head rcu; > + union { > + struct rcu_head rcu; > + struct work_struct sync_work; Nit: I find this name very confusing, the field is used to cancel timer execution, is it a convention to call such things '...sync...'? > + }; > + u64 flags; > }; > =20 [...] > +static void bpf_timer_sync_work_cb(struct work_struct *work) > +{ > + struct bpf_hrtimer *t =3D container_of(work, struct bpf_hrtimer, sync_w= ork); > + > + cancel_work_sync(&t->work); > + > + kfree_rcu(t, rcu); Sorry, I might be wrong, but this looks suspicious. The 'rcu' field of 'bpf_hrtimer' is defined as follows: struct bpf_hrtimer { ... union { struct rcu_head rcu; struct work_struct sync_work; }; ... }; And for sleepable timers the 'sync_work' field is set as follows: BPF_CALL_3(bpf_timer_init, struct bpf_timer_kern *, timer, struct bpf_map *= , map, u64, flags) { ... INIT_WORK(&t->sync_work, bpf_timer_sync_work_cb); ... } So, it looks like 'kfree_rcu' would be called for a non-rcu pointer. > +} > +