From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4A47C63798 for ; Thu, 19 Nov 2020 21:51:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C90522242 for ; Thu, 19 Nov 2020 21:51:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RAH4dACO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726861AbgKSVv0 (ORCPT ); Thu, 19 Nov 2020 16:51:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbgKSVvY (ORCPT ); Thu, 19 Nov 2020 16:51:24 -0500 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62540C0613CF for ; Thu, 19 Nov 2020 13:51:24 -0800 (PST) Received: by mail-lf1-x141.google.com with SMTP id j205so10463344lfj.6 for ; Thu, 19 Nov 2020 13:51:24 -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=zNkP1BfoND8tPkUFRfpyqdTZsuDNt6M1lpZgWEkn6Jc=; b=RAH4dACOk6p+Hl0CUknO6IqaObL74j1ij3JIrmV4Sxb2GuXcuW0/A7vF+XR9RhhFSp GPbynKn+i2ldVeFGmkbi3Ywr0Gu6zT9mlfPOchTMUS2kACmG/ekXrxinbmzEOFWcyYbz /5C73fBQ28oRR8OuM5kZQCthv6ve/myWVsRbg= 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=zNkP1BfoND8tPkUFRfpyqdTZsuDNt6M1lpZgWEkn6Jc=; b=Tb3ecdrII17ORrnJrr8O/IFQi/2KJOHpb2d8GgMV/jeyxwzpoLRc3Wnx3G0r0Bbwdb iM4s/y/2AAU+h/6nNdLxeEHHt2GnxIH0IV+yA+q1ykfhwZDGcBvPJOIhq6Ygrfnim6P+ UgNKptyzwIFcR/zw3/gstIcxtB89ZXvMSYHEvrec5rtvk00rR0l8ESRvQTqrxgq1bI3+ lGIYt6v4CUPICtr9ZC6W5cGeSUf8KmWgcv99vKuU5VJQgwFanQafzkzp2WejVOxAPElW /OQHejVhNJM4L2l+YwOfi3aw727jC+6WE8XvTXQXnlU4tFS5Vt7+WaQOYHxRx3nOCqEq uXlg== X-Gm-Message-State: AOAM533f4mkPEgU7nOeKnWlt2+Q9rRj+zapUFIN8hCKDGoWETQKxvelL fBMbuEuor8r9XAYE4eSmloIoqAoLq19/QxTyuNjfyA== X-Google-Smtp-Source: ABdhPJzAav3mWCYz/rq8AYwkC5wyEpFUWloem8MmqonR2PXl1rjJxoQVJCUYjeBQizBZlQtlvaImLgveQ0rxVWRKRgA= X-Received: by 2002:ac2:43b4:: with SMTP id t20mr6247176lfl.146.1605822682841; Thu, 19 Nov 2020 13:51:22 -0800 (PST) MIME-Version: 1.0 References: <20201119162654.2410685-1-revest@chromium.org> <20201119162654.2410685-2-revest@chromium.org> In-Reply-To: <20201119162654.2410685-2-revest@chromium.org> From: KP Singh Date: Thu, 19 Nov 2020 22:51:12 +0100 Message-ID: Subject: Re: [PATCH v2 2/5] bpf: Add a bpf_sock_from_file helper To: Florent Revest Cc: bpf , Al Viro , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Yonghong Song , Andrii Nakryiko , Florent Revest , open list , Networking Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 5:27 PM Florent Revest wrote: > > From: Florent Revest > > While eBPF programs can check whether a file is a socket by file->f_op > == &socket_file_ops, they cannot convert the void private_data pointer > to a struct socket BTF pointer. In order to do this a new helper > wrapping sock_from_file is added. > > This is useful to tracing programs but also other program types > inheriting this set of helpers such as iterators or LSM programs. > > Signed-off-by: Florent Revest Acked-by: KP Singh Some minor comments. > --- > include/uapi/linux/bpf.h | 7 +++++++ > kernel/trace/bpf_trace.c | 20 ++++++++++++++++++++ > scripts/bpf_helpers_doc.py | 4 ++++ > tools/include/uapi/linux/bpf.h | 7 +++++++ > 4 files changed, 38 insertions(+) > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > index 162999b12790..7d598f161dc0 100644 > --- a/include/uapi/linux/bpf.h > +++ b/include/uapi/linux/bpf.h > @@ -3787,6 +3787,12 @@ union bpf_attr { > * *ARG_PTR_TO_BTF_ID* of type *task_struct*. > * Return > * Pointer to the current task. > + * > + * struct socket *bpf_sock_from_file(struct file *file) > + * Description > + * If the given file contains a socket, returns the associated socket. "If the given file is a socket" or "represents a socket" would fit better here. > + * Return > + * A pointer to a struct socket on success or NULL on failure. NULL if the file is not a socket.