1. 12 Apr, 2017 40 commits
    • Dmitry Bilunov's avatar
      dm raid: fix NULL pointer dereference for raid1 without bitmap · fe96b265
      Dmitry Bilunov authored
      commit 7a0c5c5b upstream.
      
      Commit 4257e085 ("dm raid: support to change bitmap region size")
      introduced a bitmap resize call during preresume phase. User can create
      a DM device with "raid" target configured as raid1 with no metadata
      devices to hold superblock/bitmap info. It can be achieved using the
      following sequence:
      
        truncate -s 32M /dev/shm/raid-test
        LOOP=$(losetup --show -f /dev/shm/raid-test)
        dmsetup create raid-test-linear0 --table "0 1024 linear $LOOP 0"
        dmsetup create raid-test-linear1 --table "0 1024 linear $LOOP 1024"
        dmsetup create raid-test --table "0 1024 raid raid1 1 2048 2 - /dev/mapper/raid-test-linear0 - /dev/mapper/raid-test-linear1"
      
      This results in the following crash:
      
      [ 4029.110216] device-mapper: raid: Ignoring chunk size parameter for RAID 1
      [ 4029.110217] device-mapper: raid: Choosing default region size of 4MiB
      [ 4029.111349] md/raid1:mdX: active with 2 out of 2 mirrors
      [ 4029.114770] BUG: unable to handle kernel NULL pointer dereference at 0000000000000030
      [ 4029.114802] IP: bitmap_resize+0x25/0x7c0 [md_mod]
      [ 4029.114816] PGD 0
      …
      [ 4029.115059] Hardware name: Aquarius Pro P30 S85 BUY-866/B85M-E, BIOS 2304 05/25/2015
      [ 4029.115079] task: ffff88015cc29a80 task.stack: ffffc90001a5c000
      [ 4029.115097] RIP: 0010:bitmap_resize+0x25/0x7c0 [md_mod]
      [ 4029.115112] RSP: 0018:ffffc90001a5fb68 EFLAGS: 00010246
      [ 4029.115127] RAX: 0000000000000005 RBX: 0000000000000000 RCX: 0000000000000000
      [ 4029.115146] RDX: 0000000000000000 RSI: 0000000000000400 RDI: 0000000000000000
      [ 4029.115166] RBP: ffffc90001a5fc28 R08: 0000000800000000 R09: 00000008ffffffff
      [ 4029.115185] R10: ffffea0005661600 R11: ffff88015cc29a80 R12: ffff88021231f058
      [ 4029.115204] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
      [ 4029.115223] FS:  00007fe73a6b4740(0000) GS:ffff88021ea80000(0000) knlGS:0000000000000000
      [ 4029.115245] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [ 4029.115261] CR2: 0000000000000030 CR3: 0000000159a74000 CR4: 00000000001426e0
      [ 4029.115281] Call Trace:
      [ 4029.115291]  ? raid_iterate_devices+0x63/0x80 [dm_raid]
      [ 4029.115309]  ? dm_table_all_devices_attribute.isra.23+0x41/0x70 [dm_mod]
      [ 4029.115329]  ? dm_table_set_restrictions+0x225/0x2d0 [dm_mod]
      [ 4029.115346]  raid_preresume+0x81/0x2e0 [dm_raid]
      [ 4029.115361]  dm_table_resume_targets+0x47/0xe0 [dm_mod]
      [ 4029.115378]  dm_resume+0xa8/0xd0 [dm_mod]
      [ 4029.115391]  dev_suspend+0x123/0x250 [dm_mod]
      [ 4029.115405]  ? table_load+0x350/0x350 [dm_mod]
      [ 4029.115419]  ctl_ioctl+0x1c2/0x490 [dm_mod]
      [ 4029.115433]  dm_ctl_ioctl+0xe/0x20 [dm_mod]
      [ 4029.115447]  do_vfs_ioctl+0x8d/0x5a0
      [ 4029.115459]  ? ____fput+0x9/0x10
      [ 4029.115470]  ? task_work_run+0x79/0xa0
      [ 4029.115481]  SyS_ioctl+0x3c/0x70
      [ 4029.115493]  entry_SYSCALL_64_fastpath+0x13/0x94
      
      The raid_preresume() function incorrectly assumes that the raid_set has
      a bitmap enabled if RT_FLAG_RS_BITMAP_LOADED is set.  But
      RT_FLAG_RS_BITMAP_LOADED is getting set in __load_dirty_region_bitmap()
      even if there is no bitmap present (and bitmap_load() happily returns 0
      even if a bitmap isn't present).  So the only way forward in the
      near-term is to check if the bitmap is present by seeing if
      mddev->bitmap is not NULL after bitmap_load() has been called.
      
      By doing so the above NULL pointer is avoided.
      
      Fixes: 4257e085 ("dm raid: support to change bitmap region size")
      Signed-off-by: default avatarDmitry Bilunov <kmeaw@yandex-team.ru>
      Signed-off-by: default avatarAndrey Smetanin <asmetanin@yandex-team.ru>
      Acked-by: default avatarHeinz Mauelshagen <heinzm@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fe96b265
    • Michael Ellerman's avatar
      powerpc/crypto/crc32c-vpmsum: Fix missing preempt_disable() · 5c67d541
      Michael Ellerman authored
      commit 4749228f upstream.
      
      In crc32c_vpmsum() we call enable_kernel_altivec() without first
      disabling preemption, which is not allowed:
      
        WARNING: CPU: 9 PID: 2949 at ../arch/powerpc/kernel/process.c:277 enable_kernel_altivec+0x100/0x120
        Modules linked in: dm_thin_pool dm_persistent_data dm_bio_prison dm_bufio libcrc32c vmx_crypto ...
        CPU: 9 PID: 2949 Comm: docker Not tainted 4.11.0-rc5-compiler_gcc-6.3.1-00033-g308ac756 #381
        ...
        NIP [c00000000001e320] enable_kernel_altivec+0x100/0x120
        LR [d000000003df0910] crc32c_vpmsum+0x108/0x150 [crc32c_vpmsum]
        Call Trace:
          0xc138fd09 (unreliable)
          crc32c_vpmsum+0x108/0x150 [crc32c_vpmsum]
          crc32c_vpmsum_update+0x3c/0x60 [crc32c_vpmsum]
          crypto_shash_update+0x88/0x1c0
          crc32c+0x64/0x90 [libcrc32c]
          dm_bm_checksum+0x48/0x80 [dm_persistent_data]
          sb_check+0x84/0x120 [dm_thin_pool]
          dm_bm_validate_buffer.isra.0+0xc0/0x1b0 [dm_persistent_data]
          dm_bm_read_lock+0x80/0xf0 [dm_persistent_data]
          __create_persistent_data_objects+0x16c/0x810 [dm_thin_pool]
          dm_pool_metadata_open+0xb0/0x1a0 [dm_thin_pool]
          pool_ctr+0x4cc/0xb60 [dm_thin_pool]
          dm_table_add_target+0x16c/0x3c0
          table_load+0x184/0x400
          ctl_ioctl+0x2f0/0x560
          dm_ctl_ioctl+0x38/0x50
          do_vfs_ioctl+0xd8/0x920
          SyS_ioctl+0x68/0xc0
          system_call+0x38/0xfc
      
      It used to be sufficient just to call pagefault_disable(), because that
      also disabled preemption. But the two were decoupled in commit 8222dbe2
      ("sched/preempt, mm/fault: Decouple preemption from the page fault
      logic") in mid 2015.
      
      So add the missing preempt_disable/enable(). We should also call
      disable_kernel_fp(), although it does nothing by default, there is a
      debug switch to make it active and all enables should be paired with
      disables.
      
      Fixes: 6dd7a82c ("crypto: powerpc - Add POWER8 optimised crc32c")
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5c67d541
    • Paul Mackerras's avatar
      powerpc: Don't try to fix up misaligned load-with-reservation instructions · d625e1a1
      Paul Mackerras authored
      commit 48fe9e94 upstream.
      
      In the past, there was only one load-with-reservation instruction,
      lwarx, and if a program attempted a lwarx on a misaligned address, it
      would take an alignment interrupt and the kernel handler would emulate
      it as though it was lwzx, which was not really correct, but benign since
      it is loading the right amount of data, and the lwarx should be paired
      with a stwcx. to the same address, which would also cause an alignment
      interrupt which would result in a SIGBUS being delivered to the process.
      
      We now have 5 different sizes of load-with-reservation instruction. Of
      those, lharx and ldarx cause an immediate SIGBUS by luck since their
      entries in aligninfo[] overlap instructions which were not fixed up, but
      lqarx overlaps with lhz and will be emulated as such. lbarx can never
      generate an alignment interrupt since it only operates on 1 byte.
      
      To straighten this out and fix the lqarx case, this adds code to detect
      the l[hwdq]arx instructions and return without fixing them up, resulting
      in a SIGBUS being delivered to the process.
      Signed-off-by: default avatarPaul Mackerras <paulus@ozlabs.org>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d625e1a1
    • Oliver O'Halloran's avatar
      powerpc/64: Fix flush_(d|i)cache_range() called from modules · b129e418
      Oliver O'Halloran authored
      commit 8f5f525d upstream.
      
      When the kernel is compiled to use 64bit ABIv2 the _GLOBAL() macro does
      not include a global entry point. A function's global entry point is
      used when the function is called from a different TOC context and in the
      kernel this typically means a call from a module into the vmlinux (or
      vice-versa).
      
      There are a few exported asm functions declared with _GLOBAL() and
      calling them from a module will likely crash the kernel since any TOC
      relative load will yield garbage.
      
      flush_icache_range() and flush_dcache_range() are both exported to
      modules, and use the TOC, so must use _GLOBAL_TOC().
      
      Fixes: 721aeaa9 ("powerpc: Build little endian ppc64 kernel with ABIv2")
      Signed-off-by: default avatarOliver O'Halloran <oohall@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b129e418
    • Frederic Barrat's avatar
      powerpc/mm: Add missing global TLB invalidate if cxl is active · 12502ae4
      Frederic Barrat authored
      commit 88b1bf72 upstream.
      
      Commit 4c6d9acc ("powerpc/mm: Add hooks for cxl") converted local
      TLB invalidates to global if the cxl driver is active. This is necessary
      because the CAPP snoops invalidations to forward them to the PSL on the
      cxl adapter. However one path was forgotten. native_flush_hash_range()
      still does local TLB invalidates, as found out the hard way recently.
      
      This patch fixes it by following the same logic as previously: if the
      cxl driver is active, the local TLB invalidates are 'upgraded' to
      global.
      
      Fixes: 4c6d9acc ("powerpc/mm: Add hooks for cxl")
      Signed-off-by: default avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
      Reviewed-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12502ae4
    • Benjamin Herrenschmidt's avatar
      powerpc: Disable HFSCR[TM] if TM is not supported · 2a3134e1
      Benjamin Herrenschmidt authored
      commit 7ed23e1b upstream.
      
      On Power8 & Power9 the early CPU inititialisation in __init_HFSCR()
      turns on HFSCR[TM] (Hypervisor Facility Status and Control Register
      [Transactional Memory]), but that doesn't take into account that TM
      might be disabled by CPU features, or disabled by the kernel being built
      with CONFIG_PPC_TRANSACTIONAL_MEM=n.
      
      So later in boot, when we have setup the CPU features, clear HSCR[TM] if
      the TM CPU feature has been disabled. We use CPU_FTR_TM_COMP to account
      for the CONFIG_PPC_TRANSACTIONAL_MEM=n case.
      
      Without this a KVM guest might try use TM, even if told not to, and
      cause an oops in the host kernel. Typically the oops is seen in
      __kvmppc_vcore_entry() and may or may not be fatal to the host, but is
      always bad news.
      
      In practice all shipping CPU revisions do support TM, and all host
      kernels we are aware of build with TM support enabled, so no one should
      actually be able to hit this in the wild.
      
      Fixes: 2a3563b0 ("powerpc: Setup in HFSCR for POWER8")
      Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
      Tested-by: default avatarSam Bobroff <sam.bobroff@au1.ibm.com>
      [mpe: Rewrite change log with input from Sam, add Fixes/stable]
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2a3134e1
    • Arnd Bergmann's avatar
      drm/msm: adreno: fix build error without debugfs · be556971
      Arnd Bergmann authored
      commit 280489da upstream.
      
      The newly added a5xx support fails to build when debugfs is diabled:
      
      drivers/gpu/drm/msm/adreno/a5xx_gpu.c:849:4: error: 'struct msm_gpu_funcs' has no member named 'show'
      drivers/gpu/drm/msm/adreno/a5xx_gpu.c:849:11: error: 'a5xx_show' undeclared here (not in a function); did you mean 'a5xx_irq'?
      
      This adds a missing #ifdef.
      
      Fixes: b5f103ab ("drm/msm: gpu: Add A5XX target support")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarRob Clark <robdclark@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      be556971
    • James Hogan's avatar
      metag/usercopy: Add missing fixups · 169b36be
      James Hogan authored
      commit b884a190 upstream.
      
      The rapf copy loops in the Meta usercopy code is missing some extable
      entries for HTP cores with unaligned access checking enabled, where
      faults occur on the instruction immediately after the faulting access.
      
      Add the fixup labels and extable entries for these cases so that corner
      case user copy failures don't cause kernel crashes.
      
      Fixes: 373cd784 ("metag: Memory handling")
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: linux-metag@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      169b36be
    • James Hogan's avatar
      metag/usercopy: Fix src fixup in from user rapf loops · 191e4c73
      James Hogan authored
      commit 2c0b1df8 upstream.
      
      The fixup code to rewind the source pointer in
      __asm_copy_from_user_{32,64}bit_rapf_loop() always rewound the source by
      a single unit (4 or 8 bytes), however this is insufficient if the fault
      didn't occur on the first load in the loop, as the source pointer will
      have been incremented but nothing will have been stored until all 4
      register [pairs] are loaded.
      
      Read the LSM_STEP field of TXSTATUS (which is already loaded into a
      register), a bit like the copy_to_user versions, to determine how many
      iterations of MGET[DL] have taken place, all of which need rewinding.
      
      Fixes: 373cd784 ("metag: Memory handling")
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: linux-metag@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      191e4c73
    • James Hogan's avatar
      metag/usercopy: Set flags before ADDZ · e6ca39ac
      James Hogan authored
      commit fd40eee1 upstream.
      
      The fixup code for the copy_to_user rapf loops reads TXStatus.LSM_STEP
      to decide how far to rewind the source pointer. There is a special case
      for the last execution of an MGETL/MGETD, since it leaves LSM_STEP=0
      even though the number of MGETLs/MGETDs attempted was 4. This uses ADDZ
      which is conditional upon the Z condition flag, but the AND instruction
      which masked the TXStatus.LSM_STEP field didn't set the condition flags
      based on the result.
      
      Fix that now by using ANDS which does set the flags, and also marking
      the condition codes as clobbered by the inline assembly.
      
      Fixes: 373cd784 ("metag: Memory handling")
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: linux-metag@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e6ca39ac
    • James Hogan's avatar
      metag/usercopy: Zero rest of buffer from copy_from_user · b03dd10e
      James Hogan authored
      commit 563ddc10 upstream.
      
      Currently we try to zero the destination for a failed read from userland
      in fixup code in the usercopy.c macros. The rest of the destination
      buffer is then zeroed from __copy_user_zeroing(), which is used for both
      copy_from_user() and __copy_from_user().
      
      Unfortunately we fail to zero in the fixup code as D1Ar1 is set to 0
      before the fixup code entry labels, and __copy_from_user() shouldn't even
      be zeroing the rest of the buffer.
      
      Move the zeroing out into copy_from_user() and rename
      __copy_user_zeroing() to raw_copy_from_user() since it no longer does
      any zeroing. This also conveniently matches the name needed for
      RAW_COPY_USER support in a later patch.
      
      Fixes: 373cd784 ("metag: Memory handling")
      Reported-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: linux-metag@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b03dd10e
    • James Hogan's avatar
      metag/usercopy: Add early abort to copy_to_user · 60a0b56e
      James Hogan authored
      commit fb8ea062 upstream.
      
      When copying to userland on Meta, if any faults are encountered
      immediately abort the copy instead of continuing on and repeatedly
      faulting, and worse potentially copying further bytes successfully to
      subsequent valid pages.
      
      Fixes: 373cd784 ("metag: Memory handling")
      Reported-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: linux-metag@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      60a0b56e
    • James Hogan's avatar
      metag/usercopy: Fix alignment error checking · e61ffb12
      James Hogan authored
      commit 22572119 upstream.
      
      Fix the error checking of the alignment adjustment code in
      raw_copy_from_user(), which mistakenly considers it safe to skip the
      error check when aligning the source buffer on a 2 or 4 byte boundary.
      
      If the destination buffer was unaligned it may have started to copy
      using byte or word accesses, which could well be at the start of a new
      (valid) source page. This would result in it appearing to have copied 1
      or 2 bytes at the end of the first (invalid) page rather than none at
      all.
      
      Fixes: 373cd784 ("metag: Memory handling")
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: linux-metag@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e61ffb12
    • James Hogan's avatar
      metag/usercopy: Drop unused macros · 804453ff
      James Hogan authored
      commit ef62a2d8 upstream.
      
      Metag's lib/usercopy.c has a bunch of copy_from_user macros for larger
      copies between 5 and 16 bytes which are completely unused. Before fixing
      zeroing lets drop these macros so there is less to fix.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: linux-metag@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      804453ff
    • Arend Van Spriel's avatar
      brcmfmac: use local iftype avoiding use-after-free of virtual interface · 6d855e02
      Arend Van Spriel authored
      commit d77facb8 upstream.
      
      A use-after-free was found using KASAN. In brcmf_p2p_del_if() the virtual
      interface is removed using call to brcmf_remove_interface(). After that
      the virtual interface instance has been freed and should not be referenced.
      Solve this by storing the nl80211 iftype in local variable, which is used
      in a couple of places anyway.
      Reported-by: default avatarDaniel J Blueman <daniel@quora.org>
      Reviewed-by: default avatarHante Meuleman <hante.meuleman@broadcom.com>
      Reviewed-by: default avatarPieter-Paul Giesberts <pieter-paul.giesberts@broadcom.com>
      Reviewed-by: default avatarFranky Lin <franky.lin@broadcom.com>
      Signed-off-by: default avatarArend van Spriel <arend.vanspriel@broadcom.com>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6d855e02
    • Johannes Berg's avatar
      mac80211: unconditionally start new netdev queues with iTXQ support · 96499191
      Johannes Berg authored
      commit 7d65f829 upstream.
      
      When internal mac80211 TXQs aren't supported, netdev queues must
      always started out started even when driver queues are stopped
      while the interface is added. This is necessary because with the
      internal TXQ support netdev queues are never stopped and packet
      scheduling/dropping is done in mac80211.
      
      Fixes: 80a83cfc ("mac80211: skip netdev queue control with software queuing")
      Reported-and-tested-by: default avatarSven Eckelmann <sven.eckelmann@openmesh.com>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      96499191
    • Wei Yongjun's avatar
      ring-buffer: Fix return value check in test_ringbuffer() · ab23a82a
      Wei Yongjun authored
      commit 62277de7 upstream.
      
      In case of error, the function kthread_run() returns ERR_PTR()
      and never returns NULL. The NULL test in the return value check
      should be replaced with IS_ERR().
      
      Link: http://lkml.kernel.org/r/1466184839-14927-1-git-send-email-weiyj_lk@163.com
      
      Fixes: 6c43e554 ("ring-buffer: Add ring buffer startup selftest")
      Signed-off-by: default avatarWei Yongjun <yongjun_wei@trendmicro.com.cn>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ab23a82a
    • Calvin Owens's avatar
      xfs: Honor FALLOC_FL_KEEP_SIZE when punching ends of files · 24d108e4
      Calvin Owens authored
      commit 3dd09d5a upstream.
      
      When punching past EOF on XFS, fallocate(mode=PUNCH_HOLE|KEEP_SIZE) will
      round the file size up to the nearest multiple of PAGE_SIZE:
      
        calvinow@vm-disks/generic-xfs-1 ~$ dd if=/dev/urandom of=test bs=2048 count=1
        calvinow@vm-disks/generic-xfs-1 ~$ stat test
          Size: 2048            Blocks: 8          IO Block: 4096   regular file
        calvinow@vm-disks/generic-xfs-1 ~$ fallocate -n -l 2048 -o 2048 -p test
        calvinow@vm-disks/generic-xfs-1 ~$ stat test
          Size: 4096            Blocks: 8          IO Block: 4096   regular file
      
      Commit 3c2bdc91 ("xfs: kill xfs_zero_remaining_bytes") replaced
      xfs_zero_remaining_bytes() with calls to iomap helpers. The new helpers
      don't enforce that [pos,offset) lies strictly on [0,i_size) when being
      called from xfs_free_file_space(), so by "leaking" these ranges into
      xfs_zero_range() we get this buggy behavior.
      
      Fix this by reintroducing the checks xfs_zero_remaining_bytes() did
      against i_size at the bottom of xfs_free_file_space().
      Reported-by: default avatarAaron Gao <gzh@fb.com>
      Fixes: 3c2bdc91 ("xfs: kill xfs_zero_remaining_bytes")
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Brian Foster <bfoster@redhat.com>
      Signed-off-by: default avatarCalvin Owens <calvinowens@fb.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
      Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      24d108e4
    • Martin Brandenburg's avatar
      orangefs: move features validation to fix filesystem hang · 1d656a4d
      Martin Brandenburg authored
      commit cefdc26e upstream.
      
      Without this fix (and another to the userspace component itself
      described later), the kernel will be unable to process any OrangeFS
      requests after the userspace component is restarted (due to a crash or
      at the administrator's behest).
      
      The bug here is that inside orangefs_remount, the orangefs_request_mutex
      is locked.  When the userspace component restarts while the filesystem
      is mounted, it sends a ORANGEFS_DEV_REMOUNT_ALL ioctl to the device,
      which causes the kernel to send it a few requests aimed at synchronizing
      the state between the two.  While this is happening the
      orangefs_request_mutex is locked to prevent any other requests going
      through.
      
      This is only half of the bugfix.  The other half is in the userspace
      component which outright ignores(!) requests made before it considers
      the filesystem remounted, which is after the ioctl returns.  Of course
      the ioctl doesn't return until after the userspace component responds to
      the request it ignores.  The userspace component has been changed to
      allow ORANGEFS_VFS_OP_FEATURES regardless of the mount status.
      
      Mike Marshall says:
       "I've tested this patch against the fixed userspace part. This patch is
        real important, I hope it can make it into 4.11...
      
        Here's what happens when the userspace daemon is restarted, without
        the patch:
      
          =============================================
          [ INFO: possible recursive locking detected ]
          [   4.10.0-00007-ge98bdb30 #1 Not tainted    ]
          ---------------------------------------------
          pvfs2-client-co/29032 is trying to acquire lock:
           (orangefs_request_mutex){+.+.+.}, at: service_operation+0x3c7/0x7b0 [orangefs]
                        but task is already holding lock:
           (orangefs_request_mutex){+.+.+.}, at: dispatch_ioctl_command+0x1bf/0x330 [orangefs]
      
          CPU: 0 PID: 29032 Comm: pvfs2-client-co Not tainted 4.10.0-00007-ge98bdb30 #1
          Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.3-1.fc25 04/01/2014
          Call Trace:
           __lock_acquire+0x7eb/0x1290
           lock_acquire+0xe8/0x1d0
           mutex_lock_killable_nested+0x6f/0x6e0
           service_operation+0x3c7/0x7b0 [orangefs]
           orangefs_remount+0xea/0x150 [orangefs]
           dispatch_ioctl_command+0x227/0x330 [orangefs]
           orangefs_devreq_ioctl+0x29/0x70 [orangefs]
           do_vfs_ioctl+0xa3/0x6e0
           SyS_ioctl+0x79/0x90"
      Signed-off-by: default avatarMartin Brandenburg <martin@omnibond.com>
      Acked-by: default avatarMike Marshall <hubcap@omnibond.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1d656a4d
    • Gleb Fotengauer-Malinovskiy's avatar
      jump label: fix passing kbuild_cflags when checking for asm goto support · b92a638e
      Gleb Fotengauer-Malinovskiy authored
      commit 7292ae3d upstream.
      
      The latest change of asm goto support check added passing of KBUILD_CFLAGS
      to compiler.  When these flags reference gcc plugins that are not built yet,
      the check fails.
      
      When one runs "make bzImage" followed by "make modules", the kernel is always
      built with HAVE_JUMP_LABEL disabled, while the modules are built depending on
      CONFIG_JUMP_LABEL.  If HAVE_JUMP_LABEL macro happens to be different, modules
      are built with undefined references, e.g.:
      
      ERROR: "static_key_slow_inc" [net/netfilter/xt_TEE.ko] undefined!
      ERROR: "static_key_slow_dec" [net/netfilter/xt_TEE.ko] undefined!
      ERROR: "static_key_slow_dec" [net/netfilter/nft_meta.ko] undefined!
      ERROR: "static_key_slow_inc" [net/netfilter/nft_meta.ko] undefined!
      ERROR: "nf_hooks_needed" [net/netfilter/ipvs/ip_vs.ko] undefined!
      ERROR: "nf_hooks_needed" [net/ipv6/ipv6.ko] undefined!
      ERROR: "static_key_count" [net/ipv6/ipv6.ko] undefined!
      ERROR: "static_key_slow_inc" [net/ipv6/ipv6.ko] undefined!
      
      This change moves the check before all these references are added
      to KBUILD_CFLAGS.  This is correct because subsequent KBUILD_CFLAGS
      modifications are not relevant to this check.
      Reported-by: default avatarAnton V. Boyarshinov <boyarsh@altlinux.org>
      Fixes: 35f860f9 ("jump label: pass kbuild_cflags when checking for asm goto support")
      Signed-off-by: default avatarGleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
      Signed-off-by: default avatarDmitry V. Levin <ldv@altlinux.org>
      Acked-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Acked-by: default avatarDavid Lin <dtwlin@google.com>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b92a638e
    • Arnd Bergmann's avatar
      Kbuild: use cc-disable-warning consistently for maybe-uninitialized · 7b73b72f
      Arnd Bergmann authored
      commit b334e19a upstream.
      
      In commit a76bcf55 ("Kbuild: enable -Wmaybe-uninitialized warning
      for "make W=1""), I reverted another change that happened to fix a problem
      with old compilers, and now we get this report again with old compilers
      (prior to gcc-4.8) and GCOV enabled:
      
         cc1: warnings being treated as errors
         drivers/gpu/drm/i915/intel_ringbuffer.c: In function 'intel_ring_setup_status_page':
         drivers/gpu/drm/i915/intel_ringbuffer.c:438: error: 'mmio.reg' may be used uninitialized in this function
         At top level:
      >> cc1: error: unrecognized command line option "-Wno-maybe-uninitialized"
      
      The problem is that we turn off the warning conditionally in a number
      of places as we should, but one of them does it unconditionally.
      Instead, change it to call cc-disable-warning as we do elsewhere.
      
      The original patch that caused it was merged into linux-4.7, then
      4.8 removed the change and 4.9 brought it back, so we probably want
      a backport to 4.9 once this is merged.
      
      Use a ':=' assignment instead of '=' to force the cc-disable-warning
      call to only be evaluated once instead of every time.
      
      Fixes: a76bcf55 ("Kbuild: enable -Wmaybe-uninitialized warning for "make W=1"")
      Fixes: e72e2dfe ("gcov: disable -Wmaybe-uninitialized warning")
      Reported-by: default avatarkbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7b73b72f
    • Rafael J. Wysocki's avatar
      ACPI / scan: Prefer devices without _HID for _ADR matching · 52b38ad0
      Rafael J. Wysocki authored
      commit fdad4e7a upstream.
      
      Commit c2a6bbaf (ACPI / scan: Prefer devices without _HID/_CID
      for _ADR matching) added a list_empty(&adev->pnp.ids) check to
      find_child_checks() so as to catch situations in which the ACPI
      core attempts to decode _ADR for a device having a _HID too which
      is strictly against the spec.  However, it overlooked the fact that
      the adev->pnp.ids list for the devices taken into account by
      find_child_checks() may contain device IDs set internally by the
      kernel, like "LNXVIDEO" (thanks to Zhang Rui for that realization),
      and it broke the enumeration of those devices as a result.
      
      To unbreak it, replace the overly coarse grained list_empty()
      check with a much more precise check against the pnp.type.platform_id
      flag which is only set for devices having a _HID (that's how it
      should be done from the start, as having both _ADR and _CID is
      actually permitted).
      
      Fixes: c2a6bbaf (ACPI / scan: Prefer devices without _HID/_CID for _ADR matching)
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=194889Reported-and-tested-by: default avatarMike <mike@mikewilson.me.uk>
      Tested-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      52b38ad0
    • Dmitry Torokhov's avatar
      ACPI / gpio: do not fall back to parsing _CRS when we get a deferral · e56bb922
      Dmitry Torokhov authored
      commit 693bdaa1 upstream.
      
      If, while locating GPIOs by name, we get probe deferral, we should
      immediately report it to caller rather than trying to fall back to parsing
      unnamed GPIOs from _CRS block.
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Acked-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
      Acked-and-Tested-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e56bb922
    • Sami Tolvanen's avatar
      dm verity fec: fix bufio leaks · 1c9925e6
      Sami Tolvanen authored
      commit 86e3e83b upstream.
      
      Buffers read through dm_bufio_read() were not released in all code paths.
      
      Fixes: a739ff3f ("dm verity: add support for forward error correction")
      Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1c9925e6
    • Sami Tolvanen's avatar
      dm verity fec: limit error correction recursion · 88c358b1
      Sami Tolvanen authored
      commit f1a880a9 upstream.
      
      If the hash tree itself is sufficiently corrupt in addition to data blocks,
      it's possible for error correction to end up in a deep recursive loop,
      which eventually causes a kernel panic.  This change limits the
      recursion to a reasonable level during a single I/O operation.
      
      Fixes: a739ff3f ("dm verity: add support for forward error correction")
      Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      88c358b1
    • Ross Zwisler's avatar
      dax: fix radix tree insertion race · 523a1932
      Ross Zwisler authored
      commit e11f8b7b upstream.
      
      While running generic/340 in my test setup I hit the following race.  It
      can happen with kernels that support FS DAX PMDs, so v4.10 thru
      v4.11-rc5.
      
      Thread 1				Thread 2
      --------				--------
      dax_iomap_pmd_fault()
        grab_mapping_entry()
          spin_lock_irq()
          get_unlocked_mapping_entry()
          'entry' is NULL, can't call lock_slot()
          spin_unlock_irq()
          radix_tree_preload()
      					dax_iomap_pmd_fault()
      					  grab_mapping_entry()
      					    spin_lock_irq()
      					    get_unlocked_mapping_entry()
      					    ...
      					    lock_slot()
      					    spin_unlock_irq()
      					  dax_pmd_insert_mapping()
      					    <inserts a PMD mapping>
          spin_lock_irq()
          __radix_tree_insert() fails with -EEXIST
          <fall back to 4k fault, and die horribly
           when inserting a 4k entry where a PMD exists>
      
      The issue is that we have to drop mapping->tree_lock while calling
      radix_tree_preload(), but since we didn't have a radix tree entry to
      lock (unlike in the pmd_downgrade case) we have no protection against
      Thread 2 coming along and inserting a PMD at the same index.  For 4k
      entries we handled this with a special-case response to -EEXIST coming
      from the __radix_tree_insert(), but this doesn't save us for PMDs
      because the -EEXIST case can also mean that we collided with a 4k entry
      in the radix tree at a different index, but one that is covered by our
      PMD range.
      
      So, correctly handle both the 4k and 2M collision cases by explicitly
      re-checking the radix tree for an entry at our index once we reacquire
      mapping->tree_lock.
      
      This patch has made it through a clean xfstests run with the current
      v4.11-rc5 based linux/master, and it also ran generic/340 500 times in a
      loop.  It used to fail within the first 10 iterations.
      
      Link: http://lkml.kernel.org/r/20170406212944.2866-1-ross.zwisler@linux.intel.comSigned-off-by: default avatarRoss Zwisler <ross.zwisler@linux.intel.com>
      Cc: "Darrick J. Wong" <darrick.wong@oracle.com>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Dan Williams <dan.j.williams@intel.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Matthew Wilcox <mawilcox@microsoft.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      523a1932
    • bsegall@google.com's avatar
      ptrace: fix PTRACE_LISTEN race corrupting task->state · 8bdc69cc
      bsegall@google.com authored
      commit 5402e97a upstream.
      
      In PT_SEIZED + LISTEN mode STOP/CONT signals cause a wakeup against
      __TASK_TRACED.  If this races with the ptrace_unfreeze_traced at the end
      of a PTRACE_LISTEN, this can wake the task /after/ the check against
      __TASK_TRACED, but before the reset of state to TASK_TRACED.  This
      causes it to instead clobber TASK_WAKING, allowing a subsequent wakeup
      against TRACED while the task is still on the rq wake_list, corrupting
      it.
      
      Oleg said:
       "The kernel can crash or this can lead to other hard-to-debug problems.
        In short, "task->state = TASK_TRACED" in ptrace_unfreeze_traced()
        assumes that nobody else can wake it up, but PTRACE_LISTEN breaks the
        contract. Obviusly it is very wrong to manipulate task->state if this
        task is already running, or WAKING, or it sleeps again"
      
      [akpm@linux-foundation.org: coding-style fixes]
      Fixes: 9899d11f ("ptrace: ensure arch_ptrace/ptrace_request can never race with SIGKILL")
      Link: http://lkml.kernel.org/r/xm26y3vfhmkp.fsf_-_@bsegall-linux.mtv.corp.google.comSigned-off-by: default avatarBen Segall <bsegall@google.com>
      Acked-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8bdc69cc
    • Alexander Polakov's avatar
      mm/page_alloc.c: fix print order in show_free_areas() · 0666cf6c
      Alexander Polakov authored
      commit 1f06b81a upstream.
      
      Fixes: 11fb9989 ("mm: move most file-based accounting to the node")
      Link: http://lkml.kernel.org/r/1490377730.30219.2.camel@beget.ruSigned-off-by: default avatarAlexander Polyakov <apolyakov@beget.com>
      Acked-by: default avatarMichal Hocko <mhocko@suse.com>
      Cc: Mel Gorman <mgorman@techsingularity.net>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0666cf6c
    • Jan-Marek Glogowski's avatar
      Reset TreeId to zero on SMB2 TREE_CONNECT · 67485049
      Jan-Marek Glogowski authored
      commit 806a28ef upstream.
      
      Currently the cifs module breaks the CIFS specs on reconnect as
      described in http://msdn.microsoft.com/en-us/library/cc246529.aspx:
      
      "TreeId (4 bytes): Uniquely identifies the tree connect for the
      command. This MUST be 0 for the SMB2 TREE_CONNECT Request."
      Signed-off-by: default avatarJan-Marek Glogowski <glogow@fbihome.de>
      Reviewed-by: default avatarAurelien Aptel <aaptel@suse.com>
      Tested-by: default avatarAurelien Aptel <aaptel@suse.com>
      Signed-off-by: default avatarSteve French <smfrench@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      67485049
    • Arend Van Spriel's avatar
      cfg80211: check rdev resume callback only for registered wiphy · c793e337
      Arend Van Spriel authored
      commit b3ef5520 upstream.
      
      We got the following use-after-free KASAN report:
      
       BUG: KASAN: use-after-free in wiphy_resume+0x591/0x5a0 [cfg80211]
      	 at addr ffff8803fc244090
       Read of size 8 by task kworker/u16:24/2587
       CPU: 6 PID: 2587 Comm: kworker/u16:24 Tainted: G    B 4.9.13-debug+
       Hardware name: Dell Inc. XPS 15 9550/0N7TVV, BIOS 1.2.19 12/22/2016
       Workqueue: events_unbound async_run_entry_fn
        ffff880425d4f9d8 ffffffffaeedb541 ffff88042b80ef00 ffff8803fc244088
        ffff880425d4fa00 ffffffffae84d7a1 ffff880425d4fa98 ffff8803fc244080
        ffff88042b80ef00 ffff880425d4fa88 ffffffffae84da3a ffffffffc141f7d9
       Call Trace:
        [<ffffffffaeedb541>] dump_stack+0x85/0xc4
        [<ffffffffae84d7a1>] kasan_object_err+0x21/0x70
        [<ffffffffae84da3a>] kasan_report_error+0x1fa/0x500
        [<ffffffffc141f7d9>] ? cfg80211_bss_age+0x39/0xc0 [cfg80211]
        [<ffffffffc141f83a>] ? cfg80211_bss_age+0x9a/0xc0 [cfg80211]
        [<ffffffffae48d46d>] ? trace_hardirqs_on+0xd/0x10
        [<ffffffffc13fb1c0>] ? wiphy_suspend+0xc70/0xc70 [cfg80211]
        [<ffffffffae84def1>] __asan_report_load8_noabort+0x61/0x70
        [<ffffffffc13fb100>] ? wiphy_suspend+0xbb0/0xc70 [cfg80211]
        [<ffffffffc13fb751>] ? wiphy_resume+0x591/0x5a0 [cfg80211]
        [<ffffffffc13fb751>] wiphy_resume+0x591/0x5a0 [cfg80211]
        [<ffffffffc13fb1c0>] ? wiphy_suspend+0xc70/0xc70 [cfg80211]
        [<ffffffffaf3b206e>] dpm_run_callback+0x6e/0x4f0
        [<ffffffffaf3b31b2>] device_resume+0x1c2/0x670
        [<ffffffffaf3b367d>] async_resume+0x1d/0x50
        [<ffffffffae3ee84e>] async_run_entry_fn+0xfe/0x610
        [<ffffffffae3d0666>] process_one_work+0x716/0x1a50
        [<ffffffffae3d05c9>] ? process_one_work+0x679/0x1a50
        [<ffffffffafdd7b6d>] ? _raw_spin_unlock_irq+0x3d/0x60
        [<ffffffffae3cff50>] ? pwq_dec_nr_in_flight+0x2b0/0x2b0
        [<ffffffffae3d1a80>] worker_thread+0xe0/0x1460
        [<ffffffffae3d19a0>] ? process_one_work+0x1a50/0x1a50
        [<ffffffffae3e54c2>] kthread+0x222/0x2e0
        [<ffffffffae3e52a0>] ? kthread_park+0x80/0x80
        [<ffffffffae3e52a0>] ? kthread_park+0x80/0x80
        [<ffffffffae3e52a0>] ? kthread_park+0x80/0x80
        [<ffffffffafdd86aa>] ret_from_fork+0x2a/0x40
       Object at ffff8803fc244088, in cache kmalloc-1024 size: 1024
       Allocated:
       PID = 71
        save_stack_trace+0x1b/0x20
        save_stack+0x46/0xd0
        kasan_kmalloc+0xad/0xe0
        kasan_slab_alloc+0x12/0x20
        __kmalloc_track_caller+0x134/0x360
        kmemdup+0x20/0x50
        brcmf_cfg80211_attach+0x10b/0x3a90 [brcmfmac]
        brcmf_bus_start+0x19a/0x9a0 [brcmfmac]
        brcmf_pcie_setup+0x1f1a/0x3680 [brcmfmac]
        brcmf_fw_request_nvram_done+0x44c/0x11b0 [brcmfmac]
        request_firmware_work_func+0x135/0x280
        process_one_work+0x716/0x1a50
        worker_thread+0xe0/0x1460
        kthread+0x222/0x2e0
        ret_from_fork+0x2a/0x40
       Freed:
       PID = 2568
        save_stack_trace+0x1b/0x20
        save_stack+0x46/0xd0
        kasan_slab_free+0x71/0xb0
        kfree+0xe8/0x2e0
        brcmf_cfg80211_detach+0x62/0xf0 [brcmfmac]
        brcmf_detach+0x14a/0x2b0 [brcmfmac]
        brcmf_pcie_remove+0x140/0x5d0 [brcmfmac]
        brcmf_pcie_pm_leave_D3+0x198/0x2e0 [brcmfmac]
        pci_pm_resume+0x186/0x220
        dpm_run_callback+0x6e/0x4f0
        device_resume+0x1c2/0x670
        async_resume+0x1d/0x50
        async_run_entry_fn+0xfe/0x610
        process_one_work+0x716/0x1a50
        worker_thread+0xe0/0x1460
        kthread+0x222/0x2e0
        ret_from_fork+0x2a/0x40
       Memory state around the buggy address:
        ffff8803fc243f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
        ffff8803fc244000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
       >ffff8803fc244080: fc fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                ^
        ffff8803fc244100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
        ffff8803fc244180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      
      What is happening is that brcmf_pcie_resume() detects a device that
      is no longer responsive and it decides to unbind resulting in a
      wiphy_unregister() and wiphy_free() call. Now the wiphy instance
      remains allocated, because PM needs to call wiphy_resume() for it.
      However, brcmfmac already does a kfree() for the struct
      cfg80211_registered_device::ops field. Change the checks in
      wiphy_resume() to only access the struct cfg80211_registered_device::ops
      if the wiphy instance is still registered at this time.
      Reported-by: default avatarDaniel J Blueman <daniel@quora.org>
      Reviewed-by: default avatarHante Meuleman <hante.meuleman@broadcom.com>
      Reviewed-by: default avatarPieter-Paul Giesberts <pieter-paul.giesberts@broadcom.com>
      Reviewed-by: default avatarFranky Lin <franky.lin@broadcom.com>
      Signed-off-by: default avatarArend van Spriel <arend.vanspriel@broadcom.com>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c793e337
    • Victor Kamensky's avatar
      arm64: mm: unaligned access by user-land should be received as SIGBUS · b48b63d5
      Victor Kamensky authored
      commit 09a6adf5 upstream.
      
      After 52d7523d (arm64: mm: allow the kernel to handle alignment faults on
      user accesses) commit user-land accesses that produce unaligned exceptions
      like in case of aarch32 ldm/stm/ldrd/strd instructions operating on
      unaligned memory received by user-land as SIGSEGV. It is wrong, it should
      be reported as SIGBUS as it was before 52d7523d commit.
      
      Changed do_bad_area function to take signal and code parameters out of esr
      value using fault_info table, so in case of do_alignment_fault fault
      user-land will receive SIGBUS. Wrapped access to fault_info table into
      esr_to_fault_info function.
      
      Fixes: 52d7523d (arm64: mm: allow the kernel to handle alignment faults on user accesses)
      Signed-off-by: default avatarVictor Kamensky <kamensky@cisco.com>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b48b63d5
    • Quentin Schulz's avatar
      iio: bmg160: reset chip when probing · 3d44ecc1
      Quentin Schulz authored
      commit 4bdc9029 upstream.
      
      The gyroscope chip might need to be reset to be used.
      
      Without the chip being reset, the driver stopped at the first
      regmap_read (to get the CHIP_ID) and failed to probe.
      
      The datasheet of the gyroscope says that a minimum wait of 30ms after
      the reset has to be done.
      
      This patch has been checked on a BMX055 and the datasheet of the BMG160
      and the BMI055 give the same reset register and bits.
      Signed-off-by: default avatarQuentin Schulz <quentin.schulz@free-electrons.com>
      Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3d44ecc1
    • Shrirang Bagul's avatar
      iio: st_pressure: initialize lps22hb bootime · 2501a0af
      Shrirang Bagul authored
      commit 51f528a1 upstream.
      
      This patch initializes the bootime in struct st_sensor_settings for
      lps22hb sensor. Without this, sensor channels read from sysfs always
      report stale values.
      Signed-off-by: default avatarShrirang Bagul <shrirang.bagul@canonical.com>
      Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2501a0af
    • Nikolaus Schulz's avatar
      iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values · a16d8c4e
      Nikolaus Schulz authored
      commit 7fd6592d upstream.
      
      Fix formatting of negative values of type IIO_VAL_FRACTIONAL_LOG2 by
      switching from do_div(), which can't handle negative numbers, to
      div_s64_rem().  Also use shift_right for shifting, which is safe with
      negative values.
      Signed-off-by: default avatarNikolaus Schulz <nikolaus.schulz@avionic-design.de>
      Reviewed-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a16d8c4e
    • Suzuki K Poulose's avatar
      kvm: arm/arm64: Fix locking for kvm_free_stage2_pgd · 0d50669c
      Suzuki K Poulose authored
      commit 8b3405e3 upstream.
      
      In kvm_free_stage2_pgd() we don't hold the kvm->mmu_lock while calling
      unmap_stage2_range() on the entire memory range for the guest. This could
      cause problems with other callers (e.g, munmap on a memslot) trying to
      unmap a range. And since we have to unmap the entire Guest memory range
      holding a spinlock, make sure we yield the lock if necessary, after we
      unmap each PUD range.
      
      Fixes: commit d5d8184d ("KVM: ARM: Memory virtualization setup")
      Cc: Paolo Bonzini <pbonzin@redhat.com>
      Cc: Marc Zyngier <marc.zyngier@arm.com>
      Cc: Christoffer Dall <christoffer.dall@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
      [ Avoid vCPU starvation and lockup detector warnings ]
      Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
      Signed-off-by: default avatarChristoffer Dall <cdall@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0d50669c
    • Marc Zyngier's avatar
      arm/arm64: KVM: Take mmap_sem in kvm_arch_prepare_memory_region · e8c3d654
      Marc Zyngier authored
      commit 72f31048 upstream.
      
      We don't hold the mmap_sem while searching for VMAs (via find_vma), in
      kvm_arch_prepare_memory_region, which can end up in expected failures.
      
      Fixes: commit 8eef9123 ("arm/arm64: KVM: map MMIO regions at creation time")
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Eric Auger <eric.auger@rehat.com>
      Reviewed-by: default avatarChristoffer Dall <cdall@linaro.org>
      [ Handle dirty page logging failure case ]
      Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
      Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e8c3d654
    • Marc Zyngier's avatar
      arm/arm64: KVM: Take mmap_sem in stage2_unmap_vm · fc29073a
      Marc Zyngier authored
      commit 90f6e150 upstream.
      
      We don't hold the mmap_sem while searching for the VMAs when
      we try to unmap each memslot for a VM. Fix this properly to
      avoid unexpected results.
      
      Fixes: commit 957db105 ("arm/arm64: KVM: Introduce stage2_unmap_vm")
      Reviewed-by: default avatarChristoffer Dall <cdall@linaro.org>
      Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
      Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fc29073a
    • Shuxiao Zhang's avatar
      staging: android: ashmem: lseek failed due to no FMODE_LSEEK. · fb3ce7a8
      Shuxiao Zhang authored
      commit 97fbfef6 upstream.
      
      vfs_llseek will check whether the file mode has
      FMODE_LSEEK, no return failure. But ashmem can be
      lseek, so add FMODE_LSEEK to ashmem file.
      
      Comment From Greg Hackmann:
      	ashmem_llseek() passes the llseek() call through to the backing
      	shmem file.  91360b02 ("ashmem: use vfs_llseek()") changed
      	this from directly calling the file's llseek() op into a VFS
      	layer call.  This also adds a check for the FMODE_LSEEK bit, so
      	without that bit ashmem_llseek() now always fails with -ESPIPE.
      
      Fixes: 91360b02 ("ashmem: use vfs_llseek()")
      Signed-off-by: default avatarShuxiao Zhang <zhangshuxiao@xiaomi.com>
      Tested-by: default avatarGreg Hackmann <ghackmann@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fb3ce7a8
    • NeilBrown's avatar
      sysfs: be careful of error returns from ops->show() · 38b4b8a0
      NeilBrown authored
      commit c8a139d0 upstream.
      
      ops->show() can return a negative error code.
      Commit 65da3484 ("sysfs: correctly handle short reads on PREALLOC attrs.")
      (in v4.4) caused this to be stored in an unsigned 'size_t' variable, so errors
      would look like large numbers.
      As a result, if an error is returned, sysfs_kf_read() will return the
      value of 'count', typically 4096.
      
      Commit 17d0774f ("sysfs: correctly handle read offset on PREALLOC attrs")
      (in v4.8) extended this error to use the unsigned large 'len' as a size for
      memmove().
      Consequently, if ->show returns an error, then the first read() on the
      sysfs file will return 4096 and could return uninitialized memory to
      user-space.
      If the application performs a subsequent read, this will trigger a memmove()
      with extremely large count, and is likely to crash the machine is bizarre ways.
      
      This bug can currently only be triggered by reading from an md
      sysfs attribute declared with __ATTR_PREALLOC() during the
      brief period between when mddev_put() deletes an mddev from
      the ->all_mddevs list, and when mddev_delayed_delete() - which is
      scheduled on a workqueue - completes.
      Before this, an error won't be returned by the ->show()
      After this, the ->show() won't be called.
      
      I can reproduce it reliably only by putting delay like
      	usleep_range(500000,700000);
      early in mddev_delayed_delete(). Then after creating an
      md device md0 run
        echo clear > /sys/block/md0/md/array_state; cat /sys/block/md0/md/array_state
      
      The bug can be triggered without the usleep.
      
      Fixes: 65da3484 ("sysfs: correctly handle short reads on PREALLOC attrs.")
      Fixes: 17d0774f ("sysfs: correctly handle read offset on PREALLOC attrs")
      Signed-off-by: default avatarNeilBrown <neilb@suse.com>
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      Reported-and-tested-by: default avatarMiroslav Benes <mbenes@suse.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      38b4b8a0
    • Tomasz Nowicki's avatar
      PCI: thunder-pem: Fix legacy firmware PEM-specific resources · a7096135
      Tomasz Nowicki authored
      commit feb199eb upstream.
      
      SZ_16M PEM resource size includes PEM-specific register and its children
      resources. Reservation of the whole SZ_16M range leads to child device
      driver failure when pcieport driver is requesting resources:
      
        pcieport 0004:1f:00.0: can't enable device: BAR 0 [mem 0x87e0c0f00000-0x87e0c0ffffff 64bit] not claimed
      
      So we cannot reserve full 16M here and instead we want to reserve
      PEM-specific register only which is SZ_64K.
      
      At the end increase PEM resource to SZ_16M since this is what
      thunder_pem_init() call expects for proper initialization.
      
      Fixes: 9abb27c7 ("PCI: thunder-pem: Add legacy firmware support for Cavium ThunderX host controller")
      Signed-off-by: default avatarTomasz Nowicki <tn@semihalf.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a7096135