From 6fba90f20187a2ebaaa681648e630758b804a5b9 Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Fri, 12 Jun 2020 21:17:56 +0000 Subject: [PATCH] FPU init: allocate initial state from UMA to ensure alignment The Intel Instruction Set Reference says this about the XSAVE instruction: Use of a destination operand not aligned to 64-byte boundary (in either 64-bit or 32-bit modes) results in a general-protection (#GP) exception. This alignment happens naturally when all malloc buckets are powers of two. However, this change is necessary on some systems when certain non-power-of-two (and non-multiple of 64) malloc buckets are defined. Reviewed by: cem; kib; earlier version by jhb MFC after: 2 weeks Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D25098 --- sys/amd64/amd64/fpu.c | 3 +-- sys/i386/i386/npx.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index 9feb14214217..b554394a17bb 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -372,8 +372,7 @@ fpuinitstate(void *arg __unused) fpu_save_area_zone = uma_zcreate("FPU_save_area", cpu_max_ext_state_size, NULL, NULL, NULL, NULL, XSAVE_AREA_ALIGN - 1, 0); - fpu_initialstate = malloc(cpu_max_ext_state_size, M_DEVBUF, - M_WAITOK | M_ZERO); + fpu_initialstate = uma_zalloc(fpu_save_area_zone, M_WAITOK | M_ZERO); if (use_xsave) { max_ext_n = flsl(xsave_mask); xsave_area_desc = malloc(max_ext_n * sizeof(struct diff --git a/sys/i386/i386/npx.c b/sys/i386/i386/npx.c index 794eab31c27e..348f34d1e4f3 100644 --- a/sys/i386/i386/npx.c +++ b/sys/i386/i386/npx.c @@ -483,8 +483,7 @@ npxinitstate(void *arg __unused) fpu_save_area_zone = uma_zcreate("FPU_save_area", cpu_max_ext_state_size, NULL, NULL, NULL, NULL, XSAVE_AREA_ALIGN - 1, 0); - npx_initialstate = malloc(cpu_max_ext_state_size, M_DEVBUF, - M_WAITOK | M_ZERO); + npx_initialstate = uma_zalloc(fpu_save_area_zone, M_WAITOK | M_ZERO); if (use_xsave) { if (xsave_mask >> 32 != 0) max_ext_n = fls(xsave_mask >> 32) + 32;