On Thu, Aug 13, 2020 at 3:09 PM Peter Collingbourne <pcc@xxxxxxxxxx> wrote: > > Introduce a new syscall, refpage_create, which returns a file > descriptor which may be mapped using mmap. Such a mapping is similar > to an anonymous mapping, but instead of clean pages being backed by the > zero page, they are instead backed by a so-called reference page, whose > contents are specified using an argument to refpage_create. Loads from > the mapping will load directly from the reference page, and initial > stores to the mapping will copy-on-write from the reference page. Catalin, I needed this diff on top of my patch and your latest MTE series in order for reference pages to cooperate with MTE. The first hunk is probably fine but without the second one, the tags in the reference page would not be set correctly in the case where the mapping used to create the reference page was not mapped with PROT_MTE. I'm not sure if it's appropriate to have MTE-specific stuff directly in mm/refpage.c so it probably needs something like a new architecture interface or a change to an existing one. Do you have any ideas? diff --git a/mm/refpage.c b/mm/refpage.c index c2f62a4f0dc0..7e4e4b2aabe2 100644 --- a/mm/refpage.c +++ b/mm/refpage.c @@ -7,6 +7,7 @@ static int refpage_mmap(struct file *file, struct vm_area_struct *vma) { vma_set_anonymous(vma); vma->vm_private_data = vma->vm_file->private_data; + vma->vm_flags |= VM_MTE_ALLOWED; return 0; } @@ -44,6 +45,14 @@ SYSCALL_DEFINE2(refpage_create, const void *__user, content, unsigned long, } copy_highpage(refpage, userpage); + +#ifdef CONFIG_ARM64_MTE + if (system_supports_mte() && !test_bit(PG_mte_tagged, &userpage->flags)) { + set_bit(PG_mte_tagged, &refpage->flags); + mte_clear_page_tags(page_address(refpage)); + } +#endif + put_page(userpage); fd = anon_inode_getfd("[refpage]", &refpage_file_operations, refpage, Peter