From patchwork Wed Oct 10 18:23:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 148573 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1186835lji; Wed, 10 Oct 2018 11:23:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV63yyMUW8XIxGRn02j6cH1StT0IQ4cnE/xE/Dff/udnUM0X9LrDcCPgmg8LbZTsKu8dby3bz X-Received: by 2002:a17:902:8f90:: with SMTP id z16-v6mr573908plo.214.1539195822792; Wed, 10 Oct 2018 11:23:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539195822; cv=none; d=google.com; s=arc-20160816; b=pnR/zReH5QT2qwnv+eVa4Hd64G+fH0PFV2BKZT1hERGdKqwoiXox+a/Hni/iCX1hG5 J5RUFDbkqq0vKdGvFXMXFGwgDrhg96RrxKpE5c7e1ZZqVySTcAAvgoZZSOGUJaXjpva3 +QpvDQC00IH5Aace9SWKaeYJdoeYayhclqr5BgQ8Exyy9oPG2K8WbzYFDG+LaPhKI+v+ 3HV9IuHla0Itmv4smA9Lh3zvwqLpHj2c8u2Pi/NgFalmKa0SNpA3Mp0dVcOXVSJwCPkh /KUdN9UEmp6XlXtZot6DxNSPF28VVt5GQd0NVq6SnWZd4RSf3mUaTHdLKv7QA52AR32U nZNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=zT6XrclaLCw1pjxr7XA0PAGQgJDke2KLd+mzkT1hjWI=; b=URpXDZJo65AgAKVQRht8VynXMrpV0YST2l1dq3hnO+GS5F1HTq0PR+f/PWjgwltKLg k3LRVSv1/sFeBFHKvm+HGHh9OZTxEwKtY/A/pFDAADidCb89mRmf4E/tFFax8tEhMVOS 6FFWkbI7tMTAiJQTBELdeUTYp162hKMKHxUuB0ZKsQWiHFyd8uy2bEvLeFF/XZSzeXgp y2OTFwoG+x4P2XaATmfrg35tTVbmM3zJqWTPAGP5mSzoq6hTB4ibZD7L17/tQ5wOaH/O +56ni1xIskR2vbGkKY9y+xR2QU7iOIMAeK2Rf14uYavu+q3j18tMwzV1RqhNQkLmK2Zl tMbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BbG7b3PK; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h131-v6si22114514pgc.122.2018.10.10.11.23.42; Wed, 10 Oct 2018 11:23:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=BbG7b3PK; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726734AbeJKBrB (ORCPT + 14 others); Wed, 10 Oct 2018 21:47:01 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45650 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726668AbeJKBrB (ORCPT ); Wed, 10 Oct 2018 21:47:01 -0400 Received: by mail-pl1-f193.google.com with SMTP id y15-v6so2911871plr.12 for ; Wed, 10 Oct 2018 11:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=zT6XrclaLCw1pjxr7XA0PAGQgJDke2KLd+mzkT1hjWI=; b=BbG7b3PKRV91ogmt7Da1nd60IYBnNliJK9amJql60OsnLRS58rpL6HPooyV+kdJty9 1EQnGGgFZ+zWFwfy2KxcabHtwwkmIC/LET8j0o3xNUtQ/g6/geg9h8C7o2Km7XVW/9Ue nk8tfLLQy+4G9b9zxP4hGPrtkW3V5Dh445qQA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zT6XrclaLCw1pjxr7XA0PAGQgJDke2KLd+mzkT1hjWI=; b=AoY1bHKBEi3GDVOh3NocuG9kjd5ZkxNfxfwl81WfdpEKUqqkYBzRRIVY1G1sre5L4e f17rNAYURJ3pCqVeyLSV7FrlMXrdprkJtc4KUwA7OO3rixlLJrCvGp7d3h8lHI1CS7L6 P8IMJMwtg4SQ8qzjehVBnUylCQGdO0d/Adw1A4oxcF/lNWdcmkoZzv4dYM4DG7bnCI81 OWIKahL8T4qkWBTyTNUe++ypaXK1ncBUtRl9/f2K0S7T9JVNUc4jUCatlutdvCqxqsve 7QkZzfbUcwTAiL8pWgAXF9MCsRsuZSEJ8ZXvqwtBmG6sS9qcIgvCtiolBysFg/g50Nod ARCw== X-Gm-Message-State: ABuFfojPxjnu3L6jO7UwPFRha/WMFdEe08kCATo0ZUCx//Mmr/6MDLGy jFk+XFp7GB53fDAWSLvtPD6xxw== X-Received: by 2002:a17:902:286b:: with SMTP id e98-v6mr33911497plb.110.1539195821250; Wed, 10 Oct 2018 11:23:41 -0700 (PDT) Received: from localhost.localdomain ([106.51.16.178]) by smtp.gmail.com with ESMTPSA id l2-v6sm23449662pgp.20.2018.10.10.11.23.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Oct 2018 11:23:39 -0700 (PDT) From: Amit Pundir To: Greg KH Cc: Stable , Prateek Sood , Tejun Heo Subject: [PATCH for-4.9.y] cgroup: Fix deadlock in cpu hotplug path Date: Wed, 10 Oct 2018 23:53:36 +0530 Message-Id: <1539195816-16015-1-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Prateek Sood commit 116d2f7496c51b2e02e8e4ecdd2bdf5fb9d5a641 upstream. Deadlock during cgroup migration from cpu hotplug path when a task T is being moved from source to destination cgroup. kworker/0:0 cpuset_hotplug_workfn() cpuset_hotplug_update_tasks() hotplug_update_tasks_legacy() remove_tasks_in_empty_cpuset() cgroup_transfer_tasks() // stuck in iterator loop cgroup_migrate() cgroup_migrate_add_task() In cgroup_migrate_add_task() it checks for PF_EXITING flag of task T. Task T will not migrate to destination cgroup. css_task_iter_start() will keep pointing to task T in loop waiting for task T cg_list node to be removed. Task T do_exit() exit_signals() // sets PF_EXITING exit_task_namespaces() switch_task_namespaces() free_nsproxy() put_mnt_ns() drop_collected_mounts() namespace_unlock() synchronize_rcu() _synchronize_rcu_expedited() schedule_work() // on cpu0 low priority worker pool wait_event() // waiting for work item to execute Task T inserted a work item in the worklist of cpu0 low priority worker pool. It is waiting for expedited grace period work item to execute. This work item will only be executed once kworker/0:0 complete execution of cpuset_hotplug_workfn(). kworker/0:0 ==> Task T ==>kworker/0:0 In case of PF_EXITING task being migrated from source to destination cgroup, migrate next available task in source cgroup. Signed-off-by: Prateek Sood Signed-off-by: Tejun Heo [AmitP: Upstream commit cherry-pick failed, so I picked the backported changes from CAF/msm-4.9 tree instead: https://source.codeaurora.org/quic/la/kernel/msm-4.9/commit/?id=49b74f1696417b270c89cd893ca9f37088928078] Signed-off-by: Amit Pundir --- This patch can be cleanly applied and build tested on 4.4.y and 3.18.y as well but I couldn't find it in msm-4.4 and msm-3.18 trees. So this patch is really untested on those stable trees. Build tested on 4.9.131, 4.4.159 and 3.18.123 for ARCH=arm/arm64 allmodconfig. kernel/cgroup.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 4c233437ee1a..bb0cf1caf1cd 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -4386,7 +4386,11 @@ int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from) */ do { css_task_iter_start(&from->self, &it); - task = css_task_iter_next(&it); + + do { + task = css_task_iter_next(&it); + } while (task && (task->flags & PF_EXITING)); + if (task) get_task_struct(task); css_task_iter_end(&it);