From patchwork Tue May 21 02:39:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668805 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 418EFC25B77 for ; Tue, 21 May 2024 02:40:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F06ED6B008A; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92C266B009B; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EAEF6B0093; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D6DBA6B0093 for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 98E0F120FC7 for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.04.5E4349C Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf27.hostedemail.com (Postfix) with ESMTP id B868E40013 for ; Tue, 21 May 2024 02:40:13 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ioKZ5v8+; spf=pass (imf27.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716259214; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3kKY9p5rX9c1bN2ssSLpLQuO2G9ldZSHB4ioCNHoa30=; b=bLIhHEvqH2jg15J+6lXtw5F/ZehZCiIq3plNfvRFEmLCtvZRrxW9emaGJ/NifvVy1M+ftC oyzUP4QIyWON0glKOrWWZu/Fpd9n0yPfXNXYhIgNOtLCaxZam7y44il0mPPrbMLHXD6zrs Hgow6CHjIv8J0joRkWp4v9g0Fcnz1O8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ioKZ5v8+; spf=pass (imf27.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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259214; a=rsa-sha256; cv=none; b=4kt+QZcqRYkbTLKDSsl/FzmhVm1eynYS794YERFRsbBP1asvcQhUHudnmay/NEdtBCCxlo mAZtPh0Bi9oaGeCppklk4UwwhslnqJSPN2YHrrOQEBTeqmedgHd4AfcpQPaAbAr8u0i2OL QggY+UBE/iEyf2dRTFo/J9eAee6hA78= Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp02d97f4018e0d3cd0b41cdd8c86a2ca6e7~RYKizHyaC0406504065epoutp02c for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20240521024010epoutp02d97f4018e0d3cd0b41cdd8c86a2ca6e7~RYKizHyaC0406504065epoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=3kKY9p5rX9c1bN2ssSLpLQuO2G9ldZSHB4ioCNHoa30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ioKZ5v8+EiGjygozsgC5p+pkEgQD7JtEhkp4fN0M3y/s/D/L3qEG5YWaLeDKQDydR P9usUwGGq173W1LY+Ivw3z2D5R6Y4x9wCwreahs5irq2gx+TifrgR5xHU14xuEg8R7 AJO7t7DQCYACPiabfKp742Xo0JJVZe3pYTeXjMnM= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20240521024009epcas1p1cf3280cf33e9d6057ea5c4b3f7d01c0b~RYKiHzV952332223322epcas1p1j; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.36.224]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4VjzDn48LTz4x9Q0; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id AF.4F.09662.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p20ddcabed3d037904a9c651d27f82c077~RYKhfz-vs0129801298epcas1p2n; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp22b86ded1b29f1daf8837089c371f91f3~RYKhfM07S2496124961epsmtrp2q; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a35-8da83a80000025be-a9-664c0989ddba Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id AE.EA.09238.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from localhost.localdomain (unknown [10.253.104.99]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epsmtip24e01e0bac44534b743d22ec2b6b08031~RYKhVkH0A1233912339epsmtip2D; Tue, 21 May 2024 02:40:09 +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, jaewon31.kim@gmail.com, Jaewon Kim Subject: [RESEND PATCH 05/10] memblock: track memblock changed at early param Date: Tue, 21 May 2024 11:39:52 +0900 Message-Id: <20240521023957.2587005-6-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240521023957.2587005-1-jaewon31.kim@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpnk+LIzCtJLcpLzFFi42LZdlhTX7eT0yfN4PBpOYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIztg4+zdrwX6rir69G1kbGG/qdTFycEgImEgcXGrSxcjFISSwg1HiwPEJ jBDOJ0aJbztXs0A43xglmiYfZe9i5ATruPV6OxtEYi+jxPXj06CqPjNKnNv6ngWkik1AW+L9 gkmsILaIgJ3Et9kHwGxmgVKJt29OMIPYwgL+Es1b1rGB2CwCqhLLPk4D6+UVsJdoO7SQEWKb vMTMS9/BNnMKOEjMn7KYHaJGUOLkzCcsEDPlJZq3zmaGqP/KLnFkfRqE7SKxc84hFghbWOLV 8S1QH0hJfH63lw3Czpe4cPEVEyQsaiQWTjSECNtL7Po6gxUkzCygKbF+lz7EJj6Jd197WCGq eSU62oQgqtUkWp59ZYWwZST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4tL89L1kvNzNzGCA11LYwfjvfn/9A4xMnEwHmKU4GBWEuHdtMUzTYg3 JbGyKrUoP76oNCe1+BCjNAeLkjiv4YzZKUIC6YklqdmpqQWpRTBZJg5OqQYmfb3DTy/di7V6 m6a1UGd7vcG8afulHjjKcyZZrFc2vGsZeYJv2oW8LlYdCanDNVmrTrObNtge/5R48PGXVlmh XjfZy54cUS4P55xfs+qgzbk25WPfqw5O+3kja7ZR1eWzEZMPse/Kr9t+pGmh0M+tk9W+fuHP idXY0SzSpLbG23FG7MyDh84FK1/Z4hzhoOLQV5Rr1rxE8egR64gf/NPZ8+SLmoUltzat9bz7 YuU0G97bUa+nq2/P4Jd7t2Tp5sod8y8lCiVdOXZ69/YLS78t0vSsktedHKE2WW5i1s3816nb A+e7rIj+F7Jc1ql4yYf6r99vnuXY56d6o20L1xMRnrt6kWVhwkX3BXjVUnnPKLEUZyQaajEX FScCALkqXMfjAgAA X-CMS-MailID: 20240521024009epcas1p20ddcabed3d037904a9c651d27f82c077 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p20ddcabed3d037904a9c651d27f82c077 References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B868E40013 X-Stat-Signature: rk57bbmxcsdr9czcxpfxea7iczog3jrp X-HE-Tag: 1716259213-259463 X-HE-Meta: U2FsdGVkX19m+pc29ge5fxamtTsGQRLnRSU1g6951S0TkYmHWTiw41nT8ETrpnGwsiYGarlo7G37+hZFTM8ms9pBHDFbkuWECyZaKtdoIIuPE7zSOd/x2aBZrdl7zFx8gTKC08dhPh3zxJURzf7rG253Ek3eUh40e9cFdvXGyhOWBRuoiartZ+ILHAndi4xh51Uz5MOjUKCK5/xn6lkIfcT+ttJ+y2AJNbQjlhS/QDRxH+J2c3h601iGjL4hvlhpJxvpY1nFaK7bp1oOrARucBivOJl7Fm3Qm0ZhmaTaZQ1RL0yyeKj/pz+U3tcyey76Va4s3b0Y/djlCytKnDhNNFwD7Uu65ZNZqwtN2oGstFMunIxPPeu4fDNH+4ubq1rFa8oAzp/ytN+qU2iqxPYM/dxDvf1aP3Nbc+5lzwjulO1hzlawAq7poKh/S3RPisQbbxkGn1O8dA5cFDWck9ZGl/LkIvrzfJfW8yxOpCzJQYdbWSuUxgquaU98yA9nfcPPc39t5qv7o52kYOihJRr3MMAWklZqo4PuO5QSXW3uxB6gCV5uZUO7W9vTxgEXXMGqr9r0ESdb4yKus607EjqWNA7QucYraIusGabZl2ufXHJdvo/nCmwxLTfAD3TnzCV9fZbXxbLcY4jS739W8hRD+53w/BcmrcvLne5eYg93rNT7lp/uhkDuR512aNnv/z3k2jC64iUseiE1FC3KN8J6wvp7MgnWO2GS7QRpqeBgb/lHG+gK2LBsUmOzgvX/pf616tQaIifauxacXvPO9m8Q3tsmARTQ45lelBZTqTnk30Q5izYWK2YZdGaVOuCoa4jDacnQK5WDNjSwa1l/CBIjZ5+JJ3QRw1VO++6tQd6sE4nnMJaRTy2LRBD0zJ7I8loNS4zvBCojOcjz6CqptZ54gYcpZOUyjMWb9o008uQLYCr8+Nu/It9ddizu+RWXQlTEA5lNyxG5s0srb58Mn57 05L4n3e5 gHbG9cfg1Xgxxua0iAUO775odW3VelYidLIBllmTFVY4JwE4mPhzAnWYtQ2CjwBwppohTr656oh1gUmZ7NhygNJ8qBK78Uch9TgIxOfotB8aS8xTBnPZBo18R7tqH10jpZchtNjDwzs72T5mQKd4f9BF019/Gx32C9a2j 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: List-Subscribe: List-Unsubscribe: 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 | 94 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 107 insertions(+), 4 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 049313871059..aef02c150f2c 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -618,11 +618,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 206acdde51f5..17c751aac854 100644 --- a/init/main.c +++ b/init/main.c @@ -212,8 +212,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); @@ -758,8 +765,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 9b68ddc4af5e..edb2575967ab 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -178,6 +178,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 */ @@ -595,6 +607,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, phys_addr_t end = base + memblock_cap_size(base, &size); int idx, nr_new, start_rgn = -1, end_rgn; struct memblock_region *rgn; + phys_addr_t new_size = 0; if (!size) return 0; @@ -607,7 +620,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; } /* @@ -654,6 +668,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, memblock_insert_region(type, idx++, base, rbase - base, nid, flags); + new_size += rbase - base; } } /* area below @rend is dealt with, forget about it */ @@ -669,6 +684,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, end_rgn = idx + 1; memblock_insert_region(type, idx, base, end - base, nid, flags); + new_size += end - base; } } @@ -687,8 +703,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, goto repeat; } else { memblock_merge_regions(type, start_rgn, end_rgn); - return 0; } +done: + if (new_size == size) + memblock_memsize_record_add(type, obase, size); + return 0; } /** @@ -858,6 +877,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; } @@ -2039,6 +2059,7 @@ struct memsize_rgn_struct { static struct memsize_rgn_struct memsize_rgn[CONFIG_MAX_MEMBLOCK_MEMSIZE] __initdata_memblock; static int memsize_rgn_count __initdata_memblock; +static const char *memblock_memsize_name __initdata_memblock; static void __init_memblock memsize_get_valid_name(char *valid_name, const char *name) { @@ -2237,6 +2258,75 @@ 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; + } + } +} + +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)