diff mbox series

[v3,1/2] mm: Provide empty function for kmem_dump_obj() when CONFIG_PRINTK=n

Message ID 20230802034518.1115-2-thunder.leizhen@huaweicloud.com (mailing list archive)
State Superseded
Headers show
Series rcu: Dump memory object info if callback function is invalid | expand

Commit Message

Leizhen (ThunderTown) Aug. 2, 2023, 3:45 a.m. UTC
From: Zhen Lei <thunder.leizhen@huawei.com>

Commit 5bb1bb353cfe ("mm: Don't build mm_dump_obj() on CONFIG_PRINTK=n
kernels") only provides static inline empty function for mem_dump_obj().
But functions kmem_valid_obj() and kmem_dump_obj() are also exported,
they may be called by functions other than mem_dump_obj(), so their empty
functions should also be provided when CONFIG_PRINTK=n.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 include/linux/slab.h | 3 +++
 1 file changed, 3 insertions(+)

Comments

Matthew Wilcox (Oracle) Aug. 2, 2023, 3:57 a.m. UTC | #1
On Wed, Aug 02, 2023 at 11:45:16AM +0800, thunder.leizhen@huaweicloud.com wrote:
> +++ b/include/linux/slab.h
> @@ -246,6 +246,9 @@ size_t ksize(const void *objp);
>  #ifdef CONFIG_PRINTK
>  bool kmem_valid_obj(void *object);
>  void kmem_dump_obj(void *object);
> +#else
> +static inline bool kmem_valid_obj(void *object) { return false; }

That is very confusing.  kmem_valid_obj() looks like a function which
should exist regardless of CONFIG_PRINTK and to have it always return
false if CONFIG_PRINTK isn't set seems weird.

I see we have one caller of kmem_valid_obj() right now.  Which means it
shouldn't be an EXPORT_SYMBOL since that caller is not a module.

I think the right solution is to convert kmem_dump_obj() to
work the same way as vmalloc_dump_obj().  ie:

+++ b/mm/util.c
@@ -1057,11 +1057,8 @@ void mem_dump_obj(void *object)
 {
        const char *type;

-       if (kmem_valid_obj(object)) {
-               kmem_dump_obj(object);
+       if (kmem_dump_obj(object))
                return;
-       }
-
        if (vmalloc_dump_obj(object))
                return;

... with corresponding changes to eliminate kmem_valid_obj() as a
symbol.
Leizhen (ThunderTown) Aug. 2, 2023, 11:11 a.m. UTC | #2
On 2023/8/2 11:57, Matthew Wilcox wrote:
> On Wed, Aug 02, 2023 at 11:45:16AM +0800, thunder.leizhen@huaweicloud.com wrote:
>> +++ b/include/linux/slab.h
>> @@ -246,6 +246,9 @@ size_t ksize(const void *objp);
>>  #ifdef CONFIG_PRINTK
>>  bool kmem_valid_obj(void *object);
>>  void kmem_dump_obj(void *object);
>> +#else
>> +static inline bool kmem_valid_obj(void *object) { return false; }
> 
> That is very confusing.  kmem_valid_obj() looks like a function which
> should exist regardless of CONFIG_PRINTK and to have it always return
> false if CONFIG_PRINTK isn't set seems weird.

Yes, I noticed it, but I didn't come up with a good idea.

> 
> I see we have one caller of kmem_valid_obj() right now.  Which means it
> shouldn't be an EXPORT_SYMBOL since that caller is not a module.
> 
> I think the right solution is to convert kmem_dump_obj() to
> work the same way as vmalloc_dump_obj().  ie:

Okay, it's a good suggestion.

In fact, kmem_dump_obj() also does what kmem_valid_obj() does, except
that it will print warning if the check fails. So, do as you suggest,
the duplicated code can be eliminated.

> 
> +++ b/mm/util.c
> @@ -1057,11 +1057,8 @@ void mem_dump_obj(void *object)
>  {
>         const char *type;
> 
> -       if (kmem_valid_obj(object)) {
> -               kmem_dump_obj(object);
> +       if (kmem_dump_obj(object))
>                 return;
> -       }
> -
>         if (vmalloc_dump_obj(object))
>                 return;
> 
> ... with corresponding changes to eliminate kmem_valid_obj() as a
> symbol.
> 
> .
>
diff mbox series

Patch

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 848c7c82ad5ad0b..fc05fe288d176b4 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -246,6 +246,9 @@  size_t ksize(const void *objp);
 #ifdef CONFIG_PRINTK
 bool kmem_valid_obj(void *object);
 void kmem_dump_obj(void *object);
+#else
+static inline bool kmem_valid_obj(void *object) { return false; }
+static inline void kmem_dump_obj(void *object) {}
 #endif
 
 /*