Commit d5037d1d authored by Daniel Vetter's avatar Daniel Vetter Committed by Linus Torvalds

locking/selftests: add testcases for fs_reclaim

Since I butchered this I figured better to make sure we have testcases for
this now.  Since we only have a locking context for __GFP_FS that's the
only thing we're testing right now.

Link: https://lkml.kernel.org/r/20201125162532.1299794-4-daniel.vetter@ffwll.chSigned-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Qian Cai <cai@lca.pw>
Cc: Thomas Hellström (Intel) <thomas_os@shipmail.org>
Cc: Jason Gunthorpe <jgg@mellanox.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Waiman Long <longman@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 95d6c701
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/ww_mutex.h> #include <linux/ww_mutex.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/sched/mm.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/lockdep.h> #include <linux/lockdep.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
...@@ -2357,6 +2358,50 @@ static void queued_read_lock_tests(void) ...@@ -2357,6 +2358,50 @@ static void queued_read_lock_tests(void)
pr_cont("\n"); pr_cont("\n");
} }
static void fs_reclaim_correct_nesting(void)
{
fs_reclaim_acquire(GFP_KERNEL);
might_alloc(GFP_NOFS);
fs_reclaim_release(GFP_KERNEL);
}
static void fs_reclaim_wrong_nesting(void)
{
fs_reclaim_acquire(GFP_KERNEL);
might_alloc(GFP_KERNEL);
fs_reclaim_release(GFP_KERNEL);
}
static void fs_reclaim_protected_nesting(void)
{
unsigned int flags;
fs_reclaim_acquire(GFP_KERNEL);
flags = memalloc_nofs_save();
might_alloc(GFP_KERNEL);
memalloc_nofs_restore(flags);
fs_reclaim_release(GFP_KERNEL);
}
static void fs_reclaim_tests(void)
{
printk(" --------------------\n");
printk(" | fs_reclaim tests |\n");
printk(" --------------------\n");
print_testname("correct nesting");
dotest(fs_reclaim_correct_nesting, SUCCESS, 0);
pr_cont("\n");
print_testname("wrong nesting");
dotest(fs_reclaim_wrong_nesting, FAILURE, 0);
pr_cont("\n");
print_testname("protected nesting");
dotest(fs_reclaim_protected_nesting, SUCCESS, 0);
pr_cont("\n");
}
void locking_selftest(void) void locking_selftest(void)
{ {
/* /*
...@@ -2478,6 +2523,8 @@ void locking_selftest(void) ...@@ -2478,6 +2523,8 @@ void locking_selftest(void)
if (IS_ENABLED(CONFIG_QUEUED_RWLOCKS)) if (IS_ENABLED(CONFIG_QUEUED_RWLOCKS))
queued_read_lock_tests(); queued_read_lock_tests();
fs_reclaim_tests();
if (unexpected_testcase_failures) { if (unexpected_testcase_failures) {
printk("-----------------------------------------------------------------\n"); printk("-----------------------------------------------------------------\n");
debug_locks = 0; debug_locks = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment