From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIINk-0007QO-P6 for qemu-devel@nongnu.org; Thu, 23 Jul 2015 11:26:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZIINg-0003VD-Nz for qemu-devel@nongnu.org; Thu, 23 Jul 2015 11:26:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39474) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIINg-0003Ua-Gi for qemu-devel@nongnu.org; Thu, 23 Jul 2015 11:25:56 -0400 Date: Thu, 23 Jul 2015 18:25:52 +0300 From: "Michael S. Tsirkin" Message-ID: <20150723181931-mutt-send-email-mst@redhat.com> References: <1437615403-13554-1-git-send-email-marcandre.lureau@redhat.com> <1437615403-13554-3-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1437615403-13554-3-git-send-email-marcandre.lureau@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH RFC 2/6] posix: add linux-only memfd fallback List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau Cc: thibaut.collet@6wind.com, pbonzini@redhat.com, qemu-devel@nongnu.org, haifeng.lin@huawei.com On Thu, Jul 23, 2015 at 03:36:39AM +0200, Marc-Andr=E9 Lureau wrote: > Implement memfd_create() fallback if not available in system libc. > memfd_create() is still not included in glibc today, atlhough it's been > available since Linux 3.17 in Oct 2014. >=20 > memfd has numerous advantages over traditional shm/mmap for ipc memory > sharing with fd handler, which we are going to make use of for > vhost-user logging memory in following patches. >=20 > Signed-off-by: Marc-Andr=E9 Lureau > --- > include/qemu/osdep.h | 59 ++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > 1 file changed, 59 insertions(+) >=20 > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index 3247364..adc138b 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > #include > #ifdef __OpenBSD__ > #include > @@ -20,6 +21,64 @@ > =20 > #include > =20 > +#ifdef CONFIG_LINUX > + > +#ifndef F_LINUX_SPECIFIC_BASE > +#define F_LINUX_SPECIFIC_BASE 1024 > +#endif > + > +#ifndef F_ADD_SEALS > +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) > +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) > + > +#define F_SEAL_SEAL 0x0001 /* prevent further seals from being se= t */ > +#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ > +#define F_SEAL_GROW 0x0004 /* prevent file from growing */ > +#define F_SEAL_WRITE 0x0008 /* prevent writes */ > +#endif These are from include/uapi/linux/fcntl.h, they should be imported into linux-headers I think. > + > +#ifndef MFD_ALLOW_SEALING > +#define MFD_ALLOW_SEALING 0x0002U > +#endif > + > +#ifndef MFD_CLOEXEC > +#define MFD_CLOEXEC 0x0001U > +#endif > + > +#ifndef __NR_memfd_create > +# if defined __x86_64__ > +# define __NR_memfd_create 319 > +# elif defined __arm__ > +# define __NR_memfd_create 385 > +# elif defined __aarch64__ > +# define __NR_memfd_create 279 > +# elif defined _MIPS_SIM > +# if _MIPS_SIM =3D=3D _MIPS_SIM_ABI32 > +# define __NR_memfd_create 4354 > +# endif > +# if _MIPS_SIM =3D=3D _MIPS_SIM_NABI32 > +# define __NR_memfd_create 6318 > +# endif > +# if _MIPS_SIM =3D=3D _MIPS_SIM_ABI64 > +# define __NR_memfd_create 5314 > +# endif What's defining all these macros? > +# elif defined __i386__ > +# define __NR_memfd_create 356 > +# else > +# warning "__NR_memfd_create unknown for your architecture" > +# define __NR_memfd_create 0xffffffff > +# endif > +#endif > + > +#ifndef CONFIG_MEMFD > +static inline int memfd_create(const char *name, unsigned int flags) > +{ > + return syscall(__NR_memfd_create, name, flags); > +} > +#endif How about making these non-inline? I think we need stubs for non-posix systems, right? > + > +#endif /* LINUX */ > + > #if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10 > /* [u]int_fast*_t not in */ > typedef unsigned char uint_fast8_t; > --=20 > 2.4.3