Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3561260imu; Mon, 28 Jan 2019 07:02:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN4IkcxSa7+g2aZylPa2HYcRCDQMILtQ04X3ngLyQ+A+twqcnD+J0dIuL/8AYYspw11Zb50G X-Received: by 2002:a17:902:8687:: with SMTP id g7mr21901862plo.96.1548687760545; Mon, 28 Jan 2019 07:02:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548687760; cv=none; d=google.com; s=arc-20160816; b=zT0WPWroIcPIHO+5pFszNQuJa6usW/6+OMugsJRmltQ0OPFpApLptR12LSezK1CzHH 9q3sAvyU3H8uSFixgXpjhPuiylGfNELz2Jd5LR1rqN1u++Dq75KUlv+wAze/kMNKJOxJ NkYV/hjnr20IRaXowFZMu8WNVPIkP0fmAzfQNaqQS9twCtrxGD8WujUL+pEdHsFureVr 9c8eQhA7qIZ3qCFi1tFonAztr+2KEKuPY4lOryr/6q8KntqZ9DGgenk6epoi6MuvztaG LXo3S4TNvSr32yQaTBBrCR7fB59J9a0tggSxXTNDAPmj5dzIxYb8b0urKp1FB+aASrp+ yNNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=a0vmQ8T7EOtY9bSJUscSTgf6LLCtJg/5M1Y5mT6YQAs=; b=WcFFm+VCRi/pyn3tYgb63x3DG/jH1NJxlnJRM6uZ3DtAbUQ5qg/nRtL+5l8on/21WF EEqsTYPJeltjIqAk6eoqoWjqMF1Ewj4Dy4s04OkM5dZ+L4PZNkW1jI54vsDKt4vDGG+X tvrycWVdzYX0hGh9ZoaZrFAc8br13u4YRwPS1FHi1n3jT3TM3nbVHcslS7QiaPKI3Zd5 6vdoq97f9boZ8eH5sUbmL7Onr6ZJWUuEaOY+0hkNJjwL/W8T7lTf0lvyI86hsC2t1OZl DRpTdJgIW8qOkmuaTFIO4iKFSpPm5JTwAcxH3tE4v3UHale0/5XbjQSWqCylUX/AA2P6 5OUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si27617158pgi.263.2019.01.28.07.02.21; Mon, 28 Jan 2019 07:02:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726820AbfA1PCE (ORCPT + 99 others); Mon, 28 Jan 2019 10:02:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60810 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726661AbfA1PCE (ORCPT ); Mon, 28 Jan 2019 10:02:04 -0500 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 17DD29FDFC; Mon, 28 Jan 2019 15:02:03 +0000 (UTC) Received: from xps (ovpn-116-106.phx2.redhat.com [10.3.116.106]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3F8C58826; Mon, 28 Jan 2019 15:01:59 +0000 (UTC) Date: Mon, 28 Jan 2019 10:01:56 -0500 From: Rafael Aquini To: David Hildenbrand Cc: Michal Hocko , 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 Subject: Re: [PATCH RFC] mm: migrate: don't rely on PageMovable() of newpage after unlocking it Message-ID: <20190128150156.GA10872@xps> References: <20190128121609.9528-1-david@redhat.com> <20190128130709.GJ18811@dhcp22.suse.cz> <20190128132146.GK18811@dhcp22.suse.cz> <17e7d7e4-f4ca-a681-93e5-92a0c285be14@redhat.com> <20190128133514.GL18811@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) 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.39]); Mon, 28 Jan 2019 15:02:03 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 28, 2019 at 03:38:38PM +0100, David Hildenbrand wrote: > On 28.01.19 14:35, Michal Hocko wrote: > > On Mon 28-01-19 14:22:52, David Hildenbrand wrote: > >> On 28.01.19 14:21, Michal Hocko wrote: > >>> On Mon 28-01-19 14:14:28, David Hildenbrand wrote: > >>>> On 28.01.19 14:07, Michal Hocko wrote: > >>>>> On Mon 28-01-19 13:16:09, David Hildenbrand wrote: > >>>>> [...] > >>>>>> My theory: > >>>>>> > >>>>>> 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, I think 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) > >>>>> > >>>>> Does that mean that the virtio-balloon can change the Movable state > >>>>> while there are other users of the page? Can you point to the code that > >>>>> does it? How come this can be safe at all? Or is the PageMovable stable > >>>>> only under the page lock? > >>>>> > >>>> > >>>> PageMovable is stable under the lock. The relevant instructions are in > >>>> > >>>> mm/balloon_compaction.c and include/linux/balloon_compaction.h > >>> > >>> OK, I have just checked __ClearPageMovable and it indeed requires > >>> PageLock. Then we also have to move is_lru = __PageMovable(page) after > >>> the page lock. > >>> > >> > >> I assume that is fine as is as the page is isolated? (yes, it will be > >> modified later when moving but we are interested in the original state) > > > > OK, I've missed that the page is indeed isolated. Then the patch makes > > sense to me. > > > > Thanks Michal. I assume this has broken ever since balloon compaction > was introduced. I'll wait a little more and then resend as !RFC with a > cc-stable tag. > Yes, balloon deflation could always race against migration This race was a problem, initially, and was dealt with, via: commit 117aad1e9e4d97448d1df3f84b08bd65811e6d6a Author: Rafael Aquini Date: Mon Sep 30 13:45:16 2013 -0700 mm: avoid reinserting isolated balloon pages into LRU lists I think this upstream patch has re-introduced it, in a more subtle way, as we're stumbling on it now, again: commit d6d86c0a7f8ddc5b38cf089222cb1d9540762dc2 Author: Konstantin Khlebnikov Date: Thu Oct 9 15:29:27 2014 -0700 mm/balloon_compaction: redesign ballooned pages management On this particular race against migration case, virtio ballon deflation would not see it before commit b1123ea6d3b3da25af5c8a9d843bd07ab63213f4 Author: Minchan Kim Date: Tue Jul 26 15:23:09 2016 -0700 mm: balloon: use general non-lru movable page feature as the recently released balloon page would be post-processed without the page->lru list handling, which for migration stability purposes must be done under the protection of page_lock. get rid of balloon reference count. -- Rafael