From: Marc Zyngier <maz@kernel.org>
To: Alexandru Elisei <alexandru.elisei@arm.com>
Cc: kernel-team@android.com, kvmarm@lists.cs.columbia.edu,
linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org
Subject: Re: [PATCH 0/8] KVM: arm64: Disabled PMU handling
Date: Wed, 25 Nov 2020 08:39:24 +0000 [thread overview]
Message-ID: <877dq96dab.wl-maz@kernel.org> (raw)
In-Reply-To: <750f5543-054a-f1aa-229f-2d41b8e233dd@arm.com>
On Tue, 24 Nov 2020 17:28:30 +0000,
Alexandru Elisei <alexandru.elisei@arm.com> wrote:
>
> Hi Marc,
>
> I believe there is something missing from this series.
>
> The original behaviour, which this series changes, was not to do
> register emulation and PMU state update if the PMU wasn't ready,
> where vcpu->arch.pmu.ready was set to true if the PMU was
> initialized properly in kvm_vcpu_first_run_init() ->
> kvm_arm_pmu_v3_enable().
>
> The series changes PMU emulation such that register emulation and
> pmu state update is gated only on the VCPU feature being set. This
> means that now userspace can set the VCPU feature, don't do any
> initialization, and run a guest which can access PMU registers. Also
> kvm_pmu_update_state() will now be called before each VM entry. I'm
> not exactly sure what happens if we call kvm_vgic_inject_irq() for
> an irq_num = 0 and not owned by the PMU (the owner is set
> KVM_ARM_VCPU_PMU_V3_INIT -> kvm_arm_pmu_v3_init()), but I don't
> think that's allowed.
That's a very good point. I dropped the "ready" state a bit
carelessly, and nothing guards a half baked PMU anymore.
>
> I was also able to trigger this warning with a modified version of kvmtool:
[ugly warning]
> I removed all KVM_ARM_VCPU_PMU_V3_CTRL ioctl calls from kvmtool's
> pmu emulation, and I started the pmu test from kvm-unit-tests:
>
> $ ./lkvm-pmu run -c1 -m64 -f arm/pmu.flat --pmu -p cycle-counter
>
> The reason for the warning is that the correct value for
> kvm->arch.pmuver is set in kvm_arm_pmu_v3_set_attr(), which is not
> called anymore.
>
> This diff seems to solve the issue:
>
> diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
> index 643cf819f3c0..150b9cb0f741 100644
> --- a/arch/arm64/kvm/pmu-emul.c
> +++ b/arch/arm64/kvm/pmu-emul.c
> @@ -825,9 +825,12 @@ bool kvm_arm_support_pmu_v3(void)
>
> int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
> {
> - if (!vcpu->arch.pmu.created)
> + if (!kvm_vcpu_has_pmu(vcpu))
> return 0;
>
> + if (!vcpu->arch.pmu.created)
> + return -ENOEXEC;
> +
> /*
> * A valid interrupt configuration for the PMU is either to have a
> * properly configured interrupt number and using an in-kernel
>
> If you agree with the fix, I can send a proper patch.
> vcpu->arch.pmu.created is set in kvm_arm_pmu_v3_init(), which checks
> if the interrupt ID has been set. I chose to return -ENOEXEC
> because that's what KVM_RUN returns if the vcpu isn't initialized in
> kvm_arch_vcpu_ioctl_run().
Yes, this seems reasonable. The first run will fail, as for an
uninitialised vcpu.
Whist you're doing that, can you please document the ENOEXEC return
value? We only document EINTR so far.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-11-25 8:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-13 18:25 [PATCH 0/8] KVM: arm64: Disabled PMU handling Marc Zyngier
2020-11-13 18:25 ` [PATCH 1/8] KVM: arm64: Add kvm_vcpu_has_pmu() helper Marc Zyngier
2020-11-13 18:25 ` [PATCH 2/8] KVM: arm64: Set ID_AA64DFR0_EL1.PMUVer to 0 when no PMU support Marc Zyngier
2020-11-13 18:25 ` [PATCH 3/8] KVM: arm64: Refuse illegal KVM_ARM_VCPU_PMU_V3 at reset time Marc Zyngier
2020-11-26 14:59 ` Alexandru Elisei
2020-11-26 15:25 ` Marc Zyngier
2020-11-26 15:49 ` Alexandru Elisei
2020-11-13 18:25 ` [PATCH 4/8] KVM: arm64: Inject UNDEF on PMU access when no PMU configured Marc Zyngier
2020-11-13 18:25 ` [PATCH 5/8] KVM: arm64: Remove PMU RAZ/WI handling Marc Zyngier
2020-11-26 15:06 ` Alexandru Elisei
2020-11-27 8:50 ` Marc Zyngier
2020-11-13 18:26 ` [PATCH 6/8] KVM: arm64: Remove dead PMU sysreg decoding code Marc Zyngier
2020-11-26 15:18 ` Alexandru Elisei
2020-11-26 15:34 ` Marc Zyngier
2020-11-26 15:54 ` Alexandru Elisei
2020-11-26 15:57 ` Marc Zyngier
2020-11-13 18:26 ` [PATCH 7/8] KVM: arm64: Gate kvm_pmu_update_state() on the PMU feature Marc Zyngier
2020-11-13 18:26 ` [PATCH 8/8] KVM: arm64: Get rid of the PMU ready state Marc Zyngier
2020-11-24 17:28 ` [PATCH 0/8] KVM: arm64: Disabled PMU handling Alexandru Elisei
2020-11-25 8:39 ` Marc Zyngier [this message]
2020-11-26 16:34 ` Alexandru Elisei
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=877dq96dab.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=alexandru.elisei@arm.com \
--cc=kernel-team@android.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.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).