From: Vitor Massaru Iha <vitor@massaru.org>
To: kunit-dev@googlegroups.com
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
brendanhiggins@google.com, keescook@chromium.org,
davidgow@google.com, skhan@linuxfoundation.org,
linux-kernel-mentees@lists.linuxfoundation.org
Subject: [RFC 2/3] lib: Allows to borrow mm in userspace on KUnit
Date: Wed, 15 Jul 2020 00:11:19 -0300 [thread overview]
Message-ID: <20200715031120.1002016-3-vitor@massaru.org> (raw)
In-Reply-To: <20200715031120.1002016-1-vitor@massaru.org>
Signed-off-by: Vitor Massaru Iha <vitor@massaru.org>
---
include/kunit/test.h | 1 +
lib/kunit/try-catch.c | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h
index 59f3144f009a..49c38bdcb93e 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -222,6 +222,7 @@ struct kunit {
* protect it with some type of lock.
*/
struct list_head resources; /* Protected by lock. */
+ struct mm_struct *mm;
};
void kunit_init_test(struct kunit *test, const char *name, char *log);
diff --git a/lib/kunit/try-catch.c b/lib/kunit/try-catch.c
index 0dd434e40487..f677c2f2a51a 100644
--- a/lib/kunit/try-catch.c
+++ b/lib/kunit/try-catch.c
@@ -11,7 +11,8 @@
#include <linux/completion.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
-
+#include <linux/sched/mm.h>
+#include <linux/sched/task.h>
#include "try-catch-impl.h"
void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch)
@@ -24,8 +25,17 @@ EXPORT_SYMBOL_GPL(kunit_try_catch_throw);
static int kunit_generic_run_threadfn_adapter(void *data)
{
struct kunit_try_catch *try_catch = data;
+ struct kunit *test = try_catch->test;
+
+ if (test->mm != NULL)
+ kthread_use_mm(try_catch->test->mm);
try_catch->try(try_catch->context);
+ if (try_catch->test->mm) {
+ if (test->mm != NULL)
+ kthread_unuse_mm(try_catch->test->mm);
+ try_catch->test->mm = NULL;
+ }
complete_and_exit(try_catch->try_completion, 0);
}
@@ -65,6 +75,9 @@ void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context)
try_catch->context = context;
try_catch->try_completion = &try_completion;
try_catch->try_result = 0;
+
+ test->mm = get_task_mm(current);
+
task_struct = kthread_run(kunit_generic_run_threadfn_adapter,
try_catch,
"kunit_try_catch_thread");
--
2.26.2
next prev parent reply other threads:[~2020-07-15 3:11 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-15 3:11 [RFC 0/3] kunit: add support to use modules Vitor Massaru Iha
2020-07-15 3:11 ` [RFC 1/3] kunit: tool: Add support root filesystem in kunit-tool Vitor Massaru Iha
2020-07-16 0:29 ` Brendan Higgins
2020-07-16 16:34 ` Vitor Massaru Iha
2020-07-15 3:11 ` Vitor Massaru Iha [this message]
2020-07-16 0:37 ` [RFC 2/3] lib: Allows to borrow mm in userspace on KUnit Brendan Higgins
2020-07-16 16:35 ` Vitor Massaru Iha
2020-07-16 16:35 ` Vitor Massaru Iha
2020-07-15 3:11 ` [RFC 3/3] lib: Convert test_user_copy to KUnit test Vitor Massaru Iha
2020-07-16 0:40 ` Brendan Higgins
2020-07-16 16:40 ` Vitor Massaru Iha
2020-07-16 2:34 ` Kees Cook
2020-07-16 16:42 ` Vitor Massaru Iha
2020-07-15 3:47 ` [RFC 0/3] kunit: add support to use modules David Gow
2020-07-16 2:41 ` Kees Cook
2020-07-16 16:32 ` Vitor Massaru Iha
2020-07-16 16:21 ` Vitor Massaru Iha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200715031120.1002016-3-vitor@massaru.org \
--to=vitor@massaru.org \
--cc=brendanhiggins@google.com \
--cc=davidgow@google.com \
--cc=keescook@chromium.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®