[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z0XvwitcZ6ujoV9Y@x1n>
Date: Tue, 26 Nov 2024 10:56:50 -0500
From: Peter Xu <peterx@...hat.com>
To: stsp <stsp2@...dex.ru>
Cc: Muhammad Usama Anjum <Usama.Anjum@...labora.com>,
Linux kernel <linux-kernel@...r.kernel.org>
Subject: Re: userfaultfd: two-step UFFDIO_API always gives -EINVAL
On Tue, Nov 26, 2024 at 10:32:28AM +0300, stsp wrote:
> 25.11.2024 21:44, Muhammad Usama Anjum пишет:
> > The UFFD_FEATURE_WP_ASYNC was designed for exactly this case.
> > The IOCTL will return you the modified pages. An example of usage
> > can be found in selftest/mm/pagemap_ioctl.c.
> Thank you!
> I studied the examples.
> They are quite clear and good
> for copy/pasting purposes.
>
> I had yet another "problem":
> I tried to create the usefaultfd,
> then register the API and fork()
> the process. In child I do UFFDIO_REGISTER,
This doesn't sound like the right thing to do.. as the fd (returned from
syscall(userfaultfd)) should be linked to a specific mm. If the parent
invoked that syscall, it's linked to the parent address space, not child.
You may want to do syscall(userfalut) in child process, then pass it over
with scm rights. Otherwise IIUC the trap will be armed on parent virtual
address space.
> but the parent can't see that.
> So instead of copy by fork, I
> had to use SCM_RIGHTS.
> Is this expected, or should it
> work fine with forked fd? That
> would be a bit simpler than to
> apply to SCM_RIGHTS tricks.
If child is the process you'd like to monitor, I think scm rights is
exactly the right approach. Otherwise you can have a look at
UFFD_FEATURE_EVENT_FORK. However that's not designed for child-only traps,
IIUC.
Thanks,
--
Peter Xu
Powered by blists - more mailing lists