Received: by 10.213.65.68 with SMTP id h4csp414481imn; Wed, 28 Mar 2018 06:08:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx498o56AqGOfqcKSSFKLQfYFXYFZN9PhUvCwxzN0EvB1rT/ywHLaE5o/ddSf7d3Y1teGayce X-Received: by 2002:a17:902:8492:: with SMTP id c18-v6mr3766024plo.40.1522242523428; Wed, 28 Mar 2018 06:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522242523; cv=none; d=google.com; s=arc-20160816; b=VnNyVcLH26MWT62pvmvesJ1UzPTO8s0QkNz7xXqOihhpBaChhSOlcUDnrvNAB4O8BN n9erHm+Fb7JjbBfmDwfpiZvKem4TTCybXDmk+qz7AucLC6CbbDsBDf+cnrkeZ9BEaj8E SYMDeMNdI/3WjC6rdlWDEBItZzaRc0/+mWzEKeYZTTHSOils9lsdyTEv9ixw52Zxplj1 /aFELqJLlOAzc/KZ9nJPgt4AzRuIPqT09aq76r6xQfM9lM5fQWNCxiJRecRoowSD4K+B VxvEPPlH0y6IY286LCy+mDFJ2oagCBrBD/4sTKMkV7/Ux8YuS0SeHyof6VS/3HPz3UCg /aBA== 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=I7uexv43KeJZEJ1ce0QV/y/b0+3lOUchZs2NgZcgxRs=; b=fFav2V6u397xnNAjlIkwfPqyleKOKJOjt/uYdFt0CSmA0RzHnCDWhnF8fqRJz3PuJw vG3Zu3e4cwmc1kLYJr1h8h80Oy7+6qFT6w1LJd45O1tMBMlBPakftQoYbi1aKKUN43ap FXL7sL4IJnCLRK7kFgOPaaLdSzZ2+O8ruLzT3fHmqRAaIiDjbPj0MoTcC6LiDLO4pmBe SXJYbzUIxzmYCJ3TaGy81GC8TwP2OePVDLd0CbN8vAVbYK0Zy5maY2ugQ95OW4i5GB/R cb+P6PYRHBVP1bpr8PUejDUi+R7nAvui2vM5YumDBAn/IsewPxD7dtoZs4L8CyhLumR3 amAQ== 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 c5-v6si3733603plo.461.2018.03.28.06.08.16; Wed, 28 Mar 2018 06:08:43 -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 S1753354AbeC1NGr (ORCPT + 99 others); Wed, 28 Mar 2018 09:06:47 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:36937 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753166AbeC1NGo (ORCPT ); Wed, 28 Mar 2018 09:06:44 -0400 Received: by mail-wr0-f196.google.com with SMTP id l49so2201171wrl.4; Wed, 28 Mar 2018 06:06:44 -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=I7uexv43KeJZEJ1ce0QV/y/b0+3lOUchZs2NgZcgxRs=; b=Wb5brzBar1ekDDIIKPaWlEzhXC0o084jpLzYBCpqQIkFkouJxzaw52jN/PjeNRQ3v4 ACT+XW+etLvksJj2MEQl4eceT164vdGBSeJbMZtkEy47oD1ZevXEw/qE7uag69jlrZk2 ZFKpJ78NEhQ3HbtQdPnuZigO+LiiRBz7QVTUsNWpHPdrqefeTGc9nMa/X/3dWJqg1FEn aA0qSu5UoW1vCoYk3s7yIRzCH0kXJv0PFaqj+HKVJV/9X4QI2LvDv2qLmQGVDu+DrV2g 2fPcsxtOPnJk7b2cP+W61lxG/wnLl3vMBoOQ+vx6w+8K72uiwAdCvItB5mcXic4cCjz2 c7uQ== X-Gm-Message-State: AElRT7HWLYTd5YR4bmLAodjszo3a1FcFgK0zURDTbxqT71odf7LOGGFX Pt9X14UATb29/NBFFWB0C6s= X-Received: by 10.223.176.253 with SMTP id j58mr2885906wra.269.1522242403325; Wed, 28 Mar 2018 06:06:43 -0700 (PDT) Received: from hc.cavium.com (ip-109-42-2-53.web.vodafone.de. [109.42.2.53]) by smtp.gmail.com with ESMTPSA id i52sm7196162wra.82.2018.03.28.06.06.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Mar 2018 06:06:42 -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 2/2] crypto: thunderx_zip: Limit result reading attempts Date: Wed, 28 Mar 2018 15:05:57 +0200 Message-Id: <20180328130557.10560-2-jglauber@cavium.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180328130557.10560-1-jglauber@cavium.com> References: <20180328130557.10560-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 | 22 ++++++++++++++++++++++ drivers/crypto/cavium/zip/zip_deflate.c | 4 ++-- drivers/crypto/cavium/zip/zip_inflate.c | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/cavium/zip/common.h b/drivers/crypto/cavium/zip/common.h index dc451e0..9067451 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,26 @@ struct zip_operation { u32 sizeofzops; }; +#define ZIP_POLL_DELAY 20 /* microseconds */ +#define ZIP_POLL_TIMEOUT (msecs_to_jiffies(1000)) + +static inline int zip_poll_result(union zip_zres_s *result) +{ + u64 end = get_jiffies_64() + ZIP_POLL_TIMEOUT; + + while (!result->s.compcode) { + /* + * Force re-reading of compcode which is updated + * by the ZIP coprocessor. + */ + rmb(); + if (time_after64(get_jiffies_64(), end)) + return -ETIMEDOUT; + usleep_range(ZIP_POLL_DELAY / 2, ZIP_POLL_DELAY); + } + 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 9a944b8..d7133f8 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 50cbdd8..7e0d73e 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.7.4