linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Cyril Bur <cyrilbur@gmail.com>
To: Michael Neuling <mikey@neuling.org>, mpe@ellerman.id.au
Cc: linuxppc-dev@lists.ozlabs.org, Breno Leitao <brenohl@br.ibm.com>,
	Gustavo Bueno Romero <gromero@br.ibm.com>
Subject: Re: [PATCH 2/2] selftests/powerpc: Test TM and VMX register state
Date: Sat, 13 May 2017 01:16:20 +1000	[thread overview]
Message-ID: <1494602180.21781.1.camel@gmail.com> (raw)
In-Reply-To: <20170508071627.21851-2-mikey@neuling.org>

On Mon, 2017-05-08 at 17:16 +1000, Michael Neuling wrote:
> Test that the VMX checkpointed register state is maintained when a VMX
> unavailable exception is taken during a transaction.
> 
> Thanks to Breno Leitao <brenohl@br.ibm.com> and
> Gustavo Bueno Romero <gromero@br.ibm.com> for the original test this
> is based heavily on.
> 

Good looking test!

> Signed-off-by: Michael Neuling <mikey@neuling.org>

Reviewed-by: Cyril Bur <cyrilbur@gmail.com>

> ---
>  tools/testing/selftests/powerpc/tm/Makefile        |   4 +-
>  .../testing/selftests/powerpc/tm/tm-vmx-unavail.c  | 118 +++++++++++++++++++++
>  2 files changed, 121 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
> 
> diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
> index 5576ee6a51..b947995bb1 100644
> --- a/tools/testing/selftests/powerpc/tm/Makefile
> +++ b/tools/testing/selftests/powerpc/tm/Makefile
> @@ -2,7 +2,8 @@ SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu
>  	tm-signal-context-chk-vmx tm-signal-context-chk-vsx
>  
>  TEST_GEN_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
> -	tm-vmxcopy tm-fork tm-tar tm-tmspr $(SIGNAL_CONTEXT_CHK_TESTS)
> +	tm-vmxcopy tm-fork tm-tar tm-tmspr tm-vmx-unavail \
> +	$(SIGNAL_CONTEXT_CHK_TESTS)
>  
>  include ../../lib.mk
>  
> @@ -13,6 +14,7 @@ CFLAGS += -mhtm
>  $(OUTPUT)/tm-syscall: tm-syscall-asm.S
>  $(OUTPUT)/tm-syscall: CFLAGS += -I../../../../../usr/include
>  $(OUTPUT)/tm-tmspr: CFLAGS += -pthread
> +$(OUTPUT)/tm-vmx-unavail: CFLAGS += -pthread
>  
>  SIGNAL_CONTEXT_CHK_TESTS := $(patsubst %,$(OUTPUT)/%,$(SIGNAL_CONTEXT_CHK_TESTS))
>  $(SIGNAL_CONTEXT_CHK_TESTS): tm-signal.S
> diff --git a/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c b/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
> new file mode 100644
> index 0000000000..137185ba49
> --- /dev/null
> +++ b/tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c
> @@ -0,0 +1,118 @@
> +/*
> + * Copyright 2017, Michael Neuling, IBM Corp.
> + * Licensed under GPLv2.
> + * Original: Breno Leitao <brenohl@br.ibm.com> &
> + *           Gustavo Bueno Romero <gromero@br.ibm.com>
> + * Edited: Michael Neuling
> + *
> + * Force VMX unavailable during a transaction and see if it corrupts
> + * the checkpointed VMX register state after the abort.
> + */
> +
> +#include <inttypes.h>
> +#include <htmintrin.h>
> +#include <string.h>
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <pthread.h>
> +#include <sys/mman.h>
> +#include <unistd.h>
> +#include <pthread.h>
> +
> +#include "tm.h"
> +#include "utils.h"
> +
> +int passed;
> +
> +void *worker(void *unused)
> +{
> +	__int128 vmx0;
> +	uint64_t texasr;
> +
> +	asm goto (
> +		"li       3, 1;"  /* Stick non-zero value in VMX0 */
> +		"std      3, 0(%[vmx0_ptr]);"
> +		"lvx      0, 0, %[vmx0_ptr];"
> +
> +		/* Wait here a bit so we get scheduled out 255 times */
> +		"lis      3, 0x3fff;"
> +		"1: ;"
> +		"addi     3, 3, -1;"
> +		"cmpdi    3, 0;"
> +		"bne      1b;"
> +
> +		/* Kernel will hopefully turn VMX off now */
> +
> +		"tbegin. ;"
> +		"beq      failure;"
> +
> +		/* Cause VMX unavail. Any VMX instruction */
> +		"vaddcuw  0,0,0;"
> +
> +		"tend. ;"
> +		"b        %l[success];"
> +
> +		/* Check VMX0 sanity after abort */
> +		"failure: ;"
> +		"lvx       1,  0, %[vmx0_ptr];"
> +		"vcmpequb. 2,  0, 1;"
> +		"bc        4, 24, %l[value_mismatch];"
> +		"b        %l[value_match];"
> +		:
> +		: [vmx0_ptr] "r"(&vmx0)
> +		: "r3"
> +		: success, value_match, value_mismatch
> +		);
> +
> +	/* HTM aborted and VMX0 is corrupted */
> +value_mismatch:
> +	texasr = __builtin_get_texasr();
> +
> +	printf("\n\n==============\n\n");
> +	printf("Failure with error: %lx\n",   _TEXASR_FAILURE_CODE(texasr));
> +	printf("Summary error     : %lx\n",   _TEXASR_FAILURE_SUMMARY(texasr));
> +	printf("TFIAR exact       : %lx\n\n", _TEXASR_TFIAR_EXACT(texasr));
> +
> +	passed = 0;
> +	return NULL;
> +
> +	/* HTM aborted but VMX0 is correct */
> +value_match:
> +//	printf("!");
> +	return NULL;
> +
> +success:
> +//	printf(".");
> +	return NULL;
> +}
> +
> +int tm_vmx_unavail_test()
> +{
> +	int threads;
> +	pthread_t *thread;
> +
> +	SKIP_IF(!have_htm());
> +
> +	passed = 1;
> +
> +	threads = sysconf(_SC_NPROCESSORS_ONLN) * 4;
> +	thread = malloc(sizeof(pthread_t)*threads);
> +	if (!thread)
> +		return EXIT_FAILURE;
> +
> +	for (uint64_t i = 0; i < threads; i++)
> +		pthread_create(&thread[i], NULL, &worker, NULL);
> +
> +	for (uint64_t i = 0; i < threads; i++)
> +		pthread_join(thread[i], NULL);
> +
> +	free(thread);
> +
> +	return passed ? EXIT_SUCCESS : EXIT_FAILURE;
> +}
> +
> +
> +int main(int argc, char **argv)
> +{
> +	return test_harness(tm_vmx_unavail_test, "tm_vmx_unavail_test");
> +}

  reply	other threads:[~2017-05-12 15:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-08  7:16 [PATCH 1/2] powerpc/tm: Fix FP and VMX register corruption Michael Neuling
2017-05-08  7:16 ` [PATCH 2/2] selftests/powerpc: Test TM and VMX register state Michael Neuling
2017-05-12 15:16   ` Cyril Bur [this message]
2017-05-15  9:31   ` Michael Ellerman
2017-05-17  9:34   ` [2/2] " Michael Ellerman
2017-05-12 15:26 ` [PATCH 1/2] powerpc/tm: Fix FP and VMX register corruption Cyril Bur
2017-05-15  9:23   ` Michael Ellerman
2017-05-17  9:34 ` [1/2] " Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1494602180.21781.1.camel@gmail.com \
    --to=cyrilbur@gmail.com \
    --cc=brenohl@br.ibm.com \
    --cc=gromero@br.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mikey@neuling.org \
    --cc=mpe@ellerman.id.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).