From: Borislav Petkov <bp@alien8.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Dionna Glaze <dionnaglaze@google.com>,
Joerg Roedel <jroedel@suse.de>,
Michael Roth <michael.roth@amd.com>,
Nikunj A Dadhania <nikunj@amd.com>,
Peter Gonda <pgonda@google.com>,
Tom Lendacky <Thomas.Lendacky@amd.com>,
linux-coco@lists.linux.dev, x86@kernel.org
Subject: [PATCH 05/11] virt/coco/sev-guest: Carve out the request issuing logic into a helper
Date: Thu, 16 Feb 2023 13:41:14 +0100 [thread overview]
Message-ID: <20230216124120.26578-6-bp@alien8.de> (raw)
In-Reply-To: <20230216124120.26578-1-bp@alien8.de>
From: "Borislav Petkov (AMD)" <bp@alien8.de>
This makes the code flow a lot easier to follow.
No functional changes.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
---
drivers/virt/coco/sev-guest/sev-guest.c | 41 +++++++++++++++----------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c
index c0ecc5885573..e72289de2b28 100644
--- a/drivers/virt/coco/sev-guest/sev-guest.c
+++ b/drivers/virt/coco/sev-guest/sev-guest.c
@@ -318,27 +318,12 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8
return __enc_payload(snp_dev, req, payload, sz);
}
-static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, int msg_ver,
- u8 type, void *req_buf, size_t req_sz, void *resp_buf,
- u32 resp_sz, __u64 *fw_err)
+static int __handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, __u64 *fw_err)
{
unsigned long err, override_err = 0;
unsigned int override_npages = 0;
- u64 seqno;
int rc;
- /* Get message sequence and verify that its a non-zero */
- seqno = snp_get_msg_seqno(snp_dev);
- if (!seqno)
- return -EIO;
-
- memset(snp_dev->response, 0, sizeof(struct snp_guest_msg));
-
- /* Encrypt the userspace provided payload */
- rc = enc_payload(snp_dev, seqno, msg_ver, type, req_buf, req_sz);
- if (rc)
- return rc;
-
retry_request:
/*
* Call firmware to process the request. In this function the encrypted
@@ -347,7 +332,6 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in
* prevent reuse of the IV.
*/
rc = snp_issue_guest_request(exit_code, &snp_dev->input, &err);
-
switch (rc) {
case -ENOSPC:
/*
@@ -384,6 +368,29 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in
if (override_npages)
snp_dev->input.data_npages = override_npages;
+ return rc;
+}
+
+static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, int msg_ver,
+ u8 type, void *req_buf, size_t req_sz, void *resp_buf,
+ u32 resp_sz, __u64 *fw_err)
+{
+ u64 seqno;
+ int rc;
+
+ /* Get message sequence and verify that its a non-zero */
+ seqno = snp_get_msg_seqno(snp_dev);
+ if (!seqno)
+ return -EIO;
+
+ memset(snp_dev->response, 0, sizeof(struct snp_guest_msg));
+
+ /* Encrypt the userspace provided payload */
+ rc = enc_payload(snp_dev, seqno, msg_ver, type, req_buf, req_sz);
+ if (rc)
+ return rc;
+
+ rc = __handle_guest_request(snp_dev, exit_code, fw_err);
if (rc) {
dev_alert(snp_dev->dev,
"Detected error from ASP request. rc: %d, fw_err: %llu\n",
--
2.35.1
next prev parent reply other threads:[~2023-02-16 12:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 12:41 [PATCH 00/11] SEV: Cleanup sev-guest a bit and add throttling Borislav Petkov
2023-02-16 12:41 ` [PATCH 01/11] crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL Borislav Petkov
2023-02-16 12:41 ` [PATCH 02/11] virt/coco/sev-guest: Check SEV_SNP attribute at probe time Borislav Petkov
2023-02-16 12:41 ` [PATCH 03/11] virt/coco/sev-guest: Simplify extended guest request handling Borislav Petkov
2023-02-16 16:43 ` Dionna Amalie Glaze
2023-02-16 12:41 ` [PATCH 04/11] virt/coco/sev-guest: Remove the disable_vmpck label in handle_guest_request() Borislav Petkov
2023-02-16 12:41 ` Borislav Petkov [this message]
2023-02-16 12:45 ` [PATCH 06/11] virt/coco/sev-guest: Do some code style cleanups Borislav Petkov
2023-02-16 12:45 ` [PATCH 07/11] virt/coco/sev-guest: Convert the sw_exit_info_2 checking to a switch-case Borislav Petkov
2023-02-16 12:45 ` [PATCH 08/11] virt/coco/sev-guest: Add throttling awareness Borislav Petkov
2023-02-16 12:46 ` [PATCH 09/11] virt/coco/sev-guest: Double-buffer messages Borislav Petkov
2023-02-16 12:46 ` [PATCH 10/11] crypto: ccp: Get rid of __sev_platform_init_locked()'s local function pointer Borislav Petkov
2023-02-16 12:46 ` [PATCH 11/11] x86/sev: Change snp_guest_issue_request()'s fw_err argument Borislav Petkov
2023-02-16 16:59 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230216124120.26578-6-bp@alien8.de \
--to=bp@alien8.de \
--cc=Thomas.Lendacky@amd.com \
--cc=dionnaglaze@google.com \
--cc=jroedel@suse.de \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=nikunj@amd.com \
--cc=pgonda@google.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox