drivers/misc/lkdtm/powerpc.c
Source file repositories/reference/linux-study-clean/drivers/misc/lkdtm/powerpc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/lkdtm/powerpc.c- Extension
.c- Size
- 4487 bytes
- Lines
- 179
- Domain
- Driver Families
- Bucket
- drivers/misc
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
lkdtm.hlinux/slab.hlinux/vmalloc.hasm/mmu.h
Detected Declarations
function insert_slb_entryfunction inject_vmalloc_slb_multihitfunction inject_kmalloc_slb_multihitfunction insert_dup_slb_entry_0function tlbiel_vafunction lkdtm_PPC_SLB_MULTIHITfunction lkdtm_PPC_RADIX_TLBIEL
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include "lkdtm.h"
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <asm/mmu.h>
#ifdef CONFIG_PPC_64S_HASH_MMU
/* Inserts new slb entries */
static void insert_slb_entry(unsigned long p, int ssize, int page_size)
{
unsigned long flags;
flags = SLB_VSID_KERNEL | mmu_psize_defs[page_size].sllp;
preempt_disable();
asm volatile("slbmte %0,%1" :
: "r" (mk_vsid_data(p, ssize, flags)),
"r" (mk_esid_data(p, ssize, SLB_NUM_BOLTED))
: "memory");
isync();
asm volatile("slbmte %0,%1" :
: "r" (mk_vsid_data(p, ssize, flags)),
"r" (mk_esid_data(p, ssize, SLB_NUM_BOLTED + 1))
: "memory");
isync();
preempt_enable();
}
/* Inject slb multihit on vmalloc-ed address i.e 0xD00... */
static int inject_vmalloc_slb_multihit(void)
{
char *p;
p = vmalloc(PAGE_SIZE);
if (!p)
return -ENOMEM;
insert_slb_entry((unsigned long)p, MMU_SEGSIZE_1T, mmu_vmalloc_psize);
/*
* This triggers exception, If handled correctly we must recover
* from this error.
*/
p[0] = '!';
vfree(p);
return 0;
}
/* Inject slb multihit on kmalloc-ed address i.e 0xC00... */
static int inject_kmalloc_slb_multihit(void)
{
char *p;
p = kmalloc(2048, GFP_KERNEL);
if (!p)
return -ENOMEM;
insert_slb_entry((unsigned long)p, MMU_SEGSIZE_1T, mmu_linear_psize);
/*
* This triggers exception, If handled correctly we must recover
* from this error.
*/
p[0] = '!';
kfree(p);
return 0;
}
/*
* Few initial SLB entries are bolted. Add a test to inject
* multihit in bolted entry 0.
*/
static void insert_dup_slb_entry_0(void)
{
unsigned long test_address = PAGE_OFFSET, *test_ptr;
unsigned long esid, vsid;
unsigned long i = 0;
test_ptr = (unsigned long *)test_address;
preempt_disable();
asm volatile("slbmfee %0,%1" : "=r" (esid) : "r" (i));
asm volatile("slbmfev %0,%1" : "=r" (vsid) : "r" (i));
/* for i !=0 we would need to mask out the old entry number */
asm volatile("slbmte %0,%1" :
: "r" (vsid),
"r" (esid | SLB_NUM_BOLTED)
: "memory");
Annotation
- Immediate include surface: `lkdtm.h`, `linux/slab.h`, `linux/vmalloc.h`, `asm/mmu.h`.
- Detected declarations: `function insert_slb_entry`, `function inject_vmalloc_slb_multihit`, `function inject_kmalloc_slb_multihit`, `function insert_dup_slb_entry_0`, `function tlbiel_va`, `function lkdtm_PPC_SLB_MULTIHIT`, `function lkdtm_PPC_RADIX_TLBIEL`.
- Atlas domain: Driver Families / drivers/misc.
- 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.