Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3115769pxj; Mon, 17 May 2021 18:10:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8tMhdzHVKg57MyxCzKW+p+HH4JaemOTHt4UEqVldugMAAm/PK0fBybSa5mT0hj+NMpFrp X-Received: by 2002:a05:6402:40c:: with SMTP id q12mr3669962edv.0.1621300234471; Mon, 17 May 2021 18:10:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621300234; cv=none; d=google.com; s=arc-20160816; b=ieGUnU7yBUkpKVgN1HgmaexGfno433mqzOx5hw6nxpxOugTeeHT7+pCQItSIqBqRCj iA56OzyvBa9BVU6GxF3DT90+gxARQVHuYXDDu0Q4KgaXXotifyKQmfhOLUCkZ2HhtHNZ T5Owj+efgFNqtJcHl7Z66pCrzo8Kfy8zslZoNsgTMFfKHWA2+iURLkxBRWjk4ELBNHoz Lw/YAOCARlFf1fKPiTKtoWM6Q+zfyJdISrEAHNbPVGENoZ8Xy80fZ091c7PNxC6/124M 0wPaKUhXCBfwmGDx6cNwP/MQAGa/i+5KZGDhFqK5F1AlF1j0yh0YAxEoEYSQLXtlVEtY 48tQ== 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=W0hw7LlGL0wjrJRUodfemgRw704bIHJeB4ouLKybDlE=; b=V/qZITFVQAZkmWeAEmVahi+Ek3Akr4AwtAPHPv/UIABhUrnLrXpVdV12amMZ05/NQ+ 3774YB8qo0EL3zMKKGAlHsy2DxIw5BOjOktG8KvDJZ/FLQiaRHt6DcIKHsjWez0c9zmL Ie+MnRzwmQcBDC7E4RwjWHMoeIZrsY9cCjMc9jGeTwHwQiIquR9EDKXs0FJepgPx7300 +FUwh0Uhwu31PYmUfPLbHX9TY+6oziK5Ijn1h8YmAUQFJxYUAga0N4h15gXaqHSaaRd+ 25EY+aLy80ujWNUMEwS9LnzDfz8BeNC0VhaKpqZ5UlhyNEffRMtFNBHQaakzP1+SKRGP QycA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s1fNgHsc; 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 bh4si8334254ejb.680.2021.05.17.18.10.11; Mon, 17 May 2021 18:10:34 -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=s1fNgHsc; 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 S239972AbhEQOdV (ORCPT + 99 others); Mon, 17 May 2021 10:33:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:53274 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233019AbhEQO2L (ORCPT ); Mon, 17 May 2021 10:28:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 880186161C; Mon, 17 May 2021 14:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260848; bh=qVbtQ5vtqOA+Gk6dRVbQSw3FDlRRIO/UKCWvrZD4KUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s1fNgHscW2BxJljel47c1bDlBh6rickHA87ykGKFjJzoiUoqXNgKOz264Mo+TNXAQ nw3eQNwN5sGIshdKU48ydlQlwlmfGjzG1orWXeUaqr3WRpCHSiGHYjcucMXSGJD1CO IUSboxg2h4Ya708AqJUXYkkjMqmjKj7yBoeZdjqo= 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.12 221/363] mm/gup: check every subpage of a compound page during isolation Date: Mon, 17 May 2021 16:01:27 +0200 Message-Id: <20210517140310.068783947@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 ef7d2da9f03f..6530672131db 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1552,26 +1552,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 @@ -1595,8 +1592,6 @@ check_again: } } } - - i += step; } if (!list_empty(&cma_page_list)) { -- 2.30.2