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,URIBL_BLOCKED,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 21EBCC433E6 for ; Wed, 20 Jan 2021 01:43:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC0DE2245C for ; Wed, 20 Jan 2021 01:43:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC0DE2245C 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 B0D1E6B0007; Tue, 19 Jan 2021 20:43:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A93456B0008; Tue, 19 Jan 2021 20:43:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E8606B000A; Tue, 19 Jan 2021 20:43:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 767B36B0007 for ; Tue, 19 Jan 2021 20:43:40 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4718A824999B for ; Wed, 20 Jan 2021 01:43:40 +0000 (UTC) X-FDA: 77724456600.20.clam25_520c29c27556 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 22BAC180C07A3 for ; Wed, 20 Jan 2021 01:43:40 +0000 (UTC) X-HE-Tag: clam25_520c29c27556 X-Filterd-Recvd-Size: 5749 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Wed, 20 Jan 2021 01:43:39 +0000 (UTC) Received: by mail-qk1-f170.google.com with SMTP id d14so23937180qkc.13 for ; Tue, 19 Jan 2021 17:43:39 -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=/BFgBC6QAZDKdqJwclIw/UFhagKoK9nwCvAO/0D2vSo=; b=RmC0xQylQcmkuF5yjIv80DDW0RA/xoOl0q+pK7M85n5LLKQTrhG2INIIJSg26fxSgP 7kOH61xBi+5qAzjc7w69DfA5uqExX8xI5mO+zp2auZUWFUcy2LN1TmOwliOxS8hHzOCC y6VcIC1sn42Eh9UE7GmJw6iFUl65UfIUlQtNh3Um4c8otaClWyHopxsMnOY2uRBqdsGF 04ZY8+ceSUF0OnjnmE4PqYrSRDJKoZ6xTREV9VwJxKSmDIn0dpPcpa8xYyjt8POuA6Ge zhReara3vG9aSRD2JPLwsE4uj6cfzQDdUBmPLTUT810l7zuUU9Z7B8NMaN/vPSBAMZHj yhow== 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=/BFgBC6QAZDKdqJwclIw/UFhagKoK9nwCvAO/0D2vSo=; b=OjOAlLiIwSWz/6yWTXDyzzOA281kpaA1WKzciC/dIvhUzzzhPQThmMOy9MwyJQEb0+ fkMpWD1S60A0cvv+mkQxTTVAzM6PwTfOGY35LnrmvVG49hPI2FptSBdoTNzO4NJqiXiB BhojHeZylyuK1juXKjp2i/Ur1lILALzxBzX7SnHad/gEAI2V2YEsoxpSU70JNvoKRFwb M0guwnx0t6e6DsGEIRLPpjAYBHXuc+HMHZLpjWGZULqOpxijOV+ypra0EkvwYJAFIu6p vhW2+iROwDTw40wyUuPUgdaHBR82BWJ3aHLN9TMluvt11kKrPFEYDsAg9LbaQL4hj+BB yOXA== X-Gm-Message-State: AOAM532tgUUrfP7S8hbseF3f7gZYipYZhoKJZBZ9QAJ/V1A0mV9IO3Vq X9L4bI5XS70/cnax/MCtoLVo9g== X-Google-Smtp-Source: ABdhPJxqofjLc4ID+cJVT/cdrSIm0/gIX8GFxlbTBTnAtlB3KLAOZgKlTtLQIirWWKLqvIHpshfe2w== X-Received: by 2002:a37:9c4a:: with SMTP id f71mr7624514qke.495.1611107019093; Tue, 19 Jan 2021 17:43:39 -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 a9sm391871qkk.39.2021.01.19.17.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 17:43:38 -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 v6 02/14] mm/gup: check every subpage of a compound page during isolation Date: Tue, 19 Jan 2021 20:43:21 -0500 Message-Id: <20210120014333.222547-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210120014333.222547-1-pasha.tatashin@soleen.com> References: <20210120014333.222547-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 Reviewed-by: Jason Gunthorpe --- 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