On Mon, Oct 28, 2024 at 10:28:47PM +0100, Vlastimil Babka wrote: > On 10/28/24 22:19, Linus Torvalds wrote: > > On Mon, 28 Oct 2024 at 11:00, Vlastimil Babka <vbabka@xxxxxxx> wrote: > >> > >> VM_MTE_ALLOWED is also set by arm64's arch_calc_vm_flag_bits(): > >> > >> if (system_supports_mte() && (flags & MAP_ANONYMOUS)) > >> return VM_MTE_ALLOWED; > > > > Yeah, but that should just move into arch_validate_flags() too. > > There's no reason why that's done in a separate place. > > > > Linus > > Right, and VM_DATA_DEFAULT_FLAGS is only used in do_brk_flags() which is > also an anonymous VMA, and it doesn't perform arch_validate_flags() anyway. Unfortunately we can't do this and have everything work entirely consistently. This is because, while adding a file parameter to arch_validate_flags() lets us do this shmem check, we can't be sure MAP_ANON was set and we do not have access to this information at the point of the arch_validate_flags() check. We could check file == NULL, but this then excludes the MAP_ANON | MAP_HUGETLB case which is (probably accidentally) permitted by arch_calc_vm_flag_bits() and for the purposes of this fix we probably just want to keep behaviour identical. We could alternatively check the file is shmem _or_ hugetlb but this would amount to a change in behaviour and not sure we want to go there. Anyway I attach a patch that does what you suggest, I actually compiled this one (!) but don't have a system set up to test it (Mark?) If we bring this in it should probably be a separate commit... ----8<----