Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3006799ybi; Mon, 17 Jun 2019 14:32:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqx90eRyN8//ZdW8YLbrzVY1klhOpNY4/K9tkRIb4Xx/PacpbCqVPHlM4c66OMgbmGI8tKWU X-Received: by 2002:aa7:9825:: with SMTP id q5mr599914pfl.140.1560807149055; Mon, 17 Jun 2019 14:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807149; cv=none; d=google.com; s=arc-20160816; b=CPb60CHbjIundHFm3IbS5ldj1GYqav8EMQ906zWHcfZV1a9mxzKsyGIp4d3A1aIqVl Hgys+UU/+58ZePbi54K9lFmDBJiewbviirJs2YfCsvTs2PQeTiImIqkGfrQFt2kQZUFI /OQbAo4ZVVkmFQqsVjXD1XLKC/eeX/G9wPebGd0QHVSVvjADqMs+hKnaHGcRmhUq3aDG KqNscgV1bu4AzD//0zQhGhV1OTbAJoFzcyzy9r2jgk53vHpK+GmvEvzwrny6RCFzmDWa 9gZNDTvspPUymY/nahBaC1VQdSbXeM4dhX3dwVx8Rn5n9o4gir3gES8Sp2vZePmAfrQ8 LClQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Go2PyfejuRJBHdI/4HfRAHH77sfR/ecwy3g9bFRTYmM=; b=eceAnOmHHH/v9cJtR5jvKp9jj3yjLdoWo2/f8vdjaIgWaUfWpnRVx0UzKUWQ2wY3RE 5/A6qrp0bVCHDqeoQCuVLuByhRoBfuFwrSzKrIP6sefUotAEUGnAotfnoK4wAaKp4XvB qgv/gpyv2zbmiMteJcsqIUQB4St2q87Qwa+jIbcFhevdz7+9vURsfhO5Tl/dmRvRvvI7 AgG/bFtPXWP1SSJx/RvxOe/49+4uq32AZYVWU+WRU76GjVxj9zdCiBIQhN5yzSYbW977 lSpe8tRD5uGaVITdVoeKBf7I2LJ+mN5tCh3fLVk8kTUTplazIlOnbV+mdtr3mAHrde2k PyTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H30IYz2g; 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 c22si10838376plz.148.2019.06.17.14.32.14; Mon, 17 Jun 2019 14:32:29 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=H30IYz2g; 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 S1730511AbfFQV2Q (ORCPT + 99 others); Mon, 17 Jun 2019 17:28:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:55304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730499AbfFQV2M (ORCPT ); Mon, 17 Jun 2019 17:28:12 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F337A2063F; Mon, 17 Jun 2019 21:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806891; bh=7mLmb6WP1/xXbjFaN4HCkREzDNnhPdIu2GvP9UMqrQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H30IYz2g2E5x27bdzftO2Dhjue5jSNp6fvFKBuk61u+Eg2MqgB8AiiJcd9GQWmJEd 5QCpiW/L8pjIuUmAEkWi2/MO4oufUXasyY+c+j6XaCTXAEB96Q9ljXJUSLSznP9ifJ jFHPuozEZg77pcPnM+ZaJDcqEfL9mpsnDNMhjhRE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo Subject: [PATCH 4.14 18/53] cgroup: Use css_tryget() instead of css_tryget_online() in task_get_css() Date: Mon, 17 Jun 2019 23:10:01 +0200 Message-Id: <20190617210748.825777885@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210745.104187490@linuxfoundation.org> References: <20190617210745.104187490@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Tejun Heo commit 18fa84a2db0e15b02baa5d94bdb5bd509175d2f6 upstream. A PF_EXITING task can stay associated with an offline css. If such task calls task_get_css(), it can get stuck indefinitely. This can be triggered by BSD process accounting which writes to a file with PF_EXITING set when racing against memcg disable as in the backtrace at the end. After this change, task_get_css() may return a css which was already offline when the function was called. None of the existing users are affected by this change. INFO: rcu_sched self-detected stall on CPU INFO: rcu_sched detected stalls on CPUs/tasks: ... NMI backtrace for cpu 0 ... Call Trace: dump_stack+0x46/0x68 nmi_cpu_backtrace.cold.2+0x13/0x57 nmi_trigger_cpumask_backtrace+0xba/0xca rcu_dump_cpu_stacks+0x9e/0xce rcu_check_callbacks.cold.74+0x2af/0x433 update_process_times+0x28/0x60 tick_sched_timer+0x34/0x70 __hrtimer_run_queues+0xee/0x250 hrtimer_interrupt+0xf4/0x210 smp_apic_timer_interrupt+0x56/0x110 apic_timer_interrupt+0xf/0x20 RIP: 0010:balance_dirty_pages_ratelimited+0x28f/0x3d0 ... btrfs_file_write_iter+0x31b/0x563 __vfs_write+0xfa/0x140 __kernel_write+0x4f/0x100 do_acct_process+0x495/0x580 acct_process+0xb9/0xdb do_exit+0x748/0xa00 do_group_exit+0x3a/0xa0 get_signal+0x254/0x560 do_signal+0x23/0x5c0 exit_to_usermode_loop+0x5d/0xa0 prepare_exit_to_usermode+0x53/0x80 retint_user+0x8/0x8 Signed-off-by: Tejun Heo Cc: stable@vger.kernel.org # v4.2+ Fixes: ec438699a9ae ("cgroup, block: implement task_get_css() and use it in bio_associate_current()") Signed-off-by: Greg Kroah-Hartman --- include/linux/cgroup.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -484,7 +484,7 @@ static inline struct cgroup_subsys_state * * Find the css for the (@task, @subsys_id) combination, increment a * reference on and return it. This function is guaranteed to return a - * valid css. + * valid css. The returned css may already have been offlined. */ static inline struct cgroup_subsys_state * task_get_css(struct task_struct *task, int subsys_id) @@ -494,7 +494,13 @@ task_get_css(struct task_struct *task, i rcu_read_lock(); while (true) { css = task_css(task, subsys_id); - if (likely(css_tryget_online(css))) + /* + * Can't use css_tryget_online() here. A task which has + * PF_EXITING set may stay associated with an offline css. + * If such task calls this function, css_tryget_online() + * will keep failing. + */ + if (likely(css_tryget(css))) break; cpu_relax(); }