From: Suren Baghdasaryan <surenb@google.com>
To: akpm@linux-foundation.org
Cc: willy@infradead.org, torvalds@linuxfoundation.org,
vegard.nossum@oracle.com, mpe@ellerman.id.au,
Liam.Howlett@oracle.com, lrh2000@pku.edu.cn, mgorman@suse.de,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
kernel-team@android.com, surenb@google.com
Subject: [PATCH 2/3] mm: change vma_start_read to fail to lock a detached VMA
Date: Tue, 20 Jun 2023 16:57:25 -0700 [thread overview]
Message-ID: <20230620235726.3873043-2-surenb@google.com> (raw)
In-Reply-To: <20230620235726.3873043-1-surenb@google.com>
vma_start_read can successfully lock a detached VMA relying on its
caller to check for vma->detached. Change vma_start_read to include that
check and fail if the VMA got detached.
Suggested-by: Linus Torvalds <torvalds@linuxfoundation.org>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
include/linux/mm.h | 4 ++--
include/linux/vm_event_item.h | 1 -
mm/memory.c | 10 +---------
mm/vmstat.c | 1 -
4 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8410da79c570..74e3033c9fc2 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -651,8 +651,8 @@ static inline bool vma_start_read(struct vm_area_struct *vma)
if (unlikely(down_read_trylock(&vma->vm_lock->lock) == 0))
return false;
- /* Fail if VMA was write-locked after we checked it earlier */
- if (unlikely(vm_lock_seq != READ_ONCE(vma->vm_lock_seq))) {
+ /* Fail if VMA is detached or was write-locked after we checked it earlier */
+ if (unlikely(vma->detached || vm_lock_seq != READ_ONCE(vma->vm_lock_seq))) {
up_read(&vma->vm_lock->lock);
return false;
}
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 8abfa1240040..e741098954ff 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -154,7 +154,6 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
VMA_LOCK_SUCCESS,
VMA_LOCK_ABORT,
VMA_LOCK_RETRY,
- VMA_LOCK_MISS,
#endif
NR_VM_EVENT_ITEMS
};
diff --git a/mm/memory.c b/mm/memory.c
index f69fbc251198..bd666fa20748 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5275,7 +5275,7 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm,
struct vm_area_struct *vma;
rcu_read_lock();
-retry:
+
vma = mas_walk(&mas);
if (!vma)
goto inval;
@@ -5306,14 +5306,6 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm,
goto inval;
}
- /* Check if the VMA got isolated after we found it */
- if (vma->detached) {
- vma_end_read(vma);
- count_vm_vma_lock_event(VMA_LOCK_MISS);
- /* The area was replaced with another one */
- goto retry;
- }
-
rcu_read_unlock();
return vma;
inval:
diff --git a/mm/vmstat.c b/mm/vmstat.c
index c28046371b45..5d6acdb1b611 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1403,7 +1403,6 @@ const char * const vmstat_text[] = {
"vma_lock_success",
"vma_lock_abort",
"vma_lock_retry",
- "vma_lock_miss",
#endif
#endif /* CONFIG_VM_EVENT_COUNTERS || CONFIG_MEMCG */
};
--
2.41.0.162.gfafddb0af9-goog
next prev parent reply other threads:[~2023-06-20 23:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-20 23:57 [PATCH 1/3] mm: change vma_start_read to fail if VMA got detached from under it Suren Baghdasaryan
2023-06-20 23:57 ` Suren Baghdasaryan [this message]
2023-06-20 23:57 ` [PATCH 3/3] mm: check for VMA being detached before destroying it Suren Baghdasaryan
2023-06-21 0:05 ` Suren Baghdasaryan
2023-06-21 2:15 ` kernel test robot
2023-06-21 7:01 ` Suren Baghdasaryan
2023-06-21 5:53 ` kernel test robot
2023-06-26 20:51 ` [PATCH 1/3] mm: change vma_start_read to fail if VMA got detached from under it Suren Baghdasaryan
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=20230620235726.3873043-2-surenb@google.com \
--to=surenb@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lrh2000@pku.edu.cn \
--cc=mgorman@suse.de \
--cc=mpe@ellerman.id.au \
--cc=torvalds@linuxfoundation.org \
--cc=vegard.nossum@oracle.com \
--cc=willy@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).