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=-1.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no 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 27106C43331 for ; Wed, 1 Apr 2020 11:09:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E835920776 for ; Wed, 1 Apr 2020 11:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585739358; bh=7gtCgtHcfCIs3C1o4QVljjQQOXiupj3FcYgl/N+TOsw=; h=From:To:Cc:Subject:Date:List-ID:From; b=ItAg1592+wVijfVZl+3LC415cJ0THF+GI8t9N103ohO88Kk4FjPmcbax8moO852Ix Wo/Dc9/UTvNVw+fKkJnpp6fh2iYnZPRan4L79ujavmJeOfWpsap4WXHz2Fc+CcxBOi +3riByRFnnQVETh4n5zhwbOHsytKet+7SYC96s64= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732147AbgDALJR convert rfc822-to-8bit (ORCPT ); Wed, 1 Apr 2020 07:09:17 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:57201 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732269AbgDALJR (ORCPT ); Wed, 1 Apr 2020 07:09:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-145-ff90X8cOP66KmspAlL1Mdg-1; Wed, 01 Apr 2020 07:09:14 -0400 X-MC-Unique: ff90X8cOP66KmspAlL1Mdg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E631213FD; Wed, 1 Apr 2020 11:09:11 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.194.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8818110027AF; Wed, 1 Apr 2020 11:09:08 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Yonghong Song , Martin KaFai Lau , David Miller , John Fastabend , Jesper Dangaard Brouer , Wenbo Zhang , KP Singh , Andrii Nakryiko , bgregg@netflix.com, Al Viro Subject: [RFC 0/3] bpf: Add d_path helper Date: Wed, 1 Apr 2020 13:09:04 +0200 Message-Id: <20200401110907.2669564-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org hi, adding d_path helper to return full path for 'path' object. I originally added and used 'file_path' helper, which did the same, but used 'struct file' object. Then realized that file_path is just a wrapper for d_path, so we'd cover more calling sites if we add d_path helper and allowed resolving BTF object within another object, so we could call d_path also with file pointer, like: bpf_d_path(&file->f_path, buf, size); This feature is mainly to be able to add dpath (filepath originally) function to bpftrace, which seems to work nicely now, like: # bpftrace -e 'kretfunc:fget { printf("%s\n", dpath(args->ret->f_path)); }' I'm not completely sure this is all safe and bullet proof and there's no other way to do this, hence RFC post. I'd be happy also with file_path function, but I thought it'd be a shame not to try to add d_path with the verifier change. I'm open to any suggestions ;-) thanks, jirka --- Jiri Olsa (3): bpf: Add support to check if BTF object is nested in another object bpf: Add d_path helper selftests/bpf: Add test for d_path helper include/linux/bpf.h | 3 ++ include/uapi/linux/bpf.h | 14 ++++++- kernel/bpf/btf.c | 69 +++++++++++++++++++++++++++++++++ kernel/bpf/verifier.c | 18 ++++++++- kernel/trace/bpf_trace.c | 31 +++++++++++++++ scripts/bpf_helpers_doc.py | 2 + tools/include/uapi/linux/bpf.h | 14 ++++++- tools/testing/selftests/bpf/prog_tests/d_path.c | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_d_path.c | 71 ++++++++++++++++++++++++++++++++++ 9 files changed, 414 insertions(+), 4 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/d_path.c create mode 100644 tools/testing/selftests/bpf/progs/test_d_path.c