Skip to content
  1. Jul 28, 2021
    • Riccardo Mancini's avatar
      perf inject: Close inject.output on exit · f9d0c355
      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>
      f9d0c355
    • Evan Quan's avatar
      PCI: Mark AMD Navi14 GPU ATS as broken · a9c103fa
      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>
      a9c103fa
    • David Sterba's avatar
      btrfs: compression: don't try to compress if we don't have enough pages · 11561d2f
      David Sterba authored
      commit f2165627
      
       upstream
      
      The early check if we should attempt compression does not take into
      account the number of input pages. It can happen that there's only one
      page, eg. a tail page after some ranges of the BTRFS_MAX_UNCOMPRESSED
      have been processed, or an isolated page that won't be converted to an
      inline extent.
      
      The single page would be compressed but a later check would drop it
      again because the result size must be at least one block shorter than
      the input. That can never work with just one page.
      
      CC: stable@vger.kernel.org # 4.4+
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      [sudip: adjust context]
      Signed-off-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      11561d2f
    • Stephan Gerhold's avatar
      iio: accel: bma180: Fix BMA25x bandwidth register values · 4980301e
      Stephan Gerhold authored
      commit 8090d674 upstream
      
      According to the BMA253 datasheet [1] and BMA250 datasheet [2] the
      bandwidth value for BMA25x should be set as 01xxx:
      
        "Settings 00xxx result in a bandwidth of 7.81 Hz; [...]
         It is recommended [...] to use the range from ´01000b´ to ´01111b´
         only in order to be compatible with future products."
      
      However, at the moment the drivers sets bandwidth values from 0 to 6,
      which is not recommended and always results into 7.81 Hz bandwidth
      according to the datasheet.
      
      Fix this by introducing a bw_offset = 8 = 01000b for BMA25x,
      so the additional bit is always set for BMA25x.
      
      [1]: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bma253-ds000.pdf
      [2]: https://datasheet.octopart.com/BMA250-Bosch-datasheet-15540103.pdf
      
      Cc: Peter Meerwald <pmeerw@pmeerw.net>
      Fixes: 2017cff2
      
       ("iio:bma180: Add BMA250 chip support")
      Signed-off-by: default avatarStephan Gerhold <stephan@gerhold.net>
      Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Link: https://lore.kernel.org/r/20210526094408.34298-2-stephan@gerhold.net
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      [sudip: adjust context]
      Signed-off-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4980301e
    • Linus Walleij's avatar
      iio: accel: bma180: Use explicit member assignment · d04f2582
      Linus Walleij authored
      commit 9436abc4
      
       upstream
      
      This uses the C99 explicit .member assignment for the
      variant data in struct bma180_part_info. This makes it
      easier to understand and add new variants.
      
      Cc: Peter Meerwald <pmeerw@pmeerw.net>
      Cc: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d04f2582
    • Doug Berger's avatar
      net: bcmgenet: ensure EXT_ENERGY_DET_MASK is clear · 4e0afa88
      Doug Berger authored
      commit 5a3c680a upstream.
      
      Setting the EXT_ENERGY_DET_MASK bit allows the port energy detection
      logic of the internal PHY to prevent the system from sleeping. Some
      internal PHYs will report that energy is detected when the network
      interface is closed which can prevent the system from going to sleep
      if WoL is enabled when the interface is brought down.
      
      Since the driver does not support waking the system on this logic,
      this commit clears the bit whenever the internal PHY is powered up
      and the other logic for manipulating the bit is removed since it
      serves no useful function.
      
      Fixes: 1c1008c7
      
       ("net: bcmgenet: add main driver file")
      Signed-off-by: default avatarDoug Berger <opendmb@gmail.com>
      Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e0afa88
    • Marek Behún's avatar
      net: dsa: mv88e6xxx: use correct .stats_set_histogram() on Topaz · 2a4865d1
      Marek Behún authored
      commit 11527f3c upstream.
      
      Commit 40cff8fc
      
       ("net: dsa: mv88e6xxx: Fix stats histogram mode")
      introduced wrong .stats_set_histogram() method for Topaz family.
      
      The Peridot method should be used instead.
      
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Fixes: 40cff8fc
      
       ("net: dsa: mv88e6xxx: Fix stats histogram mode")
      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>
      2a4865d1
    • Charles Baylis's avatar
      drm: Return -ENOTTY for non-drm ioctls · 7d8c06b8
      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>
      7d8c06b8
    • Greg Kroah-Hartman's avatar
      nds32: fix up stack guard gap · b5d7bebd
      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>
      b5d7bebd
    • Ilya Dryomov's avatar
      rbd: always kick acquire on "acquired" and "released" notifications · ba378b79
      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>
      ba378b79
    • Ilya Dryomov's avatar
      rbd: don't hold lock_rwsem while running_list is being drained · 13066d66
      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>
      13066d66
    • Mike Kravetz's avatar
      hugetlbfs: fix mount mode command line processing · b12ead82
      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>
      b12ead82
    • Peter Collingbourne's avatar
      userfaultfd: do not untag user pointers · 60dbbd76
      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>
      60dbbd76
    • Peter Collingbourne's avatar
      selftest: use mmap instead of posix_memalign to allocate memory · 540eee8c
      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>
      540eee8c
    • Markus Boehme's avatar
      ixgbe: Fix packet corruption due to missing DMA sync · e706ac3f
      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>
      e706ac3f
    • Gustavo A. R. Silva's avatar
      media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf() · e617fa62
      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>
      e617fa62
    • Anand Jain's avatar
      btrfs: check for missing device in btrfs_trim_fs · 77713fb3
      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>
      77713fb3
    • Haoran Luo's avatar
      tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop. · f899f24d
      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>
      f899f24d
    • Steven Rostedt (VMware)'s avatar
      tracing/histogram: Rename "cpu" to "common_cpu" · 59a9f75f
      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>
      59a9f75f
    • Marc Zyngier's avatar
      firmware/efi: Tell memblock about EFI iomem reservations · 379d8da3
      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>
      379d8da3
    • Minas Harutyunyan's avatar
      usb: dwc2: gadget: Fix sending zero length packet in DDMA mode. · 281a9436
      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>
      281a9436
    • John Keeping's avatar
      USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick · 167079fb
      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>
      167079fb
    • Ian Ray's avatar
      USB: serial: cp210x: fix comments for GE CS1000 · 811c4cdf
      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>
      811c4cdf
    • Marco De Marco's avatar
      USB: serial: option: add support for u-blox LARA-R6 family · f54ee7e1
      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>
      f54ee7e1
    • Yoshihiro Shimoda's avatar
      usb: renesas_usbhs: Fix superfluous irqs happen after usb_pkt_pop() · e28d28eb
      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>
      e28d28eb
    • Mark Tomlinson's avatar
      usb: max-3421: Prevent corruption of freed memory · 863d071d
      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>
      863d071d
    • Julian Sikorski's avatar
      USB: usb-storage: Add LaCie Rugged USB3-FW to IGNORE_UAS · e4077a90
      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>
      e4077a90
    • Mathias Nyman's avatar
      usb: hub: Fix link power management max exit latency (MEL) calculations · da6f6769
      Mathias Nyman authored
      commit 1bf2761c
      
       upstream.
      
      Maximum Exit Latency (MEL) value is used by host to know how much in
      advance it needs to start waking up a U1/U2 suspended link in order to
      service a periodic transfer in time.
      
      Current MEL calculation only includes the time to wake up the path from
      U1/U2 to U0. This is called tMEL1 in USB 3.1 section C 1.5.2
      
      Total MEL = tMEL1 + tMEL2 +tMEL3 + tMEL4 which should additinally include:
      - tMEL2 which is the time it takes for PING message to reach device
      - tMEL3 time for device to process the PING and submit a PING_RESPONSE
      - tMEL4 time for PING_RESPONSE to traverse back upstream to host.
      
      Add the missing tMEL2, tMEL3 and tMEL4 to MEL calculation.
      
      Cc: <stable@kernel.org> # v3.5
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20210715150122.1995966-1-mathias.nyman@linux.intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      da6f6769
    • Mathias Nyman's avatar
      usb: hub: Disable USB 3 device initiated lpm if exit latency is too high · fea6b53e
      Mathias Nyman authored
      commit 1b7f56fb
      
       upstream.
      
      The device initiated link power management U1/U2 states should not be
      enabled in case the system exit latency plus one bus interval (125us) is
      greater than the shortest service interval of any periodic endpoint.
      
      This is the case for both U1 and U2 sytstem exit latencies and link states.
      
      See USB 3.2 section 9.4.9 "Set Feature" for more details
      
      Note, before this patch the host and device initiated U1/U2 lpm states
      were both enabled with lpm. After this patch it's possible to end up with
      only host inititated U1/U2 lpm in case the exit latencies won't allow
      device initiated lpm.
      
      If this case we still want to set the udev->usb3_lpm_ux_enabled flag so
      that sysfs users can see the link may go to U1/U2.
      
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20210715150122.1995966-2-mathias.nyman@linux.intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fea6b53e
    • Nicholas Piggin's avatar
      KVM: PPC: Book3S HV Nested: Sanitise H_ENTER_NESTED TM state · 962ce043
      Nicholas Piggin authored
      commit d9c57d3e upstream.
      
      The H_ENTER_NESTED hypercall is handled by the L0, and it is a request
      by the L1 to switch the context of the vCPU over to that of its L2
      guest, and return with an interrupt indication. The L1 is responsible
      for switching some registers to guest context, and the L0 switches
      others (including all the hypervisor privileged state).
      
      If the L2 MSR has TM active, then the L1 is responsible for
      recheckpointing the L2 TM state. Then the L1 exits to L0 via the
      H_ENTER_NESTED hcall, and the L0 saves the TM state as part of the exit,
      and then it recheckpoints the TM state as part of the nested entry and
      finally HRFIDs into the L2 with TM active MSR. Not efficient, but about
      the simplest approach for something that's horrendously complicated.
      
      Problems arise if the L1 exits to the L0 with a TM state which does not
      match the L2 TM state being requested. For example if the L1 is
      transactional but the L2 MSR is non-transactional, or vice versa. The
      L0's HRFID can take a TM Bad Thing interrupt and crash.
      
      Fix this by disallowing H_ENTER_NESTED in TM[T] state entirely, and then
      ensuring that if the L1 is suspended then the L2 must have TM active,
      and if the L1 is not suspended then the L2 must not have TM active.
      
      Fixes: 360cae31
      
       ("KVM: PPC: Book3S HV: Nested guest entry via hypercall")
      Cc: stable@vger.kernel.org # v4.20+
      Reported-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
      Acked-by: default avatarMichael Neuling <mikey@neuling.org>
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      962ce043
    • Nicholas Piggin's avatar
      KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow · 2b9ffddd
      Nicholas Piggin authored
      commit f62f3c20 upstream.
      
      The kvmppc_rtas_hcall() sets the host rtas_args.rets pointer based on
      the rtas_args.nargs that was provided by the guest. That guest nargs
      value is not range checked, so the guest can cause the host rets pointer
      to be pointed outside the args array. The individual rtas function
      handlers check the nargs and nrets values to ensure they are correct,
      but if they are not, the handlers store a -3 (0xfffffffd) failure
      indication in rets[0] which corrupts host memory.
      
      Fix this by testing up front whether the guest supplied nargs and nret
      would exceed the array size, and fail the hcall directly without storing
      a failure indication to rets[0].
      
      Also expand on a comment about why we kill the guest and try not to
      return errors directly if we have a valid rets[0] pointer.
      
      Fixes: 8e591cb7
      
       ("KVM: PPC: Book3S: Add infrastructure to implement kernel-side RTAS calls")
      Cc: stable@vger.kernel.org # v3.10+
      Reported-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b9ffddd
    • Mathias Nyman's avatar
      xhci: Fix lost USB 2 remote wake · c968f563
      Mathias Nyman authored
      commit 72f68bf5
      
       upstream.
      
      There's a small window where a USB 2 remote wake may be left unhandled
      due to a race between hub thread and xhci port event interrupt handler.
      
      When the resume event is detected in the xhci interrupt handler it kicks
      the hub timer, which should move the port from resume to U0 once resume
      has been signalled for long enough.
      
      To keep the hub "thread" running we set a bus_state->resuming_ports flag.
      This flag makes sure hub timer function kicks itself.
      
      checking this flag was not properly protected by the spinlock. Flag was
      copied to a local variable before lock was taken. The local variable was
      then checked later with spinlock held.
      
      If interrupt is handled right after copying the flag to the local variable
      we end up stopping the hub thread before it can handle the USB 2 resume.
      
      CPU0					CPU1
      (hub thread)				(xhci event handler)
      
      xhci_hub_status_data()
      status = bus_state->resuming_ports;
      					<Interrupt>
      					handle_port_status()
      					spin_lock()
      					bus_state->resuming_ports = 1
      					set_flag(HCD_FLAG_POLL_RH)
      					spin_unlock()
      spin_lock()
      if (!status)
        clear_flag(HCD_FLAG_POLL_RH)
      spin_unlock()
      
      Fix this by taking the lock a bit earlier so that it covers
      the resuming_ports flag copy in the hub thread
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20210715150651.1996099-2-mathias.nyman@linux.intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c968f563
    • Takashi Iwai's avatar
      ALSA: hdmi: Expose all pins on MSI MS-7C94 board · a660ecde
      Takashi Iwai authored
      commit 33f735f1
      
       upstream.
      
      The BIOS on MSI Mortar B550m WiFi (MS-7C94) board with AMDGPU seems
      disabling the other pins than HDMI although it has more outputs
      including DP.
      
      This patch adds the board to the allow list for enabling all pins.
      
      Reported-by: default avatarDamjan Georgievski <gdamjan@gmail.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/CAEk1YH4Jd0a8vfZxORVu7qg+Zsc-K+pR187ezNq8QhJBPW4gpw@mail.gmail.com
      Link: https://lore.kernel.org/r/20210716135600.24176-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a660ecde
    • Takashi Iwai's avatar
      ALSA: sb: Fix potential ABBA deadlock in CSP driver · f7369635
      Takashi Iwai authored
      commit 1c2b9519
      
       upstream.
      
      SB16 CSP driver may hit potentially a typical ABBA deadlock in two
      code paths:
      
       In snd_sb_csp_stop():
           spin_lock_irqsave(&p->chip->mixer_lock, flags);
           spin_lock(&p->chip->reg_lock);
      
       In snd_sb_csp_load():
           spin_lock_irqsave(&p->chip->reg_lock, flags);
           spin_lock(&p->chip->mixer_lock);
      
      Also the similar pattern is seen in snd_sb_csp_start().
      
      Although the practical impact is very small (those states aren't
      triggered in the same running state and this happens only on a real
      hardware, decades old ISA sound boards -- which must be very difficult
      to find nowadays), it's a real scenario and has to be fixed.
      
      This patch addresses those deadlocks by splitting the locks in
      snd_sb_csp_start() and snd_sb_csp_stop() for avoiding the nested
      locks.
      
      Reported-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/7b0fcdaf-cd4f-4728-2eae-48c151a92e10@gmail.com
      Link: https://lore.kernel.org/r/20210716132723.13216-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f7369635
    • Alexander Tsoy's avatar
      ALSA: usb-audio: Add registration quirk for JBL Quantum headsets · 7aa2dfbc
      Alexander Tsoy authored
      commit b0084afd
      
       upstream.
      
      These devices has two interfaces, but only the second interface
      contains the capture endpoint, thus quirk is required to delay the
      registration until the second interface appears.
      
      Tested-by: default avatarJakub Fišer <jakub@ufiseru.cz>
      Signed-off-by: default avatarAlexander Tsoy <alexander@tsoy.me>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20210721235605.53741-1-alexander@tsoy.me
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7aa2dfbc
    • Takashi Iwai's avatar
      ALSA: usb-audio: Add missing proc text entry for BESPOKEN type · 46d62c3f
      Takashi Iwai authored
      commit 64752a95 upstream.
      
      Recently we've added a new usb_mixer element type, USB_MIXER_BESPOKEN,
      but it wasn't added in the table in snd_usb_mixer_dump_cval().  This
      is no big problem since each bespoken type should have its own dump
      method, but it still isn't disallowed to use the standard one, so we
      should cover it as well.  Along with it, define the table with the
      explicit array initializer for avoiding other pitfalls.
      
      Fixes: 785b6f29
      
       ("ALSA: usb-audio: scarlett2: Fix wrong resume call")
      Reported-by: default avatarPavel Machek <pavel@denx.de>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20210714084836.1977-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      46d62c3f
    • Alexander Egorenkov's avatar
      s390/boot: fix use of expolines in the DMA code · f1754f96
      Alexander Egorenkov authored
      commit 463f36c7 upstream.
      
      The DMA code section of the decompressor must be compiled with expolines
      if Spectre V2 mitigation has been enabled for the decompressed kernel.
      This is required because although the decompressor's image contains
      the DMA code section, it is handed over to the decompressed kernel for use.
      
      Because the DMA code is already slow w/o expolines, use expolines always
      regardless whether the decompressed kernel is using them or not. This
      simplifies the DMA code by dropping the conditional compilation of
      expolines.
      
      Fixes: bf726301
      
       ("s390: use proper expoline sections for .dma code")
      Cc: <stable@vger.kernel.org> # 5.2
      Signed-off-by: default avatarAlexander Egorenkov <egorenar@linux.ibm.com>
      Reviewed-by: default avatarHeiko Carstens <hca@linux.ibm.com>
      Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f1754f96
    • Vasily Gorbik's avatar
      s390/ftrace: fix ftrace_update_ftrace_func implementation · 8eb521d1
      Vasily Gorbik authored
      commit f8c26027 upstream.
      
      s390 enforces DYNAMIC_FTRACE if FUNCTION_TRACER is selected.
      At the same time implementation of ftrace_caller is not compliant with
      HAVE_DYNAMIC_FTRACE since it doesn't provide implementation of
      ftrace_update_ftrace_func() and calls ftrace_trace_function() directly.
      
      The subtle difference is that during ftrace code patching ftrace
      replaces function tracer via ftrace_update_ftrace_func() and activates
      it back afterwards. Unexpected direct calls to ftrace_trace_function()
      during ftrace code patching leads to nullptr-dereferences when tracing
      is activated for one of functions which are used during code patching.
      Those function currently are:
      copy_from_kernel_nofault()
      copy_from_kernel_nofault_allowed()
      preempt_count_sub() [with debug_defconfig]
      preempt_count_add() [with debug_defconfig]
      
      Corresponding KASAN report:
       BUG: KASAN: nullptr-dereference in function_trace_call+0x316/0x3b0
       Read of size 4 at addr 0000000000001e08 by task migration/0/15
      
       CPU: 0 PID: 15 Comm: migration/0 Tainted: G B 5.13.0-41423-g08316af3644d
       Hardware name: IBM 3906 M04 704 (LPAR)
       Stopper: multi_cpu_stop+0x0/0x3e0 <- stop_machine_cpuslocked+0x1e4/0x218
       Call Trace:
        [<0000000001f77caa>] show_stack+0x16a/0x1d0
        [<0000000001f8de42>] dump_stack+0x15a/0x1b0
        [<0000000001f81d56>] print_address_description.constprop.0+0x66/0x2e0
        [<000000000082b0ca>] kasan_report+0x152/0x1c0
        [<00000000004cfd8e>] function_trace_call+0x316/0x3b0
        [<0000000001fb7082>] ftrace_caller+0x7a/0x7e
        [<00000000006bb3e6>] copy_from_kernel_nofault_allowed+0x6/0x10
        [<00000000006bb42e>] copy_from_kernel_nofault+0x3e/0xd0
        [<000000000014605c>] ftrace_make_call+0xb4/0x1f8
        [<000000000047a1b4>] ftrace_replace_code+0x134/0x1d8
        [<000000000047a6e0>] ftrace_modify_all_code+0x120/0x1d0
        [<000000000047a7ec>] __ftrace_modify_code+0x5c/0x78
        [<000000000042395c>] multi_cpu_stop+0x224/0x3e0
        [<0000000000423212>] cpu_stopper_thread+0x33a/0x5a0
        [<0000000000243ff2>] smpboot_thread_fn+0x302/0x708
        [<00000000002329ea>] kthread+0x342/0x408
        [<00000000001066b2>] __ret_from_fork+0x92/0xf0
        [<0000000001fb57fa>] ret_from_fork+0xa/0x30
      
       The buggy address belongs to the page:
       page:(____ptrval____) refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1
       flags: 0x1ffff00000001000(reserved|node=0|zone=0|lastcpupid=0x1ffff)
       raw: 1ffff00000001000 0000040000000048 0000040000000048 0000000000000000
       raw: 0000000000000000 0000000000000000 ffffffff00000001 0000000000000000
       page dumped because: kasan: bad access detected
      
       Memory state around the buggy address:
        0000000000001d00: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0000000000001d80: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
       >0000000000001e00: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
                             ^
        0000000000001e80: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0000000000001f00: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
       ==================================================================
      
      To fix that introduce ftrace_func callback to be called from
      ftrace_caller and update it in ftrace_update_ftrace_func().
      
      Fixes: 4cc9bed0
      
       ("[S390] cleanup ftrace backend functions")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarHeiko Carstens <hca@linux.ibm.com>
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8eb521d1
    • Huang Pei's avatar
      Revert "MIPS: add PMD table accounting into MIPS'pmd_alloc_one" · 268132b0
      Huang Pei authored
      This reverts commit 002d8b39 which is
      commit ed914d48 upstream.
      
      Commit b2b29d6d (mm: account PMD tables like PTE tables) is
      introduced between v5.9 and v5.10, so this fix (commit 002d8b39
      
      )
      should NOT apply to any pre-5.10 branch.
      
      Signed-off-by: default avatarHuang Pei <huangpei@loongson.cn>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      268132b0
    • Marcelo Henrique Cerri's avatar
      proc: Avoid mixing integer types in mem_rw() · f323809e
      Marcelo Henrique Cerri authored
      [ Upstream commit d238692b
      
       ]
      
      Use size_t when capping the count argument received by mem_rw(). Since
      count is size_t, using min_t(int, ...) can lead to a negative value
      that will later be passed to access_remote_vm(), which can cause
      unexpected behavior.
      
      Since we are capping the value to at maximum PAGE_SIZE, the conversion
      from size_t to int when passing it to access_remote_vm() as "len"
      shouldn't be a problem.
      
      Link: https://lkml.kernel.org/r/20210512125215.3348316-1-marcelo.cerri@canonical.com
      Reviewed-by: default avatarDavid Disseldorp <ddiss@suse.de>
      Signed-off-by: default avatarThadeu Lima de Souza Cascardo <cascardo@canonical.com>
      Signed-off-by: default avatarMarcelo Henrique Cerri <marcelo.cerri@canonical.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Souza Cascardo <cascardo@canonical.com>
      Cc: Christian Brauner <christian.brauner@ubuntu.com>
      Cc: Michel Lespinasse <walken@google.com>
      Cc: Helge Deller <deller@gmx.de>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Lorenzo Stoakes <lstoakes@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f323809e