Re: [RFC PATCH 08/12] perf/x86: Add APX in extended regs
From: Dave Hansen
Date: Fri Jun 13 2025 - 12:07:40 EST
On 6/13/25 06:49, kan.liang@xxxxxxxxxxxxxxx wrote:
> +#define __x86_pmu_get_regs(_mask, _regs, _size) \
> +do { \
> + if (mask & _mask && xcomp_bv & _mask) { \
> + _regs = xsave; \
> + xsave += _size; \
> + } \
> +} while (0)
Ewww.
First of all, this doesn't work generally because of the previously
mentioned alignment. Second, it's using xcomp_bv which doesn't tell you
if XSAVES wrote the data.
Last, this attempts to reimplement get_xsave_addr().
I'd do something like this:
for (xfeature_nr in mask) {
void *src = get_xsave_addr(xsave, xfeature_nr);
void *dst = ... a function to map XFEATURE_MASK_APX
to perf_regs->apx_regs,
int size = xstate_sizes(xfeature_nr);
if (!src)
continue;
memcpy(dst, src, size);
}
That should handle *all* of the nastiness. The alignment, the init
optimization. *Please* use get_xsave_addr() or one of the other helpers.