Skip to contentSkip to conversation

fsi: sbefifo: Use interruptible mutex locking

PATCH In review Eddie James 2 participants 2 messages Aug 3, 2021 – Oct 15, 2021 FSI

lore
Share & tools
lore

Eddie James

author maintainer
#0 lore raw

PATCH 1/1 fsi: sbefifo: Use interruptible mutex locking

Some SBE operations have extremely large responses and can require several minutes to process the response. During this time, the device lock must be held. If another process attempts an operation, it will wait for the mutex for longer than the kernel hung task watchdog allows. Therefore, use the interruptible function to lock the mutex.

---
 drivers/fsi/fsi-sbefifo.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/fsi/fsi-sbefifo.c +9 -3
index 84cb965bfed5..a8d8e47e6fb2 100644
@@ -740,7 +740,9 @@ int sbefifo_submit(struct device *dev, const __be32 *command, size_t cmd_len,
         iov_iter_kvec(&resp_iter, WRITE, &resp_iov, 1, rbytes);
 
 	/* Perform the command */
-	mutex_lock(&sbefifo->lock);
+	rc = mutex_lock_interruptible(&sbefifo->lock);
+	if (rc)
+		return rc;
 	rc = __sbefifo_submit(sbefifo, command, cmd_len, &resp_iter);
 	mutex_unlock(&sbefifo->lock);
 
@@ -820,7 +822,9 @@ static ssize_t sbefifo_user_read(struct file *file, char __user *buf,
 	iov_iter_init(&resp_iter, WRITE, &resp_iov, 1, len);
 
 	/* Perform the command */
-	mutex_lock(&sbefifo->lock);
+	rc = mutex_lock_interruptible(&sbefifo->lock);
+	if (rc)
+		goto bail;
 	rc = __sbefifo_submit(sbefifo, user->pending_cmd, cmd_len, &resp_iter);
 	mutex_unlock(&sbefifo->lock);
 	if (rc < 0)
@@ -875,7 +879,9 @@ static ssize_t sbefifo_user_write(struct file *file, const char __user *buf,
 		user->pending_len = 0;
 
 		/* Trigger reset request */
-		mutex_lock(&sbefifo->lock);
+		rc = mutex_lock_interruptible(&sbefifo->lock);
+		if (rc)
+			goto bail;
 		rc = sbefifo_request_reset(user->sbefifo);
 		mutex_unlock(&sbefifo->lock);
 		if (rc == 0)
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eddie James

Some SBE operations have extremely large responses and can require several minutes to process the response. During this time, the device lock must be held. If another process attempts an operation, it will wait for the mutex for longer than the kernel hung task watchdog allows. Therefore, use the interruptible function to lock the mutex.

I think this is okay. I'm not familiar with the use of mutex_lock_interruptible, so if anyone else wants to ask questions please do.

Quoted 44 lines
---
 drivers/fsi/fsi-sbefifo.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/fsi/fsi-sbefifo.c +9 -4
index 84cb965bfed5..a8d8e47e6fb2 100644
@@ -740,7 +740,9 @@ int sbefifo_submit(struct device *dev, const __be32 *command, size_t cmd_len,
         iov_iter_kvec(&resp_iter, WRITE, &resp_iov, 1, rbytes);
 
        /* Perform the command */
-       mutex_lock(&sbefifo->lock);
+       rc = mutex_lock_interruptible(&sbefifo->lock);
+       if (rc)
+               return rc;
        rc = __sbefifo_submit(sbefifo, command, cmd_len, &resp_iter);
        mutex_unlock(&sbefifo->lock);
 
@@ -820,7 +822,9 @@ static ssize_t sbefifo_user_read(struct file *file, char __user *buf,
        iov_iter_init(&resp_iter, WRITE, &resp_iov, 1, len);
 
        /* Perform the command */
-       mutex_lock(&sbefifo->lock);
+       rc = mutex_lock_interruptible(&sbefifo->lock);
+       if (rc)
+               goto bail;
        rc = __sbefifo_submit(sbefifo, user->pending_cmd, cmd_len, &resp_iter);
        mutex_unlock(&sbefifo->lock);
        if (rc < 0)
@@ -875,7 +879,9 @@ static ssize_t sbefifo_user_write(struct file *file, const char __user *buf,
                user->pending_len = 0;
 
                /* Trigger reset request */
-               mutex_lock(&sbefifo->lock);
+               rc = mutex_lock_interruptible(&sbefifo->lock);
+               if (rc)
+                       goto bail;
                rc = sbefifo_request_reset(user->sbefifo);
                mutex_unlock(&sbefifo->lock);
                if (rc == 0)
--

2.27.0