1. 03 Jul, 2018 40 commits
    • Steffen Maier's avatar
      scsi: zfcp: fix missing REC trigger trace on enqueue without ERP thread · c6751cb1
      Steffen Maier authored
      commit 6a765508 upstream.
      
      Example trace record formatted with zfcpdbf from s390-tools:
      
      Timestamp      : ...
      Area           : REC
      Subarea        : 00
      Level          : 1
      Exception      : -
      CPU ID         : ..
      Caller         : 0x...
      Record ID      : 1                      ZFCP_DBF_REC_TRIG
      Tag            : .......
      LUN            : 0x...
      WWPN           : 0x...
      D_ID           : 0x...
      Adapter status : 0x...
      Port status    : 0x...
      LUN status     : 0x...
      Ready count    : 0x...
      Running count  : 0x...
      ERP want       : 0x0.                   ZFCP_ERP_ACTION_REOPEN_...
      ERP need       : 0xc0                   ZFCP_ERP_ACTION_NONE
      Signed-off-by: default avatarSteffen Maier <maier@linux.ibm.com>
      Cc: <stable@vger.kernel.org> #2.6.38+
      Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c6751cb1
    • Steffen Maier's avatar
      scsi: zfcp: fix missing REC trigger trace for all objects in ERP_FAILED · 2df7e6f3
      Steffen Maier authored
      commit 8c3d20aa upstream.
      
      That other commit introduced an inconsistency because it would trace on
      ERP_FAILED for all callers of port forced reopen triggers (not just
      terminate_rport_io), but it would not trace on ERP_FAILED for all callers of
      other ERP triggers such as adapter, port regular, LUN.
      
      Therefore, generalize that other commit. zfcp_erp_action_enqueue() already
      had two early outs which re-used the one zfcp_dbf_rec_trig() call.  All ERP
      trigger functions finally run through zfcp_erp_action_enqueue().  So move
      the special handling for ZFCP_STATUS_COMMON_ERP_FAILED into
      zfcp_erp_action_enqueue() and add another early out with new trace marker
      for pseudo ERP need in this case. This removes all early returns from all
      ERP trigger functions so we always end up at zfcp_dbf_rec_trig().
      
      Example trace record formatted with zfcpdbf from s390-tools:
      
      Timestamp      : ...
      Area           : REC
      Subarea        : 00
      Level          : 1
      Exception      : -
      CPU ID         : ..
      Caller         : 0x...
      Record ID      : 1                      ZFCP_DBF_REC_TRIG
      Tag            : .......
      LUN            : 0x...
      WWPN           : 0x...
      D_ID           : 0x...
      Adapter status : 0x...
      Port status    : 0x...
      LUN status     : 0x...
      Ready count    : 0x...
      Running count  : 0x...
      ERP want       : 0x0.                   ZFCP_ERP_ACTION_REOPEN_...
      ERP need       : 0xe0                   ZFCP_ERP_ACTION_FAILED
      Signed-off-by: default avatarSteffen Maier <maier@linux.ibm.com>
      Cc: <stable@vger.kernel.org> #2.6.38+
      Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2df7e6f3
    • Steffen Maier's avatar
      scsi: zfcp: fix missing REC trigger trace on terminate_rport_io for ERP_FAILED · 21224f6f
      Steffen Maier authored
      commit d70aab55 upstream.
      
      For problem determination we always want to see when we were invoked on the
      terminate_rport_io callback whether we perform something or not.
      
      Temporal event sequence of interest with a long fast_io_fail_tmo of 27 sec:
      
      loose remote port
      
      t   workqueue
      [s] zfcp_q_<dev>       IRQ                 zfcperp<dev>
      
      === ================== =================== ============================
      
        0                    recv RSCN
                             q p.test_link_work
          block rport
           start fast_io_fail_tmo
          send ADISC ELS
        4                    recv ADISC fail
                             block zfcp_port
                                                 port forced reopen
                                                 send open port
       12                    recv open port fail
                                                 q p.gid_pn_work
                                                 zfcp_erp_wakeup
                                                 (zfcp_erp_wait would return)
          GID_PN fail
      
      Before this point, we got a SCSI trace with tag "sctrpi1" on fast_io_fail,
      e.g. with the typical 5 sec setting.
      
          port.status |= ERP_FAILED
      
      If fast_io_fail_tmo triggers after this point, we missed a SCSI trace.
      
          workqueue
          fc_dl_<host>
          ==================
       27 fc_timeout_fail_rport_io
          fc_terminate_rport_io
          zfcp_scsi_terminate_rport_io
          zfcp_erp_port_forced_reopen
          _zfcp_erp_port_forced_reopen
           if (port.status & ERP_FAILED)
            return;
      
      Therefore, write a trace before above early return.
      
      Example trace record formatted with zfcpdbf from s390-tools:
      
      Timestamp      : ...
      Area           : REC
      Subarea        : 00
      Level          : 1
      Exception      : -
      CPU ID         : ..
      Caller         : 0x...
      Record ID      : 1                      ZFCP_DBF_REC_TRIG
      Tag            : sctrpi1                SCSI terminate rport I/O
      LUN            : 0xffffffffffffffff                     none (invalid)
      WWPN           : 0x<wwpn>
      D_ID           : 0x<n_port_id>
      Adapter status : 0x...
      Port status    : 0x...
      LUN status     : 0x00000000                             none (invalid)
      Ready count    : 0x...
      Running count  : 0x...
      ERP want       : 0x03                   ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
      ERP need       : 0xe0                   ZFCP_ERP_ACTION_FAILED
      Signed-off-by: default avatarSteffen Maier <maier@linux.ibm.com>
      Cc: <stable@vger.kernel.org> #2.6.38+
      Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      21224f6f
    • Steffen Maier's avatar
      scsi: zfcp: fix missing REC trigger trace on terminate_rport_io early return · 48ae373c
      Steffen Maier authored
      commit 96d92704 upstream.
      
      get_device() and its internally used kobject_get() only return NULL if they
      get passed NULL as argument. zfcp_get_port_by_wwpn() loops over
      adapter->port_list so the iteration variable port is always non-NULL.
      Struct device is embedded in struct zfcp_port so &port->dev is always
      non-NULL. This is the argument to get_device().  However, if we get an
      fc_rport in terminate_rport_io() for which we cannot find a match within
      zfcp_get_port_by_wwpn(), the latter can return NULL.  v2.6.30 commit
      70932935 ("[SCSI] zfcp: Fix oops when port disappears") introduced an
      early return without adding a trace record for this case.  Even if we don't
      need recovery in this case, for debugging we should still see that our
      callback was invoked originally by scsi_transport_fc.
      
      Example trace record formatted with zfcpdbf from s390-tools:
      
      Timestamp      : ...
      Area           : REC
      Subarea        : 00
      Level          : 1
      Exception      : -
      CPU ID         : ..
      Caller         : 0x...
      Record ID      : 1
      Tag            : sctrpin        SCSI terminate rport I/O, no zfcp port
      LUN            : 0xffffffffffffffff                     none (invalid)
      WWPN           : 0x<wwpn>               WWPN
      D_ID           : 0x<n_port_id>          N_Port-ID
      Adapter status : 0x...
      Port status    : 0xffffffff             unknown (-1)
      LUN status     : 0x00000000                             none (invalid)
      Ready count    : 0x...
      Running count  : 0x...
      ERP want       : 0x03                   ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
      ERP need       : 0xc0                   ZFCP_ERP_ACTION_NONE
      Signed-off-by: default avatarSteffen Maier <maier@linux.ibm.com>
      Fixes: 70932935 ("[SCSI] zfcp: Fix oops when port disappears")
      Cc: <stable@vger.kernel.org> #2.6.38+
      Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      48ae373c
    • Steffen Maier's avatar
      scsi: zfcp: fix misleading REC trigger trace where erp_action setup failed · b0c2fc11
      Steffen Maier authored
      commit 512857a7 upstream.
      
      If a SCSI device is deleted during scsi_eh host reset, we cannot get a
      reference to the SCSI device anymore since scsi_device_get returns !=0 by
      design. Assuming the recovery of adapter and port(s) was successful,
      zfcp_erp_strategy_followup_success() attempts to trigger a LUN reset for the
      half-gone SCSI device. Unfortunately, it causes the following confusing
      trace record which states that zfcp will do a LUN recovery as "ERP need" is
      ZFCP_ERP_ACTION_REOPEN_LUN == 1 and equals "ERP want".
      
      Old example trace record formatted with zfcpdbf from s390-tools:
      
      Tag:           : ersfs_3 ERP, trigger, unit reopen, port reopen succeeded
      LUN            : 0x<FCP_LUN>
      WWPN           : 0x<WWPN>
      D_ID           : 0x<N_Port-ID>
      Adapter status : 0x5400050b
      Port status    : 0x54000001
      LUN status     : 0x40000000     ZFCP_STATUS_COMMON_RUNNING
                                      but not ZFCP_STATUS_COMMON_UNBLOCKED as it
                                      was closed on close part of adapter reopen
      ERP want       : 0x01
      ERP need       : 0x01           misleading
      
      However, zfcp_erp_setup_act() returns NULL as it cannot get the reference.
      Hence, zfcp_erp_action_enqueue() takes an early goto out and _NO_ recovery
      actually happens.
      
      We always do want the recovery trigger trace record even if no erp_action
      could be enqueued as in this case. For other cases where we did not enqueue
      an erp_action, 'need' has always been zero to indicate this. In order to
      indicate above goto out, introduce an eyecatcher "flag" to mark the "ERP
      need" as 'not needed' but still keep the information which erp_action type,
      that zfcp_erp_required_act() had decided upon, is needed.  0xc_ is chosen to
      be visibly different from 0x0_ in "ERP want".
      
      New example trace record formatted with zfcpdbf from s390-tools:
      
      Tag:           : ersfs_3 ERP, trigger, unit reopen, port reopen succeeded
      LUN            : 0x<FCP_LUN>
      WWPN           : 0x<WWPN>
      D_ID           : 0x<N_Port-ID>
      Adapter status : 0x5400050b
      Port status    : 0x54000001
      LUN status     : 0x40000000
      ERP want       : 0x01
      ERP need       : 0xc1           would need LUN ERP, but no action set up
                         ^
      
      Before v2.6.38 commit ae0904f6 ("[SCSI] zfcp: Redesign of the debug
      tracing for recovery actions.") we could detect this case because the
      "erp_action" field in the trace was NULL. The rework removed erp_action as
      argument and field from the trace.
      
      This patch here is for tracing. A fix to allow LUN recovery in the case at
      hand is a topic for a separate patch.
      
      See also commit fdbd1c5e ("[SCSI] zfcp: Allow running unit/LUN shutdown
      without acquiring reference") for a similar case and background info.
      Signed-off-by: default avatarSteffen Maier <maier@linux.ibm.com>
      Fixes: ae0904f6 ("[SCSI] zfcp: Redesign of the debug tracing for recovery actions.")
      Cc: <stable@vger.kernel.org> #2.6.38+
      Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b0c2fc11
    • Steffen Maier's avatar
      scsi: zfcp: fix missing SCSI trace for retry of abort / scsi_eh TMF · 97d3625b
      Steffen Maier authored
      commit 81979ae6 upstream.
      
      We already have a SCSI trace for the end of abort and scsi_eh TMF. Due to
      zfcp_erp_wait() and fc_block_scsi_eh() time can pass between the start of
      our eh callback and an actual send/recv of an abort / TMF request.  In order
      to see the temporal sequence including any abort / TMF send retries, add a
      trace before the above two blocking functions.  This supports problem
      determination with scsi_eh and parallel zfcp ERP.
      
      No need to explicitly trace the beginning of our eh callback, since we
      typically can send an abort / TMF and see its HBA response (in the worst
      case, it's a pseudo response on dismiss all of adapter recovery, e.g. due to
      an FSF request timeout [fsrth_1] of the abort / TMF). If we cannot send, we
      now get a trace record for the first "abrt_wt" or "[lt]r_wait" which denotes
      almost the beginning of the callback.
      
      No need to explicitly trace the wakeup after the above two blocking
      functions because the next retry loop causes another trace in any case and
      that is sufficient.
      
      Example trace records formatted with zfcpdbf from s390-tools:
      
      Timestamp      : ...
      Area           : SCSI
      Subarea        : 00
      Level          : 1
      Exception      : -
      CPU ID         : ..
      Caller         : 0x...
      Record ID      : 1
      Tag            : abrt_wt        abort, before zfcp_erp_wait()
      Request ID     : 0x0000000000000000                     none (invalid)
      SCSI ID        : 0x<scsi_id>
      SCSI LUN       : 0x<scsi_lun>
      SCSI LUN high  : 0x<scsi_lun_high>
      SCSI result    : 0x<scsi_result_of_cmd_to_be_aborted>
      SCSI retries   : 0x<retries_of_cmd_to_be_aborted>
      SCSI allowed   : 0x<allowed_retries_of_cmd_to_be_aborted>
      SCSI scribble  : 0x<req_id_of_cmd_to_be_aborted>
      SCSI opcode    : <CDB_of_cmd_to_be_aborted>
      FCP rsp inf cod: 0x..                                   none (invalid)
      FCP rsp IU     : ...                                    none (invalid)
      
      Timestamp      : ...
      Area           : SCSI
      Subarea        : 00
      Level          : 1
      Exception      : -
      CPU ID         : ..
      Caller         : 0x...
      Record ID      : 1
      Tag            : lr_wait        LUN reset, before zfcp_erp_wait()
      Request ID     : 0x0000000000000000                     none (invalid)
      SCSI ID        : 0x<scsi_id>
      SCSI LUN       : 0x<scsi_lun>
      SCSI LUN high  : 0x<scsi_lun_high>
      SCSI result    : 0x...                                  unrelated
      SCSI retries   : 0x..                                   unrelated
      SCSI allowed   : 0x..                                   unrelated
      SCSI scribble  : 0x...                                  unrelated
      SCSI opcode    : ...                                    unrelated
      FCP rsp inf cod: 0x..                                   none (invalid)
      FCP rsp IU     : ...                                    none (invalid)
      Signed-off-by: default avatarSteffen Maier <maier@linux.ibm.com>
      Fixes: 63caf367 ("[SCSI] zfcp: Improve reliability of SCSI eh handlers in zfcp")
      Fixes: af4de36d ("[SCSI] zfcp: Block scsi_eh thread for rport state BLOCKED")
      Cc: <stable@vger.kernel.org> #2.6.38+
      Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      97d3625b
    • Steffen Maier's avatar
      scsi: zfcp: fix missing SCSI trace for result of eh_host_reset_handler · 9779f499
      Steffen Maier authored
      commit df307816 upstream.
      
      For problem determination we need to see whether and why we were successful
      or not. This allows deduction of scsi_eh escalation.
      
      Example trace record formatted with zfcpdbf from s390-tools:
      
      Timestamp      : ...
      Area           : SCSI
      Subarea        : 00
      Level          : 1
      Exception      : -
      CPU ID         : ..
      Caller         : 0x...
      Record ID      : 1
      Tag            : schrh_r        SCSI host reset handler result
      Request ID     : 0x0000000000000000                     none (invalid)
      SCSI ID        : 0xffffffff                             none (invalid)
      SCSI LUN       : 0xffffffff                             none (invalid)
      SCSI LUN high  : 0xffffffff                             none (invalid)
      SCSI result    : 0x00002002     field re-used for midlayer value: SUCCESS
                                      or in other cases: 0x2009 == FAST_IO_FAIL
      SCSI retries   : 0xff                                   none (invalid)
      SCSI allowed   : 0xff                                   none (invalid)
      SCSI scribble  : 0xffffffffffffffff                     none (invalid)
      SCSI opcode    : ffffffff ffffffff ffffffff ffffffff    none (invalid)
      FCP rsp inf cod: 0xff                                   none (invalid)
      FCP rsp IU     : 00000000 00000000 00000000 00000000    none (invalid)
                       00000000 00000000
      
      v2.6.35 commit a1dbfddd ("[SCSI] zfcp: Pass return code from
      fc_block_scsi_eh to scsi eh") introduced the first return with something
      other than the previously hardcoded single SUCCESS return path.
      Signed-off-by: default avatarSteffen Maier <maier@linux.ibm.com>
      Fixes: a1dbfddd ("[SCSI] zfcp: Pass return code from fc_block_scsi_eh to scsi eh")
      Cc: <stable@vger.kernel.org> #2.6.38+
      Reviewed-by: default avatarJens Remus <jremus@linux.ibm.com>
      Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9779f499
    • Himanshu Madhani's avatar
      scsi: qla2xxx: Fix setting lower transfer speed if GPSC fails · f0c54315
      Himanshu Madhani authored
      commit 413c2f33 upstream.
      
      This patch prevents driver from setting lower default speed of 1 GB/sec,
      if the switch does not support Get Port Speed Capabilities (GPSC)
      command. Setting this default speed results into much lower write
      performance for large sequential WRITE.  This patch modifies driver to
      check for gpsc_supported flags and prevents driver from issuing
      MBC_SET_PORT_PARAM (001Ah) to set default speed of 1 GB/sec. If driver
      does not send this mailbox command, firmware assumes maximum supported
      link speed and will operate at the max speed.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarHimanshu Madhani <himanshu.madhani@cavium.com>
      Reported-by: default avatarEda Zhou <ezhou@redhat.com>
      Reviewed-by: default avatarEwan D. Milne <emilne@redhat.com>
      Tested-by: default avatarEwan D. Milne <emilne@redhat.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f0c54315
    • Martin Kelly's avatar
      iio:buffer: make length types match kfifo types · 0400b066
      Martin Kelly authored
      commit c043ec1c upstream.
      
      Currently, we use int for buffer length and bytes_per_datum. However,
      kfifo uses unsigned int for length and size_t for element size. We need
      to make sure these matches or we will have bugs related to overflow (in
      the range between INT_MAX and UINT_MAX for length, for example).
      
      In addition, set_bytes_per_datum uses size_t while bytes_per_datum is an
      int, which would cause bugs for large values of bytes_per_datum.
      
      Change buffer length to use unsigned int and bytes_per_datum to use
      size_t.
      Signed-off-by: default avatarMartin Kelly <mkelly@xevo.com>
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      [bwh: Backported to 4.9:
       - Drop change to iio_dma_buffer_set_length()
       - Adjust filename, context]
      Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0400b066
    • Liu Bo's avatar
      Btrfs: fix unexpected cow in run_delalloc_nocow · 3fd6a73d
      Liu Bo authored
      commit 58113753 upstream.
      
      Fstests generic/475 provides a way to fail metadata reads while
      checking if checksum exists for the inode inside run_delalloc_nocow(),
      and csum_exist_in_range() interprets error (-EIO) as inode having
      checksum and makes its caller enter the cow path.
      
      In case of free space inode, this ends up with a warning in
      cow_file_range().
      
      The same problem applies to btrfs_cross_ref_exist() since it may also
      read metadata in between.
      
      With this, run_delalloc_nocow() bails out when errors occur at the two
      places.
      
      cc: <stable@vger.kernel.org> v2.6.28+
      Fixes: 17d217fe ("Btrfs: fix nodatasum handling in balancing code")
      Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      3fd6a73d
    • Filipe Manana's avatar
      Btrfs: fix return value on rename exchange failure · 77c82917
      Filipe Manana authored
      commit c5b4a50b upstream.
      
      If we failed during a rename exchange operation after starting/joining a
      transaction, we would end up replacing the return value, stored in the
      local 'ret' variable, with the return value from btrfs_end_transaction().
      So this could end up returning 0 (success) to user space despite the
      operation having failed and aborted the transaction, because if there are
      multiple tasks having a reference on the transaction at the time
      btrfs_end_transaction() is called by the rename exchange, that function
      returns 0 (otherwise it returns -EIO and not the original error value).
      So fix this by not overwriting the return value on error after getting
      a transaction handle.
      
      Fixes: cdd1fedf ("btrfs: add support for RENAME_EXCHANGE and RENAME_WHITEOUT")
      CC: stable@vger.kernel.org # 4.9+
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      77c82917
    • Maciej S. Szmigiero's avatar
      X.509: unpack RSA signatureValue field from BIT STRING · 41b1d57a
      Maciej S. Szmigiero authored
      commit b65c32ec upstream.
      
      The signatureValue field of a X.509 certificate is encoded as a BIT STRING.
      For RSA signatures this BIT STRING is of so-called primitive subtype, which
      contains a u8 prefix indicating a count of unused bits in the encoding.
      
      We have to strip this prefix from signature data, just as we already do for
      key data in x509_extract_key_data() function.
      
      This wasn't noticed earlier because this prefix byte is zero for RSA key
      sizes divisible by 8. Since BIT STRING is a big-endian encoding adding zero
      prefixes has no bearing on its value.
      
      The signature length, however was incorrect, which is a problem for RSA
      implementations that need it to be exactly correct (like AMD CCP).
      Signed-off-by: default avatarMaciej S. Szmigiero <mail@maciej.szmigiero.name>
      Fixes: c26fd69f ("X.509: Add a crypto key parser for binary (DER) X.509 certificates")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      41b1d57a
    • Geert Uytterhoeven's avatar
      time: Make sure jiffies_to_msecs() preserves non-zero time periods · 8fd86587
      Geert Uytterhoeven authored
      commit abcbcb80 upstream.
      
      For the common cases where 1000 is a multiple of HZ, or HZ is a multiple of
      1000, jiffies_to_msecs() never returns zero when passed a non-zero time
      period.
      
      However, if HZ > 1000 and not an integer multiple of 1000 (e.g. 1024 or
      1200, as used on alpha and DECstation), jiffies_to_msecs() may return zero
      for small non-zero time periods.  This may break code that relies on
      receiving back a non-zero value.
      
      jiffies_to_usecs() does not need such a fix: one jiffy can only be less
      than one µs if HZ > 1000000, and such large values of HZ are already
      rejected at build time, twice:
      
        - include/linux/jiffies.h does #error if HZ >= 12288,
        - kernel/time/time.c has BUILD_BUG_ON(HZ > USEC_PER_SEC).
      
      Broken since forever.
      Signed-off-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
      Cc: John Stultz <john.stultz@linaro.org>
      Cc: Stephen Boyd <sboyd@kernel.org>
      Cc: linux-alpha@vger.kernel.org
      Cc: linux-mips@linux-mips.org
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/20180622143357.7495-1-geert@linux-m68k.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8fd86587
    • Huacai Chen's avatar
      MIPS: io: Add barrier after register read in inX() · 344d6159
      Huacai Chen authored
      commit 18f3e95b upstream.
      
      While a barrier is present in the outX() functions before the register
      write, a similar barrier is missing in the inX() functions after the
      register read. This could allow memory accesses following inX() to
      observe stale data.
      
      This patch is very similar to commit a1cc7034 ("MIPS: io: Add
      barrier after register read in readX()"). Because war_io_reorder_wmb()
      is both used by writeX() and outX(), if readX() need a barrier then so
      does inX().
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarHuacai Chen <chenhc@lemote.com>
      Patchwork: https://patchwork.linux-mips.org/patch/19516/Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Cc: James Hogan <james.hogan@mips.com>
      Cc: linux-mips@linux-mips.org
      Cc: Fuxin Zhang <zhangfx@lemote.com>
      Cc: Zhangjin Wu <wuzhangjin@gmail.com>
      Cc: Huacai Chen <chenhuacai@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      344d6159
    • Tetsuo Handa's avatar
      printk: fix possible reuse of va_list variable · db2baeef
      Tetsuo Handa authored
      commit 988a35f8 upstream.
      
      I noticed that there is a possibility that printk_safe_log_store() causes
      kernel oops because "args" parameter is passed to vsnprintf() again when
      atomic_cmpxchg() detected that we raced. Fix this by using va_copy().
      
      Link: http://lkml.kernel.org/r/201805112002.GIF21216.OFVHFOMLJtQFSO@I-love.SAKURA.ne.jp
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: dvyukov@google.com
      Cc: syzkaller@googlegroups.com
      Cc: fengguang.wu@intel.com
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Fixes: 42a0bb3f ("printk/nmi: generic solution for safe printk in NMI")
      Cc: 4.7+ <stable@vger.kernel.org> # v4.7+
      Reviewed-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      db2baeef
    • Mika Westerberg's avatar
      PCI: pciehp: Clear Presence Detect and Data Link Layer Status Changed on resume · ca558fb8
      Mika Westerberg authored
      commit 13c65840 upstream.
      
      After a suspend/resume cycle the Presence Detect or Data Link Layer Status
      Changed bits might be set.  If we don't clear them those events will not
      fire anymore and nothing happens for instance when a device is now
      hot-unplugged.
      
      Fix this by clearing those bits in a newly introduced function
      pcie_reenable_notification().  This should be fine because immediately
      after, we check if the adapter is still present by reading directly from
      the status register.
      Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ca558fb8
    • Mika Westerberg's avatar
      PCI: Add ACS quirk for Intel 300 series · 0d3d5833
      Mika Westerberg authored
      commit f154a718 upstream.
      
      Intel 300 series chipset still has the same ACS issue as the previous
      generations so extend the ACS quirk to cover it as well.
      Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0d3d5833
    • Alex Williamson's avatar
      PCI: Add ACS quirk for Intel 7th & 8th Gen mobile · 5e1deade
      Alex Williamson authored
      commit e8440f4b upstream.
      
      The specification update indicates these have the same errata for
      implementing non-standard ACS capabilities.
      Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5e1deade
    • Tokunori Ikegami's avatar
      MIPS: BCM47XX: Enable 74K Core ExternalSync for PCIe erratum · 83f9549d
      Tokunori Ikegami authored
      commit 2a027b47 upstream.
      
      The erratum and workaround are described by BCM5300X-ES300-RDS.pdf as
      below.
      
        R10: PCIe Transactions Periodically Fail
      
          Description: The BCM5300X PCIe does not maintain transaction ordering.
                       This may cause PCIe transaction failure.
          Fix Comment: Add a dummy PCIe configuration read after a PCIe
                       configuration write to ensure PCIe configuration access
                       ordering. Set ES bit of CP0 configu7 register to enable
                       sync function so that the sync instruction is functional.
          Resolution:  hndpci.c: extpci_write_config()
                       hndmips.c: si_mips_init()
                       mipsinc.h CONF7_ES
      
      This is fixed by the CFE MIPS bcmsi chipset driver also for BCM47XX.
      Also the dummy PCIe configuration read is already implemented in the
      Linux BCMA driver.
      
      Enable ExternalSync in Config7 when CONFIG_BCMA_DRIVER_PCI_HOSTMODE=y
      too so that the sync instruction is externalised.
      Signed-off-by: default avatarTokunori Ikegami <ikegami@allied-telesis.co.jp>
      Reviewed-by: default avatarPaul Burton <paul.burton@mips.com>
      Acked-by: default avatarHauke Mehrtens <hauke@hauke-m.de>
      Cc: Chris Packham <chris.packham@alliedtelesis.co.nz>
      Cc: Rafał Miłecki <zajec5@gmail.com>
      Cc: linux-mips@linux-mips.org
      Cc: stable@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/19461/Signed-off-by: default avatarJames Hogan <jhogan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      83f9549d
    • Joakim Tjernlund's avatar
      mtd: cfi_cmdset_0002: Avoid walking all chips when unlocking. · 5fdb3c46
      Joakim Tjernlund authored
      commit f1ce87f6 upstream.
      
      cfi_ppb_unlock() walks all flash chips when unlocking sectors,
      avoid walking chips unaffected by the unlock operation.
      
      Fixes: 1648eaaa ("mtd: cfi_cmdset_0002: Support Persistent Protection Bits (PPB) locking")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJoakim Tjernlund <joakim.tjernlund@infinera.com>
      Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5fdb3c46
    • Joakim Tjernlund's avatar
      mtd: cfi_cmdset_0002: Fix unlocking requests crossing a chip boudary · b4e24c28
      Joakim Tjernlund authored
      commit 0cd8116f upstream.
      
      The "sector is in requested range" test used to determine whether
      sectors should be re-locked or not is done on a variable that is reset
      everytime we cross a chip boundary, which can lead to some blocks being
      re-locked while the caller expect them to be unlocked.
      Fix the check to make sure this cannot happen.
      
      Fixes: 1648eaaa ("mtd: cfi_cmdset_0002: Support Persistent Protection Bits (PPB) locking")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJoakim Tjernlund <joakim.tjernlund@infinera.com>
      Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b4e24c28
    • Joakim Tjernlund's avatar
      mtd: cfi_cmdset_0002: fix SEGV unlocking multiple chips · 0bf4e48c
      Joakim Tjernlund authored
      commit 5fdfc3db upstream.
      
      cfi_ppb_unlock() tries to relock all sectors that were locked before
      unlocking the whole chip.
      This locking used the chip start address + the FULL offset from the
      first flash chip, thereby forming an illegal address. Fix that by using
      the chip offset(adr).
      
      Fixes: 1648eaaa ("mtd: cfi_cmdset_0002: Support Persistent Protection Bits (PPB) locking")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJoakim Tjernlund <joakim.tjernlund@infinera.com>
      Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0bf4e48c
    • Joakim Tjernlund's avatar
      mtd: cfi_cmdset_0002: Use right chip in do_ppb_xxlock() · 552eacd5
      Joakim Tjernlund authored
      commit f93aa8c4 upstream.
      
      do_ppb_xxlock() fails to add chip->start when querying for lock status
      (and chip_ready test), which caused false status reports.
      Fix that by adding adr += chip->start and adjust call sites
      accordingly.
      
      Fixes: 1648eaaa ("mtd: cfi_cmdset_0002: Support Persistent Protection Bits (PPB) locking")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJoakim Tjernlund <joakim.tjernlund@infinera.com>
      Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      552eacd5
    • Tokunori Ikegami's avatar
      mtd: cfi_cmdset_0002: Change write buffer to check correct value · e9dc5dce
      Tokunori Ikegami authored
      commit dfeae107 upstream.
      
      For the word write it is checked if the chip has the correct value.
      But it is not checked for the write buffer as only checked if ready.
      To make sure for the write buffer change to check the value.
      
      It is enough as this patch is only checking the last written word.
      Since it is described by data sheets to check the operation status.
      Signed-off-by: default avatarTokunori Ikegami <ikegami@allied-telesis.co.jp>
      Reviewed-by: default avatarJoakim Tjernlund <Joakim.Tjernlund@infinera.com>
      Cc: Chris Packham <chris.packham@alliedtelesis.co.nz>
      Cc: Brian Norris <computersforpeace@gmail.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
      Cc: Marek Vasut <marek.vasut@gmail.com>
      Cc: Richard Weinberger <richard@nod.at>
      Cc: Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>
      Cc: linux-mtd@lists.infradead.org
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e9dc5dce
    • Leon Romanovsky's avatar
      RDMA/mlx4: Discard unknown SQP work requests · afe249e3
      Leon Romanovsky authored
      commit 6b1ca7ec upstream.
      
      There is no need to crash the machine if unknown work request was
      received in SQP MAD.
      
      Cc: <stable@vger.kernel.org> # 3.6
      Fixes: 37bfc7c1 ("IB/mlx4: SR-IOV multiplex and demultiplex MADs")
      Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
      Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      afe249e3
    • Max Gurtovoy's avatar
      IB/isert: fix T10-pi check mask setting · 52e16718
      Max Gurtovoy authored
      commit 0e12af84 upstream.
      
      A copy/paste bug (probably) caused setting of an app_tag check mask
      in case where a ref_tag check was needed.
      
      Fixes: 38a2d0d4 ("IB/isert: convert to the generic RDMA READ/WRITE API")
      Fixes: 9e961ae7 ("IB/isert: Support T10-PI protected transactions")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
      Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarMax Gurtovoy <maxg@mellanox.com>
      Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      52e16718
    • Alex Estrin's avatar
      IB/isert: Fix for lib/dma_debug check_sync warning · a664281b
      Alex Estrin authored
      commit 763b6965 upstream.
      
      The following error message occurs on a target host in a debug build
      during session login:
      
      [ 3524.411874] WARNING: CPU: 5 PID: 12063 at lib/dma-debug.c:1207 check_sync+0x4ec/0x5b0
      [ 3524.421057] infiniband hfi1_0: DMA-API: device driver tries to sync DMA memory it has not allocated [device address=0x0000000000000000] [size=76 bytes]
      ......snip .....
      
      [ 3524.535846] CPU: 5 PID: 12063 Comm: iscsi_np Kdump: loaded Not tainted 3.10.0-862.el7.x86_64.debug #1
      [ 3524.546764] Hardware name: Dell Inc. PowerEdge R430/03XKDV, BIOS 1.2.6 06/08/2015
      [ 3524.555740] Call Trace:
      [ 3524.559102]  [<ffffffffa5fe915b>] dump_stack+0x19/0x1b
      [ 3524.565477]  [<ffffffffa58a2f58>] __warn+0xd8/0x100
      [ 3524.571557]  [<ffffffffa58a2fdf>] warn_slowpath_fmt+0x5f/0x80
      [ 3524.578610]  [<ffffffffa5bf5b8c>] check_sync+0x4ec/0x5b0
      [ 3524.585177]  [<ffffffffa58efc3f>] ? set_cpus_allowed_ptr+0x5f/0x1c0
      [ 3524.592812]  [<ffffffffa5bf5cd0>] debug_dma_sync_single_for_cpu+0x80/0x90
      [ 3524.601029]  [<ffffffffa586add3>] ? x2apic_send_IPI_mask+0x13/0x20
      [ 3524.608574]  [<ffffffffa585ee1b>] ? native_smp_send_reschedule+0x5b/0x80
      [ 3524.616699]  [<ffffffffa58e9b76>] ? resched_curr+0xf6/0x140
      [ 3524.623567]  [<ffffffffc0879af0>] isert_create_send_desc.isra.26+0xe0/0x110 [ib_isert]
      [ 3524.633060]  [<ffffffffc087af95>] isert_put_login_tx+0x55/0x8b0 [ib_isert]
      [ 3524.641383]  [<ffffffffa58ef114>] ? try_to_wake_up+0x1a4/0x430
      [ 3524.648561]  [<ffffffffc098cfed>] iscsi_target_do_tx_login_io+0xdd/0x230 [iscsi_target_mod]
      [ 3524.658557]  [<ffffffffc098d827>] iscsi_target_do_login+0x1a7/0x600 [iscsi_target_mod]
      [ 3524.668084]  [<ffffffffa59f9bc9>] ? kstrdup+0x49/0x60
      [ 3524.674420]  [<ffffffffc098e976>] iscsi_target_start_negotiation+0x56/0xc0 [iscsi_target_mod]
      [ 3524.684656]  [<ffffffffc098c2ee>] __iscsi_target_login_thread+0x90e/0x1070 [iscsi_target_mod]
      [ 3524.694901]  [<ffffffffc098ca50>] ? __iscsi_target_login_thread+0x1070/0x1070 [iscsi_target_mod]
      [ 3524.705446]  [<ffffffffc098ca50>] ? __iscsi_target_login_thread+0x1070/0x1070 [iscsi_target_mod]
      [ 3524.715976]  [<ffffffffc098ca78>] iscsi_target_login_thread+0x28/0x60 [iscsi_target_mod]
      [ 3524.725739]  [<ffffffffa58d60ff>] kthread+0xef/0x100
      [ 3524.732007]  [<ffffffffa58d6010>] ? insert_kthread_work+0x80/0x80
      [ 3524.739540]  [<ffffffffa5fff1b7>] ret_from_fork_nospec_begin+0x21/0x21
      [ 3524.747558]  [<ffffffffa58d6010>] ? insert_kthread_work+0x80/0x80
      [ 3524.755088] ---[ end trace 23f8bf9238bd1ed8 ]---
      [ 3595.510822] iSCSI/iqn.1994-05.com.redhat:537fa56299: Unsupported SCSI Opcode 0xa3, sending CHECK_CONDITION.
      
      The code calls dma_sync on login_tx_desc->dma_addr prior to initializing it
      with dma-mapped address.
      login_tx_desc is a part of iser_conn structure and is used only once
      during login negotiation, so the issue is fixed by eliminating
      dma_sync call for this buffer using a special case routine.
      
      Cc: <stable@vger.kernel.org>
      Reviewed-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
      Reviewed-by: default avatarDon Dutile <ddutile@redhat.com>
      Signed-off-by: default avatarAlex Estrin <alex.estrin@intel.com>
      Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
      Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a664281b
    • Erez Shitrit's avatar
      IB/mlx5: Fetch soft WQE's on fatal error state · e355402c
      Erez Shitrit authored
      commit 7b74a83c upstream.
      
      On fatal error the driver simulates CQE's for ULPs that rely on
      completion of all their posted work-request.
      
      For the GSI traffic, the mlx5 has its own mechanism that sends the
      completions via software CQE's directly to the relevant CQ.
      
      This should be kept in fatal error too, so the driver should simulate
      such CQE's with the specified error state in order to complete GSI QP
      work requests.
      
      Without the fix the next deadlock might appears:
              schedule_timeout+0x274/0x350
              wait_for_common+0xec/0x240
              mcast_remove_one+0xd0/0x120 [ib_core]
              ib_unregister_device+0x12c/0x230 [ib_core]
              mlx5_ib_remove+0xc4/0x270 [mlx5_ib]
              mlx5_detach_device+0x184/0x1a0 [mlx5_core]
              mlx5_unload_one+0x308/0x340 [mlx5_core]
              mlx5_pci_err_detected+0x74/0xe0 [mlx5_core]
      
      Cc: <stable@vger.kernel.org> # 4.7
      Fixes: 89ea94a7 ("IB/mlx5: Reset flow support for IB kernel ULPs")
      Signed-off-by: default avatarErez Shitrit <erezsh@mellanox.com>
      Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
      Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e355402c
    • Alex Estrin's avatar
      IB/{hfi1, qib}: Add handling of kernel restart · 9cac0a08
      Alex Estrin authored
      commit 8d3e7113 upstream.
      
      A warm restart will fail to unload the driver, leaving link state
      potentially flapping up to the point the BIOS resets the adapter.
      Correct the issue by hooking the shutdown pci method,
      which will bring port down.
      
      Cc: <stable@vger.kernel.org> # 4.9.x
      Reviewed-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
      Signed-off-by: default avatarAlex Estrin <alex.estrin@intel.com>
      Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
      Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9cac0a08
    • Mike Marciniszyn's avatar
      IB/qib: Fix DMA api warning with debug kernel · 9321e830
      Mike Marciniszyn authored
      commit 0252f733 upstream.
      
      The following error occurs in a debug build when running MPI PSM:
      
      [  307.415911] WARNING: CPU: 4 PID: 23867 at lib/dma-debug.c:1158
      check_unmap+0x4ee/0xa20
      [  307.455661] ib_qib 0000:05:00.0: DMA-API: device driver failed to check map
      error[device address=0x00000000df82b000] [size=4096 bytes] [mapped as page]
      [  307.517494] Modules linked in:
      [  307.531584]  ib_isert iscsi_target_mod ib_srpt target_core_mod rpcrdma
      sunrpc ib_srp scsi_transport_srp scsi_tgt ib_iser libiscsi ib_ipoib
      scsi_transport_iscsi rdma_ucm ib_ucm ib_uverbs ib_umad rdma_cm ib_cm iw_cm
      ib_qib intel_powerclamp coretemp rdmavt intel_rapl iosf_mbi kvm_intel kvm
      irqbypass crc32_pclmul ghash_clmulni_intel ipmi_ssif ib_core aesni_intel sg
      ipmi_si lrw gf128mul dca glue_helper ipmi_devintf iTCO_wdt gpio_ich hpwdt
      iTCO_vendor_support ablk_helper hpilo acpi_power_meter cryptd ipmi_msghandler
      ie31200_edac shpchp pcc_cpufreq lpc_ich pcspkr ip_tables xfs libcrc32c sd_mod
      crc_t10dif crct10dif_generic mgag200 i2c_algo_bit drm_kms_helper syscopyarea
      sysfillrect sysimgblt fb_sys_fops ttm ahci crct10dif_pclmul crct10dif_common
      drm crc32c_intel libahci tg3 libata serio_raw ptp i2c_core
      [  307.846113]  pps_core dm_mirror dm_region_hash dm_log dm_mod
      [  307.866505] CPU: 4 PID: 23867 Comm: mpitests-IMB-MP Kdump: loaded Not
      tainted 3.10.0-862.el7.x86_64.debug #1
      [  307.911178] Hardware name: HP ProLiant DL320e Gen8, BIOS J05 11/09/2013
      [  307.944206] Call Trace:
      [  307.956973]  [<ffffffffbd9e915b>] dump_stack+0x19/0x1b
      [  307.982201]  [<ffffffffbd2a2f58>] __warn+0xd8/0x100
      [  308.005999]  [<ffffffffbd2a2fdf>] warn_slowpath_fmt+0x5f/0x80
      [  308.034260]  [<ffffffffbd5f667e>] check_unmap+0x4ee/0xa20
      [  308.060801]  [<ffffffffbd41acaa>] ? page_add_file_rmap+0x2a/0x1d0
      [  308.090689]  [<ffffffffbd5f6c4d>] debug_dma_unmap_page+0x9d/0xb0
      [  308.120155]  [<ffffffffbd4082e0>] ? might_fault+0xa0/0xb0
      [  308.146656]  [<ffffffffc07761a5>] qib_tid_free.isra.14+0x215/0x2a0 [ib_qib]
      [  308.180739]  [<ffffffffc0776bf4>] qib_write+0x894/0x1280 [ib_qib]
      [  308.210733]  [<ffffffffbd540b00>] ? __inode_security_revalidate+0x70/0x80
      [  308.244837]  [<ffffffffbd53c2b7>] ? security_file_permission+0x27/0xb0
      [  308.266025] qib_ib0.8006: multicast join failed for
      ff12:401b:8006:0000:0000:0000:ffff:ffff, status -22
      [  308.323421]  [<ffffffffbd46f5d3>] vfs_write+0xc3/0x1f0
      [  308.347077]  [<ffffffffbd492a5c>] ? fget_light+0xfc/0x510
      [  308.372533]  [<ffffffffbd47045a>] SyS_write+0x8a/0x100
      [  308.396456]  [<ffffffffbd9ff355>] system_call_fastpath+0x1c/0x21
      
      The code calls a qib_map_page() which has never correctly tested for a
      mapping error.
      
      Fix by testing for pci_dma_mapping_error() in all cases and properly
      handling the failure in the caller.
      
      Additionally, streamline qib_map_page() arguments to satisfy just
      the single caller.
      
      Cc: <stable@vger.kernel.org>
      Reviewed-by: default avatarAlex Estrin <alex.estrin@intel.com>
      Tested-by: default avatarDon Dutile <ddutile@redhat.com>
      Reviewed-by: default avatarDon Dutile <ddutile@redhat.com>
      Signed-off-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
      Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
      Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9321e830
    • Stefan M Schaeckeler's avatar
      of: unittest: for strings, account for trailing \0 in property length field · f92ec84c
      Stefan M Schaeckeler authored
      commit 3b9cf790 upstream.
      
      For strings, account for trailing \0 in property length field:
      
      This is consistent with how dtc builds string properties.
      
      Function __of_prop_dup() would misbehave on such properties as it duplicates
      properties based on the property length field creating new string values
      without trailing \0s.
      Signed-off-by: default avatarStefan M Schaeckeler <sschaeck@cisco.com>
      Reviewed-by: default avatarFrank Rowand <frank.rowand@sony.com>
      Tested-by: default avatarFrank Rowand <frank.rowand@sony.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f92ec84c
    • Will Deacon's avatar
      arm64: mm: Ensure writes to swapper are ordered wrt subsequent cache maintenance · fb6786ce
      Will Deacon authored
      commit 71c8fc0c upstream.
      
      When rewriting swapper using nG mappings, we must performance cache
      maintenance around each page table access in order to avoid coherency
      problems with the host's cacheable alias under KVM. To ensure correct
      ordering of the maintenance with respect to Device memory accesses made
      with the Stage-1 MMU disabled, DMBs need to be added between the
      maintenance and the corresponding memory access.
      
      This patch adds a missing DMB between writing a new page table entry and
      performing a clean+invalidate on the same line.
      
      Fixes: f992b4df ("arm64: kpti: Add ->enable callback to remap swapper using nG mappings")
      Cc: <stable@vger.kernel.org> # 4.16.x-
      Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fb6786ce
    • Will Deacon's avatar
      arm64: kpti: Use early_param for kpti= command-line option · 12942d52
      Will Deacon authored
      commit b5b7dd64 upstream.
      
      We inspect __kpti_forced early on as part of the cpufeature enable
      callback which remaps the swapper page table using non-global entries.
      
      Ensure that __kpti_forced has been updated to reflect the kpti=
      command-line option before we start using it.
      
      Fixes: ea1e3de8 ("arm64: entry: Add fake CPU feature for unmapping the kernel at EL0")
      Cc: <stable@vger.kernel.org> # 4.16.x-
      Reported-by: default avatarWei Xu <xuwei5@hisilicon.com>
      Tested-by: default avatarSudeep Holla <sudeep.holla@arm.com>
      Tested-by: default avatarWei Xu <xuwei5@hisilicon.com>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12942d52
    • David Rivshin's avatar
      ARM: 8764/1: kgdb: fix NUMREGBYTES so that gdb_regs[] is the correct size · 8f274993
      David Rivshin authored
      commit 76ed0b80 upstream.
      
      NUMREGBYTES (which is used as the size for gdb_regs[]) is incorrectly
      based on DBG_MAX_REG_NUM instead of GDB_MAX_REGS. DBG_MAX_REG_NUM
      is the number of total registers, while GDB_MAX_REGS is the number
      of 'unsigned longs' it takes to serialize those registers. Since
      FP registers require 3 'unsigned longs' each, DBG_MAX_REG_NUM is
      smaller than GDB_MAX_REGS.
      
      This causes GDB 8.0 give the following error on connect:
      "Truncated register 19 in remote 'g' packet"
      
      This also causes the register serialization/deserialization logic
      to overflow gdb_regs[], overwriting whatever follows.
      
      Fixes: 834b2964 ("kgdb,arm: fix register dump")
      Cc: <stable@vger.kernel.org> # 2.6.37+
      Signed-off-by: default avatarDavid Rivshin <drivshin@allworx.com>
      Acked-by: default avatarRabin Vincent <rabin@rab.in>
      Tested-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8f274993
    • Mahesh Salgaonkar's avatar
      powerpc/fadump: Unregister fadump on kexec down path. · 81d6e715
      Mahesh Salgaonkar authored
      commit 722cde76 upstream.
      
      Unregister fadump on kexec down path otherwise the fadump registration
      in new kexec-ed kernel complains that fadump is already registered.
      This makes new kernel to continue using fadump registered by previous
      kernel which may lead to invalid vmcore generation. Hence this patch
      fixes this issue by un-registering fadump in fadump_cleanup() which is
      called during kexec path so that new kernel can register fadump with
      new valid values.
      
      Fixes: b500afff ("fadump: Invalidate registration and release reserved memory for general use.")
      Cc: stable@vger.kernel.org # v3.4+
      Signed-off-by: default avatarMahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      81d6e715
    • Gautham R. Shenoy's avatar
      cpuidle: powernv: Fix promotion from snooze if next state disabled · 443004a6
      Gautham R. Shenoy authored
      commit 0a4ec6aa upstream.
      
      The commit 78eaa10f ("cpuidle: powernv/pseries: Auto-promotion of
      snooze to deeper idle state") introduced a timeout for the snooze idle
      state so that it could be eventually be promoted to a deeper idle
      state. The snooze timeout value is static and set to the target
      residency of the next idle state, which would train the cpuidle
      governor to pick the next idle state eventually.
      
      The unfortunate side-effect of this is that if the next idle state(s)
      is disabled, the CPU will forever remain in snooze, despite the fact
      that the system is completely idle, and other deeper idle states are
      available.
      
      This patch fixes the issue by dynamically setting the snooze timeout
      to the target residency of the next enabled state on the device.
      
      Before Patch:
        POWER8 : Only nap disabled.
        $ cpupower monitor sleep 30
        sleep took 30.01297 seconds and exited with status 0
                      |Idle_Stats
        PKG |CORE|CPU | snoo | Nap  | Fast
           0|   8|   0| 96.41|  0.00|  0.00
           0|   8|   1| 96.43|  0.00|  0.00
           0|   8|   2| 96.47|  0.00|  0.00
           0|   8|   3| 96.35|  0.00|  0.00
           0|   8|   4| 96.37|  0.00|  0.00
           0|   8|   5| 96.37|  0.00|  0.00
           0|   8|   6| 96.47|  0.00|  0.00
           0|   8|   7| 96.47|  0.00|  0.00
      
        POWER9: Shallow states (stop0lite, stop1lite, stop2lite, stop0, stop1,
        stop2) disabled:
        $ cpupower monitor sleep 30
        sleep took 30.05033 seconds and exited with status 0
                      |Idle_Stats
        PKG |CORE|CPU | snoo | stop | stop | stop | stop | stop | stop | stop | stop
           0|  16|   0| 89.79|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00
           0|  16|   1| 90.12|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00
           0|  16|   2| 90.21|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00
           0|  16|   3| 90.29|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00
      
      After Patch:
        POWER8 : Only nap disabled.
        $ cpupower monitor sleep 30
        sleep took 30.01200 seconds and exited with status 0
                      |Idle_Stats
        PKG |CORE|CPU | snoo | Nap  | Fast
           0|   8|   0| 16.58|  0.00| 77.21
           0|   8|   1| 18.42|  0.00| 75.38
           0|   8|   2|  4.70|  0.00| 94.09
           0|   8|   3| 17.06|  0.00| 81.73
           0|   8|   4|  3.06|  0.00| 95.73
           0|   8|   5|  7.00|  0.00| 96.80
           0|   8|   6|  1.00|  0.00| 98.79
           0|   8|   7|  5.62|  0.00| 94.17
      
        POWER9: Shallow states (stop0lite, stop1lite, stop2lite, stop0, stop1,
        stop2) disabled:
      
        $ cpupower monitor sleep 30
        sleep took 30.02110 seconds and exited with status 0
                      |Idle_Stats
        PKG |CORE|CPU | snoo | stop | stop | stop | stop | stop | stop | stop | stop
           0|   0|   0|  0.69|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  9.39| 89.70
           0|   0|   1|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.05| 93.21
           0|   0|   2|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00| 89.93
           0|   0|   3|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00|  0.00| 93.26
      
      Fixes: 78eaa10f ("cpuidle: powernv/pseries: Auto-promotion of snooze to deeper idle state")
      Cc: stable@vger.kernel.org # v4.2+
      Signed-off-by: default avatarGautham R. Shenoy <ego@linux.vnet.ibm.com>
      Reviewed-by: default avatarBalbir Singh <bsingharora@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      443004a6
    • Alexey Kardashevskiy's avatar
      powerpc/powernv/ioda2: Remove redundant free of TCE pages · f9b25660
      Alexey Kardashevskiy authored
      commit 98fd72fe upstream.
      
      When IODA2 creates a PE, it creates an IOMMU table with it_ops::free
      set to pnv_ioda2_table_free() which calls pnv_pci_ioda2_table_free_pages().
      
      Since iommu_tce_table_put() calls it_ops::free when the last reference
      to the table is released, explicit call to pnv_pci_ioda2_table_free_pages()
      is not needed so let's remove it.
      
      This should fix double free in the case of PCI hotuplug as
      pnv_pci_ioda2_table_free_pages() does not reset neither
      iommu_table::it_base nor ::it_size.
      
      This was not exposed by SRIOV as it uses different code path via
      pnv_pcibios_sriov_disable().
      
      IODA1 does not inialize it_ops::free so it does not have this issue.
      
      Fixes: c5f7700b ("powerpc/powernv: Dynamically release PE")
      Cc: stable@vger.kernel.org # v4.8+
      Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f9b25660
    • Michael Neuling's avatar
      powerpc/ptrace: Fix enforcement of DAWR constraints · 90f88f05
      Michael Neuling authored
      commit cd6ef7ee upstream.
      
      Back when we first introduced the DAWR, in commit 4ae7ebe9
      ("powerpc: Change hardware breakpoint to allow longer ranges"), we
      screwed up the constraint making it a 1024 byte boundary rather than a
      512. This makes the check overly permissive. Fortunately GDB is the
      only real user and it always did they right thing, so we never
      noticed.
      
      This fixes the constraint to 512 bytes.
      
      Fixes: 4ae7ebe9 ("powerpc: Change hardware breakpoint to allow longer ranges")
      Cc: stable@vger.kernel.org # v3.9+
      Signed-off-by: default avatarMichael Neuling <mikey@neuling.org>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      90f88f05
    • Michael Neuling's avatar
      powerpc/ptrace: Fix setting 512B aligned breakpoints with PTRACE_SET_DEBUGREG · 5ea3b9bd
      Michael Neuling authored
      commit 4f7c06e2 upstream.
      
      In commit e2a800be ("powerpc/hw_brk: Fix off by one error when
      validating DAWR region end") we fixed setting the DAWR end point to
      its max value via PPC_PTRACE_SETHWDEBUG. Unfortunately we broke
      PTRACE_SET_DEBUGREG when setting a 512 byte aligned breakpoint.
      
      PTRACE_SET_DEBUGREG currently sets the length of the breakpoint to
      zero (memset() in hw_breakpoint_init()). This worked with
      arch_validate_hwbkpt_settings() before the above patch was applied but
      is now broken if the breakpoint is 512byte aligned.
      
      This sets the length of the breakpoint to 8 bytes when using
      PTRACE_SET_DEBUGREG.
      
      Fixes: e2a800be ("powerpc/hw_brk: Fix off by one error when validating DAWR region end")
      Cc: stable@vger.kernel.org # v3.11+
      Signed-off-by: default avatarMichael Neuling <mikey@neuling.org>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5ea3b9bd
    • Aneesh Kumar K.V's avatar
      powerpc/mm/hash: Add missing isync prior to kernel stack SLB switch · 10e46042
      Aneesh Kumar K.V authored
      commit 91d06971 upstream.
      
      Currently we do not have an isync, or any other context synchronizing
      instruction prior to the slbie/slbmte in _switch() that updates the
      SLB entry for the kernel stack.
      
      However that is not correct as outlined in the ISA.
      
      From Power ISA Version 3.0B, Book III, Chapter 11, page 1133:
      
        "Changing the contents of ... the contents of SLB entries ... can
         have the side effect of altering the context in which data
         addresses and instruction addresses are interpreted, and in which
         instructions are executed and data accesses are performed.
         ...
         These side effects need not occur in program order, and therefore
         may require explicit synchronization by software.
         ...
         The synchronizing instruction before the context-altering
         instruction ensures that all instructions up to and including that
         synchronizing instruction are fetched and executed in the context
         that existed before the alteration."
      
      And page 1136:
      
        "For data accesses, the context synchronizing instruction before the
         slbie, slbieg, slbia, slbmte, tlbie, or tlbiel instruction ensures
         that all preceding instructions that access data storage have
         completed to a point at which they have reported all exceptions
         they will cause."
      
      We're not aware of any bugs caused by this, but it should be fixed
      regardless.
      
      Add the missing isync when updating kernel stack SLB entry.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
      [mpe: Flesh out change log with more ISA text & explanation]
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      10e46042