Re: [RFC PATCH v3 14/17] s390/unwind_user/sframe: Enable HAVE_UNWIND_USER_SFRAME

Heiko Carstens
2025-12-10T15:11:29Z

Hi Jens,

On Mon, Dec 08, 2025 at 06:15:56PM +0100, Jens Remus wrote:
> +static inline int __s390_get_dwarf_fpr(unsigned long *val, int regnum)
> +{
> + switch (regnum) {
> + case 16:
> + fpu_std(0, (freg_t *)val);
> + break;
> + case 17:
> + fpu_std(2, (freg_t *)val);
> + break;
> + case 18:
> + fpu_std(4, (freg_t *)val);
> + break;
> + case 19:
> + fpu_std(6, (freg_t *)val);
> + break;
> + case 20:
> + fpu_std(1, (freg_t *)val);
> + break;

IIRC, I mentioned this already last time. But it is not correct to access user
space floating point register contents like this. Due to in-kernel fpu/vector
register usage the user space register contents may have been saved away to
the per-thread vxrs save area, and registers may have been used for in-kernel
usage instead.
Read: the above code could access lazy register contents of in-kernel usage.

Change the above to something like:

struct fpu *fpu = &current->thread.ufpu;

save_user_fpu_regs();
switch (regnum) {
case 16: return fpu->vxrs[0].high;
case 17: return fpu->vxrs[2].high;
case 18: return fpu->vxrs[4].high;
case 19: return fpu->vxrs[6].high;
case 20: return fpu->vxrs[1].high;
...

save_user_fpu_regs() will write all user space fpu/vector register contents to
the per-thread save area (if not already saved), and then it is possible to
read contents from there.

I'll see if I can provide something better for this use case, since this code
needs to access only the first 16 registers; so no need to write contents of
all registers to the save area.