From patchwork Fri Jul 6 22:33: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: 10512601 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 38E1F60532 for ; Fri, 6 Jul 2018 22:34:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A39D28800 for ; Fri, 6 Jul 2018 22:34:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DFD828807; Fri, 6 Jul 2018 22:34:04 +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=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB14828800 for ; Fri, 6 Jul 2018 22:34:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2D496B0006; Fri, 6 Jul 2018 18:34:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BDC976B0007; Fri, 6 Jul 2018 18:34:02 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACCFD6B0008; Fri, 6 Jul 2018 18:34:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 6DD0B6B0006 for ; Fri, 6 Jul 2018 18:34:02 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id p91-v6so5429210plb.12 for ; Fri, 06 Jul 2018 15:34:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to; bh=qqgLxPT1915al8r4XBVPEzFy6EU/KU7aIIAThGxPrLA=; b=GN62IBx8g+Ybo09dwekb9ZpR5gnSMfiqkg1BRpAivaO19pBLOXm2+WIe1kGCnA3xlj hrweABSlX2wjtoA4VqBOnC68CprnRqZVUflg+OMj+mpBcekVHXL7WaPH83US3xE8CGvZ JTi59FbEtDniCPn/n0fMeBjWGCE5l2GAXHB/zLBaQ9WIHqTH4guwurm3uwkEYGgi9jqV ip4kT9PwetVKh9RzVF5nudrauR0gFvLyv9Zj4aA4hJGcy1OpY+d8cqGbiKziKgOA1XX/ JU2TEHk+dn3CjJKFb1gbZvWD0KgFlvvAWSm7Gag5zUQ1skL9N3oGVklz3aHLmD8CSGpR FNeA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of ross.zwisler@linux.intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=ross.zwisler@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APt69E2F4W8LqvH2TgY8ihfrBekdaanta0st2yH/Wmx6jBfAPjDjghY+ aIux4MG+c/y24RSA79rUzqexGfmin7Kcx8GI1GrONIWF8rOCFfWBEiI9JmSA0EAX+2wgK6qEazb H7q0tBlNJaTYAC/3QvgbzgfXitVHwqPg8mwiWT6Jd2dRhvypPr5Zt+xqGjvhLhyX8XQ== X-Received: by 2002:a17:902:a989:: with SMTP id bh9-v6mr12063433plb.245.1530916442117; Fri, 06 Jul 2018 15:34:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdBaojjzkSb4RGqNWL+mOrSBCWlFPENTzHCobqMgBsJzTAxM5INNpTax5CEi7M52+Idk6B1 X-Received: by 2002:a17:902:a989:: with SMTP id bh9-v6mr12063414plb.245.1530916441313; Fri, 06 Jul 2018 15:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530916441; cv=none; d=google.com; s=arc-20160816; b=t3wnLPvKlI1VTtxt+EzZKz//9XURwfMCgOcGZ17nrPs+jkhV5zCQd7ZaOwmkuSpo1r vyN8S72kwITJ5Ud37KgZGcJKZurIkVZGJ2tX4orx+wuBRcsNu1F5yP3z3bwrlMBlrW3G aQWXDfylYrJMj7Yp1XeIMBlQivx/n1UsqpHWC8iQeHx224RUDqlWBgSnE6rT1VQJsqa2 aZlP2zZ14CpbR5DqxBeQIzEHjQotCz029z/EYSerH+vDhNICjqNNPzAaeeAwznKJidH5 r5d6Dn60mUXPLGRwaF6+QbHC4prGzDqDkk7UAh1hbZFZx48i3iNRk2Ok3j7Qo4H7B8q6 nHlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=qqgLxPT1915al8r4XBVPEzFy6EU/KU7aIIAThGxPrLA=; b=Q9c7uSgFSkBYnFfsY7Jz6pZPSpAT0l7f7l8MiAnqZJJ353pldm/9kdF/PVEHE70ZjN VQrHB/Qj1atUGMW9/f49vXLwR2knXjacQbLubsYbfygPSG7GvQWfe7d8t0tNfVHrk7x/ AIYZ3XqMZQ+58stg++ugloZDqoz1nxrVNRrS3d2D6Ux+mD9jbqTI57O9GfAawd94oGRn ObwCa9TQ+3+okQXk+/aLyJr1Lsujux+iKJpXYfhVD8Irjf6VTXzfTGXlWNty4yhw6Fil W57elP33H/XG3nRrPAEH9kdpVFc4ewmEhuuR3C8T3k4ek3pKhBtrm7E8UMtp1qpBanGi jxNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of ross.zwisler@linux.intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=ross.zwisler@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga11.intel.com (mga11.intel.com. [192.55.52.93]) by mx.google.com with ESMTPS id r1-v6si10385563plj.474.2018.07.06.15.34.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jul 2018 15:34:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of ross.zwisler@linux.intel.com designates 192.55.52.93 as permitted sender) client-ip=192.55.52.93; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of ross.zwisler@linux.intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=ross.zwisler@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Oscar Salvador --- 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;