Re: [PATCH] ipc/shm.c add ->pagesize function to shm_vm_ops

From: Andrew Morton
Date: Fri Jul 27 2018 - 17:50:15 EST


On Fri, 27 Jul 2018 15:17:27 -0600 Jane Chu <jane.chu@xxxxxxxxxx> wrote:

> Commit 05ea88608d4e13 (mm, hugetlbfs: introduce ->pagesize() to
> vm_operations_struct) adds a new ->pagesize() function to
> hugetlb_vm_ops, intended to cover all hugetlbfs backed files.

That was merged three months ago. Can you suggest why this was only
noticed now?

What workload triggered this? I see no cc:stable, but 4.17 is affected?

> With System V shared memory model, if "huge page" is specified,
> the "shared memory" is backed by hugetlbfs files, but the mappings
> initiated via shmget/shmat have their original vm_ops overwritten
> with shm_vm_ops, so we need to add a ->pagesize function to shm_vm_ops.
> Otherwise, vma_kernel_pagesize() returns PAGE_SIZE given a hugetlbfs
> backed vma, result in below BUG:
>
> fs/hugetlbfs/inode.c
> 443 if (unlikely(page_mapped(page))) {
> 444 BUG_ON(truncate_op);

OK, help me out here. How does an incorrect return value from
vma_kernel_pagesize() result in remove_inode_hugepages() deciding that
it's truncating a mapped page?