Received: by 10.213.65.68 with SMTP id h4csp88850imn; Fri, 30 Mar 2018 01:18:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+y2EfR1YZGdi1+TIhlpZ33GXIb7MXZGUGk9bFXLigWUtg54rliHXrZXvtTj8ShzwpzSaUC X-Received: by 2002:a17:902:7202:: with SMTP id ba2-v6mr6275647plb.249.1522397939279; Fri, 30 Mar 2018 01:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522397939; cv=none; d=google.com; s=arc-20160816; b=CwPoikLJMh+IBzN8SS7qPAZxNCz3ql+QbbRGX0MI7zMadZvKCefE8aht7vh7Y/tGHf FHxO1oMrQ8qnbDdWQ/W4iURapC3W31s0vAizX74WL7S5bpRdTkhV2axCfcHXGHJNtyq0 hw2XgvMd0kAVpmXLrIFrcCZclMOCvLo6jBQixY9yLunscmjyBRWC/n4j5GfwQPacom1x P1NvpuNKFTy1xvvbutyodjkKHweGOQsC17g8KZPLzqE3Jfq71eEKxyrG/pywP/JmCD0T UCArO//npI4lrhCukxuZqxsnmnAQnzIItKd+Y5h22vmdgBHQHFr4zZhzYZQAL6/7x+jO o9iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=+sMsi/H8lVfVBGinev4JqDbIw6xiqVkQl34aLu2Ouvo=; b=ujqhcS5UajRy5qxZ6XNLA22/6tpiiXF3TB0Dqe0o2WJHjYsuX2KXvBgezO/y04svGN FOOs3rNEJga2RC5R4nndeLc5CfCcXe3osJIsMjGCoF16GcwM/UTz8+V6fojfTy5HyVwN GvWw7hAtPVijhakLbQv80sdh3NPnYwJIwWmLIyILoMQCxZv9l7qE19FzbQNuuu2IN3he 81QyS3zn5fsgWPLX4Vne6y4n1P8DmreSA5aSieJ++YzkZZ0l1+V+/7kamQ8aPIibzqbs pJhl0jxWrYt6lgloluPkGLD2Cdl1KUNpx61r1pb/8aMeFwhNAUKhzUxvjiM9NoLiIQKq 9fiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EaStRcMi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4-v6si8321125pld.371.2018.03.30.01.18.45; Fri, 30 Mar 2018 01:18:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EaStRcMi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751373AbeC3IRT (ORCPT + 99 others); Fri, 30 Mar 2018 04:17:19 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35799 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751215AbeC3IRQ (ORCPT ); Fri, 30 Mar 2018 04:17:16 -0400 Received: by mail-pg0-f65.google.com with SMTP id j3so4707413pgf.2 for ; Fri, 30 Mar 2018 01:17:16 -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=+sMsi/H8lVfVBGinev4JqDbIw6xiqVkQl34aLu2Ouvo=; b=EaStRcMil2Fnotdib2ORbsXEZNVl5uGY/j9P2Oi7AbxT46nm3a7tae3K+5xEEFTYbn RquzLGqSbpn/5qOY+yMyJhtX7H73o2o843VJSE3bcF1Q16ZhbGaiB++mAbvYGUFQGUN4 jeS8+Vxgo9XeN1XvrFSySKoczr02q2satn77sZnusHYfG7VtiaY9j+WWNYHdb8arCId5 18yXJ178vtIxGd558fk72QfBWCKQY2zLunmBkZu3NC2oeqiMX4p81jZzw3s01UQtwY0w B5UFJgcLoIKFYyN61r/YSAm16jT4utbPfxu2uoSUWnNQuj6MZP2pXHIIlTQjf2fkCARf pP4Q== 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=+sMsi/H8lVfVBGinev4JqDbIw6xiqVkQl34aLu2Ouvo=; b=ZHBz8dcfjA9AyygotOSBnyn34Kl+ORod0aQMFneb823kq/WcI8tpFyZdwUta5bgyBt QJjjq/5x330aon5lrkyp6l8HRFgUlCh0WDRyBtvrdSBEE/BdSWY9ZoZDiT1YSHpHujJK 3LHubSKPOmNp+qCYinAuE/kjFFJQ/hrArq3a7/k3rR4eg2WqbJKPqNOa6I8/Y0sqXD+y vCRyttRBoSuVIpUCZIV4pqUGmICmKGkSlw6wsVSnXPqW06NmFRNodHgAkT6kf0/kI9le BX/kl0yCDpCQwSpK1p2fd+ODMZWu4vg3UXn1lkw/R9a09ezfv+Qor8WgGToULQqXFKrn e6GQ== X-Gm-Message-State: AElRT7GUE137WOUhVtyMH9h8zeUYv0Czc//339wa+RhG2hKwTK94nlJ5 gc10oXadBrVgnGiifznPdP0= X-Received: by 10.167.131.203 with SMTP id j11mr6590541pfn.101.1522397836057; Fri, 30 Mar 2018 01:17:16 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id l8sm4269837pff.126.2018.03.30.01.17.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Mar 2018 01:17:15 -0700 (PDT) From: Jia He To: Russell King , Andrew Morton , Michal Hocko , Catalin Marinas , Mel Gorman , Will Deacon , Mark Rutland , "H. Peter Anvin" Cc: Pavel Tatashin , Daniel Jordan , AKASHI Takahiro , Gioh Kim , Steven Sistare , Daniel Vacek , Eugeniu Rosca , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, James Morse , Ard Biesheuvel , Steve Capper , Thomas Gleixner , Ingo Molnar , x86@kernel.org, Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , richard.weiyang@gmail.com, Jia He , Jia He Subject: [PATCH v4 4/5] arm64: introduce pfn_valid_region() Date: Fri, 30 Mar 2018 01:15:54 -0700 Message-Id: <1522397755-33393-5-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522397755-33393-1-git-send-email-hejianet@gmail.com> References: <1522397755-33393-1-git-send-email-hejianet@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 23 +++++++++++++++++++++++ arch/arm64/include/asm/page.h | 3 ++- arch/arm64/mm/init.c | 23 +++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h index 7a0404f..559b414 100644 --- a/arch/arm/include/asm/page.h +++ b/arch/arm/include/asm/page.h @@ -158,7 +158,8 @@ 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 int pfn_valid_region(unsigned long pfn, int *last_idx); #endif #include diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 7779804..11f9b82 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -201,6 +201,29 @@ int pfn_valid(unsigned long pfn) } EXPORT_SYMBOL(pfn_valid); +int pfn_valid_region(unsigned long pfn, int *last_idx) +{ + unsigned long start_pfn, end_pfn; + struct memblock_type *type = &memblock.memory; + struct memblock_region *regions = type->regions; + + if (*last_idx != -1) { + start_pfn = PFN_DOWN(regions[*last_idx].base); + end_pfn = PFN_DOWN(regions[*last_idx].base + + regions[*last_idx].size); + + if (pfn >= start_pfn && pfn < end_pfn) + return !memblock_is_nomap(®ions[*last_idx]); + } + + *last_idx = memblock_search_pfn_regions(pfn); + if (*last_idx == -1) + return false; + + return !memblock_is_nomap(®ions[*last_idx]); +} +EXPORT_SYMBOL(pfn_valid_region); + /* HAVE_MEMBLOCK is always enabled on arm */ unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn, int *last_idx) diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h index 84b503a..27892d5 100644 --- a/arch/arm64/include/asm/page.h +++ b/arch/arm64/include/asm/page.h @@ -39,7 +39,8 @@ 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 int pfn_valid_region(unsigned long pfn, int *last_idx); #endif #include diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index cd9b473..6dedd77 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -293,6 +293,29 @@ int pfn_valid(unsigned long pfn) } EXPORT_SYMBOL(pfn_valid); +int pfn_valid_region(unsigned long pfn, int *last_idx) +{ + unsigned long start_pfn, end_pfn; + struct memblock_type *type = &memblock.memory; + struct memblock_region *regions = type->regions; + + if (*last_idx != -1) { + start_pfn = PFN_DOWN(regions[*last_idx].base); + end_pfn = PFN_DOWN(regions[*last_idx].base + + regions[*last_idx].size); + + if (pfn >= start_pfn && pfn < end_pfn) + return !memblock_is_nomap(®ions[*last_idx]); + } + + *last_idx = memblock_search_pfn_regions(pfn); + if (*last_idx == -1) + return false; + + return !memblock_is_nomap(®ions[*last_idx]); +} +EXPORT_SYMBOL(pfn_valid_region); + /* HAVE_MEMBLOCK is always enabled on arm64 */ unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn, int *last_idx) -- 2.7.4