Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp758384pxa; Wed, 19 Aug 2020 14:10:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzszoyjkA0Q4c6DQmaBkgos6SSwzcncnYPqZmJRxmWEdq4oQh7zBlfWnbrRseoQW4blUkVz X-Received: by 2002:aa7:d1cb:: with SMTP id g11mr26107983edp.26.1597871452650; Wed, 19 Aug 2020 14:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597871452; cv=none; d=google.com; s=arc-20160816; b=agzsBd7bUvJGaqC7Ohsyv7wFagFJIi6Cusx7aNToS6qKrwXC2RX0JYZabQHm+XZCbF m8FDM0xuBGogErgKi4D+E38VtckjySUib0WWeDrmcn0fSsybM+NZ/fxOpk3XTrbhGAx5 4FWirgxGkahSVoMPs3cCefY2JRdaoNXr4gW9lKzCFYhFyHL0cgWWulC4WAHA8JOthMV/ r0pCJFawBLhZDxiBeBhAWrImGglNeVIgiv10Z6851J0CyfKR9KYrKNxCfz2gvyNjxcL9 sI5iNq0oLagvrjFqDQpav3awC+cndBF5sF5MYR5JXinaeJalQXwtm8c27ngBA1L2cDEG IV/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=p1h0o70heWIyDfW4WJLhr1C00M5SdMyJMwYyJJrQ7Vs=; b=KgSQ4YanAfGkCoqbaeE0XPtip/k/LAMykR9R8MBWZaeS6v3Gu5bURoQOFXw74zfP8C mUgC3ejFtMFhLEHWfGwTeX7zsoTLHjbj+FNfqB3oSYx0glJ3r+907ys9Aaqbg+hvakS+ 2ZDGxF1lnwNSzV9iUpoeMOJGEmTFVWzsyUFlGEHHAoUZvKRSd/210JlzDQSuRAg3obiY VAvVSXysV+srWYP3HDzsf3Z+eSRAoHXNNmD7T7HFgJpzCzlV85bng4tno+laYPhhSZMt L0oRl7kSm7LcS5BjBO3ARPwLLJAymtYUGqsCVxZsrkggCNkWnj5Y76jZXqWqIpuwEjV2 pAYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@massaru-org.20150623.gappssmtp.com header.s=20150623 header.b="m+b/CR0I"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf25si18209982ejb.690.2020.08.19.14.10.28; Wed, 19 Aug 2020 14:10:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@massaru-org.20150623.gappssmtp.com header.s=20150623 header.b="m+b/CR0I"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727794AbgHSVIE (ORCPT + 99 others); Wed, 19 Aug 2020 17:08:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726796AbgHSVID (ORCPT ); Wed, 19 Aug 2020 17:08:03 -0400 Received: from mail-yb1-xb42.google.com (mail-yb1-xb42.google.com [IPv6:2607:f8b0:4864:20::b42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9B3FC061383 for ; Wed, 19 Aug 2020 14:08:02 -0700 (PDT) Received: by mail-yb1-xb42.google.com with SMTP id u6so8251917ybf.1 for ; Wed, 19 Aug 2020 14:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=massaru-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=p1h0o70heWIyDfW4WJLhr1C00M5SdMyJMwYyJJrQ7Vs=; b=m+b/CR0IOh/JwBLKSCJLtVSX9ATMicrNmGJWSi4OuhpDjrEiAsBSZMjmXRwXWWAYlK qoyjMPSRCmNnuV4BUvNreNFwith189w30QLZguYDXdW/ibHsJyCfanoeJrDjDPFSlpPT 9wVsSf2+Eyaqudw0VJW4P5AR6pE3SsSylUbNDj8cAHlfFwu2KkZchI+qj2oLz67YSw7Z 3U8kRcAC4LVwivqs8jwJAE6PyYSZumibj/2CjC1LhOHFuJEd0P88R560YGT73gxCJjY0 bRqczll/6S+vJtE0j8VDkzQzv18aYlwJ+10+OrVFUs0R5MOgYQ5ZXThQ1PWL0B3hP657 SMAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=p1h0o70heWIyDfW4WJLhr1C00M5SdMyJMwYyJJrQ7Vs=; b=FLBiJQ6aSQP5KVbYrTfOIlZ3B6NYKQ7j1bfCIxuZlcBVPIVoaa+nE14+rZwEf6xFlR TMzORxd94s43A2pB9R3HEfc3kyuRy1eMHKY7l6jvDLcHXYuhIoXgT9ZH3cLfvj24PivL OH8RL+wfwrB01BMtA9fTq3Rsm9Uz/+KM2fzO/s2Ivc3uhZVJFm/pyQ0+GVNaYdjgPpeb PJ9CZr9qDQgcZQZyJrqTsI7uleW/ldse3UrnLuCff4m3IJNNDdK+/UKbP48LB4mWeXMO 622FapinqQ2AZJJSV/mPrl5f/WzbkXV1/kKH5IVeWyutosXs8S4PM0VGVX94lMBDlcMP /T5Q== X-Gm-Message-State: AOAM533fVn+0H3uQRuR70uObVeiZSM5wFvvt3m+tF17e2M1LCuylljEX nahpUa7WyJKUVHJsuetok50JC8iKiEuxiTE19KoZmA== X-Received: by 2002:a25:ca50:: with SMTP id a77mr447316ybg.286.1597871281654; Wed, 19 Aug 2020 14:08:01 -0700 (PDT) MIME-Version: 1.0 References: <20200718005025.440320-1-vitor@massaru.org> In-Reply-To: From: Vitor Massaru Iha Date: Wed, 19 Aug 2020 18:07:25 -0300 Message-ID: Subject: Re: [PATCH v2] lib: kunit: Provides a userspace memory context when tests are compiled as module To: Brendan Higgins Cc: KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , Linux Kernel Mailing List , Kees Cook , David Gow , Shuah Khan , linux-kernel-mentees@lists.linuxfoundation.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 19, 2020 at 6:05 PM Brendan Higgins wrote: > > On Fri, Jul 17, 2020 at 5:50 PM Vitor Massaru Iha wrote: > > > > KUnit test cases run on kthreads, and kthreads don't have an > > adddress space (current->mm is NULL), but processes have mm. > > > > The purpose of this patch is to allow to borrow mm to KUnit kthread > > after userspace is brought up, because we know that there are processes > > running, at least the process that loaded the module to borrow mm. > > > > This allows, for example, tests such as user_copy_kunit, which uses > > vm_mmap, which needs current->mm. > > > > Signed-off-by: Vitor Massaru Iha > > Can you put these together in the same patch series as you had before? > When I asked you to split the patch up, I was just asking about that > specific patch within the series. I still think all the patches go > together. Sure, I'll do that. > As for this specific patch, I see one minor issue below; other than > that, this looks good to me, so: > > Reviewed-by: Brendan Higgins > > > --- > > v2: > > * splitted patch in 3: > > - Allows to install and load modules in root filesystem; > > - Provides an userspace memory context when tests are compiled > > as module; > > - Convert test_user_copy to KUnit test; > > * added documentation; > > * added more explanation; > > * tested a pointer; > > * released mput(); > > --- > > Documentation/dev-tools/kunit/usage.rst | 14 ++++++++++++++ > > include/kunit/test.h | 12 ++++++++++++ > > lib/kunit/try-catch.c | 15 ++++++++++++++- > > 3 files changed, 40 insertions(+), 1 deletion(-) > > > > diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst > > index 3c3fe8b5fecc..9f909157be34 100644 > > --- a/Documentation/dev-tools/kunit/usage.rst > > +++ b/Documentation/dev-tools/kunit/usage.rst > > @@ -448,6 +448,20 @@ We can now use it to test ``struct eeprom_buffer``: > > > > .. _kunit-on-non-uml: > > > > +User-space context > > +------------------ > > + > > +I case you need a user-space context, for now this is only possible through > > +tests compiled as a module. And it will be necessary to use a root filesystem > > +and uml_utilities. > > + > > +Example: > > + > > +.. code-block:: bash > > + > > + ./tools/testing/kunit/kunit.py run --timeout=60 --uml_rootfs_dir=.uml_rootfs > > + > > + > > KUnit on non-UML architectures > > ============================== > > I think the above documentation change belongs in the other related > patch where you introduce the --uml_rootfs_dir flag. > > > diff --git a/include/kunit/test.h b/include/kunit/test.h > > index 59f3144f009a..ae3337139c65 100644 > > --- a/include/kunit/test.h > > +++ b/include/kunit/test.h > > @@ -222,6 +222,18 @@ struct kunit { > > * protect it with some type of lock. > > */ > > struct list_head resources; /* Protected by lock. */ > > + /* > > + * KUnit test cases run on kthreads, and kthreads don't have an > > + * adddress space (current->mm is NULL), but processes have mm. > > + * > > + * The purpose of this mm_struct is to allow to borrow mm to KUnit kthread > > + * after userspace is brought up, because we know that there are processes > > + * running, at least the process that loaded the module to borrow mm. > > + * > > + * This allows, for example, tests such as user_copy_kunit, which uses > > + * vm_mmap, which needs current->mm. > > + */ > > + 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..d03e2093985b 100644 > > --- a/lib/kunit/try-catch.c > > +++ b/lib/kunit/try-catch.c > > @@ -11,7 +11,8 @@ > > #include > > #include > > #include > > - > > +#include > > +#include > > #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 != NULL && test->mm != NULL) > > + kthread_use_mm(test->mm); > > > > try_catch->try(try_catch->context); > > + if (test != NULL && test->mm != NULL) { > > + kthread_unuse_mm(test->mm); > > + mmput(test->mm); > > + 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"); > > > > base-commit: 725aca9585956676687c4cb803e88f770b0df2b2 > > prerequisite-patch-id: 5e5f9a8a05c5680fda1b04c9ab1b95ce91dc88b2 > > prerequisite-patch-id: 4d997940f4a9f303424af9bac412de1af861f9d9 > > prerequisite-patch-id: 582b6d9d28ce4b71628890ec832df6522ca68de0 > > -- > > 2.26.2 > >