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=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 D2610C10F13 for ; Thu, 11 Apr 2019 17:59:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2E1F20850 for ; Thu, 11 Apr 2019 17:59:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eK8ig67x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726685AbfDKR7Q (ORCPT ); Thu, 11 Apr 2019 13:59:16 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:33694 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726577AbfDKR7Q (ORCPT ); Thu, 11 Apr 2019 13:59:16 -0400 Received: by mail-qt1-f194.google.com with SMTP id k14so8223503qtb.0 for ; Thu, 11 Apr 2019 10:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wbNw1gjfxoUKnFn9+yvd1eE9vaAe1XhEQE2f13ubgvE=; b=eK8ig67x2qd302NkMUmHJy+Pr1UCHhcenKMW6iz6fp3IGkEz8kdZPSVlRowZ4iZQlQ 3NnmBaWRsmgjoG+9Xj3GJj1E4/KcXY6gJLEib/gaCYVfC0EvgbdG+gK+isk8Cl/DDQii q+mf6VHzLRz7WSCYmonkFihLZHPQffG6q/MPsPdQlbJRlVE8CLO/4oumO1XiOr3S75L1 LUt3X8Co+utjGmfqH0E5ex/Vlqi8lE7jgTsEQoulvofr6l+gOtbB9PKKdHgg7locJ+Mu INsHtH+L2wIqM6LR8BsYz59y/uYy/LrHcXo014oxH8KgnM1UtOAqbbMrfAsFxOb9AKQ5 iDNQ== 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=wbNw1gjfxoUKnFn9+yvd1eE9vaAe1XhEQE2f13ubgvE=; b=PKqKcQRfxu6dDLDuS88q+RwMpLxlPvKA8TNgwxbSb+p/R+yP5ZT3GPg9OOUFyTsS6v LQf8T6zt7NGa6m2l2yGsqtNU6uGA6J8TWueH8BR7ptoBVzF3KvJ3snp7H1qVLT9s+OS/ HwBIeOKLEXSHNoyEOcYBvqlJ5I2t2XUxHTtoUJ9LIFjQThUxykVesU5s9rpsxLjKicU8 he3lVUpTK6M+XzqWV9t8VDtuLEw9WwNrKl+KBp6w9UxzcYry1F9Jtg+mvcIpWZCws7Pw C15gDjZMPEinWR00e0paCP2EQfin0RgVYlHNwiTHFGgptWZ78mY0Mpes9WibLEH2MPkf ocGA== X-Gm-Message-State: APjAAAWbkbfEcpglCuZBSxNbCfqCWgMajYxwYJk2aclkGvcklPQO2crA 5kgTTEImwITsSn9CuGCvAePaWfYZ0InA9uivu9I= X-Google-Smtp-Source: APXvYqyGNEIuTiNceNZVMGkCQyWaIHnSvhk6FrgO1MK/VdUtmipjK+Riy6StDW6RF1SEK8c9oGCnCi/1PeWGL48h+yU= X-Received: by 2002:a0c:9624:: with SMTP id 33mr41990996qvx.71.1555005555298; Thu, 11 Apr 2019 10:59:15 -0700 (PDT) MIME-Version: 1.0 References: <20190322223848.3338614-1-javierhonduco@fb.com> <20190410203631.1576576-1-javierhonduco@fb.com> In-Reply-To: <20190410203631.1576576-1-javierhonduco@fb.com> From: Song Liu Date: Thu, 11 Apr 2019 10:59:04 -0700 Message-ID: Subject: Re: [PATCH v5 bpf-next 0/3] bpf: add bpf_descendant_of helper To: Javier Honduvilla Coto Cc: Networking , Yonghong Song , Kernel Team Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, Apr 10, 2019 at 1:38 PM Javier Honduvilla Coto wrote: > > Hi all, > > This patch adds the bpf_descendant_of helper which accepts a PID and > returns 1 if the PID of the process currently being executed is a > descendant of it or if it's itself. Returns 0 otherwise. > > This is very useful in tracing programs when we want to filter by a > given PID and all the children it might spawn. The current workarounds > most people implement for this purpose have issues: > > - Attaching to process spawning syscalls and dynamically add those PIDs > to some bpf map that would be used to filter is cumbersome and > potentially racy. > - Unrolling some loop to perform what this helper is doing consumes lots > of instructions. That and the impossibility to jump backwards makes it > really hard to be correct in really large process chains. > > Let me know what do you think! > > Thanks, For the set: Acked-by: Song Liu > > --- > Changes in V5: > - Addressed code review feedback > - Renamed from progenyof => descendant_of as suggested by Jon Haslam > and Brendan Gregg > > Changes in V4: > - Rebased on latest bpf-next after merge window > > Changes in V3: > - Removed RCU read (un)locking as BPF programs alredy run in RCU locked > context > - progenyof(0) now returns 1, which, semantically makes more sense > - Added new test case for PID 0 and changed sentinel value for errors > - Rebase on latest bpf-next/master > - Used my work email as somehow I accidentally used my personal one in v2 > > Changes in V2: > - Adding missing docs in include/uapi/linux/bpf.h > > > Javier Honduvilla Coto (3): > bpf: add bpf_descendant_of helper > bpf: sync kernel uapi headers > bpf: add tests for bpf_descendant_of > > include/linux/bpf.h | 1 + > include/uapi/linux/bpf.h | 10 +- > kernel/bpf/core.c | 1 + > kernel/bpf/helpers.c | 27 ++ > kernel/trace/bpf_trace.c | 2 + > tools/include/uapi/linux/bpf.h | 10 +- > tools/testing/selftests/bpf/.gitignore | 1 + > tools/testing/selftests/bpf/Makefile | 2 +- > tools/testing/selftests/bpf/bpf_helpers.h | 3 + > .../bpf/progs/test_descendant_of_kern.c | 46 +++ > .../selftests/bpf/test_descendant_of_user.c | 268 ++++++++++++++++++ > 11 files changed, 368 insertions(+), 3 deletions(-) > create mode 100644 tools/testing/selftests/bpf/progs/test_descendant_of_kern.c > create mode 100644 tools/testing/selftests/bpf/test_descendant_of_user.c > > -- > 2.17.1 >