public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem
@ 2011-05-03 15:37 Sasha Levin
  2011-05-03 15:37 ` [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header Sasha Levin
  2011-05-03 19:44 ` [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem Ingo Molnar
  0 siblings, 2 replies; 8+ messages in thread
From: Sasha Levin @ 2011-05-03 15:37 UTC (permalink / raw)
  To: penberg; +Cc: mingo, asias.hejun, gorcunov, prasadjoshi124, kvm, Sasha Levin

Increase idx only after updating the used element.
Not doing so may mark a buffer as used without having
it's head and length updated.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/virtio.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/virtio.c b/tools/kvm/virtio.c
index 6249521..b2d2407 100644
--- a/tools/kvm/virtio.c
+++ b/tools/kvm/virtio.c
@@ -7,9 +7,10 @@
 struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, uint32_t head, uint32_t len)
 {
 	struct vring_used_elem *used_elem;
-	used_elem	= &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num];
+	used_elem	= &queue->vring.used->ring[queue->vring.used->idx % queue->vring.num];
 	used_elem->id	= head;
 	used_elem->len	= len;
+	queue->vring.used->idx++;
 	return used_elem;
 }
 
-- 
1.7.5.rc3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header
  2011-05-03 15:37 [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem Sasha Levin
@ 2011-05-03 15:37 ` Sasha Levin
  2011-05-03 19:49   ` Ingo Molnar
  2011-05-03 19:44 ` [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem Ingo Molnar
  1 sibling, 1 reply; 8+ messages in thread
From: Sasha Levin @ 2011-05-03 15:37 UTC (permalink / raw)
  To: penberg; +Cc: mingo, asias.hejun, gorcunov, prasadjoshi124, kvm, Sasha Levin

The local kernel.h may redefine macros already
defined otherwise, wrap it with #ifdef.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/include/linux/kernel.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/include/linux/kernel.h b/tools/kvm/include/linux/kernel.h
index 8d83037..fccb624 100644
--- a/tools/kvm/include/linux/kernel.h
+++ b/tools/kvm/include/linux/kernel.h
@@ -1,10 +1,17 @@
 #ifndef KVM__LINUX_KERNEL_H_
 #define KVM__LINUX_KERNEL_H_
 
+#ifndef DIV_ROUND_UP
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#endif
 
+#ifndef ALIGN
 #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
+#endif
+
+#ifndef __ALIGN_MASK
 #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
+#endif
 
 #ifndef offsetof
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-- 
1.7.5.rc3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem
  2011-05-03 15:37 [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem Sasha Levin
  2011-05-03 15:37 ` [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header Sasha Levin
@ 2011-05-03 19:44 ` Ingo Molnar
  1 sibling, 0 replies; 8+ messages in thread
From: Ingo Molnar @ 2011-05-03 19:44 UTC (permalink / raw)
  To: Sasha Levin; +Cc: penberg, asias.hejun, gorcunov, prasadjoshi124, kvm


* Sasha Levin <levinsasha928@gmail.com> wrote:

> Increase idx only after updating the used element.
> Not doing so may mark a buffer as used without having
> it's head and length updated.
> 
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
>  tools/kvm/virtio.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/tools/kvm/virtio.c b/tools/kvm/virtio.c
> index 6249521..b2d2407 100644
> --- a/tools/kvm/virtio.c
> +++ b/tools/kvm/virtio.c
> @@ -7,9 +7,10 @@
>  struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, uint32_t head, uint32_t len)
>  {
>  	struct vring_used_elem *used_elem;
> -	used_elem	= &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num];
> +	used_elem	= &queue->vring.used->ring[queue->vring.used->idx % queue->vring.num];
>  	used_elem->id	= head;
>  	used_elem->len	= len;
> +	queue->vring.used->idx++;
>  	return used_elem;
>  }

Note that both the compiler and the CPU can reorder this code arbitrarily, so 
your patch does not address the problem.

As mentioned in earlier discussions, you need memory barriers (which also act 
as compiler barriers) to express this dependency in the order of updates to 
these data structures.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header
  2011-05-03 15:37 ` [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header Sasha Levin
@ 2011-05-03 19:49   ` Ingo Molnar
  2011-05-03 19:56     ` Sasha Levin
  0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2011-05-03 19:49 UTC (permalink / raw)
  To: Sasha Levin; +Cc: penberg, asias.hejun, gorcunov, prasadjoshi124, kvm


* Sasha Levin <levinsasha928@gmail.com> wrote:

> The local kernel.h may redefine macros already
> defined otherwise, wrap it with #ifdef.
> 
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
>  tools/kvm/include/linux/kernel.h |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/kvm/include/linux/kernel.h b/tools/kvm/include/linux/kernel.h
> index 8d83037..fccb624 100644
> --- a/tools/kvm/include/linux/kernel.h
> +++ b/tools/kvm/include/linux/kernel.h
> @@ -1,10 +1,17 @@
>  #ifndef KVM__LINUX_KERNEL_H_
>  #define KVM__LINUX_KERNEL_H_
>  
> +#ifndef DIV_ROUND_UP
>  #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> +#endif
>  
> +#ifndef ALIGN
>  #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
> +#endif
> +
> +#ifndef __ALIGN_MASK
>  #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
> +#endif

Hm, how can duplicate definitions happen? Only one place should define them - 
otherwise we might end up with incompatible definitions ...

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header
  2011-05-03 19:49   ` Ingo Molnar
@ 2011-05-03 19:56     ` Sasha Levin
  2011-05-03 19:59       ` Ingo Molnar
  0 siblings, 1 reply; 8+ messages in thread
From: Sasha Levin @ 2011-05-03 19:56 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: penberg, asias.hejun, gorcunov, prasadjoshi124, kvm

On Tue, 2011-05-03 at 21:49 +0200, Ingo Molnar wrote:
> * Sasha Levin <levinsasha928@gmail.com> wrote:
> 
> > The local kernel.h may redefine macros already
> > defined otherwise, wrap it with #ifdef.
> > 
> > Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> > ---
> >  tools/kvm/include/linux/kernel.h |    7 +++++++
> >  1 files changed, 7 insertions(+), 0 deletions(-)
> > 
> > diff --git a/tools/kvm/include/linux/kernel.h b/tools/kvm/include/linux/kernel.h
> > index 8d83037..fccb624 100644
> > --- a/tools/kvm/include/linux/kernel.h
> > +++ b/tools/kvm/include/linux/kernel.h
> > @@ -1,10 +1,17 @@
> >  #ifndef KVM__LINUX_KERNEL_H_
> >  #define KVM__LINUX_KERNEL_H_
> >  
> > +#ifndef DIV_ROUND_UP
> >  #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> > +#endif
> >  
> > +#ifndef ALIGN
> >  #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
> > +#endif
> > +
> > +#ifndef __ALIGN_MASK
> >  #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
> > +#endif
> 
> Hm, how can duplicate definitions happen? Only one place should define them - 
> otherwise we might end up with incompatible definitions ...

We has ALIGN defined in include/kvm/bios.h within our code.

-- 

Sasha.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header
  2011-05-03 19:56     ` Sasha Levin
@ 2011-05-03 19:59       ` Ingo Molnar
  2011-05-03 20:10         ` Cyrill Gorcunov
  0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2011-05-03 19:59 UTC (permalink / raw)
  To: Sasha Levin; +Cc: penberg, asias.hejun, gorcunov, prasadjoshi124, kvm


* Sasha Levin <levinsasha928@gmail.com> wrote:

> On Tue, 2011-05-03 at 21:49 +0200, Ingo Molnar wrote:
> > * Sasha Levin <levinsasha928@gmail.com> wrote:
> > 
> > > The local kernel.h may redefine macros already
> > > defined otherwise, wrap it with #ifdef.
> > > 
> > > Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> > > ---
> > >  tools/kvm/include/linux/kernel.h |    7 +++++++
> > >  1 files changed, 7 insertions(+), 0 deletions(-)
> > > 
> > > diff --git a/tools/kvm/include/linux/kernel.h b/tools/kvm/include/linux/kernel.h
> > > index 8d83037..fccb624 100644
> > > --- a/tools/kvm/include/linux/kernel.h
> > > +++ b/tools/kvm/include/linux/kernel.h
> > > @@ -1,10 +1,17 @@
> > >  #ifndef KVM__LINUX_KERNEL_H_
> > >  #define KVM__LINUX_KERNEL_H_
> > >  
> > > +#ifndef DIV_ROUND_UP
> > >  #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> > > +#endif
> > >  
> > > +#ifndef ALIGN
> > >  #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
> > > +#endif
> > > +
> > > +#ifndef __ALIGN_MASK
> > >  #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
> > > +#endif
> > 
> > Hm, how can duplicate definitions happen? Only one place should define them - 
> > otherwise we might end up with incompatible definitions ...
> 
> We has ALIGN defined in include/kvm/bios.h within our code.

Well, but then the right solution would be to not define it there but remove 
it, and use the one we get from the kernel headers?

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header
  2011-05-03 19:59       ` Ingo Molnar
@ 2011-05-03 20:10         ` Cyrill Gorcunov
  2011-05-03 20:27           ` Cyrill Gorcunov
  0 siblings, 1 reply; 8+ messages in thread
From: Cyrill Gorcunov @ 2011-05-03 20:10 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Sasha Levin, penberg, asias.hejun, prasadjoshi124, kvm

On 05/03/2011 11:59 PM, Ingo Molnar wrote:
...
>>>
>>> Hm, how can duplicate definitions happen? Only one place should define them - 
>>> otherwise we might end up with incompatible definitions ...
>>
>> We has ALIGN defined in include/kvm/bios.h within our code.
> 
> Well, but then the right solution would be to not define it there but remove 
> it, and use the one we get from the kernel headers?
> 
> Thanks,
> 
> 	Ingo

  Yeah, the right way indeed to use kernel header. The former ALIGN was introduced by
me I fear when kvm tools were out of linux tree, ie quite early. Sasha mind to simply
drop the former ALIGN out?

-- 
Thanks,
  Cyrill

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header
  2011-05-03 20:10         ` Cyrill Gorcunov
@ 2011-05-03 20:27           ` Cyrill Gorcunov
  0 siblings, 0 replies; 8+ messages in thread
From: Cyrill Gorcunov @ 2011-05-03 20:27 UTC (permalink / raw)
  To: Sasha Levin; +Cc: Ingo Molnar, penberg, asias.hejun, prasadjoshi124, kvm

On 05/04/2011 12:10 AM, Cyrill Gorcunov wrote:
> On 05/03/2011 11:59 PM, Ingo Molnar wrote:
> ...
>>>>
>>>> Hm, how can duplicate definitions happen? Only one place should define them - 
>>>> otherwise we might end up with incompatible definitions ...
>>>
>>> We has ALIGN defined in include/kvm/bios.h within our code.
>>
>> Well, but then the right solution would be to not define it there but remove 
>> it, and use the one we get from the kernel headers?
>>
>> Thanks,
>>
>> 	Ingo
> 
>   Yeah, the right way indeed to use kernel header. The former ALIGN was introduced by
> me I fear when kvm tools were out of linux tree, ie quite early. Sasha mind to simply
> drop the former ALIGN out?
> 

  Sasha, could you please also drop this lines from bios.h

#ifndef ALIGN
#define ALIGN(x, a)	\
	(((x) + ((a) - 1)) & ~((a) - 1))
#endif

/*
 * note we use 16 bytes alignment which makes segment based
 * addressing easy to compute, dont change it otherwise you
 * may break local variables offsets in BIOS irq routines
 */
#define BIOS_NEXT_IRQ_ADDR(addr, size)	\
	ALIGN((addr + size + 1), 16)

they are rudiments.

-- 
Thanks,
  Cyrill

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-05-03 20:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-03 15:37 [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem Sasha Levin
2011-05-03 15:37 ` [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header Sasha Levin
2011-05-03 19:49   ` Ingo Molnar
2011-05-03 19:56     ` Sasha Levin
2011-05-03 19:59       ` Ingo Molnar
2011-05-03 20:10         ` Cyrill Gorcunov
2011-05-03 20:27           ` Cyrill Gorcunov
2011-05-03 19:44 ` [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox