Skip to content

Commit b970579

Browse files
Jan Glaubergregkh
authored andcommitted
crypto: cavium - Limit result reading attempts
commit c782a8c upstream. 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 <jglauber@cavium.com> Reviewed-by: Robert Richter <rrichter@cavium.com> Cc: stable <stable@vger.kernel.org> # 4.14 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 072e8b1 commit b970579

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎drivers/crypto/cavium/zip/common.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
#ifndef __COMMON_H__
4747
#define __COMMON_H__
4848

49+
#include <linux/delay.h>
4950
#include <linux/init.h>
5051
#include <linux/interrupt.h>
52+
#include <linux/io.h>
5153
#include <linux/kernel.h>
5254
#include <linux/module.h>
5355
#include <linux/pci.h>
@@ -149,6 +151,25 @@ struct zip_operation {
149151
u32 sizeofzops;
150152
};
151153

154+
static inline int zip_poll_result(union zip_zres_s *result)
155+
{
156+
int retries = 1000;
157+
158+
while (!result->s.compcode) {
159+
if (!--retries) {
160+
pr_err("ZIP ERR: request timed out");
161+
return -ETIMEDOUT;
162+
}
163+
udelay(10);
164+
/*
165+
* Force re-reading of compcode which is updated
166+
* by the ZIP coprocessor.
167+
*/
168+
rmb();
169+
}
170+
return 0;
171+
}
172+
152173
/* error messages */
153174
#define zip_err(fmt, args...) pr_err("ZIP ERR:%s():%d: " \
154175
fmt "\n", __func__, __LINE__, ## args)

‎drivers/crypto/cavium/zip/zip_deflate.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ int zip_deflate(struct zip_operation *zip_ops, struct zip_state *s,
129129
/* Stats update for compression requests submitted */
130130
atomic64_inc(&zip_dev->stats.comp_req_submit);
131131

132-
while (!result_ptr->s.compcode)
133-
continue;
132+
/* Wait for completion or error */
133+
zip_poll_result(result_ptr);
134134

135135
/* Stats update for compression requests completed */
136136
atomic64_inc(&zip_dev->stats.comp_req_complete);

‎drivers/crypto/cavium/zip/zip_inflate.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ int zip_inflate(struct zip_operation *zip_ops, struct zip_state *s,
143143
/* Decompression requests submitted stats update */
144144
atomic64_inc(&zip_dev->stats.decomp_req_submit);
145145

146-
while (!result_ptr->s.compcode)
147-
continue;
146+
/* Wait for completion or error */
147+
zip_poll_result(result_ptr);
148148

149149
/* Decompression requests completed stats update */
150150
atomic64_inc(&zip_dev->stats.decomp_req_complete);

0 commit comments

Comments
 (0)