From patchwork Mon Apr 2 02:30:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10319427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9800860388 for ; Mon, 2 Apr 2018 02:35:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8856F28D4D for ; Mon, 2 Apr 2018 02:35:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BAFE28D42; Mon, 2 Apr 2018 02:35:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C93F928D42 for ; Mon, 2 Apr 2018 02:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=6AEtKHRpVtA9Wt7KklkdKmgX+AU4cG14Yty2UOss8tw=; b=IHwZmFrxVQi+Uj1DI6FiKxAinm 9PZ+zUTUpCmXN6f02+/pb6gIZ/Os18G5bnqF9MEF+hRztApEkm9J2r6VjpnhKeG0doUyEWMF1mUKb EoBGDYxizzlhIHUaSOfzXsLNtxjsR5NBNe1uqLTO4RCRr2ueTSGAZTHe3jKjaTTR+a8Myvg84iZer LvLUtMLRgWqjUQAxLSjwzncycue51IQxCCaFOBfUFWgO4tZcjAfOrl2/fE7vVdkEq2eawJmtdQGBH r5tTiZfgcNzKgeHXNNTf3ZgH/D1nF8IODN7RRYDyDgATIf8Kj5p4x8gJac16ofrZWVdlXMeGU8/qf Z+QVXF0Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f2pJT-00087b-9h; Mon, 02 Apr 2018 02:35:15 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f2pHU-00069v-T1 for linux-arm-kernel@lists.infradead.org; Mon, 02 Apr 2018 02:33:28 +0000 Received: by mail-pf0-x242.google.com with SMTP id j2so8563029pff.10 for ; Sun, 01 Apr 2018 19:33:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=89tLmX1ioocai1fj4zT7S9JG4pMiMYTIMAUpVpzMpzs=; b=skE6NEiuhET7jDql6dDDLqjuh+B/GpiFe1iYbD7Qu2VA4G8QwYhH6AHhu1BNTrfmmP HsiaOeJe7lYxSUyCGixcBVni5VWi7DAuKn+BLgsebX5adnCVCuzok+bJMwFy7UtsTocK 4dz4ibX1MiYqpPQJU4xpTzkEW9WWIkHw1dW2DM0Qn55uM5RiTiNTbyrQBKeesIzvuEbq 36RwyDRYGC96MAZA7cnKU1FzaumX5Cvq7/qqMNO5uXWI9sT52EZ4DVi3/KFc/8297+tX ZgjFgrfizdgUBnANlZMXFhI3Emr/L8+oOTPs9XWlCd+OGKpzxlRyBEpG3a67mOPeAdCw SPbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=89tLmX1ioocai1fj4zT7S9JG4pMiMYTIMAUpVpzMpzs=; b=HPm/yXh9no4KlWzh98nVqXWuAM75rBz+5Efn6on+/+fnuAXBsclGOF2iL5FPlY8QMm fSVIdlqCIYZ3P6SVbhQZnmbr5Agg6yojgwFH70hCY4LMJvlrgmjWCWCBULWiqs/0na+6 PfJigAjfB+HNmjNS+BhD0Ksc3s1tJHOK31GISDLw4ce/GJZxqDTajhb4FcT1KIu8ccaP PCElP3s+QUIZer0cbd5nbOoA5KZxB3FSMmpnu6F6IwyALEVTfVwhu7ut36VIoe+h8hTV UUzbtx58oWwDCyrYKmP06cQxxcyrpfa/nhlWlfScmfRDxQB71S9tWK6soFLToIT/TJRQ Ixmg== X-Gm-Message-State: AElRT7FtfAUM62Acn6fLeXGrgiVgRWp0iESAIdoeqpmYuzoRaFgYvjiD LMFWRNaj46yur82CeSwM13Y= X-Google-Smtp-Source: AIpwx49ISY2dxa4cVGeHIerd9PAmtS5LuPO/Adigxnfxi/RZFEox51GeVgfd670YMG3TOV0f9s2pSg== X-Received: by 10.101.75.202 with SMTP id p10mr5169900pgr.339.1522636382089; Sun, 01 Apr 2018 19:33:02 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id t20sm25934371pfh.182.2018.04.01.19.32.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 01 Apr 2018 19:33:01 -0700 (PDT) From: Jia He To: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko Subject: [PATCH v5 4/5] arm64: introduce pfn_valid_region() Date: Sun, 1 Apr 2018 19:30:35 -0700 Message-Id: <1522636236-12625-5-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522636236-12625-1-git-send-email-hejianet@gmail.com> References: <1522636236-12625-1-git-send-email-hejianet@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180401_193312_947325_B0435F0C X-CRM114-Status: GOOD ( 15.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Grygorii Strashko , Wei Yang , linux-mm@kvack.org, Eugeniu Rosca , Petr Tesarik , Nikolay Borisov , Jia He , Pavel Tatashin , Daniel Jordan , AKASHI Takahiro , Gioh Kim , Andrey Ryabinin , Laura Abbott , Daniel Vacek , Mel Gorman , Vladimir Murzin , Kees Cook , Philip Derrin , YASUAKI ISHIMATSU , Jia He , Kemi Wang , Vlastimil Babka , linux-arm-kernel@lists.infradead.org, Steve Capper , linux-kernel@vger.kernel.org, James Morse , Johannes Weiner MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This is the preparation for further optimizing in early_pfn_valid on arm and arm64. Signed-off-by: Jia He --- arch/arm/include/asm/page.h | 3 ++- arch/arm/mm/init.c | 24 ++++++++++++++++++++++++ arch/arm64/include/asm/page.h | 3 ++- arch/arm64/mm/init.c | 24 ++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h index f38909c..3bd810e 100644 --- a/arch/arm/include/asm/page.h +++ b/arch/arm/include/asm/page.h @@ -158,9 +158,10 @@ typedef struct page *pgtable_t; #ifdef CONFIG_HAVE_ARCH_PFN_VALID extern int early_region_idx; -extern int pfn_valid(unsigned long); +extern int pfn_valid(unsigned long pfn); extern unsigned long memblock_next_valid_pfn(unsigned long pfn); #define skip_to_last_invalid_pfn(pfn) (memblock_next_valid_pfn(pfn) - 1) +extern int pfn_valid_region(unsigned long pfn); #endif #include diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 06ed190..bdcbf58 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -201,6 +201,30 @@ int pfn_valid(unsigned long pfn) } EXPORT_SYMBOL(pfn_valid); +int pfn_valid_region(unsigned long pfn) +{ + unsigned long start_pfn, end_pfn; + struct memblock_type *type = &memblock.memory; + struct memblock_region *regions = type->regions; + + if (early_region_idx != -1) { + start_pfn = PFN_DOWN(regions[early_region_idx].base); + end_pfn = PFN_DOWN(regions[early_region_idx].base + + regions[early_region_idx].size); + + if (pfn >= start_pfn && pfn < end_pfn) + return !memblock_is_nomap( + ®ions[early_region_idx]); + } + + early_region_idx = memblock_search_pfn_regions(pfn); + if (early_region_idx == -1) + return false; + + return !memblock_is_nomap(®ions[early_region_idx]); +} +EXPORT_SYMBOL(pfn_valid_region); + /* HAVE_MEMBLOCK is always enabled on arm */ unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn) { diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h index f0d8c8e5..7087b63 100644 --- a/arch/arm64/include/asm/page.h +++ b/arch/arm64/include/asm/page.h @@ -39,9 +39,10 @@ typedef struct page *pgtable_t; #ifdef CONFIG_HAVE_ARCH_PFN_VALID extern int early_region_idx; -extern int pfn_valid(unsigned long); +extern int pfn_valid(unsigned long pfn); extern unsigned long memblock_next_valid_pfn(unsigned long pfn); #define skip_to_last_invalid_pfn(pfn) (memblock_next_valid_pfn(pfn) - 1) +extern int pfn_valid_region(unsigned long pfn); #endif #include diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 342e4e2..a1646b6 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -293,6 +293,30 @@ int pfn_valid(unsigned long pfn) } EXPORT_SYMBOL(pfn_valid); +int pfn_valid_region(unsigned long pfn) +{ + unsigned long start_pfn, end_pfn; + struct memblock_type *type = &memblock.memory; + struct memblock_region *regions = type->regions; + + if (early_region_idx != -1) { + start_pfn = PFN_DOWN(regions[early_region_idx].base); + end_pfn = PFN_DOWN(regions[early_region_idx].base + + regions[early_region_idx].size); + + if (pfn >= start_pfn && pfn < end_pfn) + return !memblock_is_nomap( + ®ions[early_region_idx]); + } + + early_region_idx = memblock_search_pfn_regions(pfn); + if (early_region_idx == -1) + return false; + + return !memblock_is_nomap(®ions[early_region_idx]); +} +EXPORT_SYMBOL(pfn_valid_region); + /* HAVE_MEMBLOCK is always enabled on arm64 */ unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn) {