[PATCH 05/16] make write() operation smp aware

2008-01-07 Thread Glauber de Oliveira Costa
This patch makes the write() file operation smp aware. Which means, receiving
the vcpu_id value through the offset parameter, and being well aware to which
vcpu we're talking to.

Signed-off-by: Glauber de Oliveira Costa <[EMAIL PROTECTED]>
---
 drivers/lguest/lguest_user.c |   11 +--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
index 216514b..d176004 100644
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -230,14 +230,21 @@ static ssize_t write(struct file *file, const char __user 
*in,
struct lguest *lg = file->private_data;
const unsigned long __user *input = (const unsigned long __user *)in;
unsigned long req;
+   struct lg_vcpu *vcpu = NULL;
+   int vcpu_id = *off;
 
if (get_user(req, input) != 0)
return -EFAULT;
input++;
 
/* If you haven't initialized, you must do that first. */
-   if (req != LHREQ_INITIALIZE && !lg)
-   return -EINVAL;
+   if (req != LHREQ_INITIALIZE) {
+   if (!lg || (vcpu_id > lg->nr_vcpus))
+   return -EINVAL;
+   vcpu = &lg->vcpus[vcpu_id];
+   if (!vcpu)
+   return -EINVAL;
+   }
 
/* Once the Guest is dead, all you can do is read() why it died. */
if (lg && lg->dead)
-- 
1.5.0.6

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


Re: [PATCH 05/16] make write() operation smp aware

2007-12-25 Thread Rusty Russell
On Friday 21 December 2007 00:33:45 Glauber de Oliveira Costa wrote:
> --- a/drivers/lguest/lguest_user.c
> +++ b/drivers/lguest/lguest_user.c
> @@ -223,14 +223,21 @@ static ssize_t write(struct file *file, const char
...
>   /* If you haven't initialized, you must do that first. */
> - if (req != LHREQ_INITIALIZE && !lg)
> - return -EINVAL;
> + if (req != LHREQ_INITIALIZE) {
> + if (!lg)
> + return -EINVAL;
> + vcpu = &lg->vcpus[vcpu_id];
> + if (!vcpu)
> + return -EINVAL;
> + }

Bounds check again...

Cheers,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/16] make write() operation smp aware

2007-12-20 Thread Glauber de Oliveira Costa
This patch makes the write() file operation smp aware. Which means, receiving
the vcpu_id value through the offset parameter, and being well aware to which
vcpu we're talking to.

Signed-off-by: Glauber de Oliveira Costa <[EMAIL PROTECTED]>
---
 drivers/lguest/lguest_user.c |   11 +--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
index 894d530..ae5bf4c 100644
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -223,14 +223,21 @@ static ssize_t write(struct file *file, const char __user 
*in,
struct lguest *lg = file->private_data;
const unsigned long __user *input = (const unsigned long __user *)in;
unsigned long req;
+   struct lguest_vcpu *vcpu = NULL;
+   int vcpu_id = *off;
 
if (get_user(req, input) != 0)
return -EFAULT;
input++;
 
/* If you haven't initialized, you must do that first. */
-   if (req != LHREQ_INITIALIZE && !lg)
-   return -EINVAL;
+   if (req != LHREQ_INITIALIZE) {
+   if (!lg)
+   return -EINVAL;
+   vcpu = &lg->vcpus[vcpu_id];
+   if (!vcpu)
+   return -EINVAL;
+   }
 
/* Once the Guest is dead, all you can do is read() why it died. */
if (lg && lg->dead)
-- 
1.5.0.6

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