Skip to content
  1. Mar 14, 2021
    • Arnd Bergmann's avatar
      linux/compiler-clang.h: define HAVE_BUILTIN_BSWAP* · 97e49102
      Arnd Bergmann authored
      Separating compiler-clang.h from compiler-gcc.h inadventently dropped the
      definitions of the three HAVE_BUILTIN_BSWAP macros, which requires falling
      back to the open-coded version and hoping that the compiler detects it.
      
      Since all versions of clang support the __builtin_bswap interfaces, add
      back the flags and have the headers pick these up automatically.
      
      This results in a 4% improvement of compilation speed for arm defconfig.
      
      Note: it might also be worth revisiting which architectures set
      CONFIG_ARCH_USE_BUILTIN_BSWAP for one compiler or the other, today this is
      set on six architectures (arm32, csky, mips, powerpc, s390, x86), while
      another ten architectures define custom helpers (alpha, arc, ia64, m68k,
      mips, nios2, parisc, sh, sparc, xtensa), and the rest (arm64, h8300,
      hexagon, microblaze, nds32, openrisc, riscv) just get the unoptimized
      version and rely on the compiler to detect it.
      
      A long time ago, the compiler builtins were architecture specific, but
      nowadays, all compilers that are able to build the kernel have correct
      implementations of them, though some may not be as optimized as the inline
      asm versions.
      
      The patch that dropped the optimization landed in v4.19, so as discussed
      it would be fairly safe to backport this revert to stable kernels to the
      4.19/5.4/5.10 stable kernels, but there is a remaining risk for
      regressions, and it has no known side-effects besides compile speed.
      
      Link: https://lkml.kernel.org/r/20210226161151.2629097-1-arnd@kernel.org
      Link: https://lore.kernel.org/lkml/20210225164513.3667778-1-arnd@kernel.org/
      Fixes: 815f0ddb
      
       ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Acked-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      Acked-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Acked-by: default avatarLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Nick Hu <nickhu@andestech.com>
      Cc: Greentime Hu <green.hu@gmail.com>
      Cc: Vincent Chen <deanbo422@gmail.com>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Cc: Palmer Dabbelt <palmer@dabbelt.com>
      Cc: Albert Ou <aou@eecs.berkeley.edu>
      Cc: Guo Ren <guoren@kernel.org>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Sami Tolvanen <samitolvanen@google.com>
      Cc: Marco Elver <elver@google.com>
      Cc: Arvind Sankar <nivedita@alum.mit.edu>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      97e49102
    • Vlastimil Babka's avatar
      MAINTAINERS: exclude uapi directories in API/ABI section · f0b15b60
      Vlastimil Babka authored
      Commit 7b4693e6 ("MAINTAINERS: add uapi directories to API/ABI
      section") added include/uapi/ and arch/*/include/uapi/ so that patches
      modifying them CC linux-api.  However that was already done in the past
      and resulted in too much noise and thus later removed, as explained in
      b14fd334
      
       ("MAINTAINERS: trim the file triggers for ABI/API")
      
      To prevent another round of addition and removal in the future, change the
      entries to X: (explicit exclusion) for documentation purposes, although
      they are not subdirectories of broader included directories, as there is
      apparently no defined way to add plain comments in subsystem sections.
      
      Link: https://lkml.kernel.org/r/20210301100255.25229-1-vbabka@suse.cz
      Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Reported-by: default avatarMichael Kerrisk (man-pages) <mtk.manpages@gmail.com>
      Acked-by: default avatarMichael Kerrisk (man-pages) <mtk.manpages@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      f0b15b60
    • Lior Ribak's avatar
      binfmt_misc: fix possible deadlock in bm_register_write · e7850f4d
      Lior Ribak authored
      There is a deadlock in bm_register_write:
      
      First, in the begining of the function, a lock is taken on the binfmt_misc
      root inode with inode_lock(d_inode(root)).
      
      Then, if the user used the MISC_FMT_OPEN_FILE flag, the function will call
      open_exec on the user-provided interpreter.
      
      open_exec will call a path lookup, and if the path lookup process includes
      the root of binfmt_misc, it will try to take a shared lock on its inode
      again, but it is already locked, and the code will get stuck in a deadlock
      
      To reproduce the bug:
      $ echo ":iiiii:E::ii::/proc/sys/fs/binfmt_misc/bla:F" > /proc/sys/fs/binfmt_misc/register
      
      backtrace of where the lock occurs (#5):
      0  schedule () at ./arch/x86/include/asm/current.h:15
      1  0xffffffff81b51237 in rwsem_down_read_slowpath (sem=0xffff888003b202e0, count=<optimized out>, state=state@entry=2) at kernel/locking/rwsem.c:992
      2  0xffffffff81b5150a in __down_read_common (state=2, sem=<optimized out>) at kernel/locking/rwsem.c:1213
      3  __down_read (sem=<optimized out>) at kernel/locking/rwsem.c:1222
      4  down_read (sem=<optimized out>) at kernel/locking/rwsem.c:1355
      5  0xffffffff811ee22a in inode_lock_shared (inode=<optimized out>) at ./include/linux/fs.h:783
      6  open_last_lookups (op=0xffffc9000022fe34, file=0xffff888004098600, nd=0xffffc9000022fd10) at fs/namei.c:3177
      7  path_openat (nd=nd@entry=0xffffc9000022fd10, op=op@entry=0xffffc9000022fe34, flags=flags@entry=65) at fs/namei.c:3366
      8  0xffffffff811efe1c in do_filp_open (dfd=<optimized out>, pathname=pathname@entry=0xffff8880031b9000, op=op@entry=0xffffc9000022fe34) at fs/namei.c:3396
      9  0xffffffff811e493f in do_open_execat (fd=fd@entry=-100, name=name@entry=0xffff8880031b9000, flags=<optimized out>, flags@entry=0) at fs/exec.c:913
      10 0xffffffff811e4a92 in open_exec (name=<optimized out>) at fs/exec.c:948
      11 0xffffffff8124aa84 in bm_register_write (file=<optimized out>, buffer=<optimized out>, count=19, ppos=<optimized out>) at fs/binfmt_misc.c:682
      12 0xffffffff811decd2 in vfs_write (file=file@entry=0xffff888004098500, buf=buf@entry=0xa758d0 ":iiiii:E::ii::i:CF
      ", count=count@entry=19, pos=pos@entry=0xffffc9000022ff10) at fs/read_write.c:603
      13 0xffffffff811defda in ksys_write (fd=<optimized out>, buf=0xa758d0 ":iiiii:E::ii::i:CF
      ", count=19) at fs/read_write.c:658
      14 0xffffffff81b49813 in do_syscall_64 (nr=<optimized out>, regs=0xffffc9000022ff58) at arch/x86/entry/common.c:46
      15 0xffffffff81c0007c in entry_SYSCALL_64 () at arch/x86/entry/entry_64.S:120
      
      To solve the issue, the open_exec call is moved to before the write
      lock is taken by bm_register_write
      
      Link: https://lkml.kernel.org/r/20210228224414.95962-1-liorribak@gmail.com
      Fixes: 948b701a
      
       ("binfmt_misc: add persistent opened binary handler for containers")
      Signed-off-by: default avatarLior Ribak <liorribak@gmail.com>
      Acked-by: default avatarHelge Deller <deller@gmx.de>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      e7850f4d
    • OGAWA Hirofumi's avatar
      mm/highmem.c: fix zero_user_segments() with start > end · 184cee51
      OGAWA Hirofumi authored
      zero_user_segments() is used from __block_write_begin_int(), for example
      like the following
      
      	zero_user_segments(page, 4096, 1024, 512, 918)
      
      But new the zero_user_segments() implementation for for HIGHMEM +
      TRANSPARENT_HUGEPAGE doesn't handle "start > end" case correctly, and hits
      BUG_ON().  (we can fix __block_write_begin_int() instead though, it is the
      old and multiple usage)
      
      Also it calls kmap_atomic() unnecessarily while start == end == 0.
      
      Link: https://lkml.kernel.org/r/87v9ab60r4.fsf@mail.parknet.co.jp
      Fixes: 0060ef3b
      
       ("mm: support THPs in zero_user_segments")
      Signed-off-by: default avatarOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      184cee51
    • Peter Xu's avatar
      hugetlb: do early cow when page pinned on src mm · 4eae4efa
      Peter Xu authored
      This is the last missing piece of the COW-during-fork effort when there're
      pinned pages found.  One can reference 70e806e4 ("mm: Do early cow for
      pinned pages during fork() for ptes", 2020-09-27) for more information,
      since we do similar things here rather than pte this time, but just for
      hugetlb.
      
      Note that after Jason's recent work on 57efa1fe ("mm/gup: prevent
      gup_fast from racing with COW during fork", 2020-12-15) which is safer and
      easier to understand, we're safe now within the whole copy_page_range()
      against gup-fast, we don't need the wr-protect trick that proposed in
      70e806e4
      
       anymore.
      
      Link: https://lkml.kernel.org/r/20210217233547.93892-6-peterx@redhat.com
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Reviewed-by: default avatarJason Gunthorpe <jgg@ziepe.ca>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Daniel Vetter <daniel@ffwll.ch>
      Cc: David Airlie <airlied@linux.ie>
      Cc: David Gibson <david@gibson.dropbear.id.au>
      Cc: Gal Pressman <galpress@amazon.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Jann Horn <jannh@google.com>
      Cc: Kirill Shutemov <kirill@shutemov.name>
      Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Miaohe Lin <linmiaohe@huawei.com>
      Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
      Cc: Roland Scheidegger <sroland@vmware.com>
      Cc: VMware Graphics <linux-graphics-maintainer@vmware.com>
      Cc: Wei Zhang <wzam@amazon.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      4eae4efa
    • Peter Xu's avatar
      mm: use is_cow_mapping() across tree where proper · ca6eb14d
      Peter Xu authored
      
      
      After is_cow_mapping() is exported in mm.h, replace some manual checks
      elsewhere throughout the tree but start to use the new helper.
      
      Link: https://lkml.kernel.org/r/20210217233547.93892-5-peterx@redhat.com
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Reviewed-by: default avatarJason Gunthorpe <jgg@ziepe.ca>
      Cc: VMware Graphics <linux-graphics-maintainer@vmware.com>
      Cc: Roland Scheidegger <sroland@vmware.com>
      Cc: David Airlie <airlied@linux.ie>
      Cc: Daniel Vetter <daniel@ffwll.ch>
      Cc: Mike Kravetz <mike.kravetz@oracle.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Gibson <david@gibson.dropbear.id.au>
      Cc: Gal Pressman <galpress@amazon.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Jann Horn <jannh@google.com>
      Cc: Kirill Shutemov <kirill@shutemov.name>
      Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Miaohe Lin <linmiaohe@huawei.com>
      Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
      Cc: Wei Zhang <wzam@amazon.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ca6eb14d
    • Peter Xu's avatar
      mm: introduce page_needs_cow_for_dma() for deciding whether cow · 97a7e473
      Peter Xu authored
      
      
      We've got quite a few places (pte, pmd, pud) that explicitly checked
      against whether we should break the cow right now during fork().  It's
      easier to provide a helper, especially before we work the same thing on
      hugetlbfs.
      
      Since we'll reference is_cow_mapping() in mm.h, move it there too.
      Actually it suites mm.h more since internal.h is mm/ only, but mm.h is
      exported to the whole kernel.  With that we should expect another patch to
      use is_cow_mapping() whenever we can across the kernel since we do use it
      quite a lot but it's always done with raw code against VM_* flags.
      
      Link: https://lkml.kernel.org/r/20210217233547.93892-4-peterx@redhat.com
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Reviewed-by: default avatarJason Gunthorpe <jgg@ziepe.ca>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Daniel Vetter <daniel@ffwll.ch>
      Cc: David Airlie <airlied@linux.ie>
      Cc: David Gibson <david@gibson.dropbear.id.au>
      Cc: Gal Pressman <galpress@amazon.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Jann Horn <jannh@google.com>
      Cc: Kirill Shutemov <kirill@shutemov.name>
      Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Miaohe Lin <linmiaohe@huawei.com>
      Cc: Mike Kravetz <mike.kravetz@oracle.com>
      Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
      Cc: Roland Scheidegger <sroland@vmware.com>
      Cc: VMware Graphics <linux-graphics-maintainer@vmware.com>
      Cc: Wei Zhang <wzam@amazon.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      97a7e473
    • Peter Xu's avatar
      hugetlb: break earlier in add_reservation_in_range() when we can · ca7e0457
      Peter Xu authored
      
      
      All the regions maintained in hugetlb reserved map is inclusive on "from"
      but exclusive on "to".  We can break earlier even if rg->from==t because
      it already means no possible intersection.
      
      This does not need a Fixes in all cases because when it happens
      (rg->from==t) we'll not break out of the loop while we should, however the
      next thing we'd do is still add the last file_region we'd need and quit
      the loop in the next round.  So this change is not a bugfix (since the old
      code should still run okay iiuc), but we'd better still touch it up to
      make it logically sane.
      
      Link: https://lkml.kernel.org/r/20210217233547.93892-3-peterx@redhat.com
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Reviewed-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Daniel Vetter <daniel@ffwll.ch>
      Cc: David Airlie <airlied@linux.ie>
      Cc: David Gibson <david@gibson.dropbear.id.au>
      Cc: Gal Pressman <galpress@amazon.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Jann Horn <jannh@google.com>
      Cc: Jason Gunthorpe <jgg@ziepe.ca>
      Cc: Kirill Shutemov <kirill@shutemov.name>
      Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
      Cc: Roland Scheidegger <sroland@vmware.com>
      Cc: VMware Graphics <linux-graphics-maintainer@vmware.com>
      Cc: Wei Zhang <wzam@amazon.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ca7e0457
    • Peter Xu's avatar
      hugetlb: dedup the code to add a new file_region · 2103cf9c
      Peter Xu authored
      
      
      Patch series "mm/hugetlb: Early cow on fork, and a few cleanups", v5.
      
      As reported by Gal [1], we still miss the code clip to handle early cow
      for hugetlb case, which is true.  Again, it still feels odd to fork()
      after using a few huge pages, especially if they're privately mapped to
      me..  However I do agree with Gal and Jason in that we should still have
      that since that'll complete the early cow on fork effort at least, and
      it'll still fix issues where buffers are not well under control and not
      easy to apply MADV_DONTFORK.
      
      The first two patches (1-2) are some cleanups I noticed when reading into
      the hugetlb reserve map code.  I think it's good to have but they're not
      necessary for fixing the fork issue.
      
      The last two patches (3-4) are the real fix.
      
      I tested this with a fork() after some vfio-pci assignment, so I'm pretty
      sure the page copy path could trigger well (page will be accounted right
      after the fork()), but I didn't do data check since the card I assigned is
      some random nic.
      
        https://github.com/xzpeter/linux/tree/fork-cow-pin-huge
      
      [1] https://lore.kernel.org/lkml/27564187-4a08-f187-5a84-3df50009f6ca@amazon.com/
      
      Introduce hugetlb_resv_map_add() helper to add a new file_region rather
      than duplication the similar code twice in add_reservation_in_range().
      
      Link: https://lkml.kernel.org/r/20210217233547.93892-1-peterx@redhat.com
      Link: https://lkml.kernel.org/r/20210217233547.93892-2-peterx@redhat.com
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Reviewed-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
      Cc: Gal Pressman <galpress@amazon.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Wei Zhang <wzam@amazon.com>
      Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Gibson <david@gibson.dropbear.id.au>
      Cc: Jason Gunthorpe <jgg@ziepe.ca>
      Cc: Jann Horn <jannh@google.com>
      Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
      Cc: Kirill Shutemov <kirill@shutemov.name>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Daniel Vetter <daniel@ffwll.ch>
      Cc: David Airlie <airlied@linux.ie>
      Cc: Roland Scheidegger <sroland@vmware.com>
      Cc: VMware Graphics <linux-graphics-maintainer@vmware.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      2103cf9c
    • Fenghua Yu's avatar
      mm/fork: clear PASID for new mm · 82e69a12
      Fenghua Yu authored
      
      
      When a new mm is created, its PASID should be cleared, i.e.  the PASID is
      initialized to its init state 0 on both ARM and X86.
      
      This patch was part of the series introducing mm->pasid, but got lost
      along the way [1].  It still makes sense to have it, because each address
      space has a different PASID.  And the IOMMU code in
      iommu_sva_alloc_pasid() expects the pasid field of a new mm struct to be
      cleared.
      
      [1] https://lore.kernel.org/linux-iommu/YDgh53AcQHT+T3L0@otcwcpicx3.sc.intel.com/
      
      Link: https://lkml.kernel.org/r/20210302103837.2562625-1-jean-philippe@linaro.org
      Signed-off-by: default avatarFenghua Yu <fenghua.yu@intel.com>
      Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe@linaro.org>
      Reviewed-by: default avatarTony Luck <tony.luck@intel.com>
      Cc: Jacob Pan <jacob.jun.pan@intel.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      82e69a12
    • Mike Rapoport's avatar
      mm/page_alloc.c: refactor initialization of struct page for holes in memory layout · 0740a50b
      Mike Rapoport authored
      There could be struct pages that are not backed by actual physical memory.
      This can happen when the actual memory bank is not a multiple of
      SECTION_SIZE or when an architecture does not register memory holes
      reserved by the firmware as memblock.memory.
      
      Such pages are currently initialized using init_unavailable_mem() function
      that iterates through PFNs in holes in memblock.memory and if there is a
      struct page corresponding to a PFN, the fields of this page are set to
      default values and it is marked as Reserved.
      
      init_unavailable_mem() does not take into account zone and node the page
      belongs to and sets both zone and node links in struct page to zero.
      
      Before commit 73a6e474 ("mm: memmap_init: iterate over memblock
      regions rather that check each PFN") the holes inside a zone were
      re-initialized during memmap_init() and got their zone/node links right.
      However, after that commit nothing updates the struct pages representing
      such holes.
      
      On a system that has firmware reserved holes in a zone above ZONE_DMA, for
      instance in a configuration below:
      
      	# grep -A1 E820 /proc/iomem
      	7a17b000-7a216fff : Unknown E820 type
      	7a217000-7bffffff : System RAM
      
      unset zone link in struct page will trigger
      
      	VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page);
      
      in set_pfnblock_flags_mask() when called with a struct page from a range
      other than E820_TYPE_RAM because there are pages in the range of
      ZONE_DMA32 but the unset zone link in struct page makes them appear as a
      part of ZONE_DMA.
      
      Interleave initialization of the unavailable pages with the normal
      initialization of memory map, so that zone and node information will be
      properly set on struct pages that are not backed by the actual memory.
      
      With this change the pages for holes inside a zone will get proper
      zone/node links and the pages that are not spanned by any node will get
      links to the adjacent zone/node.  The holes between nodes will be
      prepended to the zone/node above the hole and the trailing pages in the
      last section that will be appended to the zone/node below.
      
      [akpm@linux-foundation.org: don't initialize static to zero, use %llu for u64]
      
      Link: https://lkml.kernel.org/r/20210225224351.7356-2-rppt@kernel.org
      Fixes: 73a6e474
      
       ("mm: memmap_init: iterate over memblock regions rather that check each PFN")
      Signed-off-by: default avatarMike Rapoport <rppt@linux.ibm.com>
      Reported-by: default avatarQian Cai <cai@lca.pw>
      Reported-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
      Reviewed-by: default avatarBaoquan He <bhe@redhat.com>
      Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Chris Wilson <chris@chris-wilson.co.uk>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Łukasz Majczak <lma@semihalf.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Mel Gorman <mgorman@suse.de>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: "Sarvela, Tomi P" <tomi.p.sarvela@intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      0740a50b
    • Masahiro Yamada's avatar
      init/Kconfig: make COMPILE_TEST depend on HAS_IOMEM · ea29b20a
      Masahiro Yamada authored
      I read the commit log of the following two:
      
      - bc083a64 ("init/Kconfig: make COMPILE_TEST depend on !UML")
      - 334ef6ed
      
       ("init/Kconfig: make COMPILE_TEST depend on !S390")
      
      Both are talking about HAS_IOMEM dependency missing in many drivers.
      
      So, 'depends on HAS_IOMEM' seems the direct, sensible solution to me.
      
      This does not change the behavior of UML. UML still cannot enable
      COMPILE_TEST because it does not provide HAS_IOMEM.
      
      The current dependency for S390 is too strong. Under the condition of
      CONFIG_PCI=y, S390 provides HAS_IOMEM, hence can enable COMPILE_TEST.
      
      I also removed the meaningless 'default n'.
      
      Link: https://lkml.kernel.org/r/20210224140809.1067582-1-masahiroy@kernel.org
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Cc: Heiko Carstens <hca@linux.ibm.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: Arnd Bergmann <arnd@kernel.org>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: KP Singh <kpsingh@google.com>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Quentin Perret <qperret@google.com>
      Cc: Valentin Schneider <valentin.schneider@arm.com>
      Cc: "Enrico Weigelt, metux IT consult" <lkml@metux.net>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ea29b20a
    • Arnd Bergmann's avatar
      stop_machine: mark helpers __always_inline · cbf78d85
      Arnd Bergmann authored
      With clang-13, some functions only get partially inlined, with a
      specialized version referring to a global variable.  This triggers a
      harmless build-time check for the intel-rng driver:
      
      WARNING: modpost: drivers/char/hw_random/intel-rng.o(.text+0xe): Section mismatch in reference from the function stop_machine() to the function .init.text:intel_rng_hw_init()
      The function stop_machine() references
      the function __init intel_rng_hw_init().
      This is often because stop_machine lacks a __init
      annotation or the annotation of intel_rng_hw_init is wrong.
      
      In this instance, an easy workaround is to force the stop_machine()
      function to be inline, along with related interfaces that did not show the
      same behavior at the moment, but theoretically could.
      
      The combination of the two patches listed below triggers the behavior in
      clang-13, but individually these commits are correct.
      
      Link: https://lkml.kernel.org/r/20210225130153.1956990-1-arnd@kernel.org
      Fixes: fe5595c0 ("stop_machine: Provide stop_machine_cpuslocked()")
      Fixes: ee527cd3
      
       ("Use stop_machine_run in the Intel RNG driver")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
      Cc: "Paul E. McKenney" <paulmck@kernel.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Prarit Bhargava <prarit@redhat.com>
      Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Valentin Schneider <valentin.schneider@arm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      cbf78d85
    • Arnd Bergmann's avatar
      memblock: fix section mismatch warning · 34dc2efb
      Arnd Bergmann authored
      The inlining logic in clang-13 is rewritten to often not inline some
      functions that were inlined by all earlier compilers.
      
      In case of the memblock interfaces, this exposed a harmless bug of a
      missing __init annotation:
      
      WARNING: modpost: vmlinux.o(.text+0x507c0a): Section mismatch in reference from the function memblock_bottom_up() to the variable .meminit.data:memblock
      The function memblock_bottom_up() references
      the variable __meminitdata memblock.
      This is often because memblock_bottom_up lacks a __meminitdata
      annotation or the annotation of memblock is wrong.
      
      Interestingly, these annotations were present originally, but got removed
      with the explanation that the __init annotation prevents the function from
      getting inlined.  I checked this again and found that while this is the
      case with clang, gcc (version 7 through 10, did not test others) does
      inline the functions regardless.
      
      As the previous change was apparently intended to help the clang builds,
      reverting it to help the newer clang versions seems appropriate as well.
      gcc builds don't seem to care either way.
      
      Link: https://lkml.kernel.org/r/20210225133808.2188581-1-arnd@kernel.org
      Fixes: 5bdba520 ("mm: memblock: drop __init from memblock functions to make it inline")
      Reference: 2cfb3665
      
       ("include/linux/memblock.h: add __init to memblock_set_bottom_up()")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
      Reviewed-by: default avatarMike Rapoport <rppt@linux.ibm.com>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Faiyaz Mohammed <faiyazm@codeaurora.org>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
      Cc: Aslan Bakirov <aslan@fb.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      34dc2efb
  2. Mar 12, 2021
    • Linus Torvalds's avatar
      Merge tag 'drm-fixes-2021-03-12-1' of git://anongit.freedesktop.org/drm/drm · f78d76e7
      Linus Torvalds authored
      Pull drm fixes from Dave Airlie:
       "Regular fixes for rc3. The i915 pull was based on the rc1 tag so I
        just cherry-picked the single fix from there to avoid it. The misc and
        amd trees seem to be on okay bases.
      
        It's a bunch of fixes across the tree, amdgpu has most of them a few
        ttm fixes around qxl, and nouveau.
      
        core:
         - Clear holes when converting compat ioctl's between 32-bits and
           64-bits.
      
        docs:
         - Use gitlab for drm bugzilla now.
      
        ttm:
         - Fix ttm page pool accounting.
      
        fbdev:
         - Fix oops in drm_fbdev_cleanup()
      
        shmem:
         - Assorted fixes for shmem helpers.
      
        qxl:
         - unpin qxl bos created as pinned when freeing them, and make ttm
           only warn once on this behavior.
         - Zero head.surface_id correctly in qxl.
      
        atyfb:
         - Use LCD management for atyfb on PPC_MAC.
      
        meson:
         - Shutdown kms poll helper in meson correctly.
      
        nouveau:
         - fix regression in bo syncing
      
        i915:
         - Wedge the GPU if command parser setup fails
      
        amdgpu:
         - Fix aux backlight control
         - Add a backlight override parameter
         - Various display fixes
         - PCIe DPM fix for vega
         - Polaris watermark fixes
         - Additional S0ix fix
      
        radeon:
         - Fix GEM regression
         - Fix AGP dependency handling"
      
      * tag 'drm-fixes-2021-03-12-1' of git://anongit.freedesktop.org/drm/drm: (33 commits)
        drm/nouveau: fix dma syncing for loops (v2)
        drm/i915: Wedge the GPU if command parser setup fails
        drm/compat: Clear bounce structures
        drm/shmem-helpers: vunmap: Don't put pages for dma-buf
        drm: meson_drv add shutdown function
        drm/shmem-helper: Don't remove the offset in vm_area_struct pgoff
        drm/shmem-helper: Check for purged buffers in fault handler
        qxl: Fix uninitialised struct field head.surface_id
        drm/ttm: Fix TTM page pool accounting
        drm/ttm: soften TTM warnings
        drm: Use USB controller's DMA mask when importing dmabufs
        MAINTAINERS: update drm bug reporting URL
        fbdev: atyfb: use LCD management functions for PPC_PMAC also
        fbdev: atyfb: always declare aty_{ld,st}_lcd()
        drm/qxl: fix lockdep issue in qxl_alloc_release_reserved
        drm/qxl: unpin release objects
        drm/fb-helper: only unmap if buffer not null
        drm/amdgpu: fix S0ix handling when the CONFIG_AMD_PMC=m
        drm/radeon: fix AGP dependency
        drm/radeon: also init GEM funcs in radeon_gem_prime_import_sg_table
        ...
      f78d76e7
    • Dave Airlie's avatar
      drm/nouveau: fix dma syncing for loops (v2) · 4042160c
      Dave Airlie authored
      The index variable should only be increased in one place.
      
      Noticed this while trying to track down another oops.
      
      v2: use while loop.
      
      Fixes: f295c8cf
      
       ("drm/nouveau: fix dma syncing warning with debugging on.")
      Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
      Reviewed-by: default avatarMichael J. Ruhl <michael.j.ruhl@intel.com>
      Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210311043527.5376-1-airlied@gmail.com
      4042160c
    • Tvrtko Ursulin's avatar
      drm/i915: Wedge the GPU if command parser setup fails · a829f033
      Tvrtko Ursulin authored
      Commit 311a50e7
      
       ("drm/i915: Add support for mandatory cmdparsing")
      introduced mandatory command parsing but setup failures were not
      translated into wedging the GPU which was probably the intent.
      
      Possible errors come in two categories. Either the sanity check on
      internal tables has failed, which should be caught in CI unless an
      affected platform would be missed in testing; or memory allocation failure
      happened during driver load, which should be extremely unlikely but for
      correctness should still be handled.
      
      v2:
       * Tidy coding style. (Chris)
      
      [airlied: cherry-picked to avoid rc1 base]
      Signed-off-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
      Fixes: 311a50e7
      
       ("drm/i915: Add support for mandatory cmdparsing")
      Cc: Jon Bloomfield <jon.bloomfield@intel.com>
      Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
      Cc: Chris Wilson <chris.p.wilson@intel.com>
      Reviewed-by: default avatarChris Wilson <chris.p.wilson@intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210302114213.1102223-1-tvrtko.ursulin@linux.intel.com
      (cherry picked from commit 5a1a659762d35a6dc51047c9127c011303c77b7f)
      Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
      Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
      a829f033
    • Dave Airlie's avatar
      Merge tag 'amd-drm-fixes-5.12-2021-03-10' of... · fb198483
      Dave Airlie authored
      
      Merge tag 'amd-drm-fixes-5.12-2021-03-10' of https://gitlab.freedesktop.org/agd5f/linux into drm-fixes
      
      amd-drm-fixes-5.12-2021-03-10:
      
      amdgpu:
      - Fix aux backlight control
      - Add a backlight override parameter
      - Various display fixes
      - PCIe DPM fix for vega
      - Polaris watermark fixes
      - Additional S0ix fix
      
      radeon:
      - Fix GEM regression
      - Fix AGP dependency handling
      
      Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
      From: Alex Deucher <alexander.deucher@amd.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210310221141.3974-1-alexander.deucher@amd.com
      fb198483
    • Dave Airlie's avatar
      Merge tag 'drm-misc-fixes-2021-03-11' of git://anongit.freedesktop.org/drm/drm-misc into drm-fixes · e0da9686
      Dave Airlie authored
      
      
      drm-misc-fixes for rc3, rebased on rc2:
      - Fix oops in drm_fbdev_cleanup()
      - unpin qxl bos created as pinned when freeing them,
        and make ttm only warn once on this behavior.
      - Use LCD management for atyfb on PPC_MAC.
      - Use gitlab for drm bugzilla now.
      - Fix ttm page pool accounting.
      - Zero head.surface_id correctly in qxl.
      - Assorted fixes for shmem helpers.
      - Shutdown kms poll helper in meson correctly.
      - Clear holes when converting compat ioctl's between 32-bits and 64-bits.
      
      Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
      
      From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/4606f08e-d0e8-c543-5e96-cee2fd728a41@linux.intel.com
      e0da9686
    • Linus Torvalds's avatar
      Merge tag 'media/v5.12-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media · 28806e4d
      Linus Torvalds authored
      Pull media fixes from Mauro Carvalho Chehab:
       "A couple of fixes:
      
         - fix a build issue with CEC
      
         - fix a deadlock at usbtv driver
      
         - fix some null pointer address issues at vsp1 driver
      
         - fix a wrong bitmap setting at rkisp1 driver"
      
      * tag 'media/v5.12-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media:
        media: rkisp1: params: fix wrong bits settings
        media: v4l: vsp1: Fix uif null pointer access
        media: v4l: vsp1: Fix bru null pointer access
        media: usbtv: Fix deadlock on suspend
        media: rc: compile rc-cec.c into rc-core
      28806e4d
  3. Mar 11, 2021
    • Dafna Hirschfeld's avatar
      media: rkisp1: params: fix wrong bits settings · 2025a48c
      Dafna Hirschfeld authored
      The histogram mode is set using 'rkisp1_params_set_bits'.
      Only the bits of the mode should be the value argument for
      that function. Otherwise bits outside the mode mask are
      turned on which is not what was intended.
      
      Fixes: bae1155c
      
       ("media: staging: rkisp1: add output device for parameters")
      Signed-off-by: default avatarDafna Hirschfeld <dafna.hirschfeld@collabora.com>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      2025a48c
    • Biju Das's avatar
      media: v4l: vsp1: Fix uif null pointer access · 6732f313
      Biju Das authored
      RZ/G2L SoC has no UIF. This patch fixes null pointer access, when UIF
      module is not used.
      
      Fixes: 5e824f98
      
      ("media: v4l: vsp1: Integrate DISCOM in display pipeline")
      Signed-off-by: default avatarBiju Das <biju.das.jz@bp.renesas.com>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      6732f313
    • Biju Das's avatar
      media: v4l: vsp1: Fix bru null pointer access · ac8d82f5
      Biju Das authored
      RZ/G2L SoC has only BRS. This patch fixes null pointer access,when only
      BRS is enabled.
      
      Fixes: cbb7fa49
      
      ("media: v4l: vsp1: Rename BRU to BRx")
      Signed-off-by: default avatarBiju Das <biju.das.jz@bp.renesas.com>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      ac8d82f5
    • Maxim Mikityanskiy's avatar
      media: usbtv: Fix deadlock on suspend · 8a7e27fd
      Maxim Mikityanskiy authored
      usbtv doesn't support power management, so on system suspend the
      .disconnect callback of the driver is called. The teardown sequence
      includes a call to snd_card_free. Its implementation waits until the
      refcount of the sound card device drops to zero, however, if its file is
      open, snd_card_file_add takes a reference, which can't be dropped during
      the suspend, because the userspace processes are already frozen at this
      point. snd_card_free waits for completion forever, leading to a hang on
      suspend.
      
      This commit fixes this deadlock condition by replacing snd_card_free
      with snd_card_free_when_closed, that doesn't wait until all references
      are released, allowing suspend to progress.
      
      Fixes: 63ddf68d
      
       ("[media] usbtv: add audio support")
      Signed-off-by: default avatarMaxim Mikityanskiy <maxtram95@gmail.com>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      8a7e27fd
    • Hans Verkuil's avatar
      media: rc: compile rc-cec.c into rc-core · f09f9f93
      Hans Verkuil authored
      
      
      The rc-cec keymap is unusual in that it can't be built as a module,
      instead it is registered directly in rc-main.c if CONFIG_MEDIA_CEC_RC
      is set. This is because it can be called from drm_dp_cec_set_edid() via
      cec_register_adapter() in an asynchronous context, and it is not
      allowed to use request_module() to load rc-cec.ko in that case. Trying to
      do so results in a 'WARN_ON_ONCE(wait && current_is_async())'.
      
      Since this keymap is only used if CONFIG_MEDIA_CEC_RC is set, we
      just compile this keymap into the rc-core module and never as a
      separate module.
      
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Fixes: 2c6d1fff
      
       (drm: add support for DisplayPort CEC-Tunneling-over-AUX)
      Reported-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarSean Young <sean@mess.org>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      f09f9f93
    • Daniel Vetter's avatar
      drm/compat: Clear bounce structures · de066e11
      Daniel Vetter authored
      
      
      Some of them have gaps, or fields we don't clear. Native ioctl code
      does full copies plus zero-extends on size mismatch, so nothing can
      leak. But compat is more hand-rolled so need to be careful.
      
      None of these matter for performance, so just memset.
      
      Also I didn't fix up the CONFIG_DRM_LEGACY or CONFIG_DRM_AGP ioctl, those
      are security holes anyway.
      
      Acked-by: default avatarMaxime Ripard <mripard@kernel.org>
      Reported-by: syzbot+620cf21140fc7e772a5d@syzkaller.appspotmail.com # vblank ioctl
      Cc: syzbot+620cf21140fc7e772a5d@syzkaller.appspotmail.com
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210222100643.400935-1-daniel.vetter@ffwll.ch
      (cherry picked from commit e926c474
      
      )
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      de066e11
    • Noralf Trønnes's avatar
      drm/shmem-helpers: vunmap: Don't put pages for dma-buf · 64e194e2
      Noralf Trønnes authored
      dma-buf importing was reworked in commit 7d2cd72a
      
      
      ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit
      drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and
      drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages()
      unconditionally. Now without the use count set, put pages is called also
      on dma-bufs. Fix this by only putting pages if it's not imported.
      
      Signed-off-by: default avatarNoralf Trønnes <noralf@tronnes.org>
      Fixes: 7d2cd72a
      
       ("drm/shmem-helpers: Simplify dma-buf importing")
      Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
      Cc: Thomas Zimmermann <tzimmermann@suse.de>
      Acked-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Tested-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210219122203.51130-1-noralf@tronnes.org
      (cherry picked from commit cdea7251
      
      )
      Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      64e194e2
    • Artem Lapkin's avatar
      drm: meson_drv add shutdown function · fa0c16ca
      Artem Lapkin authored
      Problem: random stucks on reboot stage about 1/20 stuck/reboots
      // debug kernel log
      [    4.496660] reboot: kernel restart prepare CMD:(null)
      [    4.498114] meson_ee_pwrc c883c000.system-controller:power-controller: shutdown begin
      [    4.503949] meson_ee_pwrc c883c000.system-controller:power-controller: shutdown domain 0:VPU...
      ...STUCK...
      
      Solution: add shutdown function to meson_drm driver
      // debug kernel log
      [    5.231896] reboot: kernel restart prepare CMD:(null)
      [    5.246135] [drm:meson_drv_shutdown]
      ...
      [    5.259271] meson_ee_pwrc c883c000.system-controller:power-controller: shutdown begin
      [    5.274688] meson_ee_pwrc c883c000.system-controller:power-controller: shutdown domain 0:VPU...
      [    5.338331] reboot: Restarting system
      [    5.358293] psci: PSCI_0_2_FN_SYSTEM_RESET reboot_mode:0 cmd:(null)
      bl31 reboot reason: 0xd
      bl31 reboot reason: 0x0
      system cmd  1.
      ...REBOOT...
      
      Tested: on VIM1 VIM2 VIM3 VIM3L khadas sbcs - 1000+ successful reboots
      and Odroid boards, WeTek Play2 (GXBB)
      
      Fixes: bbbe775e
      
       ("drm: Add support for Amlogic Meson Graphic Controller")
      Signed-off-by: default avatarArtem Lapkin <art@khadas.com>
      Tested-by: default avatarChristian Hewitt <christianshewitt@gmail.com>
      Acked-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
      Acked-by: default avatarKevin Hilman <khilman@baylibre.com>
      Signed-off-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210302042202.3728113-1-art@khadas.com
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      fa0c16ca
    • Neil Roberts's avatar
      drm/shmem-helper: Don't remove the offset in vm_area_struct pgoff · 11d5a474
      Neil Roberts authored
      When mmapping the shmem, it would previously adjust the pgoff in the
      vm_area_struct to remove the fake offset that is added to be able to
      identify the buffer. This patch removes the adjustment and makes the
      fault handler use the vm_fault address to calculate the page offset
      instead. Although using this address is apparently discouraged, several
      DRM drivers seem to be doing it anyway.
      
      The problem with removing the pgoff is that it prevents
      drm_vma_node_unmap from working because that searches the mapping tree
      by address. That doesn't work because all of the mappings are at offset
      0. drm_vma_node_unmap is being used by the shmem helpers when purging
      the buffer.
      
      This fixes a bug in Panfrost which is using drm_gem_shmem_purge. Without
      this the mapping for the purged buffer can still be accessed which might
      mean it would access random pages from other buffers
      
      v2: Don't check whether the unsigned page_offset is less than 0.
      
      Cc: stable@vger.kernel.org
      Fixes: 17acb9f3
      
       ("drm/shmem: Add madvise state and purge helpers")
      Signed-off-by: default avatarNeil Roberts <nroberts@igalia.com>
      Reviewed-by: default avatarSteven Price <steven.price@arm.com>
      Signed-off-by: default avatarSteven Price <steven.price@arm.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210223155125.199577-3-nroberts@igalia.com
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      11d5a474
    • Neil Roberts's avatar
      drm/shmem-helper: Check for purged buffers in fault handler · d611b4a0
      Neil Roberts authored
      When a buffer is madvised as not needed and then purged, any attempts to
      access the buffer from user-space should cause a bus fault. This patch
      adds a check for that.
      
      Cc: stable@vger.kernel.org
      Fixes: 17acb9f3
      
       ("drm/shmem: Add madvise state and purge helpers")
      Signed-off-by: default avatarNeil Roberts <nroberts@igalia.com>
      Reviewed-by: default avatarSteven Price <steven.price@arm.com>
      Signed-off-by: default avatarSteven Price <steven.price@arm.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210223155125.199577-2-nroberts@igalia.com
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      d611b4a0
    • Colin Ian King's avatar
      qxl: Fix uninitialised struct field head.surface_id · 738acd49
      Colin Ian King authored
      The surface_id struct field in head is not being initialized and
      static analysis warns that this is being passed through to
      dev->monitors_config->heads[i] on an assignment. Clear up this
      warning by initializing it to zero.
      
      Addresses-Coverity: ("Uninitialized scalar variable")
      Fixes: a6d3c4d7
      
       ("qxl: hook monitors_config updates into crtc, not encoder.")
      Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
      Link: http://patchwork.freedesktop.org/patch/msgid/20210304094928.2280722-1-colin.king@canonical.com
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      738acd49
    • Anthony DeRossi's avatar
      drm/ttm: Fix TTM page pool accounting · ca63d76f
      Anthony DeRossi authored
      Freed pages are not subtracted from the allocated_pages counter in
      ttm_pool_type_fini(), causing a leak in the count on device removal.
      The next shrinker invocation loops forever trying to free pages that are
      no longer in the pool:
      
        rcu: INFO: rcu_sched self-detected stall on CPU
        rcu:  3-....: (9998 ticks this GP) idle=54e/1/0x4000000000000000 softirq=434857/434857 fqs=2237
          (t=10001 jiffies g=2194533 q=49211)
        NMI backtrace for cpu 3
        CPU: 3 PID: 1034 Comm: kswapd0 Tainted: P           O      5.11.0-com #1
        Hardware name: System manufacturer System Product Name/PRIME X570-PRO, BIOS 1405 11/19/2019
        Call Trace:
         <IRQ>
         ...
         </IRQ>
         sysvec_apic_timer_interrupt+0x77/0x80
         asm_sysvec_apic_timer_interrupt+0x12/0x20
        RIP: 0010:mutex_unlock+0x16/0x20
        Code: e7 48 8b 70 10 e8 7a 53 77 ff eb aa e8 43 6c ff ff 0f 1f 00 65 48 8b 14 25 00 6d 01 00 31 c9 48 89 d0 f0 48 0f b1 0f 48 39 c2 <74> 05 e9 e3 fe ff ff c3 66 90 48 8b 47 20 48 85 c0 74 0f 8b 50 10
        RSP: 0018:ffffbdb840797be8 EFLAGS: 00000246
        RAX: ffff9ff445a41c00 RBX: ffffffffc02a9ef8 RCX: 0000000000000000
        RDX: ffff9ff445a41c00 RSI: ffffbdb840797c78 RDI: ffffffffc02a9ac0
        RBP: 0000000000000080 R08: 0000000000000000 R09: ffffbdb840797c80
        R10: 0000000000000000 R11: fffffffffffffff5 R12: 0000000000000000
        R13: 0000000000000000 R14: 0000000000000084 R15: ffffffffc02a9a60
         ttm_pool_shrink+0x7d/0x90 [ttm]
         ttm_pool_shrinker_scan+0x5/0x20 [ttm]
         do_shrink_slab+0x13a/0x1a0
      ...
      
      debugfs shows the incorrect total:
      
        $ cat /sys/kernel/debug/dri/0/ttm_page_pool
                  --- 0--- --- 1--- --- 2--- --- 3--- --- 4--- --- 5--- --- 6--- --- 7--- --- 8--- --- 9--- ---10---
        wc      :        0        0        0        0        0        0        0        0        0        0        0
        uc      :        0        0        0        0        0        0        0        0        0        0        0
        wc 32   :        0        0        0        0        0        0        0        0        0        0        0
        uc 32   :        0        0        0        0        0        0        0        0        0        0        0
        DMA uc  :        0        0        0        0        0        0        0        0        0        0        0
        DMA wc  :        0        0        0        0        0        0        0        0        0        0        0
        DMA     :        0        0        0        0        0        0        0        0        0        0        0
      
        total   :     3029 of  8244261
      
      Using ttm_pool_type_take() to remove pages from the pool before freeing
      them correctly accounts for the freed pages.
      
      Fixes: d099fc8f
      
       ("drm/ttm: new TT backend allocation pool v3")
      Signed-off-by: default avatarAnthony DeRossi <ajderossi@gmail.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210303011723.22512-1-ajderossi@gmail.com
      Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
      Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      ca63d76f
    • Christian König's avatar
      drm/ttm: soften TTM warnings · d228f8d8
      Christian König authored
      
      
      QXL indeed unrefs pinned BOs and the warnings are spamming peoples log files.
      
      Make sure we warn only once until the QXL driver is fixed.
      
      Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
      References: https://lore.kernel.org/lkml/YD+eYcMMcdlXB8PY@alley/
      Link: https://patchwork.freedesktop.org/patch/422834/
      Reviewed-by: default avatarDaniel Vetter <daniel@ffwll.ch>
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      d228f8d8
    • Thomas Zimmermann's avatar
      drm: Use USB controller's DMA mask when importing dmabufs · 659ab7a4
      Thomas Zimmermann authored
      
      
      USB devices cannot perform DMA and hence have no dma_mask set in their
      device structure. Therefore importing dmabuf into a USB-based driver
      fails, which breaks joining and mirroring of display in X11.
      
      For USB devices, pick the associated USB controller as attachment device.
      This allows the DRM import helpers to perform the DMA setup. If the DMA
      controller does not support DMA transfers, we're out of luck and cannot
      import. Our current USB-based DRM drivers don't use DMA, so the actual
      DMA device is not important.
      
      Tested by joining/mirroring displays of udl and radeon under Gnome/X11.
      
      v8:
      	* release dmadev if device initialization fails (Noralf)
      	* fix commit description (Noralf)
      v7:
      	* fix use-before-init bug in gm12u320 (Dan)
      v6:
      	* implement workaround in DRM drivers and hold reference to
      	  DMA device while USB device is in use
      	* remove dev_is_usb() (Greg)
      	* collapse USB helper into usb_intf_get_dma_device() (Alan)
      	* integrate Daniel's TODO statement (Daniel)
      	* fix typos (Greg)
      v5:
      	* provide a helper for USB interfaces (Alan)
      	* add FIXME item to documentation and TODO list (Daniel)
      v4:
      	* implement workaround with USB helper functions (Greg)
      	* use struct usb_device->bus->sysdev as DMA device (Takashi)
      v3:
      	* drop gem_create_object
      	* use DMA mask of USB controller, if any (Daniel, Christian, Noralf)
      v2:
      	* move fix to importer side (Christian, Daniel)
      	* update SHMEM and CMA helpers for new PRIME callbacks
      
      Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Fixes: 6eb0233e
      
       ("usb: don't inherity DMA properties for USB devices")
      Tested-by: default avatarPavel Machek <pavel@ucw.cz>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: default avatarChristian König <christian.koenig@amd.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Acked-by: default avatarNoralf Trønnes <noralf@tronnes.org>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: <stable@vger.kernel.org> # v5.10+
      Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210303133229.3288-1-tzimmermann@suse.de
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      659ab7a4
    • Pavel Turinský's avatar
      MAINTAINERS: update drm bug reporting URL · 301469c1
      Pavel Turinský authored
      
      
      The original bugzilla seems to be read-only now, linking to the gitlab
      for new bugs.
      
      Signed-off-by: default avatarPavel Turinský <ledoian@kam.mff.cuni.cz>
      Cc: trivial@kernel.org
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210228163658.54962-1-ledoian@kam.mff.cuni.cz
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      301469c1
    • Randy Dunlap's avatar
      fbdev: atyfb: use LCD management functions for PPC_PMAC also · b2664093
      Randy Dunlap authored
      
      
      Include PPC_PMAC in the configs that use aty_ld_lcd() and
      aty_st_lcd() implementations so that the PM code may work
      correctly for PPC_PMAC.
      
      Suggested-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: linux-fbdev@vger.kernel.org
      Cc: dri-devel@lists.freedesktop.org
      Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: David Airlie <airlied@linux.ie>
      Cc: Jani Nikula <jani.nikula@linux.intel.com>
      Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210226173008.18236-1-rdunlap@infradead.org
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      b2664093
    • Randy Dunlap's avatar
      fbdev: atyfb: always declare aty_{ld,st}_lcd() · 39a3898a
      Randy Dunlap authored
      The previously added stubs for aty_{ld,}st_lcd() make it
      so that these functions are used regardless of the config
      options that were guarding them, so remove the #ifdef/#endif
      lines and make their declarations always visible.
      This fixes build warnings that were reported by clang:
      
         drivers/video/fbdev/aty/atyfb_base.c:180:6: warning: no previous prototype for function 'aty_st_lcd' [-Wmissing-prototypes]
         void aty_st_lcd(int index, u32 val, const struct atyfb_par *par)
              ^
         drivers/video/fbdev/aty/atyfb_base.c:180:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
         void aty_st_lcd(int index, u32 val, const struct atyfb_par *par)
      
         drivers/video/fbdev/aty/atyfb_base.c:183:5: warning: no previous prototype for function 'aty_ld_lcd' [-Wmissing-prototypes]
         u32 aty_ld_lcd(int index, const struct atyfb_par *par)
             ^
         drivers/video/fbdev/aty/atyfb_base.c:183:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
         u32 aty_ld_lcd(int index, const struct atyfb_par *par)
      
      They should not be marked as static since they are used in
      mach64_ct.c.
      
      Fixes: bfa5782b
      
       ("fbdev: atyfb: add stubs for aty_{ld,st}_lcd()")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: linux-fbdev@vger.kernel.org
      Cc: dri-devel@lists.freedesktop.org
      Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: David Airlie <airlied@linux.ie>
      Cc: Jani Nikula <jani.nikula@linux.intel.com>
      Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210224215528.822-1-rdunlap@infradead.org
      Acked-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      39a3898a
    • Gerd Hoffmann's avatar
      drm/qxl: fix lockdep issue in qxl_alloc_release_reserved · e998d3c8
      Gerd Hoffmann authored
      Call qxl_bo_unpin (which does a reservation) without holding the
      release_mutex lock.  Fixes lockdep (correctly) warning on a possible
      deadlock.
      
      Fixes: e8dd3506
      
       ("drm/qxl: unpin release objects")
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      Acked-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Link: http://patchwork.freedesktop.org/patch/msgid/20210217123213.2199186-5-kraxel@redhat.com
      (cherry picked from commit 19089b76
      
      )
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      e998d3c8
    • Gerd Hoffmann's avatar
      drm/qxl: unpin release objects · e8dd3506
      Gerd Hoffmann authored
      
      
      Balances the qxl_create_bo(..., pinned=true, ...);
      call in qxl_release_bo_alloc().
      
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      Acked-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Link: http://patchwork.freedesktop.org/patch/msgid/20210204145712.1531203-5-kraxel@redhat.com
      (cherry picked from commit 65ffea3c
      
      )
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      e8dd3506
    • Tong Zhang's avatar
      drm/fb-helper: only unmap if buffer not null · 874a52f9
      Tong Zhang authored
      
      
      drm_fbdev_cleanup() can be called when fb_helper->buffer is null, hence
      fb_helper->buffer should be checked before calling
      drm_client_buffer_vunmap(). This buffer is also checked in
      drm_client_framebuffer_delete(), so we should also do the same thing for
      drm_client_buffer_vunmap().
      
      [  199.128742] RIP: 0010:drm_client_buffer_vunmap+0xd/0x20
      [  199.129031] Code: 43 18 48 8b 53 20 49 89 45 00 49 89 55 08 5b 44 89 e0 41 5c 41 5d 41 5e 5d
      c3 0f 1f 00 53 48 89 fb 48 8d 7f 10 e8 73 7d a1 ff <48> 8b 7b 10 48 8d 73 18 5b e9 75 53 fc ff 0
      f 1f 44 00 00 48 b8 00
      [  199.130041] RSP: 0018:ffff888103f3fc88 EFLAGS: 00010282
      [  199.130329] RAX: 0000000000000001 RBX: 0000000000000000 RCX: ffffffff8214d46d
      [  199.130733] RDX: 1ffffffff079c6b9 RSI: 0000000000000246 RDI: ffffffff83ce35c8
      [  199.131119] RBP: ffff888103d25458 R08: 0000000000000001 R09: fffffbfff0791761
      [  199.131505] R10: ffffffff83c8bb07 R11: fffffbfff0791760 R12: 0000000000000000
      [  199.131891] R13: ffff888103d25468 R14: ffff888103d25418 R15: ffff888103f18120
      [  199.132277] FS:  00007f36fdcbb6a0(0000) GS:ffff88815b400000(0000) knlGS:0000000000000000
      [  199.132721] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [  199.133033] CR2: 0000000000000010 CR3: 0000000103d26000 CR4: 00000000000006f0
      [  199.133420] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [  199.133807] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      [  199.134195] Call Trace:
      [  199.134333]  drm_fbdev_cleanup+0x179/0x1a0
      [  199.134562]  drm_fbdev_client_unregister+0x2b/0x40
      [  199.134828]  drm_client_dev_unregister+0xa8/0x180
      [  199.135088]  drm_dev_unregister+0x61/0x110
      [  199.135315]  mgag200_pci_remove+0x38/0x52 [mgag200]
      [  199.135586]  pci_device_remove+0x62/0xe0
      [  199.135806]  device_release_driver_internal+0x148/0x270
      [  199.136094]  driver_detach+0x76/0xe0
      [  199.136294]  bus_remove_driver+0x7e/0x100
      [  199.136521]  pci_unregister_driver+0x28/0xf0
      [  199.136759]  __x64_sys_delete_module+0x268/0x300
      [  199.137016]  ? __ia32_sys_delete_module+0x300/0x300
      [  199.137285]  ? call_rcu+0x3e4/0x580
      [  199.137481]  ? fpregs_assert_state_consistent+0x4d/0x60
      [  199.137767]  ? exit_to_user_mode_prepare+0x2f/0x130
      [  199.138037]  do_syscall_64+0x33/0x40
      [  199.138237]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  199.138517] RIP: 0033:0x7f36fdc3dcf7
      
      Signed-off-by: default avatarTong Zhang <ztong0001@gmail.com>
      Fixes: 763aea17
      
       ("drm/fb-helper: Unmap client buffer during shutdown")
      Cc: Thomas Zimmermann <tzimmermann@suse.de>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: Maxime Ripard <mripard@kernel.org>
      Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
      Cc: David Airlie <airlied@linux.ie>
      Cc: Daniel Vetter <daniel@ffwll.ch>
      Cc: dri-devel@lists.freedesktop.org
      Cc: <stable@vger.kernel.org> # v5.11+
      Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210228044625.171151-1-ztong0001@gmail.com
      Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      874a52f9