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

Jens Remus
2025-12-12T08:15:28Z

Hello Heiko,

thank you for the feedback!

On 12/10/2025 4:10 PM, Heiko Carstens wrote:
> 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.

Thanks! I have changed the code accordingly. Works fine.

> 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.

Ok.

Regards,
Jens
--
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
jremus@de.ibm.com

IBM

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/