arch/s390/kvm/pv.c
Source file repositories/reference/linux-study-clean/arch/s390/kvm/pv.c
File Facts
- System
- Linux kernel
- Corpus path
arch/s390/kvm/pv.c- Extension
.c- Size
- 30631 bytes
- Lines
- 1064
- Domain
- Architecture Layer
- Bucket
- arch/s390
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/export.hlinux/kvm.hlinux/kvm_host.hlinux/minmax.hlinux/pagemap.hlinux/sched/signal.hasm/uv.hasm/mman.hlinux/pagewalk.hlinux/sched/mm.hlinux/mmu_notifier.hasm/gmap_helpers.hkvm-s390.hdat.hgaccess.hgmap.hfaultin.h
Detected Declarations
struct pv_make_securestruct pv_vm_to_be_destroyedfunction Authorfunction kvm_s390_pv_cpu_is_protectedfunction should_export_before_importfunction __kvm_s390_pv_make_securefunction _kvm_s390_pv_make_securefunction kvm_s390_pv_make_securefunction scoped_guardfunction kvm_s390_pv_convert_to_securefunction kvm_s390_pv_destroy_pagefunction kvm_s390_clear_pv_statefunction kvm_s390_pv_destroy_cpufunction kvm_s390_pv_create_cpufunction kvm_s390_pv_dealloc_vmfunction kvm_s390_pv_alloc_vmfunction kvm_s390_pv_dispose_one_leftoverfunction kvm_s390_pv_deinit_vm_fastfunction is_destroy_fast_availablefunction kvm_s390_pv_set_asidefunction kvm_s390_pv_deinit_vmfunction kvm_s390_pv_deinit_cleanup_allfunction KVM_UV_EVENTfunction kvm_s390_pv_deinit_aside_vmfunction kvm_s390_pv_mmu_notifier_releasefunction kvm_s390_pv_init_vmfunction scoped_guardfunction kvm_s390_pv_set_sec_parmsfunction unpack_onefunction kvm_s390_pv_unpackfunction kvm_s390_pv_set_cpu_statefunction kvm_s390_pv_dump_cpufunction kvm_s390_pv_dump_stor_statefunction kvm_s390_pv_dump_completeexport kvm_s390_pv_is_protectedexport kvm_s390_pv_cpu_is_protected
Annotated Snippet
struct pv_make_secure {
void *uvcb;
struct folio *folio;
struct kvm *kvm;
int rc;
bool needs_export;
};
static int __kvm_s390_pv_make_secure(struct guest_fault *f, struct folio *folio)
{
struct pv_make_secure *priv = f->priv;
int rc;
if (priv->needs_export)
uv_convert_from_secure(folio_to_phys(folio));
if (folio_test_hugetlb(folio))
return -EFAULT;
if (folio_test_large(folio))
return -E2BIG;
if (!f->page)
folio_get(folio);
rc = __make_folio_secure(folio, priv->uvcb);
if (!f->page)
folio_put(folio);
return rc;
}
static void _kvm_s390_pv_make_secure(struct guest_fault *f)
{
struct pv_make_secure *priv = f->priv;
struct folio *folio;
spinlock_t *ptl; /* pte lock from try_get_locked_pte() */
pte_t *ptep;
folio = pfn_folio(f->pfn);
priv->rc = -EAGAIN;
if (!mmap_read_trylock(priv->kvm->mm))
return;
ptep = try_get_locked_pte(priv->kvm->mm, gfn_to_hva(priv->kvm, f->gfn), &ptl);
if (IS_ERR_VALUE(ptep)) {
priv->rc = PTR_ERR(ptep);
goto out;
}
if (folio_trylock(folio)) {
priv->rc = __kvm_s390_pv_make_secure(f, folio);
if (priv->rc == -E2BIG || priv->rc == -EBUSY) {
priv->folio = folio;
folio_get(folio);
}
folio_unlock(folio);
}
if (ptep)
pte_unmap_unlock(ptep, ptl);
out:
mmap_read_unlock(priv->kvm->mm);
}
/**
* kvm_s390_pv_make_secure() - make one guest page secure
* @kvm: the guest
* @gaddr: the guest address that needs to be made secure
* @uvcb: the UVCB specifying which operation needs to be performed
*
* Context: needs to be called with kvm->srcu held.
* Return: 0 on success, < 0 in case of error.
*/
int kvm_s390_pv_make_secure(struct kvm *kvm, unsigned long gaddr, void *uvcb)
{
struct pv_make_secure priv = { .uvcb = uvcb, .kvm = kvm, };
struct guest_fault f = {
.write_attempt = true,
.gfn = gpa_to_gfn(gaddr),
.callback = _kvm_s390_pv_make_secure,
.priv = &priv,
};
int rc;
lockdep_assert_held(&kvm->srcu);
priv.needs_export = should_export_before_import(uvcb, kvm->mm);
scoped_guard(mutex, &kvm->arch.pv.import_lock) {
rc = kvm_s390_faultin_gfn(NULL, kvm, &f);
Annotation
- Immediate include surface: `linux/export.h`, `linux/kvm.h`, `linux/kvm_host.h`, `linux/minmax.h`, `linux/pagemap.h`, `linux/sched/signal.h`, `asm/uv.h`, `asm/mman.h`.
- Detected declarations: `struct pv_make_secure`, `struct pv_vm_to_be_destroyed`, `function Author`, `function kvm_s390_pv_cpu_is_protected`, `function should_export_before_import`, `function __kvm_s390_pv_make_secure`, `function _kvm_s390_pv_make_secure`, `function kvm_s390_pv_make_secure`, `function scoped_guard`, `function kvm_s390_pv_convert_to_secure`.
- Atlas domain: Architecture Layer / arch/s390.
- Implementation status: integration 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.