Re: [PATCH 2/3] KVM: arm64: Replace vgic_v3_uaccess_read_pending with vgic_uaccess_read_pending

Marc Zyngier
2022-06-07T11:11:30Z

On Thu, 02 Jun 2022 21:06:42 +0100,
Eric Auger <eauger@redhat.com> wrote:
>
> Hi Marc,
> On 6/2/22 10:30, Marc Zyngier wrote:
> > Now that GICv2 has a proper userspace accessor for the pending state,
> > switch GICv3 over to it, dropping the local version.
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> > arch/arm64/kvm/vgic/vgic-mmio-v3.c | 40 ++----------------------------
> > 1 file changed, 2 insertions(+), 38 deletions(-)
> >
> > diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
> > index f7aa7bcd6fb8..f15e29cc63ce 100644
> > --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c
> > +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
> > @@ -353,42 +353,6 @@ static unsigned long vgic_mmio_read_v3_idregs(struct kvm_vcpu *vcpu,
> > return 0;
> > }
> >
> > -static unsigned long vgic_v3_uaccess_read_pending(struct kvm_vcpu *vcpu,
> > - gpa_t addr, unsigned int len)
> > -{
> > - u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
> > - u32 value = 0;
> > - int i;
>
> > -
> > - /*
> > - * pending state of interrupt is latched in pending_latch variable.
> > - * Userspace will save and restore pending state and line_level
> > - * separately.
> > - * Refer to Documentation/virt/kvm/devices/arm-vgic-v3.rst
> > - * for handling of ISPENDR and ICPENDR.
> Don't know if you want a derivative of this comment in
> vgic_uaccess_read_pending()?

I don't find it specially helpful, but at the same time, it doesn't
hurt to move it around.

> > - */
> > - for (i = 0; i < len * 8; i++) {
> > - struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
> > - bool state = irq->pending_latch;
> > -
> > - if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
> > - int err;
> > -
> in __read_pending(), irq->irq_lock is hold which looks safer at 1st
> sight. If potentially fixing something this can be documented in the
> commit msg.

I don't think it fixes anything. The idea is that if you are
accessing the state from userspace, you already have stopped the VM,
and thus there is no concurrent modifications if the state.

> > - err = irq_get_irqchip_state(irq->host_irq,
> > - IRQCHIP_STATE_PENDING,
> > - &state);
> > - WARN_ON(err);
> > - }
> > -
> in __read_pending(), irq_is_pending(irq) is used instead of
> irq->pending_latch. for level sensitive IRQ this is not identical. This
> may also deserve some comment. The nuance may be related to the above
> comment.

That is a good point, and we should unify the userspace behaviours
between GICv2 and v3.

I'll respin the series shortly.

Thanks,

M.

--
Without deviation from the norm, progress is not possible.