From patchwork Tue May 21 02:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668808 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 71C6EC25B77 for ; Tue, 21 May 2024 02:40:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6024A6B0099; Mon, 20 May 2024 22:40:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BA436B009A; 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 6BB6C6B0083; 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 164546B008A for ; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BD971140B57 for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.28.06FF18C Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf30.hostedemail.com (Postfix) with ESMTP id 092F480002 for ; Tue, 21 May 2024 02:40:12 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=GmWAPwUP; spf=pass (imf30.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=1716259213; 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=nc9ytWVtzu00a7dgwLwPEFskmN2vz5dkqC+Zm4IulfA=; b=vASfV4y3aNxHTU7vykjoQsRjXGhBCG+IINES2+p+RLyo/IHFTqx16cppFVO6GlCFGP6ho2 ZaiWbdo1PwAxcMUrntBJOPzOzDjm31bJZS3M8hK9JgXsDTkpvJ+lgXWbEy5d6jujz1lPRi S/SudurDupbxE45FQp6THP1IYM1wzHg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=GmWAPwUP; spf=pass (imf30.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=1716259213; a=rsa-sha256; cv=none; b=UpRADwbnCimcZBsPEeIUzhD3wzUUPXkPdBmVlLEDRyjZk1PDVAEoco7dkaLUPaNzUr+wvm rtJ97EZjIkOnIzkE61M+a1IB073lFVIurhWemJyZtajJNvMQ+zZDIRe1Eau6aEmOtYrslw fa3J7aRw7YwLeOyuRGPbvPmLAo6B4ZE= Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp02ca1e3adc80fe4c0a51aa3c069ad9784d~RYKiWilNw0459104591epoutp021 for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20240521024010epoutp02ca1e3adc80fe4c0a51aa3c069ad9784d~RYKiWilNw0459104591epoutp021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=nc9ytWVtzu00a7dgwLwPEFskmN2vz5dkqC+Zm4IulfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GmWAPwUPJUumyIommwOd368ltzs6tEpcbknX9PM8XQAOHVWnJkt6n3/awC1sZxKBa uGIaHt3eL9jlpIWjc6TSETkoLd7hclQ6Dg8YZGcjFIon6PKX0EQE4AFBJAVEKG5jiw ULJWvMF7TcBLXhF/SoCUZfbXqqCmXcehj5Ly0Mgk= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20240521024009epcas1p4ae0afa00bd066e0581c51603cd14c1c5~RYKiDy1mA1450914509epcas1p4D; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.38.250]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4VjzDn3Btwz4x9Q0; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id BE.4F.09662.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p152671a613e86fa83d840962ee3db50fb~RYKhZLuN42349123491epcas1p1a; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp2ab32c1df17e1b63fac42592843b39454~RYKhYk-MV2496124961epsmtrp2p; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a35-2b3fa700000025be-a8-664c0989734b Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id E5.D3.19234.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 20240521024009epsmtip23fed4a67c5d9cdc27984091a265bcdeb~RYKhPg7O11233912339epsmtip2C; 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 03/10] memblock: handle overlapped reserved memory region Date: Tue, 21 May 2024 11:39:50 +0900 Message-Id: <20240521023957.2587005-4-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+NgFmpmk+LIzCtJLcpLzFFi42LZdlhTV7eT0yfN4HmvhMWc9WvYLLo3z2S0 6H3/isni8q45bBb31vxntTiyfjuTxezGPkYHdo+ds+6ye2xa1cnmsenTJHaPEzN+s3j0bVnF 6HFmwRF2j8+b5ALYo7JtMlITU1KLFFLzkvNTMvPSbZW8g+Od403NDAx1DS0tzJUU8hJzU22V XHwCdN0yc4AOUlIoS8wpBQoFJBYXK+nb2RTll5akKmTkF5fYKqUWpOQUmBXoFSfmFpfmpevl pZZYGRoYGJkCFSZkZzyY84WpoFeh4sW2sAbG55JdjJwcEgImEjN3HGHtYuTiEBLYwSjx4sl/ NgjnE6PEo+NtCM7rMysZYVomNd9lB7GFBHYyStx+zd3FyAFkf2aUWGoMEmYT0JZ4v2ASK4gt ImAn8W32ATCbWaBU4u2bE8wg5cICQRKH9oBNYRFQlfi+8T4TiM0rYC9xtfcuG8QmeYmZl76D 1XAKOEjMn7KYHaJGUOLkzCcsECPlJZq3zmaGqP/ILrF9nhTIeAkBF4l1280hwsISr45vYYew pSQ+v9sLNT5f4sLFV0wQ5TUSCycaQoTtJXZ9ncEKEmYW0JRYv0sfYhGfxLuvPawQ1bwSHW1C ENVqEi3PvrJC2DISf/89g7I9JI509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bP1fvUOMTByMhxglOJiVRHg3bfFME+JNSays Si3Kjy8qzUktPsQozcGiJM6rnNOZIiSQnliSmp2aWpBaBJNl4uCUamAKePXBZLr5XaOJP65O DdVXCF/E0SCz/NK9Jf4Oxxmu3p5cJvUy6C2n4+G8qnlXWttbJm3cGsUsUVaTYbDwqZ5Q+qSc OSLzWOqi5PPyivt+e9op3dyn9Fi/ek/z19cmVtM+ZK5pX83Gruev3mArt9yp9lFq+PzXzwyL TxnfXfpWTe7t5ofFdue/n5zxyOftyuK6NzyTXU+sd0p6tnt1qcrnBXOFlnBHHznIvGKxnrq9 Hpf4lb6nKaZfSyLFppVN+X09nlc9YcbBp43HXG9u0og2DGbleNDHZZ9/90vtGc9/OXZ2bLXq zE38G5n3cakrc4lEblo549YGl99KewJ/um/sZz2lecen5qaT+LWVNvFKLMUZiYZazEXFiQA4 nBKK3gIAAA== X-CMS-MailID: 20240521024009epcas1p152671a613e86fa83d840962ee3db50fb X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p152671a613e86fa83d840962ee3db50fb References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Stat-Signature: sxsgrxfkg6xxufsaabd37789zzew3psr X-Rspamd-Queue-Id: 092F480002 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1716259212-848889 X-HE-Meta: U2FsdGVkX19r0pnSiCWHRP3+fJ6uxHPvNdUqiNsj4QyuLxrkeeu7onHuU7cXU1+mEOC4FgdkktBLWnUHywb7ap/lHdRWwyAQnY+WrwfBBs/Ke2WLs66bPIsjuqjnhVWgzAxVtmtCDw14mwweGRBhF5XXdog0fkNEmUXGO9gYT1B1XKhomXkSEuwi5XgOHcVsQq96zZadDIihRt3u8XQ//TNr3B9Z0xnfX8hK/hxRCxpUV6KSoXjtOVImyJ8XH0MhgJ0jcLGkT5gzbT0Bum0LBgwKrpGd7US5kK1e7c5NpWMxxAYlaQmU0myl+l2AopQqdEdxc5tdCYbk6MOT+s3enofNMsz/Qd8nQjP8v2xEmXtwUnTa539NVvTZ17SDNcAXT2GEwegEmTT67HpmObpKKAUulLpj0ubNU/y8duXlq6K6peYcMBGWH1XS87ylV+FkwT58SG46ZK+2VifS4qs6QUyTWCosIWF82T1m/V1uZWC5fL1gNK/ZrmYvLhMbKU73h3j5ZXEXoiyIEllSwPvxONoDZG/55KHUstLETnxlcB3mmBpWUC1ZbrjD0YQW6G1KLma+TTtDct43HCbJnECKISReCr0s0B/WRAngSJwpeET3R9W31oeFOr2C4v9/tJK36VJhAbWEE7E/aZyb+zkBZ9CXoWvw77cG3JaA6eqZ861bioI4kPx4+F12PtUI4BFd9Gr/H7hI1Xd6kPjEaxwqm5PQT/1hWF88LB10o1mJlCB0+Hhbx0tfrtazycQAA25i7/yAaM5q+icNdor3MCRidGgLuKAijg358iRgq5vqPA9Zbnlr1J5yvP7z1NAXED43cpLJUOyqhqQjf7be3qufvBU9OwUbd0/TOtq3AfgjdLaY5UScLJUOWoFdqW/06GzjWf9v3Ly7cmbzm51FYPDfgiwmV2jL8IUxMb2S1kvbHQqgqW4mqje+Y9dxWvmb2CFsEkqVNnH0wL6/N8+XBjR dJMz+J9z 3N5X9TDHa9f5k4phe/DAZccPWSUza6uQbVyfq/Al6KbgMtzIBDYSyZBfPxHZxKvtipdcidw2Blje8mjADiBa6RJBXcqvnY+O3HXqp48Vo4UyHOalaHOnVslIAc02KPM2pzPHq40drp1RZ0TtA9/TXLvmjDMUNb1d+l/XR 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: It is not common, but defining an overlapped region is possible. Actually memblock_add_range allows to overlap with existing ones. The memsize currently does not handle this overlapped case. But this patch tries to handle one overlapped case. Here's the case. There is an unknown memsize region, which means the region was removed and not passed at bootloader stage. And there is a reserved memory region defined in device tree which is overlapped with the unknown region. We expect that information in device tree make the unknown region clear. This patch handle the overlapped region with following conditions. 1) The already existing overlapped region should be unknown and no-map. 2) The newly added region should have a name, and its region should be same with or part of the existing one. Here is an example. Before this patch, memsize shows both overlapped region. 0x0ea000000-0x0ed900000 0x03900000 ( 58368 KB ) nomap unusable overlapped 0x0ea000000-0x0f1400000 0x07400000 ( 118784 KB ) nomap unusable unknown After this patch, the overlapped region is named. 0x0ea000000-0x0ed900000 0x03900000 ( 58368 KB ) nomap unusable overlapped 0x0e9b00000-0x0ea000000 0x00500000 ( 5120 KB ) nomap unusable unknown Signed-off-by: Jaewon Kim --- mm/memblock.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/mm/memblock.c b/mm/memblock.c index 5204ee71ae29..4a0506e14025 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2060,6 +2060,73 @@ static void __init_memblock memsize_get_valid_name(char *valid_name, const char valid_name[val_size] = '\0'; } +static inline struct memsize_rgn_struct * __init_memblock memsize_get_new_rgn(void) +{ + if (memsize_rgn_count == ARRAY_SIZE(memsize_rgn)) { + pr_err("not enough space on memsize_rgn\n"); + return NULL; + } + return &memsize_rgn[memsize_rgn_count++]; +} + +static bool __init_memblock memsize_update_nomap_region(const char *name, phys_addr_t base, + phys_addr_t size, bool nomap) +{ + int i; + struct memsize_rgn_struct *rmem_rgn, *new_rgn; + + if (!name) + return false; + + for (i = 0; i < memsize_rgn_count; i++) { + rmem_rgn = &memsize_rgn[i]; + + if (!rmem_rgn->nomap) + continue; + if (strcmp(rmem_rgn->name, "unknown")) + continue; + if (base < rmem_rgn->base) + continue; + if (base + size > rmem_rgn->base + rmem_rgn->size) + continue; + + if (base == rmem_rgn->base && size == rmem_rgn->size) { + memsize_get_valid_name(rmem_rgn->name, name); + return true; + } + + new_rgn = memsize_get_new_rgn(); + if (!new_rgn) + return true; + new_rgn->base = base; + new_rgn->size = size; + new_rgn->nomap = nomap; + new_rgn->reusable = false; + memsize_get_valid_name(new_rgn->name, name); + + if (base == rmem_rgn->base && size < rmem_rgn->size) { + rmem_rgn->base = base + size; + rmem_rgn->size -= size; + } else if (base + size == rmem_rgn->base + rmem_rgn->size) { + rmem_rgn->size -= size; + } else { + new_rgn = memsize_get_new_rgn(); + if (!new_rgn) + return true; + new_rgn->base = base + size; + new_rgn->size = (rmem_rgn->base + rmem_rgn->size) + - (base + size); + new_rgn->nomap = nomap; + new_rgn->reusable = false; + strscpy(new_rgn->name, "unknown", sizeof(new_rgn->name)); + rmem_rgn->size = base - rmem_rgn->base; + } + return true; + } + + return false; +} + void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable) { @@ -2070,7 +2137,14 @@ void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base, pr_err("not enough space on memsize_rgn\n"); return; } - rgn = &memsize_rgn[memsize_rgn_count++]; + + if (memsize_update_nomap_region(name, base, size, nomap)) + return; + + rgn = memsize_get_new_rgn(); + if (!rgn) + return; + rgn->base = base; rgn->size = size; rgn->nomap = nomap;