Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp476804imu; Fri, 25 Jan 2019 05:44:01 -0800 (PST) X-Google-Smtp-Source: ALg8bN4wRYx9iDEjzJnxxiaI+xvmVdMeALus876HAg2odgS7NcuClTKkRZ+ECAY1uUUTkscjLnz6 X-Received: by 2002:a17:902:bb86:: with SMTP id m6mr11217918pls.315.1548423841833; Fri, 25 Jan 2019 05:44:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548423841; cv=none; d=google.com; s=arc-20160816; b=JBCzgF0Sk0XUsEDiy8ZAgbDAtcoxbYiE2iwB5cZikFmD2oUOI8nmexcfNgAKR9JoA0 LFrnIJtdaZR1NkK1flNt8+tpwpsrQpySCTxV3DWodIRlY6mqTHP4ikiP0+9i6JdTqQmV OftPwQcAUVhX7dOcXmIQDGOiLdT7qbIZodSH5ZjFmNza+B79wILOqVl2jq/cwgj8gi// ph36rKV1nJzRwpvBtB5rpkiZAVgTMlB2wDxIS5z0ZcJPI0JV42oFZG0cfBxbuEkd8Uuk YTdqPbNgkMFlRrYqiGhQtkB/scRRxMH5ROvVG+Tssmfmvo2ZYOtUuXMgqX7KObQDy8m/ Tiig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=LdkpABYc9CqQ02LauXanWHHbVBuLQJx2n/BtRizK9Ac=; b=vfek0y+QkNDVVOqs4+LQHoUwdbSME2OyLlJztrRQtqCw4cWOsFB4IqtF0h9gQDGg6z ZVDcse3ptX/p+xWVsfW3Z16pjeWmU1Ixsge4LrmM8eYLT8j7lF9/kzAabYP/NH6FDWcJ 3slb//qFp83lx1kIyhTUFxc1ULe8OxPMQ6iB4WBcWychKmi+n5tydmF3nxgVTvEsGsLm QKTVP0yk/AMnt8LkVvgJeegvp45PQBYJ1fP39rah28BTNfRDRsB4Z61JnZBgx/F4FVes rO+IzrdV2hbW1/VNGMu1hhtIHhhCXd1AnSL+2myWEwaxANk2rA/UP0vrvUsm1o0jCSH4 n3eg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t17si1467938pgk.217.2019.01.25.05.43.44; Fri, 25 Jan 2019 05:44:01 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728238AbfAYNnk (ORCPT + 99 others); Fri, 25 Jan 2019 08:43:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51754 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726252AbfAYNnj (ORCPT ); Fri, 25 Jan 2019 08:43:39 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 29A34C7A15; Fri, 25 Jan 2019 13:43:39 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.163]) by smtp.corp.redhat.com (Postfix) with SMTP id C699F61520; Fri, 25 Jan 2019 13:43:37 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 25 Jan 2019 14:43:38 +0100 (CET) Date: Fri, 25 Jan 2019 14:43:36 +0100 From: Oleg Nesterov To: Roman Gushchin Cc: Tejun Heo , kernel-team@fb.com, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Roman Gushchin Subject: Re: [PATCH v6 4/7] cgroup: cgroup v2 freezer Message-ID: <20190125134336.GA18991@redhat.com> References: <20181222000307.28231-1-guro@fb.com> <20181222000307.28231-5-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181222000307.28231-5-guro@fb.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 25 Jan 2019 13:43:39 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/21, Roman Gushchin wrote: > > +static void cgroup_do_freeze(struct cgroup *cgrp, bool freeze) > +{ > + struct css_task_iter it; > + struct task_struct *task; > + > + lockdep_assert_held(&cgroup_mutex); > + > + spin_lock_irq(&css_set_lock); > + if (freeze) { > + cgrp->freezer.nr_tasks_to_freeze = __cgroup_task_count(cgrp); > + set_bit(CGRP_FREEZE, &cgrp->flags); > + } else { > + clear_bit(CGRP_FREEZE, &cgrp->flags); > + } > + spin_unlock_irq(&css_set_lock); > + > + css_task_iter_start(&cgrp->self, 0, &it); > + while ((task = css_task_iter_next(&it))) { > + /* > + * Ignore kernel threads here. Freezing cgroups containing > + * kthreads isn't supported. > + */ > + if (task->flags & PF_KTHREAD) > + continue; > + cgroup_freeze_task(task, freeze); > + } > + css_task_iter_end(&it); I don't understand why this can race with exiting task. Or with SIGKILL which kills a task before it sets current->frozen. How can we trust nr_tasks_to_freeze at all? Yes you added cgroup_dec_tasks_to_freeze() into cgroup_exit(). But it won't be called if CGRP_FROZEN was not set yet, or because of "spurious" transitions caused by cgroup_inc/dec_frozen_cnt() called by this or other tasks. it seems that cgroup_exit() should check CGRP_FREEZE instead... Oleg.