qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: thibaut.collet@6wind.com, pbonzini@redhat.com,
	qemu-devel@nongnu.org, haifeng.lin@huawei.com
Subject: Re: [Qemu-devel] [PATCH RFC 2/6] posix: add linux-only memfd fallback
Date: Thu, 23 Jul 2015 18:25:52 +0300	[thread overview]
Message-ID: <20150723181931-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <1437615403-13554-3-git-send-email-marcandre.lureau@redhat.com>

On Thu, Jul 23, 2015 at 03:36:39AM +0200, Marc-André 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.
> 
> 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.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  include/qemu/osdep.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 59 insertions(+)
> 
> 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 <stddef.h>
>  #include <stdbool.h>
>  #include <stdint.h>
> +#include <unistd.h>
>  #include <sys/types.h>
>  #ifdef __OpenBSD__
>  #include <sys/signal.h>
> @@ -20,6 +21,64 @@
>  
>  #include <sys/time.h>
>  
> +#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 set */
> +#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 == _MIPS_SIM_ABI32
> +#      define __NR_memfd_create 4354
> +#    endif
> +#    if _MIPS_SIM == _MIPS_SIM_NABI32
> +#      define __NR_memfd_create 6318
> +#    endif
> +#    if _MIPS_SIM == _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 <sys/int_types.h> */
>  typedef unsigned char           uint_fast8_t;
> -- 
> 2.4.3

  reply	other threads:[~2015-07-23 15:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-23  1:36 [Qemu-devel] [PATCH RFC 0/6] vhost-user: add migration log support Marc-André Lureau
2015-07-23  1:36 ` [Qemu-devel] [PATCH RFC 1/6] configure: probe for memfd Marc-André Lureau
2015-07-23  1:36 ` [Qemu-devel] [PATCH RFC 2/6] posix: add linux-only memfd fallback Marc-André Lureau
2015-07-23 15:25   ` Michael S. Tsirkin [this message]
2015-07-28  8:11     ` Paolo Bonzini
2015-07-28 10:58       ` Marc-André Lureau
2015-07-28 11:50         ` Paolo Bonzini
2015-07-28 14:25           ` Marc-André Lureau
2015-07-28 16:37             ` Paolo Bonzini
2015-07-23  1:36 ` [Qemu-devel] [PATCH RFC 3/6] osdep: add memfd helpers Marc-André Lureau
2015-07-23  1:36 ` [Qemu-devel] [PATCH RFC 4/6] vhost: alloc shareable log Marc-André Lureau
2015-07-28  5:28   ` Jason Wang
2015-07-28 10:10     ` Michael S. Tsirkin
2015-07-28 14:42       ` Marc-André Lureau
2015-07-23  1:36 ` [Qemu-devel] [PATCH RFC 5/6] vhost-user: send log shm fd along with log_base Marc-André Lureau
2015-07-23  1:36 ` [Qemu-devel] [PATCH RFC 6/6] vhost-user: document migration log Marc-André Lureau
2015-07-23 15:30   ` Michael S. Tsirkin
2015-07-23 15:36     ` Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150723181931-mutt-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=haifeng.lin@huawei.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thibaut.collet@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).