]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
locking/lockdep: Avoid struct return in lock_stats()
authorArnd Bergmann <arnd@arndb.de>
Tue, 10 Jun 2025 09:29:21 +0000 (11:29 +0200)
committerBoqun Feng <boqun.feng@gmail.com>
Tue, 15 Jul 2025 04:57:20 +0000 (21:57 -0700)
Returning a large structure from the lock_stats() function causes clang
to have multiple copies of it on the stack and copy between them, which
can end up exceeding the frame size warning limit:

kernel/locking/lockdep.c:300:25: error: stack frame size (1464) exceeds limit (1280) in 'lock_stats' [-Werror,-Wframe-larger-than]
  300 | struct lock_class_stats lock_stats(struct lock_class *class)

Change the calling conventions to directly operate on the caller's copy,
which apparently is what gcc does already.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250610092941.2642847-1-arnd@kernel.org
include/linux/lockdep_types.h
kernel/locking/lockdep.c
kernel/locking/lockdep_proc.c

index 9f361d3ab9d95d98428dbc9b25361c3ffe9e4e10..eae115a26488562c27203ac0ce985f4c060f6ada 100644 (file)
@@ -175,7 +175,7 @@ struct lock_class_stats {
        unsigned long                   bounces[nr_bounce_types];
 };
 
-struct lock_class_stats lock_stats(struct lock_class *class);
+void lock_stats(struct lock_class *class, struct lock_class_stats *stats);
 void clear_lock_stats(struct lock_class *class);
 #endif
 
index dd2bbf73718b06caf9ded9aa6be73d616b154785..0c941418a2159d4d20ea0e1c47d4d9dfb9493e67 100644 (file)
@@ -297,33 +297,30 @@ static inline void lock_time_add(struct lock_time *src, struct lock_time *dst)
        dst->nr += src->nr;
 }
 
-struct lock_class_stats lock_stats(struct lock_class *class)
+void lock_stats(struct lock_class *class, struct lock_class_stats *stats)
 {
-       struct lock_class_stats stats;
        int cpu, i;
 
-       memset(&stats, 0, sizeof(struct lock_class_stats));
+       memset(stats, 0, sizeof(struct lock_class_stats));
        for_each_possible_cpu(cpu) {
                struct lock_class_stats *pcs =
                        &per_cpu(cpu_lock_stats, cpu)[class - lock_classes];
 
-               for (i = 0; i < ARRAY_SIZE(stats.contention_point); i++)
-                       stats.contention_point[i] += pcs->contention_point[i];
+               for (i = 0; i < ARRAY_SIZE(stats->contention_point); i++)
+                       stats->contention_point[i] += pcs->contention_point[i];
 
-               for (i = 0; i < ARRAY_SIZE(stats.contending_point); i++)
-                       stats.contending_point[i] += pcs->contending_point[i];
+               for (i = 0; i < ARRAY_SIZE(stats->contending_point); i++)
+                       stats->contending_point[i] += pcs->contending_point[i];
 
-               lock_time_add(&pcs->read_waittime, &stats.read_waittime);
-               lock_time_add(&pcs->write_waittime, &stats.write_waittime);
+               lock_time_add(&pcs->read_waittime, &stats->read_waittime);
+               lock_time_add(&pcs->write_waittime, &stats->write_waittime);
 
-               lock_time_add(&pcs->read_holdtime, &stats.read_holdtime);
-               lock_time_add(&pcs->write_holdtime, &stats.write_holdtime);
+               lock_time_add(&pcs->read_holdtime, &stats->read_holdtime);
+               lock_time_add(&pcs->write_holdtime, &stats->write_holdtime);
 
-               for (i = 0; i < ARRAY_SIZE(stats.bounces); i++)
-                       stats.bounces[i] += pcs->bounces[i];
+               for (i = 0; i < ARRAY_SIZE(stats->bounces); i++)
+                       stats->bounces[i] += pcs->bounces[i];
        }
-
-       return stats;
 }
 
 void clear_lock_stats(struct lock_class *class)
index b52c07c4707cd33f2a270a3c73a29628309c9aab..1916db9aa46b67833b1015775ad212590dc06c5d 100644 (file)
@@ -657,7 +657,7 @@ static int lock_stat_open(struct inode *inode, struct file *file)
                        if (!test_bit(idx, lock_classes_in_use))
                                continue;
                        iter->class = class;
-                       iter->stats = lock_stats(class);
+                       lock_stats(class, &iter->stats);
                        iter++;
                }