[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJHc60wQuCM_H_ksSWUdCjJj30Stzn1aEr4=jvzqM0ZvhuN5gQ@mail.gmail.com>
Date: Tue, 17 Oct 2023 10:10:55 -0700
From: Raghavendra Rao Ananta <rananta@...gle.com>
To: Sebastian Ott <sebott@...hat.com>
Cc: Oliver Upton <oliver.upton@...ux.dev>,
Marc Zyngier <maz@...nel.org>,
Alexandru Elisei <alexandru.elisei@....com>,
James Morse <james.morse@....com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Paolo Bonzini <pbonzini@...hat.com>,
Zenghui Yu <yuzenghui@...wei.com>,
Shaoqin Huang <shahuang@...hat.com>,
Jing Zhang <jingzhangos@...gle.com>,
Reiji Watanabe <reijiw@...gle.com>,
Colton Lewis <coltonlewis@...gle.com>,
linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.linux.dev,
linux-kernel@...r.kernel.org, kvm@...r.kernel.org
Subject: Re: [PATCH v7 10/12] KVM: selftests: aarch64: Introduce
vpmu_counter_access test
On Tue, Oct 17, 2023 at 8:48 AM Sebastian Ott <sebott@...hat.com> wrote:
>
> On Mon, 9 Oct 2023, Raghavendra Rao Ananta wrote:
> > +static void guest_code(uint64_t expected_pmcr_n)
> > +{
> > + uint64_t pmcr, pmcr_n;
> > +
> > + __GUEST_ASSERT(expected_pmcr_n <= ARMV8_PMU_MAX_GENERAL_COUNTERS,
> > + "Expected PMCR.N: 0x%lx; ARMv8 general counters: 0x%lx",
> > + expected_pmcr_n, ARMV8_PMU_MAX_GENERAL_COUNTERS);
> > +
> > + pmcr = read_sysreg(pmcr_el0);
> > + pmcr_n = get_pmcr_n(pmcr);
> > +
> > + /* Make sure that PMCR_EL0.N indicates the value userspace set */
> > + __GUEST_ASSERT(pmcr_n == expected_pmcr_n,
> > + "Expected PMCR.N: 0x%lx, PMCR.N: 0x%lx",
> > + pmcr_n, expected_pmcr_n);
>
> Expected vs read value is swapped.
>
Good catch! I'll fix this in v8.
>
> Also, since the kernel has special handling for this, should we add a
> test like below?
>
> +static void immutable_test(void)
> +{
> + struct kvm_vcpu *vcpu;
> + uint64_t sp, pmcr, pmcr_n;
> + struct kvm_vcpu_init init;
> +
> + create_vpmu_vm(guest_code);
> +
> + vcpu = vpmu_vm.vcpu;
> +
> + /* Save the initial sp to restore them later to run the guest again */
> + vcpu_get_reg(vcpu, ARM64_CORE_REG(sp_el1), &sp);
> +
> + vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0), &pmcr);
> + pmcr_n = get_pmcr_n(pmcr);
> +
> + run_vcpu(vcpu, pmcr_n);
> +
> + vm_ioctl(vpmu_vm.vm, KVM_ARM_PREFERRED_TARGET, &init);
> + init.features[0] |= (1 << KVM_ARM_VCPU_PMU_V3);
> + aarch64_vcpu_setup(vcpu, &init);
> + vcpu_init_descriptor_tables(vcpu);
> + vcpu_set_reg(vcpu, ARM64_CORE_REG(sp_el1), sp);
> + vcpu_set_reg(vcpu, ARM64_CORE_REG(regs.pc), (uint64_t)guest_code);
> +
> + /* Update the PMCR_EL0.N after the VM ran once */
> + set_pmcr_n(&pmcr, 0);
> + vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0), pmcr);
> +
> + /* Verify that the guest still gets the unmodified value */
> + run_vcpu(vcpu, pmcr_n);
> +
> + destroy_vpmu_vm();
> +}
Thanks for the suggestion! I'll add this test case in v8.
- Raghavendra
>
Powered by blists - more mailing lists