1. 19 7月, 2022 1 次提交
    • T
      s390/vfio-ap: implement in-use callback for vfio_ap driver · 3f85d1df
      Tony Krowiak 提交于
      Let's implement the callback to indicate when an APQN
      is in use by the vfio_ap device driver. The callback is
      invoked whenever a change to the apmask or aqmask would
      result in one or more queue devices being removed from the driver. The
      vfio_ap device driver will indicate a resource is in use
      if the APQN of any of the queue devices to be removed are assigned to
      any of the matrix mdevs under the driver's control.
      
      There is potential for a deadlock condition between the
      matrix_dev->guests_lock used to lock the guest during assignment of
      adapters and domains and the ap_perms_mutex locked by the AP bus when
      changes are made to the sysfs apmask/aqmask attributes.
      
      The AP Perms lock controls access to the objects that store the adapter
      numbers (ap_perms) and domain numbers (aq_perms) for the sysfs
      /sys/bus/ap/apmask and /sys/bus/ap/aqmask attributes. These attributes
      identify which queues are reserved for the zcrypt default device drivers.
      Before allowing a bit to be removed from either mask, the AP bus must check
      with the vfio_ap device driver to verify that none of the queues are
      assigned to any of its mediated devices.
      
      The apmask/aqmask attributes can be written or read at any time from
      userspace, so care must be taken to prevent a deadlock with asynchronous
      operations that might be taking place in the vfio_ap device driver. For
      example, consider the following:
      
      1. A system administrator assigns an adapter to a mediated device under the
         control of the vfio_ap device driver. The driver will need to first take
         the matrix_dev->guests_lock to potentially hot plug the adapter into
         the KVM guest.
      2. At the same time, a system administrator sets a bit in the sysfs
         /sys/bus/ap/ap_mask attribute. To complete the operation, the AP bus
         must:
         a. Take the ap_perms_mutex lock to update the object storing the values
            for the /sys/bus/ap/ap_mask attribute.
         b. Call the vfio_ap device driver's in-use callback to verify that the
            queues now being reserved for the default zcrypt drivers are not
            assigned to a mediated device owned by the vfio_ap device driver. To
            do the verification, the in-use callback function takes the
            matrix_dev->guests_lock, but has to wait because it is already held
            by the operation in 1 above.
      3. The vfio_ap device driver calls an AP bus function to verify that the
         new queues resulting from the assignment of the adapter in step 1 are
         not reserved for the default zcrypt device driver. This AP bus function
         tries to take the ap_perms_mutex lock but gets stuck waiting for the
         waiting for the lock due to step 2a above.
      
      Consequently, we have the following deadlock situation:
      
      matrix_dev->guests_lock locked (1)
      ap_perms_mutex lock locked (2a)
      Waiting for matrix_dev->gusts_lock (2b) which is currently held (1)
      Waiting for ap_perms_mutex lock (3) which is currently held (2a)
      
      To prevent this deadlock scenario, the function called in step 3 will no
      longer take the ap_perms_mutex lock and require the caller to take the
      lock. The lock will be the first taken by the adapter/domain assignment
      functions in the vfio_ap device driver to maintain the proper locking
      order.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NJason J. Herne <jjherne@linux.ibm.com>
      Signed-off-by: NAlexander Gordeev <agordeev@linux.ibm.com>
      3f85d1df
  2. 25 4月, 2022 2 次提交
    • H
      s390/zcrypt: code cleanup · 2004b57c
      Harald Freudenberger 提交于
      This patch tries to fix as much as possible of the
      checkpatch.pl --strict findings:
        CHECK: Logical continuations should be on the previous line
        CHECK: No space is necessary after a cast
        CHECK: Alignment should match open parenthesis
        CHECK: 'useable' may be misspelled - perhaps 'usable'?
        WARNING: Possible repeated word: 'is'
        CHECK: spaces preferred around that '*' (ctx:VxV)
        CHECK: Comparison to NULL could be written "!msg"
        CHECK: Prefer kzalloc(sizeof(*zc)...) over kzalloc(sizeof(struct...)...)
        CHECK: Unnecessary parentheses around resp_type->work
        CHECK: Avoid CamelCase: <xcRB>
      
      There is no functional change comming with this patch, only
      code cleanup, renaming, whitespaces, indenting, ... but no
      semantic change in any way. Also the API (zcrypt and pkey
      header file) is semantically unchanged.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Reviewed-by: NJürgen Christ <jchrist@linux.ibm.com>
      Signed-off-by: NHeiko Carstens <hca@linux.ibm.com>
      2004b57c
    • H
      s390/ap: uevent on apmask/aqpmask change · d9b38e9d
      Harald Freudenberger 提交于
      This patch introduces user space notifications for changes
      on the apmask or aqmask attributes. So it could be possible
      to write a udev rule to load/unload the vfio_ap kernel module
      based on changes of these masks.
      
      On chance of the apmask or aqmask an AP change event will
      be produced with an uevent environment variable showing
      the new APMASK or AQMASK mask.
      
      So a change on the apmask triggers an uvevent like this:
      
        KERNEL[490.160396] change   /devices/ap (ap)
        ACTION=change
        DEVPATH=/devices/ap
        SUBSYSTEM=ap
        APMASK=0xffffffdfffffffffffffffffffffffffffffffffffffffffffffffffffffffff
        SEQNUM=13367
      
      and a change on the aqmask looks like this:
      
        KERNEL[283.217642] change   /devices/ap (ap)
        ACTION=change
        DEVPATH=/devices/ap
        SUBSYSTEM=ap
        AQMASK=0xfbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
        SEQNUM=13348
      
      Only real changes to the masks are processed - the old and
      new masks are compared and no action is done if the values
      are equal (and thus no uevent). The emit of the uevent is
      the very last action done when a mask change is processed.
      However, there is no guarantee that all unbind/bind actions
      caused by the apmask/aqmask changes are completed when the
      apmask/aqmask change uevent is received in userspace.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Tested-by: NThomas Huth <thuth@redhat.com>
      Reviewed-by: NJürgen Christ <jchrist@linux.ibm.com>
      Signed-off-by: NHeiko Carstens <hca@linux.ibm.com>
      d9b38e9d
  3. 08 3月, 2022 2 次提交
  4. 02 3月, 2022 3 次提交
    • H
      s390/ap: enable sysfs attribute scans to force AP bus rescan · 8944d05f
      Harald Freudenberger 提交于
      This patch switches the sysfs attribute /sys/bus/ap/scans
      from read-only to read-write. If there is something written
      to this attribute, an AP bus rescan is forced. If an AP
      bus scan is triggered this way a debug feature entry line
      reports this in /sys/kernel/debug/s390dbf/ap/sprintf.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Reviewed-by: NJakob Naucke <naucke@linux.ibm.com>
      Reviewed-by: NJuergen Christ <jchrist@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      8944d05f
    • T
      s390/ap: notify drivers on config changed and scan complete callbacks · 28391585
      Tony Krowiak 提交于
      This patch introduces an extension to the ap bus to notify device drivers
      when the host AP configuration changes - i.e., adapters, domains or
      control domains are added or removed. When an adapter or domain is added to
      the host's AP configuration, the AP bus will create the associated queue
      devices in the linux sysfs device model. Each new type 10 (i.e., CEX4) or
      newer queue device with an APQN that is not reserved for the default device
      driver will get bound to the vfio_ap device driver. Likewise, whan an
      adapter or domain is removed from the host's AP configuration, the AP bus
      will remove the associated queue devices from the sysfs device model. Each
      of the queues that is bound to the vfio_ap device driver will get unbound.
      
      With the introduction of hot plug support, binding or unbinding of a
      queue device will result in plugging or unplugging one or more queues from
      a guest that is using the queue. If there are multiple changes to the
      host's AP configuration, it could result in the probe and remove callbacks
      getting invoked multiple times. Each time queues are plugged into or
      unplugged from a guest, the guest's VCPUs must be taken out of SIE.
      If this occurs multiple times due to changes in the host's AP
      configuration, that can have an undesirable negative affect on the guest's
      performance.
      
      To alleviate this problem, this patch introduces two new callbacks: one to
      notify the vfio_ap device driver when the AP bus scan routine detects a
      change to the host's AP configuration; and, one to notify the driver when
      the AP bus is done scanning. This will allow the vfio_ap driver to do
      bulk processing of all affected adapters, domains and control domains for
      affected guests rather than plugging or unplugging them one at a time when
      the probe or remove callback is invoked. The two new callbacks are:
      
      void (*on_config_changed)(struct ap_config_info *new_config_info,
                                struct ap_config_info *old_config_info);
      
      This callback is invoked at the start of the AP bus scan
      function when it determines that the host AP configuration information
      has changed since the previous scan. This is done by storing
      an old and current QCI info struct and comparing them. If there is any
      difference, the callback is invoked.
      
      void (*on_scan_complete)(struct ap_config_info *new_config_info,
                               struct ap_config_info *old_config_info);
      
      The on_scan_complete callback is invoked after the ap bus scan is
      completed if the host AP configuration data has changed.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      28391585
    • T
      s390/ap: driver callback to indicate resource in use · 4f8206b8
      Tony Krowiak 提交于
      Introduces a new driver callback to prevent a root user from re-assigning
      the APQN of a queue that is in use by a non-default host device driver to
      a default host device driver and vice versa. The callback will be invoked
      whenever a change to the AP bus's sysfs apmask or aqmask attributes would
      result in one or more APQNs being re-assigned. If the callback responds
      in the affirmative for any driver queried, the change to the apmask or
      aqmask will be rejected with a device busy error.
      
      For this patch, only non-default drivers will be queried. Currently,
      there is only one non-default driver, the vfio_ap device driver. The
      vfio_ap device driver facilitates pass-through of an AP queue to a
      guest. The idea here is that a guest may be administered by a different
      sysadmin than the host and we don't want AP resources to unexpectedly
      disappear from a guest's AP configuration (i.e., adapters and domains
      assigned to the matrix mdev). This will enforce the proper procedure for
      removing AP resources intended for guest usage which is to
      first unassign them from the matrix mdev, then unbind them from the
      vfio_ap device driver.
      Signed-off-by: NTony Krowiak <akrowiak@linux.ibm.com>
      Reviewed-by: NHarald Freudenberger <freude@linux.ibm.com>
      Reviewed-by: NHalil Pasic <pasic@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      4f8206b8
  5. 26 10月, 2021 3 次提交
    • H
      s390/ap: function rework based on compiler warning · 132c1e74
      Harald Freudenberger 提交于
      Slight rework of function __ap_revise_reserved()
      because of unused variable warning when build with W=1.
      This patch introduces an additional debug feature warning
      message when device_reprobe() returns with failure.
      However, the return value of __ap_revise_reserved()
      is still hard coded to 0 as this is a callback function
      to be used together with bus_for_each_dev() and thus
      the return value indicates to go on with the
      bus_for_each_dev() loop and not apport on a failure
      of something within this function.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      132c1e74
    • H
      s390/ap: new module option ap.useirq · d0982725
      Harald Freudenberger 提交于
      This patch introduces a new AP module option to be able to
      control if the ap bus code is using interrupts or not.
      By default if the interrupt support is available it is used.
      This option makes it possible to disable interrupt use even
      when interrupt support is available.
      
      It should be obvious that this option can't magically enable
      interrupt support when the hardware or hypervisor layer does
      not support AP interrupts.
      
      On the kernel command line use ap.useirq=0 or ap.useirq=1
      to disable or enable (that's the default) interrupt use.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      d0982725
    • H
      s390/zcrypt: rework of debug feature messages · 3f74eb5f
      Harald Freudenberger 提交于
      This patch reworks all the debug feature invocations to be
      more uniform. All invocations now use the macro with the
      level already part of the macro name. All messages now start
      with %s filled with __func__ (well there are still some
      exceptions), and some message text has been shortened or
      reworked.
      
      There is no functional code touched with this patch.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      3f74eb5f
  6. 15 9月, 2021 1 次提交
  7. 27 8月, 2021 1 次提交
    • H
      s390/ap: fix state machine hang after failure to enable irq · cabebb69
      Harald Freudenberger 提交于
      If for any reason the interrupt enable for an ap queue fails the
      state machine run for the queue returned wrong return codes to the
      caller. So the caller assumed interrupt support for this queue in
      enabled and thus did not re-establish the high resolution timer used
      for polling. In the end this let to a hang for the user space process
      waiting "forever" for the reply.
      
      This patch reworks these return codes to return correct indications
      for the caller to re-establish the timer when a queue runs without
      interrupt support.
      
      Please note that this is fixing a wrong behavior after a first
      failure (enable interrupt support for the queue) failed. However,
      looks like this occasionally happens on KVM systems.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NHeiko Carstens <hca@linux.ibm.com>
      cabebb69
  8. 25 8月, 2021 1 次提交
  9. 21 7月, 2021 1 次提交
    • U
      bus: Make remove callback return void · fc7a6209
      Uwe Kleine-König 提交于
      The driver core ignores the return value of this callback because there
      is only little it can do when a device disappears.
      
      This is the final bit of a long lasting cleanup quest where several
      buses were converted to also return void from their remove callback.
      Additionally some resource leaks were fixed that were caused by drivers
      returning an error code in the expectation that the driver won't go
      away.
      
      With struct bus_type::remove returning void it's prevented that newly
      implemented buses return an ignored error code and so don't anticipate
      wrong expectations for driver authors.
      
      Reviewed-by: Tom Rix <trix@redhat.com> (For fpga)
      Reviewed-by: NMathieu Poirier <mathieu.poirier@linaro.org>
      Reviewed-by: Cornelia Huck <cohuck@redhat.com> (For drivers/s390 and drivers/vfio)
      Acked-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> (For ARM, Amba and related parts)
      Acked-by: NMark Brown <broonie@kernel.org>
      Acked-by: Chen-Yu Tsai <wens@csie.org> (for sunxi-rsb)
      Acked-by: NPali Rohár <pali@kernel.org>
      Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org> (for media)
      Acked-by: Hans de Goede <hdegoede@redhat.com> (For drivers/platform)
      Acked-by: NAlexandre Belloni <alexandre.belloni@bootlin.com>
      Acked-By: NVinod Koul <vkoul@kernel.org>
      Acked-by: Juergen Gross <jgross@suse.com> (For xen)
      Acked-by: Lee Jones <lee.jones@linaro.org> (For mfd)
      Acked-by: Johannes Thumshirn <jth@kernel.org> (For mcb)
      Acked-by: NJohan Hovold <johan@kernel.org>
      Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> (For slimbus)
      Acked-by: Kirti Wankhede <kwankhede@nvidia.com> (For vfio)
      Acked-by: NMaximilian Luz <luzmaximilian@gmail.com>
      Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> (For ulpi and typec)
      Acked-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com> (For ipack)
      Acked-by: Geoff Levand <geoff@infradead.org> (For ps3)
      Acked-by: Yehezkel Bernat <YehezkelShB@gmail.com> (For thunderbolt)
      Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> (For intel_th)
      Acked-by: Dominik Brodowski <linux@dominikbrodowski.net> (For pcmcia)
      Acked-by: Rafael J. Wysocki <rafael@kernel.org> (For ACPI)
      Acked-by: Bjorn Andersson <bjorn.andersson@linaro.org> (rpmsg and apr)
      Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> (For intel-ish-hid)
      Acked-by: Dan Williams <dan.j.williams@intel.com> (For CXL, DAX, and NVDIMM)
      Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com> (For isa)
      Acked-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (For firewire)
      Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> (For hid)
      Acked-by: Thorsten Scherer <t.scherer@eckelmann.de> (For siox)
      Acked-by: Sven Van Asbroeck <TheSven73@gmail.com> (For anybuss)
      Acked-by: Ulf Hansson <ulf.hansson@linaro.org> (For MMC)
      Acked-by: Wolfram Sang <wsa@kernel.org> # for I2C
      Acked-by: NSudeep Holla <sudeep.holla@arm.com>
      Acked-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Acked-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
      Acked-by: NFinn Thain <fthain@linux-m68k.org>
      Signed-off-by: NUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Link: https://lore.kernel.org/r/20210713193522.1770306-6-u.kleine-koenig@pengutronix.deSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fc7a6209
  10. 05 7月, 2021 1 次提交
    • H
      s390/AP: support new dynamic AP bus size limit · bd39654a
      Harald Freudenberger 提交于
      This patch provides support for new dynamic AP bus message limit
      with the existing zcrypt device driver and AP bus core code.
      
      There is support for a new field 'ml' from TAPQ query. The field
      gives if != 0 the AP bus limit for this card in 4k chunk units.
      The actual message size limit per card is shown as a new read-only
      sysfs attribute. The sysfs attribute
      
        /sys/devices/ap/cardxx/max_msg_size
      
      shows the upper limit in bytes used by the AP bus and zcrypt device
      driver for requests and replies send to and received from this card.
      Currently up to CEX7 support only max 12kB msg size and thus the field
      shows 12288 meaning the upper limit of a valid msg for this card is
      12kB. Please note that the usable payload is somewhat lower and
      depends on the msg type and thus the header struct which is to be
      prepended by the zcrypt dd.
      
      The dispatcher responsible for choosing the right card and queue is
      aware of the individual card AP bus message limit. So a request is
      only assigned to a queue of a card which is able to handle the size of
      the request (e.g. a 14kB request will never go to a max 12kB card).
      If no such card is found the ioctl will fail with ENODEV.
      
      The reply buffer held by the device driver is determined by the ml
      field of the TAPQ for this card. If a response from the card exceeds
      this limit however, the response is not truncated but the ioctl for
      this request will fail with errno EMSGSIZE to indicate that the device
      driver has dropped the response because it would overflow the buffer
      limit.
      
      If the request size does not indicate to the dispatcher that an
      adapter with extended limit is to be used, a random card will be
      chosen when no specific card is addressed (ANY addressing). This may
      result in an ioctl failure when the reply size needs an adapter with
      extended limit but the randomly chosen one is not capable of handling
      the broader reply size. The user space application needs to use
      dedicated addressing to forward such a request only to suitable cards
      to get requests like this processed properly.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Reviewed-by: NIngo Tuchscherer <ingo.tuchscherer@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      bd39654a
  11. 17 6月, 2021 1 次提交
    • H
      s390/ap/zcrypt: notify userspace with online, config and mode info · df6f508c
      Harald Freudenberger 提交于
      This patch brings 3 reworked/new uevent changes:
      * All AP uevents caused by an ap card or queue device now carry an
        additional uevent env value MODE=<accel|cca|ep11>. Here is an
        example:
          KERNEL[1267.301292] add	 /devices/ap/card0a (ap)
          ACTION=add
          DEVPATH=/devices/ap/card0a
          SUBSYSTEM=ap
          DEVTYPE=ap_card
          DEV_TYPE=000D
          MODALIAS=ap:t0D
          MODE=ep11			 <- this is new
          SEQNUM=1095
        This is true for bind, unbind, add, remove, and change uevents
        related to ap card or ap queue devices.
      * On a change of the soft online attribute on a zcrypt queue or card
        device a new CHANGE uevent is sent with an env value ONLINE=<0|1>.
        Example uevent:
          KERNEL[613.067531] change	/devices/ap/card09/09.0011 (ap)
          ACTION=change
          DEVPATH=/devices/ap/card09/09.0011
          SUBSYSTEM=ap
          ONLINE=0			<- this is new
          DEVTYPE=ap_queue
          DRIVER=cex4queue
          MODE=cca
          SEQNUM=1070
      - On a change of the config state of an zcrypt card device a new
        CHANGE uevent is sent with an env value CONFIG=<0|1>.
        Example uevent:
          KERNEL[876.258680] change	/devices/ap/card09 (ap)
          ACTION=change
          DEVPATH=/devices/ap/card09
          SUBSYSTEM=ap
          CONFIG=0			<- this is new
          DEVTYPE=ap_card
          DRIVER=cex4card
          DEV_TYPE=000D
          MODALIAS=ap:t0D
          MODE=cca
          SEQNUM=1073
        Setting a card config on/off causes the dependent queue devices to
        follow the config state change and thus uevents informing about the
        config state change for the queue devices are also emitted.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Reviewed-by: NIngo Franzki <ifranzki@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      df6f508c
  12. 07 6月, 2021 2 次提交
  13. 30 11月, 2020 1 次提交
  14. 09 11月, 2020 1 次提交
    • H
      s390/ap: ap bus userspace notifications for some bus conditions · 837cd105
      Harald Freudenberger 提交于
      This patch adds notifications to userspace for two important
      conditions of the ap bus:
      
      I) Initial ap bus scan done. This indicates that the initial
         scan of all the ap devices (cards, queues) is complete and
         ap devices have been build up for all the hardware found.
         This condition is signaled with
         1) An ap bus change uevent send to userspace with an environment
            key/value pair "INITSCAN=done":
      	# udevadm monitor -k -p
      	...
      	KERNEL[97.830919] change   /devices/ap (ap)
      	ACTION=change
      	DEVPATH=/devices/ap
      	SUBSYSTEM=ap
      	INITSCAN=done
      	SEQNUM=10421
         2) A sysfs attribute /sys/bus/ap/scans which shows the
            number of completed ap bus scans done since bus init.
            So a value of 1 or greater signals that the initial
            ap bus scan is complete.
         Note: The initial ap bus scan complete condition is fulfilled
         and will be signaled even if there was no ap resource found.
      
      II) APQN driver bindings complete. This indicates that all
          APQNs have been bound to an zcrypt or alternate device
          driver. Only with the help of an device driver an APQN
          can be used for crypto load. So the binding complete
          condition is the starting point for user space to be
          sure all crypto resources on the ap bus are available
          for use.
          This condition is signaled with
          1) An ap bus change uevent send to userspace with an environment
             key/value pair "BINDINGS=complete":
      	 # udevadm monitor -k -p
      	 ...
      	 KERNEL[97.830975] change   /devices/ap (ap)
      	 ACTION=change
      	 DEVPATH=/devices/ap
      	 SUBSYSTEM=ap
      	 BINDINGS=complete
      	 SEQNUM=10422
          2) A sysfs attribute /sys/bus/ap/bindings showing
      	 "<nr of bound apqns>/<total nr of apqns> (complete)"
             when all available apqns have been bound to device drivers, or
      	 "<nr of bound apqns>/<total nr of apqns>"
             when there are some apqns not bound to an device driver.
          Note: The binding complete condition is also fulfilled, when
          there are no apqns available to bind any device driver. In
          this case the binding complete will be signaled AFTER init
          scan is done.
          Note: This condition may arise multiple times when after
          initial scan modifications on the bindings take place. For
          example a manual unbind of an APQN switches the binding
          complete condition off. When at a later time the unbound APQNs
          are bound with an device driver the binding is (again) complete
          resulting in another uevent and marking the bindings sysfs
          attribute with '(complete)'.
      
      There is also a new function to be used within the kernel:
      
        int ap_wait_init_apqn_bindings_complete(unsigned long timeout)
      
      Interface to wait for the AP bus to have done one initial ap bus
      scan and all detected APQNs have been bound to device drivers.
      If these both conditions are not fulfilled, this function blocks
      on a condition with wait_for_completion_interruptible_timeout().
      If these both conditions are fulfilled (before the timeout hits)
      the return value is 0. If the timeout (in jiffies) hits instead
      -ETIME is returned. On failures negative return values are
      returned to the caller. Please note that further unbind/bind
      actions after initial binding complete is through do not cause this
      function to block again.
      Reviewed-by: NIngo Franzki <ifranzki@linux.ibm.com>
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NHeiko Carstens <hca@linux.ibm.com>
      837cd105
  15. 03 11月, 2020 1 次提交
    • H
      s390/ap: fix ap devices reference counting · 29c2680f
      Harald Freudenberger 提交于
      With the last rework of the AP bus scan function one get_device() is
      missing causing the reference counter to be one instance too
      low. Together with binding/unbinding device drivers to an ap device it
      may end up in an segfault because the ap device is freed but a device
      driver still assumes it's pointer to the ap device is valid:
      
      Unable to handle kernel pointer dereference in virtual kernel address space
      Failing address: 6b6b6b6b6b6b6000 TEID: 6b6b6b6b6b6b6803
      Fault in home space mode while using kernel ASCE.
      Krnl PSW : 0404e00180000000 000000001472f3b6 (klist_next+0x7e/0x180)
                 R:0 T:1 IO:0 EX:0 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3
      Call Trace:
       [<000000001472f3b6>] klist_next+0x7e/0x180
      ([<000000001472f36a>] klist_next+0x32/0x180)
       [<00000000147c14de>] bus_for_each_dev+0x66/0xb8
       [<0000000014aab0d4>] ap_scan_adapter+0xcc/0x6c0
       [<0000000014aab74a>] ap_scan_bus+0x82/0x140
       [<0000000013f3b654>] process_one_work+0x27c/0x478
       [<0000000013f3b8b6>] worker_thread+0x66/0x368
       [<0000000013f44e32>] kthread+0x17a/0x1a0
       [<0000000014af23e4>] ret_from_fork+0x24/0x2c
      Kernel panic - not syncing: Fatal exception: panic_on_oops
      
      Fixed by adjusting the reference count with get_device() on the right
      place. Also now the device drivers don't need to adjust the ap
      device's reference counting any more. This is now done in the ap bus
      probe and remove functions.
      Reported-by: NMarc Hartmayer <mhartmay@linux.ibm.com>
      Fixes: 4f2fcccd ("s390/ap: add card/queue deconfig state")
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NHeiko Carstens <hca@linux.ibm.com>
      29c2680f
  16. 08 10月, 2020 3 次提交
    • H
      s390/ap: add card/queue deconfig state · 4f2fcccd
      Harald Freudenberger 提交于
      This patch adds a new config state to the ap card and queue
      devices. This state reflects the response code
      0x03 "AP deconfigured" on TQAP invocation and is tracked with
      every ap bus scan.
      
      Together with this new state now a card/queue device which
      is 'deconfigured' is not disposed any more. However, for backward
      compatibility the online state now needs to take this state into
      account. So a card/queue is offline when the device is not configured.
      Furthermore a device can't get switched from offline to online state
      when not configured.
      
      The config state is shown in sysfs at
        /sys/devices/ap/cardxx/config
      for the card and
        /sys/devices/ap/cardxx/xx.yyyy/config
      for each queue within each card.
      It is a read-only attribute reflecting the negation of the
      'AP deconfig' state as it is noted in the AP documents.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      4f2fcccd
    • H
      s390/ap: add error response code field for ap queue devices · 2ea2a609
      Harald Freudenberger 提交于
      On AP instruction failures the last response code is now
      kept in the struct ap_queue. There is also a new sysfs
      attribute showing this field (enabled only on debug kernels).
      
      Also slight rework of the AP_DBF macros to get some more
      content into one debug feature message line.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      2ea2a609
    • H
      s390/ap: split ap queue state machine state from device state · 0b641cbd
      Harald Freudenberger 提交于
      The state machine for each ap queue covered a mixture of
      device states and state machine (firmware queue state) states.
      
      This patch splits the device states and the state machine
      states into two different enums and variables. The major
      state is the device state with currently these values:
      
        AP_DEV_STATE_UNINITIATED - fresh and virgin, not touched
        AP_DEV_STATE_OPERATING   - queue dev is working normal
        AP_DEV_STATE_SHUTDOWN	   - remove/unbind/shutdown in progress
        AP_DEV_STATE_ERROR	   - device is in error state
      
      only when the device state is > UNINITIATED the state machine
      is run. The state machine represents the states of the firmware
      queue:
      
        AP_SM_STATE_RESET_START - starting point, reset (RAPQ) ap queue
        AP_SM_STATE_RESET_WAIT  - reset triggered, waiting to be finished
      			    if irqs enabled, set up irq (AQIC)
        AP_SM_STATE_SETIRQ_WAIT - enable irq triggered, waiting to be
      			    finished, then go to IDLE
        AP_SM_STATE_IDLE	  - queue is operational but empty
        AP_SM_STATE_WORKING	  - queue is operational, requests are stored
      			    and replies may wait for getting fetched
        AP_SM_STATE_QUEUE_FULL  - firmware queue is full, so only replies
      			    can get fetched
      
      For debugging each ap queue shows a sysfs attribute 'states' which
      displays the device and state machine state and is only available
      when the kernel is build with CONFIG_ZCRYPT_DEBUG enabled.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      0b641cbd
  17. 17 9月, 2020 1 次提交
  18. 31 7月, 2020 1 次提交
  19. 10 7月, 2020 1 次提交
  20. 03 7月, 2020 1 次提交
  21. 20 5月, 2020 1 次提交
  22. 27 3月, 2020 1 次提交
  23. 25 3月, 2020 1 次提交
  24. 23 3月, 2020 2 次提交
  25. 09 1月, 2020 1 次提交
    • H
      s390/zcrypt: move ap device reset from bus to driver code · 0c874cd0
      Harald Freudenberger 提交于
      This patch moves the reset invocation of an ap device when
      fresh detected from the ap bus to the probe() function of
      the driver responsible for this device.
      
      The virtualisation of ap devices makes it necessary to
      remove unconditioned resets on fresh appearing apqn devices.
      It may be that such a device is already enabled for guest
      usage. So there may be a race condition between host ap bus
      and guest ap bus doing the reset. This patch moves the
      reset from the ap bus to the zcrypt drivers. So if there
      is no zcrypt driver bound to an ap device - for example
      the ap device is bound to the vfio device driver - the
      ap device is untouched passed to the vfio device driver.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NVasily Gorbik <gor@linux.ibm.com>
      0c874cd0
  26. 19 9月, 2019 1 次提交
  27. 12 7月, 2019 1 次提交
  28. 24 6月, 2019 1 次提交
    • S
      bus_find_device: Unify the match callback with class_find_device · 418e3ea1
      Suzuki K Poulose 提交于
      There is an arbitrary difference between the prototypes of
      bus_find_device() and class_find_device() preventing their callers
      from passing the same pair of data and match() arguments to both of
      them, which is the const qualifier used in the prototype of
      class_find_device().  If that qualifier is also used in the
      bus_find_device() prototype, it will be possible to pass the same
      match() callback function to both bus_find_device() and
      class_find_device(), which will allow some optimizations to be made in
      order to avoid code duplication going forward.  Also with that, constify
      the "data" parameter as it is passed as a const to the match function.
      
      For this reason, change the prototype of bus_find_device() to match
      the prototype of class_find_device() and adjust its callers to use the
      const qualifier in accordance with the new prototype of it.
      
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andrew Lunn <andrew@lunn.ch>
      Cc: Andreas Noever <andreas.noever@gmail.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Bjorn Helgaas <bhelgaas@google.com>
      Cc: Corey Minyard <minyard@acm.org>
      Cc: Christian Borntraeger <borntraeger@de.ibm.com>
      Cc: David Kershner <david.kershner@unisys.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: David Airlie <airlied@linux.ie>
      Cc: Felipe Balbi <balbi@kernel.org>
      Cc: Frank Rowand <frowand.list@gmail.com>
      Cc: Grygorii Strashko <grygorii.strashko@ti.com>
      Cc: Harald Freudenberger <freude@linux.ibm.com>
      Cc: Hartmut Knaack <knaack.h@gmx.de>
      Cc: Heiko Stuebner <heiko@sntech.de>
      Cc: Jason Gunthorpe <jgg@ziepe.ca>
      Cc: Jonathan Cameron <jic23@kernel.org>
      Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
      Cc: Len Brown <lenb@kernel.org>
      Cc: Mark Brown <broonie@kernel.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Michael Jamet <michael.jamet@intel.com>
      Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
      Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
      Cc: Sebastian Ott <sebott@linux.ibm.com>
      Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
      Cc: Yehezkel Bernat <YehezkelShB@gmail.com>
      Cc: rafael@kernel.org
      Acked-by: NCorey Minyard <minyard@acm.org>
      Acked-by: NDavid Kershner <david.kershner@unisys.com>
      Acked-by: NMark Brown <broonie@kernel.org>
      Acked-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
      Acked-by: Wolfram Sang <wsa@the-dreams.de> # for the I2C parts
      Acked-by: NRob Herring <robh@kernel.org>
      Signed-off-by: NSuzuki K Poulose <suzuki.poulose@arm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      418e3ea1
  29. 28 5月, 2019 1 次提交
    • H
      s390/zcrypt: Fix wrong dispatching for control domain CPRBs · 7379e652
      Harald Freudenberger 提交于
      The zcrypt device driver does not handle CPRBs which address
      a control domain correctly. This fix introduces a workaround:
      The domain field of the request CPRB is checked if there is
      a valid domain value in there. If this is true and the value
      is a control only domain (a domain which is enabled in the
      crypto config ADM mask but disabled in the AQM mask) the
      CPRB is forwarded to the default usage domain. If there is
      no default domain, the request is rejected with an ENODEV.
      
      This fix is important for maintaining crypto adapters. For
      example one LPAR can use a crypto adapter domain ('Control
      and Usage') but another LPAR needs to be able to maintain
      this adapter domain ('Control'). Scenarios like this did
      not work properly and the patch enables this.
      Signed-off-by: NHarald Freudenberger <freude@linux.ibm.com>
      Signed-off-by: NHeiko Carstens <heiko.carstens@de.ibm.com>
      7379e652
  30. 29 4月, 2019 1 次提交