From patchwork Thu Jun 19 19:53:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Nazarewicz?= X-Patchwork-Id: 4385941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 60E639F314 for ; Thu, 19 Jun 2014 20:06:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 790FE20398 for ; Thu, 19 Jun 2014 20:06:37 +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 A6CEF20397 for ; Thu, 19 Jun 2014 20:06:36 +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 1WxiPJ-0007H9-Ec; Thu, 19 Jun 2014 19:54:01 +0000 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WxiPG-0007EP-VB for linux-arm-kernel@lists.infradead.org; Thu, 19 Jun 2014 19:53:59 +0000 Received: by mail-wg0-f52.google.com with SMTP id b13so2776323wgh.35 for ; Thu, 19 Jun 2014 12:53:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:in-reply-to:organization:references :user-agent:face:date:message-id:mime-version:content-type :content-transfer-encoding; bh=yY+CsHXCYLAbrv69SHncVJtRgodmXQ427Zs3Eva5aOo=; b=XbUNxBy0MrkebSUPmGamIvKcCiD6Bs6bPKxAxtqYSmzpaf+xL/7g3hZ+uqVIdpxrDA dobg45Wmn1Ed2uKWOb3wDwb5o0hASVRssRVNUiuxyuFH6nrr94IW/s/omhzeAxfzsPzA q75kntNDqX1Iz+sbK35fTZjd1ydHe4Pe53Bo7zMlWHLeiRxFL5bRzPujyzaZka6zj3Fb ySnIpJG+7i5SvGlzw7+qL1BG05GDHkcucoFQ5QOPJc/X2i38zhWGpZpzamaK+j4bEp4J yNysUfpE4sGqKY625sE8tCGr19zLiAaPtE4hnNToxwDMLHyqEGgQYO8ELoVUNANTCVAY D9gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to :organization:references:user-agent:face:date:message-id :mime-version:content-type:content-transfer-encoding; bh=yY+CsHXCYLAbrv69SHncVJtRgodmXQ427Zs3Eva5aOo=; b=KYblTLK1LSTtbf2ca5xTM6IH95le3Rp6hgsANt57BEjQXOgYa0F2VjhGLYSw5g1T3+ rXxUjGimSxX09nbaUdkBjTu+eqAkfSkOB4vRt9hqZGZvX9UxLDX4Rbrxg63w5ujrtLNL N4m/FNciDHcTWaiQVyMxmIV40nrsa00MDMV9WXp6QnqQgfmxid4tJS0K6mMkLbyJ4QXJ RRjKd0Q2lidGr+Um5dBJ3cT5/2v9nQKgznkQa58Jvc7Jeulz1wvYPieRldzQ7uq1j+SR TM41HWk5YQkWBQ0einOLd28eAk5P/5ag5W6WneRBlQM8CXgOF8wSO3FkiTcm/91wXgv2 yyKA== X-Gm-Message-State: ALoCoQl3azxRW2q9h4PfEmAprhsVImfVEiN63e3W0xG+s42feJ4ZZ8ODsdOhJDqkly1GLTCN/78S X-Received: by 10.194.200.3 with SMTP id jo3mr7466641wjc.110.1403207615878; Thu, 19 Jun 2014 12:53:35 -0700 (PDT) Received: from mpn-glaptop.roam.corp.google.com ([2620:0:105f:311:d88e:fa65:d4e6:fd02]) by mx.google.com with ESMTPSA id do5sm36107568wib.16.2014.06.19.12.53.34 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 19 Jun 2014 12:53:34 -0700 (PDT) From: Michal Nazarewicz To: Mark Salter Subject: [PATCHv2] mm: page_alloc: fix CMA area initialisation when pageblock > MAX_ORDER In-Reply-To: <1403201524.32688.62.camel@deneb.redhat.com> Organization: http://mina86.com/ References: <1402522435-13884-1-git-send-email-msalter@redhat.com> <1403201524.32688.62.camel@deneb.redhat.com> User-Agent: Notmuch/0.17+15~gb65ca8e (http://notmuchmail.org) Emacs/24.4.50.1 (x86_64-unknown-linux-gnu) X-Face: PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd; KFrfMCylc}gc??'U2j,!8%xdD Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-Hashcash: 1:20:140619:m.szyprowski@samsung.com::9x3cCUuKFDY4+PP5:00000000000000000000000000000000000000kPT X-Hashcash: 1:20:140619:linux-kernel@vger.kernel.org::mEGSAGXVs+aawoCW:0000000000000000000000000000000000i81 X-Hashcash: 1:20:140619:rientjes@google.com::2MrabMs7O0RrnwiG:0000000000000000000000000000000000000000001a5g X-Hashcash: 1:20:140619:msalter@redhat.com::ZgEXdVvcIa/wSua3:00000000000000000000000000000000000000000002KZ7 X-Hashcash: 1:20:140619:catalin.marinas@arm.com::Fhj7HryT/UQBvFHr:000000000000000000000000000000000000005rF5 X-Hashcash: 1:20:140619:linux-arm-kernel@lists.infradead.org::wzwYyEHlQ/pvsZq3:00000000000000000000000005VVh Date: Thu, 19 Jun 2014 21:53:33 +0200 Message-ID: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140619_125359_163308_80C3C5BD X-CRM114-Status: GOOD ( 15.64 ) X-Spam-Score: -0.7 (/) Cc: Catalin Marinas , Marek Szyprowski , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, David Rientjes 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no 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 With a kernel configured with ARM64_64K_PAGES && !TRANSPARENT_HUGEPAGE, the following is triggered at early boot: SMP: Total of 8 processors activated. devtmpfs: initialized Unable to handle kernel NULL pointer dereference at virtual address 00000008 pgd = fffffe0000050000 [00000008] *pgd=00000043fba00003, *pmd=00000043fba00003, *pte=00e0000078010407 Internal error: Oops: 96000006 [#1] SMP Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.15.0-rc864k+ #44 task: fffffe03bc040000 ti: fffffe03bc080000 task.ti: fffffe03bc080000 PC is at __list_add+0x10/0xd4 LR is at free_one_page+0x270/0x638 ... Call trace: [] __list_add+0x10/0xd4 [] free_one_page+0x26c/0x638 [] __free_pages_ok.part.52+0x84/0xbc [] __free_pages+0x74/0xbc [] init_cma_reserved_pageblock+0xe8/0x104 [] cma_init_reserved_areas+0x190/0x1e4 [] do_one_initcall+0xc4/0x154 [] kernel_init_freeable+0x204/0x2a8 [] kernel_init+0xc/0xd4 This happens because init_cma_reserved_pageblock() calls __free_one_page() with pageblock_order as page order but it is bigger han MAX_ORDER. This in turn causes accesses past zone->free_list[]. Fix the problem by changing init_cma_reserved_pageblock() such that it splits pageblock into individual MAX_ORDER pages if pageblock is bigger than a MAX_ORDER page. In cases where !CONFIG_HUGETLB_PAGE_SIZE_VARIABLE, which is all architectures expect for ia64, powerpc and tile at the moment, the “pageblock_order > MAX_ORDER” condition will be optimised out since both sides of the operator are constants. In cases where pageblock size is variable, the performance degradation should not be significant anyway since init_cma_reserved_pageblock() is called only at boot time at most MAX_CMA_AREAS times which by default is eight. Signed-off-by: Michal Nazarewicz Reported-by: Mark Salter Tested-by: Christopher Covington --- mm/page_alloc.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7f97767..fe114db 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -817,7 +817,18 @@ void __init init_cma_reserved_pageblock(struct page *page) set_page_refcounted(page); set_pageblock_migratetype(page, MIGRATE_CMA); - __free_pages(page, pageblock_order); + + if (pageblock_order > MAX_ORDER) { + i = pageblock_order - MAX_ORDER; + i = 1 << i; + p = page; + do { + __free_pages(p, MAX_ORDER); + } while (p += MAX_ORDER_NR_PAGES, --i); + } else { + __free_pages(page, pageblock_order); + } + adjust_managed_page_count(page, pageblock_nr_pages); } #endif