Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3490085imu; Sun, 11 Nov 2018 16:16:26 -0800 (PST) X-Google-Smtp-Source: AJdET5dlKol1rcL6U2zslD4Mt3jT7bRIoEOoX0lNstlMbTej3IxlxsNowZHKDx0KmEpztlV61Qwn X-Received: by 2002:a62:2803:: with SMTP id o3-v6mr18398705pfo.57.1541981786431; Sun, 11 Nov 2018 16:16:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981786; cv=none; d=google.com; s=arc-20160816; b=Ti+9g3yxG3TfidtLn+6gdTPU8zT1EabJDiaCQDyilDschBoHFzaMcE8QjSCAOZdwU2 HfhtXdueFrjAfpHCVkHSG1uX3GBfjGemXI2G/igLyLNS6uobNhCjlmTLg+DxMLX2cLCO Pr7d9DXBdWd0TUrn+XS1XZTka66nCVcglCVforU1qQo9emH8zYPoqQxcIiMT7swDJBa/ t8ZgTKZq26j+kdki+1G7qke4V53BXbWf9fe27ns82HiR92xIoYMHIdO2xWb7po3M1uE9 ZBXCo9wBpcCpc8UvpXrAgTRInsc0KuvBemV3WVmCpWOSn1dDzmhPlb3T1Ez226FvMDEg JxCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rzPQEaxgkZQBfRL/jOGdxKq7gukB076zYYaof50qxIg=; b=qFSsOmmvm2AjQExmxnI411qXUZLy81gEtxbeW8YaUnywTeQ9wg/Ma6Y+ReaBATuu7M rLeRlO3NS/FPT/CEdEedpkGbde7VZqAzs6RAvYJ3PdxOkzvUG3btY6qx2Pohbfx64qts UqrS8qFjU1cbjNFzVRDnHlQatq69IqFJHMMMrLzfNiy89t+eL/Ey2D/C3oXJQIWNuWff NF8UkIhY4ShhIt5RIG0QKZ6dYBp1f1hr5ughzdDnd8J7wyKJx17zK4ShUotvPGg06766 aD3GGzKN6yPQIWYSny66GK6CYvfZLUvlHF+4N+D1bDPtwLMbh1JoeRJ2XetCJTo8Szoj H0kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AMWKDgjq; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h20si14250805pgm.366.2018.11.11.16.16.11; Sun, 11 Nov 2018 16:16: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=@kernel.org header.s=default header.b=AMWKDgjq; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730603AbeKLKGS (ORCPT + 99 others); Mon, 12 Nov 2018 05:06:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:59834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730231AbeKLIRJ (ORCPT ); Mon, 12 Nov 2018 03:17:09 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 10CF9223C8; Sun, 11 Nov 2018 22:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975234; bh=kXcPqV+a0yFukw/0p+Y+7BTucICae2ESRjApL+LA4to=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AMWKDgjqcERTgnn/i7BAEWznpAWIdN6Bea6DARsWSgWHiBv0TTEZjv18Acw9Dk9IM Pl7FTX8hQ2mcSm8j7mohat/yN4s8JsGwJZHcoc57m4PjVNDhlLxJrVnU3EY2PjU0el 6TMnUQSbO49ye5C/LaTvcBi7SNpo58rnD3smNCvQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai , =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 061/361] lightnvm: pblk: fix two sleep-in-atomic-context bugs Date: Sun, 11 Nov 2018 14:16:48 -0800 Message-Id: <20181111221628.496312533@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jia-Ju Bai [ Upstream commit 7325b4bbe5952e3e939f15de812f2ee0c0d33ca9 ] 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 Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/lightnvm/pblk-recovery.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/lightnvm/pblk-recovery.c +++ b/drivers/lightnvm/pblk-recovery.c @@ -956,12 +956,14 @@ next: } } - 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) { @@ -969,8 +971,8 @@ next: 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);