Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1662423imm; Mon, 3 Sep 2018 06:22:18 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbuvizFvUcqC1JoyjiyDZq2V/n0j7UO/XENnr3XhFKkk7yvh5MNbdKQzWBNQLyk0KDbGOTo X-Received: by 2002:a63:df04:: with SMTP id u4-v6mr26635672pgg.434.1535980938700; Mon, 03 Sep 2018 06:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535980938; cv=none; d=google.com; s=arc-20160816; b=vZ97XhonRMfoqr4gdC7UqkK6YA9+jzr3ORt1CuXd8opDnwjCimPepFsJyx7b7WgxPl y5dgDV5V0zOgJT9HiB1LWrVKIL2USJXGQ5WKNFHEfQ8diCo6GqujTXSdpLI1pOBUiD7d ZSAqY/aXff1yfYqHiILeNoY/YkZbPrY0Z80MZnSqQXwJTkEDLkbS9kLPPoCom7yB4UXv ZiE0jTBXS/EbuUiud5rNyCkJWwocrofwK1wpGH8hSXyKa/upPhRHhCTbAkfeny2qmrt1 LmxItaysXjgFXIItmf07eYymQkcOSx7JY0HdFTC9gYBF+AJiyv1pajplEYmSiSUD4CnG x7zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=J/Y7GG46d2ZCvMuV3ngG2nKpj5lpHz1eSV9/uCyG43Q=; b=yZiVEOP5a9QKPBbEOLYTwoQK35G49vH8i4eiPBE5/wttzOYdC2M0zmAKOdavjEVw92 DxrJPUAIgWi6K54ebSIW5O8hKijx0a/E3HX+qsns0Yxeg6TL7/KYh8ykg85xNADqXjdJ ka9Kd3DTXFOCecYH+t2vGDGtmZOpDxCAmt4aEna521yuuxnG4zzDqITjsLlT/oBn+fLD lXEd2PEIWLGmqV1w+eo/uEdXcY09Rf5DdoASBXHQzhTLaR0FOxZR/OtajS3sKZJ5ae+X A62alzxhSj6zd1CF50MkQMvFTPf9fSsioid7DKT24J6pKYMUlY7Z/oo3qYatE/7YlNlm Mj2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e27-v6si18045336pgn.253.2018.09.03.06.22.03; Mon, 03 Sep 2018 06:22:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727296AbeICRk0 (ORCPT + 99 others); Mon, 3 Sep 2018 13:40:26 -0400 Received: from mga01.intel.com ([192.55.52.88]:9845 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725794AbeICRk0 (ORCPT ); Mon, 3 Sep 2018 13:40:26 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Sep 2018 06:20:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,325,1531810800"; d="scan'208";a="71235935" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 03 Sep 2018 06:20:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 6C44F124; Mon, 3 Sep 2018 16:20:12 +0300 (EEST) From: Mika Westerberg To: linux-kernel@vger.kernel.org Cc: Andreas Noever , Michael Jamet , Mika Westerberg , Yehezkel Bernat , Lukas Wunner , Lu Baolu Subject: [PATCH 1/2] thunderbolt: Do not handle ICM events after domain is stopped Date: Mon, 3 Sep 2018 16:20:11 +0300 Message-Id: <20180903132012.23531-1-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.18.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If there is a long chain of devices connected when the driver is loaded ICM sends device connected event for each and those are put to tb->wq for later processing. Now if the driver gets unloaded in the middle, so that the work queue is not yet empty it gets flushed by tb_domain_stop(). However, by that time the root switch is already removed so the driver crashes when it tries to dereference it in ICM event handling callbacks. Fix this by checking whether the root switch is already removed. If it is we know that the domain is stopped and we should merely skip handling the event. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/icm.c | 49 ++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c index e1e264a9a4c7..28fc4ce75edb 100644 --- a/drivers/thunderbolt/icm.c +++ b/drivers/thunderbolt/icm.c @@ -738,14 +738,6 @@ icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr) u8 link, depth; u64 route; - /* - * After NVM upgrade adding root switch device fails because we - * initiated reset. During that time ICM might still send - * XDomain connected message which we ignore here. - */ - if (!tb->root_switch) - return; - link = pkg->link_info & ICM_LINK_INFO_LINK_MASK; depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >> ICM_LINK_INFO_DEPTH_SHIFT; @@ -1037,14 +1029,6 @@ icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) if (pkg->hdr.packet_id) return; - /* - * After NVM upgrade adding root switch device fails because we - * initiated reset. During that time ICM might still send device - * connected message which we ignore here. - */ - if (!tb->root_switch) - return; - route = get_route(pkg->route_hi, pkg->route_lo); authorized = pkg->link_info & ICM_LINK_INFO_APPROVED; security_level = (pkg->hdr.flags & ICM_FLAGS_SLEVEL_MASK) >> @@ -1408,19 +1392,26 @@ static void icm_handle_notification(struct work_struct *work) mutex_lock(&tb->lock); - switch (n->pkg->code) { - case ICM_EVENT_DEVICE_CONNECTED: - icm->device_connected(tb, n->pkg); - break; - case ICM_EVENT_DEVICE_DISCONNECTED: - icm->device_disconnected(tb, n->pkg); - break; - case ICM_EVENT_XDOMAIN_CONNECTED: - icm->xdomain_connected(tb, n->pkg); - break; - case ICM_EVENT_XDOMAIN_DISCONNECTED: - icm->xdomain_disconnected(tb, n->pkg); - break; + /* + * When the domain is stopped we flush its workqueue but before + * that the root switch is removed. In that case we should treat + * the queued events as being canceled. + */ + if (tb->root_switch) { + switch (n->pkg->code) { + case ICM_EVENT_DEVICE_CONNECTED: + icm->device_connected(tb, n->pkg); + break; + case ICM_EVENT_DEVICE_DISCONNECTED: + icm->device_disconnected(tb, n->pkg); + break; + case ICM_EVENT_XDOMAIN_CONNECTED: + icm->xdomain_connected(tb, n->pkg); + break; + case ICM_EVENT_XDOMAIN_DISCONNECTED: + icm->xdomain_disconnected(tb, n->pkg); + break; + } } mutex_unlock(&tb->lock); -- 2.18.0