O Mon, Jun 28, 2021 at 10:27:23AM -0400, Vivek Goyal wrote: > On Fri, Jun 04, 2021 at 12:43:22AM -0700, Ming Lin wrote: > > Adds new flag MAP_NOSIGBUS of mmap() to specify the behavior of > > "don't SIGBUS on fault". Right now, this flag is only allowed > > for private mapping. > > > > For MAP_NOSIGBUS mapping, map in the zero page on read fault > > or fill a freshly allocated page with zeroes on write fault. > > I am wondering if this could be of limited use for me if MAP_NOSIGBUS > were to be supported for shared mappings as well. V1 did support shared mapping. https://lkml.org/lkml/2021/6/1/1078 And V0 even supported unmapping the zero page for later write. https://github.com/minggr/linux/commit/77f3722b94ff33cafe0a72c1bf1b8fa374adb29f We may support shared mapping if there is a real use case. As Hugh mentioned: > And by restricting to MAP_PRIVATE, you would allow for adding a > proper MAP_SHARED implementation later, if it's thought useful > (that being the implementation which can subsequently unmap a > zero page to let new page cache be mapped). See https://lkml.org/lkml/2021/6/1/1258 Ming > > When virtiofs is run with dax enabled, then it is possible that if > a file is shared between two guests, then one guest truncates the > file and second guest tries to do load/store operation. Given current > kvm architecture, there is no mechanism to propagate SIGBUS to guest > process, instead KVM retries page fault infinitely and guest cpu/process > hangs. > > Ideally we want this error to propagate all the way back into the > guest and to the guest process but that solution is not in place yet. > > https://lore.kernel.org/kvm/20200406190951.GA19259@xxxxxxxxxx/ > > In the absense of a proper solution, one could think of mapping > shared file on host with MAP_NOSIGBUS, and hopefully that means > kvm will be able to resolve fault to a zero filled page and guest > will not hang. But this means that data sharing between two processes > is now broken. Writes by process A will not be visible to process B > in another once this situation happens, IIUC. > > So if we were to MAP_NOSIGBUS, guest will not hang but failures resulting > from ftruncate will be silent and will be noticed sometime later. I guess > not exactly a very pleasant scenario... > > Thanks > Vivek