1. 04 Aug, 2019 40 commits
    • Dmitry Vyukov's avatar
      mm/kmemleak.c: fix check for softirq context · 478cf2d4
      Dmitry Vyukov authored
      [ Upstream commit 6ef90569 ]
      
      in_softirq() is a wrong predicate to check if we are in a softirq
      context.  It also returns true if we have BH disabled, so objects are
      falsely stamped with "softirq" comm.  The correct predicate is
      in_serving_softirq().
      
      If user does cat from /sys/kernel/debug/kmemleak previously they would
      see this, which is clearly wrong, this is system call context (see the
      comm):
      
      unreferenced object 0xffff88805bd661c0 (size 64):
        comm "softirq", pid 0, jiffies 4294942959 (age 12.400s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00  ................
          00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
        backtrace:
          [<0000000007dcb30c>] kmemleak_alloc_recursive include/linux/kmemleak.h:55 [inline]
          [<0000000007dcb30c>] slab_post_alloc_hook mm/slab.h:439 [inline]
          [<0000000007dcb30c>] slab_alloc mm/slab.c:3326 [inline]
          [<0000000007dcb30c>] kmem_cache_alloc_trace+0x13d/0x280 mm/slab.c:3553
          [<00000000969722b7>] kmalloc include/linux/slab.h:547 [inline]
          [<00000000969722b7>] kzalloc include/linux/slab.h:742 [inline]
          [<00000000969722b7>] ip_mc_add1_src net/ipv4/igmp.c:1961 [inline]
          [<00000000969722b7>] ip_mc_add_src+0x36b/0x400 net/ipv4/igmp.c:2085
          [<00000000a4134b5f>] ip_mc_msfilter+0x22d/0x310 net/ipv4/igmp.c:2475
          [<00000000d20248ad>] do_ip_setsockopt.isra.0+0x19fe/0x1c00 net/ipv4/ip_sockglue.c:957
          [<000000003d367be7>] ip_setsockopt+0x3b/0xb0 net/ipv4/ip_sockglue.c:1246
          [<000000003c7c76af>] udp_setsockopt+0x4e/0x90 net/ipv4/udp.c:2616
          [<000000000c1aeb23>] sock_common_setsockopt+0x3e/0x50 net/core/sock.c:3130
          [<000000000157b92b>] __sys_setsockopt+0x9e/0x120 net/socket.c:2078
          [<00000000a9f3d058>] __do_sys_setsockopt net/socket.c:2089 [inline]
          [<00000000a9f3d058>] __se_sys_setsockopt net/socket.c:2086 [inline]
          [<00000000a9f3d058>] __x64_sys_setsockopt+0x26/0x30 net/socket.c:2086
          [<000000001b8da885>] do_syscall_64+0x7c/0x1a0 arch/x86/entry/common.c:301
          [<00000000ba770c62>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      now they will see this:
      
      unreferenced object 0xffff88805413c800 (size 64):
        comm "syz-executor.4", pid 8960, jiffies 4294994003 (age 14.350s)
        hex dump (first 32 bytes):
          00 7a 8a 57 80 88 ff ff e0 00 00 01 00 00 00 00  .z.W............
          00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000c5d3be64>] kmemleak_alloc_recursive include/linux/kmemleak.h:55 [inline]
          [<00000000c5d3be64>] slab_post_alloc_hook mm/slab.h:439 [inline]
          [<00000000c5d3be64>] slab_alloc mm/slab.c:3326 [inline]
          [<00000000c5d3be64>] kmem_cache_alloc_trace+0x13d/0x280 mm/slab.c:3553
          [<0000000023865be2>] kmalloc include/linux/slab.h:547 [inline]
          [<0000000023865be2>] kzalloc include/linux/slab.h:742 [inline]
          [<0000000023865be2>] ip_mc_add1_src net/ipv4/igmp.c:1961 [inline]
          [<0000000023865be2>] ip_mc_add_src+0x36b/0x400 net/ipv4/igmp.c:2085
          [<000000003029a9d4>] ip_mc_msfilter+0x22d/0x310 net/ipv4/igmp.c:2475
          [<00000000ccd0a87c>] do_ip_setsockopt.isra.0+0x19fe/0x1c00 net/ipv4/ip_sockglue.c:957
          [<00000000a85a3785>] ip_setsockopt+0x3b/0xb0 net/ipv4/ip_sockglue.c:1246
          [<00000000ec13c18d>] udp_setsockopt+0x4e/0x90 net/ipv4/udp.c:2616
          [<0000000052d748e3>] sock_common_setsockopt+0x3e/0x50 net/core/sock.c:3130
          [<00000000512f1014>] __sys_setsockopt+0x9e/0x120 net/socket.c:2078
          [<00000000181758bc>] __do_sys_setsockopt net/socket.c:2089 [inline]
          [<00000000181758bc>] __se_sys_setsockopt net/socket.c:2086 [inline]
          [<00000000181758bc>] __x64_sys_setsockopt+0x26/0x30 net/socket.c:2086
          [<00000000d4b73623>] do_syscall_64+0x7c/0x1a0 arch/x86/entry/common.c:301
          [<00000000c1098bec>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Link: http://lkml.kernel.org/r/20190517171507.96046-1-dvyukov@gmail.comSigned-off-by: default avatarDmitry Vyukov <dvyukov@google.com>
      Acked-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      478cf2d4
    • Sam Ravnborg's avatar
      sh: prevent warnings when using iounmap · 8b593377
      Sam Ravnborg authored
      [ Upstream commit 733f0025 ]
      
      When building drm/exynos for sh, as part of an allmodconfig build, the
      following warning triggered:
      
        exynos7_drm_decon.c: In function `decon_remove':
        exynos7_drm_decon.c:769:24: warning: unused variable `ctx'
          struct decon_context *ctx = dev_get_drvdata(&pdev->dev);
      
      The ctx variable is only used as argument to iounmap().
      
      In sh - allmodconfig CONFIG_MMU is not defined
      so it ended up in:
      
      \#define __iounmap(addr)	do { } while (0)
      \#define iounmap		__iounmap
      
      Fix the warning by introducing a static inline function for iounmap.
      
      This is similar to several other architectures.
      
      Link: http://lkml.kernel.org/r/20190622114208.24427-1-sam@ravnborg.orgSigned-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
      Reviewed-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Mark Brown <broonie@kernel.org>
      Cc: Inki Dae <inki.dae@samsung.com>
      Cc: Krzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8b593377
    • Oliver O'Halloran's avatar
      powerpc/eeh: Handle hugepages in ioremap space · bce3e3e8
      Oliver O'Halloran authored
      [ Upstream commit 33439620 ]
      
      In commit 4a7b06c157a2 ("powerpc/eeh: Handle hugepages in ioremap
      space") support for using hugepages in the vmalloc and ioremap areas was
      enabled for radix. Unfortunately this broke EEH MMIO error checking.
      
      Detection works by inserting a hook which checks the results of the
      ioreadXX() set of functions.  When a read returns a 0xFFs response we
      need to check for an error which we do by mapping the (virtual) MMIO
      address back to a physical address, then mapping physical address to a
      PCI device via an interval tree.
      
      When translating virt -> phys we currently assume the ioremap space is
      only populated by PAGE_SIZE mappings. If a hugepage mapping is found we
      emit a WARN_ON(), but otherwise handles the check as though a normal
      page was found. In pathalogical cases such as copying a buffer
      containing a lot of 0xFFs from BAR memory this can result in the system
      not booting because it's too busy printing WARN_ON()s.
      
      There's no real reason to assume huge pages can't be present and we're
      prefectly capable of handling them, so do that.
      
      Fixes: 4a7b06c157a2 ("powerpc/eeh: Handle hugepages in ioremap space")
      Reported-by: default avatarSachin Sant <sachinp@linux.vnet.ibm.com>
      Signed-off-by: default avatarOliver O'Halloran <oohall@gmail.com>
      Tested-by: default avatarSachin Sant <sachinp@linux.vnet.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20190710150517.27114-1-oohall@gmail.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      bce3e3e8
    • morten petersen's avatar
      mailbox: handle failed named mailbox channel request · 450233af
      morten petersen authored
      [ Upstream commit 25777e57 ]
      
      Previously, if mbox_request_channel_byname was used with a name
      which did not exist in the "mbox-names" property of a mailbox
      client, the mailbox corresponding to the last entry in the
      "mbox-names" list would be incorrectly selected.
      With this patch, -EINVAL is returned if the named mailbox is
      not found.
      Signed-off-by: default avatarMorten Borup Petersen <morten_bp@live.dk>
      Signed-off-by: default avatarJassi Brar <jaswinder.singh@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      450233af
    • Ocean Chen's avatar
      f2fs: avoid out-of-range memory access · dd1fc2ce
      Ocean Chen authored
      [ Upstream commit 56f3ce67 ]
      
      blkoff_off might over 512 due to fs corrupt or security
      vulnerability. That should be checked before being using.
      
      Use ENTRIES_IN_SUM to protect invalid value in cur_data_blkoff.
      Signed-off-by: default avatarOcean Chen <oceanchen@google.com>
      Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      dd1fc2ce
    • Masahiro Yamada's avatar
      powerpc/boot: add {get, put}_unaligned_be32 to xz_config.h · 34dd8fb9
      Masahiro Yamada authored
      [ Upstream commit 9e005b76 ]
      
      The next commit will make the way of passing CONFIG options more robust.
      Unfortunately, it would uncover another hidden issue; without this
      commit, skiroot_defconfig would be broken like this:
      
      |   WRAP    arch/powerpc/boot/zImage.pseries
      | arch/powerpc/boot/wrapper.a(decompress.o): In function `bcj_powerpc.isra.10':
      | decompress.c:(.text+0x720): undefined reference to `get_unaligned_be32'
      | decompress.c:(.text+0x7a8): undefined reference to `put_unaligned_be32'
      | make[1]: *** [arch/powerpc/boot/Makefile;383: arch/powerpc/boot/zImage.pseries] Error 1
      | make: *** [arch/powerpc/Makefile;295: zImage] Error 2
      
      skiroot_defconfig is the only defconfig that enables CONFIG_KERNEL_XZ
      for ppc, which has never been correctly built before.
      
      I figured out the root cause in lib/decompress_unxz.c:
      
      | #ifdef CONFIG_PPC
      | #      define XZ_DEC_POWERPC
      | #endif
      
      CONFIG_PPC is undefined here in the ppc bootwrapper because autoconf.h
      is not included except by arch/powerpc/boot/serial.c
      
      XZ_DEC_POWERPC is not defined, therefore, bcj_powerpc() is not compiled
      for the bootwrapper.
      
      With the next commit passing CONFIG_PPC correctly, we would realize that
      {get,put}_unaligned_be32 was missing.
      
      Unlike the other decompressors, the ppc bootwrapper duplicates all the
      necessary helpers in arch/powerpc/boot/.
      
      The other architectures define __KERNEL__ and pull in helpers for
      building the decompressors.
      
      If ppc bootwrapper had defined __KERNEL__, lib/xz/xz_private.h would
      have included <asm/unaligned.h>:
      
      | #ifdef __KERNEL__
      | #       include <linux/xz.h>
      | #       include <linux/kernel.h>
      | #       include <asm/unaligned.h>
      
      However, doing so would cause tons of definition conflicts since the
      bootwrapper has duplicated everything.
      
      I just added copies of {get,put}_unaligned_be32, following the
      bootwrapper coding convention.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20190705100144.28785-1-yamada.masahiro@socionext.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      34dd8fb9
    • Konstantin Taranov's avatar
      RDMA/rxe: Fill in wc byte_len with IB_WC_RECV_RDMA_WITH_IMM · 8baa8d68
      Konstantin Taranov authored
      [ Upstream commit bdce1290 ]
      
      Calculate the correct byte_len on the receiving side when a work
      completion is generated with IB_WC_RECV_RDMA_WITH_IMM opcode.
      
      According to the IBA byte_len must indicate the number of written bytes,
      whereas it was always equal to zero for the IB_WC_RECV_RDMA_WITH_IMM
      opcode, even though data was transferred.
      
      Fixes: 8700e3e7 ("Soft RoCE driver")
      Signed-off-by: default avatarKonstantin Taranov <konstantin.taranov@inf.ethz.ch>
      Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8baa8d68
    • Numfor Mbiziwo-Tiapo's avatar
      perf test mmap-thread-lookup: Initialize variable to suppress memory sanitizer warning · ff859fa7
      Numfor Mbiziwo-Tiapo authored
      [ Upstream commit 4e4cf62b ]
      
      Running the 'perf test' command after building perf with a memory
      sanitizer causes a warning that says:
      
        WARNING: MemorySanitizer: use-of-uninitialized-value... in mmap-thread-lookup.c
      
      Initializing the go variable to 0 silences this harmless warning.
      
      Committer warning:
      
      This was harmless, just a simple test writing whatever was at that
      sizeof(int) memory area just to signal another thread blocked reading
      that file created with pipe(). Initialize it tho so that we don't get
      this warning.
      Signed-off-by: default avatarNumfor Mbiziwo-Tiapo <nums@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mark Drayton <mbd@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lkml.kernel.org/r/20190702173716.181223-1-nums@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ff859fa7
    • Vasily Gorbik's avatar
      kallsyms: exclude kasan local symbols on s390 · c677e7ad
      Vasily Gorbik authored
      [ Upstream commit 33177f01 ]
      
      gcc asan instrumentation emits the following sequence to store frame pc
      when the kernel is built with CONFIG_RELOCATABLE:
      debug/vsprintf.s:
              .section        .data.rel.ro.local,"aw"
              .align  8
      .LC3:
              .quad   .LASANPC4826@GOTOFF
      .text
              .align  8
              .type   number, @function
      number:
      .LASANPC4826:
      
      and in case reloc is issued for LASANPC label it also gets into .symtab
      with the same address as actual function symbol:
      $ nm -n vmlinux | grep 0000000001397150
      0000000001397150 t .LASANPC4826
      0000000001397150 t number
      
      In the end kernel backtraces are almost unreadable:
      [  143.748476] Call Trace:
      [  143.748484] ([<000000002da3e62c>] .LASANPC2671+0x114/0x190)
      [  143.748492]  [<000000002eca1a58>] .LASANPC2612+0x110/0x160
      [  143.748502]  [<000000002de9d830>] print_address_description+0x80/0x3b0
      [  143.748511]  [<000000002de9dd64>] __kasan_report+0x15c/0x1c8
      [  143.748521]  [<000000002ecb56d4>] strrchr+0x34/0x60
      [  143.748534]  [<000003ff800a9a40>] kasan_strings+0xb0/0x148 [test_kasan]
      [  143.748547]  [<000003ff800a9bba>] kmalloc_tests_init+0xe2/0x528 [test_kasan]
      [  143.748555]  [<000000002da2117c>] .LASANPC4069+0x354/0x748
      [  143.748563]  [<000000002dbfbb16>] do_init_module+0x136/0x3b0
      [  143.748571]  [<000000002dbff3f4>] .LASANPC3191+0x2164/0x25d0
      [  143.748580]  [<000000002dbffc4c>] .LASANPC3196+0x184/0x1b8
      [  143.748587]  [<000000002ecdf2ec>] system_call+0xd8/0x2d8
      
      Since LASANPC labels are not even unique and get into .symtab only due
      to relocs filter them out in kallsyms.
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c677e7ad
    • Geert Uytterhoeven's avatar
      serial: sh-sci: Fix TX DMA buffer flushing and workqueue races · 7e55003b
      Geert Uytterhoeven authored
      [ Upstream commit 8493eab0 ]
      
      When uart_flush_buffer() is called, the .flush_buffer() callback zeroes
      the tx_dma_len field.  This may race with the work queue function
      handling transmit DMA requests:
      
        1. If the buffer is flushed before the first DMA API call,
           dmaengine_prep_slave_single() may be called with a zero length,
           causing the DMA request to never complete, leading to messages
           like:
      
              rcar-dmac e7300000.dma-controller: Channel Address Error happen
      
           and, with debug enabled:
      
      	sh-sci e6e88000.serial: sci_dma_tx_work_fn: ffff800639b55000: 0...0, cookie 126
      
           and DMA timeouts.
      
        2. If the buffer is flushed after the first DMA API call, but before
           the second, dma_sync_single_for_device() may be called with a zero
           length, causing the transmit data not to be flushed to RAM, and
           leading to stale data being output.
      
      Fix this by:
        1. Letting sci_dma_tx_work_fn() return immediately if the transmit
           buffer is empty,
        2. Extending the critical section to cover all DMA preparational work,
           so tx_dma_len stays consistent for all of it,
        3. Using local copies of circ_buf.head and circ_buf.tail, to make sure
           they match the actual operation above.
      Reported-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Suggested-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Reviewed-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Tested-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Link: https://lore.kernel.org/r/20190624123540.20629-2-geert+renesas@glider.beSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7e55003b
    • Geert Uytterhoeven's avatar
      serial: sh-sci: Terminate TX DMA during buffer flushing · 56b68e63
      Geert Uytterhoeven authored
      [ Upstream commit 775b7ffd ]
      
      While the .flush_buffer() callback clears sci_port.tx_dma_len since
      commit 1cf4a7ef ("serial: sh-sci: Fix race condition causing
      garbage during shutdown"), it does not terminate a transmit DMA
      operation that may be in progress.
      
      Fix this by terminating any pending DMA operations, and resetting the
      corresponding cookie.
      Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Reviewed-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Tested-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      
      Link: https://lore.kernel.org/r/20190624123540.20629-3-geert+renesas@glider.beSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      56b68e63
    • Liu, Changcheng's avatar
      RDMA/i40iw: Set queue pair state when being queried · c70bfc1b
      Liu, Changcheng authored
      [ Upstream commit 2e67e775 ]
      
      The API for ib_query_qp requires the driver to set qp_state and
      cur_qp_state on return, add the missing sets.
      
      Fixes: d3749841 ("i40iw: add files for iwarp interface")
      Signed-off-by: default avatarChangcheng Liu <changcheng.liu@aliyun.com>
      Acked-by: default avatarShiraz Saleem <shiraz.saleem@intel.com>
      Reviewed-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c70bfc1b
    • Christian Lamparter's avatar
      powerpc/4xx/uic: clear pending interrupt after irq type/pol change · 5bab3a0a
      Christian Lamparter authored
      [ Upstream commit 3ab3a068 ]
      
      When testing out gpio-keys with a button, a spurious
      interrupt (and therefore a key press or release event)
      gets triggered as soon as the driver enables the irq
      line for the first time.
      
      This patch clears any potential bogus generated interrupt
      that was caused by the switching of the associated irq's
      type and polarity.
      Signed-off-by: default avatarChristian Lamparter <chunkeey@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5bab3a0a
    • Johannes Berg's avatar
      um: Silence lockdep complaint about mmap_sem · 20756b70
      Johannes Berg authored
      [ Upstream commit 80bf6cea ]
      
      When we get into activate_mm(), lockdep complains that we're doing
      something strange:
      
          WARNING: possible circular locking dependency detected
          5.1.0-10252-gb00152307319-dirty #121 Not tainted
          ------------------------------------------------------
          inside.sh/366 is trying to acquire lock:
          (____ptrval____) (&(&p->alloc_lock)->rlock){+.+.}, at: flush_old_exec+0x703/0x8d7
      
          but task is already holding lock:
          (____ptrval____) (&mm->mmap_sem){++++}, at: flush_old_exec+0x6c5/0x8d7
      
          which lock already depends on the new lock.
      
          the existing dependency chain (in reverse order) is:
      
          -> #1 (&mm->mmap_sem){++++}:
                 [...]
                 __lock_acquire+0x12ab/0x139f
                 lock_acquire+0x155/0x18e
                 down_write+0x3f/0x98
                 flush_old_exec+0x748/0x8d7
                 load_elf_binary+0x2ca/0xddb
                 [...]
      
          -> #0 (&(&p->alloc_lock)->rlock){+.+.}:
                 [...]
                 __lock_acquire+0x12ab/0x139f
                 lock_acquire+0x155/0x18e
                 _raw_spin_lock+0x30/0x83
                 flush_old_exec+0x703/0x8d7
                 load_elf_binary+0x2ca/0xddb
                 [...]
      
          other info that might help us debug this:
      
           Possible unsafe locking scenario:
      
                 CPU0                    CPU1
                 ----                    ----
            lock(&mm->mmap_sem);
                                         lock(&(&p->alloc_lock)->rlock);
                                         lock(&mm->mmap_sem);
            lock(&(&p->alloc_lock)->rlock);
      
           *** DEADLOCK ***
      
          2 locks held by inside.sh/366:
           #0: (____ptrval____) (&sig->cred_guard_mutex){+.+.}, at: __do_execve_file+0x12d/0x869
           #1: (____ptrval____) (&mm->mmap_sem){++++}, at: flush_old_exec+0x6c5/0x8d7
      
          stack backtrace:
          CPU: 0 PID: 366 Comm: inside.sh Not tainted 5.1.0-10252-gb00152307319-dirty #121
          Stack:
           [...]
          Call Trace:
           [<600420de>] show_stack+0x13b/0x155
           [<6048906b>] dump_stack+0x2a/0x2c
           [<6009ae64>] print_circular_bug+0x332/0x343
           [<6009c5c6>] check_prev_add+0x669/0xdad
           [<600a06b4>] __lock_acquire+0x12ab/0x139f
           [<6009f3d0>] lock_acquire+0x155/0x18e
           [<604a07e0>] _raw_spin_lock+0x30/0x83
           [<60151e6a>] flush_old_exec+0x703/0x8d7
           [<601a8eb8>] load_elf_binary+0x2ca/0xddb
           [...]
      
      I think it's because in exec_mmap() we have
      
      	down_read(&old_mm->mmap_sem);
      ...
              task_lock(tsk);
      ...
      	activate_mm(active_mm, mm);
      	(which does down_write(&mm->mmap_sem))
      
      I'm not really sure why lockdep throws in the whole knowledge
      about the task lock, but it seems that old_mm and mm shouldn't
      ever be the same (and it doesn't deadlock) so tell lockdep that
      they're different.
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      20756b70
    • Axel Lin's avatar
      mfd: hi655x-pmic: Fix missing return value check for devm_regmap_init_mmio_clk · f9690b8e
      Axel Lin authored
      [ Upstream commit 7efd105c ]
      
      Since devm_regmap_init_mmio_clk can fail, add return value checking.
      Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
      Acked-by: default avatarChen Feng <puck.chen@hisilicon.com>
      Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f9690b8e
    • Arnd Bergmann's avatar
      mfd: arizona: Fix undefined behavior · a3727b0a
      Arnd Bergmann authored
      [ Upstream commit 5da6cbcd ]
      
      When the driver is used with a subdevice that is disabled in the
      kernel configuration, clang gets a little confused about the
      control flow and fails to notice that n_subdevs is only
      uninitialized when subdevs is NULL, and we check for that,
      leading to a false-positive warning:
      
      drivers/mfd/arizona-core.c:1423:19: error: variable 'n_subdevs' is uninitialized when used here
            [-Werror,-Wuninitialized]
                                    subdevs, n_subdevs, NULL, 0, NULL);
                                             ^~~~~~~~~
      drivers/mfd/arizona-core.c:999:15: note: initialize the variable 'n_subdevs' to silence this warning
              int n_subdevs, ret, i;
                           ^
                            = 0
      
      Ideally, we would rearrange the code to avoid all those early
      initializations and have an explicit exit in each disabled case,
      but it's much easier to chicken out and add one more initialization
      here to shut up the warning.
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a3727b0a
    • Robert Hancock's avatar
      mfd: core: Set fwnode for created devices · f1405059
      Robert Hancock authored
      [ Upstream commit c176c6d7 ]
      
      The logic for setting the of_node on devices created by mfd did not set
      the fwnode pointer to match, which caused fwnode-based APIs to
      malfunction on these devices since the fwnode pointer was null. Fix
      this.
      Signed-off-by: default avatarRobert Hancock <hancock@sedsystems.ca>
      Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f1405059
    • Naveen N. Rao's avatar
      recordmcount: Fix spurious mcount entries on powerpc · 253278f2
      Naveen N. Rao authored
      [ Upstream commit 80e5302e ]
      
      An impending change to enable HAVE_C_RECORDMCOUNT on powerpc leads to
      warnings such as the following:
      
        # modprobe kprobe_example
        ftrace-powerpc: Not expected bl: opcode is 3c4c0001
        WARNING: CPU: 0 PID: 227 at kernel/trace/ftrace.c:2001 ftrace_bug+0x90/0x318
        Modules linked in:
        CPU: 0 PID: 227 Comm: modprobe Not tainted 5.2.0-rc6-00678-g1c329100b942 #2
        NIP:  c000000000264318 LR: c00000000025d694 CTR: c000000000f5cd30
        REGS: c000000001f2b7b0 TRAP: 0700   Not tainted  (5.2.0-rc6-00678-g1c329100b942)
        MSR:  900000010282b033 <SF,HV,VEC,VSX,EE,FP,ME,IR,DR,RI,LE,TM[E]>  CR: 28228222  XER: 00000000
        CFAR: c0000000002642fc IRQMASK: 0
        <snip>
        NIP [c000000000264318] ftrace_bug+0x90/0x318
        LR [c00000000025d694] ftrace_process_locs+0x4f4/0x5e0
        Call Trace:
        [c000000001f2ba40] [0000000000000004] 0x4 (unreliable)
        [c000000001f2bad0] [c00000000025d694] ftrace_process_locs+0x4f4/0x5e0
        [c000000001f2bb90] [c00000000020ff10] load_module+0x25b0/0x30c0
        [c000000001f2bd00] [c000000000210cb0] sys_finit_module+0xc0/0x130
        [c000000001f2be20] [c00000000000bda4] system_call+0x5c/0x70
        Instruction dump:
        419e0018 2f83ffff 419e00bc 2f83ffea 409e00cc 4800001c 0fe00000 3c62ff96
        39000001 39400000 386386d0 480000c4 <0fe00000> 3ce20003 39000001 3c62ff96
        ---[ end trace 4c438d5cebf78381 ]---
        ftrace failed to modify
        [<c0080000012a0008>] 0xc0080000012a0008
         actual:   01:00:4c:3c
        Initializing ftrace call sites
        ftrace record flags: 2000000
         (0)
         expected tramp: c00000000006af4c
      
      Looking at the relocation records in __mcount_loc shows a few spurious
      entries:
      
        RELOCATION RECORDS FOR [__mcount_loc]:
        OFFSET           TYPE              VALUE
        0000000000000000 R_PPC64_ADDR64    .text.unlikely+0x0000000000000008
        0000000000000008 R_PPC64_ADDR64    .text.unlikely+0x0000000000000014
        0000000000000010 R_PPC64_ADDR64    .text.unlikely+0x0000000000000060
        0000000000000018 R_PPC64_ADDR64    .text.unlikely+0x00000000000000b4
        0000000000000020 R_PPC64_ADDR64    .init.text+0x0000000000000008
        0000000000000028 R_PPC64_ADDR64    .init.text+0x0000000000000014
      
      The first entry in each section is incorrect. Looking at the
      relocation records, the spurious entries correspond to the
      R_PPC64_ENTRY records:
      
        RELOCATION RECORDS FOR [.text.unlikely]:
        OFFSET           TYPE              VALUE
        0000000000000000 R_PPC64_REL64     .TOC.-0x0000000000000008
        0000000000000008 R_PPC64_ENTRY     *ABS*
        0000000000000014 R_PPC64_REL24     _mcount
        <snip>
      
      The problem is that we are not validating the return value from
      get_mcountsym() in sift_rel_mcount(). With this entry, mcountsym is 0,
      but Elf_r_sym(relp) also ends up being 0. Fix this by ensuring
      mcountsym is valid before processing the entry.
      Signed-off-by: default avatarNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Acked-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Tested-by: default avatarSatheesh Rajendran <sathnaga@linux.vnet.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      253278f2
    • Bastien Nocera's avatar
      iio: iio-utils: Fix possible incorrect mask calculation · e2482f76
      Bastien Nocera authored
      [ Upstream commit 208a68c8 ]
      
      On some machines, iio-sensor-proxy was returning all 0's for IIO sensor
      values. It turns out that the bits_used for this sensor is 32, which makes
      the mask calculation:
      
      *mask = (1 << 32) - 1;
      
      If the compiler interprets the 1 literals as 32-bit ints, it generates
      undefined behavior depending on compiler version and optimization level.
      On my system, it optimizes out the shift, so the mask value becomes
      
      *mask = (1) - 1;
      
      With a mask value of 0, iio-sensor-proxy will always return 0 for every axis.
      
      Avoid incorrect 0 values caused by compiler optimization.
      
      See original fix by Brett Dutro <brett.dutro@gmail.com> in
      iio-sensor-proxy:
      https://github.com/hadess/iio-sensor-proxy/commit/9615ceac7c134d838660e209726cd86aa2064fd3Signed-off-by: default avatarBastien Nocera <hadess@hadess.net>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e2482f76
    • Bharat Kumar Gogada's avatar
      PCI: xilinx-nwl: Fix Multi MSI data programming · 5086e479
      Bharat Kumar Gogada authored
      [ Upstream commit 181fa434 ]
      
      According to the PCI Local Bus specification Revision 3.0,
      section 6.8.1.3 (Message Control for MSI), endpoints that
      are Multiple Message Capable as defined by bits [3:1] in
      the Message Control for MSI can request a number of vectors
      that is power of two aligned.
      
      As specified in section 6.8.1.6 "Message data for MSI", the Multiple
      Message Enable field (bits [6:4] of the Message Control register)
      defines the number of low order message data bits the function is
      permitted to modify to generate its system software allocated
      vectors.
      
      The MSI controller in the Xilinx NWL PCIe controller supports a number
      of MSI vectors specified through a bitmap and the hwirq number for an
      MSI, that is the value written in the MSI data TLP is determined by
      the bitmap allocation.
      
      For instance, in a situation where two endpoints sitting on
      the PCI bus request the following MSI configuration, with
      the current PCI Xilinx bitmap allocation code (that does not
      align MSI vector allocation on a power of two boundary):
      
      Endpoint #1: Requesting 1 MSI vector - allocated bitmap bits 0
      Endpoint #2: Requesting 2 MSI vectors - allocated bitmap bits [1,2]
      
      The bitmap value(s) corresponds to the hwirq number that is programmed
      into the Message Data for MSI field in the endpoint MSI capability
      and is detected by the root complex to fire the corresponding
      MSI irqs. The value written in Message Data for MSI field corresponds
      to the first bit allocated in the bitmap for Multi MSI vectors.
      
      The current Xilinx NWL MSI allocation code allows a bitmap allocation
      that is not a power of two boundaries, so endpoint #2, is allowed to
      toggle Message Data bit[0] to differentiate between its two vectors
      (meaning that the MSI data will be respectively 0x0 and 0x1 for the two
      vectors allocated to endpoint #2).
      
      This clearly aliases with the Endpoint #1 vector allocation, resulting
      in a broken Multi MSI implementation.
      
      Update the code to allocate MSI bitmap ranges with a power of two
      alignment, fixing the bug.
      
      Fixes: ab597d35 ("PCI: xilinx-nwl: Add support for Xilinx NWL PCIe Host Controller")
      Suggested-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: default avatarBharat Kumar Gogada <bharat.kumar.gogada@xilinx.com>
      [lorenzo.pieralisi@arm.com: updated commit log]
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Acked-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5086e479
    • Nathan Chancellor's avatar
      kbuild: Add -Werror=unknown-warning-option to CLANG_FLAGS · 7caebf6d
      Nathan Chancellor authored
      [ Upstream commit 589834b3 ]
      
      In commit ebcc5928 ("arm64: Silence gcc warnings about arch ABI
      drift"), the arm64 Makefile added -Wno-psabi to KBUILD_CFLAGS, which is
      a GCC only option so clang rightfully complains:
      
      warning: unknown warning option '-Wno-psabi' [-Wunknown-warning-option]
      
      https://clang.llvm.org/docs/DiagnosticsReference.html#wunknown-warning-option
      
      However, by default, this is merely a warning so the build happily goes
      on with a slew of these warnings in the process.
      
      Commit c3f0d0bc ("kbuild, LLVMLinux: Add -Werror to cc-option to
      support clang") worked around this behavior in cc-option by adding
      -Werror so that unknown flags cause an error. However, this all happens
      silently and when an unknown flag is added to the build unconditionally
      like -Wno-psabi, cc-option will always fail because there is always an
      unknown flag in the list of flags. This manifested as link time failures
      in the arm64 libstub because -fno-stack-protector didn't get added to
      KBUILD_CFLAGS.
      
      To avoid these weird cryptic failures in the future, make clang behave
      like gcc and immediately error when it encounters an unknown flag by
      adding -Werror=unknown-warning-option to CLANG_FLAGS. This can be added
      unconditionally for clang because it is supported by at least 3.0.0,
      according to godbolt [1] and 4.0.0, according to its documentation [2],
      which is far earlier than we typically support.
      
      [1]: https://godbolt.org/z/7F7rm3
      [2]: https://releases.llvm.org/4.0.0/tools/clang/docs/DiagnosticsReference.html#wunknown-warning-option
      
      Link: https://github.com/ClangBuiltLinux/linux/issues/511
      Link: https://github.com/ClangBuiltLinux/linux/issues/517Suggested-by: default avatarPeter Smith <peter.smith@linaro.org>
      Signed-off-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7caebf6d
    • Marek Vasut's avatar
      PCI: sysfs: Ignore lockdep for remove attribute · 2abc45ec
      Marek Vasut authored
      [ Upstream commit dc6b698a ]
      
      With CONFIG_PROVE_LOCKING=y, using sysfs to remove a bridge with a device
      below it causes a lockdep warning, e.g.,
      
        # echo 1 > /sys/class/pci_bus/0000:00/device/0000:00:00.0/remove
        ============================================
        WARNING: possible recursive locking detected
        ...
        pci_bus 0000:01: busn_res: [bus 01] is released
      
      The remove recursively removes the subtree below the bridge.  Each call
      uses a different lock so there's no deadlock, but the locks were all
      created with the same lockdep key so the lockdep checker can't tell them
      apart.
      
      Mark the "remove" sysfs attribute with __ATTR_IGNORE_LOCKDEP() as it is
      safe to ignore the lockdep check between different "remove" kernfs
      instances.
      
      There's discussion about a similar issue in USB at [1], which resulted in
      356c05d5 ("sysfs: get rid of some lockdep false positives") and
      e9b526fe ("i2c: suppress lockdep warning on delete_device"), which do
      basically the same thing for USB "remove" and i2c "delete_device" files.
      
      [1] https://lore.kernel.org/r/Pine.LNX.4.44L0.1204251436140.1206-100000@iolanthe.rowland.org
      Link: https://lore.kernel.org/r/20190526225151.3865-1-marek.vasut@gmail.comSigned-off-by: default avatarMarek Vasut <marek.vasut+renesas@gmail.com>
      [bhelgaas: trim commit log, details at above links]
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Cc: Geert Uytterhoeven <geert+renesas@glider.be>
      Cc: Phil Edworthy <phil.edworthy@renesas.com>
      Cc: Simon Horman <horms+renesas@verge.net.au>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Wolfram Sang <wsa@the-dreams.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2abc45ec
    • Alexey Kardashevskiy's avatar
      powerpc/pci/of: Fix OF flags parsing for 64bit BARs · 514670ac
      Alexey Kardashevskiy authored
      [ Upstream commit df5be5be ]
      
      When the firmware does PCI BAR resource allocation, it passes the assigned
      addresses and flags (prefetch/64bit/...) via the "reg" property of
      a PCI device device tree node so the kernel does not need to do
      resource allocation.
      
      The flags are stored in resource::flags - the lower byte stores
      PCI_BASE_ADDRESS_SPACE/etc bits and the other bytes are IORESOURCE_IO/etc.
      Some flags from PCI_BASE_ADDRESS_xxx and IORESOURCE_xxx are duplicated,
      such as PCI_BASE_ADDRESS_MEM_PREFETCH/PCI_BASE_ADDRESS_MEM_TYPE_64/etc.
      When parsing the "reg" property, we copy the prefetch flag but we skip
      on PCI_BASE_ADDRESS_MEM_TYPE_64 which leaves the flags out of sync.
      
      The missing IORESOURCE_MEM_64 flag comes into play under 2 conditions:
      1. we remove PCI_PROBE_ONLY for pseries (by hacking pSeries_setup_arch()
      or by passing "/chosen/linux,pci-probe-only");
      2. we request resource alignment (by passing pci=resource_alignment=
      via the kernel cmd line to request PAGE_SIZE alignment or defining
      ppc_md.pcibios_default_alignment which returns anything but 0). Note that
      the alignment requests are ignored if PCI_PROBE_ONLY is enabled.
      
      With 1) and 2), the generic PCI code in the kernel unconditionally
      decides to:
      - reassign the BARs in pci_specified_resource_alignment() (works fine)
      - write new BARs to the device - this fails for 64bit BARs as the generic
      code looks at IORESOURCE_MEM_64 (not set) and writes only lower 32bits
      of the BAR and leaves the upper 32bit unmodified which breaks BAR mapping
      in the hypervisor.
      
      This fixes the issue by copying the flag. This is useful if we want to
      enforce certain BAR alignment per platform as handling subpage sized BARs
      is proven to cause problems with hotplug (SLOF already aligns BARs to 64k).
      Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
      Reviewed-by: default avatarSam Bobroff <sbobroff@linux.ibm.com>
      Reviewed-by: default avatarOliver O'Halloran <oohall@gmail.com>
      Reviewed-by: default avatarShawn Anastasio <shawn@anastas.io>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      514670ac
    • Andrzej Pietrasiewicz's avatar
      usb: gadget: Zero ffs_io_data · d585589e
      Andrzej Pietrasiewicz authored
      [ Upstream commit 50859551 ]
      
      In some cases the "Allocate & copy" block in ffs_epfile_io() is not
      executed. Consequently, in such a case ffs_alloc_buffer() is never called
      and struct ffs_io_data is not initialized properly. This in turn leads to
      problems when ffs_free_buffer() is called at the end of ffs_epfile_io().
      
      This patch uses kzalloc() instead of kmalloc() in the aio case and memset()
      in non-aio case to properly initialize struct ffs_io_data.
      Signed-off-by: default avatarAndrzej Pietrasiewicz <andrzej.p@collabora.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d585589e
    • Serge Semin's avatar
      tty: serial_core: Set port active bit in uart_port_activate · 47807595
      Serge Semin authored
      [ Upstream commit 13b18d35 ]
      
      A bug was introduced by commit b3b57646 ("tty: serial_core: convert
      uart_open to use tty_port_open"). It caused a constant warning printed
      into the system log regarding the tty and port counter mismatch:
      
      [   21.644197] ttyS ttySx: tty_port_close_start: tty->count = 1 port count = 2
      
      in case if session hangup was detected so the warning is printed starting
      from the second open-close iteration.
      
      Particularly the problem was discovered in situation when there is a
      serial tty device without hardware back-end being setup. It is considered
      by the tty-serial subsystems as a hardware problem with session hang up.
      In this case uart_startup() will return a positive value with TTY_IO_ERROR
      flag set in corresponding tty_struct instance. The same value will get
      passed to be returned from the activate() callback and then being returned
      from tty_port_open(). But since in this case tty_port_block_til_ready()
      isn't called the TTY_PORT_ACTIVE flag isn't set (while the method had been
      called before tty_port_open conversion was introduced and the rest of the
      subsystem code expected the bit being set in this case), which prevents the
      uart_hangup() method to perform any cleanups including the tty port
      counter setting to zero. So the next attempt to open/close the tty device
      will discover the counters mismatch.
      
      In order to fix the problem we need to manually set the TTY_PORT_ACTIVE
      flag in case if uart_startup() returned a positive value. In this case
      the hang up procedure will perform a full set of cleanup actions including
      the port ref-counter resetting.
      
      Fixes: b3b57646 "tty: serial_core: convert uart_open to use tty_port_open"
      Signed-off-by: default avatarSerge Semin <fancer.lancer@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      47807595
    • Douglas Anderson's avatar
      drm/rockchip: Properly adjust to a true clock in adjusted_mode · 1d133532
      Douglas Anderson authored
      [ Upstream commit 99b9683f ]
      
      When fixing up the clock in vop_crtc_mode_fixup() we're not doing it
      quite correctly.  Specifically if we've got the true clock 266666667 Hz,
      we'll perform this calculation:
         266666667 / 1000 => 266666
      
      Later when we try to set the clock we'll do clk_set_rate(266666 *
      1000).  The common clock framework won't actually pick the proper clock
      in this case since it always wants clocks <= the specified one.
      
      Let's solve this by using DIV_ROUND_UP.
      
      Fixes: b59b8de3 ("drm/rockchip: return a true clock rate to adjusted_mode")
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Signed-off-by: default avatarSean Paul <seanpaul@chromium.org>
      Reviewed-by: default avatarYakir Yang <ykk@rock-chips.com>
      Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
      Link: https://patchwork.freedesktop.org/patch/msgid/20190614224730.98622-1-dianders@chromium.orgSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      1d133532
    • Yoshihiro Shimoda's avatar
      phy: renesas: rcar-gen2: Fix memory leak at error paths · 67ac0ef9
      Yoshihiro Shimoda authored
      [ Upstream commit d4a36e82 ]
      
      This patch fixes memory leak at error paths of the probe function.
      In for_each_child_of_node, if the loop returns, the driver should
      call of_put_node() before returns.
      Reported-by: default avatarJulia Lawall <julia.lawall@lip6.fr>
      Fixes: 1233f59f ("phy: Renesas R-Car Gen2 PHY driver")
      Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Reviewed-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      67ac0ef9
    • David Riley's avatar
      drm/virtio: Add memory barriers for capset cache. · 34db79ae
      David Riley authored
      [ Upstream commit 9ff3a5c8 ]
      
      After data is copied to the cache entry, atomic_set is used indicate
      that the data is the entry is valid without appropriate memory barriers.
      Similarly the read side was missing the corresponding memory barriers.
      Signed-off-by: default avatarDavid Riley <davidriley@chromium.org>
      Link: http://patchwork.freedesktop.org/patch/msgid/20190610211810.253227-5-davidriley@chromium.orgSigned-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      34db79ae
    • Rautkoski Kimmo EXT's avatar
      serial: 8250: Fix TX interrupt handling condition · bd36de4d
      Rautkoski Kimmo EXT authored
      [ Upstream commit db1b5bc0 ]
      
      Interrupt handler checked THRE bit (transmitter holding register
      empty) in LSR to detect if TX fifo is empty.
      In case when there is only receive interrupts the TX handling
      got called because THRE bit in LSR is set when there is no
      transmission (FIFO empty). TX handling caused TX stop, which in
      RS-485 half-duplex mode actually resets receiver FIFO. This is not
      desired during reception because of possible data loss.
      
      The fix is to check if THRI is set in IER in addition of the TX
      fifo status. THRI in IER is set when TX is started and cleared
      when TX is stopped.
      This ensures that TX handling is only called when there is really
      transmission on going and an interrupt for THRE and not when there
      are only RX interrupts.
      Signed-off-by: default avatarKimmo Rautkoski <ext-kimmo.rautkoski@vaisala.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bd36de4d
    • Jorge Ramirez-Ortiz's avatar
      tty: serial: msm_serial: avoid system lockup condition · 20258b32
      Jorge Ramirez-Ortiz authored
      [ Upstream commit ba3684f9 ]
      
      The function msm_wait_for_xmitr can be taken with interrupts
      disabled. In order to avoid a potential system lockup - demonstrated
      under stress testing conditions on SoC QCS404/5 - make sure we wait
      for a bounded amount of time.
      
      Tested on SoC QCS404.
      Signed-off-by: default avatarJorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      20258b32
    • Kefeng Wang's avatar
      tty/serial: digicolor: Fix digicolor-usart already registered warning · 483aca92
      Kefeng Wang authored
      [ Upstream commit c7ad9ba0 ]
      
      When modprobe/rmmod/modprobe module, if platform_driver_register() fails,
      the kernel complained,
      
        proc_dir_entry 'driver/digicolor-usart' already registered
        WARNING: CPU: 1 PID: 5636 at fs/proc/generic.c:360 proc_register+0x19d/0x270
      
      Fix this by adding uart_unregister_driver() when platform_driver_register() fails.
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
      Acked-by: default avatarBaruch Siach <baruch@tkos.co.il>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      483aca92
    • Wang Hai's avatar
      memstick: Fix error cleanup path of memstick_init · e69bea97
      Wang Hai authored
      [ Upstream commit 65f1a0d3 ]
      
      If bus_register fails. On its error handling path, it has cleaned up
      what it has done. There is no need to call bus_unregister again.
      Otherwise, if bus_unregister is called, issues such as null-ptr-deref
      will arise.
      
      Syzkaller report this:
      
      kobject_add_internal failed for memstick (error: -12 parent: bus)
      BUG: KASAN: null-ptr-deref in sysfs_remove_file_ns+0x1b/0x40 fs/sysfs/file.c:467
      Read of size 8 at addr 0000000000000078 by task syz-executor.0/4460
      
      Call Trace:
       __dump_stack lib/dump_stack.c:77 [inline]
       dump_stack+0xa9/0x10e lib/dump_stack.c:113
       __kasan_report+0x171/0x18d mm/kasan/report.c:321
       kasan_report+0xe/0x20 mm/kasan/common.c:614
       sysfs_remove_file_ns+0x1b/0x40 fs/sysfs/file.c:467
       sysfs_remove_file include/linux/sysfs.h:519 [inline]
       bus_remove_file+0x6c/0x90 drivers/base/bus.c:145
       remove_probe_files drivers/base/bus.c:599 [inline]
       bus_unregister+0x6e/0x100 drivers/base/bus.c:916 ? 0xffffffffc1590000
       memstick_init+0x7a/0x1000 [memstick]
       do_one_initcall+0xb9/0x3b5 init/main.c:914
       do_init_module+0xe0/0x330 kernel/module.c:3468
       load_module+0x38eb/0x4270 kernel/module.c:3819
       __do_sys_finit_module+0x162/0x190 kernel/module.c:3909
       do_syscall_64+0x72/0x2a0 arch/x86/entry/common.c:298
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      Fixes: baf8532a ("memstick: initial commit for Sony MemoryStick support")
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarWang Hai <wanghai26@huawei.com>
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e69bea97
    • Jyri Sarha's avatar
      drm/bridge: sii902x: pixel clock unit is 10kHz instead of 1kHz · ebfba805
      Jyri Sarha authored
      [ Upstream commit 8dbfc5b6 ]
      
      The pixel clock unit in the first two registers (0x00 and 0x01) of
      sii9022 is 10kHz, not 1kHz as in struct drm_display_mode. Division by
      10 fixes the issue.
      Signed-off-by: default avatarJyri Sarha <jsarha@ti.com>
      Reviewed-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
      Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      Signed-off-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/1a2a8eae0b9d6333e7a5841026bf7fd65c9ccd09.1558964241.git.jsarha@ti.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      ebfba805
    • Tomi Valkeinen's avatar
      drm/bridge: tc358767: read display_props in get_modes() · 78921099
      Tomi Valkeinen authored
      [ Upstream commit 32315730 ]
      
      We need to know the link bandwidth to filter out modes we cannot
      support, so we need to have read the display props before doing the
      filtering.
      
      To ensure we have up to date display props, call tc_get_display_props()
      in the beginning of tc_connector_get_modes().
      Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
      Reviewed-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
      Signed-off-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20190528082747.3631-22-tomi.valkeinen@ti.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      78921099
    • Christophe Leroy's avatar
      tty: serial: cpm_uart - fix init when SMC is relocated · 3459f621
      Christophe Leroy authored
      [ Upstream commit 06aaa3d0 ]
      
      SMC relocation can also be activated earlier by the bootloader,
      so the driver's behaviour cannot rely on selected kernel config.
      
      When the SMC is relocated, CPM_CR_INIT_TRX cannot be used.
      
      But the only thing CPM_CR_INIT_TRX does is to clear the
      rstate and tstate registers, so this can be done manually,
      even when SMC is not relocated.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Fixes: 9ab92120 ("cpm_uart: fix non-console port startup bug")
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3459f621
    • Wen Yang's avatar
      pinctrl: rockchip: fix leaked of_node references · 8d57d3bc
      Wen Yang authored
      [ Upstream commit 3c89c706 ]
      
      The call to of_parse_phandle returns a node pointer with refcount
      incremented thus it must be explicitly decremented after the last
      usage.
      
      Detected by coccinelle with the following warnings:
      ./drivers/pinctrl/pinctrl-rockchip.c:3221:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 3196, but without a corresponding object release within this function.
      ./drivers/pinctrl/pinctrl-rockchip.c:3223:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 3196, but without a corresponding object release within this function.
      Signed-off-by: default avatarWen Yang <wen.yang99@zte.com.cn>
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Cc: Heiko Stuebner <heiko@sntech.de>
      Cc: linux-gpio@vger.kernel.org
      Cc: linux-rockchip@lists.infradead.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8d57d3bc
    • Serge Semin's avatar
      tty: max310x: Fix invalid baudrate divisors calculator · efab087c
      Serge Semin authored
      [ Upstream commit 35240ba2 ]
      
      Current calculator doesn't do it' job quite correct. First of all the
      max310x baud-rates generator supports the divisor being less than 16.
      In this case the x2/x4 modes can be used to double or quadruple
      the reference frequency. But the current baud-rate setter function
      just filters all these modes out by the first condition and setups
      these modes only if there is a clocks-baud division remainder. The former
      doesn't seem right at all, since enabling the x2/x4 modes causes the line
      noise tolerance reduction and should be only used as a last resort to
      enable a requested too high baud-rate.
      
      Finally the fraction is supposed to be calculated from D = Fref/(c*baud)
      formulae, but not from D % 16, which causes the precision loss. So to speak
      the current baud-rate calculator code works well only if the baud perfectly
      fits to the uart reference input frequency.
      
      Lets fix the calculator by implementing the algo fully compliant with
      the fractional baud-rate generator described in the datasheet:
      D = Fref / (c*baud), where c={16,8,4} is the x1/x2/x4 rate mode
      respectively, Fref - reference input frequency. The divisor fraction is
      calculated from the same formulae, but making sure it is found with a
      resolution of 0.0625 (four bits).
      Signed-off-by: default avatarSerge Semin <fancer.lancer@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      efab087c
    • Thinh Nguyen's avatar
      usb: core: hub: Disable hub-initiated U1/U2 · 790af995
      Thinh Nguyen authored
      [ Upstream commit 56175929 ]
      
      If the device rejects the control transfer to enable device-initiated
      U1/U2 entry, then the device will not initiate U1/U2 transition. To
      improve the performance, the downstream port should not initate
      transition to U1/U2 to avoid the delay from the device link command
      response (no packet can be transmitted while waiting for a response from
      the device). If the device has some quirks and does not implement U1/U2,
      it may reject all the link state change requests, and the downstream
      port may resend and flood the bus with more requests. This will affect
      the device performance even further. This patch disables the
      hub-initated U1/U2 if the device-initiated U1/U2 entry fails.
      
      Reference: USB 3.2 spec 7.2.4.2.3
      Signed-off-by: default avatarThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      790af995
    • Peter Ujfalusi's avatar
      drm/panel: simple: Fix panel_simple_dsi_probe · d1b69112
      Peter Ujfalusi authored
      [ Upstream commit 7ad9db66 ]
      
      In case mipi_dsi_attach() fails remove the registered panel to avoid added
      panel without corresponding device.
      Signed-off-by: default avatarPeter Ujfalusi <peter.ujfalusi@ti.com>
      Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20190226081153.31334-1-peter.ujfalusi@ti.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      d1b69112
    • Paul Menzel's avatar
      nfsd: Fix overflow causing non-working mounts on 1 TB machines · 7546e0c1
      Paul Menzel authored
      [ Upstream commit 3b2d4dcf ]
      
      Since commit 10a68cdf (nfsd: fix performance-limiting session
      calculation) (Linux 5.1-rc1 and 4.19.31), shares from NFS servers with
      1 TB of memory cannot be mounted anymore. The mount just hangs on the
      client.
      
      The gist of commit 10a68cdf is the change below.
      
          -avail = clamp_t(int, avail, slotsize, avail/3);
          +avail = clamp_t(int, avail, slotsize, total_avail/3);
      
      Here are the macros.
      
          #define min_t(type, x, y)       __careful_cmp((type)(x), (type)(y), <)
          #define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi)
      
      `total_avail` is 8,434,659,328 on the 1 TB machine. `clamp_t()` casts
      the values to `int`, which for 32-bit integers can only hold values
      −2,147,483,648 (−2^31) through 2,147,483,647 (2^31 − 1).
      
      `avail` (in the function signature) is just 65536, so that no overflow
      was happening. Before the commit the assignment would result in 21845,
      and `num = 4`.
      
      When using `total_avail`, it is causing the assignment to be
      18446744072226137429 (printed as %lu), and `num` is then 4164608182.
      
      My next guess is, that `nfsd_drc_mem_used` is then exceeded, and the
      server thinks there is no memory available any more for this client.
      
      Updating the arguments of `clamp_t()` and `min_t()` to `unsigned long`
      fixes the issue.
      
      Now, `avail = 65536` (before commit 10a68cdf `avail = 21845`), but
      `num = 4` remains the same.
      
      Fixes: c54f24e3 (nfsd: fix performance-limiting session calculation)
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaul Menzel <pmenzel@molgen.mpg.de>
      Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7546e0c1