All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harry Yoo <harry.yoo@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: mm-commits@vger.kernel.org, ryabinin.a.a@gmail.com,
	dja@axtens.net, agordeev@linux.ibm.com
Subject: Re: + kasan-avoid-sleepable-page-allocation-from-atomic-context-v7.patch added to mm-hotfixes-unstable branch
Date: Tue, 13 May 2025 08:50:56 +0900	[thread overview]
Message-ID: <aCKJYHPL_3xAewUB@hyeyoo> (raw)
In-Reply-To: <20250512222307.ABA4FC4CEE7@smtp.kernel.org>

On Mon, May 12, 2025 at 03:23:07PM -0700, Andrew Morton wrote:
> 
> The patch titled
>      Subject: kasan-avoid-sleepable-page-allocation-from-atomic-context-v7
> has been added to the -mm mm-hotfixes-unstable branch.  Its filename is
>      kasan-avoid-sleepable-page-allocation-from-atomic-context-v7.patch
> 
> This patch will shortly appear at
>      https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/kasan-avoid-sleepable-page-allocation-from-atomic-context-v7.patch__;!!ACWV5N9M2RV99hQ!IDZGs5LvdWUbyEOsjCGQ9n4Rk5nHMYzHfbAvvr0U07eEBuITVQjUmFA0nvwv6w4E_2SDwb99rlhHW1qS4ZW84Q$ 
> 
> This patch will later appear in the mm-hotfixes-unstable branch at
>     git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> 
> Before you just go and hit "reply", please:
>    a) Consider who else should be cc'ed
>    b) Prefer to cc a suitable mailing list as well
>    c) Ideally: find the original patch on the mailing list and do a
>       reply-to-all to that, adding suitable additional cc's
> 
> *** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
> 
> The -mm tree is included into linux-next via the mm-everything
> branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> and is updated there every 2-3 working days
> 
> ------------------------------------------------------
> From: Alexander Gordeev <agordeev@linux.ibm.com>
> Subject: kasan-avoid-sleepable-page-allocation-from-atomic-context-v7
> Date: Mon, 12 May 2025 16:27:06 +0200
> 
> do not unnecessary free pages across iterations
> 
> Link: https://urldefense.com/v3/__https://lkml.kernel.org/r/c8eeeb146382bcadabce5b5dcf92e6176ba4fb04.1747059374.git.agordeev@linux.ibm.com__;!!ACWV5N9M2RV99hQ!IDZGs5LvdWUbyEOsjCGQ9n4Rk5nHMYzHfbAvvr0U07eEBuITVQjUmFA0nvwv6w4E_2SDwb99rlhHW1oEPUM6Aw$ 
> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
> Suggested-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
> Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
> Cc: Daniel Axtens <dja@axtens.net>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---

Andrew, please drop this patch                                                  
(kasan-avoid-sleepable-page-allocation-from-atomic-context-v7.patch).           
                                                                                
v7 has a memory leak and after discussing with Alexander this                   
'optimization' doesn't seem worth here.                                         
                                                                                
But as Alexander mentioned v6 also has a memory leak in an error case,
and I believe a proper fix to that should be (lightly tested on my box)
below.

And with the change below on top of v6, it looks good to me.
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>

diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c
index 660cc2148575..8212a7007b02 100644
--- a/mm/kasan/shadow.c
+++ b/mm/kasan/shadow.c
@@ -339,7 +339,7 @@ static int __kasan_populate_vmalloc(unsigned long start, unsigned long end)
 {
 	unsigned long nr_populated, nr_pages, nr_total = PFN_UP(end - start);
 	struct vmalloc_populate_data data;
-	int ret;
+	int ret = 0;
 
 	data.pages = (struct page **)__get_free_page(GFP_KERNEL | __GFP_ZERO);
 	if (!data.pages)
@@ -350,8 +350,8 @@ static int __kasan_populate_vmalloc(unsigned long start, unsigned long end)
 		nr_populated = alloc_pages_bulk(GFP_KERNEL, nr_pages, data.pages);
 		if (nr_populated != nr_pages) {
 			free_pages_bulk(data.pages, nr_populated);
-			free_page((unsigned long)data.pages);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			break;
 		}
 
 		data.start = start;
@@ -359,7 +359,7 @@ static int __kasan_populate_vmalloc(unsigned long start, unsigned long end)
 					  kasan_populate_vmalloc_pte, &data);
 		free_pages_bulk(data.pages, nr_pages);
 		if (ret)
-			return ret;
+			break;
 
 		start += nr_pages * PAGE_SIZE;
 		nr_total -= nr_pages;
@@ -367,7 +367,7 @@ static int __kasan_populate_vmalloc(unsigned long start, unsigned long end)
 
 	free_page((unsigned long)data.pages);
 
-	return 0;
+	return ret;
 }
 
 int kasan_populate_vmalloc(unsigned long addr, unsigned long size)

-- 
Cheers,
Harry / Hyeonggon

  reply	other threads:[~2025-05-12 23:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12 22:23 + kasan-avoid-sleepable-page-allocation-from-atomic-context-v7.patch added to mm-hotfixes-unstable branch Andrew Morton
2025-05-12 23:50 ` Harry Yoo [this message]
2025-05-13  1:14   ` Andrew Morton

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=aCKJYHPL_3xAewUB@hyeyoo \
    --to=harry.yoo@oracle.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=dja@axtens.net \
    --cc=mm-commits@vger.kernel.org \
    --cc=ryabinin.a.a@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.