From patchwork Mon Jan 10 04:23:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12708185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF9A3C433F5 for ; Mon, 10 Jan 2022 04:24:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 128EF6B00A7; Sun, 9 Jan 2022 23:24:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B4396B00A8; Sun, 9 Jan 2022 23:24:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4C2C6B00A9; Sun, 9 Jan 2022 23:24:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0243.hostedemail.com [216.40.44.243]) by kanga.kvack.org (Postfix) with ESMTP id A696C6B00A7 for ; Sun, 9 Jan 2022 23:24:38 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 67A6D96F0F for ; Mon, 10 Jan 2022 04:24:38 +0000 (UTC) X-FDA: 79013086236.01.8615C2F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf31.hostedemail.com (Postfix) with ESMTP id 1010420002 for ; Mon, 10 Jan 2022 04:24:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=/DPJvh8nZY8O3CzKnWIX/byaa2jenc4w/Fleth+y20E=; b=gHzU4niHDL73CDvZ4y9ZrGch48 bMd5a3+9Z3TkUFgqpFk1IFK3Yu6nb+K2xMlltYCDn/3nNwCt58gKoG/cLHjhUoUH0s6MH/PH5GsOt 8xM+W9e6+2bFcXR9YEJMzKaqI5d6E2wpTwXYlSlGgf/PYNXXGRUYIxs9iLRgwoR3Jd5QhKxrkvT4B n7YcK3RyLBwZNGitu7ZYNkzKAeCx6UNIvZ5FikJ+1t9s6FxkfNsmyD6tV2wkKOyW7UaFwyLWhDK3V KyVFyPhmfKXNObz8PJkzqer7lRnp7CJiUO6sO4BFlN869hlAxZAwSfE4NJHkcKdjm6ePwcZ0UAebu s/Fm3+JQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n6mE8-0025we-Dp; Mon, 10 Jan 2022 04:24:12 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , John Hubbard , Christoph Hellwig , William Kucharski , linux-kernel@vger.kernel.org, Jason Gunthorpe Subject: [PATCH v2 07/28] gup: Remove an assumption of a contiguous memmap Date: Mon, 10 Jan 2022 04:23:45 +0000 Message-Id: <20220110042406.499429-8-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220110042406.499429-1-willy@infradead.org> References: <20220110042406.499429-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1010420002 X-Stat-Signature: dfwrbf3e8jp1zzcdh1k7wzbjta1gi9c5 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=gHzU4niH; dmarc=none; spf=none (imf31.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1641788677-801412 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: This assumption needs the inverse of nth_page(), which I've temporarily named page_nth() until someone comes up with a better name. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard --- include/linux/mm.h | 2 ++ mm/gup.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index d8b7d7ed14dd..f2f3400665a4 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -216,8 +216,10 @@ int overcommit_policy_handler(struct ctl_table *, int, void *, size_t *, #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) +#define page_nth(head, tail) (page_to_pfn(tail) - page_to_pfn(head)) #else #define nth_page(page,n) ((page) + (n)) +#define page_nth(head, tail) ((tail) - (head)) #endif /* to align the pointer to the (next) page boundary */ diff --git a/mm/gup.c b/mm/gup.c index 9c0a702a4e03..afb638a30e44 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -238,8 +238,8 @@ static inline struct page *compound_range_next(unsigned long i, next = nth_page(start, i); page = compound_head(next); if (PageHead(page)) - nr = min_t(unsigned int, - page + compound_nr(page) - next, npages - i); + nr = min_t(unsigned int, npages - i, + compound_nr(page) - page_nth(page, next)); *ntails = nr; return page;