Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp378794pxj; Tue, 18 May 2021 05:35:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+R3sA0WE3Wf3j/jLunmyFOXNxrSJgoWL/O4XgrO8uTY5XzX+jPFTvyacYLE76LlmV0dgp X-Received: by 2002:aa7:cb0a:: with SMTP id s10mr6712543edt.36.1621341313465; Tue, 18 May 2021 05:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621341313; cv=none; d=google.com; s=arc-20160816; b=LgSX7a0zwhaspK3TH4PqZC2oQmmgs3aMPvEiho+Q0sQhux9JTQhvUj37V2xv7RErjw XzSV1zESQHhoOuSBigmbZEO8NXMbMzFE/A990VaT8sEaaR8ZZsr+vYLch65fKNd78RxO YiD73+MuOlRafIDCutSggMw42eQIlZcri+QU0dgRmrDZHqsSW+CE2OIJXQ1S5rIrFuLk CCnL9qxLJe7R2OvqmVbZAnS1vHqdTJfJo/xog2s1fxhuFLxQW6LEw76NmfyWshZQfupn Ptm7Q0/2O3sL1HQ3YJUjB07Shq4tAdFHtqVJ5U9j9fnqsULmaYffTBM0WVCFXj4vvgzt fvhg== 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=XnTu0/aMJAA1y6U+QFcQw+Q86YeBkZ8XY4iKLZ1aiRw=; b=GE55ham/6uIQ3baM9NKoB512T6SfehcR276PznSpKhtUd4igd/5/PrMXasvMx7sWo/ 5Zzor9PNpU8usZ27LrHjGscS2yH/KE8hg/j0gx6knkN9MfyixaDqZ48vlqIXY8OFcxiq le7zqlRiCjRIOSOXgbcslOR5E1I0mAkwKcILCzq6Q759Hd1wLUCxFcoXg4jyRkBcnCfI xeG0U+l5ZPEIPp353iV6BDep8NaDDUBPquFg7lGAL8Vq2zo+no2HIGUX7y5U2Xq82QIT V36vYBs4JTlobCj+AOo05B1GmPsUHzmDZGPKkN8DNfiZHnfaxs2i2wiNri6BG4zvsnAY lh1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0OaUnyxS; 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 n18si11243118eju.239.2021.05.18.05.34.50; Tue, 18 May 2021 05:35:13 -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=0OaUnyxS; 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 S241261AbhEQPdY (ORCPT + 99 others); Mon, 17 May 2021 11:33:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:56098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243975AbhEQPSl (ORCPT ); Mon, 17 May 2021 11:18:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F042561C75; Mon, 17 May 2021 14:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262024; bh=QpapYVIA1Q0/mraNDCl2nt4lswKCm+T9mTRZIK/Xw6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0OaUnyxS31CCK5mW8dxnNCA0tQqhSv1/cgImIe3XhOBQuBofNXRaojpJklau6wBdu R0tXY4lRu7ab4Dd++FQiJhGkVW/TiiJHRuVblW7JNilrpq0j/6rDHr/qbt4p2JBzK+ 8u+7NjEbr5KKywY0ffxzA27WYhCkbL7nUH5D5umI= 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.11 205/329] mm/gup: check every subpage of a compound page during isolation Date: Mon, 17 May 2021 16:01:56 +0200 Message-Id: <20210517140309.050345724@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@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 e4c224cd9661..84d392886d85 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1549,26 +1549,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 @@ -1592,8 +1589,6 @@ check_again: } } } - - i += step; } if (!list_empty(&cma_page_list)) { -- 2.30.2