1 // SPDX-License-Identifier: GPL-2.0-only
3 * AMD Secure Encrypted Virtualization (SEV) guest driver interface
5 * Copyright (C) 2021 Advanced Micro Devices, Inc.
7 * Author: Brijesh Singh <brijesh.singh@amd.com>
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/mutex.h>
15 #include <linux/platform_device.h>
16 #include <linux/miscdevice.h>
17 #include <linux/set_memory.h>
19 #include <crypto/aead.h>
20 #include <linux/scatterlist.h>
21 #include <linux/psp-sev.h>
22 #include <uapi/linux/sev-guest.h>
23 #include <uapi/linux/psp-sev.h>
28 #include "sev-guest.h"
30 #define DEVICE_NAME "sev-guest"
34 #define SNP_REQ_MAX_RETRY_DURATION (60*HZ)
35 #define SNP_REQ_RETRY_DELAY (2*HZ)
37 struct snp_guest_crypto {
38 struct crypto_aead *tfm;
43 struct snp_guest_dev {
45 struct miscdevice misc;
48 struct snp_guest_crypto *crypto;
49 /* request and response are in unencrypted memory */
50 struct snp_guest_msg *request, *response;
53 * Avoid information leakage by double-buffering shared messages
54 * in fields that are in regular encrypted memory.
56 struct snp_guest_msg secret_request, secret_response;
58 struct snp_secrets_page_layout *layout;
59 struct snp_req_data input;
60 u32 *os_area_msg_seqno;
65 module_param(vmpck_id, uint, 0444);
66 MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with the PSP.");
68 /* Mutex to serialize the shared buffer access and command handling. */
69 static DEFINE_MUTEX(snp_cmd_mutex);
71 static bool is_vmpck_empty(struct snp_guest_dev *snp_dev)
73 char zero_key[VMPCK_KEY_LEN] = {0};
76 return !memcmp(snp_dev->vmpck, zero_key, VMPCK_KEY_LEN);
82 * If an error is received from the host or AMD Secure Processor (ASP) there
83 * are two options. Either retry the exact same encrypted request or discontinue
86 * This is because in the current encryption scheme GHCB v2 uses AES-GCM to
87 * encrypt the requests. The IV for this scheme is the sequence number. GCM
88 * cannot tolerate IV reuse.
90 * The ASP FW v1.51 only increments the sequence numbers on a successful
91 * guest<->ASP back and forth and only accepts messages at its exact sequence
94 * So if the sequence number were to be reused the encryption scheme is
95 * vulnerable. If the sequence number were incremented for a fresh IV the ASP
96 * will reject the request.
98 static void snp_disable_vmpck(struct snp_guest_dev *snp_dev)
100 dev_alert(snp_dev->dev, "Disabling vmpck_id %d to prevent IV reuse.\n",
102 memzero_explicit(snp_dev->vmpck, VMPCK_KEY_LEN);
103 snp_dev->vmpck = NULL;
106 static inline u64 __snp_get_msg_seqno(struct snp_guest_dev *snp_dev)
110 lockdep_assert_held(&snp_cmd_mutex);
112 /* Read the current message sequence counter from secrets pages */
113 count = *snp_dev->os_area_msg_seqno;
118 /* Return a non-zero on success */
119 static u64 snp_get_msg_seqno(struct snp_guest_dev *snp_dev)
121 u64 count = __snp_get_msg_seqno(snp_dev);
124 * The message sequence counter for the SNP guest request is a 64-bit
125 * value but the version 2 of GHCB specification defines a 32-bit storage
126 * for it. If the counter exceeds the 32-bit value then return zero.
127 * The caller should check the return value, but if the caller happens to
128 * not check the value and use it, then the firmware treats zero as an
129 * invalid number and will fail the message request.
131 if (count >= UINT_MAX) {
132 dev_err(snp_dev->dev, "request message sequence counter overflow\n");
139 static void snp_inc_msg_seqno(struct snp_guest_dev *snp_dev)
142 * The counter is also incremented by the PSP, so increment it by 2
143 * and save in secrets page.
145 *snp_dev->os_area_msg_seqno += 2;
148 static inline struct snp_guest_dev *to_snp_dev(struct file *file)
150 struct miscdevice *dev = file->private_data;
152 return container_of(dev, struct snp_guest_dev, misc);
155 static struct snp_guest_crypto *init_crypto(struct snp_guest_dev *snp_dev, u8 *key, size_t keylen)
157 struct snp_guest_crypto *crypto;
159 crypto = kzalloc(sizeof(*crypto), GFP_KERNEL_ACCOUNT);
163 crypto->tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
164 if (IS_ERR(crypto->tfm))
167 if (crypto_aead_setkey(crypto->tfm, key, keylen))
170 crypto->iv_len = crypto_aead_ivsize(crypto->tfm);
171 crypto->iv = kmalloc(crypto->iv_len, GFP_KERNEL_ACCOUNT);
175 if (crypto_aead_authsize(crypto->tfm) > MAX_AUTHTAG_LEN) {
176 if (crypto_aead_setauthsize(crypto->tfm, MAX_AUTHTAG_LEN)) {
177 dev_err(snp_dev->dev, "failed to set authsize to %d\n", MAX_AUTHTAG_LEN);
182 crypto->a_len = crypto_aead_authsize(crypto->tfm);
183 crypto->authtag = kmalloc(crypto->a_len, GFP_KERNEL_ACCOUNT);
184 if (!crypto->authtag)
192 crypto_free_aead(crypto->tfm);
199 static void deinit_crypto(struct snp_guest_crypto *crypto)
201 crypto_free_aead(crypto->tfm);
203 kfree(crypto->authtag);
207 static int enc_dec_message(struct snp_guest_crypto *crypto, struct snp_guest_msg *msg,
208 u8 *src_buf, u8 *dst_buf, size_t len, bool enc)
210 struct snp_guest_msg_hdr *hdr = &msg->hdr;
211 struct scatterlist src[3], dst[3];
212 DECLARE_CRYPTO_WAIT(wait);
213 struct aead_request *req;
216 req = aead_request_alloc(crypto->tfm, GFP_KERNEL);
221 * AEAD memory operations:
222 * +------ AAD -------+------- DATA -----+---- AUTHTAG----+
223 * | msg header | plaintext | hdr->authtag |
224 * | bytes 30h - 5Fh | or | |
226 * +------------------+------------------+----------------+
228 sg_init_table(src, 3);
229 sg_set_buf(&src[0], &hdr->algo, AAD_LEN);
230 sg_set_buf(&src[1], src_buf, hdr->msg_sz);
231 sg_set_buf(&src[2], hdr->authtag, crypto->a_len);
233 sg_init_table(dst, 3);
234 sg_set_buf(&dst[0], &hdr->algo, AAD_LEN);
235 sg_set_buf(&dst[1], dst_buf, hdr->msg_sz);
236 sg_set_buf(&dst[2], hdr->authtag, crypto->a_len);
238 aead_request_set_ad(req, AAD_LEN);
239 aead_request_set_tfm(req, crypto->tfm);
240 aead_request_set_callback(req, 0, crypto_req_done, &wait);
242 aead_request_set_crypt(req, src, dst, len, crypto->iv);
243 ret = crypto_wait_req(enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req), &wait);
245 aead_request_free(req);
249 static int __enc_payload(struct snp_guest_dev *snp_dev, struct snp_guest_msg *msg,
250 void *plaintext, size_t len)
252 struct snp_guest_crypto *crypto = snp_dev->crypto;
253 struct snp_guest_msg_hdr *hdr = &msg->hdr;
255 memset(crypto->iv, 0, crypto->iv_len);
256 memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno));
258 return enc_dec_message(crypto, msg, plaintext, msg->payload, len, true);
261 static int dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_msg *msg,
262 void *plaintext, size_t len)
264 struct snp_guest_crypto *crypto = snp_dev->crypto;
265 struct snp_guest_msg_hdr *hdr = &msg->hdr;
267 /* Build IV with response buffer sequence number */
268 memset(crypto->iv, 0, crypto->iv_len);
269 memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno));
271 return enc_dec_message(crypto, msg, msg->payload, plaintext, len, false);
274 static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, u32 sz)
276 struct snp_guest_crypto *crypto = snp_dev->crypto;
277 struct snp_guest_msg *resp = &snp_dev->secret_response;
278 struct snp_guest_msg *req = &snp_dev->secret_request;
279 struct snp_guest_msg_hdr *req_hdr = &req->hdr;
280 struct snp_guest_msg_hdr *resp_hdr = &resp->hdr;
282 dev_dbg(snp_dev->dev, "response [seqno %lld type %d version %d sz %d]\n",
283 resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, resp_hdr->msg_sz);
285 /* Copy response from shared memory to encrypted memory. */
286 memcpy(resp, snp_dev->response, sizeof(*resp));
288 /* Verify that the sequence counter is incremented by 1 */
289 if (unlikely(resp_hdr->msg_seqno != (req_hdr->msg_seqno + 1)))
292 /* Verify response message type and version number. */
293 if (resp_hdr->msg_type != (req_hdr->msg_type + 1) ||
294 resp_hdr->msg_version != req_hdr->msg_version)
298 * If the message size is greater than our buffer length then return
301 if (unlikely((resp_hdr->msg_sz + crypto->a_len) > sz))
304 /* Decrypt the payload */
305 return dec_payload(snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len);
308 static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 type,
309 void *payload, size_t sz)
311 struct snp_guest_msg *req = &snp_dev->secret_request;
312 struct snp_guest_msg_hdr *hdr = &req->hdr;
314 memset(req, 0, sizeof(*req));
316 hdr->algo = SNP_AEAD_AES_256_GCM;
317 hdr->hdr_version = MSG_HDR_VER;
318 hdr->hdr_sz = sizeof(*hdr);
319 hdr->msg_type = type;
320 hdr->msg_version = version;
321 hdr->msg_seqno = seqno;
322 hdr->msg_vmpck = vmpck_id;
325 /* Verify the sequence number is non-zero */
329 dev_dbg(snp_dev->dev, "request [seqno %lld type %d version %d sz %d]\n",
330 hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz);
332 return __enc_payload(snp_dev, req, payload, sz);
335 static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code,
336 struct snp_guest_request_ioctl *rio)
338 unsigned long req_start = jiffies;
339 unsigned int override_npages = 0;
340 u64 override_err = 0;
345 * Call firmware to process the request. In this function the encrypted
346 * message enters shared memory with the host. So after this call the
347 * sequence number must be incremented or the VMPCK must be deleted to
348 * prevent reuse of the IV.
350 rc = snp_issue_guest_request(exit_code, &snp_dev->input, rio);
354 * If the extended guest request fails due to having too
355 * small of a certificate data buffer, retry the same
356 * guest request without the extended data request in
357 * order to increment the sequence number and thus avoid
360 override_npages = snp_dev->input.data_npages;
361 exit_code = SVM_VMGEXIT_GUEST_REQUEST;
364 * Override the error to inform callers the given extended
365 * request buffer size was too small and give the caller the
366 * required buffer size.
368 override_err = SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN);
371 * If this call to the firmware succeeds, the sequence number can
372 * be incremented allowing for continued use of the VMPCK. If
373 * there is an error reflected in the return value, this value
374 * is checked further down and the result will be the deletion
375 * of the VMPCK and the error code being propagated back to the
376 * user as an ioctl() return code.
381 * The host may return SNP_GUEST_VMM_ERR_BUSY if the request has been
382 * throttled. Retry in the driver to avoid returning and reusing the
383 * message sequence number on a different message.
386 if (jiffies - req_start > SNP_REQ_MAX_RETRY_DURATION) {
390 schedule_timeout_killable(SNP_REQ_RETRY_DELAY);
395 * Increment the message sequence number. There is no harm in doing
396 * this now because decryption uses the value stored in the response
397 * structure and any failure will wipe the VMPCK, preventing further
400 snp_inc_msg_seqno(snp_dev);
403 rio->exitinfo2 = override_err;
406 * If an extended guest request was issued and the supplied certificate
407 * buffer was not large enough, a standard guest request was issued to
408 * prevent IV reuse. If the standard request was successful, return -EIO
409 * back to the caller as would have originally been returned.
411 if (!rc && override_err == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN))
416 snp_dev->input.data_npages = override_npages;
421 static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code,
422 struct snp_guest_request_ioctl *rio, u8 type,
423 void *req_buf, size_t req_sz, void *resp_buf,
429 /* Get message sequence and verify that its a non-zero */
430 seqno = snp_get_msg_seqno(snp_dev);
434 /* Clear shared memory's response for the host to populate. */
435 memset(snp_dev->response, 0, sizeof(struct snp_guest_msg));
437 /* Encrypt the userspace provided payload in snp_dev->secret_request. */
438 rc = enc_payload(snp_dev, seqno, rio->msg_version, type, req_buf, req_sz);
443 * Write the fully encrypted request to the shared unencrypted
446 memcpy(snp_dev->request, &snp_dev->secret_request,
447 sizeof(snp_dev->secret_request));
449 rc = __handle_guest_request(snp_dev, exit_code, rio);
452 rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN))
455 dev_alert(snp_dev->dev,
456 "Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n",
459 snp_disable_vmpck(snp_dev);
463 rc = verify_and_dec_payload(snp_dev, resp_buf, resp_sz);
465 dev_alert(snp_dev->dev, "Detected unexpected decode failure from ASP. rc: %d\n", rc);
466 snp_disable_vmpck(snp_dev);
473 static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg)
475 struct snp_guest_crypto *crypto = snp_dev->crypto;
476 struct snp_report_resp *resp;
477 struct snp_report_req req;
480 lockdep_assert_held(&snp_cmd_mutex);
482 if (!arg->req_data || !arg->resp_data)
485 if (copy_from_user(&req, (void __user *)arg->req_data, sizeof(req)))
489 * The intermediate response buffer is used while decrypting the
490 * response payload. Make sure that it has enough space to cover the
493 resp_len = sizeof(resp->data) + crypto->a_len;
494 resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT);
498 rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg,
499 SNP_MSG_REPORT_REQ, &req, sizeof(req), resp->data,
504 if (copy_to_user((void __user *)arg->resp_data, resp, sizeof(*resp)))
512 static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg)
514 struct snp_guest_crypto *crypto = snp_dev->crypto;
515 struct snp_derived_key_resp resp = {0};
516 struct snp_derived_key_req req;
518 /* Response data is 64 bytes and max authsize for GCM is 16 bytes. */
521 lockdep_assert_held(&snp_cmd_mutex);
523 if (!arg->req_data || !arg->resp_data)
527 * The intermediate response buffer is used while decrypting the
528 * response payload. Make sure that it has enough space to cover the
531 resp_len = sizeof(resp.data) + crypto->a_len;
532 if (sizeof(buf) < resp_len)
535 if (copy_from_user(&req, (void __user *)arg->req_data, sizeof(req)))
538 rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg,
539 SNP_MSG_KEY_REQ, &req, sizeof(req), buf, resp_len);
543 memcpy(resp.data, buf, sizeof(resp.data));
544 if (copy_to_user((void __user *)arg->resp_data, &resp, sizeof(resp)))
547 /* The response buffer contains the sensitive data, explicitly clear it. */
548 memzero_explicit(buf, sizeof(buf));
549 memzero_explicit(&resp, sizeof(resp));
553 static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg)
555 struct snp_guest_crypto *crypto = snp_dev->crypto;
556 struct snp_ext_report_req req;
557 struct snp_report_resp *resp;
558 int ret, npages = 0, resp_len;
560 lockdep_assert_held(&snp_cmd_mutex);
562 if (!arg->req_data || !arg->resp_data)
565 if (copy_from_user(&req, (void __user *)arg->req_data, sizeof(req)))
568 /* userspace does not want certificate data */
569 if (!req.certs_len || !req.certs_address)
572 if (req.certs_len > SEV_FW_BLOB_MAX_SIZE ||
573 !IS_ALIGNED(req.certs_len, PAGE_SIZE))
576 if (!access_ok((const void __user *)req.certs_address, req.certs_len))
580 * Initialize the intermediate buffer with all zeros. This buffer
581 * is used in the guest request message to get the certs blob from
582 * the host. If host does not supply any certs in it, then copy
583 * zeros to indicate that certificate data was not provided.
585 memset(snp_dev->certs_data, 0, req.certs_len);
586 npages = req.certs_len >> PAGE_SHIFT;
589 * The intermediate response buffer is used while decrypting the
590 * response payload. Make sure that it has enough space to cover the
593 resp_len = sizeof(resp->data) + crypto->a_len;
594 resp = kzalloc(resp_len, GFP_KERNEL_ACCOUNT);
598 snp_dev->input.data_npages = npages;
599 ret = handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg,
600 SNP_MSG_REPORT_REQ, &req.data,
601 sizeof(req.data), resp->data, resp_len);
603 /* If certs length is invalid then copy the returned length */
604 if (arg->vmm_error == SNP_GUEST_VMM_ERR_INVALID_LEN) {
605 req.certs_len = snp_dev->input.data_npages << PAGE_SHIFT;
607 if (copy_to_user((void __user *)arg->req_data, &req, sizeof(req)))
615 copy_to_user((void __user *)req.certs_address, snp_dev->certs_data,
621 if (copy_to_user((void __user *)arg->resp_data, resp, sizeof(*resp)))
629 static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
631 struct snp_guest_dev *snp_dev = to_snp_dev(file);
632 void __user *argp = (void __user *)arg;
633 struct snp_guest_request_ioctl input;
636 if (copy_from_user(&input, argp, sizeof(input)))
639 input.exitinfo2 = 0xff;
641 /* Message version must be non-zero */
642 if (!input.msg_version)
645 mutex_lock(&snp_cmd_mutex);
647 /* Check if the VMPCK is not empty */
648 if (is_vmpck_empty(snp_dev)) {
649 dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n");
650 mutex_unlock(&snp_cmd_mutex);
656 ret = get_report(snp_dev, &input);
658 case SNP_GET_DERIVED_KEY:
659 ret = get_derived_key(snp_dev, &input);
661 case SNP_GET_EXT_REPORT:
662 ret = get_ext_report(snp_dev, &input);
668 mutex_unlock(&snp_cmd_mutex);
670 if (input.exitinfo2 && copy_to_user(argp, &input, sizeof(input)))
676 static void free_shared_pages(void *buf, size_t sz)
678 unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT;
684 ret = set_memory_encrypted((unsigned long)buf, npages);
686 WARN_ONCE(ret, "failed to restore encryption mask (leak it)\n");
690 __free_pages(virt_to_page(buf), get_order(sz));
693 static void *alloc_shared_pages(struct device *dev, size_t sz)
695 unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT;
699 page = alloc_pages(GFP_KERNEL_ACCOUNT, get_order(sz));
703 ret = set_memory_decrypted((unsigned long)page_address(page), npages);
705 dev_err(dev, "failed to mark page shared, ret=%d\n", ret);
706 __free_pages(page, get_order(sz));
710 return page_address(page);
713 static const struct file_operations snp_guest_fops = {
714 .owner = THIS_MODULE,
715 .unlocked_ioctl = snp_guest_ioctl,
718 static u8 *get_vmpck(int id, struct snp_secrets_page_layout *layout, u32 **seqno)
724 *seqno = &layout->os_area.msg_seqno_0;
725 key = layout->vmpck0;
728 *seqno = &layout->os_area.msg_seqno_1;
729 key = layout->vmpck1;
732 *seqno = &layout->os_area.msg_seqno_2;
733 key = layout->vmpck2;
736 *seqno = &layout->os_area.msg_seqno_3;
737 key = layout->vmpck3;
746 static int __init sev_guest_probe(struct platform_device *pdev)
748 struct snp_secrets_page_layout *layout;
749 struct sev_guest_platform_data *data;
750 struct device *dev = &pdev->dev;
751 struct snp_guest_dev *snp_dev;
752 struct miscdevice *misc;
753 void __iomem *mapping;
756 if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
759 if (!dev->platform_data)
762 data = (struct sev_guest_platform_data *)dev->platform_data;
763 mapping = ioremap_encrypted(data->secrets_gpa, PAGE_SIZE);
767 layout = (__force void *)mapping;
770 snp_dev = devm_kzalloc(&pdev->dev, sizeof(struct snp_guest_dev), GFP_KERNEL);
775 snp_dev->vmpck = get_vmpck(vmpck_id, layout, &snp_dev->os_area_msg_seqno);
776 if (!snp_dev->vmpck) {
777 dev_err(dev, "invalid vmpck id %d\n", vmpck_id);
781 /* Verify that VMPCK is not zero. */
782 if (is_vmpck_empty(snp_dev)) {
783 dev_err(dev, "vmpck id %d is null\n", vmpck_id);
787 platform_set_drvdata(pdev, snp_dev);
789 snp_dev->layout = layout;
791 /* Allocate the shared page used for the request and response message. */
792 snp_dev->request = alloc_shared_pages(dev, sizeof(struct snp_guest_msg));
793 if (!snp_dev->request)
796 snp_dev->response = alloc_shared_pages(dev, sizeof(struct snp_guest_msg));
797 if (!snp_dev->response)
800 snp_dev->certs_data = alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE);
801 if (!snp_dev->certs_data)
802 goto e_free_response;
805 snp_dev->crypto = init_crypto(snp_dev, snp_dev->vmpck, VMPCK_KEY_LEN);
806 if (!snp_dev->crypto)
807 goto e_free_cert_data;
809 misc = &snp_dev->misc;
810 misc->minor = MISC_DYNAMIC_MINOR;
811 misc->name = DEVICE_NAME;
812 misc->fops = &snp_guest_fops;
814 /* initial the input address for guest request */
815 snp_dev->input.req_gpa = __pa(snp_dev->request);
816 snp_dev->input.resp_gpa = __pa(snp_dev->response);
817 snp_dev->input.data_gpa = __pa(snp_dev->certs_data);
819 ret = misc_register(misc);
821 goto e_free_cert_data;
823 dev_info(dev, "Initialized SEV guest driver (using vmpck_id %d)\n", vmpck_id);
827 free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE);
829 free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg));
831 free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg));
837 static int __exit sev_guest_remove(struct platform_device *pdev)
839 struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev);
841 free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE);
842 free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg));
843 free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg));
844 deinit_crypto(snp_dev->crypto);
845 misc_deregister(&snp_dev->misc);
851 * This driver is meant to be a common SEV guest interface driver and to
852 * support any SEV guest API. As such, even though it has been introduced
853 * with the SEV-SNP support, it is named "sev-guest".
855 static struct platform_driver sev_guest_driver = {
856 .remove = __exit_p(sev_guest_remove),
862 module_platform_driver_probe(sev_guest_driver, sev_guest_probe);
864 MODULE_AUTHOR("Brijesh Singh <brijesh.singh@amd.com>");
865 MODULE_LICENSE("GPL");
866 MODULE_VERSION("1.0.0");
867 MODULE_DESCRIPTION("AMD SEV Guest Driver");
868 MODULE_ALIAS("platform:sev-guest");