Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3440023imu; Sun, 11 Nov 2018 15:08:32 -0800 (PST) X-Google-Smtp-Source: AJdET5fyEIjaXxWTzKoCtgy7jt6alM2eCpui22OkDv2GECYRqwjc/zpsk29XNML3I1UpTLMSm+Zo X-Received: by 2002:a17:902:f20b:: with SMTP id gn11mr16859843plb.93.1541977712054; Sun, 11 Nov 2018 15:08:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977712; cv=none; d=google.com; s=arc-20160816; b=o9G4Y3T/z5hqBbhxdaczuifkrRQW68Zh3SuEt99q01A/NlcqIsukHrgw/sgGKvhrtA y+W2aCPH5U35h+BW/Y/RMjh1WPtraFI7vtvqraj8t0Fh6szY2jDdOem7QcAXce6IZDjg 7/8zbGy6i+wTBsyELpPuVtkGk+dpqySHjC+am7QzMhnoUmtkhdpIVEDk13S9x1HN0gWP 6hEFYI8zIKcD8F30i5vgZivIBVzPdbxSkaJ+aVgMtSKguFv6u1D/P+xQFGOwwvwJv3A4 pliCZG5Fx+p6ACwE/NVxTFQlU4PAp0uoxSa6svuEe+QNTFuDOzaOXFsmosTu2MjzMo3j vO1A== 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=X0iNMOvlG3S7MS3Gn3Mjy2QrGOHrVoZBzNqnQRYB27A=; b=L2GVaLzQaUtDFjmIUvXD/0q+zWU07Gbn+VY36YZvfD7zwjiv8FVCrVGmmdd3E2KB/N 6cBk9hP9ERrSqXzNv6XTzpw0NCa1GAm6YlxMQrpqo105mT0MIN6DatkifaKzLUDOWksr ZfpzlEFe4K+dhwKjOPtNQ+8R0e3+I4tZMPQ3B0YuTHPD/mxFPdQrzrG0mOp0Fy5Z+Kv5 LcOPIuNBhbpFiLtIwFMICrxoy0BOc7an/Rd7LOjRkItbG21vwIqJqwRPaaov5BdTmAPM yUMDb8Byj2lOK4YmUB6Xg9kCAWVCKyVqNHHYMqhahMbWQQp4CU8oPH5hC6PNwN/duJ9r wNmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oql09N20; 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 20si13769323pgg.271.2018.11.11.15.08.17; Sun, 11 Nov 2018 15:08:32 -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=oql09N20; 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 S2390624AbeKLI4x (ORCPT + 99 others); Mon, 12 Nov 2018 03:56:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:51200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390343AbeKLIWK (ORCPT ); Mon, 12 Nov 2018 03:22:10 -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 A3A6221707; Sun, 11 Nov 2018 22:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975533; bh=P9ptb1EQj8fXnBmuRJobKYHyZUu4Qa37klPsY+eb9lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oql09N20hcpldUX9+JcI3uOSGVm8SAkf5MdA5kDep/1F51ZK8Z3Lllb7btncgYptm DVkaRReIh57nlwpk9bwxreDV+f1NfCnH2xoRIDAjaZ/OiZBNO8yEAsQfvUdQUonhIj geVSDTMu97EWRznn8aIlMFGM+Z1v4z2Go7sVFKAs= 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.14 046/222] lightnvm: pblk: fix two sleep-in-atomic-context bugs Date: Sun, 11 Nov 2018 14:22:23 -0800 Message-Id: <20181111221652.244966822@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -1001,12 +1001,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) { @@ -1014,8 +1016,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);