1. 04 Jan, 2020 40 commits
    • Josef Bacik's avatar
      btrfs: don't double lock the subvol_sem for rename exchange · 85562d8a
      Josef Bacik authored
      [ Upstream commit 943eb3bf ]
      
      If we're rename exchanging two subvols we'll try to lock this lock
      twice, which is bad.  Just lock once if either of the ino's are subvols.
      
      Fixes: cdd1fedf ("btrfs: add support for RENAME_EXCHANGE and RENAME_WHITEOUT")
      CC: stable@vger.kernel.org # 4.4+
      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 avatarSasha Levin <sashal@kernel.org>
      85562d8a
    • Guenter Roeck's avatar
      usb: xhci: Fix build warning seen with CONFIG_PM=n · 795b4ef8
      Guenter Roeck authored
      [ Upstream commit 6056a0f8 ]
      
      The following build warning is seen if CONFIG_PM is disabled.
      
      drivers/usb/host/xhci-pci.c:498:13: warning:
      	unused function 'xhci_pci_shutdown'
      
      Fixes: f2c710f7 ("usb: xhci: only set D3hot for pci device")
      Cc: Henry Lin <henryl@nvidia.com>
      Cc: stable@vger.kernel.org	# all stable releases with f2c710f7Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Acked-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20191218011911.6907-1-linux@roeck-us.netSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      795b4ef8
    • Faiz Abbas's avatar
      Revert "mmc: sdhci: Fix incorrect switch to HS mode" · 69f225a5
      Faiz Abbas authored
      commit 07bcc411 upstream.
      
      This reverts commit c894e33d.
      
      This commit aims to treat SD High speed and SDR25 as the same while
      setting UHS Timings in HOST_CONTROL2 which leads to failures with some
      SD cards in AM65x. Revert this commit.
      
      The issue this commit was trying to fix can be implemented in a platform
      specific callback instead of common sdhci code.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarFaiz Abbas <faiz_abbas@ti.com>
      Acked-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Link: https://lore.kernel.org/r/20191128110422.25917-1-faiz_abbas@ti.comSigned-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      69f225a5
    • Omar Sandoval's avatar
      btrfs: don't prematurely free work in reada_start_machine_worker() · c3c7c0cc
      Omar Sandoval authored
      [ Upstream commit e732fe95 ]
      
      Currently, reada_start_machine_worker() frees the reada_machine_work and
      then calls __reada_start_machine() to do readahead. This is another
      potential instance of the bug in "btrfs: don't prematurely free work in
      run_ordered_work()".
      
      There _might_ already be a deadlock here: reada_start_machine_worker()
      can depend on itself through stacked filesystems (__read_start_machine()
      -> reada_start_machine_dev() -> reada_tree_block_flagged() ->
      read_extent_buffer_pages() -> submit_one_bio() ->
      btree_submit_bio_hook() -> btrfs_map_bio() -> submit_stripe_bio() ->
      submit_bio() onto a loop device can trigger readahead on the lower
      filesystem).
      
      Either way, let's fix it by freeing the work at the end.
      Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
      Signed-off-by: default avatarOmar Sandoval <osandov@fb.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c3c7c0cc
    • Russell King's avatar
      net: phy: initialise phydev speed and duplex sanely · 5baa2f38
      Russell King authored
      [ Upstream commit a5d66f81 ]
      
      When a phydev is created, the speed and duplex are set to zero and
      -1 respectively, rather than using the predefined SPEED_UNKNOWN and
      DUPLEX_UNKNOWN constants.
      
      There is a window at initialisation time where we may report link
      down using the 0/-1 values.  Tidy this up and use the predefined
      constants, so debug doesn't complain with:
      
      "Unsupported (update phy-core.c)/Unsupported (update phy-core.c)"
      
      when the speed and duplex settings are printed.
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5baa2f38
    • Hewenliang's avatar
      libtraceevent: Fix memory leakage in copy_filter_type · 9d47b11b
      Hewenliang authored
      [ Upstream commit 10992af6 ]
      
      It is necessary to free the memory that we have allocated when error occurs.
      
      Fixes: ef3072cd ("tools lib traceevent: Get rid of die in add_filter_type()")
      Signed-off-by: default avatarHewenliang <hewenliang4@huawei.com>
      Reviewed-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
      Link: http://lore.kernel.org/lkml/20191119014415.57210-1-hewenliang4@huawei.comSigned-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9d47b11b
    • Michael Ellerman's avatar
      crypto: vmx - Avoid weird build failures · c07956c4
      Michael Ellerman authored
      [ Upstream commit 4ee812f6 ]
      
      In the vmx crypto Makefile we assign to a variable called TARGET and
      pass that to the aesp8-ppc.pl and ghashp8-ppc.pl scripts.
      
      The variable is meant to describe what flavour of powerpc we're
      building for, eg. either 32 or 64-bit, and big or little endian.
      
      Unfortunately TARGET is a fairly common name for a make variable, and
      if it happens that TARGET is specified as a command line parameter to
      make, the value specified on the command line will override our value.
      
      In particular this can happen if the kernel Makefile is driven by an
      external Makefile that uses TARGET for something.
      
      This leads to weird build failures, eg:
        nonsense  at /build/linux/drivers/crypto/vmx/ghashp8-ppc.pl line 45.
        /linux/drivers/crypto/vmx/Makefile:20: recipe for target 'drivers/crypto/vmx/ghashp8-ppc.S' failed
      
      Which shows that we passed an empty value for $(TARGET) to the perl
      script, confirmed with make V=1:
      
        perl /linux/drivers/crypto/vmx/ghashp8-ppc.pl  > drivers/crypto/vmx/ghashp8-ppc.S
      
      We can avoid this confusion by using override, to tell make that we
      don't want anything to override our variable, even a value specified
      on the command line. We can also use a less common name, given the
      script calls it "flavour", let's use that.
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c07956c4
    • Corentin Labbe's avatar
      crypto: sun4i-ss - Fix 64-bit size_t warnings on sun4i-ss-hash.c · ab4180b2
      Corentin Labbe authored
      [ Upstream commit a7126603 ]
      
      If you try to compile this driver on a 64-bit platform then you
      will get warnings because it mixes size_t with unsigned int which
      only works on 32-bit.
      
      This patch fixes all of the warnings on sun4i-ss-hash.c.
      Signed-off-by: default avatarCorentin Labbe <clabbe.montjoie@gmail.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ab4180b2
    • Andy Shevchenko's avatar
      fbtft: Make sure string is NULL terminated · 0ef977d8
      Andy Shevchenko authored
      [ Upstream commit 21f58548 ]
      
      New GCC warns about inappropriate use of strncpy():
      
      drivers/staging/fbtft/fbtft-core.c: In function ‘fbtft_framebuffer_alloc’:
      drivers/staging/fbtft/fbtft-core.c:665:2: warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
        665 |  strncpy(info->fix.id, dev->driver->name, 16);
            |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      Later on the copy is being used with the assumption to be NULL terminated.
      Make sure string is NULL terminated by switching to snprintf().
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Link: https://lore.kernel.org/r/20191120095716.26628-1-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0ef977d8
    • Johannes Berg's avatar
      iwlwifi: check kasprintf() return value · f0a38523
      Johannes Berg authored
      [ Upstream commit 5974fbb5 ]
      
      kasprintf() can fail, we should check the return value.
      
      Fixes: 5ed540ae ("iwlwifi: use mac80211 throughput trigger")
      Fixes: 8ca151b5 ("iwlwifi: add the MVM driver")
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarLuca Coelho <luciano.coelho@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f0a38523
    • Adrian Hunter's avatar
      x86/insn: Add some Intel instructions to the opcode map · 0421b439
      Adrian Hunter authored
      [ Upstream commit b980be18 ]
      
      Add to the opcode map the following instructions:
              cldemote
              tpause
              umonitor
              umwait
              movdiri
              movdir64b
              enqcmd
              enqcmds
              encls
              enclu
              enclv
              pconfig
              wbnoinvd
      
      For information about the instructions, refer Intel SDM May 2019
      (325462-070US) and Intel Architecture Instruction Set Extensions
      May 2019 (319433-037).
      
      The instruction decoding can be tested using the perf tools'
      "x86 instruction decoder - new instructions" test as folllows:
      
        $ perf test -v "new " 2>&1 | grep -i cldemote
        Decoded ok: 0f 1c 00                    cldemote (%eax)
        Decoded ok: 0f 1c 05 78 56 34 12        cldemote 0x12345678
        Decoded ok: 0f 1c 84 c8 78 56 34 12     cldemote 0x12345678(%eax,%ecx,8)
        Decoded ok: 0f 1c 00                    cldemote (%rax)
        Decoded ok: 41 0f 1c 00                 cldemote (%r8)
        Decoded ok: 0f 1c 04 25 78 56 34 12     cldemote 0x12345678
        Decoded ok: 0f 1c 84 c8 78 56 34 12     cldemote 0x12345678(%rax,%rcx,8)
        Decoded ok: 41 0f 1c 84 c8 78 56 34 12  cldemote 0x12345678(%r8,%rcx,8)
        $ perf test -v "new " 2>&1 | grep -i tpause
        Decoded ok: 66 0f ae f3                 tpause %ebx
        Decoded ok: 66 0f ae f3                 tpause %ebx
        Decoded ok: 66 41 0f ae f0              tpause %r8d
        $ perf test -v "new " 2>&1 | grep -i umonitor
        Decoded ok: 67 f3 0f ae f0              umonitor %ax
        Decoded ok: f3 0f ae f0                 umonitor %eax
        Decoded ok: 67 f3 0f ae f0              umonitor %eax
        Decoded ok: f3 0f ae f0                 umonitor %rax
        Decoded ok: 67 f3 41 0f ae f0           umonitor %r8d
        $ perf test -v "new " 2>&1 | grep -i umwait
        Decoded ok: f2 0f ae f0                 umwait %eax
        Decoded ok: f2 0f ae f0                 umwait %eax
        Decoded ok: f2 41 0f ae f0              umwait %r8d
        $ perf test -v "new " 2>&1 | grep -i movdiri
        Decoded ok: 0f 38 f9 03                 movdiri %eax,(%ebx)
        Decoded ok: 0f 38 f9 88 78 56 34 12     movdiri %ecx,0x12345678(%eax)
        Decoded ok: 48 0f 38 f9 03              movdiri %rax,(%rbx)
        Decoded ok: 48 0f 38 f9 88 78 56 34 12  movdiri %rcx,0x12345678(%rax)
        $ perf test -v "new " 2>&1 | grep -i movdir64b
        Decoded ok: 66 0f 38 f8 18              movdir64b (%eax),%ebx
        Decoded ok: 66 0f 38 f8 88 78 56 34 12  movdir64b 0x12345678(%eax),%ecx
        Decoded ok: 67 66 0f 38 f8 1c           movdir64b (%si),%bx
        Decoded ok: 67 66 0f 38 f8 8c 34 12     movdir64b 0x1234(%si),%cx
        Decoded ok: 66 0f 38 f8 18              movdir64b (%rax),%rbx
        Decoded ok: 66 0f 38 f8 88 78 56 34 12  movdir64b 0x12345678(%rax),%rcx
        Decoded ok: 67 66 0f 38 f8 18           movdir64b (%eax),%ebx
        Decoded ok: 67 66 0f 38 f8 88 78 56 34 12       movdir64b 0x12345678(%eax),%ecx
        $ perf test -v "new " 2>&1 | grep -i enqcmd
        Decoded ok: f2 0f 38 f8 18              enqcmd (%eax),%ebx
        Decoded ok: f2 0f 38 f8 88 78 56 34 12  enqcmd 0x12345678(%eax),%ecx
        Decoded ok: 67 f2 0f 38 f8 1c           enqcmd (%si),%bx
        Decoded ok: 67 f2 0f 38 f8 8c 34 12     enqcmd 0x1234(%si),%cx
        Decoded ok: f3 0f 38 f8 18              enqcmds (%eax),%ebx
        Decoded ok: f3 0f 38 f8 88 78 56 34 12  enqcmds 0x12345678(%eax),%ecx
        Decoded ok: 67 f3 0f 38 f8 1c           enqcmds (%si),%bx
        Decoded ok: 67 f3 0f 38 f8 8c 34 12     enqcmds 0x1234(%si),%cx
        Decoded ok: f2 0f 38 f8 18              enqcmd (%rax),%rbx
        Decoded ok: f2 0f 38 f8 88 78 56 34 12  enqcmd 0x12345678(%rax),%rcx
        Decoded ok: 67 f2 0f 38 f8 18           enqcmd (%eax),%ebx
        Decoded ok: 67 f2 0f 38 f8 88 78 56 34 12       enqcmd 0x12345678(%eax),%ecx
        Decoded ok: f3 0f 38 f8 18              enqcmds (%rax),%rbx
        Decoded ok: f3 0f 38 f8 88 78 56 34 12  enqcmds 0x12345678(%rax),%rcx
        Decoded ok: 67 f3 0f 38 f8 18           enqcmds (%eax),%ebx
        Decoded ok: 67 f3 0f 38 f8 88 78 56 34 12       enqcmds 0x12345678(%eax),%ecx
        $ perf test -v "new " 2>&1 | grep -i enqcmds
        Decoded ok: f3 0f 38 f8 18              enqcmds (%eax),%ebx
        Decoded ok: f3 0f 38 f8 88 78 56 34 12  enqcmds 0x12345678(%eax),%ecx
        Decoded ok: 67 f3 0f 38 f8 1c           enqcmds (%si),%bx
        Decoded ok: 67 f3 0f 38 f8 8c 34 12     enqcmds 0x1234(%si),%cx
        Decoded ok: f3 0f 38 f8 18              enqcmds (%rax),%rbx
        Decoded ok: f3 0f 38 f8 88 78 56 34 12  enqcmds 0x12345678(%rax),%rcx
        Decoded ok: 67 f3 0f 38 f8 18           enqcmds (%eax),%ebx
        Decoded ok: 67 f3 0f 38 f8 88 78 56 34 12       enqcmds 0x12345678(%eax),%ecx
        $ perf test -v "new " 2>&1 | grep -i encls
        Decoded ok: 0f 01 cf                    encls
        Decoded ok: 0f 01 cf                    encls
        $ perf test -v "new " 2>&1 | grep -i enclu
        Decoded ok: 0f 01 d7                    enclu
        Decoded ok: 0f 01 d7                    enclu
        $ perf test -v "new " 2>&1 | grep -i enclv
        Decoded ok: 0f 01 c0                    enclv
        Decoded ok: 0f 01 c0                    enclv
        $ perf test -v "new " 2>&1 | grep -i pconfig
        Decoded ok: 0f 01 c5                    pconfig
        Decoded ok: 0f 01 c5                    pconfig
        $ perf test -v "new " 2>&1 | grep -i wbnoinvd
        Decoded ok: f3 0f 09                    wbnoinvd
        Decoded ok: f3 0f 09                    wbnoinvd
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: x86@kernel.org
      Link: http://lore.kernel.org/lkml/20191115135447.6519-3-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0421b439
    • Chuhong Yuan's avatar
      spi: st-ssc4: add missed pm_runtime_disable · b14731b9
      Chuhong Yuan authored
      [ Upstream commit cd050abe ]
      
      The driver forgets to call pm_runtime_disable in probe failure
      and remove.
      Add the missed calls to fix it.
      Signed-off-by: default avatarChuhong Yuan <hslester96@gmail.com>
      Link: https://lore.kernel.org/r/20191118024848.21645-1-hslester96@gmail.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b14731b9
    • Omar Sandoval's avatar
      btrfs: don't prematurely free work in run_ordered_work() · 4abc387b
      Omar Sandoval authored
      [ Upstream commit c495dcd6 ]
      
      We hit the following very strange deadlock on a system with Btrfs on a
      loop device backed by another Btrfs filesystem:
      
      1. The top (loop device) filesystem queues an async_cow work item from
         cow_file_range_async(). We'll call this work X.
      2. Worker thread A starts work X (normal_work_helper()).
      3. Worker thread A executes the ordered work for the top filesystem
         (run_ordered_work()).
      4. Worker thread A finishes the ordered work for work X and frees X
         (work->ordered_free()).
      5. Worker thread A executes another ordered work and gets blocked on I/O
         to the bottom filesystem (still in run_ordered_work()).
      6. Meanwhile, the bottom filesystem allocates and queues an async_cow
         work item which happens to be the recently-freed X.
      7. The workqueue code sees that X is already being executed by worker
         thread A, so it schedules X to be executed _after_ worker thread A
         finishes (see the find_worker_executing_work() call in
         process_one_work()).
      
      Now, the top filesystem is waiting for I/O on the bottom filesystem, but
      the bottom filesystem is waiting for the top filesystem to finish, so we
      deadlock.
      
      This happens because we are breaking the workqueue assumption that a
      work item cannot be recycled while it still depends on other work. Fix
      it by waiting to free the work item until we are done with all of the
      related ordered work.
      
      P.S.:
      
      One might ask why the workqueue code doesn't try to detect a recycled
      work item. It actually does try by checking whether the work item has
      the same work function (find_worker_executing_work()), but in our case
      the function is the same. This is the only key that the workqueue code
      has available to compare, short of adding an additional, layer-violating
      "custom key". Considering that we're the only ones that have ever hit
      this, we should just play by the rules.
      
      Unfortunately, we haven't been able to create a minimal reproducer other
      than our full container setup using a compress-force=zstd filesystem on
      top of another compress-force=zstd filesystem.
      Suggested-by: default avatarTejun Heo <tj@kernel.org>
      Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
      Signed-off-by: default avatarOmar Sandoval <osandov@fb.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4abc387b
    • Omar Sandoval's avatar
      btrfs: don't prematurely free work in end_workqueue_fn() · 2d3ff930
      Omar Sandoval authored
      [ Upstream commit 9be490f1 ]
      
      Currently, end_workqueue_fn() frees the end_io_wq entry (which embeds
      the work item) and then calls bio_endio(). This is another potential
      instance of the bug in "btrfs: don't prematurely free work in
      run_ordered_work()".
      
      In particular, the endio call may depend on other work items. For
      example, btrfs_end_dio_bio() can call btrfs_subio_endio_read() ->
      __btrfs_correct_data_nocsum() -> dio_read_error() ->
      submit_dio_repair_bio(), which submits a bio that is also completed
      through a end_workqueue_fn() work item. However,
      __btrfs_correct_data_nocsum() waits for the newly submitted bio to
      complete, thus it depends on another work item.
      
      This example currently usually works because we use different workqueue
      helper functions for BTRFS_WQ_ENDIO_DATA and BTRFS_WQ_ENDIO_DIO_REPAIR.
      However, it may deadlock with stacked filesystems and is fragile
      overall. The proper fix is to free the work item at the very end of the
      work function, so let's do that.
      Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
      Signed-off-by: default avatarOmar Sandoval <osandov@fb.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2d3ff930
    • Eugeniu Rosca's avatar
      mmc: tmio: Add MMC_CAP_ERASE to allow erase/discard/trim requests · ff38837d
      Eugeniu Rosca authored
      [ Upstream commit c9184346 ]
      
      Isolated initially to renesas_sdhi_internal_dmac [1], Ulf suggested
      adding MMC_CAP_ERASE to the TMIO mmc core:
      
      On Fri, Nov 15, 2019 at 10:27:25AM +0100, Ulf Hansson wrote:
       -- snip --
       This test and due to the discussions with Wolfram and you in this
       thread, I would actually suggest that you enable MMC_CAP_ERASE for all
       tmio variants, rather than just for this particular one.
      
       In other words, set the cap in tmio_mmc_host_probe() should be fine,
       as it seems none of the tmio variants supports HW busy detection at
       this point.
       -- snip --
      
      Testing on R-Car H3ULCB-KF doesn't reveal any issues (v5.4-rc7):
      
      root@rcar-gen3:~# lsblk
      NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
      mmcblk0      179:0    0 59.2G  0 disk  <--- eMMC
      mmcblk0boot0 179:8    0    4M  1 disk
      mmcblk0boot1 179:16   0    4M  1 disk
      mmcblk1      179:24   0   30G  0 disk  <--- SD card
      
      root@rcar-gen3:~# time blkdiscard /dev/mmcblk0
      real    0m8.659s
      user    0m0.001s
      sys     0m1.920s
      
      root@rcar-gen3:~# time blkdiscard /dev/mmcblk1
      real    0m1.176s
      user    0m0.001s
      sys     0m0.124s
      
      [1] https://lore.kernel.org/linux-renesas-soc/20191112134808.23546-1-erosca@de.adit-jv.com/
      
      Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: Andrew Gabbasov <andrew_gabbasov@mentor.com>
      Originally-by: default avatarHarish Jenny K N <harish_kandiga@mentor.com>
      Suggested-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Reviewed-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ff38837d
    • Chuhong Yuan's avatar
      spi: tegra20-slink: add missed clk_unprepare · 4f43b396
      Chuhong Yuan authored
      [ Upstream commit 04358e40 ]
      
      The driver misses calling clk_unprepare in probe failure and remove.
      Add the calls to fix it.
      Signed-off-by: default avatarChuhong Yuan <hslester96@gmail.com>
      Link: https://lore.kernel.org/r/20191115083122.12278-1-hslester96@gmail.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4f43b396
    • Wang Xuerui's avatar
      iwlwifi: mvm: fix unaligned read of rx_pkt_status · b5a56a8f
      Wang Xuerui authored
      [ Upstream commit c5aaa8be ]
      
      This is present since the introduction of iwlmvm.
      Example stack trace on MIPS:
      
      [<ffffffffc0789328>] iwl_mvm_rx_rx_mpdu+0xa8/0xb88 [iwlmvm]
      [<ffffffffc0632b40>] iwl_pcie_rx_handle+0x420/0xc48 [iwlwifi]
      
      Tested with a Wireless AC 7265 for ~6 months, confirmed to fix the
      problem. No other unaligned accesses are spotted yet.
      Signed-off-by: default avatarWang Xuerui <wangxuerui@qiniu.com>
      Signed-off-by: default avatarLuca Coelho <luciano.coelho@intel.com>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b5a56a8f
    • Lianbo Jiang's avatar
      x86/crash: Add a forward declaration of struct kimage · d2d4a2f6
      Lianbo Jiang authored
      [ Upstream commit 112eee5d ]
      
      Add a forward declaration of struct kimage to the crash.h header because
      future changes will invoke a crash-specific function from the realmode
      init path and the compiler will complain otherwise like this:
      
        In file included from arch/x86/realmode/init.c:11:
        ./arch/x86/include/asm/crash.h:5:32: warning: ‘struct kimage’ declared inside\
         parameter list will not be visible outside of this definition or declaration
            5 | int crash_load_segments(struct kimage *image);
              |                                ^~~~~~
        ./arch/x86/include/asm/crash.h:6:37: warning: ‘struct kimage’ declared inside\
         parameter list will not be visible outside of this definition or declaration
            6 | int crash_copy_backup_region(struct kimage *image);
              |                                     ^~~~~~
        ./arch/x86/include/asm/crash.h:7:39: warning: ‘struct kimage’ declared inside\
         parameter list will not be visible outside of this definition or declaration
            7 | int crash_setup_memmap_entries(struct kimage *image,
              |
      
       [ bp: Rewrite the commit message. ]
      Reported-by: default avatarkbuild test robot <lkp@intel.com>
      Signed-off-by: default avatarLianbo Jiang <lijiang@redhat.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: bhe@redhat.com
      Cc: d.hatayama@fujitsu.com
      Cc: dhowells@redhat.com
      Cc: dyoung@redhat.com
      Cc: ebiederm@xmission.com
      Cc: horms@verge.net.au
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jürgen Gross <jgross@suse.com>
      Cc: kexec@lists.infradead.org
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Cc: vgoyal@redhat.com
      Cc: x86-ml <x86@kernel.org>
      Link: https://lkml.kernel.org/r/20191108090027.11082-4-lijiang@redhat.com
      Link: https://lkml.kernel.org/r/201910310233.EJRtTMWP%25lkp@intel.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      d2d4a2f6
    • Viresh Kumar's avatar
      cpufreq: Register drivers only after CPU devices have been registered · b5a67ca2
      Viresh Kumar authored
      [ Upstream commit 46770be0 ]
      
      The cpufreq core heavily depends on the availability of the struct
      device for CPUs and if they aren't available at the time cpufreq driver
      is registered, we will never succeed in making cpufreq work.
      
      This happens due to following sequence of events:
      
      - cpufreq_register_driver()
        - subsys_interface_register()
        - return 0; //successful registration of driver
      
      ... at a later point of time
      
      - register_cpu();
        - device_register();
          - bus_probe_device();
            - sif->add_dev();
      	- cpufreq_add_dev();
      	  - get_cpu_device(); //FAILS
        - per_cpu(cpu_sys_devices, num) = &cpu->dev; //used by get_cpu_device()
        - return 0; //CPU registered successfully
      
      Because the per-cpu variable cpu_sys_devices is set only after the CPU
      device is regsitered, cpufreq will never be able to get it when
      cpufreq_add_dev() is called.
      
      This patch avoids this failure by making sure device structure of at
      least CPU0 is available when the cpufreq driver is registered, else
      return -EPROBE_DEFER.
      Reported-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
      Co-developed-by: default avatarAmit Kucheria <amit.kucheria@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      Tested-by: default avatarAmit Kucheria <amit.kucheria@linaro.org>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b5a67ca2
    • Sudip Mukherjee's avatar
      parport: load lowlevel driver if ports not found · 48f3a538
      Sudip Mukherjee authored
      [ Upstream commit 231ec2f2 ]
      
      Usually all the distro will load the parport low level driver as part
      of their initialization. But we can get into a situation where all the
      parallel port drivers are built as module and we unload all the modules
      at a later time. Then if we just do "modprobe parport" it will only
      load the parport module and will not load the low level driver which
      will actually register the ports. So, check the bus if there is any
      parport registered, if not, load the low level driver.
      
      We can get into the above situation with all distro but only Suse has
      setup the alias for "parport_lowlevel" and so it only works in Suse.
      Users of Debian based distro will need to load the lowlevel module
      manually.
      Signed-off-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Link: https://lore.kernel.org/r/20191016144540.18810-3-sudipm.mukherjee@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      48f3a538
    • Ilya Leoshkevich's avatar
      s390/disassembler: don't hide instruction addresses · 6a2af04f
      Ilya Leoshkevich authored
      [ Upstream commit 544f1d62 ]
      
      Due to kptr_restrict, JITted BPF code is now displayed like this:
      
      000000000b6ed1b2: ebdff0800024  stmg    %r13,%r15,128(%r15)
      000000004cde2ba0: 41d0f040      la      %r13,64(%r15)
      00000000fbad41b0: a7fbffa0      aghi    %r15,-96
      
      Leaking kernel addresses to dmesg is not a concern in this case, because
      this happens only when JIT debugging is explicitly activated, which only
      root can do.
      
      Use %px in this particular instance, and also to print an instruction
      address in show_code and PCREL (e.g. brasl) arguments in print_insn.
      While at present functionally equivalent to %016lx, %px is recommended
      by Documentation/core-api/printk-formats.rst for such cases.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Reviewed-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6a2af04f
    • Ben Zhang's avatar
      ASoC: rt5677: Mark reg RT5677_PWR_ANLG2 as volatile · 18305963
      Ben Zhang authored
      [ Upstream commit eabf424f ]
      
      The codec dies when RT5677_PWR_ANLG2(MX-64h) is set to 0xACE1
      while it's streaming audio over SPI. The DSP firmware turns
      on PLL2 (MX-64 bit 8) when SPI streaming starts.  However regmap
      does not believe that register can change by itself. When
      BST1 (bit 15) is turned on with regmap_update_bits(), it doesn't
      read the register first before write, so PLL2 power bit is
      cleared by accident.
      
      Marking MX-64h as volatile in regmap solved the issue.
      Signed-off-by: default avatarBen Zhang <benzh@chromium.org>
      Signed-off-by: default avatarCurtis Malainey <cujomalainey@chromium.org>
      Link: https://lore.kernel.org/r/20191106011335.223061-6-cujomalainey@chromium.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      18305963
    • Chuhong Yuan's avatar
      spi: pxa2xx: Add missed security checks · 4a9d8865
      Chuhong Yuan authored
      [ Upstream commit 5eb263ef ]
      
      pxa2xx_spi_init_pdata misses checks for devm_clk_get and
      platform_get_irq.
      Add checks for them to fix the bugs.
      
      Since ssp->clk and ssp->irq are used in probe, they are mandatory here.
      So we cannot use _optional() for devm_clk_get and platform_get_irq.
      Signed-off-by: default avatarChuhong Yuan <hslester96@gmail.com>
      Link: https://lore.kernel.org/r/20191109080943.30428-1-hslester96@gmail.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4a9d8865
    • Robert Richter's avatar
      EDAC/ghes: Fix grain calculation · bd5facda
      Robert Richter authored
      [ Upstream commit 7088e29e ]
      
      The current code to convert a physical address mask to a grain
      (defined as granularity in bytes) is:
      
      	e->grain = ~(mem_err->physical_addr_mask & ~PAGE_MASK);
      
      This is broken in several ways:
      
      1) It calculates to wrong grain values. E.g., a physical address mask
      of ~0xfff should give a grain of 0x1000. Without considering
      PAGE_MASK, there is an off-by-one. Things are worse when also
      filtering it with ~PAGE_MASK. This will calculate to a grain with the
      upper bits set. In the example it even calculates to ~0.
      
      2) The grain does not depend on and is unrelated to the kernel's
      page-size. The page-size only matters when unmapping memory in
      memory_failure(). Smaller grains are wrongly rounded up to the
      page-size, on architectures with a configurable page-size (e.g. arm64)
      this could round up to the even bigger page-size of the hypervisor.
      
      Fix this with:
      
      	e->grain = ~mem_err->physical_addr_mask + 1;
      
      The grain_bits are defined as:
      
      	grain = 1 << grain_bits;
      
      Change also the grain_bits calculation accordingly, it is the same
      formula as in edac_mc.c now and the code can be unified.
      
      The value in ->physical_addr_mask coming from firmware is assumed to
      be contiguous, but this is not sanity-checked. However, in case the
      mask is non-contiguous, a conversion to grain_bits effectively
      converts the grain bit mask to a power of 2 by rounding it up.
      Suggested-by: default avatarJames Morse <james.morse@arm.com>
      Signed-off-by: default avatarRobert Richter <rrichter@marvell.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Reviewed-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Cc: "linux-edac@vger.kernel.org" <linux-edac@vger.kernel.org>
      Cc: Tony Luck <tony.luck@intel.com>
      Link: https://lkml.kernel.org/r/20191106093239.25517-11-rrichter@marvell.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      bd5facda
    • Chuhong Yuan's avatar
      media: si470x-i2c: add missed operations in remove · 4111f10e
      Chuhong Yuan authored
      [ Upstream commit 2df200ab ]
      
      The driver misses calling v4l2_ctrl_handler_free and
      v4l2_device_unregister in remove like what is done in probe failure.
      Add the calls to fix it.
      Signed-off-by: default avatarChuhong Yuan <hslester96@gmail.com>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4111f10e
    • Mike Isely's avatar
      media: pvrusb2: Fix oops on tear-down when radio support is not present · 61d8117f
      Mike Isely authored
      [ Upstream commit 7f404ae9 ]
      
      In some device configurations there's no radio or radio support in the
      driver.  That's OK, as the driver sets itself up accordingly.  However
      on tear-down in these caes it's still trying to tear down radio
      related context when there isn't anything there, leading to
      dereferences through a null pointer and chaos follows.
      
      How this bug survived unfixed for 11 years in the pvrusb2 driver is a
      mystery to me.
      
      [hverkuil: fix two checkpatch warnings]
      Signed-off-by: default avatarMike Isely <isely@pobox.com>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      61d8117f
    • Miaoqing Pan's avatar
      ath10k: fix get invalid tx rate for Mesh metric · 807185ff
      Miaoqing Pan authored
      [ Upstream commit 05a11003 ]
      
      ath10k does not provide transmit rate info per MSDU
      in tx completion, mark that as -1 so mac80211
      will ignore the rates. This fixes mac80211 update Mesh
      link metric with invalid transmit rate info.
      
      Tested HW: QCA9984
      Tested FW: 10.4-3.9.0.2-00035
      Signed-off-by: default avatarHou Bao Hou <houbao@codeaurora.org>
      Signed-off-by: default avatarAnilkumar Kolli <akolli@codeaurora.org>
      Signed-off-by: default avatarMiaoqing Pan <miaoqing@codeaurora.org>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      807185ff
    • Masami Hiramatsu's avatar
      perf probe: Filter out instances except for inlined subroutine and subprogram · 3c8d7fa8
      Masami Hiramatsu authored
      [ Upstream commit da6cb952 ]
      
      Filter out instances except for inlined_subroutine and subprogram DIE in
      die_walk_instances() and die_is_func_instance().
      
      This fixes an issue that perf probe sets some probes on calling address
      instead of a target function itself.
      
      When perf probe walks on instances of an abstruct origin (a kind of
      function prototype of inlined function), die_walk_instances() can also
      pass a GNU_call_site (a GNU extension for call site) to callback. Since
      it is not an inlined instance of target function, we have to filter out
      when searching a probe point.
      
      Without this patch, perf probe sets probes on call site address too.This
      can happen on some function which is marked "inlined", but has actual
      symbol. (I'm not sure why GCC mark it "inlined"):
      
        # perf probe -D vfs_read
        p:probe/vfs_read _text+2500017
        p:probe/vfs_read_1 _text+2499468
        p:probe/vfs_read_2 _text+2499563
        p:probe/vfs_read_3 _text+2498876
        p:probe/vfs_read_4 _text+2498512
        p:probe/vfs_read_5 _text+2498627
      
      With this patch:
      
      Slightly different results, similar tho:
      
        # perf probe -D vfs_read
        p:probe/vfs_read _text+2498512
      
      Committer testing:
      
        # uname -a
        Linux quaco 5.3.8-200.fc30.x86_64 #1 SMP Tue Oct 29 14:46:22 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
      
      Before:
      
        # perf probe -D vfs_read
        p:probe/vfs_read _text+3131557
        p:probe/vfs_read_1 _text+3130975
        p:probe/vfs_read_2 _text+3131047
        p:probe/vfs_read_3 _text+3130380
        p:probe/vfs_read_4 _text+3130000
        # uname -a
        Linux quaco 5.3.8-200.fc30.x86_64 #1 SMP Tue Oct 29 14:46:22 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
        #
      
      After:
      
        # perf probe -D vfs_read
        p:probe/vfs_read _text+3130000
        #
      
      Fixes: db0d2c64 ("perf probe: Search concrete out-of-line instances")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157241937063.32002.11024544873990816590.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3c8d7fa8
    • Masami Hiramatsu's avatar
      perf probe: Skip end-of-sequence and non statement lines · b89ad0c6
      Masami Hiramatsu authored
      [ Upstream commit f4d99bdf ]
      
      Skip end-of-sequence and non-statement lines while walking through lines
      list.
      
      The "end-of-sequence" line information means:
      
       "the current address is that of the first byte after the
        end of a sequence of target machine instructions."
       (DWARF version 4 spec 6.2.2)
      
      This actually means out of scope and we can not probe on it.
      
      On the other hand, the statement lines (is_stmt) means:
      
       "the current instruction is a recommended breakpoint location.
        A recommended breakpoint location is intended to “represent”
        a line, a statement and/or a semantically distinct subpart
        of a statement."
      
       (DWARF version 4 spec 6.2.2)
      
      So, non-statement line info also should be skipped.
      
      These can reduce unneeded probe points and also avoid an error.
      
      E.g. without this patch:
      
        # perf probe -a "clear_tasks_mm_cpumask:1"
        Added new events:
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask:1)
          probe:clear_tasks_mm_cpumask_1 (on clear_tasks_mm_cpumask:1)
          probe:clear_tasks_mm_cpumask_2 (on clear_tasks_mm_cpumask:1)
          probe:clear_tasks_mm_cpumask_3 (on clear_tasks_mm_cpumask:1)
          probe:clear_tasks_mm_cpumask_4 (on clear_tasks_mm_cpumask:1)
      
        You can now use it in all perf tools, such as:
      
        	perf record -e probe:clear_tasks_mm_cpumask_4 -aR sleep 1
      
        #
      
      This puts 5 probes on one line, but acutally it's not inlined function.
      This is because there are many non statement instructions at the
      function prologue.
      
      With this patch:
      
        # perf probe -a "clear_tasks_mm_cpumask:1"
        Added new event:
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask:1)
      
        You can now use it in all perf tools, such as:
      
        	perf record -e probe:clear_tasks_mm_cpumask -aR sleep 1
      
        #
      
      Now perf-probe skips unneeded addresses.
      
      Committer testing:
      
      Slightly different results, but similar:
      
      Before:
      
        # uname -a
        Linux quaco 5.3.8-200.fc30.x86_64 #1 SMP Tue Oct 29 14:46:22 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
        #
        # perf probe -a "clear_tasks_mm_cpumask:1"
        Added new events:
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask:1)
          probe:clear_tasks_mm_cpumask_1 (on clear_tasks_mm_cpumask:1)
          probe:clear_tasks_mm_cpumask_2 (on clear_tasks_mm_cpumask:1)
      
        You can now use it in all perf tools, such as:
      
        	perf record -e probe:clear_tasks_mm_cpumask_2 -aR sleep 1
      
        #
      
      After:
      
        # perf probe -a "clear_tasks_mm_cpumask:1"
        Added new event:
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask:1)
      
        You can now use it in all perf tools, such as:
      
        	perf record -e probe:clear_tasks_mm_cpumask -aR sleep 1
      
        # perf probe -l
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask@kernel/cpu.c)
        #
      
      Fixes: 4cc9cec6 ("perf probe: Introduce lines walker interface")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157241936090.32002.12156347518596111660.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b89ad0c6
    • Masami Hiramatsu's avatar
      perf probe: Fix to show calling lines of inlined functions · 8466b890
      Masami Hiramatsu authored
      [ Upstream commit 86c0bf85 ]
      
      Fix to show calling lines of inlined functions (where an inline function
      is called).
      
      die_walk_lines() filtered out the lines inside inlined functions based
      on the address. However this also filtered out the lines which call
      those inlined functions from the target function.
      
      To solve this issue, check the call_file and call_line attributes and do
      not filter out if it matches to the line information.
      
      Without this fix, perf probe -L doesn't show some lines correctly.
      (don't see the lines after 17)
      
        # perf probe -L vfs_read
        <vfs_read@/home/mhiramat/ksrc/linux/fs/read_write.c:0>
              0  ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
              1  {
              2         ssize_t ret;
      
              4         if (!(file->f_mode & FMODE_READ))
                                return -EBADF;
              6         if (!(file->f_mode & FMODE_CAN_READ))
                                return -EINVAL;
              8         if (unlikely(!access_ok(buf, count)))
                                return -EFAULT;
      
             11         ret = rw_verify_area(READ, file, pos, count);
             12         if (!ret) {
             13                 if (count > MAX_RW_COUNT)
                                        count =  MAX_RW_COUNT;
             15                 ret = __vfs_read(file, buf, count, pos);
             16                 if (ret > 0) {
                                        fsnotify_access(file);
                                        add_rchar(current, ret);
                                }
      
      With this fix:
      
        # perf probe -L vfs_read
        <vfs_read@/home/mhiramat/ksrc/linux/fs/read_write.c:0>
              0  ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
              1  {
              2         ssize_t ret;
      
              4         if (!(file->f_mode & FMODE_READ))
                                return -EBADF;
              6         if (!(file->f_mode & FMODE_CAN_READ))
                                return -EINVAL;
              8         if (unlikely(!access_ok(buf, count)))
                                return -EFAULT;
      
             11         ret = rw_verify_area(READ, file, pos, count);
             12         if (!ret) {
             13                 if (count > MAX_RW_COUNT)
                                        count =  MAX_RW_COUNT;
             15                 ret = __vfs_read(file, buf, count, pos);
             16                 if (ret > 0) {
             17                         fsnotify_access(file);
             18                         add_rchar(current, ret);
                                }
             20                 inc_syscr(current);
                        }
      
      Fixes: 4cc9cec6 ("perf probe: Introduce lines walker interface")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157241937995.32002.17899884017011512577.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8466b890
    • Masami Hiramatsu's avatar
      perf probe: Return a better scope DIE if there is no best scope · 4ec7e16d
      Masami Hiramatsu authored
      [ Upstream commit c701636a ]
      
      Make find_best_scope() returns innermost DIE at given address if there
      is no best matched scope DIE. Since Gcc sometimes generates intuitively
      strange line info which is out of inlined function address range, we
      need this fixup.
      
      Without this, sometimes perf probe failed to probe on a line inside an
      inlined function:
      
        # perf probe -D ksys_open:3
        Failed to find scope of probe point.
          Error: Failed to add events.
      
      With this fix, 'perf probe' can probe it:
      
        # perf probe -D ksys_open:3
        p:probe/ksys_open _text+25707308
        p:probe/ksys_open_1 _text+25710596
        p:probe/ksys_open_2 _text+25711114
        p:probe/ksys_open_3 _text+25711343
        p:probe/ksys_open_4 _text+25714058
        p:probe/ksys_open_5 _text+2819653
        p:probe/ksys_open_6 _text+2819701
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
      Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
      Cc: Tom Zanussi <tom.zanussi@linux.intel.com>
      Link: http://lore.kernel.org/lkml/157291300887.19771.14936015360963292236.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4ec7e16d
    • Masami Hiramatsu's avatar
      perf probe: Skip overlapped location on searching variables · da443aa6
      Masami Hiramatsu authored
      [ Upstream commit dee36a2a ]
      
      Since debuginfo__find_probes() callback function can be called with  the
      location which already passed, the callback function must filter out
      such overlapped locations.
      
      add_probe_trace_event() has already done it by commit 1a375ae7
      ("perf probe: Skip same probe address for a given line"), but
      add_available_vars() doesn't. Thus perf probe -v shows same address
      repeatedly as below:
      
        # perf probe -V vfs_read:18
        Available variables at vfs_read:18
                @<vfs_read+217>
                        char*   buf
                        loff_t* pos
                        ssize_t ret
                        struct file*    file
                @<vfs_read+217>
                        char*   buf
                        loff_t* pos
                        ssize_t ret
                        struct file*    file
                @<vfs_read+226>
                        char*   buf
                        loff_t* pos
                        ssize_t ret
                        struct file*    file
      
      With this fix, perf probe -V shows it correctly:
      
        # perf probe -V vfs_read:18
        Available variables at vfs_read:18
                @<vfs_read+217>
                        char*   buf
                        loff_t* pos
                        ssize_t ret
                        struct file*    file
                @<vfs_read+226>
                        char*   buf
                        loff_t* pos
                        ssize_t ret
                        struct file*    file
      
      Fixes: cf6eb489 ("perf probe: Show accessible local variables")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157241938927.32002.4026859017790562751.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      da443aa6
    • Masami Hiramatsu's avatar
      perf probe: Fix to probe a function which has no entry pc · 11c5a6ce
      Masami Hiramatsu authored
      [ Upstream commit 5d16dbcc ]
      
      Fix 'perf probe' to probe a function which has no entry pc or low pc but
      only has ranges attribute.
      
      probe_point_search_cb() uses dwarf_entrypc() to get the probe address,
      but that doesn't work for the function DIE which has only ranges
      attribute. Use die_entrypc() instead.
      
      Without this fix:
      
        # perf probe -k ../build-x86_64/vmlinux -D clear_tasks_mm_cpumask:0
        Probe point 'clear_tasks_mm_cpumask' not found.
          Error: Failed to add events.
      
      With this:
      
        # perf probe -k ../build-x86_64/vmlinux -D clear_tasks_mm_cpumask:0
        p:probe/clear_tasks_mm_cpumask clear_tasks_mm_cpumask+0
      
      Committer testing:
      
      Before:
      
        [root@quaco ~]# perf probe clear_tasks_mm_cpumask:0
        Probe point 'clear_tasks_mm_cpumask' not found.
          Error: Failed to add events.
        [root@quaco ~]#
      
      After:
      
        [root@quaco ~]# perf probe clear_tasks_mm_cpumask:0
        Added new event:
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask)
      
        You can now use it in all perf tools, such as:
      
        	perf record -e probe:clear_tasks_mm_cpumask -aR sleep 1
      
        [root@quaco ~]#
      
      Using it with 'perf trace':
      
        [root@quaco ~]# perf trace -e probe:clear_tasks_mm_cpumask
      
      Doesn't seem to be used in x86_64:
      
        $ find . -name "*.c" | xargs grep clear_tasks_mm_cpumask
        ./kernel/cpu.c: * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU
        ./kernel/cpu.c:void clear_tasks_mm_cpumask(int cpu)
        ./arch/xtensa/kernel/smp.c:	clear_tasks_mm_cpumask(cpu);
        ./arch/csky/kernel/smp.c:	clear_tasks_mm_cpumask(cpu);
        ./arch/sh/kernel/smp.c:	clear_tasks_mm_cpumask(cpu);
        ./arch/arm/kernel/smp.c:	clear_tasks_mm_cpumask(cpu);
        ./arch/powerpc/mm/nohash/mmu_context.c:	clear_tasks_mm_cpumask(cpu);
        $ find . -name "*.h" | xargs grep clear_tasks_mm_cpumask
        ./include/linux/cpu.h:void clear_tasks_mm_cpumask(int cpu);
        $ find . -name "*.S" | xargs grep clear_tasks_mm_cpumask
        $
      
      Fixes: e1ecbbc3 ("perf probe: Fix to handle optimized not-inlined functions")
      Reported-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157199319438.8075.4695576954550638618.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      11c5a6ce
    • Masami Hiramatsu's avatar
      perf probe: Fix to show inlined function callsite without entry_pc · 86b5bd0a
      Masami Hiramatsu authored
      [ Upstream commit 18e21eb6 ]
      
      Fix 'perf probe --line' option to show inlined function callsite lines
      even if the function DIE has only ranges.
      
      Without this:
      
        # perf probe -L amd_put_event_constraints
        ...
            2  {
            3         if (amd_has_nb(cpuc) && amd_is_nb_event(&event->hw))
                              __amd_put_nb_event_constraints(cpuc, event);
            5  }
      
      With this patch:
      
        # perf probe -L amd_put_event_constraints
        ...
            2  {
            3         if (amd_has_nb(cpuc) && amd_is_nb_event(&event->hw))
            4                 __amd_put_nb_event_constraints(cpuc, event);
            5  }
      
      Committer testing:
      
      Before:
      
        [root@quaco ~]# perf probe -L amd_put_event_constraints
        <amd_put_event_constraints@/usr/src/debug/kernel-5.2.fc30/linux-5.2.18-200.fc30.x86_64/arch/x86/events/amd/core.c:0>
              0  static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
                                                      struct perf_event *event)
              2  {
              3         if (amd_has_nb(cpuc) && amd_is_nb_event(&event->hw))
                                __amd_put_nb_event_constraints(cpuc, event);
              5  }
      
                 PMU_FORMAT_ATTR(event, "config:0-7,32-35");
                 PMU_FORMAT_ATTR(umask, "config:8-15"   );
      
        [root@quaco ~]#
      
      After:
      
        [root@quaco ~]# perf probe -L amd_put_event_constraints
        <amd_put_event_constraints@/usr/src/debug/kernel-5.2.fc30/linux-5.2.18-200.fc30.x86_64/arch/x86/events/amd/core.c:0>
              0  static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
                                                      struct perf_event *event)
              2  {
              3         if (amd_has_nb(cpuc) && amd_is_nb_event(&event->hw))
              4                 __amd_put_nb_event_constraints(cpuc, event);
              5  }
      
                 PMU_FORMAT_ATTR(event, "config:0-7,32-35");
                 PMU_FORMAT_ATTR(umask, "config:8-15"   );
      
        [root@quaco ~]# perf probe amd_put_event_constraints:4
        Added new event:
          probe:amd_put_event_constraints (on amd_put_event_constraints:4)
      
        You can now use it in all perf tools, such as:
      
        	perf record -e probe:amd_put_event_constraints -aR sleep 1
      
        [root@quaco ~]#
      
        [root@quaco ~]# perf probe -l
          probe:amd_put_event_constraints (on amd_put_event_constraints:4@arch/x86/events/amd/core.c)
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask@kernel/cpu.c)
        [root@quaco ~]#
      
      Using it:
      
        [root@quaco ~]# perf trace -e probe:*
        ^C[root@quaco ~]#
      
      Ok, Intel system here... :-)
      
      Fixes: 4cc9cec6 ("perf probe: Introduce lines walker interface")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157199322107.8075.12659099000567865708.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      86b5bd0a
    • Masami Hiramatsu's avatar
      perf probe: Fix to show ranges of variables in functions without entry_pc · 516288df
      Masami Hiramatsu authored
      [ Upstream commit af04dd2f ]
      
      Fix to show ranges of variables (--range and --vars option) in functions
      which DIE has only ranges but no entry_pc attribute.
      
      Without this fix:
      
        # perf probe --range -V clear_tasks_mm_cpumask
        Available variables at clear_tasks_mm_cpumask
        	@<clear_tasks_mm_cpumask+0>
        		(No matched variables)
      
      With this fix:
      
        # perf probe --range -V clear_tasks_mm_cpumask
        Available variables at clear_tasks_mm_cpumask
      	@<clear_tasks_mm_cpumask+0>
      		[VAL]	int	cpu	@<clear_tasks_mm_cpumask+[0-35,317-317,2052-2059]>
      
      Committer testing:
      
      Before:
      
        [root@quaco ~]# perf probe --range -V clear_tasks_mm_cpumask
        Available variables at clear_tasks_mm_cpumask
                @<clear_tasks_mm_cpumask+0>
                        (No matched variables)
        [root@quaco ~]#
      
      After:
      
        [root@quaco ~]# perf probe --range -V clear_tasks_mm_cpumask
        Available variables at clear_tasks_mm_cpumask
                @<clear_tasks_mm_cpumask+0>
                        [VAL]   int     cpu     @<clear_tasks_mm_cpumask+[0-23,23-105,105-106,106-106,1843-1850,1850-1862]>
        [root@quaco ~]#
      
      Using it:
      
        [root@quaco ~]# perf probe clear_tasks_mm_cpumask cpu
        Added new event:
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask with cpu)
      
        You can now use it in all perf tools, such as:
      
        	perf record -e probe:clear_tasks_mm_cpumask -aR sleep 1
      
        [root@quaco ~]# perf probe -l
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask@kernel/cpu.c with cpu)
        [root@quaco ~]#
        [root@quaco ~]# perf trace -e probe:*cpumask
        ^C[root@quaco ~]#
      
      Fixes: 349e8d26 ("perf probe: Add --range option to show a variable's location range")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157199323018.8075.8179744380479673672.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      516288df
    • Masami Hiramatsu's avatar
      perf probe: Fix to probe an inline function which has no entry pc · 104666b6
      Masami Hiramatsu authored
      [ Upstream commit eb6933b2 ]
      
      Fix perf probe to probe an inlne function which has no entry pc
      or low pc but only has ranges attribute.
      
      This seems very rare case, but I could find a few examples, as
      same as probe_point_search_cb(), use die_entrypc() to get the
      entry address in probe_point_inline_cb() too.
      
      Without this patch:
      
        # perf probe -D __amd_put_nb_event_constraints
        Failed to get entry address of __amd_put_nb_event_constraints.
        Probe point '__amd_put_nb_event_constraints' not found.
          Error: Failed to add events.
      
      With this patch:
      
        # perf probe -D __amd_put_nb_event_constraints
        p:probe/__amd_put_nb_event_constraints amd_put_event_constraints+43
      
      Committer testing:
      
      Before:
      
        [root@quaco ~]# perf probe -D __amd_put_nb_event_constraints
        Failed to get entry address of __amd_put_nb_event_constraints.
        Probe point '__amd_put_nb_event_constraints' not found.
          Error: Failed to add events.
        [root@quaco ~]#
      
      After:
      
        [root@quaco ~]# perf probe -D __amd_put_nb_event_constraints
        p:probe/__amd_put_nb_event_constraints _text+33789
        [root@quaco ~]#
      
      Fixes: 4ea42b18 ("perf: Add perf probe subcommand, a kprobe-event setup helper")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157199320336.8075.16189530425277588587.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      104666b6
    • Masami Hiramatsu's avatar
      perf probe: Walk function lines in lexical blocks · e4ae92b8
      Masami Hiramatsu authored
      [ Upstream commit acb6a704 ]
      
      Since some inlined functions are in lexical blocks of given function, we
      have to recursively walk through the DIE tree.  Without this fix,
      perf-probe -L can miss the inlined functions which is in a lexical block
      (like if (..) { func() } case.)
      
      However, even though, to walk the lines in a given function, we don't
      need to follow the children DIE of inlined functions because those do
      not have any lines in the specified function.
      
      We need to walk though whole trees only if we walk all lines in a given
      file, because an inlined function can include another inlined function
      in the same file.
      
      Fixes: b0e9cb28 ("perf probe: Fix to search nested inlined functions in CU")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157190836514.1859.15996864849678136353.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e4ae92b8
    • Masami Hiramatsu's avatar
      perf probe: Fix to list probe event with correct line number · 65333030
      Masami Hiramatsu authored
      [ Upstream commit 3895534d ]
      
      Since debuginfo__find_probe_point() uses dwarf_entrypc() for finding the
      entry address of the function on which a probe is, it will fail when the
      function DIE has only ranges attribute.
      
      To fix this issue, use die_entrypc() instead of dwarf_entrypc().
      
      Without this fix, perf probe -l shows incorrect offset:
      
        # perf probe -l
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask+18446744071579263632@work/linux/linux/kernel/cpu.c)
          probe:clear_tasks_mm_cpumask_1 (on clear_tasks_mm_cpumask+18446744071579263752@work/linux/linux/kernel/cpu.c)
      
      With this:
      
        # perf probe -l
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask@work/linux/linux/kernel/cpu.c)
          probe:clear_tasks_mm_cpumask_1 (on clear_tasks_mm_cpumask:21@work/linux/linux/kernel/cpu.c)
      
      Committer testing:
      
      Before:
      
        [root@quaco ~]# perf probe -l
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask+18446744071579765152@kernel/cpu.c)
        [root@quaco ~]#
      
      After:
      
        [root@quaco ~]# perf probe -l
          probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask@kernel/cpu.c)
        [root@quaco ~]#
      
      Fixes: 1d46ea2a ("perf probe: Fix listing incorrect line number with inline function")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157199321227.8075.14655572419136993015.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      65333030
    • Masami Hiramatsu's avatar
      perf probe: Fix to find range-only function instance · 54ea1fe2
      Masami Hiramatsu authored
      [ Upstream commit b77afa1f ]
      
      Fix die_is_func_instance() to find range-only function instance.
      
      In some case, a function instance can be made without any low PC or
      entry PC, but only with address ranges by optimization.  (e.g. cold text
      partially in "text.unlikely" section) To find such function instance, we
      have to check the range attribute too.
      
      Fixes: e1ecbbc3 ("perf probe: Fix to handle optimized not-inlined functions")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/157190835669.1859.8368628035930950596.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      54ea1fe2
    • Ping-Ke Shih's avatar
      rtlwifi: fix memory leak in rtl92c_set_fw_rsvdpagepkt() · 4ee618ad
      Ping-Ke Shih authored
      [ Upstream commit 5174f1e4 ]
      
      This leak was found by testing the EDIMAX EW-7612 on Raspberry Pi 3B+ with
      Linux 5.4-rc5 (multi_v7_defconfig + rtlwifi + kmemleak) and noticed a
      single memory leak during probe:
      
      unreferenced object 0xec13ee40 (size 176):
        comm "kworker/u8:1", pid 36, jiffies 4294939321 (age 5580.790s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<fc1bbb3e>] __netdev_alloc_skb+0x9c/0x164
          [<863dfa6e>] rtl92c_set_fw_rsvdpagepkt+0x254/0x340 [rtl8192c_common]
          [<9572be0d>] rtl92cu_set_hw_reg+0xf48/0xfa4 [rtl8192cu]
          [<116df4d8>] rtl_op_bss_info_changed+0x234/0x96c [rtlwifi]
          [<8933575f>] ieee80211_bss_info_change_notify+0xb8/0x264 [mac80211]
          [<d4061e86>] ieee80211_assoc_success+0x934/0x1798 [mac80211]
          [<e55adb56>] ieee80211_rx_mgmt_assoc_resp+0x174/0x314 [mac80211]
          [<5974629e>] ieee80211_sta_rx_queued_mgmt+0x3f4/0x7f0 [mac80211]
          [<d91091c6>] ieee80211_iface_work+0x208/0x318 [mac80211]
          [<ac5fcae4>] process_one_work+0x22c/0x564
          [<f5e6d3b6>] worker_thread+0x44/0x5d8
          [<82c7b073>] kthread+0x150/0x154
          [<b43e1b7d>] ret_from_fork+0x14/0x2c
          [<794dff30>] 0x0
      
      It is because 8192cu doesn't implement usb_cmd_send_packet(), and this
      patch just frees the skb within the function to resolve memleak problem
      by now. Since 8192cu doesn't turn on fwctrl_lps that needs to download
      command packet for firmware via the function, applying this patch doesn't
      affect driver behavior.
      Reported-by: default avatarStefan Wahren <wahrenst@gmx.net>
      Signed-off-by: default avatarPing-Ke Shih <pkshih@realtek.com>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4ee618ad