Received: by 10.223.185.116 with SMTP id b49csp3508124wrg; Mon, 26 Feb 2018 00:52:27 -0800 (PST) X-Google-Smtp-Source: AH8x224zShdz5UKc8k/RXQN/aL9f1CfF7oofypdIyS4fE2qVUDLL1adTLu1Dv8eqNpw6R3ko0scC X-Received: by 10.98.48.2 with SMTP id w2mr9824048pfw.162.1519635146945; Mon, 26 Feb 2018 00:52:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519635146; cv=none; d=google.com; s=arc-20160816; b=PmwiL+d+K08VlIuFZSr3anjWfX7bEwZChth8pljy8ZqXl8EvIyp5vd9QKRwH07BPfT NzWrK3JVkmXixMWUvlpSsZQ7TX/HVJYB7qSKRrt5fozb7o7d3dx2WNIxq8f6aUT1mh+G cFGELjZcL2Vqj3WA3fAIbhFeeTWDX1PvayH4fl0HssBDHSqI90/qNbLVDLeqyfNtAPK6 I58UWl9UtmMmHfOT87raNPe3r2z8pWDiosGXBL7ufxjMWW9jicER/2S6fPTZhAIExKUm SKrBfHRuqnJyRomEj1zNgW+wKhKOYC5X3o6rUUKdTFMRYzhXBRAfb49+41bDEPtt/92b DjYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Q8oRa3pMk77oMmm/HFmj0dClNd11dTn6bUo7atxsfXs=; b=mrPBsBO5gYJoaMyWa7WXRjSGxkG2dC/HQcM/ALgMIDC03hKMCiD+/KYLv3qcLwsmD1 26w//UxXu399EYn9bzpuzc7F0bVZeFLug+qrAd5XFZDAG4eCT8xIWtjqzvCqd3mUFRQi ZafbcGYHDXlzqgbYT+Vaw7KqfqfPsKXZ1ftRwWKKs/aJmQxZOck0pZl1VYo3Q8xdnJQT 7k9ji2fi1ZOaQcEdqFdkQv8bOq6DCXCbCA8lBKeF5MinsPa4JcT0Z/eH3h01Z3ziLLjx 2Kzy6e7k3UUytddt17GKUNiy0Q4i8kIs/mtIZY1MF3V6ezZ4AAx3h+l8v3DtPj00Tz8Q FdWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dGwaf91y; 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 sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5-v6si6413097plh.135.2018.02.26.00.52.12; Mon, 26 Feb 2018 00:52:26 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=dGwaf91y; 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 sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbeBZIvh (ORCPT + 99 others); Mon, 26 Feb 2018 03:51:37 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36959 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751396AbeBZIvf (ORCPT ); Mon, 26 Feb 2018 03:51:35 -0500 Received: by mail-pg0-f66.google.com with SMTP id y26so5932625pgv.4 for ; Mon, 26 Feb 2018 00:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Q8oRa3pMk77oMmm/HFmj0dClNd11dTn6bUo7atxsfXs=; b=dGwaf91ysXh67UwtWXzrP36iq2dZBsTe7J7a42LB/lv9kBjteYYQqKek4oCgWyJIAU xAxj4aedm4jPfvx/jlLFBb1Jr6eCISoaCnviIROjZpRhc+orj/Gp0aDs1CEXrcR36Slz sTt0GJALA51x8x+yvzIgzRBobBWBJWDGKzqkCfa2yEd3wVqJsZvDW63bNaSSxCIFZIGP dc+bQiw6uxwGUHr0n3ZvLTuCgs3j59DkOedwsAfnxj52/VvovXrsVYACr0QOAp87B4eP 06oV9/U0XoBfIl99uqWYvl6Y+BElGIaxeqxV/WN06SbxhGr7vQxeHc5XNkqlE7j2+rqc kbzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Q8oRa3pMk77oMmm/HFmj0dClNd11dTn6bUo7atxsfXs=; b=BbdJ7p3o+3Ao573ai0ywSaCOuHUi4OcekXRvVXYB+L92XRaee58qpOCmDWwcF9gVMd TbL5SSIphkB4rO84PnE1wAQCAI3KB2IJPLjD/JxYlirfCO0s4yXnxqve82Lj4soI4ySX d3Y83Ee33VIxLIXoFwo/ob6Kfpbdqck6nfKvtfWR4H4vwhd5E13E5nJZ2gGtr5iBvllE 1J6ekWMCEgA800B10QpaPyqGtD/NlAnKlC6qcUP+ggJtkaWc50UiwCABuPT+5t7Q+jy2 Gh8G/7z9QpWvgd1U7ALPOFQr3pKHbilxMrOFXrhoupJN3e0Ze1PH+5NXpXFFASsNMqms 58Bg== X-Gm-Message-State: APf1xPCyGqJJdBcN3CgLhzVCCtGA2dHKXFZqB/f/vQ+AxHPmi8FXEIlF tSdOy9s834pzoX6fiAtkCvU= X-Received: by 10.98.162.26 with SMTP id m26mr9885078pff.217.1519635095051; Mon, 26 Feb 2018 00:51:35 -0800 (PST) Received: from localhost.localdomain ([203.236.8.208]) by smtp.gmail.com with ESMTPSA id y186sm17825671pfb.92.2018.02.26.00.51.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:51:34 -0800 (PST) From: baegjae@gmail.com To: keith.busch@intel.com, axboe@fb.com, hch@lst.de, sagi@grimberg.me, baegjae@gmail.com Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvme-multipath: fix sysfs dangerously created links Date: Mon, 26 Feb 2018 17:51:23 +0900 Message-Id: <20180226085123.26120-1-baegjae@gmail.com> X-Mailer: git-send-email 2.8.3.windows.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baegjae Sung If multipathing is enabled, each NVMe subsystem creates a head namespace (e.g., nvme0n1) and multiple private namespaces (e.g., nvme0c0n1 and nvme0c1n1) in sysfs. When creating links for private namespaces, links of head namespace are used, so the namespace creation order must be followed (e.g., nvme0n1 -> nvme0c1n1). If the order is not followed, links of sysfs will be incomplete or kernel panic will occur. The kernel panic was: kernel BUG at fs/sysfs/symlink.c:27! Call Trace: nvme_mpath_add_disk_links+0x5d/0x80 [nvme_core] nvme_validate_ns+0x5c2/0x850 [nvme_core] nvme_scan_work+0x1af/0x2d0 [nvme_core] Correct order Context A Context B nvme0n1 nvme0c0n1 nvme0c1n1 Incorrect order Context A Context B nvme0c1n1 nvme0n1 nvme0c0n1 The function of a head namespace creation is moved to maintain the correct order. We verified the code with or without multipathing using three vendors of dual-port NVMe SSDs. Signed-off-by: Baegjae Sung --- drivers/nvme/host/core.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 0fe7ea35c221..28777b7352a5 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2844,7 +2844,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, } static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, - struct nvme_id_ns *id, bool *new) + struct nvme_id_ns *id) { struct nvme_ctrl *ctrl = ns->ctrl; bool is_shared = id->nmic & (1 << 0); @@ -2860,8 +2860,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, ret = PTR_ERR(head); goto out_unlock; } - - *new = true; + nvme_mpath_add_disk(head); } else { struct nvme_ns_ids ids; @@ -2873,8 +2872,6 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, ret = -EINVAL; goto out_unlock; } - - *new = false; } list_add_tail(&ns->siblings, &head->list); @@ -2945,7 +2942,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) struct nvme_id_ns *id; char disk_name[DISK_NAME_LEN]; int node = dev_to_node(ctrl->dev), flags = GENHD_FL_EXT_DEVT; - bool new = true; ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node); if (!ns) @@ -2971,7 +2967,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) if (id->ncap == 0) goto out_free_id; - if (nvme_init_ns_head(ns, nsid, id, &new)) + if (nvme_init_ns_head(ns, nsid, id)) goto out_free_id; nvme_setup_streams_ns(ctrl, ns); @@ -3037,8 +3033,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) pr_warn("%s: failed to register lightnvm sysfs group for identification\n", ns->disk->disk_name); - if (new) - nvme_mpath_add_disk(ns->head); nvme_mpath_add_disk_links(ns); return; out_unlink_ns: -- 2.16.2