Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2212346pxm; Fri, 4 Mar 2022 11:29:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjcgOQkaNJSstffQvWTPrHoIF5nGkElYoGw+iO0Bl4KSLI3TZDBNJpZcRFaA5lv2TYCYJl X-Received: by 2002:a17:90b:3ece:b0:1bf:21bd:87d7 with SMTP id rm14-20020a17090b3ece00b001bf21bd87d7mr184607pjb.5.1646422189287; Fri, 04 Mar 2022 11:29:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646422189; cv=none; d=google.com; s=arc-20160816; b=N5MQE6TFSiY25/Ql2zIndLhhGVtCb6QW4uHJRf6xKFFnlL0bwN+UCOEhwrdjybnKD5 XqD8y1WJTuDlMb9jlDHO2YfHqJnLYzenSrfqyUdr3fc9e2v+vDYTctS4mNEOJSVFsO/J 5EaqPAsrs3wT9vZj+xew1CT1TkO/sED/UeShNJCDa8EhKpzw4Ou+YYNzKuI5etPWNCDp 3soSjOX8HxZHFPSLk3DupdRCrO02eiTcsMBfYhnrRJwH8vlOSI7EjOzT7d2JZ4upm+jk RNoJ0t9e9gojeS7IvKfllCtBB3CuOzSjJYoSUeTPpP9oEG+IKM1LSYhO8s8a8DZ5t5ki eYWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P4dsF2EhkFauEdp0HjjqmUlAUUQayYI3BzeDrS6IW5o=; b=Uo+LUBP05QY8GtMmcroEOasgjZAyAgP+wCiU45ft6DBnIEWsojEFuEqneoYjnv1w3W Kbj2QPCYRvMlRuvMpMG+By0WXQiyRLq7o7Zxyl4KuVcuvmgome3YdZkWWuiSlf0lYUFJ cWdMCIdNmcckt4W/MmkjKsc5mPYpN/Xi21TA5JOb+xeyfk6CSSeGDbHGN/sL/eHNA32x A0CLmbmuGVfAidjfjuxXa3Jyn60xBIgOBCvsY9yU5sd/vqk5+cQvYXjXSzyJdHhvDRw8 A/IUcbgmAiByCsvf+wNneXhhzssdC3r6WvzVQ+X/lOBUtKxn/ePFdqnOTKiGRyS/8jHn 4crg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ia4FtQcu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g2-20020a17090adac200b001bd14e01f4asi324601pjx.56.2022.03.04.11.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 11:29:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ia4FtQcu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 72A0A214167; Fri, 4 Mar 2022 11:12:21 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241250AbiCDRgv (ORCPT + 99 others); Fri, 4 Mar 2022 12:36:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241356AbiCDRg0 (ORCPT ); Fri, 4 Mar 2022 12:36:26 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D0F7BB0B0 for ; Fri, 4 Mar 2022 09:35:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646415302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P4dsF2EhkFauEdp0HjjqmUlAUUQayYI3BzeDrS6IW5o=; b=ia4FtQcutzUm/SYZ7PA/n7szeQWW8HcKb3F1uta84l9Eyk0QIUcnmwSKPh6XSeMKWLi/gX NJpzt7mEiiQp08oizW778XHmu6/8ZPrnZ6udcjVU4LHn3EJHT8ZIOd+IxVeNF6VuLgZlpu DY25OddLfgggp10TgFNGf3RvX8ZzOIQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-425-XrAQH9HIPDG3yTSLSPEL1A-1; Fri, 04 Mar 2022 12:35:01 -0500 X-MC-Unique: XrAQH9HIPDG3yTSLSPEL1A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CD1E805EE5; Fri, 4 Mar 2022 17:34:58 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45EE386595; Fri, 4 Mar 2022 17:34:39 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , Dave Marchevsky , Joe Stringer Cc: Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires Subject: [PATCH bpf-next v2 26/28] libbpf: add handling for BPF_F_INSERT_HEAD in HID programs Date: Fri, 4 Mar 2022 18:28:50 +0100 Message-Id: <20220304172852.274126-27-benjamin.tissoires@redhat.com> In-Reply-To: <20220304172852.274126-1-benjamin.tissoires@redhat.com> References: <20220304172852.274126-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Export the newly created flag to libbpf. Signed-off-by: Benjamin Tissoires --- new in v2 --- tools/include/uapi/linux/bpf.h | 10 ++++++++++ tools/lib/bpf/libbpf.c | 17 +++++++++-------- tools/lib/bpf/libbpf.h | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 417cf1c31579..23ebe5e96d69 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1123,6 +1123,16 @@ enum bpf_link_type { */ #define BPF_F_XDP_HAS_FRAGS (1U << 5) +/* HID flag used in BPF_LINK_CREATE command + * + * NONE(default): The bpf program will be added at the tail of the list + * of existing bpf program for this type. + * + * BPF_F_INSERT_HEAD: The bpf program will be added at the beginning + * of the list of existing bpf program for this type.. + */ +#define BPF_F_INSERT_HEAD (1U << 0) + /* When BPF ldimm64's insn[0].src_reg != 0 then this can have * the following extensions: * diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index d1e305f760bb..6f0cb6717207 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -10533,10 +10533,11 @@ static struct bpf_link *attach_lsm(const struct bpf_program *prog, long cookie) static struct bpf_link * bpf_program__attach_fd(const struct bpf_program *prog, int target_fd, int btf_id, - const char *target_name) + const char *target_name, __u32 flags) { DECLARE_LIBBPF_OPTS(bpf_link_create_opts, opts, - .target_btf_id = btf_id); + .target_btf_id = btf_id, + .flags = flags); enum bpf_attach_type attach_type; char errmsg[STRERR_BUFSIZE]; struct bpf_link *link; @@ -10570,19 +10571,19 @@ bpf_program__attach_fd(const struct bpf_program *prog, int target_fd, int btf_id struct bpf_link * bpf_program__attach_cgroup(const struct bpf_program *prog, int cgroup_fd) { - return bpf_program__attach_fd(prog, cgroup_fd, 0, "cgroup"); + return bpf_program__attach_fd(prog, cgroup_fd, 0, "cgroup", 0); } struct bpf_link * bpf_program__attach_netns(const struct bpf_program *prog, int netns_fd) { - return bpf_program__attach_fd(prog, netns_fd, 0, "netns"); + return bpf_program__attach_fd(prog, netns_fd, 0, "netns", 0); } struct bpf_link *bpf_program__attach_xdp(const struct bpf_program *prog, int ifindex) { /* target_fd/target_ifindex use the same field in LINK_CREATE */ - return bpf_program__attach_fd(prog, ifindex, 0, "xdp"); + return bpf_program__attach_fd(prog, ifindex, 0, "xdp", 0); } struct bpf_link *bpf_program__attach_freplace(const struct bpf_program *prog, @@ -10608,7 +10609,7 @@ struct bpf_link *bpf_program__attach_freplace(const struct bpf_program *prog, if (btf_id < 0) return libbpf_err_ptr(btf_id); - return bpf_program__attach_fd(prog, target_fd, btf_id, "freplace"); + return bpf_program__attach_fd(prog, target_fd, btf_id, "freplace", 0); } else { /* no target, so use raw_tracepoint_open for compatibility * with old kernels @@ -10663,9 +10664,9 @@ static struct bpf_link *attach_iter(const struct bpf_program *prog, long cookie) } struct bpf_link * -bpf_program__attach_hid(const struct bpf_program *prog, int hid_fd) +bpf_program__attach_hid(const struct bpf_program *prog, int hid_fd, __u32 flags) { - return bpf_program__attach_fd(prog, hid_fd, 0, "hid"); + return bpf_program__attach_fd(prog, hid_fd, 0, "hid", flags); } struct bpf_link *bpf_program__attach(const struct bpf_program *prog) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index f677ac0a9ede..65be3e2ec62d 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -530,7 +530,7 @@ LIBBPF_API struct bpf_link * bpf_program__attach_iter(const struct bpf_program *prog, const struct bpf_iter_attach_opts *opts); LIBBPF_API struct bpf_link * -bpf_program__attach_hid(const struct bpf_program *prog, int hid_fd); +bpf_program__attach_hid(const struct bpf_program *prog, int hid_fd, __u32 flags); /* * Libbpf allows callers to adjust BPF programs before being loaded -- 2.35.1