From patchwork Thu Mar 24 07:01:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12790446 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 DBDF0C433F5 for ; Thu, 24 Mar 2022 06:59:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 951B76B007E; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C5AF8D0001; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30C156B007B; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id 067BF6B007D for ; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id AC807A30BF for ; Thu, 24 Mar 2022 06:59:25 +0000 (UTC) X-FDA: 79278378690.31.BD953E5 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf16.hostedemail.com (Postfix) with ESMTP id B226C18002D for ; Thu, 24 Mar 2022 06:59:24 +0000 (UTC) Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220324065922epoutp026f9cdeae790dcef706178b59a038e58b~fPumzQVK51428414284epoutp02d for ; Thu, 24 Mar 2022 06:59:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220324065922epoutp026f9cdeae790dcef706178b59a038e58b~fPumzQVK51428414284epoutp02d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105162; bh=KyBdZg8CThIyXolubx/7sGIn+ypooiLqPM4nQuxNNcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T/F8+jQJnqAcCruZ1LHJv3s2D5EeFE9uc/DAPnXzMUbMCBtDN4oE2+be0W6plmVh8 xXn1JSY/llGkikbr9ZuTjrYvJA/FpuZ7EXs/OXW9N2Ru2ienSZTr2CiOWwQ5WEfrQT w/+fhPVod3jnWj3FJrVWJCvWzhOVpmoq7VWytMtI= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20220324065921epcas1p3b26228c7923bad0615f453f252832899~fPumTg15a0544405444epcas1p3J; Thu, 24 Mar 2022 06:59:21 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.36.226]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4KPGKz6rNvz4x9QX; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id C2.0A.64085.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p256ff799f37a765a432475808e708d639~fPukWGpZ80342903429epcas1p28; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220324065919epsmtrp17a689e995e1ebee583756cc406048a8b~fPukVPaz92225222252epsmtrp1U; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a35-9c3ff7000000fa55-0c-623c16c78af8 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 86.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 20220324065919epsmtip28837454c5e037d06492410f49713d2ec~fPukNtTfb3186931869epsmtip2c; 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 4/8] memblock: track memblock changed at early param Date: Thu, 24 Mar 2022 16:01:54 +0900 Message-Id: <20220324070158.22969-5-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+NgFnrJKsWRmVeSWpSXmKPExsWy7bCmge5xMZskgwsLdCzmrF/DZtG9eSaj Re/7V0wWl3fNYbO4t+Y/q8WR9duZLGY39jFaPF7P7cDhsXPWXXaPTas62Tw2fZrE7nFixm8W j74tqxg9ziw4wu7xeZNcAHtUtk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJe Ym6qrZKLT4CuW2YO0FFKCmWJOaVAoYDE4mIlfTubovzSklSFjPziElul1IKUnAKzAr3ixNzi 0rx0vbzUEitDAwMjU6DChOyMfdOusxdct6xYunUPawPjTd0uRk4OCQETieZL/WxdjFwcQgI7 GCWWXnrADpIQEvjEKLG3hRci8ZlR4urPqSwwHZ27fjFCJHYxSjQeOc4M4fxglHh19BwbSBWb gLbE+wWTWEFsEQE7iW+zD7CCFDELdDFKPPhwEGyUsICLxL+P/8EaWARUJR7OuApm8wrYSrx/ dRZqnbzE6g0HmEFsTqBBK5ccAFstIXCPXWLa/1VQRS4SzX9mMEPYwhKvj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OATuJlUsOQB1kK3H25AG2CYx8CxgZVjFKphYU56bnFhsWGOWllusVJ+YW l+al6yXn525iBAekltYOxj2rPugdYmTiYDzEKMHBrCTCe/+ydZIQb0piZVVqUX58UWlOavEh RmkOFiVx3gtdJ+OFBNITS1KzU1MLUotgskwcnFINTAb/lF2K/u87uqp+sVT3sw7jnMZptsHv p88IrrLTFan2N+Gbt+TH0uIWLZ7/tVYmlzldm6cVmqT6LT/Hd3TR/d2xTpJLPu/oydrfmmUo yOg1j3Xff7aN+07Pd62X6ft3vo19haf0OrYMTdlyj7L/bX51s62u38r7faXywMdO10/ry2YY 8jtZJ812FA373lu29feVfXwZ55ZHJwbNFbOUX84hF53wxFP0nc+S1FzJO47WLfaPNC77zVft Oz1TfO76aXPF7E9ZMW6dn7vdwmm9VW9qtK2vq/GCzqCl77+nV+X7LCv5VX5I9ovR8uTZh3Ki Zm86ccqVy2nqlscVTx+bpj4yzMsPTzZ7vOps6/EdSizFGYmGWsxFxYkA3wxP9bcCAAA= X-CMS-MailID: 20220324065919epcas1p256ff799f37a765a432475808e708d639 X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p256ff799f37a765a432475808e708d639 References: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b="T/F8+jQJ"; spf=pass (imf16.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B226C18002D X-Stat-Signature: 4u41a6hsc918ckr79zrrdzr8naf9qfzg X-HE-Tag: 1648105164-984780 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: In addition to reserved-memory in device tree, an option in cmdline may result in memblock allocation. This patch tries to distinguish memblock changes done at early param. A region in memsize will be created with name as the param string. And the region size will be updated during the param function. Signed-off-by: Jaewon Kim --- include/linux/memblock.h | 4 ++ init/main.c | 13 ++++- mm/memblock.c | 101 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 112 insertions(+), 6 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 201f8723dfd8..4be4e0e6baf4 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -609,11 +609,15 @@ 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); +extern void memblock_memsize_set_name(const char *name); +extern void memblock_memsize_unset_name(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) { } +static inline void memblock_memsize_set_name(const char *name) { } +static inline void memblock_memsize_unset_name(void) { } #endif #endif /* _LINUX_MEMBLOCK_H */ diff --git a/init/main.c b/init/main.c index 560f45c27ffe..ce59521b5ae5 100644 --- a/init/main.c +++ b/init/main.c @@ -214,8 +214,15 @@ static bool __init obsolete_checksetup(char *line) pr_warn("Parameter %s is obsolete, ignored\n", p->str); return true; - } else if (p->setup_func(line + n)) - return true; + } else { + int ret; + + memblock_memsize_set_name(p->str); + ret = p->setup_func(line + n); + memblock_memsize_unset_name(); + if (ret) + return true; + } } p++; } while (p < __setup_end); @@ -736,8 +743,10 @@ static int __init do_early_param(char *param, char *val, (strcmp(param, "console") == 0 && strcmp(p->str, "earlycon") == 0) ) { + memblock_memsize_set_name(p->str); if (p->setup_func(val) != 0) pr_warn("Malformed early option '%s'\n", param); + memblock_memsize_unset_name(); } } /* We accept everything at this stage. */ diff --git a/mm/memblock.c b/mm/memblock.c index 9195a51bfa5d..4f21b596687e 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -169,6 +169,18 @@ static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size) return *size = min(*size, PHYS_ADDR_MAX - base); } +#ifdef CONFIG_MEMBLOCK_MEMSIZE +static void memblock_memsize_record_add(struct memblock_type *type, + phys_addr_t base, phys_addr_t size); +static void memblock_memsize_record_remove(struct memblock_type *type, + phys_addr_t base, phys_addr_t size); +#else +static inline void memblock_memsize_record_add(struct memblock_type *type, + phys_addr_t base, phys_addr_t size) { } +static inline void memblock_memsize_record_remove(struct memblock_type *type, + phys_addr_t base, phys_addr_t size) { } +#endif /* CONFIG_MEMBLOCK_MEMSIZE */ + /* * Address comparison utilities */ @@ -578,6 +590,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, bool insert = false; phys_addr_t obase = base; phys_addr_t end = base + memblock_cap_size(base, &size); + phys_addr_t new_size = 0; int idx, nr_new; struct memblock_region *rgn; @@ -592,7 +605,8 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, type->regions[0].flags = flags; memblock_set_region_node(&type->regions[0], nid); type->total_size = size; - return 0; + new_size = size; + goto done; } repeat: /* @@ -621,10 +635,12 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, #endif WARN_ON(flags != rgn->flags); nr_new++; - if (insert) + if (insert) { memblock_insert_region(type, idx++, base, rbase - base, nid, flags); + new_size += rbase - base; + } } /* area below @rend is dealt with, forget about it */ base = min(rend, end); @@ -633,9 +649,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, /* insert the remaining portion */ if (base < end) { nr_new++; - if (insert) + if (insert) { memblock_insert_region(type, idx, base, end - base, nid, flags); + new_size += end - base; + } } if (!nr_new) @@ -653,8 +671,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, goto repeat; } else { memblock_merge_regions(type); - return 0; } +done: + if (new_size == size) + memblock_memsize_record_add(type, obase, size); + return 0; } /** @@ -790,6 +811,7 @@ static int __init_memblock memblock_remove_range(struct memblock_type *type, for (i = end_rgn - 1; i >= start_rgn; i--) memblock_remove_region(type, i); + memblock_memsize_record_remove(type, base, size); return 0; } @@ -2091,6 +2113,77 @@ void __init memblock_memsize_detect_hole(void) } } } + +/* assume that freeing region is NOT bigger than the previous region */ +static void __init_memblock memblock_memsize_free(phys_addr_t free_base, + phys_addr_t free_size) +{ + int i; + struct memsize_rgn_struct *rgn; + phys_addr_t free_end, end; + + free_end = free_base + free_size - 1; + memblock_dbg("%s %pa..%pa\n", + __func__, &free_base, &free_end); + + for (i = 0; i < memsize_rgn_count; i++) { + rgn = &memsize_rgn[i]; + + end = rgn->base + rgn->size; + if (free_base < rgn->base || + free_base >= end) + continue; + + free_end = free_base + free_size; + if (free_base == rgn->base) { + rgn->size -= free_size; + if (rgn->size != 0) + rgn->base += free_size; + } else if (free_end == end) { + rgn->size -= free_size; + } else { + memblock_memsize_record(rgn->name, free_end, + end - free_end, rgn->nomap, rgn->reusable); + rgn->size = free_base - rgn->base; + } + } +} + +static const char *memblock_memsize_name; + +void __init memblock_memsize_set_name(const char *name) +{ + memblock_memsize_name = name; +} + +void __init memblock_memsize_unset_name(void) +{ + memblock_memsize_name = NULL; +} + +static void __init_memblock memblock_memsize_record_add(struct memblock_type *type, + phys_addr_t base, phys_addr_t size) +{ + if (memblock_memsize_name) { + if (type == &memblock.reserved) + memblock_memsize_record(memblock_memsize_name, + base, size, false, false); + else if (type == &memblock.memory) + memblock_memsize_free(base, size); + } +} + +static void __init_memblock memblock_memsize_record_remove(struct memblock_type *type, + phys_addr_t base, phys_addr_t size) +{ + if (memblock_memsize_name) { + if (type == &memblock.reserved) + memblock_memsize_free(base, size); + else if (type == &memblock.memory) + memblock_memsize_record(memblock_memsize_name, + base, size, true, false); + } +} #endif /* MEMBLOCK_MEMSIZE */ static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn)