Commit 5543d3c
mm/uffd: allow vma to merge as much as possible
We used to not pass in the pgoff correctly when register/unregister uffd
regions, it caused incorrect behavior on vma merging and can cause
mergeable vmas being separate after ioctls return.
For example, when we have:
vma1(range 0-9, with uffd), vma2(range 10-19, no uffd)
Then someone unregisters uffd on range (5-9), it should logically become:
vma1(range 0-4, with uffd), vma2(range 5-19, no uffd)
But with current code we'll have:
vma1(range 0-4, with uffd), vma3(range 5-9, no uffd), vma2(range 10-19, no uffd)
This patch allows such merge to happen correctly before ioctl returns.
This behavior seems to have existed since the 1st day of uffd. Since
pgoff for vma_merge() is only used to identify the possibility of vma
merging, meanwhile here what we did was always passing in a pgoff smaller
than what we should, so there should have no other side effect besides not
merging it. Let's still tentatively copy stable for this, even though I
don't see anything will go wrong besides vma being split (which is mostly
not user visible).
Link: https://lkml.kernel.org/r/20230517190916.3429499-3-peterx@redhat.com
Fixes: 86039bd ("userfaultfd: add new syscall to provide memory externalization")
Signed-off-by: Peter Xu <peterx@redhat.com>
Reported-by: Lorenzo Stoakes <lstoakes@gmail.com>
Acked-by: Lorenzo Stoakes <lstoakes@gmail.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>1 parent 270aa01 commit 5543d3c
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1332 | 1332 | | |
1333 | 1333 | | |
1334 | 1334 | | |
| 1335 | + | |
1335 | 1336 | | |
1336 | 1337 | | |
1337 | 1338 | | |
| |||
1484 | 1485 | | |
1485 | 1486 | | |
1486 | 1487 | | |
| 1488 | + | |
1487 | 1489 | | |
1488 | | - | |
| 1490 | + | |
1489 | 1491 | | |
1490 | 1492 | | |
1491 | 1493 | | |
| |||
1565 | 1567 | | |
1566 | 1568 | | |
1567 | 1569 | | |
| 1570 | + | |
1568 | 1571 | | |
1569 | 1572 | | |
1570 | 1573 | | |
| |||
1667 | 1670 | | |
1668 | 1671 | | |
1669 | 1672 | | |
| 1673 | + | |
1670 | 1674 | | |
1671 | | - | |
| 1675 | + | |
1672 | 1676 | | |
1673 | 1677 | | |
1674 | 1678 | | |
| |||
0 commit comments