Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6061656ybl; Sun, 22 Dec 2019 22:19:03 -0800 (PST) X-Google-Smtp-Source: APXvYqwQnIuKbHC0J9OESSB/5pUHoclu8SRyq9wcIL/nFbNZYP0qrfWhO/yx5XsiRzMRo67L6BxG X-Received: by 2002:a9d:7552:: with SMTP id b18mr29316062otl.20.1577081943093; Sun, 22 Dec 2019 22:19:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577081943; cv=none; d=google.com; s=arc-20160816; b=PEaqb+ClVfNXGrmjM5UD2oFIJ89qUCi43upCswudrITVb82ql3dFpw4rFsFZxE4oNM FMwCmA7XM5mEAdzF22v6aPChw0xSQbMsTmneCAxKpp4RhSG8mWR3tGx2uTOrUxQ/dMwa tGE0cA1qeSvCtTp0m997Vrg/E00GnCH04tKh5EJuIVGw0S0ot3eF0f2IGVp3VPlnpOJi 2+EygvUhPqN2GQTC0QCtVvKZQWrxaWIwcACwflsPIiMYfEUN7E7aGVyMJV2EFKurwmM3 qZk/zvxSd1nueDbbw+z++nBClk6yuVtpzoOs6UHxxS3+Ane7GzIgp7CzBFXFuloLI36j yC0A== 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=7lkxjVJ1rdxQlv4RD/Pzw0TfL3wL9Q7mGZvk2OLhbeE=; b=Cu23KRUKpD5BwGBL1bwRrIqQtOsdNspj9kTeGYiIXxIQGJOlHs0+yTr+L8+0+2qWn8 Nm3tqsQwBoFNHL8fVWWPRht0q0OSTQCQHEUeNsFWLrRVBB4xRKg8h1lAk4r66/v42y53 nvjAEyVdVgL+m86EaURpFFMEChy0Wa7dPz81Gya1dwjjcQDN8rCecauoUAkMdmSFe4mt iQhgRT4vg4k2sc1l8Ne0ASuvh5RH5ZqdDNxm6nSDo7aOa5/2DtvoLH2uVZrJ6ANWHjsh xjDxmCpkA6Jqi6lKAfMIWMg6Fj1Jjc8yjbNMFygShBSD+R6qCHcDDS+NW6gH/ENtzs+H Mlsw== 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 q7si6653724otn.108.2019.12.22.22.18.50; Sun, 22 Dec 2019 22:19:03 -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 S1725909AbfLWGSM (ORCPT + 99 others); Mon, 23 Dec 2019 01:18:12 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:54079 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbfLWGSM (ORCPT ); Mon, 23 Dec 2019 01:18:12 -0500 Received: from [172.58.139.225] (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 1ijH2e-0003zo-Nn; Mon, 23 Dec 2019 06:18:09 +0000 From: Christian Brauner To: linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Tejun Heo Cc: Christian Brauner Subject: [PATCH v2 0/3] clone3 & cgroups: allow spawning processes into cgroups Date: Mon, 23 Dec 2019 07:15:01 +0100 Message-Id: <20191223061504.28716-1-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 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 v2 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 */ 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. 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. (This is a pre-holiday patchset and I'm moving so I might be a little slower responding to reviews but I wanted to send this out before the new year.) 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 (3): cgroup: unify attach permission checking clone3: allow spawning processes into cgroups selftests/cgroup: add tests for cloning into cgroups include/linux/cgroup-defs.h | 7 +- include/linux/cgroup.h | 25 +- include/linux/sched/task.h | 4 + include/uapi/linux/sched.h | 5 + kernel/cgroup/cgroup.c | 277 ++++++++++++++---- kernel/cgroup/pids.c | 25 +- 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, 506 insertions(+), 75 deletions(-) base-commit: d1eef1c619749b2a57e514a3fa67d9a516ffa919 -- 2.24.0