ne_misc_dev.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. */
  5. #ifndef _NE_MISC_DEV_H_
  6. #define _NE_MISC_DEV_H_
  7. #include <linux/cpumask.h>
  8. #include <linux/list.h>
  9. #include <linux/miscdevice.h>
  10. #include <linux/mm.h>
  11. #include <linux/mutex.h>
  12. #include <linux/pci.h>
  13. #include <linux/wait.h>
  14. #include "ne_pci_dev.h"
  15. /**
  16. * struct ne_mem_region - Entry in the enclave user space memory regions list.
  17. * @mem_region_list_entry: Entry in the list of enclave memory regions.
  18. * @memory_size: Size of the user space memory region.
  19. * @nr_pages: Number of pages that make up the memory region.
  20. * @pages: Pages that make up the user space memory region.
  21. * @userspace_addr: User space address of the memory region.
  22. */
  23. struct ne_mem_region {
  24. struct list_head mem_region_list_entry;
  25. u64 memory_size;
  26. unsigned long nr_pages;
  27. struct page **pages;
  28. u64 userspace_addr;
  29. };
  30. /**
  31. * struct ne_enclave - Per-enclave data used for enclave lifetime management.
  32. * @enclave_info_mutex : Mutex for accessing this internal state.
  33. * @enclave_list_entry : Entry in the list of created enclaves.
  34. * @eventq: Wait queue used for out-of-band event notifications
  35. * triggered from the PCI device event handler to
  36. * the enclave process via the poll function.
  37. * @has_event: Variable used to determine if the out-of-band event
  38. * was triggered.
  39. * @max_mem_regions: The maximum number of memory regions that can be
  40. * handled by the hypervisor.
  41. * @mem_regions_list: Enclave user space memory regions list.
  42. * @mem_size: Enclave memory size.
  43. * @mm : Enclave process abstraction mm data struct.
  44. * @nr_mem_regions: Number of memory regions associated with the enclave.
  45. * @nr_parent_vm_cores : The size of the threads per core array. The
  46. * total number of CPU cores available on the
  47. * parent / primary VM.
  48. * @nr_threads_per_core: The number of threads that a full CPU core has.
  49. * @nr_vcpus: Number of vcpus associated with the enclave.
  50. * @numa_node: NUMA node of the enclave memory and CPUs.
  51. * @slot_uid: Slot unique id mapped to the enclave.
  52. * @state: Enclave state, updated during enclave lifetime.
  53. * @threads_per_core: Enclave full CPU cores array, indexed by core id,
  54. * consisting of cpumasks with all their threads.
  55. * Full CPU cores are taken from the NE CPU pool
  56. * and are available to the enclave.
  57. * @vcpu_ids: Cpumask of the vCPUs that are set for the enclave.
  58. */
  59. struct ne_enclave {
  60. struct mutex enclave_info_mutex;
  61. struct list_head enclave_list_entry;
  62. wait_queue_head_t eventq;
  63. bool has_event;
  64. u64 max_mem_regions;
  65. struct list_head mem_regions_list;
  66. u64 mem_size;
  67. struct mm_struct *mm;
  68. unsigned int nr_mem_regions;
  69. unsigned int nr_parent_vm_cores;
  70. unsigned int nr_threads_per_core;
  71. unsigned int nr_vcpus;
  72. int numa_node;
  73. u64 slot_uid;
  74. u16 state;
  75. cpumask_var_t *threads_per_core;
  76. cpumask_var_t vcpu_ids;
  77. };
  78. /**
  79. * enum ne_state - States available for an enclave.
  80. * @NE_STATE_INIT: The enclave has not been started yet.
  81. * @NE_STATE_RUNNING: The enclave was started and is running as expected.
  82. * @NE_STATE_STOPPED: The enclave exited without userspace interaction.
  83. */
  84. enum ne_state {
  85. NE_STATE_INIT = 0,
  86. NE_STATE_RUNNING = 2,
  87. NE_STATE_STOPPED = U16_MAX,
  88. };
  89. /**
  90. * struct ne_devs - Data structure to keep refs to the NE misc and PCI devices.
  91. * @ne_misc_dev: Nitro Enclaves misc device.
  92. * @ne_pci_dev : Nitro Enclaves PCI device.
  93. */
  94. struct ne_devs {
  95. struct miscdevice *ne_misc_dev;
  96. struct ne_pci_dev *ne_pci_dev;
  97. };
  98. /* Nitro Enclaves (NE) data structure for keeping refs to the NE misc and PCI devices. */
  99. extern struct ne_devs ne_devs;
  100. #endif /* _NE_MISC_DEV_H_ */