Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1737071pxf; Fri, 12 Mar 2021 18:39:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZOV9dNiff4336CZbyWt4b3FsI8KB/mwZr0CqwDHka8Q6x+zDZkLmiIZzfBB9BI5T7Q5Ii X-Received: by 2002:aa7:d0cb:: with SMTP id u11mr17612154edo.163.1615603158774; Fri, 12 Mar 2021 18:39:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615603158; cv=none; d=google.com; s=arc-20160816; b=McZ5QjZxffVA/gtnrfBhsOWZFQNpqKiYOhwE5xwwIPi5iHVWhbdilC04VgIFvCWAad SfXbhyNs2ZButNupP1oZG3yb0kVekssMe7Z/3P1zst0W+4F2xe3pB8r57w2EiWvqYgyi YCt6jZDDH+moV9D0hQaWq0+W/hsAImmJIdLZmgkKJrtMxUBTqLMOxDB3UIF3Mj6L3cxr MapZFlPoBLRRPku/EYSzWFsMHdVJsGfJp3M388khXPLuKwCwilHO52LqIKIIfcS6vSi+ x3GJiuaFUp8aWkvpyDOF/zCeXuALzK/i/Hh8kj3xRaPe5ZqIzcIU/cFnZqFMZ0VlTkSW 1rZQ== 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=hhCFhzbiKA2mlAUj4Ovu5/MkFXN1mMvRNkUzf2/XxUc=; b=D2LUZ/XElF0sGr4fZVaobQbX0T4dKOyBrBWaMcbIg3gTAaUO8QtPiU32XrQPmxH1gh SJlGDT8MYag+eP8+QxijssijTakDtfyNgvJJDXAdXStG616TvDfZQulgycNTUoVukcLK KHpjc474Z/GPHaRyju0dTnogx+ftykIGi8oo2dJKTSY6m6srgw8Hpd+yuuk6n7o7K+jO W6XLvUXAIjWS8UlFnV9qzk8pfMNlvtEdKBr+auxnsWGwiZ+Q9LM2vAuGj45IOmjxMCqv dJ5M+IzeYxNKn7v0U0thdoGbdeogh2kkQmF999fFFHNl2S4Y/n3vNJ+MEfYpQN1zJsNU r/Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CztLwOEO; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a1si5333153ejt.680.2021.03.12.18.38.56; Fri, 12 Mar 2021 18:39:18 -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=@gmail.com header.s=20161025 header.b=CztLwOEO; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232942AbhCMCdj (ORCPT + 99 others); Fri, 12 Mar 2021 21:33:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232878AbhCMCdO (ORCPT ); Fri, 12 Mar 2021 21:33:14 -0500 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED58BC061574; Fri, 12 Mar 2021 18:33:13 -0800 (PST) Received: by mail-yb1-xb29.google.com with SMTP id u3so27370365ybk.6; Fri, 12 Mar 2021 18:33:13 -0800 (PST) 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=hhCFhzbiKA2mlAUj4Ovu5/MkFXN1mMvRNkUzf2/XxUc=; b=CztLwOEOVFlFwk9qn8RKcouRdGHbLE/7ydkyGqDM9Bqtw2s8uUmDVIqCqkzcsYinON lNiziQO56mB8lUvRXlnYx1llPePefMhlz4xYcQ6X94vyc+RdmyuWbvztda7qLL8nkA2c NAuy9WwG2lIrvHMVtsrPFLzRZlDQhE8axzIZUWS3y84/KzwC9Fpzp5D1xqZKab/P910U ilR8RGdwOpynwqMOjknOGjIKsEG9GqMKdQ86UHay8yu3lziNgmwFYQxRJI/0G7pRU8bi GwBE8qXMfu48vF17nCTSoJpK97mcVjpPNQDWuKD+22IAOMwJU/+FLDGJf5EjIY1KJmeQ IDWQ== 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=hhCFhzbiKA2mlAUj4Ovu5/MkFXN1mMvRNkUzf2/XxUc=; b=QfgBZsoWim+navgjHxM5U0aIX71eQVUECH+lQESJwGJ3O3XfTNVkEmZkNowgRrX5Nc fg+D2iBP/WlwoxD6OT75gb0mwCLyt4UQ6OXPZY8MO0r+zrjbunF8lQDn94AE5eEoRbfa 4HCvb1U7Xr7eeS9H65h5CSXjqCES9WeiZO/Jvcrst2koyH2wJU81gSPJL8Hy/DJ1Rkmq lcoPWiFBJ+3ZeJaYYtlXbTSNLl2VGF62BieW9yA6XwxvQQmExmixFTCWdQWp+RDaZ8zs tmDFdSC22+aJTYuFhWusGuE5Y5orrpLjSqaUjSoKLDLGsloQyG228u6r6MeI2Ym6pW5s Ay7Q== X-Gm-Message-State: AOAM530vxUljlKbVMoHumw2oNMy2yXZCKCZgM0GxCZ8jGOh+TJm/Im+Z ePxb1vjEyz4HyTPjhs9evbdyurQggip+Ruw8IiY= X-Received: by 2002:a25:874c:: with SMTP id e12mr22073648ybn.403.1615602792435; Fri, 12 Mar 2021 18:33:12 -0800 (PST) MIME-Version: 1.0 References: <20210312214316.132993-1-sultan@kerneltoast.com> In-Reply-To: From: Andrii Nakryiko Date: Fri, 12 Mar 2021 18:33:01 -0800 Message-ID: Subject: Re: [PATCH] libbpf: Use the correct fd when attaching to perf events To: Sultan Alsawaf Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 12, 2021 at 6:22 PM Sultan Alsawaf wrote: > > On Fri, Mar 12, 2021 at 05:31:14PM -0800, Andrii Nakryiko wrote: > > On Fri, Mar 12, 2021 at 1:43 PM Sultan Alsawaf wrote: > > > > > > From: Sultan Alsawaf > > > > > > We should be using the program fd here, not the perf event fd. > > > > Why? Can you elaborate on what issue you ran into with the current code? > > bpf_link__pin() would fail with -EINVAL when using tracepoints, kprobes, or > uprobes. The failure would happen inside the kernel, in bpf_link_get_from_fd() > right here: > if (f.file->f_op != &bpf_link_fops) { > fdput(f); > return ERR_PTR(-EINVAL); > } kprobe/tracepoint/perf_event attachments behave like bpf_link (so libbpf uses user-space high-level bpf_link APIs for it), but they are not bpf_link-based in the kernel. So bpf_link__pin() won't work for such types of programs until we actually have bpf_link-backed attachment support in the kernel itself. I never got to implementing this because we already had auto-detachment properties from perf_event FD itself. But it would be nice to have that done as a real bpf_link in the kernel (with all the observability, program update, force-detach support). Looking for volunteers to make this happen ;) > > Since bpf wasn't looking for the perf event fd, I swapped it for the program fd > and bpf_link__pin() worked. But you were pinning the BPF program, not a BPF link. Which is not what should have happen. > > Sultan