From: Peter Zijlstra <peterz@infradead.org>
To: Raphael Gault <raphael.gault@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, mingo@redhat.com,
catalin.marinas@arm.com, will.deacon@arm.com, acme@kernel.org,
mark.rutland@arm.com
Subject: Re: [RFC 5/7] arm64: pmu: Add hook to handle pmu-related undefined instructions
Date: Wed, 29 May 2019 11:45:56 +0200 [thread overview]
Message-ID: <20190529094556.GJ2623@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20190528150320.25953-6-raphael.gault@arm.com>
On Tue, May 28, 2019 at 04:03:18PM +0100, Raphael Gault wrote:
> +static int emulate_pmu(struct pt_regs *regs, u32 insn)
> +{
> + u32 sys_reg, rt;
> + u32 pmuserenr;
> +
> + sys_reg = (u32)aarch64_insn_decode_immediate(AARCH64_INSN_IMM_16, insn) << 5;
> + rt = aarch64_insn_decode_register(AARCH64_INSN_REGTYPE_RT, insn);
> + pmuserenr = read_sysreg(pmuserenr_el0);
> +
> + if ((pmuserenr & (ARMV8_PMU_USERENR_ER|ARMV8_PMU_USERENR_CR)) !=
> + (ARMV8_PMU_USERENR_ER|ARMV8_PMU_USERENR_CR))
> + return -EINVAL;
> +
I would really prefer there to be a comment here that explain how the
'0' value works. Maybe something like:
/*
* Userspace is expected to only use this in the context of the
* scheme described in the struct perf_event_mmap_page comments.
*
* Given that context, we can only get here if we got migrated
* between getting the register index and doing the MSR read.
* This in turn implies we'll fail the sequence and retry, so
* any value returned is 'good', all we need is to be non-fatal.
*/
> + pt_regs_write_reg(regs, rt, 0);
And given the above, we don't even need to do this, we can simply
preserve whatever garbage was in the register and return to userspace.
The only thing we really need is for the trap to be non-fatal.
> +
> + arm64_skip_faulting_instruction(regs, 4);
> + return 0;
> +}
> +
> +/*
> + * This hook will only be triggered by mrs
> + * instructions on PMU registers. This is mandatory
> + * in order to have a consistent behaviour even on
> + * big.LITTLE systems.
> + */
> +static struct undef_hook pmu_hook = {
> + .instr_mask = 0xffff8800,
> + .instr_val = 0xd53b8800,
> + .fn = emulate_pmu,
> +};
> +
> +static int __init enable_pmu_emulation(void)
> +{
> + register_undef_hook(&pmu_hook);
> + return 0;
> +}
> +
> +core_initcall(enable_pmu_emulation);
next prev parent reply other threads:[~2019-05-29 9:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-28 15:03 [RFC V2 0/7] arm64: Enable access to pmu registers by user-space Raphael Gault
2019-05-28 15:03 ` [RFC 1/7] perf: arm64: Compile tests unconditionally Raphael Gault
2019-05-28 15:19 ` Arnaldo Carvalho de Melo
2019-05-28 16:16 ` Mark Rutland
2019-05-28 15:03 ` [RFC 2/7] perf: arm64: Add test to check userspace access to hardware counters Raphael Gault
2019-05-28 15:03 ` [RFC 3/7] perf: arm64: Use rseq to test userspace access to pmu counters Raphael Gault
2019-05-28 15:03 ` [RFC 4/7] arm64: pmu: Add function implementation to update event index in userpage Raphael Gault
2019-05-29 9:46 ` Peter Zijlstra
2019-05-29 10:46 ` Raphael Gault
2019-05-29 10:50 ` Robin Murphy
2019-05-29 12:25 ` Raphael Gault
2019-05-29 12:32 ` Peter Zijlstra
2019-05-29 12:39 ` Raphael Gault
2019-05-28 15:03 ` [RFC 5/7] arm64: pmu: Add hook to handle pmu-related undefined instructions Raphael Gault
2019-05-29 9:45 ` Peter Zijlstra [this message]
2019-05-28 15:03 ` [RFC 6/7] arm64: perf: Enable pmu counter direct access for perf event on armv8 Raphael Gault
2019-05-28 15:03 ` [RFC 7/7] Documentation: arm64: Document PMU counters access from userspace Raphael Gault
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=20190529094556.GJ2623@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=raphael.gault@arm.com \
--cc=will.deacon@arm.com \
/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