All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Vlastimil Babka <vbabka@kernel.org>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Pedro Falcato <pfalcato@suse.de>, Jann Horn <jannh@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Kees Cook <kees@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ollie Wild <aaw@google.com>, Adrian Bunk <bunk@stusta.de>,
	Xu Xin <xu.xin@linux.dev>,
	Chengming Zhou <chengming.zhou@linux.dev>,
	Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
	Hugh Dickins <hughd@google.com>, Joey Gouly <joey.gouly@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-mm@kvack.org, Chris Mason <mason@kernel.org>,
	Josef Bacik <josef@toxicpanda.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH 3/7] mm/ksm: only interrupt unmerging on a fatal signal
Date: Sun, 22 Nov 2026 16:54:27 +0100	[thread overview]
Message-ID: <fd2ba9f1-db7e-4d15-9860-4d3930898266@kernel.org> (raw)
In-Reply-To: <20261121-some-more-ai-fixes-v1-3-236e925d9b64@kernel.org>

On 11/21/26 17:02, Lorenzo Stoakes (ARM) wrote:
> Commit d952b79136a6 ("ksm: fix endless loop on oom") added a check for
> pending signals on KSM break, so that a lengthy unmerge could be
> interrupted, with the system call then restarted via -ERESTARTSYS.
> 
> However, it assumes that the callers can always restart whatever system
> call started it in the first place (the commit message questions whether
> this was wise).
> 
> Well, it turns out that it was not wise, as this baked in an implicit
> assumption about system call restartability, and it was and is not safe for
> mremap().
> 
> mremap() holds an mmap write lock over the operation, which an -ERESTARTSYS
> drops, meaning that the restart is not in a consistent state.
> 
> This was made considerably worse with commit d23cb648e365 ("mm/mremap:
> permit mremap() move of multiple VMAs"), which can result in data loss if
> you encounter this issue.
> 
> Consider an mremap() specifying MREMAP_FIXED | MREMAP_DONTUNMAP of two
> KSM-mergeable VMAs, where a signal becomes pending part way through:
> 
>     first pass                          restart
>     ==========                          =======
>     unmap tgt1 range
>     copy src1 to tgt1, move page tables
>     unmap tgt2 range
>     break_ksm(src2) = -ERESTARTSYS
>                                         unmap tgt1 range, which now
>                                           holds the data from src1
>                                         copy the now-empty src1 to tgt1
> 
> This results in the user observing a successful mremap() but with src1's
> data missing.
> 
> Without MREMAP_DONTUNMAP, remap_move() would find a gap at the start of the
> range on restart and fail with -EFAULT there instead.
> 
> Fix the issue by only breaking out of an unmerge if a fatal signal is
> pending, returning -EINTR when we do. This makes KSM unmerging consistent
> with many other signal checks in mm.
> 
> Target commit d23cb648e365 ("mm/mremap: permit mremap() move of multiple
> VMAs") for the fix as this made the issue significantly more impactful.
> 
> Reported-by: Chris Mason <mason@kernel.org>
> Fixes: d23cb648e365 ("mm/mremap: permit mremap() move of multiple VMAs")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
>  mm/ksm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 623a2cdb3924..5d320a200951 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -627,8 +627,8 @@ static int break_ksm_pmd_entry(pmd_t *pmdp, unsigned long addr, unsigned long en
>  
>  	if (ksm_test_exit(walk->mm))
>  		return 0;
> -	if (signal_pending(current))
> -		return -ERESTARTSYS;
> +	if (fatal_signal_pending(current))
> +		return -EINTR;
>  
>  	start_ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl);
>  	if (!start_ptep)
> 

Thanks, I'll queue this in mm-core for the next merge window.

Everything else can be merged by Andrew.

Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David

  parent reply	other threads:[~2026-11-22 15:54 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 16:02 [PATCH 0/7] mm: reworked AI-generated VMA and mremap fixes Lorenzo Stoakes (ARM)
2026-11-21 16:02 ` [PATCH 1/7] mm/vma: error out on invalid bounds in unmapped_area_topdown() Lorenzo Stoakes (ARM)
2026-11-22  3:20   ` Suren Baghdasaryan
2026-11-22 15:55   ` Gregory Price (Meta)
2026-11-22 18:03   ` Jose A. Perez de Azpillaga
2026-11-24 23:29   ` + mm-vma-error-out-on-invalid-bounds-in-unmapped_area_topdown.patch added to mm-new branch Andrew Morton
2026-11-21 16:02 ` [PATCH 2/7] mm/vma: lock VMAs before taking mm_all_locks_mutex Lorenzo Stoakes (ARM)
2026-11-22  3:23   ` Suren Baghdasaryan
2026-11-22 15:53   ` Gregory Price (Meta)
2026-11-22 18:03   ` Jose A. Perez de Azpillaga
2026-11-24 23:29   ` + mm-vma-lock-vmas-before-taking-mm_all_locks_mutex.patch added to mm-new branch Andrew Morton
2026-11-21 16:02 ` [PATCH 3/7] mm/ksm: only interrupt unmerging on a fatal signal Lorenzo Stoakes (ARM)
2026-11-22  3:27   ` Suren Baghdasaryan
2026-11-22 15:54   ` David Hildenbrand (Arm) [this message]
2026-11-22 15:56   ` Gregory Price (Meta)
2026-11-21 16:02 ` [PATCH 4/7] mm/vma: fix uncharge after failed stack relocation Lorenzo Stoakes (ARM)
2026-11-22  3:34   ` Suren Baghdasaryan
2026-11-22 15:50   ` Gregory Price (Meta)
2026-11-22 16:04   ` sashiko-bot
2026-11-24 23:29   ` + mm-vma-fix-uncharge-after-failed-stack-relocation.patch added to mm-new branch Andrew Morton
2026-11-21 16:02 ` [PATCH 5/7] mm/mremap: apply the mmap() offset limits on expansion Lorenzo Stoakes (ARM)
2026-11-22  3:37   ` Suren Baghdasaryan
2026-11-22 15:50   ` Gregory Price (Meta)
2026-11-22 18:03   ` Jose A. Perez de Azpillaga
2026-11-24 23:29   ` + mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch added to mm-new branch Andrew Morton
2026-11-21 16:02 ` [PATCH 6/7] mm/mremap: respect guard gaps on in-place expansion Lorenzo Stoakes (ARM)
2026-11-22  3:41   ` Suren Baghdasaryan
2026-11-22 15:49   ` Gregory Price (Meta)
2026-11-22 18:03   ` Jose A. Perez de Azpillaga
2026-11-24 23:29   ` + mm-mremap-respect-guard-gaps-on-in-place-expansion.patch added to mm-new branch Andrew Morton
2026-11-21 16:02 ` [PATCH 7/7] mm/vma: make brk mappings non-executable under MDWE Lorenzo Stoakes (ARM)
2026-11-22  3:46   ` Suren Baghdasaryan
2026-11-22 15:48   ` Gregory Price (Meta)
2026-11-22 18:03   ` Jose A. Perez de Azpillaga
2026-11-24 23:29   ` + mm-vma-make-brk-mappings-non-executable-under-mdwe.patch added to mm-new branch Andrew Morton
2026-11-22 15:55 ` (subset) [PATCH 0/7] mm: reworked AI-generated VMA and mremap fixes David Hildenbrand
2026-11-22 15:57 ` Gregory Price (Meta)

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=fd2ba9f1-db7e-4d15-9860-4d3930898266@kernel.org \
    --to=david@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=aaw@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=bunk@stusta.de \
    --cc=catalin.marinas@arm.com \
    --cc=chengming.zhou@linux.dev \
    --cc=hughd@google.com \
    --cc=jannh@google.com \
    --cc=joey.gouly@arm.com \
    --cc=josef@toxicpanda.com \
    --cc=kees@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mason@kernel.org \
    --cc=mhocko@suse.com \
    --cc=pfalcato@suse.de \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.org \
    --cc=xu.xin@linux.dev \
    /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.