Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2135395pxb; Fri, 25 Mar 2022 11:42:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTP3Dx/vndGglQhaBaA4FGxlOZY4p0KsgC966Vi5Io2cVDUC8pRZrmC2KRK4cEEg+D1I/8 X-Received: by 2002:a17:90a:65c9:b0:1bd:5b80:5c39 with SMTP id i9-20020a17090a65c900b001bd5b805c39mr26263698pjs.185.1648233778809; Fri, 25 Mar 2022 11:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648233778; cv=none; d=google.com; s=arc-20160816; b=COa5Xmw73LDu83uzUDcPcZ+pcriEAo6MmnQxKDVjTkUlvj8xgapbvZotaVd2fkrYND HcG+zruomNlK/WAa586raE01nCV+Z3ZeTtTj8NPerTRDv1+UAvog/5L/xB9bZOBQ2kAP ygmIILPIm+Et1Ci4pCnteFS48ZITvGKPqaOnfD940980JgFKT3uK3CB1pKAZ/n4JQ7oh UG3fX16o89ULH7S/+ZOznZiIH8x7hCF+S+G+5mzXzcFdWtKnEaUedSp75eoPxLZ8ZZxI v6elU+0B7AFbza0nNpvFxt6v5+ySXUhkMkSwDYTMeIc2Ig0pogBhKhlke++fi5xOynvE 7hdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=04++ejy5/yIf+QVT4m1oQmzMNHrje9zF1MhViQLha2g=; b=W0tMehm57aHZKvMWjggjueob7ypJyomNRa1vbdHrUrLKXc9RQGu+x4cZVAAADgckOg xMJ3JGbzdI2hyt9vWGVRs5JykvtLyT0wNWgMqMid3wkvDUivpmXHM3BEHGmcaQl/yV80 yYSemX4FMVIi+BA5t8xwV1P0Tf7tSqEJyx3TOsbSBJ5jSj46hrHRZpp1ANDTolKTAfHY /GoCXs84oUnq//ZV+Li2HcSg34oYzuLGyUEPbWQaIpKf/sgvp1fGw/wNGHXs3tBK7L2a pItg7z3YNiJi/IAnCTe3XN9jsVINKgDJahghXIh864VkARmTJN81cW2Q3btl78agSIhC XA0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=qKNtYeZ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h12-20020a170902748c00b00153b2d16471si3054791pll.121.2022.03.25.11.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:42:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=qKNtYeZ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7FDCE19F235; Fri, 25 Mar 2022 10:59:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244401AbiCXHBK (ORCPT + 99 others); Thu, 24 Mar 2022 03:01:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345695AbiCXHA7 (ORCPT ); Thu, 24 Mar 2022 03:00:59 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CF853A6A for ; Wed, 23 Mar 2022 23:59:25 -0700 (PDT) Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220324065922epoutp02f83061aa187f53dc8ea4f43225075a8c~fPunCN5cE1323613236epoutp02g for ; Thu, 24 Mar 2022 06:59:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220324065922epoutp02f83061aa187f53dc8ea4f43225075a8c~fPunCN5cE1323613236epoutp02g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105162; bh=04++ejy5/yIf+QVT4m1oQmzMNHrje9zF1MhViQLha2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qKNtYeZ0d13TzxYZ6nir9OU9mDYAaeIQRgOPACiwmFkZx2JKmG7vl77+xIioF1AHO 8GQv2kEKrsN+24cnMwXD4uP91Rzah0Ruhvju+h3Fyak3hYhXkSF5Mj+ulSd8IIoxto HV1Kp9YTkH94CbnJNFyhClITZTcNaCoZKdqBoi3Y= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20220324065921epcas1p470d911984edf8b239256e90b1c145648~fPump5zYj2719127191epcas1p4r; Thu, 24 Mar 2022 06:59:21 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.38.248]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4KPGKz5PQ0z4x9QJ; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id 01.2B.28648.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p1b30eabc8bbe01da1ef90280b6ee8bcea~fPukRm-t23006230062epcas1p1U; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220324065919epsmtrp20497a364e1b0f1aacf11b10546c2b47a~fPukQ0VTV2562325623epsmtrp2W; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a39-ff1ff70000006fe8-8c-623c16c79bb9 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 56.AD.03370.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from jaewon-linux.10.32.193.11 (unknown [10.253.100.104]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epsmtip2c96f2e23e1233729ba054029a3a09905~fPukJGmsT3186931869epsmtip2b; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) From: Jaewon Kim To: rppt@kernel.org, vbabka@suse.cz, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ytk.lee@samsung.com, jaewon31.kim@gmail.com, Jaewon Kim Subject: [PATCH 2/8] memblock: detect hidden memory hole size Date: Thu, 24 Mar 2022 16:01:52 +0900 Message-Id: <20220324070158.22969-3-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBKsWRmVeSWpSXmKPExsWy7bCmvu5xMZskg9YOdYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwWj9dzO3B47Jx1l91j06pONo9Nnyaxe5yY8ZvF o2/LKkaPMwuOsHt83iQXwB6VbZORmpiSWqSQmpecn5KZl26r5B0c7xxvamZgqGtoaWGupJCX mJtqq+TiE6DrlpkDdJSSQlliTilQKCC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IhZz1q9hs+jePJPR ovf9KyaLy7vmsFncW/Of1eLI+u1MFrMb+xgtHq/nduDw2DnrLrvHplWdbB6bPk1i9zgx4zeL R9+WVYweZxYcYff4vEkugD2KyyYlNSezLLVI3y6BK+Pyt+tsBQdkK3bM4WxgvCzexcjJISFg InHzz2X2LkYuDiGBHYwSnx58YYJIyEi8Of+UpYuRA8gWljh8uBii5hujxLb1s1lAatgEtCXe L5jECmKLCDhJbLiymgWkiFlgAqPEymWfwIqEBWwlGu+8BytiEVCVmPdvGhuIzQsUvzDtLRvE MnmJ1RsOMIPYnAJ2EiuXHGAEsYWAas6ePMA2gZFvASPDKkbJ1ILi3PTcYsMCo7zUcr3ixNzi 0rx0veT83E2M4IDU0trBuGfVB71DjEwcjIcYJTiYlUR471+2ThLiTUmsrEotyo8vKs1JLT7E KM3BoiTOe6HrZLyQQHpiSWp2ampBahFMlomDU6qBSeji2oy5s/QmMT6VMrtom/3l2jqL791P +g6+tpA4fmGjUhz3s4+Rm6Ok1qbdnm5o/WSCg6JMUEJDf/31zavYC6at+62sfLc4/nC6wfY1 s3+8q/zD+nafTukd3i1XckM3+0lP2rTo8796FZlW61sXmN4cf3D9xMuP+89IB3iKmV748fb9 593LDwlUXmANDmOTYk5IcM6SXv8i/dOy63+f8d5PmOdSOturdMI69lqrqw/5lZdsvq+ZJm5R cJJxe4aEsPX2p2fj47hk5+sXfbNbytWtd3wLY0/JCy1BH6t6zeknlV2E/gU8PXw177R9zv7v P15NfRTE754YmTR9kduvFadv2qbqZfK/Cn7UorCKv0WJpTgj0VCLuag4EQBzrkittwIAAA== X-CMS-MailID: 20220324065919epcas1p1b30eabc8bbe01da1ef90280b6ee8bcea X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p1b30eabc8bbe01da1ef90280b6ee8bcea References: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bootloader knows the actual memory size, but bootloader may reserve some memory for a specific purpose and pass the only remaining memory region to kernel. Even though kernel does not know what it is, we need to detect those regions to sum up all reserved memory. Let me call it memory hole. To expect the hole size, this patch assume two things. One is that each physical memory has 1GB aligned size and address. And the hole is less than 1GB. For the hole, let it be shown as unknown in memsize logic. This is an example. 0x0bf000000-0x0c0000000 0x01000000 ( 16384 KB ) nomap unusable unknown Signed-off-by: Jaewon Kim --- drivers/of/fdt.c | 2 ++ include/linux/memblock.h | 2 ++ mm/memblock.c | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index ec2f60a78f8f..9721a3d7b7ae 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1294,6 +1294,8 @@ void __init early_init_dt_scan_nodes(void) /* Handle linux,usable-memory-range property */ early_init_dt_check_for_usable_mem_range(); + + memblock_memsize_detect_hole(); } bool __init early_init_dt_scan(void *params) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 468b016e179b..201f8723dfd8 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -608,10 +608,12 @@ static inline void early_memtest(phys_addr_t start, phys_addr_t end) extern void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable); +extern void memblock_memsize_detect_hole(void); #else static inline void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable) { } +static inline void memblock_memsize_detect_hole(void) { } #endif #endif /* _LINUX_MEMBLOCK_H */ diff --git a/mm/memblock.c b/mm/memblock.c index 8492757f7192..8e032f44eb57 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1970,6 +1970,51 @@ void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base, memblock_dbg("%s %pa..%pa nomap:%d reusable:%d\n", __func__, &base, &end, nomap, reusable); } + +/* This function will be called to by early_init_dt_scan_nodes */ +void __init memblock_memsize_detect_hole(void) +{ + phys_addr_t base, end; + phys_addr_t prev_end, hole_sz; + int idx; + struct memblock_region *rgn; + int memblock_cnt = (int)memblock.memory.cnt; + + /* assume that the hole size is less than 1 GB */ + for_each_memblock_type(idx, (&memblock.memory), rgn) { + prev_end = (idx == 0) ? round_down(rgn->base, SZ_1G) : end; + base = rgn->base; + end = rgn->base + rgn->size; + + /* only for the last region, check a hole after the region */ + if (idx + 1 == memblock_cnt) { + hole_sz = round_up(end, SZ_1G) - end; + if (hole_sz) + memblock_memsize_record(NULL, end, hole_sz, + true, false); + } + + /* for each region, check a hole prior to the region */ + hole_sz = base - prev_end; + if (!hole_sz) + continue; + if (hole_sz < SZ_1G) { + memblock_memsize_record(NULL, prev_end, hole_sz, true, + false); + } else { + phys_addr_t hole_sz1, hole_sz2; + + hole_sz1 = round_up(prev_end, SZ_1G) - prev_end; + if (hole_sz1) + memblock_memsize_record(NULL, prev_end, + hole_sz1, true, false); + hole_sz2 = base % SZ_1G; + if (hole_sz2) + memblock_memsize_record(NULL, base - hole_sz2, + hole_sz2, true, false); + } + } +} #endif /* MEMBLOCK_MEMSIZE */ static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn) -- 2.17.1