]> Git Repo - linux.git/commitdiff
Merge branch 'x86/cc' into x86/sev
authorThomas Gleixner <[email protected]>
Thu, 30 Mar 2023 12:07:05 +0000 (14:07 +0200)
committerThomas Gleixner <[email protected]>
Thu, 30 Mar 2023 12:07:05 +0000 (14:07 +0200)
Pick up the cc_vendor changes.

1  2 
arch/x86/coco/core.c
arch/x86/include/asm/coco.h

diff --combined arch/x86/coco/core.c
index f4f0625691fd43d8015404dedc2cd43fd893f575,684f0a910475cf6622bb32535ba47cd9d59f80be..73f83233d25df8481b322456039b49b0f108699f
@@@ -13,7 -13,7 +13,7 @@@
  #include <asm/coco.h>
  #include <asm/processor.h>
  
static enum cc_vendor vendor __ro_after_init;
enum cc_vendor cc_vendor __ro_after_init;
  static u64 cc_mask __ro_after_init;
  
  static bool intel_cc_platform_has(enum cc_attr attr)
        }
  }
  
 +/*
 + * Handle the SEV-SNP vTOM case where sme_me_mask is zero, and
 + * the other levels of SME/SEV functionality, including C-bit
 + * based SEV-SNP, are not enabled.
 + */
 +static __maybe_unused bool amd_cc_platform_vtom(enum cc_attr attr)
 +{
 +      switch (attr) {
 +      case CC_ATTR_GUEST_MEM_ENCRYPT:
 +      case CC_ATTR_MEM_ENCRYPT:
 +              return true;
 +      default:
 +              return false;
 +      }
 +}
 +
  /*
   * SME and SEV are very similar but they are not the same, so there are
   * times that the kernel will need to distinguish between SME and SEV. The
   * up under SME the trampoline area cannot be encrypted, whereas under SEV
   * the trampoline area must be encrypted.
   */
 +
  static bool amd_cc_platform_has(enum cc_attr attr)
  {
  #ifdef CONFIG_AMD_MEM_ENCRYPT
 +
 +      if (sev_status & MSR_AMD64_SNP_VTOM)
 +              return amd_cc_platform_vtom(attr);
 +
        switch (attr) {
        case CC_ATTR_MEM_ENCRYPT:
                return sme_me_mask;
  #endif
  }
  
 -static bool hyperv_cc_platform_has(enum cc_attr attr)
 -{
 -      return attr == CC_ATTR_GUEST_MEM_ENCRYPT;
 -}
 -
  bool cc_platform_has(enum cc_attr attr)
  {
-       switch (vendor) {
+       switch (cc_vendor) {
        case CC_VENDOR_AMD:
                return amd_cc_platform_has(attr);
        case CC_VENDOR_INTEL:
                return intel_cc_platform_has(attr);
 -      case CC_VENDOR_HYPERV:
 -              return hyperv_cc_platform_has(attr);
        default:
                return false;
        }
@@@ -117,14 -103,11 +117,14 @@@ u64 cc_mkenc(u64 val
         * encryption status of the page.
         *
         * - for AMD, bit *set* means the page is encrypted
 -       * - for Intel *clear* means encrypted.
 +       * - for AMD with vTOM and for Intel, *clear* means encrypted
         */
-       switch (vendor) {
+       switch (cc_vendor) {
        case CC_VENDOR_AMD:
 -              return val | cc_mask;
 +              if (sev_status & MSR_AMD64_SNP_VTOM)
 +                      return val & ~cc_mask;
 +              else
 +                      return val | cc_mask;
        case CC_VENDOR_INTEL:
                return val & ~cc_mask;
        default:
  u64 cc_mkdec(u64 val)
  {
        /* See comment in cc_mkenc() */
-       switch (vendor) {
+       switch (cc_vendor) {
        case CC_VENDOR_AMD:
 -              return val & ~cc_mask;
 +              if (sev_status & MSR_AMD64_SNP_VTOM)
 +                      return val | cc_mask;
 +              else
 +                      return val & ~cc_mask;
        case CC_VENDOR_INTEL:
                return val | cc_mask;
        default:
  }
  EXPORT_SYMBOL_GPL(cc_mkdec);
  
- __init void cc_set_vendor(enum cc_vendor v)
- {
-       vendor = v;
- }
  __init void cc_set_mask(u64 mask)
  {
        cc_mask = mask;
index d2c6a2e8d04d9eccd0df1ee42e4aa163d2cc0982,91b9448ffe76899c065204cbf88ff6b7ccfaf2ce..eb08796002f3c59c352172da5a44d4ef386988ea
@@@ -7,16 -7,34 +7,33 @@@
  enum cc_vendor {
        CC_VENDOR_NONE,
        CC_VENDOR_AMD,
 -      CC_VENDOR_HYPERV,
        CC_VENDOR_INTEL,
  };
  
- void cc_set_vendor(enum cc_vendor v);
- void cc_set_mask(u64 mask);
  #ifdef CONFIG_ARCH_HAS_CC_PLATFORM
+ extern enum cc_vendor cc_vendor;
+ static inline enum cc_vendor cc_get_vendor(void)
+ {
+       return cc_vendor;
+ }
+ static inline void cc_set_vendor(enum cc_vendor vendor)
+ {
+       cc_vendor = vendor;
+ }
+ void cc_set_mask(u64 mask);
  u64 cc_mkenc(u64 val);
  u64 cc_mkdec(u64 val);
  #else
+ static inline enum cc_vendor cc_get_vendor(void)
+ {
+       return CC_VENDOR_NONE;
+ }
+ static inline void cc_set_vendor(enum cc_vendor vendor) { }
  static inline u64 cc_mkenc(u64 val)
  {
        return val;
This page took 0.068828 seconds and 4 git commands to generate.