Received: by 10.213.65.68 with SMTP id h4csp2774792imn; Mon, 9 Apr 2018 08:50:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx49+O4DC5OXT/Kke9OABYBl+Ck7D+I60iwdh+2T30QLvCZZIrIWx2ZtRIUJOAcDNihKaH2Mh X-Received: by 2002:a17:902:820d:: with SMTP id x13-v6mr2197488pln.225.1523289039890; Mon, 09 Apr 2018 08:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523289039; cv=none; d=google.com; s=arc-20160816; b=F9tKeFZeubJSJ5IEVUdK1LxPDahEV+LNXxBoY9WjwXx1X3t7T8hNmMWjtfrGjwMEsh 5p0tmfz1umR+wef07NaNKlKfPCHJQNkQcZmEED0k38c8DpJZ6Ze8MpUlhMXlMnm5OZNK UfAYdAtskKjYR8tV3Qo6BsqPBtDuDKI59p9eGwktOyicMYjpBm8Dk2FgH7srI1Vnqogo 0o0O4ByVRKr7REXB4FlCsbWtkD6Ab/ML/zVvtJ9ujz9nQjjUhLe5lph0Sm5Xr9Pus+Bu /HzgtusYFuWJdRHOudzd4glXGNhkqFRpAaSlWhGnhjIkRiU1pIe/27f53WM6A/zSsT7Y xPFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=9hhZuEegfK9YwbPIKMHGVaCuCNe0Ikr7Dt8wziYFYlE=; b=lKXTxwh90QZG6oeFvd86olYKfHS5VwdxXD615FPCywN4R/asrJlh2FBkZBvh+ftRj3 45S04W4HsxrJOenXm/ka0e/Jk13FRPy3HWJZQYkqhn3fBlBiWfCI2X6rUSAq7Q5YqgBa pShyr6TCV+6tyi8MUd9mkKJJ6MkD3mqcYbzji77VpTEM9oqRNb0mLyS1Iac2tKThMfxG mOeF5yLlxoHS01584MjHjPrTSrt3QRDcY9m2oGFROVTfEi8AuJuAJdGSpuOVpKGeQ99A xU6YHPrgpGYnlMeZRK5GXZ2x2rQnX/WPPhDSyS5JLharw4GCimKcHebDbgkygXfvGNq/ INxQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 92-v6si539441plw.229.2018.04.09.08.49.57; Mon, 09 Apr 2018 08:50:39 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753318AbeDIPqs (ORCPT + 99 others); Mon, 9 Apr 2018 11:46:48 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:38593 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753217AbeDIPqi (ORCPT ); Mon, 9 Apr 2018 11:46:38 -0400 Received: by mail-wm0-f66.google.com with SMTP id i3so17665497wmf.3; Mon, 09 Apr 2018 08:46:37 -0700 (PDT) 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:in-reply-to :references; bh=9hhZuEegfK9YwbPIKMHGVaCuCNe0Ikr7Dt8wziYFYlE=; b=hl6eXyy7c6qk87a8maxfsTV9YudtYdvGHJjy3rPObjwdvnP+nOtnIBTIO/Qt5D7uub oHIYW9yW8/NTA1oG/Y+TjUvr+M4dGOw9GZnmti8EoUP+GpH7t21wGuMHlXNKnxiKkQ4T t1n/ZYBJEENXxoeeaOcnXRTYWCwkzQOUkFTDa2HAbH4Dn/B6nfaz9TWpZXAGYO5e67Bj 3VBk/dB/MjA1DcUcX+EoF1IHVeOLvJL9h4e9QfXyN78+oAHphilWFJeYGpK5EjbBOhXa dzmdD+mHLTcyAw6KpQGv3E36qAy4vr2s7a0W8Ji65MZikkLrIPf4ILxxTOLUGOItwIi9 lunA== X-Gm-Message-State: ALQs6tB3JlOitdXMMogwzAruH/kSSFon7YuxGJEQULMxe3Q3kIhMPfHp l1Ixy0/tpv9OXTyfK7H2/G0= X-Received: by 10.28.135.9 with SMTP id j9mr361671wmd.68.1523288796839; Mon, 09 Apr 2018 08:46:36 -0700 (PDT) Received: from wintermute.fritz.box (HSI-KBW-078-043-196-194.hsi4.kabel-badenwuerttemberg.de. [78.43.196.194]) by smtp.gmail.com with ESMTPSA id w40sm881163wrc.33.2018.04.09.08.46.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Apr 2018 08:46:36 -0700 (PDT) From: Jan Glauber To: Herbert Xu Cc: "David S . Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Mahipal Challa , Robert Richter , Jan Glauber , stable Subject: [PATCH v2 2/5] crypto: thunderx_zip: Limit result reading attempts Date: Mon, 9 Apr 2018 17:45:51 +0200 Message-Id: <20180409154554.7578-3-jglauber@cavium.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180409154554.7578-1-jglauber@cavium.com> References: <20180409154554.7578-1-jglauber@cavium.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After issuing a request an endless loop was used to read the completion state from memory which is asynchronously updated by the ZIP coprocessor. Add an upper bound to the retry attempts to prevent a CPU getting stuck forever in case of an error. Additionally, add a read memory barrier and a small delay between the reading attempts. Signed-off-by: Jan Glauber Reviewed-by: Robert Richter Cc: stable # 4.14 --- drivers/crypto/cavium/zip/common.h | 21 +++++++++++++++++++++ drivers/crypto/cavium/zip/zip_deflate.c | 4 ++-- drivers/crypto/cavium/zip/zip_inflate.c | 4 ++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/cavium/zip/common.h b/drivers/crypto/cavium/zip/common.h index dc451e0a43c5..58fb3ed6e644 100644 --- a/drivers/crypto/cavium/zip/common.h +++ b/drivers/crypto/cavium/zip/common.h @@ -46,8 +46,10 @@ #ifndef __COMMON_H__ #define __COMMON_H__ +#include #include #include +#include #include #include #include @@ -149,6 +151,25 @@ struct zip_operation { u32 sizeofzops; }; +static inline int zip_poll_result(union zip_zres_s *result) +{ + int retries = 1000; + + while (!result->s.compcode) { + if (!--retries) { + pr_err("ZIP ERR: request timed out"); + return -ETIMEDOUT; + } + udelay(10); + /* + * Force re-reading of compcode which is updated + * by the ZIP coprocessor. + */ + rmb(); + } + return 0; +} + /* error messages */ #define zip_err(fmt, args...) pr_err("ZIP ERR:%s():%d: " \ fmt "\n", __func__, __LINE__, ## args) diff --git a/drivers/crypto/cavium/zip/zip_deflate.c b/drivers/crypto/cavium/zip/zip_deflate.c index 9a944b8c1e29..d7133f857d67 100644 --- a/drivers/crypto/cavium/zip/zip_deflate.c +++ b/drivers/crypto/cavium/zip/zip_deflate.c @@ -129,8 +129,8 @@ int zip_deflate(struct zip_operation *zip_ops, struct zip_state *s, /* Stats update for compression requests submitted */ atomic64_inc(&zip_dev->stats.comp_req_submit); - while (!result_ptr->s.compcode) - continue; + /* Wait for completion or error */ + zip_poll_result(result_ptr); /* Stats update for compression requests completed */ atomic64_inc(&zip_dev->stats.comp_req_complete); diff --git a/drivers/crypto/cavium/zip/zip_inflate.c b/drivers/crypto/cavium/zip/zip_inflate.c index 50cbdd83dbf2..7e0d73e2f89e 100644 --- a/drivers/crypto/cavium/zip/zip_inflate.c +++ b/drivers/crypto/cavium/zip/zip_inflate.c @@ -143,8 +143,8 @@ int zip_inflate(struct zip_operation *zip_ops, struct zip_state *s, /* Decompression requests submitted stats update */ atomic64_inc(&zip_dev->stats.decomp_req_submit); - while (!result_ptr->s.compcode) - continue; + /* Wait for completion or error */ + zip_poll_result(result_ptr); /* Decompression requests completed stats update */ atomic64_inc(&zip_dev->stats.decomp_req_complete); -- 2.16.2