From patchwork Thu Feb 11 16:24:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12083657 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.5 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 1DF29C433E0 for ; Thu, 11 Feb 2021 16:24:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A0CB164E95 for ; Thu, 11 Feb 2021 16:24:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A0CB164E95 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 579256B010B; Thu, 11 Feb 2021 11:24:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 417926B010C; Thu, 11 Feb 2021 11:24:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 157EE6B010D; Thu, 11 Feb 2021 11:24:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id F1C046B010B for ; Thu, 11 Feb 2021 11:24:33 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B78F6181AEF1E for ; Thu, 11 Feb 2021 16:24:33 +0000 (UTC) X-FDA: 77806510026.04.B9E7F9A Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by imf21.hostedemail.com (Postfix) with ESMTP id 9F47DE0011CE for ; Thu, 11 Feb 2021 16:24:32 +0000 (UTC) Received: by mail-qk1-f174.google.com with SMTP id l27so5687014qki.9 for ; Thu, 11 Feb 2021 08:24:33 -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=LL91sOR6eNdLBKKX+cwP2EUL4T0OiDJ4l8AEtucy7F0=; b=Cu6OHd4IUjAcSplCwvpYfXX30K5w7v6nYpY1ArywdPsTP+EXS6Oaiocsonki3raoXR SLxlbJk5ql00SZPeoI3Tl2LzMaXU1I5Cquh/q5MCHSMzr8UDfoCLn0igPWuGMbHc6ckR /GXj7V2jbEsnNl8OtcHyY80k3q6kHFSgEpAWWE3hnTxUPdV7hKwxqU0vPufG77ip5IeD 1nvTBp2ZkabycEZ954AkMsimOJGZPux+lDVJKPXX9/1i6MxZrhfky6eJVJZiVQ2kb1qN u7xl4XzcGzgfKDZdwz6mF1NZca6lQca5gq1Kcfnh16KgeVBRwLxlSWbyGeLTQgvMjshv 5t0Q== 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=LL91sOR6eNdLBKKX+cwP2EUL4T0OiDJ4l8AEtucy7F0=; b=I2sCPNSzv7IdwcEuMQNCgrYGPJTErRbvhs36+DBPXIqi1DxhbvwX8ye2AIzRAbuYvY uIsv+3p/lpmJOgjsKdNmnynrJWjDU5gSJS2UiM3jgiO0PwX8fezVaDRuV4zy0+cVfD7P rifZX64S8pnLqlqiZRzqpFbcgJO8pRVNVzqqyAavRCGLRYy953Q8fz5WCouznSRK8Ry1 dWji0hF1wSfsdKELCPXjWsQsMSThB1Ij7hSQ1/gIxR9Q/sjHwyiy6FiUy3IzOn/flAZz Y85kJkPX26PfsT4RBru8Yg1IXSAlQ7HUk8oxcRU4ljIGTytqr//o9qUhWUDq8BMM+oND TRag== X-Gm-Message-State: AOAM533yEBy5CuYNngtUSt1akg/rinRIaNUU1DKGsfxrINfECCbF28Yc cBwfDbw+3Ju3rqnqqdhsUjuG7g== X-Google-Smtp-Source: ABdhPJwOvjkc4WjRekXFLBt/hqaYUExG2N08qrgzJfAlZ/EDH7efpQkM+/m48smbKkvu5kmAAyDM8A== X-Received: by 2002:a05:620a:166a:: with SMTP id d10mr8596059qko.213.1613060672602; Thu, 11 Feb 2021 08:24:32 -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 i23sm3831778qtq.42.2021.02.11.08.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 08:24:32 -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, jmorris@namei.org Subject: [PATCH v10 02/14] mm/gup: check every subpage of a compound page during isolation Date: Thu, 11 Feb 2021 11:24:15 -0500 Message-Id: <20210211162427.618913-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210211162427.618913-1-pasha.tatashin@soleen.com> References: <20210211162427.618913-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Stat-Signature: wt8ow619sc149a5uaxy8s1ahxg56axtk X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9F47DE0011CE Received-SPF: none (soleen.com>: No applicable sender policy available) receiver=imf21; identity=mailfrom; envelope-from=""; helo=mail-qk1-f174.google.com; client-ip=209.85.222.174 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613060672-665697 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 huge 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 88441de65e34..1f73cbf7fb37 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1548,26 +1548,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_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 @@ -1591,8 +1588,6 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, } } } - - i += step; } if (!list_empty(&cma_page_list)) {