tools/testing/selftests/powerpc/tm/tm-poison.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/tm/tm-poison.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/powerpc/tm/tm-poison.c
Extension
.c
Size
5528 bytes
Lines
183
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

while (1) {
			sched_yield();
			asm (
				"mtvsrd 31, %[poison];" // f31 = poison
				"mtvsrd 63, %[poison];" // vr31 = poison

				: : [poison] "r" (poison) : );
		}
	}

	/**
	 * parent
	 */
	asm (
		/*
		 * Set r3, r4, and f31 to known value 1 before entering
		 * in transaction. They won't be written after that.
		 */
		"       li      3, 0x1          ;"
		"       li      4, 0x1          ;"
		"       mtvsrd  31, 4           ;"

		/*
		 * The Time Base (TB) is a 64-bit counter register that is
		 * independent of the CPU clock and which is incremented
		 * at a frequency of 512000000 Hz, so every 1.953125ns.
		 * So it's necessary 120s/0.000000001953125s = 61440000000
		 * increments to get a 2 minutes timeout. Below we set that
		 * value in r5 and then use r6 to track initial TB value,
		 * updating TB values in r7 at every iteration and comparing it
		 * to r6. When r7 (current) - r6 (initial) > 61440000000 we bail
		 * out since for sure we spent already 2 minutes in the loop.
		 * SPR 268 is the TB register.
		 */
		"       lis     5, 14           ;"
		"       ori     5, 5, 19996     ;"
		"       sldi    5, 5, 16        ;" // r5 = 61440000000

		"       mfspr   6, 268          ;" // r6 (TB initial)
		"1:     mfspr   7, 268          ;" // r7 (TB current)
		"       subf    7, 6, 7         ;" // r7 - r6 > 61440000000 ?
		"       cmpd    7, 5            ;"
		"       bgt     3f              ;" // yes, exit

		/*
		 * Main loop to check f31
		 */
		"       tbegin.                 ;" // no, try again
		"       beq     1b              ;" // restart if no timeout
		"       mfvsrd  3, 31           ;" // read f31
		"       cmpd    3, 4            ;" // f31 == 1 ?
		"       bne     2f              ;" // broken :-(
		"       tabort. 3               ;" // try another transaction
		"2:     tend.                   ;" // commit transaction
		"3:     mr    %[unknown], 3     ;" // record r3

		: [unknown] "=r" (unknown)
		:
		: "cr0", "r3", "r4", "r5", "r6", "r7", "vs31"

		);

	/*
	 * On leak 'unknown' will contain 'poison' value from child,
	 * otherwise (no leak) 'unknown' will contain the same value
	 * as r3 before entering in transactional mode, i.e. 0x1.
	 */
	fail_fp = unknown != 0x1;
	if (fail_fp)
		printf("Unknown value %#"PRIx64" leaked into f31!\n", unknown);
	else
		printf("Good, no poison or leaked value into FP registers\n");

	asm (
		/*
		 * Set r3, r4, and vr31 to known value 1 before entering
		 * in transaction. They won't be written after that.
		 */
		"       li      3, 0x1          ;"
		"       li      4, 0x1          ;"
		"       mtvsrd  63, 4           ;"

		"       lis     5, 14           ;"
		"       ori     5, 5, 19996     ;"
		"       sldi    5, 5, 16        ;" // r5 = 61440000000

		"       mfspr   6, 268          ;" // r6 (TB initial)
		"1:     mfspr   7, 268          ;" // r7 (TB current)
		"       subf    7, 6, 7         ;" // r7 - r6 > 61440000000 ?
		"       cmpd    7, 5            ;"

Annotation

Implementation Notes