selftests/powerpc: Check all FPRs in fpu_syscall test
authorMichael Ellerman <mpe@ellerman.id.au>
Tue, 28 Nov 2023 13:27:48 +0000 (00:27 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 13 Dec 2023 02:29:09 +0000 (13:29 +1100)
There is a selftest that checks if FPRs are corrupted across a fork, aka
clone. It was added as part of the series that optimised the clone path
to save the parent's FP state without "giving up" (turning off FP).

See commit 8792468da5e1 ("powerpc: Add the ability to save FPU without
giving it up").

The test encodes the assumption that FPRs 0-13 are volatile across the
syscall, by only checking the volatile FPRs are not changed by the fork.
There was also a comment in the fpu_preempt test alluding to that:

  The check_fpu function in asm only checks the non volatile registers
  as it is reused from the syscall test

It is true that the function call ABI treats f0-f13 as volatile,
however the syscall ABI has since been documented as *not* treating those
registers as volatile. See commit 7b8845a2a2ec ("powerpc/64: Document
the syscall ABI").

So change the test to check all FPRs are not corrupted by the syscall.
Note that this currently fails, because save_fpu() etc. do not restore
f0/vsr0.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231128132748.1990179-5-mpe@ellerman.id.au
tools/testing/selftests/powerpc/math/fpu_asm.S
tools/testing/selftests/powerpc/math/fpu_syscall.c

index 051392ad3ce7a15411aa4b226dffbb6eede9bc98..efe1e1be46950b9dd9a982231d3a797534e980a7 100644 (file)
@@ -109,8 +109,9 @@ FUNC_START(test_fpu)
        std     r3,STACK_FRAME_PARAM(0)(sp) # Address of darray
        std r4,STACK_FRAME_PARAM(1)(sp) # Address of pid
 
-       bl load_fpu
-       nop
+       // Load FPRs with expected values
+       OP_REGS lfd, 8, 0, 31, r3
+
        li      r0,__NR_fork
        sc
 
@@ -119,7 +120,7 @@ FUNC_START(test_fpu)
        std     r3,0(r9)
 
        ld r3,STACK_FRAME_PARAM(0)(sp)
-       bl check_fpu
+       bl check_all_fprs
        nop
 
        POP_FPU(256)
index 694f225c7e45ed6034487a2b20c2a4fb8d8427e4..751d46b133fcb9aff883c5b985adf63086cba7ac 100644 (file)
 #include <stdlib.h>
 
 #include "utils.h"
+#include "fpu.h"
 
 extern int test_fpu(double *darray, pid_t *pid);
 
-double darray[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,
-                    1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0,
-                    2.1};
+double darray[32];
 
 int syscall_fpu(void)
 {
@@ -27,6 +26,9 @@ int syscall_fpu(void)
        int i;
        int ret;
        int child_ret;
+
+       randomise_darray(darray, ARRAY_SIZE(darray));
+
        for (i = 0; i < 1000; i++) {
                /* test_fpu will fork() */
                ret = test_fpu(darray, &fork_pid);