Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4756065imu; Tue, 29 Jan 2019 07:03:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN4qTka19LeGOa7+VyLl0kneVofa5Kt6dngyzuKSGOSpxJe8h/H8Djr7MQc3PYkmldQWZv9B X-Received: by 2002:a63:a16:: with SMTP id 22mr23977655pgk.318.1548774192634; Tue, 29 Jan 2019 07:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548774192; cv=none; d=google.com; s=arc-20160816; b=L4mu6luVjYQ30+tcaNxeMu4Hjx/QNPeIfN23SGnHWVjSpHbaMJH9bKZzbn09GCLuZf mcSKWQPJyy3KaAEZrZsbEBRbnUQTh42LAdryepL/WhzZKtJkocHH13Za8Z3ATe8bvGZ7 32yqxHdxqqQ4TWRnxtbJxhY5gdDqUnQ4DA0PNe3cX3OfDiIPB+exvi28Andb0hkrauia izi8NSxAWUjSikxMzCTwAA7kHyAK5eJOhrxTOgUF3D/cmh5mkt0rRW1jrOjaX75ALhBP LlVLJsnN4IWEydD7gt/oOex7XvCd0lm7oyG6ObTUBtTAIkXLiYX4E+SPPoBzmR6ddj2o BpWQ== 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=YDOslvIMqOWVjS/5Ewf21KINcXBgvrkJh3A+xj3OapQ=; b=ktLBs96kLDz+JJuLTCa+x3TreluKuf8zwkveL+7w1oterh/04vSi/kXd/hIswGyXAV P8V8fSgtDKmhtym8fHbm8YSrNExQSt/uYDQkLHI4KJAb4MCIZ/doLa6e8p7Aq5s3jA5c w2PugsI6+gX70DuWUTNPkgYpgLx5BNagS3nf9MbrQ3XKcwHkUEC757M8I/5obrWZHUiE sYaVYdaUYjVp7EK1LMel6eGrKF+mu2qdn4y3VJ5zEPJW73y+ZIPefNR3FE2PENbUXfdb I40umoxZQqDIGjpHGLQKq2MIg+KNjW8Zjopf3tzVIImx37y4oqgkMfIsT5ab74RQqI+x dLrg== 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 90si36964866plb.17.2019.01.29.07.02.55; Tue, 29 Jan 2019 07:03:12 -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 S1728745AbfA2PCS (ORCPT + 99 others); Tue, 29 Jan 2019 10:02:18 -0500 Received: from mga17.intel.com ([192.55.52.151]:45434 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728550AbfA2PB4 (ORCPT ); Tue, 29 Jan 2019 10:01:56 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2019 07:01:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,537,1539673200"; d="scan'208";a="113610583" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 29 Jan 2019 07:01:52 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 4127AB6D; Tue, 29 Jan 2019 17:01:45 +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 22/28] thunderbolt: Run tb_xdp_handle_request() in system workqueue Date: Tue, 29 Jan 2019 18:01:37 +0300 Message-Id: <20190129150143.12681-23-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129150143.12681-1-mika.westerberg@linux.intel.com> References: <20190129150143.12681-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 7b6d1428bfad..a85b92a6936b 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -411,6 +411,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