Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755894AbdDNXdG (ORCPT ); Fri, 14 Apr 2017 19:33:06 -0400 Received: from mail-eopbgr10111.outbound.protection.outlook.com ([40.107.1.111]:5280 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755184AbdDNXcv (ORCPT ); Fri, 14 Apr 2017 19:32:51 -0400 Authentication-Results: huawei.com; dkim=none (message not signed) header.d=none;huawei.com; dmarc=none action=none header.from=virtuozzo.com; Date: Fri, 14 Apr 2017 16:32:34 -0700 From: Andrei Vagin To: Li Zefan CC: Tejun Heo , , LKML , Cgroups Subject: Re: cgroup: avoid attaching a cgroup root to two different superblocks Message-ID: <20170414233233.GA8183@outlook.office365.com> References: <58E7532B.4030505@huawei.com> <20170414232737.GC20350@outlook.office365.com> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Disposition: inline In-Reply-To: <20170414232737.GC20350@outlook.office365.com> User-Agent: Mutt/1.8.0 (2017-02-23) X-Originating-IP: [162.246.95.100] X-ClientProxiedBy: DM5PR1601CA0016.namprd16.prod.outlook.com (10.174.111.29) To VI1PR0801MB1981.eurprd08.prod.outlook.com (10.173.74.14) X-MS-Office365-Filtering-Correlation-Id: ecc14ff3-48e8-4cef-d74c-08d4838e8ed7 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:VI1PR0801MB1981; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1981;3:OuwsB7tBxHz0huvQFhRwaPa/6zmSGfxDYR02gTPAyDsGYKazqVCNK0GsOmBPqmdJanwYojasZGXRaggouyv2igluUk3NffNRorcrF4uNjHSWHUujy4FYTOa106lkhBaHn7hhgIVVRd5t/NmFizlQ/MdoaoP5ovii/gjWK59y0kErpOZtls7P7Rz2ybNIAprKGSP4uAkjunxlIosSZVP+9IVwAmCYdHnUnzfHC0G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Lmmb7E75uoYQ0yg/htzHPv7K69k7OxDFqIyLuecklzIDC8ei5ilP5Q0czM2pYe05ed5jqw/BJZhzF3vaLWjFSXDI8xaJpAOJH+H5lCLhk9r5p2jrwHtYf8sUboECS+xOyNYzZ+4jcUdnymLP1QGMoMDmR8ddO+w2154mRHnURWsR4zg/dU11RBbJt4TYixgvNs8AlXYHLxdCMPGJ18H25ID5sdzNdEEn6ShYmfXERGg14h0MvlcziSsU/fmUO3bzwRauvH5wE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(50582790962513)(211936372134217); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(6041248)(201703131423075)(201702281528075)(201703061421075)(20161123555025)(20161123560025)(20161123562025)(20161123564025)(6072148);SRVR:VI1PR0801MB1981;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB1981; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1981;4:tJt/tV6KmxING3609Oe7KkMXjkvECDv3lX86pkiYXyzI1yaJ7X/ZE/wzT1WyEJhE4dCNtsU8l/seW1xWvpzyT8ozcFbX2NU/wsr+0Ddm+B7uT+gxEE1BjV2jxhkWyXKVezzepTRSQtQ95raa/m2ySiO/r1JS/voHYuhB6XkyoQIKowNmX6FnyQ+yIDzC27KALt8jhbZEzMgdj6PtUgglqCTpRhVG0uZVZ0oKBEvnJ+W7kcNpSZr2FopYFbgt0JP4WbfQFy3Ea0kEgMnVC2/sU1g3DEhMJn+BQNV9Tq48qZOEnXhjpPTt0tuEI/VM91OAS17y10NRhIBjLmDdDAxrSme7JuP+hTkpWECAY4UTlwI6OFP5wd5rC2YOqKcCWI80paIlyPNY39vrmerXIcpyUino173PyJfq0695sPPOXj9ZMjK7MGuys7bwNIHc2jxQ36GyXlQV78yRp3XkC7elRYN2YfsCn3MhCfyeW4oXoUgmdzEl0ofRv4Xer+MCwkY53UVC8me2Jl3wcEmLCdmtmjjIfK67kxUyz9AqSgmrz+19bzccjdgDlIscpGm5lAP7xL/vo1E7P1DiovktdP01J4a5vR+CXbzbEihBnNdxfzY2eFFRHm2xp+Suro/n5mFGOYzFxofnWbqNXKyhU3vDaF6k5ExJUMTcoOva6ByrICRvLZ08WQL87IdLGIHvR93BKml45TxuSYO3QP+HvEoIIT4SX4qGo/71gYjLDtnJ7TT1UFtniaPGDTGINxl7boUok63a0fwDc9eerXGePo0r+rLbY47WTRN3iIBsSm9ww5W6h724DcA46JyJJMSJ5cHaGRE9dkB3t9aIR9ilwuI3qw== X-Forefront-PRVS: 02778BF158 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(39450400003)(39410400002)(39830400002)(39400400002)(24454002)(50986999)(6506006)(54356999)(76176999)(54906002)(4001350100001)(189998001)(55016002)(6306002)(4326008)(106356001)(81166006)(50466002)(8676002)(25786009)(66066001)(47776003)(1076002)(23686003)(5660300001)(2906002)(33656002)(9686003)(3846002)(6116002)(83506001)(6916009)(2950100002)(6246003)(6666003)(5890100001)(575784001)(42186005)(38730400002)(53936002)(110136004)(305945005)(7736002)(229853002)(53416004)(86362001)(18370500001)(26326002)(21314002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB1981;H:outlook.office365.com;FPR:;SPF:None;MLV:nov;PTR:InfoNoRecords;LANG:en; X-Microsoft-Exchange-Diagnostics: =?koi8-r?Q?1;VI1PR0801MB1981;23:hYCAXyi7EDzL7QPPpe89Gd3EHZGDU55aEqklT4JHQ?= =?koi8-r?Q?m4x2dkqs0YrfkUC71uHeEllNz+E58oVKmuorYrvtL2JDIktV99CowWA3CHUXTu?= =?koi8-r?Q?65weVafBfAdPNQ37PhCmmO5HFKUr/6BK6dA3fVj0Ijy60pp6v9mYFbQhpQQH4h?= =?koi8-r?Q?0OPZotefIjMhTqbgEtjSnOgSZpEqyXUOB8E0KEkh1lL0hsyWcOiHKaLhp1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 1;VI1PR0801MB1981;7:mcJLJ4j2LeGenp7jWCRcjNY3OXZqL8/YXLhYvr7RPjlSH8Ol5qANteQjO0cG1N9LmjzhlCC4BNjuDu1JBGkQGh6279Fg21eMgN0v4hG+MAbzA60rlKP6VitS+CiZZnUm9omFiur91uMPMPJQm7mEQQiz8QXn+Ct7bx1GOukk+Jj1b2VB7Qj58ZAqZU+GhX1JVV75fja1AmZ9qp0GIXmETcBgojfev6m8NaHGFT21uN+g+ahQNZJ48vlOpEJ1z8S9FbECjQFNz/GP30fKVTG+G4HB8B9l+RqAL1m1ICkAzXPWuDHzD4fsY0aV97diqiB5h0nMigGobpGEdjW27SBLnw==;20:DG8LvdjtZ3uG9JHwFnc9HH1mBLmFGppeIW3dVcnAbSy0JdFkjakqeMlVdi7HRy/irEFimv895kJOMgNdQmm4MJDMNcupCCuypBb7r+28MRFr9qi4hDjGCrKI8ffjivI8oyroZB24H3Ylrui+/d9jU4SyD7U22qrzgppG6HBP1aA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2017 23:32:45.7735 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1981 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4597 Lines: 124 On Fri, Apr 14, 2017 at 04:27:37PM -0700, Andrei Vagin wrote: > Hello, > > One of our CRIU tests hangs with this patch. > > Steps to reproduce: > curl -o cgroupns.c https://gist.githubusercontent.com/avagin/f87c8a8bd2a0de9afcc74976327786bc/raw/5843701ef3679f50dd2427cf57a80871082eb28c/gistfile1.txt > gcc cgroupns.c -o cgroupns > ./cgroupns > ./cgroupns I've found a trivial reproducer: mkdir /tmp/xxx mount -t cgroup -o none,name=zdtmtst xxx /tmp/xxx mkdir /tmp/xxx/xxx umount /tmp/xxx mount -t cgroup -o none,name=zdtmtst xxx /tmp/xxx > > [root@fc24 ~]# strace -s 256 -fe clone,unshare,setns,mount ./cgroupns > mount("none", "/tmp/cgroupns.test/zdtmtst", "cgroup", 0, "none,name=zdtmtst") = 0 > unshare(CLONE_NEWCGROUP) = 0 > clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fe5da0b89d0) = 529 > strace: Process 529 attached > [pid 529] setns(3, CLONE_NEWCGROUP) = 0 > [pid 529] +++ exited with 0 +++ > --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=529, si_uid=0, si_status=0, si_utime=0, si_stime=0} --- > +++ exited with 0 +++ > [root@fc24 ~]# strace -s 256 -fe clone,unshare,setns,mount ./cgroupns > mount("none", "/tmp/cgroupns.test/zdtmtst", "cgroup", 0, "none,name=zdtmtst") = ? ERESTARTNOINTR (To be restarted) > mount("none", "/tmp/cgroupns.test/zdtmtst", "cgroup", 0, "none,name=zdtmtst") = ? ERESTARTNOINTR (To be restarted) > mount("none", "/tmp/cgroupns.test/zdtmtst", "cgroup", 0, "none,name=zdtmtst") = ? ERESTARTNOINTR (To be restarted) > mount("none", "/tmp/cgroupns.test/zdtmtst", "cgroup", 0, "none,name=zdtmtst") = ? ERESTARTNOINTR (To be restarted) > mount("none", "/tmp/cgroupns.test/zdtmtst", "cgroup", 0, "none,name=zdtmtst") = ? ERESTARTNOINTR (To be restarted) > mount("none", "/tmp/cgroupns.test/zdtmtst", "cgroup", 0, "none,name=zdtmtst") = ? ERESTARTNOINTR (To be restarted) > .... > > Thanks, > Andrei > > On Fri, Apr 07, 2017 at 04:51:55PM +0800, Li Zefan wrote: > > Run this: > > > > touch file0 > > for ((; ;)) > > { > > mount -t cpuset xxx file0 > > } > > > > And this concurrently: > > > > touch file1 > > for ((; ;)) > > { > > mount -t cpuset xxx file1 > > } > > > > We'll trigger a warning like this: > > > > ------------[ cut here ]------------ > > WARNING: CPU: 1 PID: 4675 at lib/percpu-refcount.c:317 percpu_ref_kill_and_confirm+0x92/0xb0 > > percpu_ref_kill_and_confirm called more than once on css_release! > > CPU: 1 PID: 4675 Comm: mount Not tainted 4.11.0-rc5+ #5 > > Hardware name: Bochs Bochs, BIOS Bochs 01/01/2007 > > Call Trace: > > dump_stack+0x63/0x84 > > __warn+0xd1/0xf0 > > warn_slowpath_fmt+0x5f/0x80 > > percpu_ref_kill_and_confirm+0x92/0xb0 > > cgroup_kill_sb+0x95/0xb0 > > deactivate_locked_super+0x43/0x70 > > deactivate_super+0x46/0x60 > > ... > > ---[ end trace a79f61c2a2633700 ]--- > > > > Here's a race: > > > > Thread A Thread B > > > > cgroup1_mount() > > # alloc a new cgroup root > > cgroup_setup_root() > > cgroup1_mount() > > # no sb yet, returns NULL > > kernfs_pin_sb() > > > > # but succeeds in getting the refcnt, > > # so re-use cgroup root > > percpu_ref_tryget_live() > > # alloc sb with cgroup root > > cgroup_do_mount() > > > > cgroup_kill_sb() > > # alloc another sb with same root > > cgroup_do_mount() > > > > cgroup_kill_sb() > > > > We end up using the same cgroup root for two different superblocks, > > so percpu_ref_kill() will be called twice on the same root when the > > two superblocks are destroyed. > > > > We should fix to make sure the superblock pinning is really successful. > > > > Cc: stable@vger.kernel.org # 3.16+ > > Reported-by: Dmitry Vyukov > > Signed-off-by: Zefan Li > > --- > > kernel/cgroup/cgroup-v1.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c > > index 1dc22f6..12e19f0 100644 > > --- a/kernel/cgroup/cgroup-v1.c > > +++ b/kernel/cgroup/cgroup-v1.c > > @@ -1146,7 +1146,7 @@ struct dentry *cgroup1_mount(struct file_system_type *fs_type, int flags, > > * path is super cold. Let's just sleep a bit and retry. > > */ > > pinned_sb = kernfs_pin_sb(root->kf_root, NULL); > > - if (IS_ERR(pinned_sb) || > > + if (IS_ERR_OR_NULL(pinned_sb) || > > !percpu_ref_tryget_live(&root->cgrp.self.refcnt)) { > > mutex_unlock(&cgroup_mutex); > > if (!IS_ERR_OR_NULL(pinned_sb))