Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1325156imm; Tue, 2 Oct 2018 06:33:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV63E9GRC5/rRkJOpCbhMh5q3JusbJHRt6AtsYZXzTtN5bcZz8VDW6pgB3sFsW7+2KwILcW9T X-Received: by 2002:a65:4585:: with SMTP id o5-v6mr14145968pgq.212.1538487207363; Tue, 02 Oct 2018 06:33:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538487207; cv=none; d=google.com; s=arc-20160816; b=PFs5YV4NPlsZcZ/k+WCBFgpsM91bNQk4UGePn6C9EVVUIDpTTD/8kHzyRbA2DKs76i aD1zK4I6aowG+oOnU7ZHHEMIOBs9xVOES2onCsCiDDUt8ns8u5TaF1vOENVb2Ow2aUBN D6aaQg+/wj0c/fWGtypgvKem29s1mPYwOqflir1ncFVhR+bczQ4hi320NNrhcu2e4IUx Np+XcuFh8Qh3LOFLYIUaGtHXuGSRXPgdps2DA7TF5HPwpFIgJ5xVb9XQWcgdjQWBcrhv AJ1BJSXq2lciNfIUsdNJ6v4AuLFqPPlVoI+wzIuL3L2vB90FAGfSwRVoLSpSMTqYSGbO rq4Q== 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; bh=wUnq7jGwSDD6XIQBZfuQJO/amKPV0TbjX7co0x9eafU=; b=Vv6DIqW85ThxfXOFtvZuUQ6kHpSyOgaWPIquY0y7xUMo30g3gTdc4kgX18pwIzIn1E hEcLpmkFqvgq1dZJFF9BYoPlq1pDhobQsw+C6rmOI9J3l0tfEuUmtXi2dyae12Y3Y+rg 2WH3M5J9FEBVW6cpy4YG71jZ2hKHXb7JrCZypOEJuChKoSzNM9Mf5MEbrlOHmo0fNBMy XJW0pyydSobqnTYMvNoGUQakDkESgC6JbrsuQtd5KLFxTpwThaYSsfVbDciLMVGnH8Et dzKnIOaSK79dre9SCOOFlFYM3EAnRee8Yd49RQHAoBVvsRcKQEOZyTrb0MsIfSb6ARSj y7cQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d127-v6si17424272pfa.189.2018.10.02.06.33.12; Tue, 02 Oct 2018 06:33:27 -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; 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 S1731336AbeJBUPn (ORCPT + 99 others); Tue, 2 Oct 2018 16:15:43 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34464 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731329AbeJBUPm (ORCPT ); Tue, 2 Oct 2018 16:15:42 -0400 Received: from localhost (24-104-73-23-ip-static.hfc.comcastbusiness.net [24.104.73.23]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 399B35AA; Tue, 2 Oct 2018 13:32:19 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , "Martin K. Petersen" , James Bottomley , Sasha Levin Subject: [PATCH 4.14 033/137] scsi: klist: Make it safe to use klists in atomic context Date: Tue, 2 Oct 2018 06:23:54 -0700 Message-Id: <20181002132500.764822155@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002132458.446916963@linuxfoundation.org> References: <20181002132458.446916963@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: Bart Van Assche [ Upstream commit 624fa7790f80575a4ec28fbdb2034097dc18d051 ] In the scsi_transport_srp implementation it cannot be avoided to iterate over a klist from atomic context when using the legacy block layer instead of blk-mq. Hence this patch that makes it safe to use klists in atomic context. This patch avoids that lockdep reports the following: WARNING: SOFTIRQ-safe -> SOFTIRQ-unsafe lock order detected Possible interrupt unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&(&k->k_lock)->rlock); local_irq_disable(); lock(&(&q->__queue_lock)->rlock); lock(&(&k->k_lock)->rlock); lock(&(&q->__queue_lock)->rlock); stack backtrace: Workqueue: kblockd blk_timeout_work Call Trace: dump_stack+0xa4/0xf5 check_usage+0x6e6/0x700 __lock_acquire+0x185d/0x1b50 lock_acquire+0xd2/0x260 _raw_spin_lock+0x32/0x50 klist_next+0x47/0x190 device_for_each_child+0x8e/0x100 srp_timed_out+0xaf/0x1d0 [scsi_transport_srp] scsi_times_out+0xd4/0x410 [scsi_mod] blk_rq_timed_out+0x36/0x70 blk_timeout_work+0x1b5/0x220 process_one_work+0x4fe/0xad0 worker_thread+0x63/0x5a0 kthread+0x1c1/0x1e0 ret_from_fork+0x24/0x30 See also commit c9ddf73476ff ("scsi: scsi_transport_srp: Fix shost to rport translation"). Signed-off-by: Bart Van Assche Cc: Martin K. Petersen Cc: James Bottomley Acked-by: Greg Kroah-Hartman Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- lib/klist.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/lib/klist.c +++ b/lib/klist.c @@ -336,8 +336,9 @@ struct klist_node *klist_prev(struct kli void (*put)(struct klist_node *) = i->i_klist->put; struct klist_node *last = i->i_cur; struct klist_node *prev; + unsigned long flags; - spin_lock(&i->i_klist->k_lock); + spin_lock_irqsave(&i->i_klist->k_lock, flags); if (last) { prev = to_klist_node(last->n_node.prev); @@ -356,7 +357,7 @@ struct klist_node *klist_prev(struct kli prev = to_klist_node(prev->n_node.prev); } - spin_unlock(&i->i_klist->k_lock); + spin_unlock_irqrestore(&i->i_klist->k_lock, flags); if (put && last) put(last); @@ -377,8 +378,9 @@ struct klist_node *klist_next(struct kli void (*put)(struct klist_node *) = i->i_klist->put; struct klist_node *last = i->i_cur; struct klist_node *next; + unsigned long flags; - spin_lock(&i->i_klist->k_lock); + spin_lock_irqsave(&i->i_klist->k_lock, flags); if (last) { next = to_klist_node(last->n_node.next); @@ -397,7 +399,7 @@ struct klist_node *klist_next(struct kli next = to_klist_node(next->n_node.next); } - spin_unlock(&i->i_klist->k_lock); + spin_unlock_irqrestore(&i->i_klist->k_lock, flags); if (put && last) put(last);