Skip to content
  1. Jul 28, 2021
    • Riccardo Mancini's avatar
      perf inject: Close inject.output on exit · 25af91a8
      Riccardo Mancini authored
      commit 02e6246f
      
       upstream.
      
      ASan reports a memory leak when running:
      
        # perf test "83: Zstd perf.data compression/decompression"
      
      which happens inside 'perf inject'.
      
      The bug is caused by inject.output never being closed.
      
      This patch adds the missing perf_data__close().
      
      Signed-off-by: default avatarRiccardo Mancini <rickyman7@gmail.com>
      Fixes: 6ef81c55
      
       ("perf session: Return error code for perf_session__new() function on failure")
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/c06f682afa964687367cf6e92a64ceb49aec76a5.1626343282.git.rickyman7@gmail.com
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      25af91a8
    • Robert Richter's avatar
      Documentation: Fix intiramfs script name · fb35426d
      Robert Richter authored
      commit 5e60f363 upstream.
      
      Documentation was not changed when renaming the script in commit
      80e715a0 ("initramfs: rename gen_initramfs_list.sh to
      gen_initramfs.sh"). Fixing this.
      
      Basically does:
      
       $ sed -i -e s/gen_initramfs_list.sh/gen_initramfs.sh/g $(git grep -l gen_initramfs_list.sh)
      
      Fixes: 80e715a0
      
       ("initramfs: rename gen_initramfs_list.sh to gen_initramfs.sh")
      Signed-off-by: default avatarRobert Richter <rrichter@amd.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fb35426d
    • Paul Blakey's avatar
      skbuff: Release nfct refcount on napi stolen or re-used skbs · 570341f1
      Paul Blakey authored
      commit 8550ff8d upstream.
      
      When multiple SKBs are merged to a new skb under napi GRO,
      or SKB is re-used by napi, if nfct was set for them in the
      driver, it will not be released while freeing their stolen
      head state or on re-use.
      
      Release nfct on napi's stolen or re-used SKBs, and
      in gro_list_prepare, check conntrack metadata diff.
      
      Fixes: 5c6b9460
      
       ("net/mlx5e: CT: Handle misses after executing CT action")
      Reviewed-by: default avatarRoi Dayan <roid@nvidia.com>
      Signed-off-by: default avatarPaul Blakey <paulb@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      570341f1
    • Mahesh Bandewar's avatar
      bonding: fix build issue · 31828ffd
      Mahesh Bandewar authored
      commit 5b69874f upstream.
      
      The commit 9a560550 (" bonding: Add struct bond_ipesc to manage SA") is causing
      following build error when XFRM is not selected in kernel config.
      
      lld: error: undefined symbol: xfrm_dev_state_flush
      >>> referenced by bond_main.c:3453 (drivers/net/bonding/bond_main.c:3453)
      >>>               net/bonding/bond_main.o:(bond_netdev_event) in archive drivers/built-in.a
      
      Fixes: 9a560550
      
       (" bonding: Add struct bond_ipesc to manage SA")
      Signed-off-by: default avatarMahesh Bandewar <maheshb@google.com>
      CC: Taehee Yoo <ap420073@gmail.com>
      CC: Jay Vosburgh <jay.vosburgh@canonical.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      31828ffd
    • Evan Quan's avatar
      PCI: Mark AMD Navi14 GPU ATS as broken · c9d97b7b
      Evan Quan authored
      commit e8946a53 upstream
      
      Observed unexpected GPU hang during runpm stress test on 0x7341 rev 0x00.
      Further debugging shows broken ATS is related.
      
      Disable ATS on this part.  Similar issues on other devices:
      
        a2da5d8c ("PCI: Mark AMD Raven iGPU ATS as broken in some platforms")
        45beb31d ("PCI: Mark AMD Navi10 GPU rev 0x00 ATS as broken")
        5e89cd30
      
       ("PCI: Mark AMD Navi14 GPU rev 0xc5 ATS as broken")
      
      Suggested-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Link: https://lore.kernel.org/r/20210602021255.939090-1-evan.quan@amd.com
      Signed-off-by: default avatarEvan Quan <evan.quan@amd.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: default avatarKrzysztof Wilczyński <kw@linux.com>
      Cc: stable@vger.kernel.org
      [sudip: adjust context]
      Signed-off-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c9d97b7b
    • Marek Behún's avatar
      net: dsa: mv88e6xxx: enable SerDes PCS register dump via ethtool -d on Topaz · f7ee3611
      Marek Behún authored
      commit 953b0dcb upstream.
      
      Commit bf3504ce
      
       ("net: dsa: mv88e6xxx: Add 6390 family PCS
      registers to ethtool -d") added support for dumping SerDes PCS registers
      via ethtool -d for Peridot.
      
      The same implementation is also valid for Topaz, but was not
      enabled at the time.
      
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Fixes: bf3504ce
      
       ("net: dsa: mv88e6xxx: Add 6390 family PCS registers to ethtool -d")
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f7ee3611
    • Marek Behún's avatar
      net: dsa: mv88e6xxx: enable SerDes RX stats for Topaz · 30f1d4d0
      Marek Behún authored
      commit a03b98d6 upstream.
      
      Commit 0df95287
      
       ("mv88e6xxx: Add serdes Rx statistics") added
      support for RX statistics on SerDes ports for Peridot.
      
      This same implementation is also valid for Topaz, but was not enabled
      at the time.
      
      We need to use the generic .serdes_get_lane() method instead of the
      Peridot specific one in the stats methods so that on Topaz the proper
      one is used.
      
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Fixes: 0df95287
      
       ("mv88e6xxx: Add serdes Rx statistics")
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      30f1d4d0
    • Likun Gao's avatar
      drm/amdgpu: update golden setting for sienna_cichlid · fc31b5be
      Likun Gao authored
      commit 3e94b596
      
       upstream.
      
      Update GFX golden setting for sienna_cichlid.
      
      Signed-off-by: default avatarLikun Gao <Likun.Gao@amd.com>
      Reviewed-by: default avatarHawking Zhang <Hawking.Zhang@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fc31b5be
    • Charles Baylis's avatar
      drm: Return -ENOTTY for non-drm ioctls · 69a603aa
      Charles Baylis authored
      commit 3abab27c
      
       upstream.
      
      drm: Return -ENOTTY for non-drm ioctls
      
      Return -ENOTTY from drm_ioctl() when userspace passes in a cmd number
      which doesn't relate to the drm subsystem.
      
      Glibc uses the TCGETS ioctl to implement isatty(), and without this
      change isatty() returns it incorrectly returns true for drm devices.
      
      To test run this command:
      $ if [ -t 0 ]; then echo is a tty; fi < /dev/dri/card0
      which shows "is a tty" without this patch.
      
      This may also modify memory which the userspace application is not
      expecting.
      
      Signed-off-by: default avatarCharles Baylis <cb-kernel@fishzet.co.uk>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/msgid/YPG3IBlzaMhfPqCr@stando.fishzet.co.uk
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      69a603aa
    • Adrian Hunter's avatar
      driver core: Prevent warning when removing a device link from unregistered consumer · 2831eeb7
      Adrian Hunter authored
      commit e64daad6 upstream.
      
      sysfs_remove_link() causes a warning if the parent directory does not
      exist. That can happen if the device link consumer has not been registered.
      So do not attempt sysfs_remove_link() in that case.
      
      Fixes: 287905e6
      
       ("driver core: Expose device link details in sysfs")
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: stable@vger.kernel.org # 5.9+
      Reviewed-by: default avatarRafael J. Wysocki <rafael@kernel.org>
      Link: https://lore.kernel.org/r/20210716114408.17320-2-adrian.hunter@intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2831eeb7
    • Greg Kroah-Hartman's avatar
      nds32: fix up stack guard gap · 0e759383
      Greg Kroah-Hartman authored
      commit c453db6c upstream.
      
      Commit 1be7107f
      
       ("mm: larger stack guard gap, between vmas") fixed
      up all architectures to deal with the stack guard gap.  But when nds32
      was added to the tree, it forgot to do the same thing.
      
      Resolve this by properly fixing up the nsd32's version of
      arch_get_unmapped_area()
      
      Cc: Nick Hu <nickhu@andestech.com>
      Cc: Greentime Hu <green.hu@gmail.com>
      Cc: Vincent Chen <deanbo422@gmail.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: Qiang Liu <cyruscyliu@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Reported-by: default avatariLifetruth <yixiaonn@gmail.com>
      Acked-by: default avatarHugh Dickins <hughd@google.com>
      Link: https://lore.kernel.org/r/20210629104024.2293615-1-gregkh@linuxfoundation.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0e759383
    • Jérôme Glisse's avatar
      misc: eeprom: at24: Always append device id even if label property is set. · 7497f4c9
      Jérôme Glisse authored
      commit c36748ac upstream.
      
      We need to append device id even if eeprom have a label property set as some
      platform can have multiple eeproms with same label and we can not register
      each of those with same label. Failing to register those eeproms trigger
      cascade failures on such platform (system is no longer working).
      
      This fix regression on such platform introduced with 4e302c3b
      
      
      
      Reported-by: default avatarAlexander Fomichev <fomichev.ru@gmail.com>
      Fixes: 4e302c3b
      
       ("misc: eeprom: at24: fix NVMEM name with custom AT24 device name")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJérôme Glisse <jglisse@redhat.com>
      Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7497f4c9
    • Ilya Dryomov's avatar
      rbd: always kick acquire on "acquired" and "released" notifications · 8571daac
      Ilya Dryomov authored
      commit 8798d070
      
       upstream.
      
      Skipping the "lock has been released" notification if the lock owner
      is not what we expect based on owner_cid can lead to I/O hangs.
      One example is our own notifications: because owner_cid is cleared
      in rbd_unlock(), when we get our own notification it is processed as
      unexpected/duplicate and maybe_kick_acquire() isn't called.  If a peer
      that requested the lock then doesn't go through with acquiring it,
      I/O requests that came in while the lock was being quiesced would
      be stalled until another I/O request is submitted and kicks acquire
      from rbd_img_exclusive_lock().
      
      This makes the comment in rbd_release_lock() actually true: prior to
      this change the canceled work was being requeued in response to the
      "lock has been acquired" notification from rbd_handle_acquired_lock().
      
      Cc: stable@vger.kernel.org # 5.3+
      Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
      Tested-by: default avatarRobin Geuze <robin.geuze@nl.team.blue>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8571daac
    • Ilya Dryomov's avatar
      rbd: don't hold lock_rwsem while running_list is being drained · 2f3731de
      Ilya Dryomov authored
      commit ed9eb710
      
       upstream.
      
      Currently rbd_quiesce_lock() holds lock_rwsem for read while blocking
      on releasing_wait completion.  On the I/O completion side, each image
      request also needs to take lock_rwsem for read.  Because rw_semaphore
      implementation doesn't allow new readers after a writer has indicated
      interest in the lock, this can result in a deadlock if something that
      needs to take lock_rwsem for write gets involved.  For example:
      
      1. watch error occurs
      2. rbd_watch_errcb() takes lock_rwsem for write, clears owner_cid and
         releases lock_rwsem
      3. after reestablishing the watch, rbd_reregister_watch() takes
         lock_rwsem for write and calls rbd_reacquire_lock()
      4. rbd_quiesce_lock() downgrades lock_rwsem to for read and blocks on
         releasing_wait until running_list becomes empty
      5. another watch error occurs
      6. rbd_watch_errcb() blocks trying to take lock_rwsem for write
      7. no in-flight image request can complete and delete itself from
         running_list because lock_rwsem won't be granted anymore
      
      A similar scenario can occur with "lock has been acquired" and "lock
      has been released" notification handers which also take lock_rwsem for
      write to update owner_cid.
      
      We don't actually get anything useful from sitting on lock_rwsem in
      rbd_quiesce_lock() -- owner_cid updates certainly don't need to be
      synchronized with.  In fact the whole owner_cid tracking logic could
      probably be removed from the kernel client because we don't support
      proxied maintenance operations.
      
      Cc: stable@vger.kernel.org # 5.3+
      URL: https://tracker.ceph.com/issues/42757
      Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
      Tested-by: default avatarRobin Geuze <robin.geuze@nl.team.blue>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2f3731de
    • Mike Kravetz's avatar
      hugetlbfs: fix mount mode command line processing · 92291fa2
      Mike Kravetz authored
      commit e0f7e2b2 upstream.
      
      In commit 32021982 ("hugetlbfs: Convert to fs_context") processing
      of the mount mode string was changed from match_octal() to fsparam_u32.
      
      This changed existing behavior as match_octal does not require octal
      values to have a '0' prefix, but fsparam_u32 does.
      
      Use fsparam_u32oct which provides the same behavior as match_octal.
      
      Link: https://lkml.kernel.org/r/20210721183326.102716-1-mike.kravetz@oracle.com
      Fixes: 32021982
      
       ("hugetlbfs: Convert to fs_context")
      Signed-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Reported-by: default avatarDennis Camera <bugs+kernel.org@dtnr.ch>
      Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Cc: David Howells <dhowells@redhat.com>
      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>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      92291fa2
    • Mike Rapoport's avatar
      memblock: make for_each_mem_range() traverse MEMBLOCK_HOTPLUG regions · 1a25c573
      Mike Rapoport authored
      commit 79e482e9 upstream.
      
      Commit b10d6bca ("arch, drivers: replace for_each_membock() with
      for_each_mem_range()") didn't take into account that when there is
      movable_node parameter in the kernel command line, for_each_mem_range()
      would skip ranges marked with MEMBLOCK_HOTPLUG.
      
      The page table setup code in POWER uses for_each_mem_range() to create
      the linear mapping of the physical memory and since the regions marked
      as MEMORY_HOTPLUG are skipped, they never make it to the linear map.
      
      A later access to the memory in those ranges will fail:
      
        BUG: Unable to handle kernel data access on write at 0xc000000400000000
        Faulting instruction address: 0xc00000000008a3c0
        Oops: Kernel access of bad area, sig: 11 [#1]
        LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=2048 NUMA pSeries
        Modules linked in:
        CPU: 0 PID: 53 Comm: kworker/u2:0 Not tainted 5.13.0 #7
        NIP:  c00000000008a3c0 LR: c0000000003c1ed8 CTR: 0000000000000040
        REGS: c000000008a57770 TRAP: 0300   Not tainted  (5.13.0)
        MSR:  8000000002009033 <SF,VEC,EE,ME,IR,DR,RI,LE>  CR: 84222202  XER: 20040000
        CFAR: c0000000003c1ed4 DAR: c000000400000000 DSISR: 42000000 IRQMASK: 0
        GPR00: c0000000003c1ed8 c000000008a57a10 c0000000019da700 c000000400000000
        GPR04: 0000000000000280 0000000000000180 0000000000000400 0000000000000200
        GPR08: 0000000000000100 0000000000000080 0000000000000040 0000000000000300
        GPR12: 0000000000000380 c000000001bc0000 c0000000001660c8 c000000006337e00
        GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
        GPR20: 0000000040000000 0000000020000000 c000000001a81990 c000000008c30000
        GPR24: c000000008c20000 c000000001a81998 000fffffffff0000 c000000001a819a0
        GPR28: c000000001a81908 c00c000001000000 c000000008c40000 c000000008a64680
        NIP clear_user_page+0x50/0x80
        LR __handle_mm_fault+0xc88/0x1910
        Call Trace:
          __handle_mm_fault+0xc44/0x1910 (unreliable)
          handle_mm_fault+0x130/0x2a0
          __get_user_pages+0x248/0x610
          __get_user_pages_remote+0x12c/0x3e0
          get_arg_page+0x54/0xf0
          copy_string_kernel+0x11c/0x210
          kernel_execve+0x16c/0x220
          call_usermodehelper_exec_async+0x1b0/0x2f0
          ret_from_kernel_thread+0x5c/0x70
        Instruction dump:
        79280fa4 79271764 79261f24 794ae8e2 7ca94214 7d683a14 7c893a14 7d893050
        7d4903a6 60000000 60000000 60000000 <7c001fec> 7c091fec 7c081fec 7c051fec
        ---[ end trace 490b8c67e6075e09 ]---
      
      Making for_each_mem_range() include MEMBLOCK_HOTPLUG regions in the
      traversal fixes this issue.
      
      Link: https://bugzilla.redhat.com/show_bug.cgi?id=1976100
      Link: https://lkml.kernel.org/r/20210712071132.20902-1-rppt@kernel.org
      Fixes: b10d6bca
      
       ("arch, drivers: replace for_each_membock() with for_each_mem_range()")
      Signed-off-by: default avatarMike Rapoport <rppt@linux.ibm.com>
      Tested-by: default avatarGreg Kurz <groug@kaod.org>
      Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: <stable@vger.kernel.org>	[5.10+]
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1a25c573
    • Peter Collingbourne's avatar
      userfaultfd: do not untag user pointers · 0b591c02
      Peter Collingbourne authored
      commit e71e2ace upstream.
      
      Patch series "userfaultfd: do not untag user pointers", v5.
      
      If a user program uses userfaultfd on ranges of heap memory, it may end
      up passing a tagged pointer to the kernel in the range.start field of
      the UFFDIO_REGISTER ioctl.  This can happen when using an MTE-capable
      allocator, or on Android if using the Tagged Pointers feature for MTE
      readiness [1].
      
      When a fault subsequently occurs, the tag is stripped from the fault
      address returned to the application in the fault.address field of struct
      uffd_msg.  However, from the application's perspective, the tagged
      address *is* the memory address, so if the application is unaware of
      memory tags, it may get confused by receiving an address that is, from
      its point of view, outside of the bounds of the allocation.  We observed
      this behavior in the kselftest for userfaultfd [2] but other
      applications could have the same problem.
      
      Address this by not untagging pointers passed to the userfaultfd ioctls.
      Instead, let the system call fail.  Also change the kselftest to use
      mmap so that it doesn't encounter this problem.
      
      [1] https://source.android.com/devices/tech/debug/tagged-pointers
      [2] tools/testing/selftests/vm/userfaultfd.c
      
      This patch (of 2):
      
      Do not untag pointers passed to the userfaultfd ioctls.  Instead, let
      the system call fail.  This will provide an early indication of problems
      with tag-unaware userspace code instead of letting the code get confused
      later, and is consistent with how we decided to handle brk/mmap/mremap
      in commit dcde2373 ("mm: Avoid creating virtual address aliases in
      brk()/mmap()/mremap()"), as well as being consistent with the existing
      tagged address ABI documentation relating to how ioctl arguments are
      handled.
      
      The code change is a revert of commit 7d032574 ("userfaultfd: untag
      user pointers") plus some fixups to some additional calls to
      validate_range that have appeared since then.
      
      [1] https://source.android.com/devices/tech/debug/tagged-pointers
      [2] tools/testing/selftests/vm/userfaultfd.c
      
      Link: https://lkml.kernel.org/r/20210714195437.118982-1-pcc@google.com
      Link: https://lkml.kernel.org/r/20210714195437.118982-2-pcc@google.com
      Link: https://linux-review.googlesource.com/id/I761aa9f0344454c482b83fcfcce547db0a25501b
      Fixes: 63f0c603
      
       ("arm64: Introduce prctl() options to control the tagged user addresses ABI")
      Signed-off-by: default avatarPeter Collingbourne <pcc@google.com>
      Reviewed-by: default avatarAndrey Konovalov <andreyknvl@gmail.com>
      Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Cc: Alistair Delva <adelva@google.com>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Dave Martin <Dave.Martin@arm.com>
      Cc: Evgenii Stepanov <eugenis@google.com>
      Cc: Lokesh Gidra <lokeshgidra@google.com>
      Cc: Mitch Phillips <mitchp@google.com>
      Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: William McVicker <willmcvicker@google.com>
      Cc: <stable@vger.kernel.org>	[5.4]
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0b591c02
    • Pavel Begunkov's avatar
      io_uring: remove double poll entry on arm failure · fca5343b
      Pavel Begunkov authored
      commit 46fee9ab upstream.
      
      __io_queue_proc() can enqueue both poll entries and still fail
      afterwards, so the callers trying to cancel it should also try to remove
      the second poll entry (if any).
      
      For example, it may leave the request alive referencing a io_uring
      context but not accessible for cancellation:
      
      [  282.599913][ T1620] task:iou-sqp-23145   state:D stack:28720 pid:23155 ppid:  8844 flags:0x00004004
      [  282.609927][ T1620] Call Trace:
      [  282.613711][ T1620]  __schedule+0x93a/0x26f0
      [  282.634647][ T1620]  schedule+0xd3/0x270
      [  282.638874][ T1620]  io_uring_cancel_generic+0x54d/0x890
      [  282.660346][ T1620]  io_sq_thread+0xaac/0x1250
      [  282.696394][ T1620]  ret_from_fork+0x1f/0x30
      
      Cc: stable@vger.kernel.org
      Fixes: 18bceab1
      
       ("io_uring: allow POLL_ADD with double poll_wait() users")
      Reported-and-tested-by: default avatar <syzbot+ac957324022b7132accf@syzkaller.appspotmail.com>
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/0ec1228fc5eda4cb524eeda857da8efdc43c331c.1626774457.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fca5343b
    • Pavel Begunkov's avatar
      io_uring: explicitly count entries for poll reqs · 9eef9029
      Pavel Begunkov authored
      commit 68b11e8b upstream.
      
      If __io_queue_proc() fails to add a second poll entry, e.g. kmalloc()
      failed, but it goes on with a third waitqueue, it may succeed and
      overwrite the error status. Count the number of poll entries we added,
      so we can set pt->error to zero at the beginning and find out when the
      mentioned scenario happens.
      
      Cc: stable@vger.kernel.org
      Fixes: 18bceab1
      
       ("io_uring: allow POLL_ADD with double poll_wait() users")
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/9d6b9e561f88bcc0163623b74a76c39f712151c3.1626774457.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9eef9029
    • Peter Collingbourne's avatar
      selftest: use mmap instead of posix_memalign to allocate memory · 1077e2b1
      Peter Collingbourne authored
      commit 0db282ba upstream.
      
      This test passes pointers obtained from anon_allocate_area to the
      userfaultfd and mremap APIs.  This causes a problem if the system
      allocator returns tagged pointers because with the tagged address ABI
      the kernel rejects tagged addresses passed to these APIs, which would
      end up causing the test to fail.  To make this test compatible with such
      system allocators, stop using the system allocator to allocate memory in
      anon_allocate_area, and instead just use mmap.
      
      Link: https://lkml.kernel.org/r/20210714195437.118982-3-pcc@google.com
      Link: https://linux-review.googlesource.com/id/Icac91064fcd923f77a83e8e133f8631c5b8fc241
      Fixes: c47174fc
      
       ("userfaultfd: selftest")
      Co-developed-by: default avatarLokesh Gidra <lokeshgidra@google.com>
      Signed-off-by: default avatarLokesh Gidra <lokeshgidra@google.com>
      Signed-off-by: default avatarPeter Collingbourne <pcc@google.com>
      Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
      Cc: Dave Martin <Dave.Martin@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Alistair Delva <adelva@google.com>
      Cc: William McVicker <willmcvicker@google.com>
      Cc: Evgenii Stepanov <eugenis@google.com>
      Cc: Mitch Phillips <mitchp@google.com>
      Cc: Andrey Konovalov <andreyknvl@gmail.com>
      Cc: <stable@vger.kernel.org>	[5.4]
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1077e2b1
    • Frederic Weisbecker's avatar
      posix-cpu-timers: Fix rearm racing against process tick · 6e81e2c3
      Frederic Weisbecker authored
      commit 1a3402d9
      
       upstream.
      
      Since the process wide cputime counter is started locklessly from
      posix_cpu_timer_rearm(), it can be concurrently stopped by operations
      on other timers from the same thread group, such as in the following
      unlucky scenario:
      
               CPU 0                                CPU 1
               -----                                -----
                                                 timer_settime(TIMER B)
         posix_cpu_timer_rearm(TIMER A)
             cpu_clock_sample_group()
                 (pct->timers_active already true)
      
                                                 handle_posix_cpu_timers()
                                                     check_process_timers()
                                                         stop_process_timers()
                                                             pct->timers_active = false
             arm_timer(TIMER A)
      
         tick -> run_posix_cpu_timers()
             // sees !pct->timers_active, ignore
             // our TIMER A
      
      Fix this with simply locking process wide cputime counting start and
      timer arm in the same block.
      
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarFrederic Weisbecker <frederic@kernel.org>
      Fixes: 60f2ceaa
      
       ("posix-cpu-timers: Remove unnecessary locking around cpu_clock_sample_group")
      Cc: stable@vger.kernel.org
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6e81e2c3
    • Bhaumik Bhatt's avatar
      bus: mhi: core: Validate channel ID when processing command completions · 3efec3b4
      Bhaumik Bhatt authored
      commit 546362a9 upstream.
      
      MHI reads the channel ID from the event ring element sent by the
      device which can be any value between 0 and 255. In order to
      prevent any out of bound accesses, add a check against the maximum
      number of channels supported by the controller and those channels
      not configured yet so as to skip processing of that event ring
      element.
      
      Link: https://lore.kernel.org/r/1624558141-11045-1-git-send-email-bbhatt@codeaurora.org
      Fixes: 1d3173a3
      
       ("bus: mhi: core: Add support for processing events from client device")
      Cc: stable@vger.kernel.org #5.10
      Reviewed-by: default avatarHemant Kumar <hemantk@codeaurora.org>
      Reviewed-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
      Reviewed-by: default avatarJeffrey Hugo <quic_jhugo@quicinc.com>
      Signed-off-by: default avatarBhaumik Bhatt <bbhatt@codeaurora.org>
      Signed-off-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
      Link: https://lore.kernel.org/r/20210716075106.49938-3-manivannan.sadhasivam@linaro.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3efec3b4
    • Markus Boehme's avatar
      ixgbe: Fix packet corruption due to missing DMA sync · b3f3a58a
      Markus Boehme authored
      commit 09cfae9f upstream.
      
      When receiving a packet with multiple fragments, hardware may still
      touch the first fragment until the entire packet has been received. The
      driver therefore keeps the first fragment mapped for DMA until end of
      packet has been asserted, and delays its dma_sync call until then.
      
      The driver tries to fit multiple receive buffers on one page. When using
      3K receive buffers (e.g. using Jumbo frames and legacy-rx is turned
      off/build_skb is being used) on an architecture with 4K pages, the
      driver allocates an order 1 compound page and uses one page per receive
      buffer. To determine the correct offset for a delayed DMA sync of the
      first fragment of a multi-fragment packet, the driver then cannot just
      use PAGE_MASK on the DMA address but has to construct a mask based on
      the actual size of the backing page.
      
      Using PAGE_MASK in the 3K RX buffer/4K page architecture configuration
      will always sync the first page of a compound page. With the SWIOTLB
      enabled this can lead to corrupted packets (zeroed out first fragment,
      re-used garbage from another packet) and various consequences, such as
      slow/stalling data transfers and connection resets. For example, testing
      on a link with MTU exceeding 3058 bytes on a host with SWIOTLB enabled
      (e.g. "iommu=soft swiotlb=262144,force") TCP transfers quickly fizzle
      out without this patch.
      
      Cc: stable@vger.kernel.org
      Fixes: 0c5661ec
      
       ("ixgbe: fix crash in build_skb Rx code path")
      Signed-off-by: default avatarMarkus Boehme <markubo@amazon.com>
      Tested-by: default avatarTony Brelinski <tonyx.brelinski@intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b3f3a58a
    • Gustavo A. R. Silva's avatar
      media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf() · e991457a
      Gustavo A. R. Silva authored
      commit 8d4abca9 upstream.
      
      Fix an 11-year old bug in ngene_command_config_free_buf() while
      addressing the following warnings caught with -Warray-bounds:
      
      arch/alpha/include/asm/string.h:22:16: warning: '__builtin_memcpy' offset [12, 16] from the object at 'com' is out of the bounds of referenced subobject 'config' with type 'unsigned char' at offset 10 [-Warray-bounds]
      arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [12, 16] from the object at 'com' is out of the bounds of referenced subobject 'config' with type 'unsigned char' at offset 10 [-Warray-bounds]
      
      The problem is that the original code is trying to copy 6 bytes of
      data into a one-byte size member _config_ of the wrong structue
      FW_CONFIGURE_BUFFERS, in a single call to memcpy(). This causes a
      legitimate compiler warning because memcpy() overruns the length
      of &com.cmd.ConfigureBuffers.config. It seems that the right
      structure is FW_CONFIGURE_FREE_BUFFERS, instead, because it contains
      6 more members apart from the header _hdr_. Also, the name of
      the function ngene_command_config_free_buf() suggests that the actual
      intention is to ConfigureFreeBuffers, instead of ConfigureBuffers
      (which takes place in the function ngene_command_config_buf(), above).
      
      Fix this by enclosing those 6 members of struct FW_CONFIGURE_FREE_BUFFERS
      into new struct config, and use &com.cmd.ConfigureFreeBuffers.config as
      the destination address, instead of &com.cmd.ConfigureBuffers.config,
      when calling memcpy().
      
      This also helps with the ongoing efforts to globally enable
      -Warray-bounds and get us closer to being able to tighten the
      FORTIFY_SOURCE routines on memcpy().
      
      Link: https://github.com/KSPP/linux/issues/109
      Fixes: dae52d00
      
       ("V4L/DVB: ngene: Initial check-in")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Link: https://lore.kernel.org/linux-hardening/20210420001631.GA45456@embeddedor/
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e991457a
    • Anand Jain's avatar
      btrfs: check for missing device in btrfs_trim_fs · 755971dc
      Anand Jain authored
      commit 16a200f6
      
       upstream.
      
      A fstrim on a degraded raid1 can trigger the following null pointer
      dereference:
      
        BTRFS info (device loop0): allowing degraded mounts
        BTRFS info (device loop0): disk space caching is enabled
        BTRFS info (device loop0): has skinny extents
        BTRFS warning (device loop0): devid 2 uuid 97ac16f7-e14d-4db1-95bc-3d489b424adb is missing
        BTRFS warning (device loop0): devid 2 uuid 97ac16f7-e14d-4db1-95bc-3d489b424adb is missing
        BTRFS info (device loop0): enabling ssd optimizations
        BUG: kernel NULL pointer dereference, address: 0000000000000620
        PGD 0 P4D 0
        Oops: 0000 [#1] SMP NOPTI
        CPU: 0 PID: 4574 Comm: fstrim Not tainted 5.13.0-rc7+ #31
        Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
        RIP: 0010:btrfs_trim_fs+0x199/0x4a0 [btrfs]
        RSP: 0018:ffff959541797d28 EFLAGS: 00010293
        RAX: 0000000000000000 RBX: ffff946f84eca508 RCX: a7a67937adff8608
        RDX: ffff946e8122d000 RSI: 0000000000000000 RDI: ffffffffc02fdbf0
        RBP: ffff946ea4615000 R08: 0000000000000001 R09: 0000000000000000
        R10: 0000000000000000 R11: ffff946e8122d960 R12: 0000000000000000
        R13: ffff959541797db8 R14: ffff946e8122d000 R15: ffff959541797db8
        FS:  00007f55917a5080(0000) GS:ffff946f9bc00000(0000) knlGS:0000000000000000
        CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        CR2: 0000000000000620 CR3: 000000002d2c8001 CR4: 00000000000706f0
        Call Trace:
        btrfs_ioctl_fitrim+0x167/0x260 [btrfs]
        btrfs_ioctl+0x1c00/0x2fe0 [btrfs]
        ? selinux_file_ioctl+0x140/0x240
        ? syscall_trace_enter.constprop.0+0x188/0x240
        ? __x64_sys_ioctl+0x83/0xb0
        __x64_sys_ioctl+0x83/0xb0
      
      Reproducer:
      
        $ mkfs.btrfs -fq -d raid1 -m raid1 /dev/loop0 /dev/loop1
        $ mount /dev/loop0 /btrfs
        $ umount /btrfs
        $ btrfs dev scan --forget
        $ mount -o degraded /dev/loop0 /btrfs
      
        $ fstrim /btrfs
      
      The reason is we call btrfs_trim_free_extents() for the missing device,
      which uses device->bdev (NULL for missing device) to find if the device
      supports discard.
      
      Fix is to check if the device is missing before calling
      btrfs_trim_free_extents().
      
      CC: stable@vger.kernel.org # 5.4+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      755971dc
    • Steven Rostedt (VMware)'s avatar
      tracing: Synthetic event field_pos is an index not a boolean · 552b053f
      Steven Rostedt (VMware) authored
      commit 3b13911a upstream.
      
      Performing the following:
      
       ># echo 'wakeup_lat s32 pid; u64 delta; char wake_comm[]' > synthetic_events
       ># echo 'hist:keys=pid:__arg__1=common_timestamp.usecs' > events/sched/sched_waking/trigger
       ># echo 'hist:keys=next_pid:pid=next_pid,delta=common_timestamp.usecs-$__arg__1:onmatch(sched.sched_waking).trace(wakeup_lat,$pid,$delta,prev_comm)'\
            > events/sched/sched_switch/trigger
       ># echo 1 > events/synthetic/enable
      
      Crashed the kernel:
      
       BUG: kernel NULL pointer dereference, address: 000000000000001b
       #PF: supervisor read access in kernel mode
       #PF: error_code(0x0000) - not-present page
       PGD 0 P4D 0
       Oops: 0000 [#1] PREEMPT SMP
       CPU: 7 PID: 0 Comm: swapper/7 Not tainted 5.13.0-rc5-test+ #104
       Hardware name: Hewlett-Packard HP Compaq Pro 6300 SFF/339A, BIOS K01 v03.03 07/14/2016
       RIP: 0010:strlen+0x0/0x20
       Code: f6 82 80 2b 0b bc 20 74 11 0f b6 50 01 48 83 c0 01 f6 82 80 2b 0b bc
        20 75 ef c3 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 <80> 3f 00 74 10
        48 89 f8 48 83 c0 01 80 38 9 f8 c3 31
       RSP: 0018:ffffaa75000d79d0 EFLAGS: 00010046
       RAX: 0000000000000002 RBX: ffff9cdb55575270 RCX: 0000000000000000
       RDX: ffff9cdb58c7a320 RSI: ffffaa75000d7b40 RDI: 000000000000001b
       RBP: ffffaa75000d7b40 R08: ffff9cdb40a4f010 R09: ffffaa75000d7ab8
       R10: ffff9cdb4398c700 R11: 0000000000000008 R12: ffff9cdb58c7a320
       R13: ffff9cdb55575270 R14: ffff9cdb58c7a000 R15: 0000000000000018
       FS:  0000000000000000(0000) GS:ffff9cdb5aa00000(0000) knlGS:0000000000000000
       CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       CR2: 000000000000001b CR3: 00000000c0612006 CR4: 00000000001706e0
       Call Trace:
        trace_event_raw_event_synth+0x90/0x1d0
        action_trace+0x5b/0x70
        event_hist_trigger+0x4bd/0x4e0
        ? cpumask_next_and+0x20/0x30
        ? update_sd_lb_stats.constprop.0+0xf6/0x840
        ? __lock_acquire.constprop.0+0x125/0x550
        ? find_held_lock+0x32/0x90
        ? sched_clock_cpu+0xe/0xd0
        ? lock_release+0x155/0x440
        ? update_load_avg+0x8c/0x6f0
        ? enqueue_entity+0x18a/0x920
        ? __rb_reserve_next+0xe5/0x460
        ? ring_buffer_lock_reserve+0x12a/0x3f0
        event_triggers_call+0x52/0xe0
        trace_event_buffer_commit+0x1ae/0x240
        trace_event_raw_event_sched_switch+0x114/0x170
        __traceiter_sched_switch+0x39/0x50
        __schedule+0x431/0xb00
        schedule_idle+0x28/0x40
        do_idle+0x198/0x2e0
        cpu_startup_entry+0x19/0x20
        secondary_startup_64_no_verify+0xc2/0xcb
      
      The reason is that the dynamic events array keeps track of the field
      position of the fields array, via the field_pos variable in the
      synth_field structure. Unfortunately, that field is a boolean for some
      reason, which means any field_pos greater than 1 will be a bug (in this
      case it was 2).
      
      Link: https://lkml.kernel.org/r/20210721191008.638bce34@oasis.local.home
      
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: stable@vger.kernel.org
      Fixes: bd82631d
      
       ("tracing: Add support for dynamic strings to synthetic events")
      Reviewed-by: default avatarTom Zanussi <zanussi@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      552b053f
    • Haoran Luo's avatar
      tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop. · 757bdba8
      Haoran Luo authored
      commit 67f0d6d9 upstream.
      
      The "rb_per_cpu_empty()" misinterpret the condition (as not-empty) when
      "head_page" and "commit_page" of "struct ring_buffer_per_cpu" points to
      the same buffer page, whose "buffer_data_page" is empty and "read" field
      is non-zero.
      
      An error scenario could be constructed as followed (kernel perspective):
      
      1. All pages in the buffer has been accessed by reader(s) so that all of
      them will have non-zero "read" field.
      
      2. Read and clear all buffer pages so that "rb_num_of_entries()" will
      return 0 rendering there's no more data to read. It is also required
      that the "read_page", "commit_page" and "tail_page" points to the same
      page, while "head_page" is the next page of them.
      
      3. Invoke "ring_buffer_lock_reserve()" with large enough "length"
      so that it shot pass the end of current tail buffer page. Now the
      "head_page", "commit_page" and "tail_page" points to the same page.
      
      4. Discard current event with "ring_buffer_discard_commit()", so that
      "head_page", "commit_page" and "tail_page" points to a page whose buffer
      data page is now empty.
      
      When the error scenario has been constructed, "tracing_read_pipe" will
      be trapped inside a deadloop: "trace_empty()" returns 0 since
      "rb_per_cpu_empty()" returns 0 when it hits the CPU containing such
      constructed ring buffer. Then "trace_find_next_entry_inc()" always
      return NULL since "rb_num_of_entries()" reports there's no more entry
      to read. Finally "trace_seq_to_user()" returns "-EBUSY" spanking
      "tracing_read_pipe" back to the start of the "waitagain" loop.
      
      I've also written a proof-of-concept script to construct the scenario
      and trigger the bug automatically, you can use it to trace and validate
      my reasoning above:
      
        https://github.com/aegistudio/RingBufferDetonator.git
      
      Tests has been carried out on linux kernel 5.14-rc2
      (2734d6c1), my fixed version
      of kernel (for testing whether my update fixes the bug) and
      some older kernels (for range of affected kernels). Test result is
      also attached to the proof-of-concept repository.
      
      Link: https://lore.kernel.org/linux-trace-devel/YPaNxsIlb2yjSi5Y@aegistudio/
      Link: https://lore.kernel.org/linux-trace-devel/YPgrN85WL9VyrZ55@aegistudio
      
      Cc: stable@vger.kernel.org
      Fixes: bf41a158
      
       ("ring-buffer: make reentrant")
      Suggested-by: default avatarLinus Torvalds <torvalds@linuxfoundation.org>
      Signed-off-by: default avatarHaoran Luo <www@aegistudio.net>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      757bdba8
    • Steven Rostedt (VMware)'s avatar
      tracing/histogram: Rename "cpu" to "common_cpu" · a5e1aff5
      Steven Rostedt (VMware) authored
      commit 1e3bac71 upstream.
      
      Currently the histogram logic allows the user to write "cpu" in as an
      event field, and it will record the CPU that the event happened on.
      
      The problem with this is that there's a lot of events that have "cpu"
      as a real field, and using "cpu" as the CPU it ran on, makes it
      impossible to run histograms on the "cpu" field of events.
      
      For example, if I want to have a histogram on the count of the
      workqueue_queue_work event on its cpu field, running:
      
       ># echo 'hist:keys=cpu' > events/workqueue/workqueue_queue_work/trigger
      
      Gives a misleading and wrong result.
      
      Change the command to "common_cpu" as no event should have "common_*"
      fields as that's a reserved name for fields used by all events. And
      this makes sense here as common_cpu would be a field used by all events.
      
      Now we can even do:
      
       ># echo 'hist:keys=common_cpu,cpu if cpu < 100' > events/workqueue/workqueue_queue_work/trigger
       ># cat events/workqueue/workqueue_queue_work/hist
       # event histogram
       #
       # trigger info: hist:keys=common_cpu,cpu:vals=hitcount:sort=hitcount:size=2048 if cpu < 100 [active]
       #
      
       { common_cpu:          0, cpu:          2 } hitcount:          1
       { common_cpu:          0, cpu:          4 } hitcount:          1
       { common_cpu:          7, cpu:          7 } hitcount:          1
       { common_cpu:          0, cpu:          7 } hitcount:          1
       { common_cpu:          0, cpu:          1 } hitcount:          1
       { common_cpu:          0, cpu:          6 } hitcount:          2
       { common_cpu:          0, cpu:          5 } hitcount:          2
       { common_cpu:          1, cpu:          1 } hitcount:          4
       { common_cpu:          6, cpu:          6 } hitcount:          4
       { common_cpu:          5, cpu:          5 } hitcount:         14
       { common_cpu:          4, cpu:          4 } hitcount:         26
       { common_cpu:          0, cpu:          0 } hitcount:         39
       { common_cpu:          2, cpu:          2 } hitcount:        184
      
      Now for backward compatibility, I added a trick. If "cpu" is used, and
      the field is not found, it will fall back to "common_cpu" and work as
      it did before. This way, it will still work for old programs that use
      "cpu" to get the actual CPU, but if the event has a "cpu" as a field, it
      will get that event's "cpu" field, which is probably what it wants
      anyway.
      
      I updated the tracefs/README to include documentation about both the
      common_timestamp and the common_cpu. This way, if that text is present in
      the README, then an application can know that common_cpu is supported over
      just plain "cpu".
      
      Link: https://lkml.kernel.org/r/20210721110053.26b4f641@oasis.local.home
      
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: stable@vger.kernel.org
      Fixes: 8b7622bf
      
       ("tracing: Add cpu field for hist triggers")
      Reviewed-by: default avatarTom Zanussi <zanussi@kernel.org>
      Reviewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a5e1aff5
    • Steven Rostedt (VMware)'s avatar
      tracepoints: Update static_call before tp_funcs when adding a tracepoint · 0edad8b9
      Steven Rostedt (VMware) authored
      commit 352384d5 upstream.
      
      Because of the significant overhead that retpolines pose on indirect
      calls, the tracepoint code was updated to use the new "static_calls" that
      can modify the running code to directly call a function instead of using
      an indirect caller, and this function can be changed at runtime.
      
      In the tracepoint code that calls all the registered callbacks that are
      attached to a tracepoint, the following is done:
      
      	it_func_ptr = rcu_dereference_raw((&__tracepoint_##name)->funcs);
      	if (it_func_ptr) {
      		__data = (it_func_ptr)->data;
      		static_call(tp_func_##name)(__data, args);
      	}
      
      If there's just a single callback, the static_call is updated to just call
      that callback directly. Once another handler is added, then the static
      caller is updated to call the iterator, that simply loops over all the
      funcs in the array and calls each of the callbacks like the old method
      using indirect calling.
      
      The issue was discovered with a race between updating the funcs array and
      updating the static_call. The funcs array was updated first and then the
      static_call was updated. This is not an issue as long as the first element
      in the old array is the same as the first element in the new array. But
      that assumption is incorrect, because callbacks also have a priority
      field, and if there's a callback added that has a higher priority than the
      callback on the old array, then it will become the first callback in the
      new array. This means that it is possible to call the old callback with
      the new callback data element, which can cause a kernel panic.
      
      	static_call = callback1()
      	funcs[] = {callback1,data1};
      	callback2 has higher priority than callback1
      
      	CPU 1				CPU 2
      	-----				-----
      
         new_funcs = {callback2,data2},
                     {callback1,data1}
      
         rcu_assign_pointer(tp->funcs, new_funcs);
      
        /*
         * Now tp->funcs has the new array
         * but the static_call still calls callback1
         */
      
      				it_func_ptr = tp->funcs [ new_funcs ]
      				data = it_func_ptr->data [ data2 ]
      				static_call(callback1, data);
      
      				/* Now callback1 is called with
      				 * callback2's data */
      
      				[ KERNEL PANIC ]
      
         update_static_call(iterator);
      
      To prevent this from happening, always switch the static_call to the
      iterator before assigning the tp->funcs to the new array. The iterator will
      always properly match the callback with its data.
      
      To trigger this bug:
      
        In one terminal:
      
          while :; do hackbench 50; done
      
        In another terminal
      
          echo 1 > /sys/kernel/tracing/events/sched/sched_waking/enable
          while :; do
              echo 1 > /sys/kernel/tracing/set_event_pid;
              sleep 0.5
              echo 0 > /sys/kernel/tracing/set_event_pid;
              sleep 0.5
         done
      
      And it doesn't take long to crash. This is because the set_event_pid adds
      a callback to the sched_waking tracepoint with a high priority, which will
      be called before the sched_waking trace event callback is called.
      
      Note, the removal to a single callback updates the array first, before
      changing the static_call to single callback, which is the proper order as
      the first element in the array is the same as what the static_call is
      being changed to.
      
      Link: https://lore.kernel.org/io-uring/4ebea8f0-58c9-e571-fd30-0ce4f6f09c70@samba.org/
      
      Cc: stable@vger.kernel.org
      Fixes: d25e37d8
      
       ("tracepoint: Optimize using static_call()")
      Reported-by: default avatarStefan Metzmacher <metze@samba.org>
      tested-by: default avatarStefan Metzmacher <metze@samba.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0edad8b9
    • Marc Zyngier's avatar
      firmware/efi: Tell memblock about EFI iomem reservations · 4ed4074c
      Marc Zyngier authored
      commit 2bab693a
      
       upstream.
      
      kexec_load_file() relies on the memblock infrastructure to avoid
      stamping over regions of memory that are essential to the survival
      of the system.
      
      However, nobody seems to agree how to flag these regions as reserved,
      and (for example) EFI only publishes its reservations in /proc/iomem
      for the benefit of the traditional, userspace based kexec tool.
      
      On arm64 platforms with GICv3, this can result in the payload being
      placed at the location of the LPI tables. Shock, horror!
      
      Let's augment the EFI reservation code with a memblock_reserve() call,
      protecting our dear tables from the secondary kernel invasion.
      
      Reported-by: default avatarMoritz Fischer <mdf@kernel.org>
      Tested-by: default avatarMoritz Fischer <mdf@kernel.org>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      Cc: stable@vger.kernel.org
      Cc: Ard Biesheuvel <ardb@kernel.org>
      Cc: James Morse <james.morse@arm.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4ed4074c
    • Amelie Delaunay's avatar
      usb: typec: stusb160x: register role switch before interrupt registration · 647e26b0
      Amelie Delaunay authored
      commit 86762ad4 upstream.
      
      During interrupt registration, attach state is checked. If attached,
      then the Type-C state is updated with typec_set_xxx functions and role
      switch is set with usb_role_switch_set_role().
      
      If the usb_role_switch parameter is error or null, the function simply
      returns 0.
      
      So, to update usb_role_switch role if a device is attached before the
      irq is registered, usb_role_switch must be registered before irq
      registration.
      
      Fixes: da0cb631
      
       ("usb: typec: add support for STUSB160x Type-C controller family")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarAmelie Delaunay <amelie.delaunay@foss.st.com>
      Link: https://lore.kernel.org/r/20210716120718.20398-2-amelie.delaunay@foss.st.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      647e26b0
    • Minas Harutyunyan's avatar
      usb: dwc2: gadget: Fix sending zero length packet in DDMA mode. · a206167b
      Minas Harutyunyan authored
      commit d53dc388 upstream.
      
      Sending zero length packet in DDMA mode perform by DMA descriptor
      by setting SP (short packet) flag.
      
      For DDMA in function dwc2_hsotg_complete_in() does not need to send
      zlp.
      
      Tested by USBCV MSC tests.
      
      Fixes: f71b5e25
      
       ("usb: dwc2: gadget: fix zero length packet transfers")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarMinas Harutyunyan <Minas.Harutyunyan@synopsys.com>
      Link: https://lore.kernel.org/r/967bad78c55dd2db1c19714eee3d0a17cf99d74a.1626777738.git.Minas.Harutyunyan@synopsys.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a206167b
    • Minas Harutyunyan's avatar
      usb: dwc2: gadget: Fix GOUTNAK flow for Slave mode. · f2c04f6b
      Minas Harutyunyan authored
      commit fecb3a17 upstream.
      
      Because of dwc2_hsotg_ep_stop_xfr() function uses poll
      mode, first need to mask GINTSTS_GOUTNAKEFF interrupt.
      In Slave mode GINTSTS_GOUTNAKEFF interrupt will be
      aserted only after pop OUT NAK status packet from RxFIFO.
      
      In dwc2_hsotg_ep_sethalt() function before setting
      DCTL_SGOUTNAK need to unmask GOUTNAKEFF interrupt.
      
      Tested by USBCV CH9 and MSC tests set in Slave, BDMA and DDMA.
      All tests are passed.
      
      Fixes: a4f82771 ("usb: dwc2: gadget: Disable enabled HW endpoint in dwc2_hsotg_ep_disable")
      Fixes: 6070636c
      
       ("usb: dwc2: Fix Stalling a Non-Isochronous OUT EP")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarMinas Harutyunyan <Minas.Harutyunyan@synopsys.com>
      Link: https://lore.kernel.org/r/e17fad802bbcaf879e1ed6745030993abb93baf8.1626152924.git.Minas.Harutyunyan@synopsys.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f2c04f6b
    • Zhang Qilong's avatar
      usb: gadget: Fix Unbalanced pm_runtime_enable in tegra_xudc_probe · 7073acb5
      Zhang Qilong authored
      commit 5b012481 upstream.
      
      Add missing pm_runtime_disable() when probe error out. It could
      avoid pm_runtime implementation complains when removing and probing
      again the driver.
      
      Fixes: 49db4272
      
       ("usb: gadget: Add UDC driver for tegra XUSB device mode controller")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarZhang Qilong <zhangqilong3@huawei.com>
      Link: https://lore.kernel.org/r/20210618141441.107817-1-zhangqilong3@huawei.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7073acb5
    • John Keeping's avatar
      USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick · 1bf7371b
      John Keeping authored
      commit d6a206e6
      
       upstream.
      
      Add the USB serial device ID for the CEL ZigBee EM3588 radio stick.
      
      Signed-off-by: default avatarJohn Keeping <john@metanate.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1bf7371b
    • Ian Ray's avatar
      USB: serial: cp210x: fix comments for GE CS1000 · 45c87a94
      Ian Ray authored
      commit e9db418d upstream.
      
      Fix comments for GE CS1000 CP210x USB ID assignments.
      
      Fixes: 42213a01
      
       ("USB: serial: cp210x: add some more GE USB IDs")
      Signed-off-by: default avatarIan Ray <ian.ray@ge.com>
      Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      45c87a94
    • Marco De Marco's avatar
      USB: serial: option: add support for u-blox LARA-R6 family · f528521c
      Marco De Marco authored
      commit 94b619a0
      
       upstream.
      
      The patch is meant to support LARA-R6 Cat 1 module family.
      
      Module USB ID:
      Vendor  ID: 0x05c6
      Product ID: 0x90fA
      
      Interface layout:
      If 0: Diagnostic
      If 1: AT parser
      If 2: AT parser
      If 3: QMI wwan (not available in all versions)
      
      Signed-off-by: default avatarMarco De Marco <marco.demarco@posteo.net>
      Link: https://lore.kernel.org/r/49260184.kfMIbaSn9k@mars
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f528521c
    • Yoshihiro Shimoda's avatar
      usb: renesas_usbhs: Fix superfluous irqs happen after usb_pkt_pop() · 311fd7f7
      Yoshihiro Shimoda authored
      commit 5719df24 upstream.
      
      This driver has a potential issue which this driver is possible to
      cause superfluous irqs after usb_pkt_pop() is called. So, after
      the commit 3af32605 ("usb: renesas_usbhs: fix error return
      code of usbhsf_pkt_handler()") had been applied, we could observe
      the following error happened when we used g_audio.
      
          renesas_usbhs e6590000.usb: irq_ready run_error 1 : -22
      
      To fix the issue, disable the tx or rx interrupt in usb_pkt_pop().
      
      Fixes: 2743e7f9
      
       ("usb: renesas_usbhs: fix the usb_pkt_pop()")
      Cc: <stable@vger.kernel.org> # v4.4+
      Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Link: https://lore.kernel.org/r/20210624122039.596528-1-yoshihiro.shimoda.uh@renesas.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      311fd7f7
    • Mark Tomlinson's avatar
      usb: max-3421: Prevent corruption of freed memory · 7af54a4e
      Mark Tomlinson authored
      commit b5fdf5c6 upstream.
      
      The MAX-3421 USB driver remembers the state of the USB toggles for a
      device/endpoint. To save SPI writes, this was only done when a new
      device/endpoint was being used. Unfortunately, if the old device was
      removed, this would cause writes to freed memory.
      
      To fix this, a simpler scheme is used. The toggles are read from
      hardware when a URB is completed, and the toggles are always written to
      hardware when any URB transaction is started. This will cause a few more
      SPI transactions, but no causes kernel panics.
      
      Fixes: 2d53139f
      
       ("Add support for using a MAX3421E chip as a host driver.")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarMark Tomlinson <mark.tomlinson@alliedtelesis.co.nz>
      Link: https://lore.kernel.org/r/20210625031456.8632-1-mark.tomlinson@alliedtelesis.co.nz
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7af54a4e
    • Julian Sikorski's avatar
      USB: usb-storage: Add LaCie Rugged USB3-FW to IGNORE_UAS · 69da81a9
      Julian Sikorski authored
      commit 6abf2fe6
      
       upstream.
      
      LaCie Rugged USB3-FW appears to be incompatible with UAS. It generates
      errors like:
      [ 1151.582598] sd 14:0:0:0: tag#16 uas_eh_abort_handler 0 uas-tag 1 inflight: IN
      [ 1151.582602] sd 14:0:0:0: tag#16 CDB: Report supported operation codes a3 0c 01 12 00 00 00 00 02 00 00 00
      [ 1151.588594] scsi host14: uas_eh_device_reset_handler start
      [ 1151.710482] usb 2-4: reset SuperSpeed Gen 1 USB device number 2 using xhci_hcd
      [ 1151.741398] scsi host14: uas_eh_device_reset_handler success
      [ 1181.785534] scsi host14: uas_eh_device_reset_handler start
      
      Signed-off-by: default avatarJulian Sikorski <belegdol+github@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20210720171910.36497-1-belegdol+github@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      69da81a9