aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean McAvoy <seanmcavoy@gmail.com>2021-11-06 20:24:45 -0400
committerFrancesco Colista <fcolista@alpinelinux.org>2021-11-07 08:48:07 +0000
commit23a90b1607ab3cf7503ceaea4db51ab94f6d7f37 (patch)
tree2fd2e221943a73eb76e53a3df1f40c76c61bfb91
parent812c69135482ec8ef8a5d3b979499d8c8c015973 (diff)
testing/lxd: upgrade to 4.20, remove previously needed patches
-rw-r--r--testing/lxd/10-check-whether-the-kernel-supports-core-sched.patch191
-rw-r--r--testing/lxd/20-support-core-sched-for-vm.patch268
-rw-r--r--testing/lxd/30-reorder-kernel-features.patch51
-rw-r--r--testing/lxd/40-separate-entries-for-pure-core-sched.patch80
-rw-r--r--testing/lxd/50-support-core-sched-for-container.patch236
-rw-r--r--testing/lxd/APKBUILD16
6 files changed, 3 insertions, 839 deletions
diff --git a/testing/lxd/10-check-whether-the-kernel-supports-core-sched.patch b/testing/lxd/10-check-whether-the-kernel-supports-core-sched.patch
deleted file mode 100644
index fc1d672a03f..00000000000
--- a/testing/lxd/10-check-whether-the-kernel-supports-core-sched.patch
+++ /dev/null
@@ -1,191 +0,0 @@
-From ba6be1043714458b29c4b37687d4f624ee421943 Mon Sep 17 00:00:00 2001
-From: Christian Brauner <christian.brauner@ubuntu.com>
-Date: Fri, 1 Oct 2021 10:27:58 +0200
-Subject: [PATCH] lxd/checkfeature: check whether the kernel supports core
- scheduling
-
-Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
----
- lxd/daemon.go | 2 +-
- lxd/include/syscall_wrappers.h | 78 ++++++++++++++++++++++++++++++++++
- lxd/main_checkfeature.go | 39 +++++++++++++++++
- 3 files changed, 118 insertions(+), 1 deletion(-)
-
-diff --git a/lxd/daemon.go b/lxd/daemon.go
-index df6e3adff..4155ea1e8 100644
---- a/lxd/daemon.go
-+++ b/lxd/daemon.go
-@@ -841,7 +841,7 @@ func (d *Daemon) init() error {
- logger.Info(" - pidfds: no")
- }
-
-- if d.os.LXCFeatures["core_scheduling"] {
-+ if canUseCoreScheduling() && d.os.LXCFeatures["core_scheduling"] {
- d.os.CoreScheduling = true
- logger.Info(" - core scheduling: yes")
- } else {
-diff --git a/lxd/include/syscall_wrappers.h b/lxd/include/syscall_wrappers.h
-index 25e56a5ce..4832b6637 100644
---- a/lxd/include/syscall_wrappers.h
-+++ b/lxd/include/syscall_wrappers.h
-@@ -6,6 +6,7 @@
- #endif
- #include <asm/unistd.h>
- #include <errno.h>
-+#include <sys/prctl.h>
- #include <sys/syscall.h>
- #include <sys/types.h>
- #include <unistd.h>
-@@ -49,4 +50,81 @@ static inline int move_mount(int from_dfd, const char *from_pathname, int to_dfd
- to_pathname, flags);
- }
-
-+/* arg1 of prctl() */
-+#ifndef PR_SCHED_CORE
-+#define PR_SCHED_CORE 62
-+#endif
-+
-+/* arg2 of prctl() */
-+#ifndef PR_SCHED_CORE_GET
-+#define PR_SCHED_CORE_GET 0
-+#endif
-+
-+#ifndef PR_SCHED_CORE_CREATE
-+#define PR_SCHED_CORE_CREATE 1 /* create unique core_sched cookie */
-+#endif
-+
-+#ifndef PR_SCHED_CORE_SHARE_TO
-+#define PR_SCHED_CORE_SHARE_TO 2 /* push core_sched cookie to pid */
-+#endif
-+
-+#ifndef PR_SCHED_CORE_SHARE_FROM
-+#define PR_SCHED_CORE_SHARE_FROM 3 /* pull core_sched cookie to pid */
-+#endif
-+
-+#ifndef PR_SCHED_CORE_MAX
-+#define PR_SCHED_CORE_MAX 4
-+#endif
-+
-+/* arg3 of prctl() */
-+#ifndef PR_SCHED_CORE_SCOPE_THREAD
-+#define PR_SCHED_CORE_SCOPE_THREAD 0
-+#endif
-+
-+#ifndef PR_SCHED_CORE_SCOPE_THREAD_GROUP
-+#define PR_SCHED_CORE_SCOPE_THREAD_GROUP 1
-+#endif
-+
-+#ifndef PR_SCHED_CORE_SCOPE_PROCESS_GROUP
-+#define PR_SCHED_CORE_SCOPE_PROCESS_GROUP 2
-+#endif
-+
-+#define INVALID_SCHED_CORE_COOKIE ((__u64)-1)
-+
-+static inline bool core_scheduling_cookie_valid(__u64 cookie)
-+{
-+ return (cookie > 0) && (cookie != INVALID_SCHED_CORE_COOKIE);
-+}
-+
-+static inline __u64 core_scheduling_cookie_get(pid_t pid)
-+{
-+ __u64 cookie;
-+ int ret;
-+
-+ ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid,
-+ PR_SCHED_CORE_SCOPE_THREAD, (unsigned long)&cookie);
-+ if (ret)
-+ return INVALID_SCHED_CORE_COOKIE;
-+
-+ return cookie;
-+}
-+
-+static inline int core_scheduling_cookie_create_threadgroup(pid_t pid)
-+{
-+ int ret;
-+
-+ ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, pid,
-+ PR_SCHED_CORE_SCOPE_THREAD_GROUP, 0);
-+ if (ret)
-+ return -errno;
-+
-+ return 0;
-+}
-+
-+static inline int core_scheduling_cookie_share_with(pid_t pid)
-+{
-+ return prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, pid,
-+ PR_SCHED_CORE_SCOPE_THREAD, 0);
-+}
-+
- #endif /* __LXD_SYSCALL_WRAPPER_H */
-diff --git a/lxd/main_checkfeature.go b/lxd/main_checkfeature.go
-index 0cc892071..a2c134da6 100644
---- a/lxd/main_checkfeature.go
-+++ b/lxd/main_checkfeature.go
-@@ -43,6 +43,7 @@ import (
- #include "include/syscall_numbers.h"
- #include "include/syscall_wrappers.h"
-
-+__ro_after_init bool core_scheduling_aware = false;
- __ro_after_init bool close_range_aware = false;
- __ro_after_init bool tiocgptpeer_aware = false;
- __ro_after_init bool netnsid_aware = false;
-@@ -502,6 +503,39 @@ static void is_close_range_aware(void)
- close_range_aware = true;
- }
-
-+static void is_core_scheduling_aware(void)
-+{
-+ int ret;
-+ pid_t pid;
-+
-+ pid = fork();
-+ if (pid < 0)
-+ return;
-+
-+ if (pid == 0) {
-+ pid_t pid_self;
-+ __u64 core_sched_cookie;
-+
-+ pid_self = getpid();
-+
-+ ret = core_scheduling_cookie_create_threadgroup(pid_self);
-+ if (ret)
-+ _exit(EXIT_FAILURE);
-+
-+ core_sched_cookie = core_scheduling_cookie_get(pid_self);
-+ if (!core_scheduling_cookie_valid(core_sched_cookie))
-+ _exit(EXIT_FAILURE);
-+
-+ _exit(EXIT_SUCCESS);
-+ }
-+
-+ ret = wait_for_pid(pid);
-+ if (ret)
-+ return;
-+
-+ core_scheduling_aware = true;
-+}
-+
- void checkfeature(void)
- {
- __do_close int hostnetns_fd = -EBADF, newnetns_fd = -EBADF, pidfd = -EBADF;
-@@ -512,6 +546,7 @@ void checkfeature(void)
- is_seccomp_notify_aware();
- is_tiocgptpeer_aware();
- is_close_range_aware();
-+ is_core_scheduling_aware();
-
- if (pidfd >= 0)
- pidfd_setns_aware = !setns(pidfd, CLONE_NEWNET);
-@@ -604,3 +639,7 @@ func canUseCloseRange() bool {
- func canUsePidFdSetns() bool {
- return bool(C.pidfd_setns_aware)
- }
-+
-+func canUseCoreScheduling() bool {
-+ return bool(C.core_scheduling_aware)
-+}
---
-2.33.1
-
diff --git a/testing/lxd/20-support-core-sched-for-vm.patch b/testing/lxd/20-support-core-sched-for-vm.patch
deleted file mode 100644
index 10d9af1d173..00000000000
--- a/testing/lxd/20-support-core-sched-for-vm.patch
+++ /dev/null
@@ -1,268 +0,0 @@
-From 9b3ebef85d4c5d13bbbc0f12f80492eb0ed16960 Mon Sep 17 00:00:00 2001
-From: Christian Brauner <christian.brauner@ubuntu.com>
-Date: Wed, 6 Oct 2021 10:56:12 +0200
-Subject: [PATCH] lxd: support core scheduling for virtual machines
-
-Add a new forkcoresched command. We fork off a new helper process that
-moves itself into a new core scheduling domain and then bestows that
-core scheduling domain onto the vcpu threads. This works around a
-missing feature in the current kernel api.
-
-Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
----
- lxd/include/syscall_wrappers.h | 18 +++++
- lxd/instance/drivers/driver_common.go | 18 +++++
- lxd/instance/drivers/driver_qemu.go | 21 ++++--
- lxd/main.go | 4 ++
- lxd/main_forkcoresched.go | 97 +++++++++++++++++++++++++++
- lxd/main_nsexec.go | 3 +
- 6 files changed, 154 insertions(+), 7 deletions(-)
- create mode 100644 lxd/main_forkcoresched.go
-
-diff --git a/lxd/include/syscall_wrappers.h b/lxd/include/syscall_wrappers.h
-index 4832b6637..29a3373a9 100644
---- a/lxd/include/syscall_wrappers.h
-+++ b/lxd/include/syscall_wrappers.h
-@@ -121,10 +121,28 @@ static inline int core_scheduling_cookie_create_threadgroup(pid_t pid)
- return 0;
- }
-
-+static inline int core_scheduling_cookie_create_thread(pid_t pid)
-+{
-+ int ret;
-+
-+ ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, pid,
-+ PR_SCHED_CORE_SCOPE_THREAD, 0);
-+ if (ret)
-+ return -errno;
-+
-+ return 0;
-+}
-+
- static inline int core_scheduling_cookie_share_with(pid_t pid)
- {
- return prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, pid,
- PR_SCHED_CORE_SCOPE_THREAD, 0);
- }
-
-+static inline int core_scheduling_cookie_share_to(pid_t pid)
-+{
-+ return prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, pid,
-+ PR_SCHED_CORE_SCOPE_THREAD, 0);
-+}
-+
- #endif /* __LXD_SYSCALL_WRAPPER_H */
-diff --git a/lxd/instance/drivers/driver_common.go b/lxd/instance/drivers/driver_common.go
-index db7c86f61..13e79a49e 100644
---- a/lxd/instance/drivers/driver_common.go
-+++ b/lxd/instance/drivers/driver_common.go
-@@ -4,6 +4,7 @@ import (
- "database/sql"
- "fmt"
- "path/filepath"
-+ "strconv"
- "strings"
- "time"
-
-@@ -962,3 +963,20 @@ func (d *common) recordLastState() error {
- return nil
- })
- }
-+
-+func (d *common) setCoreSched(pids []int) error {
-+ if !d.state.OS.CoreScheduling {
-+ return nil
-+ }
-+
-+ args := []string{
-+ "forkcoresched",
-+ }
-+
-+ for _, pid := range pids {
-+ args = append(args, strconv.Itoa(pid))
-+ }
-+
-+ _, err := shared.RunCommand(d.state.OS.ExecPath, args...)
-+ return err
-+}
-diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
-index 03550ef11..e894e3a42 100644
---- a/lxd/instance/drivers/driver_qemu.go
-+++ b/lxd/instance/drivers/driver_qemu.go
-@@ -1371,6 +1371,20 @@ func (d *qemu) Start(stateful bool) error {
- return err
- }
-
-+ // Get the list of PIDs from the VM.
-+ pids, err := monitor.GetCPUs()
-+ if err != nil {
-+ op.Done(err)
-+ return err
-+ }
-+
-+ err = d.setCoreSched(pids)
-+ if err != nil {
-+ err = fmt.Errorf("Failed to allocate new core scheduling domain for vCPU threads: %w", err)
-+ op.Done(err)
-+ return err
-+ }
-+
- // Apply CPU pinning.
- cpuLimit, ok := d.expandedConfig["limits.cpu"]
- if ok && cpuLimit != "" {
-@@ -1383,13 +1397,6 @@ func (d *qemu) Start(stateful bool) error {
- return err
- }
-
-- // Get the list of PIDs from the VM.
-- pids, err := monitor.GetCPUs()
-- if err != nil {
-- op.Done(err)
-- return err
-- }
--
- // Confirm nothing weird is going on.
- if len(pins) != len(pids) {
- err = fmt.Errorf("QEMU has less vCPUs than configured")
-diff --git a/lxd/main.go b/lxd/main.go
-index 91976e9f9..3e4dd1621 100644
---- a/lxd/main.go
-+++ b/lxd/main.go
-@@ -146,6 +146,10 @@ func main() {
- forksyscallCmd := cmdForksyscall{global: &globalCmd}
- app.AddCommand(forksyscallCmd.Command())
-
-+ // forkcoresched sub-command
-+ forkcoreschedCmd := cmdForkcoresched{global: &globalCmd}
-+ app.AddCommand(forkcoreschedCmd.Command())
-+
- // forkmount sub-command
- forkmountCmd := cmdForkmount{global: &globalCmd}
- app.AddCommand(forkmountCmd.Command())
-diff --git a/lxd/main_forkcoresched.go b/lxd/main_forkcoresched.go
-new file mode 100644
-index 000000000..ac2437056
---- /dev/null
-+++ b/lxd/main_forkcoresched.go
-@@ -0,0 +1,97 @@
-+package main
-+
-+import (
-+ "fmt"
-+
-+ "github.com/spf13/cobra"
-+
-+ // Used by cgo
-+ _ "github.com/lxc/lxd/lxd/include"
-+)
-+
-+/*
-+#ifndef _GNU_SOURCE
-+#define _GNU_SOURCE 1
-+#endif
-+#include <fcntl.h>
-+#include <libgen.h>
-+#include <sched.h>
-+#include <stdbool.h>
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <string.h>
-+#include <sys/prctl.h>
-+#include <sys/types.h>
-+#include <unistd.h>
-+
-+#include "include/memory_utils.h"
-+#include "include/mount_utils.h"
-+#include "include/syscall_numbers.h"
-+#include "include/syscall_wrappers.h"
-+
-+extern char* advance_arg(bool required);
-+
-+void forkcoresched(void)
-+{
-+ char *cur = NULL;
-+ int ret;
-+ __u64 cookie;
-+
-+ // Check that we're root
-+ if (geteuid() != 0)
-+ _exit(EXIT_FAILURE);
-+
-+ // Get the subcommand
-+ cur = advance_arg(false);
-+ if (cur == NULL ||
-+ (strcmp(cur, "--help") == 0 ||
-+ strcmp(cur, "--version") == 0 || strcmp(cur, "-h") == 0))
-+ _exit(EXIT_SUCCESS);
-+
-+ ret = core_scheduling_cookie_create_thread(0);
-+ if (ret)
-+ _exit(EXIT_FAILURE);
-+
-+ cookie = core_scheduling_cookie_get(0);
-+ if (!core_scheduling_cookie_valid(cookie))
-+ _exit(EXIT_FAILURE);
-+
-+ for (const char *pidstr = cur; pidstr; pidstr = advance_arg(false)) {
-+ ret = core_scheduling_cookie_share_to(atoi(pidstr));
-+ if (ret)
-+ _exit(EXIT_FAILURE);
-+
-+ cookie = core_scheduling_cookie_get(0);
-+ if (!core_scheduling_cookie_valid(cookie))
-+ _exit(EXIT_FAILURE);
-+ }
-+
-+ _exit(EXIT_SUCCESS);
-+}
-+*/
-+import "C"
-+
-+type cmdForkcoresched struct {
-+ global *cmdGlobal
-+}
-+
-+func (c *cmdForkcoresched) Command() *cobra.Command {
-+ // Main subcommand
-+ cmd := &cobra.Command{}
-+ cmd.Use = "forkcoresched <PID> [...]"
-+ cmd.Short = "Create new core scheduling domain"
-+ cmd.Long = `Description:
-+ Create new core scheduling domain
-+
-+ This command is used to move a set of processes into a new core scheduling
-+ domain.
-+`
-+ cmd.RunE = c.Run
-+ cmd.Hidden = true
-+
-+ return cmd
-+}
-+
-+func (c *cmdForkcoresched) Run(cmd *cobra.Command, args []string) error {
-+ return fmt.Errorf("This command should have been intercepted in cgo")
-+}
-diff --git a/lxd/main_nsexec.go b/lxd/main_nsexec.go
-index e35bf7412..78e13256d 100644
---- a/lxd/main_nsexec.go
-+++ b/lxd/main_nsexec.go
-@@ -49,6 +49,7 @@ import (
-
- // External functions
- extern void checkfeature();
-+extern void forkcoresched();
- extern void forkexec();
- extern void forkfile();
- extern void forksyscall();
-@@ -370,6 +371,8 @@ __attribute__((constructor)) void init(void) {
- forkproxy();
- else if (strcmp(cmdline_cur, "forkuevent") == 0)
- forkuevent();
-+ else if (strcmp(cmdline_cur, "forkcoresched") == 0)
-+ forkcoresched();
- else if (strcmp(cmdline_cur, "forkzfs") == 0) {
- ret = unshare(CLONE_NEWNS);
- if (ret < 0) {
---
-2.33.1
-
diff --git a/testing/lxd/30-reorder-kernel-features.patch b/testing/lxd/30-reorder-kernel-features.patch
deleted file mode 100644
index dd8da991fd3..00000000000
--- a/testing/lxd/30-reorder-kernel-features.patch
+++ /dev/null
@@ -1,51 +0,0 @@
-From e367aef1a724b2bdcf750fb846af366d7bc49441 Mon Sep 17 00:00:00 2001
-From: Christian Brauner <christian.brauner@ubuntu.com>
-Date: Wed, 6 Oct 2021 11:44:31 +0200
-Subject: [PATCH] lxd/sys/os: reorder kernel features
-
-Features like "CloseRange" are pure kernel features, i.e. they don't
-require checking the LXC shared library for support. Others such as
-PidFds currently require a supporting LXC library version.
-Move them into separate alignment blocks.
-
-Some entries like "CoreScheduling" shouldn't depend on LXC library
-version as well as kernel version in order to be marked as available
-since they are useful to both container and vms and vms aren't limited
-by LXC version obviously.
-
-Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
----
- lxd/sys/os.go | 9 +++++----
- 1 file changed, 5 insertions(+), 4 deletions(-)
-
-diff --git a/lxd/sys/os.go b/lxd/sys/os.go
-index 99204ec91..2688c2ea5 100644
---- a/lxd/sys/os.go
-+++ b/lxd/sys/os.go
-@@ -73,18 +73,19 @@ type OS struct {
-
- // Kernel features
- CloseRange bool
-- CoreScheduling bool
-- NativeTerminals bool
- NetnsGetifaddrs bool
-- PidFds bool
- PidFdSetns bool
- SeccompListener bool
-- SeccompListenerAddfd bool
- SeccompListenerContinue bool
- Shiftfs bool
- UeventInjection bool
- VFS3Fscaps bool
-
-+ CoreScheduling bool
-+ NativeTerminals bool
-+ PidFds bool
-+ SeccompListenerAddfd bool
-+
- // LXC features
- LXCFeatures map[string]bool
- }
---
-2.33.1
-
diff --git a/testing/lxd/40-separate-entries-for-pure-core-sched.patch b/testing/lxd/40-separate-entries-for-pure-core-sched.patch
deleted file mode 100644
index 033d59bf81f..00000000000
--- a/testing/lxd/40-separate-entries-for-pure-core-sched.patch
+++ /dev/null
@@ -1,80 +0,0 @@
-From 3e232c54cc9cf2a9bf9e1aa099c7b790bab5fbc9 Mon Sep 17 00:00:00 2001
-From: Christian Brauner <christian.brauner@ubuntu.com>
-Date: Wed, 6 Oct 2021 11:56:05 +0200
-Subject: [PATCH] os: add separate entries for pure core scheduling kernel
- feature and container support
-
-Allow callers with access to os to tell the difference between kernel
-support and container support. This will be used in follow-up patches to
-implement core scheduling support for containers even when the shared
-library doesn't support it.
-
-Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
----
- lxd/daemon.go | 6 +++++-
- lxd/instance/drivers/driver_lxc.go | 2 +-
- lxd/sys/os.go | 9 +++++----
- 3 files changed, 11 insertions(+), 6 deletions(-)
-
-diff --git a/lxd/daemon.go b/lxd/daemon.go
-index 6d2d53c1b..8233f41f9 100644
---- a/lxd/daemon.go
-+++ b/lxd/daemon.go
-@@ -840,9 +840,13 @@ func (d *Daemon) init() error {
- logger.Info(" - pidfds: no")
- }
-
-- if canUseCoreScheduling() && d.os.LXCFeatures["core_scheduling"] {
-+ if canUseCoreScheduling() {
- d.os.CoreScheduling = true
- logger.Info(" - core scheduling: yes")
-+
-+ if d.os.LXCFeatures["core_scheduling"] {
-+ d.os.ContainerCoreScheduling = true
-+ }
- } else {
- logger.Info(" - core scheduling: no")
- }
-diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
-index 8dcd96873..0670a89c7 100644
---- a/lxd/instance/drivers/driver_lxc.go
-+++ b/lxd/instance/drivers/driver_lxc.go
-@@ -739,7 +739,7 @@ func (d *lxc) initLXC(config bool) error {
- }
- }
-
-- if d.state.OS.CoreScheduling {
-+ if d.state.OS.ContainerCoreScheduling {
- err = lxcSetConfigItem(cc, "lxc.sched.core", "1")
- if err != nil {
- return err
-diff --git a/lxd/sys/os.go b/lxd/sys/os.go
-index 2688c2ea5..07a91adb2 100644
---- a/lxd/sys/os.go
-+++ b/lxd/sys/os.go
-@@ -73,6 +73,7 @@ type OS struct {
-
- // Kernel features
- CloseRange bool
-+ CoreScheduling bool
- NetnsGetifaddrs bool
- PidFdSetns bool
- SeccompListener bool
-@@ -81,10 +82,10 @@ type OS struct {
- UeventInjection bool
- VFS3Fscaps bool
-
-- CoreScheduling bool
-- NativeTerminals bool
-- PidFds bool
-- SeccompListenerAddfd bool
-+ ContainerCoreScheduling bool
-+ NativeTerminals bool
-+ PidFds bool
-+ SeccompListenerAddfd bool
-
- // LXC features
- LXCFeatures map[string]bool
---
-2.33.1
-
diff --git a/testing/lxd/50-support-core-sched-for-container.patch b/testing/lxd/50-support-core-sched-for-container.patch
deleted file mode 100644
index 5424ec94c31..00000000000
--- a/testing/lxd/50-support-core-sched-for-container.patch
+++ /dev/null
@@ -1,236 +0,0 @@
-From 7ca2b76e01a04787c2c5f308dea830937957dc20 Mon Sep 17 00:00:00 2001
-From: Christian Brauner <christian.brauner@ubuntu.com>
-Date: Wed, 6 Oct 2021 12:41:10 +0200
-Subject: [PATCH] lxd: support core scheduling for container even without LXC
- library support
-
-Let the forkcoresched hook be useable from a hook in LXD. This allows us
-to turn on core scheduling for the main container workload even when the
-LXC shared library doesn't support core scheduling.
-
-Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
----
- lxd/instance/drivers/driver_common.go | 1 +
- lxd/instance/drivers/driver_lxc.go | 11 +++++
- lxd/main_forkcoresched.go | 26 ++++++++++-
- lxd/main_forkexec.go | 62 +++++++++++++++++++++++----
- 4 files changed, 90 insertions(+), 10 deletions(-)
-
-diff --git a/lxd/instance/drivers/driver_common.go b/lxd/instance/drivers/driver_common.go
-index 13e79a49e..78281c255 100644
---- a/lxd/instance/drivers/driver_common.go
-+++ b/lxd/instance/drivers/driver_common.go
-@@ -971,6 +971,7 @@ func (d *common) setCoreSched(pids []int) error {
-
- args := []string{
- "forkcoresched",
-+ "0",
- }
-
- for _, pid := range pids {
-diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
-index 0670a89c7..29c17f71b 100644
---- a/lxd/instance/drivers/driver_lxc.go
-+++ b/lxd/instance/drivers/driver_lxc.go
-@@ -744,6 +744,11 @@ func (d *lxc) initLXC(config bool) error {
- if err != nil {
- return err
- }
-+ } else if d.state.OS.CoreScheduling {
-+ err = lxcSetConfigItem(cc, "lxc.hook.start-host", fmt.Sprintf("/proc/%d/exe forkcoresched 1", os.Getpid()))
-+ if err != nil {
-+ return err
-+ }
- }
-
- // Allow for lightweight init
-@@ -5686,6 +5691,12 @@ func (d *lxc) Exec(req api.InstanceExecPost, stdin *os.File, stdout *os.File, st
- fmt.Sprintf("%d", req.Group),
- }
-
-+ if d.state.OS.CoreScheduling && !d.state.OS.ContainerCoreScheduling {
-+ args = append(args, "1")
-+ } else {
-+ args = append(args, "0")
-+ }
-+
- args = append(args, "--")
- args = append(args, "env")
- args = append(args, envSlice...)
-diff --git a/lxd/main_forkcoresched.go b/lxd/main_forkcoresched.go
-index ac2437056..6113a30fc 100644
---- a/lxd/main_forkcoresched.go
-+++ b/lxd/main_forkcoresched.go
-@@ -34,6 +34,8 @@ extern char* advance_arg(bool required);
- void forkcoresched(void)
- {
- char *cur = NULL;
-+ char *pidstr;
-+ int hook;
- int ret;
- __u64 cookie;
-
-@@ -56,7 +58,24 @@ void forkcoresched(void)
- if (!core_scheduling_cookie_valid(cookie))
- _exit(EXIT_FAILURE);
-
-- for (const char *pidstr = cur; pidstr; pidstr = advance_arg(false)) {
-+ hook = atoi(cur);
-+ switch (hook) {
-+ case 0:
-+ for (pidstr = cur; pidstr; pidstr = advance_arg(false)) {
-+ ret = core_scheduling_cookie_share_to(atoi(pidstr));
-+ if (ret)
-+ _exit(EXIT_FAILURE);
-+
-+ cookie = core_scheduling_cookie_get(0);
-+ if (!core_scheduling_cookie_valid(cookie))
-+ _exit(EXIT_FAILURE);
-+ }
-+ break;
-+ case 1:
-+ pidstr = getenv("LXC_PID");
-+ if (!pidstr)
-+ _exit(EXIT_FAILURE);
-+
- ret = core_scheduling_cookie_share_to(atoi(pidstr));
- if (ret)
- _exit(EXIT_FAILURE);
-@@ -64,6 +83,9 @@ void forkcoresched(void)
- cookie = core_scheduling_cookie_get(0);
- if (!core_scheduling_cookie_valid(cookie))
- _exit(EXIT_FAILURE);
-+ break;
-+ default:
-+ _exit(EXIT_FAILURE);
- }
-
- _exit(EXIT_SUCCESS);
-@@ -78,7 +100,7 @@ type cmdForkcoresched struct {
- func (c *cmdForkcoresched) Command() *cobra.Command {
- // Main subcommand
- cmd := &cobra.Command{}
-- cmd.Use = "forkcoresched <PID> [...]"
-+ cmd.Use = "forkcoresched <hook> <PID> [...]"
- cmd.Short = "Create new core scheduling domain"
- cmd.Long = `Description:
- Create new core scheduling domain
-diff --git a/lxd/main_forkexec.go b/lxd/main_forkexec.go
-index cfa4cd6bc..339d2202e 100644
---- a/lxd/main_forkexec.go
-+++ b/lxd/main_forkexec.go
-@@ -27,6 +27,7 @@ import (
-
- #include "include/macro.h"
- #include "include/memory_utils.h"
-+#include "include/process_utils.h"
- #include "include/syscall_wrappers.h"
- #include <lxc/attach_options.h>
- #include <lxc/lxccontainer.h>
-@@ -232,15 +233,17 @@ __attribute__ ((noinline)) static int __forkexec(void)
- call_cleaner(lxc_container_put) struct lxc_container *c = NULL;
- const char *config_path = NULL, *lxcpath = NULL, *name = NULL;
- char *cwd = NULL;
-+ pid_t init_pid;
- lxc_attach_options_t attach_options = LXC_ATTACH_OPTIONS_DEFAULT;
- lxc_attach_command_t command = {
- .program = NULL,
- };
- int fds_to_ignore[] = {EXEC_STDIN_FD, EXEC_STDOUT_FD, EXEC_STDERR_FD, EXEC_PIPE_FD};
- int ret;
-- pid_t pid;
-+ pid_t attached_pid;
- uid_t uid;
- gid_t gid;
-+ int coresched;
-
- if (geteuid() != 0)
- return log_error(EXIT_FAILURE, "Error: forkexec requires root privileges");
-@@ -260,6 +263,9 @@ __attribute__ ((noinline)) static int __forkexec(void)
- gid = atoi(advance_arg(true));
- if (gid < 0)
- gid = (gid_t) - 1;
-+ coresched = atoi(advance_arg(true));
-+ if (coresched != 0 && coresched != 1)
-+ _exit(EXIT_FAILURE);
-
- for (char *arg = NULL, *section = NULL; (arg = advance_arg(false)); ) {
- if (!strcmp(arg, "--") && (!section || strcmp(section, "cmd"))) {
-@@ -328,19 +334,59 @@ __attribute__ ((noinline)) static int __forkexec(void)
- command.program = argvp[0];
- command.argv = argvp;
-
-- ret = c->attach(c, lxc_attach_run_command, &command, &attach_options, &pid);
-+ ret = c->attach(c, lxc_attach_run_command, &command, &attach_options, &attached_pid);
- if (ret < 0)
- return EXIT_FAILURE;
-
-- if (!write_nointr(status_pipe, &pid, sizeof(pid))) {
-+ if (!write_nointr(status_pipe, &attached_pid, sizeof(attached_pid))) {
- // Kill the child just to be safe.
-- fprintf(stderr, "Failed to send pid %d of executing child to LXD. Killing child\n", pid);
-- kill(pid, SIGKILL);
-+ fprintf(stderr, "Failed to send pid %d of executing child to LXD. Killing child\n", attached_pid);
-+ kill(attached_pid, SIGKILL);
-+ goto out_reap;
- }
-
-- ret = wait_for_pid_status_nointr(pid);
-+ if (coresched == 1) {
-+ pid_t pid;
-+
-+ init_pid = c->init_pid(c);
-+ if (init_pid < 0) {
-+ kill(attached_pid, SIGKILL);
-+ goto out_reap;
-+ }
-+
-+ pid = vfork();
-+ if (pid < 0) {
-+ kill(attached_pid, SIGKILL);
-+ goto out_reap;
-+ }
-+
-+ if (pid == 0) {
-+ __u64 cookie;
-+
-+ ret = core_scheduling_cookie_share_with(init_pid);
-+ if (ret)
-+ _exit(EXIT_FAILURE);
-+
-+ ret = core_scheduling_cookie_share_to(attached_pid);
-+ if (ret)
-+ _exit(EXIT_FAILURE);
-+
-+ cookie = core_scheduling_cookie_get(attached_pid);
-+ if (!core_scheduling_cookie_valid(cookie))
-+ _exit(EXIT_FAILURE);
-+
-+ _exit(EXIT_SUCCESS);
-+ }
-+
-+ ret = wait_for_pid(pid);
-+ if (ret)
-+ kill(attached_pid, SIGKILL);
-+ }
-+
-+out_reap:
-+ ret = wait_for_pid_status_nointr(attached_pid);
- if (ret < 0)
-- return log_error(EXIT_FAILURE, "Failed to wait for child process %d", pid);
-+ return log_error(EXIT_FAILURE, "Failed to wait for child process %d", attached_pid);
-
- if (WIFEXITED(ret))
- return WEXITSTATUS(ret);
-@@ -365,7 +411,7 @@ type cmdForkexec struct {
- func (c *cmdForkexec) Command() *cobra.Command {
- // Main subcommand
- cmd := &cobra.Command{}
-- cmd.Use = "forkexec <container name> <containers path> <config> <cwd> <uid> <gid> -- env [key=value...] -- cmd <args...>"
-+ cmd.Use = "forkexec <container name> <containers path> <config> <cwd> <uid> <gid> <coresched> -- env [key=value...] -- cmd <args...>"
- cmd.Short = "Execute a task inside the container"
- cmd.Long = `Description:
- Execute a task inside the container
---
-2.33.1
-
diff --git a/testing/lxd/APKBUILD b/testing/lxd/APKBUILD
index 18414a3c920..d116bd2ccef 100644
--- a/testing/lxd/APKBUILD
+++ b/testing/lxd/APKBUILD
@@ -1,8 +1,8 @@
# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=lxd
-pkgver=4.19
-pkgrel=2
+pkgver=4.20
+pkgrel=0
pkgdesc="a container hypervisor and a new user experience for LXC"
url="https://linuxcontainers.org/lxd/"
arch="all !mips !mips64"
@@ -68,11 +68,6 @@ options="!check"
source="https://linuxcontainers.org/downloads/lxd/lxd-$pkgver.tar.gz
$pkgname.confd
$pkgname.initd
- 10-check-whether-the-kernel-supports-core-sched.patch
- 20-support-core-sched-for-vm.patch
- 30-reorder-kernel-features.patch
- 40-separate-entries-for-pure-core-sched.patch
- 50-support-core-sched-for-container.patch
"
ldpath="/usr/lib/lxd"
sonameprefix="$pkgname:"
@@ -138,12 +133,7 @@ scripts() {
}
sha512sums="
-8569912999af71c92740c060f85ea2a37b1943e924ab4be62421c96cb1ee05a3eb2802f130fc11774cb036d8348260ca65d63b6da2ca3fe6f75a681a36d62dfd lxd-4.19.tar.gz
+af8639e93f719a6aa1e37e7dafb5c221230470eb7a565422e6d1f6540e1d4250c00549831a17abbf3d4252bd473b71469bbbc93c7afcde68704d6a401967ed72 lxd-4.20.tar.gz
1bbb26a61b3812e6eb4c3cb7db6c2d9adb43195f96f317d6bba1ace6a97f1faed0677a12c3827002bc147edba9b355f0e7ead3960d254a131b25fb8c060ea8d0 lxd.confd
ebf9608ea3db25b456a557c81838c6a793adf5f490bd64e1f3dc6951bad619188cb0170f0a794b086adbd128267b4339ab46c1b6a815a4ae7f3a6566b7854d97 lxd.initd
-d981406c65a216c3239735c31d24ef9bbdd3d378f560b1f776e4b204e247476ba9d924368a60309566c1906c46005891cc196ea2e4fcb20a2c939ec53e281b6f 10-check-whether-the-kernel-supports-core-sched.patch
-eed62eec91e653b7b52982eb4083c972210f1d5eb47ddf63709b50623d5cfe689e90ae00eed7fa119675f56101c87c1df4a0249184b94edb6c5e797db13af2e9 20-support-core-sched-for-vm.patch
-95d8b8bb1649a897734bda20f5fc3da3e30edb445319f5e7e8b4090f4511c3980f6d1220fc326b180165b526711e4729acd16171ddda12485ed2428804cb9614 30-reorder-kernel-features.patch
-b302c7ef4a37f50c00c516ee9957ecbd8116796ddd75470f6c942f96dd506e7bd44af2cd8bfdcacccd25f29d74b0c9c94335dc181479669b4e40ff915c19ccf0 40-separate-entries-for-pure-core-sched.patch
-28b5807e9c5dc9c5fa0a078d831c0a3f9e6eae4256c17be190b958bcfac829a4de7262006205e3b7d11156368a70b56ca4472e4fde47fb37d040693156140e5c 50-support-core-sched-for-container.patch
"