From: David Gow <davidgow@google.com>
To: Brendan Jackman <jackmanb@google.com>
Cc: Brendan Higgins <brendan.higgins@linux.dev>,
Rae Moar <raemoar63@gmail.com>, Kees Cook <kees@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 1/3] kunit: test: Delete pointless resource API usage
Date: Mon, 5 Jan 2026 17:56:05 +0800 [thread overview]
Message-ID: <CABVgOSn8UjWjEe-FNfOBSpZiBL0797VvJQZOOGp5QB6tv52COQ@mail.gmail.com> (raw)
In-Reply-To: <20251223-b4-kunit-user-alloc-v1-1-fb910ae0e50c@google.com>
[-- Attachment #1: Type: text/plain, Size: 3769 bytes --]
On Wed, 24 Dec 2025 at 00:18, Brendan Jackman <jackmanb@google.com> wrote:
>
> This code uses the low-level resource API to track parameters of the
> vm_mmap call, but it doesn't do anything with them, because the mm
> teardown code takes care of tearing down the mmaps. Delete it.
>
> Signed-off-by: Brendan Jackman <jackmanb@google.com>
> ---
This makes sense. Maybe there's a case where tracking mmaps as
resources could be useful in the future, but I can't think of any off
the top of my head, so this is just wasteful for now.
Reviewed-by: David Gow <davidgow@google.com>
Cheers,
-- David
> lib/kunit/user_alloc.c | 76 ++++----------------------------------------------
> 1 file changed, 6 insertions(+), 70 deletions(-)
>
> diff --git a/lib/kunit/user_alloc.c b/lib/kunit/user_alloc.c
> index b8cac765e6204..564f5566641d5 100644
> --- a/lib/kunit/user_alloc.c
> +++ b/lib/kunit/user_alloc.c
> @@ -7,21 +7,6 @@
> #include <linux/kthread.h>
> #include <linux/mm.h>
>
> -struct kunit_vm_mmap_resource {
> - unsigned long addr;
> - size_t size;
> -};
> -
> -/* vm_mmap() arguments */
> -struct kunit_vm_mmap_params {
> - struct file *file;
> - unsigned long addr;
> - unsigned long len;
> - unsigned long prot;
> - unsigned long flag;
> - unsigned long offset;
> -};
> -
> int kunit_attach_mm(void)
> {
> struct mm_struct *mm;
> @@ -50,67 +35,18 @@ int kunit_attach_mm(void)
> }
> EXPORT_SYMBOL_GPL(kunit_attach_mm);
>
> -static int kunit_vm_mmap_init(struct kunit_resource *res, void *context)
> -{
> - struct kunit_vm_mmap_params *p = context;
> - struct kunit_vm_mmap_resource vres;
> - int ret;
> -
> - ret = kunit_attach_mm();
> - if (ret)
> - return ret;
> -
> - vres.size = p->len;
> - vres.addr = vm_mmap(p->file, p->addr, p->len, p->prot, p->flag, p->offset);
> - if (!vres.addr)
> - return -ENOMEM;
> - res->data = kmemdup(&vres, sizeof(vres), GFP_KERNEL);
> - if (!res->data) {
> - vm_munmap(vres.addr, vres.size);
> - return -ENOMEM;
> - }
> -
> - return 0;
> -}
> -
> -static void kunit_vm_mmap_free(struct kunit_resource *res)
> -{
> - struct kunit_vm_mmap_resource *vres = res->data;
> -
> - /*
> - * Since this is executed from the test monitoring process,
> - * the test's mm has already been torn down. We don't need
> - * to run vm_munmap(vres->addr, vres->size), only clean up
> - * the vres.
> - */
> -
> - kfree(vres);
> - res->data = NULL;
> -}
> -
> unsigned long kunit_vm_mmap(struct kunit *test, struct file *file,
> unsigned long addr, unsigned long len,
> unsigned long prot, unsigned long flag,
> unsigned long offset)
> {
> - struct kunit_vm_mmap_params params = {
> - .file = file,
> - .addr = addr,
> - .len = len,
> - .prot = prot,
> - .flag = flag,
> - .offset = offset,
> - };
> - struct kunit_vm_mmap_resource *vres;
> + int err;
>
> - vres = kunit_alloc_resource(test,
> - kunit_vm_mmap_init,
> - kunit_vm_mmap_free,
> - GFP_KERNEL,
> - ¶ms);
> - if (vres)
> - return vres->addr;
> - return 0;
> + err = kunit_attach_mm();
> + if (err)
> + return err;
> +
> + return vm_mmap(file, addr, len, prot, flag, offset);
> }
> EXPORT_SYMBOL_GPL(kunit_vm_mmap);
>
>
> --
> 2.51.2
>
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5281 bytes --]
next prev parent reply other threads:[~2026-01-05 9:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-23 16:18 [PATCH 0/3] EDITME: cover title for b4/kunit-user-alloc Brendan Jackman
2025-12-23 16:18 ` [PATCH 1/3] kunit: test: Delete pointless resource API usage Brendan Jackman
2026-01-05 9:56 ` David Gow [this message]
2025-12-23 16:18 ` [PATCH 2/3] kthread: Add kthread_take_mm() Brendan Jackman
2026-01-05 9:56 ` David Gow
2026-01-05 10:52 ` Brendan Jackman
2025-12-23 16:18 ` [PATCH 3/3] kunit: test: fix mm_struct leak in kunit_attach_mm() Brendan Jackman
2026-01-05 9:56 ` David Gow
2025-12-23 16:46 ` [PATCH 0/3] EDITME: cover title for b4/kunit-user-alloc Brendan Jackman
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=CABVgOSn8UjWjEe-FNfOBSpZiBL0797VvJQZOOGp5QB6tv52COQ@mail.gmail.com \
--to=davidgow@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=brendan.higgins@linux.dev \
--cc=bsegall@google.com \
--cc=david@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=jackmanb@google.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=raemoar63@gmail.com \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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