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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=unavailable 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 C2D1DC282D0 for ; Mon, 28 Jan 2019 21:09:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5D17D217F5 for ; Mon, 28 Jan 2019 21:09:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D17D217F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CAB258E0003; Mon, 28 Jan 2019 16:09:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C59E08E0001; Mon, 28 Jan 2019 16:09:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B238C8E0003; Mon, 28 Jan 2019 16:09:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id 849DE8E0001 for ; Mon, 28 Jan 2019 16:09:26 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id p79so19651934qki.15 for ; Mon, 28 Jan 2019 13:09:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:to:cc :references:from:openpgp:autocrypt:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=wNlDRfvp3oVVeOYVKeZHcv5V8UVYVlJHqI7gCedr3kw=; b=Xt76qQgOUFkCWdNiBzkg/mkhCyMHGDdPu17YTeYLlsTS7CMtp1vRlvVBOesA4LjUlr Hk9Y/eM3tpnJgHqhwFNNFiAdqn+TwAvNSLTNem4LPueYL+q+bhwwUrtw6n91cO0puYth LLzuPeMNqeMof3YAMg7SkgxX2rr29r66ILv0FmQXa6ZaFGkim+O5QRN3Lp5mbMYiLDUS arDKPK13lh7V+Yhimy6BwYYJZd0fOThTZgKCe+bnVtR4YdlGCotW1wLV+r36f1gsGuzg HYvtAjJA6cvkTcMwCHoROzHcgO6jQgU0ylWCzK8TsPGkEUxBZx2R/PBLhuRjuXQpyFcs qVXg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AJcUukdKyuJYYGv3zNqfIOUaafNToSNurgEL6T3aLU6jsoK985onEBhu lSVbOAedlZgQf9TKda0BkWiAk8ih2UKsmbViSdW5LH8yocxRuOgCnFspNI47vUHacsb0ybS0L+x Ez0eKioCdQH+ZpL/lr5J6ZGju81jOF1dt72B3LMbU6OxFwkWSnbg5JBUEtIqtWOExRQ== X-Received: by 2002:ac8:28d2:: with SMTP id j18mr22651296qtj.191.1548709766301; Mon, 28 Jan 2019 13:09:26 -0800 (PST) X-Google-Smtp-Source: ALg8bN7hw6AaghWb04vG+5Is07wzo1O5IpE5E7o4DfXVhGqsIk2iqCGsZNCd0QyYFUTdEEZbEF91 X-Received: by 2002:ac8:28d2:: with SMTP id j18mr22651252qtj.191.1548709765577; Mon, 28 Jan 2019 13:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548709765; cv=none; d=google.com; s=arc-20160816; b=BubyR5/c9dr92KjgdSIiuYmX9JplvhSKOO1BopFeouWYkwAPiTa/kdhjgUm/jZJTru yTeshKXiLyJYMc1LFlHUMCMaqfCijf0/gRqbbyOY+x7uNO53TllO0dkhCZc77RJoOdRo 7fI8uXeQkUeDjUYHyc99exSexTGXA8yxjaHn42hsHny0XDvap74b9zXM2KAB/xofx8FP KBno1s3ApOK4xvLoq2LuM7HvmJIFg0BgU/Hgm4hX1gWIwRtciYKlwthwit32x5fEcOB9 MRO7mLj05g54AediB4DoTfBaCrUN6CvX4U5LKKSnr4u0J7/5L4nl1NbrqiLDQykLR1Yo kvYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:organization:autocrypt:openpgp:from :references:cc:to:subject; bh=wNlDRfvp3oVVeOYVKeZHcv5V8UVYVlJHqI7gCedr3kw=; b=IQSECPuqhQ0HojgtRJmn04CokFnY0pHuj1xJRBNiXJBWfQBVU50rtKxhJVBpUgifzl LOY7sXf8SjSh/5vwl/WppUjO8+IEDGdFD/+0kRAMDyTKTU+gE3/ICtZiQu1GnYYvh/DL zXOyUsvOFb3sqJDtovbFLqJaDzglAPRKwMJwRFbD0GctgQM0QS0AH+YBx30kQbW2A9EA G+jRqwE0K+AEAxHF2RdmysfglM6YrBB6vUd5dI+Qt5SF4MJGCP/2YzXi8DkBPDXBSvOa zb7gklzUgj8Kmy1c8VSckBcKw0OGGZxw0s3tEpgJY6zS68u7OC6LFAGfUStBW8iF3+SI Pq9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id y84si2129918qka.39.2019.01.28.13.09.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 13:09:25 -0800 (PST) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 22EC52CD81B; Mon, 28 Jan 2019 21:09:24 +0000 (UTC) Received: from [10.36.116.25] (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F3355C8AB; Mon, 28 Jan 2019 21:09:15 +0000 (UTC) Subject: Re: [PATCH v1] mm: migrate: don't rely on PageMovable() of newpage after unlocking it To: Michal Hocko Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Mel Gorman , "Kirill A. Shutemov" , Naoya Horiguchi , Jan Kara , Andrea Arcangeli , Dominik Brodowski , Matthew Wilcox , Vratislav Bendel , Rafael Aquini , Konstantin Khlebnikov , Minchan Kim , stable@vger.kernel.org References: <20190128160403.16657-1-david@redhat.com> <20190128201902.GW18811@dhcp22.suse.cz> From: David Hildenbrand Openpgp: preference=signencrypt Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz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JaFtxackPszlcpRVkAs6Msn9tu8hlvB517pyUgvuD7ZS9gGOMmYwFQDyytpepo YApVV00P0u3AaE0Cj/o71STqGJKZxcVhPaZ+LR+UCBZOyKfEyq+ZN311VpOJZ1IvTExf+S/5 lqnciDtbO3I4Wq0ArLX1gs1q1XlXLaVaA3yVqeC8E7kOchDNinD3hJS4OX0e1gdsx/e6COvy qNg5aL5n0Kl4fcVqM0LdIhsubVs4eiNCa5XMSYpXmVi3HAuFyg9dN+x8thSwI836FoMASwOl C7tHsTjnSGufB+D7F7ZBT61BffNBBIm1KdMxcxqLUVXpBQHHlGkbwI+3Ye+nE6HmZH7IwLwV W+Ajl7oYF+jeKaH4DZFtgLYGLtZ1LDwKPjX7VAsa4Yx7S5+EBAaZGxK510MjIx6SGrZWBrrV TEvdV00F2MnQoeXKzD7O4WFbL55hhyGgfWTHwZ457iN9SgYi1JLPqWkZB0JRXIEtjd4JEQcx +8Umfre0Xt4713VxMygW0PnQt5aSQdMD58jHFxTk092mU+yIHj5LeYgvwSgZN4airXk5yRXl SE+xAvmumFBY Organization: Red Hat GmbH Message-ID: <725cd2b9-984f-d69b-1967-660d32858ce4@redhat.com> Date: Mon, 28 Jan 2019 22:09:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <20190128201902.GW18811@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 28 Jan 2019 21:09:24 +0000 (UTC) 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 28.01.19 21:19, Michal Hocko wrote: > On Mon 28-01-19 21:02:52, David Hildenbrand wrote: >> On 28.01.19 17:04, David Hildenbrand wrote: >>> While debugging some crashes related to virtio-balloon deflation that >>> happened under the old balloon migration code, I stumbled over a race >>> that still exists today. >>> >>> What we experienced: >>> >>> drivers/virtio/virtio_balloon.c:release_pages_balloon(): >>> - WARNING: CPU: 13 PID: 6586 at lib/list_debug.c:59 __list_del_entry+0xa1/0xd0 >>> - list_del corruption. prev->next should be ffffe253961090a0, but was dead000000000100 >>> >>> Turns out after having added the page to a local list when dequeuing, >>> the page would suddenly be moved to an LRU list before we would free it >>> via the local list, corrupting both lists. So a page we own and that is >>> !LRU was moved to an LRU list. >>> >>> In __unmap_and_move(), we lock the old and newpage and perform the >>> migration. In case of vitio-balloon, the new page will become >>> movable, the old page will no longer be movable. >>> >>> However, after unlocking newpage, there is nothing stopping the newpage >>> from getting dequeued and freed by virtio-balloon. This >>> will result in the newpage >>> 1. No longer having PageMovable() >>> 2. Getting moved to the local list before finally freeing it (using >>> page->lru) >>> >>> Back in the migration thread in __unmap_and_move(), we would after >>> unlocking the newpage suddenly no longer have PageMovable(newpage) and >>> will therefore call putback_lru_page(newpage), modifying page->lru >>> although that list is still in use by virtio-balloon. >>> >>> To summarize, we have a race between migrating the newpage and checking >>> for PageMovable(newpage). Instead of checking PageMovable(newpage), we >>> can simply rely on is_lru of the original page. >>> >>> Looks like this was introduced by d6d86c0a7f8d ("mm/balloon_compaction: >>> redesign ballooned pages management"), which was backported up to 3.12. >>> Old compaction code used PageBalloon() via -_is_movable_balloon_page() >>> instead of PageMovable(), however with the same semantics. >>> >>> Cc: Andrew Morton >>> Cc: Mel Gorman >>> Cc: "Kirill A. Shutemov" >>> Cc: Michal Hocko >>> Cc: Naoya Horiguchi >>> Cc: Jan Kara >>> Cc: Andrea Arcangeli >>> Cc: Dominik Brodowski >>> Cc: Matthew Wilcox >>> Cc: Vratislav Bendel >>> Cc: Rafael Aquini >>> Cc: Konstantin Khlebnikov >>> Cc: Minchan Kim >>> Cc: stable@vger.kernel.org # 3.12+ >>> Fixes: d6d86c0a7f8d ("mm/balloon_compaction: redesign ballooned pages management") >>> Reported-by: Vratislav Bendel >>> Acked-by: Michal Hocko >>> Acked-by: Rafael Aquini >>> Signed-off-by: David Hildenbrand >>> --- >>> mm/migrate.c | 6 ++++-- >>> 1 file changed, 4 insertions(+), 2 deletions(-) >>> >>> diff --git a/mm/migrate.c b/mm/migrate.c >>> index 4512afab46ac..31e002270b05 100644 >>> --- a/mm/migrate.c >>> +++ b/mm/migrate.c >>> @@ -1135,10 +1135,12 @@ static int __unmap_and_move(struct page *page, struct page *newpage, >>> * If migration is successful, decrease refcount of the newpage >>> * which will not free the page because new page owner increased >>> * refcounter. As well, if it is LRU page, add the page to LRU >>> - * list in here. >>> + * list in here. Don't rely on PageMovable(newpage), as that could >>> + * already have changed after unlocking newpage (e.g. >>> + * virtio-balloon deflation). >>> */ >>> if (rc == MIGRATEPAGE_SUCCESS) { >>> - if (unlikely(__PageMovable(newpage))) >>> + if (unlikely(!is_lru)) >>> put_page(newpage); >>> else >>> putback_lru_page(newpage); >>> >> >> Vratislav just pointed out that this issue should not happen on upstream >> as __PageMovable(newpage) will still return true even after >> __ClearPageMovable(newpage). Only PageMovable(newpage) would actually >> return false. >> >> (not sure if I am happy about this, this is horribly confusing and >> complicated) > > It is confusing as hell! __ClearPageMovable is a misnomer and I have to > admit I have misread the implementation to actually ~PAGE_MAPPING_MOVABLE. > >> I am not 100% sure yet, but I guess Vratislav is right. So it was >> effectively fixed by >> >> b1123ea6d3b3 ("mm: balloon: use general non-lru movable page feature"), >> which checks for __PageMovable(newpage) instead of >> __is_movable_balloon_page(newpage). > > So this is not just a clean up. Sigh! > >> Anybody wanting to fix stable kernels either has to backport something >> proposed in this patch or b1123ea6d3b3. > > I think we should go with a simple patch for stable so this patch sounds > like a good thing. *PageMovable thingy needs a much better documentation > and ideally a cleaner implementation as well. The current state is just > incomprehensible. Especially as __ClearPageMovable will not make __PageMovable fail, fun with code :) > > David, could you reformulate the changelog accordingly please? My ack > still holds. You mean reformulating + resending for stable kernels only? b1123ea6d3b3 was merged with v4.8. d6d86c0a7f8d was backported to v3.12+. So v3.12 - v4.7 are affected and will free pages to the LRU list. Without 195a8c43e93d ("virtio-balloon: deflate via a page list") - merged with v4.13 - this BUG is not immediately visible I guess. Pages are still added to the wrong list (LRU although they shouldn't) but the virtio-balloon local list does not exist/corrupt. I assume adding these pages to the LRU list is bad itself, right? If a distro backported 195a8c43e93d without b1123ea6d3b3, the BUG becomes directly visible (this is how we hit it). Thanks! -- Thanks, David / dhildenb