Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp753269ybb; Fri, 10 Apr 2020 09:24:26 -0700 (PDT) X-Google-Smtp-Source: APiQypKXCbYtx3p7LKQBID99onsvoG2CaJH1rjzYwbbdoIYDsEt4uXgjeFEx0s7A8lgOXd35AuqB X-Received: by 2002:ac8:4f42:: with SMTP id i2mr5001161qtw.337.1586535866022; Fri, 10 Apr 2020 09:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586535866; cv=none; d=google.com; s=arc-20160816; b=QrmOkdZGikI6s8bde4MalWL2w2dh/bEekV1JVOdE2jr42idr7ZIGAJg4fK1lR00kiU HBiUdjJrQuq3YNtPJr0AxpyEjQWMI+UcFZYGFmwYp/9roWpLGlajgZu/a2tVgL0H32nt 5PHybS2OjCF9xBNfmeg7pvvxasTsqRDbpKVK/tBS3lg8IFyqEEk+MKb14ZGQ4PEdcuRa cem5vXyDI70SI/sTxQXe9cnlCaBM3iBhho7FfqQqg/hP2x7azV+cLUGOktHRrjP2etX9 hDW0lqeWgTL3O/kbeVDDYKR+VGswCbEMUto4Lf5/fUtzw4obxKOvLCro3miO+rsgferK 3Z0Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=uKOOFpBMpsxQLj3kDvN/9el/ZGEfPFFVWNgPbZWR2c0=; b=fEMB6zDJa4/5zdL9bqlLyX+ER9hQbevaoezQeraDNSA8+DQmMKiyDoiDrxJ6suXeWE +uakXLNm5MirVrNIHN1GAEwm7YV1L2YhDRp2+M3OCaHX/+Kk0qLsDFP97F705kjIH3Id nU81kGUuvMXukpDZrDNaN6qtOVyIc8tavuRttiHSFWOOjubtELG1SwDiJrQ9Zl+6EOST /iJJnBFc9NBdWRpl2R02ghLMQRK6nfkS3cq9C64bKRAjzcw6/w9/vEzn3Hz4q8VHGOCt UM3RR3M7z/1H52U5/y0lmcHMb0sEBNKDCASyuDFdxz4wL8/M+Gz4qyANzCfW7PP6xrYl bXeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ouarj1AP; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c28si1393223qtw.17.2020.04.10.09.24.11; Fri, 10 Apr 2020 09:24:26 -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=@chromium.org header.s=google header.b=Ouarj1AP; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726654AbgDJQXW (ORCPT + 99 others); Fri, 10 Apr 2020 12:23:22 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42692 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726234AbgDJQXW (ORCPT ); Fri, 10 Apr 2020 12:23:22 -0400 Received: by mail-pf1-f196.google.com with SMTP id 22so1220848pfa.9 for ; Fri, 10 Apr 2020 09:23:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uKOOFpBMpsxQLj3kDvN/9el/ZGEfPFFVWNgPbZWR2c0=; b=Ouarj1APAOtAKPq92iy9qVy1+Uuym5EIwg+BdogZj5iIRVBRPNKEXVAQ2foI9cJkXH aM5IxKMVsdY97twkrJZ0y8LSK31jgvy1r3pJ4Zx/0XzYAnEE+rNVRCOp5Bu8JQph70Jp u7pLKwZk8VB7CfWAZZ10FB2DXDoI0TYdtYYh4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uKOOFpBMpsxQLj3kDvN/9el/ZGEfPFFVWNgPbZWR2c0=; b=MwuUVRra/Dvg7oQLPn9L6/tX3BAszikUQQ/C5nbAHYB2bxp6iZcBT4ANG9Xuw3Dk3P hFa1b8KoonUeHfYeXeZgcWwGr+GRoWU0Ig+aJK9JRm046WW813EgiDQug41Fvq440AwN FWZ+CWDgfaCHZcMvKrcL7SpQhekghYXTQBpsZy2GocXj2j9oyFj+ke8xhT9t2kkf0001 3DFiaegmZgdXT7e0lef38cPzJouME9SrahachreDwhdjvWaRTPzvw06XSTguI2yXN/QS 7UroLLjkwnCxG+EmteAKyZb1oP5n3TIn2rh7VQR+gckI+CsvKOWuANnV/Ao7j7PwrMd3 Ur9Q== X-Gm-Message-State: AGi0PuZr9JiqUpQLl461TDuX4aAD1Cjku5/zBq3lPJBbV+99cGHwYqc1 4NJAgcnEUniADjNL1RfnaynxktWvo92+yA== X-Received: by 2002:a62:3808:: with SMTP id f8mr5649414pfa.38.1586535798877; Fri, 10 Apr 2020 09:23:18 -0700 (PDT) Received: from mathewk1.lan ([161.97.192.125]) by smtp.gmail.com with ESMTPSA id c4sm1977138pgg.17.2020.04.10.09.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2020 09:23:18 -0700 (PDT) From: Mathew King To: linux-kernel@vger.kernel.org Cc: Jett Rink , Benson Leung , Enric Balletbo i Serra , Guenter Roeck , Rushikesh S Kadam , Mathew King Subject: [PATCH v2 1/2] platform/chrome: cros_ec_ishtp: skip old cros_ec responses Date: Fri, 10 Apr 2020 10:23:04 -0600 Message-Id: <20200410162305.76638-1-mathewk@chromium.org> X-Mailer: git-send-email 2.26.0.110.g2183baf09c-goog 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 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. 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 we treat the old response as the response to the current command. This is a condition that should not normally happen but it has been observed with a bad ISH image. So add a token 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 --- v2: - Change from using id to token - Reword the commit message --- 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..e673a7f738fc 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 token; + 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(). + * @token: Expected token 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 token; 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 next_token; 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.token = next_token++; client_data->response.received = false; + out_hdr->token = client_data->response.token; + 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.token != in_msg->hdr.token) { + dev_err_ratelimited(dev, + "Dropping old response token %d\n", + in_msg->hdr.token); + goto end_error; + } + + /* Sanity check */ + if (!client_data->response.data) { dev_err(dev, - "Previous firmware message not yet processed\n"); + "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); -- 2.26.0.110.g2183baf09c-goog