From patchwork Tue Oct 9 11:12:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matias Bjorling X-Patchwork-Id: 10632299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35F75112B for ; Tue, 9 Oct 2018 11:16:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16B6228A5E for ; Tue, 9 Oct 2018 11:16:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 095A528A6F; Tue, 9 Oct 2018 11:16:32 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D39028A5E for ; Tue, 9 Oct 2018 11:16:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726856AbeJISbV (ORCPT ); Tue, 9 Oct 2018 14:31:21 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38457 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727769AbeJISbV (ORCPT ); Tue, 9 Oct 2018 14:31:21 -0400 Received: by mail-pf1-f193.google.com with SMTP id f29-v6so679392pff.5 for ; Tue, 09 Oct 2018 04:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jYV4XtZvQJcH5lonM8XkSCurPDD+mGIDAojfNLj+Ipk=; b=J8lZLHOYK1LrbY6Pq/9Td9waby+CNpeceM5hEqGwFAqmiObwbixI9PITvVw+LvWVuj uRfzErRYQ4itOZQ/++9nktVEnKHTW+vpC72Lax2iRMNNuUB0GxFcfwOoSkpNGmSgBPnJ 6ts8HuZ9YBAvMcQO+cW8LSsC3y9Sd8u50AVaxs0OIHkIZpWzkl3Ou5NLdMykqEDBK/zS w8KMwzdeQzXuIJhb23ZflMtGoUEDvRw+tZTwzhsD77IDYJPTMPCGaj3rC2/z+3U477NO GjcAuuPp1TRhpzYsRnBhJkDoSC4FlIJpWj6jqPYaa8bTDVub8z3U8dPAQiy2TglkBtoo TK+Q== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=jYV4XtZvQJcH5lonM8XkSCurPDD+mGIDAojfNLj+Ipk=; b=IbIzPPx3y15Onwbnc4f6j2lj0HMD2LJYM2iGb1DZ3yggIPIXdC/L7YfNsnY63CFo3C Cnm8VJ/FNwtoLEv/VAxJg5eAv5TbTxg6iNty85wDiddRWbFxdVTGYboWVu7h6n1ctE4M 9th3nYmYFTCU0yHZJCWGgrH0sw5J/QVVGgLLjKydlX4SwfdkkA/LxbC32GHD9uq8ioUB u00c5J1qFOT+tt3++90If6qhpTqIOrEn3ENjYdYhs7HXJEZKxdqlBFF0DQ++pM5qOqqU yAtMpPG0+ePis/jD0ZoW5S/1iFgXI+sTK7yl2Rx6FQYSv61RbAvxaZ+0LJboQAn2fTc9 y64Q== X-Gm-Message-State: ABuFfohLGrwW6ENFMEmR0D5ckLDlgOEb0PYAOQ36wFqkqr++ebPYcX1o 2yC/9ZQ76Hsed0/IS5dCYPrFrQ== X-Google-Smtp-Source: ACcGV62Osy0EJ7KNHfxsdRbYHE4EeCaoGvN/YD7HHLYD7aXxQHLmkipoSCwVGlZC1vgCnUA2LSwzUQ== X-Received: by 2002:a63:3308:: with SMTP id z8-v6mr21143648pgz.220.1539083694326; Tue, 09 Oct 2018 04:14:54 -0700 (PDT) Received: from skyninja.hgst.com (rap-us.hgst.com. [199.255.44.250]) by smtp.gmail.com with ESMTPSA id p1-v6sm25342380pff.128.2018.10.09.04.14.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 04:14:53 -0700 (PDT) From: =?utf-8?q?Matias_Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai , =?utf-8?q?Matias_Bj=C3=B8rling?= Subject: [GIT PULL 30/45] lightnvm: pblk: fix two sleep-in-atomic-context bugs Date: Tue, 9 Oct 2018 13:12:00 +0200 Message-Id: <20181009111215.7653-31-mb@lightnvm.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181009111215.7653-1-mb@lightnvm.io> References: <20181009111215.7653-1-mb@lightnvm.io> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jia-Ju Bai 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, the call to pblk_line_replace_data() is moved out of the spinlock protection. These bugs are found by my static analysis tool DSAC. Signed-off-by: Jia-Ju Bai Reviewed-by: Javier González Signed-off-by: Matias Bjørling --- drivers/lightnvm/pblk-recovery.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/lightnvm/pblk-recovery.c b/drivers/lightnvm/pblk-recovery.c index 8036c3eb6372..2526722304bb 100644 --- a/drivers/lightnvm/pblk-recovery.c +++ b/drivers/lightnvm/pblk-recovery.c @@ -966,12 +966,14 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk) } } - spin_lock(&l_mg->free_lock); if (!open_lines) { + spin_lock(&l_mg->free_lock); WARN_ON_ONCE(!test_and_clear_bit(meta_line, &l_mg->meta_bitmap)); + spin_unlock(&l_mg->free_lock); pblk_line_replace_data(pblk); } else { + spin_lock(&l_mg->free_lock); /* Allocate next line for preparation */ l_mg->data_next = pblk_line_get(pblk); if (l_mg->data_next) { @@ -979,8 +981,8 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk) l_mg->data_next->type = PBLK_LINETYPE_DATA; is_next = 1; } + spin_unlock(&l_mg->free_lock); } - spin_unlock(&l_mg->free_lock); if (is_next) pblk_line_erase(pblk, l_mg->data_next);