From patchwork Thu Dec 4 12:03:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 5437841 Return-Path: X-Original-To: patchwork-linux-arm-msm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A3AB3BEEA8 for ; Thu, 4 Dec 2014 12:03:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD1782035C for ; Thu, 4 Dec 2014 12:03:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E6834201F2 for ; Thu, 4 Dec 2014 12:03:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932098AbaLDMDZ (ORCPT ); Thu, 4 Dec 2014 07:03:25 -0500 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:44662 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932099AbaLDMDV (ORCPT ); Thu, 4 Dec 2014 07:03:21 -0500 Received: from foss-smtp-na-1.foss.arm.com (unknown [10.80.61.8]) by foss-mx-na.foss.arm.com (Postfix) with ESMTP id EA38DEE; Thu, 4 Dec 2014 06:03:11 -0600 (CST) Received: from collaborate-mta1.arm.com (highbank-bc01-b06.austin.arm.com [10.112.81.134]) by foss-smtp-na-1.foss.arm.com (Postfix) with ESMTP id 685385FAD7; Thu, 4 Dec 2014 06:03:09 -0600 (CST) Received: from e104818-lin.cambridge.arm.com (e104818-lin.cambridge.arm.com [10.1.203.148]) by collaborate-mta1.arm.com (Postfix) with ESMTPS id 055F213F8B9; Thu, 4 Dec 2014 06:03:07 -0600 (CST) Date: Thu, 4 Dec 2014 12:03:05 +0000 From: Catalin Marinas To: Russell King - ARM Linux Cc: "Wang, Yalin" , "'linux-mm@kvack.org'" , Will Deacon , "'linux-kernel@vger.kernel.org'" , "'linux-arm-kernel@lists.infradead.org'" , "'linux-arm-msm@vger.kernel.org'" , Peter Maydell Subject: Re: [RFC v2] arm:extend the reserved mrmory for initrd to be page aligned Message-ID: <20141204120305.GC17783@e104818-lin.cambridge.arm.com> References: <35FD53F367049845BC99AC72306C23D103D6DB491609@CNBJMBX05.corpusers.net> <20140915113325.GD12361@n2100.arm.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140915113325.GD12361@n2100.arm.linux.org.uk> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Sep 15, 2014 at 12:33:25PM +0100, Russell King - ARM Linux wrote: > On Mon, Sep 15, 2014 at 07:07:20PM +0800, Wang, Yalin wrote: > > @@ -636,6 +646,11 @@ static int keep_initrd; > > void free_initrd_mem(unsigned long start, unsigned long end) > > { > > if (!keep_initrd) { > > + if (start == initrd_start) > > + start = round_down(start, PAGE_SIZE); > > + if (end == initrd_end) > > + end = round_up(end, PAGE_SIZE); > > + > > poison_init_mem((void *)start, PAGE_ALIGN(end) - start); > > free_reserved_area((void *)start, (void *)end, -1, "initrd"); > > } > > is the only bit of code you likely need to achieve your goal. > > Thinking about this, I think that you are quite right to align these. > The memory around the initrd is defined to be system memory, and we > already free the pages around it, so it *is* wrong not to free the > partial initrd pages. Actually, I think we have a problem, at least on arm64 (raised by Peter Maydell). There is no guarantee that the page around start/end of initrd is free, it may contain the dtb for example. This is even more obvious when we have a 64KB page kernel (the boot loader doesn't know the page size that the kernel is going to use). The bug was there before as we had poison_init_mem() already (not it disappeared since free_reserved_area does the poisoning). So as a quick fix I think we need the rounding the other way (and in the general case we probably lose a page at the end of initrd): A better fix would be to check what else is around the start/end of initrd. diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 494297c698ca..39fd080683e7 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -335,9 +335,9 @@ void free_initrd_mem(unsigned long start, unsigned long end) { if (!keep_initrd) { if (start == initrd_start) - start = round_down(start, PAGE_SIZE); + start = round_up(start, PAGE_SIZE); if (end == initrd_end) - end = round_up(end, PAGE_SIZE); + end = round_down(end, PAGE_SIZE); free_reserved_area((void *)start, (void *)end, 0, "initrd"); }