From patchwork Thu Oct 23 14:33:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 5141181 Return-Path: X-Original-To: patchwork-linux-arm@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 D4000C11AC for ; Thu, 23 Oct 2014 14:36:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0734A201F5 for ; Thu, 23 Oct 2014 14:36:30 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 25A0A20123 for ; Thu, 23 Oct 2014 14:36:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XhJTJ-0006Nj-Bx; Thu, 23 Oct 2014 14:34:37 +0000 Received: from galahad.ideasonboard.com ([2001:4b98:dc2:45:216:3eff:febb:480d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XhJT0-0005oF-7c for linux-arm-kernel@lists.infradead.org; Thu, 23 Oct 2014 14:34:19 +0000 Received: from avalon.ideasonboard.com (dsl-hkibrasgw3-50ddcc-40.dhcp.inet.fi [80.221.204.40]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id DD5AB223C6; Thu, 23 Oct 2014 16:31:54 +0200 (CEST) From: Laurent Pinchart To: linux-mm@kvack.org Subject: [PATCH 1/4] mm: cma: Don't crash on allocation if CMA area can't be activated Date: Thu, 23 Oct 2014 17:33:45 +0300 Message-Id: <1414074828-4488-2-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1414074828-4488-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> References: <1414074828-4488-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141023_073418_463036_3D72DBAF X-CRM114-Status: GOOD ( 12.41 ) X-Spam-Score: -1.4 (-) Cc: Russell King - ARM Linux , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Nazarewicz , Joonsoo Kim , linux-arm-kernel@lists.infradead.org, Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 If activation of the CMA area fails its mutex won't be initialized, leading to an oops at allocation time when trying to lock the mutex. Fix this by failing allocation if the area hasn't been successfully actived, and detect that condition by moving the CMA bitmap allocation after page block reservation completion. Signed-off-by: Laurent Pinchart Acked-by: Michal Nazarewicz --- mm/cma.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 963bc4a..16c6650 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -93,11 +93,6 @@ static int __init cma_activate_area(struct cma *cma) unsigned i = cma->count >> pageblock_order; struct zone *zone; - cma->bitmap = kzalloc(bitmap_size, GFP_KERNEL); - - if (!cma->bitmap) - return -ENOMEM; - WARN_ON_ONCE(!pfn_valid(pfn)); zone = page_zone(pfn_to_page(pfn)); @@ -114,17 +109,17 @@ static int __init cma_activate_area(struct cma *cma) * to be in the same zone. */ if (page_zone(pfn_to_page(pfn)) != zone) - goto err; + return -EINVAL; } init_cma_reserved_pageblock(pfn_to_page(base_pfn)); } while (--i); + cma->bitmap = kzalloc(bitmap_size, GFP_KERNEL); + if (!cma->bitmap) + return -ENOMEM; + mutex_init(&cma->lock); return 0; - -err: - kfree(cma->bitmap); - return -EINVAL; } static int __init cma_init_reserved_areas(void) @@ -313,7 +308,7 @@ struct page *cma_alloc(struct cma *cma, int count, unsigned int align) struct page *page = NULL; int ret; - if (!cma || !cma->count) + if (!cma || !cma->count || !cma->bitmap) return NULL; pr_debug("%s(cma %p, count %d, align %d)\n", __func__, (void *)cma,