Re: [PATCH 06/13] x86/sev: Rename global "sev_enabled" flag to "sev_guest"

From: Tom Lendacky
Date: Mon Jan 11 2021 - 11:48:34 EST


On 1/11/21 10:02 AM, Tom Lendacky wrote:
On 1/8/21 6:47 PM, Sean Christopherson wrote:
Use "guest" instead of "enabled" for the global "running as an SEV guest"
flag to avoid confusion over whether "sev_enabled" refers to the guest or
the host.  This will also allow KVM to usurp "sev_enabled" for its own
purposes.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>

Acked-by: Tom Lendacky <thomas.lendacky@xxxxxxx>

Ah, I tried building with CONFIG_KVM=y and CONFIG_KVM_AMD=y and got a build error:

In file included from arch/x86/kvm/svm/svm.c:43:
arch/x86/kvm/svm/svm.h:222:20: error: ‘sev_guest’ redeclared as different kind of symbol
222 | static inline bool sev_guest(struct kvm *kvm)
| ^~~~~~~~~
In file included from ./include/linux/mem_encrypt.h:17,
from ./arch/x86/include/asm/page_types.h:7,
from ./arch/x86/include/asm/page.h:9,
from ./arch/x86/include/asm/thread_info.h:12,
from ./include/linux/thread_info.h:38,
from ./arch/x86/include/asm/preempt.h:7,
from ./include/linux/preempt.h:78,
from ./include/linux/percpu.h:6,
from ./include/linux/context_tracking_state.h:5,
from ./include/linux/hardirq.h:5,
from ./include/linux/kvm_host.h:7,
from arch/x86/kvm/svm/svm.c:3:
./arch/x86/include/asm/mem_encrypt.h:23:13: note: previous declaration of ‘sev_guest’ was here
23 | extern bool sev_guest;
| ^~~~~~~~~

Thanks,
Tom


---
  arch/x86/include/asm/mem_encrypt.h | 2 +-
  arch/x86/mm/mem_encrypt.c          | 4 ++--
  arch/x86/mm/mem_encrypt_identity.c | 2 +-
  3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h
index 2f62bbdd9d12..9b3990928674 100644
--- a/arch/x86/include/asm/mem_encrypt.h
+++ b/arch/x86/include/asm/mem_encrypt.h
@@ -20,7 +20,7 @@
  extern u64 sme_me_mask;
  extern u64 sev_status;
-extern bool sev_enabled;
+extern bool sev_guest;
  void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr,
               unsigned long decrypted_kernel_vaddr,
diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c
index bc0833713be9..0f798355de03 100644
--- a/arch/x86/mm/mem_encrypt.c
+++ b/arch/x86/mm/mem_encrypt.c
@@ -44,7 +44,7 @@ EXPORT_SYMBOL(sme_me_mask);
  DEFINE_STATIC_KEY_FALSE(sev_enable_key);
  EXPORT_SYMBOL_GPL(sev_enable_key);
-bool sev_enabled __section(".data");
+bool sev_guest __section(".data");
  /* Buffer used for early in-place encryption by BSP, no locking needed */
  static char sme_early_buffer[PAGE_SIZE] __initdata __aligned(PAGE_SIZE);
@@ -344,7 +344,7 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size)
   */
  bool sme_active(void)
  {
-    return sme_me_mask && !sev_enabled;
+    return sme_me_mask && !sev_guest;
  }
  bool sev_active(void)
diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c
index 6c5eb6f3f14f..91b6b899c02b 100644
--- a/arch/x86/mm/mem_encrypt_identity.c
+++ b/arch/x86/mm/mem_encrypt_identity.c
@@ -545,7 +545,7 @@ void __init sme_enable(struct boot_params *bp)
          /* SEV state cannot be controlled by a command line option */
          sme_me_mask = me_mask;
-        sev_enabled = true;
+        sev_guest = true;
          physical_mask &= ~sme_me_mask;
          return;
      }