[PATCH 1/3] kernel.h: drop STACK_MAGIC macro

Yury Norov (NVIDIA) posted 3 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Yury Norov (NVIDIA) 2 months, 1 week ago
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
@@ -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;
 
-- 
2.43.0
Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Christophe Leroy (CS GROUP) 2 months, 1 week ago

Le 29/11/2025 à 20:53, Yury Norov (NVIDIA) a écrit :
> The macro is only used by i915. Move it to a local header and drop from
> the kernel.h.

At the begining of the git history we have:

$ git grep STACK_MAGIC 1da177e4c3f41
1da177e4c3f41:arch/h8300/kernel/traps.c:        if (STACK_MAGIC != 
*(unsigned long *)((unsigned long)current+PAGE_SIZE))
1da177e4c3f41:arch/m68k/mac/macints.c:          if (STACK_MAGIC != 
*(unsigned long *)current->kernel_stack_page)
1da177e4c3f41:include/linux/kernel.h:#define STACK_MAGIC        0xdeadbeef

Would be good to know the history of its usage over time.

I see:
- Removed from m68k by 3cd53b14e7c4 ("m68k/mac: Improve NMI handler")
- Removed from h8300 by 1c4b5ecb7ea1 ("remove the h8300 architecture")
- Started being used in i915 selftest by 250f8c8140ac ("drm/i915/gtt: 
Read-only pages for insert_entries on bdw+")

Christophe

> 
> 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
> @@ -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;
>   

Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Yury Norov 2 months, 1 week ago
On Mon, Dec 01, 2025 at 10:38:01AM +0100, Christophe Leroy (CS GROUP) wrote:
> 
> 
> Le 29/11/2025 à 20:53, Yury Norov (NVIDIA) a écrit :
> > The macro is only used by i915. Move it to a local header and drop from
> > the kernel.h.
> 
> At the begining of the git history we have:
> 
> $ git grep STACK_MAGIC 1da177e4c3f41
> 1da177e4c3f41:arch/h8300/kernel/traps.c:        if (STACK_MAGIC !=
> *(unsigned long *)((unsigned long)current+PAGE_SIZE))
> 1da177e4c3f41:arch/m68k/mac/macints.c:          if (STACK_MAGIC !=
> *(unsigned long *)current->kernel_stack_page)
> 1da177e4c3f41:include/linux/kernel.h:#define STACK_MAGIC        0xdeadbeef
> 
> Would be good to know the history of its usage over time.
> 
> I see:
> - Removed from m68k by 3cd53b14e7c4 ("m68k/mac: Improve NMI handler")
> - Removed from h8300 by 1c4b5ecb7ea1 ("remove the h8300 architecture")
> - Started being used in i915 selftest by 250f8c8140ac ("drm/i915/gtt:
> Read-only pages for insert_entries on bdw+")

STACK_MAGIC was added in 1994 in 1.0.2.  It was indeed used in a couple
of places in core subsystems back then to detect stack corruption. But
since that people invented better ways to guard stacks.

You can check commit 4914d770dec4 in this project:

https://archive.org/details/git-history-of-linux
Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Andy Shevchenko 2 months, 1 week ago
On Mon, Dec 01, 2025 at 09:50:31PM -0500, Yury Norov wrote:
> On Mon, Dec 01, 2025 at 10:38:01AM +0100, Christophe Leroy (CS GROUP) wrote:
> > Le 29/11/2025 à 20:53, Yury Norov (NVIDIA) a écrit :

...

> You can check commit 4914d770dec4 in this project:
> 
> https://archive.org/details/git-history-of-linux

Side note: we have history/history.git tree on kernel.org, and,
if anyone wants to check, it is handy.

Each of the history tree has its own pros and cons:
https://stackoverflow.com/a/51901211/2511795

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Jani Nikula 2 months, 1 week ago
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
Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Andi Shyti 2 months, 1 week ago
Hi Jani,

On Mon, Dec 01, 2025 at 09:46:47AM +0200, Jani Nikula wrote:
> 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.

Doing this cleanups is a bit out of the scope of this patch.
Given that the patch itself has quite a good consensus, let move
it forward and I can take care of the i915 cleanup once it gets
merged.

Andi
Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Yury Norov 2 months, 1 week ago
On Tue, Dec 02, 2025 at 09:58:19PM +0100, Andi Shyti wrote:
> Hi Jani,
> 
> On Mon, Dec 01, 2025 at 09:46:47AM +0200, Jani Nikula wrote:
> > 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.
> 
> Doing this cleanups is a bit out of the scope of this patch.
> Given that the patch itself has quite a good consensus, let move
> it forward and I can take care of the i915 cleanup once it gets
> merged.

I'm already testing it in my tree:

https://github.com/norov/linux/tree/sm1

If everything is fine, I'll submit v2 with this change, otherwise will
schedule it for future improvements.
Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Jani Nikula 2 months, 1 week ago
On Tue, 02 Dec 2025, Yury Norov <yury.norov@gmail.com> wrote:
> On Tue, Dec 02, 2025 at 09:58:19PM +0100, Andi Shyti wrote:
>> Hi Jani,
>> 
>> On Mon, Dec 01, 2025 at 09:46:47AM +0200, Jani Nikula wrote:
>> > 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.
>> 
>> Doing this cleanups is a bit out of the scope of this patch.
>> Given that the patch itself has quite a good consensus, let move
>> it forward and I can take care of the i915 cleanup once it gets
>> merged.
>
> I'm already testing it in my tree:
>
> https://github.com/norov/linux/tree/sm1
>
> If everything is fine, I'll submit v2 with this change, otherwise will
> schedule it for future improvements.

I had a look,

Acked-by: Jani Nikula <jani.nikula@intel.com>



-- 
Jani Nikula, Intel
Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Andy Shevchenko 2 months, 1 week ago
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
Re: [PATCH 1/3] kernel.h: drop STACK_MAGIC macro
Posted by Randy Dunlap 2 months, 1 week ago

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