From 860ab933039763be122006165abdc4fae4b34727 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Thu, 28 Oct 2021 17:07:14 +0200 Subject: [PATCH 1/4] build: add static libcap to output Signed-off-by: Christian Brauner --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index d832eb8b3..bef89f452 100644 --- a/meson.build +++ b/meson.build @@ -541,6 +541,7 @@ foreach tuple : [ ['SECCOMP'], ['SELinux'], ['libcap'], + ['static libcap'], ['openssl'], ] From 747bc634c5f5514d987a8900613574e20b6ffe37 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Thu, 28 Oct 2021 17:07:27 +0200 Subject: [PATCH 2/4] build: add io-uring-event-loop option Signed-off-by: Christian Brauner --- meson.build | 32 ++++++++++++++++++++------------ meson_options.txt | 3 +++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index bef89f452..a4125962f 100644 --- a/meson.build +++ b/meson.build @@ -59,6 +59,7 @@ logpath = get_option('log-path') lxcpathprefix = get_option('config-path') rootfsmount = get_option('rootfs-mount-dir') runtimepath = join_paths(prefixdir, get_option('runtime-path')) +wants_io_uring = get_option('io-uring-event-loop') conf.set_quoted('BINDIR', bindir) conf.set_quoted('DATADIR', datadir) @@ -279,6 +280,11 @@ foreach ident : [ conf.set10('HAVE_' + ident[0].to_upper(), have) endforeach +if wants_io_uring == true + liburing = dependency('liburing') + conf.set10('HAVE_LIBURING', liburing.found()) +endif + sh = find_program('sh') git = find_program('git', required : false) time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"').stdout().strip() @@ -383,6 +389,17 @@ subdir('src/include') subdir('src/lxc/tools/include') subdir('src/lxc') +liblxc_dependencies = [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor] + +if wants_io_uring == true + liblxc_dependencies += [liburing] +endif + liblxc = shared_library( 'lxc', version : liblxc_version, @@ -390,22 +407,12 @@ liblxc = shared_library( link_args : ['-DPIC'], c_args : ['-DPIC'], link_whole : [liblxc_static], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies: liblxc_dependencies, install : true) liblxc_dep = declare_dependency( link_with: liblxc, - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor]) + dependencies: liblxc_dependencies) dummy_config_data = configuration_data() dummy_config_data.set_quoted('DUMMY_VARIABLE', '1') @@ -543,6 +550,7 @@ foreach tuple : [ ['libcap'], ['static libcap'], ['openssl'], + ['liburing'], ] if tuple.length() >= 2 diff --git a/meson_options.txt b/meson_options.txt index 0989055df..ac1e05032 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -36,3 +36,6 @@ option('user-network-conf', type : 'string', value : 'lxc/lxc-usernet', option('user-network-db', type : 'string', value : 'lxc/nics', description : 'user network database') + +option('io-uring-event-loop', type : 'boolean', value: 'false', + description : 'enable io-uring based event loop') From aac3f106ff012e1d6835b20c250dcf09c364530c Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Thu, 28 Oct 2021 17:39:11 +0200 Subject: [PATCH 3/4] mainloop: make sure that descr->ring is allocated This is future proofing more than anything else. Signed-off-by: Christian Brauner --- src/lxc/mainloop.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lxc/mainloop.c b/src/lxc/mainloop.c index 7c8f5d86a..17a4d5529 100644 --- a/src/lxc/mainloop.c +++ b/src/lxc/mainloop.c @@ -515,8 +515,10 @@ void lxc_mainloop_close(struct lxc_async_descr *descr) if (descr->type == LXC_MAINLOOP_IO_URING) { #if HAVE_LIBURING - io_uring_queue_exit(descr->ring); - munmap(descr->ring, sizeof(struct io_uring)); + if (descr->ring) { + io_uring_queue_exit(descr->ring); + munmap(descr->ring, sizeof(struct io_uring)); + } #else ERROR("Unsupported io_uring mainloop"); #endif From a585382b972c25ee8489147d94918d001ef439a7 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Thu, 28 Oct 2021 17:39:42 +0200 Subject: [PATCH 4/4] start: check event loop type before closing fd Since this is a union we might otherwise stomp on io_uring mmap()ed memory. Fixes: #4016 Signed-off-by: Christian Brauner --- src/lxc/start.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lxc/start.c b/src/lxc/start.c index 8f7173ec8..1a6046c7a 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -629,7 +629,8 @@ int lxc_poll(const char *name, struct lxc_handler *handler) TRACE("Mainloop is ready"); ret = lxc_mainloop(&descr, -1); - close_prot_errno_disarm(descr.epfd); + if (descr.type == LXC_MAINLOOP_EPOLL) + close_prot_errno_disarm(descr.epfd); if (ret < 0 || !handler->init_died) goto out_mainloop_console;