Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755648AbdDNX14 (ORCPT ); Fri, 14 Apr 2017 19:27:56 -0400 Received: from mail-ve1eur01on0107.outbound.protection.outlook.com ([104.47.1.107]:45240 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752573AbdDNX1x (ORCPT ); Fri, 14 Apr 2017 19:27:53 -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:27:38 -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: <20170414232737.GC20350@outlook.office365.com> References: <58E7532B.4030505@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Disposition: inline In-Reply-To: <58E7532B.4030505@huawei.com> User-Agent: Mutt/1.8.0 (2017-02-23) X-Originating-IP: [162.246.95.100] X-ClientProxiedBy: CO2PR05CA0007.namprd05.prod.outlook.com (10.166.88.145) To VI1PR0801MB1982.eurprd08.prod.outlook.com (10.173.74.15) X-MS-Office365-Filtering-Correlation-Id: abb83765-1974-4c09-6157-08d4838dde45 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:VI1PR0801MB1982; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1982;3:k++20Y8fUXhSRBEZxMK35rJAGgXbuPN5yWrSwHBpsTIhny8Coanlqwv4gBCFhnTpjC+dMcQexwIrePI0ciCH/caOsL4k41GX0dMfI9BX+HlHkd5VvTVHdzzfo7Y405dPio3KpKZXqDx4sSvCyyVFHl7hEft/9eT1gLe3daNpmMb5/qH16mOqDAKc0jyBPPHYALOESIBGeCN0w3C/e8Tb015K9o5uY70XhqbbGYEeWFU/OPf0iJSf8Zp0et+wsFi7hy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av2j6kv45JzoBMm6VlkzsQQMSfCyvvmy+7eY06BvsVM2a3Y9NfO/SyQ/aoorWkcCtkpps+Fi8g4oMNRiWl3Jn3h5DFkwgqWzyzVRJ3dqWZvISOTn1G+OoPxQOT7vdMnaVy0fJJOGEQKn+na1219kfJSQD4zhcjmjCsnta7MgqL7CBE/zR0UbhpG4UzMcPAJUoPeFNU3IAhj0HXIkjAThai7NXkhxcT1WMalVMU+4gQc7fuUlMmupymcj6Zy6lKyDXmE= 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)(20161123555025)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(6072148);SRVR:VI1PR0801MB1982;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB1982; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1982;4:Ivg/7Yenek94ySA9pSxUff71Ek6sTMBHpGX8WdlDmvRmwb4Wn9wKEitINgjPGgG7bM0CDsK72HWdUjvOxa1Bv7kK7Xll3d2QAUTTmEYSgBRJGTh8G80pTKh0wGZjKYSpZVBH/0lmZeiYfzD0kzvRPu9JZVqW/8NqTf3U2SjRvyh7GmNTJMx2EU/GJwMQMJ3nw/s3VfqMntw2ie6PpQ2KWvGbgpmRDA5Yec72OqFvKXgk+3lNOkhG9jtSFvvgIPofvzDEqBTEv2Z0bw+nQImOr9jLihiWmAtoqz8oL1EHtsjMSQaYJtrGlobzte5pjJc/Mqd3wLZ7NPyreI67xrnnyCmwN/oWwZbvDg0wkXhzr5ltWE/fDpB0s0vnHBBeeisA7mtF0dtzh2TUy0DfxqmPR1pRcdoO5tsi3MDjSUwagysAXJLDOX5YyGrmXTchrY5qQBDz8+uVhQKkItI90EXa3Ok0XWuoZynLS2aPpp6cqs0RYCgE0BoAvNkPASRHX/2J3s6bIYlRubKjc19glLRP3maN8+CjuXreYCWF4QvvOF1SbFkT9Gwei9kZyvzaq5j18KNfIxJhqVd5RiaLmroApPdxSEjQgoDgY+41znf+L6WX556qul1JG0wlDreIKMbQvlS2I2HaRdDJlE2upYiD3PqMJ8a7SgfO9S1eQIR40VW94zgKlrzEc87vDcAmM9/N3d13IqQ71LRL1kU057RLmsbp3CNstY9UoiIARVXo0wLbvyfTCiRHDhh1MkFZJVcGD/Ljz/i8m49ZR80Br1E9LE2Q8v1RMweYpHoGw8JSZYLa7ZJ4G9kv/W3DT4VyB+F15CMg435S7eZhCL4YtqbfAg== X-Forefront-PRVS: 02778BF158 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(39830400002)(39400400002)(39410400002)(39450400003)(24454002)(4326008)(6116002)(38730400002)(66066001)(3846002)(23686003)(25786009)(6506006)(7736002)(47776003)(1076002)(305945005)(6916009)(5890100001)(2950100002)(6666003)(110136004)(229853002)(2906002)(83506001)(50986999)(33656002)(53416004)(106356001)(55016002)(42186005)(54356999)(5660300001)(4001350100001)(76176999)(86362001)(575784001)(50466002)(54906002)(9686003)(53936002)(6246003)(8676002)(81166006)(6306002)(189998001)(18370500001)(26326002)(21314002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB1982;H:outlook.office365.com;FPR:;SPF:None;MLV:nov;PTR:InfoNoRecords;LANG:en; X-Microsoft-Exchange-Diagnostics: =?koi8-r?Q?1;VI1PR0801MB1982;23:1lYLg65LAFFSIc4HBLEn+KYRKavrevCBjHbbnRZSx?= =?koi8-r?Q?lEUZiSY/O1hCy+OTQzMKgfTZr9gj21BzVaDO1PiJqBh++suhOgbZlyq+/u61H4?= =?koi8-r?Q?HCiDIhN+eABIlXsdgajtGZxBYCQLiHTTi+X1yx89F/lV0rwbvjJ1qRtZYPfWyR?= =?koi8-r?Q?Xg22c3vmGay0m5rIELtEeyo8nWtAHjZKdymQcXLk/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ws?= =?koi8-r?Q?xqRi4PC5uce8oi9CAuFDohLpmctyBMJYY6cphjtDvZOMqPU2zU2v9+ZdN0Xpei?= =?koi8-r?Q?Z+WylqCn2yiN2J+6gGeDJc8AYd09HFBDcghiQHYA+HI51kENSoX0+y424AtUuF?= =?koi8-r?Q?m21pmsl7Mxt/VJJvUB9vps4w3NXJ5talSfpqPf+G1uHr7cYiBqZe31bFMLEGf?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1982;6:hR9KAvVjteARzjRgnaEsroodPAXQcQjr8JE0tJDEbRrv+1v7YVSUui3dHN+n8+MLCKQVg45gnirjW7XoIUVbkBbU5UL+jiMgAINcESAmge1JYVOPSe4XFA56qbw9f7/DHOdFJ6X5O/TFNEIarZFqBvwqKKo1NopGfKLf25hU99rVmP0r6BB0EkemkqVDyPCmkRR/aycJTHgaRo263VHCdWGUtzf5jkC1hAdEiw0rbhbgA9YaHoAq45n70KSCMEyRRx05mTp+e/YIKgMbGdlANQIPX18+5tcd0y1vxqZ7fhhhMnUSYR76VN+1tYvmLdEkw7QwmiuG/aLI2U2gjInftNBViibhpIBf9DYAS+UJwSfd9n8imkIzhLq2sNGyvpkjPM8YXSbLpk/754JoUC9ewAMRjL46Vc/pZ8YcmebQD+Tn33iIeakNGrKLHExx6yIjUGXfbnGkCh4AugOZArjgaA==;5:tQkwdJWo+B1Fgj4C5htRbcnqSdVZXDDq/u8DG/MLhzGsvMxCEVqxhch70wnv+8wus7bzwN9lljHKdbdulvLdI8CNYr0cdZqgCtREYVgXZuL7GRtFar+X6jv7x5TYXk56QXKR1Fy9GMFhYoxJRRmiNA==;24:4CwaL7gUnwtHOqVvEva0ehOQT/SKpupi36cMpYX0Uyd1aMO8QIWWFa8Yej1jvveBOTgMXTgYNsVtwpct8yZE0MQegAuf1r2VspTX4RaKyTU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1982;7:HD50oBs8bIqRDXtJaHm85dA18J9fcmodW6wae4OfvOjtrkRP8YTbNaJik8uQSb9/XwO/nFrs1Fkbk7KsAzrFEksQgcSg//aB9gQei/lyvMAf4ur+HD9d21ek4DUlhxRCBS1C3w2Z0ssIq7jSB+vm2OK71DOtbgZzQna32ipsKocU3P88X1/rCZgO0SDy69076EHu1wbl5GH6Ya4jV6cXhZpUaPwXg+WQt7fwwm0Ywq6K7EjbZcQzzuOfb2iFVCP5iqdM6TCHRSUyke/FOVedneqT+zsw806JS77EPVfVRdM2DEZIdLZNgGFLMsL5Db09IsqUafYEooTSc85BW6C2Vg==;20:m8KNKJgS98TXlgjQIkKqDCjRoZfFCN075DPJ5zEV4xnBskG40pLclcUREKjKIa9QUvMM5FdWpqR8inTX2vKfWYBXf3o7POoiZOuBPj7Adz6lvbjMrc0YWpyr6ZhJBwlZjuNZv/FwhW7uHeStSCh9/s7+57TM1Q8gx6jBindldMc= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2017 23:27:49.6218 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1982 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4120 Lines: 115 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 [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))