Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3396920pxf; Mon, 22 Mar 2021 05:37:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3wW6D8hA9Rw7QTljj4kuC6bZ6WNIaskZNkTQo8XOkZnCchz55Uj4PFz2vdcvSPix2DyCk X-Received: by 2002:a05:6402:375:: with SMTP id s21mr25390693edw.287.1616416633614; Mon, 22 Mar 2021 05:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616416633; cv=none; d=google.com; s=arc-20160816; b=ptO9cP2osnmFPSK6DuXq2uQg4K3EOM7SCVfuOSj+bJhWMA6T8sqPcFk70EsrAqVcUi UeGy3fi4mZ6U2eDOtEbhEm4LcwSOY7WUgmN+N5aFAQyXp9c7RWcDefbTXFnygozQQ4Qs pWT9A8jb3dhKPx4MZlN4l5Geiyl+elY5+N9uyneak+fhzkp9m/Mvaid8vyEBHx7kNdEr eWERX/w0RK0sEGQpHKM/l9tanDVBoW9FnZOmy8oiltXfY3i1mXYgbkiJNsIjso61lov8 WQ5oeb51e4Ja3/Eh5cHbczUR/BBhCMJyiK2RCQhD+238GULLBJzgb4dWgqllKuqnzk0M ebsA== 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=MnDkV0+Kwc4Nt1JQlD9fSiR7ODPTbdEgS72Nq0xSKt8=; b=wPQqCL5Jxvsy5MJnb0ybaSmqVM3URvdDSWI0bvnNeRYF9Mv5rxZEYombAKWC0/YaWa eAM0w4tPaNUKD9r7ud8zxH0gq61wIhppQLnjg9Q28sfBFxqHowzZx06+zjact9rLhh+0 8G4P4idNKQdPN4EOIewZ5+lfoPffgAhLZVQT+ZudwsK1v7tns62CR7Za4I9GaHsJBGv8 vP+pgoDFCE0O1ysc/8VkBzHIOFCzK5UqGAoHKy9SRj2IDQWWTfCpl8CC6G9A5SpNO6QZ pg4rB3US7PJVfWRSJaFYgbvRhtsyeQ7qQ53Kgr7macV9Eb3EOu9ADjhysZ3IXgxq2bvF Q5Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=poqPUtHn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b15si11481963ejv.689.2021.03.22.05.36.51; Mon, 22 Mar 2021 05:37:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=poqPUtHn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231807AbhCVMf4 (ORCPT + 99 others); Mon, 22 Mar 2021 08:35:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:55678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230290AbhCVMdA (ORCPT ); Mon, 22 Mar 2021 08:33:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8C3ED619A8; Mon, 22 Mar 2021 12:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616416380; bh=VdBJmZUaLe0VaDm377AThMdHYlmhbxsnqxyu+AZpJhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=poqPUtHnARdFHxLPRCFj7zavvXBm3ZuNVla2OopYCJBZXv9tLZ6RLJlgg3YtAq6Jk 8XHDu/AUPad87DJBszg3dg6TKHOJ2YPKUZJRlRfDG1MUfnCIUEXqi0UdBP85l/N42i QWzXRlNPt8ewCrBwkct8Ju9QDY5+9tzLmXUzqWIU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chiranjeevi Rapolu , Mika Westerberg Subject: [PATCH 5.11 085/120] thunderbolt: Initialize HopID IDAs in tb_switch_alloc() Date: Mon, 22 Mar 2021 13:27:48 +0100 Message-Id: <20210322121932.517724419@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121929.669628946@linuxfoundation.org> References: <20210322121929.669628946@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mika Westerberg commit 781e14eaa7d168dc07d2a2eea5c55831a5bb46f3 upstream. If there is a failure before the tb_switch_add() is called the switch object is released by tb_switch_release() but at that point HopID IDAs have not yet been initialized. So we see splat like this: BUG: spinlock bad magic on CPU#2, kworker/u8:5/115 ... Workqueue: thunderbolt0 tb_handle_hotplug Call Trace: dump_stack+0x97/0xdc ? spin_bug+0x9a/0xa7 do_raw_spin_lock+0x68/0x98 _raw_spin_lock_irqsave+0x3f/0x5d ida_destroy+0x4f/0x127 tb_switch_release+0x6d/0xfd device_release+0x2c/0x7d kobject_put+0x9b/0xbc tb_handle_hotplug+0x278/0x452 process_one_work+0x1db/0x396 worker_thread+0x216/0x375 kthread+0x14d/0x155 ? pr_cont_work+0x58/0x58 ? kthread_blkcg+0x2e/0x2e ret_from_fork+0x1f/0x40 Fix this by always initializing HopID IDAs in tb_switch_alloc(). Fixes: 0b2863ac3cfd ("thunderbolt: Add functions for allocating and releasing HopIDs") Cc: stable@vger.kernel.org Reported-by: Chiranjeevi Rapolu Signed-off-by: Mika Westerberg Signed-off-by: Greg Kroah-Hartman --- drivers/thunderbolt/switch.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -762,12 +762,6 @@ static int tb_init_port(struct tb_port * tb_dump_port(port->sw->tb, &port->config); - /* Control port does not need HopID allocation */ - if (port->port) { - ida_init(&port->in_hopids); - ida_init(&port->out_hopids); - } - INIT_LIST_HEAD(&port->list); return 0; @@ -1789,10 +1783,8 @@ static void tb_switch_release(struct dev dma_port_free(sw->dma_port); tb_switch_for_each_port(sw, port) { - if (!port->disabled) { - ida_destroy(&port->in_hopids); - ida_destroy(&port->out_hopids); - } + ida_destroy(&port->in_hopids); + ida_destroy(&port->out_hopids); } kfree(sw->uuid); @@ -1972,6 +1964,12 @@ struct tb_switch *tb_switch_alloc(struct /* minimum setup for tb_find_cap and tb_drom_read to work */ sw->ports[i].sw = sw; sw->ports[i].port = i; + + /* Control port does not need HopID allocation */ + if (i) { + ida_init(&sw->ports[i].in_hopids); + ida_init(&sw->ports[i].out_hopids); + } } ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_PLUG_EVENTS);