arch/powerpc/kvm/book3s_64_vio.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kvm/book3s_64_vio.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kvm/book3s_64_vio.c- Extension
.c- Size
- 18946 bytes
- Lines
- 797
- 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/sched/signal.hlinux/hugetlb.hlinux/list.hlinux/anon_inodes.hlinux/iommu.hlinux/file.hlinux/mm.hlinux/rcupdate_wait.hasm/kvm_ppc.hasm/kvm_book3s.hasm/book3s/64/mmu-hash.hasm/hvcall.hasm/synch.hasm/ppc-opcode.hasm/udbg.hasm/iommu.hasm/tce.hasm/mmu_context.h
Detected Declarations
function kvmppc_tce_pagesfunction kvmppc_stt_pagesfunction kvm_spapr_tce_iommu_table_freefunction kvm_spapr_tce_liobn_putfunction kvm_spapr_tce_release_iommu_groupfunction list_for_each_entry_safefunction kvm_spapr_tce_attach_iommu_groupfunction release_spapr_tce_tablefunction kvm_spapr_tce_faultfunction kvm_spapr_tce_mmapfunction kvm_spapr_tce_releasefunction list_for_each_entry_safefunction kvm_vm_ioctl_create_spapr_tcefunction kvmppc_tce_to_uafunction kvmppc_tce_validatefunction kvmppc_tce_putfunction kvmppc_clear_tcefunction kvmppc_tce_iommu_mapped_decfunction kvmppc_tce_iommu_do_unmapfunction kvmppc_tce_iommu_unmapfunction kvmppc_tce_iommu_do_mapfunction kvmppc_tce_iommu_mapfunction kvmppc_h_put_tcefunction list_for_each_entry_locklessfunction kvmppc_h_put_tce_indirectfunction list_for_each_entry_locklessfunction kvmppc_h_stuff_tcefunction list_for_each_entry_locklessfunction kvmppc_h_get_tceexport kvmppc_h_put_tceexport kvmppc_h_put_tce_indirectexport kvmppc_h_stuff_tceexport kvmppc_h_get_tce
Annotated Snippet
static const struct file_operations kvm_spapr_tce_fops = {
.mmap = kvm_spapr_tce_mmap,
.release = kvm_spapr_tce_release,
};
int kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
struct kvm_create_spapr_tce_64 *args)
{
struct kvmppc_spapr_tce_table *stt = NULL;
struct kvmppc_spapr_tce_table *siter;
struct mm_struct *mm = kvm->mm;
unsigned long npages;
int ret;
if (!args->size || args->page_shift < 12 || args->page_shift > 34 ||
(args->offset + args->size > (ULLONG_MAX >> args->page_shift)))
return -EINVAL;
npages = kvmppc_tce_pages(args->size);
ret = account_locked_vm(mm, kvmppc_stt_pages(npages), true);
if (ret)
return ret;
ret = -ENOMEM;
stt = kzalloc_flex(*stt, pages, npages, GFP_KERNEL | __GFP_NOWARN);
if (!stt)
goto fail_acct;
stt->liobn = args->liobn;
stt->page_shift = args->page_shift;
stt->offset = args->offset;
stt->size = args->size;
stt->kvm = kvm;
mutex_init(&stt->alloc_lock);
INIT_LIST_HEAD_RCU(&stt->iommu_tables);
mutex_lock(&kvm->lock);
/* Check this LIOBN hasn't been previously allocated */
ret = 0;
list_for_each_entry(siter, &kvm->arch.spapr_tce_tables, list) {
if (siter->liobn == args->liobn) {
ret = -EBUSY;
break;
}
}
kvm_get_kvm(kvm);
if (!ret)
ret = anon_inode_getfd("kvm-spapr-tce", &kvm_spapr_tce_fops,
stt, O_RDWR | O_CLOEXEC);
if (ret >= 0)
list_add_rcu(&stt->list, &kvm->arch.spapr_tce_tables);
else
kvm_put_kvm_no_destroy(kvm);
mutex_unlock(&kvm->lock);
if (ret >= 0)
return ret;
kfree(stt);
fail_acct:
account_locked_vm(mm, kvmppc_stt_pages(npages), false);
return ret;
}
static long kvmppc_tce_to_ua(struct kvm *kvm, unsigned long tce,
unsigned long *ua)
{
unsigned long gfn = tce >> PAGE_SHIFT;
struct kvm_memory_slot *memslot;
memslot = __gfn_to_memslot(kvm_memslots(kvm), gfn);
if (!memslot)
return -EINVAL;
*ua = __gfn_to_hva_memslot(memslot, gfn) |
(tce & ~(PAGE_MASK | TCE_PCI_READ | TCE_PCI_WRITE));
return 0;
}
static long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *stt,
unsigned long tce)
{
unsigned long gpa = tce & ~(TCE_PCI_READ | TCE_PCI_WRITE);
enum dma_data_direction dir = iommu_tce_direction(tce);
struct kvmppc_spapr_tce_iommu_table *stit;
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/sched/signal.h`.
- Detected declarations: `function kvmppc_tce_pages`, `function kvmppc_stt_pages`, `function kvm_spapr_tce_iommu_table_free`, `function kvm_spapr_tce_liobn_put`, `function kvm_spapr_tce_release_iommu_group`, `function list_for_each_entry_safe`, `function kvm_spapr_tce_attach_iommu_group`, `function release_spapr_tce_table`, `function kvm_spapr_tce_fault`, `function kvm_spapr_tce_mmap`.
- 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.