[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 08/42] xen/riscv: distinguish h/w and virtual vINTC sources



> A vIRQ of a domain's vINTC is either a h/w source, one a physical IRQ is
> routed to by route_irq_to_guest(), or a virtual source, whose line is
> driven by the emulator of a device in Xen and whose state exists in the
> vINTC only. used_irqs only tells that a vIRQ is taken, not which of the
> two it is, whereas they have to be told apart: only a h/w source has a
> physical IRQ to release when the domain goes away, and h/w registers to
> keep in line with the guest's view.
> 
> Track the h/w sources in a new hw_irqs bitmap, the subset of used_irqs
> a h/w IRQ is routed to. intc_route_irq_to_guest() sets the vIRQ's bit
> there, so it now takes the domain and the vIRQ, and
> domain_vintc_deinit() releases the h/w sources only.
> 
> An IRQ shared between devices is routed to the domain once per device,
> so vintc_reserve_virq() legitimately fails with -EEXIST for all but the
> first of them. map_irq_to_domain() now accepts -EEXIST only for a vIRQ
> which is a h/w source already, so that a vIRQ reserved for a virtual
> source can't be taken over by a h/w IRQ.
>

The commit message says what the patch adds, but not why used_irqs alone
isn't enough, so I had to dig into the diff and the notes below the ---
to understand why hw_irqs is needed.

It turns out that the two problems it fixes are latent: map_irq_to_domain()
routing a h/w IRQ to a vIRQ reserved for a virtual source, and
domain_vintc_deinit() calling release_guest_irq() on a virtual source.
Neither can happen in this series, as no virtual source is ever reserved:
map_irq_to_domain() is the only caller of vintc_reserve_virq(), up to the
end of the series, and vintc_set_irq_level() has no caller at all.

So the message should state both problems, and that they only show up
once a device emulator in Xen reserves a vIRQ. Alternatively, the
map_irq_to_domain() hunk could come together with the first such
emulator.

Suggested wording:

xen/riscv: distinguish h/w and virtual vINTC sources

A vIRQ of a domain's vINTC is either a h/w source, to which a physical
IRQ is routed by route_irq_to_guest(), or a virtual source, whose line
is driven by a device emulator in Xen and whose state lives in the vINTC
only. used_irqs only tells that a vIRQ is taken, not which of the two it
is, whereas they have to be told apart:

    - map_irq_to_domain() accepts -EEXIST from vintc_reserve_virq() and
      goes on calling route_irq_to_guest(). That is expected for an IRQ
      shared between h/w sources, but would be wrong for a vIRQ reserved for
      a virtual source, as the h/w IRQ would then get routed to it.

    - domain_vintc_deinit() calls release_guest_irq() for every vIRQ in
      used_irqs, which would include virtual sources, while they have no
      physical IRQ routed to them.

No virtual source is reserved yet, so it can't happen currently.
They will once a device emulator in Xen reserves a vIRQ.

Track the h/w sources in a new hw_irqs bitmap, the subset of used_irqs a
physical IRQ is routed to. intc_route_irq_to_guest() sets the bit, which
requires passing it the domain and the vIRQ, as hw_irqs is per-domain
and indexed by vIRQ. On -EEXIST, map_irq_to_domain() now goes on only if
the vIRQ is already a h/w source and fails if it is a virtual one, and
domain_vintc_deinit() releases h/w sources only.

Suggested wording:

xen/riscv: distinguish h/w and virtual vINTC sources

A vIRQ of a domain's vINTC is either a h/w source, to which a physical
IRQ is routed by route_irq_to_guest(), or a virtual source, whose line
is driven by a device emulator in Xen and whose state lives in the vINTC
only. used_irqs only tells that a vIRQ is taken, not which of the two it
is, whereas they have to be told apart:

    - map_irq_to_domain() accepts -EEXIST from vintc_reserve_virq() and
      goes on calling route_irq_to_guest(). That is expected for an IRQ
      shared between h/w sources, but would be wrong for a vIRQ reserved for
      a virtual source, as the h/w IRQ would then get routed to it.

    - domain_vintc_deinit() calls release_guest_irq() for every vIRQ in
      used_irqs, which would include virtual sources, while they have no
      physical IRQ routed to them.

No virtual source is reserved yet, so it can't happen currently.
They will once a device emulator in Xen reserves a vIRQ.

Track the h/w sources in a new hw_irqs bitmap, the subset of used_irqs a
physical IRQ is routed to. intc_route_irq_to_guest() sets the bit, which
requires passing it the domain and the vIRQ, as hw_irqs is per-domain
and indexed by vIRQ. On -EEXIST, map_irq_to_domain() now goes on only if
the vIRQ is already a h/w source and fails if it is a virtual one, and
domain_vintc_deinit() releases h/w sources only.

> [ ... 29 lines skipped ... ]
> @@ -25,14 +25,21 @@ int __overlay_init map_irq_to_domain(struct domain *d, 
> unsigned int irq,
>      {
>          /*
>           * -EEXIST merely means that the IRQ has already been reserved, which
> -         * legitimately happens when the IRQ is shared between devices. Any
> -         * other failure has to be fatal: the IRQ would otherwise be routed 
> to
> -         * the domain without domain_vintc_deinit() ever releasing it again.
> +         * legitimately happens when the IRQ is shared between devices: the
> +         * vIRQ is then a h/w source already, route_irq_to_guest() having
> +         * connected it to the IRQ for the first of them. A vIRQ reserved for
> +         * a virtual source, whose line an emulator in Xen drives, mustn't be
> +         * taken over by a h/w IRQ, though. Any other failure has to be fatal
> +         * too: the IRQ would otherwise be routed to the domain without
> +         * domain_vintc_deinit() ever releasing it again.
>           */
The wording implicitly says "-EEXIST means the vIRQ is a h/w source",
while what you mean (and what the check below does) is "-EEXIST on a vIRQ
which is a h/w source already means the IRQ was mapped for an earlier
device".

Suggested rewording:

/*
 * An IRQ shared between devices is mapped once per device: for the first
 * of them, vintc_reserve_virq() reserved the vIRQ and route_irq_to_guest()
 * connected it to the IRQ, so for the next ones -EEXIST on a h/w source is
 * expected and harmless. A vIRQ reserved for a virtual source, whose line
 * an emulator in Xen drives, mustn't be taken over by a h/w IRQ, though.
 * Any other failure has to be fatal too: the IRQ would otherwise be routed
 * to the domain without domain_vintc_deinit() ever releasing it again.
 */

-- 
Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.