git: 4e6e4fa8be99 - main - vm_object: Fix synchronization with teardown in the object list loop
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 18 Nov 2026 19:24:59 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=4e6e4fa8be9940e711b791073eee5bcfa77ec5d4
commit 4e6e4fa8be9940e711b791073eee5bcfa77ec5d4
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-11-18 16:36:09 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-18 19:24:35 +0000
vm_object: Fix synchronization with teardown in the object list loop
Checking for OBJT_DEAD is racy since pagers update the object type
without the object lock held. Check for the flag as well, as that is
set beforehand. Otherwise pager dealloc can race with, e.g.,
cdev_pager_get_path().
Try to minimize accesses of the object after dropping the object lock in
vm_object_list_handler().
---
sys/vm/vm_object.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index 1e6e25d26a54..b6f5e4983fd4 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -2523,7 +2523,7 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
vm_object_t obj;
vm_page_t m;
u_long sp;
- int count, error;
+ int count, error, flags;
key_t key;
unsigned short seq;
bool want_path;
@@ -2556,12 +2556,13 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
*/
mtx_lock(&vm_object_list_mtx);
TAILQ_FOREACH(obj, &vm_object_list, object_list) {
- if (obj->type == OBJT_DEAD ||
+ if (obj->type == OBJT_DEAD || (obj->flags & OBJ_DEAD) != 0 ||
(swap_only && (obj->flags & (OBJ_ANON | OBJ_SWAP)) == 0))
continue;
VM_OBJECT_RLOCK(obj);
- if (obj->type == OBJT_DEAD ||
- (swap_only && (obj->flags & (OBJ_ANON | OBJ_SWAP)) == 0)) {
+ flags = obj->flags;
+ if (obj->type == OBJT_DEAD || (flags & OBJ_DEAD) != 0 ||
+ (swap_only && (flags & (OBJ_ANON | OBJ_SWAP)) == 0)) {
VM_OBJECT_RUNLOCK(obj);
continue;
}
@@ -2604,7 +2605,7 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
NULL);
if (vp != NULL) {
vref(vp);
- } else if ((obj->flags & OBJ_ANON) != 0) {
+ } else if ((flags & OBJ_ANON) != 0) {
MPASS(kvo->kvo_type == KVME_TYPE_SWAP);
kvo->kvo_me = (uintptr_t)obj;
/* tmpfs objs are reported as vnodes */
@@ -2617,13 +2618,18 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
sizeof(kvo->kvo_path));
}
VM_OBJECT_RUNLOCK(obj);
- if ((obj->flags & OBJ_SYSVSHM) != 0) {
+
+ /*
+ * Note, it is safe to invoke shmobjinfo() and shm_get_path()
+ * concurrent with teardown of the object.
+ */
+ if ((flags & OBJ_SYSVSHM) != 0) {
kvo->kvo_flags |= KVMO_FLAG_SYSVSHM;
shmobjinfo(obj, &key, &seq);
kvo->kvo_vn_fileid = key;
kvo->kvo_vn_fsid_freebsd11 = seq;
}
- if ((obj->flags & OBJ_POSIXSHM) != 0) {
+ if ((flags & OBJ_POSIXSHM) != 0) {
kvo->kvo_flags |= KVMO_FLAG_POSIXSHM;
shm_get_path(obj, kvo->kvo_path,
sizeof(kvo->kvo_path));