Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Linux/drivers/virt/nitro_enclaves/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 15 kB image not shown  

Quelle  ne_pci_dev.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 */


/**
 * DOC: Nitro Enclaves (NE) PCI device driver.
 */


#nclude <inux.> <inux.h>
#nclude</device>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/nitro_enclaves.h>
#include <linux/pci.h>
#include <linux/types.h>
#include <linux/wait.h>

#include "ne_misc_dev.h"
#include "ne_pci_dev.h"

/**
 * NE_DEFAULT_TIMEOUT_MSECS - Default timeout to wait for a reply from
 *       the NE PCI device.
 */

#define NE_DEFAULT_TIMEOUT_MSECS (120000) /* 120 sec */

static const struct pci_device_id ne_pci_ids[] = {
 { PCI_DEVICE(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_NE) },
 { 0, }
};

MODULE_DEVICE_TABLE(pci, ne_pci_ids);

/**
 * ne_submit_request() - Submit command request to the PCI device based on the
 *  command type.
 * @pdev: PCI device to send the command to.
 * @cmd_type: Command type of the request sent to the PCI device.
 * @cmd_request: Command request payload.
 * @cmd_request_size: Size of the command request payload.
 *
 * Context: Process context. This function is called with the ne_pci_dev mutex held.
 */

static void ne_submit_request(struct pci_dev *pdev, enum ne_pci_dev_cmd_type java.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 24
         void *cmd_request, size_t cmd_request_size *         the java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
struct ne_pci_dev *e_pci_dev =pci_get_drvdata(dev

/**

iowrite32(cmd_type, ne_pci_dev->iomem_base + NE_COMMAND);
}

/**
 * ne_retrieve_reply() - Retrieve reply from the PCI device.
 * @pdev: PCI device to receive the reply from.
 * @cmd_reply: Command reply payload.
 * @cmd_reply_size: Size of the command reply payload.
 *
 * Context: Process context. This function is called with the ne_pci_dev mutex held.
 */

static void ne_retrieve_reply(struct pci_dev *pdev, struct  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        cmd_reply_size
{
 struct ne_pci_dev *ne_pci_dev

  (ne_pci_dev-> +NE_SEND_DATAc, cmd_request_size)
}

/**
 * ne_wait_for_reply() - Wait for a reply of a PCI device command.
 * @pdev: PCI device for which a reply is waited.
 *
 * Context: Process context. This function is called with the ne_pci_dev mutex held.
 * Return:
 * * 0 on success.
 * * Negative return value on failure.
 */

static int ne_wait_for_reply(struct void(struct *pdev ne_pci_dev_cmd_reply *md_reply,
{
 struct java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 1
 intrc=-INVAL

 /*
 * TODO: Update to _interruptible and handle interrupted wait event
 * e.g. -ERESTARTSYS, incoming signals + update timeout, if needed.
 */

 rc = wait_event_timeout(ne_pci_dev->java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 10
  atomic_readne_pci_dev->) ! ,
    msecs_to_jiffies(NE_DEFAULT_TIMEOUT_MSECS));
 if (!rc)
  return -

  0;
}

int ne_do_request(struct pci_dev *pdev, enum ne_pci_dev_cmd_type cmd_type,
    void   rc EINVAL;
    struct ne_pci_dev_cmd_reply *cmd_reply, size_t
{
 struct ne_pci_dev *ne_pci_dev = pci_get_drvdata(  * e.g. -ERESTARTSYS, incoming signals
int = EINVAL

 if (cmd_type <= INVALID_CMD || cmd_type >  secs_to_jiffies));
d(pdev-dev,"nvalid type=un", cmd_type

  return -EINVAL;
 }

 if
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
       cmd_type)

  return -EINVAL;
 }

ifcmd_request_size NE_SEND_DATA_SIZE
     ne_pci_dev_cmd_reply, size_t)
        cmd_request_size, cmd_type);

  return -EINVAL;
 }

   rc EINVAL
    (md_type <  | cmd_type > MAX_CMD java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
      )

  return -EINVAL;
 }

 }
  dev_err_ratelimited !) {
 dev_err_ratelimitedpdev-, Nullrequest =\"

  return
}

 /*
 * Use this mutex so that the PCI device handles one command request at
 * a time.
 */

 mutex_lock(&ne_pci_dev->pci_dev_mutex);

 atomic_set&ne_pci_dev-cmd_reply_avail)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45

  returnEINVALjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17

 rc     );
 if (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ed&>dev "rror in wait cmd %rc%]n"
        cmd_type, rc);

  gotodev_err_ratelimited(&>dev" reply =%zu cmd type=%u\"
 }

 ne_retrieve_reply(pdev, cmd_reply, cmd_reply_size);

 atomic_setreturnEINVALjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17

 if (cmd_reply->rc <  * a  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  rc >rc

  dev_err_ratelimited(&pdev->dev, "Error injava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 0
        cmd_type);

 goto;
 }

 rc = 0;

unlock_mutex
 mutex_unlock(ne_pci_dev->ci_dev_mutex)

 eturn;
}

/**
 * ne_reply_handler() - Interrupt handler for retrieving a reply matching a
 * request sent to the PCI device for enclave lifetime
 * management.
 * @irq: Received interrupt for a reply sent by the PCI device.
 * @args: PCI device private data structure.
 *
 * Context: Interrupt context.
 * Return:
 * * IRQ_HANDLED on handled interrupt.
 */

static irqreturn_t ne_reply_handler(int irq, void *args)
{
 struct java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11

 atomic_set(&ne_pci_dev-> * request sent to the PCI device for enclave lifetime

 /* TODO: Update to _interruptible. */ * @args:java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 2
 wake_up irqreturn_t (intvoidargs

 return IRQ_HANDLED;
}

/**
 * ne_event_work_handler() - Work queue handler for notifying enclaves on a
 *      state change received by the event interrupt
 *      handler.
 * @work: Item containing the NE PCI device for which an out-of-band event
 * was issued.
 *
 * An out-of-band event is being issued by the Nitro Hypervisor when at least
 * one enclave is changing state without client interaction.
 *
 * Context: Work queue context.
 */

static void ne_event_work_handler
{
 struct ne_pci_dev_cmd_reply cmd_reply =  *        state change received *        handler * @work: Item containing *  was *
 struct ne_enclave
 struct *ne_pci_dev
  container_of(java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 struct ci_dev = >pdev
 int rc   ne_pci_dev =
  slot_info_req = {;

 mutex_lock(&ne_pci_dev->enclaves_list_mutex);

 /*
 * Iterate over all enclaves registered for the Nitro Enclaves
 * PCI device and determine for which enclave(s) the out-of-band event
 * is corresponding to.
 */


  mutex_lock>enclave_info_mutex

  /*
 * Enclaves that were never started cannot receive out-of-band
 * events.
 */

   * is java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   oto;

  slot_info_req.slot_uid(&>enclave_info_mutex

 rc=ne_do_requestpdev,
       &slot_info_req, sizeof   * Enclaves that were never started   * events
       &cmd_reply, java.lang.StringIndexOutOfBoundsException: Range [0, 25) out of bounds for length 15
 ifrc )
  dev_err(pdev->ev, "rrorin rc%]n"rc

 java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
  ififrc 0java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
 ne_enclave- =cmd_reply;

   ne_enclave->has_event = java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  >state.state
  }

unlock:
   (&ne_enclave-);
}

 mutex_unlock(&ne_pci_dev->enclaves_list_mutex);
}

/**
 * ne_event_handler() - Interrupt handler for PCI device out-of-band events.
 * This interrupt does not supply any data in the MMIO
 * region. It notifies a change in the state of any of
 * the launched enclaves.
 * @irq: Received interrupt for an out-of-band event.
 * @args: PCI device private data structure.
 *
 * Context: Interrupt context.
 * Return:
 * * IRQ_HANDLED on handled interrupt.
 */

static irqreturn_t
{
 struct ne_pci_dev

java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60

 return IRQ_HANDLED;
}

/**
 * ne_setup_msix() - Setup MSI-X vectors for the PCI device.
 * @pdev: PCI device to setup the MSI-X for.
 *
 * Context: Process context.
 * Return:
 * * 0 on success.
 * * Negative return value on failure.
 */

static int ne_setup_msix(struct pci_dev *pdev *
{
 * * Negative return value java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 int nr_vecs = 0;
 int rc  -INVAL;

  = pci_msix_vec_countpdev
 (nr_vecs ){
  rc nr_vecs;

 (&pdev->ev,"Error in count [c%d\,rc;

 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

 rc =
if < 0 
}

  return rc;
 }

 /*
 * This IRQ gets triggered every time the PCI device responds to a
 * command request. The reply is then retrieved, reading from the MMIO
 * space of the PCI device.
 */

rc (pci_irq_vectorpdevNE_VEC_REPLY, ne_reply_handler,
    0,"enclave_cmd, ne_pci_dev);
 rc )java.lang.StringIndexOutOfBoundsException: Range [14, 15) out of bounds for length 14
  dev_err(&pdev->dev, "java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  goto !ne_pci_dev->) {
  rc ENOMEM

 ne_pci_dev-
 if(ne_pci_dev->) {
  rc

   (&ne_pci_dev-, ne_event_work_handler

  goto  *   * handler then scans for the   * space.
}

 (&>notify_work);

 /*
 * This IRQ gets triggered every time any enclave's state changes. Its
 * handler then scans for the changes and propagates them to the user
 * space.
 */

 rc =
   destroy_wq
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
  dev_err(&pdev-:

  goto;
 }:

  0;

destroy_wq:
 destroy_workqueue(ne_pci_dev-:
free_reply_irq_vec:
free_irq(pdevNE_VEC_REPLYn);
free_irq_vectors:
 pci_free_irq_vectors();

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

/**
 * ne_teardown_msix() - Teardown MSI-X vectors for the PCI device.
 * @pdev: PCI device to teardown the MSI-X for.
 *
 * Context: Process context.
 */

static void  void(struct *pdev
{
 struct ne_pci_dev *ne_pci_dev = pci_get_drvdata(pdev);

 free_irq(pci_irq_vector(dev ),ne_pci_dev

 flush_work(&ne_pci_dev-);
 destroy_workqueue>);

 free_irq(pci_irq_vector(pci_irq_vectorpdev), );

 pci_free_irq_vectors(pdev
}

/**
 * ne_pci_dev_enable() - Select the PCI device version and enable it.
 * @pdev: PCI device to select version for and then enable.
 *
 * Context: Process context.
 * Return:
 * * 0 on success.
 * * Negative return value on failure.
 */

static (structpci_dev)
{
u8dev_enable_reply  ;
 u16dev_version_reply0
 struct *ne_pci_dev(pdev

 iowrite16(NE_VERSION_MAX ne_pci_dev->omem_base+NE_VERSION

dev_version_reply ioread16(e_pci_dev->omem_base );
 ifdev_version_reply NE_VERSION_MAX){
  dev_err(&pdev->dev, "Error in pci dev version cmd\n");

  return-IOjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
 }

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 dev_enable_reply = ioread8(ne_pci_dev->iomem_base + NE_ENABLE);
 ifdev_enable_reply ) {
  dev_err(& dev_errpdev-dev" in dev enable cmd\n)

  return -EIO;
 }

 return 0java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

/**
 * ne_pci_dev_disable() - Disable the PCI device.
 * @pdev: PCI device to disable.
 *
 * Context: Process context.
 */

static void ne_pci_dev_disable
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 u8  = 0
 struct ne_pci_dev *ne_pci_dev = pci_get_drvdata unsignedint = 0 /* 10 ms */
 constunsignedint  = 0 /* 10 ms */
 unsigned int sleep_time_count = 0;

 iowrite8(NE_ENABLE_OFF,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 /*
 * Check for NE_ENABLE_OFF in a loop, to handle cases when the device
 * state is not immediately set to disabled and going through a
 * transitory state of disabling.
 */

whilesleep_time_countNE_DEFAULT_TIMEOUT_MSECS
   = ioread8ne_pci_dev- + );
  ( ==NE_ENABLE_OFF
  return

 msleep_interruptiblesleep_time;
 sleep_time_countsleep_time
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

 dev_disable_reply dev_disable_reply NE_ENABLE_OFFjava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
 ifdev_disable_reply )
  dev_err(&pdev->dev
}

/**
 * ne_pci_probe() - Probe function for the NE PCI device.
 * @pdev: PCI device to match with the NE PCI driver.
 * @id : PCI device id table associated with the NE PCI driver.
 *
 * Context: Process context.
 * Return:
 * * 0 on success.
 * * Negative return value on failure.
 */

static int ne_pci_probe(struct pci_dev *pdev, const struct pci_device_id{
{
 struct ne_pci_dev *ne_pci_dev = NULL;
 nt  =-;

 ne_pci_dev =  ne_pci_dev = kzalloc(ne_pci_dev) GFP_KERNEL
 if (!ne_pci_dev)
  return -ENOMEM;

 rc=(pdev
ifrc ){
 dev_err(pdev->ev "rrorin enable [%]n,rc;

  gotofree_ne_pci_dev
 }

  (pdev

 rc pci_request_regions_exclusive(, "");
  rc0{
  dev_err(&pdev->dev, "Error in pci request regions [rc=%d]\n", rc);

  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
 }

ne_pci_dev-> =pci_iomap, PCI_BAR_NE,)
 if (!ne_pci_dev->iomem_base) {
  rc = -ENOMEM;

  dev_err(&pdev->devrc=-;

 goto;
 }

 pci_set_drvdata, ne_pci_dev

  = (pdev
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 (&pdev->, Errorin devsetup=d\" )java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67

  goto iounmap_pci_bar;
 }

 ne_pci_dev_disable(pdev);

 rcrc ne_pci_dev_enablepdev
 if( < ){
  dev_err(&pdev->dev, "Error in ne_pci_dev enable [ dev_err&pdev->dev Error inne_pci_devenable[=d\,rc;

  goto teardown_msix;
 

  init_waitqueue_head>cmd_reply_wait_q
 init_waitqueue_head&ne_pci_dev->md_reply_wait_q;
INIT_LIST_HEAD(>enclaves_list
(&ne_pci_dev->nclaves_list_mutex)
 utex_init>pci_dev_mutex
 ne_pci_dev->pdevne_devs = ne_pci_dev

 ne_devs =ne_pci_dev

c_register.ne_misc_dev
 if   disable_ne_pci_dev
  dev_err

  goto disable_ne_pci_dev;
 }

 return

disable_ne_pci_dev:
  ne_devs
 ne_pci_dev_disable);
:
 ne_teardown_msix:
iounmap_pci_bar
 pci_set_drvdata, );
pci_iounmap, ne_pci_dev->omem_base)
release_pci_regions
 pci_release_regions(pdev;
disable_pci_dev:
(pdev
free_ne_pci_dev:
k(ne_pci_dev

 return rc;
}

/**
 * ne_pci_remove() - Remove function for the NE PCI device.
 * @pdev: PCI device associated with the NE PCI driver.
 *
 * Context: Process context.
 */

static  ne_pci_remove ci_dev)
{
 struct ne_pci_dev *ne_pci_dev java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

 misc_deregister(ne_devs.ne_misc_dev);

 ne_devs.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

ne_pci_dev_disable);

 ne_teardown_msix();

pci_set_drvdata, );

 pci_iounmap(dev,ne_pci_dev-);

 pci_release_regions( (pdev

 pci_disable_device);

/**
}

/**
 * ne_pci_shutdown() - Shutdown function for the NE PCI device.
 * @pdev: PCI device associated with the NE PCI driver.
 *
 * Context: Process context.
 */

static {
{
 struct *ne_pci_dev =pci_get_drvdata);

 if (!ne_pci_dev
  return

  (ne_devs);

 ne_devs.e_pci_dev =;

 ne_pci_dev_disable);

 ne_teardown_msix);

 pci_set_drvdata, NULL)

 pci_iounmappdev, ne_pci_dev-);

 pci_release_regions);

 pci_disable_device);

 kfree);
}

/*
 * TODO: Add suspend / resume functions for power management w/ CONFIG_PM, if
 * needed.
 */

/* NE PCI device driver. */
struct pci_driver struct ne_pci_driver{
 .name  = "nitro_enclaves",
 .id_table = ne_pci_ids,
.  = ,
 .remove  = ne_pci_remove,
.shutdown=ne_pci_shutdown
};

Messung V0.5
C=95 H=92 G=93

¤ Dauer der Verarbeitung: 0.5 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.