Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp435064ybb; Thu, 28 Mar 2019 05:38:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNJ71DqIidHp3PQRpcLVlUbHOa6l0dHOeGvDcqoYdanCdWJL7hWdSvjbhJPDLTyvaTfRW6 X-Received: by 2002:a17:902:526:: with SMTP id 35mr40243534plf.276.1553776714176; Thu, 28 Mar 2019 05:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553776714; cv=none; d=google.com; s=arc-20160816; b=Q7RcVTQRBRETTu4l3aDsqLAOKpzwOiinLCpB7G3VFraztds7LAHECTdeSW0g8+lrFY 0A96zIdiPBNpi07vX3+71FjwE7Tgogr9UtJt0HE1G+HHaAe41OoA9aZzKjOKCZyyw9gy 7pmacYgMgmL0LvsNTTEQZeapypo6KtO1/kRXmXVFYb8SR3lbj34QZuWJIoVDGRV6nqrg KTWzZiLOP1mPVHSebUQ5K04j/QRMkV5OMh0OQAi898KuXPbnzJ2jEVXLXx1CxgtB4aGq qamO68paVPdBvhNhlkmoDxb0l2ZZSYKj7S9NfGt9rjlSHxyvU5vaBiviWk2YfExtAYFN pUiA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=R7sdsx+yEPNlv2+V2G4ZTxlh7iZUGnUTYF+dbZL5iGY=; b=ArrDj2NWhJjqswz2hA8UPN76MRCVDJMnYJcD/mGQ+WUAHfV1Icyk+JSd2IeTB2dNKo vYx5VfrCHUz6InN7sFhJ2aAa+m1vsexzKhh6R4AWmzbIgc1WjtZG3tFtq9qIkoAwlS8n /syCkRi8QO/9nY0wOSY7K8iVJtr1p+TlchkQGP+jOaQ5qTOOZx/XV2RrgDidmc6c9Nhr RZMA5VuJzIDkif8kSmQrPlFD+Y99Zk7NnU2rhxp0mPStSeibeSfhCy7ode6354X/rBST 1JxwBRWzteW9O3B85pEf0wEmSEvWPq4MBdRR2LBhFfGzY2aw1H8y5J+5Dem1U5IURiqJ BSkg== 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 p10si21055509plk.413.2019.03.28.05.38.18; Thu, 28 Mar 2019 05:38:34 -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 S1727566AbfC1MhP (ORCPT + 99 others); Thu, 28 Mar 2019 08:37:15 -0400 Received: from mga09.intel.com ([134.134.136.24]:34153 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbfC1Mgs (ORCPT ); Thu, 28 Mar 2019 08:36:48 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2019 05:36:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,280,1549958400"; d="scan'208";a="138136892" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 28 Mar 2019 05:36:42 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 2BC02161E; Thu, 28 Mar 2019 14:36:35 +0200 (EET) From: Mika Westerberg To: linux-kernel@vger.kernel.org Cc: Michael Jamet , Yehezkel Bernat , Andreas Noever , Lukas Wunner , "David S . Miller" , Andy Shevchenko , Christian Kellner , Mario.Limonciello@dell.com, Mika Westerberg , netdev@vger.kernel.org Subject: [PATCH v3 28/36] thunderbolt: Run tb_xdp_handle_request() in system workqueue Date: Thu, 28 Mar 2019 15:36:25 +0300 Message-Id: <20190328123633.42882-29-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190328123633.42882-1-mika.westerberg@linux.intel.com> References: <20190328123633.42882-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We run all XDomain requests during discovery in tb->wq and since it only runs one work at the time it means that sending back reply to the other domain may be delayed too much depending whether there is an active XDomain discovery request running. To make sure we can send reply to the other domain as soon as possible run tb_xdp_handle_request() in system workqueue instead. Since the device can be hot-removed in the middle we need to make sure the domain structure is still around when the function is run so increase reference count before we schedule the reply work. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/tb.h | 7 +++++++ drivers/thunderbolt/xdomain.c | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index dd7808f9de39..19bdeeaf1d18 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -462,6 +462,13 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd); int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd); int tb_domain_disconnect_all_paths(struct tb *tb); +static inline struct tb *tb_domain_get(struct tb *tb) +{ + if (tb) + get_device(&tb->dev); + return tb; +} + static inline void tb_domain_put(struct tb *tb) { put_device(&tb->dev); diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c index 7bae92bc486f..44d3b2e486cd 100644 --- a/drivers/thunderbolt/xdomain.c +++ b/drivers/thunderbolt/xdomain.c @@ -524,6 +524,8 @@ static void tb_xdp_handle_request(struct work_struct *work) out: kfree(xw->pkg); kfree(xw); + + tb_domain_put(tb); } static bool @@ -542,9 +544,9 @@ tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr, kfree(xw); return false; } - xw->tb = tb; + xw->tb = tb_domain_get(tb); - queue_work(tb->wq, &xw->work); + schedule_work(&xw->work); return true; } -- 2.20.1