kmsan: silence -Wmissing-prototypes warnings
Commit Message
When building the kernel with W=1, the compiler reports numerous
warnings about the missing prototypes for KMSAN instrumentation hooks.
Because these functions are not supposed to be called explicitly by the
kernel code (calls to them are emitted by the compiler), they do not
have to be declared in the headers. Instead, we add forward declarations
right before the definitions to silence the warnings produced by
-Wmissing-prototypes.
Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/lkml/202301020356.dFruA4I5-lkp@intel.com/T/
Reported-by: Vlastimil Babka <vbabka@suse.cz>
Suggested-by: Marco Elver <elver@google.com>
Signed-off-by: Alexander Potapenko <glider@google.com>
---
mm/kmsan/instrumentation.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
Comments
On Thu, 12 Jan 2023 at 11:31, Alexander Potapenko <glider@google.com> wrote:
>
> When building the kernel with W=1, the compiler reports numerous
> warnings about the missing prototypes for KMSAN instrumentation hooks.
>
> Because these functions are not supposed to be called explicitly by the
> kernel code (calls to them are emitted by the compiler), they do not
> have to be declared in the headers. Instead, we add forward declarations
> right before the definitions to silence the warnings produced by
> -Wmissing-prototypes.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/lkml/202301020356.dFruA4I5-lkp@intel.com/T/
> Reported-by: Vlastimil Babka <vbabka@suse.cz>
> Suggested-by: Marco Elver <elver@google.com>
> Signed-off-by: Alexander Potapenko <glider@google.com>
Reviewed-by: Marco Elver <elver@google.com>
> ---
> mm/kmsan/instrumentation.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/mm/kmsan/instrumentation.c b/mm/kmsan/instrumentation.c
> index 770fe02904f36..cf12e9616b243 100644
> --- a/mm/kmsan/instrumentation.c
> +++ b/mm/kmsan/instrumentation.c
> @@ -38,7 +38,15 @@ get_shadow_origin_ptr(void *addr, u64 size, bool store)
> return ret;
> }
>
> +/*
> + * KMSAN instrumentation functions follow. They are not declared elsewhere in
> + * the kernel code, so they are preceded by prototypes, to silence
> + * -Wmissing-prototypes warnings.
> + */
> +
> /* Get shadow and origin pointers for a memory load with non-standard size. */
> +struct shadow_origin_ptr __msan_metadata_ptr_for_load_n(void *addr,
> + uintptr_t size);
> struct shadow_origin_ptr __msan_metadata_ptr_for_load_n(void *addr,
> uintptr_t size)
> {
> @@ -47,6 +55,8 @@ struct shadow_origin_ptr __msan_metadata_ptr_for_load_n(void *addr,
> EXPORT_SYMBOL(__msan_metadata_ptr_for_load_n);
>
> /* Get shadow and origin pointers for a memory store with non-standard size. */
> +struct shadow_origin_ptr __msan_metadata_ptr_for_store_n(void *addr,
> + uintptr_t size);
> struct shadow_origin_ptr __msan_metadata_ptr_for_store_n(void *addr,
> uintptr_t size)
> {
> @@ -59,12 +69,16 @@ EXPORT_SYMBOL(__msan_metadata_ptr_for_store_n);
> * with fixed size.
> */
> #define DECLARE_METADATA_PTR_GETTER(size) \
> + struct shadow_origin_ptr __msan_metadata_ptr_for_load_##size( \
> + void *addr); \
> struct shadow_origin_ptr __msan_metadata_ptr_for_load_##size( \
> void *addr) \
> { \
> return get_shadow_origin_ptr(addr, size, /*store*/ false); \
> } \
> EXPORT_SYMBOL(__msan_metadata_ptr_for_load_##size); \
> + struct shadow_origin_ptr __msan_metadata_ptr_for_store_##size( \
> + void *addr); \
> struct shadow_origin_ptr __msan_metadata_ptr_for_store_##size( \
> void *addr) \
> { \
> @@ -86,6 +100,7 @@ DECLARE_METADATA_PTR_GETTER(8);
> * entering or leaving IRQ. We omit the check for kmsan_in_runtime() to ensure
> * the memory written to in these cases is also marked as initialized.
> */
> +void __msan_instrument_asm_store(void *addr, uintptr_t size);
> void __msan_instrument_asm_store(void *addr, uintptr_t size)
> {
> unsigned long ua_flags;
> @@ -138,6 +153,7 @@ static inline void set_retval_metadata(u64 shadow, depot_stack_handle_t origin)
> }
>
> /* Handle llvm.memmove intrinsic. */
> +void *__msan_memmove(void *dst, const void *src, uintptr_t n);
> void *__msan_memmove(void *dst, const void *src, uintptr_t n)
> {
> depot_stack_handle_t origin;
> @@ -162,6 +178,7 @@ void *__msan_memmove(void *dst, const void *src, uintptr_t n)
> EXPORT_SYMBOL(__msan_memmove);
>
> /* Handle llvm.memcpy intrinsic. */
> +void *__msan_memcpy(void *dst, const void *src, uintptr_t n);
> void *__msan_memcpy(void *dst, const void *src, uintptr_t n)
> {
> depot_stack_handle_t origin;
> @@ -188,6 +205,7 @@ void *__msan_memcpy(void *dst, const void *src, uintptr_t n)
> EXPORT_SYMBOL(__msan_memcpy);
>
> /* Handle llvm.memset intrinsic. */
> +void *__msan_memset(void *dst, int c, uintptr_t n);
> void *__msan_memset(void *dst, int c, uintptr_t n)
> {
> depot_stack_handle_t origin;
> @@ -217,6 +235,7 @@ EXPORT_SYMBOL(__msan_memset);
> * uninitialized value to memory. When reporting an error, KMSAN unrolls and
> * prints the whole chain of stores that preceded the use of this value.
> */
> +depot_stack_handle_t __msan_chain_origin(depot_stack_handle_t origin);
> depot_stack_handle_t __msan_chain_origin(depot_stack_handle_t origin)
> {
> depot_stack_handle_t ret = 0;
> @@ -237,6 +256,7 @@ depot_stack_handle_t __msan_chain_origin(depot_stack_handle_t origin)
> EXPORT_SYMBOL(__msan_chain_origin);
>
> /* Poison a local variable when entering a function. */
> +void __msan_poison_alloca(void *address, uintptr_t size, char *descr);
> void __msan_poison_alloca(void *address, uintptr_t size, char *descr)
> {
> depot_stack_handle_t handle;
> @@ -272,6 +292,7 @@ void __msan_poison_alloca(void *address, uintptr_t size, char *descr)
> EXPORT_SYMBOL(__msan_poison_alloca);
>
> /* Unpoison a local variable. */
> +void __msan_unpoison_alloca(void *address, uintptr_t size);
> void __msan_unpoison_alloca(void *address, uintptr_t size)
> {
> if (!kmsan_enabled || kmsan_in_runtime())
> @@ -287,6 +308,7 @@ EXPORT_SYMBOL(__msan_unpoison_alloca);
> * Report that an uninitialized value with the given origin was used in a way
> * that constituted undefined behavior.
> */
> +void __msan_warning(u32 origin);
> void __msan_warning(u32 origin)
> {
> if (!kmsan_enabled || kmsan_in_runtime())
> @@ -303,6 +325,7 @@ EXPORT_SYMBOL(__msan_warning);
> * At the beginning of an instrumented function, obtain the pointer to
> * `struct kmsan_context_state` holding the metadata for function parameters.
> */
> +struct kmsan_context_state *__msan_get_context_state(void);
> struct kmsan_context_state *__msan_get_context_state(void)
> {
> return &kmsan_get_context()->cstate;
> --
> 2.39.0.314.g84b9a713c41-goog
>
@@ -38,7 +38,15 @@ get_shadow_origin_ptr(void *addr, u64 size, bool store)
return ret;
}
+/*
+ * KMSAN instrumentation functions follow. They are not declared elsewhere in
+ * the kernel code, so they are preceded by prototypes, to silence
+ * -Wmissing-prototypes warnings.
+ */
+
/* Get shadow and origin pointers for a memory load with non-standard size. */
+struct shadow_origin_ptr __msan_metadata_ptr_for_load_n(void *addr,
+ uintptr_t size);
struct shadow_origin_ptr __msan_metadata_ptr_for_load_n(void *addr,
uintptr_t size)
{
@@ -47,6 +55,8 @@ struct shadow_origin_ptr __msan_metadata_ptr_for_load_n(void *addr,
EXPORT_SYMBOL(__msan_metadata_ptr_for_load_n);
/* Get shadow and origin pointers for a memory store with non-standard size. */
+struct shadow_origin_ptr __msan_metadata_ptr_for_store_n(void *addr,
+ uintptr_t size);
struct shadow_origin_ptr __msan_metadata_ptr_for_store_n(void *addr,
uintptr_t size)
{
@@ -59,12 +69,16 @@ EXPORT_SYMBOL(__msan_metadata_ptr_for_store_n);
* with fixed size.
*/
#define DECLARE_METADATA_PTR_GETTER(size) \
+ struct shadow_origin_ptr __msan_metadata_ptr_for_load_##size( \
+ void *addr); \
struct shadow_origin_ptr __msan_metadata_ptr_for_load_##size( \
void *addr) \
{ \
return get_shadow_origin_ptr(addr, size, /*store*/ false); \
} \
EXPORT_SYMBOL(__msan_metadata_ptr_for_load_##size); \
+ struct shadow_origin_ptr __msan_metadata_ptr_for_store_##size( \
+ void *addr); \
struct shadow_origin_ptr __msan_metadata_ptr_for_store_##size( \
void *addr) \
{ \
@@ -86,6 +100,7 @@ DECLARE_METADATA_PTR_GETTER(8);
* entering or leaving IRQ. We omit the check for kmsan_in_runtime() to ensure
* the memory written to in these cases is also marked as initialized.
*/
+void __msan_instrument_asm_store(void *addr, uintptr_t size);
void __msan_instrument_asm_store(void *addr, uintptr_t size)
{
unsigned long ua_flags;
@@ -138,6 +153,7 @@ static inline void set_retval_metadata(u64 shadow, depot_stack_handle_t origin)
}
/* Handle llvm.memmove intrinsic. */
+void *__msan_memmove(void *dst, const void *src, uintptr_t n);
void *__msan_memmove(void *dst, const void *src, uintptr_t n)
{
depot_stack_handle_t origin;
@@ -162,6 +178,7 @@ void *__msan_memmove(void *dst, const void *src, uintptr_t n)
EXPORT_SYMBOL(__msan_memmove);
/* Handle llvm.memcpy intrinsic. */
+void *__msan_memcpy(void *dst, const void *src, uintptr_t n);
void *__msan_memcpy(void *dst, const void *src, uintptr_t n)
{
depot_stack_handle_t origin;
@@ -188,6 +205,7 @@ void *__msan_memcpy(void *dst, const void *src, uintptr_t n)
EXPORT_SYMBOL(__msan_memcpy);
/* Handle llvm.memset intrinsic. */
+void *__msan_memset(void *dst, int c, uintptr_t n);
void *__msan_memset(void *dst, int c, uintptr_t n)
{
depot_stack_handle_t origin;
@@ -217,6 +235,7 @@ EXPORT_SYMBOL(__msan_memset);
* uninitialized value to memory. When reporting an error, KMSAN unrolls and
* prints the whole chain of stores that preceded the use of this value.
*/
+depot_stack_handle_t __msan_chain_origin(depot_stack_handle_t origin);
depot_stack_handle_t __msan_chain_origin(depot_stack_handle_t origin)
{
depot_stack_handle_t ret = 0;
@@ -237,6 +256,7 @@ depot_stack_handle_t __msan_chain_origin(depot_stack_handle_t origin)
EXPORT_SYMBOL(__msan_chain_origin);
/* Poison a local variable when entering a function. */
+void __msan_poison_alloca(void *address, uintptr_t size, char *descr);
void __msan_poison_alloca(void *address, uintptr_t size, char *descr)
{
depot_stack_handle_t handle;
@@ -272,6 +292,7 @@ void __msan_poison_alloca(void *address, uintptr_t size, char *descr)
EXPORT_SYMBOL(__msan_poison_alloca);
/* Unpoison a local variable. */
+void __msan_unpoison_alloca(void *address, uintptr_t size);
void __msan_unpoison_alloca(void *address, uintptr_t size)
{
if (!kmsan_enabled || kmsan_in_runtime())
@@ -287,6 +308,7 @@ EXPORT_SYMBOL(__msan_unpoison_alloca);
* Report that an uninitialized value with the given origin was used in a way
* that constituted undefined behavior.
*/
+void __msan_warning(u32 origin);
void __msan_warning(u32 origin)
{
if (!kmsan_enabled || kmsan_in_runtime())
@@ -303,6 +325,7 @@ EXPORT_SYMBOL(__msan_warning);
* At the beginning of an instrumented function, obtain the pointer to
* `struct kmsan_context_state` holding the metadata for function parameters.
*/
+struct kmsan_context_state *__msan_get_context_state(void);
struct kmsan_context_state *__msan_get_context_state(void)
{
return &kmsan_get_context()->cstate;