Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: switch the rmap lock held option off in compat layer

In the mmap_prepare compatibility layer, we don't need to hold the rmap
lock, as we are being called from an .mmap handler.

The .mmap_prepare hook, when invoked in the VMA logic, is called prior to
the VMA being instantiated, but the completion hook is called after the VMA
is linked into the maple tree, meaning rmap walkers can reach it.

The mmap hook does not link the VMA into the tree, so this cannot happen.

Therefore it's safe to simply disable this in the mmap_prepare
compatibility layer.

Also update VMA tests code to reflect current compatibility layer state.

[akpm@linux-foundation.org: fix comment typo, per Vlastimil]
Link: https://lkml.kernel.org/r/dda74230d26a1fcd79a3efab61fa4101dd1cac64.1774045440.git.ljs@kernel.org
Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bodo Stroesser <bostroesser@gmail.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Clemens Ladisch <clemens@ladisch.de>
Cc: David Hildenbrand <david@kernel.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: K. Y. Srinivasan <kys@microsoft.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Long Li <longli@microsoft.com>
Cc: Marc Dionne <marc.dionne@auristor.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Richard Weinberger <richard@nod.at>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: Wei Liu <wei.liu@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes (Oracle) and committed by
Andrew Morton
33506d4b f96e1d5f

+27 -21
+5 -1
mm/util.c
··· 1204 1204 1205 1205 .action.type = MMAP_NOTHING, /* Default */ 1206 1206 }; 1207 + struct mmap_action *action = &desc.action; 1207 1208 int err; 1208 1209 1209 1210 err = vfs_mmap_prepare(file, &desc); ··· 1215 1214 if (err) 1216 1215 return err; 1217 1216 1217 + /* being invoked from .mmap means we don't have to enforce this. */ 1218 + action->hide_from_rmap_until_complete = false; 1219 + 1218 1220 set_vma_from_desc(vma, &desc); 1219 - err = mmap_action_complete(vma, &desc.action); 1221 + err = mmap_action_complete(vma, action); 1220 1222 if (err) { 1221 1223 const size_t len = vma_pages(vma) << PAGE_SHIFT; 1222 1224
+22 -20
tools/testing/vma/include/dup.h
··· 1260 1260 static inline void set_vma_from_desc(struct vm_area_struct *vma, 1261 1261 struct vm_area_desc *desc); 1262 1262 1263 - static inline int __compat_vma_mmap(const struct file_operations *f_op, 1264 - struct file *file, struct vm_area_struct *vma) 1263 + static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc) 1264 + { 1265 + return file->f_op->mmap_prepare(desc); 1266 + } 1267 + 1268 + static inline unsigned long vma_pages(struct vm_area_struct *vma) 1269 + { 1270 + return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; 1271 + } 1272 + 1273 + static inline int compat_vma_mmap(struct file *file, struct vm_area_struct *vma) 1265 1274 { 1266 1275 struct vm_area_desc desc = { 1267 1276 .mm = vma->vm_mm, ··· 1285 1276 1286 1277 .action.type = MMAP_NOTHING, /* Default */ 1287 1278 }; 1279 + struct mmap_action *action = &desc.action; 1288 1280 int err; 1289 1281 1290 - err = f_op->mmap_prepare(&desc); 1282 + err = vfs_mmap_prepare(file, &desc); 1291 1283 if (err) 1292 1284 return err; 1293 1285 ··· 1296 1286 if (err) 1297 1287 return err; 1298 1288 1289 + /* being invoked from .mmmap means we don't have to enforce this. */ 1290 + action->hide_from_rmap_until_complete = false; 1291 + 1299 1292 set_vma_from_desc(vma, &desc); 1300 - return mmap_action_complete(vma, &desc.action); 1301 - } 1293 + err = mmap_action_complete(vma, action); 1294 + if (err) { 1295 + const size_t len = vma_pages(vma) << PAGE_SHIFT; 1302 1296 1303 - static inline int compat_vma_mmap(struct file *file, 1304 - struct vm_area_struct *vma) 1305 - { 1306 - return __compat_vma_mmap(file->f_op, file, vma); 1297 + do_munmap(current->mm, vma->vm_start, len, NULL); 1298 + } 1299 + return err; 1307 1300 } 1308 - 1309 1301 1310 1302 static inline void vma_iter_init(struct vma_iterator *vmi, 1311 1303 struct mm_struct *mm, unsigned long addr) 1312 1304 { 1313 1305 mas_init(&vmi->mas, &mm->mm_mt, addr); 1314 - } 1315 - 1316 - static inline unsigned long vma_pages(struct vm_area_struct *vma) 1317 - { 1318 - return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; 1319 1306 } 1320 1307 1321 1308 static inline void mmap_assert_locked(struct mm_struct *); ··· 1482 1475 return compat_vma_mmap(file, vma); 1483 1476 1484 1477 return file->f_op->mmap(file, vma); 1485 - } 1486 - 1487 - static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc) 1488 - { 1489 - return file->f_op->mmap_prepare(desc); 1490 1478 } 1491 1479 1492 1480 static inline void vma_set_file(struct vm_area_struct *vma, struct file *file)