Re: [Xen-devel] [v3 08/15] Suppress posting interrupts when 'SN' is set

2015-07-10 Thread Jan Beulich
>>> On 24.06.15 at 07:18,  wrote:
> @@ -1698,13 +1700,35 @@ static void vmx_deliver_posted_intr(struct vcpu *v, 
> u8 vector)
>   */
>  pi_set_on(&v->arch.hvm_vmx.pi_desc);
>  }
> -else if ( !pi_test_and_set_on(&v->arch.hvm_vmx.pi_desc) )
> +else
>  {
> +prev.control = 0;
> +
> +do {
> +old.control = v->arch.hvm_vmx.pi_desc.control &
> +  ~(1 << POSTED_INTR_ON | 1 << POSTED_INTR_SN);
> +new.control = v->arch.hvm_vmx.pi_desc.control |
> +  1 << POSTED_INTR_ON;
> +
> +/*
> + * Currently, we don't support urgent interrupt, all
> + * interrupts are recognized as non-urgent interrupt,
> + * so we cannot send posted-interrupt when 'SN' is set.
> + * Besides that, if 'ON' is already set, we cannot set
> + * posted-interrupts as well.
> + */
> +if ( prev.sn || prev.on )
> +{
> +vcpu_kick(v);
> +return;
> +}
> +
> +prev.control = cmpxchg(&v->arch.hvm_vmx.pi_desc.control,
> +   old.control, new.control);
> +} while ( prev.control != old.control );

This pretty clearly demonstrates that mixing bitfields and non-bitfield
mask operations makes code hard to read: How is one supposed to
see at the first glance that e.g. prev.on and
old.control & (1 << POSTED_INTR_ON) are the same thing?

Jan


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [v3 08/15] Suppress posting interrupts when 'SN' is set

2015-07-08 Thread Wu, Feng


> -Original Message-
> From: Tian, Kevin
> Sent: Wednesday, July 08, 2015 7:31 PM
> To: Wu, Feng; xen-devel@lists.xen.org
> Cc: k...@xen.org; jbeul...@suse.com; andrew.coop...@citrix.com; Zhang,
> Yang Z; george.dun...@eu.citrix.com
> Subject: RE: [v3 08/15] Suppress posting interrupts when 'SN' is set
> 
> > From: Wu, Feng
> > Sent: Wednesday, July 08, 2015 6:11 PM
> > > From: Tian, Kevin
> > > Sent: Wednesday, July 08, 2015 5:06 PM
> > >
> > > > From: Wu, Feng
> > > > Sent: Wednesday, June 24, 2015 1:18 PM
> > > >
> > > > Currently, we don't support urgent interrupt, all interrupts
> > > > are recognized as non-urgent interrupt, so we cannot send
> > > > posted-interrupt when 'SN' is set.
> > > >
> > > > Signed-off-by: Feng Wu 
> > > > ---
> > > > v3:
> > > > use cmpxchg to test SN/ON and set ON
> > > >
> > > >  xen/arch/x86/hvm/vmx/vmx.c | 32
> > 
> > > >  1 file changed, 28 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> > > > index 0837627..b94ef6a 100644
> > > > --- a/xen/arch/x86/hvm/vmx/vmx.c
> > > > +++ b/xen/arch/x86/hvm/vmx/vmx.c
> > > > @@ -1686,6 +1686,8 @@ static void
> __vmx_deliver_posted_interrupt(struct
> > > vcpu *v)
> > > >
> > > >  static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
> > > >  {
> > > > +struct pi_desc old, new, prev;
> > > > +
> > >
> > > move to 'else if'.
> > >
> > > >  if ( pi_test_and_set_pir(vector, &v->arch.hvm_vmx.pi_desc) )
> > > >  return;
> > > >
> > > > @@ -1698,13 +1700,35 @@ static void vmx_deliver_posted_intr(struct
> vcpu
> > > *v, u8
> > > > vector)
> > > >   */
> > > >  pi_set_on(&v->arch.hvm_vmx.pi_desc);
> > > >  }
> > > > -else if ( !pi_test_and_set_on(&v->arch.hvm_vmx.pi_desc) )
> > > > +else
> > > >  {
> > > > +prev.control = 0;
> > > > +
> > > > +do {
> > > > +old.control = v->arch.hvm_vmx.pi_desc.control &
> > > > +  ~(1 << POSTED_INTR_ON | 1 <<
> > > POSTED_INTR_SN);
> > > > +new.control = v->arch.hvm_vmx.pi_desc.control |
> > > > +  1 << POSTED_INTR_ON;
> > > > +
> > > > +/*
> > > > + * Currently, we don't support urgent interrupt, all
> > > > + * interrupts are recognized as non-urgent interrupt,
> > > > + * so we cannot send posted-interrupt when 'SN' is set.
> > > > + * Besides that, if 'ON' is already set, we cannot set
> > > > + * posted-interrupts as well.
> > > > + */
> > > > +if ( prev.sn || prev.on )
> > > > +{
> > > > +vcpu_kick(v);
> > > > +return;
> > > > +}
> > >
> > > would it make more sense to move above check after cmpxchg?
> >
> > My original idea is that, we only need to do the check when
> > prev.control != old.control, which means the cmpxchg is not
> > successful completed. If we add the check between cmpxchg
> > and while ( prev.control != old.control ), it seems the logic is
> > not so clear, since we don't need to check prev.sn and prev.on
> > when cmxchg succeeds in setting the new value.
> >
> > Thanks,
> > Feng
> >
> 
> Then it'd be clearer if you move the check the start of the loop, so
> you can avoid two additional reads when the prev.on/sn is set. :-)

Good idea!

Thanks,
Feng

> 
> Thanks
> Kevin

___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [v3 08/15] Suppress posting interrupts when 'SN' is set

2015-07-08 Thread Tian, Kevin
> From: Wu, Feng
> Sent: Wednesday, July 08, 2015 6:11 PM
> > From: Tian, Kevin
> > Sent: Wednesday, July 08, 2015 5:06 PM
> >
> > > From: Wu, Feng
> > > Sent: Wednesday, June 24, 2015 1:18 PM
> > >
> > > Currently, we don't support urgent interrupt, all interrupts
> > > are recognized as non-urgent interrupt, so we cannot send
> > > posted-interrupt when 'SN' is set.
> > >
> > > Signed-off-by: Feng Wu 
> > > ---
> > > v3:
> > > use cmpxchg to test SN/ON and set ON
> > >
> > >  xen/arch/x86/hvm/vmx/vmx.c | 32
> 
> > >  1 file changed, 28 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> > > index 0837627..b94ef6a 100644
> > > --- a/xen/arch/x86/hvm/vmx/vmx.c
> > > +++ b/xen/arch/x86/hvm/vmx/vmx.c
> > > @@ -1686,6 +1686,8 @@ static void __vmx_deliver_posted_interrupt(struct
> > vcpu *v)
> > >
> > >  static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
> > >  {
> > > +struct pi_desc old, new, prev;
> > > +
> >
> > move to 'else if'.
> >
> > >  if ( pi_test_and_set_pir(vector, &v->arch.hvm_vmx.pi_desc) )
> > >  return;
> > >
> > > @@ -1698,13 +1700,35 @@ static void vmx_deliver_posted_intr(struct vcpu
> > *v, u8
> > > vector)
> > >   */
> > >  pi_set_on(&v->arch.hvm_vmx.pi_desc);
> > >  }
> > > -else if ( !pi_test_and_set_on(&v->arch.hvm_vmx.pi_desc) )
> > > +else
> > >  {
> > > +prev.control = 0;
> > > +
> > > +do {
> > > +old.control = v->arch.hvm_vmx.pi_desc.control &
> > > +  ~(1 << POSTED_INTR_ON | 1 <<
> > POSTED_INTR_SN);
> > > +new.control = v->arch.hvm_vmx.pi_desc.control |
> > > +  1 << POSTED_INTR_ON;
> > > +
> > > +/*
> > > + * Currently, we don't support urgent interrupt, all
> > > + * interrupts are recognized as non-urgent interrupt,
> > > + * so we cannot send posted-interrupt when 'SN' is set.
> > > + * Besides that, if 'ON' is already set, we cannot set
> > > + * posted-interrupts as well.
> > > + */
> > > +if ( prev.sn || prev.on )
> > > +{
> > > +vcpu_kick(v);
> > > +return;
> > > +}
> >
> > would it make more sense to move above check after cmpxchg?
> 
> My original idea is that, we only need to do the check when
> prev.control != old.control, which means the cmpxchg is not
> successful completed. If we add the check between cmpxchg
> and while ( prev.control != old.control ), it seems the logic is
> not so clear, since we don't need to check prev.sn and prev.on
> when cmxchg succeeds in setting the new value.
> 
> Thanks,
> Feng
> 

Then it'd be clearer if you move the check the start of the loop, so
you can avoid two additional reads when the prev.on/sn is set. :-)

Thanks
Kevin

___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [v3 08/15] Suppress posting interrupts when 'SN' is set

2015-07-08 Thread Wu, Feng


> -Original Message-
> From: Tian, Kevin
> Sent: Wednesday, July 08, 2015 5:06 PM
> To: Wu, Feng; xen-devel@lists.xen.org
> Cc: k...@xen.org; jbeul...@suse.com; andrew.coop...@citrix.com; Zhang,
> Yang Z; george.dun...@eu.citrix.com
> Subject: RE: [v3 08/15] Suppress posting interrupts when 'SN' is set
> 
> > From: Wu, Feng
> > Sent: Wednesday, June 24, 2015 1:18 PM
> >
> > Currently, we don't support urgent interrupt, all interrupts
> > are recognized as non-urgent interrupt, so we cannot send
> > posted-interrupt when 'SN' is set.
> >
> > Signed-off-by: Feng Wu 
> > ---
> > v3:
> > use cmpxchg to test SN/ON and set ON
> >
> >  xen/arch/x86/hvm/vmx/vmx.c | 32 
> >  1 file changed, 28 insertions(+), 4 deletions(-)
> >
> > diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> > index 0837627..b94ef6a 100644
> > --- a/xen/arch/x86/hvm/vmx/vmx.c
> > +++ b/xen/arch/x86/hvm/vmx/vmx.c
> > @@ -1686,6 +1686,8 @@ static void __vmx_deliver_posted_interrupt(struct
> vcpu *v)
> >
> >  static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
> >  {
> > +struct pi_desc old, new, prev;
> > +
> 
> move to 'else if'.
> 
> >  if ( pi_test_and_set_pir(vector, &v->arch.hvm_vmx.pi_desc) )
> >  return;
> >
> > @@ -1698,13 +1700,35 @@ static void vmx_deliver_posted_intr(struct vcpu
> *v, u8
> > vector)
> >   */
> >  pi_set_on(&v->arch.hvm_vmx.pi_desc);
> >  }
> > -else if ( !pi_test_and_set_on(&v->arch.hvm_vmx.pi_desc) )
> > +else
> >  {
> > +prev.control = 0;
> > +
> > +do {
> > +old.control = v->arch.hvm_vmx.pi_desc.control &
> > +  ~(1 << POSTED_INTR_ON | 1 <<
> POSTED_INTR_SN);
> > +new.control = v->arch.hvm_vmx.pi_desc.control |
> > +  1 << POSTED_INTR_ON;
> > +
> > +/*
> > + * Currently, we don't support urgent interrupt, all
> > + * interrupts are recognized as non-urgent interrupt,
> > + * so we cannot send posted-interrupt when 'SN' is set.
> > + * Besides that, if 'ON' is already set, we cannot set
> > + * posted-interrupts as well.
> > + */
> > +if ( prev.sn || prev.on )
> > +{
> > +vcpu_kick(v);
> > +return;
> > +}
> 
> would it make more sense to move above check after cmpxchg?

My original idea is that, we only need to do the check when
prev.control != old.control, which means the cmpxchg is not
successful completed. If we add the check between cmpxchg
and while ( prev.control != old.control ), it seems the logic is
not so clear, since we don't need to check prev.sn and prev.on
when cmxchg succeeds in setting the new value.

Thanks,
Feng

> 
> > +
> > +prev.control = cmpxchg(&v->arch.hvm_vmx.pi_desc.control,
> > +   old.control, new.control);
> > +} while ( prev.control != old.control );
> > +
> >  __vmx_deliver_posted_interrupt(v);
> > -return;
> >  }
> > -
> > -vcpu_kick(v);
> >  }
> >
> >  static void vmx_sync_pir_to_irr(struct vcpu *v)
> > --
> > 2.1.0


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [v3 08/15] Suppress posting interrupts when 'SN' is set

2015-07-08 Thread Tian, Kevin
> From: Wu, Feng
> Sent: Wednesday, June 24, 2015 1:18 PM
> 
> Currently, we don't support urgent interrupt, all interrupts
> are recognized as non-urgent interrupt, so we cannot send
> posted-interrupt when 'SN' is set.
> 
> Signed-off-by: Feng Wu 
> ---
> v3:
> use cmpxchg to test SN/ON and set ON
> 
>  xen/arch/x86/hvm/vmx/vmx.c | 32 
>  1 file changed, 28 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> index 0837627..b94ef6a 100644
> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -1686,6 +1686,8 @@ static void __vmx_deliver_posted_interrupt(struct vcpu 
> *v)
> 
>  static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
>  {
> +struct pi_desc old, new, prev;
> +

move to 'else if'.

>  if ( pi_test_and_set_pir(vector, &v->arch.hvm_vmx.pi_desc) )
>  return;
> 
> @@ -1698,13 +1700,35 @@ static void vmx_deliver_posted_intr(struct vcpu *v, u8
> vector)
>   */
>  pi_set_on(&v->arch.hvm_vmx.pi_desc);
>  }
> -else if ( !pi_test_and_set_on(&v->arch.hvm_vmx.pi_desc) )
> +else
>  {
> +prev.control = 0;
> +
> +do {
> +old.control = v->arch.hvm_vmx.pi_desc.control &
> +  ~(1 << POSTED_INTR_ON | 1 << POSTED_INTR_SN);
> +new.control = v->arch.hvm_vmx.pi_desc.control |
> +  1 << POSTED_INTR_ON;
> +
> +/*
> + * Currently, we don't support urgent interrupt, all
> + * interrupts are recognized as non-urgent interrupt,
> + * so we cannot send posted-interrupt when 'SN' is set.
> + * Besides that, if 'ON' is already set, we cannot set
> + * posted-interrupts as well.
> + */
> +if ( prev.sn || prev.on )
> +{
> +vcpu_kick(v);
> +return;
> +}

would it make more sense to move above check after cmpxchg?

> +
> +prev.control = cmpxchg(&v->arch.hvm_vmx.pi_desc.control,
> +   old.control, new.control);
> +} while ( prev.control != old.control );
> +
>  __vmx_deliver_posted_interrupt(v);
> -return;
>  }
> -
> -vcpu_kick(v);
>  }
> 
>  static void vmx_sync_pir_to_irr(struct vcpu *v)
> --
> 2.1.0


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [v3 08/15] Suppress posting interrupts when 'SN' is set

2015-06-29 Thread Wu, Feng


> -Original Message-
> From: Andrew Cooper [mailto:andrew.coop...@citrix.com]
> Sent: Monday, June 29, 2015 11:41 PM
> To: Wu, Feng; xen-devel@lists.xen.org
> Cc: Tian, Kevin; k...@xen.org; george.dun...@eu.citrix.com;
> jbeul...@suse.com; Zhang, Yang Z
> Subject: Re: [Xen-devel] [v3 08/15] Suppress posting interrupts when 'SN' is 
> set
> 
> On 24/06/15 06:18, Feng Wu wrote:
> > Currently, we don't support urgent interrupt, all interrupts
> > are recognized as non-urgent interrupt, so we cannot send
> > posted-interrupt when 'SN' is set.
> >
> > Signed-off-by: Feng Wu 
> > ---
> > v3:
> > use cmpxchg to test SN/ON and set ON
> >
> >  xen/arch/x86/hvm/vmx/vmx.c | 32 
> >  1 file changed, 28 insertions(+), 4 deletions(-)
> >
> > diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> > index 0837627..b94ef6a 100644
> > --- a/xen/arch/x86/hvm/vmx/vmx.c
> > +++ b/xen/arch/x86/hvm/vmx/vmx.c
> > @@ -1686,6 +1686,8 @@ static void __vmx_deliver_posted_interrupt(struct
> vcpu *v)
> >
> >  static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
> >  {
> > +struct pi_desc old, new, prev;
> 
> These should be moved into the else clause below, to reduce their scope.
> 
> > +
> >  if ( pi_test_and_set_pir(vector, &v->arch.hvm_vmx.pi_desc) )
> >  return;
> >
> > @@ -1698,13 +1700,35 @@ static void vmx_deliver_posted_intr(struct vcpu
> *v, u8 vector)
> >   */
> >  pi_set_on(&v->arch.hvm_vmx.pi_desc);
> >  }
> > -else if ( !pi_test_and_set_on(&v->arch.hvm_vmx.pi_desc) )
> > +else
> >  {
> > +prev.control = 0;
> > +
> > +do {
> > +old.control = v->arch.hvm_vmx.pi_desc.control &
> > +  ~(1 << POSTED_INTR_ON | 1 <<
> POSTED_INTR_SN);
> 
> Brackets around each of the 1 << $NNN please.
> 
> > +new.control = v->arch.hvm_vmx.pi_desc.control |
> > +  1 << POSTED_INTR_ON;
> > +
> > +/*
> > + * Currently, we don't support urgent interrupt, all
> > + * interrupts are recognized as non-urgent interrupt,
> > + * so we cannot send posted-interrupt when 'SN' is set.
> > + * Besides that, if 'ON' is already set, we cannot set
> > + * posted-interrupts as well.
> > + */
> > +if ( prev.sn || prev.on )
> > +{
> > +vcpu_kick(v);
> > +return;
> > +}
> > +
> > +prev.control = cmpxchg(&v->arch.hvm_vmx.pi_desc.control,
> > +   old.control, new.control);
> > +} while ( prev.control != old.control );
> > +
> >  __vmx_deliver_posted_interrupt(v);
> > -return;
> >  }
> > -
> > -vcpu_kick(v);
> 
> This removes a vcpu_kick() from the eoi_exitmap_changed path, which I
> suspect is not what you intend.

Oops.. thanks for pointing it out!

Thanks,
Feng

> 
> ~Andrew
> 
> >  }
> >
> >  static void vmx_sync_pir_to_irr(struct vcpu *v)


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [v3 08/15] Suppress posting interrupts when 'SN' is set

2015-06-29 Thread Andrew Cooper
On 24/06/15 06:18, Feng Wu wrote:
> Currently, we don't support urgent interrupt, all interrupts
> are recognized as non-urgent interrupt, so we cannot send
> posted-interrupt when 'SN' is set.
>
> Signed-off-by: Feng Wu 
> ---
> v3:
> use cmpxchg to test SN/ON and set ON
>
>  xen/arch/x86/hvm/vmx/vmx.c | 32 
>  1 file changed, 28 insertions(+), 4 deletions(-)
>
> diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> index 0837627..b94ef6a 100644
> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -1686,6 +1686,8 @@ static void __vmx_deliver_posted_interrupt(struct vcpu 
> *v)
>  
>  static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
>  {
> +struct pi_desc old, new, prev;

These should be moved into the else clause below, to reduce their scope.

> +
>  if ( pi_test_and_set_pir(vector, &v->arch.hvm_vmx.pi_desc) )
>  return;
>  
> @@ -1698,13 +1700,35 @@ static void vmx_deliver_posted_intr(struct vcpu *v, 
> u8 vector)
>   */
>  pi_set_on(&v->arch.hvm_vmx.pi_desc);
>  }
> -else if ( !pi_test_and_set_on(&v->arch.hvm_vmx.pi_desc) )
> +else
>  {
> +prev.control = 0;
> +
> +do {
> +old.control = v->arch.hvm_vmx.pi_desc.control &
> +  ~(1 << POSTED_INTR_ON | 1 << POSTED_INTR_SN);

Brackets around each of the 1 << $NNN please.

> +new.control = v->arch.hvm_vmx.pi_desc.control |
> +  1 << POSTED_INTR_ON;
> +
> +/*
> + * Currently, we don't support urgent interrupt, all
> + * interrupts are recognized as non-urgent interrupt,
> + * so we cannot send posted-interrupt when 'SN' is set.
> + * Besides that, if 'ON' is already set, we cannot set
> + * posted-interrupts as well.
> + */
> +if ( prev.sn || prev.on )
> +{
> +vcpu_kick(v);
> +return;
> +}
> +
> +prev.control = cmpxchg(&v->arch.hvm_vmx.pi_desc.control,
> +   old.control, new.control);
> +} while ( prev.control != old.control );
> +
>  __vmx_deliver_posted_interrupt(v);
> -return;
>  }
> -
> -vcpu_kick(v);

This removes a vcpu_kick() from the eoi_exitmap_changed path, which I
suspect is not what you intend.

~Andrew

>  }
>  
>  static void vmx_sync_pir_to_irr(struct vcpu *v)


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


[Xen-devel] [v3 08/15] Suppress posting interrupts when 'SN' is set

2015-06-23 Thread Feng Wu
Currently, we don't support urgent interrupt, all interrupts
are recognized as non-urgent interrupt, so we cannot send
posted-interrupt when 'SN' is set.

Signed-off-by: Feng Wu 
---
v3:
use cmpxchg to test SN/ON and set ON

 xen/arch/x86/hvm/vmx/vmx.c | 32 
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 0837627..b94ef6a 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1686,6 +1686,8 @@ static void __vmx_deliver_posted_interrupt(struct vcpu *v)
 
 static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
 {
+struct pi_desc old, new, prev;
+
 if ( pi_test_and_set_pir(vector, &v->arch.hvm_vmx.pi_desc) )
 return;
 
@@ -1698,13 +1700,35 @@ static void vmx_deliver_posted_intr(struct vcpu *v, u8 
vector)
  */
 pi_set_on(&v->arch.hvm_vmx.pi_desc);
 }
-else if ( !pi_test_and_set_on(&v->arch.hvm_vmx.pi_desc) )
+else
 {
+prev.control = 0;
+
+do {
+old.control = v->arch.hvm_vmx.pi_desc.control &
+  ~(1 << POSTED_INTR_ON | 1 << POSTED_INTR_SN);
+new.control = v->arch.hvm_vmx.pi_desc.control |
+  1 << POSTED_INTR_ON;
+
+/*
+ * Currently, we don't support urgent interrupt, all
+ * interrupts are recognized as non-urgent interrupt,
+ * so we cannot send posted-interrupt when 'SN' is set.
+ * Besides that, if 'ON' is already set, we cannot set
+ * posted-interrupts as well.
+ */
+if ( prev.sn || prev.on )
+{
+vcpu_kick(v);
+return;
+}
+
+prev.control = cmpxchg(&v->arch.hvm_vmx.pi_desc.control,
+   old.control, new.control);
+} while ( prev.control != old.control );
+
 __vmx_deliver_posted_interrupt(v);
-return;
 }
-
-vcpu_kick(v);
 }
 
 static void vmx_sync_pir_to_irr(struct vcpu *v)
-- 
2.1.0


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel