Commit 1bdf2258 authored by Michael Ellerman's avatar Michael Ellerman
Browse files

selftests/powerpc: Check all FPRs in fpu_syscall test



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 8792468d ("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 7b8845a2 ("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: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231128132748.1990179-5-mpe@ellerman.id.au
parent 60d2c3af
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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)
+5 −3
Original line number Diff line number Diff line
@@ -14,12 +14,11 @@
#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);