Re: [PATCH RFC v1 02/11] x86/fpu/xstate: Introduce xstate order table and accessor macro

From: Dave Hansen
Date: Thu Feb 27 2025 - 14:03:14 EST


On 2/27/25 10:44, Chang S. Bae wrote:
> The kernel has largely assumed that higher xstate component numbers
> correspond to later offsets in the buffer. However, this assumption does
> not hold for the non-compacted format, where a newer state component may
> have a lower offset.

Maybe "no longer holds" instead of "does not hold".

This never happened before APX, right?

...
> +/*
> + * Ordering of xstate components in non-compacted format: The xfeature
> + * number does not necessarily indicate its position in the XSAVE buffer.
> + * This array defines the traversal order of xstate features, included in
> + * XFEATURE_MASK_USER_SUPPORTED.
> + */
> +static const enum xfeature xfeature_noncompact_order[] = {

Nit: I think we call this "uncompacted" in most places.

> + XFEATURE_FP,
> + XFEATURE_SSE,
> + XFEATURE_YMM,
> + XFEATURE_BNDREGS,
> + XFEATURE_BNDCSR,
> + XFEATURE_OPMASK,
> + XFEATURE_ZMM_Hi256,
> + XFEATURE_Hi16_ZMM,
> + XFEATURE_PKRU,
> + XFEATURE_XTILE_CFG,
> + XFEATURE_XTILE_DATA,
> +};

There are two possible ways to do this:

One, hard-code it like you have here. If we do this, we probably also
need some verification debug code that it got done right.

Two, dynamically generate it. I suspect that once you have the
uncompacted offset read out of CPUID, you could generate this in fewer
lines of code than it takes to define it manually. I think it would also
not require adding new features manually.