From patchwork Tue Dec 12 13:33:00 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: 10107365 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 3060C602C2 for ; Tue, 12 Dec 2017 13:31:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DD8329BB3 for ; Tue, 12 Dec 2017 13:31:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12D6429BB8; Tue, 12 Dec 2017 13:31:05 +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 BFEF029BB3 for ; Tue, 12 Dec 2017 13:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754511AbdLLNat (ORCPT ); Tue, 12 Dec 2017 08:30:49 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:44423 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754121AbdLLNaq (ORCPT ); Tue, 12 Dec 2017 08:30:46 -0500 Received: by mail-pf0-f194.google.com with SMTP id m26so14198050pfj.11; Tue, 12 Dec 2017 05:30:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=LYnrb849xqtamk62NNWliW5dMcJCoAJKBxLzMQGhYUA=; b=PT5047U4d0MwlnS5NeTi/vJAMAxrVj2d9LIV37BufuFehBr8MP1pdplOt3TjTcCD0f 25lMuQ9TOYlVBEnrSX6W5t0dKTT6ZMAxhWGn5U+npTmgsmDtXWPgwtR0pMCETSxTpIpz acKqMY5LQALr8l6xgcj6plf0XgEym7tFdLY8RI760FIseKvzVgM8PAhlAO7L7QN3t7mb UsxsocYbBMMYP4K5+yhrKENvLS6Nnk/SmRywtibM/r3D8AQI17I2BXSTMeQyeEbnSAZD hfvo9f2Hc9Rf/OUXBeTUVDm78yAc2GoCMvytg0/GrbE2EA4eJ1AtSEGYV90P6VmbQyQn V+4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LYnrb849xqtamk62NNWliW5dMcJCoAJKBxLzMQGhYUA=; b=bytUtmTYRCdfWsGm+5jqjPrjU4eFx9UFxd9eVvCCPjR8CcYruJeVqU9XP/Num9PlF0 rAD5aWUa6shv35/9NpD9uNb3mjQrIC/uRGWT2UCkYCrRZAhkCUoQcZ9prcGQD8V6mOeY JkQd2pKV2Akx8Eax1VWp7XSSWxHKDv582xlMZoUJin5pF3Mmrfm3Q+mHjAxrqctPDJAK BiIQ8cXFqzJexGvwm8QCieEh28Ei7p3mSyc9vvTgL4RuQ+EirimhZUJxtvaOGSxRM7a6 gqZfG5Kgl1WOhU4TRXuHTrL06oZPni178LxGAeGh3QV54lKMaieYxavXXiOy5BjrrGa/ Wu1w== X-Gm-Message-State: AKGB3mI7IXqoJ2ofESfV10NUHXHdGpp1K1l496oGOnHCTqsrRmog3EMI qYXdTNLWJi55Bmu7qQdfh9EqjpbC X-Google-Smtp-Source: ACJfBou0I/3NjYOa1+W4LEoUaBu5v0ZqBvqZKpLjEsXVpcZcv0tr9/21Ryywq9DVvWBSkII6slb8fw== X-Received: by 10.98.10.77 with SMTP id s74mr2347517pfi.104.1513085445463; Tue, 12 Dec 2017 05:30:45 -0800 (PST) Received: from bai-oslab.tsinghua.edu.cn ([2402:f000:1:4413:7146:1b55:9590:7719]) by smtp.gmail.com with ESMTPSA id j6sm31588318pfg.85.2017.12.12.05.30.41 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Dec 2017 05:30:45 -0800 (PST) From: Jia-Ju Bai To: support@areca.com.tw, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com, keescook@chromium.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] arcmsr: Fix possible sleep-in-atomic bugs in arcmsr_queue_command Date: Tue, 12 Dec 2017 21:33:00 +0800 Message-Id: <1513085580-28705-1-git-send-email-baijiaju1990@gmail.com> X-Mailer: git-send-email 1.7.9.5 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 From: Jia-Ju Bai The driver may sleep under a spinlock, and the function call paths are: arcmsr_queue_command(acquire the spinlock) arcmsr_queue_command_lck arcmsr_handle_virtual_command arcmsr_iop_message_xfer arcmsr_iop_parking arcmsr_stop_adapter_bgrb arcmsr_hbaA_stop_bgrb arcmsr_hbaA_wait_msgint_ready msleep --> may sleep arcmsr_queue_command(acquire the spinlock) arcmsr_queue_command_lck arcmsr_handle_virtual_command arcmsr_iop_message_xfer arcmsr_iop_parking arcmsr_stop_adapter_bgrb arcmsr_hbaB_stop_bgrb arcmsr_hbaB_wait_msgint_ready msleep --> may sleep arcmsr_queue_command(acquire the spinlock) arcmsr_queue_command_lck arcmsr_handle_virtual_command arcmsr_iop_message_xfer arcmsr_iop_parking arcmsr_stop_adapter_bgrb arcmsr_hbaC_stop_bgrb arcmsr_hbaC_wait_msgint_ready msleep --> may sleep arcmsr_queue_command(acquire the spinlock) arcmsr_queue_command_lck arcmsr_handle_virtual_command arcmsr_iop_message_xfer arcmsr_iop_parking arcmsr_stop_adapter_bgrb arcmsr_hbaD_stop_bgrb arcmsr_hbaD_wait_msgint_ready msleep --> may sleep To fix them, msleep is replaced with mdelay. These bugs are found by my static analysis tool and my code review. Signed-off-by: Jia-Ju Bai --- drivers/scsi/arcmsr/arcmsr_hba.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c index af032c4..31d94bd 100644 --- a/drivers/scsi/arcmsr/arcmsr_hba.c +++ b/drivers/scsi/arcmsr/arcmsr_hba.c @@ -347,7 +347,7 @@ static uint8_t arcmsr_hbaA_wait_msgint_ready(struct AdapterControlBlock *acb) ®->outbound_intstatus); return true; } - msleep(10); + mdelay(10); } /* max 20 seconds */ return false; @@ -367,7 +367,7 @@ static uint8_t arcmsr_hbaB_wait_msgint_ready(struct AdapterControlBlock *acb) reg->drv2iop_doorbell); return true; } - msleep(10); + mdelay(10); } /* max 20 seconds */ return false; @@ -385,7 +385,7 @@ static uint8_t arcmsr_hbaC_wait_msgint_ready(struct AdapterControlBlock *pACB) &phbcmu->outbound_doorbell_clear); /*clear interrupt*/ return true; } - msleep(10); + mdelay(10); } /* max 20 seconds */ return false; @@ -403,7 +403,7 @@ static bool arcmsr_hbaD_wait_msgint_ready(struct AdapterControlBlock *pACB) reg->outbound_doorbell); return true; } - msleep(10); + mdelay(10); } /* max 20 seconds */ return false; }