Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2183032iof; Tue, 7 Jun 2022 22:27:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgiqTxiQP/bszzBrwXTEsTqNzLhXSmy0DN4Q89Lbq9WRULiepQr7K/T3zQS1ylDgyoR0CI X-Received: by 2002:a63:81c6:0:b0:3fc:8ba2:9f9a with SMTP id t189-20020a6381c6000000b003fc8ba29f9amr29284566pgd.432.1654666033521; Tue, 07 Jun 2022 22:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666033; cv=none; d=google.com; s=arc-20160816; b=0+4KgLmRgQOy23aNljHGwZci0kT/SOzCj9lbdgNSu7Mmc3j69ABTDF77EulPCb1Asj 6W38qzfyY7j37tH1FVZItRlyFlL3b7A9mq6rWjEAoUndMcuemEvC0kAPawVFvfDA3UDV j1iCs2uQXha59f1D+5mlv/K3+gbhdbtJ6SOA1yeYpovKSc33hY/kS6B3vzO2dppiiJOH D5EDIGdMw4fSvjkvhWOL28/qJJMIKc3zUw6Z+mK5jnEQl8tNUEj7wYR8oKTX7oLv1Jdg JtkZCJ1j++oAFQ+5swOcjehtKyEgp2q0qHIYmfZ0otUYu7lLjMZBg/QUBYrfs1m2Hst8 emCA== 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=yeUyK6NesqrT0gTDuXuV2em2HWHghqB2M0srqmnNwZA=; b=Anf4h779U9wxJoroUVY1r3XPCjrdHedKBk7rErsZ4+/koCAgJFVqhmfg5WrG2tnOCk 2RIbMYWuTBaFWkUDkZbIYK+JVdq34liwPL8EDLhUQuB+D6LOHLW1lq/qVEO9aesRthxT ZBLZOsZhOV/2yxQ9MhYS1hlawRpUVKyTbXyyM7a+ecRl8pgR5FaQER2okQjI+j/bXjn6 eGBiKOHIYznV3Irc3OP6VUknyoWQ1wQD0rphz5gkyP+cZX3TPZaL4iaivlFYb5wQ8mh6 StZ0Fmk2569ECunXlsU43yQ6iozpqN9KV1he3WsdLo5w7tzPCyBovpk06rFi9rnMDsyi iFSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A4auHl+S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n6-20020a170902f60600b0015d4c2be643si14893019plg.488.2022.06.07.22.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:27:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A4auHl+S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A03CB479932; Tue, 7 Jun 2022 21:53:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348683AbiFGR6J (ORCPT + 99 others); Tue, 7 Jun 2022 13:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347470AbiFGRhx (ORCPT ); Tue, 7 Jun 2022 13:37:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D37AE29813; Tue, 7 Jun 2022 10:33:15 -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 dfw.source.kernel.org (Postfix) with ESMTPS id F131960BC6; Tue, 7 Jun 2022 17:32:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E2B6C385A5; Tue, 7 Jun 2022 17:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623158; bh=/kXF5EwV/X6EjUXiAUV7ID0fOWl4eERfxctu+CQl7TY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A4auHl+SQ98r/yRbzRnSJsdchyDNfFBel/jitQi5hjSwvGm3Gry4HvTnO+7S+g40X /PyGmBpcYQmDL9799h6I0GoL2GuViTHTmxhx1Da/gfuvR97I+FY1kaXUMe7uMEqV1U 5HHYbYbTZYGTzSEG6rep8tg+DOojI7pfmeR9fQxU= 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.10 316/452] RDMA/hfi1: Prevent use of lock before it is initialized Date: Tue, 7 Jun 2022 19:02:53 +0200 Message-Id: <20220607164917.974785343@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 0b73dc7847aa..a044bee257f9 100644 --- a/drivers/infiniband/hw/hfi1/sdma.c +++ b/drivers/infiniband/hw/hfi1/sdma.c @@ -1330,11 +1330,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