From: Julien Grall <julien.grall@arm.com>
To: Andre Przywara <andre.przywara@arm.com>,
Stefano Stabellini <sstabellini@kernel.org>
Cc: xen-devel@lists.xenproject.org
Subject: Re: [RFC PATCH 01/10] ARM: vGIC: remove rank lock from IRQ routing functions
Date: Thu, 4 May 2017 16:53:04 +0100 [thread overview]
Message-ID: <1c11740c-d9f5-8ab7-2b43-6c76be81a6fb@arm.com> (raw)
In-Reply-To: <20170504153123.1204-2-andre.przywara@arm.com>
Hi Andre,
On 04/05/17 16:31, Andre Przywara wrote:
> gic_route_irq_to_guest() and gic_remove_irq_from_guest() take the rank
> lock, however never actually access the rank structure.
> Avoid taking the lock in those two functions and remove some more
> unneeded code on the way.
The rank is here to protect p->desc when checking that the virtual
interrupt was not yet routed to another physical interrupt.
Without this locking, you can have two concurrent call of
gic_route_irq_to_guest that will update the same virtual interrupt but
with different physical interrupts.
You would have to replace the rank lock by the per-pending_irq lock to
keep the code safe.
Cheers,
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> xen/arch/arm/gic.c | 28 ++++------------------------
> 1 file changed, 4 insertions(+), 24 deletions(-)
>
> diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c
> index da19130..c734f66 100644
> --- a/xen/arch/arm/gic.c
> +++ b/xen/arch/arm/gic.c
> @@ -136,25 +136,19 @@ void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority)
> int gic_route_irq_to_guest(struct domain *d, unsigned int virq,
> struct irq_desc *desc, unsigned int priority)
> {
> - unsigned long flags;
> /* Use vcpu0 to retrieve the pending_irq struct. Given that we only
> * route SPIs to guests, it doesn't make any difference. */
> - struct vcpu *v_target = vgic_get_target_vcpu(d->vcpu[0], virq);
> - struct vgic_irq_rank *rank = vgic_rank_irq(v_target, virq);
> - struct pending_irq *p = irq_to_pending(v_target, virq);
> - int res = -EBUSY;
> + struct pending_irq *p = irq_to_pending(d->vcpu[0], virq);
>
> ASSERT(spin_is_locked(&desc->lock));
> /* Caller has already checked that the IRQ is an SPI */
> ASSERT(virq >= 32);
> ASSERT(virq < vgic_num_irqs(d));
>
> - vgic_lock_rank(v_target, rank, flags);
> -
> if ( p->desc ||
> /* The VIRQ should not be already enabled by the guest */
> test_bit(GIC_IRQ_GUEST_ENABLED, &p->status) )
> - goto out;
> + return -EBUSY;
>
> desc->handler = gic_hw_ops->gic_guest_irq_type;
> set_bit(_IRQ_GUEST, &desc->status);
> @@ -164,29 +158,20 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int virq,
> gic_set_irq_priority(desc, priority);
>
> p->desc = desc;
> - res = 0;
>
> -out:
> - vgic_unlock_rank(v_target, rank, flags);
> -
> - return res;
> + return 0;
> }
>
> /* This function only works with SPIs for now */
> int gic_remove_irq_from_guest(struct domain *d, unsigned int virq,
> struct irq_desc *desc)
> {
> - struct vcpu *v_target = vgic_get_target_vcpu(d->vcpu[0], virq);
> - struct vgic_irq_rank *rank = vgic_rank_irq(v_target, virq);
> - struct pending_irq *p = irq_to_pending(v_target, virq);
> - unsigned long flags;
> + struct pending_irq *p = irq_to_pending(d->vcpu[0], virq);
>
> ASSERT(spin_is_locked(&desc->lock));
> ASSERT(test_bit(_IRQ_GUEST, &desc->status));
> ASSERT(p->desc == desc);
>
> - vgic_lock_rank(v_target, rank, flags);
> -
> if ( d->is_dying )
> {
> desc->handler->shutdown(desc);
> @@ -204,10 +189,7 @@ int gic_remove_irq_from_guest(struct domain *d, unsigned int virq,
> */
> if ( test_bit(_IRQ_INPROGRESS, &desc->status) ||
> !test_bit(_IRQ_DISABLED, &desc->status) )
> - {
> - vgic_unlock_rank(v_target, rank, flags);
> return -EBUSY;
> - }
> }
>
> clear_bit(_IRQ_GUEST, &desc->status);
> @@ -215,8 +197,6 @@ int gic_remove_irq_from_guest(struct domain *d, unsigned int virq,
>
> p->desc = NULL;
>
> - vgic_unlock_rank(v_target, rank, flags);
> -
> return 0;
> }
>
>
--
Julien Grall
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-05-04 15:53 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-04 15:31 [RFC PATCH 00/10] ARM VGIC rework: remove rank, introduce per-IRQ lock Andre Przywara
2017-05-04 15:31 ` [RFC PATCH 01/10] ARM: vGIC: remove rank lock from IRQ routing functions Andre Przywara
2017-05-04 15:53 ` Julien Grall [this message]
2017-05-08 9:15 ` Andre Przywara
2017-05-08 14:26 ` Julien Grall
2017-05-08 21:53 ` Stefano Stabellini
2017-05-08 22:13 ` Julien Grall
2017-05-09 0:47 ` Stefano Stabellini
2017-05-09 15:24 ` Julien Grall
2017-05-04 15:31 ` [RFC PATCH 02/10] ARM: vGIC: rework gic_raise_*_irq() functions Andre Przywara
2017-05-04 15:31 ` [RFC PATCH 03/10] ARM: vGIC: introduce and initialize pending_irq lock Andre Przywara
2017-05-04 15:31 ` [RFC PATCH 04/10] ARM: vGIC: add struct pending_irq locking Andre Przywara
2017-05-04 16:21 ` Julien Grall
2017-05-05 9:02 ` Andre Przywara
2017-05-05 23:29 ` Stefano Stabellini
2017-05-06 6:41 ` Julien Grall
2017-05-05 23:42 ` Stefano Stabellini
2017-05-04 16:54 ` Julien Grall
2017-05-05 23:26 ` Stefano Stabellini
2017-05-04 15:31 ` [RFC PATCH 05/10] ARM: vGIC: move priority from irq_rank to struct pending_irq Andre Przywara
2017-05-04 16:39 ` Julien Grall
2017-05-04 16:47 ` Julien Grall
2017-05-04 15:31 ` [RFC PATCH 06/10] ARM: vGIC: move config " Andre Przywara
2017-05-04 16:55 ` Julien Grall
2017-05-04 15:31 ` [RFC PATCH 07/10] ARM: vGIC: move enable status " Andre Przywara
2017-05-04 15:31 ` [RFC PATCH 08/10] ARM: vGIC: move target vcpu " Andre Przywara
2017-05-04 17:20 ` Julien Grall
2017-05-04 15:31 ` [RFC PATCH 09/10] ARM: vGIC: introduce vgic_get/put_pending_irq Andre Przywara
2017-05-04 17:36 ` Julien Grall
2017-05-04 22:42 ` Stefano Stabellini
2017-05-04 15:31 ` [RFC PATCH 10/10] ARM: vGIC: remove struct irq_rank and support functions Andre Przywara
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=1c11740c-d9f5-8ab7-2b43-6c76be81a6fb@arm.com \
--to=julien.grall@arm.com \
--cc=andre.przywara@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).