From patchwork Wed May 30 05:21:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 10437631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 367FF602BF for ; Wed, 30 May 2018 05:20:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BE2728842 for ; Wed, 30 May 2018 05:20:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F07628848; Wed, 30 May 2018 05:20:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31FB328842 for ; Wed, 30 May 2018 05:20:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD9A16B0007; Wed, 30 May 2018 01:20:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B88276B0008; Wed, 30 May 2018 01:20:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A76DD6B000A; Wed, 30 May 2018 01:20:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 671FF6B0007 for ; Wed, 30 May 2018 01:20:46 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id t17-v6so9312607ply.13 for ; Tue, 29 May 2018 22:20:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-filter:dkim-signature:from:to:cc:subject :date:message-id:cms-type:dlp-filter:references; bh=9v3qTLwbPQIELUA2DhZCxp+rtFm9Teddw8dG58+ObDM=; b=fEkC+1JgrpENy1UDxZmi9JHX5D0KKQs8PYpDdBtLiA7cCHiUvE+FKpQR9Z5Z31wrwQ z8azxeGCcMR8s/zUNtHal3n/dd6JXmKeEknIiBROzlsaoW0QM1LPGwXC2yEX5s6jU8jz 3dCbJn8mTWzgN1eCK3gXhmZIxx+kkoDdUuHw0DYlQioA5A5ay9QyeH3bCJ8QLfnphBEJ tK4whb2hj+gkS/Rd8xBxPspvnwSpyzzErXqqUSvrtKGr137UCQ+Pr/iEfpTFGym/Be0T 3bD/dx0IoMilTRQ3COqErLRWC3fB9kwkABdN2kH1CYDWTuDTvTLXDOkEzMYFlPG5ox0e 5UUA== X-Gm-Message-State: ALKqPwdTs1v5NjR3LnB7J22mOzrd/T9B8q9t6QIte+sCkyLkqkGIh/4b 4tpYcKbB/H/GYqet4bPYpivZ4HpK73MXaJQFRNFTGPYV0V1QhJbyAerxcei8zQ5Can0ZSj+PtLb xEcZCL4tkwdiISiZy6BzEuoNWf0VLdb+jqlbvvyyWY+z1b/OHSVBDWTFD7BfA4ryd4g== X-Received: by 2002:a17:902:b604:: with SMTP id b4-v6mr1415296pls.18.1527657646074; Tue, 29 May 2018 22:20:46 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLOru73sAWelIdd0+RlhDraPSXxCnCqI5x6/H70LH7i2g0c3gaBbRbj38pC2e+/Rl+hvOF5 X-Received: by 2002:a17:902:b604:: with SMTP id b4-v6mr1415254pls.18.1527657645268; Tue, 29 May 2018 22:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527657645; cv=none; d=google.com; s=arc-20160816; b=JuMLdEDrRUpJyGhC0WY+Vu/JZ6QMD/l1xvMGpPe9obloUXirpFEVWFloTw6/lb3Suo ufK5EoxNfZQCH+JaY1zjPK9RavvE4eeMpBgjChIQnONEP86jCNWrSWmsFRXZvUg/Cj9T bH8pcqyN5J6CqGmYsHRunqWS6lFjaktJ78PhgWwHaeaKIWXCzmMPAdjWhCY5r6uQTW0J NchrvDTTLef2NxL2NVvW9WHqgMAlJOt5qKGCGHjexFI7DiyaHlTAFAHfGGe8oLDWRRGl /8LAYeIywJsfOM0AROIAJME5yGxB+V14Z7lsQD7PwX3gw17GTjs1nAGVt1qkiArclTAI VYkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=9v3qTLwbPQIELUA2DhZCxp+rtFm9Teddw8dG58+ObDM=; b=Bwklr/OHziixj6ppTLwp4bY5qz0TH/HFaVNuvoo+JJnFG0+BZGylJC6XwCPwimimCv +FfavCyq2ZaWUpMk7ybv5SbG9S7BquIJohK+2PhvwezllKmHaexSN8CrOExgJEnUc60y PpZFr5BQM2nXGlX4+JkCMIQ78GCy3TNgDYoxXbFPoPPmHpr+4Ihh00e/zTjJQyF8TZj3 3UCu17vxS4TSm0AJIqzxdeARg0x1lAUnHm3BMHdTak062RSgxV4PEBJEPIviYisuTWcn b65EY0xPmZSC/7xsN/ZfxOEN7K5Wl3Rh6tDpRmwHaWuCSg70fgI3EN0vTGVkeFJGYNJg DoMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=ejOMfQF4; spf=pass (google.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from mailout2.samsung.com (mailout2.samsung.com. [203.254.224.25]) by mx.google.com with ESMTPS id k6-v6si26627010pgq.85.2018.05.29.22.20.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 22:20:45 -0700 (PDT) Received-SPF: pass (google.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) client-ip=203.254.224.25; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=ejOMfQF4; spf=pass (google.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com 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+ArltmDtBVSgpliTmlQKGAxOJiJX07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MnC4jNIqAq0f38C1g9r4CtRMuzBhaIbfISV371s0xg5FrAyLCKUTK1 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: 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: X-Virus-Scanned: ClamAV using ClamSMTP 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);