From patchwork Tue Oct 3 02:53:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 9981423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9252E602B8 for ; Tue, 3 Oct 2017 02:52:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85EE6285CF for ; Tue, 3 Oct 2017 02:52:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 794DF28707; Tue, 3 Oct 2017 02:52:13 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable 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 43071285CF for ; Tue, 3 Oct 2017 02:52:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751072AbdJCCv4 (ORCPT ); Mon, 2 Oct 2017 22:51:56 -0400 Received: from m12-14.163.com ([220.181.12.14]:34467 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750846AbdJCCvz (ORCPT ); Mon, 2 Oct 2017 22:51:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=bVoHxCuz5ZV4LCQDN2 QdaKjEqfpl0wkzU4HEVydeJNU=; b=m1OZsHI7A6yRqGlFSJ+9Vz04VTlls3NTL6 /kll3KY9R5xxkaPsw8IPp/EFhcmkv+Ps08pbnfFfVs9kp0gUeAsGIHNI3S7UR1hx bETQ24hH0O0PCO1qUMMeoH8QYFgp57xkHMl2d1O7NLmwvW85qrJhzEX9P7svyDDp +64K7p0zc= Received: from bai-oslab.tsinghua.edu.cn (unknown [166.111.70.46]) by smtp10 (Coremail) with SMTP id DsCowADnzwMM+9JZpsLsHw--.33700S2; Tue, 03 Oct 2017 10:50:56 +0800 (CST) From: Jia-Ju Bai To: satishkh@cisco.com, kartilak@cisco.com, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] scsi/fnic: Fix a sleep-in-atomic bug in fnic_handle_event Date: Tue, 3 Oct 2017 10:53:15 +0800 Message-Id: <1506999195-27236-1-git-send-email-baijiaju1990@163.com> X-Mailer: git-send-email 1.7.9.5 X-CM-TRANSID: DsCowADnzwMM+9JZpsLsHw--.33700S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7XryfCw18tFy5ur1xWF47XFb_yoWkGFc_u3 yvvry7Ar1j9rsIkr1xArZ7WFySyayfur1xWr1Sqa4rury5Aw4UCw4qyF1kWry5XF4UZFW7 tF1qq3WFvr42gjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUbByI5UUUUU== X-Originating-IP: [166.111.70.46] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbiYxBmelaDvGC-KwAAsy Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver may sleep under a spinlock, and the function call path is: fnic_handle_event (acquire the spinlock) fnic_fcoe_start_fcf_disc fcoe_ctlr_link_up mutec_lock --> may sleep To fix it, the spinlock can be released before fnic_fcoe_start_fcf_disc, and acquired again after this function. This bug is found by my static analysis tool and my code review. Signed-off-by: Jia-Ju Bai --- drivers/scsi/fnic/fnic_fcs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/fnic/fnic_fcs.c b/drivers/scsi/fnic/fnic_fcs.c index 999fc75..4c99c96 100644 --- a/drivers/scsi/fnic/fnic_fcs.c +++ b/drivers/scsi/fnic/fnic_fcs.c @@ -265,7 +265,9 @@ void fnic_handle_event(struct work_struct *work) case FNIC_EVT_START_FCF_DISC: FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "Start FCF Discovery\n"); + spin_unlock_irqrestore(&fnic->fnic_lock, flags); fnic_fcoe_start_fcf_disc(fnic); + spin_lock_irqsave(&fnic->fnic_lock, flags); break; default: FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,