Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp847292ybh; Wed, 15 Jul 2020 17:37:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxznnLar4CjupQKWQV28+yWbO9aPuZgjqGOzQrFHSgfDwT3zHwIIl4/zO6Y+r3qURrkUyDG X-Received: by 2002:a05:6402:1d97:: with SMTP id dk23mr2155111edb.1.1594859870225; Wed, 15 Jul 2020 17:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594859870; cv=none; d=google.com; s=arc-20160816; b=rv8n2IN7ErUU2eh+V1xG+Vvo4A0t2ObaHQYO7/k6hSP1IC8P4UjTyemIVtHvp0nnbA 17Nu/xCxunKm+4kQ+jM1Zsdplk/qCYEqv5buhW9wJ0CQphg8FhIcXDXjPamqiqTloa0M k7fGEJlppVti+8L72zzIjS5/674mC4bj3V+uwzh/sPjqyUS6I9LsaBGvq1v0+ZspwtvV 5gwyJHH0ZpN0+UZbly5PjRIVSHR3O5vgl6YhfzG9eIXY8vX0pUT+Hodgaf4TIyczp1Ei wUa+tdh+zAWjnbpwwIn6dbJfdAP9ennIRHgPK8MvndTxxnlH14RDey5aEq4jmqVno4sX EcXA== 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=mVodWiEHQkq0E0nBn3v+yTDqfSzN287V6yNqrTXAono=; b=xca9b1qH9s0fbNN7WUMCYFC1KrNMp/QnMujiMiTVftrLMErqjEpSviSr5sh87Rj+wO DEo+P8QwsjyJ/qr/p+sz1Dt8ZP+btE98QdA+D9KK9MF/jH57zUw3qyks+f5HqC+aiZ2k xORv4oJac9QsOZSKR3Xt90wCfv59eQCpTl8FtNzp/LfVVMXs4lTxwG2B7FBeLbAI0+O9 iTgPdAVSFN6Ru1RhxVwx/P2HiA1a69txfNszB5qBI+04adUs3Hnl4LPhV1quHwmYNzj3 OmRdU9zSQg6X+8I05v1oH+uHTE+HbZCbBzaUotAwuOd3ELJj0SOBfELu0AzUe1FHh1qZ /o8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DFRDIY5f; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw21si2113948edb.600.2020.07.15.17.37.27; Wed, 15 Jul 2020 17:37:50 -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=@google.com header.s=20161025 header.b=DFRDIY5f; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbgGPAhT (ORCPT + 99 others); Wed, 15 Jul 2020 20:37:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727042AbgGPAhS (ORCPT ); Wed, 15 Jul 2020 20:37:18 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FD5FC08C5CE for ; Wed, 15 Jul 2020 17:37:18 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id z3so2850728pfn.12 for ; Wed, 15 Jul 2020 17:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mVodWiEHQkq0E0nBn3v+yTDqfSzN287V6yNqrTXAono=; b=DFRDIY5fVPO+tRVNaoPThKmwQLGgQrirP047p4B4mIhpL3deqJvaKcI6gRIHq2khNf F2HBJTLyaJ0AOeUJMrdPmoZXu1MX6JIUNyHpWyKuJmvM4f/vwPug1KfLEUZ9EumRKA8+ BDV3AXymAZFVYqoNfq8/LWIfCLKe5k65NnSlI0GlLgzpaZG5zzpqmG/4uDVihsjMcOeU RRYscvBpSrSYR2qq/IoM2yj8IHgx7LEJk22IysJ1llJHOVowsOCwtN28MeycXUYHEswY ai80mqr23WL40hFdEbfuHRotDCTONfWYWb3obD3Hmh1+8qpd3YxhafkepdkyH2YmY3R0 59FA== 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=mVodWiEHQkq0E0nBn3v+yTDqfSzN287V6yNqrTXAono=; b=TQqDSsfV/WkL6IlewVAlrmaE29IyWi0LBCHd2mOgrY41fgBJzp2lWwZl/Uxu0zPbhg 7T5MPBhqxTdra9rcftpY2pbATgcRqInnbS44ICjvsO5R1fDecbNGUb1UBESfcChiUZwa MOjh2+2Gc30o4PKCBcDYPQWqJiiY+KQdWPF+CuV0Z6gv11nejTOXagbaWHGhQBWXBqhZ ACKSqopaKTx9+svrGgP9EtxaijQuIVIk375OsphD9BscJ1ZmdPaR0Xa6flXgrq/OZfQX sVH+t/iUWpM4thobZdza3gVIFGKuTGfgO1CW6z1kfe5U4R5JEErsKI7ptggqbBh9fMLa zj1A== X-Gm-Message-State: AOAM533bxcxYqyaZ3VxsnhQsr05bcri0Qu98hChk7zIg4Z/KuxNO9fQ8 +/4H5i0qYEbZvZVDweF5hwH3ua97EPVSgKsh3DTdQCXI X-Received: by 2002:a63:6e0e:: with SMTP id j14mr1944707pgc.384.1594859837823; Wed, 15 Jul 2020 17:37:17 -0700 (PDT) MIME-Version: 1.0 References: <20200715031120.1002016-1-vitor@massaru.org> <20200715031120.1002016-3-vitor@massaru.org> In-Reply-To: <20200715031120.1002016-3-vitor@massaru.org> From: Brendan Higgins Date: Wed, 15 Jul 2020 17:37:06 -0700 Message-ID: Subject: Re: [RFC 2/3] lib: Allows to borrow mm in userspace on KUnit To: Vitor Massaru Iha 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 Tue, Jul 14, 2020 at 8:11 PM Vitor Massaru Iha wrote: Probably want to add more of a description here as what you are doing is not entirely trivial to someone not familiar with mm contexts. > > Signed-off-by: Vitor Massaru Iha > --- > 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; Part of me thinks we should put a better name here, part of me thinks it is fine because it matches the convention. Either way, this DEFINITELY deserves a comment explaining what it is, why it exists, and how it should/shouldn't be used. > }; > > 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 > #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->mm != NULL) > + kthread_use_mm(try_catch->test->mm); > > try_catch->try(try_catch->context); > + if (try_catch->test->mm) { Here and below: You already have a pointer to test. You should use it. > + 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 >