From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAEBDC433E0 for ; Tue, 19 Jan 2021 04:39:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 417DF20848 for ; Tue, 19 Jan 2021 04:39:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 417DF20848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 860686B0071; Mon, 18 Jan 2021 23:39:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 83A6F8D002E; Mon, 18 Jan 2021 23:39:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D8E78D002D; Mon, 18 Jan 2021 23:39:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id 564FF6B0071 for ; Mon, 18 Jan 2021 23:39:27 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 148E9181AF5CA for ; Tue, 19 Jan 2021 04:39:27 +0000 (UTC) X-FDA: 77721270774.09.tramp45_621840e2754f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id ED3BD180AD830 for ; Tue, 19 Jan 2021 04:39:26 +0000 (UTC) X-HE-Tag: tramp45_621840e2754f X-Filterd-Recvd-Size: 5706 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 Jan 2021 04:39:26 +0000 (UTC) Received: by mail-qk1-f170.google.com with SMTP id w79so20775535qkb.5 for ; Mon, 18 Jan 2021 20:39:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7Zip2QrmKQ/Mplic3YGjgwGPQdefB544/adjAiin1/E=; b=FJM8VIvv0OUU4yIdZkGWfg8bo1z91Vm4wnb+rF+Aqdi7m++B0uERD6Ylx03QPvZUpi RLGNPtXoanfpidtqZpgsFnG4tDyY1VW2sTt0uibOXptbLmCJsuoYFzKC7Qj2PmDRiGU2 gto4YFvVExedtPn86aLUavKI2J9x6LUPZioSgzAEb1L4rJiSPJNiPJm3czeTh51s9l/a kk45Lxxa0ZnSIEYx3bUY4BtCzLBp9m4L5r0bE2mcJxmriQOsZpDjKzbwqhg8n41R833x jSro0CWsMJWTkIvEG4XIEbatykdhcM53L4q6J1sYnalXE/rzb+FMO7QeZBjpVvwbySGJ 4RGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Zip2QrmKQ/Mplic3YGjgwGPQdefB544/adjAiin1/E=; b=amwIxBhbtyU1qHoKwaz/T1KkO7ioZ3eRLSkn3ZFmW5YvIEOTwEuWBRDr+WZQ2U1rW7 bpGquky51BUItIUV8LXA42+FNoY1215dB+84Rr15mqlCDT2N/8qWGx0WcISdYA9+jnA4 occVeWCRV77UujtKNev9hzG8+fBmnNcgIZA46Wy/SFpx3FO9Ks71o5YwIigcvPWUEBDj SxGCcrDZDNXImYtwhNiQ00DogF0J4D/cwh1JY59KrAHCPoCxV5YzNkjMF+od4xnu4yr0 emGUBzrtPsm5qNoQjn3UHzwCZYmS8xNUqidRbKzOcpLFf2WWYrgCFWPjpSZV8viaHzVy 3bkQ== X-Gm-Message-State: AOAM530SkNN1Is2i3t9lojNzemXDGOHoIVA83FTufJGck4TbvUDJ5Ubx vKFQLxbfpw2GMSseV/EfAGZxag== X-Google-Smtp-Source: ABdhPJx0jhW1FsaaMPRajeI4eKkMnvtdY6UgwPpqZSl8lUTzedh5iHTxAoJBWP1QS03gqLKsrFWgqg== X-Received: by 2002:ae9:ef12:: with SMTP id d18mr2753571qkg.473.1611031165857; Mon, 18 Jan 2021 20:39:25 -0800 (PST) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id z20sm11934536qkz.37.2021.01.18.20.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 20:39:25 -0800 (PST) From: Pavel Tatashin To: pasha.tatashin@soleen.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, vbabka@suse.cz, mhocko@suse.com, david@redhat.com, osalvador@suse.de, dan.j.williams@intel.com, sashal@kernel.org, tyhicks@linux.microsoft.com, iamjoonsoo.kim@lge.com, mike.kravetz@oracle.com, rostedt@goodmis.org, mingo@redhat.com, jgg@ziepe.ca, peterz@infradead.org, mgorman@suse.de, willy@infradead.org, rientjes@google.com, jhubbard@nvidia.com, linux-doc@vger.kernel.org, ira.weiny@intel.com, linux-kselftest@vger.kernel.org Subject: [PATCH v5 02/14] mm/gup: check every subpage of a compound page during isolation Date: Mon, 18 Jan 2021 23:39:08 -0500 Message-Id: <20210119043920.155044-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210119043920.155044-1-pasha.tatashin@soleen.com> References: <20210119043920.155044-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Fixes: aa712399c1e8 ("mm/gup: speed up check_and_migrate_cma_pages() on h= uge page") Reported-by: Jason Gunthorpe Signed-off-by: Pavel Tatashin --- mm/gup.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 24f25b1e9103..16f10d5a9eb6 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1556,26 +1556,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 =3D true; bool migrate_allow =3D true; LIST_HEAD(cma_page_list); long ret =3D nr_pages; + struct page *prev_head, *head; struct migration_target_control mtc =3D { .nid =3D NUMA_NO_NODE, .gfp_mask =3D GFP_USER | __GFP_NOWARN, }; =20 check_again: - for (i =3D 0; i < nr_pages;) { - - struct page *head =3D compound_head(pages[i]); - - /* - * gup may start from a tail page. Advance step by the left - * part. - */ - step =3D compound_nr(head) - (pages[i] - head); + prev_head =3D NULL; + for (i =3D 0; i < nr_pages; i++) { + head =3D compound_head(pages[i]); + if (head =3D=3D prev_head) + continue; + prev_head =3D 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 @@ -1599,8 +1596,6 @@ static long check_and_migrate_cma_pages(struct mm_s= truct *mm, } } } - - i +=3D step; } =20 if (!list_empty(&cma_page_list)) { --=20 2.25.1