Linux Trace Kernel
 help / color / mirror / Atom feed
* Re: 答复: [External Mail]Re: [PATCH v4] dma-buf: add some tracepoints to debug.
From: Christian König @ 2025-12-01  8:24 UTC (permalink / raw)
  To: 高翔, Barry Song, Xiang Gao
  Cc: sumit.semwal@linaro.org, rostedt@goodmis.org, mhiramat@kernel.org,
	linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com,
	dhowells@redhat.com, kuba@kernel.org, brauner@kernel.org,
	akpm@linux-foundation.org, linux-trace-kernel@vger.kernel.org
In-Reply-To: <d7269943f2c742bdb4d019ec074e5a8c@xiaomi.com>

On 12/1/25 02:44, 高翔 wrote:
>> BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
> At present, from the perspective of processes, trace still makes sense.

Yeah, it probably do in most use cases. I just want to cover all use cases.

Maybe just use %p to print the attachment pointer until we have something better.

> 
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *发件人:* 高翔
> *发送时间:* 2025年11月28日 21:14:14
> *收件人:* Christian König; Barry Song; Xiang Gao
> *抄送:* sumit.semwal@linaro.org; rostedt@goodmis.org; mhiramat@kernel.org; linux-media@vger.kernel.org; dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; mathieu.desnoyers@efficios.com; dhowells@redhat.com; kuba@kernel.org; brauner@kernel.org; akpm@linux-foundation.org; linux-trace-kernel@vger.kernel.org
> *主题:* 答复: [External Mail]Re: [PATCH v4] dma-buf: add some tracepoints to debug.
>  
> 
>> Thinking more about it I was wondering if we really need the userspace assigned name in the tracepoint in the first place.
>> The ino should be sufficient to uniquely identify each dma-buf, tracing the name should only be printed if it's changing or otherwise we spam the tracelog quite a bit with it.
> 
> Many threads use dmabuf "qcom,system". If there is a userspace name, we can immediately find the dmabuf I'm using. It might indeed not be necessary in other scenarios.

The DMA-buf "name" is an userspace assigned name and *not* useable for what you suggest here.

E.g. it is usually something like "texture", "shader", "dummy", "global"....

Could be that you have a driver or use case where it is something more specific and we can keep it where it makes sense for you, but I strongly suggest to always print the ino first since that one is guaranteed to be unique.

Regards,
Christian.

> 
> 
>> BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
> 
> This requires some thought.
> 
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *发件人:* Christian König <christian.koenig@amd.com>
> *发送时间:* 2025年11月28日 17:39:31
> *收件人:* Barry Song; Xiang Gao
> *抄送:* sumit.semwal@linaro.org; rostedt@goodmis.org; mhiramat@kernel.org; linux-media@vger.kernel.org; dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; mathieu.desnoyers@efficios.com; dhowells@redhat.com; kuba@kernel.org; brauner@kernel.org; akpm@linux-foundation.org; linux-trace-kernel@vger.kernel.org; 高翔
> *主题:* [External Mail]Re: [PATCH v4] dma-buf: add some tracepoints to debug.
>  
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xiaomi.com进行反馈
> 
> On 11/28/25 10:31, Barry Song wrote:
>> On Fri, Nov 28, 2025 at 4:53 PM Xiang Gao <gxxa03070307@gmail.com> wrote:
>>>
>>> From: gaoxiang17 <gaoxiang17@xiaomi.com>
>>>
>>> I want to track the status of dmabuf in real time in the production environment.
>>> But now we can only check it by traversing the fd in the process or dmabuf_list.
>>
>> might be:
>>
>> Since we can only inspect dmabuf by iterating over process FDs or the
>> dmabuf_list, we need to add our own tracepoints to track its status in
>> real time in production.
>>
>>>
>>> For example:
>>>    binder:3031_4-18348   [005] ...1.   545.568275: dma_buf_export: exp_name=qcom,system name=(null) size=217088 ino=2750
>>>    binder:3031_4-18348   [005] ...1.   545.568284: dma_buf_fd: exp_name=qcom,system name=(null) size=217088 ino=2750 fd=8
>>>    binder:3031_4-18348   [005] ...1.   545.568399: dma_buf_mmap_internal: exp_name=qcom,system name=qcom,system size=28672 ino=2751
>>>      kworker/5:1-130     [005] ...1.   545.570193: dma_buf_put: exp_name=qcom,system name=ab size=28672 ino=2751
>>>     RenderThread-18891   [005] ...1.   545.602994: dma_buf_get: exp_name=qcom,system name=ab size=217088 ino=2750 fd=1087
>>>     RenderThread-9409    [000] .n.1.   545.745004: dma_buf_dynamic_attach: exp_name=qcom,system name=ab size=217088 ino=2750 is_dynamic=0 dev_name=kgsl-3d0
>>>     RenderThread-9409    [005] ...1.   545.747802: dma_buf_detach: exp_name=qcom,system name=bq size=12771328 ino=2764 is_dynamic=0 dev_name=kgsl-3d0
>>>
>>> Signed-off-by: Xiang Gao <gaoxiang17@xiaomi.com>
>>> ---
>>>  drivers/dma-buf/dma-buf.c      |  48 +++++++++-
>>>  include/trace/events/dma_buf.h | 160 +++++++++++++++++++++++++++++++++
>>>  2 files changed, 207 insertions(+), 1 deletion(-)
>>>  create mode 100644 include/trace/events/dma_buf.h
>>>
>>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
>>> index 2bcf9ceca997..6e04e12f149e 100644
>>> --- a/drivers/dma-buf/dma-buf.c
>>> +++ b/drivers/dma-buf/dma-buf.c
>>> @@ -35,6 +35,9 @@
>>>
>>>  #include "dma-buf-sysfs-stats.h"
>>>
>>> +#define CREATE_TRACE_POINTS
>>> +#include <trace/events/dma_buf.h>
>>> +
>>>  static inline int is_dma_buf_file(struct file *);
>>>
>>>  static DEFINE_MUTEX(dmabuf_list_mutex);
>>> @@ -220,6 +223,11 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
>>>             dmabuf->size >> PAGE_SHIFT)
>>>                 return -EINVAL;
>>>
>>> +       if (trace_dma_buf_mmap_internal_enabled()) {
>>> +               guard(spinlock)(&dmabuf->name_lock);
>>> +               trace_dma_buf_mmap_internal(dmabuf);
>>> +       }
>>> +
>>>         return dmabuf->ops->mmap(dmabuf, vma);
>>>  }
>>>
>>> @@ -745,6 +753,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
>>>
>>>         __dma_buf_list_add(dmabuf);
>>>
>>> +       if (trace_dma_buf_export_enabled()) {
>>> +               guard(spinlock)(&dmabuf->name_lock);
>>> +               trace_dma_buf_export(dmabuf);
>>> +       }
>>> +
>>
>> perhaps a macro similar to the one below
>>
>> #define DMA_BUF_TRACE(FUNC, ...)                  \
>>     do {                                          \
>>         if (FUNC##_enabled()) {                   \
>>             guard(spinlock)(&dmabuf->name_lock); \
>>             FUNC(__VA_ARGS__);                    \
>>         }                                         \
>>     } while (0)
>>
>>
>> This would help us avoid duplicating a lot of code.
>>
>> could be:
>> DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);
>> DMA_BUF_TRACE(trace_dma_buf_attach, dmabuf, dev);
>>
>> ?
> 
> Thinking more about it I was wondering if we really need the userspace assigned name in the tracepoint in the first place.
> 
> The ino should be sufficient to uniquely identify each dma-buf, tracing the name should only be printed if it's changing or otherwise we spam the tracelog quite a bit with it.
> 
> BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
> 
> Regards,
> Christian.
> 


^ permalink raw reply

* Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
From: Jani Nikula @ 2025-12-01  7:46 UTC (permalink / raw)
  To: Yury Norov (NVIDIA), Steven Rostedt, Masami Hiramatsu,
	Mathieu Desnoyers, Andy Shevchenko, Randy Dunlap, Ingo Molnar,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, Petr Pavlu,
	Daniel Gomez, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Andrew Morton, linux-kernel, intel-gfx,
	dri-devel, linux-modules, linux-trace-kernel
  Cc: Yury Norov (NVIDIA)
In-Reply-To: <20251129195304.204082-2-yury.norov@gmail.com>

On Sat, 29 Nov 2025, "Yury Norov (NVIDIA)" <yury.norov@gmail.com> wrote:
> The macro is only used by i915. Move it to a local header and drop from
> the kernel.h.
>
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> ---
>  drivers/gpu/drm/i915/i915_utils.h | 2 ++
>  include/linux/kernel.h            | 2 --
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> index a0c892e4c40d..6c197e968305 100644
> --- a/drivers/gpu/drm/i915/i915_utils.h
> +++ b/drivers/gpu/drm/i915/i915_utils.h

i915_utils.h is on a diet itself. STACK_MAGIC is only used in selftests,
please put this in i915_selftest.h.

I guess also need to include that from gt/selftest_ring_submission.c,
the only one that uses STACK_MAGIC but doesn't include i915_selftest.h.

BR,
Jani.


> @@ -32,6 +32,8 @@
>  #include <linux/workqueue.h>
>  #include <linux/sched/clock.h>
>  
> +#define STACK_MAGIC	0xdeadbeef
> +
>  #ifdef CONFIG_X86
>  #include <asm/hypervisor.h>
>  #endif
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index 5b46924fdff5..61d63c57bc2d 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -40,8 +40,6 @@
>  
>  #include <uapi/linux/kernel.h>
>  
> -#define STACK_MAGIC	0xdeadbeef
> -
>  struct completion;
>  struct user;

-- 
Jani Nikula, Intel

^ permalink raw reply

* Re: [PATCH 3/3] tracing: move tracing declarations from kernel.h to a dedicated header
From: Andy Shevchenko @ 2025-12-01  2:50 UTC (permalink / raw)
  To: david laight
  Cc: Yury Norov, Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Randy Dunlap, Ingo Molnar, Jani Nikula, Joonas Lahtinen,
	Rodrigo Vivi, Tvrtko Ursulin, Petr Pavlu, Daniel Gomez,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Andrew Morton, linux-kernel, intel-gfx, dri-devel, linux-modules,
	linux-trace-kernel
In-Reply-To: <20251130230925.376b5377@pumpkin>

On Sun, Nov 30, 2025 at 11:09:25PM +0000, david laight wrote:
> On Sun, 30 Nov 2025 21:44:46 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

...

> It is worth checking whether the files get included anyway, and whether it
> really makes that much difference.
> 
> Fiddling with kernel.h and extracting small 'leaf' headers from it is also
> unlikely to make a big difference.

It makes a big difference for the kernel.h and its (ab)users.
Especially when we have cyclic dependencies and "include everything"
cases due to other _headers_ including kernel.h.

> Try adding a syntax error to (say) sys/ioctl.h and see where it is included
> from the first time - I suspect you'll be surprised.
> Working on that include list might be more fruitful (in reducing build times).

kernel.h elimination (in the form it exists right now) is very fruitful.
However, you may help with the (say) ioctl.h or whatever you consider
really fruitful, we all will thank you (no jokes).

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* Re: [PATCH 3/3] tracing: move tracing declarations from kernel.h to a dedicated header
From: david laight @ 2025-11-30 23:09 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Yury Norov, Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Randy Dunlap, Ingo Molnar, Jani Nikula, Joonas Lahtinen,
	Rodrigo Vivi, Tvrtko Ursulin, Petr Pavlu, Daniel Gomez,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Andrew Morton, linux-kernel, intel-gfx, dri-devel, linux-modules,
	linux-trace-kernel
In-Reply-To: <aSyertuRRX9Czvyz@smile.fi.intel.com>

On Sun, 30 Nov 2025 21:44:46 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Sun, Nov 30, 2025 at 01:16:19PM -0500, Yury Norov wrote:
> > On Sat, Nov 29, 2025 at 10:30:23PM +0200, Andy Shevchenko wrote:  
> > > On Sat, Nov 29, 2025 at 02:53:02PM -0500, Yury Norov (NVIDIA) wrote:  
> > > > Tracing is a half of the kernel.h in terms of LOCs, although it's a
> > > > self-consistent part. Move it to a separate header.
> > > > 
> > > > This is a pure move, except for removing a few 'extern's.  
> > > 
> > > Yeah, I also have something similar (but half-baked) locally, the Q I wanted to
> > > ask is why a separate header? We have already some of tracing headers. Doesn't
> > > suit well?  
> > 
> > Just as said in the commit message - this part is more or less
> > self-consistent and debugging-oriented. If someone needs to just
> > throw trace_printk() in their driver, they will not have to pull
> > all the heavy tracing machinery.  
> 
> Please, add a summary of this to it. It will be much clearer and based on it
> I agree with your judgement.

It is worth checking whether the files get included anyway, and whether it
really makes that much difference.

Fiddling with kernel.h and extracting small 'leaf' headers from it is also
unlikely to make a big difference.

Try adding a syntax error to (say) sys/ioctl.h and see where it is included
from the first time - I suspect you'll be surprised.
Working on that include list might be more fruitful (in reducing build times).

	David

^ permalink raw reply

* Re: [PATCH 3/3] tracing: move tracing declarations from kernel.h to a dedicated header
From: Steven Rostedt @ 2025-11-30 20:36 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Yury Norov, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aSyertuRRX9Czvyz@smile.fi.intel.com>

On Sun, 30 Nov 2025 21:44:46 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Sun, Nov 30, 2025 at 01:16:19PM -0500, Yury Norov wrote:
> > On Sat, Nov 29, 2025 at 10:30:23PM +0200, Andy Shevchenko wrote:  
> > > On Sat, Nov 29, 2025 at 02:53:02PM -0500, Yury Norov (NVIDIA) wrote:  
> > > > Tracing is a half of the kernel.h in terms of LOCs, although it's a
> > > > self-consistent part. Move it to a separate header.
> > > > 
> > > > This is a pure move, except for removing a few 'extern's.  
> > > 
> > > Yeah, I also have something similar (but half-baked) locally, the Q I wanted to
> > > ask is why a separate header? We have already some of tracing headers. Doesn't
> > > suit well?  
> > 
> > Just as said in the commit message - this part is more or less
> > self-consistent and debugging-oriented. If someone needs to just
> > throw trace_printk() in their driver, they will not have to pull
> > all the heavy tracing machinery.  
> 
> Please, add a summary of this to it. It will be much clearer and based on it
> I agree with your judgement.

Agreed. Please update the change log stating that the tracing code in
kernel.h is only used for quick debugging purposes and is not used for
the normal tracing utilities.

-- Steve

^ permalink raw reply

* Re: [PATCH 3/3] tracing: move tracing declarations from kernel.h to a dedicated header
From: Steven Rostedt @ 2025-11-30 20:34 UTC (permalink / raw)
  To: Yury Norov (NVIDIA)
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Andy Shevchenko,
	Randy Dunlap, Ingo Molnar, Jani Nikula, Joonas Lahtinen,
	Rodrigo Vivi, Tvrtko Ursulin, Petr Pavlu, Daniel Gomez,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Andrew Morton, linux-kernel, intel-gfx, dri-devel, linux-modules,
	linux-trace-kernel
In-Reply-To: <20251129195304.204082-4-yury.norov@gmail.com>

On Sat, 29 Nov 2025 14:53:02 -0500
"Yury Norov (NVIDIA)" <yury.norov@gmail.com> wrote:

> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -27,6 +27,7 @@
>  #include <linux/math.h>
>  #include <linux/minmax.h>
>  #include <linux/typecheck.h>
> +#include <linux/tracing.h>
>  #include <linux/panic.h>
>  #include <linux/printk.h>
>  #include <linux/build_bug.h>

I'm fine with this as long as it's available as much as printk is.

Acked-by: Steven Rostedt <rostedt@goodmis.org>

-- Steve

^ permalink raw reply

* Re: [PATCH 3/3] tracing: move tracing declarations from kernel.h to a dedicated header
From: Andy Shevchenko @ 2025-11-30 19:44 UTC (permalink / raw)
  To: Yury Norov
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aSyJ83v7EEAPHXeU@yury>

On Sun, Nov 30, 2025 at 01:16:19PM -0500, Yury Norov wrote:
> On Sat, Nov 29, 2025 at 10:30:23PM +0200, Andy Shevchenko wrote:
> > On Sat, Nov 29, 2025 at 02:53:02PM -0500, Yury Norov (NVIDIA) wrote:
> > > Tracing is a half of the kernel.h in terms of LOCs, although it's a
> > > self-consistent part. Move it to a separate header.
> > > 
> > > This is a pure move, except for removing a few 'extern's.
> > 
> > Yeah, I also have something similar (but half-baked) locally, the Q I wanted to
> > ask is why a separate header? We have already some of tracing headers. Doesn't
> > suit well?
> 
> Just as said in the commit message - this part is more or less
> self-consistent and debugging-oriented. If someone needs to just
> throw trace_printk() in their driver, they will not have to pull
> all the heavy tracing machinery.

Please, add a summary of this to it. It will be much clearer and based on it
I agree with your judgement.

...

> > > --- a/include/linux/kernel.h
> > > +++ b/include/linux/kernel.h
> > > @@ -27,6 +27,7 @@
> > >  #include <linux/math.h>
> > >  #include <linux/minmax.h>
> > >  #include <linux/typecheck.h>
> > 
> > > +#include <linux/tracing.h>
> > 
> > There is better place for t*.h, i.e. after static_call_types.h.
> 
> They are poorly sorted for seemingly no good reason. I found the first
> t*.h and just put this header next to it. Don't think that placing it
> next to static_call_types.h is any better or worse.

It's better, because the (sparsed) chain of the sorted one is longer.

> > Btw, have you tried to sort alphabetically the bulk in the kernel.h after
> > your series. Does it still build? (Just wondering about state of affairs
> > with the possible cyclic dependencies.)
> 
> I didn't try. Sorting #include's is not the purpose of the series.

I know, I'm _just wondering_.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* Re: [PATCH 2/3] kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h
From: Andy Shevchenko @ 2025-11-30 19:42 UTC (permalink / raw)
  To: Yury Norov
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aSyMobJnY4qKmsdk@yury>

On Sun, Nov 30, 2025 at 01:27:45PM -0500, Yury Norov wrote:
> On Sat, Nov 29, 2025 at 10:24:48PM +0200, Andy Shevchenko wrote:
> > On Sat, Nov 29, 2025 at 02:53:01PM -0500, Yury Norov (NVIDIA) wrote:
> > > The macro is related to sysfs, but is defined in kernel.h. Move it to
> > > the proper header, and unload the generic kernel.h.
> > 
> > Tough guy :-)
> > I hope it builds well in your case.
> > 
> > FWIW,
> > https://lore.kernel.org/lkml/20220603172101.49950-1-andriy.shevchenko@linux.intel.com/
> > https://lore.kernel.org/lkml/20240212115500.2078463-1-max.kellermann@ionos.com/
> > https://lore.kernel.org/lkml/20240215093646.3265823-1-max.kellermann@ionos.com/
> 
> Oh, OK. Surely I didn't want to undercut your or Max's work.

It's not about undercutting, I referred just for your information.

> Do you know why it wasn't merged in 2022 and 2024?

I have no idea why his (shorten) version of the series had been ignored.
Perhaps wrong / missing Cc? Also he went too far on splitting things, and IIRC
I mentioned that to him in one of the review rounds (but not sure).

So, I think you can take his work as Originally-by: and modify accordingly.

> > Assuming it builds in allmodconfig, allyesconfig on x86_32/64 and arm/64
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> It seemingly builds well. Thanks for review.

That said, I'm totally fine with your patch as mine at least didn't build
that time.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* Re: [PATCH 2/3] kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h
From: Andy Shevchenko @ 2025-11-30 19:38 UTC (permalink / raw)
  To: Yury Norov
  Cc: Randy Dunlap, Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aSyCC7TQoGgTn2rT@yury>

On Sun, Nov 30, 2025 at 12:42:35PM -0500, Yury Norov wrote:
> On Sat, Nov 29, 2025 at 10:19:29PM -0800, Randy Dunlap wrote:
> > 
> > 
> > On 11/29/25 12:24 PM, Andy Shevchenko wrote:
> > > On Sat, Nov 29, 2025 at 02:53:01PM -0500, Yury Norov (NVIDIA) wrote:
> > >> The macro is related to sysfs, but is defined in kernel.h. Move it to
> > >> the proper header, and unload the generic kernel.h.
> > > 
> > > Tough guy :-)
> > > I hope it builds well in your case.
> > > 
> > > FWIW,
> > > https://lore.kernel.org/lkml/20220603172101.49950-1-andriy.shevchenko@linux.intel.com/
> > > https://lore.kernel.org/lkml/20240212115500.2078463-1-max.kellermann@ionos.com/
> > > https://lore.kernel.org/lkml/20240215093646.3265823-1-max.kellermann@ionos.com/
> > > 
> > > Assuming it builds in allmodconfig, allyesconfig on x86_32/64 and arm/64
> > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > 
> > I don't build allyesconfigs any more (final? linking takes too long).
> > It builds successfully for arm64 allmodconfig, arm allmodconfig,
> > i386 allmodconfig, and x86_64 allmodconfig.
> > 
> > And the source files that use VERIFY_OCTAL_PERMISSIONS() all build successfully
> > (which means that they possibly include <linux/sysfs.h> indirectly, i.e.,
> > by luck). There aren't many of them, so I checked:
> > 
> > arch/arc/kernel/perf_event.c:	arc_pmu->attr[j].attr.attr.mode = VERIFY_OCTAL_PERMISSIONS(0444);
> > INDIRECT
> > drivers/edac/thunderx_edac.c:	.mode = VERIFY_OCTAL_PERMISSIONS(_mode),		    \
> > INDIRECT
> > drivers/media/platform/amphion/vpu_dbg.c:		    VERIFY_OCTAL_PERMISSIONS(0644),
> > INDIRECT
> > drivers/soc/aspeed/aspeed-uart-routing.c:	 .mode = VERIFY_OCTAL_PERMISSIONS(0644) },	\
> > INDIRECT
> > fs/xfs/xfs_error.c:		 .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) },	\
> > INDIRECT
> > include/linux/moduleparam.h:	    VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
> > INDIRECT
> > 
> > so all of them got lucky. :)
> > 
> > Acked-by: Randy Dunlap <rdunlap@infradead.org>
> > Tested-by: Randy Dunlap <rdunlap@infradead.org>
> 
> Thanks, Randy.
> 
> This series was tested by 0-day and LKP. 0-day runs allyesconfig,

AFAICS in the below no configuration had been tested against allYESconfig.
All of them are allNOconfig.

> as far as I know. It only sends email in case of errors. LKP is OK, find the
> report below.

> All but XFS include it via linux/module.h -> linux/moduleparam.h path.
> XFS has a linkage layer: xfs.h -> xfs_linux.h-> linux/module.h, so
> it's pretty much the same.
> 
> I think, module.h inclusion path is OK for this macro and definitely
> better than kernel.h. Notice, none of them, except for vgpu_dbg,
> include kernel.h directly.

Ideally those (especially and in the first place headers) should follow IWYU
principle and avoid indirect (non-guaranteed) inclusions.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* Re: [PATCH 2/3] kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h
From: Andy Shevchenko @ 2025-11-30 19:35 UTC (permalink / raw)
  To: Yury Norov
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aSyFNSqWv_A7JNpI@yury>

On Sun, Nov 30, 2025 at 12:56:05PM -0500, Yury Norov wrote:
> On Sat, Nov 29, 2025 at 10:35:54PM +0200, Andy Shevchenko wrote:
> > On Sat, Nov 29, 2025 at 10:34:02PM +0200, Andy Shevchenko wrote:
> > > On Sat, Nov 29, 2025 at 10:24:55PM +0200, Andy Shevchenko wrote:
> > > > On Sat, Nov 29, 2025 at 02:53:01PM -0500, Yury Norov (NVIDIA) wrote:
> > > > > The macro is related to sysfs, but is defined in kernel.h. Move it to
> > > > > the proper header, and unload the generic kernel.h.
> > > > 
> > > > Tough guy :-)
> > > > I hope it builds well in your case.
> > > > 
> > > > FWIW,
> > > > https://lore.kernel.org/lkml/20220603172101.49950-1-andriy.shevchenko@linux.intel.com/
> > > > https://lore.kernel.org/lkml/20240212115500.2078463-1-max.kellermann@ionos.com/
> > > > https://lore.kernel.org/lkml/20240215093646.3265823-1-max.kellermann@ionos.com/
> > > > 
> > > > Assuming it builds in allmodconfig, allyesconfig on x86_32/64 and arm/64
> > > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > 
> > > Actually, one thing should be fixed, i.e.
> > > Documentation/filesystems/sysfs.rst:123:Note as stated in include/linux/kernel.h "OTHER_WRITABLE? ...
> > 
> > And just in case, look into
> > https://lore.kernel.org/r/20251126214709.2322314-1-andriy.shevchenko@linux.intel.com
> 
> Sure. Please find attached.

Just fold this into your patch.

Thanks!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* Re: [PATCH v8 26/28] KVM: arm64: Add hyp_enter/hyp_exit events to pKVM hyp
From: Marc Zyngier @ 2025-11-30 19:00 UTC (permalink / raw)
  To: Vincent Donnefort
  Cc: rostedt, mhiramat, mathieu.desnoyers, linux-trace-kernel,
	oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, kvmarm,
	linux-arm-kernel, jstultz, qperret, will, aneesh.kumar,
	kernel-team, linux-kernel
In-Reply-To: <20251107093840.3779150-27-vdonnefort@google.com>

On Fri, 07 Nov 2025 09:38:38 +0000,
Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> The hyp_enter and hyp_exit events are logged by the hypervisor any time
> it is entered and exited.
> 
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> 
> diff --git a/arch/arm64/include/asm/kvm_hypevents.h b/arch/arm64/include/asm/kvm_hypevents.h
> index d6e033c96c52..ce3953bc884a 100644
> --- a/arch/arm64/include/asm/kvm_hypevents.h
> +++ b/arch/arm64/include/asm/kvm_hypevents.h
> @@ -7,4 +7,21 @@
>  #include <nvhe/trace.h>
>  #endif
>  
> +HYP_EVENT(hyp_enter,
> +	HE_PROTO(void),
> +	HE_STRUCT(
> +	),
> +	HE_ASSIGN(
> +	),
> +	HE_PRINTK()
> +);
> +
> +HYP_EVENT(hyp_exit,
> +	HE_PROTO(void),
> +	HE_STRUCT(
> +	),
> +	HE_ASSIGN(
> +	),
> +	HE_PRINTK()
> +);
>  #endif
> diff --git a/arch/arm64/kvm/hyp/include/nvhe/arm-smccc.h b/arch/arm64/kvm/hyp/include/nvhe/arm-smccc.h
> new file mode 100644
> index 000000000000..4b69d33e4f2d
> --- /dev/null
> +++ b/arch/arm64/kvm/hyp/include/nvhe/arm-smccc.h
> @@ -0,0 +1,13 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#include <asm/kvm_hypevents.h>
> +
> +#include <linux/arm-smccc.h>
> +
> +#undef arm_smccc_1_1_smc
> +#define arm_smccc_1_1_smc(...)					\
> +	do {							\
> +		trace_hyp_exit();				\
> +		__arm_smccc_1_1(SMCCC_SMC_INST, __VA_ARGS__);	\
> +		trace_hyp_enter();				\
> +	} while (0)

Huh. No, please. Don't override existing kernel constructs behind
everybody's back. I know that tracing folks love to play that sort of
game, but I really don't want any of that here.

Just define a wrapper that is KVM-specific, and use that.

Then from a semantic perspective, an SMC call, an ERET back to EL1
host, and an ERET back to EL1 guest are all very different events that
you lump under the "exit" category. That's not right. Same thing for
"enter".

Thanks,

	M.

-- 
Jazz isn't dead. It just smells funny.

^ permalink raw reply

* Re: [PATCH v8 25/28] KVM: arm64: Add event support to the pKVM hyp and trace remote
From: Marc Zyngier @ 2025-11-30 18:54 UTC (permalink / raw)
  To: Vincent Donnefort
  Cc: rostedt, mhiramat, mathieu.desnoyers, linux-trace-kernel,
	oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, kvmarm,
	linux-arm-kernel, jstultz, qperret, will, aneesh.kumar,
	kernel-team, linux-kernel
In-Reply-To: <20251107093840.3779150-26-vdonnefort@google.com>

On Fri, 07 Nov 2025 09:38:37 +0000,
Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> Allow the creation of hypervisor and trace remote events with a single
> macro HYP_EVENT(). That macro expands in the kernel side to add all
> the required declarations (based on REMOTE_EVENT()) as well as in the
> hypervisor side to create the trace_<event>() function.
> 
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> 
> diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
> index 4faabf398881..f7b29eae7010 100644
> --- a/arch/arm64/include/asm/kvm_asm.h
> +++ b/arch/arm64/include/asm/kvm_asm.h
> @@ -95,6 +95,7 @@ enum __kvm_host_smccc_func {
>  	__KVM_HOST_SMCCC_FUNC___pkvm_enable_tracing,
>  	__KVM_HOST_SMCCC_FUNC___pkvm_reset_tracing,
>  	__KVM_HOST_SMCCC_FUNC___pkvm_swap_reader_tracing,
> +	__KVM_HOST_SMCCC_FUNC___pkvm_enable_event,

nit: add 'tracing' to the name of the function, like its little
friends. Saves us from wondering whether this is about PMU events or
not...

>  };
>  
>  #define DECLARE_KVM_VHE_SYM(sym)	extern char sym[]
> diff --git a/arch/arm64/include/asm/kvm_define_hypevents.h b/arch/arm64/include/asm/kvm_define_hypevents.h
> new file mode 100644
> index 000000000000..0ef5a9eefcbe
> --- /dev/null
> +++ b/arch/arm64/include/asm/kvm_define_hypevents.h
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef HYP_EVENT_FILE
> +# undef __ARM64_KVM_HYPEVENTS_H_
> +# define REMOTE_EVENT_INCLUDE_FILE arch/arm64/include/asm/kvm_hypevents.h
> +#else
> +# define REMOTE_EVENT_INCLUDE_FILE HYP_EVENT_FILE
> +#endif

I'm feeling a bit sick here. Can you please document here how the
whole repainting trickery works, how the event equivalence works, and
what the whole thing depends on? I *really* don't want to have to
reverse engineer this stuff when it will break.

> +
> +#define REMOTE_EVENT_SECTION "_hyp_events"
> +
> +#define HE_STRUCT(__args)		__args
> +#define HE_PRINTK(__args...)		__args
> +#define he_field			re_field
> +
> +#define HYP_EVENT(__name, __proto, __struct, __assign, __printk) \
> +	REMOTE_EVENT(__name, 0, RE_STRUCT(__struct), RE_PRINTK(__printk))
> +
> +#define HYP_EVENT_MULTI_READ
> +
> +#include <trace/define_remote_events.h>
> diff --git a/arch/arm64/include/asm/kvm_hypevents.h b/arch/arm64/include/asm/kvm_hypevents.h
> new file mode 100644
> index 000000000000..d6e033c96c52
> --- /dev/null
> +++ b/arch/arm64/include/asm/kvm_hypevents.h
> @@ -0,0 +1,10 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#if !defined(__ARM64_KVM_HYPEVENTS_H_) || defined(HYP_EVENT_MULTI_READ)
> +#define __ARM64_KVM_HYPEVENTS_H_
> +
> +#ifdef __KVM_NVHE_HYPERVISOR__
> +#include <nvhe/trace.h>
> +#endif
> +
> +#endif
> diff --git a/arch/arm64/include/asm/kvm_hyptrace.h b/arch/arm64/include/asm/kvm_hyptrace.h
> index 9c30a479bc36..d6e0953a07d6 100644
> --- a/arch/arm64/include/asm/kvm_hyptrace.h
> +++ b/arch/arm64/include/asm/kvm_hyptrace.h
> @@ -10,4 +10,17 @@ struct hyp_trace_desc {
>  	struct trace_buffer_desc	trace_buffer_desc;
>  
>  };
> +
> +struct hyp_event_id {
> +	unsigned short	id;
> +	void		*data;
> +};
> +
> +extern struct remote_event __hyp_events_start[];
> +extern struct remote_event __hyp_events_end[];
> +
> +/* hyp_event section used by the hypervisor */
> +extern struct hyp_event_id __hyp_event_ids_start[];
> +extern struct hyp_event_id __hyp_event_ids_end[];
> +
>  #endif
> diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
> index 5369763606e7..c0efa9aa541b 100644
> --- a/arch/arm64/kernel/image-vars.h
> +++ b/arch/arm64/kernel/image-vars.h
> @@ -137,6 +137,10 @@ KVM_NVHE_ALIAS(__hyp_data_start);
>  KVM_NVHE_ALIAS(__hyp_data_end);
>  KVM_NVHE_ALIAS(__hyp_rodata_start);
>  KVM_NVHE_ALIAS(__hyp_rodata_end);
> +#ifdef CONFIG_PKVM_TRACING
> +KVM_NVHE_ALIAS(__hyp_event_ids_start);
> +KVM_NVHE_ALIAS(__hyp_event_ids_end);
> +#endif
>  
>  /* pKVM static key */
>  KVM_NVHE_ALIAS(kvm_protected_mode_initialized);
> diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
> index ad6133b89e7a..0e201a3c8de5 100644
> --- a/arch/arm64/kernel/vmlinux.lds.S
> +++ b/arch/arm64/kernel/vmlinux.lds.S
> @@ -13,12 +13,23 @@
>  	*(__kvm_ex_table)					\
>  	__stop___kvm_ex_table = .;
>  
> +#ifdef CONFIG_PKVM_TRACING
> +#define HYPERVISOR_EVENT_IDS 					\
> +	. = ALIGN(PAGE_SIZE);					\
> +	__hyp_event_ids_start = .;				\
> +	*(HYP_SECTION_NAME(.event_ids))				\
> +	__hyp_event_ids_end = .;
> +#else
> +#define HYPERVISOR_EVENT_IDS
> +#endif
> +
>  #define HYPERVISOR_RODATA_SECTIONS				\
>  	HYP_SECTION_NAME(.rodata) : {				\
>  		. = ALIGN(PAGE_SIZE);				\
>  		__hyp_rodata_start = .;				\
>  		*(HYP_SECTION_NAME(.data..ro_after_init))	\
>  		*(HYP_SECTION_NAME(.rodata))			\
> +		HYPERVISOR_EVENT_IDS				\
>  		. = ALIGN(PAGE_SIZE);				\
>  		__hyp_rodata_end = .;				\
>  	}
> @@ -307,6 +318,13 @@ SECTIONS
>  
>  	HYPERVISOR_DATA_SECTION
>  
> +#ifdef CONFIG_PKVM_TRACING
> +	.data.hyp_events : {
> +		__hyp_events_start = .;
> +		*(SORT(_hyp_events.*))
> +		__hyp_events_end = .;
> +	}
> +#endif
>  	/*
>  	 * Data written with the MMU off but read with the MMU on requires
>  	 * cache lines to be invalidated, discarding up to a Cache Writeback
> diff --git a/arch/arm64/kvm/hyp/include/nvhe/define_events.h b/arch/arm64/kvm/hyp/include/nvhe/define_events.h
> new file mode 100644
> index 000000000000..2298b49cb355
> --- /dev/null
> +++ b/arch/arm64/kvm/hyp/include/nvhe/define_events.h
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef HYP_EVENT_FILE
> +# define __HYP_EVENT_FILE <asm/kvm_hypevents.h>
> +#else
> +# define __HYP_EVENT_FILE __stringify(HYP_EVENT_FILE)
> +#endif
> +
> +#undef HYP_EVENT
> +#define HYP_EVENT(__name, __proto, __struct, __assign, __printk)	\
> +	atomic_t __ro_after_init __name##_enabled = ATOMIC_INIT(0);	\
> +	struct hyp_event_id hyp_event_id_##__name			\
> +	__section(".hyp.event_ids."#__name) = {				\
> +		.data = (void *)&__name##_enabled,			\
> +	}
> +
> +#define HYP_EVENT_MULTI_READ
> +#include __HYP_EVENT_FILE
> +#undef HYP_EVENT_MULTI_READ
> +
> +#undef HYP_EVENT
> diff --git a/arch/arm64/kvm/hyp/include/nvhe/trace.h b/arch/arm64/kvm/hyp/include/nvhe/trace.h
> index 0d2732f0d406..f7b286e92853 100644
> --- a/arch/arm64/kvm/hyp/include/nvhe/trace.h
> +++ b/arch/arm64/kvm/hyp/include/nvhe/trace.h
> @@ -1,21 +1,52 @@
>  /* SPDX-License-Identifier: GPL-2.0-only */
>  #ifndef __ARM64_KVM_HYP_NVHE_TRACE_H
>  #define __ARM64_KVM_HYP_NVHE_TRACE_H
> +
> +#include <linux/trace_remote_event.h>
> +
>  #include <asm/kvm_hyptrace.h>
>  
> +#define HE_PROTO(__args...)	__args
> +
>  #ifdef CONFIG_PKVM_TRACING
>  void *tracing_reserve_entry(unsigned long length);
>  void tracing_commit_entry(void);
>  
> +#define HE_ASSIGN(__args...)	__args
> +#define HE_STRUCT		RE_STRUCT
> +#define he_field		re_field
> +
> +#define HYP_EVENT(__name, __proto, __struct, __assign, __printk)		\
> +	REMOTE_EVENT_FORMAT(__name, __struct);					\
> +	extern atomic_t __name##_enabled;					\
> +	extern struct hyp_event_id hyp_event_id_##__name;			\
> +	static __always_inline void trace_##__name(__proto)			\
> +	{									\
> +		struct remote_event_format_##__name *__entry;			\
> +		size_t length = sizeof(*__entry);				\
> +										\
> +		if (!atomic_read(&__name##_enabled))				\
> +			return;							\
> +		__entry = tracing_reserve_entry(length);			\
> +		if (!__entry)							\
> +			return;							\
> +		__entry->hdr.id = hyp_event_id_##__name.id;			\
> +		__assign							\
> +		tracing_commit_entry();						\
> +	}
> +
>  void __pkvm_update_clock_tracing(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc);
>  int __pkvm_load_tracing(unsigned long desc_va, size_t desc_size);
>  void __pkvm_unload_tracing(void);
>  int __pkvm_enable_tracing(bool enable);
>  int __pkvm_reset_tracing(unsigned int cpu);
>  int __pkvm_swap_reader_tracing(unsigned int cpu);
> +int __pkvm_enable_event(unsigned short id, bool enable);
>  #else
>  static inline void *tracing_reserve_entry(unsigned long length) { return NULL; }
>  static inline void tracing_commit_entry(void) { }
> +#define HYP_EVENT(__name, __proto, __struct, __assign, __printk)      \
> +	static inline void trace_##__name(__proto) {}
>  
>  static inline
>  void __pkvm_update_clock_tracing(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc) { }
> @@ -24,5 +55,6 @@ static inline void __pkvm_unload_tracing(void) { }
>  static inline int __pkvm_enable_tracing(bool enable) { return -ENODEV; }
>  static inline int __pkvm_reset_tracing(unsigned int cpu) { return -ENODEV; }
>  static inline int __pkvm_swap_reader_tracing(unsigned int cpu) { return -ENODEV; }
> +static inline int __pkvm_enable_event(unsigned short id, bool enable)  { return -ENODEV; }
>  #endif
>  #endif
> diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
> index 504c3b9caef8..b77959e963f3 100644
> --- a/arch/arm64/kvm/hyp/nvhe/Makefile
> +++ b/arch/arm64/kvm/hyp/nvhe/Makefile
> @@ -29,7 +29,7 @@ hyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
>  	 ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o
>  hyp-obj-y += ../../../kernel/smccc-call.o
>  hyp-obj-$(CONFIG_LIST_HARDENED) += list_debug.o
> -hyp-obj-$(CONFIG_PKVM_TRACING) += clock.o trace.o ../../../../../kernel/trace/simple_ring_buffer.o
> +hyp-obj-$(CONFIG_PKVM_TRACING) += clock.o trace.o ../../../../../kernel/trace/simple_ring_buffer.o events.o
>  hyp-obj-y += $(lib-objs)
>  
>  ##
> diff --git a/arch/arm64/kvm/hyp/nvhe/events.c b/arch/arm64/kvm/hyp/nvhe/events.c
> new file mode 100644
> index 000000000000..5905b42cb0d0
> --- /dev/null
> +++ b/arch/arm64/kvm/hyp/nvhe/events.c
> @@ -0,0 +1,36 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2025 Google LLC
> + * Author: Vincent Donnefort <vdonnefort@google.com>
> + */
> +
> +#include <nvhe/mm.h>
> +#include <nvhe/trace.h>
> +
> +#include <nvhe/define_events.h>
> +
> +extern struct hyp_event_id __hyp_event_ids_start[];
> +extern struct hyp_event_id __hyp_event_ids_end[];

Isn't that already declared in an include file?

> +
> +int __pkvm_enable_event(unsigned short id, bool enable)
> +{
> +	struct hyp_event_id *event_id = __hyp_event_ids_start;
> +	atomic_t *enable_key;
> +
> +	for (; (unsigned long)event_id < (unsigned long)__hyp_event_ids_end;
> +	     event_id++) {
> +		if (event_id->id != id)
> +			continue;
> +
> +		enable_key = (atomic_t *)event_id->data;
> +		enable_key = hyp_fixmap_map(__hyp_pa(enable_key));
> +
> +		atomic_set(enable_key, enable);
> +
> +		hyp_fixmap_unmap();
> +
> +		return 0;
> +	}
> +
> +	return -EINVAL;
> +}
> diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> index 8adad701fc76..5e4b519e5204 100644
> --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> @@ -634,6 +634,14 @@ static void handle___pkvm_swap_reader_tracing(struct kvm_cpu_context *host_ctxt)
>  	cpu_reg(host_ctxt, 1) = __pkvm_swap_reader_tracing(cpu);
>  }
>  
> +static void handle___pkvm_enable_event(struct kvm_cpu_context *host_ctxt)
> +{
> +	DECLARE_REG(unsigned short, id, host_ctxt, 1);
> +	DECLARE_REG(bool, enable, host_ctxt, 2);
> +
> +	cpu_reg(host_ctxt, 1) = __pkvm_enable_event(id, enable);
> +}
> +
>  typedef void (*hcall_t)(struct kvm_cpu_context *);
>  
>  #define HANDLE_FUNC(x)	[__KVM_HOST_SMCCC_FUNC_##x] = (hcall_t)handle_##x
> @@ -681,6 +689,7 @@ static const hcall_t host_hcall[] = {
>  	HANDLE_FUNC(__pkvm_enable_tracing),
>  	HANDLE_FUNC(__pkvm_reset_tracing),
>  	HANDLE_FUNC(__pkvm_swap_reader_tracing),
> +	HANDLE_FUNC(__pkvm_enable_event),
>  };
>  
>  static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
> diff --git a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S
> index d724f6d69302..a68411bf4bef 100644
> --- a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S
> +++ b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S
> @@ -16,6 +16,12 @@ SECTIONS {
>  	HYP_SECTION(.text)
>  	HYP_SECTION(.data..ro_after_init)
>  	HYP_SECTION(.rodata)
> +#ifdef CONFIG_PKVM_TRACING
> +	. = ALIGN(PAGE_SIZE);
> +	BEGIN_HYP_SECTION(.event_ids)
> +		*(SORT(.hyp.event_ids.*))
> +	END_HYP_SECTION
> +#endif
>  
>  	/*
>  	 * .hyp..data..percpu needs to be page aligned to maintain the same
> diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c
> index 1062b4310f8c..73539f5b5e42 100644
> --- a/arch/arm64/kvm/hyp_trace.c
> +++ b/arch/arm64/kvm/hyp_trace.c
> @@ -307,7 +307,7 @@ static int hyp_trace_reset(unsigned int cpu, void *priv)
>  
>  static int hyp_trace_enable_event(unsigned short id, bool enable, void *priv)
>  {
> -	return 0;
> +	return kvm_call_hyp_nvhe(__pkvm_enable_event, id, enable);
>  }
>  
>  static int hyp_trace_clock_show(struct seq_file *m, void *v)
> @@ -334,10 +334,27 @@ static struct trace_remote_callbacks trace_remote_callbacks = {
>  	.enable_event		= hyp_trace_enable_event,
>  };
>  
> +#include <asm/kvm_define_hypevents.h>
> +
> +static void hyp_trace_init_events(void)
> +{
> +	struct hyp_event_id *hyp_event_id = __hyp_event_ids_start;
> +	struct remote_event *event = __hyp_events_start;
> +	int id = 0;
> +
> +	/* Events on both sides hypervisor are sorted */
> +	for (; (unsigned long)event < (unsigned long)__hyp_events_end;

It feels very bizarre that you have to cast anything here. Aren't the
two variables of the same type, part of the same array, and shouldn't
pointer arithmetic apply?

> +		event++, hyp_event_id++, id++)
> +		event->id = hyp_event_id->id = id;
> +}
> +
>  int hyp_trace_init(void)
>  {
>  	if (!is_protected_kvm_enabled())
>  		return 0;
>  
> -	return trace_remote_register("hypervisor", &trace_remote_callbacks, &trace_buffer, NULL, 0);
> +	hyp_trace_init_events();
> +
> +	return trace_remote_register("hypervisor", &trace_remote_callbacks, &trace_buffer,
> +				     __hyp_events_start, __hyp_events_end - __hyp_events_start);
>  }
> diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c
> index 4f2b67d1bfec..e54cc3e75dc5 100644
> --- a/kernel/trace/trace_remote.c
> +++ b/kernel/trace/trace_remote.c
> @@ -1040,7 +1040,7 @@ static int remote_event_format_show(struct seq_file *s, void *unused)
>  	while (field->name) {
>  		seq_printf(s, "\tfield:%s %s;\toffset:%zu;\tsize:%u;\tsigned:%d;\n",
>  			   field->type, field->name, offset, field->size,
> -			   !field->is_signed);
> +			   field->is_signed);
>  		offset += field->size;
>  		field++;
>  	}
> @@ -1071,7 +1071,7 @@ static int remote_event_callback(const char *name, umode_t *mode, void **data,
>  
>  	if (!strcmp(name, "format")) {
>  		*mode = TRACEFS_MODE_READ;
> -		*fops = &remote_event_id_fops;
> +		*fops = &remote_event_format_fops;
>  		return 1;
>  	}
>  

Thanks,

	M.

-- 
Jazz isn't dead. It just smells funny.

^ permalink raw reply

* Re: [PATCH v8 24/28] KVM: arm64: Add trace reset to the pKVM hyp
From: Marc Zyngier @ 2025-11-30 18:33 UTC (permalink / raw)
  To: Vincent Donnefort
  Cc: rostedt, mhiramat, mathieu.desnoyers, linux-trace-kernel,
	oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, kvmarm,
	linux-arm-kernel, jstultz, qperret, will, aneesh.kumar,
	kernel-team, linux-kernel
In-Reply-To: <20251107093840.3779150-25-vdonnefort@google.com>

On Fri, 07 Nov 2025 09:38:36 +0000,
Vincent Donnefort <vdonnefort@google.com> wrote:
> 

[...]

> +int __pkvm_reset_tracing(unsigned int cpu)
> +{
> +	int ret = 0;
> +
> +	if (cpu >= hyp_nr_cpus)
> +		return -EINVAL;
> +
> +	hyp_spin_lock(&trace_buffer.lock);
> +
> +	if (hyp_trace_buffer_loaded(&trace_buffer))
> +		ret = simple_ring_buffer_reset(per_cpu_ptr(trace_buffer.simple_rbs, cpu));
> +	else
> +		ret = -ENODEV;
> +
> +	hyp_spin_unlock(&trace_buffer.lock);
> +
> +	return ret;

nit; there is no case where the 'ret' default value can be used.
Either drop the init or make it so that the default value is
meaningful (-ENODEV).

Thanks,

	M.

-- 
Jazz isn't dead. It just smells funny.

^ permalink raw reply

* Re: [PATCH 2/3] kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h
From: Yury Norov @ 2025-11-30 18:27 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aStWkK6exUj9YEC1@smile.fi.intel.com>

On Sat, Nov 29, 2025 at 10:24:48PM +0200, Andy Shevchenko wrote:
> On Sat, Nov 29, 2025 at 02:53:01PM -0500, Yury Norov (NVIDIA) wrote:
> > The macro is related to sysfs, but is defined in kernel.h. Move it to
> > the proper header, and unload the generic kernel.h.
> 
> Tough guy :-)
> I hope it builds well in your case.
> 
> FWIW,
> https://lore.kernel.org/lkml/20220603172101.49950-1-andriy.shevchenko@linux.intel.com/
> https://lore.kernel.org/lkml/20240212115500.2078463-1-max.kellermann@ionos.com/
> https://lore.kernel.org/lkml/20240215093646.3265823-1-max.kellermann@ionos.com/

Oh, OK. Surely I didn't want to undercut your or Max's work. Do you
know why it wasn't merged in 2022 and 2024?
 
> Assuming it builds in allmodconfig, allyesconfig on x86_32/64 and arm/64
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

It seemingly builds well. Thanks for review.

^ permalink raw reply

* Re: [PATCH v8 21/28] KVM: arm64: Add tracing capability for the pKVM hyp
From: Marc Zyngier @ 2025-11-30 18:23 UTC (permalink / raw)
  To: Vincent Donnefort
  Cc: rostedt, mhiramat, mathieu.desnoyers, linux-trace-kernel,
	oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, kvmarm,
	linux-arm-kernel, jstultz, qperret, will, aneesh.kumar,
	kernel-team, linux-kernel
In-Reply-To: <aR8DM6Xf8cmTGVR0@google.com>

On Thu, 20 Nov 2025 12:01:55 +0000,
Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> On Wed, Nov 19, 2025 at 05:06:38PM +0000, Marc Zyngier wrote:
> > On Fri, 07 Nov 2025 09:38:33 +0000,
> > Vincent Donnefort <vdonnefort@google.com> wrote:
> > > 
> > > When running with protected mode, the host has very little knowledge
> > > about what is happening in the hypervisor. Of course this is an
> > > essential feature for security but nonetheless, that piece of code
> > > growing with more responsibilities, we need now a way to debug and
> > > profile it. Tracefs by its reliability, versatility and support for
> > > user-space is the perfect tool.
> > > 
> > > There's no way the hypervisor could log events directly into the host
> > > tracefs ring-buffers. So instead let's use our own, where the hypervisor
> > > is the writer and the host the reader.
> > > 
> > > Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> > > 
> > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
> > > index 9da54d4ee49e..ad02dee140d3 100644
> > > --- a/arch/arm64/include/asm/kvm_asm.h
> > > +++ b/arch/arm64/include/asm/kvm_asm.h
> > > @@ -89,6 +89,10 @@ enum __kvm_host_smccc_func {
> > >  	__KVM_HOST_SMCCC_FUNC___pkvm_vcpu_load,
> > >  	__KVM_HOST_SMCCC_FUNC___pkvm_vcpu_put,
> > >  	__KVM_HOST_SMCCC_FUNC___pkvm_tlb_flush_vmid,
> > > +	__KVM_HOST_SMCCC_FUNC___pkvm_load_tracing,
> > > +	__KVM_HOST_SMCCC_FUNC___pkvm_unload_tracing,
> > > +	__KVM_HOST_SMCCC_FUNC___pkvm_enable_tracing,
> > > +	__KVM_HOST_SMCCC_FUNC___pkvm_swap_reader_tracing,
> > >  };
> > >  
> > >  #define DECLARE_KVM_VHE_SYM(sym)	extern char sym[]
> > > diff --git a/arch/arm64/include/asm/kvm_hyptrace.h b/arch/arm64/include/asm/kvm_hyptrace.h
> > > new file mode 100644
> > > index 000000000000..9c30a479bc36
> > > --- /dev/null
> > > +++ b/arch/arm64/include/asm/kvm_hyptrace.h
> > > @@ -0,0 +1,13 @@
> > > +/* SPDX-License-Identifier: GPL-2.0-only */
> > > +#ifndef __ARM64_KVM_HYPTRACE_H_
> > > +#define __ARM64_KVM_HYPTRACE_H_
> > > +
> > > +#include <linux/ring_buffer.h>
> > > +
> > > +struct hyp_trace_desc {
> > > +	unsigned long			bpages_backing_start;
> > 
> > Why is this an integer type? You keep casting it all over the place,
> > which tells me that's not the ideal type.
> 
> That's because it is a kern VA the hyp needs to convert. However it would indeed
> make my life easier to declare it as a struct simple_buffer_page * in the
> struct hyp_trace_buffer below.
> 
> > 
> > > +	size_t				bpages_backing_size;
> > > +	struct trace_buffer_desc	trace_buffer_desc;
> > > +
> > > +};
> > > +#endif
> > > diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig
> > > index 4f803fd1c99a..580426cdbe77 100644
> > > --- a/arch/arm64/kvm/Kconfig
> > > +++ b/arch/arm64/kvm/Kconfig
> > > @@ -83,4 +83,11 @@ config PTDUMP_STAGE2_DEBUGFS
> > >  
> > >  	  If in doubt, say N.
> > >  
> > > +config PKVM_TRACING
> > > +	bool
> > > +	depends on KVM
> > > +	depends on TRACING
> > > +	select SIMPLE_RING_BUFFER
> > > +	default y
> > 
> > I'd rather this is made to depend on NVHE_EL2_DEBUG, just like the
> > other debug options.
> 
> NVHE_EL2_DEBUG is unsafe for production because of the stage-2 relax on panic.
> While this one is. So ideally this should be usable even without NVHE_EL2_DEBUG.

I don't see what makes tracing safer, as it potentially exposes
information (timing, control flow) that the host use to infer what is
happening at EL2. Which is, after all, the whole point of tracing.

I really think this should be guarded by NVHE_EL2_DEBUG, and the
stage-2 relaxation tied to the stacktrace infrastructure, so that you
can select both independently.

> I can remove this hidden PKVM_TRACING option and use everywhere
> CONFIG_TRACING. But then I need something to select
> SIMPLE_RING_BUFFER.
> 
> Perhaps with the following?
> 
> diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig
> index 2ae6bf499236..c561bf9d4754 100644
> --- a/arch/arm64/kvm/Kconfig
> +++ b/arch/arm64/kvm/Kconfig
> @@ -38,6 +38,7 @@ menuconfig KVM
>         select SCHED_INFO
>         select GUEST_PERF_EVENTS if PERF_EVENTS
>         select KVM_GUEST_MEMFD
> +       select SIMPLE_RING_BUFFER if CONFIG_TRACING

That's better, but my ask about making this depending on DEBUG still
stand.

Thanks,

	M.

-- 
Jazz isn't dead. It just smells funny.

^ permalink raw reply

* Re: [PATCH 3/3] tracing: move tracing declarations from kernel.h to a dedicated header
From: Yury Norov @ 2025-11-30 18:16 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aStX3242e3mo5H05@smile.fi.intel.com>

On Sat, Nov 29, 2025 at 10:30:23PM +0200, Andy Shevchenko wrote:
> On Sat, Nov 29, 2025 at 02:53:02PM -0500, Yury Norov (NVIDIA) wrote:
> > Tracing is a half of the kernel.h in terms of LOCs, although it's a
> > self-consistent part. Move it to a separate header.
> > 
> > This is a pure move, except for removing a few 'extern's.
> 
> Yeah, I also have something similar (but half-baked) locally, the Q I wanted to
> ask is why a separate header? We have already some of tracing headers. Doesn't
> suit well?

Just as said in the commit message - this part is more or less
self-consistent and debugging-oriented. If someone needs to just
throw trace_printk() in their driver, they will not have to pull
all the heavy tracing machinery.

> ...
> 
> > --- a/include/linux/kernel.h
> > +++ b/include/linux/kernel.h
> > @@ -27,6 +27,7 @@
> >  #include <linux/math.h>
> >  #include <linux/minmax.h>
> >  #include <linux/typecheck.h>
> 
> > +#include <linux/tracing.h>
> 
> There is better place for t*.h, i.e. after static_call_types.h.

They are poorly sorted for seemingly no good reason. I found the first
t*.h and just put this header next to it. Don't think that placing it
next to static_call_types.h is any better or worse.
 
> Btw, have you tried to sort alphabetically the bulk in the kernel.h after
> your series. Does it still build? (Just wondering about state of affairs
> with the possible cyclic dependencies.)

I didn't try. Sorting #include's is not the purpose of the series.

Thanks,
Yury

^ permalink raw reply

* Re: [PATCH v8 20/28] KVM: arm64: Add clock support for the pKVM hyp
From: Marc Zyngier @ 2025-11-30 18:15 UTC (permalink / raw)
  To: Vincent Donnefort
  Cc: g, rostedt, mhiramat, mathieu.desnoyers, linux-trace-kernel,
	oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, kvmarm,
	linux-arm-kernel, jstultz, qperret, will, aneesh.kumar,
	kernel-team, linux-kernel
In-Reply-To: <aR79MCNlAKP1H-PQ@google.com>

On Thu, 20 Nov 2025 11:36:16 +0000,
Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> [...]
> 
> > > +/* Using host provided data. Do not use for anything else than debugging. */
> > > +u64 trace_clock(void)
> > > +{
> > > +	struct clock_data *clock = &trace_clock_data;
> > > +	u64 bank = smp_load_acquire(&clock->cur);
> > > +	u64 cyc, ns;
> > > +
> > > +	cyc = __arch_counter_get_cntpct() - clock->data[bank].epoch_cyc;
> > 
> > I can only imagine that you don't care about the broken systems that
> > do not have a monotonic counter, and that will happily have their
> > counter swing back and forth?
> 
> I haven't used the _stable() variant for the affected devices... Hum this will
> not be trivial from the hypervisor. I'll see what I can do.

In all honestly, simply disabling tracing when you don't have a stable
counter should be enough. I don't think there is much to be gained
with supporting that on sub-standard HW (the bar is low enough).

> > Also, you may want to document why you are using the physical counter
> > instead of the virtual one. I guess that you don't want CNTVOFF_EL2 to
> > apply when HCR_EL2.E2H==0, but given that you never allow anything
> > else for pKVM, this is slightly odd.
> 
> You mean I might as well use __arch_counter_get_cntvct() as CNTVOFF_EL2 will
> always be ignored in the pKVM case?

That, plus the fact that CNTVOFF_EL2 is only evaluated at EL2 when
E2H=0 (and that case is going to disappear over time).

	M.

-- 
Jazz isn't dead. It just smells funny.

^ permalink raw reply

* Re: [PATCH 2/3] kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h
From: Yury Norov @ 2025-11-30 17:56 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aStZKktOEWliXWT1@smile.fi.intel.com>

On Sat, Nov 29, 2025 at 10:35:54PM +0200, Andy Shevchenko wrote:
> On Sat, Nov 29, 2025 at 10:34:02PM +0200, Andy Shevchenko wrote:
> > On Sat, Nov 29, 2025 at 10:24:55PM +0200, Andy Shevchenko wrote:
> > > On Sat, Nov 29, 2025 at 02:53:01PM -0500, Yury Norov (NVIDIA) wrote:
> > > > The macro is related to sysfs, but is defined in kernel.h. Move it to
> > > > the proper header, and unload the generic kernel.h.
> > > 
> > > Tough guy :-)
> > > I hope it builds well in your case.
> > > 
> > > FWIW,
> > > https://lore.kernel.org/lkml/20220603172101.49950-1-andriy.shevchenko@linux.intel.com/
> > > https://lore.kernel.org/lkml/20240212115500.2078463-1-max.kellermann@ionos.com/
> > > https://lore.kernel.org/lkml/20240215093646.3265823-1-max.kellermann@ionos.com/
> > > 
> > > Assuming it builds in allmodconfig, allyesconfig on x86_32/64 and arm/64
> > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > 
> > Actually, one thing should be fixed, i.e.
> > Documentation/filesystems/sysfs.rst:123:Note as stated in include/linux/kernel.h "OTHER_WRITABLE? ...
> 
> And just in case, look into
> https://lore.kernel.org/r/20251126214709.2322314-1-andriy.shevchenko@linux.intel.com

Sure. Please find attached.

From 8b08bfd1d4b885bffb67c548d17d98760ca06e76 Mon Sep 17 00:00:00 2001
From: "Yury Norov (NVIDIA)" <yury.norov@gmail.com>
Date: Sun, 30 Nov 2025 12:50:11 -0500
Subject: [PATCH] sysfs: Align update documentation

This series moves VERIFY_OCTAL_PERMISSIONS() from linux/kernel.h to
linux/sysfs.h. Update documentation accordingly

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 Documentation/filesystems/sysfs.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/filesystems/sysfs.rst b/Documentation/filesystems/sysfs.rst
index 2703c04af7d0..ffcef4d6bc8d 100644
--- a/Documentation/filesystems/sysfs.rst
+++ b/Documentation/filesystems/sysfs.rst
@@ -120,7 +120,7 @@ is equivalent to doing::
 	    .store = store_foo,
     };
 
-Note as stated in include/linux/kernel.h "OTHER_WRITABLE?  Generally
+Note as stated in include/linux/sysfs.h "OTHER_WRITABLE?  Generally
 considered a bad idea." so trying to set a sysfs file writable for
 everyone will fail reverting to RO mode for "Others".
 
-- 
2.43.0



^ permalink raw reply related

* Re: [PATCH 2/3] kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h
From: Yury Norov @ 2025-11-30 17:42 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Andy Shevchenko, Steven Rostedt, Masami Hiramatsu,
	Mathieu Desnoyers, Ingo Molnar, Jani Nikula, Joonas Lahtinen,
	Rodrigo Vivi, Tvrtko Ursulin, Petr Pavlu, Daniel Gomez,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Andrew Morton, linux-kernel, intel-gfx, dri-devel, linux-modules,
	linux-trace-kernel
In-Reply-To: <e0d34a20-7547-4788-8449-95fcd5588434@infradead.org>

On Sat, Nov 29, 2025 at 10:19:29PM -0800, Randy Dunlap wrote:
> 
> 
> On 11/29/25 12:24 PM, Andy Shevchenko wrote:
> > On Sat, Nov 29, 2025 at 02:53:01PM -0500, Yury Norov (NVIDIA) wrote:
> >> The macro is related to sysfs, but is defined in kernel.h. Move it to
> >> the proper header, and unload the generic kernel.h.
> > 
> > Tough guy :-)
> > I hope it builds well in your case.
> > 
> > FWIW,
> > https://lore.kernel.org/lkml/20220603172101.49950-1-andriy.shevchenko@linux.intel.com/
> > https://lore.kernel.org/lkml/20240212115500.2078463-1-max.kellermann@ionos.com/
> > https://lore.kernel.org/lkml/20240215093646.3265823-1-max.kellermann@ionos.com/
> > 
> > Assuming it builds in allmodconfig, allyesconfig on x86_32/64 and arm/64
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> I don't build allyesconfigs any more (final? linking takes too long).
> It builds successfully for arm64 allmodconfig, arm allmodconfig,
> i386 allmodconfig, and x86_64 allmodconfig.
> 
> And the source files that use VERIFY_OCTAL_PERMISSIONS() all build successfully
> (which means that they possibly include <linux/sysfs.h> indirectly, i.e.,
> by luck). There aren't many of them, so I checked:
> 
> arch/arc/kernel/perf_event.c:	arc_pmu->attr[j].attr.attr.mode = VERIFY_OCTAL_PERMISSIONS(0444);
> INDIRECT
> drivers/edac/thunderx_edac.c:	.mode = VERIFY_OCTAL_PERMISSIONS(_mode),		    \
> INDIRECT
> drivers/media/platform/amphion/vpu_dbg.c:		    VERIFY_OCTAL_PERMISSIONS(0644),
> INDIRECT
> drivers/soc/aspeed/aspeed-uart-routing.c:	 .mode = VERIFY_OCTAL_PERMISSIONS(0644) },	\
> INDIRECT
> fs/xfs/xfs_error.c:		 .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) },	\
> INDIRECT
> include/linux/moduleparam.h:	    VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
> INDIRECT
> 
> so all of them got lucky. :)
> 
> Acked-by: Randy Dunlap <rdunlap@infradead.org>
> Tested-by: Randy Dunlap <rdunlap@infradead.org>

Thanks, Randy.

This series was tested by 0-day and LKP. 0-day runs allyesconfig, as
far as I know. It only sends email in case of errors. LKP is OK, find
the report below.

All but XFS include it via linux/module.h -> linux/moduleparam.h path.
XFS has a linkage layer: xfs.h -> xfs_linux.h-> linux/module.h, so
it's pretty much the same.

I think, module.h inclusion path is OK for this macro and definitely
better than kernel.h. Notice, none of them, except for vgpu_dbg,
include kernel.h directly.

Thanks,
Yury

tree/branch: https://github.com/norov/linux stack_magic
branch HEAD: d8dffbf7bce40e2fbfe077f9c9f4a3471786666f  tracing: move tracing declarations from kernel.h to a dedicated header

elapsed time: 1669m

configs tested: 103
configs skipped: 2

The following configs have been built successfully.
More configs may be tested in the coming days.

tested configs:
alpha                   allnoconfig    gcc-15.1.0
alpha                     defconfig    gcc-15.1.0
arc                     allnoconfig    gcc-15.1.0
arc                       defconfig    gcc-15.1.0
arc         randconfig-001-20251128    gcc-8.5.0
arc         randconfig-002-20251128    gcc-15.1.0
arm                     allnoconfig    clang-22
arm           am200epdkit_defconfig    gcc-15.1.0
arm             aspeed_g5_defconfig    gcc-15.1.0
arm         randconfig-001-20251128    gcc-14.3.0
arm         randconfig-002-20251128    gcc-8.5.0
arm         randconfig-003-20251128    clang-22
arm         randconfig-004-20251128    clang-17
arm               s3c6400_defconfig    gcc-15.1.0
arm                 u8500_defconfig    gcc-15.1.0
arm64                   allnoconfig    gcc-15.1.0
arm64       randconfig-001-20251129    clang-22
arm64       randconfig-002-20251129    clang-22
arm64       randconfig-003-20251129    gcc-8.5.0
arm64       randconfig-004-20251129    clang-22
csky                    allnoconfig    gcc-15.1.0
csky        randconfig-001-20251129    gcc-15.1.0
csky        randconfig-002-20251129    gcc-15.1.0
hexagon                 allnoconfig    clang-22
hexagon     randconfig-001-20251129    clang-22
hexagon     randconfig-002-20251129    clang-22
i386                    allnoconfig    gcc-14
i386        randconfig-001-20251129    gcc-14
i386        randconfig-002-20251129    gcc-12
i386        randconfig-003-20251129    clang-20
i386        randconfig-004-20251129    gcc-14
i386        randconfig-005-20251129    clang-20
i386        randconfig-006-20251129    clang-20
i386        randconfig-007-20251129    gcc-14
i386        randconfig-011-20251129    clang-20
i386        randconfig-012-20251129    gcc-13
i386        randconfig-013-20251129    clang-20
i386        randconfig-014-20251129    clang-20
i386        randconfig-015-20251129    gcc-14
loongarch               allnoconfig    clang-22
loongarch                 defconfig    clang-19
loongarch   randconfig-001-20251129    gcc-15.1.0
loongarch   randconfig-002-20251129    gcc-14.3.0
m68k                    allnoconfig    gcc-15.1.0
m68k                      defconfig    gcc-15.1.0
microblaze              allnoconfig    gcc-15.1.0
microblaze                defconfig    gcc-15.1.0
mips                    allnoconfig    gcc-15.1.0
nios2                   allnoconfig    gcc-11.5.0
nios2                     defconfig    gcc-11.5.0
nios2       randconfig-001-20251129    gcc-11.5.0
nios2       randconfig-002-20251129    gcc-11.5.0
openrisc                allnoconfig    gcc-15.1.0
openrisc                  defconfig    gcc-15.1.0
parisc                  allnoconfig    gcc-15.1.0
parisc                    defconfig    gcc-15.1.0
parisc      generic-64bit_defconfig    gcc-15.1.0
parisc      randconfig-001-20251128    gcc-14.3.0
parisc      randconfig-002-20251128    gcc-15.1.0
parisc64                  defconfig    gcc-15.1.0
powerpc                 allnoconfig    gcc-15.1.0
powerpc            pcm030_defconfig    clang-22
powerpc     randconfig-001-20251128    gcc-11.5.0
powerpc     randconfig-002-20251128    clang-22
powerpc64   randconfig-001-20251128    clang-22
powerpc64   randconfig-002-20251128    gcc-8.5.0
riscv                   allnoconfig    gcc-15.1.0
riscv                     defconfig    clang-22
s390                    allnoconfig    clang-22
s390                      defconfig    clang-22
sh                      allnoconfig    gcc-15.1.0
sh                        defconfig    gcc-15.1.0
sparc                   allnoconfig    gcc-15.1.0
sparc                     defconfig    gcc-15.1.0
sparc       randconfig-001-20251129    gcc-8.5.0
sparc       randconfig-002-20251129    gcc-8.5.0
sparc64                   defconfig    clang-20
sparc64     randconfig-001-20251129    gcc-8.5.0
sparc64     randconfig-002-20251129    gcc-14.3.0
um                      allnoconfig    clang-22
um                        defconfig    clang-22
um                   i386_defconfig    gcc-14
um          randconfig-001-20251129    clang-22
um          randconfig-002-20251129    gcc-14
um                 x86_64_defconfig    clang-22
x86_64                  allnoconfig    clang-20
x86_64                    defconfig    gcc-14
x86_64      randconfig-011-20251129    gcc-14
x86_64      randconfig-012-20251129    gcc-14
x86_64      randconfig-013-20251129    gcc-14
x86_64      randconfig-014-20251129    clang-20
x86_64      randconfig-015-20251129    gcc-12
x86_64      randconfig-016-20251129    clang-20
x86_64      randconfig-071-20251129    gcc-14
x86_64      randconfig-072-20251129    clang-20
x86_64      randconfig-073-20251129    gcc-14
x86_64      randconfig-074-20251129    gcc-12
x86_64      randconfig-075-20251129    gcc-14
x86_64      randconfig-076-20251129    gcc-14
xtensa                  allnoconfig    gcc-15.1.0
xtensa      randconfig-001-20251129    gcc-10.5.0
xtensa      randconfig-002-20251129    gcc-14.3.0
xtensa          xip_kc705_defconfig    gcc-15.1.0

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

^ permalink raw reply

* Re: [PATCH 2/3] kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h
From: Randy Dunlap @ 2025-11-30  6:19 UTC (permalink / raw)
  To: Andy Shevchenko, Yury Norov (NVIDIA)
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Ingo Molnar,
	Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
	Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Andrew Morton, linux-kernel, intel-gfx,
	dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aStWkK6exUj9YEC1@smile.fi.intel.com>



On 11/29/25 12:24 PM, Andy Shevchenko wrote:
> On Sat, Nov 29, 2025 at 02:53:01PM -0500, Yury Norov (NVIDIA) wrote:
>> The macro is related to sysfs, but is defined in kernel.h. Move it to
>> the proper header, and unload the generic kernel.h.
> 
> Tough guy :-)
> I hope it builds well in your case.
> 
> FWIW,
> https://lore.kernel.org/lkml/20220603172101.49950-1-andriy.shevchenko@linux.intel.com/
> https://lore.kernel.org/lkml/20240212115500.2078463-1-max.kellermann@ionos.com/
> https://lore.kernel.org/lkml/20240215093646.3265823-1-max.kellermann@ionos.com/
> 
> Assuming it builds in allmodconfig, allyesconfig on x86_32/64 and arm/64
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

I don't build allyesconfigs any more (final? linking takes too long).
It builds successfully for arm64 allmodconfig, arm allmodconfig,
i386 allmodconfig, and x86_64 allmodconfig.

And the source files that use VERIFY_OCTAL_PERMISSIONS() all build successfully
(which means that they possibly include <linux/sysfs.h> indirectly, i.e.,
by luck). There aren't many of them, so I checked:

arch/arc/kernel/perf_event.c:	arc_pmu->attr[j].attr.attr.mode = VERIFY_OCTAL_PERMISSIONS(0444);
INDIRECT
drivers/edac/thunderx_edac.c:	.mode = VERIFY_OCTAL_PERMISSIONS(_mode),		    \
INDIRECT
drivers/media/platform/amphion/vpu_dbg.c:		    VERIFY_OCTAL_PERMISSIONS(0644),
INDIRECT
drivers/soc/aspeed/aspeed-uart-routing.c:	 .mode = VERIFY_OCTAL_PERMISSIONS(0644) },	\
INDIRECT
fs/xfs/xfs_error.c:		 .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) },	\
INDIRECT
include/linux/moduleparam.h:	    VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
INDIRECT

so all of them got lucky. :)

Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
-- 
~Randy

^ permalink raw reply

* Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
From: Randy Dunlap @ 2025-11-29 23:40 UTC (permalink / raw)
  To: Andy Shevchenko, Yury Norov (NVIDIA)
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Ingo Molnar,
	Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
	Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Andrew Morton, linux-kernel, intel-gfx,
	dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aStYXphpN84Nr8LZ@smile.fi.intel.com>



On 11/29/25 12:32 PM, Andy Shevchenko wrote:
> On Sat, Nov 29, 2025 at 02:53:00PM -0500, Yury Norov (NVIDIA) wrote:
>> The macro is only used by i915. Move it to a local header and drop from
>> the kernel.h.
> 
> Agree, if one wants to reinstate it, there should be better place for it
> (something related to kasan?).

or <linux/poison.h>

> FWIW,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Acked-by: Randy Dunlap <rdunlap@infradead.org>

-- 
~Randy

^ permalink raw reply

* Re: [PATCH 2/3] kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h
From: Andy Shevchenko @ 2025-11-29 20:35 UTC (permalink / raw)
  To: Yury Norov (NVIDIA)
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aStYs-LDKbJe6zvW@smile.fi.intel.com>

On Sat, Nov 29, 2025 at 10:34:02PM +0200, Andy Shevchenko wrote:
> On Sat, Nov 29, 2025 at 10:24:55PM +0200, Andy Shevchenko wrote:
> > On Sat, Nov 29, 2025 at 02:53:01PM -0500, Yury Norov (NVIDIA) wrote:
> > > The macro is related to sysfs, but is defined in kernel.h. Move it to
> > > the proper header, and unload the generic kernel.h.
> > 
> > Tough guy :-)
> > I hope it builds well in your case.
> > 
> > FWIW,
> > https://lore.kernel.org/lkml/20220603172101.49950-1-andriy.shevchenko@linux.intel.com/
> > https://lore.kernel.org/lkml/20240212115500.2078463-1-max.kellermann@ionos.com/
> > https://lore.kernel.org/lkml/20240215093646.3265823-1-max.kellermann@ionos.com/
> > 
> > Assuming it builds in allmodconfig, allyesconfig on x86_32/64 and arm/64
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Actually, one thing should be fixed, i.e.
> Documentation/filesystems/sysfs.rst:123:Note as stated in include/linux/kernel.h "OTHER_WRITABLE? ...

And just in case, look into
https://lore.kernel.org/r/20251126214709.2322314-1-andriy.shevchenko@linux.intel.com

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* Re: [PATCH 2/3] kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h
From: Andy Shevchenko @ 2025-11-29 20:33 UTC (permalink / raw)
  To: Yury Norov (NVIDIA)
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <aStWkK6exUj9YEC1@smile.fi.intel.com>

On Sat, Nov 29, 2025 at 10:24:55PM +0200, Andy Shevchenko wrote:
> On Sat, Nov 29, 2025 at 02:53:01PM -0500, Yury Norov (NVIDIA) wrote:
> > The macro is related to sysfs, but is defined in kernel.h. Move it to
> > the proper header, and unload the generic kernel.h.
> 
> Tough guy :-)
> I hope it builds well in your case.
> 
> FWIW,
> https://lore.kernel.org/lkml/20220603172101.49950-1-andriy.shevchenko@linux.intel.com/
> https://lore.kernel.org/lkml/20240212115500.2078463-1-max.kellermann@ionos.com/
> https://lore.kernel.org/lkml/20240215093646.3265823-1-max.kellermann@ionos.com/
> 
> Assuming it builds in allmodconfig, allyesconfig on x86_32/64 and arm/64
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Actually, one thing should be fixed, i.e.
Documentation/filesystems/sysfs.rst:123:Note as stated in include/linux/kernel.h "OTHER_WRITABLE? ...

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
From: Andy Shevchenko @ 2025-11-29 20:32 UTC (permalink / raw)
  To: Yury Norov (NVIDIA)
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <20251129195304.204082-2-yury.norov@gmail.com>

On Sat, Nov 29, 2025 at 02:53:00PM -0500, Yury Norov (NVIDIA) wrote:
> The macro is only used by i915. Move it to a local header and drop from
> the kernel.h.

Agree, if one wants to reinstate it, there should be better place for it
(something related to kasan?).

FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply

* Re: [PATCH 3/3] tracing: move tracing declarations from kernel.h to a dedicated header
From: Andy Shevchenko @ 2025-11-29 20:30 UTC (permalink / raw)
  To: Yury Norov (NVIDIA)
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Randy Dunlap,
	Ingo Molnar, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, Petr Pavlu, Daniel Gomez, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Andrew Morton, linux-kernel,
	intel-gfx, dri-devel, linux-modules, linux-trace-kernel
In-Reply-To: <20251129195304.204082-4-yury.norov@gmail.com>

On Sat, Nov 29, 2025 at 02:53:02PM -0500, Yury Norov (NVIDIA) wrote:
> Tracing is a half of the kernel.h in terms of LOCs, although it's a
> self-consistent part. Move it to a separate header.
> 
> This is a pure move, except for removing a few 'extern's.

Yeah, I also have something similar (but half-baked) locally, the Q I wanted to
ask is why a separate header? We have already some of tracing headers. Doesn't
suit well?

...

> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -27,6 +27,7 @@
>  #include <linux/math.h>
>  #include <linux/minmax.h>
>  #include <linux/typecheck.h>

> +#include <linux/tracing.h>

There is better place for t*.h, i.e. after static_call_types.h.

Btw, have you tried to sort alphabetically the bulk in the kernel.h after
your series. Does it still build? (Just wondering about state of affairs
with the possible cyclic dependencies.)

>  #include <linux/panic.h>
>  #include <linux/printk.h>
>  #include <linux/build_bug.h>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox