From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Andreas Noever <andreas.noever@gmail.com>,
Michael Jamet <michael.jamet@intel.com>,
Yehezkel Bernat <yehezkel.bernat@intel.com>,
Lukas Wunner <lukas@wunner.de>,
Amir Levy <amir.jer.levy@intel.com>,
Andy Lutomirski <luto@kernel.org>,
Mario.Limonciello@dell.com, Jared.Dominguez@dell.com,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 15/24] thunderbolt: Rework control channel to be more reliable
Date: Thu, 25 May 2017 15:25:46 +0200 [thread overview]
Message-ID: <20170525132546.GI16244@kroah.com> (raw)
In-Reply-To: <20170518143914.60902-16-mika.westerberg@linux.intel.com>
On Thu, May 18, 2017 at 05:39:05PM +0300, Mika Westerberg wrote:
> If a request times out the response might arrive right after the request
> is failed. This response is pushed to the kfifo and next request will
> read it instead. Since it most likely will not pass our validation
> checks in parse_header() the next request will fail as well, and
> response to that request will be pushed to the kfifo, ad infinitum.
>
> We end up in a situation where all requests fail and no devices can be
> added anymore until the driver is unloaded and reloaded again.
>
> To overcome this, rework the control channel so that we will have a
> queue of outstanding requests. Each request will be handled in turn and
> the response is validated against what is expected. Unexpected packets
> (for example responses for requests that have been timed out) are
> dropped. This model is copied from Greybus implementation with small
> changes here and there to get it cope with Thunderbolt control packets.
>
> In addition the configuration packets support sequence number which the
> switch is supposed to copy from the request to response. We use this to
> drop responses that are already timed out. Taking advantage of the
> sequence number, we automatically retry configuration read/write 4 times
> before giving up.
>
> Also timeout is not a programming error so there is no need to trigger a
> scary backtrace (WARN), instead we just log a warning. After all
> Thunderbolt devices are hot-pluggable by definition which means user can
> unplug a device any time and that is totally acceptable.
>
> With this change there is no need to take the global domain lock when
> sending configuration packets anymore. This is useful when we add
> support for cross-domain (XDomain) communication later on.
>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Reviewed-by: Yehezkel Bernat <yehezkel.bernat@intel.com>
> Reviewed-by: Michael Jamet <michael.jamet@intel.com>
> ---
> drivers/thunderbolt/ctl.c | 471 +++++++++++++++++++++++++++++++++++++++-------
> drivers/thunderbolt/ctl.h | 65 +++++++
> drivers/thunderbolt/tb.h | 2 +-
> 3 files changed, 467 insertions(+), 71 deletions(-)
>
> diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c
> index b3ee755fdb37..2b1255cbf3c9 100644
> --- a/drivers/thunderbolt/ctl.c
> +++ b/drivers/thunderbolt/ctl.c
> @@ -5,22 +5,17 @@
> */
>
> #include <linux/crc32.h>
> +#include <linux/delay.h>
> #include <linux/slab.h>
> #include <linux/pci.h>
> #include <linux/dmapool.h>
> #include <linux/workqueue.h>
> -#include <linux/kfifo.h>
>
> #include "ctl.h"
>
>
> -struct ctl_pkg {
> - struct tb_ctl *ctl;
> - void *buffer;
> - struct ring_frame frame;
> -};
> -
> -#define TB_CTL_RX_PKG_COUNT 10
> +#define TB_CTL_RX_PKG_COUNT 10
> +#define TB_CTL_RETRIES 4
>
> /**
> * struct tb_cfg - thunderbolt control channel
> @@ -32,8 +27,9 @@ struct tb_ctl {
>
> struct dma_pool *frame_pool;
> struct ctl_pkg *rx_packets[TB_CTL_RX_PKG_COUNT];
> - DECLARE_KFIFO(response_fifo, struct ctl_pkg*, 16);
> - struct completion response_ready;
> + struct mutex request_lock;
> + struct list_head request_queue;
> + bool running;
>
> event_cb callback;
> void *callback_data;
> @@ -55,10 +51,115 @@ struct tb_ctl {
> #define tb_ctl_dbg(ctl, format, arg...) \
> dev_dbg(&(ctl)->nhi->pdev->dev, format, ## arg)
>
> +static DECLARE_WAIT_QUEUE_HEAD(tb_cfg_request_cancel_queue);
> +
> +/**
> + * tb_cfg_request_alloc() - Allocates a new config request
> + *
> + * This is refcounted object so when you are done with this, call
> + * tb_cfg_request_put() to it.
> + */
> +struct tb_cfg_request *tb_cfg_request_alloc(void)
> +{
> + struct tb_cfg_request *req;
> +
> + req = kzalloc(sizeof(*req), GFP_KERNEL);
> + if (!req)
> + return NULL;
> +
> + kref_init(&req->kref);
> +
> + return req;
> +}
> +
> +/**
> + * tb_cfg_request_get() - Increase refcount of a request
> + * @req: Request whose refcount is increased
> + */
> +void tb_cfg_request_get(struct tb_cfg_request *req)
> +{
> + kref_get(&req->kref);
> +}
> +
> +static void tb_cfg_request_destroy(struct kref *kref)
> +{
> + struct tb_cfg_request *req = container_of(kref, typeof(*req), kref);
> +
> + kfree(req);
> +}
> +
> +/**
> + * tb_cfg_request_put() - Decrease refcount and possibly release the request
> + * @req: Request whose refcount is decreased
> + *
> + * Call this function when you are done with the request. When refcount
> + * goes to %0 the object is released.
> + */
> +void tb_cfg_request_put(struct tb_cfg_request *req)
> +{
> + kref_put(&req->kref, tb_cfg_request_destroy);
> +}
What prevents this call from being called twice on the same object from
different threads at the same time? You still need a lock somewhere to
protect yourself from that, am I just missing where that lock is?
thanks,
greg k-h
next prev parent reply other threads:[~2017-05-25 13:25 UTC|newest]
Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-18 14:38 [PATCH 00/24] Thunderbolt security levels and NVM firmware upgrade Mika Westerberg
2017-05-18 14:38 ` [PATCH 01/24] thunderbolt: Use const buffer pointer in write operations Mika Westerberg
2017-05-25 13:19 ` Greg Kroah-Hartman
2017-05-18 14:38 ` [PATCH 02/24] thunderbolt: Do not try to read UID if DROM offset is read as 0 Mika Westerberg
2017-05-21 13:46 ` Andreas Noever
2017-05-22 8:40 ` Mika Westerberg
2017-05-22 18:41 ` Andreas Noever
2017-05-22 20:38 ` Mika Westerberg
2017-05-22 20:57 ` Andreas Noever
2017-05-18 14:38 ` [PATCH 03/24] thunderbolt: Do not warn about newer DROM versions Mika Westerberg
2017-05-18 14:38 ` [PATCH 04/24] thunderbolt: Add MSI-X support Mika Westerberg
2017-05-21 17:51 ` Andreas Noever
2017-05-22 8:52 ` Mika Westerberg
2017-05-22 10:35 ` Bernat, Yehezkel
2017-05-22 11:01 ` Mika Westerberg
2017-05-18 14:38 ` [PATCH 05/24] thunderbolt: Rework capability handling Mika Westerberg
2017-05-18 16:38 ` Andy Shevchenko
2017-05-19 8:12 ` Mika Westerberg
2017-05-19 13:18 ` Andy Shevchenko
2017-05-21 19:09 ` Andreas Noever
2017-05-22 9:45 ` Mika Westerberg
2017-05-22 9:58 ` Levy, Amir (Jer)
2017-05-25 6:13 ` Lukas Wunner
2017-05-18 14:38 ` [PATCH 06/24] thunderbolt: Introduce thunderbolt bus and connection manager Mika Westerberg
2017-05-18 16:43 ` Andy Shevchenko
2017-05-19 8:15 ` Mika Westerberg
2017-05-19 13:16 ` Andy Shevchenko
2017-05-24 10:28 ` Lukas Wunner
2017-05-24 10:39 ` Mika Westerberg
2017-05-25 13:23 ` Greg Kroah-Hartman
2017-05-25 14:42 ` Mika Westerberg
2017-05-18 14:38 ` [PATCH 07/24] thunderbolt: Convert switch to a device Mika Westerberg
2017-05-18 16:49 ` Andy Shevchenko
2017-05-19 8:20 ` Mika Westerberg
2017-05-24 11:09 ` Lukas Wunner
2017-05-24 11:43 ` Mika Westerberg
2017-05-24 13:53 ` Lukas Wunner
2017-05-25 6:57 ` Mika Westerberg
2017-05-18 14:38 ` [PATCH 08/24] thunderbolt: Fail switch adding operation if reading DROM fails Mika Westerberg
2017-05-18 14:38 ` [PATCH 09/24] thunderbolt: Do not fail if DROM data CRC32 is invalid Mika Westerberg
2017-05-18 14:39 ` [PATCH 10/24] thunderbolt: Read vendor and device name from DROM Mika Westerberg
2017-05-18 19:19 ` Andy Shevchenko
2017-05-19 8:22 ` Mika Westerberg
2017-05-19 10:07 ` Lukas Wunner
2017-05-19 10:28 ` Mika Westerberg
2017-05-21 5:31 ` Lukas Wunner
2017-05-21 7:48 ` Mika Westerberg
2017-05-21 9:33 ` Lukas Wunner
2017-05-18 14:39 ` [PATCH 11/24] thunderbolt: Move control channel messages to tb_msgs.h Mika Westerberg
2017-05-18 14:39 ` [PATCH 12/24] thunderbolt: Expose get_route() to other files Mika Westerberg
2017-05-18 14:39 ` [PATCH 13/24] thunderbolt: Expose make_header() " Mika Westerberg
2017-05-18 14:39 ` [PATCH 14/24] thunderbolt: Let the connection manager handle all notifications Mika Westerberg
2017-05-24 14:00 ` Lukas Wunner
2017-05-25 7:02 ` Mika Westerberg
2017-05-18 14:39 ` [PATCH 15/24] thunderbolt: Rework control channel to be more reliable Mika Westerberg
2017-05-25 13:25 ` Greg Kroah-Hartman [this message]
2017-05-25 14:35 ` Mika Westerberg
2017-05-18 14:39 ` [PATCH 16/24] thunderbolt: Add Thunderbolt 3 PCI IDs Mika Westerberg
2017-05-18 14:39 ` [PATCH 17/24] thunderbolt: Add support for NHI mailbox Mika Westerberg
2017-05-18 14:39 ` [PATCH 18/24] thunderbolt: Store Thunderbolt generation in the switch structure Mika Westerberg
2017-05-21 4:47 ` Lukas Wunner
2017-05-21 5:29 ` Levy, Amir (Jer)
2017-05-21 5:35 ` Lukas Wunner
2017-05-21 7:40 ` Mika Westerberg
2017-05-21 8:00 ` Mika Westerberg
2017-05-21 8:07 ` Levy, Amir (Jer)
2017-05-21 9:55 ` Bernat, Yehezkel
2017-05-21 10:47 ` Mika Westerberg
2017-05-21 11:18 ` Bernat, Yehezkel
2017-05-21 11:47 ` Mika Westerberg
2017-05-21 10:44 ` Mika Westerberg
2017-05-18 14:39 ` [PATCH 19/24] thunderbolt: Add support for DMA configuration based mailbox Mika Westerberg
2017-05-18 14:39 ` [PATCH 20/24] thunderbolt: Do not touch the hardware if the NHI is gone on resume Mika Westerberg
2017-05-24 14:43 ` Lukas Wunner
2017-05-25 7:10 ` Mika Westerberg
2017-05-18 14:39 ` [PATCH 21/24] thunderbolt: Add support for Internal Connection Manager (ICM) Mika Westerberg
2017-05-18 14:39 ` [PATCH 22/24] thunderbolt: Add support for host and device NVM firmware upgrade Mika Westerberg
2017-05-18 19:35 ` Andy Shevchenko
2017-05-19 8:26 ` Mika Westerberg
2017-05-25 13:28 ` Greg Kroah-Hartman
2017-05-25 14:39 ` Mika Westerberg
2017-05-25 14:57 ` Greg Kroah-Hartman
2017-05-18 14:39 ` [PATCH 23/24] thunderbolt: Add documentation how Thunderbolt bus can be used Mika Westerberg
2017-05-18 14:39 ` [PATCH 24/24] MAINTAINERS: Add maintainers for Thunderbolt driver Mika Westerberg
2017-05-19 16:35 ` [PATCH 00/24] Thunderbolt security levels and NVM firmware upgrade Mario.Limonciello
2017-05-19 17:19 ` Mika Westerberg
2017-05-19 17:54 ` Mario.Limonciello
2017-05-20 8:24 ` Mika Westerberg
2017-05-22 11:37 ` Mika Westerberg
2017-05-22 20:07 ` Mario.Limonciello
2017-05-22 20:10 ` Bernat, Yehezkel
2017-05-22 23:54 ` Mario.Limonciello
2017-05-22 20:48 ` Mika Westerberg
2017-05-23 17:30 ` Mario.Limonciello
2017-05-24 11:11 ` Mika Westerberg
2017-05-24 19:06 ` Mario.Limonciello
2017-05-24 19:32 ` Jamet, Michael
2017-05-25 7:20 ` mika.westerberg
2017-05-25 8:04 ` mika.westerberg
2017-05-25 12:03 ` mika.westerberg
2017-08-11 15:13 ` mika.westerberg
2017-05-25 7:19 ` Mika Westerberg
2017-05-19 18:00 ` Mika Westerberg
2017-05-20 9:15 ` Levy, Amir (Jer)
2017-05-21 8:08 ` mika.westerberg
2017-05-23 13:25 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170525132546.GI16244@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=Jared.Dominguez@dell.com \
--cc=Mario.Limonciello@dell.com \
--cc=amir.jer.levy@intel.com \
--cc=andreas.noever@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=luto@kernel.org \
--cc=michael.jamet@intel.com \
--cc=mika.westerberg@linux.intel.com \
--cc=yehezkel.bernat@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome