2020-10-19 15:14:02

by Joerg Roedel

[permalink] [raw]
Subject: [PATCH 1/5] x86/boot/compressed/64: Introduce sev_status

From: Joerg Roedel <[email protected]>

Introduce sev_status and initialize it together with sme_me_mask to have
an indicator which SEV features are enabled.

Signed-off-by: Joerg Roedel <[email protected]>
---
arch/x86/boot/compressed/mem_encrypt.S | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S
index dd07e7b41b11..0effd58f0095 100644
--- a/arch/x86/boot/compressed/mem_encrypt.S
+++ b/arch/x86/boot/compressed/mem_encrypt.S
@@ -71,6 +71,8 @@ SYM_FUNC_END(get_sev_encryption_bit)
SYM_FUNC_START(set_sev_encryption_mask)
#ifdef CONFIG_AMD_MEM_ENCRYPT
push %rbp
+ push %rax
+ push %rcx
push %rdx

movq %rsp, %rbp /* Save current stack pointer */
@@ -81,10 +83,19 @@ SYM_FUNC_START(set_sev_encryption_mask)

bts %rax, sme_me_mask(%rip) /* Create the encryption mask */

+ /* Read sev_status */
+ movl $MSR_AMD64_SEV, %ecx
+ rdmsr
+ shlq $32, %rdx
+ orq %rdx, %rax
+ movq %rax, sev_status(%rip)
+
.Lno_sev_mask:
movq %rbp, %rsp /* Restore original stack pointer */

pop %rdx
+ pop %rcx
+ pop %rax
pop %rbp
#endif

@@ -96,5 +107,6 @@ SYM_FUNC_END(set_sev_encryption_mask)

#ifdef CONFIG_AMD_MEM_ENCRYPT
.balign 8
-SYM_DATA(sme_me_mask, .quad 0)
+SYM_DATA(sme_me_mask, .quad 0)
+SYM_DATA(sev_status, .quad 0)
#endif
--
2.28.0


2020-10-20 08:51:55

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 1/5] x86/boot/compressed/64: Introduce sev_status

On Mon, Oct 19, 2020 at 05:11:17PM +0200, Joerg Roedel wrote:
> From: Joerg Roedel <[email protected]>
>
> Introduce sev_status and initialize it together with sme_me_mask to have
> an indicator which SEV features are enabled.
>
> Signed-off-by: Joerg Roedel <[email protected]>
> ---
> arch/x86/boot/compressed/mem_encrypt.S | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S
> index dd07e7b41b11..0effd58f0095 100644
> --- a/arch/x86/boot/compressed/mem_encrypt.S
> +++ b/arch/x86/boot/compressed/mem_encrypt.S
> @@ -71,6 +71,8 @@ SYM_FUNC_END(get_sev_encryption_bit)
> SYM_FUNC_START(set_sev_encryption_mask)
> #ifdef CONFIG_AMD_MEM_ENCRYPT
> push %rbp
> + push %rax
> + push %rcx

There's no need to save/restore RAX and RCX, they are callee save. This
function is only called from C, so I doubt it's using a custom ABI.

> push %rdx
>
> movq %rsp, %rbp /* Save current stack pointer */
> @@ -81,10 +83,19 @@ SYM_FUNC_START(set_sev_encryption_mask)
>
> bts %rax, sme_me_mask(%rip) /* Create the encryption mask */
>
> + /* Read sev_status */
> + movl $MSR_AMD64_SEV, %ecx
> + rdmsr
> + shlq $32, %rdx
> + orq %rdx, %rax
> + movq %rax, sev_status(%rip)
> +
> .Lno_sev_mask:
> movq %rbp, %rsp /* Restore original stack pointer */
>
> pop %rdx
> + pop %rcx
> + pop %rax
> pop %rbp
> #endif
>
> @@ -96,5 +107,6 @@ SYM_FUNC_END(set_sev_encryption_mask)
>
> #ifdef CONFIG_AMD_MEM_ENCRYPT
> .balign 8
> -SYM_DATA(sme_me_mask, .quad 0)
> +SYM_DATA(sme_me_mask, .quad 0)
> +SYM_DATA(sev_status, .quad 0)
> #endif
> --
> 2.28.0
>

2020-10-20 08:55:49

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 1/5] x86/boot/compressed/64: Introduce sev_status

On Mon, Oct 19, 2020 at 05:59:25PM -0700, Sean Christopherson wrote:
> On Mon, Oct 19, 2020 at 05:11:17PM +0200, Joerg Roedel wrote:
> > From: Joerg Roedel <[email protected]>
> >
> > Introduce sev_status and initialize it together with sme_me_mask to have
> > an indicator which SEV features are enabled.
> >
> > Signed-off-by: Joerg Roedel <[email protected]>
> > ---
> > arch/x86/boot/compressed/mem_encrypt.S | 14 +++++++++++++-
> > 1 file changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S
> > index dd07e7b41b11..0effd58f0095 100644
> > --- a/arch/x86/boot/compressed/mem_encrypt.S
> > +++ b/arch/x86/boot/compressed/mem_encrypt.S
> > @@ -71,6 +71,8 @@ SYM_FUNC_END(get_sev_encryption_bit)
> > SYM_FUNC_START(set_sev_encryption_mask)
> > #ifdef CONFIG_AMD_MEM_ENCRYPT
> > push %rbp
> > + push %rax
> > + push %rcx
>
> There's no need to save/restore RAX and RCX, they are callee save. This
> function is only called from C, so I doubt it's using a custom ABI.

Gah, *caller* save. Feedback stands, my English notwithstanding.

2020-10-20 11:26:44

by Jörg Rödel

[permalink] [raw]
Subject: Re: [PATCH 1/5] x86/boot/compressed/64: Introduce sev_status

On Mon, Oct 19, 2020 at 05:59:25PM -0700, Sean Christopherson wrote:
> On Mon, Oct 19, 2020 at 05:11:17PM +0200, Joerg Roedel wrote:
> > + push %rax
> > + push %rcx
>
> There's no need to save/restore RAX and RCX, they are callee save. This
> function is only called from C, so I doubt it's using a custom ABI.

Right, removed the save/restore of these registers from the function.

Thanks,

Joerg