1. 26 Sep, 2018 40 commits
    • Thierry Reding's avatar
      drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping · eddbab90
      Thierry Reding authored
      [ Upstream commit b59fb482 ]
      
      Depending on the kernel configuration, early ARM architecture setup code
      may have attached the GPU to a DMA/IOMMU mapping that transparently uses
      the IOMMU to back the DMA API. Tegra requires special handling for IOMMU
      backed buffers (a special bit in the GPU's MMU page tables indicates the
      memory path to take: via the SMMU or directly to the memory controller).
      Transparently backing DMA memory with an IOMMU prevents Nouveau from
      properly handling such memory accesses and causes memory access faults.
      
      As a side-note: buffers other than those allocated in instance memory
      don't need to be physically contiguous from the GPU's perspective since
      the GPU can map them into contiguous buffers using its own MMU. Mapping
      these buffers through the IOMMU is unnecessary and will even lead to
      performance degradation because of the additional translation. One
      exception to this are compressible buffers which need large pages. In
      order to enable these large pages, multiple small pages will have to be
      combined into one large (I/O virtually contiguous) mapping via the
      IOMMU. However, that is a topic outside the scope of this fix and isn't
      currently supported. An implementation will want to explicitly create
      these large pages in the Nouveau driver, so detaching from a DMA/IOMMU
      mapping would still be required.
      Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
      Acked-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarRobin Murphy <robin.murphy@arm.com>
      Tested-by: default avatarNicolas Chauvet <kwizart@gmail.com>
      Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eddbab90
    • Nicholas Mc Guire's avatar
      ARM: hisi: check of_iomap and fix missing of_node_put · f615d18b
      Nicholas Mc Guire authored
      [ Upstream commit 81646a3d ]
      
      of_find_compatible_node() returns a device node with refcount incremented
      and thus needs an explicit of_node_put(). Further relying on an unchecked
      of_iomap() which can return NULL is problematic here, after all ctrl_base
      is critical enough for hix5hd2_set_cpu() to call BUG() if not available
      so a check seems mandated here.
      Signed-off-by: default avatarNicholas Mc Guire <hofrat@osadl.org>
      0002 Fixes: commit 06cc5c1d ("ARM: hisi: enable hix5hd2 SoC")
      Signed-off-by: default avatarWei Xu <xuwei5@hisilicon.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f615d18b
    • Nicholas Mc Guire's avatar
      ARM: hisi: fix error handling and missing of_node_put · eafee071
      Nicholas Mc Guire authored
      [ Upstream commit 9f30b5ae ]
      
      of_iomap() can return NULL which seems critical here and thus should be
      explicitly flagged so that the cause of system halting can be understood.
      As of_find_compatible_node() is returning a device node with refcount
      incremented it must be explicitly decremented here.
      Signed-off-by: default avatarNicholas Mc Guire <hofrat@osadl.org>
      Fixes: commit 7fda91e7 ("ARM: hisi: enable smp for HiP01")
      Signed-off-by: default avatarWei Xu <xuwei5@hisilicon.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eafee071
    • Nicholas Mc Guire's avatar
      ARM: hisi: handle of_iomap and fix missing of_node_put · 96d4584f
      Nicholas Mc Guire authored
      [ Upstream commit d396cb18 ]
      
      Relying on an unchecked of_iomap() which can return NULL is problematic
      here, an explicit check seems mandatory. Also the call to
      of_find_compatible_node() returns a device node with refcount incremented
      therefor an explicit of_node_put() is needed here.
      Signed-off-by: default avatarNicholas Mc Guire <hofrat@osadl.org>
      Fixes: commit 22bae429 ("ARM: hi3xxx: add hotplug support")
      Signed-off-by: default avatarWei Xu <xuwei5@hisilicon.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      96d4584f
    • Paul Burton's avatar
      MIPS: loongson64: cs5536: Fix PCI_OHCI_INT_REG reads · f13ad779
      Paul Burton authored
      [ Upstream commit cd87668d ]
      
      The PCI_OHCI_INT_REG case in pci_ohci_read_reg() contains the following
      if statement:
      
        if ((lo & 0x00000f00) == CS5536_USB_INTR)
      
      CS5536_USB_INTR expands to the constant 11, which gives us the following
      condition which can never evaluate true:
      
        if ((lo & 0xf00) == 11)
      
      At least when using GCC 8.1.0 this falls foul of the tautoligcal-compare
      warning, and since the code is built with the -Werror flag the build
      fails.
      
      Fix this by shifting lo right by 8 bits in order to match the
      corresponding PCI_OHCI_INT_REG case in pci_ohci_write_reg().
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Patchwork: https://patchwork.linux-mips.org/patch/19861/
      Cc: Huacai Chen <chenhc@lemote.com>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: linux-mips@linux-mips.org
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f13ad779
    • Jann Horn's avatar
      mtdchar: fix overflows in adjustment of `count` · 15332502
      Jann Horn authored
      [ Upstream commit 6c6bc9ea ]
      
      The first checks in mtdchar_read() and mtdchar_write() attempt to limit
      `count` such that `*ppos + count <= mtd->size`. However, they ignore the
      possibility of `*ppos > mtd->size`, allowing the calculation of `count` to
      wrap around. `mtdchar_lseek()` prevents seeking beyond mtd->size, but the
      pread/pwrite syscalls bypass this.
      
      I haven't found any codepath on which this actually causes dangerous
      behavior, but it seems like a sensible change anyway.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      15332502
    • Ronny Chevalier's avatar
      audit: fix use-after-free in audit_add_watch · 20d6cff3
      Ronny Chevalier authored
      [ Upstream commit baa2a4fd ]
      
      audit_add_watch stores locally krule->watch without taking a reference
      on watch. Then, it calls audit_add_to_parent, and uses the watch stored
      locally.
      
      Unfortunately, it is possible that audit_add_to_parent updates
      krule->watch.
      When it happens, it also drops a reference of watch which
      could free the watch.
      
      How to reproduce (with KASAN enabled):
      
          auditctl -w /etc/passwd -F success=0 -k test_passwd
          auditctl -w /etc/passwd -F success=1 -k test_passwd2
      
      The second call to auditctl triggers the use-after-free, because
      audit_to_parent updates krule->watch to use a previous existing watch
      and drops the reference to the newly created watch.
      
      To fix the issue, we grab a reference of watch and we release it at the
      end of the function.
      Signed-off-by: default avatarRonny Chevalier <ronny.chevalier@hp.com>
      Reviewed-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      20d6cff3
    • Maciej W. Rozycki's avatar
      binfmt_elf: Respect error return from `regset->active' · 0b726a48
      Maciej W. Rozycki authored
      [ Upstream commit 2f819db5 ]
      
      The regset API documented in <linux/regset.h> defines -ENODEV as the
      result of the `->active' handler to be used where the feature requested
      is not available on the hardware found.  However code handling core file
      note generation in `fill_thread_core_info' interpretes any non-zero
      result from the `->active' handler as the regset requested being active.
      Consequently processing continues (and hopefully gracefully fails later
      on) rather than being abandoned right away for the regset requested.
      
      Fix the problem then by making the code proceed only if a positive
      result is returned from the `->active' handler.
      Signed-off-by: default avatarMaciej W. Rozycki <macro@mips.com>
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Fixes: 4206d3aa ("elf core dump: notes user_regset")
      Patchwork: https://patchwork.linux-mips.org/patch/19332/
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: linux-fsdevel@vger.kernel.org
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0b726a48
    • Dan Carpenter's avatar
      CIFS: fix wrapping bugs in num_entries() · 74fb4686
      Dan Carpenter authored
      commit 56446f21 upstream.
      
      The problem is that "entryptr + next_offset" and "entryptr + len + size"
      can wrap.  I ended up changing the type of "entryptr" because it makes
      the math easier when we don't have to do so much casting.
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Reviewed-by: default avatarAurelien Aptel <aaptel@suse.com>
      Reviewed-by: default avatarPavel Shilovsky <pshilov@microsoft.com>
      CC: Stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      74fb4686
    • Dan Carpenter's avatar
      cifs: prevent integer overflow in nxt_dir_entry() · 2d363196
      Dan Carpenter authored
      commit 8ad8aa35 upstream.
      
      The "old_entry + le32_to_cpu(pDirInfo->NextEntryOffset)" can wrap
      around so I have added a check for integer overflow.
      Reported-by: default avatarDr Silvio Cesare of InfoSect <silvio.cesare@gmail.com>
      Reviewed-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
      Reviewed-by: default avatarAurelien Aptel <aaptel@suse.com>
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      CC: Stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2d363196
    • Jia-Ju Bai's avatar
      usb: cdc-wdm: Fix a sleep-in-atomic-context bug in service_outstanding_interrupt() · b8b53ade
      Jia-Ju Bai authored
      commit 6e22e3af upstream.
      
      wdm_in_callback() is a completion handler function for the USB driver.
      So it should not sleep. But it calls service_outstanding_interrupt(),
      which calls usb_submit_urb() with GFP_KERNEL.
      
      To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC.
      
      This bug is found by my static analysis tool DSAC.
      Signed-off-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b8b53ade
    • Ben Hutchings's avatar
      USB: yurex: Fix buffer over-read in yurex_write() · 4be36bcc
      Ben Hutchings authored
      commit 7e10f14e upstream.
      
      If the written data starts with a digit, yurex_write() tries to parse
      it as an integer using simple_strtoull().  This requires a null-
      terminator, and currently there's no guarantee that there is one.
      
      (The sample program at
      https://github.com/NeoCat/YUREX-driver-for-Linux/blob/master/sample/yurex_clock.pl
      writes an integer without a null terminator.  It seems like it must
      have worked by chance!)
      
      Always add a null byte after the written data.  Enlarge the buffer
      to allow for this.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4be36bcc
    • Jia-Ju Bai's avatar
      usb: misc: uss720: Fix two sleep-in-atomic-context bugs · b214cde7
      Jia-Ju Bai authored
      commit bc8acc21 upstream.
      
      async_complete() in uss720.c is a completion handler function for the
      USB driver. So it should not sleep, but it is can sleep according to the
      function call paths (from bottom to top) in Linux-4.16.
      
      [FUNC] set_1284_register(GFP_KERNEL)
      drivers/usb/misc/uss720.c, 372:
        set_1284_register in parport_uss720_frob_control
      drivers/parport/ieee1284.c, 560:
        [FUNC_PTR]parport_uss720_frob_control in parport_ieee1284_ack_data_avail
      drivers/parport/ieee1284.c, 577:
        parport_ieee1284_ack_data_avail in parport_ieee1284_interrupt
      ./include/linux/parport.h, 474:
        parport_ieee1284_interrupt in parport_generic_irq
      drivers/usb/misc/uss720.c, 116:
        parport_generic_irq in async_complete
      
      [FUNC] get_1284_register(GFP_KERNEL)
      drivers/usb/misc/uss720.c, 382:
        get_1284_register in parport_uss720_read_status
      drivers/parport/ieee1284.c, 555:
        [FUNC_PTR]parport_uss720_read_status in parport_ieee1284_ack_data_avail
      drivers/parport/ieee1284.c, 577:
        parport_ieee1284_ack_data_avail in parport_ieee1284_interrupt
      ./include/linux/parport.h, 474:
        parport_ieee1284_interrupt in parport_generic_irq
      drivers/usb/misc/uss720.c, 116:
        parport_generic_irq in async_complete
      
      Note that [FUNC_PTR] means a function pointer call is used.
      
      To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC.
      
      These bugs are found by my static analysis tool DSAC.
      Signed-off-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b214cde7
    • Johan Hovold's avatar
      USB: serial: io_ti: fix array underflow in completion handler · 403c5c23
      Johan Hovold authored
      commit 691a03cf upstream.
      
      As reported by Dan Carpenter, a malicious USB device could set
      port_number to a negative value and we would underflow the port array in
      the interrupt completion handler.
      
      As these devices only have one or two ports, fix this by making sure we
      only consider the seventh bit when determining the port number (and
      ignore bits 0xb0 which are typically set to 0x30).
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Cc: stable <stable@vger.kernel.org>
      Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      403c5c23
    • Alan Stern's avatar
      USB: net2280: Fix erroneous synchronization change · f409f340
      Alan Stern authored
      commit dec3c23c upstream.
      
      Commit f16443a0 ("USB: gadgetfs, dummy-hcd, net2280: fix locking
      for callbacks") was based on a serious misunderstanding.  It
      introduced regressions into both the dummy-hcd and net2280 drivers.
      
      The problem in dummy-hcd was fixed by commit 7dbd8f4c ("USB:
      dummy-hcd: Fix erroneous synchronization change"), but the problem in
      net2280 remains.  Namely: the ->disconnect(), ->suspend(), ->resume(),
      and ->reset() callbacks must be invoked without the private lock held;
      otherwise a deadlock will occur when the callback routine tries to
      interact with the UDC driver.
      
      This patch largely is a reversion of the relevant parts of
      f16443a0.  It also drops the private lock around the calls to
      ->suspend() and ->resume() (something the earlier patch forgot to do).
      This is safe from races with device interrupts because it occurs
      within the interrupt handler.
      
      Finally, the patch changes where the ->disconnect() callback is
      invoked when net2280_pullup() turns the pullup off.  Rather than
      making the callback from within stop_activity() at a time when dropping
      the private lock could be unsafe, the callback is moved to a point
      after the lock has already been dropped.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Fixes: f16443a0 ("USB: gadgetfs, dummy-hcd, net2280: fix locking for callbacks")
      Reported-by: default avatarD. Ziesche <dziesche@zes.com>
      Tested-by: default avatarD. Ziesche <dziesche@zes.com>
      CC: <stable@vger.kernel.org>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f409f340
    • Maxence Duprès's avatar
      USB: add quirk for WORLDE Controller KS49 or Prodipe MIDI 49C USB controller · 34f1df0f
      Maxence Duprès authored
      commit 9b83a1c3 upstream.
      
      WORLDE Controller KS49 or Prodipe MIDI 49C USB controller
      cause a -EPROTO error, a communication restart and loop again.
      
      This issue has already been fixed for KS25.
      https://lore.kernel.org/patchwork/patch/753077/
      
      I just add device 201 for KS49 in quirks.c to get it works.
      Signed-off-by: default avatarLaurent Roux <xpros64@hotmail.fr>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      34f1df0f
    • Jia-Ju Bai's avatar
      usb: host: u132-hcd: Fix a sleep-in-atomic-context bug in u132_get_frame() · 637acc7b
      Jia-Ju Bai authored
      commit 6d4f268f upstream.
      
      i_usX2Y_subs_startup in usbusx2yaudio.c is a completion handler function
      for the USB driver. So it should not sleep, but it is can sleep
      according to the function call paths (from bottom to top) in Linux-4.16.
      
      [FUNC] msleep
      drivers/usb/host/u132-hcd.c, 2558:
      	msleep in u132_get_frame
      drivers/usb/core/hcd.c, 2231:
      	[FUNC_PTR]u132_get_frame in usb_hcd_get_frame_number
      drivers/usb/core/usb.c, 822:
      	usb_hcd_get_frame_number in usb_get_current_frame_number
      sound/usb/usx2y/usbusx2yaudio.c, 303:
      	usb_get_current_frame_number in i_usX2Y_urb_complete
      sound/usb/usx2y/usbusx2yaudio.c, 366:
      	i_usX2Y_urb_complete in i_usX2Y_subs_startup
      
      Note that [FUNC_PTR] means a function pointer call is used.
      
      To fix this bug, msleep() is replaced with mdelay().
      
      This bug is found by my static analysis tool DSAC.
      Signed-off-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      637acc7b
    • Mathias Nyman's avatar
      usb: Avoid use-after-free by flushing endpoints early in usb_set_interface() · 35bcdf48
      Mathias Nyman authored
      commit f9a5b4f5 upstream.
      
      The steps taken by usb core to set a new interface is very different from
      what is done on the xHC host side.
      
      xHC hardware will do everything in one go. One command is used to set up
      new endpoints, free old endpoints, check bandwidth, and run the new
      endpoints.
      
      All this is done by xHC when usb core asks the hcd to check for
      available bandwidth. At this point usb core has not yet flushed the old
      endpoints, which will cause use-after-free issues in xhci driver as
      queued URBs are cancelled on a re-allocated endpoint.
      
      To resolve this add a call to usb_disable_interface() which will flush
      the endpoints before calling usb_hcd_alloc_bandwidth()
      
      Additional checks in xhci driver will also be implemented to gracefully
      handle stale URB cancel on freed and re-allocated endpoints
      
      Cc: <stable@vger.kernel.org>
      Reported-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      35bcdf48
    • Tim Anderson's avatar
      USB: Add quirk to support DJI CineSSD · 49c05a00
      Tim Anderson authored
      commit f45681f9 upstream.
      
      This device does not correctly handle the LPM operations.
      
      Also, the device cannot handle ATA pass-through commands
      and locks up when attempted while running in super speed.
      
      This patch adds the equivalent quirk logic as found in uas.
      Signed-off-by: default avatarTim Anderson <tsa@biglakesoftware.com>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      49c05a00
    • Mathias Nyman's avatar
      usb: Don't die twice if PCI xhci host is not responding in resume · c343fc80
      Mathias Nyman authored
      commit f3dc41c5 upstream.
      
      usb_hc_died() should only be called once, and with the primary HCD
      as parameter. It will mark both primary and secondary hcd's dead.
      
      Remove the extra call to usb_cd_died with the shared hcd as parameter.
      
      Fixes: ff9d78b3 ("USB: Set usb_hcd->state and flags for shared roothubs")
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Cc: stable <stable@vger.kernel.org>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c343fc80
    • Gustavo A. R. Silva's avatar
      misc: hmc6352: fix potential Spectre v1 · 68fe884e
      Gustavo A. R. Silva authored
      commit de916736 upstream.
      
      val is indirectly controlled by user-space, hence leading to a
      potential exploitation of the Spectre variant 1 vulnerability.
      
      This issue was detected with the help of Smatch:
      
      drivers/misc/hmc6352.c:54 compass_store() warn: potential spectre issue
      'map' [r]
      
      Fix this by sanitizing val before using it to index map
      
      Notice that given that speculation windows are large, the policy is
      to kill the speculation on the first load and not worry if it can be
      completed with a dependent load/store [1].
      
      [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      68fe884e
    • K. Y. Srinivasan's avatar
      Tools: hv: Fix a bug in the key delete code · c527796f
      K. Y. Srinivasan authored
      commit 86503bd3 upstream.
      
      Fix a bug in the key delete code - the num_records range
      from 0 to num_records-1.
      Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
      Reported-by: default avatarDavid Binderman <dcb314@hotmail.com>
      Cc: <stable@vger.kernel.org>
      Reviewed-by: default avatarMichael Kelley <mikelley@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c527796f
    • Aaron Knister's avatar
      IB/ipoib: Avoid a race condition between start_xmit and cm_rep_handler · ee4d1a30
      Aaron Knister authored
      commit 816e846c upstream.
      
      Inside of start_xmit() the call to check if the connection is up and the
      queueing of the packets for later transmission is not atomic which leaves
      a window where cm_rep_handler can run, set the connection up, dequeue
      pending packets and leave the subsequently queued packets by start_xmit()
      sitting on neigh->queue until they're dropped when the connection is torn
      down. This only applies to connected mode. These dropped packets can
      really upset TCP, for example, and cause multi-minute delays in
      transmission for open connections.
      
      Here's the code in start_xmit where we check to see if the connection is
      up:
      
             if (ipoib_cm_get(neigh)) {
                     if (ipoib_cm_up(neigh)) {
                             ipoib_cm_send(dev, skb, ipoib_cm_get(neigh));
                             goto unref;
                     }
             }
      
      The race occurs if cm_rep_handler execution occurs after the above
      connection check (specifically if it gets to the point where it acquires
      priv->lock to dequeue pending skb's) but before the below code snippet in
      start_xmit where packets are queued.
      
             if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
                     push_pseudo_header(skb, phdr->hwaddr);
                     spin_lock_irqsave(&priv->lock, flags);
                     __skb_queue_tail(&neigh->queue, skb);
                     spin_unlock_irqrestore(&priv->lock, flags);
             } else {
                     ++dev->stats.tx_dropped;
                     dev_kfree_skb_any(skb);
             }
      
      The patch acquires the netif tx lock in cm_rep_handler for the section
      where it sets the connection up and dequeues and retransmits deferred
      skb's.
      
      Fixes: 839fcaba ("IPoIB: Connected mode experimental support")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarAaron Knister <aaron.s.knister@nasa.gov>
      Tested-by: default avatarIra Weiny <ira.weiny@intel.com>
      Reviewed-by: default avatarIra Weiny <ira.weiny@intel.com>
      Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ee4d1a30
    • Juergen Gross's avatar
      xen/netfront: fix waiting for xenbus state change · a739cb3e
      Juergen Gross authored
      commit 8edfe2e9 upstream.
      
      Commit 822fb18a ("xen-netfront: wait xenbus state change when load
      module manually") added a new wait queue to wait on for a state change
      when the module is loaded manually. Unfortunately there is no wakeup
      anywhere to stop that waiting.
      
      Instead of introducing a new wait queue rename the existing
      module_unload_q to module_wq and use it for both purposes (loading and
      unloading).
      
      As any state change of the backend might be intended to stop waiting
      do the wake_up_all() in any case when netback_changed() is called.
      
      Fixes: 822fb18a ("xen-netfront: wait xenbus state change when load module manually")
      Cc: <stable@vger.kernel.org> #4.18
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a739cb3e
    • Bin Yang's avatar
      pstore: Fix incorrect persistent ram buffer mapping · 1cd01dba
      Bin Yang authored
      commit 831b624d upstream.
      
      persistent_ram_vmap() returns the page start vaddr.
      persistent_ram_iomap() supports non-page-aligned mapping.
      
      persistent_ram_buffer_map() always adds offset-in-page to the vaddr
      returned from these two functions, which causes incorrect mapping of
      non-page-aligned persistent ram buffer.
      
      By default ftrace_size is 4096 and max_ftrace_cnt is nr_cpu_ids. Without
      this patch, the zone_sz in ramoops_init_przs() is 4096/nr_cpu_ids which
      might not be page aligned. If the offset-in-page > 2048, the vaddr will be
      in next page. If the next page is not mapped, it will cause kernel panic:
      
      [    0.074231] BUG: unable to handle kernel paging request at ffffa19e0081b000
      ...
      [    0.075000] RIP: 0010:persistent_ram_new+0x1f8/0x39f
      ...
      [    0.075000] Call Trace:
      [    0.075000]  ramoops_init_przs.part.10.constprop.15+0x105/0x260
      [    0.075000]  ramoops_probe+0x232/0x3a0
      [    0.075000]  platform_drv_probe+0x3e/0xa0
      [    0.075000]  driver_probe_device+0x2cd/0x400
      [    0.075000]  __driver_attach+0xe4/0x110
      [    0.075000]  ? driver_probe_device+0x400/0x400
      [    0.075000]  bus_for_each_dev+0x70/0xa0
      [    0.075000]  driver_attach+0x1e/0x20
      [    0.075000]  bus_add_driver+0x159/0x230
      [    0.075000]  ? do_early_param+0x95/0x95
      [    0.075000]  driver_register+0x70/0xc0
      [    0.075000]  ? init_pstore_fs+0x4d/0x4d
      [    0.075000]  __platform_driver_register+0x36/0x40
      [    0.075000]  ramoops_init+0x12f/0x131
      [    0.075000]  do_one_initcall+0x4d/0x12c
      [    0.075000]  ? do_early_param+0x95/0x95
      [    0.075000]  kernel_init_freeable+0x19b/0x222
      [    0.075000]  ? rest_init+0xbb/0xbb
      [    0.075000]  kernel_init+0xe/0xfc
      [    0.075000]  ret_from_fork+0x3a/0x50
      Signed-off-by: default avatarBin Yang <bin.yang@intel.com>
      [kees: add comments describing the mapping differences, updated commit log]
      Fixes: 24c3d2f3 ("staging: android: persistent_ram: Make it possible to use memory outside of bootmem")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1cd01dba
    • Parav Pandit's avatar
      RDMA/cma: Protect cma dev list with lock · 07c63fd0
      Parav Pandit authored
      commit 954a8e3a upstream.
      
      When AF_IB addresses are used during rdma_resolve_addr() a lock is not
      held. A cma device can get removed while list traversal is in progress
      which may lead to crash. ie
      
              CPU0                                     CPU1
              ====                                     ====
      rdma_resolve_addr()
       cma_resolve_ib_dev()
        list_for_each()                         cma_remove_one()
          cur_dev->device                        mutex_lock(&lock)
                                                  list_del();
                                                 mutex_unlock(&lock);
                                                 cma_process_remove();
      
      
      Therefore, hold a lock while traversing the list which avoids such
      situation.
      
      Cc: <stable@vger.kernel.org> # 3.10
      Fixes: f17df3b0 ("RDMA/cma: Add support for AF_IB to rdma_resolve_addr()")
      Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
      Reviewed-by: default avatarDaniel Jurgens <danielj@mellanox.com>
      Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
      Reviewed-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
      Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      07c63fd0
    • Xiao Liang's avatar
      xen-netfront: fix warn message as irq device name has '/' · 12c3ba18
      Xiao Liang authored
      [ Upstream commit 21f2706b ]
      
      There is a call trace generated after commit 2d408c0d(
      xen-netfront: fix queue name setting). There is no 'device/vif/xx-q0-tx' file found
      under /proc/irq/xx/.
      
      This patch only picks up device type and id as its name.
      
      With the patch, now /proc/interrupts looks like below and the warning message gone:
       70:         21          0          0          0   xen-dyn    -event     vif0-q0-tx
       71:         15          0          0          0   xen-dyn    -event     vif0-q0-rx
       72:         14          0          0          0   xen-dyn    -event     vif0-q1-tx
       73:         33          0          0          0   xen-dyn    -event     vif0-q1-rx
       74:         12          0          0          0   xen-dyn    -event     vif0-q2-tx
       75:         24          0          0          0   xen-dyn    -event     vif0-q2-rx
       76:         19          0          0          0   xen-dyn    -event     vif0-q3-tx
       77:         21          0          0          0   xen-dyn    -event     vif0-q3-rx
      
      Below is call trace information without this patch:
      
      name 'device/vif/0-q0-tx'
      WARNING: CPU: 2 PID: 37 at fs/proc/generic.c:174 __xlate_proc_name+0x85/0xa0
      RIP: 0010:__xlate_proc_name+0x85/0xa0
      RSP: 0018:ffffb85c40473c18 EFLAGS: 00010286
      RAX: 0000000000000000 RBX: 0000000000000006 RCX: 0000000000000006
      RDX: 0000000000000007 RSI: 0000000000000096 RDI: ffff984c7f516930
      RBP: ffffb85c40473cb8 R08: 000000000000002c R09: 0000000000000229
      R10: 0000000000000000 R11: 0000000000000001 R12: ffffb85c40473c98
      R13: ffffb85c40473cb8 R14: ffffb85c40473c50 R15: 0000000000000000
      FS:  0000000000000000(0000) GS:ffff984c7f500000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007f69b6899038 CR3: 000000001c20a006 CR4: 00000000001606e0
      Call Trace:
      __proc_create+0x45/0x230
      ? snprintf+0x49/0x60
      proc_mkdir_data+0x35/0x90
      register_handler_proc+0xef/0x110
      ? proc_register+0xfc/0x110
      ? proc_create_data+0x70/0xb0
      __setup_irq+0x39b/0x660
      ? request_threaded_irq+0xad/0x160
      request_threaded_irq+0xf5/0x160
      ? xennet_tx_buf_gc+0x1d0/0x1d0 [xen_netfront]
      bind_evtchn_to_irqhandler+0x3d/0x70
      ? xenbus_alloc_evtchn+0x41/0xa0
      netback_changed+0xa46/0xcda [xen_netfront]
      ? find_watch+0x40/0x40
      xenwatch_thread+0xc5/0x160
      ? finish_wait+0x80/0x80
      kthread+0x112/0x130
      ? kthread_create_worker_on_cpu+0x70/0x70
      ret_from_fork+0x35/0x40
      Code: 81 5c 00 48 85 c0 75 cc 5b 49 89 2e 31 c0 5d 4d 89 3c 24 41 5c 41 5d 41 5e 41 5f c3 4c 89 ee 48 c7 c7 40 4f 0e b4 e8 65 ea d8 ff <0f> 0b b8 fe ff ff ff 5b 5d 41 5c 41 5d 41 5e 41 5f c3 66 0f 1f
      ---[ end trace 650e5561b0caab3a ]---
      Signed-off-by: default avatarXiao Liang <xiliang@redhat.com>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12c3ba18
    • Michael Müller's avatar
      crypto: sharah - Unregister correct algorithms for SAHARA 3 · 71501201
      Michael Müller authored
      [ Upstream commit 0e7d4d93 ]
      
      This patch fixes two typos related to unregistering algorithms supported by
      SAHARAH 3. In sahara_register_algs the wrong algorithms are unregistered
      in case of an error. In sahara_unregister_algs the wrong array is used to
      determine the iteration count.
      Signed-off-by: default avatarMichael Müller <michael@fds-team.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      71501201
    • Randy Dunlap's avatar
      platform/x86: toshiba_acpi: Fix defined but not used build warnings · da189ebd
      Randy Dunlap authored
      [ Upstream commit c2e2a618 ]
      
      Fix a build warning in toshiba_acpi.c when CONFIG_PROC_FS is not enabled
      by marking the unused function as __maybe_unused.
      
      ../drivers/platform/x86/toshiba_acpi.c:1685:12: warning: 'version_proc_show' defined but not used [-Wunused-function]
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: Azael Avalos <coproscefalo@gmail.com>
      Cc: platform-driver-x86@vger.kernel.org
      Cc: Andy Shevchenko <andy@infradead.org>
      Signed-off-by: default avatarDarren Hart (VMware) <dvhart@infradead.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      da189ebd
    • Julian Wiedmann's avatar
      s390/qeth: reset layer2 attribute on layer switch · a4b8132c
      Julian Wiedmann authored
      [ Upstream commit 70551dc4 ]
      
      After the subdriver's remove() routine has completed, the card's layer
      mode is undetermined again. Reflect this in the layer2 field.
      
      If qeth_dev_layer2_store() hits an error after remove() was called, the
      card _always_ requires a setup(), even if the previous layer mode is
      requested again.
      But qeth_dev_layer2_store() bails out early if the requested layer mode
      still matches the current one. So unless we reset the layer2 field,
      re-probing the card back to its previous mode is currently not possible.
      Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a4b8132c
    • Julian Wiedmann's avatar
      s390/qeth: fix race in used-buffer accounting · 29162495
      Julian Wiedmann authored
      [ Upstream commit a702349a ]
      
      By updating q->used_buffers only _after_ do_QDIO() has completed, there
      is a potential race against the buffer's TX completion. In the unlikely
      case that the TX completion path wins, qeth_qdio_output_handler() would
      decrement the counter before qeth_flush_buffers() even incremented it.
      Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      29162495
    • Loic Poulain's avatar
      arm64: dts: qcom: db410c: Fix Bluetooth LED trigger · 4f3381ab
      Loic Poulain authored
      [ Upstream commit e53db018 ]
      
      Current LED trigger, 'bt', is not known/used by any existing driver.
      Fix this by renaming it to 'bluetooth-power' trigger which is
      controlled by the Bluetooth subsystem.
      
      Fixes: 9943230c ("arm64: dts: qcom: Add apq8016-sbc board LED's related device nodes")
      Signed-off-by: default avatarLoic Poulain <loic.poulain@linaro.org>
      Signed-off-by: default avatarAndy Gross <andy.gross@linaro.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4f3381ab
    • Vitaly Kuznetsov's avatar
      xen-netfront: fix queue name setting · 2e0c018c
      Vitaly Kuznetsov authored
      [ Upstream commit 2d408c0d ]
      
      Commit f599c64f ("xen-netfront: Fix race between device setup and
      open") changed the initialization order: xennet_create_queues() now
      happens before we do register_netdev() so using netdev->name in
      xennet_init_queue() is incorrect, we end up with the following in
      /proc/interrupts:
      
       60:        139          0   xen-dyn    -event     eth%d-q0-tx
       61:        265          0   xen-dyn    -event     eth%d-q0-rx
       62:        234          0   xen-dyn    -event     eth%d-q1-tx
       63:          1          0   xen-dyn    -event     eth%d-q1-rx
      
      and this looks ugly. Actually, using early netdev name (even when it's
      already set) is also not ideal: nowadays we tend to rename eth devices
      and queue name may end up not corresponding to the netdev name.
      
      Use nodename from xenbus device for queue naming: this can't change in VM's
      lifetime. Now /proc/interrupts looks like
      
       62:        202          0   xen-dyn    -event     device/vif/0-q0-tx
       63:        317          0   xen-dyn    -event     device/vif/0-q0-rx
       64:        262          0   xen-dyn    -event     device/vif/0-q1-tx
       65:         17          0   xen-dyn    -event     device/vif/0-q1-rx
      
      Fixes: f599c64f ("xen-netfront: Fix race between device setup and open")
      Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
      Reviewed-by: default avatarRoss Lagerwall <ross.lagerwall@citrix.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2e0c018c
    • Manikanta Pubbisetty's avatar
      mac80211: restrict delayed tailroom needed decrement · 77332078
      Manikanta Pubbisetty authored
      [ Upstream commit 133bf90d ]
      
      As explained in ieee80211_delayed_tailroom_dec(), during roam,
      keys of the old AP will be destroyed and new keys will be
      installed. Deletion of the old key causes
      crypto_tx_tailroom_needed_cnt to go from 1 to 0 and the new key
      installation causes a transition from 0 to 1.
      
      Whenever crypto_tx_tailroom_needed_cnt transitions from 0 to 1,
      we invoke synchronize_net(); the reason for doing this is to avoid
      a race in the TX path as explained in increment_tailroom_need_count().
      This synchronize_net() operation can be slow and can affect the station
      roam time. To avoid this, decrementing the crypto_tx_tailroom_needed_cnt
      is delayed for a while so that upon installation of new key the
      transition would be from 1 to 2 instead of 0 to 1 and thereby
      improving the roam time.
      
      This is all correct for a STA iftype, but deferring the tailroom_needed
      decrement for other iftypes may be unnecessary.
      
      For example, let's consider the case of a 4-addr client connecting to
      an AP for which AP_VLAN interface is also created, let the initial
      value for tailroom_needed on the AP be 1.
      
      * 4-addr client connects to the AP (AP: tailroom_needed = 1)
      * AP will clear old keys, delay decrement of tailroom_needed count
      * AP_VLAN is created, it takes the tailroom count from master
        (AP_VLAN: tailroom_needed = 1, AP: tailroom_needed = 1)
      * Install new key for the station, assume key is plumbed in the HW,
        there won't be any change in tailroom_needed count on AP iface
      * Delayed decrement of tailroom_needed count on AP
        (AP: tailroom_needed = 0, AP_VLAN: tailroom_needed = 1)
      
      Because of the delayed decrement on AP iface, tailroom_needed count goes
      out of sync between AP(master iface) and AP_VLAN(slave iface) and
      there would be unnecessary tailroom created for the packets going
      through AP_VLAN iface.
      
      Also, WARN_ONs were observed while trying to bring down the AP_VLAN
      interface:
      (warn_slowpath_common) (warn_slowpath_null+0x18/0x20)
      (warn_slowpath_null) (ieee80211_free_keys+0x114/0x1e4)
      (ieee80211_free_keys) (ieee80211_del_virtual_monitor+0x51c/0x850)
      (ieee80211_del_virtual_monitor) (ieee80211_stop+0x30/0x3c)
      (ieee80211_stop) (__dev_close_many+0x94/0xb8)
      (__dev_close_many) (dev_close_many+0x5c/0xc8)
      
      Restricting delayed decrement to station interface alone fixes the problem
      and it makes sense to do so because delayed decrement is done to improve
      roam time which is applicable only for client devices.
      Signed-off-by: default avatarManikanta Pubbisetty <mpubbise@codeaurora.org>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      77332078
    • Paul Cercueil's avatar
      MIPS: jz4740: Bump zload address · 2ca7b66d
      Paul Cercueil authored
      [ Upstream commit c6ea7e97 ]
      
      Having the zload address at 0x8060.0000 means the size of the
      uncompressed kernel cannot be bigger than around 6 MiB, as it is
      deflated at address 0x8001.0000.
      
      This limit is too small; a kernel with some built-in drivers and things
      like debugfs enabled will already be over 6 MiB in size, and so will
      fail to extract properly.
      
      To fix this, we bump the zload address from 0x8060.0000 to 0x8100.0000.
      
      This is fine, as all the boards featuring Ingenic JZ SoCs have at least
      32 MiB of RAM, and use u-boot or compatible bootloaders which won't
      hardcode the load address but read it from the uImage's header.
      Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Patchwork: https://patchwork.linux-mips.org/patch/19787/
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2ca7b66d
    • Nicholas Piggin's avatar
      powerpc/powernv: opal_put_chars partial write fix · 8e8c3ba5
      Nicholas Piggin authored
      [ Upstream commit bd90284c ]
      
      The intention here is to consume and discard the remaining buffer
      upon error. This works if there has not been a previous partial write.
      If there has been, then total_len is no longer total number of bytes
      to copy. total_len is always "bytes left to copy", so it should be
      added to written bytes.
      
      This code may not be exercised any more if partial writes will not be
      hit, but this is a small bugfix before a larger change.
      Reviewed-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8e8c3ba5
    • Sandipan Das's avatar
      perf powerpc: Fix callchain ip filtering · d4aa4e4f
      Sandipan Das authored
      [ Upstream commit c715fcfd ]
      
      For powerpc64, redundant entries in the callchain are filtered out by
      determining the state of the return address and the stack frame using
      DWARF debug information.
      
      For making these filtering decisions we must analyze the debug
      information for the location corresponding to the program counter value,
      i.e. the first entry in the callchain, and not the LR value; otherwise,
      perf may filter out either the second or the third entry in the
      callchain incorrectly.
      
      This can be observed on a powerpc64le system running Fedora 27 as shown
      below.
      
      Case 1 - Attaching a probe at inet_pton+0x8 (binary offset 0x15af28).
               Return address is still in LR and a new stack frame is not yet
               allocated. The LR value, i.e. the second entry, should not be
      	 filtered out.
      
        # objdump -d /usr/lib64/libc-2.26.so | less
        ...
        000000000010eb10 <gaih_inet.constprop.7>:
        ...
          10fa48:       78 bb e4 7e     mr      r4,r23
          10fa4c:       0a 00 60 38     li      r3,10
          10fa50:       d9 b4 04 48     bl      15af28 <inet_pton+0x8>
          10fa54:       00 00 00 60     nop
          10fa58:       ac f4 ff 4b     b       10ef04 <gaih_inet.constprop.7+0x3f4>
        ...
        0000000000110450 <getaddrinfo>:
        ...
          1105a8:       54 00 ff 38     addi    r7,r31,84
          1105ac:       58 00 df 38     addi    r6,r31,88
          1105b0:       69 e5 ff 4b     bl      10eb18 <gaih_inet.constprop.7+0x8>
          1105b4:       78 1b 71 7c     mr      r17,r3
          1105b8:       50 01 7f e8     ld      r3,336(r31)
        ...
        000000000015af20 <inet_pton>:
          15af20:       0b 00 4c 3c     addis   r2,r12,11
          15af24:       e0 c1 42 38     addi    r2,r2,-15904
          15af28:       a6 02 08 7c     mflr    r0
          15af2c:       f0 ff c1 fb     std     r30,-16(r1)
          15af30:       f8 ff e1 fb     std     r31,-8(r1)
        ...
      
        # perf probe -x /usr/lib64/libc-2.26.so -a inet_pton+0x8
        # perf record -e probe_libc:inet_pton -g ping -6 -c 1 ::1
        # perf script
      
      Before:
      
        ping  4507 [002] 514985.546540: probe_libc:inet_pton: (7fffa7dbaf28)
                    7fffa7dbaf28 __GI___inet_pton+0x8 (/usr/lib64/libc-2.26.so)
                    7fffa7d705b4 getaddrinfo+0x164 (/usr/lib64/libc-2.26.so)
                       13fb52d70 _init+0xbfc (/usr/bin/ping)
                    7fffa7c836a0 generic_start_main.isra.0+0x140 (/usr/lib64/libc-2.26.so)
                    7fffa7c83898 __libc_start_main+0xb8 (/usr/lib64/libc-2.26.so)
                               0 [unknown] ([unknown])
      
      After:
      
        ping  4507 [002] 514985.546540: probe_libc:inet_pton: (7fffa7dbaf28)
                    7fffa7dbaf28 __GI___inet_pton+0x8 (/usr/lib64/libc-2.26.so)
                    7fffa7d6fa54 gaih_inet.constprop.7+0xf44 (/usr/lib64/libc-2.26.so)
                    7fffa7d705b4 getaddrinfo+0x164 (/usr/lib64/libc-2.26.so)
                       13fb52d70 _init+0xbfc (/usr/bin/ping)
                    7fffa7c836a0 generic_start_main.isra.0+0x140 (/usr/lib64/libc-2.26.so)
                    7fffa7c83898 __libc_start_main+0xb8 (/usr/lib64/libc-2.26.so)
                               0 [unknown] ([unknown])
      
      Case 2 - Attaching a probe at _int_malloc+0x180 (binary offset 0x9cf10).
               Return address in still in LR and a new stack frame has already
               been allocated but not used. The caller's caller, i.e. the third
      	 entry, is invalid and should be filtered out and not the second
      	 one.
      
        # objdump -d /usr/lib64/libc-2.26.so | less
        ...
        000000000009cd90 <_int_malloc>:
           9cd90:       17 00 4c 3c     addis   r2,r12,23
           9cd94:       70 a3 42 38     addi    r2,r2,-23696
           9cd98:       26 00 80 7d     mfcr    r12
           9cd9c:       f8 ff e1 fb     std     r31,-8(r1)
           9cda0:       17 00 e4 3b     addi    r31,r4,23
           9cda4:       d8 ff 61 fb     std     r27,-40(r1)
           9cda8:       78 23 9b 7c     mr      r27,r4
           9cdac:       1f 00 bf 2b     cmpldi  cr7,r31,31
           9cdb0:       f0 ff c1 fb     std     r30,-16(r1)
           9cdb4:       b0 ff c1 fa     std     r22,-80(r1)
           9cdb8:       78 1b 7e 7c     mr      r30,r3
           9cdbc:       08 00 81 91     stw     r12,8(r1)
           9cdc0:       11 ff 21 f8     stdu    r1,-240(r1)
           9cdc4:       4c 01 9d 41     bgt     cr7,9cf10 <_int_malloc+0x180>
           9cdc8:       20 00 a4 2b     cmpldi  cr7,r4,32
        ...
           9cf08:       00 00 00 60     nop
           9cf0c:       00 00 42 60     ori     r2,r2,0
           9cf10:       e4 06 ff 7b     rldicr  r31,r31,0,59
           9cf14:       40 f8 a4 7f     cmpld   cr7,r4,r31
           9cf18:       68 05 9d 41     bgt     cr7,9d480 <_int_malloc+0x6f0>
        ...
        000000000009e3c0 <tcache_init.part.4>:
        ...
           9e420:       40 02 80 38     li      r4,576
           9e424:       78 fb e3 7f     mr      r3,r31
           9e428:       71 e9 ff 4b     bl      9cd98 <_int_malloc+0x8>
           9e42c:       00 00 a3 2f     cmpdi   cr7,r3,0
           9e430:       78 1b 7e 7c     mr      r30,r3
        ...
        000000000009f7a0 <__libc_malloc>:
        ...
           9f8f8:       00 00 89 2f     cmpwi   cr7,r9,0
           9f8fc:       1c ff 9e 40     bne     cr7,9f818 <__libc_malloc+0x78>
           9f900:       c9 ea ff 4b     bl      9e3c8 <tcache_init.part.4+0x8>
           9f904:       00 00 00 60     nop
           9f908:       e8 90 22 e9     ld      r9,-28440(r2)
        ...
      
        # perf probe -x /usr/lib64/libc-2.26.so -a _int_malloc+0x180
        # perf record -e probe_libc:_int_malloc -g ./test-malloc
        # perf script
      
      Before:
      
        test-malloc  6554 [009] 515975.797403: probe_libc:_int_malloc: (7fffa6e6cf10)
                    7fffa6e6cf10 _int_malloc+0x180 (/usr/lib64/libc-2.26.so)
                    7fffa6dd0000 [unknown] (/usr/lib64/libc-2.26.so)
                    7fffa6e6f904 malloc+0x164 (/usr/lib64/libc-2.26.so)
                    7fffa6e6f9fc malloc+0x25c (/usr/lib64/libc-2.26.so)
                        100006b4 main+0x38 (/home/testuser/test-malloc)
                    7fffa6df36a0 generic_start_main.isra.0+0x140 (/usr/lib64/libc-2.26.so)
                    7fffa6df3898 __libc_start_main+0xb8 (/usr/lib64/libc-2.26.so)
                               0 [unknown] ([unknown])
      
      After:
      
        test-malloc  6554 [009] 515975.797403: probe_libc:_int_malloc: (7fffa6e6cf10)
                    7fffa6e6cf10 _int_malloc+0x180 (/usr/lib64/libc-2.26.so)
                    7fffa6e6e42c tcache_init.part.4+0x6c (/usr/lib64/libc-2.26.so)
                    7fffa6e6f904 malloc+0x164 (/usr/lib64/libc-2.26.so)
                    7fffa6e6f9fc malloc+0x25c (/usr/lib64/libc-2.26.so)
                        100006b4 main+0x38 (/home/sandipan/test-malloc)
                    7fffa6df36a0 generic_start_main.isra.0+0x140 (/usr/lib64/libc-2.26.so)
                    7fffa6df3898 __libc_start_main+0xb8 (/usr/lib64/libc-2.26.so)
                               0 [unknown] ([unknown])
      Signed-off-by: default avatarSandipan Das <sandipan@linux.ibm.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Maynard Johnson <maynard@us.ibm.com>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Fixes: a60335ba ("perf tools powerpc: Adjust callchain based on DWARF debug info")
      Link: http://lkml.kernel.org/r/24bb726d91ed173aebc972ec3f41a2ef2249434e.1530724939.git.sandipan@linux.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d4aa4e4f
    • Krzysztof Kozlowski's avatar
      ARM: exynos: Clear global variable on init error path · 016353ef
      Krzysztof Kozlowski authored
      [ Upstream commit cd480691 ]
      
      For most of Exynos SoCs, Power Management Unit (PMU) address space is
      mapped into global variable 'pmu_base_addr' very early when initializing
      PMU interrupt controller.  A lot of other machine code depends on it so
      when doing iounmap() on this address, clear the global as well to avoid
      usage of invalid value (pointing to unmapped memory region).
      
      Properly mapped PMU address space is a requirement for all other machine
      code so this fix is purely theoretical.  Boot will fail immediately in
      many other places after following this error path.
      Signed-off-by: default avatarKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      016353ef
    • Fredrik Noring's avatar
      fbdev: Distinguish between interlaced and progressive modes · 57a1dd74
      Fredrik Noring authored
      [ Upstream commit 1ba0a59c ]
      
      I discovered the problem when developing a frame buffer driver for the
      PlayStation 2 (not yet merged), using the following video modes for the
      PlayStation 3 in drivers/video/fbdev/ps3fb.c:
      
          }, {
              /* 1080if */
              "1080if", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
              FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
          }, {
              /* 1080pf */
              "1080pf", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5,
              FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
          },
      
      In ps3fb_probe, the mode_option module parameter is used with fb_find_mode
      but it can only select the interlaced variant of 1920x1080 since the loop
      matching the modes does not take the difference between interlaced and
      progressive modes into account.
      
      In short, without the patch, progressive 1920x1080 cannot be chosen as a
      mode_option parameter since fb_find_mode (falsely) thinks interlace is a
      perfect match.
      Signed-off-by: default avatarFredrik Noring <noring@nocrew.org>
      Cc: "Maciej W. Rozycki" <macro@linux-mips.org>
      [b.zolnierkie: updated patch description]
      Signed-off-by: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      57a1dd74
    • Sandipan Das's avatar
      perf powerpc: Fix callchain ip filtering when return address is in a register · e71975f0
      Sandipan Das authored
      [ Upstream commit 9068533e ]
      
      For powerpc64, perf will filter out the second entry in the callchain,
      i.e. the LR value, if the return address of the function corresponding
      to the probed location has already been saved on its caller's stack.
      
      The state of the return address is determined using debug information.
      At any point within a function, if the return address is already saved
      somewhere, a DWARF expression can tell us about its location. If the
      return address in still in LR only, no DWARF expression would exist.
      
      Typically, the instructions in a function's prologue first copy the LR
      value to R0 and then pushes R0 on to the stack. If LR has already been
      copied to R0 but R0 is yet to be pushed to the stack, we can still get a
      DWARF expression that says that the return address is in R0. This is
      indicating that getting a DWARF expression for the return address does
      not guarantee the fact that it has already been saved on the stack.
      
      This can be observed on a powerpc64le system running Fedora 27 as shown
      below.
      
        # objdump -d /usr/lib64/libc-2.26.so | less
        ...
        000000000015af20 <inet_pton>:
          15af20:       0b 00 4c 3c     addis   r2,r12,11
          15af24:       e0 c1 42 38     addi    r2,r2,-15904
          15af28:       a6 02 08 7c     mflr    r0
          15af2c:       f0 ff c1 fb     std     r30,-16(r1)
          15af30:       f8 ff e1 fb     std     r31,-8(r1)
          15af34:       78 1b 7f 7c     mr      r31,r3
          15af38:       78 23 83 7c     mr      r3,r4
          15af3c:       78 2b be 7c     mr      r30,r5
          15af40:       10 00 01 f8     std     r0,16(r1)
          15af44:       c1 ff 21 f8     stdu    r1,-64(r1)
          15af48:       28 00 81 f8     std     r4,40(r1)
        ...
      
        # readelf --debug-dump=frames-interp /usr/lib64/libc-2.26.so | less
        ...
        00027024 0000000000000024 00027028 FDE cie=00000000 pc=000000000015af20..000000000015af88
           LOC           CFA      r30   r31   ra
        000000000015af20 r1+0     u     u     u
        000000000015af34 r1+0     c-16  c-8   r0
        000000000015af48 r1+64    c-16  c-8   c+16
        000000000015af5c r1+0     c-16  c-8   c+16
        000000000015af78 r1+0     u     u
        ...
      
        # perf probe -x /usr/lib64/libc-2.26.so -a inet_pton+0x18
        # perf record -e probe_libc:inet_pton -g ping -6 -c 1 ::1
        # perf script
      
      Before:
      
        ping  2829 [005] 512917.460174: probe_libc:inet_pton: (7fff7e2baf38)
                    7fff7e2baf38 __GI___inet_pton+0x18 (/usr/lib64/libc-2.26.so)
                    7fff7e2705b4 getaddrinfo+0x164 (/usr/lib64/libc-2.26.so)
                       12f152d70 _init+0xbfc (/usr/bin/ping)
                    7fff7e1836a0 generic_start_main.isra.0+0x140 (/usr/lib64/libc-2.26.so)
                    7fff7e183898 __libc_start_main+0xb8 (/usr/lib64/libc-2.26.so)
                               0 [unknown] ([unknown])
      
      After:
      
        ping  2829 [005] 512917.460174: probe_libc:inet_pton: (7fff7e2baf38)
                    7fff7e2baf38 __GI___inet_pton+0x18 (/usr/lib64/libc-2.26.so)
                    7fff7e26fa54 gaih_inet.constprop.7+0xf44 (/usr/lib64/libc-2.26.so)
                    7fff7e2705b4 getaddrinfo+0x164 (/usr/lib64/libc-2.26.so)
                       12f152d70 _init+0xbfc (/usr/bin/ping)
                    7fff7e1836a0 generic_start_main.isra.0+0x140 (/usr/lib64/libc-2.26.so)
                    7fff7e183898 __libc_start_main+0xb8 (/usr/lib64/libc-2.26.so)
                               0 [unknown] ([unknown])
      Reported-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
      Signed-off-by: default avatarSandipan Das <sandipan@linux.ibm.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Maynard Johnson <maynard@us.ibm.com>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Link: http://lkml.kernel.org/r/66e848a7bdf2d43b39210a705ff6d828a0865661.1530724939.git.sandipan@linux.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e71975f0