Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp618468iog; Mon, 13 Jun 2022 09:15:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vQTOXwmHYdxxMu3pgL4lDptkuCGdrpiG6BlGdKrtfbAE42gdfBiQQA8Wek7yJUi5I6hGsz X-Received: by 2002:a17:902:e1cc:b0:164:1517:e8bf with SMTP id t12-20020a170902e1cc00b001641517e8bfmr411938pla.98.1655136923981; Mon, 13 Jun 2022 09:15:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655136923; cv=none; d=google.com; s=arc-20160816; b=gUbm1DmCDzDnKSmEUCBA7sFoWBviCivr9oat2l6az3eEl0tpyJpLy25Ay/VJvaXFy3 HssunRtEVZTF4hKgOtfAZwYV4wYIRyFruKMv+rZEyceXWVAF/RjdT50I3M37+072C3lT bOtXB50M1KdszZ2Gi3NwEh185TzkscVu0j4reMa8dic5NtKXNKlMipmA5txSX2WoEOFv mSlCm88/6ZjRgxJMTyPDVFBbUOGDUp/0SIF42LKtGTYFuNG29xq3mCcI9ypMYQbc7EEO ZfhtW64N/OJYDQrAAsPJCKpVfQtnK+m7zAp8Jha1fNZ7lDMFSt4RHyAuf6ndLlgJeR1h 9+nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G3YF5mMYInIXMGRWK07aoiJusSCSV7Rpq18Zni4nefc=; b=J4+y6ntzYkDA1dchP9zlE3Bw4J0fBRvcHT0ClfgnMnVggEVqiyAy1UiJ1eQq+sKF1F U74mBtPqKk6BmJ2OSdkg0ZIYGVBJLN8MVY2GwEfdxWcXhicOM7aF0pq3HHbU9+6hfcwX rgTXmFAb9BxWnG/+aZSIpAyabzHqukiOJMqyL8+INnsye75zSm8Am4Mv+vqM0fbE+ZRf XGftu+7VIr+bSNdM4o1dB70TvA8N38P1fIVgeFRdolTGsW8P8wWicXTc647Mxtpfrobi 3ouWqbr95tK47T0hQBRd9C+9RICvpv+CZw61tiG+reJJCNEVZiRJi2b2+Y+E/cNFhtLL d8+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hQZyt5xb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t7-20020a634607000000b003fadcc14015si10106053pga.15.2022.06.13.09.15.10; Mon, 13 Jun 2022 09:15:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hQZyt5xb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353948AbiFML0O (ORCPT + 99 others); Mon, 13 Jun 2022 07:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353434AbiFMLTo (ORCPT ); Mon, 13 Jun 2022 07:19:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E79B3B002; Mon, 13 Jun 2022 03:41:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CF409B80EA3; Mon, 13 Jun 2022 10:41:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 304EDC3411C; Mon, 13 Jun 2022 10:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116873; bh=710qDeAQ+M2wd+oQnN+CKC6Zb5QNapd+zSvcMbkNVZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hQZyt5xby/6XAippub76DF5pOvT6awuJEoI8+bfrgwHTLdDE/e5unTE9bkMCeu6u2 OvL18VSjGGTHXyMcSjqmGfpnHiGdlp6LFX/1G0p0tsWfETaP0AqXuaQ0x1W9TDCE9B DOBNr3E0fBhNHsJk+g7YBYpUH0SMmvtgzRCuNTQ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheyu Ma , Douglas Miller , Dennis Dalessandro , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.4 194/411] RDMA/hfi1: Prevent use of lock before it is initialized Date: Mon, 13 Jun 2022 12:07:47 +0200 Message-Id: <20220613094934.478195288@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Douglas Miller [ Upstream commit 05c03dfd09c069c4ffd783b47b2da5dcc9421f2c ] If there is a failure during probe of hfi1 before the sdma_map_lock is initialized, the call to hfi1_free_devdata() will attempt to use a lock that has not been initialized. If the locking correctness validator is on then an INFO message and stack trace resembling the following may be seen: INFO: trying to register non-static key. The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator. Call Trace: register_lock_class+0x11b/0x880 __lock_acquire+0xf3/0x7930 lock_acquire+0xff/0x2d0 _raw_spin_lock_irq+0x46/0x60 sdma_clean+0x42a/0x660 [hfi1] hfi1_free_devdata+0x3a7/0x420 [hfi1] init_one+0x867/0x11a0 [hfi1] pci_device_probe+0x40e/0x8d0 The use of sdma_map_lock in sdma_clean() is for freeing the sdma_map memory, and sdma_map is not allocated/initialized until after sdma_map_lock has been initialized. This code only needs to be run if sdma_map is not NULL, and so checking for that condition will avoid trying to use the lock before it is initialized. Fixes: 473291b3ea0e ("IB/hfi1: Fix for early release of sdma context") Fixes: 7724105686e7 ("IB/hfi1: add driver files") Link: https://lore.kernel.org/r/20220520183701.48973.72434.stgit@awfm-01.cornelisnetworks.com Reported-by: Zheyu Ma Signed-off-by: Douglas Miller Signed-off-by: Dennis Dalessandro Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hfi1/sdma.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/sdma.c b/drivers/infiniband/hw/hfi1/sdma.c index 248be21acdbe..2a684fc6056e 100644 --- a/drivers/infiniband/hw/hfi1/sdma.c +++ b/drivers/infiniband/hw/hfi1/sdma.c @@ -1329,11 +1329,13 @@ void sdma_clean(struct hfi1_devdata *dd, size_t num_engines) kvfree(sde->tx_ring); sde->tx_ring = NULL; } - spin_lock_irq(&dd->sde_map_lock); - sdma_map_free(rcu_access_pointer(dd->sdma_map)); - RCU_INIT_POINTER(dd->sdma_map, NULL); - spin_unlock_irq(&dd->sde_map_lock); - synchronize_rcu(); + if (rcu_access_pointer(dd->sdma_map)) { + spin_lock_irq(&dd->sde_map_lock); + sdma_map_free(rcu_access_pointer(dd->sdma_map)); + RCU_INIT_POINTER(dd->sdma_map, NULL); + spin_unlock_irq(&dd->sde_map_lock); + synchronize_rcu(); + } kfree(dd->per_sdma); dd->per_sdma = NULL; -- 2.35.1