From patchwork Fri Jul 6 19:06:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 10512411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C6DBD60532 for ; Fri, 6 Jul 2018 19:07:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B24442876D for ; Fri, 6 Jul 2018 19:07:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6102287A0; Fri, 6 Jul 2018 19:07:21 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5B3A42876D for ; Fri, 6 Jul 2018 19:07:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3B99E2033736F; Fri, 6 Jul 2018 12:07:21 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: None (no SPF record) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=ross.zwisler@linux.intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 15D51202E53D8 for ; Fri, 6 Jul 2018 12:07:20 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2018 12:07:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,317,1526367600"; d="scan'208";a="62819344" Received: from theros.lm.intel.com ([10.232.112.164]) by FMSMGA003.fm.intel.com with ESMTP; 06 Jul 2018 12:07:07 -0700 From: Ross Zwisler To: pasha.tatashin@oracle.com, linux-nvdimm@lists.01.org Subject: [PATCH] mm/sparse.c: fix error path in sparse_add_one_section Date: Fri, 6 Jul 2018 13:06:58 -0600 Message-Id: <20180706190658.6873-1-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.14.4 in-reply-to: X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: osalvador@techadventures.net, bhe@redhat.com, Dave Hansen , LKML , Linux MM , Michal Hocko , "Kirill A. Shutemov" , Andrew Morton , Vlastimil Babka , osalvador@suse.de MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The following commit in -next: commit 054620849110 ("mm/sparse.c: make sparse_init_one_section void and remove check") changed how the error handling in sparse_add_one_section() works. Previously sparse_index_init() could return -EEXIST, and the function would continue on happily. 'ret' would get unconditionally overwritten by the result from sparse_init_one_section() and the error code after the 'out:' label wouldn't be triggered. With the above referenced commit, though, an -EEXIST error return from sparse_index_init() now takes us through the function and into the error case after 'out:'. This eventually causes a kernel BUG, probably because we've just freed a memory section that we successfully set up and marked as present: BUG: unable to handle kernel paging request at ffffea0005000080 RIP: 0010:memmap_init_zone+0x154/0x1cf Call Trace: move_pfn_range_to_zone+0x168/0x180 devm_memremap_pages+0x29b/0x480 pmem_attach_disk+0x1ae/0x6c0 [nd_pmem] ? devm_memremap+0x79/0xb0 nd_pmem_probe+0x7e/0xa0 [nd_pmem] nvdimm_bus_probe+0x6e/0x160 [libnvdimm] driver_probe_device+0x310/0x480 __device_attach_driver+0x86/0x100 ? __driver_attach+0x110/0x110 bus_for_each_drv+0x6e/0xb0 __device_attach+0xe2/0x160 device_initial_probe+0x13/0x20 bus_probe_device+0xa6/0xc0 device_add+0x41b/0x660 ? lock_acquire+0xa3/0x210 nd_async_device_register+0x12/0x40 [libnvdimm] async_run_entry_fn+0x3e/0x170 process_one_work+0x230/0x680 worker_thread+0x3f/0x3b0 kthread+0x12f/0x150 ? process_one_work+0x680/0x680 ? kthread_create_worker_on_cpu+0x70/0x70 ret_from_fork+0x3a/0x50 Fix this by clearing 'ret' back to 0 if sparse_index_init() returns -EEXIST. This restores the previous behavior. Signed-off-by: Ross Zwisler --- mm/sparse.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 9574113fc745..d254bd2d3289 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -753,8 +753,12 @@ int __meminit sparse_add_one_section(struct pglist_data *pgdat, * plus, it does a kmalloc */ ret = sparse_index_init(section_nr, pgdat->node_id); - if (ret < 0 && ret != -EEXIST) - return ret; + if (ret < 0) { + if (ret == -EEXIST) + ret = 0; + else + return ret; + } memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, altmap); if (!memmap) return -ENOMEM;