tools/testing/selftests/arm64/fp/zt-ptrace.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/arm64/fp/zt-ptrace.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/arm64/fp/zt-ptrace.c
Extension
.c
Size
7094 bytes
Lines
367
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (*size < sz) {
			p = realloc(*buf, sz);
			if (!p) {
				errno = ENOMEM;
				goto error;
			}

			*buf = p;
			*size = sz;
		}

		iov.iov_base = *buf;
		iov.iov_len = sz;
		if (ptrace(PTRACE_GETREGSET, pid, NT_ARM_ZA, &iov))
			goto error;

		za = *buf;
		if (za->size <= sz)
			break;

		sz = za->size;
	}

	return za;

error:
	return NULL;
}

static int set_za(pid_t pid, const struct user_za_header *za)
{
	struct iovec iov;

	iov.iov_base = (void *)za;
	iov.iov_len = za->size;
	return ptrace(PTRACE_SETREGSET, pid, NT_ARM_ZA, &iov);
}

static int get_zt(pid_t pid, char zt[ZT_SIG_REG_BYTES])
{
	struct iovec iov;

	iov.iov_base = zt;
	iov.iov_len = ZT_SIG_REG_BYTES;
	return ptrace(PTRACE_GETREGSET, pid, NT_ARM_ZT, &iov);
}

static int set_zt(pid_t pid, const char zt[ZT_SIG_REG_BYTES])
{
	struct iovec iov;

	iov.iov_base = (void *)zt;
	iov.iov_len = ZT_SIG_REG_BYTES;
	return ptrace(PTRACE_SETREGSET, pid, NT_ARM_ZT, &iov);
}

/* Reading with ZA disabled returns all zeros */
static void ptrace_za_disabled_read_zt(pid_t child)
{
	struct user_za_header za;
	char zt[ZT_SIG_REG_BYTES];
	int ret, i;
	bool fail = false;

	/* Disable PSTATE.ZA using the ZA interface */
	memset(&za, 0, sizeof(za));
	za.vl = sme_vl;
	za.size = sizeof(za);

	ret = set_za(child, &za);
	if (ret != 0) {
		ksft_print_msg("Failed to disable ZA\n");
		fail = true;
	}

	/* Read back ZT */
	ret = get_zt(child, zt);
	if (ret != 0) {
		ksft_print_msg("Failed to read ZT\n");
		fail = true;
	}

	for (i = 0; i < ARRAY_SIZE(zt); i++) {
		if (zt[i]) {
			ksft_print_msg("zt[%d]: 0x%x != 0\n", i, zt[i]);
			fail = true;
		}
	}

	ksft_test_result(!fail, "ptrace_za_disabled_read_zt\n");

Annotation

Implementation Notes