Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp595409ima; Wed, 6 Feb 2019 05:23:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IYYDAYYHBSMvhbaJ5jr7336fZT3J30SHP/GRWN+fEEbz6VMt7/HmLrPjHEo2Yb/J0yTF7mb X-Received: by 2002:a17:902:9f89:: with SMTP id g9mr10740321plq.214.1549459417799; Wed, 06 Feb 2019 05:23:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549459417; cv=none; d=google.com; s=arc-20160816; b=JrNo94ZgJ5k8G4mqKf9eCQzqj5LRJT2zY/0LGY6QuxDt+n3SHdVCs2h48AiEqSo8hY rm6ch4Sf1De+7F3GuRdr2dLUSboxw2tu2styG7PKU8pNMDuu9e/qLvgRz0MAWwx18qjk eeOrTHAi1Sy0AJjpXZ6uCCI8amtWrDMXG4jNWd3KjiP070+gWWCNe331nvJq8xyIuGQL yUDHyQamb8PcTQ+kgtTBEQ2dYNTDv+th8oz5uar5gkv4mw+ePx67aoYa0VKvudMhBKRC 2yb6gDhdfQ1pAPb0KJLDyaK0ZL4kC6e5I4bq/YmnKcZRpqowoiQYbLvwHaNj2glTgsTG 122g== 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=M/MHZgowr+dJRQki8veZ5wjs1X2PAVS7v7aa96F3C2Q=; b=kN7H4J8iDHoZ1M/hcovhB/lA23G6OBKznkZ0dsN9Mwt9PCtDBK2senfwfp8q7A33ay dEktBczhFCihYz0NOGvm1RE714FZH7ZK4Wk4D69lQlfJYIPWpSY+RnVhbMv7sIFwtbgk jrmH5S7DkUWN9dKLIsotlWPss+p8lIqWBdzyJVLd7MUJTTJYAtJycbZM1jRtUNT+Ce9U mdsUToKUKqy1w4ldwWbbiRCpnoBKlXKB2yRfG2Ecvvxldj/vAnx1VZtAE/Le8d9qANdZ bGO6OMsqxqUHZ8rLCGPOB4lZwcCUP9eKEuA63w+pxVQE9jV17eTJfmynMh3JKek5hONH XI1w== 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 y12si5823146plk.174.2019.02.06.05.23.21; Wed, 06 Feb 2019 05:23:37 -0800 (PST) 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 S1730937AbfBFNV2 (ORCPT + 99 others); Wed, 6 Feb 2019 08:21:28 -0500 Received: from mga14.intel.com ([192.55.52.115]:26742 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730587AbfBFNRs (ORCPT ); Wed, 6 Feb 2019 08:17:48 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2019 05:17:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,340,1544515200"; d="scan'208";a="316787169" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 06 Feb 2019 05:17:45 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 6886D806; Wed, 6 Feb 2019 15:17:39 +0200 (EET) From: Mika Westerberg To: linux-kernel@vger.kernel.org Cc: Michael Jamet , Yehezkel Bernat , Andreas Noever , Lukas Wunner , "David S . Miller" , Mika Westerberg , Andy Shevchenko , netdev@vger.kernel.org Subject: [PATCH v2 22/28] thunderbolt: Run tb_xdp_handle_request() in system workqueue Date: Wed, 6 Feb 2019 16:17:32 +0300 Message-Id: <20190206131738.43696-23-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190206131738.43696-1-mika.westerberg@linux.intel.com> References: <20190206131738.43696-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 e06e5a944998..7e155eed1fee 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -410,6 +410,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 e27dd8beb94b..59789bdd93ac 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 void @@ -538,9 +540,9 @@ tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr, INIT_WORK(&xw->work, tb_xdp_handle_request); xw->pkg = kmemdup(hdr, size, GFP_KERNEL); - xw->tb = tb; + xw->tb = tb_domain_get(tb); - queue_work(tb->wq, &xw->work); + schedule_work(&xw->work); } /** -- 2.20.1