Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3832038ybl; Tue, 21 Jan 2020 07:51:36 -0800 (PST) X-Google-Smtp-Source: APXvYqwcoMvQnjAer5b0qdJ42QTkN6U619gzKOqUHmXp1m4J9KAA1aT2FWobTLwtlSkyqXsUt6N3 X-Received: by 2002:aca:1a17:: with SMTP id a23mr3326834oia.84.1579621895919; Tue, 21 Jan 2020 07:51:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579621895; cv=none; d=google.com; s=arc-20160816; b=ZEQFyW5MnpIDyOWCHCl/DM7k0VWxOST/KPWzEE1frFuyKY4ueHN5srB7UJY56tTCNW BBwW9/pSyi+wRbAJwKAUup2q+maByI5qCQy7aAwxrh/S0wmVIncgXBcnwarZVlSJAuCm m/A3KASCD7idPXyf24s8oT1WnpUL6g2tQCZwyacr1OlggxY27dWTDo3ubMnGVkm1MjzC ntrKO3yXQ4Xbqn1keUDth89t8ThKjP7sEBd1dbsSuMZHGDNuacGxXV+1O/fMV35ClbL6 swdqn3fgBykaMLiz+QLyhrjIbZkFf/A9hDzInWl/AeKKhv42i0Ocheu8G/d88D0gaOY2 B8+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=e7UAhPg1QPkPgijAC0ZkyGbg4qVcXY49vfjg5qsBW8o=; b=ngxtGMTspiJZ8kgRlODYs/qyEKvPtSbAq2Xp3EeCjS80VTllxYsItyuZEV5iMfc8ja N+qaQ5IZwZ3Z1BpYmHj/7+GKiMqnfK7lMX7qL/9gkfKIrohEnmlkeYMs5SYAk3GqquvA WQqXtU3DWz6EznnlK8NzqSY/8ypMsnoIq5HWZUYm4hYkPsNnE59T0u0drt64C+GOj/AQ 9EJN+bU6p8HiqrsLx4tXz3MTk9BiaepqVzKM5ZSN6VCTFDXhi0cvBNO76TIFLbBYlp2j 4LY/qNlDRNSYGgHx4ACIyUU/FSfXVPrjLErfKi4JKLTXmYZGSLgW3XBpqgv/2DjGGKpG JguQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 17si24413802otv.149.2020.01.21.07.51.22; Tue, 21 Jan 2020 07:51:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729081AbgAUPu0 (ORCPT + 99 others); Tue, 21 Jan 2020 10:50:26 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:39888 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726714AbgAUPu0 (ORCPT ); Tue, 21 Jan 2020 10:50:26 -0500 Received: from [154.119.55.246] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1itvnM-0004D0-5C; Tue, 21 Jan 2020 15:50:24 +0000 From: Christian Brauner To: linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Tejun Heo Cc: Oleg Nesterov , Christian Brauner Subject: [PATCH v5 0/6] clone3 & cgroups: allow spawning processes into cgroups Date: Tue, 21 Jan 2020 16:48:38 +0100 Message-Id: <20200121154844.411-1-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hey Tejun, This is v5 of the promised series to enable spawning processes into a target cgroup different from the parent's cgroup. /* v1 */ Link: https://lore.kernel.org/r/20191218173516.7875-1-christian.brauner@ubuntu.com /* v2 */ Link: https://lore.kernel.org/r/20191223061504.28716-1-christian.brauner@ubuntu.com Rework locking and remove unneeded helper functions. Please see individual patch changelogs for details. With this I've been able to run the cgroup selftests and stress tests in loops for a long time without any regressions or deadlocks; lockdep and kasan did not complain either. /* v3 */ Link: https://lore.kernel.org/r/20200117002143.15559-1-christian.brauner@ubuntu.com Split preliminary work into separate patches. See changelog of individual commits. /* v4 */ Link: https://lore.kernel.org/r/20200117181219.14542-1-christian.brauner@ubuntu.com Verify that we have write access to the target cgroup. This is usually done by the vfs but since we aren't going through the vfs with CLONE_INTO_CGROUP we need to do it ourselves. /* v5 */ Don't pass down the parent task_struct as argument, just use current directly. Put kargs->cset on error. With this cgroup migration will be a lot easier, and accounting will be more exact. It also allows for nice features such as creating a frozen process by spawning it into a frozen cgroup. The code simplifies container creation and exec logic quite a bit as well. I've tried to contain all core changes for this features in kernel/cgroup/* to avoid exposing cgroup internals. This has mostly worked. When a new process is supposed to be spawned in a cgroup different from the parent's then we briefly acquire the cgroup mutex right before fork()'s point of no return and drop it once the child process has been attached to the tasklist and to its css_set. This is done to ensure that the cgroup isn't removed behind our back. The cgroup mutex is _only_ held in this case; the usual case, where the child is created in the same cgroup as the parent does not acquire it since the cgroup can't be removed. The series already comes with proper testing. Once we've decided that this approach is good I'll expand the test-suite even more. The branch can be found in the following locations: [1]: kernel.org: https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/log/?h=clone_into_cgroup [2]: github.com: https://github.com/brauner/linux/tree/clone_into_cgroup [3]: gitlab.com: https://gitlab.com/brauner/linux/commits/clone_into_cgroup Thanks! Christian Christian Brauner (6): cgroup: unify attach permission checking cgroup: add cgroup_get_from_file() helper cgroup: refactor fork helpers cgroup: add cgroup_may_write() helper clone3: allow spawning processes into cgroups selftests/cgroup: add tests for cloning into cgroups include/linux/cgroup-defs.h | 6 +- include/linux/cgroup.h | 20 +- include/linux/sched/task.h | 4 + include/uapi/linux/sched.h | 5 + kernel/cgroup/cgroup.c | 297 ++++++++++++++---- kernel/cgroup/pids.c | 15 +- kernel/fork.c | 19 +- tools/testing/selftests/cgroup/Makefile | 6 +- tools/testing/selftests/cgroup/cgroup_util.c | 126 ++++++++ tools/testing/selftests/cgroup/cgroup_util.h | 4 + tools/testing/selftests/cgroup/test_core.c | 64 ++++ .../selftests/clone3/clone3_selftests.h | 19 +- 12 files changed, 501 insertions(+), 84 deletions(-) base-commit: b3a987b0264d3ddbb24293ebff10eddfc472f653 -- 2.25.0