Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp50695ybb; Thu, 9 Apr 2020 17:02:10 -0700 (PDT) X-Google-Smtp-Source: APiQypKLjYDi8hzUfOBFfvvlFGNZ/nc19Ng91PSl9/qMfelv0qq8nWIUHwmJk9+CAL5Eaq8j3s7H X-Received: by 2002:ae9:f00a:: with SMTP id l10mr1595823qkg.169.1586476930113; Thu, 09 Apr 2020 17:02:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586476930; cv=none; d=google.com; s=arc-20160816; b=tGEpMy79y78mPtwJlc+qqL8w37xv5JqOJx/8U1rd2WbjgufAk72TGaZ7wXCcZntnpC OZzc4AModcy+e7w1Xha8R3BWta7SNXwwBIpxWbzuilo/fG/3P51OBOv2OxZVDRs5+p9q trvV7PJNjDkEyglnMyzdEBROsU56uxDfxSr/Il+VUoKpUYKsBNUKlyjunyz/jm3dWnC1 455IoYMB6Dp7unCbgXhnuNhNbvX5tXnnmuuuAEVg9rWpohDX7NvtDarsBcX1VwAH8Zfm Be5szh3HFGSuKH5mnK9WASxm/mC0b4N6u0EfPg42q+0anVpAuSSvRZt/CzG64MxxUB2v nWEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=savnQiNafTj4VsSOknzzkJIynCZPv9JUHy5bAOzJVPE=; b=rRSZ8/uxJjihwr6qXnzgzDToZn8v8YcyWdQ57OwniJ2XALkw6OOV4YFUI6og18PDM4 6CzyBt6FuF+ytJhtm2KxABpkhI5v1QtXXbodY3wkQts5VNnesgQ9kD6wAr6esDZmMs9k wTsISpcOePvpYA9+SwxqMQaKko6T99LazWBO6uXNu1eCtE6z+u77DmFtSpYMHmLVJfYm J+WHdR8cYKaDb/tQiRwtzEvrFAi8jE9qLVTYazmE0aKtSGyZEsA7JXabU1LMOBZy0lW2 MSDJSksNGnp6gxwc7oSoP1td/YZ7rNFq+KvTROdItbsHFyUDKBBti/e6ZY7IMZfLPTIH 39TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RS9CCriI; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4si402025qka.207.2020.04.09.17.01.53; Thu, 09 Apr 2020 17:02:10 -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=@google.com header.s=20161025 header.b=RS9CCriI; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726942AbgDIX7V (ORCPT + 99 others); Thu, 9 Apr 2020 19:59:21 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:39405 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726779AbgDIX7U (ORCPT ); Thu, 9 Apr 2020 19:59:20 -0400 Received: by mail-yb1-f195.google.com with SMTP id h205so350349ybg.6 for ; Thu, 09 Apr 2020 16:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=savnQiNafTj4VsSOknzzkJIynCZPv9JUHy5bAOzJVPE=; b=RS9CCriIfEcjaZ6wcIuA/ZK/Zri35Y+T6epBYFTgcu9gbEkE+Wh08hFf68eAB6pj3O M4oX/A1AUrWD4q4f4hqvv8rbCEQAXvujljM6MEO/kHIglcj0QBbOTcNa5f95P5ofSx6I eAfi1K1McutoyHw84tA4PIa8OpKfW6BymyCi5keNAvnGydkJvU8eROcdWr4VYRxiwKYq g8ukpXS5V4QSVHAFkIxZtjVm17KMUqU74J7j1YOzGhjqFh4145fNLTHcgT5ORw1NmVqf QqGBr0tWXBdFxrTmsCEeh0/67JF6Dla4lojSd9ucmkUk7w5CRFNUYLL/dp44bv3bJfaJ UDdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=savnQiNafTj4VsSOknzzkJIynCZPv9JUHy5bAOzJVPE=; b=uJk5bBW/1cPWvwFdhQH8n5QoCeEBJO6ztlz9s9E/O/8ha3D1y2vcKQRz1XU4jStlHV +nESdsabpFKguVWEKxjmWHRu1AXXpTP0uQKCKgjli7HspqkOKaQb90KzuqhOzHNh5urO 0G/Kwf2YSWHqZkU6lTR9xPhWozL09lsJRWReD3mp5E+dYEnFc8z4U9MR/3xUwD+HU6IE Ak4OlbMu9OlwufPCKuGyKtCt87fzWFIdE9FzJUvvIVgQ/AXVkgGSuuQBbhbPnMcoh/6L nrJENrCax6npWknykVxICOtWqwlcEvIk5J9LCSWqGe1UhMouvGmJt09gQUFp+WK+uBv1 AEsw== X-Gm-Message-State: AGi0PuY0yYU25znacT9OJI3ErNg0KsYlOBebMXjfB6c6FLUiyG4KvctO ph87XFNMUA/1kg8KUHjVB8ntvJlwIhQsRJlrwY0Otw== X-Received: by 2002:a25:ab2e:: with SMTP id u43mr3612207ybi.453.1586476758097; Thu, 09 Apr 2020 16:59:18 -0700 (PDT) MIME-Version: 1.0 References: <20200408181638.184559-1-mathewk@chromium.org> In-Reply-To: From: Mat King Date: Thu, 9 Apr 2020 17:59:07 -0600 Message-ID: Subject: Re: [PATCH 1/2] platform/chrome: skip old cros_ec responses To: Enric Balletbo i Serra Cc: Mathew King , Linux Kernel Mailing List , Jett Rink , Benson Leung , Guenter Roeck Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 9, 2020 at 4:42 PM Enric Balletbo i Serra wrote: > > Hi Mathew, > > Thanks for your patch. > > On 8/4/20 20:16, Mathew King wrote: > > From: Jett Rink > > > > The ISHTP layer can give us old responses that we already gave up on. We > > do not want to interpret these old responses as the current response we > > are waiting for. > > > > Looking at the code and with the above explanation I am not sure I get what is > doing this patch, could you explain a bit more, thanks. The cros_ish should only have one request in flight at a time, we send the request and wait for the response from the ISH. If the ISH is too slow to respond we give up on that request and we can send a new request. The ISH may still send the response to the request that timed out and without this patch we would treat the old response as the response to the current command. This is a condition that should not normally happen but we have seen it with a bad ISH image. So we just add an Id to the request header which is copied into the response header when the ISH processes the message to ensure that response is for the current request. > > > Signed-off-by: Jett Rink > > Signed-off-by: Mathew King > > --- > > drivers/platform/chrome/cros_ec_ishtp.c | 32 ++++++++++++++++++------- > > 1 file changed, 23 insertions(+), 9 deletions(-) > > > > diff --git a/drivers/platform/chrome/cros_ec_ishtp.c b/drivers/platform/chrome/cros_ec_ishtp.c > > index 93a71e93a2f1..6f90deb5cf55 100644 > > --- a/drivers/platform/chrome/cros_ec_ishtp.c > > +++ b/drivers/platform/chrome/cros_ec_ishtp.c > > @@ -48,7 +48,8 @@ static const guid_t cros_ish_guid = > > struct header { > > u8 channel; > > u8 status; > > - u8 reserved[2]; > > + u8 id; > > + u8 reserved; > > } __packed; > > > > struct cros_ish_out_msg { > > @@ -90,6 +91,7 @@ static DECLARE_RWSEM(init_lock); > > * data exceeds this value, we log an error. > > * @size: Actual size of data received from firmware. > > * @error: 0 for success, negative error code for a failure in process_recv(). > > + * @expected_id: Expected id for response that we are waiting on. > > * @received: Set to true on receiving a valid firmware response to host command > > * @wait_queue: Wait queue for host to wait for firmware response. > > */ > > @@ -98,6 +100,7 @@ struct response_info { > > size_t max_size; > > size_t size; > > int error; > > + u8 expected_id; > > bool received; > > wait_queue_head_t wait_queue; > > }; > > @@ -162,6 +165,7 @@ static int ish_send(struct ishtp_cl_data *client_data, > > u8 *out_msg, size_t out_size, > > u8 *in_msg, size_t in_size) > > { > > + static u8 current_id; > > int rv; > > struct header *out_hdr = (struct header *)out_msg; > > struct ishtp_cl *cros_ish_cl = client_data->cros_ish_cl; > > @@ -174,8 +178,11 @@ static int ish_send(struct ishtp_cl_data *client_data, > > client_data->response.data = in_msg; > > client_data->response.max_size = in_size; > > client_data->response.error = 0; > > + client_data->response.expected_id = ++current_id; > > So on every ish_send call this variable is increased in a range 1 to 255 first, > then overflows and goes from 0 to 255. Is this what you want to do? On our internal code review this was switched from a post increment to a pre increment so that the variable name made sense. The id itself doesn't really matter as long as it is changed every response. We could also call it next_id and do a post increment and then we would start at 0. Do you have preference? > > > client_data->response.received = false; > > > > + out_hdr->id = client_data->response.expected_id; > > + > > rv = ishtp_cl_send(cros_ish_cl, out_msg, out_size); > > if (rv) { > > dev_err(cl_data_to_dev(client_data), > > @@ -249,17 +256,23 @@ static void process_recv(struct ishtp_cl *cros_ish_cl, > > > > switch (in_msg->hdr.channel) { > > case CROS_EC_COMMAND: > > - /* Sanity check */ > > - if (!client_data->response.data) { > > + if (client_data->response.received) { > > dev_err(dev, > > - "Receiving buffer is null. Should be allocated by calling function\n"); > > - client_data->response.error = -EINVAL; > > - goto error_wake_up; > > + "Previous firmware message not yet processed\n"); > > + goto end_error; > > } > > > > - if (client_data->response.received) { > > + if (client_data->response.expected_id != in_msg->hdr.id) { > > And here you compare that the response received matches with the message id. I > assume the ISH is sending a sequential id on every message? The ISH will copy the id from the request to the id of the response > > > dev_err(dev, > > - "Previous firmware message not yet processed\n"); > > + "Dropping old response id %d\n", > > + in_msg->hdr.id); > > > How often this message appears? Since we have stabilized our ISH code it rarely happens if ever. If it does happen it indicates an error in the ISH code or the driver code but we still want to attempt to recover gracefully if possible. > > > + goto end_error; > > + } > > + > > + /* Sanity check */ > > + if (!client_data->response.data) { > > + dev_err(dev, > > + "Receiving buffer is null. Should be allocated by calling function\n"); > > client_data->response.error = -EINVAL; > > goto error_wake_up; > > } > > @@ -289,9 +302,10 @@ static void process_recv(struct ishtp_cl *cros_ish_cl, > > memcpy(client_data->response.data, > > rb_in_proc->buffer.data, data_len); > > > > +error_wake_up: > > /* Set flag before waking up the caller */ > > client_data->response.received = true; > > -error_wake_up: > > + > > /* Wake the calling thread */ > > wake_up_interruptible(&client_data->response.wait_queue); > > > >