lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5007B034.4030909@huawei.com>
Date:	Thu, 19 Jul 2012 14:59:00 +0800
From:	Li Zefan <lizefan@...wei.com>
To:	"Aneesh Kumar K.V" <aneesh.kumar@...ux.vnet.ibm.com>
CC:	Andrew Morton <akpm@...ux-foundation.org>, <linux-mm@...ck.org>,
	<kamezawa.hiroyu@...fujitsu.com>, <mhocko@...e.cz>,
	<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] hugetlb/cgroup: Simplify pre_destroy callback

on 2012/7/19 10:55, Aneesh Kumar K.V wrote:

> Andrew Morton <akpm@...ux-foundation.org> writes:
> 
>> On Wed, 18 Jul 2012 11:04:09 +0530
>> "Aneesh Kumar K.V" <aneesh.kumar@...ux.vnet.ibm.com> wrote:
>>
>>> From: "Aneesh Kumar K.V" <aneesh.kumar@...ux.vnet.ibm.com>
>>>
>>> Since we cannot fail in hugetlb_cgroup_move_parent, we don't really
>>> need to check whether cgroup have any change left after that. Also skip
>>> those hstates for which we don't have any charge in this cgroup.
>>>
>>> ...
>>>
>>> +	for_each_hstate(h) {
>>> +		/*
>>> +		 * if we don't have any charge, skip this hstate
>>> +		 */
>>> +		idx = hstate_index(h);
>>> +		if (res_counter_read_u64(&h_cg->hugepage[idx], RES_USAGE) == 0)
>>> +			continue;
>>> +		spin_lock(&hugetlb_lock);
>>> +		list_for_each_entry(page, &h->hugepage_activelist, lru)
>>> +			hugetlb_cgroup_move_parent(idx, cgroup, page);
>>> +		spin_unlock(&hugetlb_lock);
>>> +		VM_BUG_ON(res_counter_read_u64(&h_cg->hugepage[idx], RES_USAGE));
>>> +	}
>>>  out:
>>>  	return ret;
>>>  }
>>
>> This looks fishy.
>>
>> We test RES_USAGE before taking hugetlb_lock.  What prevents some other
>> thread from increasing RES_USAGE after that test?
>>
>> After walking the list we test RES_USAGE after dropping hugetlb_lock. 
>> What prevents another thread from incrementing RES_USAGE before that
>> test, triggering the BUG?
> 
> IIUC core cgroup will prevent a new task getting added to the cgroup
> when we are in pre_destroy. Since we already check that the cgroup doesn't
> have any task, the RES_USAGE cannot increase in pre_destroy.
> 


You're wrong here. We release cgroup_lock before calling pre_destroy and retrieve
the lock after that, so a task can be attached to the cgroup in this interval.

See 3fa59dfbc3b223f02c26593be69ce6fc9a940405 ("cgroup: fix potential deadlock in pre_destroy")

But I think the memcg->pre_destroy has been reworked and now we can safely hold
cgroup_lock when calling the callback, and this can make the code a bit simpler.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ