Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1592715pxb; Wed, 10 Feb 2021 11:58:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTRwv6pxJdxBNoi/yUXQ3xCw1BBCLCZb9mdB1v+xewMN+Vd9cGWKbeKhMn7mTQWKqq30zy X-Received: by 2002:a17:906:2c1a:: with SMTP id e26mr3207788ejh.322.1612987106281; Wed, 10 Feb 2021 11:58:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612987106; cv=none; d=google.com; s=arc-20160816; b=Q4wlXyXX8JO+x+8jkyAjp/lND3XP64ie8BHHghAvWxC+9nLjZv8VU33ipKgz0AJtX+ BNTrMqKehJiG9It08uuD/Ib6kabIvnotzdinuYsFI7ez9G4YswNF4RjvAkVYE5N/aNe1 LG5ycyWXfDmBMBhuIBv8kbIWAcKhKywgXTa1pML0tXIjngapoY2zVvMb3MfzOEciicJi Rj+OuyBBo5LIzurTq7MfHedDiq11icMZUMSy435Azt10VK+uXBOrkCh2SLQJuee8YChe DAxNS5rkHluJZlVHtZR5MJIFJcpkx4dWL/It8WgFnNxyKEoZWkRFS9hejWPauwmj6C7g Ckjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oExERL/T/0oMJ6g/yHZwloOKPrmB18DS3AGZFjvCYuQ=; b=0PadjTHEcai1wLSgK/d/F4N5eGSHlUNaUng9cKG8XhMsqyfin0MmrJzurR2qEcL+bW 8GJxgf8oyMdY76GZ8PuxNmsrr4FCIFYV7ABjkuXxdBtpTusRpCC+8d/9Ska1VNZO+D69 tIfGvqeYPuSUN7ajE3/3LdzZd7q7FVhGV3yqcPV/tr/fC77v9EgR36EQGxKPQNyCMDtw WGm4Xz4H9qP03va39fb9k8fOR9cXWcTg5i7mYZcxDxwqAzfKKqSunSlbmPaCTZJFLLVJ NF1iSFVZuHsev1sG4tttCTNq0/CquDEnt7PV1zg5iCc4tAXKUSlKrH6AMNfk1opqu8eL PWBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ih6f+nFK; 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 f16si1967562eja.263.2021.02.10.11.58.01; Wed, 10 Feb 2021 11:58:26 -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=Ih6f+nFK; 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 S232776AbhBJT4d (ORCPT + 99 others); Wed, 10 Feb 2021 14:56:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232432AbhBJT4X (ORCPT ); Wed, 10 Feb 2021 14:56:23 -0500 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEA11C06174A for ; Wed, 10 Feb 2021 11:55:42 -0800 (PST) Received: by mail-yb1-xb2e.google.com with SMTP id k4so3244566ybp.6 for ; Wed, 10 Feb 2021 11:55:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oExERL/T/0oMJ6g/yHZwloOKPrmB18DS3AGZFjvCYuQ=; b=Ih6f+nFKCSlny/j5kMBWvNz+0gAQU1ehWl88piEDqDY+eHdO8gPthBlHS1jGmyiubg rs9dpUJgssjTAF3dSq6pXEJCbuTcWEzYd//W3e3wj3jT+GqUbrgGPNPjwLbeIr/Hww11 EruevPLigxul9FCLV/La+bv7cs6I98IYWrTJ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oExERL/T/0oMJ6g/yHZwloOKPrmB18DS3AGZFjvCYuQ=; b=FVe2/mmTwgd706g3HPGrRPpq3eJ61RDmDxvbraFxm8RlN34FmLuIjW+vtbknm5/IZ7 ok766llXIkPjnfOevTxGa54K/hmeLq6B9P8PW5gRsH0S9qrs6oW457KuSWbMBie2A2BQ PwDw4wEuSVNzh3Kk4vWv7L3BqxkPPswB2owf9/hfw0sPPqpH273zBkCBaS/PqBJS5a+g ebVgZJw/kWYgKCdAnzNiNzW585AAwAARSuSJCDucKIdscBnvSk5AV+9FEf2oDzSl9tVn lvVP5ZUuaKrWTq/oqAQFA/1ssak9ieieM2yZI37/JojT6iEmwI/TrfiX9HR/p4+9h0G0 PROQ== X-Gm-Message-State: AOAM532iBcu8uRiCpEwRJo1VJau5kxQ23FeSI4DCFJIBNnzWaujVQrT8 zK2qmxbDqXsDloay2dIAVAqhq09POrKc+p41fXXFUA== X-Received: by 2002:a25:1385:: with SMTP id 127mr6136492ybt.437.1612986942057; Wed, 10 Feb 2021 11:55:42 -0800 (PST) MIME-Version: 1.0 References: <20210210111406.785541-1-revest@chromium.org> <20210210111406.785541-2-revest@chromium.org> In-Reply-To: From: Florent Revest Date: Wed, 10 Feb 2021 20:55:31 +0100 Message-ID: Subject: Re: [PATCH bpf-next v7 2/5] bpf: Expose bpf_get_socket_cookie to tracing programs To: Andrii Nakryiko Cc: bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , KP Singh , Florent Revest , Brendan Jackman , open list , KP Singh Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 10, 2021 at 8:52 PM Andrii Nakryiko wrote: > > On Wed, Feb 10, 2021 at 3:14 AM Florent Revest wrote: > > > > This needs a new helper that: > > - can work in a sleepable context (using sock_gen_cookie) > > - takes a struct sock pointer and checks that it's not NULL > > > > Signed-off-by: Florent Revest > > Acked-by: KP Singh > > --- > > It's customary to send cover letter with patch sets of 2 or more > related patches. It's a good place to explain the motivation of a > patch set. And a good place to ack all patches in one go ;) You're right :) I first (naively!) thought it would be a short series but it grew bigger than I originally thought. I will make sure I do in the future. ;) > Acked-by: Andrii Nakryiko > > > > include/linux/bpf.h | 1 + > > include/uapi/linux/bpf.h | 8 ++++++++ > > kernel/trace/bpf_trace.c | 2 ++ > > net/core/filter.c | 12 ++++++++++++ > > tools/include/uapi/linux/bpf.h | 8 ++++++++ > > 5 files changed, 31 insertions(+) > > > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > > index 321966fc35db..d212ae7d9731 100644 > > --- a/include/linux/bpf.h > > +++ b/include/linux/bpf.h > > @@ -1888,6 +1888,7 @@ extern const struct bpf_func_proto bpf_per_cpu_ptr_proto; > > extern const struct bpf_func_proto bpf_this_cpu_ptr_proto; > > extern const struct bpf_func_proto bpf_ktime_get_coarse_ns_proto; > > extern const struct bpf_func_proto bpf_sock_from_file_proto; > > +extern const struct bpf_func_proto bpf_get_socket_ptr_cookie_proto; > > > > const struct bpf_func_proto *bpf_tracing_func_proto( > > enum bpf_func_id func_id, const struct bpf_prog *prog); > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > > index 0b735c2729b2..a8d9ad543300 100644 > > --- a/include/uapi/linux/bpf.h > > +++ b/include/uapi/linux/bpf.h > > @@ -1673,6 +1673,14 @@ union bpf_attr { > > * Return > > * A 8-byte long unique number. > > * > > + * u64 bpf_get_socket_cookie(struct sock *sk) > > + * Description > > + * Equivalent to **bpf_get_socket_cookie**\ () helper that accepts > > + * *sk*, but gets socket from a BTF **struct sock**. This helper > > + * also works for sleepable programs. > > + * Return > > + * A 8-byte long unique number or 0 if *sk* is NULL. > > + * > > * u32 bpf_get_socket_uid(struct sk_buff *skb) > > * Return > > * The owner UID of the socket associated to *skb*. If the socket > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > > index 6c0018abe68a..845b2168e006 100644 > > --- a/kernel/trace/bpf_trace.c > > +++ b/kernel/trace/bpf_trace.c > > @@ -1760,6 +1760,8 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) > > return &bpf_sk_storage_delete_tracing_proto; > > case BPF_FUNC_sock_from_file: > > return &bpf_sock_from_file_proto; > > + case BPF_FUNC_get_socket_cookie: > > + return &bpf_get_socket_ptr_cookie_proto; > > #endif > > case BPF_FUNC_seq_printf: > > return prog->expected_attach_type == BPF_TRACE_ITER ? > > diff --git a/net/core/filter.c b/net/core/filter.c > > index e15d4741719a..57aaed478362 100644 > > --- a/net/core/filter.c > > +++ b/net/core/filter.c > > @@ -4631,6 +4631,18 @@ static const struct bpf_func_proto bpf_get_socket_cookie_sock_proto = { > > .arg1_type = ARG_PTR_TO_CTX, > > }; > > > > +BPF_CALL_1(bpf_get_socket_ptr_cookie, struct sock *, sk) > > +{ > > + return sk ? sock_gen_cookie(sk) : 0; > > +} > > + > > +const struct bpf_func_proto bpf_get_socket_ptr_cookie_proto = { > > + .func = bpf_get_socket_ptr_cookie, > > + .gpl_only = false, > > + .ret_type = RET_INTEGER, > > + .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON, > > +}; > > + > > BPF_CALL_1(bpf_get_socket_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx) > > { > > return __sock_gen_cookie(ctx->sk); > > diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h > > index 0b735c2729b2..a8d9ad543300 100644 > > --- a/tools/include/uapi/linux/bpf.h > > +++ b/tools/include/uapi/linux/bpf.h > > @@ -1673,6 +1673,14 @@ union bpf_attr { > > * Return > > * A 8-byte long unique number. > > * > > + * u64 bpf_get_socket_cookie(struct sock *sk) > > + * Description > > + * Equivalent to **bpf_get_socket_cookie**\ () helper that accepts > > + * *sk*, but gets socket from a BTF **struct sock**. This helper > > + * also works for sleepable programs. > > + * Return > > + * A 8-byte long unique number or 0 if *sk* is NULL. > > + * > > * u32 bpf_get_socket_uid(struct sk_buff *skb) > > * Return > > * The owner UID of the socket associated to *skb*. If the socket > > -- > > 2.30.0.478.g8a0d178c01-goog > >