Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Do not use call_usermodehelper() when testing the shrinker callback.
Browse files Browse the repository at this point in the history
If the usermode helper enters an infinite loop, we will hang. I caught this
when debugging an infinite loop in `drop_slab()` on Linux 3.12.y.  Instead of
doing an upcall into userland, lets write to the file directly from the kernel.
This does not solve the infinite loop in `shrink_slab()`, but it makes
debugging such issues easier, makes the code cleaner and makes the test suite
slightly faster.

Signed-off-by: Richard Yao <ryao@gentoo.org>
  • Loading branch information
ryao committed Oct 23, 2014
1 parent 0da9081 commit 9d43478
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions module/splat/splat-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Solaris Porting LAyer Tests (SPLAT) Kernel Compatibility Tests.
\*****************************************************************************/

#include <linux/file.h>
#include <sys/kmem.h>
#include "splat-internal.h"

Expand Down Expand Up @@ -94,32 +95,27 @@ __splat_linux_shrinker_fn(struct shrinker *shrink, struct shrink_control *sc)

SPL_SHRINKER_CALLBACK_WRAPPER(splat_linux_shrinker_fn);

#define DROP_SLAB_CMD \
"exec 0</dev/null " \
" 1>/proc/sys/vm/drop_caches " \
" 2>/dev/null; " \
"echo 2"

static int
splat_linux_drop_slab(struct file *file)
splat_echo(char *path, char *data, ssize_t len)
{
char *argv[] = { "/bin/sh",
"-c",
DROP_SLAB_CMD,
NULL };
char *envp[] = { "HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
NULL };
struct file *fp;
mm_segment_t saved_fs;
loff_t offset = 0;
int rc;

rc = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
if (rc)
splat_vprint(file, SPLAT_LINUX_TEST1_NAME,
"Failed user helper '%s %s %s', rc = %d\n",
argv[0], argv[1], argv[2], rc);
fp = filp_open(path, O_WRONLY, 0644);
if ((rc = PTR_RET(fp)))
return (rc);

return rc;
saved_fs = get_fs();
set_fs(get_ds());
rc = vfs_write(fp, data, len, &offset);
set_fs(saved_fs);

if (rc == 0)
rc = filp_close(fp, 0);

return (rc);
}

/*
Expand Down Expand Up @@ -152,7 +148,7 @@ splat_linux_test1(struct file *file, void *arg)
splat_linux_shrinker_file = file;

spl_register_shrinker(&splat_linux_shrinker);
rc = splat_linux_drop_slab(file);
rc = splat_echo("/proc/sys/vm/drop_caches", "2", 1);
if (rc)
goto out;

Expand Down

0 comments on commit 9d43478

Please sign in to comment.