1. 19 7月, 2022 4 次提交
    • T
      s390/vfio-ap: introduce shadow APCB · 49b0109f
      Tony Krowiak 提交于
      The APCB is a field within the CRYCB that provides the AP configuration
      to a KVM guest. Let's introduce a shadow copy of the KVM guest's APCB and
      maintain it for the lifespan of the guest.
      
      The shadow APCB serves the following purposes:
      
      1. The shadow APCB can be maintained even when the mediated device is not
         currently in use by a KVM guest. Since the mediated device's AP
         configuration is filtered to ensure that no AP queues are passed through
         to the KVM guest that are not bound to the vfio_ap device driver or
         available to the host, the mediated device's AP configuration may differ
         from the guest's. Having a shadow of a guest's APCB allows us to provide
         a sysfs interface to view the guest's APCB even if the mediated device
         is not currently passed through to a KVM guest. This can aid in
         problem determination when the guest is unexpectedly missing AP
         resources.
      
      2. If filtering was done in-place for the real APCB, the guest could pick
         up a transient state. Doing the filtering on a shadow and transferring
         the AP configuration to the real APCB after the guest is started or when
         AP resources are assigned to or unassigned from the mediated device, or
         when the host configuration changes, the guest's AP configuration will
         never be in a transient state.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NHalil Pasic <pasic@linux.ibm.com>
      Signed-off-by: NAlexander Gordeev <agordeev@linux.ibm.com>
      49b0109f
    • T
      s390/vfio-ap: manage link between queue struct and matrix mdev · 11cb2419
      Tony Krowiak 提交于
      Let's create links between each queue device bound to the vfio_ap device
      driver and the matrix mdev to which the queue's APQN is assigned. The idea
      is to facilitate efficient retrieval of the objects representing the queue
      devices and matrix mdevs as well as to verify that a queue assigned to
      a matrix mdev is bound to the driver.
      
      The links will be created as follows:
      
       * When the queue device is probed, if its APQN is assigned to a matrix
         mdev, the structures representing the queue device and the matrix mdev
         will be linked.
      
       * When an adapter or domain is assigned to a matrix mdev, for each new
         APQN assigned that references a queue device bound to the vfio_ap
         device driver, the structures representing the queue device and the
         matrix mdev will be linked.
      
      The links will be removed as follows:
      
       * When the queue device is removed, if its APQN is assigned to a matrix
         mdev, the link from the structure representing the matrix mdev to the
         structure representing the queue will be removed. Since the storage
         allocated for the vfio_ap_queue will be freed, there is no need to
         remove the link to the matrix_mdev to which the queue's APQN is
         assigned.
      
       * When an adapter or domain is unassigned from a matrix mdev, for each
         APQN unassigned that references a queue device bound to the vfio_ap
         device driver, the structures representing the queue device and the
         matrix mdev will be unlinked.
      
       * When an mdev is removed, the link from any queues assigned to the mdev
         to the mdev will be removed.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NHalil Pasic <pasic@linux.ibm.com>
      Signed-off-by: NAlexander Gordeev <agordeev@linux.ibm.com>
      11cb2419
    • T
      s390/vfio-ap: move probe and remove callbacks to vfio_ap_ops.c · 260f3ea1
      Tony Krowiak 提交于
      Let's move the probe and remove callbacks into the vfio_ap_ops.c
      file to keep all code related to managing queues in a single file. This
      way, all functions related to queue management can be removed from the
      vfio_ap_private.h header file defining the public interfaces for the
      vfio_ap device driver.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NHalil Pasic <pasic@linux.ibm.com>
      Signed-off-by: NAlexander Gordeev <agordeev@linux.ibm.com>
      260f3ea1
    • T
      s390/vfio-ap: use new AP bus interface to search for queue devices · 034921cd
      Tony Krowiak 提交于
      This patch refactors the vfio_ap device driver to use the AP bus's
      ap_get_qdev() function to retrieve the vfio_ap_queue struct containing
      information about a queue that is bound to the vfio_ap device driver.
      The bus's ap_get_qdev() function retrieves the queue device from a
      hashtable keyed by APQN. This is much more efficient than looping over
      the list of devices attached to the AP bus by several orders of
      magnitude.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NHalil Pasic <pasic@linux.ibm.com>
      Reviewed-by: NJason J. Herne <jjherne@linux.ibm.com>
      Signed-off-by: NAlexander Gordeev <agordeev@linux.ibm.com>
      034921cd
  2. 24 5月, 2022 1 次提交
  3. 12 5月, 2022 2 次提交
  4. 21 4月, 2022 1 次提交
  5. 28 3月, 2022 1 次提交
    • T
      s390/vfio-ap: fix kernel doc and signature of group notifier functions · 71078220
      Tony Krowiak 提交于
      The vfio_ap device driver registers a group notifier function to handle
      the VFIO_GROUP_NOTIFY_SET_KVM event signalling the KVM pointer has been
      set or cleared. There are two helper functions invoked by the handler
      function: One called when the KVM pointer has been set, and the other
      when the pointer is cleared.
      
      The kernel doc for both of these functions contains a comment introduced
      by commit 0cc00c8d (s390/vfio-ap: fix circular lockdep when
      setting/clearing crypto masks) that is no longer valid. This patch removes
      this comment from the kernel doc of each helper function.
      
      Commit 86956e70 (s390/vfio-ap: replace open coded locks for
      VFIO_GROUP_NOTIFY_SET_KVM notification) added a parameter to the signature
      of the helper function that handles the event indicating the KVM pointer
      has been cleared. The parameter added was the KVM pointer itself.
      One of the function's primary purposes is to clear the KVM pointer from the
      ap_matrix_mdev instance in which it is stored. Since the callers of this
      function derive the KVM pointer passed to the function from the
      ap_matrix_mdev object itself, it is completely unnecessary to include this
      parameter in the function's signature since it can simply be retrieved from
      the ap_matrix_mdev object which is also passed in. This patch removes the
      KVM pointer from the function's signature.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      71078220
  6. 07 2月, 2022 2 次提交
    • T
      s390/vfio-ap: add s390dbf logging to the vfio_ap_irq_enable function · 783f0a3c
      Tony Krowiak 提交于
      This patch adds s390dbf logging to the function that executes the
      PQAP(AQIC) instruction on behalf of the guest to which the queue for which
      interrupts are being enabled or disabled is attached.
      
      Currently, the vfio_ap_irq_enable function sets status response code 06
      (notification indicator byte address (nib) invalid) in the status word
      when the vfio_pin_pages function - called to pin the page containing the
      nib - returns an error or a different number of pages pinned than
      requested.
      
      Setting the response code returned to userspace without also logging a
      message in the kernel makes it impossible to determine whether the response
      was due to an error detected by the vfio_ap device driver or because the
      response code was returned by the firmware in response to the PQAP(AQIC)
      instruction.
      
      In addition to logging a warning for the situation above, this patch adds
      the following:
      
      * A function to validate the nib address invoked prior to calling the
        vfio_pin_pages function. This allows for logging a message informing
        the reader of the reason the page containing the nib can not be pinned
        if the nib address is not valid. Response code 06 (invalid nib address)
        will be set in the status word returned to the guest from the
        instruction.
      
      * Checks the return value from the kvm_s390_gisc_register and logs a
        message informing the reader of the failure. Status response code 08
        (invalid gisa) will be set in the status word returned to the guest from
        the PQAP(AQIC) instruction.
      
      * Checks the status response code returned from execution of the PQAP(AQIC)
        instruction and if it indicates an error, logs a message informing the
        reader.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NMatthew Rosato <mjrosato@linux.ibm.com>
      Acked-by: NHeiko Carstens <hca@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      783f0a3c
    • T
      s390/vfio-ap: add s390dbf logging to the handle_pqap function · 68f554b7
      Tony Krowiak 提交于
      This patch adds s390dbf logging to the function that handles interception
      of the PQAP(AQIC) instruction. Several items of data are validated before
      ultimately calling the functions that execute the PQAP(AQIC) instruction on
      behalf of the guest to which the queue for which interrupts are being
      enabled or disabled is attached.
      
      Currently, the handle_pqap function sets status response code 01 (queue not
      available) in the status word that is normally returned from the
      PQAP(AQIC) instruction under the following conditions:
      
      * Set when the function pointer to the handler is not set in the
        kvm_s390_crypto object (i.e., the PQAP hook is not registered).
      
      * Set when the KVM pointer is not set in the ap_matrix_mdev object
        (i.e., the matrix mdev is not passed through to a guest).
      
      * Set when the queue for which interrupts are being enabled or
        disabled is either not bound to the vfio_ap device driver or not assigned
        to the matrix mdev.
      
      Setting the response code returned to userspace without also logging a
      message in the kernel makes it impossible to determine whether the response
      was due to an error detected by the vfio_ap device driver or because the
      response code was returned by the firmware in response to the PQAP(AQIC)
      instruction, so this patch logs a message to the s390dbf log for the
      vfio_ap device driver for each of the situations described above.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NMatthew Rosato <mjrosato@linux.ibm.com>
      Acked-by: NHeiko Carstens <hca@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      68f554b7
  7. 26 10月, 2021 1 次提交
  8. 01 10月, 2021 1 次提交
  9. 25 9月, 2021 1 次提交
  10. 26 8月, 2021 1 次提交
  11. 25 8月, 2021 3 次提交
  12. 11 8月, 2021 1 次提交
  13. 21 6月, 2021 1 次提交
  14. 13 4月, 2021 2 次提交
  15. 05 4月, 2021 1 次提交
    • T
      s390/vfio-ap: fix circular lockdep when setting/clearing crypto masks · 0cc00c8d
      Tony Krowiak 提交于
      This patch fixes a lockdep splat introduced by commit f21916ec
      ("s390/vfio-ap: clean up vfio_ap resources when KVM pointer invalidated").
      The lockdep splat only occurs when starting a Secure Execution guest.
      Crypto virtualization (vfio_ap) is not yet supported for SE guests;
      however, in order to avoid this problem when support becomes available,
      this fix is being provided.
      
      The circular locking dependency was introduced when the setting of the
      masks in the guest's APCB was executed while holding the matrix_dev->lock.
      While the lock is definitely needed to protect the setting/unsetting of the
      matrix_mdev->kvm pointer, it is not necessarily critical for setting the
      masks; so, the matrix_dev->lock will be released while the masks are being
      set or cleared.
      
      Keep in mind, however, that another process that takes the matrix_dev->lock
      can get control while the masks in the guest's APCB are being set or
      cleared as a result of the driver being notified that the KVM pointer
      has been set or unset. This could result in invalid access to the
      matrix_mdev->kvm pointer by the intervening process. To avoid this
      scenario, two new fields are being added to the ap_matrix_mdev struct:
      
      struct ap_matrix_mdev {
      	...
      	bool kvm_busy;
      	wait_queue_head_t wait_for_kvm;
         ...
      };
      
      The functions that handle notification that the KVM pointer value has
      been set or cleared will set the kvm_busy flag to true until they are done
      processing at which time they will set it to false and wake up the tasks on
      the matrix_mdev->wait_for_kvm wait queue. Functions that require
      access to matrix_mdev->kvm will sleep on the wait queue until they are
      awakened at which time they can safely access the matrix_mdev->kvm
      field.
      
      Fixes: f21916ec ("s390/vfio-ap: clean up vfio_ap resources when KVM pointer invalidated")
      Cc: stable@vger.kernel.org
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Signed-off-by: NHeiko Carstens <hca@linux.ibm.com>
      0cc00c8d
  16. 08 3月, 2021 1 次提交
  17. 27 1月, 2021 2 次提交
  18. 25 3月, 2020 1 次提交
  19. 05 9月, 2019 1 次提交
  20. 12 7月, 2019 1 次提交
  21. 02 7月, 2019 2 次提交
  22. 22 2月, 2019 1 次提交
  23. 08 10月, 2018 1 次提交
  24. 05 10月, 2018 1 次提交
  25. 28 9月, 2018 4 次提交
  26. 27 9月, 2018 2 次提交
    • T
      s390: vfio-ap: sysfs interface to view matrix mdev matrix · 81b2b4b7
      Tony Krowiak 提交于
      Provides a sysfs interface to view the AP matrix configured for the
      mediated matrix device.
      
      The relevant sysfs structures are:
      
      /sys/devices/vfio_ap/matrix/
      ...... [mdev_supported_types]
      ......... [vfio_ap-passthrough]
      ............ [devices]
      ...............[$uuid]
      .................. matrix
      
      To view the matrix configured for the mediated matrix device,
      print the matrix file:
      
      	cat matrix
      
      Below are examples of the output from the above command:
      
      Example 1: Adapters and domains assigned
      	Assignments:
      		Adapters 5 and 6
      		Domains 4 and 71 (0x47)
      
      	Output
      		05.0004
      		05.0047
      		06.0004
      	06.0047
      
      Examples 2: Only adapters assigned
      	Assignments:
      		Adapters 5 and 6
      
      	Output:
      		05.
      		06.
      
      Examples 3: Only domains assigned
      	Assignments:
      		Domains 4 and 71 (0x47)
      
      	Output:
      		.0004
      		.0047
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NHalil Pasic <pasic@linux.ibm.com>
      Reviewed-by: NCornelia Huck <cohuck@redhat.com>
      Tested-by: NMichael Mueller <mimu@linux.ibm.com>
      Tested-by: NFarhan Ali <alifm@linux.ibm.com>
      Tested-by: NPierre Morel <pmorel@linux.ibm.com>
      Message-Id: <20180925231641.4954-10-akrowiak@linux.vnet.ibm.com>
      Signed-off-by: NChristian Borntraeger <borntraeger@de.ibm.com>
      81b2b4b7
    • T
      s390: vfio-ap: sysfs interfaces to configure control domains · 3b1eab7f
      Tony Krowiak 提交于
      Provides the sysfs interfaces for:
      
      1. Assigning AP control domains to the mediated matrix device
      
      2. Unassigning AP control domains from a mediated matrix device
      
      3. Displaying the control domains assigned to a mediated matrix
         device
      
      The IDs of the AP control domains assigned to the mediated matrix
      device are stored in an AP domain mask (ADM). The bits in the ADM,
      from most significant to least significant bit, correspond to
      AP domain numbers 0 to 255. On some systems, the maximum allowable
      domain number may be less than 255 - depending upon the host's
      AP configuration - and assignment may be rejected if the input
      domain ID exceeds the limit.
      
      When a control domain is assigned, the bit corresponding its domain
      ID will be set in the ADM. Likewise, when a domain is unassigned,
      the bit corresponding to its domain ID will be cleared in the ADM.
      
      The relevant sysfs structures are:
      
      /sys/devices/vfio_ap/matrix/
      ...... [mdev_supported_types]
      ......... [vfio_ap-passthrough]
      ............ [devices]
      ...............[$uuid]
      .................. assign_control_domain
      .................. unassign_control_domain
      
      To assign a control domain to the $uuid mediated matrix device's
      ADM, write its domain number to the assign_control_domain file.
      To unassign a domain, write its domain number to the
      unassign_control_domain file. The domain number is specified
      using conventional semantics: If it begins with 0x the number
      will be parsed as a hexadecimal (case insensitive) number;
      if it begins with 0, it is parsed as an octal number;
      otherwise, it will be parsed as a decimal number.
      
      For example, to assign control domain 173 (0xad) to the mediated
      matrix device $uuid:
      
      	echo 173 > assign_control_domain
      
      	or
      
      	echo 0255 > assign_control_domain
      
      	or
      
      	echo 0xad > assign_control_domain
      
      To unassign control domain 173 (0xad):
      
      	echo 173 > unassign_control_domain
      
      	or
      
      	echo 0255 > unassign_control_domain
      
      	or
      
      	echo 0xad > unassign_control_domain
      
      The assignment will be rejected if the APQI exceeds the maximum
      value for an AP domain:
        * If the AP Extended Addressing (APXA) facility is installed,
          the max value is 255
        * Else the max value is 15
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NHalil Pasic <pasic@linux.ibm.com>
      Reviewed-by: NCornelia Huck <cohuck@redhat.com>
      Tested-by: NMichael Mueller <mimu@linux.ibm.com>
      Tested-by: NFarhan Ali <alifm@linux.ibm.com>
      Tested-by: NPierre Morel <pmorel@linux.ibm.com>
      Message-Id: <20180925231641.4954-9-akrowiak@linux.vnet.ibm.com>
      Signed-off-by: NChristian Borntraeger <borntraeger@de.ibm.com>
      3b1eab7f