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)
Thu, Apr 11, 4:56 AM
Unknown Object (File)
Fri, Apr 5, 6:23 AM
Unknown Object (File)
Sat, Mar 30, 12:24 AM
Unknown Object (File)
Feb 19 2024, 11:00 PM
Unknown Object (File)
Jan 16 2024, 3:34 AM
Unknown Object (File)
Dec 20 2023, 3:30 AM
Unknown Object (File)
Dec 15 2023, 4:26 PM
Unknown Object (File)
Dec 12 2023, 12:27 PM

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.