Skip to contentSkip to conversation

kasan: fix build by including kernel.h

PATCH In review Marco Elver 3 participants 5 messages Jul 5, 2021 – Jul 6, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kasan: fix build by including kernel.h

The <linux/kasan.h> header relies on _RET_IP_ being defined, and had been receiving that definition via inclusion of bug.h which includes kernel.h. However, since f39650de687e that is no longer the case and get the following build error when building CONFIG_KASAN_HW_TAGS on arm64:

In file included from arch/arm64/mm/kasan_init.c:10:
./include/linux/kasan.h: In function 'kasan_slab_free':
./include/linux/kasan.h:230:39: error: '_RET_IP_' undeclared (first use in this function)

    230 |   return __kasan_slab_free(s, object, _RET_IP_, init);

Fix it by including kernel.h from kasan.h.

Fixes f39650de687e ("kernel.h: split out panic and oops helpers")
Cc Andy Shevchenko <[email protected]>
Cc Andrew Morton <[email protected]>
---
 include/linux/kasan.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/kasan.h +1 -0
index 5310e217bd74..dd874a1ee862 100644
@@ -3,6 +3,7 @@
 #define _LINUX_KASAN_H
 
 #include <linux/bug.h>
+#include <linux/kernel.h>
 #include <linux/static_key.h>
 #include <linux/types.h>
 
Signature · 1 line
2.32.0.93.g670b81a890-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Marco Elver

The <linux/kasan.h> header relies on _RET_IP_ being defined, and had been receiving that definition via inclusion of bug.h which includes kernel.h. However, since f39650de687e that is no longer the case and get the following build error when building CONFIG_KASAN_HW_TAGS on arm64:

Quoted 6 lines

In file included from arch/arm64/mm/kasan_init.c:10:
./include/linux/kasan.h: In function 'kasan_slab_free':
./include/linux/kasan.h:230:39: error: '_RET_IP_' undeclared (first use in this function)

    230 |   return __kasan_slab_free(s, object, _RET_IP_, init);

Fix it by including kernel.h from kasan.h.

...which I would like to avoid in the long term, but for now it's probably the best quick fix, otherwise it will require the real split of _RET_IP or at least rethinking its location.

Thanks!

Quoted 1 line
Fixes f39650de687e ("kernel.h: split out panic and oops helpers")

P.S. I have tested the initial patch against full build of x86_64, and it was long time available for different CIs/build bots, none complained so far.

Quoted 22 lines
Cc Andy Shevchenko <[email protected]>
Cc Andrew Morton <[email protected]>
---
 include/linux/kasan.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/kasan.h +1 -1
index 5310e217bd74..dd874a1ee862 100644
@@ -3,6 +3,7 @@
 #define _LINUX_KASAN_H
 
 #include <linux/bug.h>
+#include <linux/kernel.h>
 #include <linux/static_key.h>
 #include <linux/types.h>
 
--

2.32.0.93.g670b81a890-goog

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Marco Elver

The <linux/kasan.h> header relies on _RET_IP_ being defined, and had been receiving that definition via inclusion of bug.h which includes kernel.h. However, since f39650de687e that is no longer the case and get the following build error when building CONFIG_KASAN_HW_TAGS on arm64:

In file included from arch/arm64/mm/kasan_init.c:10:
./include/linux/kasan.h: In function 'kasan_slab_free':
./include/linux/kasan.h:230:39: error: '_RET_IP_' undeclared (first use in this function)

    230 |   return __kasan_slab_free(s, object, _RET_IP_, init);
Quoted 8 lines
Quoted 1 line

Fix it by including kernel.h from kasan.h.

...which I would like to avoid in the long term, but for now it's probably the best quick fix, otherwise it will require the real split of _RET_IP or at least rethinking its location.

Thanks!

Thanks!

Quoted 5 lines
Quoted 1 line
Fixes f39650de687e ("kernel.h: split out panic and oops helpers")

P.S. I have tested the initial patch against full build of x86_64, and it was long time available for different CIs/build bots, none complained so far.

It only manifests on arm64 when using CONFIG_KASAN_HW_TAGS mode (requires Arm64 MTE extensions). The other 2 modes include <linux/pgtable.h> in kasan.h, and that seems to include kernel.h somewhere. The HW_TAGS mode, however, doesn't receive -next testing by a CI system AFAIK, so this was missed because it's not yet used by many (I'd expect that to change when CPUs with MTE are more widespread).

Thanks,
-- Marco

Reviewed-by
#3 lore raw
Quoted 14 lines · Marco Elver
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Marco Elver

The <linux/kasan.h> header relies on _RET_IP_ being defined, and had been receiving that definition via inclusion of bug.h which includes kernel.h. However, since f39650de687e that is no longer the case and get the following build error when building CONFIG_KASAN_HW_TAGS on arm64:

In file included from arch/arm64/mm/kasan_init.c:10:
./include/linux/kasan.h: In function 'kasan_slab_free':
./include/linux/kasan.h:230:39: error: '_RET_IP_' undeclared (first use in this function)

    230 |   return __kasan_slab_free(s, object, _RET_IP_, init);

Fix it by including kernel.h from kasan.h.

Quoted 8 lines
Quoted 6 lines

...which I would like to avoid in the long term, but for now it's probably the best quick fix, otherwise it will require the real split of _RET_IP or at least rethinking its location.

Thanks!

Thanks!

Should be:

Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Fixes f39650de687e ("kernel.h: split out panic and oops helpers")

P.S. I have tested the initial patch against full build of x86_64, and it was long time available for different CIs/build bots, none complained so far.

Quoted 7 lines

It only manifests on arm64 when using CONFIG_KASAN_HW_TAGS mode (requires Arm64 MTE extensions). The other 2 modes include <linux/pgtable.h> in kasan.h, and that seems to include kernel.h somewhere. The HW_TAGS mode, however, doesn't receive -next testing by a CI system AFAIK, so this was missed because it's not yet used by many (I'd expect that to change when CPUs with MTE are more widespread).

Got it.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
reviewer Reviewed-by on v1 1/1
#4 lore raw
In reply to Marco Elver
Quoted 34 lines · Marco Elver

The <linux/kasan.h> header relies on _RET_IP_ being defined, and had been receiving that definition via inclusion of bug.h which includes kernel.h. However, since f39650de687e that is no longer the case and get the following build error when building CONFIG_KASAN_HW_TAGS on arm64:

In file included from arch/arm64/mm/kasan_init.c:10:
./include/linux/kasan.h: In function 'kasan_slab_free':
./include/linux/kasan.h:230:39: error: '_RET_IP_' undeclared (first use in this function)

    230 |   return __kasan_slab_free(s, object, _RET_IP_, init);

Fix it by including kernel.h from kasan.h.

Fixes f39650de687e ("kernel.h: split out panic and oops helpers")
Cc Andy Shevchenko <[email protected]>
Cc Andrew Morton <[email protected]>
---
 include/linux/kasan.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/kasan.h +1 -1
index 5310e217bd74..dd874a1ee862 100644
@@ -3,6 +3,7 @@
 #define _LINUX_KASAN_H
 
 #include <linux/bug.h>
+#include <linux/kernel.h>
 #include <linux/static_key.h>
 #include <linux/types.h>
 
--
Quoted 2 lines

2.32.0.93.g670b81a890-goog