All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/4] memfd fixes.
       [not found] <CGME20190311135911eucas1p2612665dccba27cc8b5d81b67a70480c6@eucas1p2.samsung.com>
@ 2019-03-11 13:58 ` Ilya Maximets
       [not found]   ` <CGME20190311135916eucas1p27b50ca29c84af5f7529d56fd43a2964d@eucas1p2.samsung.com>
                     ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ilya Maximets @ 2019-03-11 13:58 UTC (permalink / raw)
  To: Marc-André Lureau, Eduardo Habkost
  Cc: qemu-devel, Paolo Bonzini, Igor Mammedov, Gerd Hoffmann,
	Daniel P. Berrangé,
	Ilya Maximets

Version 3:
    * Rebase on top of current master.

Version 2:
    * First patch changed to just drop the memfd backend
      if seals are not supported.

Ilya Maximets (4):
  hostmem-memfd: disable for systems wihtout sealing support
  memfd: always check for MFD_CLOEXEC
  memfd: set up correct errno if not supported
  memfd: improve error messages

 backends/hostmem-memfd.c | 18 ++++++++----------
 tests/vhost-user-test.c  |  5 +++--
 util/memfd.c             | 10 ++++++++--
 3 files changed, 19 insertions(+), 14 deletions(-)

-- 
2.17.1

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

* [Qemu-devel] [PATCH v3 1/4] hostmem-memfd: disable for systems wihtout sealing support
       [not found]   ` <CGME20190311135916eucas1p27b50ca29c84af5f7529d56fd43a2964d@eucas1p2.samsung.com>
@ 2019-03-11 13:58     ` Ilya Maximets
  0 siblings, 0 replies; 5+ messages in thread
From: Ilya Maximets @ 2019-03-11 13:58 UTC (permalink / raw)
  To: Marc-André Lureau, Eduardo Habkost
  Cc: qemu-devel, Paolo Bonzini, Igor Mammedov, Gerd Hoffmann,
	Daniel P. Berrangé,
	Ilya Maximets

If seals are not supported, memfd_create() will fail.
Furthermore, there is no way to disable it in this case because
'.seal' property is not registered.

This issue leads to vhost-user-test failures on RHEL 7.2:

  qemu-system-x86_64: -object memory-backend-memfd,id=mem,size=2M,: \
                      failed to create memfd: Invalid argument

and actually breaks the feature on such systems.

Let's restrict memfd backend to systems with sealing support.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
---
 backends/hostmem-memfd.c | 18 ++++++++----------
 tests/vhost-user-test.c  |  5 +++--
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c
index 98c9bf3240..46b15b916a 100644
--- a/backends/hostmem-memfd.c
+++ b/backends/hostmem-memfd.c
@@ -154,15 +154,13 @@ memfd_backend_class_init(ObjectClass *oc, void *data)
                                               "Huge pages size (ex: 2M, 1G)",
                                               &error_abort);
     }
-    if (qemu_memfd_check(MFD_ALLOW_SEALING)) {
-        object_class_property_add_bool(oc, "seal",
-                                       memfd_backend_get_seal,
-                                       memfd_backend_set_seal,
-                                       &error_abort);
-        object_class_property_set_description(oc, "seal",
-                                              "Seal growing & shrinking",
-                                              &error_abort);
-    }
+    object_class_property_add_bool(oc, "seal",
+                                   memfd_backend_get_seal,
+                                   memfd_backend_set_seal,
+                                   &error_abort);
+    object_class_property_set_description(oc, "seal",
+                                          "Seal growing & shrinking",
+                                          &error_abort);
 }
 
 static const TypeInfo memfd_backend_info = {
@@ -175,7 +173,7 @@ static const TypeInfo memfd_backend_info = {
 
 static void register_types(void)
 {
-    if (qemu_memfd_check(0)) {
+    if (qemu_memfd_check(MFD_ALLOW_SEALING)) {
         type_register_static(&memfd_backend_info);
     }
 }
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index 0c965b3b1e..3817966010 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -178,7 +178,8 @@ static void append_mem_opts(TestServer *server, GString *cmd_line,
                             int size, enum test_memfd memfd)
 {
     if (memfd == TEST_MEMFD_AUTO) {
-        memfd = qemu_memfd_check(0) ? TEST_MEMFD_YES : TEST_MEMFD_NO;
+        memfd = qemu_memfd_check(MFD_ALLOW_SEALING) ? TEST_MEMFD_YES
+                                                    : TEST_MEMFD_NO;
     }
 
     if (memfd == TEST_MEMFD_YES) {
@@ -930,7 +931,7 @@ static void register_vhost_user_test(void)
                  "virtio-net",
                  test_read_guest_mem, &opts);
 
-    if (qemu_memfd_check(0)) {
+    if (qemu_memfd_check(MFD_ALLOW_SEALING)) {
         opts.before = vhost_user_test_setup_memfd;
         qos_add_test("vhost-user/read-guest-mem/memfd",
                      "virtio-net",
-- 
2.17.1

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

* [Qemu-devel] [PATCH v3 2/4] memfd: always check for MFD_CLOEXEC
       [not found]   ` <CGME20190311135919eucas1p11c7fad66884a0303b2637cd2d2b05cad@eucas1p1.samsung.com>
@ 2019-03-11 13:58     ` Ilya Maximets
  0 siblings, 0 replies; 5+ messages in thread
From: Ilya Maximets @ 2019-03-11 13:58 UTC (permalink / raw)
  To: Marc-André Lureau, Eduardo Habkost
  Cc: qemu-devel, Paolo Bonzini, Igor Mammedov, Gerd Hoffmann,
	Daniel P. Berrangé,
	Ilya Maximets

QEMU always sets this flag unconditionally. We need to
check if it's supported.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 util/memfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/memfd.c b/util/memfd.c
index 8debd0d037..d74ce4d793 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -188,7 +188,7 @@ bool qemu_memfd_alloc_check(void)
 bool qemu_memfd_check(unsigned int flags)
 {
 #ifdef CONFIG_LINUX
-    int mfd = memfd_create("test", flags);
+    int mfd = memfd_create("test", flags | MFD_CLOEXEC);
 
     if (mfd >= 0) {
         close(mfd);
-- 
2.17.1

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

* [Qemu-devel] [PATCH v3 3/4] memfd: set up correct errno if not supported
       [not found]   ` <CGME20190311135922eucas1p2e131e72beea41ae584761ea5a62a948c@eucas1p2.samsung.com>
@ 2019-03-11 13:58     ` Ilya Maximets
  0 siblings, 0 replies; 5+ messages in thread
From: Ilya Maximets @ 2019-03-11 13:58 UTC (permalink / raw)
  To: Marc-André Lureau, Eduardo Habkost
  Cc: qemu-devel, Paolo Bonzini, Igor Mammedov, Gerd Hoffmann,
	Daniel P. Berrangé,
	Ilya Maximets

qemu_memfd_create() prints the value of 'errno' which is not
set in this case.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 util/memfd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/util/memfd.c b/util/memfd.c
index d74ce4d793..393d23da96 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -40,6 +40,7 @@ static int 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
 }
-- 
2.17.1

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

* [Qemu-devel] [PATCH v3 4/4] memfd: improve error messages
       [not found]   ` <CGME20190311135925eucas1p21442eda0f28a7e6ae1f9a238ca0a4f0d@eucas1p2.samsung.com>
@ 2019-03-11 13:58     ` Ilya Maximets
  0 siblings, 0 replies; 5+ messages in thread
From: Ilya Maximets @ 2019-03-11 13:58 UTC (permalink / raw)
  To: Marc-André Lureau, Eduardo Habkost
  Cc: qemu-devel, Paolo Bonzini, Igor Mammedov, Gerd Hoffmann,
	Daniel P. Berrangé,
	Ilya Maximets

This gives more information about the failure.
Additionally 'ENOSYS' returned for a non-Linux platforms instead of
'errno', which is not initilaized in this case.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 util/memfd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/util/memfd.c b/util/memfd.c
index 393d23da96..00334e5b21 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -71,14 +71,18 @@ int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
     }
     mfd = memfd_create(name, flags);
     if (mfd < 0) {
+        error_setg_errno(errp, errno,
+                         "failed to create memfd with flags 0x%x", flags);
         goto err;
     }
 
     if (ftruncate(mfd, size) == -1) {
+        error_setg_errno(errp, errno, "failed to resize memfd to %zu", size);
         goto err;
     }
 
     if (seals && fcntl(mfd, F_ADD_SEALS, seals) == -1) {
+        error_setg_errno(errp, errno, "failed to add seals 0x%x", seals);
         goto err;
     }
 
@@ -88,8 +92,9 @@ err:
     if (mfd >= 0) {
         close(mfd);
     }
+#else
+    error_setg_errno(errp, ENOSYS, "failed to create memfd");
 #endif
-    error_setg_errno(errp, errno, "failed to create memfd");
     return -1;
 }
 
-- 
2.17.1

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

end of thread, other threads:[~2019-03-11 13:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20190311135911eucas1p2612665dccba27cc8b5d81b67a70480c6@eucas1p2.samsung.com>
2019-03-11 13:58 ` [Qemu-devel] [PATCH v3 0/4] memfd fixes Ilya Maximets
     [not found]   ` <CGME20190311135916eucas1p27b50ca29c84af5f7529d56fd43a2964d@eucas1p2.samsung.com>
2019-03-11 13:58     ` [Qemu-devel] [PATCH v3 1/4] hostmem-memfd: disable for systems wihtout sealing support Ilya Maximets
     [not found]   ` <CGME20190311135919eucas1p11c7fad66884a0303b2637cd2d2b05cad@eucas1p1.samsung.com>
2019-03-11 13:58     ` [Qemu-devel] [PATCH v3 2/4] memfd: always check for MFD_CLOEXEC Ilya Maximets
     [not found]   ` <CGME20190311135922eucas1p2e131e72beea41ae584761ea5a62a948c@eucas1p2.samsung.com>
2019-03-11 13:58     ` [Qemu-devel] [PATCH v3 3/4] memfd: set up correct errno if not supported Ilya Maximets
     [not found]   ` <CGME20190311135925eucas1p21442eda0f28a7e6ae1f9a238ca0a4f0d@eucas1p2.samsung.com>
2019-03-11 13:58     ` [Qemu-devel] [PATCH v3 4/4] memfd: improve error messages Ilya Maximets

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.