Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4107792imm; Tue, 29 May 2018 22:21:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ+nwPAjitbXi+CHL2nbBFJBba71MlY3HI5KqO9ZKdn/AMP/OlJBhFxkxAjEEV/nubIcQqE X-Received: by 2002:a65:4309:: with SMTP id j9-v6mr1017778pgq.375.1527657709745; Tue, 29 May 2018 22:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527657709; cv=none; d=google.com; s=arc-20160816; b=Ml7vBMMN1TgfXmOLdRkUrJx+nrBkry7Zs6ArdxKRHG/pv4jDudlAnASRsSfLS/9Xpz AlKVsxJgnsL9MNAORT0/OFRYGUvTKVMD027g5WLADwrZCshfvsMbkbEU3tYxnggkSc11 EvrIPPmInwUesl9tKJ54RnSmWma+uzVCVTVoNPErL3R84IV44aW0dSNk4XVcSaw4yGX+ r51qIu+KXa5Q6X6B3YRwVRKNONdp+0DYTo8pAOV6YYZYRWiRSqYE1YHe5uTn5I7kiWbH Xn5eDIV/gW0Ixe/O2Lmn87kDS3Zz1h0eFf8tpNKYwkvm9hSeIDDXuS26LRymx5N+OKaN 9J9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=9v3qTLwbPQIELUA2DhZCxp+rtFm9Teddw8dG58+ObDM=; b=Bw6/fAckTG91JgpgEg3+QSIvQfzHRIdXdct3CHZQN4ltd3h4g8Sqk1WgAItSiGbye4 s8mL33l/PiVkMw93wepJj7DxCMdZwKLZgtVpbBjXKzgelSC76eRmR5r0TzsWoh/JCv8w fhaeJS0AtIDGzNke398k61MbHdBDKBwapKLyubk6nyqVvnqzTGcLsrqtUpNfz2108LNk behSziC5Xnw7uCDo9ZZRJ8SNTMP5RNDE3e55HWhMnBW9YKPbL0VWwoh5vvX7RjZu59xO 1U1AqKWf7JpqTz2LgvDpmLXacRY49lEv0RQjRiykRsg7iThSOR8PftkSX2zVVO3pKx5E Qi3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=ejOMfQF4; 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=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12-v6si33878044pls.422.2018.05.29.22.21.35; Tue, 29 May 2018 22:21:49 -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=@samsung.com header.s=mail20170921 header.b=ejOMfQF4; 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=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755296AbeE3FUt (ORCPT + 99 others); Wed, 30 May 2018 01:20:49 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:57364 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751912AbeE3FUp (ORCPT ); Wed, 30 May 2018 01:20:45 -0400 Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20180530052043epoutp02b845fdd985403143f3a073ae206fd026~zVIhj2zZY2131021310epoutp02p; Wed, 30 May 2018 05:20:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20180530052043epoutp02b845fdd985403143f3a073ae206fd026~zVIhj2zZY2131021310epoutp02p DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1527657643; bh=9v3qTLwbPQIELUA2DhZCxp+rtFm9Teddw8dG58+ObDM=; h=From:To:Cc:Subject:Date:References:From; b=ejOMfQF4B6p1tlnAINt3xW1ibvOytGMu1+hOgheL46uD4f+NnFnvN1qYOLKwGik94 KP1j+SRnCx0o3bi5zO2XstGyPtQucjGpOI4D7pHuwP9RUep6IOSk2xRgOTEJYByAHQ liDFvT6+AD0EGb46Kd1W23sRTebkKAF49wPYv2XA= Received: from epsmges2p1.samsung.com (unknown [182.195.40.160]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20180530052042epcas1p301f43c4e1537a51ea62b9bffee148696~zVIgUC1GZ2746527465epcas1p3G; Wed, 30 May 2018 05:20:42 +0000 (GMT) Received: from epcas2p2.samsung.com ( [182.195.41.54]) by epsmges2p1.samsung.com (Symantec Messaging Gateway) with SMTP id 24.28.04217.9A43E0B5; Wed, 30 May 2018 14:20:41 +0900 (KST) Received: from epsmgms2p2new.samsung.com (unknown [182.195.42.143]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20180530052041epcas2p395f2fbf4506d911c127cc4243838fedb~zVIf80h_10287802878epcas2p31; Wed, 30 May 2018 05:20:41 +0000 (GMT) X-AuditID: b6c32a45-429ff70000001079-30-5b0e34a9bda2 Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 4F.15.04192.9A43E0B5; Wed, 30 May 2018 14:20:41 +0900 (KST) Received: from jaewon-linux.10.32.193.11 ([10.253.104.82]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P9J007E706FHD40@mmp1.samsung.com>; Wed, 30 May 2018 14:20:41 +0900 (KST) From: Jaewon Kim To: robh+dt@kernel.org, m.szyprowski@samsung.com, mitchelh@codeaurora.org Cc: frowand.list@gmail.com, devicetree@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, Jaewon Kim Subject: [PATCH] drivers: of: of_reserved_mem: detect count overflow or range overlap Date: Wed, 30 May 2018 14:21:42 +0900 Message-id: <20180530052142.24761-1-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.13.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrEKsWRmVeSWpSXmKPExsWy7bCmme5KE75og43/LSzmHznHajHzzX82 i+7NMxktet+/YrK4vGsOm8W9Nf9ZLdYeuctusXb+NjaL1r1H2B04PS739TJ57Jx1l91j06pO No9Nnyaxe/RtWcXo8XmTXABbVKpNRmpiSmqRQmpecn5KZl66rZJ3cLxzvKmZgaGuoaWFuZJC XmJuqq2Si0+ArltmDtBVSgpliTmlQKGAxOJiJX07m6L80pJUhYz84hJbpWhDQyM9QwNzPSMj IG0ea2VkClSSkJqxZO1n1oKJqhV7D31lbmCcLtvFyMkhIWAicf7jX7YuRi4OIYEdjBKNbQ/Z IZzvjBIfH3czw1QtvDKBBSKxm1Hi/sMGJgjnD5Bz6AhYFZuAtsT7BZNYQWwRAU+JpgPzmEGK mAVWM0qcvriUBSQhLBAuMfnFFHYQm0VAVaL7+RewBl4BW4mWZw0sEOvkJa786gdbJyHQwSZx /uQDVoiEi0THnEVQRcISr45vYYewpSWerdrICNHQzCjxduZmKKeFUeLupl5GiCpjid6eC2C3 MgvwSXQc/gvUzQEU55XoaBOCKPGQ2NH0DmyBkECsxK/D29kmMEosYGRYxSiWWlCcm55abFRg qFecmFtcmpeul5yfu4kRnD60XHcwzjjnc4hRgINRiYe3I4o3Wog1say4MvcQowQHs5IIb+le nmgh3pTEyqrUovz4otKc1OJDjKbAQJjILCWanA9MbXkl8YamRsbGxhZmRsaGJsZK4rw3zf5F CQmkJ5akZqemFqQWwfQxcXBKNTCu3Xe8mk83PUXVpWXtnZxWpanJ82ZE7m5QezqHK0b8c8zx tmvVQoFVb3wW+jFcU0tXORH5Yl+LkkbJoc697KsZv7w/KXA8rbSTVelYoPLbYxfe9a+d9UnQ cqfwKmGl+LNhFg82cSwvb996eHPl5NXMU1Jnzbt17vW32O4tPw9suqfKU5RyNO6LEktxRqKh FnNRcSIAD019xDUDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmluLIzCtJLcpLzFFi42I5/e+xgO5KE75og13NKhbzj5xjtZj55j+b RffmmYwWve9fMVlc3jWHzeLemv+sFmuP3GW3WDt/G5tF694j7A6cHpf7epk8ds66y+6xaVUn m8emT5PYPfq2rGL0+LxJLoAtissmJTUnsyy1SN8ugStjydrPrAUTVSv2HvrK3MA4XbaLkZND QsBEYuGVCSxdjFwcQgI7GSXWtayAcv4wSjTvWsgEUsUmoC3xfsEkVhBbRMBTounAPGYQm1lg NaPEz24tEFtYIFxiXkMnC4jNIqAq0f38C1g9r4CtRMuzBhaIbfISV371s0xg5FrAyLCKUTK1 oDg3PbfYqMAoL7Vcrzgxt7g0L10vOT93EyMwaLYd1urfwfh4SfwhRgEORiUeXoMI3mgh1sSy 4srcQ4wSHMxKIryle3mihXhTEiurUovy44tKc1KLDzFKc7AoifPy5x+LFBJITyxJzU5NLUgt gskycXBKNTDO2yDqxqx461zd13NzguTWCn/aa8ylOLvknqjyH6F/JicPHkxRl5YIXSV0TEKr 3efjPId+Hqe2RXs1lepjvMPEUz6uXmbhrzQx2D1j78nJTPf03FnPH+1g/p7Y+Yb1xqvqD1l7 zux58lTE+Pkhw7vqn0XEua5c333e73S2bdqmZwE71B8+fn9diaU4I9FQi7moOBEAayzyDxYC AAA= X-CMS-MailID: 20180530052041epcas2p395f2fbf4506d911c127cc4243838fedb X-Msg-Generator: CA CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20180530052041epcas2p395f2fbf4506d911c127cc4243838fedb References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During development, number of reserved memory region could be increased and a new region could be unwantedly overlapped. In that case the new region may work well but one of exisiting region could be affected so that it would not be defined properly. It may require time consuming work to find reason that there is a newly added region. If a newly added region invoke kernel panic, it will be helpful. This patch records if there is count overflow or range overlap, and invoke panic if that case. These are test example based on v4.9. Case 1 - out of region count <3>[ 0.000000] [0: swapper: 0] OF: reserved mem: not enough space all defined regions. <0>[ 1.688695] [6: swapper/0: 1] Kernel panic - not syncing: overflow on reserved memory, check the latest change <4>[ 1.688743] [6: swapper/0: 1] CPU: 6 PID: 1 Comm: swapper/0 Not tainted 4.9.65+ #10 <4>[ 1.688836] [6: swapper/0: 1] Call trace: <4>[ 1.688869] [6: swapper/0: 1] [] dump_backtrace+0x0/0x248 <4>[ 1.688913] [6: swapper/0: 1] [] show_stack+0x18/0x28 <4>[ 1.688958] [6: swapper/0: 1] [] dump_stack+0x98/0xc0 <4>[ 1.689001] [6: swapper/0: 1] [] panic+0x1e0/0x404 <4>[ 1.689046] [6: swapper/0: 1] [] check_reserved_mem+0x40/0x50 <4>[ 1.689091] [6: swapper/0: 1] [] do_one_initcall+0x54/0x214 <4>[ 1.689138] [6: swapper/0: 1] [] kernel_init_freeable+0x198/0x24c <4>[ 1.689187] [6: swapper/0: 1] [] kernel_init+0x18/0x144 <4>[ 1.689229] [6: swapper/0: 1] [] ret_from_fork+0x10/0x40 Case 2 - overlapped region <3>[ 0.000000] [0: swapper: 0] OF: reserved mem: OVERLAP DETECTED! <0>[ 2.309331] [2: swapper/0: 1] Kernel panic - not syncing: reserved memory overlap, check the latest change <4>[ 2.309398] [2: swapper/0: 1] CPU: 2 PID: 1 Comm: swapper/0 Not tainted 4.9.65+ #14 <4>[ 2.309508] [2: swapper/0: 1] Call trace: <4>[ 2.309546] [2: swapper/0: 1] [] dump_backtrace+0x0/0x248 <4>[ 2.309599] [2: swapper/0: 1] [] show_stack+0x18/0x28 <4>[ 2.309652] [2: swapper/0: 1] [] dump_stack+0x98/0xc0 <4>[ 2.309701] [2: swapper/0: 1] [] panic+0x1e0/0x404 <4>[ 2.309751] [2: swapper/0: 1] [] check_reserved_mem+0x4c/0x50 <4>[ 2.309802] [2: swapper/0: 1] [] do_one_initcall+0x54/0x214 <4>[ 2.309856] [2: swapper/0: 1] [] kernel_init_freeable+0x198/0x24c <4>[ 2.309913] [2: swapper/0: 1] [] kernel_init+0x18/0x144 <4>[ 2.309961] [2: swapper/0: 1] [] ret_from_fork+0x10/0x40 Signed-off-by: Jaewon Kim --- drivers/of/of_reserved_mem.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 9a4f4246231d..e97d5c5dcc9a 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -65,6 +65,7 @@ int __init __weak early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, } #endif +static bool rmem_overflow; /** * res_mem_save_node() - save fdt node for second pass initialization */ @@ -75,6 +76,7 @@ void __init fdt_reserved_mem_save_node(unsigned long node, const char *uname, if (reserved_mem_count == ARRAY_SIZE(reserved_mem)) { pr_err("not enough space all defined regions.\n"); + rmem_overflow = true; return; } @@ -221,6 +223,7 @@ static int __init __rmem_cmp(const void *a, const void *b) return 0; } +static bool rmem_overlap; static void __init __rmem_check_for_overlap(void) { int i; @@ -245,6 +248,7 @@ static void __init __rmem_check_for_overlap(void) pr_err("OVERLAP DETECTED!\n%s (%pa--%pa) overlaps with %s (%pa--%pa)\n", this->name, &this->base, &this_end, next->name, &next->base, &next_end); + rmem_overlap = true; } } } @@ -419,3 +423,13 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) return NULL; } EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); + +static int check_reserved_mem(void) +{ + if (rmem_overflow) + panic("overflow on reserved memory, check the latest change"); + if (rmem_overlap) + panic("overlap on reserved memory, check the latest change"); + return 0; +} +late_initcall(check_reserved_mem); -- 2.13.0