From patchwork Wed May 18 22:23:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 68063 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2886856qge; Wed, 18 May 2016 15:50:55 -0700 (PDT) X-Received: by 10.66.189.100 with SMTP id gh4mr3937218pac.133.1463611855564; Wed, 18 May 2016 15:50:55 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q81si14998003pfa.134.2016.05.18.15.50.55; Wed, 18 May 2016 15:50:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752076AbcERWux (ORCPT + 29 others); Wed, 18 May 2016 18:50:53 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:36425 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752009AbcERWuw (ORCPT ); Wed, 18 May 2016 18:50:52 -0400 Received: by mail-pf0-f175.google.com with SMTP id c189so23616500pfb.3 for ; Wed, 18 May 2016 15:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=ND96zYEZELuaf3A2WbyO7GPADAaB79Q5+8co9XYocIM=; b=Kq0W19YGgdN29BTZKs7MZWiZ8cPVe/j0Acqf7J4VQuVSBHgIhUMceCZY0+hVVL/fk9 RYClaQ12CyJXat9DPFTU7VvzyqZ9TcpXksEbImNWpDFAvZuN7E56ii/ywWCRSiMp/bJU Ryy/+678cvoPczPlBiVU5111oglUqexEaQdKA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ND96zYEZELuaf3A2WbyO7GPADAaB79Q5+8co9XYocIM=; b=k8LqWXgjTXcDcJqbcy5JrBStduW5dI12rjCOHIoiThjzD3UPcIDNtPpJ/q0vT29G8I RUe3WLJ5j0WNFbQ7quEnTch1oZ/f+bfE6/i6XCV7jzUUuAqQs2/U8QTkEoz5qyQWZcdf y7KAyNRGakDp8XWq+YHZ7Ngj/03zlwWWL1t0MTWE756P6nw65JHWz2t0rpu55AxoL6Ps zATkvJUIXS6CFTeq0N42PZzdaT/dMrRWVRQV+A6Eihtg3KM4njJJPCYmXeyQi1L1lQE5 rkyhS3RW7Zk0JuzuwulXKLAtgqZcItHjTqUOBV9Clqj54IdOmIMvqeioH3sCEnTyrq15 LhrA== X-Gm-Message-State: AOPr4FWddnb6tlC4ApEcdST+5j5Ueu+lCKJK3wp9SXJ8JJ8qnhhi1IpVjxp/RMesgI2RPBpN X-Received: by 10.98.18.195 with SMTP id 64mr14619840pfs.152.1463611851348; Wed, 18 May 2016 15:50:51 -0700 (PDT) Received: from yshi-Precision-T5600.corp.ad.wrs.com (unknown-216-82.windriver.com. [147.11.216.82]) by smtp.gmail.com with ESMTPSA id w187sm14635394pfw.50.2016.05.18.15.50.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 May 2016 15:50:50 -0700 (PDT) From: Yang Shi To: akpm@linux-foundation.org, iamjoonsoo.kim@lge.com Cc: vbabka@suse.cz, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linaro-kernel@lists.linaro.org, yang.shi@linaro.org Subject: [PATCH] mm: page_is_guard return false when page_ext arrays are not allocated yet Date: Wed, 18 May 2016 15:23:45 -0700 Message-Id: <1463610225-29060-1-git-send-email-yang.shi@linaro.org> X-Mailer: git-send-email 2.0.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When enabling the below kernel configs: CONFIG_DEFERRED_STRUCT_PAGE_INIT CONFIG_DEBUG_PAGEALLOC CONFIG_PAGE_EXTENSION CONFIG_DEBUG_VM kernel bootup may fail due to the following oops: BUG: unable to handle kernel NULL pointer dereference at (null) IP: [] free_pcppages_bulk+0x2d2/0x8d0 PGD 0 Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC Modules linked in: CPU: 11 PID: 106 Comm: pgdatinit1 Not tainted 4.6.0-rc5-next-20160427 #26 Hardware name: Intel Corporation S5520HC/S5520HC, BIOS S5500.86B.01.10.0025.030220091519 03/02/2009 task: ffff88017c080040 ti: ffff88017c084000 task.ti: ffff88017c084000 RIP: 0010:[] [] free_pcppages_bulk+0x2d2/0x8d0 RSP: 0000:ffff88017c087c48 EFLAGS: 00010046 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000001 RDX: 0000000000000980 RSI: 0000000000000080 RDI: 0000000000660401 RBP: ffff88017c087cd0 R08: 0000000000000401 R09: 0000000000000009 R10: ffff88017c080040 R11: 000000000000000a R12: 0000000000000400 R13: ffffea0019810000 R14: ffffea0019810040 R15: ffff88066cfe6080 FS: 0000000000000000(0000) GS:ffff88066cd40000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000000002406000 CR4: 00000000000006e0 Stack: ffff88066cd5bbd8 ffff88066cfe6640 0000000000000000 0000000000000000 0000001f0000001f ffff88066cd5bbe8 ffffea0019810000 000000008118f53e 0000000000000009 0000000000000401 ffffffff0000000a 0000000000000001 Call Trace: [] free_hot_cold_page+0x192/0x1d0 [] __free_pages+0x5c/0x90 [] __free_pages_boot_core+0x11a/0x14e [] deferred_free_range+0x50/0x62 [] deferred_init_memmap+0x220/0x3c3 [] ? setup_per_cpu_pageset+0x35/0x35 [] kthread+0xf8/0x110 [] ret_from_fork+0x22/0x40 [] ? kthread_create_on_node+0x200/0x200 Code: 49 89 d4 48 c1 e0 06 49 01 c5 e9 de fe ff ff 4c 89 f7 44 89 4d b8 4c 89 45 c0 44 89 5d c8 48 89 4d d0 e8 62 c7 07 00 48 8b 4d d0 <48> 8b 00 44 8b 5d c8 4c 8b 45 c0 44 8b 4d b8 a8 02 0f 84 05 ff RIP [] free_pcppages_bulk+0x2d2/0x8d0 RSP CR2: 0000000000000000 The problem is lookup_page_ext() returns NULL then page_is_guard() tried to access it in page freeing. page_is_guard() depends on PAGE_EXT_DEBUG_GUARD bit of page extension flag, but freeing page might reach here before the page_ext arrays are allocated when feeding a range of pages to the allocator for the first time during bootup or memory hotplug. When it returns NULL, page_is_guard() should just return false instead of checking PAGE_EXT_DEBUG_GUARD unconditionally. Signed-off-by: Yang Shi --- include/linux/mm.h | 3 +++ 1 file changed, 3 insertions(+) -- 2.0.2 diff --git a/include/linux/mm.h b/include/linux/mm.h index 727f7997..b1f2ad1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2409,6 +2409,9 @@ static inline bool page_is_guard(struct page *page) return false; page_ext = lookup_page_ext(page); + if (unlikely(!page_ext)) + return false; + return test_bit(PAGE_EXT_DEBUG_GUARD, &page_ext->flags); } #else