Skip to contentSkip to conversation

powerpc: Allow for a custom decr value to be specified to load on decr excp

PATCH Superseded Suraj Jitindar Singh 3 participants 4 messages May 1, 2019 – May 3, 2019 KVM

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: Allow for a custom decr value to be specified to load on decr excp

Currently the handler for a decrementer exception will simply reload the maximum value (0x7FFFFFFF), which will take ~4 seconds to expire again. This means that if a vcpu cedes, it will be ~4 seconds between wakeups.

The h_cede_tm test is testing a known breakage when a guest cedes while suspended. To be sure we cede 500 times to check for the bug. However since it takes ~4 seconds to be woken up once we've ceded, we only get through ~20 iterations before we reach the 90 seconds timeout and the test appears to fail.

Add an option when registering the decrementer handler to specify the value which should be reloaded by the handler, allowing the timeout to be chosen.

Modify the spr test to use the max timeout to preserve existing behaviour.
Modify the h_cede_tm test to use a 10ms timeout to ensure we can perform 500 iterations before hitting the 90 second time limit for a test.

This means the h_cede_tm test now succeeds rather than timing out.

---
 lib/powerpc/handlers.c | 7 ++++---
 powerpc/sprs.c         | 3 ++-
 powerpc/tm.c           | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)
lib/powerpc/handlers.c +4 -3
index be8226a..c8721e0 100644
@@ -12,11 +12,12 @@
 
 /*
  * Generic handler for decrementer exceptions (0x900)
- * Just reset the decrementer back to its maximum value (0x7FFFFFFF)
+ * Just reset the decrementer back to the value specified when registering the
+ * handler
  */
-void dec_except_handler(struct pt_regs *regs __unused, void *data __unused)
+void dec_except_handler(struct pt_regs *regs __unused, void *data)
 {
-	uint32_t dec = 0x7FFFFFFF;
+	uint64_t dec = *((uint64_t *) data);
 
 	asm volatile ("mtdec %0" : : "r" (dec));
 }
powerpc/sprs.c +2 -1
index 6744bd8..3bd6ac7 100644
@@ -253,6 +253,7 @@ int main(int argc, char **argv)
 		0x1234567890ABCDEFULL, 0xFEDCBA0987654321ULL,
 		-1ULL,
 	};
+	uint64_t decr = 0x7FFFFFFF;
 
 	for (i = 1; i < argc; i++) {
 		if (!strcmp(argv[i], "-w")) {
@@ -288,7 +289,7 @@ int main(int argc, char **argv)
 		(void) getchar();
 	} else {
 		puts("Sleeping...\n");
-		handle_exception(0x900, &dec_except_handler, NULL);
+		handle_exception(0x900, &dec_except_handler, &decr);
 		asm volatile ("mtdec %0" : : "r" (0x3FFFFFFF));
 		hcall(H_CEDE);
 	}
powerpc/tm.c +2 -1
index bd56baa..0f3f543 100644
@@ -95,11 +95,12 @@ static bool enable_tm(void)
 static void test_h_cede_tm(int argc, char **argv)
 {
 	int i;
+	uint64_t decr = 0x3FFFFF;
 
 	if (argc > 2)
 		report_abort("Unsupported argument: '%s'", argv[2]);
 
-	handle_exception(0x900, &dec_except_handler, NULL);
+	handle_exception(0x900, &dec_except_handler, &decr);
 
 	if (!start_all_cpus(halt, 0))
 		report_abort("Failed to start secondary cpus");
Signature · 1 line
2.13.6
#1 lore raw
Quoted 74 lines · Suraj Jitindar Singh

Currently the handler for a decrementer exception will simply reload the maximum value (0x7FFFFFFF), which will take ~4 seconds to expire again. This means that if a vcpu cedes, it will be ~4 seconds between wakeups.

The h_cede_tm test is testing a known breakage when a guest cedes while suspended. To be sure we cede 500 times to check for the bug. However since it takes ~4 seconds to be woken up once we've ceded, we only get through ~20 iterations before we reach the 90 seconds timeout and the test appears to fail.

Add an option when registering the decrementer handler to specify the value which should be reloaded by the handler, allowing the timeout to be chosen.

Modify the spr test to use the max timeout to preserve existing behaviour.
Modify the h_cede_tm test to use a 10ms timeout to ensure we can perform 500 iterations before hitting the 90 second time limit for a test.

This means the h_cede_tm test now succeeds rather than timing out.

---
  lib/powerpc/handlers.c | 7 ++++---
  powerpc/sprs.c         | 3 ++-
  powerpc/tm.c           | 3 ++-
  3 files changed, 8 insertions(+), 5 deletions(-)
lib/powerpc/handlers.c +4 -3
index be8226a..c8721e0 100644
@@ -12,11 +12,12 @@
 
  /*
   * Generic handler for decrementer exceptions (0x900)
- * Just reset the decrementer back to its maximum value (0x7FFFFFFF)
+ * Just reset the decrementer back to the value specified when registering the
+ * handler
   */
-void dec_except_handler(struct pt_regs *regs __unused, void *data __unused)
+void dec_except_handler(struct pt_regs *regs __unused, void *data)
  {
-	uint32_t dec = 0x7FFFFFFF;
+	uint64_t dec = *((uint64_t *) data);
 
  	asm volatile ("mtdec %0" : : "r" (dec));
  }
powerpc/sprs.c +2 -1
index 6744bd8..3bd6ac7 100644
@@ -253,6 +253,7 @@ int main(int argc, char **argv)
  		0x1234567890ABCDEFULL, 0xFEDCBA0987654321ULL,
  		-1ULL,
  	};
+	uint64_t decr = 0x7FFFFFFF;
 
  	for (i = 1; i < argc; i++) {
  		if (!strcmp(argv[i], "-w")) {
@@ -288,7 +289,7 @@ int main(int argc, char **argv)
  		(void) getchar();
  	} else {
  		puts("Sleeping...\n");
-		handle_exception(0x900, &dec_except_handler, NULL);
+		handle_exception(0x900, &dec_except_handler, &decr);
  		asm volatile ("mtdec %0" : : "r" (0x3FFFFFFF));
  		hcall(H_CEDE);
  	}
powerpc/tm.c +0 -0
index bd56baa..0f3f543 100644

powerpc/tm.c static bool enable_tm(void) · line 103

Quoted 10 lines
powerpc/tm.c +2 -1
@@ -95,11 +95,12 @@ static bool enable_tm(void)
  static void test_h_cede_tm(int argc, char **argv)
  {
  	int i;
+	uint64_t decr = 0x3FFFFF;
 
  	if (argc > 2)
  		report_abort("Unsupported argument: '%s'", argv[2]);
 
-	handle_exception(0x900, &dec_except_handler, NULL);
+	handle_exception(0x900, &dec_except_handler, &decr);

Maybe you should also need here:

     asm volatile ("mtdec %0" : : "r" (decr));

To set the first one to the same values as the following ones?

Thanks,
Laurent

#2 lore raw
Quoted 99 lines · Laurent Vivier
Quoted 98 lines · Suraj Jitindar Singh

Currently the handler for a decrementer exception will simply reload the
maximum value (0x7FFFFFFF), which will take ~4 seconds to expire again.
This means that if a vcpu cedes, it will be ~4 seconds between wakeups.

The h_cede_tm test is testing a known breakage when a guest cedes while
suspended. To be sure we cede 500 times to check for the bug. However
since it takes ~4 seconds to be woken up once we've ceded, we only get
through ~20 iterations before we reach the 90 seconds timeout and the
test appears to fail.

Add an option when registering the decrementer handler to specify the
value which should be reloaded by the handler, allowing the timeout to be
chosen.

Modify the spr test to use the max timeout to preserve existing behaviour.
Modify the h_cede_tm test to use a 10ms timeout to ensure we can perform
500 iterations before hitting the 90 second time limit for a test.

This means the h_cede_tm test now succeeds rather than timing out.

---
  lib/powerpc/handlers.c | 7 ++++---
  powerpc/sprs.c         | 3 ++-
  powerpc/tm.c           | 3 ++-
  3 files changed, 8 insertions(+), 5 deletions(-)
lib/powerpc/handlers.c +1 -1
index be8226a..c8721e0 100644
@@ -12,11 +12,12 @@
 
  /*
   * Generic handler for decrementer exceptions (0x900)
- * Just reset the decrementer back to its maximum value
 (0x7FFFFFFF)
+ * Just reset the decrementer back to the value specified when

registering the
+ * handler
*/
-void dec_except_handler(struct pt_regs *regs __unused, void *data __unused)

lib/powerpc/handlers.c +2 -1
+void dec_except_handler(struct pt_regs *regs __unused, void *data)
  {
-	uint32_t dec = 0x7FFFFFFF;
+	uint64_t dec = *((uint64_t *) data);
 
  	asm volatile ("mtdec %0" : : "r" (dec));
  }
powerpc/sprs.c +2 -1
index 6744bd8..3bd6ac7 100644
@@ -253,6 +253,7 @@ int main(int argc, char **argv)
  		0x1234567890ABCDEFULL, 0xFEDCBA0987654321ULL,
  		-1ULL,
  	};
+	uint64_t decr = 0x7FFFFFFF;
 
  	for (i = 1; i < argc; i++) {
  		if (!strcmp(argv[i], "-w")) {
@@ -288,7 +289,7 @@ int main(int argc, char **argv)
  		(void) getchar();
  	} else {
  		puts("Sleeping...\n");
-		handle_exception(0x900, &dec_except_handler,
 NULL);
+		handle_exception(0x900, &dec_except_handler,
 &decr);
  		asm volatile ("mtdec %0" : : "r" (0x3FFFFFFF));
  		hcall(H_CEDE);
  	}
powerpc/tm.c +1 -0
index bd56baa..0f3f543 100644
@@ -95,11 +95,12 @@ static bool enable_tm(void)
  static void test_h_cede_tm(int argc, char **argv)
  {
  	int i;
+	uint64_t decr = 0x3FFFFF;
 
  	if (argc > 2)
  		report_abort("Unsupported argument: '%s'",
 argv[2]);
 
Quoted 8 lines

powerpc/tm.c static bool enable_tm(void) · line 104

Quoted 2 lines
powerpc/tm.c +1 -1
-	handle_exception(0x900, &dec_except_handler, NULL);
+	handle_exception(0x900, &dec_except_handler, &decr);

Maybe you should also need here:

     asm volatile ("mtdec %0" : : "r" (decr));

To set the first one to the same values as the following ones?

I guess we could get a case where the decrementer is really large (if large decrementer is enabled for example) and otherwise we just don't wake up...

In practise I'm not sure. But I'll add it if you like

Suraj.

Quoted 3 lines

Thanks,
Laurent

#3 lore raw
Quoted 61 lines · Suraj Jitindar Singh
Quoted 60 lines · Laurent Vivier
Quoted 59 lines · Suraj Jitindar Singh

Currently the handler for a decrementer exception will simply reload the
maximum value (0x7FFFFFFF), which will take ~4 seconds to expire again.
This means that if a vcpu cedes, it will be ~4 seconds between wakeups.

The h_cede_tm test is testing a known breakage when a guest cedes while
suspended. To be sure we cede 500 times to check for the bug. However
since it takes ~4 seconds to be woken up once we've ceded, we only get
through ~20 iterations before we reach the 90 seconds timeout and the
test appears to fail.

Add an option when registering the decrementer handler to specify the
value which should be reloaded by the handler, allowing the timeout to be
chosen.

Modify the spr test to use the max timeout to preserve existing behaviour.
Modify the h_cede_tm test to use a 10ms timeout to ensure we can perform
500 iterations before hitting the 90 second time limit for a test.

This means the h_cede_tm test now succeeds rather than timing out.

---
  lib/powerpc/handlers.c | 7 ++++---
  powerpc/sprs.c         | 3 ++-
  powerpc/tm.c           | 3 ++-
  3 files changed, 8 insertions(+), 5 deletions(-)
lib/powerpc/handlers.c +1 -1
index be8226a..c8721e0 100644
@@ -12,11 +12,12 @@
 
  /*
   * Generic handler for decrementer exceptions (0x900)
- * Just reset the decrementer back to its maximum value
 (0x7FFFFFFF)
+ * Just reset the decrementer back to the value specified when

registering the
+ * handler
*/
-void dec_except_handler(struct pt_regs *regs __unused, void *data __unused)

lib/powerpc/handlers.c +2 -1
+void dec_except_handler(struct pt_regs *regs __unused, void *data)
  {
-	uint32_t dec = 0x7FFFFFFF;
+	uint64_t dec = *((uint64_t *) data);
Quoted 11 lines
Quoted 11 lines

powerpc/sprs.c int main(int argc, char **argv) · line 256

Quoted 11 lines

asm volatile ("mtdec %0" : : "r" (dec));
}

powerpc/sprs.c +1 -0
index 6744bd8..3bd6ac7 100644
@@ -253,6 +253,7 @@ int main(int argc, char **argv)
  		0x1234567890ABCDEFULL, 0xFEDCBA0987654321ULL,
  		-1ULL,
  	};
+	uint64_t decr = 0x7FFFFFFF;

Declare the variable as "static", please, otherwise the pointer to it might get invalid at the end of the function.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
powerpc/sprs.c +1 -1
  	for (i = 1; i < argc; i++) {
  		if (!strcmp(argv[i], "-w")) {
@@ -288,7 +289,7 @@ int main(int argc, char **argv)
  		(void) getchar();
  	} else {
  		puts("Sleeping...\n");
-		handle_exception(0x900, &dec_except_handler,
 NULL);
+		handle_exception(0x900, &dec_except_handler,
 &decr);
  		asm volatile ("mtdec %0" : : "r" (0x3FFFFFFF));
  		hcall(H_CEDE);
  	}
powerpc/tm.c +0 -0
Quoted 8 lines
Quoted 8 lines

powerpc/tm.c static bool enable_tm(void) · line 98

Quoted 8 lines

index bd56baa..0f3f543 100644

powerpc/tm.c +1 -0
@@ -95,11 +95,12 @@ static bool enable_tm(void)
  static void test_h_cede_tm(int argc, char **argv)
  {
  	int i;
+	uint64_t decr = 0x3FFFFF;

"static" please.

Quoted 11 lines
Quoted 11 lines

powerpc/tm.c static bool enable_tm(void) · line 103

Quoted 6 lines
powerpc/tm.c +1 -1
  	if (argc > 2)
  		report_abort("Unsupported argument: '%s'",
 argv[2]);
 
-	handle_exception(0x900, &dec_except_handler, NULL);
+	handle_exception(0x900, &dec_except_handler, &decr);

Maybe you should also need here:

     asm volatile ("mtdec %0" : : "r" (decr));
Quoted 7 lines
Quoted 1 line

To set the first one to the same values as the following ones?

I guess we could get a case where the decrementer is really large (if large decrementer is enabled for example) and otherwise we just don't wake up...

In practise I'm not sure. But I'll add it if you like

I think I agree with Laurent - it's likely better to add the mtdec here.

Also, while you're at it, could/should we maybe remove the "nodefault" in unittests.cfg again (or rather the whole "groups" line)? I'm really afraid that this test does not get enough test coverage due to this...

Thomas