igt-dev.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Antonio Argenziano <antonio.argenziano@intel.com>
Cc: "igt-dev@lists.freedesktop.org" <igt-dev@lists.freedesktop.org>,
	"De Marchi, Lucas" <lucas.demarchi@intel.com>
Subject: Re: [igt-dev] [PATCH i-g-t v2 2/2] build: provide stub implementation for memfd_create
Date: Wed, 25 Jul 2018 15:56:40 -0700	[thread overview]
Message-ID: <20180725225640.GQ16907@intel.com> (raw)
In-Reply-To: <82ee618c-1243-e828-f67a-0a63ed4a3e71@intel.com>

On Wed, Jul 25, 2018 at 02:28:31PM -0700, Antonio Argenziano wrote:
> 
> 
> On 25/07/18 12:57, De Marchi, Lucas wrote:
> > On Wed, 2018-07-25 at 09:46 -0700, Antonio Argenziano wrote:
> > > 
> > > On 24/07/18 15:20, Lucas De Marchi wrote:
> > > > When libc misses memfd_create(), provide a stub implementation to go
> > > > through the syscall() route. Syscall numbers are provided for platforms
> > > > currently supported by i-g-t only.
> > > > 
> > > > v2: add support to autotools
> > > > 
> > > > Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
> > > > ---
> > > >    configure.ac                  |  3 +++
> > > >    lib/stubs/syscalls/sys/mman.h | 37 +++++++++++++++++++++++++++++++++++
> > > >    meson.build                   |  3 +++
> > > 
> > > I thought you were going to remove "#include <linux/memfd.h>" from
> > > gem_userptr_blits and include the stub instead.
> > 
> > I decided not to. To summarize:
> > 
> > In order to get the memfd_create() function definition one needs to include
> > sys/mman.h. The man page is wrong and I sent a patch.
> > 
> > linux/memfd.h is the kernel header (i.e. not from libc). It's useful to have
> > it if we are using or going to use new flags not present in the libc headers.
> > Or harmless. This is their content for me:
> > 
> > kernel header (linux/memfd.h):
> > /* flags for memfd_create(2) (unsigned int) */
> > #define MFD_CLOEXEC             0x0001U
> > #define MFD_ALLOW_SEALING       0x0002U
> > #define MFD_HUGETLB             0x0004U
> > 
> > libc header (bits/mman-shared.h which is down the include chain for
> > sys/mman.h):
> > 
> > #ifdef __USE_GNU
> > /* Flags for memfd_create.  */
> > # ifndef MFD_CLOEXEC
> > #  define MFD_CLOEXEC 1U
> > #  define MFD_ALLOW_SEALING 2U
> > #  define MFD_HUGETLB 4U
> > # endif
> > ...
> > 
> > We could also check if linux/memfd.h is available or just remove the include
> > since we are not using any flag not available on libc, but IMO it's not
> > necessary or at least not for this patch.
> 
> Fair enough, time for me to modernize a little anyway :).
> 
> For both patches:
> Acked-by: Antonio Argenziano <antonio.argenziano@intel.com>

pushed, thanks

> 
> > 
> > 
> > Lucas De Marchi
> > 
> > > 
> > > Antonio.
> > > 
> > > >    3 files changed, 43 insertions(+)
> > > >    create mode 100644 lib/stubs/syscalls/sys/mman.h
> > > > 
> > > > diff --git a/configure.ac b/configure.ac
> > > > index 0a5b0425..416a3240 100644
> > > > --- a/configure.ac
> > > > +++ b/configure.ac
> > > > @@ -81,6 +81,9 @@ AC_CHECK_FUNCS(timer_create, [], [
> > > >    ])
> > > >    AC_SUBST(TIMER_LIBS)
> > > > +dnl Check for memfd_create
> > > > +AC_CHECK_FUNCS(memfd_create)
> > > > +
> > > >    dnl Check for CPUID
> > > >    cpuid="yes"
> > > >    AC_TRY_LINK([
> > > > diff --git a/lib/stubs/syscalls/sys/mman.h b/lib/stubs/syscalls/sys/mman.h
> > > > new file mode 100644
> > > > index 00000000..2ac2da6a
> > > > --- /dev/null
> > > > +++ b/lib/stubs/syscalls/sys/mman.h
> > > > @@ -0,0 +1,37 @@
> > > > +/* SPDX-License-Identifier: MIT */
> > > > +
> > > > +#pragma once
> > > > +
> > > > +#include_next <sys/mman.h>
> > > > +
> > > > +#if !defined(HAVE_MEMFD_CREATE) || !HAVE_MEMFD_CREATE
> > > > +#include <errno.h>
> > > > +#include <sys/syscall.h>
> > > > +#include <sys/types.h>
> > > > +#include <unistd.h>
> > > > +
> > > > +#ifndef __NR_memfd_create
> > > > +#if defined __x86_64__
> > > > +#define __NR_memfd_create 319
> > > > +#elif defined __i386__
> > > > +#define __NR_memfd_create 356
> > > > +#elif defined __arm__
> > > > +#define __NR_memfd_create 385
> > > > +#else
> > > > +#warning "__NR_memfd_create unknown for your architecture"
> > > > +#endif
> > > > +#endif
> > > > +
> > > > +static inline int missing_memfd_create(const char *name, unsigned int
> > > > flags)
> > > > +{
> > > > +#ifdef __NR_memfd_create
> > > > +	return syscall(__NR_memfd_create, name, flags);
> > > > +#else
> > > > +	errno = ENOSYS;
> > > > +	return -1;
> > > > +#endif
> > > > +}
> > > > +
> > > > +#define memfd_create missing_memfd_create
> > > > +
> > > > +#endif
> > > > diff --git a/meson.build b/meson.build
> > > > index 22118828..63ac6292 100644
> > > > --- a/meson.build
> > > > +++ b/meson.build
> > > > @@ -196,6 +196,9 @@ if cc.has_member('struct sysinfo', 'totalram',
> > > >    	config.set('HAVE_STRUCT_SYSINFO_TOTALRAM', 1)
> > > >    endif
> > > > +have = cc.has_function('memfd_create', prefix : '''#include
> > > > <sys/mman.h>''', args : '-D_GNU_SOURCE')
> > > > +config.set10('HAVE_MEMFD_CREATE', have)
> > > > +
> > > >    add_project_arguments('-D_GNU_SOURCE', language : 'c')
> > > >    add_project_arguments('-include', 'config.h', language : 'c')
> > > > 
> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2018-07-25 22:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-24 22:20 [igt-dev] [PATCH i-g-t v2 0/2] Fix i-g-t on old systems Lucas De Marchi
2018-07-24 22:20 ` [igt-dev] [PATCH i-g-t v2 1/2] build: provide include for missing syscalls Lucas De Marchi
2018-07-25  0:04   ` Rodrigo Vivi
2018-08-02 10:19   ` Tvrtko Ursulin
2018-07-24 22:20 ` [igt-dev] [PATCH i-g-t v2 2/2] build: provide stub implementation for memfd_create Lucas De Marchi
2018-07-25  0:04   ` Rodrigo Vivi
2018-07-25 16:46   ` Antonio Argenziano
2018-07-25 19:57     ` De Marchi, Lucas
2018-07-25 21:28       ` Antonio Argenziano
2018-07-25 22:56         ` Rodrigo Vivi [this message]
2018-08-02 10:18   ` Tvrtko Ursulin
2018-07-24 23:32 ` [igt-dev] ✓ Fi.CI.BAT: success for Fix i-g-t on old systems (rev2) Patchwork
2018-07-25  1:25 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

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=20180725225640.GQ16907@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=antonio.argenziano@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.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).