bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nios2, openrisc, xtensa: Fix definitions of bpf_user_pt_regs_t
@ 2025-08-22 13:58 Ben Hutchings
  2025-08-23  5:45 ` Stafford Horne
  2025-08-23 23:16 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Ben Hutchings @ 2025-08-22 13:58 UTC (permalink / raw)
  To: bpf; +Cc: Ben Hutchings, Dinh Nguyen, linux-openrisc, Chris Zankel,
	Max Filippov

The UAPI <asm/bpf_perf_event.h> header is required to define the type
alias bpf_user_pt_regs_t.  The generic version includes
<linux/ptrace.h> and defines it as an alias for struct pt_regs.

For these 3 architectures, struct pt_regs is not defined in the UAPI.
They need to override the generic version with an architecture-
specific definition of bpf_user_pt_regs_t.

References: https://autobuild.buildroot.org/results/bf2/bf21079facd21d684e8656e7ac44b4218a8fcb9d/build-end.log
Fixes: c895f6f703ad ("bpf: correct broken uapi for BPF_PROG_TYPE_PERF_EVENT program type")
Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
---
I understand that perf_events is not yet supported on nios2 and
openrisc, so this isn't obviously useful.  However, libbpf has generic
handling for BPF_PROG_TYPE_PERF_EVENT that includes
<linux/bpf_perf_event.h> and it now fails to build on openrisc.

I verified that:
- This fixes building libbpf with Buildroot for openrisc
- This makes "#include <linux/bpf_perf_event.h>" work on xtensa

I wasn't able to test nios2 at all.

Ben.

 arch/nios2/include/uapi/asm/bpf_perf_event.h    | 9 +++++++++
 arch/openrisc/include/uapi/asm/bpf_perf_event.h | 9 +++++++++
 arch/xtensa/include/uapi/asm/bpf_perf_event.h   | 9 +++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 arch/nios2/include/uapi/asm/bpf_perf_event.h
 create mode 100644 arch/openrisc/include/uapi/asm/bpf_perf_event.h
 create mode 100644 arch/xtensa/include/uapi/asm/bpf_perf_event.h

diff --git a/arch/nios2/include/uapi/asm/bpf_perf_event.h b/arch/nios2/include/uapi/asm/bpf_perf_event.h
new file mode 100644
index 000000000000..5e1e648aeec4
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/bpf_perf_event.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI__ASM_BPF_PERF_EVENT_H__
+#define _UAPI__ASM_BPF_PERF_EVENT_H__
+
+#include <asm/ptrace.h>
+
+typedef struct user_pt_regs bpf_user_pt_regs_t;
+
+#endif /* _UAPI__ASM_BPF_PERF_EVENT_H__ */
diff --git a/arch/openrisc/include/uapi/asm/bpf_perf_event.h b/arch/openrisc/include/uapi/asm/bpf_perf_event.h
new file mode 100644
index 000000000000..6cb1c2823288
--- /dev/null
+++ b/arch/openrisc/include/uapi/asm/bpf_perf_event.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI__ASM_BPF_PERF_EVENT_H__
+#define _UAPI__ASM_BPF_PERF_EVENT_H__
+
+#include <asm/ptrace.h>
+
+typedef struct user_regs_struct bpf_user_pt_regs_t;
+
+#endif /* _UAPI__ASM_BPF_PERF_EVENT_H__ */
diff --git a/arch/xtensa/include/uapi/asm/bpf_perf_event.h b/arch/xtensa/include/uapi/asm/bpf_perf_event.h
new file mode 100644
index 000000000000..5e1e648aeec4
--- /dev/null
+++ b/arch/xtensa/include/uapi/asm/bpf_perf_event.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI__ASM_BPF_PERF_EVENT_H__
+#define _UAPI__ASM_BPF_PERF_EVENT_H__
+
+#include <asm/ptrace.h>
+
+typedef struct user_pt_regs bpf_user_pt_regs_t;
+
+#endif /* _UAPI__ASM_BPF_PERF_EVENT_H__ */
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] nios2, openrisc, xtensa: Fix definitions of bpf_user_pt_regs_t
  2025-08-22 13:58 [PATCH] nios2, openrisc, xtensa: Fix definitions of bpf_user_pt_regs_t Ben Hutchings
@ 2025-08-23  5:45 ` Stafford Horne
  2025-08-23 23:16 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: Stafford Horne @ 2025-08-23  5:45 UTC (permalink / raw)
  To: Ben Hutchings
  Cc: bpf, Dinh Nguyen, linux-openrisc, Chris Zankel, Max Filippov

On Fri, Aug 22, 2025 at 03:58:48PM +0200, Ben Hutchings wrote:
> The UAPI <asm/bpf_perf_event.h> header is required to define the type
> alias bpf_user_pt_regs_t.  The generic version includes
> <linux/ptrace.h> and defines it as an alias for struct pt_regs.
> 
> For these 3 architectures, struct pt_regs is not defined in the UAPI.
> They need to override the generic version with an architecture-
> specific definition of bpf_user_pt_regs_t.
> 
> References: https://autobuild.buildroot.org/results/bf2/bf21079facd21d684e8656e7ac44b4218a8fcb9d/build-end.log
> Fixes: c895f6f703ad ("bpf: correct broken uapi for BPF_PROG_TYPE_PERF_EVENT program type")
> Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
> ---
> I understand that perf_events is not yet supported on nios2 and
> openrisc, so this isn't obviously useful.  However, libbpf has generic
> handling for BPF_PROG_TYPE_PERF_EVENT that includes
> <linux/bpf_perf_event.h> and it now fails to build on openrisc.

Understood.

> I verified that:
> - This fixes building libbpf with Buildroot for openrisc
> - This makes "#include <linux/bpf_perf_event.h>" work on xtensa
> 
> I wasn't able to test nios2 at all.
> 
> Ben.
> 
>  arch/nios2/include/uapi/asm/bpf_perf_event.h    | 9 +++++++++
>  arch/openrisc/include/uapi/asm/bpf_perf_event.h | 9 +++++++++
>  arch/xtensa/include/uapi/asm/bpf_perf_event.h   | 9 +++++++++
>  3 files changed, 27 insertions(+)
>  create mode 100644 arch/nios2/include/uapi/asm/bpf_perf_event.h
>  create mode 100644 arch/openrisc/include/uapi/asm/bpf_perf_event.h
>  create mode 100644 arch/xtensa/include/uapi/asm/bpf_perf_event.h
> 
> diff --git a/arch/nios2/include/uapi/asm/bpf_perf_event.h b/arch/nios2/include/uapi/asm/bpf_perf_event.h
> new file mode 100644
> index 000000000000..5e1e648aeec4
> --- /dev/null
> +++ b/arch/nios2/include/uapi/asm/bpf_perf_event.h
> @@ -0,0 +1,9 @@
> +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
> +#ifndef _UAPI__ASM_BPF_PERF_EVENT_H__
> +#define _UAPI__ASM_BPF_PERF_EVENT_H__
> +
> +#include <asm/ptrace.h>
> +
> +typedef struct user_pt_regs bpf_user_pt_regs_t;
> +
> +#endif /* _UAPI__ASM_BPF_PERF_EVENT_H__ */
> diff --git a/arch/openrisc/include/uapi/asm/bpf_perf_event.h b/arch/openrisc/include/uapi/asm/bpf_perf_event.h
> new file mode 100644
> index 000000000000..6cb1c2823288
> --- /dev/null
> +++ b/arch/openrisc/include/uapi/asm/bpf_perf_event.h
> @@ -0,0 +1,9 @@
> +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
> +#ifndef _UAPI__ASM_BPF_PERF_EVENT_H__
> +#define _UAPI__ASM_BPF_PERF_EVENT_H__
> +
> +#include <asm/ptrace.h>
> +
> +typedef struct user_regs_struct bpf_user_pt_regs_t;
> +
> +#endif /* _UAPI__ASM_BPF_PERF_EVENT_H__ */

This bit,

Acked-by: Stafford Horne <shorne@gmail.com>

Who do you plan on having take this patch for upstream?  Will you?

-Stafford

> diff --git a/arch/xtensa/include/uapi/asm/bpf_perf_event.h b/arch/xtensa/include/uapi/asm/bpf_perf_event.h
> new file mode 100644
> index 000000000000..5e1e648aeec4
> --- /dev/null
> +++ b/arch/xtensa/include/uapi/asm/bpf_perf_event.h
> @@ -0,0 +1,9 @@
> +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
> +#ifndef _UAPI__ASM_BPF_PERF_EVENT_H__
> +#define _UAPI__ASM_BPF_PERF_EVENT_H__
> +
> +#include <asm/ptrace.h>
> +
> +typedef struct user_pt_regs bpf_user_pt_regs_t;
> +
> +#endif /* _UAPI__ASM_BPF_PERF_EVENT_H__ */
> -- 
> 2.39.5
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nios2, openrisc, xtensa: Fix definitions of bpf_user_pt_regs_t
  2025-08-22 13:58 [PATCH] nios2, openrisc, xtensa: Fix definitions of bpf_user_pt_regs_t Ben Hutchings
  2025-08-23  5:45 ` Stafford Horne
@ 2025-08-23 23:16 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2025-08-23 23:16 UTC (permalink / raw)
  To: Ben Hutchings, bpf
  Cc: oe-kbuild-all, Ben Hutchings, Dinh Nguyen, linux-openrisc,
	Chris Zankel, Max Filippov

Hi Ben,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on openrisc/for-next jcmvbkbc-xtensa/xtensa-for-next v6.17-rc2 next-20250822]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Ben-Hutchings/nios2-openrisc-xtensa-Fix-definitions-of-bpf_user_pt_regs_t/20250822-220742
base:   linus/master
patch link:    https://lore.kernel.org/r/20250822135848.1922288-1-ben.hutchings%40mind.be
patch subject: [PATCH] nios2, openrisc, xtensa: Fix definitions of bpf_user_pt_regs_t
config: xtensa-allyesconfig (https://download.01.org/0day-ci/archive/20250824/202508240726.GADEDNYH-lkp@intel.com/config)
compiler: xtensa-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250824/202508240726.GADEDNYH-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508240726.GADEDNYH-lkp@intel.com/

All errors (new ones prefixed by >>):

   kernel/events/core.c: In function 'bpf_overflow_handler':
>> kernel/events/core.c:10208:18: error: assignment to 'bpf_user_pt_regs_t *' {aka 'struct user_pt_regs *'} from incompatible pointer type 'struct pt_regs *' [-Wincompatible-pointer-types]
   10208 |         ctx.regs = perf_arch_bpf_user_pt_regs(regs);
         |                  ^


vim +10208 kernel/events/core.c

030a976efae83f Peter Zijlstra 2022-11-19  10195  
4c03fe11b96bda Kyle Huey      2024-04-11  10196  #ifdef CONFIG_BPF_SYSCALL
f11f10bfa1ca23 Kyle Huey      2024-04-11  10197  static int bpf_overflow_handler(struct perf_event *event,
4c03fe11b96bda Kyle Huey      2024-04-11  10198  				struct perf_sample_data *data,
4c03fe11b96bda Kyle Huey      2024-04-11  10199  				struct pt_regs *regs)
4c03fe11b96bda Kyle Huey      2024-04-11  10200  {
4c03fe11b96bda Kyle Huey      2024-04-11  10201  	struct bpf_perf_event_data_kern ctx = {
4c03fe11b96bda Kyle Huey      2024-04-11  10202  		.data = data,
4c03fe11b96bda Kyle Huey      2024-04-11  10203  		.event = event,
4c03fe11b96bda Kyle Huey      2024-04-11  10204  	};
4c03fe11b96bda Kyle Huey      2024-04-11  10205  	struct bpf_prog *prog;
4c03fe11b96bda Kyle Huey      2024-04-11  10206  	int ret = 0;
4c03fe11b96bda Kyle Huey      2024-04-11  10207  
4c03fe11b96bda Kyle Huey      2024-04-11 @10208  	ctx.regs = perf_arch_bpf_user_pt_regs(regs);
4c03fe11b96bda Kyle Huey      2024-04-11  10209  	if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1))
4c03fe11b96bda Kyle Huey      2024-04-11  10210  		goto out;
4c03fe11b96bda Kyle Huey      2024-04-11  10211  	rcu_read_lock();
4c03fe11b96bda Kyle Huey      2024-04-11  10212  	prog = READ_ONCE(event->prog);
4c03fe11b96bda Kyle Huey      2024-04-11  10213  	if (prog) {
4c03fe11b96bda Kyle Huey      2024-04-11  10214  		perf_prepare_sample(data, event, regs);
4c03fe11b96bda Kyle Huey      2024-04-11  10215  		ret = bpf_prog_run(prog, &ctx);
4c03fe11b96bda Kyle Huey      2024-04-11  10216  	}
4c03fe11b96bda Kyle Huey      2024-04-11  10217  	rcu_read_unlock();
4c03fe11b96bda Kyle Huey      2024-04-11  10218  out:
4c03fe11b96bda Kyle Huey      2024-04-11  10219  	__this_cpu_dec(bpf_prog_active);
4c03fe11b96bda Kyle Huey      2024-04-11  10220  
f11f10bfa1ca23 Kyle Huey      2024-04-11  10221  	return ret;
4c03fe11b96bda Kyle Huey      2024-04-11  10222  }
4c03fe11b96bda Kyle Huey      2024-04-11  10223  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-23 23:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22 13:58 [PATCH] nios2, openrisc, xtensa: Fix definitions of bpf_user_pt_regs_t Ben Hutchings
2025-08-23  5:45 ` Stafford Horne
2025-08-23 23:16 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).