tools/testing/selftests/powerpc/dexcr/dexcr.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/dexcr/dexcr.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/dexcr/dexcr.c- Extension
.c- Size
- 4133 bytes
- Lines
- 173
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hsetjmp.hsignal.hsys/prctl.hsys/types.hsys/wait.hdexcr.hreg.hutils.h
Detected Declarations
function generic_signal_handlerfunction dexcr_existsfunction pr_which_to_aspectfunction pr_get_dexcrfunction pr_set_dexcrfunction pr_dexcr_aspect_supportedfunction pr_dexcr_aspect_editablefunction hashchk_triggersfunction get_dexcrfunction await_child_successfunction hashstfunction hashchkfunction do_bad_hashchk
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
#include <errno.h>
#include <setjmp.h>
#include <signal.h>
#include <sys/prctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "dexcr.h"
#include "reg.h"
#include "utils.h"
static jmp_buf generic_signal_jump_buf;
static void generic_signal_handler(int signum, siginfo_t *info, void *context)
{
longjmp(generic_signal_jump_buf, 0);
}
bool dexcr_exists(void)
{
struct sigaction old;
volatile bool exists;
old = push_signal_handler(SIGILL, generic_signal_handler);
if (setjmp(generic_signal_jump_buf))
goto out;
/*
* If the SPR is not recognised by the hardware it triggers
* a hypervisor emulation interrupt. If the kernel does not
* recognise/try to emulate it, we receive a SIGILL signal.
*
* If we do not receive a signal, assume we have the SPR or the
* kernel is trying to emulate it correctly.
*/
exists = false;
mfspr(SPRN_DEXCR_RO);
exists = true;
out:
pop_signal_handler(SIGILL, old);
return exists;
}
unsigned int pr_which_to_aspect(unsigned long which)
{
switch (which) {
case PR_PPC_DEXCR_SBHE:
return DEXCR_PR_SBHE;
case PR_PPC_DEXCR_IBRTPD:
return DEXCR_PR_IBRTPD;
case PR_PPC_DEXCR_SRAPD:
return DEXCR_PR_SRAPD;
case PR_PPC_DEXCR_NPHIE:
return DEXCR_PR_NPHIE;
default:
FAIL_IF_EXIT_MSG(true, "unknown PR aspect");
}
}
int pr_get_dexcr(unsigned long which)
{
return prctl(PR_PPC_GET_DEXCR, which, 0UL, 0UL, 0UL);
}
int pr_set_dexcr(unsigned long which, unsigned long ctrl)
{
return prctl(PR_PPC_SET_DEXCR, which, ctrl, 0UL, 0UL);
}
bool pr_dexcr_aspect_supported(unsigned long which)
{
if (pr_get_dexcr(which) == -1)
return errno == ENODEV;
return true;
}
bool pr_dexcr_aspect_editable(unsigned long which)
{
return pr_get_dexcr(which) & PR_PPC_DEXCR_CTRL_EDITABLE;
}
/*
* Just test if a bad hashchk triggers a signal, without checking
* for support or if the NPHIE aspect is enabled.
*/
bool hashchk_triggers(void)
Annotation
- Immediate include surface: `errno.h`, `setjmp.h`, `signal.h`, `sys/prctl.h`, `sys/types.h`, `sys/wait.h`, `dexcr.h`, `reg.h`.
- Detected declarations: `function generic_signal_handler`, `function dexcr_exists`, `function pr_which_to_aspect`, `function pr_get_dexcr`, `function pr_set_dexcr`, `function pr_dexcr_aspect_supported`, `function pr_dexcr_aspect_editable`, `function hashchk_triggers`, `function get_dexcr`, `function await_child_success`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.