xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: Stefano Stabellini <sstabellini@kernel.org>
Cc: xen-devel@lists.xenproject.org, nd@arm.com
Subject: Re: [PATCH v5 2/3] xen/arm: move setting of new target vcpu to vgic_migrate_irq
Date: Fri, 3 Mar 2017 17:38:38 +0000	[thread overview]
Message-ID: <06e1c5ef-6d23-d0f6-41ea-42f4fe7ae799@arm.com> (raw)
In-Reply-To: <1488406545-26164-2-git-send-email-sstabellini@kernel.org>

Hi Stefano,

On 01/03/17 22:15, Stefano Stabellini wrote:
> Move the atomic write of rank->vcpu, which sets the new vcpu target, to
> vgic_migrate_irq, at the beginning of the lock protected area (protected
> by the vgic lock).
>
> This code movement reduces race conditions between vgic_migrate_irq and
> setting rank->vcpu on one pcpu and gic_update_one_lr on another pcpu.
>
> When gic_update_one_lr and vgic_migrate_irq take the same vgic lock,
> there are no more race conditions with this patch. When vgic_migrate_irq
> is called multiple times while GIC_IRQ_GUEST_MIGRATING is already set, a
> race condition still exists because in that case gic_update_one_lr and
> vgic_migrate_irq take different vgic locks.
>
> Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
>  xen/arch/arm/vgic-v2.c     |  5 ++---
>  xen/arch/arm/vgic-v3.c     |  4 +---
>  xen/arch/arm/vgic.c        | 15 ++++++++++-----
>  xen/include/asm-arm/vgic.h |  3 ++-
>  4 files changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/xen/arch/arm/vgic-v2.c b/xen/arch/arm/vgic-v2.c
> index 0674f7b..43b4ac3 100644
> --- a/xen/arch/arm/vgic-v2.c
> +++ b/xen/arch/arm/vgic-v2.c
> @@ -158,10 +158,9 @@ static void vgic_store_itargetsr(struct domain *d, struct vgic_irq_rank *rank,
>          {
>              vgic_migrate_irq(d->vcpu[old_target],
>                               d->vcpu[new_target],
> -                             virq);
> +                             virq,
> +                             &rank->vcpu[offset]);
>          }
> -
> -        write_atomic(&rank->vcpu[offset], new_target);

With this change rank->vcpu[offset] will not be updated for virtual SPIs 
(e.g p->desc != NULL). And therefore affinity for them will not work.

However, from my understanding the problem you are trying to solve with 
this patch is having rank->vcpu[offset] to be set as soon as possible. 
It does not really matter if it is protected by the lock, what you care 
is rank->vcpu[offset] been seen before the lock has been released.

So if GIC_IRQ_GUEST_MIGRATE is set and gic_update_one_lr is running 
straight after the lock is released, rank->vcpu[offset] will contain the 
correct vCPU.

A better approach would be to move write_atomic(...) before 
vgic_migrated_irq(...). What do you think?

Cheers,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-03-03 17:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-01 22:15 [PATCH v5 0/3] xen/arm: remove race conditions in irq migration Stefano Stabellini
2017-03-01 22:15 ` [PATCH v5 1/3] arm: remove irq from inflight, then change physical affinity Stefano Stabellini
2017-03-01 22:15   ` [PATCH v5 2/3] xen/arm: move setting of new target vcpu to vgic_migrate_irq Stefano Stabellini
2017-03-03 17:38     ` Julien Grall [this message]
2017-03-29 23:48       ` Stefano Stabellini
2017-03-31 15:29         ` Julien Grall
2017-03-01 22:15   ` [PATCH v5 3/3] xen/arm: vgic_migrate_irq: do not race against GIC_IRQ_GUEST_MIGRATING Stefano Stabellini
2017-03-03 17:47     ` Julien Grall
2017-03-29 23:47       ` Stefano Stabellini
2017-03-31 16:02         ` Julien Grall
2017-03-31 20:24           ` Stefano Stabellini
2017-04-03 11:03             ` Julien Grall
2017-04-03 21:24               ` Stefano Stabellini
2017-03-01 23:24   ` [PATCH v5 1/3] arm: remove irq from inflight, then change physical affinity Julien Grall
2017-03-03 17:04     ` Julien Grall
2017-03-03 19:34       ` Stefano Stabellini
2017-03-03 19:38         ` Julien Grall
2017-03-22 23:59           ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=06e1c5ef-6d23-d0f6-41ea-42f4fe7ae799@arm.com \
    --to=julien.grall@arm.com \
    --cc=nd@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).