arch/powerpc/kvm/book3s_64_mmu_hv.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kvm/book3s_64_mmu_hv.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kvm/book3s_64_mmu_hv.c- Extension
.c- Size
- 53142 bytes
- Lines
- 2122
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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
linux/types.hlinux/string.hlinux/kvm.hlinux/kvm_host.hlinux/highmem.hlinux/gfp.hlinux/slab.hlinux/hugetlb.hlinux/vmalloc.hlinux/srcu.hlinux/anon_inodes.hlinux/file.hlinux/debugfs.hasm/kvm_ppc.hasm/kvm_book3s.hasm/book3s/64/mmu-hash.hasm/hvcall.hasm/synch.hasm/ppc-opcode.hasm/cputable.hasm/pte-walk.hbook3s.hbook3s_hv.htrace_hv.h
Detected Declarations
struct kvm_resize_hptstruct kvm_htab_ctxstruct debugfs_htab_statefunction kvmppc_allocate_hptfunction kvmppc_set_hptfunction kvmppc_alloc_reset_hptfunction kvmppc_free_hptfunction hpte0_pgsize_encodingfunction hpte1_pgsize_encodingfunction kvmppc_map_vrmafunction kvmppc_mmu_hv_initfunction kvmppc_virtmode_do_h_enterfunction kvmppc_mmu_get_real_addrfunction kvmppc_mmu_book3s_64_hv_xlatefunction instruction_is_storefunction kvmppc_hv_emulate_mmiofunction kvmppc_book3s_hv_page_faultfunction kvmppc_rmap_resetfunction kvmppc_unmap_hptefunction hpte_rpnfunction kvm_unmap_rmappfunction kvm_unmap_gfn_range_hvfunction kvmppc_core_flush_memslot_hvfunction kvm_age_rmappfunction kvm_age_gfn_hvfunction kvm_test_age_rmappfunction kvm_test_age_gfn_hvfunction vcpus_runningfunction kvm_test_clear_dirty_npagesfunction kvmppc_harvest_vpa_dirtyfunction kvmppc_hv_get_dirty_log_hptfunction kvmppc_unpin_guest_pagefunction resize_hpt_allocatefunction resize_hpt_rehash_hptefunction resize_hpt_rehashfunction resize_hpt_pivotfunction resize_hpt_releasefunction resize_hpt_prepare_workfunction kvm_vm_ioctl_resize_hpt_preparefunction resize_hpt_boot_vcpufunction hpte_dirtyfunction record_hptefunction kvm_htab_readfunction kvm_htab_writefunction kvm_htab_releasefunction kvm_vm_ioctl_get_htab_fdfunction debugfs_htab_openfunction debugfs_htab_release
Annotated Snippet
static const struct file_operations kvm_htab_fops = {
.read = kvm_htab_read,
.write = kvm_htab_write,
.llseek = default_llseek,
.release = kvm_htab_release,
};
int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *ghf)
{
int ret;
struct kvm_htab_ctx *ctx;
int rwflag;
/* reject flags we don't recognize */
if (ghf->flags & ~(KVM_GET_HTAB_BOLTED_ONLY | KVM_GET_HTAB_WRITE))
return -EINVAL;
ctx = kzalloc_obj(*ctx);
if (!ctx)
return -ENOMEM;
kvm_get_kvm(kvm);
ctx->kvm = kvm;
ctx->index = ghf->start_index;
ctx->flags = ghf->flags;
ctx->first_pass = 1;
rwflag = (ghf->flags & KVM_GET_HTAB_WRITE) ? O_WRONLY : O_RDONLY;
ret = anon_inode_getfd("kvm-htab", &kvm_htab_fops, ctx, rwflag | O_CLOEXEC);
if (ret < 0) {
kfree(ctx);
kvm_put_kvm_no_destroy(kvm);
return ret;
}
if (rwflag == O_RDONLY) {
mutex_lock(&kvm->slots_lock);
atomic_inc(&kvm->arch.hpte_mod_interest);
/* make sure kvmppc_do_h_enter etc. see the increment */
synchronize_srcu_expedited(&kvm->srcu);
mutex_unlock(&kvm->slots_lock);
}
return ret;
}
struct debugfs_htab_state {
struct kvm *kvm;
struct mutex mutex;
unsigned long hpt_index;
int chars_left;
int buf_index;
char buf[64];
};
static int debugfs_htab_open(struct inode *inode, struct file *file)
{
struct kvm *kvm = inode->i_private;
struct debugfs_htab_state *p;
p = kzalloc_obj(*p);
if (!p)
return -ENOMEM;
kvm_get_kvm(kvm);
p->kvm = kvm;
mutex_init(&p->mutex);
file->private_data = p;
return nonseekable_open(inode, file);
}
static int debugfs_htab_release(struct inode *inode, struct file *file)
{
struct debugfs_htab_state *p = file->private_data;
kvm_put_kvm(p->kvm);
kfree(p);
return 0;
}
static ssize_t debugfs_htab_read(struct file *file, char __user *buf,
size_t len, loff_t *ppos)
{
struct debugfs_htab_state *p = file->private_data;
ssize_t ret, r;
unsigned long i, n;
unsigned long v, hr, gr;
struct kvm *kvm;
__be64 *hptp;
kvm = p->kvm;
Annotation
- Immediate include surface: `linux/types.h`, `linux/string.h`, `linux/kvm.h`, `linux/kvm_host.h`, `linux/highmem.h`, `linux/gfp.h`, `linux/slab.h`, `linux/hugetlb.h`.
- Detected declarations: `struct kvm_resize_hpt`, `struct kvm_htab_ctx`, `struct debugfs_htab_state`, `function kvmppc_allocate_hpt`, `function kvmppc_set_hpt`, `function kvmppc_alloc_reset_hpt`, `function kvmppc_free_hpt`, `function hpte0_pgsize_encoding`, `function hpte1_pgsize_encoding`, `function kvmppc_map_vrma`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.