Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3618989pxu; Tue, 8 Dec 2020 17:31:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJygVmt3foDnj0V7NbI0A3kK4SdOA5G5jnHooFThQBk4qG43ylWdJx24Iv/i6ro7EN1WfVJK X-Received: by 2002:a17:906:591a:: with SMTP id h26mr121288ejq.174.1607477461050; Tue, 08 Dec 2020 17:31:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607477461; cv=none; d=google.com; s=arc-20160816; b=IR020f4iz7NRa15e9ejYvXk0wY0YAfRDYNa7s9W4pjRd3R7Yaf9XRqGVQJZOp/N1U0 pf5dfj4KsMeERJn4SNdq4VJPT81V6VEpJ8ttLiia7oDv5cuhEK7ZprkYYe5MNhKcRFl3 eDw6cp2hKVOs0Oc3RZ9zQ3X8etsyeqEQhs4hBFmPRpXIrW8Pg4yH8JWB8CQRm8ZXH3tb XpNMMImcpR+8+0tiNIDRcigSMW0yxGs5Nxd3cQFzdqNMg1pKtgn62HjS9wlMW+a+m+Yt pbnXLOhBemQb1NcW/MWFYDdi+/MKjG4spaytjp9YvZOr0ynLgGwFw7Ag3itOh5cyYDIG 46tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=GY4quZCaSnF2YYcFBZRxCRau/11uuDMbwi+oWqtuM1k=; b=V+PJUQaJIkaViGRjEbwDz1j/hr9pB0E9Rd8WonEfmU/lv/0HwOQP1U8didyxMgKORy ksMS+0J8ZgskGh5HrAD6vfOrVMaWJlEYtqde+L6PzHh6gfwWHbrUVM8Sj0QVH+q0x6an dnXTza7FMzn1Tt/vraKpzbnU7+cxiIjIyC6O2wjLaXF9nLrijR01AA8mz/w1zBNMqWvj rHCD3WWw5CdnYUWn+TzN5uaQP6dnhTFG+t6Omq/rYgMAFh5Pg0pbuguvsCb9uTSVYhjC mQzXTRx/LYdgbb/ZXXpJCudQXd9DbVZ5OKEn5TidKku9A4KH6A4uZpZfhqMxJRPj1tXb SQQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="TvPQr7/u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zc8si62397ejb.662.2020.12.08.17.30.38; Tue, 08 Dec 2020 17:31:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="TvPQr7/u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729803AbgLHUqL (ORCPT + 99 others); Tue, 8 Dec 2020 15:46:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726104AbgLHUqL (ORCPT ); Tue, 8 Dec 2020 15:46:11 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BDCFC0613CF for ; Tue, 8 Dec 2020 12:45:25 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id x6so13696260wro.11 for ; Tue, 08 Dec 2020 12:45:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=GY4quZCaSnF2YYcFBZRxCRau/11uuDMbwi+oWqtuM1k=; b=TvPQr7/uYkYDPuyGQ0ikNVrQg5P9WPbsBMJPgWQP/PhBgDH7YcbheuxLR6Q/dVcHFz oYtxly75A0e95xyaiwnaEoz8xFf/lfIPm9I1d4u7uWlC5dZfJBJqh94BADDy4/rGWQgk bqGGwzpCq96PNrubgsbmY+lFjrAERE0H0zGvo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=GY4quZCaSnF2YYcFBZRxCRau/11uuDMbwi+oWqtuM1k=; b=tVU5ZQeMp72XjXJrAjoejRaAic0ws0PtN8kDe9X3I3N04KQLbm2jPRDmxYLOPCDjv/ ShIwh9t3+ajrZrxtqjW8H/uEvc7kcwENkrD01Pv4L0l91B8sy8YvH48YWAU2mRRjk1Vb X5dFrmekvhCIaO/6h2ULKLzfcDFaOxL6UwWeZwomtEtj6O046Aozqci1OQRoA+UGmlZ+ kI9u3DM5ElZnssY62XM1hBYVJTxXlrrcRej+SDw1IHV+pgPwkhiCPvGqMKaW7pvUBck1 Nlw2XH4NnepeOGpi5euXgHW2iskp8d2qWXUJZRwCM4nRg3BsiMA1JGPMqnLuEUSHjb0r bPnQ== X-Gm-Message-State: AOAM532N5r6O3wka1PLtkXn7K8z3xXZIwEhMHKdDALMIDrHYZ4dpE0C7 GS4Qw24lfl/xksddAV5MVjYePKkPpZ/OAA== X-Received: by 2002:a50:d484:: with SMTP id s4mr13538549edi.13.1607455854622; Tue, 08 Dec 2020 11:30:54 -0800 (PST) Received: from ?IPv6:2a04:ee41:4:1318:ea45:a00:4d43:48fc? ([2a04:ee41:4:1318:ea45:a00:4d43:48fc]) by smtp.gmail.com with ESMTPSA id z22sm16468889eji.91.2020.12.08.11.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 11:30:52 -0800 (PST) Message-ID: <61135b81892e029d293b1baa3345ba78f1e848c7.camel@chromium.org> Subject: Re: [PATCH bpf-next v2 1/3] bpf: Expose bpf_get_socket_cookie to tracing programs From: Florent Revest To: Daniel Borkmann , bpf@vger.kernel.org Cc: ast@kernel.org, andrii@kernel.org, kpsingh@chromium.org, revest@google.com, linux-kernel@vger.kernel.org Date: Tue, 08 Dec 2020 20:30:51 +0100 In-Reply-To: <7c70a64f-1aba-0e11-983d-9338f25a367e@iogearbox.net> References: <20201203213330.1657666-1-revest@google.com> <7c70a64f-1aba-0e11-983d-9338f25a367e@iogearbox.net> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.4-2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2020-12-04 at 20:03 +0100, Daniel Borkmann wrote: > On 12/4/20 7:56 PM, Daniel Borkmann wrote: > > On 12/3/20 10:33 PM, Florent Revest wrote: > > > This creates a new helper proto because the existing > > > bpf_get_socket_cookie_sock_proto has a ARG_PTR_TO_CTX argument > > > and only > > > works for BPF programs where the context is a sock. > > > > > > This helper could also be useful to other BPF program types such > > > as LSM. > > > > > > Signed-off-by: Florent Revest > > > --- > > > include/uapi/linux/bpf.h | 7 +++++++ > > > kernel/trace/bpf_trace.c | 4 ++++ > > > net/core/filter.c | 7 +++++++ > > > tools/include/uapi/linux/bpf.h | 7 +++++++ > > > 4 files changed, 25 insertions(+) > > > > > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > > > index c3458ec1f30a..3e0e33c43998 100644 > > > --- a/include/uapi/linux/bpf.h > > > +++ b/include/uapi/linux/bpf.h > > > @@ -1662,6 +1662,13 @@ union bpf_attr { > > > * Return > > > * A 8-byte long non-decreasing number. > > > * > > > + * u64 bpf_get_socket_cookie(void *sk) > > > + * Description > > > + * Equivalent to **bpf_get_socket_cookie**\ () helper > > > that accepts > > > + * *sk*, but gets socket from a BTF **struct sock**. > > > + * Return > > > + * A 8-byte long non-decreasing number. > > > > I would not mention this here since it's not fully correct and we > > should avoid users taking non-decreasing granted in their progs. > > The only assumption you can make is that it can be considered a > > unique number. See also [0] with reverse counter.. > > > > [0] > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=92acdc58ab11af66fcaef485433fde61b5e32fac Ah this is a good point, thank you! I will send a v3 with an extra patch that s/non-decreasing/unique/ in the other descriptions. I had not given it any extra thought, I just stupidly copied/pasted existing descriptions. :) > One more thought, in case you plan to use this from sleepable > context, you would need to use sock_gen_cookie() variant in the BPF > helper instead. Out of curiosity, why don't we just always call sock_gen_cookie? Is it to avoid the performance impact of increasing the preempt counter and introducing a memory barriers ?