-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
powerpc: Correct DSCR during TM context switch
Correct the DSCR SPR becoming temporarily corrupted if a task is context switched during a transaction. The problem occurs while suspending the task and is caused by saving the DSCR to thread.dscr after it has already been set to the CPU's default value: __switch_to() calls __switch_to_tm() which calls tm_reclaim_task() which calls tm_reclaim_thread() which calls tm_reclaim() where the DSCR is set to the CPU's default __switch_to() calls _switch() where thread.dscr is set to the DSCR When the task is resumed, it's transaction will be doomed (as usual) and the DSCR SPR will be corrupted, although the checkpointed value will be correct. Therefore the DSCR will be immediately corrected by the transaction aborting, unless it has been suspended. In that case the incorrect value can be seen by the task until it resumes the transaction. The fix is to treat the DSCR similarly to the TAR and save it early in __switch_to(). A program exposing the problem is added to the kernel self tests as: tools/testing/selftests/powerpc/tm/tm-resched-dscr. Signed-off-by: Sam Bobroff <sam.bobroff@au1.ibm.com> CC: <stable@vger.kernel.org> [v3.10+] Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
- Loading branch information
Sam bobroff
authored and
Benjamin Herrenschmidt
committed
Jun 11, 2014
1 parent
fb5a515
commit 96d0161
Showing
6 changed files
with
114 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
PROGS := tm-resched-dscr | ||
|
||
all: $(PROGS) | ||
|
||
$(PROGS): | ||
|
||
run_tests: all | ||
@-for PROG in $(PROGS); do \ | ||
./$$PROG; \ | ||
done; | ||
|
||
clean: | ||
rm -f $(PROGS) *.o | ||
|
||
.PHONY: all run_tests clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* Test context switching to see if the DSCR SPR is correctly preserved | ||
* when within a transaction. | ||
* | ||
* Note: We assume that the DSCR has been left at the default value (0) | ||
* for all CPUs. | ||
* | ||
* Method: | ||
* | ||
* Set a value into the DSCR. | ||
* | ||
* Start a transaction, and suspend it (*). | ||
* | ||
* Hard loop checking to see if the transaction has become doomed. | ||
* | ||
* Now that we *may* have been preempted, record the DSCR and TEXASR SPRS. | ||
* | ||
* If the abort was because of a context switch, check the DSCR value. | ||
* Otherwise, try again. | ||
* | ||
* (*) If the transaction is not suspended we can't see the problem because | ||
* the transaction abort handler will restore the DSCR to it's checkpointed | ||
* value before we regain control. | ||
*/ | ||
|
||
#include <inttypes.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <assert.h> | ||
#include <asm/tm.h> | ||
|
||
#define TBEGIN ".long 0x7C00051D ;" | ||
#define TEND ".long 0x7C00055D ;" | ||
#define TCHECK ".long 0x7C00059C ;" | ||
#define TSUSPEND ".long 0x7C0005DD ;" | ||
#define TRESUME ".long 0x7C2005DD ;" | ||
#define SPRN_TEXASR 0x82 | ||
#define SPRN_DSCR 0x03 | ||
|
||
int main(void) { | ||
uint64_t rv, dscr1 = 1, dscr2, texasr; | ||
|
||
printf("Check DSCR TM context switch: "); | ||
fflush(stdout); | ||
for (;;) { | ||
rv = 1; | ||
asm __volatile__ ( | ||
/* set a known value into the DSCR */ | ||
"ld 3, %[dscr1];" | ||
"mtspr %[sprn_dscr], 3;" | ||
|
||
/* start and suspend a transaction */ | ||
TBEGIN | ||
"beq 1f;" | ||
TSUSPEND | ||
|
||
/* hard loop until the transaction becomes doomed */ | ||
"2: ;" | ||
TCHECK | ||
"bc 4, 0, 2b;" | ||
|
||
/* record DSCR and TEXASR */ | ||
"mfspr 3, %[sprn_dscr];" | ||
"std 3, %[dscr2];" | ||
"mfspr 3, %[sprn_texasr];" | ||
"std 3, %[texasr];" | ||
|
||
TRESUME | ||
TEND | ||
"li %[rv], 0;" | ||
"1: ;" | ||
: [rv]"=r"(rv), [dscr2]"=m"(dscr2), [texasr]"=m"(texasr) | ||
: [dscr1]"m"(dscr1) | ||
, [sprn_dscr]"i"(SPRN_DSCR), [sprn_texasr]"i"(SPRN_TEXASR) | ||
: "memory", "r3" | ||
); | ||
assert(rv); /* make sure the transaction aborted */ | ||
if ((texasr >> 56) != TM_CAUSE_RESCHED) { | ||
putchar('.'); | ||
fflush(stdout); | ||
continue; | ||
} | ||
if (dscr2 != dscr1) { | ||
printf(" FAIL\n"); | ||
exit(EXIT_FAILURE); | ||
} else { | ||
printf(" OK\n"); | ||
exit(EXIT_SUCCESS); | ||
} | ||
} | ||
} |