Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2479087imd; Fri, 2 Nov 2018 12:07:17 -0700 (PDT) X-Google-Smtp-Source: AJdET5eY+SlZ6E5PysmcmE5NklLjMX+ZCMwRb0HJ7TgR/BwIz+OCYa/AHVJLG2yhMmCGwPopWRYN X-Received: by 2002:a17:902:3204:: with SMTP id y4-v6mr12814289plb.135.1541185637912; Fri, 02 Nov 2018 12:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541185637; cv=none; d=google.com; s=arc-20160816; b=kbvu2VczLJhVhL8sTFET7elS701ooOlbA96/EqGFZVSZ4A81lJ3q/T5C312paj1yfd Q9rDUTYWH/IJ9hoy7OjcKlkZ7oM/fYW+LzAalhT46GOshBxiKJE0TKbeqKJ8YtvfbKLF fCJ4qzVdpUeCMPgPojEkL1nH6f/FuTOmhaUxHmUKNblGD7Df4VvDJtSAs70hwg13xiVR xsv7YWfE0s8pB0+2n2WrJ5blx3rdqJtPTtRm5FlnrRRVi/RXRqCnsStoAcSe1/iYvroH ffabbkJg2lCIW33dGiWz+gyQAknFtO9nKfZEV1XbPbWQefaSOmCn0N5pbeAJ+XivPGOt obWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3GZGwrzEOztgPP0m6AFK9FVS0YDprIzkLYzib2QBRew=; b=iQ2i7dOmiO0KYGm573guKaJ1prZ7oJnDjVVuIUagzxFwvvYe9zWsHXL5Ow0d0kyjSB UeXNBvW88NCX95YbcfMo9ZExIWwcccP4TTg+0jvwPYePOvKYJhCTucYeF3hYGha0fjDr QJK3HYpO7OVjsvBvGy23XwFYtkkuAgLoK7ARW5j00o8EygBON+hAXyuPEF2kiFgp2du/ 6F5vnpN7s2puvqBOx1jj7cmuZZ3SYbb9BJdXZcjxm2bP/b7CU3VQ1F+T6TYaeXh1jbfX WnqbKb03VLMmy1Qbf970tv6mTrxCRQV0LH+frtmnGLkMad7/OZd+0Vv3Kaae3JnqiuN+ Kqhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Cm2OZIs0; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13-v6si30126974pfb.155.2018.11.02.12.07.03; Fri, 02 Nov 2018 12:07:17 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Cm2OZIs0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729693AbeKCDuF (ORCPT + 99 others); Fri, 2 Nov 2018 23:50:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:44934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728835AbeKCDuE (ORCPT ); Fri, 2 Nov 2018 23:50:04 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 884F62084D; Fri, 2 Nov 2018 18:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184112; bh=uZg+UwKc1Nk6LyXiPX1IfsxWCNuHjqbPAvrzTLeKRAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cm2OZIs0Sg6WC/mNQ3W09mLPlJQnGlmQfigqSVJcZUVjmrtfQJHVB2pYcdcxIjtyN XXZ68L1t2KpRxH8QKn63sHiWR6mWkl1ipiXI8AiVrzXa8Uix/rxJMvaYqR/yzFHi+/ 9og7kGpcH7EZ+JrvnB5ZufitC0t6wi7U6EKht758= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mika Westerberg , Sasha Levin Subject: [PATCH 4.18 058/150] thunderbolt: Do not handle ICM events after domain is stopped Date: Fri, 2 Nov 2018 19:33:40 +0100 Message-Id: <20181102182907.587708075@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 86da809dda64a63fc27e05a215475325c3aaae92 ] 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 Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- 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 500911f16498..5bad9fdec5f8 100644 --- a/drivers/thunderbolt/icm.c +++ b/drivers/thunderbolt/icm.c @@ -653,14 +653,6 @@ icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr) bool approved; 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; @@ -950,14 +942,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) >> @@ -1317,19 +1301,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.17.1