Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp178976imd; Wed, 31 Oct 2018 16:55:02 -0700 (PDT) X-Google-Smtp-Source: AJdET5cz+YxKjEBQ26OFMrOyg3mW95zcL7ODDDnxrn9q1VY97gpw3KD4cdCcKe2KfrCtLSyDMbpH X-Received: by 2002:a17:902:8a93:: with SMTP id p19-v6mr5294345plo.41.1541030102796; Wed, 31 Oct 2018 16:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541030102; cv=none; d=google.com; s=arc-20160816; b=j+a78jiknL/bg2Uju6c4gejCw7qsF+CW1ppkHk+iDslCgXbDYyrI/by18sb9UvrTnL 4b4XPMezGUL8EwJEVLqtChecL9GIkdKNd3RViX27YBAJEX4+BKPM3iwAel9twHOEXCTZ dhnm3CICfgHJoh/jYOc0Ao4wcCw6yV8NcETf6Oc6+sI6qgoXmugJbypPOOfycaOOWdT1 Q8nhva6WswOMvds9vFyHkp7ce5KeF/LhnAwEpXkJsQj+7Wyi4s2NA83t0Y5f7FU86wGB zbNhTAUcfjK82pr/ro4dFasXYOHcnV44ZD0vY0ivvgziMIuR8WzYTsFMOVT2hb6qf9IR O9lg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BXTIYVu2IsCA7OrEAS8YApZrTDotfhE4SpM2MRGyo88=; b=qLok8LssSIp6Z9lYfBaNiDWLtKokPDqEcirTLfq+2/eM9yQ/sNLRB+PUJHuq9sG0FW F9cSjWsC9yFL+thNpaacUBqWf8c3iX1u2pA/VBVxDmXUXkUhrWCNbJfqdvoDVdp1vAIv Z1JlY8bxdfNKSw0Qrs1McZGJCH2+bWnfw7Dsp47XGEzxwiMjkT2lON12KSSBJRf8WrhZ gP8NcLSDvstjF9hDhPBlsWfirX5dPyEuG/PZPY6QcnsqWH/4cjGwioEesqciIyQ0hN3L 4i7YM3fOYRuccuPIoVrJIVBmB7WsCjl1ldHx2s0FmhzJkuh8PES60fgXa4ID21dsJ15S w/4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=txKsLTfL; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20-v6si29406594pgk.360.2018.10.31.16.54.48; Wed, 31 Oct 2018 16:55:02 -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=@kernel.org header.s=default header.b=txKsLTfL; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727580AbeKAIGI (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:52834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727552AbeKAIGH (ORCPT ); Thu, 1 Nov 2018 04:06:07 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 041D82082E; Wed, 31 Oct 2018 23:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027156; bh=U0FIY94KVxxOVM7ehnAIkhqOiUTwYdf3xzS1h5Sw7lg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=txKsLTfLMtUeNt9vzm8UUfdxbr6woQ1HVSxSSpBUUBYhtmA2FY/0GVZbP+IpItBo+ xsRpm9xOz+BYT5xvuSZsIgo6U54yG9Tez5KbQtph+TDQhVbzdwPEyYvpllHxABfdjd ZmxeaQYZhVLjJAAvv+lmVBaQNrjQO4EtkcwVOY9E= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jia-Ju Bai , =?UTF-8?q?Matias=20Bj=C3=B8rling?= , Jens Axboe , Sasha Levin Subject: [PATCH AUTOSEL 4.19 015/146] lightnvm: pblk: fix two sleep-in-atomic-context bugs Date: Wed, 31 Oct 2018 19:03:30 -0400 Message-Id: <20181031230541.28822-15-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> 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 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 --- 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 e232e47e1353..df75d9caec45 100644 --- a/drivers/lightnvm/pblk-recovery.c +++ b/drivers/lightnvm/pblk-recovery.c @@ -956,12 +956,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) { @@ -969,8 +971,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); -- 2.17.1