1. 22 Sep, 2020 8 commits
    • Andra Paraschiv's avatar
      nitro_enclaves: Add logic for creating an enclave VM · 38907e12
      Andra Paraschiv authored
      Add ioctl command logic for enclave VM creation. It triggers a slot
      allocation. The enclave resources will be associated with this slot and
      it will be used as an identifier for triggering enclave run.
      
      Return a file descriptor, namely enclave fd. This is further used by the
      associated user space enclave process to set enclave resources and
      trigger enclave termination.
      
      The poll function is implemented in order to notify the enclave process
      when an enclave exits without a specific enclave termination command
      trigger e.g. when an enclave crashes.
      
      Changelog
      
      v9 -> v10
      
      * Update commit message to include the changelog before the SoB tag(s).
      
      v8 -> v9
      
      * Use the ne_devs data structure to get the refs for the NE PCI device.
      
      v7 -> v8
      
      * No changes.
      
      v6 -> v7
      
      * Use the NE misc device parent field to get the NE PCI device.
      * Update the naming and add more comments to make more clear the logic
        of handling full CPU cores and dedicating them to the enclave.
      
      v5 -> v6
      
      * Update the code base to init the ioctl function in this patch.
      * Update documentation to kernel-doc format.
      
      v4 -> v5
      
      * Release the reference to the NE PCI device on create VM error.
      * Close enclave fd on copy_to_user() failure; rename fd to enclave fd
        while at it.
      * Remove sanity checks for situations that shouldn't happen, only if
        buggy system or broken logic at all.
      * Remove log on copy_to_user() failure.
      
      v3 -> v4
      
      * Use dev_err instead of custom NE log pattern.
      * Update the NE ioctl call to match the decoupling from the KVM API.
      * Add metadata for the NUMA node for the enclave memory and CPUs.
      
      v2 -> v3
      
      * Remove the WARN_ON calls.
      * Update static calls sanity checks.
      * Update kzfree() calls to kfree().
      * Remove file ops that do nothing for now - open.
      
      v1 -> v2
      
      * Add log pattern for NE.
      * Update goto labels to match their purpose.
      * Remove the BUG_ON calls.
      Reviewed-by: default avatarAlexander Graf <graf@amazon.com>
      Signed-off-by: default avatarAlexandru Vasile <lexnv@amazon.com>
      Signed-off-by: default avatarAndra Paraschiv <andraprs@amazon.com>
      Link: https://lore.kernel.org/r/20200921121732.44291-9-andraprs@amazon.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      38907e12
    • Andra Paraschiv's avatar
      nitro_enclaves: Init misc device providing the ioctl interface · bd47c995
      Andra Paraschiv authored
      The Nitro Enclaves driver provides an ioctl interface to the user space
      for enclave lifetime management e.g. enclave creation / termination and
      setting enclave resources such as memory and CPU.
      
      This ioctl interface is mapped to a Nitro Enclaves misc device.
      
      Changelog
      
      v9 -> v10
      
      * Update commit message to include the changelog before the SoB tag(s).
      
      v8 -> v9
      
      * Use the ne_devs data structure to get the refs for the NE misc device
        in the NE PCI device driver logic.
      
      v7 -> v8
      
      * Add define for the CID of the primary / parent VM.
      * Update the NE PCI driver shutdown logic to include misc device
        deregister.
      
      v6 -> v7
      
      * Set the NE PCI device the parent of the NE misc device to be able to
        use it in the ioctl logic.
      * Update the naming and add more comments to make more clear the logic
        of handling full CPU cores and dedicating them to the enclave.
      
      v5 -> v6
      
      * Remove the ioctl to query API version.
      * Update documentation to kernel-doc format.
      
      v4 -> v5
      
      * Update the size of the NE CPU pool string from 4096 to 512 chars.
      
      v3 -> v4
      
      * Use dev_err instead of custom NE log pattern.
      * Remove the NE CPU pool init during kernel module loading, as the CPU
        pool is now setup at runtime, via a sysfs file for the kernel
        parameter.
      * Add minimum enclave memory size definition.
      
      v2 -> v3
      
      * Remove the GPL additional wording as SPDX-License-Identifier is
        already in place.
      * Remove the WARN_ON calls.
      * Remove linux/bug and linux/kvm_host includes that are not needed.
      * Remove "ratelimited" from the logs that are not in the ioctl call
        paths.
      * Remove file ops that do nothing for now - open and release.
      
      v1 -> v2
      
      * Add log pattern for NE.
      * Update goto labels to match their purpose.
      * Update ne_cpu_pool data structure to include the global mutex.
      * Update NE misc device mode to 0660.
      * Check if the CPU siblings are included in the NE CPU pool, as full CPU
        cores are given for the enclave(s).
      Reviewed-by: default avatarAlexander Graf <graf@amazon.com>
      Signed-off-by: default avatarAndra Paraschiv <andraprs@amazon.com>
      Link: https://lore.kernel.org/r/20200921121732.44291-8-andraprs@amazon.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bd47c995
    • Andra Paraschiv's avatar
      nitro_enclaves: Handle out-of-band PCI device events · e5d616d8
      Andra Paraschiv authored
      In addition to the replies sent by the Nitro Enclaves PCI device in
      response to command requests, out-of-band enclave events can happen e.g.
      an enclave crashes. In this case, the Nitro Enclaves driver needs to be
      aware of the event and notify the corresponding user space process that
      abstracts the enclave.
      
      Register an MSI-X interrupt vector to be used for this kind of
      out-of-band events. The interrupt notifies that the state of an enclave
      changed and the driver logic scans the state of each running enclave to
      identify for which this notification is intended.
      
      Create an workqueue to handle the out-of-band events. Notify user space
      enclave process that is using a polling mechanism on the enclave fd.
      
      Changelog
      
      v9 -> v10
      
      * Update commit message to include the changelog before the SoB tag(s).
      
      v8 -> v9
      
      * Use the reference to the pdev directly from the ne_pci_dev instead of
        the one from the enclave data structure.
      
      v7 -> v8
      
      * No changes.
      
      v6 -> v7
      
      * No changes.
      
      v5 -> v6
      
      * Update documentation to kernel-doc format.
      
      v4 -> v5
      
      * Remove sanity checks for situations that shouldn't happen, only if
        buggy system or broken logic at all.
      
      v3 -> v4
      
      * Use dev_err instead of custom NE log pattern.
      * Return IRQ_NONE when interrupts are not handled.
      
      v2 -> v3
      
      * Remove the WARN_ON calls.
      * Update static calls sanity checks.
      * Remove "ratelimited" from the logs that are not in the ioctl call
        paths.
      
      v1 -> v2
      
      * Add log pattern for NE.
      * Update goto labels to match their purpose.
      Reviewed-by: default avatarAlexander Graf <graf@amazon.com>
      Signed-off-by: default avatarAlexandru-Catalin Vasile <lexnv@amazon.com>
      Signed-off-by: default avatarAndra Paraschiv <andraprs@amazon.com>
      Link: https://lore.kernel.org/r/20200921121732.44291-7-andraprs@amazon.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e5d616d8
    • Andra Paraschiv's avatar
      nitro_enclaves: Handle PCI device command requests · ad2b6980
      Andra Paraschiv authored
      The Nitro Enclaves PCI device exposes a MMIO space that this driver
      uses to submit command requests and to receive command replies e.g. for
      enclave creation / termination or setting enclave resources.
      
      Add logic for handling PCI device command requests based on the given
      command type.
      
      Register an MSI-X interrupt vector for command reply notifications to
      handle this type of communication events.
      
      Changelog
      
      v9 -> v10
      
      * Update commit message to include the changelog before the SoB tag(s).
      
      v8 -> v9
      
      * No changes.
      
      v7 -> v8
      
      * Update function signature for submit request and retrive reply
        functions as they only returned 0, no error code.
      * Include command type value in the error logs of ne_do_request().
      
      v6 -> v7
      
      * No changes.
      
      v5 -> v6
      
      * Update documentation to kernel-doc format.
      
      v4 -> v5
      
      * Remove sanity checks for situations that shouldn't happen, only if
        buggy system or broken logic at all.
      
      v3 -> v4
      
      * Use dev_err instead of custom NE log pattern.
      * Return IRQ_NONE when interrupts are not handled.
      
      v2 -> v3
      
      * Remove the WARN_ON calls.
      * Update static calls sanity checks.
      * Remove "ratelimited" from the logs that are not in the ioctl call
        paths.
      
      v1 -> v2
      
      * Add log pattern for NE.
      * Remove the BUG_ON calls.
      * Update goto labels to match their purpose.
      * Add fix for kbuild report:
        https://lore.kernel.org/lkml/202004231644.xTmN4Z1z%25lkp@intel.com/Reviewed-by: default avatarAlexander Graf <graf@amazon.com>
      Signed-off-by: default avatarAlexandru-Catalin Vasile <lexnv@amazon.com>
      Signed-off-by: default avatarAndra Paraschiv <andraprs@amazon.com>
      Link: https://lore.kernel.org/r/20200921121732.44291-6-andraprs@amazon.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ad2b6980
    • Andra Paraschiv's avatar
      nitro_enclaves: Init PCI device driver · 89308c11
      Andra Paraschiv authored
      The Nitro Enclaves PCI device is used by the kernel driver as a means of
      communication with the hypervisor on the host where the primary VM and
      the enclaves run. It handles requests with regard to enclave lifetime.
      
      Setup the PCI device driver and add support for MSI-X interrupts.
      
      Changelog
      
      v9 -> v10
      
      * Update commit message to include the changelog before the SoB tag(s).
      
      v8 -> v9
      
      * Init the reference to the ne_pci_dev in the ne_devs data structure.
      
      v7 -> v8
      
      * Add NE PCI driver shutdown logic.
      
      v6 -> v7
      
      * No changes.
      
      v5 -> v6
      
      * Update documentation to kernel-doc format.
      
      v4 -> v5
      
      * Remove sanity checks for situations that shouldn't happen, only if
        buggy system or broken logic at all.
      
      v3 -> v4
      
      * Use dev_err instead of custom NE log pattern.
      * Update NE PCI driver name to "nitro_enclaves".
      
      v2 -> v3
      
      * Remove the GPL additional wording as SPDX-License-Identifier is
        already in place.
      * Remove the WARN_ON calls.
      * Remove linux/bug include that is not needed.
      * Update static calls sanity checks.
      * Remove "ratelimited" from the logs that are not in the ioctl call
        paths.
      * Update kzfree() calls to kfree().
      
      v1 -> v2
      
      * Add log pattern for NE.
      * Update PCI device setup functions to receive PCI device data structure and
        then get private data from it inside the functions logic.
      * Remove the BUG_ON calls.
      * Add teardown function for MSI-X setup.
      * Update goto labels to match their purpose.
      * Implement TODO for NE PCI device disable state check.
      * Update function name for NE PCI device probe / remove.
      Reviewed-by: default avatarAlexander Graf <graf@amazon.com>
      Signed-off-by: default avatarAlexandru-Catalin Vasile <lexnv@amazon.com>
      Signed-off-by: default avatarAlexandru Ciobotaru <alcioa@amazon.com>
      Signed-off-by: default avatarAndra Paraschiv <andraprs@amazon.com>
      Link: https://lore.kernel.org/r/20200921121732.44291-5-andraprs@amazon.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      89308c11
    • Andra Paraschiv's avatar
      nitro_enclaves: Define enclave info for internal bookkeeping · 1df62489
      Andra Paraschiv authored
      The Nitro Enclaves driver keeps an internal info per each enclave.
      
      This is needed to be able to manage enclave resources state, enclave
      notifications and have a reference of the PCI device that handles
      command requests for enclave lifetime management.
      
      Changelog
      
      v9 -> v10
      
      * Update commit message to include the changelog before the SoB tag(s).
      
      v8 -> v9
      
      * Add data structure to keep references to both Nitro Enclaves misc and
        PCI devices.
      
      v7 -> v8
      
      * No changes.
      
      v6 -> v7
      
      * Update the naming and add more comments to make more clear the logic
        of handling full CPU cores and dedicating them to the enclave.
      
      v5 -> v6
      
      * Update documentation to kernel-doc format.
      * Include in the enclave memory region data structure the user space
        address and size for duplicate user space memory regions checks.
      
      v4 -> v5
      
      * Include enclave cores field in the enclave metadata.
      * Update the vCPU ids data structure to be a cpumask instead of a list.
      
      v3 -> v4
      
      * Add NUMA node field for an enclave metadata as the enclave memory and
        CPUs need to be from the same NUMA node.
      
      v2 -> v3
      
      * Remove the GPL additional wording as SPDX-License-Identifier is
        already in place.
      
      v1 -> v2
      
      * Add enclave memory regions and vcpus count for enclave bookkeeping.
      * Update ne_state comments to reflect NE_START_ENCLAVE ioctl naming
        update.
      Reviewed-by: default avatarAlexander Graf <graf@amazon.com>
      Signed-off-by: default avatarAlexandru-Catalin Vasile <lexnv@amazon.com>
      Signed-off-by: default avatarAndra Paraschiv <andraprs@amazon.com>
      Link: https://lore.kernel.org/r/20200921121732.44291-4-andraprs@amazon.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1df62489
    • Andra Paraschiv's avatar
      nitro_enclaves: Define the PCI device interface · 0a445617
      Andra Paraschiv authored
      The Nitro Enclaves (NE) driver communicates with a new PCI device, that
      is exposed to a virtual machine (VM) and handles commands meant for
      handling enclaves lifetime e.g. creation, termination, setting memory
      regions. The communication with the PCI device is handled using a MMIO
      space and MSI-X interrupts.
      
      This device communicates with the hypervisor on the host, where the VM
      that spawned the enclave itself runs, e.g. to launch a VM that is used
      for the enclave.
      
      Define the MMIO space of the NE PCI device, the commands that are
      provided by this device. Add an internal data structure used as private
      data for the PCI device driver and the function for the PCI device
      command requests handling.
      
      Changelog
      
      v9 -> v10
      
      * Update commit message to include the changelog before the SoB tag(s).
      
      v8 -> v9
      
      * Fix indent for the NE PCI device command types enum.
      
      v7 -> v8
      
      * No changes.
      
      v6 -> v7
      
      * Update the documentation to include references to the NE PCI device id
        and MMIO bar.
      
      v5 -> v6
      
      * Update documentation to kernel-doc format.
      
      v4 -> v5
      
      * Add a TODO for including flags in the request to the NE PCI device to
        set a memory region for an enclave. It is not used for now.
      
      v3 -> v4
      
      * Remove the "packed" attribute and include padding in the NE data
        structures.
      
      v2 -> v3
      
      * Remove the GPL additional wording as SPDX-License-Identifier is
        already in place.
      
      v1 -> v2
      
      * Update path naming to drivers/virt/nitro_enclaves.
      * Update NE_ENABLE_OFF / NE_ENABLE_ON defines.
      Reviewed-by: default avatarAlexander Graf <graf@amazon.com>
      Signed-off-by: default avatarAlexandru-Catalin Vasile <lexnv@amazon.com>
      Signed-off-by: default avatarAlexandru Ciobotaru <alcioa@amazon.com>
      Signed-off-by: default avatarAndra Paraschiv <andraprs@amazon.com>
      Link: https://lore.kernel.org/r/20200921121732.44291-3-andraprs@amazon.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0a445617
    • Andra Paraschiv's avatar
      nitro_enclaves: Add ioctl interface definition · 15b760c3
      Andra Paraschiv authored
      The Nitro Enclaves driver handles the enclave lifetime management. This
      includes enclave creation, termination and setting up its resources such
      as memory and CPU.
      
      An enclave runs alongside the VM that spawned it. It is abstracted as a
      process running in the VM that launched it. The process interacts with
      the NE driver, that exposes an ioctl interface for creating an enclave
      and setting up its resources.
      
      Changelog
      
      v9 -> v10
      
      * Update commit message to include the changelog before the SoB tag(s).
      
      v8 -> v9
      
      * No changes.
      
      v7 -> v8
      
      * Add NE custom error codes for user space memory regions not backed by
        pages multiple of 2 MiB, invalid flags and enclave CID.
      * Add max flag value for enclave image load info.
      
      v6 -> v7
      
      * Clarify in the ioctls documentation that the return value is -1 and
        errno is set on failure.
      * Update the error code value for NE_ERR_INVALID_MEM_REGION_SIZE as it
        gets in user space as value 25 (ENOTTY) instead of 515. Update the
        NE custom error codes values range to not be the same as the ones
        defined in include/linux/errno.h, although these are not propagated
        to user space.
      
      v5 -> v6
      
      * Fix typo in the description about the NE CPU pool.
      * Update documentation to kernel-doc format.
      * Remove the ioctl to query API version.
      
      v4 -> v5
      
      * Add more details about the ioctl calls usage e.g. error codes, file
        descriptors used.
      * Update the ioctl to set an enclave vCPU to not return a file
        descriptor.
      * Add specific NE error codes.
      
      v3 -> v4
      
      * Decouple NE ioctl interface from KVM API.
      * Add NE API version and the corresponding ioctl call.
      * Add enclave / image load flags options.
      
      v2 -> v3
      
      * Remove the GPL additional wording as SPDX-License-Identifier is
        already in place.
      
      v1 -> v2
      
      * Add ioctl for getting enclave image load metadata.
      * Update NE_ENCLAVE_START ioctl name to NE_START_ENCLAVE.
      * Add entry in Documentation/userspace-api/ioctl/ioctl-number.rst for NE
        ioctls.
      * Update NE ioctls definition based on the updated ioctl range for major
        and minor.
      Reviewed-by: default avatarAlexander Graf <graf@amazon.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarAlexandru Vasile <lexnv@amazon.com>
      Signed-off-by: default avatarAndra Paraschiv <andraprs@amazon.com>
      Link: https://lore.kernel.org/r/20200921121732.44291-2-andraprs@amazon.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      15b760c3
  2. 17 Sep, 2020 23 commits
  3. 16 Sep, 2020 7 commits
  4. 14 Sep, 2020 2 commits