* [PATCH] vhost: correctly set bits of dirty pages
@ 2010-11-29 5:48 Jason Wang
2010-11-29 8:18 ` Michael S. Tsirkin
0 siblings, 1 reply; 4+ messages in thread
From: Jason Wang @ 2010-11-29 5:48 UTC (permalink / raw)
To: virtualization, netdev, linux-kernel, kvm, mst
When counting pages we should increase it by 1 instead of VHOST_PAGE_SIZE,
and also make log_write() can correctly process the request across
pages with write_address not start at page boundary.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
drivers/vhost/vhost.c | 20 +++++++++-----------
1 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index a29d91c..576300b 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -884,23 +884,21 @@ static int set_bit_to_user(int nr, void __user *addr)
static int log_write(void __user *log_base,
u64 write_address, u64 write_length)
{
- int r;
- if (!write_length)
- return 0;
- write_address /= VHOST_PAGE_SIZE;
- for (;;) {
+ int r = 0;
+ while (write_length > 0) {
+ u64 l = VHOST_PAGE_SIZE - write_address % VHOST_PAGE_SIZE;
+ u64 write_page = write_address / VHOST_PAGE_SIZE;
u64 base = (u64)(unsigned long)log_base;
- u64 log = base + write_address / 8;
- int bit = write_address % 8;
+ u64 log = base + write_page / 8;
+ int bit = write_page % 8;
if ((u64)(unsigned long)log != log)
return -EFAULT;
r = set_bit_to_user(bit, (void __user *)(unsigned long)log);
if (r < 0)
return r;
- if (write_length <= VHOST_PAGE_SIZE)
- break;
- write_length -= VHOST_PAGE_SIZE;
- write_address += VHOST_PAGE_SIZE;
+ l = min(l, write_length);
+ write_length -= l;
+ write_address += l;
}
return r;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost: correctly set bits of dirty pages
2010-11-29 5:48 [PATCH] vhost: correctly set bits of dirty pages Jason Wang
@ 2010-11-29 8:18 ` Michael S. Tsirkin
2010-11-29 8:25 ` Michael S. Tsirkin
2010-11-29 13:50 ` Jason Wang
0 siblings, 2 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2010-11-29 8:18 UTC (permalink / raw)
To: Jason Wang; +Cc: virtualization, netdev, linux-kernel, kvm
On Mon, Nov 29, 2010 at 01:48:20PM +0800, Jason Wang wrote:
> When counting pages we should increase it by 1 instead of VHOST_PAGE_SIZE,
> and also make log_write() can correctly process the request across
> pages with write_address not start at page boundary.
>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
Thanks, good catch!
But let's to it in small steps: first, a small patch to fix the bug:
I think this is equivalent, right?
Subject: vhost: correctly set bits of dirty pages
When counting pages we should increase address by 1 instead of
VHOST_PAGE_SIZE, and also make log_write() can correctly process the
request across pages with write_address not starting at page boundary.
Reported-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 568eb70..d0a3552 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -887,6 +887,7 @@ static int log_write(void __user *log_base,
int r;
if (!write_length)
return 0;
+ write_length += write_address % VHOST_PAGE_SIZE;
write_address /= VHOST_PAGE_SIZE;
for (;;) {
u64 base = (u64)(unsigned long)log_base;
@@ -900,7 +901,7 @@ static int log_write(void __user *log_base,
if (write_length <= VHOST_PAGE_SIZE)
break;
write_length -= VHOST_PAGE_SIZE;
- write_address += VHOST_PAGE_SIZE;
+ write_address += 1;
}
return r;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost: correctly set bits of dirty pages
2010-11-29 8:18 ` Michael S. Tsirkin
@ 2010-11-29 8:25 ` Michael S. Tsirkin
2010-11-29 13:50 ` Jason Wang
1 sibling, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2010-11-29 8:25 UTC (permalink / raw)
To: Jason Wang; +Cc: virtualization, netdev, linux-kernel, kvm
On Mon, Nov 29, 2010 at 10:18:40AM +0200, Michael S. Tsirkin wrote:
> On Mon, Nov 29, 2010 at 01:48:20PM +0800, Jason Wang wrote:
> > When counting pages we should increase it by 1 instead of VHOST_PAGE_SIZE,
> > and also make log_write() can correctly process the request across
> > pages with write_address not start at page boundary.
> >
> > Signed-off-by: Jason Wang <jasowang@redhat.com>
>
>
> Thanks, good catch!
> But let's to it in small steps: first, a small patch to fix the bug:
> I think this is equivalent, right?
>
> Subject: vhost: correctly set bits of dirty pages
>
> When counting pages we should increase address by 1 instead of
> VHOST_PAGE_SIZE, and also make log_write() can correctly process the
> request across pages with write_address not starting at page boundary.
>
> Reported-by: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
And then this on top:
vhost: better variable name in logging
We really store a page offset in write_address,
so rename it write_page to avoid confusion.
Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index d0a3552..1a3d3ed 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -884,15 +884,15 @@ static int set_bit_to_user(int nr, void __user *addr)
static int log_write(void __user *log_base,
u64 write_address, u64 write_length)
{
+ u64 write_page = write_address / VHOST_PAGE_SIZE
int r;
if (!write_length)
return 0;
write_length += write_address % VHOST_PAGE_SIZE;
- write_address /= VHOST_PAGE_SIZE;
for (;;) {
u64 base = (u64)(unsigned long)log_base;
- u64 log = base + write_address / 8;
- int bit = write_address % 8;
+ u64 log = base + write_page / 8;
+ int bit = write_page % 8;
if ((u64)(unsigned long)log != log)
return -EFAULT;
r = set_bit_to_user(bit, (void __user *)(unsigned long)log);
@@ -901,7 +901,7 @@ static int log_write(void __user *log_base,
if (write_length <= VHOST_PAGE_SIZE)
break;
write_length -= VHOST_PAGE_SIZE;
- write_address += 1;
+ write_page += 1;
}
return r;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost: correctly set bits of dirty pages
2010-11-29 8:18 ` Michael S. Tsirkin
2010-11-29 8:25 ` Michael S. Tsirkin
@ 2010-11-29 13:50 ` Jason Wang
1 sibling, 0 replies; 4+ messages in thread
From: Jason Wang @ 2010-11-29 13:50 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: Jason Wang, virtualization, netdev, linux-kernel, kvm
Michael S. Tsirkin writes:
> On Mon, Nov 29, 2010 at 01:48:20PM +0800, Jason Wang wrote:
> > When counting pages we should increase it by 1 instead of VHOST_PAGE_SIZE,
> > and also make log_write() can correctly process the request across
> > pages with write_address not start at page boundary.
> >
> > Signed-off-by: Jason Wang <jasowang@redhat.com>
>
> dd
> Thanks, good catch!
> But let's to it in small steps: first, a small patch to fix the bug:
> I think this is equivalent, right?
>
Yes.
> Subject: vhost: correctly set bits of dirty pages
>
> When counting pages we should increase address by 1 instead of
> VHOST_PAGE_SIZE, and also make log_write() can correctly process the
> request across pages with write_address not starting at page boundary.
>
> Reported-by: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>
I'm fine with this, thanks!
> ---
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 568eb70..d0a3552 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -887,6 +887,7 @@ static int log_write(void __user *log_base,
> int r;
> if (!write_length)
> return 0;
> + write_length += write_address % VHOST_PAGE_SIZE;
> write_address /= VHOST_PAGE_SIZE;
> for (;;) {
> u64 base = (u64)(unsigned long)log_base;
> @@ -900,7 +901,7 @@ static int log_write(void __user *log_base,
> if (write_length <= VHOST_PAGE_SIZE)
> break;
> write_length -= VHOST_PAGE_SIZE;
> - write_address += VHOST_PAGE_SIZE;
> + write_address += 1;
> }
> return r;
> }
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-11-29 13:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-29 5:48 [PATCH] vhost: correctly set bits of dirty pages Jason Wang
2010-11-29 8:18 ` Michael S. Tsirkin
2010-11-29 8:25 ` Michael S. Tsirkin
2010-11-29 13:50 ` Jason Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).