arch/x86/virt/svm/sev.c
Source file repositories/reference/linux-study-clean/arch/x86/virt/svm/sev.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/virt/svm/sev.c- Extension
.c- Size
- 28153 bytes
- Lines
- 1103
- Domain
- Architecture Layer
- Bucket
- arch/x86
- 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.
- 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/cc_platform.hlinux/printk.hlinux/mm_types.hlinux/set_memory.hlinux/memblock.hlinux/kernel.hlinux/mm.hlinux/cpumask.hlinux/iommu.hlinux/amd-iommu.hlinux/nospec.hasm/sev.hasm/processor.hasm/setup.hasm/svm.hasm/smp.hasm/cpu.hasm/apic.hasm/cpuid/api.hasm/cmdline.hasm/iommu.hasm/msr.h
Detected Declarations
struct rmpentrystruct rmpentry_rawstruct rmp_segment_descfunction mfd_reconfigurefunction snp_enablefunction __snp_fixup_e820_tablesfunction fixup_e820_tables_for_segmented_rmpfunction fixup_e820_tables_for_contiguous_rmpfunction snp_fixup_e820_tablesfunction clear_rmpfunction alloc_rmp_segment_descfunction free_rmp_segment_tablefunction alloc_rmp_segment_tablefunction setup_contiguous_rmptablefunction setup_segmented_rmptablefunction setup_rmptablefunction clear_hsave_pafunction snp_preparefunction snp_shutdownfunction snp_rmptable_initfunction set_rmp_segment_infofunction probe_contiguous_rmptable_infofunction probe_segmented_rmptable_infofunction snp_probe_rmptable_infofunction array_index_nospecfunction get_rmpentryfunction __snp_lookup_rmpentryfunction snp_lookup_rmpentryfunction dump_rmpentryfunction snp_dump_hva_rmpentryfunction psmashfunction adjust_direct_mapfunction rmpupdatefunction rmp_make_privatefunction rmp_make_sharedfunction __snp_leak_pagesfunction kdump_sev_callbackexport snp_lookup_rmpentryexport psmashexport rmp_make_privateexport rmp_make_sharedexport __snp_leak_pages
Annotated Snippet
struct rmpentry {
u64 gpa;
u8 assigned :1,
rsvd1 :7;
u8 pagesize :1,
hpage_region_status :1,
rsvd2 :6;
u8 immutable :1,
rsvd3 :7;
u8 rsvd4;
u32 asid;
} __packed;
/*
* The raw RMP entry format is not architectural. The format is defined in PPR
* Family 19h Model 01h, Rev B1 processor. This format represents the actual
* entry in the RMP table memory. The bitfield definitions are used for machines
* without the RMPREAD instruction (Zen3 and Zen4), otherwise the "hi" and "lo"
* fields are only used for dumping the raw data.
*/
struct rmpentry_raw {
union {
struct {
u64 assigned : 1,
pagesize : 1,
immutable : 1,
rsvd1 : 9,
gpa : 39,
asid : 10,
vmsa : 1,
validated : 1,
rsvd2 : 1;
};
u64 lo;
};
u64 hi;
} __packed;
/*
* The first 16KB from the RMP_BASE is used by the processor for the
* bookkeeping, the range needs to be added during the RMP entry lookup.
*/
#define RMPTABLE_CPU_BOOKKEEPING_SZ 0x4000
/*
* For a non-segmented RMP table, use the maximum physical addressing as the
* segment size in order to always arrive at index 0 in the table.
*/
#define RMPTABLE_NON_SEGMENTED_SHIFT 52
struct rmp_segment_desc {
struct rmpentry_raw *rmp_entry;
u64 max_index;
u64 size;
};
/*
* Segmented RMP Table support.
* - The segment size is used for two purposes:
* - Identify the amount of memory covered by an RMP segment
* - Quickly locate an RMP segment table entry for a physical address
*
* - The RMP segment table contains pointers to an RMP table that covers
* a specific portion of memory. There can be up to 512 8-byte entries,
* one pages worth.
*/
#define RST_ENTRY_MAPPED_SIZE(x) ((x) & GENMASK_ULL(19, 0))
#define RST_ENTRY_SEGMENT_BASE(x) ((x) & GENMASK_ULL(51, 20))
#define RST_SIZE SZ_4K
static struct rmp_segment_desc **rmp_segment_table __ro_after_init;
static unsigned int rst_max_index __ro_after_init = 512;
static unsigned int rmp_segment_shift;
static u64 rmp_segment_size;
static u64 rmp_segment_mask;
#define RST_ENTRY_INDEX(x) ((x) >> rmp_segment_shift)
#define RMP_ENTRY_INDEX(x) ((u64)(PHYS_PFN((x) & rmp_segment_mask)))
static u64 rmp_cfg;
static void *rmp_bookkeeping __ro_after_init;
/* Mask to apply to a PFN to get the first PFN of a 2MB page */
#define PFN_PMD_MASK GENMASK_ULL(63, PMD_SHIFT - PAGE_SHIFT)
static u64 probed_rmp_base, probed_rmp_size;
static LIST_HEAD(snp_leaked_pages_list);
Annotation
- Immediate include surface: `linux/cc_platform.h`, `linux/printk.h`, `linux/mm_types.h`, `linux/set_memory.h`, `linux/memblock.h`, `linux/kernel.h`, `linux/mm.h`, `linux/cpumask.h`.
- Detected declarations: `struct rmpentry`, `struct rmpentry_raw`, `struct rmp_segment_desc`, `function mfd_reconfigure`, `function snp_enable`, `function __snp_fixup_e820_tables`, `function fixup_e820_tables_for_segmented_rmp`, `function fixup_e820_tables_for_contiguous_rmp`, `function snp_fixup_e820_tables`, `function clear_rmp`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- 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.