Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp535443pxj; Tue, 18 May 2021 08:46:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlqMYfOEv0szUV5BCSE0vDTe2XiyFa91KNAnUT1b/B6RMakH8oqM5BP8OK60cAh4Pyq7EZ X-Received: by 2002:aa7:d50e:: with SMTP id y14mr7860678edq.346.1621352799432; Tue, 18 May 2021 08:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621352799; cv=none; d=google.com; s=arc-20160816; b=St3fqk1S1JKSV0wd7bNDX9AWy3LfF+AI0sFCjv5d6oaPl8Ayw8jXsGsJ2SqfNtOTM+ 4Hrk9gUc/zJcjW+/OAku3VMXlFWIfmXIL2Hq7QPPq1Rl7fPxUHdLURh0rDOlA3BkdJzl iArBiTlH0nPChPEdXzc6I5XHDznSMHfO4vRNauK06iUAbLoSxk5igy3cXxwU6vmoz3iQ 39nj19EbqjZUkiQn+HZTQZVczjGVNdjfZwUHJWcVNk9AoaFTlE0wR/ljo8DRQCTLBLsV m9lvduhtpympYmJHJknfOVZxdxx+4De2/cBxWOvhaGFlWR5RvQBMHEewQJPBYZzbPsmC j7zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gOPxgk5IpXjdCdIuJZsqEZP8kZD7j+wrUw329qjzXN8=; b=EHigRfJXDG0HwCAfW7RnR539UGR0ii/02EFdAbH23XiASPKR5sSMP49BgZdPnhLKmP GlBkx59QBNjy5I0GPhS0zQVFrcle1TvAKQiSoH5Pk6dPZqGrPTQXUVS4dGrkyZCu+sjV 41ljfvPjmBKMpZnZZgp8IXuBSqWc1ufHhqsSrDaTTiEgXzj1gsObgq9v5mmMMDZ431k2 qezSs1gWhkewMiVk/gKuU155kp5tgLE/QoJ6yIoVzNrrqirxYe/pERY+DByhnQ37Gbj2 5bVByIDFI2FiaAz+xtAMAC+MacS453mBWsrfs0qBrCgfs2grzOkWwLuOVhxdmTR6ULxf 6cWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ncfJBBtX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq20si1660169ejc.236.2021.05.18.08.46.09; Tue, 18 May 2021 08:46:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ncfJBBtX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345717AbhEQP5O (ORCPT + 99 others); Mon, 17 May 2021 11:57:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:39260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245207AbhEQPiF (ORCPT ); Mon, 17 May 2021 11:38:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8445061CF5; Mon, 17 May 2021 14:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262440; bh=HLJ3NJIpRqpABOIEjYfYS5Rt/D0McBXE7qoiT+4RsXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ncfJBBtXr24SXVoLfW1xdjbgXTKBeCXnidGhstWFsDtgxAXBfePymmrjww56qFstr APmZXAx1UjK7ubPqguCZvlcE0fLPrarltsz6BUkR6F3RYTc4AOXtuKZkzrRs5z9Ov+ 2G61I8hsjdz4lNGwGjPCv9adkd0WIrg07qugdjr4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Tatashin , Jason Gunthorpe , Dan Williams , David Hildenbrand , David Rientjes , Ingo Molnar , Ira Weiny , James Morris , Jason Gunthorpe , John Hubbard , Joonsoo Kim , Matthew Wilcox , Mel Gorman , Michal Hocko , Michal Hocko , Mike Kravetz , Oscar Salvador , Peter Zijlstra , Sasha Levin , "Steven Rostedt (VMware)" , Tyler Hicks , Vlastimil Babka , Andrew Morton , Linus Torvalds Subject: [PATCH 5.10 170/289] mm/gup: check every subpage of a compound page during isolation Date: Mon, 17 May 2021 16:01:35 +0200 Message-Id: <20210517140310.840986381@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Tatashin [ Upstream commit 83c02c23d0747a7bdcd71f99a538aacec94b146c ] When pages are isolated in check_and_migrate_movable_pages() we skip compound number of pages at a time. However, as Jason noted, it is not necessary correct that pages[i] corresponds to the pages that we skipped. This is because it is possible that the addresses in this range had split_huge_pmd()/split_huge_pud(), and these functions do not update the compound page metadata. The problem can be reproduced if something like this occurs: 1. User faulted huge pages. 2. split_huge_pmd() was called for some reason 3. User has unmapped some sub-pages in the range 4. User tries to longterm pin the addresses. The resulting pages[i] might end-up having pages which are not compound size page aligned. Link: https://lkml.kernel.org/r/20210215161349.246722-3-pasha.tatashin@soleen.com Fixes: aa712399c1e8 ("mm/gup: speed up check_and_migrate_cma_pages() on huge page") Signed-off-by: Pavel Tatashin Reported-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Cc: Dan Williams Cc: David Hildenbrand Cc: David Rientjes Cc: Ingo Molnar Cc: Ira Weiny Cc: James Morris Cc: Jason Gunthorpe Cc: John Hubbard Cc: Joonsoo Kim Cc: Matthew Wilcox Cc: Mel Gorman Cc: Michal Hocko Cc: Michal Hocko Cc: Mike Kravetz Cc: Oscar Salvador Cc: Peter Zijlstra Cc: Sasha Levin Cc: Steven Rostedt (VMware) Cc: Tyler Hicks Cc: Vlastimil Babka Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/gup.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 054ff923d3d9..e10807c4c46b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1562,26 +1562,23 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, unsigned int gup_flags) { unsigned long i; - unsigned long step; bool drain_allow = true; bool migrate_allow = true; LIST_HEAD(cma_page_list); long ret = nr_pages; + struct page *prev_head, *head; struct migration_target_control mtc = { .nid = NUMA_NO_NODE, .gfp_mask = GFP_USER | __GFP_MOVABLE | __GFP_NOWARN, }; check_again: - for (i = 0; i < nr_pages;) { - - struct page *head = compound_head(pages[i]); - - /* - * gup may start from a tail page. Advance step by the left - * part. - */ - step = compound_nr(head) - (pages[i] - head); + prev_head = NULL; + for (i = 0; i < nr_pages; i++) { + head = compound_head(pages[i]); + if (head == prev_head) + continue; + prev_head = head; /* * If we get a page from the CMA zone, since we are going to * be pinning these entries, we might as well move them out @@ -1605,8 +1602,6 @@ check_again: } } } - - i += step; } if (!list_empty(&cma_page_list)) { -- 2.30.2