From patchwork Sat Sep 1 11:39:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 10584673 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC1CD13AC for ; Sat, 1 Sep 2018 11:40:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0AF92AB9A for ; Sat, 1 Sep 2018 11:40:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90FEF2ABEC; Sat, 1 Sep 2018 11:40:16 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 198D82AB9A for ; Sat, 1 Sep 2018 11:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726827AbeIAPvl (ORCPT ); Sat, 1 Sep 2018 11:51:41 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36231 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726430AbeIAPvl (ORCPT ); Sat, 1 Sep 2018 11:51:41 -0400 Received: by mail-pf1-f194.google.com with SMTP id b11-v6so6688751pfo.3; Sat, 01 Sep 2018 04:39:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=mi+hw9mk3Z/J7/fU0plW5Uvm7iOTyHvlmITO5aQv+dI=; b=QFClXFjK50mb9brs7BGgPn11x8BzE/Jd/mhmKaEY9UWUXk4dCAnnWUrRKK9zEItZ28 0X8ZeA7yvK3JrC/tDNMivMad82is16xhvVG3JRin/nIQrbELN/A3zDsH/Rs4ZVdX/mpz bXyCS5Xy08pSJ9PH8dvSl6noucsWIEvnFc4wqMTUby5avmmkqDMYeJecHGs+oDLK65aq 6uKRkHZdYB2VJLKbGWzjKNbOa1Ae/MxZ1UEAMmlkeJ/k8sDomoedZrqMoZUiuf9HYpQI FCALpoVt0n+hfc1fkdzzmC6cfG8ndETBg0oZ3F/lDvwiI2QgK/jBa8vFRX/dA88Ws1P6 NP6w== 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=mi+hw9mk3Z/J7/fU0plW5Uvm7iOTyHvlmITO5aQv+dI=; b=et0JmCT7RGh66TCB6wajyR7m/ATib4zcbmwtA2y2RQATrFpmRdxLlv8rc73nykSrIQ 0jXMxO3iUsHLlo/mhFimqLCMB1UHa1SDnff2fEsX9ZbOgDsNBZv/N5H8jp9VJ9TvZyq5 h01RRloovzSVjlcFdoljPsSDJDriJZ9CBrGo78AtHGJ8iO7BZ+x5AaUR9Q5wU5D2ev+7 kPCzsnKAMI6xLC2eSCJnEOJ59srHIwHTPaOLUwtJwxvDRWW44JjXZL7w9SxiB3+iNh8E /ZhC97ztklLftOfcse15hOPhHjlVtSUJ5PckNVrDD9IV0PIATH+rPJuA9wMBgmwT7Rm8 aW/g== X-Gm-Message-State: APzg51DoFkNjaQ0HO7VHs0i8V4eR+avSNzyDnxRzchnV5BETqD4RnfAi yVPinkZhzTH7WsoX06tNzGttwArz X-Google-Smtp-Source: ANB0VdZ7Jhf9trd5uSsNFOoD6zZnAZsnGuEzCyi+WlXjVLeokQ9w4NYWBiAiDEeNLArYAawreY9v6A== X-Received: by 2002:a65:6086:: with SMTP id t6-v6mr3604257pgu.424.1535801997449; Sat, 01 Sep 2018 04:39:57 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:2913:cd09:aee0:380]) by smtp.gmail.com with ESMTPSA id c78-v6sm21586620pfc.188.2018.09.01.04.39.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 04:39:57 -0700 (PDT) From: Jia-Ju Bai To: oulijun@huawei.com, xavier.huwei@huawei.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] infiniband: hw: hns: Fix a sleep-in-atomic-context bug in hns_roce_set_hem() Date: Sat, 1 Sep 2018 19:39:48 +0800 Message-Id: <20180901113948.28967-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver may sleep with holding a spinlock. The function call paths (from bottom to top) in Linux-4.16 are: drivers/infiniband/hw/hns/hns_roce_hem.c, 345: msleep in hns_roce_set_hem drivers/infiniband/hw/hns/hns_roce_hem.c, 330: _raw_spin_lock_irqsave in hns_roce_set_hem To fix this bug, msleep() is replaced with mdelay(). This bug is found by my static analysis tool DSAC. Signed-off-by: Jia-Ju Bai --- drivers/infiniband/hw/hns/hns_roce_hem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_hem.c b/drivers/infiniband/hw/hns/hns_roce_hem.c index 63b5b3edabcb..8c142676c589 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hem.c +++ b/drivers/infiniband/hw/hns/hns_roce_hem.c @@ -342,7 +342,7 @@ static int hns_roce_set_hem(struct hns_roce_dev *hr_dev, } else { break; } - msleep(HW_SYNC_SLEEP_TIME_INTERVAL); + mdelay(HW_SYNC_SLEEP_TIME_INTERVAL); } bt_cmd_l = (u32)bt_ba;