Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp698202rdb; Tue, 23 Jan 2024 11:58:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYQcxtlKIcRpqJp4ILo+b/hIasfNElFa04ZcR4RTEjxGaa6lGnhFMhR+1u+uBKWz50dQ3f X-Received: by 2002:a05:6402:520d:b0:55c:a484:4167 with SMTP id s13-20020a056402520d00b0055ca4844167mr120583edd.3.1706039879912; Tue, 23 Jan 2024 11:57:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706039879; cv=pass; d=google.com; s=arc-20160816; b=gTayfg4yYUr7AT/o/IkOZDqoz5uuYX/IPsttb1OQeIfaIUQIhd/lJ59GBakF6Xmq9Q t7zZxDESuKQFi5uLkRhbs/bTx6H+80LWCMu00cIk7SW8/MKGnv/jhQ88b0Tw3CWZO7X6 AAAJZUbsxjwy3YVsFWodL41rCizlkJZDPZpW1g2TJ/5aD3KebcKs/VLjCq2PU0lE3Nsf MTHQAKll2dqfAUc3VTrgsgeiyzXuksGU62I1Y43sqKsIgnbBaOu1ZeZaVFIenh0LaC8b /n1PpNhl4w7/b38FnZOIGa9iKZFvBS4bUrOWgAKfKe8zV8zlJKBkDJqCcj+ya5mvcjyR 55GA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=mhXtvpl1MwEVA0HGf6b0dQAn6qf2NBu4JbI0qDtQpds=; fh=wg8GYdbDP7oFnRL6Ij0vZZAAGt2W7xr7u3QZs+YiI4E=; b=hO2tEp99/KCd/1YS/sP69WIJYHooL7dwVCbNYFHRndgoC1tf2qGffsE9qcqwVKhK2E dl5RxVhCnAU06lP2y3GPPaFWnGrDj8eG4840FUVcURncRd7bkb9Hgzz/+WpMva/c1FNP d5JhAlsI9tXz3R8wfD+gZimowjwpqofY4SjRTRqsQa9kIn+Hk+sNi4/mBF7bITfxVcIw y2j38Xd144veKanQAgAG6aMH8KfeW0v7rLPGas/CyPJaAOEBB+MT+P2sO95iMN+ol/sz EQSnBqGVWdC9dkrDLJmhWA/kqOVw33Ial6kOYV8QywCmxJXPP1rhch+j0PLQX5tVFoZc m3lg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DEgvV1Hg; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-35999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i5-20020a0564020f0500b0055c3a1a9d8bsi2502385eda.36.2024.01.23.11.57.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 11:57:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DEgvV1Hg; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-35999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7C84A1F24D3C for ; Tue, 23 Jan 2024 19:57:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C31182D94; Tue, 23 Jan 2024 19:57:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DEgvV1Hg" Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEA3D823D4; Tue, 23 Jan 2024 19:57:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706039864; cv=none; b=Pp5OBPOvA9paDA/sjbWB+ikWbJYavidb4hMRtswErovNvNJEY7rBe8E/n22iEjkeOUhmQeVaI4rrgj1DVvDOabKnTunx2kL25mLT9Y0noNomXT45FSy+nDtg9M1/f3OQh5r3Q+CUuqQF+NMAda7NOu24ZfY65Bi29IQuMdh1aGs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706039864; c=relaxed/simple; bh=6kxs3ZRNvsnBerU+pBLILGlvcZuN7Asm/1eLx4m2eKA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ePs55uIxn/9NV9WI1WJz0D/xijBey0J+x32pS1vA4CXsUFTtP3ikF0qxmlwp6xAfu7ABipZ+6qfPM+5/JnWXgl4whzC6292Fsv7aCosAYWmeRh3YXPAVBpbhLgB79jwUqxDacAVpf/s8HLfVivKvoQQ0jwcXRqonKUpFuXeCzhk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DEgvV1Hg; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6d9f94b9186so4652932b3a.0; Tue, 23 Jan 2024 11:57:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706039862; x=1706644662; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mhXtvpl1MwEVA0HGf6b0dQAn6qf2NBu4JbI0qDtQpds=; b=DEgvV1HgHSFEatdIKN/iO58TUXikAeyhIUkKuTzcNpYAIIkgvfOqGfkQ9QKhJOLTAp uyc07YlGYSLpZhyLIpGsJ58xQWsMnCSqts9VHuktNNG6jKmS399TtepO5uqpZTcdRkxB w5cyBYs7h4v0OQeLB9qCAk4dEpNVymx+b/mUbqgtxLfDI0yRnXvYWpBHsVaOK8np158E 9cCwi5FS5+zBMYleY1W5RJGMl3EajNV7XXOU8BainHWGrpA4GeergzrsGDyB8kvyV6kL st3SKlEwlJebv3VzX4Qc5BuDwx8yI0/XxkB4FpohhKnfK5N+IQXtUaEZDsvj7+Qv0p8a 891g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706039862; x=1706644662; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mhXtvpl1MwEVA0HGf6b0dQAn6qf2NBu4JbI0qDtQpds=; b=YltenMu5ziiyRCwCwYVsVBJAYdA5ZEBK1vvCRXpKwm1wazhwcQQwXNBA8zqN0vPZIX Ruraa6mCRTZ/ZOCXGTenlYg4+Zu0HG+TvIiINelaqCazxrbO2wab7uU6g3KHduTpUdb3 ioCGF1ckcFzUOX214iz44F1eUGK2zkNsddqn3qkeXjnGIzr7DxWkX2hU7gjmjN4cN9qI MX1jkYpPLk8NOi1ZRr+vbreIAFxwa85LBhvX3lKkAajkrE35znwhcDVDLqeE+PcSw4yf B8dLFmOdIJUzREm9T/kRAwxdZvJgiu95KfPp2++SgQkarlx9b/A+c4HGPnQVqhlQ4R1/ s4gw== X-Gm-Message-State: AOJu0Yyvd3GYo/MNLE1OSf6AAhLdWYYUGwVwR75V71nm7j9e57u0UFQm eXd/F4f0Swg1We/uB14PMIjWwni/4ro5Ulj4D3pCesdl+FhdB1miLNMk9JNc923cDdbRYcPIrzW 8jinLgbP/E0a13hSvE9wCX0vEb/E= X-Received: by 2002:a05:6a21:a592:b0:19c:6687:13d0 with SMTP id gd18-20020a056a21a59200b0019c668713d0mr124067pzc.27.1706039862102; Tue, 23 Jan 2024 11:57:42 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240123-b4-hid-bpf-fixes-v1-0-aa1fac734377@kernel.org> <20240123-b4-hid-bpf-fixes-v1-2-aa1fac734377@kernel.org> In-Reply-To: <20240123-b4-hid-bpf-fixes-v1-2-aa1fac734377@kernel.org> From: Andrii Nakryiko Date: Tue, 23 Jan 2024 11:57:30 -0800 Message-ID: Subject: Re: [PATCH 2/2] HID: bpf: use __bpf_kfunc instead of noinline To: Benjamin Tissoires Cc: Jiri Kosina , Benjamin Tissoires , Dan Carpenter , Daniel Borkmann , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jan 23, 2024 at 8:46=E2=80=AFAM Benjamin Tissoires wrote: > > Follow the docs at Documentation/bpf/kfuncs.rst: > - declare the function with `__bpf_kfunc` > - disables missing prototype warnings, which allows to remove them from > include/linux/hid-bpf.h > > Removing the prototypes is not an issue because we currently have to > redeclare them when writing the BPF program. They will eventually be > generated by bpftool directly AFAIU. > > Signed-off-by: Benjamin Tissoires > --- > drivers/hid/bpf/hid_bpf_dispatch.c | 22 +++++++++++++++++----- > include/linux/hid_bpf.h | 11 ----------- > 2 files changed, 17 insertions(+), 16 deletions(-) > > diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf= _dispatch.c > index 5111d1fef0d3..119e4f03df55 100644 > --- a/drivers/hid/bpf/hid_bpf_dispatch.c > +++ b/drivers/hid/bpf/hid_bpf_dispatch.c > @@ -143,6 +143,11 @@ u8 *call_hid_bpf_rdesc_fixup(struct hid_device *hdev= , u8 *rdesc, unsigned int *s > } > EXPORT_SYMBOL_GPL(call_hid_bpf_rdesc_fixup); > > +/* Disables missing prototype warnings */ > +__diag_push(); > +__diag_ignore_all("-Wmissing-prototypes", > + "Global kfuncs as their definitions will be in BTF"); > + would it be possible to use __bpf_kfunc_start_defs() and __bpf_kfunc_end_defs() macros instead of explicit __diag push/pop pairs? It's defined in include/linux/btf.h > /** > * hid_bpf_get_data - Get the kernel memory pointer associated with the = context @ctx > * > @@ -152,7 +157,7 @@ EXPORT_SYMBOL_GPL(call_hid_bpf_rdesc_fixup); > * > * @returns %NULL on error, an %__u8 memory pointer on success > */ > -noinline __u8 * > +__bpf_kfunc __u8 * > hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const siz= e_t rdwr_buf_size) > { > struct hid_bpf_ctx_kern *ctx_kern; > @@ -167,6 +172,7 @@ hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned in= t offset, const size_t rdwr > > return ctx_kern->data + offset; > } > +__diag_pop(); /* missing prototype warnings */ > > /* > * The following set contains all functions we agree BPF programs > @@ -274,6 +280,11 @@ static int do_hid_bpf_attach_prog(struct hid_device = *hdev, int prog_fd, struct b > return fd; > } > > +/* Disables missing prototype warnings */ > +__diag_push(); > +__diag_ignore_all("-Wmissing-prototypes", > + "Global kfuncs as their definitions will be in BTF"); > + > /** > * hid_bpf_attach_prog - Attach the given @prog_fd to the given HID devi= ce > * > @@ -286,7 +297,7 @@ static int do_hid_bpf_attach_prog(struct hid_device *= hdev, int prog_fd, struct b > * is pinned to the BPF file system). > */ > /* called from syscall */ > -noinline int > +__bpf_kfunc int > hid_bpf_attach_prog(unsigned int hid_id, int prog_fd, __u32 flags) > { > struct hid_device *hdev; > @@ -328,7 +339,7 @@ hid_bpf_attach_prog(unsigned int hid_id, int prog_fd,= __u32 flags) > * > * @returns A pointer to &struct hid_bpf_ctx on success, %NULL on error. > */ > -noinline struct hid_bpf_ctx * > +__bpf_kfunc struct hid_bpf_ctx * > hid_bpf_allocate_context(unsigned int hid_id) > { > struct hid_device *hdev; > @@ -359,7 +370,7 @@ hid_bpf_allocate_context(unsigned int hid_id) > * @ctx: the HID-BPF context to release > * > */ > -noinline void > +__bpf_kfunc void > hid_bpf_release_context(struct hid_bpf_ctx *ctx) > { > struct hid_bpf_ctx_kern *ctx_kern; > @@ -380,7 +391,7 @@ hid_bpf_release_context(struct hid_bpf_ctx *ctx) > * > * @returns %0 on success, a negative error code otherwise. > */ > -noinline int > +__bpf_kfunc int > hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz, > enum hid_report_type rtype, enum hid_class_request req= type) > { > @@ -448,6 +459,7 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf= , size_t buf__sz, > kfree(dma_data); > return ret; > } > +__diag_pop(); /* missing prototype warnings */ > > /* our HID-BPF entrypoints */ > BTF_SET8_START(hid_bpf_fmodret_ids) > diff --git a/include/linux/hid_bpf.h b/include/linux/hid_bpf.h > index 840cd254172d..7118ac28d468 100644 > --- a/include/linux/hid_bpf.h > +++ b/include/linux/hid_bpf.h > @@ -77,17 +77,6 @@ enum hid_bpf_attach_flags { > int hid_bpf_device_event(struct hid_bpf_ctx *ctx); > int hid_bpf_rdesc_fixup(struct hid_bpf_ctx *ctx); > > -/* Following functions are kfunc that we export to BPF programs */ > -/* available everywhere in HID-BPF */ > -__u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, con= st size_t __sz); > - > -/* only available in syscall */ > -int hid_bpf_attach_prog(unsigned int hid_id, int prog_fd, __u32 flags); > -int hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__s= z, > - enum hid_report_type rtype, enum hid_class_request= reqtype); > -struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id); > -void hid_bpf_release_context(struct hid_bpf_ctx *ctx); > - > /* > * Below is HID internal > */ > > -- > 2.43.0 > >