Skip to content
  1. Jul 29, 2020
    • Barry Song's avatar
      mm/hugetlb: avoid hardcoding while checking if cma is enabled · 931b5890
      Barry Song authored
      commit dbda8fea upstream.
      
      hugetlb_cma[0] can be NULL due to various reasons, for example, node0
      has no memory.  so NULL hugetlb_cma[0] doesn't necessarily mean cma is
      not enabled.  gigantic pages might have been reserved on other nodes.
      This patch fixes possible double reservation and CMA leak.
      
      [akpm@linux-foundation.org: fix CONFIG_CMA=n warning]
      [sfr@canb.auug.org.au: better checks before using hugetlb_cma]
        Link: http://lkml.kernel.org/r/20200721205716.6dbaa56b@canb.auug.org.au
      
      Fixes: cf11e85f
      
       ("mm: hugetlb: optionally allocate gigantic hugepages using cma")
      Signed-off-by: default avatarBarry Song <song.bao.hua@hisilicon.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Acked-by: default avatarRoman Gushchin <guro@fb.com>
      Cc: Jonathan Cameron <jonathan.cameron@huawei.com>
      Cc: <stable@vger.kernel.org>
      Link: http://lkml.kernel.org/r/20200710005726.36068-1-song.bao.hua@hisilicon.com
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      931b5890
    • Muchun Song's avatar
      mm: memcg/slab: fix memory leak at non-root kmem_cache destroy · 02f0803f
      Muchun Song authored
      commit d38a2b7a upstream.
      
      If the kmem_cache refcount is greater than one, we should not mark the
      root kmem_cache as dying.  If we mark the root kmem_cache dying
      incorrectly, the non-root kmem_cache can never be destroyed.  It
      resulted in memory leak when memcg was destroyed.  We can use the
      following steps to reproduce.
      
        1) Use kmem_cache_create() to create a new kmem_cache named A.
        2) Coincidentally, the kmem_cache A is an alias for kmem_cache B,
           so the refcount of B is just increased.
        3) Use kmem_cache_destroy() to destroy the kmem_cache A, just
           decrease the B's refcount but mark the B as dying.
        4) Create a new memory cgroup and alloc memory from the kmem_cache
           B. It leads to create a non-root kmem_cache for allocating memory.
        5) When destroy the memory cgroup created in the step 4), the
           non-root kmem_cache can never be destroyed.
      
      If we repeat steps 4) and 5), this will cause a lot of memory leak.  So
      only when refcount reach zero, we mark the root kmem_cache as dying.
      
      Fixes: 92ee383f
      
       ("mm: fix race between kmem_cache destroy, create and deactivate")
      Signed-off-by: default avatarMuchun Song <songmuchun@bytedance.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Reviewed-by: default avatarShakeel Butt <shakeelb@google.com>
      Acked-by: default avatarRoman Gushchin <guro@fb.com>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Shakeel Butt <shakeelb@google.com>
      Cc: <stable@vger.kernel.org>
      Link: http://lkml.kernel.org/r/20200716165103.83462-1-songmuchun@bytedance.com
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      02f0803f
    • Hugh Dickins's avatar
      mm/memcg: fix refcount error while moving and swapping · bd79bb52
      Hugh Dickins authored
      commit 8d22a935 upstream.
      
      It was hard to keep a test running, moving tasks between memcgs with
      move_charge_at_immigrate, while swapping: mem_cgroup_id_get_many()'s
      refcount is discovered to be 0 (supposedly impossible), so it is then
      forced to REFCOUNT_SATURATED, and after thousands of warnings in quick
      succession, the test is at last put out of misery by being OOM killed.
      
      This is because of the way moved_swap accounting was saved up until the
      task move gets completed in __mem_cgroup_clear_mc(), deferred from when
      mem_cgroup_move_swap_account() actually exchanged old and new ids.
      Concurrent activity can free up swap quicker than the task is scanned,
      bringing id refcount down 0 (which should only be possible when
      offlining).
      
      Just skip that optimization: do that part of the accounting immediately.
      
      Fixes: 615d66c3
      
       ("mm: memcontrol: fix memcg id ref counter on swap charge move")
      Signed-off-by: default avatarHugh Dickins <hughd@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Reviewed-by: default avatarAlex Shi <alex.shi@linux.alibaba.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Alex Shi <alex.shi@linux.alibaba.com>
      Cc: Shakeel Butt <shakeelb@google.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: <stable@vger.kernel.org>
      Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2007071431050.4726@eggly.anvils
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bd79bb52
    • Chengguang Xu's avatar
      vfs/xattr: mm/shmem: kernfs: release simple xattr entry in a right way · e1aa90dc
      Chengguang Xu authored
      commit 3bef735a upstream.
      
      After commit fdc85222 ("kernfs: kvmalloc xattr value instead of
      kmalloc"), simple xattr entry is allocated with kvmalloc() instead of
      kmalloc(), so we should release it with kvfree() instead of kfree().
      
      Fixes: fdc85222
      
       ("kernfs: kvmalloc xattr value instead of kmalloc")
      Signed-off-by: default avatarChengguang Xu <cgxu519@mykernel.net>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Acked-by: default avatarHugh Dickins <hughd@google.com>
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      Cc: Daniel Xu <dxu@dxuuu.xyz>
      Cc: Chris Down <chris@chrisdown.name>
      Cc: Andreas Dilger <adilger@dilger.ca>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: <stable@vger.kernel.org>	[5.7]
      Link: http://lkml.kernel.org/r/20200704051608.15043-1-cgxu519@mykernel.net
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e1aa90dc
    • Kirill A. Shutemov's avatar
      mm/mmap.c: close race between munmap() and expand_upwards()/downwards() · b6afd2a9
      Kirill A. Shutemov authored
      commit 246c320a upstream.
      
      VMA with VM_GROWSDOWN or VM_GROWSUP flag set can change their size under
      mmap_read_lock().  It can lead to race with __do_munmap():
      
      	Thread A			Thread B
      __do_munmap()
        detach_vmas_to_be_unmapped()
        mmap_write_downgrade()
      				expand_downwards()
      				  vma->vm_start = address;
      				  // The VMA now overlaps with
      				  // VMAs detached by the Thread A
      				// page fault populates expanded part
      				// of the VMA
        unmap_region()
          // Zaps pagetables partly
          // populated by Thread B
      
      Similar race exists for expand_upwards().
      
      The fix is to avoid downgrading mmap_lock in __do_munmap() if detached
      VMAs are next to VM_GROWSDOWN or VM_GROWSUP VMA.
      
      [akpm@linux-foundation.org: s/mmap_sem/mmap_lock/ in comment]
      
      Fixes: dd2283f2
      
       ("mm: mmap: zap pages with read mmap_sem in munmap")
      Reported-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Reviewed-by: default avatarYang Shi <yang.shi@linux.alibaba.com>
      Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: <stable@vger.kernel.org>	[4.20+]
      Link: http://lkml.kernel.org/r/20200709105309.42495-1-kirill.shutemov@linux.intel.com
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b6afd2a9
    • Fangrui Song's avatar
      Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation · 4055a0a9
      Fangrui Song authored
      commit ca9b31f6
      
       upstream.
      
      When CROSS_COMPILE is set (e.g. aarch64-linux-gnu-), if
      $(CROSS_COMPILE)elfedit is found at /usr/bin/aarch64-linux-gnu-elfedit,
      GCC_TOOLCHAIN_DIR will be set to /usr/bin/.  --prefix= will be set to
      /usr/bin/ and Clang as of 11 will search for both
      $(prefix)aarch64-linux-gnu-$needle and $(prefix)$needle.
      
      GCC searchs for $(prefix)aarch64-linux-gnu/$version/$needle,
      $(prefix)aarch64-linux-gnu/$needle and $(prefix)$needle. In practice,
      $(prefix)aarch64-linux-gnu/$needle rarely contains executables.
      
      To better model how GCC's -B/--prefix takes in effect in practice, newer
      Clang (since
      https://github.com/llvm/llvm-project/commit/3452a0d8c17f7166f479706b293caf6ac76ffd90)
      only searches for $(prefix)$needle. Currently it will find /usr/bin/as
      instead of /usr/bin/aarch64-linux-gnu-as.
      
      Set --prefix= to $(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
      (/usr/bin/aarch64-linux-gnu-) so that newer Clang can find the
      appropriate cross compiling GNU as (when -no-integrated-as is in
      effect).
      
      Cc: stable@vger.kernel.org
      Reported-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: default avatarFangrui Song <maskray@google.com>
      Reviewed-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Tested-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Link: https://github.com/ClangBuiltLinux/linux/issues/1099
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4055a0a9
    • Tetsuo Handa's avatar
      vt: Reject zero-sized screen buffer size. · 02abdb61
      Tetsuo Handa authored
      commit ce684552
      
       upstream.
      
      syzbot is reporting general protection fault in do_con_write() [1] caused
      by vc->vc_screenbuf == ZERO_SIZE_PTR caused by vc->vc_screenbuf_size == 0
      caused by vc->vc_cols == vc->vc_rows == vc->vc_size_row == 0 caused by
      fb_set_var() from ioctl(FBIOPUT_VSCREENINFO) on /dev/fb0 , for
      gotoxy(vc, 0, 0) from reset_terminal() from vc_init() from vc_allocate()
       from con_install() from tty_init_dev() from tty_open() on such console
      causes vc->vc_pos == 0x10000000e due to
      ((unsigned long) ZERO_SIZE_PTR) + -1U * 0 + (-1U << 1).
      
      I don't think that a console with 0 column or 0 row makes sense. And it
      seems that vc_do_resize() does not intend to allow resizing a console to
      0 column or 0 row due to
      
        new_cols = (cols ? cols : vc->vc_cols);
        new_rows = (lines ? lines : vc->vc_rows);
      
      exception.
      
      Theoretically, cols and rows can be any range as long as
      0 < cols * rows * 2 <= KMALLOC_MAX_SIZE is satisfied (e.g.
      cols == 1048576 && rows == 2 is possible) because of
      
        vc->vc_size_row = vc->vc_cols << 1;
        vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
      
      in visual_init() and kzalloc(vc->vc_screenbuf_size) in vc_allocate().
      
      Since we can detect cols == 0 or rows == 0 via screenbuf_size = 0 in
      visual_init(), we can reject kzalloc(0). Then, vc_allocate() will return
      an error, and con_write() will not be called on a console with 0 column
      or 0 row.
      
      We need to make sure that integer overflow in visual_init() won't happen.
      Since vc_do_resize() restricts cols <= 32767 and rows <= 32767, applying
      1 <= cols <= 32767 and 1 <= rows <= 32767 restrictions to vc_allocate()
      will be practically fine.
      
      This patch does not touch con_init(), for returning -EINVAL there
      does not help when we are not returning -ENOMEM.
      
      [1] https://syzkaller.appspot.com/bug?extid=017265e8553724e514e8
      
      Reported-and-tested-by: default avatarsyzbot <syzbot+017265e8553724e514e8@syzkaller.appspotmail.com>
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200712111013.11881-1-penguin-kernel@I-love.SAKURA.ne.jp
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      02abdb61
    • Tetsuo Handa's avatar
      fbdev: Detect integer underflow at "struct fbcon_ops"->clear_margins. · 339a89bb
      Tetsuo Handa authored
      commit 033724d6
      
       upstream.
      
      syzbot is reporting general protection fault in bitfill_aligned() [1]
      caused by integer underflow in bit_clear_margins(). The cause of this
      problem is when and how do_vc_resize() updates vc->vc_{cols,rows}.
      
      If vc_do_resize() fails (e.g. kzalloc() fails) when var.xres or var.yres
      is going to shrink, vc->vc_{cols,rows} will not be updated. This allows
      bit_clear_margins() to see info->var.xres < (vc->vc_cols * cw) or
      info->var.yres < (vc->vc_rows * ch). Unexpectedly large rw or bh will
      try to overrun the __iomem region and causes general protection fault.
      
      Also, vc_resize(vc, 0, 0) does not set vc->vc_{cols,rows} = 0 due to
      
        new_cols = (cols ? cols : vc->vc_cols);
        new_rows = (lines ? lines : vc->vc_rows);
      
      exception. Since cols and lines are calculated as
      
        cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
        rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
        cols /= vc->vc_font.width;
        rows /= vc->vc_font.height;
        vc_resize(vc, cols, rows);
      
      in fbcon_modechanged(), var.xres < vc->vc_font.width makes cols = 0
      and var.yres < vc->vc_font.height makes rows = 0. This means that
      
        const int fd = open("/dev/fb0", O_ACCMODE);
        struct fb_var_screeninfo var = { };
        ioctl(fd, FBIOGET_VSCREENINFO, &var);
        var.xres = var.yres = 1;
        ioctl(fd, FBIOPUT_VSCREENINFO, &var);
      
      easily reproduces integer underflow bug explained above.
      
      Of course, callers of vc_resize() are not handling vc_do_resize() failure
      is bad. But we can't avoid vc_resize(vc, 0, 0) which returns 0. Therefore,
      as a band-aid workaround, this patch checks integer underflow in
      "struct fbcon_ops"->clear_margins call, assuming that
      vc->vc_cols * vc->vc_font.width and vc->vc_rows * vc->vc_font.heigh do not
      cause integer overflow.
      
      [1] https://syzkaller.appspot.com/bug?id=a565882df74fa76f10d3a6fec4be31098dbb37c6
      
      Reported-and-tested-by: default avatarsyzbot <syzbot+e5fd3e65515b48c02a30@syzkaller.appspotmail.com>
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200715015102.3814-1-penguin-kernel@I-love.SAKURA.ne.jp
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      339a89bb
    • Eric Biggers's avatar
      /dev/mem: Add missing memory barriers for devmem_inode · 0747aa3b
      Eric Biggers authored
      commit b34e7e29 upstream.
      
      WRITE_ONCE() isn't the correct way to publish a pointer to a data
      structure, since it doesn't include a write memory barrier.  Therefore
      other tasks may see that the pointer has been set but not see that the
      pointed-to memory has finished being initialized yet.  Instead a
      primitive with "release" semantics is needed.
      
      Use smp_store_release() for this.
      
      The use of READ_ONCE() on the read side is still potentially correct if
      there's no control dependency, i.e. if all memory being "published" is
      transitively reachable via the pointer itself.  But this pairing is
      somewhat confusing and error-prone.  So just upgrade the read side to
      smp_load_acquire() so that it clearly pairs with smp_store_release().
      
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Russell King <linux@arm.linux.org.uk>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Fixes: 3234ac66
      
       ("/dev/mem: Revoke mappings when a driver claims the region")
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Cc: stable <stable@vger.kernel.org>
      Acked-by: default avatarDan Williams <dan.j.williams@intel.com>
      Link: https://lore.kernel.org/r/20200716060553.24618-1-ebiggers@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0747aa3b
    • Georgi Djakov's avatar
      interconnect: msm8916: Fix buswidth of pcnoc_s nodes · 093ed127
      Georgi Djakov authored
      commit 92d232d1
      
       upstream.
      
      The buswidth of the pcnoc_s_* nodes is actually not 8, but
      4 bytes. Let's fix it.
      
      Reported-by: default avatarJun Nie <jun.nie@linaro.org>
      Reviewed-by: default avatarMike Tipton <mdtipton@codeaurora.org>
      Fixes: 30c8fa3e
      
       ("interconnect: qcom: Add MSM8916 interconnect provider driver")
      Link: https://lore.kernel.org/r/20200709130004.12462-1-georgi.djakov@linaro.org
      Signed-off-by: default avatarGeorgi Djakov <georgi.djakov@linaro.org>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200723083735.5616-3-georgi.djakov@linaro.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      093ed127
    • Serge Semin's avatar
      serial: 8250_mtk: Fix high-speed baud rates clamping · 53d34574
      Serge Semin authored
      commit 551e553f upstream.
      
      Commit 7b668c06 ("serial: 8250: Fix max baud limit in generic 8250
      port") fixed limits of a baud rate setting for a generic 8250 port.
      In other words since that commit the baud rate has been permitted to be
      within [uartclk / 16 / UART_DIV_MAX; uartclk / 16], which is absolutely
      normal for a standard 8250 UART port. But there are custom 8250 ports,
      which provide extended baud rate limits. In particular the Mediatek 8250
      port can work with baud rates up to "uartclk" speed.
      
      Normally that and any other peculiarity is supposed to be handled in a
      custom set_termios() callback implemented in the vendor-specific
      8250-port glue-driver. Currently that is how it's done for the most of
      the vendor-specific 8250 ports, but for some reason for Mediatek a
      solution has been spread out to both the glue-driver and to the generic
      8250-port code. Due to that a bug has been introduced, which permitted the
      extended baud rate limit for all even for standard 8250-ports. The bug
      has been fixed by the commit 7b668c06 ("serial: 8250: Fix max baud
      limit in generic 8250 port") by narrowing the baud rates limit back down to
      the normal bounds. Unfortunately by doing so we also broke the
      Mediatek-specific extended bauds feature.
      
      A fix of the problem described above is twofold. First since we can't get
      back the extended baud rate limits feature to the generic set_termios()
      function and that method supports only a standard baud rates range, the
      requested baud rate must be locally stored before calling it and then
      restored back to the new termios structure after the generic set_termios()
      finished its magic business. By doing so we still use the
      serial8250_do_set_termios() method to set the LCR/MCR/FCR/etc. registers,
      while the extended baud rate setting procedure will be performed later in
      the custom Mediatek-specific set_termios() callback. Second since a true
      baud rate is now fully calculated in the custom set_termios() method we
      need to locally update the port timeout by calling the
      uart_update_timeout() function. After the fixes described above are
      implemented in the 8250_mtk.c driver, the Mediatek 8250-port should
      get back to normally working with extended baud rates.
      
      Link: https://lore.kernel.org/linux-serial/20200701211337.3027448-1-danielwinkler@google.com
      
      Fixes: 7b668c06
      
       ("serial: 8250: Fix max baud limit in generic 8250 port")
      Reported-by: default avatarDaniel Winkler <danielwinkler@google.com>
      Signed-off-by: default avatarSerge Semin <Sergey.Semin@baikalelectronics.ru>
      Cc: stable <stable@vger.kernel.org>
      Tested-by: default avatarClaire Chang <tientzu@chromium.org>
      Link: https://lore.kernel.org/r/20200714124113.20918-1-Sergey.Semin@baikalelectronics.ru
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      53d34574
    • Yang Yingliang's avatar
      serial: 8250: fix null-ptr-deref in serial8250_start_tx() · eb710a1a
      Yang Yingliang authored
      commit f4c23a14
      
       upstream.
      
      I got null-ptr-deref in serial8250_start_tx():
      
      [   78.114630] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
      [   78.123778] Mem abort info:
      [   78.126560]   ESR = 0x86000007
      [   78.129603]   EC = 0x21: IABT (current EL), IL = 32 bits
      [   78.134891]   SET = 0, FnV = 0
      [   78.137933]   EA = 0, S1PTW = 0
      [   78.141064] user pgtable: 64k pages, 48-bit VAs, pgdp=00000027d41a8600
      [   78.147562] [0000000000000000] pgd=00000027893f0003, p4d=00000027893f0003, pud=00000027893f0003, pmd=00000027c9a20003, pte=0000000000000000
      [   78.160029] Internal error: Oops: 86000007 [#1] SMP
      [   78.164886] Modules linked in: sunrpc vfat fat aes_ce_blk crypto_simd cryptd aes_ce_cipher crct10dif_ce ghash_ce sha2_ce sha256_arm64 sha1_ce ses enclosure sg sbsa_gwdt ipmi_ssif spi_dw_mmio sch_fq_codel vhost_net tun vhost vhost_iotlb tap ip_tables ext4 mbcache jbd2 ahci hisi_sas_v3_hw libahci hisi_sas_main libsas hns3 scsi_transport_sas hclge libata megaraid_sas ipmi_si hnae3 ipmi_devintf ipmi_msghandler br_netfilter bridge stp llc nvme nvme_core xt_sctp sctp libcrc32c dm_mod nbd
      [   78.207383] CPU: 11 PID: 23258 Comm: null-ptr Not tainted 5.8.0-rc6+ #48
      [   78.214056] Hardware name: Huawei TaiShan 2280 V2/BC82AMDC, BIOS 2280-V2 CS V3.B210.01 03/12/2020
      [   78.222888] pstate: 80400089 (Nzcv daIf +PAN -UAO BTYPE=--)
      [   78.228435] pc : 0x0
      [   78.230618] lr : serial8250_start_tx+0x160/0x260
      [   78.235215] sp : ffff800062eefb80
      [   78.238517] x29: ffff800062eefb80 x28: 0000000000000fff
      [   78.243807] x27: ffff800062eefd80 x26: ffff202fd83b3000
      [   78.249098] x25: ffff800062eefd80 x24: ffff202fd83b3000
      [   78.254388] x23: ffff002fc5e50be8 x22: 0000000000000002
      [   78.259679] x21: 0000000000000001 x20: 0000000000000000
      [   78.264969] x19: ffffa688827eecc8 x18: 0000000000000000
      [   78.270259] x17: 0000000000000000 x16: 0000000000000000
      [   78.275550] x15: ffffa68881bc67a8 x14: 00000000000002e6
      [   78.280841] x13: ffffa68881bc67a8 x12: 000000000000c539
      [   78.286131] x11: d37a6f4de9bd37a7 x10: ffffa68881cccff0
      [   78.291421] x9 : ffffa68881bc6000 x8 : ffffa688819daa88
      [   78.296711] x7 : ffffa688822a0f20 x6 : ffffa688819e0000
      [   78.302002] x5 : ffff800062eef9d0 x4 : ffffa68881e707a8
      [   78.307292] x3 : 0000000000000000 x2 : 0000000000000002
      [   78.312582] x1 : 0000000000000001 x0 : ffffa688827eecc8
      [   78.317873] Call trace:
      [   78.320312]  0x0
      [   78.322147]  __uart_start.isra.9+0x64/0x78
      [   78.326229]  uart_start+0xb8/0x1c8
      [   78.329620]  uart_flush_chars+0x24/0x30
      [   78.333442]  n_tty_receive_buf_common+0x7b0/0xc30
      [   78.338128]  n_tty_receive_buf+0x44/0x2c8
      [   78.342122]  tty_ioctl+0x348/0x11f8
      [   78.345599]  ksys_ioctl+0xd8/0xf8
      [   78.348903]  __arm64_sys_ioctl+0x2c/0xc8
      [   78.352812]  el0_svc_common.constprop.2+0x88/0x1b0
      [   78.357583]  do_el0_svc+0x44/0xd0
      [   78.360887]  el0_sync_handler+0x14c/0x1d0
      [   78.364880]  el0_sync+0x140/0x180
      [   78.368185] Code: bad PC value
      
      SERIAL_PORT_DFNS is not defined on each arch, if it's not defined,
      serial8250_set_defaults() won't be called in serial8250_isa_init_ports(),
      so the p->serial_in pointer won't be initialized, and it leads a null-ptr-deref.
      Fix this problem by calling serial8250_set_defaults() after init uart port.
      
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200721143852.4058352-1-yangyingliang@huawei.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eb710a1a
    • Johan Hovold's avatar
      serial: tegra: fix CREAD handling for PIO · b6727b8f
      Johan Hovold authored
      commit b374c562 upstream.
      
      Commit 33ae787b ("serial: tegra: add support to ignore read") added
      support for dropping input in case CREAD isn't set, but for PIO the
      ignore_status_mask wasn't checked until after the character had been
      put in the receive buffer.
      
      Note that the NULL tty-port test is bogus and will be removed by a
      follow-on patch.
      
      Fixes: 33ae787b
      
       ("serial: tegra: add support to ignore read")
      Cc: stable <stable@vger.kernel.org>     # 5.4
      Cc: Shardar Shariff Md <smohammed@nvidia.com>
      Cc: Krishna Yarlagadda <kyarlagadda@nvidia.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Acked-by: default avatarThierry Reding <treding@nvidia.com>
      Link: https://lore.kernel.org/r/20200710135947.2737-2-johan@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b6727b8f
    • Ian Abbott's avatar
      staging: comedi: addi_apci_1564: check INSN_CONFIG_DIGITAL_TRIG shift · fed64b9d
      Ian Abbott authored
      commit 926234f1 upstream.
      
      The `INSN_CONFIG` comedi instruction with sub-instruction code
      `INSN_CONFIG_DIGITAL_TRIG` includes a base channel in `data[3]`. This is
      used as a right shift amount for other bitmask values without being
      checked.  Shift amounts greater than or equal to 32 will result in
      undefined behavior.  Add code to deal with this.
      
      Fixes: 1e15687e
      
       ("staging: comedi: addi_apci_1564: add Change-of-State interrupt subdevice and required functions")
      Cc: <stable@vger.kernel.org> #3.17+
      Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
      Link: https://lore.kernel.org/r/20200717145257.112660-4-abbotti@mev.co.uk
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fed64b9d
    • Ian Abbott's avatar
      staging: comedi: addi_apci_1500: check INSN_CONFIG_DIGITAL_TRIG shift · 723c6904
      Ian Abbott authored
      commit fc846e9d upstream.
      
      The `INSN_CONFIG` comedi instruction with sub-instruction code
      `INSN_CONFIG_DIGITAL_TRIG` includes a base channel in `data[3]`. This is
      used as a right shift amount for other bitmask values without being
      checked.  Shift amounts greater than or equal to 32 will result in
      undefined behavior.  Add code to deal with this, adjusting the checks
      for invalid channels so that enabled channel bits that would have been
      lost by shifting are also checked for validity.  Only channels 0 to 15
      are valid.
      
      Fixes: a8c66b68 ("staging: comedi: addi_apci_1500: rewrite the subdevice support functions")
      Cc: <stable@vger.kernel.org> #4.0+: ef75e14a
      
      : staging: comedi: verify array index is correct before using it
      Cc: <stable@vger.kernel.org> #4.0+
      Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
      Link: https://lore.kernel.org/r/20200717145257.112660-5-abbotti@mev.co.uk
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      723c6904
    • Ian Abbott's avatar
      staging: comedi: ni_6527: fix INSN_CONFIG_DIGITAL_TRIG support · 9aed007a
      Ian Abbott authored
      commit f07804ec upstream.
      
      `ni6527_intr_insn_config()` processes `INSN_CONFIG` comedi instructions
      for the "interrupt" subdevice.  When `data[0]` is
      `INSN_CONFIG_DIGITAL_TRIG` it is configuring the digital trigger.  When
      `data[2]` is `COMEDI_DIGITAL_TRIG_ENABLE_EDGES` it is configuring rising
      and falling edge detection for the digital trigger, using a base channel
      number (or shift amount) in `data[3]`, a rising edge bitmask in
      `data[4]` and falling edge bitmask in `data[5]`.
      
      If the base channel number (shift amount) is greater than or equal to
      the number of channels (24) of the digital input subdevice, there are no
      changes to the rising and falling edges, so the mask of channels to be
      changed can be set to 0, otherwise the mask of channels to be changed,
      and the rising and falling edge bitmasks are shifted by the base channel
      number before calling `ni6527_set_edge_detection()` to change the
      appropriate registers.  Unfortunately, the code is comparing the base
      channel (shift amount) to the interrupt subdevice's number of channels
      (1) instead of the digital input subdevice's number of channels (24).
      Fix it by comparing to 32 because all shift amounts for an `unsigned
      int` must be less than that and everything from bit 24 upwards is
      ignored by `ni6527_set_edge_detection()` anyway.
      
      Fixes: 110f9e68
      
       ("staging: comedi: ni_6527: support INSN_CONFIG_DIGITAL_TRIG")
      Cc: <stable@vger.kernel.org> # 3.17+
      Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
      Link: https://lore.kernel.org/r/20200717145257.112660-2-abbotti@mev.co.uk
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9aed007a
    • Ian Abbott's avatar
      staging: comedi: addi_apci_1032: check INSN_CONFIG_DIGITAL_TRIG shift · 06e6dcc2
      Ian Abbott authored
      commit 0bd0db42 upstream.
      
      The `INSN_CONFIG` comedi instruction with sub-instruction code
      `INSN_CONFIG_DIGITAL_TRIG` includes a base channel in `data[3]`. This is
      used as a right shift amount for other bitmask values without being
      checked.  Shift amounts greater than or equal to 32 will result in
      undefined behavior.  Add code to deal with this.
      
      Fixes: 33cdce62
      
       ("staging: comedi: addi_apci_1032: conform to new INSN_CONFIG_DIGITAL_TRIG")
      Cc: <stable@vger.kernel.org> #3.8+
      Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
      Link: https://lore.kernel.org/r/20200717145257.112660-3-abbotti@mev.co.uk
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      06e6dcc2
    • Rustam Kovhaev's avatar
      staging: wlan-ng: properly check endpoint types · 6d56f193
      Rustam Kovhaev authored
      commit faaff976
      
       upstream.
      
      As syzkaller detected, wlan-ng driver does not do sanity check of
      endpoints in prism2sta_probe_usb(), add check for xfer direction and type
      
      Reported-and-tested-by: default avatar <syzbot+c2a1fa67c02faa0de723@syzkaller.appspotmail.com>
      Link: https://syzkaller.appspot.com/bug?extid=c2a1fa67c02faa0de723
      Signed-off-by: default avatarRustam Kovhaev <rkovhaev@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200722161052.999754-1-rkovhaev@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6d56f193
    • Helmut Grohne's avatar
      tty: xilinx_uartps: Really fix id assignment · 13bf0663
      Helmut Grohne authored
      commit 22a82fa7 upstream.
      
      The problems started with the revert (18cc7ac8). The
      cdns_uart_console.index is statically assigned -1. When the port is
      registered, Linux assigns consecutive numbers to it. It turned out that
      when using ttyPS1 as console, the index is not updated as we are reusing
      the same cdns_uart_console instance for multiple ports. When registering
      ttyPS0, it gets updated from -1 to 0, but when registering ttyPS1, it
      already is 0 and not updated.
      
      That led to 2ae11c46. It assigns the index prior to registering
      the uart_driver once. Unfortunately, that ended up breaking the
      situation where the probe order does not match the id order. When using
      the same device tree for both uboot and linux, it is important that the
      serial0 alias points to the console. So some boards reverse those
      aliases. This was reported by Jan Kiszka. The proposed fix was reverting
      the index assignment and going back to the previous iteration.
      
      However such a reversed assignement (serial0 -> uart1, serial1 -> uart0)
      was already partially broken by the revert (18cc7ac8
      
      ). While the
      ttyPS device works, the kmsg connection is already broken and kernel
      messages go missing. Reverting the id assignment does not fix this.
      
      >From the xilinx_uartps driver pov (after reverting the refactoring
      commits), there can be only one console. This manifests in static
      variables console_pprt and cdns_uart_console. These variables are not
      properly linked and can go out of sync. The cdns_uart_console.index is
      important for uart_add_one_port. We call that function for each port -
      one of which hopefully is the console. If it isn't, the CON_ENABLED flag
      is not set and console_port is cleared. The next cdns_uart_probe call
      then tries to register the next port using that same cdns_uart_console.
      
      It is important that console_port and cdns_uart_console (and its index
      in particular) stay in sync. The index assignment implemented by
      Shubhrajyoti Datta is correct in principle. It just may have to happen a
      second time if the first cdns_uart_probe call didn't encounter the
      console device. And we shouldn't change the index once the console uart
      is registered.
      
      Reported-by: default avatarShubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
      Reported-by: default avatarJan Kiszka <jan.kiszka@web.de>
      Link: https://lore.kernel.org/linux-serial/f4092727-d8f5-5f91-2c9f-76643aace993@siemens.com/
      Fixes: 18cc7ac8 ("Revert "serial: uartps: Register own uart console and driver structures"")
      Fixes: 2ae11c46 ("tty: xilinx_uartps: Fix missing id assignment to the console")
      Fixes: 76ed2e10
      
       ("Revert "tty: xilinx_uartps: Fix missing id assignment to the console"")
      Signed-off-by: default avatarHelmut Grohne <helmut.grohne@intenta.de>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200713073227.GA3805@laureti-dev
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      13bf0663
    • Johannes Berg's avatar
      iwlwifi: mvm: don't call iwl_mvm_free_inactive_queue() under RCU · 86062f8d
      Johannes Berg authored
      commit fbb1461a
      
       upstream.
      
      iwl_mvm_free_inactive_queue() will sleep in synchronize_net() under
      some circumstances, so don't call it under RCU. There doesn't appear
      to be a need for RCU protection around this particular call.
      
      Cc: stable@vger.kernel.org # v5.4+
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarLuca Coelho <luciano.coelho@intel.com>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Link: https://lore.kernel.org/r/iwlwifi.20200403112332.0f49448c133d.I17fd308bc4a9491859c9b112f4eb5d2c3fc18d7d@changeid
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      86062f8d
    • Steve French's avatar
      Revert "cifs: Fix the target file was deleted when rename failed." · 0df6a4d2
      Steve French authored
      commit 0e670518 upstream.
      
      This reverts commit 9ffad926
      
      .
      
      Upon additional testing with older servers, it was found that
      the original commit introduced a regression when using the old SMB1
      dialect and rsyncing over an existing file.
      
      The patch will need to be respun to address this, likely including
      a larger refactoring of the SMB1 and SMB3 rename code paths to make
      it less confusing and also to address some additional rename error
      cases that SMB3 may be able to workaround.
      
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Reported-by: default avatarPatrick Fernie <patrick.fernie@gmail.com>
      CC: Stable <stable@vger.kernel.org>
      Acked-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
      Acked-by: default avatarPavel Shilovsky <pshilov@microsoft.com>
      Acked-by: default avatarZhang Xiaoxu <zhangxiaoxu5@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0df6a4d2
    • Forest Crossman's avatar
      usb: xhci: Fix ASM2142/ASM3142 DMA addressing · 24ab19ee
      Forest Crossman authored
      commit dbb0897e
      
       upstream.
      
      The ASM2142/ASM3142 (same PCI IDs) does not support full 64-bit DMA
      addresses, which can cause silent memory corruption or IOMMU errors on
      platforms that use the upper bits. Add the XHCI_NO_64BIT_SUPPORT quirk
      to fix this issue.
      
      Signed-off-by: default avatarForest Crossman <cyrozap@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200717112734.328432-1-cyrozap@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      24ab19ee
    • Jon Hunter's avatar
      usb: tegra: Fix allocation for the FPCI context · 9f54c504
      Jon Hunter authored
      commit 0b987032 upstream.
      
      Commit 5c4e8d37 ("usb: host: xhci-tegra: Add support for XUSB
      context save/restore") is using the IPFS 'num_offsets' value when
      allocating memory for FPCI context instead of the FPCI 'num_offsets'.
      
      After commit cad064f1 ("devres: handle zero size in devm_kmalloc()")
      was added system suspend started failing on Tegra186. The kernel log
      showed that the Tegra XHCI driver was crashing on entry to suspend when
      attempting the save the USB context. On Tegra186, the IPFS context has a
      zero length but the FPCI content has a non-zero length, and because of
      the bug in the Tegra XHCI driver we are incorrectly allocating a zero
      length array for the FPCI context. The crash seen on entering suspend
      when we attempt to save the FPCI context and following commit
      cad064f1 ("devres: handle zero size in devm_kmalloc()") this now
      causes a NULL pointer deference when we access the memory. Fix this by
      correcting the amount of memory we are allocating for FPCI contexts.
      
      Cc: stable@vger.kernel.org
      
      Fixes: 5c4e8d37
      
       ("usb: host: xhci-tegra: Add support for XUSB context save/restore")
      
      Signed-off-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Acked-by: default avatarThierry Reding <treding@nvidia.com>
      Link: https://lore.kernel.org/r/20200715113842.30680-1-jonathanh@nvidia.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9f54c504
    • Chunfeng Yun's avatar
      usb: xhci-mtk: fix the failure of bandwidth allocation · 89cbdfbc
      Chunfeng Yun authored
      commit 5ce1a24d upstream.
      
      The wMaxPacketSize field of endpoint descriptor may be zero
      as default value in alternate interface, and they are not
      actually selected when start stream, so skip them when try to
      allocate bandwidth.
      
      Cc: stable <stable@vger.kernel.org>
      Fixes: 0cbd4b34
      
       ("xhci: mediatek: support MTK xHCI host controller")
      Signed-off-by: default avatarChunfeng Yun <chunfeng.yun@mediatek.com>
      Link: https://lore.kernel.org/r/1594360672-2076-1-git-send-email-chunfeng.yun@mediatek.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      89cbdfbc
    • Tetsuo Handa's avatar
      binder: Don't use mmput() from shrinker function. · 98e96c7c
      Tetsuo Handa authored
      commit f867c771 upstream.
      
      syzbot is reporting that mmput() from shrinker function has a risk of
      deadlock [1], for delayed_uprobe_add() from update_ref_ctr() calls
      kzalloc(GFP_KERNEL) with delayed_uprobe_lock held, and
      uprobe_clear_state() from __mmput() also holds delayed_uprobe_lock.
      
      Commit a1b2289c
      
       ("android: binder: drop lru lock in isolate
      callback") replaced mmput() with mmput_async() in order to avoid sleeping
      with spinlock held. But this patch replaces mmput() with mmput_async() in
      order not to start __mmput() from shrinker context.
      
      [1] https://syzkaller.appspot.com/bug?id=bc9e7303f537c41b2b0cc2dfcea3fc42964c2d45
      
      Reported-by: default avatarsyzbot <syzbot+1068f09c44d151250c33@syzkaller.appspotmail.com>
      Reported-by: default avatarsyzbot <syzbot+e5344baa319c9a96edec@syzkaller.appspotmail.com>
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Reviewed-by: default avatarMichal Hocko <mhocko@suse.com>
      Acked-by: default avatarTodd Kjos <tkjos@google.com>
      Acked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/4ba9adb2-43f5-2de0-22de-f6075c1fab50@i-love.sakura.ne.jp
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      98e96c7c
    • Arvind Sankar's avatar
      x86/boot: Don't add the EFI stub to targets · 79818ce5
      Arvind Sankar authored
      [ Upstream commit da05b143
      
       ]
      
      vmlinux-objs-y is added to targets, which currently means that the EFI
      stub gets added to the targets as well. It shouldn't be added since it
      is built elsewhere.
      
      This confuses Makefile.build which interprets the EFI stub as a target
      	$(obj)/$(objtree)/drivers/firmware/efi/libstub/lib.a
      and will create drivers/firmware/efi/libstub/ underneath
      arch/x86/boot/compressed, to hold this supposed target, if building
      out-of-tree. [0]
      
      Fix this by pulling the stub out of vmlinux-objs-y into efi-obj-y.
      
      [0] See scripts/Makefile.build near the end:
          # Create directories for object files if they do not exist
      
      Signed-off-by: default avatarArvind Sankar <nivedita@alum.mit.edu>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Acked-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Link: https://lkml.kernel.org/r/20200715032631.1562882-1-nivedita@alum.mit.edu
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      79818ce5
    • Palmer Dabbelt's avatar
      RISC-V: Upgrade smp_mb__after_spinlock() to iorw,iorw · fcf756c2
      Palmer Dabbelt authored
      [ Upstream commit 38b7c2a3
      
       ]
      
      While digging through the recent mmiowb preemption issue it came up that
      we aren't actually preventing IO from crossing a scheduling boundary.
      While it's a bit ugly to overload smp_mb__after_spinlock() with this
      behavior, it's what PowerPC is doing so there's some precedent.
      
      Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fcf756c2
    • Qi Liu's avatar
      drivers/perf: Prevent forced unbinding of PMU drivers · b25f9539
      Qi Liu authored
      [ Upstream commit f32ed8eb
      
       ]
      
      Forcefully unbinding PMU drivers during perf sampling will lead to
      a kernel panic, because the perf upper-layer framework call a NULL
      pointer in this situation.
      
      To solve this issue, "suppress_bind_attrs" should be set to true, so
      that bind/unbind can be disabled via sysfs and prevent unbinding PMU
      drivers during perf sampling.
      
      Signed-off-by: default avatarQi Liu <liuqi115@huawei.com>
      Reviewed-by: default avatarJohn Garry <john.garry@huawei.com>
      Link: https://lore.kernel.org/r/1594975763-32966-1-git-send-email-liuqi115@huawei.com
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b25f9539
    • Will Deacon's avatar
      asm-generic/mmiowb: Allow mmiowb_set_pending() when preemptible() · 92e543a6
      Will Deacon authored
      [ Upstream commit bd024e82
      
       ]
      
      Although mmiowb() is concerned only with serialising MMIO writes occuring
      in contexts where a spinlock is held, the call to mmiowb_set_pending()
      from the MMIO write accessors can occur in preemptible contexts, such
      as during driver probe() functions where ordering between CPUs is not
      usually a concern, assuming that the task migration path provides the
      necessary ordering guarantees.
      
      Unfortunately, the default implementation of mmiowb_set_pending() is not
      preempt-safe, as it makes use of a a per-cpu variable to track its
      internal state. This has been reported to generate the following splat
      on riscv:
      
       | BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
       | caller is regmap_mmio_write32le+0x1c/0x46
       | CPU: 3 PID: 1 Comm: swapper/0 Not tainted 5.8.0-rc3-hfu+ #1
       | Call Trace:
       |  walk_stackframe+0x0/0x7a
       |  dump_stack+0x6e/0x88
       |  regmap_mmio_write32le+0x18/0x46
       |  check_preemption_disabled+0xa4/0xaa
       |  regmap_mmio_write32le+0x18/0x46
       |  regmap_mmio_write+0x26/0x44
       |  regmap_write+0x28/0x48
       |  sifive_gpio_probe+0xc0/0x1da
      
      Although it's possible to fix the driver in this case, other splats have
      been seen from other drivers, including the infamous 8250 UART, and so
      it's better to address this problem in the mmiowb core itself.
      
      Fix mmiowb_set_pending() by using the raw_cpu_ptr() to get at the mmiowb
      state and then only updating the 'mmiowb_pending' field if we are not
      preemptible (i.e. we have a non-zero nesting count).
      
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Cc: Guo Ren <guoren@kernel.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Reported-by: default avatarPalmer Dabbelt <palmer@dabbelt.com>
      Reported-by: default avatarEmil Renner Berthing <kernel@esmil.dk>
      Tested-by: default avatarEmil Renner Berthing <kernel@esmil.dk>
      Reviewed-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      Acked-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      Link: https://lore.kernel.org/r/20200716112816.7356-1-will@kernel.org
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      92e543a6
    • Arnd Bergmann's avatar
      x86: math-emu: Fix up 'cmp' insn for clang ias · 6b964243
      Arnd Bergmann authored
      [ Upstream commit 81e96851
      
       ]
      
      The clang integrated assembler requires the 'cmp' instruction to
      have a length prefix here:
      
      arch/x86/math-emu/wm_sqrt.S:212:2: error: ambiguous instructions require an explicit suffix (could be 'cmpb', 'cmpw', or 'cmpl')
       cmp $0xffffffff,-24(%ebp)
       ^
      
      Make this a 32-bit comparison, which it was clearly meant to be.
      
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Link: https://lkml.kernel.org/r/20200527135352.1198078-1-arnd@arndb.de
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6b964243
    • Will Deacon's avatar
      arm64: Use test_tsk_thread_flag() for checking TIF_SINGLESTEP · fd31dfd9
      Will Deacon authored
      [ Upstream commit 5afc7855
      
       ]
      
      Rather than open-code test_tsk_thread_flag() at each callsite, simply
      replace the couple of offenders with calls to test_tsk_thread_flag()
      directly.
      
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fd31dfd9
    • Qi Liu's avatar
      drivers/perf: Fix kernel panic when rmmod PMU modules during perf sampling · c4c65882
      Qi Liu authored
      [ Upstream commit bdc5c744
      
       ]
      
      When users try to remove PMU modules during perf sampling, kernel panic
      will happen because the pmu->read() is a NULL pointer here.
      
      INFO on HiSilicon hip08 platform as follow:
      pc : hisi_uncore_pmu_event_update+0x30/0xa4 [hisi_uncore_pmu]
      lr : hisi_uncore_pmu_read+0x20/0x2c [hisi_uncore_pmu]
      sp : ffff800010103e90
      x29: ffff800010103e90 x28: ffff0027db0c0e40
      x27: ffffa29a76f129d8 x26: ffffa29a77ceb000
      x25: ffffa29a773a5000 x24: ffffa29a77392000
      x23: ffffddffe5943f08 x22: ffff002784285960
      x21: ffff002784285800 x20: ffff0027d2e76c80
      x19: ffff0027842859e0 x18: ffff80003498bcc8
      x17: ffffa29a76afe910 x16: ffffa29a7583f530
      x15: 16151a1512061a1e x14: 0000000000000000
      x13: ffffa29a76f1e238 x12: 0000000000000001
      x11: 0000000000000400 x10: 00000000000009f0
      x9 : ffff8000107b3e70 x8 : ffff0027db0c1890
      x7 : ffffa29a773a7000 x6 : 00000007f5131013
      x5 : 00000007f5131013 x4 : 09f257d417c00000
      x3 : 00000002187bd7ce x2 : ffffa29a38f0f0d8
      x1 : ffffa29a38eae268 x0 : ffff0027d2e76c80
      Call trace:
      hisi_uncore_pmu_event_update+0x30/0xa4 [hisi_uncore_pmu]
      hisi_uncore_pmu_read+0x20/0x2c [hisi_uncore_pmu]
      __perf_event_read+0x1a0/0x1f8
      flush_smp_call_function_queue+0xa0/0x160
      generic_smp_call_function_single_interrupt+0x18/0x20
      handle_IPI+0x31c/0x4dc
      gic_handle_irq+0x2c8/0x310
      el1_irq+0xcc/0x180
      arch_cpu_idle+0x4c/0x20c
      default_idle_call+0x20/0x30
      do_idle+0x1b4/0x270
      cpu_startup_entry+0x28/0x30
      secondary_start_kernel+0x1a4/0x1fc
      
      To solve the above issue, current module should be registered to kernel,
      so that try_module_get() can be invoked when perf sampling starts. This
      adds the reference counting of module and could prevent users from removing
      modules during sampling.
      
      Reported-by: default avatarHaifeng Wang <wang.wanghaifeng@huawei.com>
      Signed-off-by: default avatarQi Liu <liuqi115@huawei.com>
      Reviewed-by: default avatarJohn Garry <john.garry@huawei.com>
      Link: https://lore.kernel.org/r/1594891165-8228-1-git-send-email-liuqi115@huawei.com
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c4c65882
    • PeiSen Hou's avatar
      ALSA: hda/realtek - fixup for yet another Intel reference board · 59076483
      PeiSen Hou authored
      [ Upstream commit 5734e509
      
       ]
      
      Add headset_jack for the intel reference board support with
      10ec:1230.
      
      Signed-off-by: default avatarPeiSen Hou <pshou@realtek.com.tw>
      Link: https://lore.kernel.org/r/20200716090134.9811-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      59076483
    • Cristian Marussi's avatar
      hwmon: (scmi) Fix potential buffer overflow in scmi_hwmon_probe() · b6914cfb
      Cristian Marussi authored
      [ Upstream commit 3ce17cd2
      
       ]
      
      SMATCH detected a potential buffer overflow in the manipulation of
      hwmon_attributes array inside the scmi_hwmon_probe function:
      
      drivers/hwmon/scmi-hwmon.c:226
       scmi_hwmon_probe() error: buffer overflow 'hwmon_attributes' 6 <= 9
      
      Fix it by statically declaring the size of the array as the maximum
      possible as defined by hwmon_max define.
      
      Signed-off-by: default avatarCristian Marussi <cristian.marussi@arm.com>
      Reviewed-by: default avatarSudeep Holla <sudeep.holla@arm.com>
      Link: https://lore.kernel.org/r/20200715121338.GA18761@e119603-lin.cambridge.arm.com
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b6914cfb
    • Vasiliy Kupriakov's avatar
      platform/x86: asus-wmi: allow BAT1 battery name · 69187e3b
      Vasiliy Kupriakov authored
      [ Upstream commit 9a33e375
      
       ]
      
      The battery on my laptop ASUS TUF Gaming FX706II is named BAT1.
      This patch allows battery extension to load.
      
      Signed-off-by: default avatarVasiliy Kupriakov <rublag-ns@yandex.ru>
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      69187e3b
    • Srinivas Pandruvada's avatar
      platform/x86: ISST: Add new PCI device ids · 171c6cad
      Srinivas Pandruvada authored
      [ Upstream commit e1eea3f8
      
       ]
      
      Added new PCI device ids for supporting mailbox and MMIO interface for
      Sapphire Rapids.
      
      Signed-off-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      171c6cad
    • Guenter Roeck's avatar
      hwmon: (nct6775) Accept PECI Calibration as temperature source for NCT6798D · 603b876a
      Guenter Roeck authored
      [ Upstream commit 8a03746c
      
       ]
      
      Stefan Dietrich reports invalid temperature source messages on Asus Formula
      XII Z490.
      
      nct6775 nct6775.656: Invalid temperature source 28 at index 0,
      		source register 0x100, temp register 0x73
      
      Debugging suggests that temperature source 28 reports the CPU temperature.
      Let's assume that temperature sources 28 and 29 reflect "PECI Agent {0,1}
      Calibration", similar to other chips of the series.
      
      Reported-by: default avatarStefan Dietrich <roots@gmx.de>
      Cc: Stefan Dietrich <roots@gmx.de>
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      603b876a
    • Jack Xiao's avatar
      drm/amdgpu: fix preemption unit test · 21869ebb
      Jack Xiao authored
      [ Upstream commit d845a205
      
       ]
      
      Remove signaled jobs from job list and ensure the
      job was indeed preempted.
      
      Signed-off-by: default avatarJack Xiao <Jack.Xiao@amd.com>
      Reviewed-by: default avatarHawking Zhang <Hawking.Zhang@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      21869ebb
    • Jack Xiao's avatar
      drm/amdgpu/gfx10: fix race condition for kiq · d2b27b4f
      Jack Xiao authored
      [ Upstream commit 7d65a577
      
       ]
      
      During preemption test for gfx10, it uses kiq to trigger
      gfx preemption, which would result in race condition
      with flushing TLB for kiq.
      
      Signed-off-by: default avatarJack Xiao <Jack.Xiao@amd.com>
      Reviewed-by: default avatarHawking Zhang <Hawking.Zhang@amd.com>
      Acked-by: default avatarChristian König <christian.koenig@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d2b27b4f
    • Chu Lin's avatar
      hwmon: (adm1275) Make sure we are reading enough data for different chips · f5aaa22d
      Chu Lin authored
      [ Upstream commit 6d1d41c0
      
       ]
      
      Issue:
      When PEC is enabled, binding adm1272 to the adm1275 would
      fail due to PEC error. See below:
      adm1275: probe of xxxx failed with error -74
      
      Diagnosis:
      Per the datasheet of adm1272, adm1278, adm1293 and amd1294,
      PMON_CONFIG (0xd4) is 16bits wide. On the other hand,
      PMON_CONFIG (0xd4) for adm1275 is 8bits wide. The driver should not
      assume everything is 8bits wide and read only 8bits from it.
      
      Solution:
      If it is adm1272, adm1278, adm1293 and adm1294, use i2c_read_word.
      Else, use i2c_read_byte
      
      Testing:
      Binding adm1272 to the driver.
      The change is only tested on adm1272.
      
      Signed-off-by: default avatarChu Lin <linchuyuan@google.com>
      Link: https://lore.kernel.org/r/20200709040612.3977094-1-linchuyuan@google.com
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f5aaa22d