Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp128245imm; Fri, 6 Jul 2018 15:35:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcc3udOjIS/YWcbL/vBSfEKUFFu2Tf18LcKIUptjsbj2dIhVRSQ+Hy7eJvrXbOfnhgpICa1 X-Received: by 2002:a63:5660:: with SMTP id g32-v6mr11033135pgm.227.1530916517338; Fri, 06 Jul 2018 15:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530916517; cv=none; d=google.com; s=arc-20160816; b=gNK0bLyScdiwKehj5yiUPcSoevQXlU3AcDCZaf5Llt8MHqyGJOEg6R1TsPLqGlLoin kHTSWOUX2fqS+PoCN90iXGBcc9KSVjkuQbXPB2IS5UiUtB3F9EQOG1iu/3bwk6T0w9tk EEBC1PpOQe115RS1vUlYh94ZqiDXkqNjj8AOLE9WCaofufTX/9qg9CeATFI3bU8oPmky pGUKZe43ygRpt5IX7zgw6+U0lk644B0fw4i1lCGSEPZjFBq5tGTnhlJz+oCi6uF7N67Z hYokJikp9arDN8+kFWaAGJNsyFCla3Rh5liUTzZl5iLeW8tBjqYLdX0OAqn2bxv1+Tha jhjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:message-id:date:subject:cc:to :from:arc-authentication-results; bh=qqgLxPT1915al8r4XBVPEzFy6EU/KU7aIIAThGxPrLA=; b=SRzO+cx8Xu44n/uHTwWpaCk0BzboCLbsLGcqzndBwjAZmSFMWRZs5BvW5u00tlXJIu /jQ0rDXV4/Yg2110Yf5d6Y7mn/O5fcB4wgu3OJPLmpYcfcazm8XTMM6XoRpTFAi7uQS1 +S+9E/bVP1Sb3FaWhWEwz3eHIexn1Pvg9cT1hDv0ln666zlaxYeP8QZjcR1RdOd7XA+V Kr4x+RhjzX2heZX351dzHx6XVsCLshiJDJjcH5jDTmsoZ7XI5x1+VcOozXL3DviovYc1 VFhIaSEdayJL0VFnCr08YEm+KSS7T45oy1dk0M0USmz+bULW1sD2eWGJ8PlkYbPTKwuj ASrA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j85-v6si10074698pfa.232.2018.07.06.15.35.03; Fri, 06 Jul 2018 15:35:17 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754415AbeGFWeO (ORCPT + 99 others); Fri, 6 Jul 2018 18:34:14 -0400 Received: from mga12.intel.com ([192.55.52.136]:2114 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754150AbeGFWeB (ORCPT ); Fri, 6 Jul 2018 18:34:01 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2018 15:34:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,318,1526367600"; d="scan'208";a="64834531" Received: from theros.lm.intel.com ([10.232.112.164]) by fmsmga002.fm.intel.com with ESMTP; 06 Jul 2018 15:34:00 -0700 From: Ross Zwisler To: pasha.tatashin@oracle.com, linux-nvdimm@lists.01.org Cc: Ross Zwisler , osalvador@techadventures.net, bhe@redhat.com, Dave Hansen , LKML , Linux MM , Michal Hocko , Vlastimil Babka , Andrew Morton , "Kirill A. Shutemov" , osalvador@suse.de Subject: [PATCH v2] mm/sparse.c: fix error path in sparse_add_one_section Date: Fri, 6 Jul 2018 16:33:58 -0600 Message-Id: <20180706223358.742-1-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.14.4 in-reply-to: <20180706190658.6873-1-ross.zwisler@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/sparse.c b/mm/sparse.c index f55e79fda03e..eb188eb6b82d 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -770,6 +770,7 @@ int __meminit sparse_add_one_section(struct pglist_data *pgdat, ret = sparse_index_init(section_nr, pgdat->node_id); if (ret < 0 && ret != -EEXIST) return ret; + ret = 0; memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, altmap); if (!memmap) return -ENOMEM; -- 2.14.4