All of lore.kernel.org
 help / color / mirror / Atom feed
* several patches around Linux userland emulator
@ 2020-04-19 18:49 Nikolay Igotti
  2020-04-20  8:37 ` Laurent Vivier
  0 siblings, 1 reply; 2+ messages in thread
From: Nikolay Igotti @ 2020-04-19 18:49 UTC (permalink / raw)
  To: riku.voipio, laurent; +Cc: qemu-devel


[-- Attachment #1.1: Type: text/plain, Size: 122 bytes --]

   Hi,

Attached 3 relatively trivial patches helping with running userland Linux
emulation.

  Best regards,
    Nikolay

[-- Attachment #1.2: Type: text/html, Size: 220 bytes --]

[-- Attachment #2: 0001-plugins-avoid-failing-plugin-when-CPU-is-inited-seve.patch --]
[-- Type: application/octet-stream, Size: 1180 bytes --]

From 40a54f4e8f17266137ed50a4831d48409a4d5f3d Mon Sep 17 00:00:00 2001
From: Nikolay Igotti <igotti@gmail.com>
Date: Sun, 19 Apr 2020 21:43:34 +0300
Subject: [PATCH] plugins: avoid failing plugin when CPU is inited several
 times

In linux-user multithreaded scenarious CPU could be inited many times with the same id,
so avoid assertions on already present hashtable entry.
---
 plugins/core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/plugins/core.c b/plugins/core.c
index 51bfc94787..889cc6441a 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -196,13 +196,10 @@ plugin_register_cb_udata(qemu_plugin_id_t id, enum qemu_plugin_event ev,
 
 void qemu_plugin_vcpu_init_hook(CPUState *cpu)
 {
-    bool success;
-
     qemu_rec_mutex_lock(&plugin.lock);
     plugin_cpu_update__locked(&cpu->cpu_index, NULL, NULL);
-    success = g_hash_table_insert(plugin.cpu_ht, &cpu->cpu_index,
+    g_hash_table_insert(plugin.cpu_ht, &cpu->cpu_index,
                                   &cpu->cpu_index);
-    g_assert(success);
     qemu_rec_mutex_unlock(&plugin.lock);
 
     plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_INIT);
-- 
2.24.2 (Apple Git-127)


[-- Attachment #3: 0001-linux-user-fix-page-table-trashing-when-mmap-munmap-.patch --]
[-- Type: application/octet-stream, Size: 1124 bytes --]

From 356132111d690a4c9ee74490805e6cfb134dba63 Mon Sep 17 00:00:00 2001
From: Nikolay Igotti <igotti@gmail.com>
Date: Sun, 19 Apr 2020 21:31:41 +0300
Subject: [PATCH] linux-user: fix page table trashing when mmap/munmap called
 frequently on large regions

Some applications, for example Wasmer WebAssembly VM, perform frequent map/unmap of
huge (6G) regions, so when executed under linux-user it leads to creation of many PTE/PDE
for the region, and they never get reclaimed. As result, emulator process consumes a lot
of RAM. To fix this problem we try to reuse VMA, when possible.
---
 linux-user/mmap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index e378033797..c1d6163d7a 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -650,6 +650,8 @@ int target_munmap(abi_ulong start, abi_ulong len)
     if (ret == 0) {
         page_set_flags(start, start + len, 0);
         tb_invalidate_phys_range(start, start + len);
+        if (start < mmap_next_start)
+            mmap_next_start = start;
     }
     mmap_unlock();
     return ret;
-- 
2.24.2 (Apple Git-127)


[-- Attachment #4: 0001-linux-user-strace-better-format-mmap-logs-support-mr.patch --]
[-- Type: application/octet-stream, Size: 3158 bytes --]

From 70f9186e30be4af206fe89f882a80bb914eb2f2a Mon Sep 17 00:00:00 2001
From: Nikolay Igotti <igotti@gmail.com>
Date: Sun, 19 Apr 2020 21:41:04 +0300
Subject: [PATCH] linux-user: strace: better format mmap logs, support mremap

On 64-bit platforms strace entries were not properly formatted, also some addresses were printed as integers.
Also mremap syscall support is added.
---
 linux-user/strace.c    | 31 +++++++++++++++++++++++++++----
 linux-user/strace.list |  2 +-
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 0d9095c674..3e65ffe356 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -969,6 +969,14 @@ UNUSED static struct flags mmap_flags[] = {
     FLAG_END,
 };
 
+#ifdef TARGET_NR_mremap
+UNUSED static struct flags mremap_flags[] = {
+    FLAG_GENERIC(MREMAP_MAYMOVE),
+    FLAG_GENERIC(MREMAP_FIXED),
+    FLAG_END,
+};
+#endif
+
 UNUSED static struct flags clone_flags[] = {
     FLAG_GENERIC(CLONE_VM),
     FLAG_GENERIC(CLONE_FS),
@@ -2654,11 +2662,11 @@ print_mmap(const struct syscallname *name,
 {
     print_syscall_prologue(name);
     print_pointer(arg0, 0);
-    print_raw_param("%d", arg1, 0);
+    print_raw_param("%lld", (long long)arg1, 0);
     print_flags(mmap_prot_flags, arg2, 0);
     print_flags(mmap_flags, arg3, 0);
     print_raw_param("%d", arg4, 0);
-    print_raw_param("%#x", arg5, 1);
+    print_raw_param("%#llx", (long long)arg5, 1);
     print_syscall_epilogue(name);
 }
 #define print_mmap2     print_mmap
@@ -2672,12 +2680,27 @@ print_mprotect(const struct syscallname *name,
 {
     print_syscall_prologue(name);
     print_pointer(arg0, 0);
-    print_raw_param("%d", arg1, 0);
+    print_raw_param("%lld", (long long)arg1, 0);
     print_flags(mmap_prot_flags, arg2, 1);
     print_syscall_epilogue(name);
 }
 #endif
 
+#ifdef TARGET_NR_mremap
+static void
+print_mremap(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_pointer(arg0, 0);
+    print_raw_param("%lld", (long long)arg1, 0);
+    print_raw_param("%lld", (long long)arg2, 0);
+    print_flags(mremap_flags, arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_munmap
 static void
 print_munmap(const struct syscallname *name,
@@ -2686,7 +2709,7 @@ print_munmap(const struct syscallname *name,
 {
     print_syscall_prologue(name);
     print_pointer(arg0, 0);
-    print_raw_param("%d", arg1, 1);
+    print_raw_param("%lld", (long long)arg1, 1);
     print_syscall_epilogue(name);
 }
 #endif
diff --git a/linux-user/strace.list b/linux-user/strace.list
index d49a1e92a8..b3bd1c6229 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -612,7 +612,7 @@
 { TARGET_NR_mq_unlink, "mq_unlink" , NULL, print_mq_unlink, NULL },
 #endif
 #ifdef TARGET_NR_mremap
-{ TARGET_NR_mremap, "mremap" , NULL, NULL, NULL },
+{ TARGET_NR_mremap, "mremap" , NULL, print_mremap, print_syscall_ret_addr },
 #endif
 #ifdef TARGET_NR_msgctl
 { TARGET_NR_msgctl, "msgctl" , NULL, NULL, NULL },
-- 
2.24.2 (Apple Git-127)


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

* Re: several patches around Linux userland emulator
  2020-04-19 18:49 several patches around Linux userland emulator Nikolay Igotti
@ 2020-04-20  8:37 ` Laurent Vivier
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Vivier @ 2020-04-20  8:37 UTC (permalink / raw)
  To: Nikolay Igotti, riku.voipio; +Cc: qemu-devel

Le 19/04/2020 à 20:49, Nikolay Igotti a écrit :
>    Hi,
> 
> Attached 3 relatively trivial patches helping with running userland
> Linux emulation.

Hi,

thank you for your patches.

Can you send them in a series rather than in attachment: it will allow
to add inlined comments.

See

  https://wiki.qemu.org/Contribute/SubmitAPatch

You can use "git format-patch" and "git send-email" or "git publish" to
do that.

Thanks,
Laurent


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

end of thread, other threads:[~2020-04-20  8:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-19 18:49 several patches around Linux userland emulator Nikolay Igotti
2020-04-20  8:37 ` 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.