Thread (9 messages) flat view 9 messages, 3 authors, 2018-08-07

[PATCH v3 RESEND 2/2] tpm: add support for nonblocking operation

From: jgg@ziepe.ca (Jason Gunthorpe)
Date: 2018-08-07 18:20:20
Also in: linux-integrity, lkml

On Mon, Aug 06, 2018 at 04:05:48PM -0700, James Bottomley wrote:
quoted
@@ -118,25 +155,48 @@ ssize_t tpm_common_write(struct file *file,
const char __user *buf,
?	?* the char dev is held open.
?	?*/
?	if (tpm_try_get_ops(priv->chip)) {
-		mutex_unlock(&priv->buffer_mutex);
-		return -EPIPE;
+		ret = -EPIPE;
+		goto out;
?	}
-	out_size = tpm_transmit(priv->chip, priv->space, priv-
quoted
data_buffer,
-				sizeof(priv->data_buffer), 0);
?
-	tpm_put_ops(priv->chip);
-	if (out_size < 0) {
-		mutex_unlock(&priv->buffer_mutex);
-		return out_size;
+	/*
+	?* If in nonblocking mode schedule an async job to send
+	?* the command return the size.
+	?* In case of error the err code will be returned in
+	?* the subsequent read call.
+	?*/
+	if (file->f_flags & O_NONBLOCK) {
+		queue_work(tpm_dev_wq, &priv->async_work);
+		return size;
Here you return holding the buffer_mutex, waiting for tpm_async_work to
release it.
Doesn't lockdep complain when locks are left held after returning to
user space? Even if it doesn't, that is a pretty ugly thing to do.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help