From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07F06C282DD for ; Sat, 11 Jan 2020 00:03:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AF0842053B for ; Sat, 11 Jan 2020 00:03:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="jLj7968m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF0842053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4ADF78E0005; Fri, 10 Jan 2020 19:03:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 438198E0001; Fri, 10 Jan 2020 19:03:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FFCB8E0005; Fri, 10 Jan 2020 19:03:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0161.hostedemail.com [216.40.44.161]) by kanga.kvack.org (Postfix) with ESMTP id 1641C8E0001 for ; Fri, 10 Jan 2020 19:03:56 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 98A1A180AD811 for ; Sat, 11 Jan 2020 00:03:55 +0000 (UTC) X-FDA: 76363405230.30.grain32_51a36c65285d X-HE-Tag: grain32_51a36c65285d X-Filterd-Recvd-Size: 6343 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Sat, 11 Jan 2020 00:03:54 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id r19so3901793ljg.3 for ; Fri, 10 Jan 2020 16:03:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=0dV0HpLb0SFVmBzU2FxcT9u699TRcir0XtuMO7iJ5Rk=; b=jLj7968mfYKL2VYZr0TuLfiNgEm5+DSR9KdJ7zlbQDt/OA7icoEp8yEMnyLppqBrue 3NcMP+/XLLUMQj7Tk8Ede7FOYr8o9bc2tL4Wqsl08zcoZFkqXB9vNlaQS9kd6XhnhAYa uLKfVHKK3ZcR0lMjU2IQbPTpuHVY+C0O4ylgpVM9nFwKVM/+4xnm7yYBzpTkvlEvVwwg Cf7J2R+hdmjc9S5e5ra4dZ3oIn7TmzBc8WMZPbgzzMJUBj6BCtwcvkOa0AxYMorFQVPh sk5+IEgmkdM4y1F3gxQqL1rQvdHZrj0kRrSzdfoHeqNk6/HSxWPpfmUzTrJK2rwYZtM/ SzTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=0dV0HpLb0SFVmBzU2FxcT9u699TRcir0XtuMO7iJ5Rk=; b=glUS195VdX1tOAUQtD3BWyFygPgFqaDAUBsnCwTK5EiZutWvuI58Vl6W8OK2IK+xXp Q9pSXrFmebqIa5bf3gcVyNCUI6c8wAcs8zE+FkEieXNLyQcw5rOWeLNshQouvIW+Intr /3hzrWUaLapjmioeBb8VdCBkRPvWXIyNeJ/g8qYJioQbJeZJObppLbtat+nh6G2xZrCl KfUJ1VSd8enn+1W7RRDolWvqxr5bXepUyR98dcVtadI4nYbd4eY9EjpQ6Fz4HHDaLdni UWccDH5CVK1V0mbhOdSmeWNz18zLNQTbAFxI4rutdkmvTnfPNgUGNqFFotVHXqw124rz bclw== X-Gm-Message-State: APjAAAUhTY/E25j8GIC7Pblz0HBOmuOZ2Y31avRvxOYiQyb6LuDjqVbS SgxYwdOZAAYQEovWLV0u0V+r9g== X-Google-Smtp-Source: APXvYqzxnwFlKBQ+HuZ0Ajaxu7sWb5whqIl3y01j830CNxhgfR+kjdu4tsCtYI+F/Uo0FrIyKKggQw== X-Received: by 2002:a2e:858b:: with SMTP id b11mr4091674lji.135.1578701033705; Fri, 10 Jan 2020 16:03:53 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id n23sm1791373lfa.41.2020.01.10.16.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2020 16:03:53 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id B1C2010144E; Sat, 11 Jan 2020 03:03:52 +0300 (+03) Date: Sat, 11 Jan 2020 03:03:52 +0300 From: "Kirill A. Shutemov" To: Wei Yang Cc: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, yang.shi@linux.alibaba.com, alexander.duyck@gmail.com, rientjes@google.com Subject: Re: [Patch v2] mm: thp: grab the lock before manipulation defer list Message-ID: <20200111000352.efy6krudecpshezh@box> References: <20200109143054.13203-1-richardw.yang@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200109143054.13203-1-richardw.yang@linux.intel.com> User-Agent: NeoMutt/20180716 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Jan 09, 2020 at 10:30:54PM +0800, Wei Yang wrote: > As all the other places, we grab the lock before manipulate the defer list. > Current implementation may face a race condition. > > For example, the potential race would be: > > CPU1 CPU2 > mem_cgroup_move_account split_huge_page_to_list > !list_empty > lock > !list_empty > list_del > unlock > lock > # !list_empty might not hold anymore > list_del_init > unlock I don't think this particular race is possible. Both parties take page lock before messing with deferred queue, but anytway: Acked-by: Kirill A. Shutemov > > When this sequence happens, the list_del_init() in > mem_cgroup_move_account() would crash if CONFIG_DEBUG_LIST since the > page is already been removed by list_del in split_huge_page_to_list(). > > Fixes: 87eaceb3faa5 ("mm: thp: make deferred split shrinker memcg aware") > > Signed-off-by: Wei Yang > Acked-by: David Rientjes > > --- > v2: > * move check on compound outside suggested by Alexander > * an example of the race condition, suggested by Michal > --- > mm/memcontrol.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index bc01423277c5..1492eefe4f3c 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5368,10 +5368,12 @@ static int mem_cgroup_move_account(struct page *page, > } > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > - if (compound && !list_empty(page_deferred_list(page))) { > + if (compound) { > spin_lock(&from->deferred_split_queue.split_queue_lock); > - list_del_init(page_deferred_list(page)); > - from->deferred_split_queue.split_queue_len--; > + if (!list_empty(page_deferred_list(page))) { > + list_del_init(page_deferred_list(page)); > + from->deferred_split_queue.split_queue_len--; > + } > spin_unlock(&from->deferred_split_queue.split_queue_lock); > } > #endif > @@ -5385,11 +5387,13 @@ static int mem_cgroup_move_account(struct page *page, > page->mem_cgroup = to; > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > - if (compound && list_empty(page_deferred_list(page))) { > + if (compound) { > spin_lock(&to->deferred_split_queue.split_queue_lock); > - list_add_tail(page_deferred_list(page), > - &to->deferred_split_queue.split_queue); > - to->deferred_split_queue.split_queue_len++; > + if (list_empty(page_deferred_list(page))) { > + list_add_tail(page_deferred_list(page), > + &to->deferred_split_queue.split_queue); > + to->deferred_split_queue.split_queue_len++; > + } > spin_unlock(&to->deferred_split_queue.split_queue_lock); > } > #endif > -- > 2.17.1 > > -- Kirill A. Shutemov