From d152a162e9926dcf150c8d81418b726478151198 Mon Sep 17 00:00:00 2001 From: jiang-dawei15 Date: Tue, 15 Mar 2022 09:50:10 +0800 Subject: [PATCH 1/4] cflages: add cflags '-ftls-model=initial-exec' This option changes the thread local storage (TLS) model. Thread-local storage is a mechanism by which variables are allocated in a way that causes one instance of the variable per extant thread. i.global-dynamic Generates a generic TLS code. The code can be used everywhere and the code can access variables defined anywhere else. This setting causes the largest size code to be generated and uses the most run time to produce. ii.local-dynamic Generates an optimized TLS code. To use this setting, the thread-local variables must be defined in the same object in which they are referenced. iii.initial-exec Generates a restrictive, optimized TLS code. To use this setting, the thread-local variables accessed must be defined in one of the modules available to the program. iv.local-exec Generates the most restrictive TLS code. To use this setting, the thread-local variables must be defined in the executable. Optimize qemu cflags with '-ftls-model=initial-exec' which means we use initial-exec mode. --- qemu.spec | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/qemu.spec b/qemu.spec index 9ae6a04..d2d8e81 100644 --- a/qemu.spec +++ b/qemu.spec @@ -1,6 +1,6 @@ Name: qemu Version: 6.2.0 -Release: 25 +Release: 26 Epoch: 2 Summary: QEMU is a generic and open source machine emulator and virtualizer License: GPLv2 and BSD and MIT and CC-BY-SA-4.0 @@ -383,7 +383,7 @@ cd ../ ./configure \ --prefix=%{_prefix} \ --target-list=${buildarch} \ - --extra-cflags="%{optflags} -fPIE -DPIE -fPIC" \ + --extra-cflags="%{optflags} -fPIE -DPIE -fPIC -ftls-model=initial-exec" \ --extra-ldflags="-Wl,--build-id -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack" \ --datadir=%{_datadir} \ --docdir=%{_docdir}/ \ @@ -682,6 +682,9 @@ getent passwd qemu >/dev/null || \ %endif %changelog +* Tue Mar 15 2022 jiangdawei +- cflags: add ftls-mode=initial-exec + * Tue Mar 15 2022 yezengruan - sw_64: Add sw64 architecture support - update BinDir -- Gitee From 518ee8d1151e193e1d1dfcb3c8ab0c97584e419a Mon Sep 17 00:00:00 2001 From: yezengruan Date: Fri, 18 Mar 2022 14:07:18 +0800 Subject: [PATCH 2/4] add patch for sw64 support Signed-off-by: yezengruan --- qemu.spec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qemu.spec b/qemu.spec index d2d8e81..ea76381 100644 --- a/qemu.spec +++ b/qemu.spec @@ -234,6 +234,7 @@ Patch0220: pcie-Add-pcie-root-port-fast-plug-unplug-feature.patch Patch0221: pcie-Compat-with-devices-which-do-not-support-Link-W.patch Patch0222: scsi-bus-fix-unmatched-object_unref.patch Patch0223: tools-virtiofsd-Add-rseq-syscall-to-the-seccomp-allo.patch +Patch0224: sw_64-Add-sw64-architecture-support.patch BuildRequires: flex BuildRequires: gcc @@ -622,6 +623,9 @@ getent passwd qemu >/dev/null || \ %{_datadir}/%{name}/kvmvapic.bin %{_datadir}/%{name}/sgabios.bin %endif +%exclude %{_datadir}/%{name}/core3-hmcode +%exclude %{_datadir}/%{name}/core3-reset +%exclude %{_datadir}/%{name}/uefi-bios-sw %files help %dir %{qemudocdir} -- Gitee From 0a27da9d7f55cacec68efd1cb9661165b4064d21 Mon Sep 17 00:00:00 2001 From: jiang-dawei15 Date: Fri, 18 Mar 2022 15:41:47 +0800 Subject: [PATCH 3/4] coro: support live patch for libcare Description: For coroutine live patch, we need find all coroutines stack and check them before patching. There is no structure to manage all coroutines in qemu. So we add a list which contain all running coroutines to accelerate libcare live patch. Signed-off-by: jiang-dawei15 Signed-off-by: yezengruan --- coro-support-live-patch-for-libcare.patch | 120 ++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 coro-support-live-patch-for-libcare.patch diff --git a/coro-support-live-patch-for-libcare.patch b/coro-support-live-patch-for-libcare.patch new file mode 100644 index 0000000..5e287eb --- /dev/null +++ b/coro-support-live-patch-for-libcare.patch @@ -0,0 +1,120 @@ +From 2135fe8e9c4d459d3f06babf3bfd71b5387b0214 Mon Sep 17 00:00:00 2001 +From: jiang-dawei15 +Date: Tue, 15 Mar 2022 10:28:34 +0800 +Subject: [PATCH] coro: support live patch for libcare + +Description: +For coroutine live patch, we need find all coroutines stack and check them +before patching. There is no structure to manage all coroutines in qemu. So we +add a list which contain all running coroutines to accelerate libcare live +patch. +--- + include/qemu/coroutine_int.h | 3 ++- + util/coroutine-ucontext.c | 52 ++++++++++++++++++++++++++++++++++++ + util/qemu-coroutine.c | 4 +++ + 3 files changed, 58 insertions(+), 1 deletion(-) + +diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h +index 1da148552f..11b550a0fc 100644 +--- a/include/qemu/coroutine_int.h ++++ b/include/qemu/coroutine_int.h +@@ -73,5 +73,6 @@ Coroutine *qemu_coroutine_new(void); + void qemu_coroutine_delete(Coroutine *co); + CoroutineAction qemu_coroutine_switch(Coroutine *from, Coroutine *to, + CoroutineAction action); +- ++void qemu_coroutine_info_add(const Coroutine *co_); ++void qemu_coroutine_info_delete(const Coroutine *co_); + #endif +diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c +index 904b375192..23ab7cdf74 100644 +--- a/util/coroutine-ucontext.c ++++ b/util/coroutine-ucontext.c +@@ -79,6 +79,19 @@ union cc_arg { + int i[2]; + }; + ++/** ++ * coroutines list for libcare ++ */ ++struct CoroutineInformation { ++ sigjmp_buf *env; ++ QLIST_ENTRY(CoroutineInformation) next; ++}; ++ ++static QemuMutex coro_mtx; ++QLIST_HEAD(, CoroutineInformation) coro_info_list = QLIST_HEAD_INITIALIZER(pool); ++int coro_env_offset = offsetof(struct CoroutineInformation, env); ++int coro_next_offset = offsetof(struct CoroutineInformation, next); ++ + /* + * QEMU_ALWAYS_INLINE only does so if __OPTIMIZE__, so we cannot use it. + * always_inline is required to avoid TSan runtime fatal errors. +@@ -330,3 +343,42 @@ bool qemu_in_coroutine(void) + { + return current && current->caller; + } ++ ++static void __attribute__((constructor)) coro_mutex_init(void) ++{ ++ qemu_mutex_init(&coro_mtx); ++} ++ ++void qemu_coroutine_info_add(const Coroutine *co_) ++{ ++ CoroutineUContext *co; ++ struct CoroutineInformation *coro_info; ++ ++ /* save coroutine env to coro_info_list */ ++ co = DO_UPCAST(CoroutineUContext, base, co_); ++ coro_info = g_malloc0(sizeof(struct CoroutineInformation)); ++ coro_info->env = &co->env; ++ ++ qemu_mutex_lock(&coro_mtx); ++ QLIST_INSERT_HEAD(&coro_info_list, coro_info, next); ++ qemu_mutex_unlock(&coro_mtx); ++} ++ ++void qemu_coroutine_info_delete(const Coroutine *co_) ++{ ++ CoroutineUContext *co; ++ struct CoroutineInformation *coro_info; ++ ++ /* Remove relative coroutine env info from coro_info_list */ ++ co = DO_UPCAST(CoroutineUContext, base, co_); ++ ++ qemu_mutex_lock(&coro_mtx); ++ QLIST_FOREACH(coro_info, &coro_info_list, next) { ++ if (coro_info->env == &co->env) { ++ QLIST_REMOVE(coro_info, next); ++ g_free(coro_info); ++ break; ++ } ++ } ++ qemu_mutex_unlock(&coro_mtx); ++} +diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c +index b9586d6929..9c81336d8e 100644 +--- a/util/qemu-coroutine.c ++++ b/util/qemu-coroutine.c +@@ -75,6 +75,8 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void *opaque) + co = qemu_coroutine_new(); + } + ++ qemu_coroutine_info_add(co); ++ + co->entry = entry; + co->entry_arg = opaque; + QSIMPLEQ_INIT(&co->co_queue_wakeup); +@@ -85,6 +87,8 @@ static void coroutine_delete(Coroutine *co) + { + co->caller = NULL; + ++ qemu_coroutine_info_delete(co); ++ + if (CONFIG_COROUTINE_POOL) { + if (release_pool_size < POOL_BATCH_SIZE * 2) { + QSLIST_INSERT_HEAD_ATOMIC(&release_pool, co, pool_next); +-- +2.27.0 + -- Gitee From 62e9a21b5bff03ee0398ad849c23f226e0f77ec0 Mon Sep 17 00:00:00 2001 From: yezengruan Date: Fri, 18 Mar 2022 15:46:13 +0800 Subject: [PATCH 4/4] spec: Update release version with !266 and support sw64 Signed-off-by: yezengruan --- qemu.spec | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qemu.spec b/qemu.spec index ea76381..2326488 100644 --- a/qemu.spec +++ b/qemu.spec @@ -1,6 +1,6 @@ Name: qemu Version: 6.2.0 -Release: 26 +Release: 27 Epoch: 2 Summary: QEMU is a generic and open source machine emulator and virtualizer License: GPLv2 and BSD and MIT and CC-BY-SA-4.0 @@ -235,6 +235,7 @@ Patch0221: pcie-Compat-with-devices-which-do-not-support-Link-W.patch Patch0222: scsi-bus-fix-unmatched-object_unref.patch Patch0223: tools-virtiofsd-Add-rseq-syscall-to-the-seccomp-allo.patch Patch0224: sw_64-Add-sw64-architecture-support.patch +Patch0225: coro-support-live-patch-for-libcare.patch BuildRequires: flex BuildRequires: gcc @@ -686,7 +687,11 @@ getent passwd qemu >/dev/null || \ %endif %changelog -* Tue Mar 15 2022 jiangdawei +* Fri Mar 18 2022 yezengruan +- coro: support live patch for libcare +- add patch for sw64 support + +* Tue Mar 15 2022 jiangdawei - cflags: add ftls-mode=initial-exec * Tue Mar 15 2022 yezengruan -- Gitee