tools/testing/selftests/mm/pkey-powerpc.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/pkey-powerpc.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/pkey-powerpc.h- Extension
.h- Size
- 4005 bytes
- Lines
- 146
- 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
sys/stat.h
Detected Declarations
function pkey_bit_positionfunction __read_pkey_regfunction __write_pkey_regfunction cpu_has_pkeysfunction arch_is_powervmfunction get_arch_reserved_keysfunction expect_fault_on_read_execonly_keyfunction REPEAT_8
Annotated Snippet
#ifndef _PKEYS_POWERPC_H
#define _PKEYS_POWERPC_H
#include <sys/stat.h>
#ifndef SYS_pkey_alloc
# define SYS_pkey_alloc 384
# define SYS_pkey_free 385
#endif
#define REG_IP_IDX PT_NIP
#define MCONTEXT_IP(mc) mc.gp_regs[REG_IP_IDX]
#define MCONTEXT_TRAPNO(mc) mc.gp_regs[REG_TRAPNO]
#define REG_TRAPNO PT_TRAP
#define MCONTEXT_FPREGS
#define gregs gp_regs
#define fpregs fp_regs
#define si_pkey_offset 0x20
#undef PKEY_DISABLE_ACCESS
#define PKEY_DISABLE_ACCESS 0x3 /* disable read and write */
#undef PKEY_DISABLE_WRITE
#define PKEY_DISABLE_WRITE 0x2
#define NR_PKEYS 32
#define NR_RESERVED_PKEYS_4K 27 /* pkey-0, pkey-1, exec-only-pkey
and 24 other keys that cannot be
represented in the PTE */
#define NR_RESERVED_PKEYS_64K_3KEYS 3 /* PowerNV and KVM: pkey-0,
pkey-1 and exec-only key */
#define NR_RESERVED_PKEYS_64K_4KEYS 4 /* PowerVM: pkey-0, pkey-1,
pkey-31 and exec-only key */
#define PKEY_BITS_PER_PKEY 2
#define HPAGE_SIZE (1UL << 24)
#define PAGE_SIZE sysconf(_SC_PAGESIZE)
static inline u32 pkey_bit_position(int pkey)
{
return (NR_PKEYS - pkey - 1) * PKEY_BITS_PER_PKEY;
}
static inline u64 __read_pkey_reg(void)
{
u64 pkey_reg;
asm volatile("mfspr %0, 0xd" : "=r" (pkey_reg));
return pkey_reg;
}
static inline void __write_pkey_reg(u64 pkey_reg)
{
u64 amr = pkey_reg;
dprintf4("%s() changing %016llx to %016llx\n",
__func__, __read_pkey_reg(), pkey_reg);
asm volatile("isync; mtspr 0xd, %0; isync"
: : "r" ((unsigned long)(amr)) : "memory");
dprintf4("%s() pkey register after changing %016llx to %016llx\n",
__func__, __read_pkey_reg(), pkey_reg);
}
static inline int cpu_has_pkeys(void)
{
/* No simple way to determine this */
return 1;
}
static inline bool arch_is_powervm()
{
struct stat buf;
if ((stat("/sys/firmware/devicetree/base/ibm,partition-name", &buf) == 0) &&
(stat("/sys/firmware/devicetree/base/hmc-managed?", &buf) == 0) &&
(stat("/sys/firmware/devicetree/base/chosen/qemu,graphic-width", &buf) == -1) )
return true;
return false;
}
static inline int get_arch_reserved_keys(void)
{
if (sysconf(_SC_PAGESIZE) == 4096)
return NR_RESERVED_PKEYS_4K;
else
if (arch_is_powervm())
return NR_RESERVED_PKEYS_64K_4KEYS;
else
Annotation
- Immediate include surface: `sys/stat.h`.
- Detected declarations: `function pkey_bit_position`, `function __read_pkey_reg`, `function __write_pkey_reg`, `function cpu_has_pkeys`, `function arch_is_powervm`, `function get_arch_reserved_keys`, `function expect_fault_on_read_execonly_key`, `function REPEAT_8`.
- 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.