drivers/virt/coco/sev-guest/sev-guest.c
Source file repositories/reference/linux-study-clean/drivers/virt/coco/sev-guest/sev-guest.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/virt/coco/sev-guest/sev-guest.c- Extension
.c- Size
- 18661 bytes
- Lines
- 718
- Domain
- Driver Families
- Bucket
- drivers/virt
- 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.
- 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/module.hlinux/kernel.hlinux/types.hlinux/mutex.hlinux/io.hlinux/platform_device.hlinux/miscdevice.hlinux/set_memory.hlinux/fs.hlinux/tsm.hcrypto/gcm.hlinux/psp-sev.hlinux/sockptr.hlinux/cleanup.hlinux/uuid.hlinux/configfs.hlinux/mm.huapi/linux/sev-guest.huapi/linux/psp-sev.hasm/svm.hasm/sev.h
Detected Declarations
struct snp_guest_devstruct snp_req_respstruct snp_msg_report_resp_hdrstruct snp_msg_cert_entryfunction get_reportfunction get_derived_keyfunction get_ext_reportfunction snp_guest_ioctlfunction sev_svsm_report_newfunction sev_report_newfunction sev_report_attr_visiblefunction sev_report_bin_attr_visiblefunction unregister_sev_tsmfunction sev_guest_probefunction sev_guest_remove
Annotated Snippet
static const struct file_operations snp_guest_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = snp_guest_ioctl,
};
struct snp_msg_report_resp_hdr {
u32 status;
u32 report_size;
u8 rsvd[24];
};
struct snp_msg_cert_entry {
guid_t guid;
u32 offset;
u32 length;
};
static int sev_svsm_report_new(struct tsm_report *report, void *data)
{
unsigned int rep_len, man_len, certs_len;
struct tsm_report_desc *desc = &report->desc;
struct svsm_attest_call ac = {};
unsigned int retry_count;
void *rep, *man, *certs;
struct svsm_call call;
unsigned int size;
bool try_again;
void *buffer;
u64 call_id;
int ret;
/*
* Allocate pages for the request:
* - Report blob (4K)
* - Manifest blob (4K)
* - Certificate blob (16K)
*
* Above addresses must be 4K aligned
*/
rep_len = SZ_4K;
man_len = SZ_4K;
certs_len = SEV_FW_BLOB_MAX_SIZE;
if (guid_is_null(&desc->service_guid)) {
call_id = SVSM_ATTEST_CALL(SVSM_ATTEST_SERVICES);
} else {
export_guid(ac.service_guid, &desc->service_guid);
ac.service_manifest_ver = desc->service_manifest_version;
call_id = SVSM_ATTEST_CALL(SVSM_ATTEST_SINGLE_SERVICE);
}
retry_count = 0;
retry:
memset(&call, 0, sizeof(call));
size = rep_len + man_len + certs_len;
buffer = alloc_pages_exact(size, __GFP_ZERO);
if (!buffer)
return -ENOMEM;
rep = buffer;
ac.report_buf.pa = __pa(rep);
ac.report_buf.len = rep_len;
man = rep + rep_len;
ac.manifest_buf.pa = __pa(man);
ac.manifest_buf.len = man_len;
certs = man + man_len;
ac.certificates_buf.pa = __pa(certs);
ac.certificates_buf.len = certs_len;
ac.nonce.pa = __pa(desc->inblob);
ac.nonce.len = desc->inblob_len;
ret = snp_issue_svsm_attest_req(call_id, &call, &ac);
if (ret) {
free_pages_exact(buffer, size);
switch (call.rax_out) {
case SVSM_ERR_INVALID_PARAMETER:
try_again = false;
if (ac.report_buf.len > rep_len) {
rep_len = PAGE_ALIGN(ac.report_buf.len);
try_again = true;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/types.h`, `linux/mutex.h`, `linux/io.h`, `linux/platform_device.h`, `linux/miscdevice.h`, `linux/set_memory.h`.
- Detected declarations: `struct snp_guest_dev`, `struct snp_req_resp`, `struct snp_msg_report_resp_hdr`, `struct snp_msg_cert_entry`, `function get_report`, `function get_derived_key`, `function get_ext_report`, `function snp_guest_ioctl`, `function sev_svsm_report_new`, `function sev_report_new`.
- Atlas domain: Driver Families / drivers/virt.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.