Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp686169imm; Fri, 31 Aug 2018 10:26:39 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYBsROeLVKgdwhzNKZNeK54UK85cAZut0JMGdr1tM0iSLNZaZ68hF+hgpX2fmuG3No+YwAG X-Received: by 2002:a17:902:5381:: with SMTP id c1-v6mr16284153pli.328.1535736399605; Fri, 31 Aug 2018 10:26:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535736399; cv=none; d=google.com; s=arc-20160816; b=C/4sE7ko2KaojcTcpB7oosxYxXSyxZX7m+oO7FT+Ws+NpM67bpRgWMmHnEk5LUuJ9r m5whKr4y+91VuHKp8nbt2Gz4mJj6sGrYHs3gdwuxR7OtkUm5CYV9y48gPrApv8x4pxVq SMCfqC0TL8CZJoxzT1i8CcFt1gutO0zdvhllK94GTx05G6Wr8+MoR6ytITPgP15LRUqP cX1GaLWbCVJlxmTuKv9hX66nwUiZf2A7jEwTVbMpOZ9U7BWYOsMXwI7N4wjNnoww6kGL 4ADxtkw/S+45BCmB6r3bXQ9NY8Cdaddw+jMrnmNJpH4Saf4y85Q1qmC2o61fc93jZbO7 Ppxw== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=jApFaNrbzox1VYDVZnygnIoodfOIXcyp6aIaOSGr6EI=; b=RKIKz5KZ1ZoNJWWlPVlOegXEafqlrxuSHwNe4f9jmJfeBp8BPGVAeHj2Vwr3YfXReA QYtP4Xb67UNOW92WU8VFJs0NPKjFAU7d7i+gMANlX/J+JYqquwDp6Ot0kaEU+s26qjmh N9LbhanuZQRkIDxNYytrTuQywqwdMJoGbJ0eodJutkTDN05NVKyKDVns1N/XsyuUapC3 pySef2UO4iQaW93nbeuofDde3NfR9yqP/QPlewGoLRrKRBfwazaHgS+FpEUW1wzP/0yp 2vvnSGFrBznxVWVFnVDzYn0yOzclD9+8bVqZ+Jya10j+qEDGgaIEgylum5VFSoK++wlz kqOA== 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 x24-v6si10256884pgh.295.2018.08.31.10.26.23; Fri, 31 Aug 2018 10:26:39 -0700 (PDT) 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 S1729307AbeHaU1w (ORCPT + 99 others); Fri, 31 Aug 2018 16:27:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57180 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727268AbeHaU1w (ORCPT ); Fri, 31 Aug 2018 16:27:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0D9626362; Fri, 31 Aug 2018 16:19:37 +0000 (UTC) Received: from redhat.com (ovpn-123-69.rdu2.redhat.com [10.10.123.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38FF32166B41; Fri, 31 Aug 2018 16:19:37 +0000 (UTC) Date: Fri, 31 Aug 2018 12:19:35 -0400 From: Jerome Glisse To: Balbir Singh Cc: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org, Ralph Campbell , "Kirill A . Shutemov" , stable@vger.kernel.org Subject: Re: [PATCH 3/7] mm/rmap: map_pte() was not handling private ZONE_DEVICE page properly v2 Message-ID: <20180831161935.GB4111@redhat.com> References: <20180824192549.30844-3-jglisse@redhat.com> <20180830144156.7226-1-jglisse@redhat.com> <20180831092724.GD28695@350D> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180831092724.GD28695@350D> User-Agent: Mutt/1.10.0 (2018-05-17) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 31 Aug 2018 16:19:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 31 Aug 2018 16:19:37 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jglisse@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 31, 2018 at 07:27:24PM +1000, Balbir Singh wrote: > On Thu, Aug 30, 2018 at 10:41:56AM -0400, jglisse@redhat.com wrote: > > From: Ralph Campbell > > > > Private ZONE_DEVICE pages use a special pte entry and thus are not > > present. Properly handle this case in map_pte(), it is already handled > > in check_pte(), the map_pte() part was lost in some rebase most probably. > > > > Without this patch the slow migration path can not migrate back private > > ZONE_DEVICE memory to regular memory. This was found after stress > > testing migration back to system memory. This ultimatly can lead the > > CPU to an infinite page fault loop on the special swap entry. > > > > Changes since v1: > > - properly lock pte directory in map_pte() > > > > Signed-off-by: Ralph Campbell > > Signed-off-by: J?r?me Glisse > > Cc: Andrew Morton > > Cc: Kirill A. Shutemov > > Cc: Balbir Singh > > Cc: stable@vger.kernel.org > > --- > > mm/page_vma_mapped.c | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c > > index ae3c2a35d61b..bd67e23dce33 100644 > > --- a/mm/page_vma_mapped.c > > +++ b/mm/page_vma_mapped.c > > @@ -21,7 +21,14 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw) > > if (!is_swap_pte(*pvmw->pte)) > > return false; > > } else { > > - if (!pte_present(*pvmw->pte)) > > + if (is_swap_pte(*pvmw->pte)) { > > + swp_entry_t entry; > > + > > + /* Handle un-addressable ZONE_DEVICE memory */ > > + entry = pte_to_swp_entry(*pvmw->pte); > > + if (!is_device_private_entry(entry)) > > + return false; > > OK, so we skip this pte from unmap since it's already unmapped? This prevents > try_to_unmap from unmapping it and it gets restored with MIGRATE_PFN_MIGRATE > flag cleared? > > Sounds like the right thing, if I understand it correctly Well not exactly we do not skip it, we replace it with a migration pte see try_to_unmap_one() which get call with TTU_MIGRATION flag set (which do not translate in PVMW_MIGRATION being set on contrary). From migration point of view even if this is a swap pte, it is still a valid mapping of the page and is counted as such for all intent and purposes. The only thing we don't need is flushing CPU tlb or cache. So this all happens when we are migrating something back to regular memory either because of CPU fault or because the device driver want to make room in its memory and decided to evict that page back to regular memory. Cheers, J?r?me