Stefano Garzarella <sgarz...@redhat.com> writes: > Add a new `shm` bool option for `-object memory-backend-file`. > > When this option is set to true, the POSIX shm_open(3) is used instead > of open(2). > > So a file will not be created in the filesystem, but a "POSIX shared > memory object" will be instantiated. In Linux this turns into a file > in /dev/shm, but in other OSes this may not happen (for example in > macOS or FreeBSD nothing is shown in any filesystem). > > This new feature is useful when we need to share guest memory with > another process (e.g. vhost-user backend), but we don't have > memfd_create() or any special filesystems (e.g. /dev/shm) available > as in macOS. > > Signed-off-by: Stefano Garzarella <sgarz...@redhat.com> > --- > I am not sure this is the best way to support shm_open() in QEMU. > > Other solutions I had in mind were: > > - create a new memory-backend-shm
How would that look like? Would it involve duplicating code? > - extend memory-backend-memfd to use shm_open() on systems where memfd is > not available (problem: shm_open wants a name to assign to the object, but > we can do a workaround by using a random name and do the unlink right away) Hmm. Too much magic? I don't know... > Any preference/suggestion? [...] > diff --git a/qapi/qom.json b/qapi/qom.json > index 2a6e49365a..bfb01b909f 100644 > --- a/qapi/qom.json > +++ b/qapi/qom.json > @@ -682,6 +682,9 @@ # @mem-path: the path to either a shared memory or huge page # filesystem mount Does this need adjustment? [...] > # writable RAM instead of ROM, and want to set this property to 'off'. > # (default: auto, since 8.2) > # > +# @shm: if true, shm_open(3) is used to create/open POSIX shared memory > +# object; if false, an open(2) is used. (default: false) (since 9.0) > +# Please format like this for consistency: # @shm: if true, shm_open(3) is used to create/open POSIX shared memory # object; if false, an open(2) is used (default: false) (since 9.0) > # Since: 2.1 > ## > { 'struct': 'MemoryBackendFileProperties', > @@ -692,6 +695,7 @@ > 'mem-path': 'str', > '*pmem': { 'type': 'bool', 'if': 'CONFIG_LIBPMEM' }, > '*readonly': 'bool', > + '*shm': 'bool', > '*rom': 'OnOffAuto' } } > > ## [...]