Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753004AbbFET5c (ORCPT ); Fri, 5 Jun 2015 15:57:32 -0400 Received: from mail-ig0-f173.google.com ([209.85.213.173]:35088 "EHLO mail-ig0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752345AbbFET5a (ORCPT ); Fri, 5 Jun 2015 15:57:30 -0400 MIME-Version: 1.0 X-Originating-IP: [122.106.150.15] In-Reply-To: <1431749621-30451-8-git-send-email-cyphar@cyphar.com> References: <1431749621-30451-1-git-send-email-cyphar@cyphar.com> <1431749621-30451-8-git-send-email-cyphar@cyphar.com> Date: Sat, 6 Jun 2015 05:57:29 +1000 Message-ID: Subject: Re: [PATCH v11 7/7] cgroup: implement the PIDs subsystem From: Aleksa Sarai To: Tejun Heo Cc: lizefan@huawei.com, mingo@redhat.com, Peter Zijlstra , richard@nod.at, =?UTF-8?B?RnLDqWTDqXJpYyBXZWlzYmVja2Vy?= , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Aleksa Sarai Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2465 Lines: 84 Hello Tejun, Is it safe for us to task_get_css() every task in the tset in ->can_attach() and then put_css() in ->attach() and ->cancel_attach()? In other words: if we have a ref to a task's css, are we guaranteed that the task_css() will return the same thing every time? Here's what I'm currently doing: static int pids_can_attach(struct cgroup_subsys_state *css, struct cgroup_taskset *tset) { struct pids_cgroup *pids = css_pids(css); struct task_struct *task, *fail_task; int err; cgroup_taskset_for_each(task, tset) { struct cgroup_subsys_state *old_css; struct pids_cgroup *old_pids; old_css = task_get_css(task, pids_cgrp_id); old_pids = css_pids(old_css); err = pids_try_charge(pids, 1); if (err) goto out_fail; pids_uncharge(old_pids, 1); continue; out_fail: fail_task = task; goto err_revert; } return 0; err_revert: cgroup_taskset_for_each(task, tset) { css_put(task_css(task, pids_cgrp_id)); if (task == fail_task) break; pids_uncharge(pids, 1); } return err; } static void pids_cancel_attach(struct cgroup_subsys_state *css, struct cgroup_taskset *tset) { struct pids_cgroup *pids = css_pids(css); struct task_struct *task; cgroup_taskset_for_each(task, tset) { struct cgroup_subsys_state *old_css; struct pids_cgroup *old_pids; old_css = task_css(task, pids_cgrp_id); old_pids = css_pids(old_css); pids_charge(old_pids, 1); pids_uncharge(pids, 1); css_put(old_css); } } static void pids_attach(struct cgroup_subsys_state *css, struct cgroup_taskset *tset) { struct task_struct *task; cgroup_taskset_for_each(task, tset) css_put(task_css(task, pids_cgrp_id)); } -- Aleksa Sarai (cyphar) www.cyphar.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/