Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp344765imm; Sat, 1 Sep 2018 04:54:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYDuNYzEKC5sB+MtiTA/DZKtSC/KbefV4ddgzAtFl/xZufyr2ggx/BXXojmCEOfykIf2frE X-Received: by 2002:a62:a6cc:: with SMTP id r73-v6mr20341993pfl.60.1535802890443; Sat, 01 Sep 2018 04:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535802890; cv=none; d=google.com; s=arc-20160816; b=csNFwjqmumZU3dWKjeKWgnxAJ0wziyN6xxvfbGR8UYHELudrjS+FsyM7JQm23aOmPh OcA0WFNjSSR76VO384rSqtNHuOlXJupnPCXMHjnI3GaScMAn/ZHZCR172tOfsbm7Hd2s fqdvUoVoMjinQbXxuXb8en/yWVhnJ8eSCGaRaRHek4OJRRUP23K9/8J58n+bas++9QQx vianBb1Vx8kjz4E8Eo+CUh6UcVxbhPoN3j8z5Q93HsunfGoEQMH6+UJC57Nz6d6my4Ee nx9Q/ROOIQWw8e8HFbIwGsKVIVtMdKZfnLXcWJRCsczpp3Zzz84sB9AZ9PpUFx+VLkLn iKDQ== 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=IWiPvKQSdfz/cocXP+iDE5523lfsqoaXSAQHXVKKEnw=; b=gdEDEld7u+7Zgr4kPSqHhf4sbhI6W0eS+2bbckdB1NgPk1G27aLgj2Rq0ZvBqXODz0 xnHG8UIWhI+HoUKK61V+/E0bfgt0RT/WYzyXNmmPqHiP8WZ7I/upIvwBC6I7Ap0p2Xn8 uUFoTb15QvufiqyWRHjXYiNB69fMXrab4Ao+itxrznGcDjpJ7Pn0CR4r/IxTQgtZOfT0 ReGm4MSlMKv+QzRpl2ulvtjEeUB6DkovY1hwKHikzHeC8WKSHwt0yHtuZ55NZtMM9ZiZ i9tb0RoctODqEouZeA1TpdsSwP0W2ibh1lPpgXQDcY3YpXKS3d2dumX4toq98YuMOoxX cZtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XJSXfdTg; 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 f2-v6si12878570pgg.552.2018.09.01.04.54.33; Sat, 01 Sep 2018 04:54:50 -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=@gmail.com header.s=20161025 header.b=XJSXfdTg; 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 S1727059AbeIAQFM (ORCPT + 99 others); Sat, 1 Sep 2018 12:05:12 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36736 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbeIAQFM (ORCPT ); Sat, 1 Sep 2018 12:05:12 -0400 Received: by mail-pl1-f194.google.com with SMTP id e11-v6so6632201plb.3; Sat, 01 Sep 2018 04:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=IWiPvKQSdfz/cocXP+iDE5523lfsqoaXSAQHXVKKEnw=; b=XJSXfdTgPeowQOME785lO5OL7PIcaVLnpSufnnYxl126DVJXBxXtUf6NMzhZ1nbHb4 8Amr11c+kH3SqndpaWjgtt0rfRJsXMwrYnCH2xQM8oKlUBH+IFkutku0xidwc/V+Dg3F WMvViArSFllNrs1ui89FjhreCnl+c9I7MEbM7Y2+JYUZA2b4zG3xktk5I5xKKcvdJnJZ OzA02xdM3cM2/szBTpv2RsOnC+UNAYEbeecZxCCIkgrJtSfSvj9t85kUPpoo6A1RZbO/ r+72351FGUAYFVjdn3zBmPlJlVMg11OpEQBnWznIP1wsl62NJCYgNufooY9lTt8G0Lfw pOFA== 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=IWiPvKQSdfz/cocXP+iDE5523lfsqoaXSAQHXVKKEnw=; b=pnH1Zh8Zb+bMoFdIu3irfo7LDkV+yTF4JmcHE3hl8wx4cQScSAI6WMAa+tmYychL/F j/RgNeS6kFe9+mImHDobo/UYIBmyETcg1Wr+Xe6o1DNJMdpxz+EPivPPG9IRiQ/H5sOh Ot+TvLcrB5zVNetLi3jXLePv0c6wzF8XCiQ2i4IZiRll/sFpdPuRDSbFGbHFMWTChAOI N2folB4mjpbP9CHZ2/yw9h0Nm13aS4/vntGS+AE2F2aDIVSDw+c8E4XQA3JoSM/S/2mg mWR1kFuGzx1nMhtlVTzpLqPGNCsUIUKXIrVkcI3BtJ/s8BzX2Qtm9OxT1mDSJpUNXEDZ k08A== X-Gm-Message-State: APzg51DyMFbPJ2+e26pO0xWScqY260l8we2az5AKFuDXWCkwKZsnHpK1 4i5VAGHda4z9XgfiSgktVRU= X-Received: by 2002:a17:902:6684:: with SMTP id e4-v6mr16036198plk.50.1535802805331; Sat, 01 Sep 2018 04:53:25 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:2913:cd09:aee0:380]) by smtp.gmail.com with ESMTPSA id w69-v6sm25114914pgd.37.2018.09.01.04.53.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 04:53:24 -0700 (PDT) From: Jia-Ju Bai To: mb@lightnvm.io Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] lightnvm: pblk: Fix two sleep-in-atomic-context bugs in pblk_line_submit_smeta_io() Date: Sat, 1 Sep 2018 19:53:18 +0800 Message-Id: <20180901115318.30416-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The driver may sleep with holding a spinlock. The function call paths (from bottom to top) in Linux-4.16 are: [FUNC] nvm_dev_dma_alloc(GFP_KERNEL) drivers/lightnvm/pblk-core.c, 754: nvm_dev_dma_alloc in pblk_line_submit_smeta_io drivers/lightnvm/pblk-core.c, 1048: pblk_line_submit_smeta_io in pblk_line_init_bb drivers/lightnvm/pblk-core.c, 1434: pblk_line_init_bb in pblk_line_replace_data drivers/lightnvm/pblk-recovery.c, 980: pblk_line_replace_data in pblk_recov_l2p drivers/lightnvm/pblk-recovery.c, 976: spin_lock in pblk_recov_l2p [FUNC] bio_map_kern(GFP_KERNEL) drivers/lightnvm/pblk-core.c, 762: bio_map_kern in pblk_line_submit_smeta_io drivers/lightnvm/pblk-core.c, 1048: pblk_line_submit_smeta_io in pblk_line_init_bb drivers/lightnvm/pblk-core.c, 1434: pblk_line_init_bb in pblk_line_replace_data drivers/lightnvm/pblk-recovery.c, 980: pblk_line_replace_data in pblk_recov_l2p drivers/lightnvm/pblk-recovery.c, 976: spin_lock in pblk_recov_l2p To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC. These bugs are found by my static analysis tool DSAC. Signed-off-by: Jia-Ju Bai --- drivers/lightnvm/pblk-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c index ed9cc977c8b3..5d915c93b6cf 100644 --- a/drivers/lightnvm/pblk-core.c +++ b/drivers/lightnvm/pblk-core.c @@ -802,7 +802,7 @@ static int pblk_line_submit_smeta_io(struct pblk *pblk, struct pblk_line *line, memset(&rqd, 0, sizeof(struct nvm_rq)); - rqd.meta_list = nvm_dev_dma_alloc(dev->parent, GFP_KERNEL, + rqd.meta_list = nvm_dev_dma_alloc(dev->parent, GFP_ATOMIC, &rqd.dma_meta_list); if (!rqd.meta_list) return -ENOMEM; @@ -810,7 +810,7 @@ static int pblk_line_submit_smeta_io(struct pblk *pblk, struct pblk_line *line, rqd.ppa_list = rqd.meta_list + pblk_dma_meta_size; rqd.dma_ppa_list = rqd.dma_meta_list + pblk_dma_meta_size; - bio = bio_map_kern(dev->q, line->smeta, lm->smeta_len, GFP_KERNEL); + bio = bio_map_kern(dev->q, line->smeta, lm->smeta_len, GFP_ATOMIC); if (IS_ERR(bio)) { ret = PTR_ERR(bio); goto free_ppa_list; -- 2.17.0