1. 05 Nov, 2020 40 commits
    • Jiri Olsa's avatar
      perf python scripting: Fix printable strings in python3 scripts · f9b29e6e
      Jiri Olsa authored
      commit 6fcd5ddc upstream.
      
      Hagen reported broken strings in python3 tracepoint scripts:
      
        make PYTHON=python3
        perf record -e sched:sched_switch -a -- sleep 5
        perf script --gen-script py
        perf script -s ./perf-script.py
      
        [..]
        sched__sched_switch      7 563231.759525792        0 swapper   prev_comm=bytearray(b'swapper/7\x00\x00\x00\x00\x00\x00\x00'), prev_pid=0, prev_prio=120, prev_state=, next_comm=bytearray(b'mutex-thread-co\x00'),
      
      The problem is in the is_printable_array function that does not take the
      zero byte into account and claim such string as not printable, so the
      code will create byte array instead of string.
      
      Committer testing:
      
      After this fix:
      
      sched__sched_switch 3 484522.497072626  1158680 kworker/3:0-eve  prev_comm=kworker/3:0, prev_pid=1158680, prev_prio=120, prev_state=I, next_comm=swapper/3, next_pid=0, next_prio=120
      Sample: {addr=0, cpu=3, datasrc=84410401, datasrc_decode=N/A|SNP N/A|TLB N/A|LCK N/A, ip=18446744071841817196, period=1, phys_addr=0, pid=1158680, tid=1158680, time=484522497072626, transaction=0, values=[(0, 0)], weight=0}
      
      sched__sched_switch 4 484522.497085610  1225814 perf             prev_comm=perf, prev_pid=1225814, prev_prio=120, prev_state=, next_comm=migration/4, next_pid=30, next_prio=0
      Sample: {addr=0, cpu=4, datasrc=84410401, datasrc_decode=N/A|SNP N/A|TLB N/A|LCK N/A, ip=18446744071841817196, period=1, phys_addr=0, pid=1225814, tid=1225814, time=484522497085610, transaction=0, values=[(0, 0)], weight=0}
      
      Fixes: 249de6e0
      
       ("perf script python: Fix string vs byte array resolving")
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Tested-by: default avatarHagen Paul Pfeifer <hagen@jauu.net>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Link: http://lore.kernel.org/lkml/20200928201135.3633850-1-jolsa@kernel.org
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f9b29e6e
    • Zhihao Cheng's avatar
      ubifs: dent: Fix some potential memory leaks while iterating entries · 059da7d1
      Zhihao Cheng authored
      commit 58f6e78a
      
       upstream.
      
      Fix some potential memory leaks in error handling branches while
      iterating dent entries. For example, function dbg_check_dir()
      forgets to free pdent if it exists.
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Cc: <stable@vger.kernel.org>
      Fixes: 1e51764a
      
       ("UBIFS: add new flash file system")
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      059da7d1
    • Chuck Lever's avatar
      NFSD: Add missing NFSv2 .pc_func methods · b9d61ebc
      Chuck Lever authored
      commit 6b3dccd4
      
       upstream.
      
      There's no protection in nfsd_dispatch() against a NULL .pc_func
      helpers. A malicious NFS client can trigger a crash by invoking the
      unused/unsupported NFSv2 ROOT or WRITECACHE procedures.
      
      The current NFSD dispatcher does not support returning a void reply
      to a non-NULL procedure, so the reply to both of these is wrong, for
      the moment.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b9d61ebc
    • Olga Kornievskaia's avatar
      NFSv4.2: support EXCHGID4_FLAG_SUPP_FENCE_OPS 4.2 EXCHANGE_ID flag · 83210b23
      Olga Kornievskaia authored
      commit 8c39076c
      
       upstream.
      
      RFC 7862 introduced a new flag that either client or server is
      allowed to set: EXCHGID4_FLAG_SUPP_FENCE_OPS.
      
      Client needs to update its bitmask to allow for this flag value.
      
      v2: changed minor version argument to unsigned int
      Signed-off-by: default avatarOlga Kornievskaia <kolga@netapp.com>
      CC: <stable@vger.kernel.org>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      83210b23
    • Mahesh Salgaonkar's avatar
      powerpc/powernv/elog: Fix race while processing OPAL error log event. · d2a486bb
      Mahesh Salgaonkar authored
      commit aea948bb upstream.
      
      Every error log reported by OPAL is exported to userspace through a
      sysfs interface and notified using kobject_uevent(). The userspace
      daemon (opal_errd) then reads the error log and acknowledges the error
      log is saved safely to disk. Once acknowledged the kernel removes the
      respective sysfs file entry causing respective resources to be
      released including kobject.
      
      However it's possible the userspace daemon may already be scanning
      elog entries when a new sysfs elog entry is created by the kernel.
      User daemon may read this new entry and ack it even before kernel can
      notify userspace about it through kobject_uevent() call. If that
      happens then we have a potential race between
      elog_ack_store->kobject_put() and kobject_uevent which can lead to
      use-after-free of a kernfs object resulting in a kernel crash. eg:
      
        BUG: Unable to handle kernel data access on read at 0x6b6b6b6b6b6b6bfb
        Faulting instruction address: 0xc0000000008ff2a0
        Oops: Kernel access of bad area, sig: 11 [#1]
        LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA PowerNV
        CPU: 27 PID: 805 Comm: irq/29-opal-elo Not tainted 5.9.0-rc2-gcc-8.2.0-00214-g6f56a67bcbb5-dirty #363
        ...
        NIP kobject_uevent_env+0xa0/0x910
        LR  elog_event+0x1f4/0x2d0
        Call Trace:
          0x5deadbeef0000122 (unreliable)
          elog_event+0x1f4/0x2d0
          irq_thread_fn+0x4c/0xc0
          irq_thread+0x1c0/0x2b0
          kthread+0x1c4/0x1d0
          ret_from_kernel_thread+0x5c/0x6c
      
      This patch fixes this race by protecting the sysfs file
      creation/notification by holding a reference count on kobject until we
      safely send kobject_uevent().
      
      The function create_elog_obj() returns the elog object which if used
      by caller function will end up in use-after-free problem again.
      However, the return value of create_elog_obj() function isn't being
      used today and there is no need as well. Hence change it to return
      void to make this fix complete.
      
      Fixes: 774fea1a
      
       ("powerpc/powernv: Read OPAL error log and export it through sysfs")
      Cc: stable@vger.kernel.org # v3.15+
      Reported-by: default avatarOliver O'Halloran <oohall@gmail.com>
      Signed-off-by: default avatarMahesh Salgaonkar <mahesh@linux.ibm.com>
      Signed-off-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
      Reviewed-by: default avatarOliver O'Halloran <oohall@gmail.com>
      Reviewed-by: default avatarVasant Hegde <hegdevasant@linux.vnet.ibm.com>
      [mpe: Rework the logic to use a single return, reword comments, add oops]
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20201006122051.190176-1-mpe@ellerman.id.au
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d2a486bb
    • Joel Stanley's avatar
      powerpc: Warn about use of smt_snooze_delay · 03e0e2cd
      Joel Stanley authored
      commit a02f6d42 upstream.
      
      It's not done anything for a long time. Save the percpu variable, and
      emit a warning to remind users to not expect it to do anything.
      
      This uses pr_warn_once instead of pr_warn_ratelimit as testing
      'ppc64_cpu --smt=off' on a 24 core / 4 SMT system showed the warning
      to be noisy, as the online/offline loop is slow.
      
      Fixes: 3fa8cad8
      
       ("powerpc/pseries/cpuidle: smt-snooze-delay cleanup.")
      Cc: stable@vger.kernel.org # v3.14
      Signed-off-by: default avatarJoel Stanley <joel@jms.id.au>
      Acked-by: default avatarGautham R. Shenoy <ego@linux.vnet.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20200902000012.3440389-1-joel@jms.id.au
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      03e0e2cd
    • Andrew Donnellan's avatar
      powerpc/rtas: Restrict RTAS requests from userspace · 818783bf
      Andrew Donnellan authored
      commit bd59380c
      
       upstream.
      
      A number of userspace utilities depend on making calls to RTAS to retrieve
      information and update various things.
      
      The existing API through which we expose RTAS to userspace exposes more
      RTAS functionality than we actually need, through the sys_rtas syscall,
      which allows root (or anyone with CAP_SYS_ADMIN) to make any RTAS call they
      want with arbitrary arguments.
      
      Many RTAS calls take the address of a buffer as an argument, and it's up to
      the caller to specify the physical address of the buffer as an argument. We
      allocate a buffer (the "RMO buffer") in the Real Memory Area that RTAS can
      access, and then expose the physical address and size of this buffer in
      /proc/powerpc/rtas/rmo_buffer. Userspace is expected to read this address,
      poke at the buffer using /dev/mem, and pass an address in the RMO buffer to
      the RTAS call.
      
      However, there's nothing stopping the caller from specifying whatever
      address they want in the RTAS call, and it's easy to construct a series of
      RTAS calls that can overwrite arbitrary bytes (even without /dev/mem
      access).
      
      Additionally, there are some RTAS calls that do potentially dangerous
      things and for which there are no legitimate userspace use cases.
      
      In the past, this would not have been a particularly big deal as it was
      assumed that root could modify all system state freely, but with Secure
      Boot and lockdown we need to care about this.
      
      We can't fundamentally change the ABI at this point, however we can address
      this by implementing a filter that checks RTAS calls against a list
      of permitted calls and forces the caller to use addresses within the RMO
      buffer.
      
      The list is based off the list of calls that are used by the librtas
      userspace library, and has been tested with a number of existing userspace
      RTAS utilities. For compatibility with any applications we are not aware of
      that require other calls, the filter can be turned off at build time.
      
      Cc: stable@vger.kernel.org
      Reported-by: default avatarDaniel Axtens <dja@axtens.net>
      Signed-off-by: default avatarAndrew Donnellan <ajd@linux.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20200820044512.7543-1-ajd@linux.ibm.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      818783bf
    • Sven Schnelle's avatar
      s390/stp: add locking to sysfs functions · 0bc43e64
      Sven Schnelle authored
      commit b3bd0249
      
       upstream.
      
      The sysfs function might race with stp_work_fn. To prevent that,
      add the required locking. Another issue is that the sysfs functions
      are checking the stp_online flag, but this flag just holds the user
      setting whether STP is enabled. Add a flag to clock_sync_flag whether
      stp_info holds valid data and use that instead.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarSven Schnelle <svens@linux.ibm.com>
      Reviewed-by: default avatarAlexander Egorenkov <egorenar@linux.ibm.com>
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0bc43e64
    • Jonathan Cameron's avatar
      iio:gyro:itg3200: Fix timestamp alignment and prevent data leak. · 6a969548
      Jonathan Cameron authored
      commit 10ab7cfd upstream.
      
      One of a class of bugs pointed out by Lars in a recent review.
      iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
      to the size of the timestamp (8 bytes).  This is not guaranteed in
      this driver which uses a 16 byte array of smaller elements on the stack.
      This is fixed by using an explicit c structure. As there are no
      holes in the structure, there is no possiblity of data leakage
      in this case.
      
      The explicit alignment of ts is not strictly necessary but potentially
      makes the code slightly less fragile.  It also removes the possibility
      of this being cut and paste into another driver where the alignment
      isn't already true.
      
      Fixes: 36e0371e
      
       ("iio:itg3200: Use iio_push_to_buffers_with_timestamp()")
      Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Cc: <Stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200722155103.979802-6-jic23@kernel.org
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6a969548
    • Jonathan Cameron's avatar
      iio:adc:ti-adc12138 Fix alignment issue with timestamp · c2a0f7d6
      Jonathan Cameron authored
      commit 293e809b upstream.
      
      One of a class of bugs pointed out by Lars in a recent review.
      iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
      to the size of the timestamp (8 bytes).  This is not guaranteed in
      this driver which uses an array of smaller elements on the stack.
      
      We move to a suitable structure in the iio_priv() data with alignment
      explicitly requested.  This data is allocated with kzalloc so no
      data can leak apart from previous readings. Note that previously
      no leak at all could occur, but previous readings should never
      be a problem.
      
      In this case the timestamp location depends on what other channels
      are enabled. As such we can't use a structure without misleading
      by suggesting only one possible timestamp location.
      
      Fixes: 50a6edb1
      
       ("iio: adc: add ADC12130/ADC12132/ADC12138 ADC driver")
      Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Cc: Akinobu Mita <akinobu.mita@gmail.com>
      Cc: <Stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200722155103.979802-26-jic23@kernel.org
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c2a0f7d6
    • Jonathan Cameron's avatar
      iio:adc:ti-adc0832 Fix alignment issue with timestamp · 4c120060
      Jonathan Cameron authored
      commit 39e91f3b upstream.
      
      One of a class of bugs pointed out by Lars in a recent review.
      iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
      to the size of the timestamp (8 bytes).  This is not guaranteed in
      this driver which uses an array of smaller elements on the stack.
      
      We fix this issues by moving to a suitable structure in the iio_priv()
      data with alignment explicitly requested.  This data is allocated
      with kzalloc so no data can leak apart from previous readings.
      Note that previously no data could leak 'including' previous readings
      but I don't think it is an issue to potentially leak them like
      this now does.
      
      In this case the postioning of the timestamp is depends on what
      other channels are enabled. As such we cannot use a structure to
      make the alignment explicit as it would be missleading by suggesting
      only one possible location for the timestamp.
      
      Fixes: 815bbc87
      
       ("iio: ti-adc0832: add triggered buffer support")
      Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Cc: Akinobu Mita <akinobu.mita@gmail.com>
      Cc: <Stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200722155103.979802-25-jic23@kernel.org
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4c120060
    • Jonathan Cameron's avatar
      iio:light:si1145: Fix timestamp alignment and prevent data leak. · 3f1e6f25
      Jonathan Cameron authored
      commit 0456ecf3 upstream.
      
      One of a class of bugs pointed out by Lars in a recent review.
      iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
      to the size of the timestamp (8 bytes).  This is not guaranteed in
      this driver which uses a 24 byte array of smaller elements on the stack.
      As Lars also noted this anti pattern can involve a leak of data to
      userspace and that indeed can happen here.  We close both issues by
      moving to a suitable array in the iio_priv() data with alignment
      explicitly requested.  This data is allocated with kzalloc so no
      data can leak appart from previous readings.
      
      Depending on the enabled channels, the  location of the timestamp
      can be at various aligned offsets through the buffer.  As such we
      any use of a structure to enforce this alignment would incorrectly
      suggest a single location for the timestamp.  Comments adjusted to
      express this clearly in the code.
      
      Fixes: ac45e57f
      
       ("iio: light: Add driver for Silabs si1132, si1141/2/3 and si1145/6/7 ambient light, uv index and proximity sensors")
      Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
      Cc: <Stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200722155103.979802-9-jic23@kernel.org
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3f1e6f25
    • Paul Cercueil's avatar
      dmaengine: dma-jz4780: Fix race in jz4780_dma_tx_status · 7bd05331
      Paul Cercueil authored
      commit baf6fd97 upstream.
      
      The jz4780_dma_tx_status() function would check if a channel's cookie
      state was set to 'completed', and if not, it would enter the critical
      section. However, in that time frame, the jz4780_dma_chan_irq() function
      was able to set the cookie to 'completed', and clear the jzchan->vchan
      pointer, which was deferenced in the critical section of the first
      function.
      
      Fix this race by checking the channel's cookie state after entering the
      critical function and not before.
      
      Fixes: d894fc60
      
       ("dmaengine: jz4780: add driver for the Ingenic JZ4780 DMA controller")
      Cc: stable@vger.kernel.org # v4.0
      Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
      Reported-by: default avatarArtur Rojek <contact@artur-rojek.eu>
      Tested-by: default avatarArtur Rojek <contact@artur-rojek.eu>
      Link: https://lore.kernel.org/r/20201004140307.885556-1-paul@crapouillou.net
      
      Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7bd05331
    • Jiri Slaby's avatar
      vt: keyboard, extend func_buf_lock to readers · 7f4c966f
      Jiri Slaby authored
      commit 82e61c39 upstream.
      
      Both read-side users of func_table/func_buf need locking. Without that,
      one can easily confuse the code by repeatedly setting altering strings
      like:
      while (1)
      	for (a = 0; a < 2; a++) {
      		struct kbsentry kbs = {};
      		strcpy((char *)kbs.kb_string, a ? ".\n" : "88888\n");
      		ioctl(fd, KDSKBSENT, &kbs);
      	}
      
      When that program runs, one can get unexpected output by holding F1
      (note the unxpected period on the last line):
      .
      88888
      .8888
      
      So protect all accesses to 'func_table' (and func_buf) by preexisting
      'func_buf_lock'.
      
      It is easy in 'k_fn' handler as 'puts_queue' is expected not to sleep.
      On the other hand, KDGKBSENT needs a local (atomic) copy of the string
      because copy_to_user can sleep. Use already allocated, but unused
      'kbs->kb_string' for that purpose.
      
      Note that the program above needs at least CAP_SYS_TTY_CONFIG.
      
      This depends on the previous patch and on the func_buf_lock lock added
      in commit 46ca3f73
      
       (tty/vt: fix write/write race in ioctl(KDSKBSENT)
      handler) in 5.2.
      
      Likely fixes CVE-2020-25656.
      
      Cc: <stable@vger.kernel.org>
      Reported-by: default avatarMinh Yuan <yuanmingbuaa@gmail.com>
      Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
      Link: https://lore.kernel.org/r/20201019085517.10176-2-jslaby@suse.cz
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7f4c966f
    • Jiri Slaby's avatar
      vt: keyboard, simplify vt_kdgkbsent · 46edbcd1
      Jiri Slaby authored
      commit 6ca03f90
      
       upstream.
      
      Use 'strlen' of the string, add one for NUL terminator and simply do
      'copy_to_user' instead of the explicit 'for' loop. This makes the
      KDGKBSENT case more compact.
      
      The only thing we need to take care about is NULL 'func_table[i]'. Use
      an empty string in that case.
      
      The original check for overflow could never trigger as the func_buf
      strings are always shorter or equal to 'struct kbsentry's.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
      Link: https://lore.kernel.org/r/20201019085517.10176-1-jslaby@suse.cz
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      46edbcd1
    • Chris Wilson's avatar
      drm/i915: Force VT'd workarounds when running as a guest OS · 1e066477
      Chris Wilson authored
      commit 8195400f
      
       upstream.
      
      If i915.ko is being used as a passthrough device, it does not know if
      the host is using intel_iommu. Mixing the iommu and gfx causes a few
      issues (such as scanout overfetch) which we need to workaround inside
      the driver, so if we detect we are running under a hypervisor, also
      assume the device access is being virtualised.
      Reported-by: default avatarStefan Fritsch <sf@sfritsch.de>
      Suggested-by: default avatarStefan Fritsch <sf@sfritsch.de>
      Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
      Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
      Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
      Cc: Stefan Fritsch <sf@sfritsch.de>
      Cc: stable@vger.kernel.org
      Tested-by: default avatarStefan Fritsch <sf@sfritsch.de>
      Reviewed-by: default avatarZhenyu Wang <zhenyuw@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20201019101523.4145-1-chris@chris-wilson.co.uk
      (cherry picked from commit f566fdcd
      
      )
      Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1e066477
    • Ran Wang's avatar
      usb: host: fsl-mph-dr-of: check return of dma_set_mask() · 72b3bcab
      Ran Wang authored
      commit 3cd54a61 upstream.
      
      fsl_usb2_device_register() should stop init if dma_set_mask() return
      error.
      
      Fixes: cae05861
      
       ("drivers/usb/host: fsl: Set DMA_MASK of usb platform device")
      Reviewed-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarRan Wang <ran.wang_1@nxp.com>
      Link: https://lore.kernel.org/r/20201010060308.33693-1-ran.wang_1@nxp.com
      
      
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      72b3bcab
    • Jerome Brunet's avatar
      usb: cdc-acm: fix cooldown mechanism · 9801a43b
      Jerome Brunet authored
      commit 38203b83 upstream.
      
      Commit a4e7279c ("cdc-acm: introduce a cool down") is causing
      regression if there is some USB error, such as -EPROTO.
      
      This has been reported on some samples of the Odroid-N2 using the Combee II
      Zibgee USB dongle.
      
      > struct acm *acm = container_of(work, struct acm, work)
      
      is incorrect in case of a delayed work and causes warnings, usually from
      the workqueue:
      
      > WARNING: CPU: 0 PID: 0 at kernel/workqueue.c:1474 __queue_work+0x480/0x528.
      
      When this happens, USB eventually stops working completely after a while.
      Also the ACM_ERROR_DELAY bit is never set, so the cooldown mechanism
      previously introduced cannot be triggered and acm_submit_read_urb() is
      never called.
      
      This changes makes the cdc-acm driver use a single delayed work, fixing the
      pointer arithmetic in acm_softint() and set the ACM_ERROR_DELAY when the
      cooldown mechanism appear to be needed.
      
      Fixes: a4e7279c
      
       ("cdc-acm: introduce a cool down")
      Cc: Oliver Neukum <oneukum@suse.com>
      Reported-by: default avatarPascal Vizeli <pascal.vizeli@nabucasa.com>
      Acked-by: default avatarOliver Neukum <oneukum@suse.com>
      Signed-off-by: default avatarJerome Brunet <jbrunet@baylibre.com>
      Link: https://lore.kernel.org/r/20201019170702.150534-1-jbrunet@baylibre.com
      
      
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9801a43b
    • Li Jun's avatar
      usb: dwc3: core: don't trigger runtime pm when remove driver · d92f1821
      Li Jun authored
      commit 266d0493 upstream.
      
      No need to trigger runtime pm in driver removal, otherwise if user
      disable auto suspend via sys file, runtime suspend may be entered,
      which will call dwc3_core_exit() again and there will be clock disable
      not balance warning:
      
      [ 2026.820154] xhci-hcd xhci-hcd.0.auto: remove, state 4
      [ 2026.825268] usb usb2: USB disconnect, device number 1
      [ 2026.831017] xhci-hcd xhci-hcd.0.auto: USB bus 2 deregistered
      [ 2026.836806] xhci-hcd xhci-hcd.0.auto: remove, state 4
      [ 2026.842029] usb usb1: USB disconnect, device number 1
      [ 2026.848029] xhci-hcd xhci-hcd.0.auto: USB bus 1 deregistered
      [ 2026.865889] ------------[ cut here ]------------
      [ 2026.870506] usb2_ctrl_root_clk already disabled
      [ 2026.875082] WARNING: CPU: 0 PID: 731 at drivers/clk/clk.c:958
      clk_core_disable+0xa0/0xa8
      [ 2026.883170] Modules linked in: dwc3(-) phy_fsl_imx8mq_usb [last
      unloaded: dwc3]
      [ 2026.890488] CPU: 0 PID: 731 Comm: rmmod Not tainted
      5.8.0-rc7-00280-g9d08cca-dirty #245
      [ 2026.898489] Hardware name: NXP i.MX8MQ EVK (DT)
      [ 2026.903020] pstate: 20000085 (nzCv daIf -PAN -UAO BTYPE=--)
      [ 2026.908594] pc : clk_core_disable+0xa0/0xa8
      [ 2026.912777] lr : clk_core_disable+0xa0/0xa8
      [ 2026.916958] sp : ffff8000121b39a0
      [ 2026.920271] x29: ffff8000121b39a0 x28: ffff0000b11f3700
      [ 2026.925583] x27: 0000000000000000 x26: ffff0000b539c700
      [ 2026.930895] x25: 000001d7e44e1232 x24: ffff0000b76fa800
      [ 2026.936208] x23: ffff0000b76fa6f8 x22: ffff800008d01040
      [ 2026.941520] x21: ffff0000b539ce00 x20: ffff0000b7105000
      [ 2026.946832] x19: ffff0000b7105000 x18: 0000000000000010
      [ 2026.952144] x17: 0000000000000001 x16: 0000000000000000
      [ 2026.957456] x15: ffff0000b11f3b70 x14: ffffffffffffffff
      [ 2026.962768] x13: ffff8000921b36f7 x12: ffff8000121b36ff
      [ 2026.968080] x11: ffff8000119e1000 x10: ffff800011bf26d0
      [ 2026.973392] x9 : 0000000000000000 x8 : ffff800011bf3000
      [ 2026.978704] x7 : ffff800010695d68 x6 : 0000000000000252
      [ 2026.984016] x5 : ffff0000bb9881f0 x4 : 0000000000000000
      [ 2026.989327] x3 : 0000000000000027 x2 : 0000000000000023
      [ 2026.994639] x1 : ac2fa471aa7cab00 x0 : 0000000000000000
      [ 2026.999951] Call trace:
      [ 2027.002401]  clk_core_disable+0xa0/0xa8
      [ 2027.006238]  clk_core_disable_lock+0x20/0x38
      [ 2027.010508]  clk_disable+0x1c/0x28
      [ 2027.013911]  clk_bulk_disable+0x34/0x50
      [ 2027.017758]  dwc3_core_exit+0xec/0x110 [dwc3]
      [ 2027.022122]  dwc3_suspend_common+0x84/0x188 [dwc3]
      [ 2027.026919]  dwc3_runtime_suspend+0x74/0x9c [dwc3]
      [ 2027.031712]  pm_generic_runtime_suspend+0x28/0x40
      [ 2027.036419]  genpd_runtime_suspend+0xa0/0x258
      [ 2027.040777]  __rpm_callback+0x88/0x140
      [ 2027.044526]  rpm_callback+0x20/0x80
      [ 2027.048015]  rpm_suspend+0xd0/0x418
      [ 2027.051503]  __pm_runtime_suspend+0x58/0xa0
      [ 2027.055693]  dwc3_runtime_idle+0x7c/0x90 [dwc3]
      [ 2027.060224]  __rpm_callback+0x88/0x140
      [ 2027.063973]  rpm_idle+0x78/0x150
      [ 2027.067201]  __pm_runtime_idle+0x58/0xa0
      [ 2027.071130]  dwc3_remove+0x64/0xc0 [dwc3]
      [ 2027.075140]  platform_drv_remove+0x28/0x48
      [ 2027.079239]  device_release_driver_internal+0xf4/0x1c0
      [ 2027.084377]  driver_detach+0x4c/0xd8
      [ 2027.087954]  bus_remove_driver+0x54/0xa8
      [ 2027.091877]  driver_unregister+0x2c/0x58
      [ 2027.095799]  platform_driver_unregister+0x10/0x18
      [ 2027.100509]  dwc3_driver_exit+0x14/0x1408 [dwc3]
      [ 2027.105129]  __arm64_sys_delete_module+0x178/0x218
      [ 2027.109922]  el0_svc_common.constprop.0+0x68/0x160
      [ 2027.114714]  do_el0_svc+0x20/0x80
      [ 2027.118031]  el0_sync_handler+0x88/0x190
      [ 2027.121953]  el0_sync+0x140/0x180
      [ 2027.125267] ---[ end trace 027f4f8189958f1f ]---
      [ 2027.129976] ------------[ cut here ]------------
      
      Fixes: fc8bb91b
      
       ("usb: dwc3: implement runtime PM")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarLi Jun <jun.li@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d92f1821
    • Li Jun's avatar
      usb: dwc3: core: add phy cleanup for probe error handling · 00275153
      Li Jun authored
      commit 03c1fd62 upstream.
      
      Add the phy cleanup if dwc3 mode init fail, which is the missing part of
      de-init for dwc3 core init.
      
      Fixes: c499ff71
      
       ("usb: dwc3: core: re-factor init and exit paths")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarLi Jun <jun.li@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      00275153
    • Thinh Nguyen's avatar
      usb: dwc3: ep0: Fix ZLP for OUT ep0 requests · 388c2fdc
      Thinh Nguyen authored
      commit 66706077 upstream.
      
      The current ZLP handling for ep0 requests is only for control IN
      requests. For OUT direction, DWC3 needs to check and setup for MPS
      alignment.
      
      Usually, control OUT requests can indicate its transfer size via the
      wLength field of the control message. So usb_request->zero is usually
      not needed for OUT direction. To handle ZLP OUT for control endpoint,
      make sure the TRB is MPS size.
      
      Cc: stable@vger.kernel.org
      Fixes: c7fcdeb2 ("usb: dwc3: ep0: simplify EP0 state machine")
      Fixes: d6e5a549
      
       ("usb: dwc3: simplify ZLP handling")
      Signed-off-by: default avatarThinh Nguyen <Thinh.Nguyen@synopsys.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      388c2fdc
    • Filipe Manana's avatar
      btrfs: fix use-after-free on readahead extent after failure to create it · 0e8b5aba
      Filipe Manana authored
      commit 83bc1560 upstream.
      
      If we fail to find suitable zones for a new readahead extent, we end up
      leaving a stale pointer in the global readahead extents radix tree
      (fs_info->reada_tree), which can trigger the following trace later on:
      
        [13367.696354] BUG: kernel NULL pointer dereference, address: 00000000000000b0
        [13367.696802] #PF: supervisor read access in kernel mode
        [13367.697249] #PF: error_code(0x0000) - not-present page
        [13367.697721] PGD 0 P4D 0
        [13367.698171] Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC PTI
        [13367.698632] CPU: 6 PID: 851214 Comm: btrfs Tainted: G        W         5.9.0-rc6-btrfs-next-69 #1
        [13367.699100] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
        [13367.700069] RIP: 0010:__lock_acquire+0x20a/0x3970
        [13367.700562] Code: ff 1f 0f b7 c0 48 0f (...)
        [13367.701609] RSP: 0018:ffffb14448f57790 EFLAGS: 00010046
        [13367.702140] RAX: 0000000000000000 RBX: 29b935140c15e8cf RCX: 0000000000000000
        [13367.702698] RDX: 0000000000000002 RSI: ffffffffb3d66bd0 RDI: 0000000000000046
        [13367.703240] RBP: ffff8a52ba8ac040 R08: 00000c2866ad9288 R09: 0000000000000001
        [13367.703783] R10: 0000000000000001 R11: 00000000b66d9b53 R12: ffff8a52ba8ac9b0
        [13367.704330] R13: 0000000000000000 R14: ffff8a532b6333e8 R15: 0000000000000000
        [13367.704880] FS:  00007fe1df6b5700(0000) GS:ffff8a5376600000(0000) knlGS:0000000000000000
        [13367.705438] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        [13367.705995] CR2: 00000000000000b0 CR3: 000000022cca8004 CR4: 00000000003706e0
        [13367.706565] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
        [13367.707127] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
        [13367.707686] Call Trace:
        [13367.708246]  ? ___slab_alloc+0x395/0x740
        [13367.708820]  ? reada_add_block+0xae/0xee0 [btrfs]
        [13367.709383]  lock_acquire+0xb1/0x480
        [13367.709955]  ? reada_add_block+0xe0/0xee0 [btrfs]
        [13367.710537]  ? reada_add_block+0xae/0xee0 [btrfs]
        [13367.711097]  ? rcu_read_lock_sched_held+0x5d/0x90
        [13367.711659]  ? kmem_cache_alloc_trace+0x8d2/0x990
        [13367.712221]  ? lock_acquired+0x33b/0x470
        [13367.712784]  _raw_spin_lock+0x34/0x80
        [13367.713356]  ? reada_add_block+0xe0/0xee0 [btrfs]
        [13367.713966]  reada_add_block+0xe0/0xee0 [btrfs]
        [13367.714529]  ? btrfs_root_node+0x15/0x1f0 [btrfs]
        [13367.715077]  btrfs_reada_add+0x117/0x170 [btrfs]
        [13367.715620]  scrub_stripe+0x21e/0x10d0 [btrfs]
        [13367.716141]  ? kvm_sched_clock_read+0x5/0x10
        [13367.716657]  ? __lock_acquire+0x41e/0x3970
        [13367.717184]  ? scrub_chunk+0x60/0x140 [btrfs]
        [13367.717697]  ? find_held_lock+0x32/0x90
        [13367.718254]  ? scrub_chunk+0x60/0x140 [btrfs]
        [13367.718773]  ? lock_acquired+0x33b/0x470
        [13367.719278]  ? scrub_chunk+0xcd/0x140 [btrfs]
        [13367.719786]  scrub_chunk+0xcd/0x140 [btrfs]
        [13367.720291]  scrub_enumerate_chunks+0x270/0x5c0 [btrfs]
        [13367.720787]  ? finish_wait+0x90/0x90
        [13367.721281]  btrfs_scrub_dev+0x1ee/0x620 [btrfs]
        [13367.721762]  ? rcu_read_lock_any_held+0x8e/0xb0
        [13367.722235]  ? preempt_count_add+0x49/0xa0
        [13367.722710]  ? __sb_start_write+0x19b/0x290
        [13367.723192]  btrfs_ioctl+0x7f5/0x36f0 [btrfs]
        [13367.723660]  ? __fget_files+0x101/0x1d0
        [13367.724118]  ? find_held_lock+0x32/0x90
        [13367.724559]  ? __fget_files+0x101/0x1d0
        [13367.724982]  ? __x64_sys_ioctl+0x83/0xb0
        [13367.725399]  __x64_sys_ioctl+0x83/0xb0
        [13367.725802]  do_syscall_64+0x33/0x80
        [13367.726188]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
        [13367.726574] RIP: 0033:0x7fe1df7add87
        [13367.726948] Code: 00 00 00 48 8b 05 09 91 (...)
        [13367.727763] RSP: 002b:00007fe1df6b4d48 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
        [13367.728179] RAX: ffffffffffffffda RBX: 000055ce1fb596a0 RCX: 00007fe1df7add87
        [13367.728604] RDX: 000055ce1fb596a0 RSI: 00000000c400941b RDI: 0000000000000003
        [13367.729021] RBP: 0000000000000000 R08: 00007fe1df6b5700 R09: 0000000000000000
        [13367.729431] R10: 00007fe1df6b5700 R11: 0000000000000246 R12: 00007ffd922b07de
        [13367.729842] R13: 00007ffd922b07df R14: 00007fe1df6b4e40 R15: 0000000000802000
        [13367.730275] Modules linked in: btrfs blake2b_generic xor (...)
        [13367.732638] CR2: 00000000000000b0
        [13367.733166] ---[ end trace d298b6805556acd9 ]---
      
      What happens is the following:
      
      1) At reada_find_extent() we don't find any existing readahead extent for
         the metadata extent starting at logical address X;
      
      2) So we proceed to create a new one. We then call btrfs_map_block() to get
         information about which stripes contain extent X;
      
      3) After that we iterate over the stripes and create only one zone for the
         readahead extent - only one because reada_find_zone() returned NULL for
         all iterations except for one, either because a memory allocation failed
         or it couldn't find the block group of the extent (it may have just been
         deleted);
      
      4) We then add the new readahead extent to the readahead extents radix
         tree at fs_info->reada_tree;
      
      5) Then we iterate over each zone of the new readahead extent, and find
         that the device used for that zone no longer exists, because it was
         removed or it was the source device of a device replace operation.
         Since this left 'have_zone' set to 0, after finishing the loop we jump
         to the 'error' label, call kfree() on the new readahead extent and
         return without removing it from the radix tree at fs_info->reada_tree;
      
      6) Any future call to reada_find_extent() for the logical address X will
         find the stale pointer in the readahead extents radix tree, increment
         its reference counter, which can trigger the use-after-free right
         away or return it to the caller reada_add_block() that results in the
         use-after-free of the example trace above.
      
      So fix this by making sure we delete the readahead extent from the radix
      tree if we fail to setup zones for it (when 'have_zone = 0').
      
      Fixes: 31945021
      
       ("btrfs: reada: bypass adding extent when all zone failed")
      CC: stable@vger.kernel.org # 4.9+
      Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.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>
      0e8b5aba
    • Josef Bacik's avatar
      btrfs: cleanup cow block on error · bd54c7d9
      Josef Bacik authored
      commit 572c83ac
      
       upstream.
      
      In fstest btrfs/064 a transaction abort in __btrfs_cow_block could lead
      to a system lockup. It gets stuck trying to write back inodes, and the
      write back thread was trying to lock an extent buffer:
      
        $ cat /proc/2143497/stack
        [<0>] __btrfs_tree_lock+0x108/0x250
        [<0>] lock_extent_buffer_for_io+0x35e/0x3a0
        [<0>] btree_write_cache_pages+0x15a/0x3b0
        [<0>] do_writepages+0x28/0xb0
        [<0>] __writeback_single_inode+0x54/0x5c0
        [<0>] writeback_sb_inodes+0x1e8/0x510
        [<0>] wb_writeback+0xcc/0x440
        [<0>] wb_workfn+0xd7/0x650
        [<0>] process_one_work+0x236/0x560
        [<0>] worker_thread+0x55/0x3c0
        [<0>] kthread+0x13a/0x150
        [<0>] ret_from_fork+0x1f/0x30
      
      This is because we got an error while COWing a block, specifically here
      
              if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) {
                      ret = btrfs_reloc_cow_block(trans, root, buf, cow);
                      if (ret) {
                              btrfs_abort_transaction(trans, ret);
                              return ret;
                      }
              }
      
        [16402.241552] BTRFS: Transaction aborted (error -2)
        [16402.242362] WARNING: CPU: 1 PID: 2563188 at fs/btrfs/ctree.c:1074 __btrfs_cow_block+0x376/0x540
        [16402.249469] CPU: 1 PID: 2563188 Comm: fsstress Not tainted 5.9.0-rc6+ #8
        [16402.249936] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
        [16402.250525] RIP: 0010:__btrfs_cow_block+0x376/0x540
        [16402.252417] RSP: 0018:ffff9cca40e578b0 EFLAGS: 00010282
        [16402.252787] RAX: 0000000000000025 RBX: 0000000000000002 RCX: ffff9132bbd19388
        [16402.253278] RDX: 00000000ffffffd8 RSI: 0000000000000027 RDI: ffff9132bbd19380
        [16402.254063] RBP: ffff9132b41a49c0 R08: 0000000000000000 R09: 0000000000000000
        [16402.254887] R10: 0000000000000000 R11: ffff91324758b080 R12: ffff91326ef17ce0
        [16402.255694] R13: ffff91325fc0f000 R14: ffff91326ef176b0 R15: ffff9132815e2000
        [16402.256321] FS:  00007f542c6d7b80(0000) GS:ffff9132bbd00000(0000) knlGS:0000000000000000
        [16402.256973] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        [16402.257374] CR2: 00007f127b83f250 CR3: 0000000133480002 CR4: 0000000000370ee0
        [16402.257867] Call Trace:
        [16402.258072]  btrfs_cow_block+0x109/0x230
        [16402.258356]  btrfs_search_slot+0x530/0x9d0
        [16402.258655]  btrfs_lookup_file_extent+0x37/0x40
        [16402.259155]  __btrfs_drop_extents+0x13c/0xd60
        [16402.259628]  ? btrfs_block_rsv_migrate+0x4f/0xb0
        [16402.259949]  btrfs_replace_file_extents+0x190/0x820
        [16402.260873]  btrfs_clone+0x9ae/0xc00
        [16402.261139]  btrfs_extent_same_range+0x66/0x90
        [16402.261771]  btrfs_remap_file_range+0x353/0x3b1
        [16402.262333]  vfs_dedupe_file_range_one.part.0+0xd5/0x140
        [16402.262821]  vfs_dedupe_file_range+0x189/0x220
        [16402.263150]  do_vfs_ioctl+0x552/0x700
        [16402.263662]  __x64_sys_ioctl+0x62/0xb0
        [16402.264023]  do_syscall_64+0x33/0x40
        [16402.264364]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
        [16402.264862] RIP: 0033:0x7f542c7d15cb
        [16402.266901] RSP: 002b:00007ffd35944ea8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
        [16402.267627] RAX: ffffffffffffffda RBX: 00000000009d1968 RCX: 00007f542c7d15cb
        [16402.268298] RDX: 00000000009d2490 RSI: 00000000c0189436 RDI: 0000000000000003
        [16402.268958] RBP: 00000000009d2520 R08: 0000000000000036 R09: 00000000009d2e64
        [16402.269726] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000002
        [16402.270659] R13: 000000000001f000 R14: 00000000009d1970 R15: 00000000009d2e80
        [16402.271498] irq event stamp: 0
        [16402.271846] hardirqs last  enabled at (0): [<0000000000000000>] 0x0
        [16402.272497] hardirqs last disabled at (0): [<ffffffff910dbf59>] copy_process+0x6b9/0x1ba0
        [16402.273343] softirqs last  enabled at (0): [<ffffffff910dbf59>] copy_process+0x6b9/0x1ba0
        [16402.273905] softirqs last disabled at (0): [<0000000000000000>] 0x0
        [16402.274338] ---[ end trace 737874a5a41a8236 ]---
        [16402.274669] BTRFS: error (device dm-9) in __btrfs_cow_block:1074: errno=-2 No such entry
        [16402.276179] BTRFS info (device dm-9): forced readonly
        [16402.277046] BTRFS: error (device dm-9) in btrfs_replace_file_extents:2723: errno=-2 No such entry
        [16402.278744] BTRFS: error (device dm-9) in __btrfs_cow_block:1074: errno=-2 No such entry
        [16402.279968] BTRFS: error (device dm-9) in __btrfs_cow_block:1074: errno=-2 No such entry
        [16402.280582] BTRFS info (device dm-9): balance: ended with status: -30
      
      The problem here is that as soon as we allocate the new block it is
      locked and marked dirty in the btree inode.  This means that we could
      attempt to writeback this block and need to lock the extent buffer.
      However we're not unlocking it here and thus we deadlock.
      
      Fix this by unlocking the cow block if we have any errors inside of
      __btrfs_cow_block, and also free it so we do not leak it.
      
      CC: stable@vger.kernel.org # 4.4+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.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>
      bd54c7d9
    • Denis Efremov's avatar
      btrfs: use kvzalloc() to allocate clone_roots in btrfs_ioctl_send() · 69b8f1a8
      Denis Efremov authored
      commit 8eb2fd00 upstream.
      
      btrfs_ioctl_send() used open-coded kvzalloc implementation earlier.
      The code was accidentally replaced with kzalloc() call [1]. Restore
      the original code by using kvzalloc() to allocate sctx->clone_roots.
      
      [1] https://patchwork.kernel.org/patch/9757891/#20529627
      
      Fixes: 818e010b
      
       ("btrfs: replace opencoded kvzalloc with the helper")
      CC: stable@vger.kernel.org # 4.14+
      Signed-off-by: default avatarDenis Efremov <efremov@linux.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>
      69b8f1a8
    • Filipe Manana's avatar
      btrfs: send, recompute reference path after orphanization of a directory · 3350eb1f
      Filipe Manana authored
      commit 9c2b4e03
      
       upstream.
      
      During an incremental send, when an inode has multiple new references we
      might end up emitting rename operations for orphanizations that have a
      source path that is no longer valid due to a previous orphanization of
      some directory inode. This causes the receiver to fail since it tries
      to rename a path that does not exists.
      
      Example reproducer:
      
        $ cat reproducer.sh
        #!/bin/bash
      
        mkfs.btrfs -f /dev/sdi >/dev/null
        mount /dev/sdi /mnt/sdi
      
        touch /mnt/sdi/f1
        touch /mnt/sdi/f2
        mkdir /mnt/sdi/d1
        mkdir /mnt/sdi/d1/d2
      
        # Filesystem looks like:
        #
        # .                           (ino 256)
        # |----- f1                   (ino 257)
        # |----- f2                   (ino 258)
        # |----- d1/                  (ino 259)
        #        |----- d2/           (ino 260)
      
        btrfs subvolume snapshot -r /mnt/sdi /mnt/sdi/snap1
        btrfs send -f /tmp/snap1.send /mnt/sdi/snap1
      
        # Now do a series of changes such that:
        #
        # *) inode 258 has one new hardlink and the previous name changed
        #
        # *) both names conflict with the old names of two other inodes:
        #
        #    1) the new name "d1" conflicts with the old name of inode 259,
        #       under directory inode 256 (root)
        #
        #    2) the new name "d2" conflicts with the old name of inode 260
        #       under directory inode 259
        #
        # *) inodes 259 and 260 now have the old names of inode 258
        #
        # *) inode 257 is now located under inode 260 - an inode with a number
        #    smaller than the inode (258) for which we created a second hard
        #    link and swapped its names with inodes 259 and 260
        #
        ln /mnt/sdi/f2 /mnt/sdi/d1/f2_link
        mv /mnt/sdi/f1 /mnt/sdi/d1/d2/f1
      
        # Swap d1 and f2.
        mv /mnt/sdi/d1 /mnt/sdi/tmp
        mv /mnt/sdi/f2 /mnt/sdi/d1
        mv /mnt/sdi/tmp /mnt/sdi/f2
      
        # Swap d2 and f2_link
        mv /mnt/sdi/f2/d2 /mnt/sdi/tmp
        mv /mnt/sdi/f2/f2_link /mnt/sdi/f2/d2
        mv /mnt/sdi/tmp /mnt/sdi/f2/f2_link
      
        # Filesystem now looks like:
        #
        # .                                (ino 256)
        # |----- d1                        (ino 258)
        # |----- f2/                       (ino 259)
        #        |----- f2_link/           (ino 260)
        #        |       |----- f1         (ino 257)
        #        |
        #        |----- d2                 (ino 258)
      
        btrfs subvolume snapshot -r /mnt/sdi /mnt/sdi/snap2
        btrfs send -f /tmp/snap2.send -p /mnt/sdi/snap1 /mnt/sdi/snap2
      
        mkfs.btrfs -f /dev/sdj >/dev/null
        mount /dev/sdj /mnt/sdj
      
        btrfs receive -f /tmp/snap1.send /mnt/sdj
        btrfs receive -f /tmp/snap2.send /mnt/sdj
      
        umount /mnt/sdi
        umount /mnt/sdj
      
      When executed the receive of the incremental stream fails:
      
        $ ./reproducer.sh
        Create a readonly snapshot of '/mnt/sdi' in '/mnt/sdi/snap1'
        At subvol /mnt/sdi/snap1
        Create a readonly snapshot of '/mnt/sdi' in '/mnt/sdi/snap2'
        At subvol /mnt/sdi/snap2
        At subvol snap1
        At snapshot snap2
        ERROR: rename d1/d2 -> o260-6-0 failed: No such file or directory
      
      This happens because:
      
      1) When processing inode 257 we end up computing the name for inode 259
         because it is an ancestor in the send snapshot, and at that point it
         still has its old name, "d1", from the parent snapshot because inode
         259 was not yet processed. We then cache that name, which is valid
         until we start processing inode 259 (or set the progress to 260 after
         processing its references);
      
      2) Later we start processing inode 258 and collecting all its new
         references into the list sctx->new_refs. The first reference in the
         list happens to be the reference for name "d1" while the reference for
         name "d2" is next (the last element of the list).
         We compute the full path "d1/d2" for this second reference and store
         it in the reference (its ->full_path member). The path used for the
         new parent directory was "d1" and not "f2" because inode 259, the
         new parent, was not yet processed;
      
      3) When we start processing the new references at process_recorded_refs()
         we start with the first reference in the list, for the new name "d1".
         Because there is a conflicting inode that was not yet processed, which
         is directory inode 259, we orphanize it, renaming it from "d1" to
         "o259-6-0";
      
      4) Then we start processing the new reference for name "d2", and we
         realize it conflicts with the reference of inode 260 in the parent
         snapshot. So we issue an orphanization operation for inode 260 by
         emitting a rename operation with a destination path of "o260-6-0"
         and a source path of "d1/d2" - this source path is the value we
         stored in the reference earlier at step 2), corresponding to the
         ->full_path member of the reference, however that path is no longer
         valid due to the orphanization of the directory inode 259 in step 3).
         This makes the receiver fail since the path does not exists, it should
         have been "o259-6-0/d2".
      
      Fix this by recomputing the full path of a reference before emitting an
      orphanization if we previously orphanized any directory, since that
      directory could be a parent in the new path. This is a rare scenario so
      keeping it simple and not checking if that previously orphanized directory
      is in fact an ancestor of the inode we are trying to orphanize.
      
      A test case for fstests follows soon.
      
      CC: stable@vger.kernel.org # 4.4+
      Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3350eb1f
    • Filipe Manana's avatar
      btrfs: reschedule if necessary when logging directory items · 42e60fc1
      Filipe Manana authored
      commit bb56f02f upstream.
      
      Logging directories with many entries can take a significant amount of
      time, and in some cases monopolize a cpu/core for a long time if the
      logging task doesn't happen to block often enough.
      
      Johannes and Lu Fengqi reported test case generic/041 triggering a soft
      lockup when the kernel has CONFIG_SOFTLOCKUP_DETECTOR=y. For this test
      case we log an inode with 3002 hard links, and because the test removed
      one hard link before fsyncing the file, the inode logging causes the
      parent directory do be logged as well, which has 6004 directory items to
      log (3002 BTRFS_DIR_ITEM_KEY items plus 3002 BTRFS_DIR_INDEX_KEY items),
      so it can take a significant amount of time and trigger the soft lockup.
      
      So just make tree-log.c:log_dir_items() reschedule when necessary,
      releasing the current search path before doing so and then resume from
      where it was before the reschedule.
      
      The stack trace produced when the soft lockup happens is the following:
      
      [10480.277653] watchdog: BUG: soft lockup - CPU#2 stuck for 22s! [xfs_io:28172]
      [10480.279418] Modules linked in: dm_thin_pool dm_persistent_data (...)
      [10480.284915] irq event stamp: 29646366
      [10480.285987] hardirqs last  enabled at (29646365): [<ffffffff85249b66>] __slab_alloc.constprop.0+0x56/0x60
      [10480.288482] hardirqs last disabled at (29646366): [<ffffffff8579b00d>] irqentry_enter+0x1d/0x50
      [10480.290856] softirqs last  enabled at (4612): [<ffffffff85a00323>] __do_softirq+0x323/0x56c
      [10480.293615] softirqs last disabled at (4483): [<ffffffff85800dbf>] asm_call_on_stack+0xf/0x20
      [10480.296428] CPU: 2 PID: 28172 Comm: xfs_io Not tainted 5.9.0-rc4-default+ #1248
      [10480.298948] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-59-gc9ba527-rebuilt.opensuse.org 04/01/2014
      [10480.302455] RIP: 0010:__slab_alloc.constprop.0+0x19/0x60
      [10480.304151] Code: 86 e8 31 75 21 00 66 66 2e 0f 1f 84 00 00 00 (...)
      [10480.309558] RSP: 0018:ffffadbe09397a58 EFLAGS: 00000282
      [10480.311179] RAX: ffff8a495ab92840 RBX: 0000000000000282 RCX: 0000000000000006
      [10480.313242] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff85249b66
      [10480.315260] RBP: ffff8a497d04b740 R08: 0000000000000001 R09: 0000000000000001
      [10480.317229] R10: ffff8a497d044800 R11: ffff8a495ab93c40 R12: 0000000000000000
      [10480.319169] R13: 0000000000000000 R14: 0000000000000c40 R15: ffffffffc01daf70
      [10480.321104] FS:  00007fa1dc5c0e40(0000) GS:ffff8a497da00000(0000) knlGS:0000000000000000
      [10480.323559] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [10480.325235] CR2: 00007fa1dc5befb8 CR3: 0000000004f8a006 CR4: 0000000000170ea0
      [10480.327259] Call Trace:
      [10480.328286]  ? overwrite_item+0x1f0/0x5a0 [btrfs]
      [10480.329784]  __kmalloc+0x831/0xa20
      [10480.331009]  ? btrfs_get_32+0xb0/0x1d0 [btrfs]
      [10480.332464]  overwrite_item+0x1f0/0x5a0 [btrfs]
      [10480.333948]  log_dir_items+0x2ee/0x570 [btrfs]
      [10480.335413]  log_directory_changes+0x82/0xd0 [btrfs]
      [10480.336926]  btrfs_log_inode+0xc9b/0xda0 [btrfs]
      [10480.338374]  ? init_once+0x20/0x20 [btrfs]
      [10480.339711]  btrfs_log_inode_parent+0x8d3/0xd10 [btrfs]
      [10480.341257]  ? dget_parent+0x97/0x2e0
      [10480.342480]  btrfs_log_dentry_safe+0x3a/0x50 [btrfs]
      [10480.343977]  btrfs_sync_file+0x24b/0x5e0 [btrfs]
      [10480.345381]  do_fsync+0x38/0x70
      [10480.346483]  __x64_sys_fsync+0x10/0x20
      [10480.347703]  do_syscall_64+0x2d/0x70
      [10480.348891]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      [10480.350444] RIP: 0033:0x7fa1dc80970b
      [10480.351642] Code: 0f 05 48 3d 00 f0 ff ff 77 45 c3 0f 1f 40 00 48 (...)
      [10480.356952] RSP: 002b:00007fffb3d081d0 EFLAGS: 00000293 ORIG_RAX: 000000000000004a
      [10480.359458] RAX: ffffffffffffffda RBX: 0000562d93d45e40 RCX: 00007fa1dc80970b
      [10480.361426] RDX: 0000562d93d44ab0 RSI: 0000562d93d45e60 RDI: 0000000000000003
      [10480.363367] RBP: 0000000000000001 R08: 0000000000000000 R09: 00007fa1dc7b2a40
      [10480.365317] R10: 0000562d93d0e366 R11: 0000000000000293 R12: 0000000000000001
      [10480.367299] R13: 0000562d93d45290 R14: 0000562d93d45e40 R15: 0000562d93d45e60
      
      Link: https://lore.kernel.org/linux-btrfs/20180713090216.GC575@fnst.localdomain/
      
      Reported-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
      CC: stable@vger.kernel.org # 4.4+
      Tested-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.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>
      42e60fc1
    • Helge Deller's avatar
      scsi: mptfusion: Fix null pointer dereferences in mptscsih_remove() · 9d4ac27c
      Helge Deller authored
      commit 2f4843b1 upstream.
      
      The mptscsih_remove() function triggers a kernel oops if the Scsi_Host
      pointer (ioc->sh) is NULL, as can be seen in this syslog:
      
       ioc0: LSI53C1030 B2: Capabilities={Initiator,Target}
       Begin: Waiting for root file system ...
       scsi host2: error handler thread failed to spawn, error = -4
       mptspi: ioc0: WARNING - Unable to register controller with SCSI subsystem
       Backtrace:
        [<000000001045b7cc>] mptspi_probe+0x248/0x3d0 [mptspi]
        [<0000000040946470>] pci_device_probe+0x1ac/0x2d8
        [<0000000040add668>] really_probe+0x1bc/0x988
        [<0000000040ade704>] driver_probe_device+0x160/0x218
        [<0000000040adee24>] device_driver_attach+0x160/0x188
        [<0000000040adef90>] __driver_attach+0x144/0x320
        [<0000000040ad7c78>] bus_for_each_dev+0xd4/0x158
        [<0000000040adc138>] driver_attach+0x4c/0x80
        [<0000000040adb3ec>] bus_add_driver+0x3e0/0x498
        [<0000000040ae0130>] driver_register+0xf4/0x298
        [<00000000409450c4>] __pci_register_driver+0x78/0xa8
        [<000000000007d248>] mptspi_init+0x18c/0x1c4 [mptspi]
      
      This patch adds the necessary NULL-pointer checks.  Successfully tested on
      a HP C8000 parisc workstation with buggy SCSI drives.
      
      Link: https://lore.kernel.org/r/20201022090005.GA9000@ls3530.fritz.box
      
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9d4ac27c
    • Martin Fuzzey's avatar
      w1: mxc_w1: Fix timeout resolution problem leading to bus error · caeca56c
      Martin Fuzzey authored
      commit c9723750 upstream.
      
      On my platform (i.MX53) bus access sometimes fails with
      	w1_search: max_slave_count 64 reached, will continue next search.
      
      The reason is the use of jiffies to implement a 200us timeout in
      mxc_w1_ds2_touch_bit().
      On some platforms the jiffies timer resolution is insufficient for this.
      
      Fix by replacing jiffies by ktime_get().
      
      For consistency apply the same change to the other use of jiffies in
      mxc_w1_ds2_reset_bus().
      
      Fixes: f80b2581
      
       ("w1: mxc_w1: Optimize mxc_w1_ds2_touch_bit()")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarMartin Fuzzey <martin.fuzzey@flowbird.group>
      Link: https://lore.kernel.org/r/1601455030-6607-1-git-send-email-martin.fuzzey@flowbird.group
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      caeca56c
    • Wei Huang's avatar
      acpi-cpufreq: Honor _PSD table setting on new AMD CPUs · 3e1f2d01
      Wei Huang authored
      commit 5368512a upstream.
      
      acpi-cpufreq has a old quirk that overrides the _PSD table supplied by
      BIOS on AMD CPUs. However the _PSD table of new AMD CPUs (Family 19h+)
      now accurately reports the P-state dependency of CPU cores. Hence this
      quirk needs to be fixed in order to support new CPUs' frequency control.
      
      Fixes: acd31624
      
       ("acpi-cpufreq: Add quirk to disable _PSD usage on all AMD CPUs")
      Signed-off-by: default avatarWei Huang <wei.huang2@amd.com>
      [ rjw: Subject edit ]
      Cc: 3.10+ <stable@vger.kernel.org> # 3.10+
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3e1f2d01
    • Jamie Iles's avatar
      ACPI: debug: don't allow debugging when ACPI is disabled · 451c6a4d
      Jamie Iles authored
      commit 0fada277 upstream.
      
      If ACPI is disabled then loading the acpi_dbg module will result in the
      following splat when lock debugging is enabled.
      
        DEBUG_LOCKS_WARN_ON(lock->magic != lock)
        WARNING: CPU: 0 PID: 1 at kernel/locking/mutex.c:938 __mutex_lock+0xa10/0x1290
        Kernel panic - not syncing: panic_on_warn set ...
        CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.9.0-rc8+ #103
        Hardware name: linux,dummy-virt (DT)
        Call trace:
         dump_backtrace+0x0/0x4d8
         show_stack+0x34/0x48
         dump_stack+0x174/0x1f8
         panic+0x360/0x7a0
         __warn+0x244/0x2ec
         report_bug+0x240/0x398
         bug_handler+0x50/0xc0
         call_break_hook+0x160/0x1d8
         brk_handler+0x30/0xc0
         do_debug_exception+0x184/0x340
         el1_dbg+0x48/0xb0
         el1_sync_handler+0x170/0x1c8
         el1_sync+0x80/0x100
         __mutex_lock+0xa10/0x1290
         mutex_lock_nested+0x6c/0xc0
         acpi_register_debugger+0x40/0x88
         acpi_aml_init+0xc4/0x114
         do_one_initcall+0x24c/0xb10
         kernel_init_freeable+0x690/0x728
         kernel_init+0x20/0x1e8
         ret_from_fork+0x10/0x18
      
      This is because acpi_debugger.lock has not been initialized as
      acpi_debugger_init() is not called when ACPI is disabled.  Fail module
      loading to avoid this and any subsequent problems that might arise by
      trying to debug AML when ACPI is disabled.
      
      Fixes: 8cfb0cdf
      
       ("ACPI / debugger: Add IO interface to access debugger functionalities")
      Reviewed-by: default avatarHanjun Guo <guohanjun@huawei.com>
      Signed-off-by: default avatarJamie Iles <jamie@nuviainc.com>
      Cc: 4.10+ <stable@vger.kernel.org> # 4.10+
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      451c6a4d
    • Alex Hung's avatar
      ACPI: video: use ACPI backlight for HP 635 Notebook · 16d8a0bd
      Alex Hung authored
      commit b226faab upstream.
      
      The default backlight interface is AMD's radeon_bl0 which does not
      work on this system, so use the ACPI backlight interface on it
      instead.
      
      BugLink: https://bugs.launchpad.net/bugs/1894667
      
      
      Cc: All applicable <stable@vger.kernel.org>
      Signed-off-by: default avatarAlex Hung <alex.hung@canonical.com>
      [ rjw: Changelog edits ]
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      16d8a0bd
    • Ben Hutchings's avatar
      ACPI / extlog: Check for RDMSR failure · 423ea50f
      Ben Hutchings authored
      commit 7cecb47f upstream.
      
      extlog_init() uses rdmsrl() to read an MSR, which on older CPUs
      provokes a error message at boot:
      
          unchecked MSR access error: RDMSR from 0x179 at rIP: 0xcd047307 (native_read_msr+0x7/0x40)
      
      Use rdmsrl_safe() instead, and return -ENODEV if it fails.
      
      Reported-by: jim@photojim.ca
      References: https://bugs.debian.org/971058
      
      
      Cc: All applicable <stable@vger.kernel.org>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      423ea50f
    • Ashish Sangwan's avatar
      NFS: fix nfs_path in case of a rename retry · 924bdf1a
      Ashish Sangwan authored
      commit 247db735
      
       upstream.
      
      We are generating incorrect path in case of rename retry because
      we are restarting from wrong dentry. We should restart from the
      dentry which was received in the call to nfs_path.
      
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarAshish Sangwan <ashishsangwan2@gmail.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      924bdf1a
    • Jan Kara's avatar
      fs: Don't invalidate page buffers in block_write_full_page() · 7ed80e77
      Jan Kara authored
      commit 6dbf7bb5
      
       upstream.
      
      If block_write_full_page() is called for a page that is beyond current
      inode size, it will truncate page buffers for the page and return 0.
      This logic has been added in 2.5.62 in commit 81eb69062588 ("fix ext3
      BUG due to race with truncate") in history.git tree to fix a problem
      with ext3 in data=ordered mode. This particular problem doesn't exist
      anymore because ext3 is long gone and ext4 handles ordered data
      differently. Also normally buffers are invalidated by truncate code and
      there's no need to specially handle this in ->writepage() code.
      
      This invalidation of page buffers in block_write_full_page() is causing
      issues to filesystems (e.g. ext4 or ocfs2) when block device is shrunk
      under filesystem's hands and metadata buffers get discarded while being
      tracked by the journalling layer. Although it is obviously "not
      supported" it can cause kernel crashes like:
      
      [ 7986.689400] BUG: unable to handle kernel NULL pointer dereference at
      +0000000000000008
      [ 7986.697197] PGD 0 P4D 0
      [ 7986.699724] Oops: 0002 [#1] SMP PTI
      [ 7986.703200] CPU: 4 PID: 203778 Comm: jbd2/dm-3-8 Kdump: loaded Tainted: G
      +O     --------- -  - 4.18.0-147.5.0.5.h126.eulerosv2r9.x86_64 #1
      [ 7986.716438] Hardware name: Huawei RH2288H V3/BC11HGSA0, BIOS 1.57 08/11/2015
      [ 7986.723462] RIP: 0010:jbd2_journal_grab_journal_head+0x1b/0x40 [jbd2]
      ...
      [ 7986.810150] Call Trace:
      [ 7986.812595]  __jbd2_journal_insert_checkpoint+0x23/0x70 [jbd2]
      [ 7986.818408]  jbd2_journal_commit_transaction+0x155f/0x1b60 [jbd2]
      [ 7986.836467]  kjournald2+0xbd/0x270 [jbd2]
      
      which is not great. The crash happens because bh->b_private is suddently
      NULL although BH_JBD flag is still set (this is because
      block_invalidatepage() cleared BH_Mapped flag and subsequent bh lookup
      found buffer without BH_Mapped set, called init_page_buffers() which has
      rewritten bh->b_private). So just remove the invalidation in
      block_write_full_page().
      
      Note that the buffer cache invalidation when block device changes size
      is already careful to avoid similar problems by using
      invalidate_mapping_pages() which skips busy buffers so it was only this
      odd block_write_full_page() behavior that could tear down bdev buffers
      under filesystem's hands.
      Reported-by: default avatarYe Bin <yebin10@huawei.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7ed80e77
    • Marek Behún's avatar
      leds: bcm6328, bcm6358: use devres LED registering function · 286ac996
      Marek Behún authored
      commit ff5c89d4
      
       upstream.
      
      These two drivers do not provide remove method and use devres for
      allocation of other resources, yet they use led_classdev_register
      instead of the devres variant, devm_led_classdev_register.
      
      Fix this.
      Signed-off-by: default avatarMarek Behún <marek.behun@nic.cz>
      Cc: Álvaro Fernández Rojas <noltari@gmail.com>
      Cc: Kevin Cernekee <cernekee@gmail.com>
      Cc: Jaedon Shin <jaedon.shin@gmail.com>
      Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
      Cc: stable@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      286ac996
    • Kim Phillips's avatar
      perf/x86/amd/ibs: Fix raw sample data accumulation · 45194d69
      Kim Phillips authored
      commit 36e1be8a upstream.
      
      Neither IbsBrTarget nor OPDATA4 are populated in IBS Fetch mode.
      Don't accumulate them into raw sample user data in that case.
      
      Also, in Fetch mode, add saving the IBS Fetch Control Extended MSR.
      
      Technically, there is an ABI change here with respect to the IBS raw
      sample data format, but I don't see any perf driver version information
      being included in perf.data file headers, but, existing users can detect
      whether the size of the sample record has reduced by 8 bytes to
      determine whether the IBS driver has this fix.
      
      Fixes: 904cb367
      
       ("perf/x86/amd/ibs: Update IBS MSRs and feature definitions")
      Reported-by: default avatarStephane Eranian <stephane.eranian@google.com>
      Signed-off-by: default avatarKim Phillips <kim.phillips@amd.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/20200908214740.18097-6-kim.phillips@amd.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      45194d69
    • Kim Phillips's avatar
      perf/x86/amd/ibs: Don't include randomized bits in get_ibs_op_count() · d59681a8
      Kim Phillips authored
      commit 680d6963 upstream.
      
      get_ibs_op_count() adds hardware's current count (IbsOpCurCnt) bits
      to its count regardless of hardware's valid status.
      
      According to the PPR for AMD Family 17h Model 31h B0 55803 Rev 0.54,
      if the counter rolls over, valid status is set, and the lower 7 bits
      of IbsOpCurCnt are randomized by hardware.
      
      Don't include those bits in the driver's event count.
      
      Fixes: 8b1e1363
      
       ("perf/x86-ibs: Fix usage of IBS op current count")
      Signed-off-by: default avatarKim Phillips <kim.phillips@amd.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d59681a8
    • Song Liu's avatar
      md/raid5: fix oops during stripe resizing · 10a02c90
      Song Liu authored
      commit b44c018c
      
       upstream.
      
      KoWei reported crash during raid5 reshape:
      
      [ 1032.252932] Oops: 0002 [#1] SMP PTI
      [...]
      [ 1032.252943] RIP: 0010:memcpy_erms+0x6/0x10
      [...]
      [ 1032.252947] RSP: 0018:ffffba1ac0c03b78 EFLAGS: 00010286
      [ 1032.252949] RAX: 0000784ac0000000 RBX: ffff91bec3d09740 RCX: 0000000000001000
      [ 1032.252951] RDX: 0000000000001000 RSI: ffff91be6781c000 RDI: 0000784ac0000000
      [ 1032.252953] RBP: ffffba1ac0c03bd8 R08: 0000000000001000 R09: ffffba1ac0c03bf8
      [ 1032.252954] R10: 0000000000000000 R11: 0000000000000000 R12: ffffba1ac0c03bf8
      [ 1032.252955] R13: 0000000000001000 R14: 0000000000000000 R15: 0000000000000000
      [ 1032.252958] FS:  0000000000000000(0000) GS:ffff91becf500000(0000) knlGS:0000000000000000
      [ 1032.252959] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [ 1032.252961] CR2: 0000784ac0000000 CR3: 000000031780a002 CR4: 00000000001606e0
      [ 1032.252962] Call Trace:
      [ 1032.252969]  ? async_memcpy+0x179/0x1000 [async_memcpy]
      [ 1032.252977]  ? raid5_release_stripe+0x8e/0x110 [raid456]
      [ 1032.252982]  handle_stripe_expansion+0x15a/0x1f0 [raid456]
      [ 1032.252988]  handle_stripe+0x592/0x1270 [raid456]
      [ 1032.252993]  handle_active_stripes.isra.0+0x3cb/0x5a0 [raid456]
      [ 1032.252999]  raid5d+0x35c/0x550 [raid456]
      [ 1032.253002]  ? schedule+0x42/0xb0
      [ 1032.253006]  ? schedule_timeout+0x10e/0x160
      [ 1032.253011]  md_thread+0x97/0x160
      [ 1032.253015]  ? wait_woken+0x80/0x80
      [ 1032.253019]  kthread+0x104/0x140
      [ 1032.253022]  ? md_start_sync+0x60/0x60
      [ 1032.253024]  ? kthread_park+0x90/0x90
      [ 1032.253027]  ret_from_fork+0x35/0x40
      
      This is because cache_size_mutex was unlocked too early in resize_stripes,
      which races with grow_one_stripe() that grow_one_stripe() allocates a
      stripe with wrong pool_size.
      
      Fix this issue by unlocking cache_size_mutex after updating pool_size.
      
      Cc: <stable@vger.kernel.org> # v4.4+
      Reported-by: default avatarKoWei Sung <winders@amazon.com>
      Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      10a02c90
    • Chao Leng's avatar
      nvme-rdma: fix crash when connect rejected · f1750073
      Chao Leng authored
      [ Upstream commit 43efdb8e
      
       ]
      
      A crash can happened when a connect is rejected.   The host establishes
      the connection after received ConnectReply, and then continues to send
      the fabrics Connect command.  If the controller does not receive the
      ReadyToUse capsule, host may receive a ConnectReject reply.
      
      Call nvme_rdma_destroy_queue_ib after the host received the
      RDMA_CM_EVENT_REJECTED event.  Then when the fabrics Connect command
      times out, nvme_rdma_timeout calls nvme_rdma_complete_rq to fail the
      request.  A crash happenes due to use after free in
      nvme_rdma_complete_rq.
      
      nvme_rdma_destroy_queue_ib is redundant when handling the
      RDMA_CM_EVENT_REJECTED event as nvme_rdma_destroy_queue_ib is already
      called in connection failure handler.
      Signed-off-by: default avatarChao Leng <lengchao@huawei.com>
      Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f1750073
    • Douglas Gilbert's avatar
      sgl_alloc_order: fix memory leak · 04472a1e
      Douglas Gilbert authored
      [ Upstream commit b2a182a4
      
       ]
      
      sgl_alloc_order() can fail when 'length' is large on a memory
      constrained system. When order > 0 it will potentially be
      making several multi-page allocations with the later ones more
      likely to fail than the earlier one. So it is important that
      sgl_alloc_order() frees up any pages it has obtained before
      returning NULL. In the case when order > 0 it calls the wrong
      free page function and leaks. In testing the leak was
      sufficient to bring down my 8 GiB laptop with OOM.
      Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
      Signed-off-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      04472a1e