[mm,2/4] kasan: reuse kasan_track in kasan_stack_ring_entry

Message ID 20231221183540.168428-2-andrey.konovalov@linux.dev
State New
Headers
Series [mm,1/4] kasan: clean up kasan_cache_create |

Commit Message

andrey.konovalov@linux.dev Dec. 21, 2023, 6:35 p.m. UTC
  From: Andrey Konovalov <andreyknvl@google.com>

Avoid duplicating fields of kasan_track in kasan_stack_ring_entry:
reuse the structure.

Fixes: 5d4c6ac94694 ("kasan: record and report more information")
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 mm/kasan/kasan.h       |  7 +------
 mm/kasan/report_tags.c | 12 ++++++------
 mm/kasan/tags.c        | 12 ++++++------
 3 files changed, 13 insertions(+), 18 deletions(-)
  

Comments

Marco Elver Dec. 21, 2023, 8:10 p.m. UTC | #1
On Thu, 21 Dec 2023 at 19:35, <andrey.konovalov@linux.dev> wrote:
>
> From: Andrey Konovalov <andreyknvl@google.com>
>
> Avoid duplicating fields of kasan_track in kasan_stack_ring_entry:
> reuse the structure.

No functional change?

> Fixes: 5d4c6ac94694 ("kasan: record and report more information")
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

Reviewed-by: Marco Elver <elver@google.com>

> ---
>  mm/kasan/kasan.h       |  7 +------
>  mm/kasan/report_tags.c | 12 ++++++------
>  mm/kasan/tags.c        | 12 ++++++------
>  3 files changed, 13 insertions(+), 18 deletions(-)
>
> diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
> index 5e298e3ac909..9072ce4c1263 100644
> --- a/mm/kasan/kasan.h
> +++ b/mm/kasan/kasan.h
> @@ -279,13 +279,8 @@ struct kasan_free_meta {
>  struct kasan_stack_ring_entry {
>         void *ptr;
>         size_t size;
> -       u32 pid;
> -       depot_stack_handle_t stack;
> +       struct kasan_track track;
>         bool is_free;
> -#ifdef CONFIG_KASAN_EXTRA_INFO
> -       u64 cpu:20;
> -       u64 timestamp:44;
> -#endif /* CONFIG_KASAN_EXTRA_INFO */
>  };
>
>  struct kasan_stack_ring {
> diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c
> index 979f284c2497..688b9d70b04a 100644
> --- a/mm/kasan/report_tags.c
> +++ b/mm/kasan/report_tags.c
> @@ -31,8 +31,8 @@ static const char *get_common_bug_type(struct kasan_report_info *info)
>  static void kasan_complete_extra_report_info(struct kasan_track *track,
>                                          struct kasan_stack_ring_entry *entry)
>  {
> -       track->cpu = entry->cpu;
> -       track->timestamp = entry->timestamp;
> +       track->cpu = entry->track.cpu;
> +       track->timestamp = entry->track.timestamp;
>  }
>  #endif /* CONFIG_KASAN_EXTRA_INFO */
>
> @@ -80,8 +80,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info)
>                         if (free_found)
>                                 break;
>
> -                       info->free_track.pid = entry->pid;
> -                       info->free_track.stack = entry->stack;
> +                       info->free_track.pid = entry->track.pid;
> +                       info->free_track.stack = entry->track.stack;
>  #ifdef CONFIG_KASAN_EXTRA_INFO
>                         kasan_complete_extra_report_info(&info->free_track, entry);
>  #endif /* CONFIG_KASAN_EXTRA_INFO */
> @@ -98,8 +98,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info)
>                         if (alloc_found)
>                                 break;
>
> -                       info->alloc_track.pid = entry->pid;
> -                       info->alloc_track.stack = entry->stack;
> +                       info->alloc_track.pid = entry->track.pid;
> +                       info->alloc_track.stack = entry->track.stack;
>  #ifdef CONFIG_KASAN_EXTRA_INFO
>                         kasan_complete_extra_report_info(&info->alloc_track, entry);
>  #endif /* CONFIG_KASAN_EXTRA_INFO */
> diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c
> index c13b198b8302..c4d14dbf27c0 100644
> --- a/mm/kasan/tags.c
> +++ b/mm/kasan/tags.c
> @@ -100,8 +100,8 @@ static void save_extra_info(struct kasan_stack_ring_entry *entry)
>         u32 cpu = raw_smp_processor_id();
>         u64 ts_nsec = local_clock();
>
> -       entry->cpu = cpu;
> -       entry->timestamp = ts_nsec >> 3;
> +       entry->track.cpu = cpu;
> +       entry->track.timestamp = ts_nsec >> 3;
>  }
>  #endif /* CONFIG_KASAN_EXTRA_INFO */
>
> @@ -134,15 +134,15 @@ static void save_stack_info(struct kmem_cache *cache, void *object,
>         if (!try_cmpxchg(&entry->ptr, &old_ptr, STACK_RING_BUSY_PTR))
>                 goto next; /* Busy slot. */
>
> -       old_stack = entry->stack;
> +       old_stack = entry->track.stack;
>
>         entry->size = cache->object_size;
> -       entry->pid = current->pid;
> -       entry->stack = stack;
> -       entry->is_free = is_free;
> +       entry->track.pid = current->pid;
> +       entry->track.stack = stack;
>  #ifdef CONFIG_KASAN_EXTRA_INFO
>         save_extra_info(entry);
>  #endif /* CONFIG_KASAN_EXTRA_INFO */
> +       entry->is_free = is_free;
>
>         entry->ptr = object;
>
> --
> 2.25.1
>
  
Andrey Konovalov Dec. 21, 2023, 8:19 p.m. UTC | #2
On Thu, Dec 21, 2023 at 9:11 PM Marco Elver <elver@google.com> wrote:
>
> On Thu, 21 Dec 2023 at 19:35, <andrey.konovalov@linux.dev> wrote:
> >
> > From: Andrey Konovalov <andreyknvl@google.com>
> >
> > Avoid duplicating fields of kasan_track in kasan_stack_ring_entry:
> > reuse the structure.
>
> No functional change?

Yes, no functional changes in this and the following patches in the series.

> > Fixes: 5d4c6ac94694 ("kasan: record and report more information")
> > Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
>
> Reviewed-by: Marco Elver <elver@google.com>

Thank you!
  

Patch

diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index 5e298e3ac909..9072ce4c1263 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -279,13 +279,8 @@  struct kasan_free_meta {
 struct kasan_stack_ring_entry {
 	void *ptr;
 	size_t size;
-	u32 pid;
-	depot_stack_handle_t stack;
+	struct kasan_track track;
 	bool is_free;
-#ifdef CONFIG_KASAN_EXTRA_INFO
-	u64 cpu:20;
-	u64 timestamp:44;
-#endif /* CONFIG_KASAN_EXTRA_INFO */
 };
 
 struct kasan_stack_ring {
diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c
index 979f284c2497..688b9d70b04a 100644
--- a/mm/kasan/report_tags.c
+++ b/mm/kasan/report_tags.c
@@ -31,8 +31,8 @@  static const char *get_common_bug_type(struct kasan_report_info *info)
 static void kasan_complete_extra_report_info(struct kasan_track *track,
 					 struct kasan_stack_ring_entry *entry)
 {
-	track->cpu = entry->cpu;
-	track->timestamp = entry->timestamp;
+	track->cpu = entry->track.cpu;
+	track->timestamp = entry->track.timestamp;
 }
 #endif /* CONFIG_KASAN_EXTRA_INFO */
 
@@ -80,8 +80,8 @@  void kasan_complete_mode_report_info(struct kasan_report_info *info)
 			if (free_found)
 				break;
 
-			info->free_track.pid = entry->pid;
-			info->free_track.stack = entry->stack;
+			info->free_track.pid = entry->track.pid;
+			info->free_track.stack = entry->track.stack;
 #ifdef CONFIG_KASAN_EXTRA_INFO
 			kasan_complete_extra_report_info(&info->free_track, entry);
 #endif /* CONFIG_KASAN_EXTRA_INFO */
@@ -98,8 +98,8 @@  void kasan_complete_mode_report_info(struct kasan_report_info *info)
 			if (alloc_found)
 				break;
 
-			info->alloc_track.pid = entry->pid;
-			info->alloc_track.stack = entry->stack;
+			info->alloc_track.pid = entry->track.pid;
+			info->alloc_track.stack = entry->track.stack;
 #ifdef CONFIG_KASAN_EXTRA_INFO
 			kasan_complete_extra_report_info(&info->alloc_track, entry);
 #endif /* CONFIG_KASAN_EXTRA_INFO */
diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c
index c13b198b8302..c4d14dbf27c0 100644
--- a/mm/kasan/tags.c
+++ b/mm/kasan/tags.c
@@ -100,8 +100,8 @@  static void save_extra_info(struct kasan_stack_ring_entry *entry)
 	u32 cpu = raw_smp_processor_id();
 	u64 ts_nsec = local_clock();
 
-	entry->cpu = cpu;
-	entry->timestamp = ts_nsec >> 3;
+	entry->track.cpu = cpu;
+	entry->track.timestamp = ts_nsec >> 3;
 }
 #endif /* CONFIG_KASAN_EXTRA_INFO */
 
@@ -134,15 +134,15 @@  static void save_stack_info(struct kmem_cache *cache, void *object,
 	if (!try_cmpxchg(&entry->ptr, &old_ptr, STACK_RING_BUSY_PTR))
 		goto next; /* Busy slot. */
 
-	old_stack = entry->stack;
+	old_stack = entry->track.stack;
 
 	entry->size = cache->object_size;
-	entry->pid = current->pid;
-	entry->stack = stack;
-	entry->is_free = is_free;
+	entry->track.pid = current->pid;
+	entry->track.stack = stack;
 #ifdef CONFIG_KASAN_EXTRA_INFO
 	save_extra_info(entry);
 #endif /* CONFIG_KASAN_EXTRA_INFO */
+	entry->is_free = is_free;
 
 	entry->ptr = object;