xref: /qemu/target/i386/confidential-guest.h (revision f81198cefad223afc8e1ae60e9830b60e5f2d6ff)
1  /*
2   * x86-specific confidential guest methods.
3   *
4   * Copyright (c) 2024 Red Hat Inc.
5   *
6   * Authors:
7   *  Paolo Bonzini <pbonzini@redhat.com>
8   *
9   * This work is licensed under the terms of the GNU GPL, version 2 or later.
10   * See the COPYING file in the top-level directory.
11   */
12  #ifndef TARGET_I386_CG_H
13  #define TARGET_I386_CG_H
14  
15  #include "qom/object.h"
16  
17  #include "exec/confidential-guest-support.h"
18  
19  #define TYPE_X86_CONFIDENTIAL_GUEST "x86-confidential-guest"
20  
21  OBJECT_DECLARE_TYPE(X86ConfidentialGuest,
22                      X86ConfidentialGuestClass,
23                      X86_CONFIDENTIAL_GUEST)
24  
25  struct X86ConfidentialGuest {
26      /* <private> */
27      ConfidentialGuestSupport parent_obj;
28  };
29  
30  /**
31   * X86ConfidentialGuestClass:
32   *
33   * Class to be implemented by confidential-guest-support concrete objects
34   * for the x86 target.
35   */
36  struct X86ConfidentialGuestClass {
37      /* <private> */
38      ConfidentialGuestSupportClass parent;
39  
40      /* <public> */
41      int (*kvm_type)(X86ConfidentialGuest *cg);
42      uint32_t (*mask_cpuid_features)(X86ConfidentialGuest *cg, uint32_t feature, uint32_t index,
43                                      int reg, uint32_t value);
44  };
45  
46  /**
47   * x86_confidential_guest_kvm_type:
48   *
49   * Calls #X86ConfidentialGuestClass.unplug callback of @plug_handler.
50   */
51  static inline int x86_confidential_guest_kvm_type(X86ConfidentialGuest *cg)
52  {
53      X86ConfidentialGuestClass *klass = X86_CONFIDENTIAL_GUEST_GET_CLASS(cg);
54  
55      if (klass->kvm_type) {
56          return klass->kvm_type(cg);
57      } else {
58          return 0;
59      }
60  }
61  
62  /**
63   * x86_confidential_guest_mask_cpuid_features:
64   *
65   * Removes unsupported features from a confidential guest's CPUID values, returns
66   * the value with the bits removed.  The bits removed should be those that KVM
67   * provides independent of host-supported CPUID features, but are not supported by
68   * the confidential computing firmware.
69   */
70  static inline int x86_confidential_guest_mask_cpuid_features(X86ConfidentialGuest *cg,
71                                                               uint32_t feature, uint32_t index,
72                                                               int reg, uint32_t value)
73  {
74      X86ConfidentialGuestClass *klass = X86_CONFIDENTIAL_GUEST_GET_CLASS(cg);
75  
76      if (klass->mask_cpuid_features) {
77          return klass->mask_cpuid_features(cg, feature, index, reg, value);
78      } else {
79          return value;
80      }
81  }
82  
83  #endif
84