drivers/crypto/ccp/sev-dev.c
Source file repositories/reference/linux-study-clean/drivers/crypto/ccp/sev-dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/ccp/sev-dev.c- Extension
.c- Size
- 76682 bytes
- Lines
- 2985
- Domain
- Driver Families
- Bucket
- drivers/crypto
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- 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/bitfield.hlinux/module.hlinux/kernel.hlinux/kthread.hlinux/sched.hlinux/interrupt.hlinux/spinlock.hlinux/spinlock_types.hlinux/types.hlinux/mutex.hlinux/delay.hlinux/hw_random.hlinux/ccp.hlinux/firmware.hlinux/panic_notifier.hlinux/gfp.hlinux/cpufeature.hlinux/fs.hlinux/fs_struct.hlinux/psp.hlinux/amd-iommu.hlinux/crash_dump.hasm/smp.hasm/cacheflush.hasm/e820/types.hasm/sev.hasm/msr.hpsp-dev.hsev-dev.h
Detected Declarations
struct snp_hv_fixed_pages_entrystruct cmd_buf_descenum snp_hv_fixed_pages_statefunction sev_version_greater_or_equalfunction sev_irq_handlerfunction sev_wait_cmd_iocfunction sev_cmd_buffer_lenfunction sev_read_init_ex_filefunction sev_write_init_ex_filefunction sev_write_init_ex_file_if_requiredfunction snp_reclaim_pagesfunction rmp_mark_pages_firmwarefunction __snp_free_firmware_pagesfunction snp_free_firmware_pagefunction snp_populate_cmd_buf_desc_listfunction snp_map_cmd_buf_descfunction snp_unmap_cmd_buf_descfunction snp_map_cmd_buf_desc_listfunction snp_unmap_cmd_buf_desc_listfunction sev_cmd_buf_writablefunction snp_legacy_handling_neededfunction snp_prep_cmd_buffunction snp_reclaim_cmd_buffunction __sev_do_cmd_lockedfunction sev_do_cmdfunction __sev_init_lockedfunction __sev_init_ex_lockedfunction __sev_do_init_lockedfunction snp_hv_fixed_pages_state_updatefunction snp_free_hv_fixed_pagesfunction list_for_each_entry_safefunction snp_add_hv_fixed_pagesfunction snp_leak_hv_fixed_pagesfunction list_for_each_entry_safefunction sev_is_snp_ciphertext_hiding_supportedfunction snp_get_platform_datafunction snp_filter_reserved_mem_regionsfunction __sev_snp_init_lockedfunction memoryfunction __sev_platform_init_handle_tmrfunction __sev_platform_init_handle_init_ex_pathfunction __sev_platform_init_lockedfunction _sev_platform_init_lockedfunction sev_platform_initfunction __sev_platform_shutdown_lockedfunction sev_get_platform_statefunction sev_move_to_init_statefunction sev_ioctl_do_reset
Annotated Snippet
static const struct file_operations sev_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = sev_ioctl,
};
int sev_platform_status(struct sev_user_data_status *data, int *error)
{
return sev_do_cmd(SEV_CMD_PLATFORM_STATUS, data, error);
}
EXPORT_SYMBOL_GPL(sev_platform_status);
int sev_guest_deactivate(struct sev_data_deactivate *data, int *error)
{
return sev_do_cmd(SEV_CMD_DEACTIVATE, data, error);
}
EXPORT_SYMBOL_GPL(sev_guest_deactivate);
int sev_guest_activate(struct sev_data_activate *data, int *error)
{
return sev_do_cmd(SEV_CMD_ACTIVATE, data, error);
}
EXPORT_SYMBOL_GPL(sev_guest_activate);
int sev_guest_decommission(struct sev_data_decommission *data, int *error)
{
return sev_do_cmd(SEV_CMD_DECOMMISSION, data, error);
}
EXPORT_SYMBOL_GPL(sev_guest_decommission);
int sev_guest_df_flush(int *error)
{
return sev_do_cmd(SEV_CMD_DF_FLUSH, NULL, error);
}
EXPORT_SYMBOL_GPL(sev_guest_df_flush);
static void sev_exit(struct kref *ref)
{
misc_deregister(&misc_dev->misc);
kfree(misc_dev);
misc_dev = NULL;
}
static int sev_misc_init(struct sev_device *sev)
{
struct device *dev = sev->dev;
int ret;
/*
* SEV feature support can be detected on multiple devices but the SEV
* FW commands must be issued on the master. During probe, we do not
* know the master hence we create /dev/sev on the first device probe.
* sev_do_cmd() finds the right master device to which to issue the
* command to the firmware.
*/
if (!misc_dev) {
struct miscdevice *misc;
misc_dev = kzalloc_obj(*misc_dev);
if (!misc_dev)
return -ENOMEM;
misc = &misc_dev->misc;
misc->minor = MISC_DYNAMIC_MINOR;
misc->name = DEVICE_NAME;
misc->fops = &sev_fops;
ret = misc_register(misc);
if (ret)
return ret;
kref_init(&misc_dev->refcount);
} else {
kref_get(&misc_dev->refcount);
}
init_waitqueue_head(&sev->int_queue);
sev->misc = misc_dev;
dev_dbg(dev, "registered SEV device\n");
return 0;
}
int sev_dev_init(struct psp_device *psp)
{
struct device *dev = psp->dev;
struct sev_device *sev;
int ret = -ENOMEM;
if (!boot_cpu_has(X86_FEATURE_SEV)) {
dev_info_once(dev, "SEV: memory encryption not enabled by BIOS\n");
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/module.h`, `linux/kernel.h`, `linux/kthread.h`, `linux/sched.h`, `linux/interrupt.h`, `linux/spinlock.h`, `linux/spinlock_types.h`.
- Detected declarations: `struct snp_hv_fixed_pages_entry`, `struct cmd_buf_desc`, `enum snp_hv_fixed_pages_state`, `function sev_version_greater_or_equal`, `function sev_irq_handler`, `function sev_wait_cmd_ioc`, `function sev_cmd_buffer_len`, `function sev_read_init_ex_file`, `function sev_write_init_ex_file`, `function sev_write_init_ex_file_if_required`.
- Atlas domain: Driver Families / drivers/crypto.
- 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.