All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: "Lukas Jünger" <lukas.juenger@ice.rwth-aachen.de>
Cc: catalin.marinas@arm.com, will@kernel.org, kvmarm@lists.cs.columbia.edu
Subject: Re: KVM userspace GICv2 IRQ controller on platform with GICv3
Date: Mon, 04 Oct 2021 12:02:36 +0100	[thread overview]
Message-ID: <875yudrr1v.wl-maz@kernel.org> (raw)
In-Reply-To: <90101279-8099-7a77-bf73-5c8bdce2d51b@ice.rwth-aachen.de>

On Mon, 04 Oct 2021 11:30:06 +0100,
Lukas Jünger <lukas.juenger@ice.rwth-aachen.de> wrote:
> 
> [1  <text/plain (en-US); utf-8 (quoted-printable)>]
> On 04.10.21 12:24, Marc Zyngier wrote:
> > Hi Lukas,
> 
> Hi Mark,
> 
> Thanks for your quick reply.
> 
> > On Mon, 04 Oct 2021 11:07:47 +0100,
> > Lukas Jünger <lukas.juenger@ice.rwth-aachen.de> wrote:
> >> Hello,
> >> 
> >> I am trying to run an emulator that uses KVM on arm64 to execute
> >> code. The emulator contains a userspace model of a GICv2 IRQ
> >> controller. The platform that I am running on (n1sdp) has a
> > N1-SDP? My condolences...
> Is there more to this?

How do you like the PCI patches? :D

> >> GICv3. When I boot Linux in the emulator I run into
> >> gic_check_cpu_features()  in drivers/irqchip/irq-gic.c, which taints
> >> the kernel as the host uses system registers to communicate with the
> >> host GICv3. I saw that ICC_SRE_ELx can be used to force MMIO, but
> >> setting this from inside the VM did not work and using KVM_SET_ONE_REG
> >> failed with error.
> > N1-SDP doesn't implement the MMIO interface at all, and our GIC
> > emulation doesn't either. Both are valid implementations.
> > 
> >> Is there a way to use a userspace GICv2 model with KVM on a GICv3 host
> >> without tainting?
> > The tainting happens because you have created a VM with a GICv3
> > irqchip (at some point, your VMM calls into KVM to create a device
> > with the KVM_DEV_TYPE_ARM_VGIC_V3 attribute). The guest then sees that
> > GICv3 is enabled (ICC_SRE_ELx.SRE==1), and yet you somehow expose a
> > GICv2 to the guest (either via DT or ACPI). That's illegal.
> > 
> > If you want a userspace interrupt controller, you need prevent the
> > creation of an in-kernel interrupt controller, which is a change in
> > your VMM or maybe a configuration change.
> I'm not using an in-kernel irq controller, at least I don't set one
> up. This is all custom, so no QEMU etc. The GICv2 is also a custom
> model that lives in user space. The guest gets a DT telling it that
> there is a GICv2 and it should access it via MMIO. This all used to
> work on Raspberry Pi 3

RPI3 doesn't have a GIC at all, so the example is a bit moot.

> and Socionext Synquacer.

This one however is more interesting, as it has a GICv3 + v2 compat.

> The port to N1-SDP is
> giving me trouble. I understand why it is tainting the kernel, I was
> just wondering if I could somehow tell KVM to set this up correctly,
> e.g. by setting the ICC_SRE_ELx.

KVM doesn't *set* ICC_SRE_EL1.SRE. It is RAO/WI on this machine, which
is perfectly legal. However, KVM traps this access and emulates it
(access_gic_sre() returns vcpu->arch.vgic_cpu.vgic_v3.vgic_sre).

So if you see ICC_SRE_EL1.SRE==1 in your guest, that's because
vgic_sre is set to something that is non-zero. The only way for this
bit to be set is in vgic_v3_enable(), which has the following code:

<quote>
	if (vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
		vgic_v3->vgic_sre = (ICC_SRE_EL1_DIB |
				     ICC_SRE_EL1_DFB |
				     ICC_SRE_EL1_SRE);
		vcpu->arch.vgic_cpu.pendbaser = INITIAL_PENDBASER_VALUE;
	} else {
		vgic_v3->vgic_sre = 0;
	}
</quote>

So short of a terrible bug that would dump random values in this
structure, you are setting vgic_model to a GICv3 implementation. This
can only be done from userspace if you are creating a GICv3 irqchip.

Without seeing what your userspace does, I'm afraid I can't help you
much further. Can you please provide some traces of what it does? A
strace dump would certainly help.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

  reply	other threads:[~2021-10-04 11:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-04 10:07 KVM userspace GICv2 IRQ controller on platform with GICv3 Lukas Jünger
2021-10-04 10:24 ` Marc Zyngier
2021-10-04 10:30   ` Lukas Jünger
2021-10-04 11:02     ` Marc Zyngier [this message]
2021-10-04 11:27       ` Lukas Jünger
2021-10-04 13:11         ` Marc Zyngier
2021-10-04 14:15           ` Lukas Jünger
2021-10-04 15:48             ` Marc Zyngier
2021-10-05 12:06               ` Lukas Jünger

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=875yudrr1v.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=lukas.juenger@ice.rwth-aachen.de \
    --cc=will@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.