linux-coco.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Dov Murik <dovmurik@linux.ibm.com>
To: linux-coco@lists.linux.dev
Cc: Dov Murik <dovmurik@linux.ibm.com>,
	Tobin Feldman-Fitzthum <tobin@linux.ibm.com>,
	James Bottomley <jejb@linux.ibm.com>,
	Claudio Carvalho <cclaudio@linux.ibm.com>
Subject: [RFC PATCH 1/3] x86/sev: Add __svsm_msr_protocol_2() which returns register values
Date: Wed,  7 Jun 2023 18:06:44 +0300	[thread overview]
Message-ID: <20230607150646.97208-2-dovmurik@linux.ibm.com> (raw)
In-Reply-To: <20230607150646.97208-1-dovmurik@linux.ibm.com>

Existing function __svsm_msr_protocol() performs an SVSM call but
returns only the value of rax.

Complex SVSM calls (like SVSM_ATTEST_SERVICES) may return several
values: in rax, rcx, rdx, r8, and r9.  The new call allows callers to
get all these values.

Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
---
 arch/x86/kernel/sev-shared.c | 49 ++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c
index d989b1add933..1e4960cf1e6e 100644
--- a/arch/x86/kernel/sev-shared.c
+++ b/arch/x86/kernel/sev-shared.c
@@ -115,6 +115,55 @@ static int __svsm_msr_protocol(struct svsm_caa *caa, u64 rax, u64 rcx, u64 rdx,
 	return ret;
 }
 
+static int __svsm_msr_protocol_2(struct svsm_caa *caa, u64 *rax, u64 *rcx, u64 *rdx,
+				 u64 *r8, u64 *r9)
+{
+	u64 val, resp;
+	u8 pending;
+	int ret;
+	u64 rax_ret, rcx_ret, rdx_ret, r8_ret, r9_ret;
+
+	val = sev_es_rd_ghcb_msr();
+
+	sev_es_wr_ghcb_msr(GHCB_MSR_VMPL_REQ_LEVEL(0));
+
+	asm volatile("mov %8, %%r8\n\t"
+		     "mov %9, %%r9\n\t"
+		     "movb $1, %10\n\t"
+		     "rep; vmmcall\n\t"
+		     "mov %%r8, %3\n\t"
+		     "mov %%r9, %4\n\t"
+		     : "=a" (rax_ret), "=c" (rcx_ret), "=d" (rdx_ret), "=r" (r8_ret), "=r" (r9_ret)
+		     : "a" (*rax), "c" (*rcx), "d" (*rdx), "r" (*r8), "r" (*r9),
+		       "m" (caa->call_pending) : );
+
+	resp = sev_es_rd_ghcb_msr();
+
+	sev_es_wr_ghcb_msr(val);
+	ret = (int)rax_ret;
+
+	pending = 0;
+	asm volatile("xchgb %0, %1" : "+r" (pending) : "m" (caa->call_pending) : "memory");
+	if (pending)
+		ret = -EINVAL;
+
+	if (GHCB_RESP_CODE(resp) != GHCB_MSR_VMPL_RESP)
+		ret = -EINVAL;
+
+	if (GHCB_MSR_VMPL_RESP_VAL(resp) != 0)
+		ret = -EINVAL;
+
+	if (ret != -EINVAL) {
+		*rax = rax_ret;
+		*rcx = rcx_ret;
+		*rdx = rdx_ret;
+		*r8 = r8_ret;
+		*r9 = r9_ret;
+	}
+
+	return ret;
+}
+
 static bool __init sev_es_check_cpu_features(void)
 {
 	if (!has_cpuflag(X86_FEATURE_RDRAND)) {
-- 
2.35.3


  reply	other threads:[~2023-06-07 15:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-07 15:06 [RFC PATCH 0/3] Retrieve SNP attestation from SVSM Dov Murik
2023-06-07 15:06 ` Dov Murik [this message]
2023-06-07 15:06 ` [RFC PATCH 2/3] x86/sev: Add snp_svsm_attest_services() Dov Murik
2023-06-07 15:06 ` [RFC PATCH 3/3] virt: sevguest: Add support to get attestation report from SVSM Dov Murik
2023-06-07 16:23   ` Daniel P. Berrangé
2023-06-07 17:05     ` Dov Murik

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=20230607150646.97208-2-dovmurik@linux.ibm.com \
    --to=dovmurik@linux.ibm.com \
    --cc=cclaudio@linux.ibm.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-coco@lists.linux.dev \
    --cc=tobin@linux.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).