All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user: add memfd_create
@ 2019-08-16 21:10 Shu-Chun Weng via Qemu-devel
  2019-08-18 21:57 ` Philippe Mathieu-Daudé
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Shu-Chun Weng via Qemu-devel @ 2019-08-16 21:10 UTC (permalink / raw)
  To: Riku Voipio, Laurent Vivier; +Cc: arunkaly, qemu-devel, Shu-Chun Weng

Add support for the memfd_create syscall. If the host does not have the
libc wrapper, translate to a direct syscall with NC-macro.

Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
Signed-off-by: Shu-Chun Weng <scw@google.com>
---
 include/qemu/memfd.h |  4 ++++
 linux-user/syscall.c | 11 +++++++++++
 util/memfd.c         |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
index d551c28b68..975b6bdb77 100644
--- a/include/qemu/memfd.h
+++ b/include/qemu/memfd.h
@@ -32,6 +32,10 @@
 #define MFD_HUGE_SHIFT 26
 #endif
 
+#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
+int memfd_create(const char *name, unsigned int flags);
+#endif
+
 int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
                       uint64_t hugetlbsize, unsigned int seals, Error **errp);
 bool qemu_memfd_alloc_check(void);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8367cb138d..b506c1f40e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "qemu/path.h"
+#include "qemu/memfd.h"
 #include <elf.h>
 #include <endian.h>
 #include <grp.h>
@@ -11938,6 +11939,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
         /* PowerPC specific.  */
         return do_swapcontext(cpu_env, arg1, arg2, arg3);
 #endif
+#ifdef TARGET_NR_memfd_create
+    case TARGET_NR_memfd_create:
+        p = lock_user_string(arg1);
+        if (!p) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(memfd_create(p, arg2));
+        unlock_user(p, arg1, 0);
+        return ret;
+#endif
 
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
diff --git a/util/memfd.c b/util/memfd.c
index 00334e5b21..4a3c07e0be 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -35,7 +35,7 @@
 #include <sys/syscall.h>
 #include <asm/unistd.h>
 
-static int memfd_create(const char *name, unsigned int flags)
+int memfd_create(const char *name, unsigned int flags)
 {
 #ifdef __NR_memfd_create
     return syscall(__NR_memfd_create, name, flags);
-- 
2.23.0.rc1.153.gdeed80330f-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: add memfd_create
  2019-08-16 21:10 [Qemu-devel] [PATCH] linux-user: add memfd_create Shu-Chun Weng via Qemu-devel
@ 2019-08-18 21:57 ` Philippe Mathieu-Daudé
  2019-08-19  7:12 ` Marc-André Lureau
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-08-18 21:57 UTC (permalink / raw)
  To: Shu-Chun Weng, Riku Voipio, Laurent Vivier
  Cc: arunkaly, Marc-André Lureau, qemu-devel

Cc'ing Marc-André

On 8/16/19 11:10 PM, Shu-Chun Weng via Qemu-devel wrote:
> Add support for the memfd_create syscall. If the host does not have the
> libc wrapper, translate to a direct syscall with NC-macro.
> 
> Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
> Signed-off-by: Shu-Chun Weng <scw@google.com>
> ---
>  include/qemu/memfd.h |  4 ++++
>  linux-user/syscall.c | 11 +++++++++++
>  util/memfd.c         |  2 +-
>  3 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
> index d551c28b68..975b6bdb77 100644
> --- a/include/qemu/memfd.h
> +++ b/include/qemu/memfd.h
> @@ -32,6 +32,10 @@
>  #define MFD_HUGE_SHIFT 26
>  #endif
>  
> +#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
> +int memfd_create(const char *name, unsigned int flags);
> +#endif
> +
>  int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
>                        uint64_t hugetlbsize, unsigned int seals, Error **errp);
>  bool qemu_memfd_alloc_check(void);
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 8367cb138d..b506c1f40e 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -20,6 +20,7 @@
>  #include "qemu/osdep.h"
>  #include "qemu/cutils.h"
>  #include "qemu/path.h"
> +#include "qemu/memfd.h"
>  #include <elf.h>
>  #include <endian.h>
>  #include <grp.h>
> @@ -11938,6 +11939,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>          /* PowerPC specific.  */
>          return do_swapcontext(cpu_env, arg1, arg2, arg3);
>  #endif
> +#ifdef TARGET_NR_memfd_create
> +    case TARGET_NR_memfd_create:
> +        p = lock_user_string(arg1);
> +        if (!p) {
> +            return -TARGET_EFAULT;
> +        }
> +        ret = get_errno(memfd_create(p, arg2));
> +        unlock_user(p, arg1, 0);
> +        return ret;
> +#endif
>  
>      default:
>          qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
> diff --git a/util/memfd.c b/util/memfd.c
> index 00334e5b21..4a3c07e0be 100644
> --- a/util/memfd.c
> +++ b/util/memfd.c
> @@ -35,7 +35,7 @@
>  #include <sys/syscall.h>
>  #include <asm/unistd.h>
>  
> -static int memfd_create(const char *name, unsigned int flags)
> +int memfd_create(const char *name, unsigned int flags)
>  {
>  #ifdef __NR_memfd_create
>      return syscall(__NR_memfd_create, name, flags);
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: add memfd_create
  2019-08-16 21:10 [Qemu-devel] [PATCH] linux-user: add memfd_create Shu-Chun Weng via Qemu-devel
  2019-08-18 21:57 ` Philippe Mathieu-Daudé
@ 2019-08-19  7:12 ` Marc-André Lureau
  2019-08-19 11:56 ` Peter Maydell
  2019-09-10  8:16 ` Laurent Vivier
  3 siblings, 0 replies; 10+ messages in thread
From: Marc-André Lureau @ 2019-08-19  7:12 UTC (permalink / raw)
  To: Shu-Chun Weng; +Cc: arunkaly, Riku Voipio, Laurent Vivier, QEMU

On Sat, Aug 17, 2019 at 1:28 AM Shu-Chun Weng via Qemu-devel
<qemu-devel@nongnu.org> wrote:
>
> Add support for the memfd_create syscall. If the host does not have the
> libc wrapper, translate to a direct syscall with NC-macro.
>
> Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
> Signed-off-by: Shu-Chun Weng <scw@google.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  include/qemu/memfd.h |  4 ++++
>  linux-user/syscall.c | 11 +++++++++++
>  util/memfd.c         |  2 +-
>  3 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
> index d551c28b68..975b6bdb77 100644
> --- a/include/qemu/memfd.h
> +++ b/include/qemu/memfd.h
> @@ -32,6 +32,10 @@
>  #define MFD_HUGE_SHIFT 26
>  #endif
>
> +#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
> +int memfd_create(const char *name, unsigned int flags);
> +#endif
> +
>  int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
>                        uint64_t hugetlbsize, unsigned int seals, Error **errp);
>  bool qemu_memfd_alloc_check(void);
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 8367cb138d..b506c1f40e 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -20,6 +20,7 @@
>  #include "qemu/osdep.h"
>  #include "qemu/cutils.h"
>  #include "qemu/path.h"
> +#include "qemu/memfd.h"
>  #include <elf.h>
>  #include <endian.h>
>  #include <grp.h>
> @@ -11938,6 +11939,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>          /* PowerPC specific.  */
>          return do_swapcontext(cpu_env, arg1, arg2, arg3);
>  #endif
> +#ifdef TARGET_NR_memfd_create
> +    case TARGET_NR_memfd_create:
> +        p = lock_user_string(arg1);
> +        if (!p) {
> +            return -TARGET_EFAULT;
> +        }
> +        ret = get_errno(memfd_create(p, arg2));
> +        unlock_user(p, arg1, 0);
> +        return ret;
> +#endif
>
>      default:
>          qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
> diff --git a/util/memfd.c b/util/memfd.c
> index 00334e5b21..4a3c07e0be 100644
> --- a/util/memfd.c
> +++ b/util/memfd.c
> @@ -35,7 +35,7 @@
>  #include <sys/syscall.h>
>  #include <asm/unistd.h>
>
> -static int memfd_create(const char *name, unsigned int flags)
> +int memfd_create(const char *name, unsigned int flags)
>  {
>  #ifdef __NR_memfd_create
>      return syscall(__NR_memfd_create, name, flags);
> --
> 2.23.0.rc1.153.gdeed80330f-goog
>
>


-- 
Marc-André Lureau


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: add memfd_create
  2019-08-16 21:10 [Qemu-devel] [PATCH] linux-user: add memfd_create Shu-Chun Weng via Qemu-devel
  2019-08-18 21:57 ` Philippe Mathieu-Daudé
  2019-08-19  7:12 ` Marc-André Lureau
@ 2019-08-19 11:56 ` Peter Maydell
  2019-08-19 18:08   ` [Qemu-devel] [PATCH v2] " Shu-Chun Weng via Qemu-devel
                     ` (2 more replies)
  2019-09-10  8:16 ` Laurent Vivier
  3 siblings, 3 replies; 10+ messages in thread
From: Peter Maydell @ 2019-08-19 11:56 UTC (permalink / raw)
  To: Shu-Chun Weng; +Cc: arunkaly, Riku Voipio, Laurent Vivier, QEMU Developers

On Fri, 16 Aug 2019 at 22:28, Shu-Chun Weng via Qemu-devel
<qemu-devel@nongnu.org> wrote:
>
> Add support for the memfd_create syscall. If the host does not have the
> libc wrapper, translate to a direct syscall with NC-macro.
>
> Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
> Signed-off-by: Shu-Chun Weng <scw@google.com>
> ---
>  include/qemu/memfd.h |  4 ++++
>  linux-user/syscall.c | 11 +++++++++++
>  util/memfd.c         |  2 +-
>  3 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
> index d551c28b68..975b6bdb77 100644
> --- a/include/qemu/memfd.h
> +++ b/include/qemu/memfd.h
> @@ -32,6 +32,10 @@
>  #define MFD_HUGE_SHIFT 26
>  #endif
>
> +#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
> +int memfd_create(const char *name, unsigned int flags);
> +#endif
> +
>  int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
>                        uint64_t hugetlbsize, unsigned int seals, Error **errp);
>  bool qemu_memfd_alloc_check(void);
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 8367cb138d..b506c1f40e 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -20,6 +20,7 @@
>  #include "qemu/osdep.h"
>  #include "qemu/cutils.h"
>  #include "qemu/path.h"
> +#include "qemu/memfd.h"
>  #include <elf.h>
>  #include <endian.h>
>  #include <grp.h>
> @@ -11938,6 +11939,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>          /* PowerPC specific.  */
>          return do_swapcontext(cpu_env, arg1, arg2, arg3);
>  #endif
> +#ifdef TARGET_NR_memfd_create
> +    case TARGET_NR_memfd_create:
> +        p = lock_user_string(arg1);
> +        if (!p) {
> +            return -TARGET_EFAULT;
> +        }
> +        ret = get_errno(memfd_create(p, arg2));

I think here you may need to call
           fd_trans_unregister(ret);

since memfd_create() returns a file descriptor.
(This call unregisters any pre-existing hooks for "we need
to mangle the data for reads/writes of this file descriptor",
in case the fd was previously being used for a file descriptor
type that needed that.) This is what eg NR_open does.

Laurent -- do I have this right? It's not entirely clear
to me that we could ever be in a situation where a syscall
like open or memfd_create returns an fd that's got an fd_trans
hook active, because that would imply we'd failed to delete
the hook on fd-close somehow. Is this just a belt-and-braces
bit of coding ?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v2] linux-user: add memfd_create
  2019-08-19 11:56 ` Peter Maydell
@ 2019-08-19 18:08   ` Shu-Chun Weng via Qemu-devel
  2019-08-19 18:09   ` [Qemu-devel] [PATCH v3] " Shu-Chun Weng via Qemu-devel
  2019-08-23 16:42   ` [Qemu-devel] [PATCH] " Laurent Vivier
  2 siblings, 0 replies; 10+ messages in thread
From: Shu-Chun Weng via Qemu-devel @ 2019-08-19 18:08 UTC (permalink / raw)
  To: marcandre.lureau
  Cc: arunkaly, Shu-Chun Weng, riku.voipio, qemu-devel, laurent

Add support for the memfd_create syscall. If the host does not have the
libc wrapper, translate to a direct syscall with NC-macro.

Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
Signed-off-by: Shu-Chun Weng <scw@google.com>
---
 include/qemu/memfd.h |  4 ++++
 linux-user/syscall.c | 11 +++++++++++
 util/memfd.c         |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
index d551c28b68..975b6bdb77 100644
--- a/include/qemu/memfd.h
+++ b/include/qemu/memfd.h
@@ -32,6 +32,10 @@
 #define MFD_HUGE_SHIFT 26
 #endif
 
+#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
+int memfd_create(const char *name, unsigned int flags);
+#endif
+
 int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
                       uint64_t hugetlbsize, unsigned int seals, Error **errp);
 bool qemu_memfd_alloc_check(void);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8367cb138d..b506c1f40e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "qemu/path.h"
+#include "qemu/memfd.h"
 #include <elf.h>
 #include <endian.h>
 #include <grp.h>
@@ -11938,6 +11939,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
         /* PowerPC specific.  */
         return do_swapcontext(cpu_env, arg1, arg2, arg3);
 #endif
+#ifdef TARGET_NR_memfd_create
+    case TARGET_NR_memfd_create:
+        p = lock_user_string(arg1);
+        if (!p) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(memfd_create(p, arg2));
+        unlock_user(p, arg1, 0);
+        return ret;
+#endif
 
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
diff --git a/util/memfd.c b/util/memfd.c
index 00334e5b21..4a3c07e0be 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -35,7 +35,7 @@
 #include <sys/syscall.h>
 #include <asm/unistd.h>
 
-static int memfd_create(const char *name, unsigned int flags)
+int memfd_create(const char *name, unsigned int flags)
 {
 #ifdef __NR_memfd_create
     return syscall(__NR_memfd_create, name, flags);
-- 
2.23.0.rc1.153.gdeed80330f-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3] linux-user: add memfd_create
  2019-08-19 11:56 ` Peter Maydell
  2019-08-19 18:08   ` [Qemu-devel] [PATCH v2] " Shu-Chun Weng via Qemu-devel
@ 2019-08-19 18:09   ` Shu-Chun Weng via Qemu-devel
  2019-08-23 16:48     ` Laurent Vivier
  2019-09-10 16:49     ` Laurent Vivier
  2019-08-23 16:42   ` [Qemu-devel] [PATCH] " Laurent Vivier
  2 siblings, 2 replies; 10+ messages in thread
From: Shu-Chun Weng via Qemu-devel @ 2019-08-19 18:09 UTC (permalink / raw)
  To: marcandre.lureau
  Cc: arunkaly, Shu-Chun Weng, riku.voipio, qemu-devel, laurent

Add support for the memfd_create syscall. If the host does not have the
libc wrapper, translate to a direct syscall with NC-macro.

Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
Signed-off-by: Shu-Chun Weng <scw@google.com>
---
 include/qemu/memfd.h |  4 ++++
 linux-user/syscall.c | 12 ++++++++++++
 util/memfd.c         |  2 +-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
index d551c28b68..975b6bdb77 100644
--- a/include/qemu/memfd.h
+++ b/include/qemu/memfd.h
@@ -32,6 +32,10 @@
 #define MFD_HUGE_SHIFT 26
 #endif
 
+#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
+int memfd_create(const char *name, unsigned int flags);
+#endif
+
 int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
                       uint64_t hugetlbsize, unsigned int seals, Error **errp);
 bool qemu_memfd_alloc_check(void);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8367cb138d..f3f9311e9c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "qemu/path.h"
+#include "qemu/memfd.h"
 #include <elf.h>
 #include <endian.h>
 #include <grp.h>
@@ -11938,6 +11939,17 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
         /* PowerPC specific.  */
         return do_swapcontext(cpu_env, arg1, arg2, arg3);
 #endif
+#ifdef TARGET_NR_memfd_create
+    case TARGET_NR_memfd_create:
+        p = lock_user_string(arg1);
+        if (!p) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(memfd_create(p, arg2));
+        fd_trans_unregister(ret);
+        unlock_user(p, arg1, 0);
+        return ret;
+#endif
 
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
diff --git a/util/memfd.c b/util/memfd.c
index 00334e5b21..4a3c07e0be 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -35,7 +35,7 @@
 #include <sys/syscall.h>
 #include <asm/unistd.h>
 
-static int memfd_create(const char *name, unsigned int flags)
+int memfd_create(const char *name, unsigned int flags)
 {
 #ifdef __NR_memfd_create
     return syscall(__NR_memfd_create, name, flags);
-- 
2.23.0.rc1.153.gdeed80330f-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: add memfd_create
  2019-08-19 11:56 ` Peter Maydell
  2019-08-19 18:08   ` [Qemu-devel] [PATCH v2] " Shu-Chun Weng via Qemu-devel
  2019-08-19 18:09   ` [Qemu-devel] [PATCH v3] " Shu-Chun Weng via Qemu-devel
@ 2019-08-23 16:42   ` Laurent Vivier
  2 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2019-08-23 16:42 UTC (permalink / raw)
  To: Peter Maydell, Shu-Chun Weng; +Cc: arunkaly, Riku Voipio, QEMU Developers

Le 19/08/2019 à 13:56, Peter Maydell a écrit :
> On Fri, 16 Aug 2019 at 22:28, Shu-Chun Weng via Qemu-devel
> <qemu-devel@nongnu.org> wrote:
>>
>> Add support for the memfd_create syscall. If the host does not have the
>> libc wrapper, translate to a direct syscall with NC-macro.
>>
>> Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
>> Signed-off-by: Shu-Chun Weng <scw@google.com>
>> ---
>>  include/qemu/memfd.h |  4 ++++
>>  linux-user/syscall.c | 11 +++++++++++
>>  util/memfd.c         |  2 +-
>>  3 files changed, 16 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
>> index d551c28b68..975b6bdb77 100644
>> --- a/include/qemu/memfd.h
>> +++ b/include/qemu/memfd.h
>> @@ -32,6 +32,10 @@
>>  #define MFD_HUGE_SHIFT 26
>>  #endif
>>
>> +#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
>> +int memfd_create(const char *name, unsigned int flags);
>> +#endif
>> +
>>  int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
>>                        uint64_t hugetlbsize, unsigned int seals, Error **errp);
>>  bool qemu_memfd_alloc_check(void);
>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> index 8367cb138d..b506c1f40e 100644
>> --- a/linux-user/syscall.c
>> +++ b/linux-user/syscall.c
>> @@ -20,6 +20,7 @@
>>  #include "qemu/osdep.h"
>>  #include "qemu/cutils.h"
>>  #include "qemu/path.h"
>> +#include "qemu/memfd.h"
>>  #include <elf.h>
>>  #include <endian.h>
>>  #include <grp.h>
>> @@ -11938,6 +11939,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>>          /* PowerPC specific.  */
>>          return do_swapcontext(cpu_env, arg1, arg2, arg3);
>>  #endif
>> +#ifdef TARGET_NR_memfd_create
>> +    case TARGET_NR_memfd_create:
>> +        p = lock_user_string(arg1);
>> +        if (!p) {
>> +            return -TARGET_EFAULT;
>> +        }
>> +        ret = get_errno(memfd_create(p, arg2));
> 
> I think here you may need to call
>            fd_trans_unregister(ret);
> 
> since memfd_create() returns a file descriptor.
> (This call unregisters any pre-existing hooks for "we need
> to mangle the data for reads/writes of this file descriptor",
> in case the fd was previously being used for a file descriptor
> type that needed that.) This is what eg NR_open does.
> 
> Laurent -- do I have this right? It's not entirely clear
> to me that we could ever be in a situation where a syscall
> like open or memfd_create returns an fd that's got an fd_trans
> hook active, because that would imply we'd failed to delete
> the hook on fd-close somehow. Is this just a belt-and-braces
> bit of coding ?

Exactly.

It's in case we missed one fd close and then to be sure an existing "fd
translator" will not mess with data of the new one.

Thanks,
Laurent




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v3] linux-user: add memfd_create
  2019-08-19 18:09   ` [Qemu-devel] [PATCH v3] " Shu-Chun Weng via Qemu-devel
@ 2019-08-23 16:48     ` Laurent Vivier
  2019-09-10 16:49     ` Laurent Vivier
  1 sibling, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2019-08-23 16:48 UTC (permalink / raw)
  To: Shu-Chun Weng, marcandre.lureau; +Cc: arunkaly, riku.voipio, qemu-devel

Le 19/08/2019 à 20:09, Shu-Chun Weng via Qemu-devel a écrit :
> Add support for the memfd_create syscall. If the host does not have the
> libc wrapper, translate to a direct syscall with NC-macro.
> 
> Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
> Signed-off-by: Shu-Chun Weng <scw@google.com>
> ---

Please, next time, to help review, add an history here, something like:

v3: add fd_trans_unregister()
v2: no change

And don't send new versions as a reply to the previous ones.

>  include/qemu/memfd.h |  4 ++++
>  linux-user/syscall.c | 12 ++++++++++++
>  util/memfd.c         |  2 +-
>  3 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
> index d551c28b68..975b6bdb77 100644
> --- a/include/qemu/memfd.h
> +++ b/include/qemu/memfd.h
> @@ -32,6 +32,10 @@
>  #define MFD_HUGE_SHIFT 26
>  #endif
>  
> +#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
> +int memfd_create(const char *name, unsigned int flags);
> +#endif
> +
>  int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
>                        uint64_t hugetlbsize, unsigned int seals, Error **errp);
>  bool qemu_memfd_alloc_check(void);
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 8367cb138d..f3f9311e9c 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -20,6 +20,7 @@
>  #include "qemu/osdep.h"
>  #include "qemu/cutils.h"
>  #include "qemu/path.h"
> +#include "qemu/memfd.h"
>  #include <elf.h>
>  #include <endian.h>
>  #include <grp.h>
> @@ -11938,6 +11939,17 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>          /* PowerPC specific.  */
>          return do_swapcontext(cpu_env, arg1, arg2, arg3);
>  #endif
> +#ifdef TARGET_NR_memfd_create
> +    case TARGET_NR_memfd_create:
> +        p = lock_user_string(arg1);
> +        if (!p) {
> +            return -TARGET_EFAULT;
> +        }
> +        ret = get_errno(memfd_create(p, arg2));
> +        fd_trans_unregister(ret);
> +        unlock_user(p, arg1, 0);
> +        return ret;
> +#endif
>  
>      default:
>          qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
> diff --git a/util/memfd.c b/util/memfd.c
> index 00334e5b21..4a3c07e0be 100644
> --- a/util/memfd.c
> +++ b/util/memfd.c
> @@ -35,7 +35,7 @@
>  #include <sys/syscall.h>
>  #include <asm/unistd.h>
>  
> -static int memfd_create(const char *name, unsigned int flags)
> +int memfd_create(const char *name, unsigned int flags)
>  {
>  #ifdef __NR_memfd_create
>      return syscall(__NR_memfd_create, name, flags);
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: add memfd_create
  2019-08-16 21:10 [Qemu-devel] [PATCH] linux-user: add memfd_create Shu-Chun Weng via Qemu-devel
                   ` (2 preceding siblings ...)
  2019-08-19 11:56 ` Peter Maydell
@ 2019-09-10  8:16 ` Laurent Vivier
  3 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2019-09-10  8:16 UTC (permalink / raw)
  To: Shu-Chun Weng, Riku Voipio; +Cc: arunkaly, qemu-devel

Le 16/08/2019 à 23:10, Shu-Chun Weng via Qemu-devel a écrit :
> Add support for the memfd_create syscall. If the host does not have the
> libc wrapper, translate to a direct syscall with NC-macro.
> 
> Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
> Signed-off-by: Shu-Chun Weng <scw@google.com>
> ---
>  include/qemu/memfd.h |  4 ++++
>  linux-user/syscall.c | 11 +++++++++++
>  util/memfd.c         |  2 +-
>  3 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
> index d551c28b68..975b6bdb77 100644
> --- a/include/qemu/memfd.h
> +++ b/include/qemu/memfd.h
> @@ -32,6 +32,10 @@
>  #define MFD_HUGE_SHIFT 26
>  #endif
>  
> +#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
> +int memfd_create(const char *name, unsigned int flags);
> +#endif
> +
>  int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
>                        uint64_t hugetlbsize, unsigned int seals, Error **errp);
>  bool qemu_memfd_alloc_check(void);
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 8367cb138d..b506c1f40e 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -20,6 +20,7 @@
>  #include "qemu/osdep.h"
>  #include "qemu/cutils.h"
>  #include "qemu/path.h"
> +#include "qemu/memfd.h"
>  #include <elf.h>
>  #include <endian.h>
>  #include <grp.h>
> @@ -11938,6 +11939,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>          /* PowerPC specific.  */
>          return do_swapcontext(cpu_env, arg1, arg2, arg3);
>  #endif
> +#ifdef TARGET_NR_memfd_create
> +    case TARGET_NR_memfd_create:
> +        p = lock_user_string(arg1);
> +        if (!p) {
> +            return -TARGET_EFAULT;
> +        }
> +        ret = get_errno(memfd_create(p, arg2));
> +        unlock_user(p, arg1, 0);
> +        return ret;
> +#endif
>  
>      default:
>          qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
> diff --git a/util/memfd.c b/util/memfd.c
> index 00334e5b21..4a3c07e0be 100644
> --- a/util/memfd.c
> +++ b/util/memfd.c
> @@ -35,7 +35,7 @@
>  #include <sys/syscall.h>
>  #include <asm/unistd.h>
>  
> -static int memfd_create(const char *name, unsigned int flags)
> +int memfd_create(const char *name, unsigned int flags)
>  {
>  #ifdef __NR_memfd_create
>      return syscall(__NR_memfd_create, name, flags);
> 

Applied to my linux-user branch.

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v3] linux-user: add memfd_create
  2019-08-19 18:09   ` [Qemu-devel] [PATCH v3] " Shu-Chun Weng via Qemu-devel
  2019-08-23 16:48     ` Laurent Vivier
@ 2019-09-10 16:49     ` Laurent Vivier
  1 sibling, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2019-09-10 16:49 UTC (permalink / raw)
  To: Shu-Chun Weng; +Cc: arunkaly, riku.voipio, marcandre.lureau, qemu-devel

On 19/08/2019 20:09, Shu-Chun Weng wrote:
> Add support for the memfd_create syscall. If the host does not have the
> libc wrapper, translate to a direct syscall with NC-macro.
> 
> Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
> Signed-off-by: Shu-Chun Weng <scw@google.com>
> ---
>  include/qemu/memfd.h |  4 ++++
>  linux-user/syscall.c | 12 ++++++++++++
>  util/memfd.c         |  2 +-
>  3 files changed, 17 insertions(+), 1 deletion(-)

A nice follow up to this patch would be to implement the file-sealing
APIs provided by fnctl (see memfd_create(2) and fcntl(2), File sealing).

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-09-10 16:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-16 21:10 [Qemu-devel] [PATCH] linux-user: add memfd_create Shu-Chun Weng via Qemu-devel
2019-08-18 21:57 ` Philippe Mathieu-Daudé
2019-08-19  7:12 ` Marc-André Lureau
2019-08-19 11:56 ` Peter Maydell
2019-08-19 18:08   ` [Qemu-devel] [PATCH v2] " Shu-Chun Weng via Qemu-devel
2019-08-19 18:09   ` [Qemu-devel] [PATCH v3] " Shu-Chun Weng via Qemu-devel
2019-08-23 16:48     ` Laurent Vivier
2019-09-10 16:49     ` Laurent Vivier
2019-08-23 16:42   ` [Qemu-devel] [PATCH] " Laurent Vivier
2019-09-10  8:16 ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.