FAILED: patch "[PATCH] virt: sev-guest: Move SNP Guest Request data pages handling" failed to apply to 6.13-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.13-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.13.y
git checkout FETCH_HEAD
git cherry-pick -x 3e385c0d6ce88ac9916dcf84267bd5855d830748
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025030957-magnetism-lustily-55d9@gregkh' --subject-prefix 'PATCH 6.13.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 3e385c0d6ce88ac9916dcf84267bd5855d830748 Mon Sep 17 00:00:00 2001
From: Alexey Kardashevskiy <[email protected]>
Date: Fri, 7 Mar 2025 12:37:00 +1100
Subject: [PATCH] virt: sev-guest: Move SNP Guest Request data pages handling
under snp_cmd_mutex
Compared to the SNP Guest Request, the "Extended" version adds data pages for receiving certificates. If not enough pages provided, the HV can report to the VM how much is needed so the VM can reallocate and repeat.
Commit
ae596615d93d ("virt: sev-guest: Reduce the scope of SNP command mutex")
moved handling of the allocated/desired pages number out of scope of said mutex and create a possibility for a race (multiple instances trying to trigger Extended request in a VM) as there is just one instance of snp_msg_desc per /dev/sev-guest and no locking other than snp_cmd_mutex.
Fix the issue by moving the data blob/size and the GHCB input struct (snp_req_data) into snp_guest_req which is allocated on stack now and accessed by the GHCB caller under that mutex.
Stop allocating SEV_FW_BLOB_MAX_SIZE in snp_msg_alloc() as only one of four callers needs it. Free the received blob in get_ext_report() right after it is copied to the userspace. Possible future users of snp_send_guest_request() are likely to have different ideas about the buffer size anyways.
arch/x86/coco/sev/core.c +8 -15
@@ -2853,19 +2853,8 @@ struct snp_msg_desc *snp_msg_alloc(void)if (!mdesc->response) goto e_free_request; - mdesc->certs_data =alloc_shared_pages (SEV_FW_BLOB_MAX_SIZE ); -if (!mdesc->certs_data) - goto e_free_response; - -/* initial the input address for guest request */ - mdesc->input.req_gpa =__pa (mdesc->request); - mdesc->input.resp_gpa =__pa (mdesc->response); - mdesc->input.data_gpa =__pa (mdesc->certs_data); -return mdesc; -e_free_response: -free_shared_pages (mdesc->response,sizeof (struct snp_guest_msg )); e_free_request:free_shared_pages (mdesc->request,sizeof (struct snp_guest_msg )); e_unmap:
@@ -2885,7 +2874,6 @@ void snp_msg_free(struct snp_msg_desc *mdesc)kfree (mdesc->ctx);free_shared_pages (mdesc->response,sizeof (struct snp_guest_msg ));free_shared_pages (mdesc->request,sizeof (struct snp_guest_msg )); -free_shared_pages (mdesc->certs_data,SEV_FW_BLOB_MAX_SIZE );iounmap ((__force void __iomem *)mdesc->secrets);memset (mdesc,0 ,sizeof (*mdesc));
@@ -3054,7 +3042,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r* sequence number must be incremented or the VMPCK must be deleted to * prevent reuse of the IV. */ - rc =snp_issue_guest_request (req, &mdesc->input, rio); + rc =snp_issue_guest_request (req, &req->input, rio);switch (rc) {case -ENOSPC :/*
@@ -3064,7 +3052,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r* order to increment the sequence number and thus avoid * IV reuse. */ - override_npages = mdesc->input.data_npages; + override_npages = req->input.data_npages; req->exit_code =SVM_VMGEXIT_GUEST_REQUEST ;/*
@@ -3120,7 +3108,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r }if (override_npages) - mdesc->input.data_npages = override_npages; + req->input.data_npages = override_npages;return rc; }
@@ -3158,6 +3146,11 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req*/ memcpy (mdesc->request, &mdesc->secret_request,sizeof (mdesc->secret_request)); +/* Initialize the input address for guest request */ + req->input.req_gpa =__pa (mdesc->request); + req->input.resp_gpa =__pa (mdesc->response); + req->input.data_gpa = req->certs_data ?__pa (req->certs_data) :0 ; + rc =__handle_guest_request (mdesc, req, rio);if (rc) { if (rc == -EIO &&
arch/x86/include/asm/sev.h +3 -3
@@ -203,6 +203,9 @@ struct snp_guest_req {unsigned int vmpck_id;u8 msg_version;u8 msg_type; + +struct snp_req_data input; +void *certs_data; };/*
@@ -263,9 +266,6 @@ struct snp_msg_desc {struct snp_guest_msg secret_request, secret_response;struct snp_secrets_page *secrets; -struct snp_req_data input; - -void *certs_data;struct aesgcm_ctx *ctx;
drivers/virt/coco/sev-guest/sev-guest.c +28 -6
@@ -176,6 +176,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_requesstruct snp_guest_req req = {};int ret, npages =0 , resp_len;sockptr_t certs_address; +struct page *page;if (sockptr_is_null (io->req_data) ||sockptr_is_null (io->resp_data))return -EINVAL ;
@@ -209,8 +210,20 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques* the host. If host does not supply any certs in it, then copy * zeros to indicate that certificate data was not provided. */ -memset (mdesc->certs_data,0 , report_req->certs_len); npages = report_req->certs_len >>PAGE_SHIFT ; + page =alloc_pages (GFP_KERNEL_ACCOUNT | __GFP_ZERO, +get_order (report_req->certs_len)); +if (!page) +return -ENOMEM ; + + req.certs_data =page_address (page); + ret =set_memory_decrypted ((unsigned long )req.certs_data, npages); +if (ret) { +pr_err ("failed to mark page shared, ret=%d\n" , ret); +__free_pages (page,get_order (report_req->certs_len)); +return -EFAULT ; + } + cmd:/* * The intermediate response buffer is used while decrypting the
@@ -219,10 +232,12 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques*/ resp_len =sizeof (report_resp->data) + mdesc->ctx->authsize; report_resp =kzalloc (resp_len,GFP_KERNEL_ACCOUNT ); -if (!report_resp) -return -ENOMEM ; +if (!report_resp) { + ret = -ENOMEM ; + goto e_free_data; + } - mdesc->input.data_npages = npages; + req.input.data_npages = npages; req.msg_version = arg->msg_version; req.msg_type =SNP_MSG_REPORT_REQ ;
@@ -237,7 +252,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques/* If certs length is invalid then copy the returned length */ if (arg->vmm_error ==SNP_GUEST_VMM_ERR_INVALID_LEN ) { - report_req->certs_len = mdesc->input.data_npages <<PAGE_SHIFT ; + report_req->certs_len = req.input.data_npages <<PAGE_SHIFT ;if (copy_to_sockptr (io->req_data, report_req,sizeof (*report_req))) ret = -EFAULT ;
@@ -246,7 +261,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_requesif (ret) goto e_free; -if (npages &©_to_sockptr (certs_address, mdesc->certs_data, report_req->certs_len)) { +if (npages &©_to_sockptr (certs_address, req.certs_data, report_req->certs_len)) { ret = -EFAULT ; goto e_free; }
@@ -256,6 +271,13 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques e_free:kfree (report_resp); +e_free_data: +if (npages) { +if (set_memory_encrypted ((unsigned long )req.certs_data, npages)) +WARN_ONCE (ret,"failed to restore encryption mask (leak it)\n" ); +else +__free_pages (page,get_order (report_req->certs_len)); + }return ret; }
PATCH 1/1 virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
Compared to the SNP Guest Request, the "Extended" version adds data pages for receiving certificates. If not enough pages provided, the HV can report to the VM how much is needed so the VM can reallocate and repeat.
Commit ae596615d93d ("virt: sev-guest: Reduce the scope of SNP command mutex") moved handling of the allocated/desired pages number out of scope of said mutex and create a possibility for a race (multiple instances trying to trigger Extended request in a VM) as there is just one instance of snp_msg_desc per /dev/sev-guest and no locking other than snp_cmd_mutex.
Fix the issue by moving the data blob/size and the GHCB input struct (snp_req_data) into snp_guest_req which is allocated on stack now and accessed by the GHCB caller under that mutex.
Stop allocating SEV_FW_BLOB_MAX_SIZE in snp_msg_alloc() as only one of four callers needs it. Free the received blob in get_ext_report() right after it is copied to the userspace. Possible future users of snp_send_guest_request() are likely to have different ideas about the buffer size anyways.
--- arch/x86/include/asm/sev.h | 6 +-- drivers/virt/coco/sev-guest/sev-guest.c | 63 +++++++++++++++---------- 2 files changed, 42 insertions(+), 27 deletions(-)
arch/x86/include/asm/sev.h +3 -3
@@ -185,6 +185,9 @@ struct snp_guest_req {unsigned int vmpck_id;u8 msg_version;u8 msg_type; + +struct snp_req_data input; +void *certs_data; };/*
@@ -245,9 +248,6 @@ struct snp_msg_desc {struct snp_guest_msg secret_request, secret_response;struct snp_secrets_page *secrets; -struct snp_req_data input; - -void *certs_data;struct aesgcm_ctx *ctx;
drivers/virt/coco/sev-guest/sev-guest.c +39 -24
160 lines not on this page · raw message
Signature · 1 line
2.47.1
Re: [PATCH 6.13.y] virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
Quoted 20 lines · Alexey Kardashevskiy
Compared to the SNP Guest Request, the "Extended" version adds data pages for receiving certificates. If not enough pages provided, the HV can report to the VM how much is needed so the VM can reallocate and repeat.
Commit
ae596615d93d("virt: sev-guest: Reduce the scope of SNP command mutex") moved handling of the allocated/desired pages number out of scope of said mutex and create a possibility for a race (multiple instances trying to trigger Extended request in a VM) as there is just one instance ofsnp_msg_descper/dev/sev-guestand no locking other thansnp_cmd_mutex.Fix the issue by moving the data blob/size and the GHCB input struct (
snp_req_data) intosnp_guest_reqwhich is allocated on stack now and accessed by the GHCB caller under that mutex.Stop allocating
SEV_FW_BLOB_MAX_SIZEinsnp_msg_alloc()as only one of four callers needs it. Free the received blob inget_ext_report()right after it is copied to the userspace. Possible future users ofsnp_send_guest_request()are likely to have different ideas about the buffer size anyways.
Quoted 4 lines
Fixes ae596615d93d ("virt: sev-guest: Reduce the scope of SNP command mutex")Cc [email protected] # 6.13Cc Nikunj A Dadhania <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>
Missed:
(cherry picked from commit 3e385c0d6ce88ac9916dcf84267bd5855d830748)
I first cherrypicked and sent, then I read about "cherry-oick -x", sorry for the noise. thanks,
Quoted 206 lines
--- arch/x86/include/asm/sev.h | 6 +-- drivers/virt/coco/sev-guest/sev-guest.c | 63 +++++++++++++++---------- 2 files changed, 42 insertions(+), 27 deletions(-)arch/x86/include/asm/sev.h +3
-3@@ -185,6 +185,9 @@ struct snp_guest_req {unsigned int vmpck_id;u8 msg_version;u8 msg_type; + +struct snp_req_data input; +void *certs_data; };/* @@ -245,9 +248,6 @@ struct snp_msg_desc {struct snp_guest_msg secret_request, secret_response;struct snp_secrets_page *secrets; -struct snp_req_data input; - -void *certs_data;struct aesgcm_ctx *ctx;drivers/virt/coco/sev-guest/sev-guest.c +39
-24@@ -249,7 +249,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r* sequence number must be incremented or the VMPCK must be deleted to * prevent reuse of the IV. */ - rc =snp_issue_guest_request (req, &mdesc->input, rio); + rc =snp_issue_guest_request (req, &req->input, rio);switch (rc) {case -ENOSPC :/* @@ -259,7 +259,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r* order to increment the sequence number and thus avoid * IV reuse. */ - override_npages = mdesc->input.data_npages; + override_npages = req->input.data_npages; req->exit_code =SVM_VMGEXIT_GUEST_REQUEST ;/* @@ -315,7 +315,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r }if (override_npages) - mdesc->input.data_npages = override_npages; + req->input.data_npages = override_npages;return rc; }@@ -354,6 +354,11 @@ static int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_rmemcpy (mdesc->request, &mdesc->secret_request,sizeof (mdesc->secret_request)); +/* initial the input address for guest request */ + req->input.req_gpa =__pa (mdesc->request); + req->input.resp_gpa =__pa (mdesc->response); + req->input.data_gpa = req->certs_data ?__pa (req->certs_data) :0 ; + rc =__handle_guest_request (mdesc, req, rio);if (rc) { if (rc == -EIO &&@@ -495,6 +500,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_requesstruct snp_guest_req req = {};int ret, npages =0 , resp_len;sockptr_t certs_address; +struct page *page;if (sockptr_is_null (io->req_data) ||sockptr_is_null (io->resp_data))return -EINVAL ;@@ -528,8 +534,20 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques* the host. If host does not supply any certs in it, then copy * zeros to indicate that certificate data was not provided. */ -memset (mdesc->certs_data,0 , report_req->certs_len); npages = report_req->certs_len >>PAGE_SHIFT ; + page =alloc_pages (GFP_KERNEL_ACCOUNT | __GFP_ZERO, +get_order (report_req->certs_len)); +if (!page) +return -ENOMEM ; + + req.certs_data =page_address (page); + ret =set_memory_decrypted ((unsigned long )req.certs_data, npages); +if (ret) { +pr_err ("failed to mark page shared, ret=%d\n" , ret); +__free_pages (page,get_order (report_req->certs_len)); +return -EFAULT ; + } + cmd:/* * The intermediate response buffer is used while decrypting the @@ -538,10 +556,12 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques*/ resp_len =sizeof (report_resp->data) + mdesc->ctx->authsize; report_resp =kzalloc (resp_len,GFP_KERNEL_ACCOUNT ); -if (!report_resp) -return -ENOMEM ; +if (!report_resp) { + ret = -ENOMEM ; + goto e_free_data; + } - mdesc->input.data_npages = npages; + req.input.data_npages = npages; req.msg_version = arg->msg_version; req.msg_type =SNP_MSG_REPORT_REQ ;@@ -556,7 +576,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques/* If certs length is invalid then copy the returned length */ if (arg->vmm_error ==SNP_GUEST_VMM_ERR_INVALID_LEN ) { - report_req->certs_len = mdesc->input.data_npages <<PAGE_SHIFT ; + report_req->certs_len = req.input.data_npages <<PAGE_SHIFT ;if (copy_to_sockptr (io->req_data, report_req,sizeof (*report_req))) ret = -EFAULT ;@@ -565,7 +585,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_requesif (ret) goto e_free; -if (npages &©_to_sockptr (certs_address, mdesc->certs_data, report_req->certs_len)) { +if (npages &©_to_sockptr (certs_address, req.certs_data, report_req->certs_len)) { ret = -EFAULT ; goto e_free; }@@ -575,6 +595,13 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques e_free:kfree (report_resp); +e_free_data: +if (npages) { +if (set_memory_encrypted ((unsigned long )req.certs_data, npages)) +WARN_ONCE (ret,"failed to restore encryption mask (leak it)\n" ); +else +__free_pages (page,get_order (report_req->certs_len)); + }return ret; }@@ -1048,35 +1075,26 @@ static int __init sev_guest_probe(struct platform_device *pdev)if (!mdesc->response) goto e_free_request; - mdesc->certs_data =alloc_shared_pages (dev,SEV_FW_BLOB_MAX_SIZE ); -if (!mdesc->certs_data) - goto e_free_response; - ret = -EIO ; mdesc->ctx =snp_init_crypto (mdesc->vmpck,VMPCK_KEY_LEN );if (!mdesc->ctx) - goto e_free_cert_data; + goto e_free_response; misc = &snp_dev->misc; misc->minor =MISC_DYNAMIC_MINOR ; misc->name =DEVICE_NAME ; misc->fops = &snp_guest_fops; -/* Initialize the input addresses for guest request */ - mdesc->input.req_gpa =__pa (mdesc->request); - mdesc->input.resp_gpa =__pa (mdesc->response); - mdesc->input.data_gpa =__pa (mdesc->certs_data); -/* Set the privlevel_floor attribute based on the vmpck_id */ sev_tsm_ops.privlevel_floor = vmpck_id; ret =tsm_register (&sev_tsm_ops, snp_dev);if (ret) - goto e_free_cert_data; + goto e_free_response; ret =devm_add_action_or_reset (&pdev->dev, unregister_sev_tsm,NULL );if (ret) - goto e_free_cert_data; + goto e_free_response; ret =misc_register (misc);if (ret)@@ -1088,8 +1106,6 @@ static int __init sev_guest_probe(struct platform_device *pdev) e_free_ctx:kfree (mdesc->ctx); -e_free_cert_data: -free_shared_pages (mdesc->certs_data,SEV_FW_BLOB_MAX_SIZE ); e_free_response:free_shared_pages (mdesc->response,sizeof (struct snp_guest_msg )); e_free_request:@@ -1104,7 +1120,6 @@ static void __exit sev_guest_remove(struct platform_device *pdev)struct snp_guest_dev *snp_dev =platform_get_drvdata (pdev);struct snp_msg_desc *mdesc = snp_dev->msg_desc; -free_shared_pages (mdesc->certs_data,SEV_FW_BLOB_MAX_SIZE );free_shared_pages (mdesc->response,sizeof (struct snp_guest_msg ));free_shared_pages (mdesc->request,sizeof (struct snp_guest_msg ));kfree (mdesc->ctx);
Signature · 1 line
Alexey
Greg KH
maintainerRe: [PATCH 6.13.y] virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
Quoted 28 lines · Alexey Kardashevskiy
Quoted 20 lines · Alexey Kardashevskiy
Compared to the SNP Guest Request, the "Extended" version adds data pages for receiving certificates. If not enough pages provided, the HV can report to the VM how much is needed so the VM can reallocate and repeat.
Commit
ae596615d93d("virt: sev-guest: Reduce the scope of SNP command mutex") moved handling of the allocated/desired pages number out of scope of said mutex and create a possibility for a race (multiple instances trying to trigger Extended request in a VM) as there is just one instance ofsnp_msg_descper/dev/sev-guestand no locking other thansnp_cmd_mutex.Fix the issue by moving the data blob/size and the GHCB input struct (
snp_req_data) intosnp_guest_reqwhich is allocated on stack now and accessed by the GHCB caller under that mutex.Stop allocating
SEV_FW_BLOB_MAX_SIZEinsnp_msg_alloc()as only one of four callers needs it. Free the received blob inget_ext_report()right after it is copied to the userspace. Possible future users ofsnp_send_guest_request()are likely to have different ideas about the buffer size anyways.Quoted 4 lines
Fixes ae596615d93d ("virt: sev-guest: Reduce the scope of SNP command mutex")Cc [email protected] # 6.13Cc Nikunj A Dadhania <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>
Quoted 6 lines
Missed:
(cherry picked from commit
3e385c0d6ce88ac9916dcf84267bd5855d830748)I first cherrypicked and sent, then I read about "cherry-oick -x", sorry for the noise. thanks,
Please resend with this in the commit so that our tools pick it up properly.
thanks,
greg k-h
Sasha Levin
maintainerRe: [PATCH 6.13.y] virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
In reply to Alexey Kardashevskiy[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to it
Found matching upstream commit: 3e385c0d6ce88ac9916dcf84267bd5855d830748
Note: The patch differs from the upstream commit:
---
1: 3e385c0d6ce88 ! 1: a6b033d98441d virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
@@ Metadata
## Commit message ##
virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
- Compared to the SNP Guest Request, the "Extended" version adds data pages for
- receiving certificates. If not enough pages provided, the HV can report to the
- VM how much is needed so the VM can reallocate and repeat.
+ Compared to the SNP Guest Request, the "Extended" version adds data pages
+ for receiving certificates. If not enough pages provided, the HV can
+ report to the VM how much is needed so the VM can reallocate and repeat.
- Commit
-
- ae596615d93d ("virt: sev-guest: Reduce the scope of SNP command mutex")
-
- moved handling of the allocated/desired pages number out of scope of said
- mutex and create a possibility for a race (multiple instances trying to
- trigger Extended request in a VM) as there is just one instance of
- snp_msg_desc per /dev/sev-guest and no locking other than snp_cmd_mutex.
+ Commit ae596615d93d ("virt: sev-guest: Reduce the scope of SNP command
+ mutex") moved handling of the allocated/desired pages number out of scope
+ of said mutex and create a possibility for a race (multiple instances
+ trying to trigger Extended request in a VM) as there is just one instance
+ of snp_msg_desc per /dev/sev-guest and no locking other than snp_cmd_mutex.
Fix the issue by moving the data blob/size and the GHCB input struct
- (snp_req_data) into snp_guest_req which is allocated on stack now and accessed
- by the GHCB caller under that mutex.
+ (snp_req_data) into snp_guest_req which is allocated on stack now
+ and accessed by the GHCB caller under that mutex.
- Stop allocating SEV_FW_BLOB_MAX_SIZE in snp_msg_alloc() as only one of four
- callers needs it. Free the received blob in get_ext_report() right after it is
- copied to the userspace. Possible future users of snp_send_guest_request() are
- likely to have different ideas about the buffer size anyways.
+ Stop allocating SEV_FW_BLOB_MAX_SIZE in snp_msg_alloc() as only one of
+ four callers needs it. Free the received blob in get_ext_report() right
+ after it is copied to the userspace. Possible future users of
+ snp_send_guest_request() are likely to have different ideas about
+ the buffer size anyways.
+ Cc: [email protected] # 6.13
+ Cc: Nikunj A Dadhania <[email protected]>
- Signed-off-by: Borislav Petkov (AMD) <[email protected]>
- Reviewed-by: Nikunj A Dadhania <[email protected]>
- Cc: [email protected]
- Link: https://lore.kernel.org/r/[email protected]
- ## arch/x86/coco/sev/core.c ##
-@@ arch/x86/coco/sev/core.c: struct snp_msg_desc *snp_msg_alloc(void)
- if (!mdesc->response)
- goto e_free_request;
+ ## arch/x86/include/asm/sev.h ##
+@@ arch/x86/include/asm/sev.h: struct snp_guest_req {
+ unsigned int vmpck_id;
+ u8 msg_version;
+ u8 msg_type;
++
++ struct snp_req_data input;
++ void *certs_data;
+ };
-- mdesc->certs_data = alloc_shared_pages(SEV_FW_BLOB_MAX_SIZE);
-- if (!mdesc->certs_data)
-- goto e_free_response;
--
-- /* initial the input address for guest request */
-- mdesc->input.req_gpa = __pa(mdesc->request);
-- mdesc->input.resp_gpa = __pa(mdesc->response);
-- mdesc->input.data_gpa = __pa(mdesc->certs_data);
+ /*
+@@ arch/x86/include/asm/sev.h: struct snp_msg_desc {
+ struct snp_guest_msg secret_request, secret_response;
+
+ struct snp_secrets_page *secrets;
+- struct snp_req_data input;
-
- return mdesc;
+- void *certs_data;
--e_free_response:
-- free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
- e_free_request:
- free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg));
- e_unmap:
-@@ arch/x86/coco/sev/core.c: void snp_msg_free(struct snp_msg_desc *mdesc)
- kfree(mdesc->ctx);
- free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
- free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg));
-- free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE);
- iounmap((__force void __iomem *)mdesc->secrets);
+ struct aesgcm_ctx *ctx;
- memset(mdesc, 0, sizeof(*mdesc));
-@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r +
+ ## drivers/virt/coco/sev-guest/sev-guest.c ##
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
* sequence number must be incremented or the VMPCK must be deleted to
* prevent reuse of the IV.
*/
@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc
switch (rc) {
case -ENOSPC:
/*
-@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r +@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
* order to increment the sequence number and thus avoid
* IV reuse.
*/
@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc
req->exit_code = SVM_VMGEXIT_GUEST_REQUEST;
/*
-@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r +@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
}
if (override_npages)
@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc
return rc;
}
-@@ arch/x86/coco/sev/core.c: int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req
- */
- memcpy(mdesc->request, &mdesc->secret_request, sizeof(mdesc->secret_request));
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
+ memcpy(mdesc->request, &mdesc->secret_request,
+ sizeof(mdesc->secret_request));
-+ /* Initialize the input address for guest request */
++ /* initial the input address for guest request */
+ req->input.req_gpa = __pa(mdesc->request);
+ req->input.resp_gpa = __pa(mdesc->response);
+ req->input.data_gpa = req->certs_data ? __pa(req->certs_data) : 0;
@@ arch/x86/coco/sev/core.c: int snp_send_guest_request(struct snp_msg_desc *mdesc,
rc = __handle_guest_request(mdesc, req, rio);
if (rc) {
if (rc == -EIO &&
-
- ## arch/x86/include/asm/sev.h ##
-@@ arch/x86/include/asm/sev.h: struct snp_guest_req {
- unsigned int vmpck_id;
- u8 msg_version;
- u8 msg_type;
-+
-+ struct snp_req_data input;
-+ void *certs_data;
- };
-
- /*
-@@ arch/x86/include/asm/sev.h: struct snp_msg_desc {
- struct snp_guest_msg secret_request, secret_response;
-
- struct snp_secrets_page *secrets;
-- struct snp_req_data input;
--
-- void *certs_data;
-
- struct aesgcm_ctx *ctx;
-
-
- ## drivers/virt/coco/sev-guest/sev-guest.c ##
@@ drivers/virt/coco/sev-guest/sev-guest.c: static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques
struct snp_guest_req req = {};
int ret, npages = 0, resp_len;
@@ drivers/virt/coco/sev-guest/sev-guest.c: static int get_ext_report(struct snp_gu
return ret;
}
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __init sev_guest_probe(struct platform_device *pdev)
+ if (!mdesc->response)
+ goto e_free_request;
+
+- mdesc->certs_data = alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE);
+- if (!mdesc->certs_data)
+- goto e_free_response;
+-
+ ret = -EIO;
+ mdesc->ctx = snp_init_crypto(mdesc->vmpck, VMPCK_KEY_LEN);
+ if (!mdesc->ctx)
+- goto e_free_cert_data;
++ goto e_free_response;
+
+ misc = &snp_dev->misc;
+ misc->minor = MISC_DYNAMIC_MINOR;
+ misc->name = DEVICE_NAME;
+ misc->fops = &snp_guest_fops;
+
+- /* Initialize the input addresses for guest request */
+- mdesc->input.req_gpa = __pa(mdesc->request);
+- mdesc->input.resp_gpa = __pa(mdesc->response);
+- mdesc->input.data_gpa = __pa(mdesc->certs_data);
+-
+ /* Set the privlevel_floor attribute based on the vmpck_id */
+ sev_tsm_ops.privlevel_floor = vmpck_id;
+
+ ret = tsm_register(&sev_tsm_ops, snp_dev);
+ if (ret)
+- goto e_free_cert_data;
++ goto e_free_response;
+
+ ret = devm_add_action_or_reset(&pdev->dev, unregister_sev_tsm, NULL);
+ if (ret)
+- goto e_free_cert_data;
++ goto e_free_response;
+
+ ret = misc_register(misc);
+ if (ret)
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __init sev_guest_probe(struct platform_device *pdev) +
+ e_free_ctx:
+ kfree(mdesc->ctx);
+-e_free_cert_data:
+- free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE);
+ e_free_response:
+ free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
+ e_free_request:
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static void __exit sev_guest_remove(struct platform_device *pdev)
+ struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev);
+ struct snp_msg_desc *mdesc = snp_dev->msg_desc;
+
+- free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE);
+ free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
+ free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg));
+ kfree(mdesc->ctx);
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.13.y | Success | Success |
Borislav Petkov
maintainerQuoted 8 lines · On Sun, Mar 09, 2025 at 11:29:57AM +0100, [email protected] wrote:
The patch below does not apply to the 6.13-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.To reproduce the conflict and resubmit, you may use the following commands:
Quoted 8 lines
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.13.y
git checkoutFETCH_HEAD
git cherry-pick -x3e385c0d6ce88ac9916dcf84267bd5855d830748
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025030957-magnetism-lustily-55d9@gregkh' --subject-prefix 'PATCH 6.13.y' HEAD^..Possible dependencies:
Yeah, aik is going to send you a proper backport here.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePATCH 1/1 virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
In reply to [email protected]Compared to the SNP Guest Request, the "Extended" version adds data pages for receiving certificates. If not enough pages provided, the HV can report to the VM how much is needed so the VM can reallocate and repeat.
Commit
ae596615d93d ("virt: sev-guest: Reduce the scope of SNP command mutex")
moved handling of the allocated/desired pages number out of scope of said mutex and create a possibility for a race (multiple instances trying to trigger Extended request in a VM) as there is just one instance of snp_msg_desc per /dev/sev-guest and no locking other than snp_cmd_mutex.
Fix the issue by moving the data blob/size and the GHCB input struct (snp_req_data) into snp_guest_req which is allocated on stack now and accessed by the GHCB caller under that mutex.
Stop allocating SEV_FW_BLOB_MAX_SIZE in snp_msg_alloc() as only one of four callers needs it. Free the received blob in get_ext_report() right after it is copied to the userspace. Possible future users of snp_send_guest_request() are likely to have different ideas about the buffer size anyways.
--- arch/x86/include/asm/sev.h | 6 +-- drivers/virt/coco/sev-guest/sev-guest.c | 63 +++++++++++++++---------- 2 files changed, 42 insertions(+), 27 deletions(-)
arch/x86/include/asm/sev.h +3 -3
@@ -185,6 +185,9 @@ struct snp_guest_req {unsigned int vmpck_id;u8 msg_version;u8 msg_type; + +struct snp_req_data input; +void *certs_data; };/*
@@ -245,9 +248,6 @@ struct snp_msg_desc {struct snp_guest_msg secret_request, secret_response;struct snp_secrets_page *secrets; -struct snp_req_data input; - -void *certs_data;struct aesgcm_ctx *ctx;
drivers/virt/coco/sev-guest/sev-guest.c +39 -24
160 lines not on this page · raw message
Signature · 1 line
2.47.1
Re: [PATCH 6.13.y] virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to it
Found matching upstream commit: 3e385c0d6ce88ac9916dcf84267bd5855d830748
Note: The patch differs from the upstream commit:
---
1: 3e385c0d6ce88 ! 1: 796b69e2edd7a virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
@@ Commit message
- Cc: [email protected]
+ Cc: [email protected] # 6.13
+ (cherry picked from commit 3e385c0d6ce88ac9916dcf84267bd5855d830748)
- ## arch/x86/coco/sev/core.c ##
-@@ arch/x86/coco/sev/core.c: struct snp_msg_desc *snp_msg_alloc(void)
- if (!mdesc->response)
- goto e_free_request;
+ ## arch/x86/include/asm/sev.h ##
+@@ arch/x86/include/asm/sev.h: struct snp_guest_req {
+ unsigned int vmpck_id;
+ u8 msg_version;
+ u8 msg_type;
++
++ struct snp_req_data input;
++ void *certs_data;
+ };
-- mdesc->certs_data = alloc_shared_pages(SEV_FW_BLOB_MAX_SIZE);
-- if (!mdesc->certs_data)
-- goto e_free_response;
--
-- /* initial the input address for guest request */
-- mdesc->input.req_gpa = __pa(mdesc->request);
-- mdesc->input.resp_gpa = __pa(mdesc->response);
-- mdesc->input.data_gpa = __pa(mdesc->certs_data);
+ /*
+@@ arch/x86/include/asm/sev.h: struct snp_msg_desc {
+ struct snp_guest_msg secret_request, secret_response;
+
+ struct snp_secrets_page *secrets;
+- struct snp_req_data input;
-
- return mdesc;
+- void *certs_data;
--e_free_response:
-- free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
- e_free_request:
- free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg));
- e_unmap:
-@@ arch/x86/coco/sev/core.c: void snp_msg_free(struct snp_msg_desc *mdesc)
- kfree(mdesc->ctx);
- free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
- free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg));
-- free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE);
- iounmap((__force void __iomem *)mdesc->secrets);
+ struct aesgcm_ctx *ctx;
- memset(mdesc, 0, sizeof(*mdesc));
-@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r +
+ ## drivers/virt/coco/sev-guest/sev-guest.c ##
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
* sequence number must be incremented or the VMPCK must be deleted to
* prevent reuse of the IV.
*/
@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc
switch (rc) {
case -ENOSPC:
/*
-@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r +@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
* order to increment the sequence number and thus avoid
* IV reuse.
*/
@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc
req->exit_code = SVM_VMGEXIT_GUEST_REQUEST;
/*
-@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r +@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
}
if (override_npages)
@@ arch/x86/coco/sev/core.c: static int __handle_guest_request(struct snp_msg_desc
return rc;
}
-@@ arch/x86/coco/sev/core.c: int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req
- */
- memcpy(mdesc->request, &mdesc->secret_request, sizeof(mdesc->secret_request));
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
+ memcpy(mdesc->request, &mdesc->secret_request,
+ sizeof(mdesc->secret_request));
-+ /* Initialize the input address for guest request */
++ /* initial the input address for guest request */
+ req->input.req_gpa = __pa(mdesc->request);
+ req->input.resp_gpa = __pa(mdesc->response);
+ req->input.data_gpa = req->certs_data ? __pa(req->certs_data) : 0;
@@ arch/x86/coco/sev/core.c: int snp_send_guest_request(struct snp_msg_desc *mdesc,
rc = __handle_guest_request(mdesc, req, rio);
if (rc) {
if (rc == -EIO &&
-
- ## arch/x86/include/asm/sev.h ##
-@@ arch/x86/include/asm/sev.h: struct snp_guest_req {
- unsigned int vmpck_id;
- u8 msg_version;
- u8 msg_type;
-+
-+ struct snp_req_data input;
-+ void *certs_data;
- };
-
- /*
-@@ arch/x86/include/asm/sev.h: struct snp_msg_desc {
- struct snp_guest_msg secret_request, secret_response;
-
- struct snp_secrets_page *secrets;
-- struct snp_req_data input;
--
-- void *certs_data;
-
- struct aesgcm_ctx *ctx;
-
-
- ## drivers/virt/coco/sev-guest/sev-guest.c ##
@@ drivers/virt/coco/sev-guest/sev-guest.c: static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques
struct snp_guest_req req = {};
int ret, npages = 0, resp_len;
@@ drivers/virt/coco/sev-guest/sev-guest.c: static int get_ext_report(struct snp_gu
return ret;
}
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __init sev_guest_probe(struct platform_device *pdev)
+ if (!mdesc->response)
+ goto e_free_request;
+
+- mdesc->certs_data = alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE);
+- if (!mdesc->certs_data)
+- goto e_free_response;
+-
+ ret = -EIO;
+ mdesc->ctx = snp_init_crypto(mdesc->vmpck, VMPCK_KEY_LEN);
+ if (!mdesc->ctx)
+- goto e_free_cert_data;
++ goto e_free_response;
+
+ misc = &snp_dev->misc;
+ misc->minor = MISC_DYNAMIC_MINOR;
+ misc->name = DEVICE_NAME;
+ misc->fops = &snp_guest_fops;
+
+- /* Initialize the input addresses for guest request */
+- mdesc->input.req_gpa = __pa(mdesc->request);
+- mdesc->input.resp_gpa = __pa(mdesc->response);
+- mdesc->input.data_gpa = __pa(mdesc->certs_data);
+-
+ /* Set the privlevel_floor attribute based on the vmpck_id */
+ sev_tsm_ops.privlevel_floor = vmpck_id;
+
+ ret = tsm_register(&sev_tsm_ops, snp_dev);
+ if (ret)
+- goto e_free_cert_data;
++ goto e_free_response;
+
+ ret = devm_add_action_or_reset(&pdev->dev, unregister_sev_tsm, NULL);
+ if (ret)
+- goto e_free_cert_data;
++ goto e_free_response;
+
+ ret = misc_register(misc);
+ if (ret)
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static int __init sev_guest_probe(struct platform_device *pdev) +
+ e_free_ctx:
+ kfree(mdesc->ctx);
+-e_free_cert_data:
+- free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE);
+ e_free_response:
+ free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
+ e_free_request:
+@@ drivers/virt/coco/sev-guest/sev-guest.c: static void __exit sev_guest_remove(struct platform_device *pdev)
+ struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev);
+ struct snp_msg_desc *mdesc = snp_dev->msg_desc;
+
+- free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE);
+ free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
+ free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg));
+ kfree(mdesc->ctx);
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.13.y | Success | Success |
Re: [PATCH 6.13.y] virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
What does the tool not like in particular? The fact they are different? Or the backported commit log must have started with "commit xxx upstream." and "(cherry picked from commit xxx)" is not good enough? Thanks,
Quoted 206 lines · Sasha Levin
[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to itFound matching upstream commit:
3e385c0d6ce88ac9916dcf84267bd5855d830748Note: The patch differs from the upstream commit:
---
1:3e385c0d6ce88! 1:796b69e2edd7avirt: sev-guest: Move SNP Guest Request data pages handling undersnp_cmd_mutex
@@ Commit messageSigned-off-by Alexey Kardashevskiy <[email protected]>Signed-off-by Borislav Petkov (AMD) <[email protected]>Reviewed-by Nikunj A Dadhania <[email protected]>- Cc: [email protected]
+ Cc: [email protected] # 6.13+ (cherry picked from commit
3e385c0d6ce88ac9916dcf84267bd5855d830748)- ##
arch/x86/coco/sev/core.c##
-@@arch/x86/coco/sev/core.c: structsnp_msg_desc*snp_msg_alloc(void)
- if (!mdesc->response)
- gotoe_free_request;
+ ##arch/x86/include/asm/sev.h##
+@@arch/x86/include/asm/sev.h: structsnp_guest_req{
+ unsigned intvmpck_id;
+ u8msg_version;
+ u8msg_type;
++
++ structsnp_req_datainput;
++ void*certs_data;
+ };--
mdesc->certs_data=alloc_shared_pages(SEV_FW_BLOB_MAX_SIZE);
-- if (!mdesc->certs_data)
-- gotoe_free_response;
--
-- /* initial the input address for guest request */
--mdesc->input.req_gpa=__pa(mdesc->request);
--mdesc->input.resp_gpa=__pa(mdesc->response);
--mdesc->input.data_gpa=__pa(mdesc->certs_data);
+ /*
+@@arch/x86/include/asm/sev.h: structsnp_msg_desc{
+ structsnp_guest_msgsecret_request,secret_response;
+
+ structsnp_secrets_page*secrets;
+- structsnp_req_datainput;
-
- return mdesc;
+- void*certs_data;--e_free_response:
--free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
-e_free_request:
-free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg));
-e_unmap:
-@@arch/x86/coco/sev/core.c: voidsnp_msg_free(struct snp_msg_desc *mdesc)
-kfree(mdesc->ctx);
-free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
-free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg));
--free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE);
-iounmap((__force void __iomem *)mdesc->secrets);
+ structaesgcm_ctx*ctx;-
memset(mdesc, 0, sizeof(*mdesc));
-@@arch/x86/coco/sev/core.c: static int __handle_guest_request(structsnp_msg_desc*mdesc, structsnp_guest_r+
+ ##drivers/virt/coco/sev-guest/sev-guest.c##
+@@drivers/virt/coco/sev-guest/sev-guest.c: static int __handle_guest_request(structsnp_msg_desc*mdesc, structsnp_guest_r
* sequence number must be incremented or the VMPCK must be deleted to
* prevent reuse of the IV.
*/
@@arch/x86/coco/sev/core.c: static int __handle_guest_request(structsnp_msg_desc
switch (rc) {
case-ENOSPC:
/*
-@@arch/x86/coco/sev/core.c: static int __handle_guest_request(structsnp_msg_desc*mdesc, structsnp_guest_r+@@drivers/virt/coco/sev-guest/sev-guest.c: static int __handle_guest_request(structsnp_msg_desc*mdesc, structsnp_guest_r
* order to increment the sequence number and thus avoid
* IV reuse.
*/
@@arch/x86/coco/sev/core.c: static int __handle_guest_request(structsnp_msg_desc
req->exit_code=SVM_VMGEXIT_GUEST_REQUEST;/*
-@@arch/x86/coco/sev/core.c: static int __handle_guest_request(structsnp_msg_desc*mdesc, structsnp_guest_r+@@drivers/virt/coco/sev-guest/sev-guest.c: static int __handle_guest_request(structsnp_msg_desc*mdesc, structsnp_guest_r
}if (
override_npages)
@@arch/x86/coco/sev/core.c: static int __handle_guest_request(structsnp_msg_descreturn rc;
}
-@@arch/x86/coco/sev/core.c: int snp_send_guest_request(structsnp_msg_desc*mdesc, structsnp_guest_req*req
- */
-memcpy(mdesc->request, &mdesc->secret_request, sizeof(mdesc->secret_request));
+@@drivers/virt/coco/sev-guest/sev-guest.c: static int snp_send_guest_request(structsnp_msg_desc*mdesc, structsnp_guest_r
+ memcpy(mdesc->request,&mdesc->secret_request,
+sizeof(mdesc->secret_request));-+ /* Initialize the input address for guest request */
++ /* initial the input address for guest request */
+req->input.req_gpa=__pa(mdesc->request);
+req->input.resp_gpa=__pa(mdesc->response);
+req->input.data_gpa=req->certs_data?__pa(req->certs_data): 0;
@@arch/x86/coco/sev/core.c: int snp_send_guest_request(structsnp_msg_desc*mdesc,
rc =__handle_guest_request(mdesc, req, rio);
if (rc) {
if (rc ==-EIO&&
-
- ##arch/x86/include/asm/sev.h##
-@@arch/x86/include/asm/sev.h: structsnp_guest_req{
- unsigned intvmpck_id;
- u8msg_version;
- u8msg_type;
-+
-+ structsnp_req_datainput;
-+ void*certs_data;
- };
-
- /*
-@@arch/x86/include/asm/sev.h: structsnp_msg_desc{
- structsnp_guest_msgsecret_request,secret_response;
-
- structsnp_secrets_page*secrets;
-- structsnp_req_datainput;
--
-- void*certs_data;
-
- structaesgcm_ctx*ctx;
-
-
- ##drivers/virt/coco/sev-guest/sev-guest.c##
@@drivers/virt/coco/sev-guest/sev-guest.c: static int get_ext_report(structsnp_guest_dev*snp_dev, structsnp_guest_reques
structsnp_guest_reqreq = {};
int ret, npages = 0,resp_len;
@@drivers/virt/coco/sev-guest/sev-guest.c: static int get_ext_report(structsnp_gu
return ret;
}+@@
drivers/virt/coco/sev-guest/sev-guest.c: static int__initsev_guest_probe(struct platform_device *pdev)
+ if (!mdesc->response)
+ gotoe_free_request;
+
+-mdesc->certs_data=alloc_shared_pages(dev, SEV_FW_BLOB_MAX_SIZE);
+- if (!mdesc->certs_data)
+- gotoe_free_response;
+-
+ ret =-EIO;
+mdesc->ctx=snp_init_crypto(mdesc->vmpck, VMPCK_KEY_LEN);
+ if (!mdesc->ctx)
+- gotoe_free_cert_data;
++ gotoe_free_response;
+
+ misc =&snp_dev->misc;
+misc->minor=MISC_DYNAMIC_MINOR;
+misc->name=DEVICE_NAME;
+misc->fops=&snp_guest_fops;
+
+- /* Initialize the input addresses for guest request */
+-mdesc->input.req_gpa=__pa(mdesc->request);
+-mdesc->input.resp_gpa=__pa(mdesc->response);
+-mdesc->input.data_gpa=__pa(mdesc->certs_data);
+-
+ /* Set theprivlevel_floorattribute based on thevmpck_id*/
+ sev_tsm_ops.privlevel_floor =vmpck_id;
+
+ ret =tsm_register(&sev_tsm_ops, snp_dev);
+ if (ret)
+- gotoe_free_cert_data;
++ gotoe_free_response;
+
+ ret =devm_add_action_or_reset(&pdev->dev, unregister_sev_tsm, NULL);
+ if (ret)
+- gotoe_free_cert_data;
++ gotoe_free_response;
+
+ ret =misc_register(misc);
+ if (ret)
+@@drivers/virt/coco/sev-guest/sev-guest.c: static int__initsev_guest_probe(struct platform_device *pdev)+
+e_free_ctx:
+kfree(mdesc->ctx);
+-e_free_cert_data:
+-free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE);
+e_free_response:
+free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
+e_free_request:
+@@drivers/virt/coco/sev-guest/sev-guest.c: static void__exitsev_guest_remove(struct platform_device *pdev)
+ structsnp_guest_dev*snp_dev=platform_get_drvdata(pdev);
+ structsnp_msg_desc*mdesc =snp_dev->msg_desc;
+
+-free_shared_pages(mdesc->certs_data, SEV_FW_BLOB_MAX_SIZE);
+free_shared_pages(mdesc->response, sizeof(struct snp_guest_msg));
+free_shared_pages(mdesc->request, sizeof(struct snp_guest_msg));
+kfree(mdesc->ctx);
---Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.13.y | Success | Success |
Signature · 1 line
Alexey
Greg KH
maintainerRe: [PATCH 6.13.y] virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
Quoted 3 lines · Alexey Kardashevskiy
What does the tool not like in particular? The fact they are different? Or the backported commit log must have started with "commit xxx upstream." and "(cherry picked from commit xxx)" is not good enough? Thanks,
This is showing that the diff is totally different from what is upstream. Why is it so different? Why did you not list your changes?
Are you sure you got the git commit id correct?
thanks,
greg k-h
Re: [PATCH 6.13.y] virt: sev-guest: Move SNP Guest Request data pages handling under snp_cmd_mutex
Quoted 7 lines · Greg KH
Quoted 3 lines · Alexey Kardashevskiy
What does the tool not like in particular? The fact they are different? Or the backported commit log must have started with "commit xxx upstream." and "(cherry picked from commit xxx)" is not good enough? Thanks,
This is showing that the diff is totally different from what is upstream. Why is it so different? Why did you not list your changes?
A bunch of code moved from one file (sev-guest.c) to another (core.c) after v6.13, but otherwise the two patches are identical, I checked chunk by chunk. But yeah, when compared via diff, it is not that obvious, I agree.
Quoted 1 line
Are you sure you got the git commit id correct?
Yes.
Quoted 4 lines
thanks,
greg k-h
Signature · 1 line
Alexey