Page MenuHomeFreeBSD

[PowerPC] Fix outdated FP regs on fork(2) and friends
ClosedPublic

Authored by bdragon on Apr 20 2021, 4:01 AM.
Referenced Files
Unknown Object (File)
Mon, Dec 2, 5:14 AM
Unknown Object (File)
Nov 21 2024, 6:42 AM
Unknown Object (File)
Nov 16 2024, 8:44 AM
Unknown Object (File)
Nov 16 2024, 6:05 AM
Unknown Object (File)
Nov 6 2024, 3:54 PM
Unknown Object (File)
Oct 22 2024, 5:55 PM
Unknown Object (File)
Sep 21 2024, 3:45 PM
Unknown Object (File)
Sep 9 2024, 6:14 AM

Details

Summary

Failure to update the FP / vector state was causing daemon(3) to violate C ABI by failing to preserve nonvolatile registers.

This was causing a weird issue where moused was not working on PowerBook G4s when daemonizing, but was working fine when running it foreground.

Force saving off the same state that cpu_switch() does in cases where we are about to copy a thread.

MFC after: 1 week
Sponsored by: Tag1 Consulting, Inc.

Test Plan
/*
 * Test for ABI violation due to side effects of daemon(3).
 *
 * NOTE: Compile with -O2 to see the effect.
 */
#include <stdio.h>
#include <stdlib.h>
/* Allow compiling for Linux too. */
#include <unistd.h>

static double test = 1234.56f;

/*
 * This contrivance coerces clang to not bounce the double
 * off of memory again in main.
 */
void __attribute__((noinline))
print_double(int j1, int j2, double d)
{
	printf("%f\n", d);
}

int
main(int argc, char *argv[])
{
	print_double(0, 0, test);

	if (daemon(0, 1)) {
	}
	/* Compiler assumes nonvolatile regs are intact... */
	print_double(0, 0, test);
	return(0);
}

Working output:

1234.560059
1234.560059

Output in broken case:

1234.560059
0.0

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bdragon retitled this revision from [PowerPC] Fix outdated FP regs on fork() and friends to [PowerPC] Fix outdated FP regs on fork(2) and friends.Apr 20 2021, 4:06 AM
bdragon edited the summary of this revision. (Show Details)
sys/powerpc/powerpc/vm_machdep.c
125

I need to skip this when td1 != curthread, just got a boot panic on a dual processor G4. I had missed the part where we could also be here because we're cloning off of thread0.

This revision was not accepted when it landed; it landed in state Needs Review.Sep 4 2021, 4:35 PM
This revision was automatically updated to reflect the committed changes.