linux-um.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [uml-devel] [PATCH v3 0/3] um: fix and extend FPU support
@ 2016-03-19 16:58 Eli Cooper
  2016-03-19 16:58 ` [uml-devel] [PATCH v3 1/3] um: fix FPU state preservation around signal handlers Eli Cooper
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Eli Cooper @ 2016-03-19 16:58 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Richard Weinberger, Jeff Dike

This series first fixes a bug that results in corrupted FPU state after
invoking signal handlers. It also adds support for the extended processor
state (XSTATE) for x86_64 UML, especially the YMM registers used by AVX(2)
instructions.

Tested with a minimal multi-threaded FPU-intensive test program (see below).
This series supersedes the previous sigreturn fix as that one is incorrect
when the process is multi-threaded.

Changes since v2:
 - Add an improved sigreturn fix to this series
 - Merge the ptrace changes into the last commit
 - Make the selftest program multi-threaded

Changes since v1:
 - Refactor functions with oversized stack frame
 - Add a tiny selftest program to the cover letter

Eli Cooper (3):
  um: fix FPU state preservation around signal handlers
  um: extend fpstate to _xstate to support YMM registers
  um: add extended processor state save/restore support

 arch/um/include/shared/registers.h    |  2 ++
 arch/um/kernel/process.c              |  2 +-
 arch/um/os-Linux/signal.c             | 28 ++++++++++++++------
 arch/x86/um/os-Linux/registers.c      | 49 +++++++++++++++++++++++++++++++++--
 arch/x86/um/ptrace_32.c               |  5 ++--
 arch/x86/um/ptrace_64.c               | 16 ++++++------
 arch/x86/um/shared/sysdep/ptrace_64.h |  4 +--
 arch/x86/um/signal.c                  | 37 +++++++++-----------------
 arch/x86/um/user-offsets.c            |  2 +-
 9 files changed, 95 insertions(+), 50 deletions(-)

--
/* Test if context switches preserve YMM registers, multi-threaded version
 * The main function, threads and the signal handler all have their unique
 * ymm0 value, and constantly detect if someone steps on their toes.
 * Should loop forever.
 */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/time.h>
#include <immintrin.h>

#define N 10

void sighandler(int signum)
{
	int n = 0xffff;
	register uint32_t eax asm("eax");

	__m256i m0 = _mm256_set_epi64x(0x1234L << 32, 0, 0, 0);
	while (n--) {
		asm("vextracti128 $1,%ymm0,%xmm1");
		asm("vpextrd $3,%xmm1,%eax");
		if (eax != 0x1234)
			exit(3);
	}
}

void thread(void *arg)
{
	long n = (long)arg;
	register uint32_t eax asm("eax");

	__m256i m0 = _mm256_set_epi64x(n << 32, 0, 0, 0);
	do {
		asm("vextracti128 $1,%ymm0,%xmm1");
		asm("vpextrd $3,%xmm1,%eax");
	} while (eax == n);
	exit(2);
}

int main()
{
	register uint32_t eax asm("eax");
	pthread_t threads[N];
	struct itimerval itv;
	struct timeval tv;
	struct sigaction act;

	tv.tv_sec = 0;
	tv.tv_usec = 100000;
	itv.it_interval = tv;
	itv.it_value = tv;

	act.sa_handler = sighandler;
	act.sa_flags = 0;
	sigemptyset(&act.sa_mask);
	sigaction(SIGALRM, &act, NULL);

	setitimer(ITIMER_REAL, &itv, NULL);

	for (long i = 0; i < N; i++)
		pthread_create(threads + i, NULL, (void *)thread, (void *)i);

	__m256i m0 = _mm256_set_epi64x(0xabcdL << 32, 0, 0, 0);
	do {
		asm("vextracti128 $1,%ymm0,%xmm1");
		asm("vpextrd $3,%xmm1,%eax");
	} while (eax == 0xabcd);
	printf("%lx\n", eax);

	return 1;
}

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [uml-devel] [PATCH v3 0/3] um: fix and extend FPU support
@ 2016-05-20 15:48 Richard Weinberger
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Weinberger @ 2016-05-20 15:48 UTC (permalink / raw)
  To: Eli Cooper; +Cc: Jeff Dike, user-mode-linux-devel


Am 20.05.2016 17:31 schrieb Eli Cooper <elicooper@gmx.com>:
>
> On 2016/4/5 5:42, Richard Weinberger wrote: 
> > Sorry for my late response. 
> > I'll put this now into -next and give it some testing. 
>
> Ping? 
>
> It has been some time but I don't see this in -next yet. 

Sorry, I'm late. It will hit next tomorrow.
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-05-20 15:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-19 16:58 [uml-devel] [PATCH v3 0/3] um: fix and extend FPU support Eli Cooper
2016-03-19 16:58 ` [uml-devel] [PATCH v3 1/3] um: fix FPU state preservation around signal handlers Eli Cooper
2016-03-19 16:58 ` [uml-devel] [PATCH v3 2/3] um: extend fpstate to _xstate to support YMM registers Eli Cooper
2016-03-19 16:58 ` [uml-devel] [PATCH v3 3/3] um: add extended processor state save/restore support Eli Cooper
2016-04-04 21:42 ` [uml-devel] [PATCH v3 0/3] um: fix and extend FPU support Richard Weinberger
2016-05-20 15:31   ` Eli Cooper
  -- strict thread matches above, loose matches on Subject: below --
2016-05-20 15:48 Richard Weinberger

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).