lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211203003636.11417-4-jiaxun.yang@flygoat.com>
Date:   Fri,  3 Dec 2021 00:36:29 +0000
From:   Jiaxun Yang <jiaxun.yang@...goat.com>
To:     x86@...nel.org
Cc:     tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
        dave.hansen@...ux.intel.com, hpa@...or.com,
        chang.seok.bae@...el.com, linux-kernel@...r.kernel.org,
        Jiaxun Yang <jiaxun.yang@...goat.com>,
        Jiaxun Yang <j.yang-87@....ed.ac.uk>
Subject: [RFC PATCH 03/10] x86/fpu: Calculate xsave state addr on fly

As we are going to have xsave buffer with different xcomp_bv,
the compact layout of those buffers can be different.

Calculate state address on fly instead of cache them on boot.

Signed-off-by: Jiaxun Yang <j.yang-87@....ed.ac.uk>
---
 arch/x86/kernel/fpu/xstate.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 353c661f8027..06f6214e9dd7 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1006,12 +1006,32 @@ void fpu__resume_cpu(void)
  */
 static void *__raw_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
 {
+	int i;
+	unsigned int offset;
+
 	if (!xfeature_enabled(xfeature_nr)) {
 		WARN_ON_FPU(1);
 		return NULL;
 	}
 
-	return (void *)xsave + xstate_comp_offsets[xfeature_nr];
+	/* Hanlde legacy states and standard format ext states */
+	if (xfeature_nr < FIRST_EXTENDED_XFEATURE ||
+		!(xsave->header.xcomp_bv & XCOMP_BV_COMPACTED_FORMAT))
+		return (void *)xsave + xstate_offsets[xfeature_nr];
+
+	/* Calculate compact ext state offsets */
+	offset = FXSAVE_SIZE + XSAVE_HDR_SIZE;
+	for_each_extended_xfeature(i, xsave->header.xcomp_bv) {
+		if (xfeature_is_aligned(i))
+			offset = ALIGN(offset, 64);
+
+		if (i == xfeature_nr)
+			return (void *)xsave + offset;
+
+		offset += xstate_sizes[i];
+	}
+
+	return NULL;
 }
 /*
  * Given the xsave area and a state inside, this function returns the
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ