Re: [PATCH] mm: thp: Deny THP for guest_memfd and secretmem in file_thp_enabled()

From: David Hildenbrand (Arm)

Date: Tue Feb 10 2026 - 04:36:18 EST


On 2/10/26 02:51, Deepanshu Kartikey wrote:
On Tue, Feb 10, 2026 at 1:43 AM David Hildenbrand (Arm)
<david@xxxxxxxxxx> wrote:


The following is a bit nasty as well but should do the trick until we rip
out the CONFIG_READ_ONLY_THP_FOR_FS stuff.


diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 03886d4ccecc..4ac1cb36b861 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -40,6 +40,7 @@
#include <linux/pgalloc.h>
#include <linux/pgalloc_tag.h>
#include <linux/pagewalk.h>
+#include <linux/secretmem.h>

#include <asm/tlb.h>
#include "internal.h"
@@ -94,6 +95,10 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma)

inode = file_inode(vma->vm_file);

+ if (mapping_inaccessible(inode->i_mapping) ||
+ secretmem_mapping(inode->i_mapping))
+ return false;
+
return !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
}



Hi David,

Agreed, using mapping_inaccessible() for guest_memfd and
secretmem_mapping() for secretmem is much simpler than introducing a
new AS flag. No changes needed outside of file_thp_enabled().

I will send a v2 with your suggested diff and test it on syzbot.

Let's wait a bit until we are in agreement that this is the right thing to do :)

--
Cheers,

David