Skip to content

Commit 20bf82a

Browse files
josefbacikjankara
authored andcommitted
mm: don't allow huge faults for files with pre content watches
There's nothing stopping us from supporting this, we could simply pass the order into the helper and emit the proper length. However currently there's no tests to validate this works properly, so disable it until there's a desire to support this along with the appropriate tests. Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/9035b82cff08a3801cef3d06bbf2778b2e5a4dba.1731684329.git.josef@toxicpanda.com
1 parent fac8484 commit 20bf82a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

mm/memory.c

+19
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include <linux/ptrace.h>
7777
#include <linux/vmalloc.h>
7878
#include <linux/sched/sysctl.h>
79+
#include <linux/fsnotify.h>
7980

8081
#include <trace/events/kmem.h>
8182

@@ -5662,8 +5663,17 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf)
56625663
static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf)
56635664
{
56645665
struct vm_area_struct *vma = vmf->vma;
5666+
56655667
if (vma_is_anonymous(vma))
56665668
return do_huge_pmd_anonymous_page(vmf);
5669+
/*
5670+
* Currently we just emit PAGE_SIZE for our fault events, so don't allow
5671+
* a huge fault if we have a pre content watch on this file. This would
5672+
* be trivial to support, but there would need to be tests to ensure
5673+
* this works properly and those don't exist currently.
5674+
*/
5675+
if (unlikely(FMODE_FSNOTIFY_HSM(vma->vm_file->f_mode)))
5676+
return VM_FAULT_FALLBACK;
56675677
if (vma->vm_ops->huge_fault)
56685678
return vma->vm_ops->huge_fault(vmf, PMD_ORDER);
56695679
return VM_FAULT_FALLBACK;
@@ -5687,6 +5697,9 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf)
56875697
}
56885698

56895699
if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) {
5700+
/* See comment in create_huge_pmd. */
5701+
if (unlikely(FMODE_FSNOTIFY_HSM(vma->vm_file->f_mode)))
5702+
goto split;
56905703
if (vma->vm_ops->huge_fault) {
56915704
ret = vma->vm_ops->huge_fault(vmf, PMD_ORDER);
56925705
if (!(ret & VM_FAULT_FALLBACK))
@@ -5709,6 +5722,9 @@ static vm_fault_t create_huge_pud(struct vm_fault *vmf)
57095722
/* No support for anonymous transparent PUD pages yet */
57105723
if (vma_is_anonymous(vma))
57115724
return VM_FAULT_FALLBACK;
5725+
/* See comment in create_huge_pmd. */
5726+
if (unlikely(FMODE_FSNOTIFY_HSM(vma->vm_file->f_mode)))
5727+
return VM_FAULT_FALLBACK;
57125728
if (vma->vm_ops->huge_fault)
57135729
return vma->vm_ops->huge_fault(vmf, PUD_ORDER);
57145730
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
@@ -5726,6 +5742,9 @@ static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud)
57265742
if (vma_is_anonymous(vma))
57275743
goto split;
57285744
if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) {
5745+
/* See comment in create_huge_pmd. */
5746+
if (unlikely(FMODE_FSNOTIFY_HSM(vma->vm_file->f_mode)))
5747+
goto split;
57295748
if (vma->vm_ops->huge_fault) {
57305749
ret = vma->vm_ops->huge_fault(vmf, PUD_ORDER);
57315750
if (!(ret & VM_FAULT_FALLBACK))

0 commit comments

Comments
 (0)