Lines Matching defs:snp_dev

76 static bool is_vmpck_empty(struct snp_guest_dev *snp_dev)
80 if (snp_dev->vmpck)
81 return !memcmp(snp_dev->vmpck, zero_key, VMPCK_KEY_LEN);
103 static void snp_disable_vmpck(struct snp_guest_dev *snp_dev)
105 dev_alert(snp_dev->dev, "Disabling vmpck_id %d to prevent IV reuse.\n",
107 memzero_explicit(snp_dev->vmpck, VMPCK_KEY_LEN);
108 snp_dev->vmpck = NULL;
111 static inline u64 __snp_get_msg_seqno(struct snp_guest_dev *snp_dev)
118 count = *snp_dev->os_area_msg_seqno;
124 static u64 snp_get_msg_seqno(struct snp_guest_dev *snp_dev)
126 u64 count = __snp_get_msg_seqno(snp_dev);
137 dev_err(snp_dev->dev, "request message sequence counter overflow\n");
144 static void snp_inc_msg_seqno(struct snp_guest_dev *snp_dev)
150 *snp_dev->os_area_msg_seqno += 2;
160 static struct snp_guest_crypto *init_crypto(struct snp_guest_dev *snp_dev, u8 *key, size_t keylen)
182 dev_err(snp_dev->dev, "failed to set authsize to %d\n", MAX_AUTHTAG_LEN);
254 static int __enc_payload(struct snp_guest_dev *snp_dev, struct snp_guest_msg *msg,
257 struct snp_guest_crypto *crypto = snp_dev->crypto;
266 static int dec_payload(struct snp_guest_dev *snp_dev, struct snp_guest_msg *msg,
269 struct snp_guest_crypto *crypto = snp_dev->crypto;
279 static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload, u32 sz)
281 struct snp_guest_crypto *crypto = snp_dev->crypto;
282 struct snp_guest_msg *resp = &snp_dev->secret_response;
283 struct snp_guest_msg *req = &snp_dev->secret_request;
287 dev_dbg(snp_dev->dev, "response [seqno %lld type %d version %d sz %d]\n",
291 memcpy(resp, snp_dev->response, sizeof(*resp));
310 return dec_payload(snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len);
313 static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 type,
316 struct snp_guest_msg *req = &snp_dev->secret_request;
334 dev_dbg(snp_dev->dev, "request [seqno %lld type %d version %d sz %d]\n",
337 return __enc_payload(snp_dev, req, payload, sz);
340 static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code,
355 rc = snp_issue_guest_request(exit_code, &snp_dev->input, rio);
365 override_npages = snp_dev->input.data_npages;
405 snp_inc_msg_seqno(snp_dev);
421 snp_dev->input.data_npages = override_npages;
426 static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code,
435 seqno = snp_get_msg_seqno(snp_dev);
440 memset(snp_dev->response, 0, sizeof(struct snp_guest_msg));
442 /* Encrypt the userspace provided payload in snp_dev->secret_request. */
443 rc = enc_payload(snp_dev, seqno, rio->msg_version, type, req_buf, req_sz);
451 memcpy(snp_dev->request, &snp_dev->secret_request,
452 sizeof(snp_dev->secret_request));
454 rc = __handle_guest_request(snp_dev, exit_code, rio);
460 dev_alert(snp_dev->dev,
464 snp_disable_vmpck(snp_dev);
468 rc = verify_and_dec_payload(snp_dev, resp_buf, resp_sz);
470 dev_alert(snp_dev->dev, "Detected unexpected decode failure from ASP. rc: %d\n", rc);
471 snp_disable_vmpck(snp_dev);
478 static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg)
480 struct snp_guest_crypto *crypto = snp_dev->crypto;
481 struct snp_report_req *req = &snp_dev->req.report;
503 rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg,
517 static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg)
519 struct snp_derived_key_req *req = &snp_dev->req.derived_key;
520 struct snp_guest_crypto *crypto = snp_dev->crypto;
543 rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg,
558 static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioctl *arg)
560 struct snp_ext_report_req *req = &snp_dev->req.ext_report;
561 struct snp_guest_crypto *crypto = snp_dev->crypto;
590 memset(snp_dev->certs_data, 0, req->certs_len);
603 snp_dev->input.data_npages = npages;
604 ret = handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg,
610 req->certs_len = snp_dev->input.data_npages << PAGE_SHIFT;
620 copy_to_user((void __user *)req->certs_address, snp_dev->certs_data,
636 struct snp_guest_dev *snp_dev = to_snp_dev(file);
653 if (is_vmpck_empty(snp_dev)) {
654 dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n");
661 ret = get_report(snp_dev, &input);
664 ret = get_derived_key(snp_dev, &input);
667 ret = get_ext_report(snp_dev, &input);
756 struct snp_guest_dev *snp_dev;
775 snp_dev = devm_kzalloc(&pdev->dev, sizeof(struct snp_guest_dev), GFP_KERNEL);
776 if (!snp_dev)
780 snp_dev->vmpck = get_vmpck(vmpck_id, layout, &snp_dev->os_area_msg_seqno);
781 if (!snp_dev->vmpck) {
787 if (is_vmpck_empty(snp_dev)) {
792 platform_set_drvdata(pdev, snp_dev);
793 snp_dev->dev = dev;
794 snp_dev->layout = layout;
797 snp_dev->request = alloc_shared_pages(dev, sizeof(struct snp_guest_msg));
798 if (!snp_dev->request)
801 snp_dev->response = alloc_shared_pages(dev, sizeof(struct snp_guest_msg));
802 if (!snp_dev->response)
805 snp_dev->certs_data = alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE);
806 if (!snp_dev->certs_data)
810 snp_dev->crypto = init_crypto(snp_dev, snp_dev->vmpck, VMPCK_KEY_LEN);
811 if (!snp_dev->crypto)
814 misc = &snp_dev->misc;
820 snp_dev->input.req_gpa = __pa(snp_dev->request);
821 snp_dev->input.resp_gpa = __pa(snp_dev->response);
822 snp_dev->input.data_gpa = __pa(snp_dev->certs_data);
832 free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE);
834 free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg));
836 free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg));
844 struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev);
846 free_shared_pages(snp_dev->certs_data, SEV_FW_BLOB_MAX_SIZE);
847 free_shared_pages(snp_dev->response, sizeof(struct snp_guest_msg));
848 free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg));
849 deinit_crypto(snp_dev->crypto);
850 misc_deregister(&snp_dev->misc);