[PATCH] CXL: Fix afu_read() not doing finish_wait() on signal or non-blocking

2014-10-08 Thread Ian Munsie
From: Ian Munsie 

If afu_read() returned due to a signal or the AFU file descriptor being
opened non-blocking it would not call finish_wait() before returning,
which could lead to a crash later when something else wakes up the wait
queue.

This patch restructures the wait logic to ensure that the cleanup is
done correctly.

Signed-off-by: Ian Munsie 
---

Resending with correct whitespace as my mailer decided to replace tabs with
spaces on the last try.

 drivers/misc/cxl/file.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 847b7e6..378b099 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -273,6 +273,7 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
struct cxl_context *ctx = file->private_data;
struct cxl_event event;
unsigned long flags;
+   int rc;
DEFINE_WAIT(wait);
 
if (count < CXL_READ_MIN_SIZE)
@@ -285,13 +286,17 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
if (ctx_event_pending(ctx))
break;
 
-   spin_unlock_irqrestore(>lock, flags);
-   if (file->f_flags & O_NONBLOCK)
-   return -EAGAIN;
+   if (file->f_flags & O_NONBLOCK) {
+   rc = -EAGAIN;
+   goto out;
+   }
 
-   if (signal_pending(current))
-   return -ERESTARTSYS;
+   if (signal_pending(current)) {
+   rc = -ERESTARTSYS;
+   goto out;
+   }
 
+   spin_unlock_irqrestore(>lock, flags);
pr_devel("afu_read going to sleep...\n");
schedule();
pr_devel("afu_read woken up\n");
@@ -336,6 +341,11 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
if (copy_to_user(buf, , event.header.size))
return -EFAULT;
return event.header.size;
+
+out:
+   finish_wait(>wq, );
+   spin_unlock_irqrestore(>lock, flags);
+   return rc;
 }
 
 static const struct file_operations afu_fops = {
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] CXL: Fix afu_read() not doing finish_wait() on signal or non-blocking

2014-10-08 Thread Ian Munsie
If afu_read() returned due to a signal or the AFU file descriptor being
opened non-blocking it would not call finish_wait() before returning,
which could lead to a crash later when something else wakes up the wait
queue.

This patch restructures the wait logic to ensure that the cleanup is
done correctly.

Signed-off-by: Ian Munsie 
---
 drivers/misc/cxl/file.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 847b7e6..378b099 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -273,6 +273,7 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
struct cxl_context *ctx = file->private_data;
struct cxl_event event;
unsigned long flags;
+   int rc;
DEFINE_WAIT(wait);
 
if (count < CXL_READ_MIN_SIZE)
@@ -285,13 +286,17 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
if (ctx_event_pending(ctx))
break;
 
-   spin_unlock_irqrestore(>lock, flags);
-   if (file->f_flags & O_NONBLOCK)
-   return -EAGAIN;
+   if (file->f_flags & O_NONBLOCK) {
+   rc = -EAGAIN;
+   goto out;
+   }
 
-   if (signal_pending(current))
-   return -ERESTARTSYS;
+   if (signal_pending(current)) {
+   rc = -ERESTARTSYS;
+   goto out;
+   }
 
+   spin_unlock_irqrestore(>lock, flags);
pr_devel("afu_read going to sleep...\n");
schedule();
pr_devel("afu_read woken up\n");
@@ -336,6 +341,11 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
if (copy_to_user(buf, , event.header.size))
return -EFAULT;
return event.header.size;
+
+out:
+   finish_wait(>wq, );
+   spin_unlock_irqrestore(>lock, flags);
+   return rc;
 }
 
 static const struct file_operations afu_fops = {
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] CXL: Fix afu_read() not doing finish_wait() on signal or non-blocking

2014-10-08 Thread Ian Munsie
If afu_read() returned due to a signal or the AFU file descriptor being
opened non-blocking it would not call finish_wait() before returning,
which could lead to a crash later when something else wakes up the wait
queue.

This patch restructures the wait logic to ensure that the cleanup is
done correctly.

Signed-off-by: Ian Munsie imun...@au1.ibm.com
---
 drivers/misc/cxl/file.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 847b7e6..378b099 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -273,6 +273,7 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
struct cxl_context *ctx = file-private_data;
struct cxl_event event;
unsigned long flags;
+   int rc;
DEFINE_WAIT(wait);
 
if (count  CXL_READ_MIN_SIZE)
@@ -285,13 +286,17 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
if (ctx_event_pending(ctx))
break;
 
-   spin_unlock_irqrestore(ctx-lock, flags);
-   if (file-f_flags  O_NONBLOCK)
-   return -EAGAIN;
+   if (file-f_flags  O_NONBLOCK) {
+   rc = -EAGAIN;
+   goto out;
+   }
 
-   if (signal_pending(current))
-   return -ERESTARTSYS;
+   if (signal_pending(current)) {
+   rc = -ERESTARTSYS;
+   goto out;
+   }
 
+   spin_unlock_irqrestore(ctx-lock, flags);
pr_devel(afu_read going to sleep...\n);
schedule();
pr_devel(afu_read woken up\n);
@@ -336,6 +341,11 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
if (copy_to_user(buf, event, event.header.size))
return -EFAULT;
return event.header.size;
+
+out:
+   finish_wait(ctx-wq, wait);
+   spin_unlock_irqrestore(ctx-lock, flags);
+   return rc;
 }
 
 static const struct file_operations afu_fops = {
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] CXL: Fix afu_read() not doing finish_wait() on signal or non-blocking

2014-10-08 Thread Ian Munsie
From: Ian Munsie imun...@au1.ibm.com

If afu_read() returned due to a signal or the AFU file descriptor being
opened non-blocking it would not call finish_wait() before returning,
which could lead to a crash later when something else wakes up the wait
queue.

This patch restructures the wait logic to ensure that the cleanup is
done correctly.

Signed-off-by: Ian Munsie imun...@au1.ibm.com
---

Resending with correct whitespace as my mailer decided to replace tabs with
spaces on the last try.

 drivers/misc/cxl/file.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 847b7e6..378b099 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -273,6 +273,7 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
struct cxl_context *ctx = file-private_data;
struct cxl_event event;
unsigned long flags;
+   int rc;
DEFINE_WAIT(wait);
 
if (count  CXL_READ_MIN_SIZE)
@@ -285,13 +286,17 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
if (ctx_event_pending(ctx))
break;
 
-   spin_unlock_irqrestore(ctx-lock, flags);
-   if (file-f_flags  O_NONBLOCK)
-   return -EAGAIN;
+   if (file-f_flags  O_NONBLOCK) {
+   rc = -EAGAIN;
+   goto out;
+   }
 
-   if (signal_pending(current))
-   return -ERESTARTSYS;
+   if (signal_pending(current)) {
+   rc = -ERESTARTSYS;
+   goto out;
+   }
 
+   spin_unlock_irqrestore(ctx-lock, flags);
pr_devel(afu_read going to sleep...\n);
schedule();
pr_devel(afu_read woken up\n);
@@ -336,6 +341,11 @@ static ssize_t afu_read(struct file *file, char __user 
*buf, size_t count,
if (copy_to_user(buf, event, event.header.size))
return -EFAULT;
return event.header.size;
+
+out:
+   finish_wait(ctx-wq, wait);
+   spin_unlock_irqrestore(ctx-lock, flags);
+   return rc;
 }
 
 static const struct file_operations afu_fops = {
-- 
2.1.0

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/