Skip to contentSkip to conversation

ptrace07: should not use a hard-coded xstate size and use CPUID specified instead

PATCH Superseded Pengfei Xu 1 participant 1 message Sep 29, 2022 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Pengfei Xu

author
#1 lore raw

PATCH 1/1 ptrace07: should not use a hard-coded xstate size and use CPUID specified instead

Should not use a hard-coded xstate size(512 * 8 = 4096 bytes) which is wrong, should use maximum XSAVE size specified by CPUID.(EAX=0DH, ECX=0H):EBX. If the CPU's maximum XSAVE size exceeds the hard-coded xstate size 4096 bytes, it will cause the ptrace07 case to fail as below:
"
./ptrace07
tst_test.c:1528: TINFO: Timeout per run is 0h 00m 30s ptrace07.c:142: TBROK: PTRACE_SETREGSET failed with unexpected error: EFAULT (14) tst_test.c:1571: TINFO: Killed the leftover descendant processes

Summary:

passed   0
failed   0
broken   1
skipped  0

warnings 0
"

---
 testcases/kernel/syscalls/ptrace/ptrace07.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ptrace/ptrace07.c +11 -2
index da62cadb0..358a422c0 100644
@@ -35,6 +35,7 @@
 #include "config.h"
 #include "ptrace.h"
 #include "tst_test.h"
+#include "ltp_cpuid.h"
 
 #ifndef PTRACE_GETREGSET
 # define PTRACE_GETREGSET 0x4204
@@ -48,6 +49,8 @@
 # define NT_X86_XSTATE 0x202
 #endif
 
+#define CPUID_LEAF_XSTATE 0xd
+
 static void check_regs_loop(uint32_t initval)
 {
 	const unsigned long num_iters = 1000000000;
@@ -83,8 +86,14 @@ static void do_test(void)
 	int i;
 	int num_cpus = tst_ncpus();
 	pid_t pid;
-	uint64_t xstate[512];
-	struct iovec iov = { .iov_base = xstate, .iov_len = sizeof(xstate) };
+	uint32_t eax, ebx, ecx = 0, edx, *xstate;
+	/*
+	 * CPUID.(EAX=0DH, ECX=0H):EBX: maximum size (bytes, from the beginning
+	 * of the XSAVE/XRSTOR save area) required by enabled features in XCR0.
+	 */
+	cpuid(CPUID_LEAF_XSTATE, &eax, &ebx, &ecx, &edx);
+	xstate = aligned_alloc(64, ebx);
+	struct iovec iov = { .iov_base = xstate, .iov_len = ebx };
 	int status;
 	bool okay;
 
Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp