From patchwork Sat Jul 6 06:41:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junhua Huang X-Patchwork-Id: 11033561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4E7014C0 for ; Sat, 6 Jul 2019 06:47:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A97E828AD0 for ; Sat, 6 Jul 2019 06:47:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 991A828AD9; Sat, 6 Jul 2019 06:47:38 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F09EB28AD0 for ; Sat, 6 Jul 2019 06:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=HpPA0sz03Y9nB7V5Ek5DgHCeuxf9+VhD9muNwvJO85U=; b=inM KeKJ89zuBLNZPU9mCHBv/V8LI58vfgtY1/FCxobGBDPgl1DZIn6oLKsp4vloz7VhlT0Kiu7QsVPmg BgECtUulyjZy74R/OS2a40ZC1tdivpfHvvswqW+KeprWUhh2IwmelB7yK93lFYJygc4tTdJU/KQ99 C71i6lWKFnBKbe9wzu9jITIXo3dTPc+dN7zJVKxOdnLImEQ+acHppyl1/esty+V/3sIMiOFCBtYhJ N4u1Jwa1CNeYmpL04932c9u9fnMCMnNFj5UAg7726Dyjz4AB1FaykAlh3qunf/youZe9SL/yhgVal /8RIe4bnME09aYg2fdYoKuFQw1TT4Jw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hjeTu-0003h6-Tq; Sat, 06 Jul 2019 06:47:34 +0000 Received: from mxhk.zte.com.cn ([63.217.80.70]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hjeTr-0003fb-8C for linux-arm-kernel@lists.infradead.org; Sat, 06 Jul 2019 06:47:33 +0000 Received: from mse-fl2.zte.com.cn (unknown [10.30.14.239]) by Forcepoint Email with ESMTPS id 18AAF49C2BE7C4472856; Sat, 6 Jul 2019 14:47:10 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse-fl2.zte.com.cn with ESMTP id x666ko2S087166; Sat, 6 Jul 2019 14:46:50 +0800 (GMT-8) (envelope-from huang.junhua@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2019070614473487-2126688 ; Sat, 6 Jul 2019 14:47:34 +0800 From: Junhua Huang To: catalin.marinas@arm.com Subject: [PATCH v2] arm64: mm: free the initrd reserved memblock in a aligned manner Date: Sat, 6 Jul 2019 14:41:15 +0800 Message-Id: <1562395275-10772-1-git-send-email-huang.junhua@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2019-07-06 14:47:34, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-07-06 14:46:57, Serialize complete at 2019-07-06 14:46:57 X-MAIL: mse-fl2.zte.com.cn x666ko2S087166 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190705_234731_447856_41F0B103 X-CRM114-Status: GOOD ( 11.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wang.yi59@zte.com.cn, f.fainelli@gmail.com, jiang.xuexin@zte.com.cn, david@redhat.com, robin.murphy@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, rppt@linux.vnet.ibm.com, xue.zhihong@zte.com.cn, hannes@cmpxchg.org, Junhua Huang , akpm@linux-foundation.org, logang@deltatee.com, linux-arm-kernel@lists.infradead.org, ghackmann@android.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We should free the initrd reserved memblock in an aligned manner, because the initrd reserves the memblock in an aligned manner in arm64_memblock_init(). Otherwise there are some fragments in memblock_reserved regions after free_initrd_mem(). e.g.: /sys/kernel/debug/memblock # cat reserved 0: 0x0000000080080000..0x00000000817fafff 1: 0x0000000083400000..0x0000000083ffffff 2: 0x0000000090000000..0x000000009000407f 3: 0x00000000b0000000..0x00000000b000003f 4: 0x00000000b26184ea..0x00000000b2618fff The fragments like the ranges from b0000000 to b000003f and from b26184ea to b2618fff should be freed. And we can do free_reserved_area() after memblock_free(), as free_reserved_area() calls __free_pages(), once we've done that it could be allocated somewhere else, but memblock and iomem still say this is reserved memory. Signed-off-by: Junhua Huang --- v2: fix the start/end typo to free the same memory that we reserved and remove the blank line. arch/arm64/mm/init.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index d2adffb81b5d..2e9e42d06362 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -580,8 +580,12 @@ void free_initmem(void) #ifdef CONFIG_BLK_DEV_INITRD void __init free_initrd_mem(unsigned long start, unsigned long end) { + unsigned long aligned_start, aligned_end; + + aligned_start = __virt_to_phys(start) & PAGE_MASK; + aligned_end = PAGE_ALIGN(__virt_to_phys(end)); + memblock_free(aligned_start, aligned_end - aligned_start); free_reserved_area((void *)start, (void *)end, 0, "initrd"); - memblock_free(__virt_to_phys(start), end - start); } #endif