1. 09 Sep, 2018 40 commits
    • Shan Hai's avatar
      bcache: release dc->writeback_lock properly in bch_writeback_thread() · 3ddf06cd
      Shan Hai authored
      commit 3943b040 upstream.
      
      The writeback thread would exit with a lock held when the cache device
      is detached via sysfs interface, fix it by releasing the held lock
      before exiting the while-loop.
      
      Fixes: fadd94e0 (bcache: quit dc->writeback_thread when BCACHE_DEV_DETACHING is set)
      Signed-off-by: default avatarShan Hai <shan.hai@oracle.com>
      Signed-off-by: default avatarColy Li <colyli@suse.de>
      Tested-by: default avatarShenghui Wang <shhuiw@foxmail.com>
      Cc: stable@vger.kernel.org #4.17+
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3ddf06cd
    • Steven Rostedt (VMware)'s avatar
      printk/tracing: Do not trace printk_nmi_enter() · 6c6d1748
      Steven Rostedt (VMware) authored
      commit d1c392c9 upstream.
      
      I hit the following splat in my tests:
      
      ------------[ cut here ]------------
      IRQs not enabled as expected
      WARNING: CPU: 3 PID: 0 at kernel/time/tick-sched.c:982 tick_nohz_idle_enter+0x44/0x8c
      Modules linked in: ip6t_REJECT nf_reject_ipv6 ip6table_filter ip6_tables ipv6
      CPU: 3 PID: 0 Comm: swapper/3 Not tainted 4.19.0-rc2-test+ #2
      Hardware name: MSI MS-7823/CSM-H87M-G43 (MS-7823), BIOS V1.6 02/22/2014
      EIP: tick_nohz_idle_enter+0x44/0x8c
      Code: ec 05 00 00 00 75 26 83 b8 c0 05 00 00 00 75 1d 80 3d d0 36 3e c1 00
      75 14 68 94 63 12 c1 c6 05 d0 36 3e c1 01 e8 04 ee f8 ff <0f> 0b 58 fa bb a0
      e5 66 c1 e8 25 0f 04 00 64 03 1d 28 31 52 c1 8b
      EAX: 0000001c EBX: f26e7f8c ECX: 00000006 EDX: 00000007
      ESI: f26dd1c0 EDI: 00000000 EBP: f26e7f40 ESP: f26e7f38
      DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068 EFLAGS: 00010296
      CR0: 80050033 CR2: 0813c6b0 CR3: 2f342000 CR4: 001406f0
      Call Trace:
       do_idle+0x33/0x202
       cpu_startup_entry+0x61/0x63
       start_secondary+0x18e/0x1ed
       startup_32_smp+0x164/0x168
      irq event stamp: 18773830
      hardirqs last  enabled at (18773829): [<c040150c>] trace_hardirqs_on_thunk+0xc/0x10
      hardirqs last disabled at (18773830): [<c040151c>] trace_hardirqs_off_thunk+0xc/0x10
      softirqs last  enabled at (18773824): [<c0ddaa6f>] __do_softirq+0x25f/0x2bf
      softirqs last disabled at (18773767): [<c0416bbe>] call_on_stack+0x45/0x4b
      ---[ end trace b7c64aa79e17954a ]---
      
      After a bit of debugging, I found what was happening. This would trigger
      when performing "perf" with a high NMI interrupt rate, while enabling and
      disabling function tracer. Ftrace uses breakpoints to convert the nops at
      the start of functions to calls to the function trampolines. The breakpoint
      traps disable interrupts and this makes calls into lockdep via the
      trace_hardirqs_off_thunk in the entry.S code. What happens is the following:
      
        do_idle {
      
          [interrupts enabled]
      
          <interrupt> [interrupts disabled]
      	TRACE_IRQS_OFF [lockdep says irqs off]
      	[...]
      	TRACE_IRQS_IRET
      	    test if pt_regs say return to interrupts enabled [yes]
      	    TRACE_IRQS_ON [lockdep says irqs are on]
      
      	    <nmi>
      		nmi_enter() {
      		    printk_nmi_enter() [traced by ftrace]
      		    [ hit ftrace breakpoint ]
      		    <breakpoint exception>
      			TRACE_IRQS_OFF [lockdep says irqs off]
      			[...]
      			TRACE_IRQS_IRET [return from breakpoint]
      			   test if pt_regs say interrupts enabled [no]
      			   [iret back to interrupt]
      	   [iret back to code]
      
          tick_nohz_idle_enter() {
      
      	lockdep_assert_irqs_enabled() [lockdep say no!]
      
      Although interrupts are indeed enabled, lockdep thinks it is not, and since
      we now do asserts via lockdep, it gives a false warning. The issue here is
      that printk_nmi_enter() is called before lockdep_off(), which disables
      lockdep (for this reason) in NMIs. By simply not allowing ftrace to see
      printk_nmi_enter() (via notrace annotation) we keep lockdep from getting
      confused.
      
      Cc: stable@vger.kernel.org
      Fixes: 42a0bb3f ("printk/nmi: generic solution for safe printk in NMI")
      Acked-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Acked-by: default avatarPetr Mladek <pmladek@suse.com>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6c6d1748
    • Vishal Verma's avatar
      libnvdimm: fix ars_status output length calculation · 05a085c7
      Vishal Verma authored
      commit 286e8771 upstream.
      
      Commit efda1b5d ("acpi, nfit, libnvdimm: fix / harden ars_status output length handling")
      Introduced additional hardening for ambiguity in the ACPI spec for
      ars_status output sizing. However, it had a couple of cases mixed up.
      Where it should have been checking for (and returning) "out_field[1] -
      4" it was using "out_field[1] - 8" and vice versa.
      
      This caused a four byte discrepancy in the buffer size passed on to
      the command handler, and in some cases, this caused memory corruption
      like:
      
        ./daxdev-errors.sh: line 76: 24104 Aborted   (core dumped) ./daxdev-errors $busdev $region
        malloc(): memory corruption
        Program received signal SIGABRT, Aborted.
        [...]
        #5  0x00007ffff7865a2e in calloc () from /lib64/libc.so.6
        #6  0x00007ffff7bc2970 in ndctl_bus_cmd_new_ars_status (ars_cap=ars_cap@entry=0x6153b0) at ars.c:136
        #7  0x0000000000401644 in check_ars_status (check=0x7fffffffdeb0, bus=0x604c20) at daxdev-errors.c:144
        #8  test_daxdev_clear_error (region_name=<optimized out>, bus_name=<optimized out>)
            at daxdev-errors.c:332
      
      Cc: <stable@vger.kernel.org>
      Cc: Dave Jiang <dave.jiang@intel.com>
      Cc: Keith Busch <keith.busch@intel.com>
      Cc: Lukasz Dorau <lukasz.dorau@intel.com>
      Cc: Dan Williams <dan.j.williams@intel.com>
      Fixes: efda1b5d ("acpi, nfit, libnvdimm: fix / harden ars_status output length handling")
      Signed-off-by: default avatarVishal Verma <vishal.l.verma@intel.com>
      Reviewed-by: default avatarKeith Busch <keith.busch@intel.com>
      Signed-of-by: default avatarDave Jiang <dave.jiang@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      05a085c7
    • Christian Brauner's avatar
      getxattr: use correct xattr length · 6fdad64a
      Christian Brauner authored
      commit 82c9a927 upstream.
      
      When running in a container with a user namespace, if you call getxattr
      with name = "system.posix_acl_access" and size % 8 != 4, then getxattr
      silently skips the user namespace fixup that it normally does resulting in
      un-fixed-up data being returned.
      This is caused by posix_acl_fix_xattr_to_user() being passed the total
      buffer size and not the actual size of the xattr as returned by
      vfs_getxattr().
      This commit passes the actual length of the xattr as returned by
      vfs_getxattr() down.
      
      A reproducer for the issue is:
      
        touch acl_posix
      
        setfacl -m user:0:rwx acl_posix
      
      and the compile:
      
        #define _GNU_SOURCE
        #include <errno.h>
        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
        #include <sys/types.h>
        #include <unistd.h>
        #include <attr/xattr.h>
      
        /* Run in user namespace with nsuid 0 mapped to uid != 0 on the host. */
        int main(int argc, void **argv)
        {
                ssize_t ret1, ret2;
                char buf1[128], buf2[132];
                int fret = EXIT_SUCCESS;
                char *file;
      
                if (argc < 2) {
                        fprintf(stderr,
                                "Please specify a file with "
                                "\"system.posix_acl_access\" permissions set\n");
                        _exit(EXIT_FAILURE);
                }
                file = argv[1];
      
                ret1 = getxattr(file, "system.posix_acl_access",
                                buf1, sizeof(buf1));
                if (ret1 < 0) {
                        fprintf(stderr, "%s - Failed to retrieve "
                                        "\"system.posix_acl_access\" "
                                        "from \"%s\"\n", strerror(errno), file);
                        _exit(EXIT_FAILURE);
                }
      
                ret2 = getxattr(file, "system.posix_acl_access",
                                buf2, sizeof(buf2));
                if (ret2 < 0) {
                        fprintf(stderr, "%s - Failed to retrieve "
                                        "\"system.posix_acl_access\" "
                                        "from \"%s\"\n", strerror(errno), file);
                        _exit(EXIT_FAILURE);
                }
      
                if (ret1 != ret2) {
                        fprintf(stderr, "The value of \"system.posix_acl_"
                                        "access\" for file \"%s\" changed "
                                        "between two successive calls\n", file);
                        _exit(EXIT_FAILURE);
                }
      
                for (ssize_t i = 0; i < ret2; i++) {
                        if (buf1[i] == buf2[i])
                                continue;
      
                        fprintf(stderr,
                                "Unexpected different in byte %zd: "
                                "%02x != %02x\n", i, buf1[i], buf2[i]);
                        fret = EXIT_FAILURE;
                }
      
                if (fret == EXIT_SUCCESS)
                        fprintf(stderr, "Test passed\n");
                else
                        fprintf(stderr, "Test failed\n");
      
                _exit(fret);
        }
      and run:
      
        ./tester acl_posix
      
      On a non-fixed up kernel this should return something like:
      
        root@c1:/# ./t
        Unexpected different in byte 16: ffffffa0 != 00
        Unexpected different in byte 17: ffffff86 != 00
        Unexpected different in byte 18: 01 != 00
      
      and on a fixed kernel:
      
        root@c1:~# ./t
        Test passed
      
      Cc: stable@vger.kernel.org
      Fixes: 2f6f0654 ("userns: Convert vfs posix_acl support to use kuids and kgids")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=199945Reported-by: default avatarColin Watson <cjwatson@ubuntu.com>
      Signed-off-by: default avatarChristian Brauner <christian@brauner.io>
      Acked-by: default avatarSerge Hallyn <serge@hallyn.com>
      Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6fdad64a
    • Mikulas Patocka's avatar
      udlfb: set optimal write delay · a328c4ce
      Mikulas Patocka authored
      commit bb24153a upstream.
      
      The default delay 5 jiffies is too much when the kernel is compiled with
      HZ=100 - it results in jumpy cursor in Xwindow.
      
      In order to find out the optimal delay, I benchmarked the driver on
      1280x720x30fps video. I found out that with HZ=1000, 10ms is acceptable,
      but with HZ=250 or HZ=300, we need 4ms, so that the video is played
      without any frame skips.
      
      This patch changes the delay to this value.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a328c4ce
    • Mikulas Patocka's avatar
      fb: fix lost console when the user unplugs a USB adapter · 3752de78
      Mikulas Patocka authored
      commit 8c5b0442 upstream.
      
      I have a USB display adapter using the udlfb driver and I use it on an ARM
      board that doesn't have any graphics card. When I plug the adapter in, the
      console is properly displayed, however when I unplug and re-plug the
      adapter, the console is not displayed and I can't access it until I reboot
      the board.
      
      The reason is this:
      When the adapter is unplugged, dlfb_usb_disconnect calls
      unlink_framebuffer, then it waits until the reference count drops to zero
      and then it deallocates the framebuffer. However, the console that is
      attached to the framebuffer device keeps the reference count non-zero, so
      the framebuffer device is never destroyed. When the USB adapter is plugged
      again, it creates a new device /dev/fb1 and the console is not attached to
      it.
      
      This patch fixes the bug by unbinding the console from unlink_framebuffer.
      The code to unbind the console is moved from do_unregister_framebuffer to
      a function unbind_console. When the console is unbound, the reference
      count drops to zero and the udlfb driver frees the framebuffer. When the
      adapter is plugged back, a new framebuffer is created and the console is
      attached to it.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Bernie Thompson <bernie@plugable.com>
      Cc: Ladislav Michl <ladis@linux-mips.org>
      Cc: stable@vger.kernel.org
      [b.zolnierkie: preserve old behavior for do_unregister_framebuffer()]
      Signed-off-by: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3752de78
    • Vignesh R's avatar
      pwm: tiehrpwm: Fix disabling of output of PWMs · 8001317c
      Vignesh R authored
      commit 38dabd91 upstream.
      
      pwm-tiehrpwm driver disables PWM output by putting it in low output
      state via active AQCSFRC register in ehrpwm_pwm_disable(). But, the
      AQCSFRC shadow register is not updated. Therefore, when shadow AQCSFRC
      register is re-enabled in ehrpwm_pwm_enable() (say to enable second PWM
      output), previous settings are lost as shadow register value is loaded
      into active register. This results in things like PWMA getting enabled
      automatically, when PWMB is enabled and vice versa. Fix this by
      updating AQCSFRC shadow register as well during ehrpwm_pwm_disable().
      
      Fixes: 19891b20 ("pwm: pwm-tiehrpwm: PWM driver support for EHRPWM")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarVignesh R <vigneshr@ti.com>
      Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8001317c
    • Richard Weinberger's avatar
      ubifs: Fix synced_i_size calculation for xattr inodes · 36ac3a01
      Richard Weinberger authored
      commit 59965593 upstream.
      
      In ubifs_jnl_update() we sync parent and child inodes to the flash,
      in case of xattrs, the parent inode (AKA host inode) has a non-zero
      data_len. Therefore we need to adjust synced_i_size too.
      
      This issue was reported by ubifs self tests unter a xattr related work
      load.
      UBIFS error (ubi0:0 pid 1896): dbg_check_synced_i_size: ui_size is 4, synced_i_size is 0, but inode is clean
      UBIFS error (ubi0:0 pid 1896): dbg_check_synced_i_size: i_ino 65, i_mode 0x81a4, i_size 4
      
      Cc: <stable@vger.kernel.org>
      Fixes: 1e51764a ("UBIFS: add new flash file system")
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      36ac3a01
    • Richard Weinberger's avatar
      ubifs: Check data node size before truncate · 1bc1f0f7
      Richard Weinberger authored
      commit 95a22d20 upstream.
      
      Check whether the size is within bounds before using it.
      If the size is not correct, abort and dump the bad data node.
      
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Silvio Cesare <silvio.cesare@gmail.com>
      Cc: stable@vger.kernel.org
      Fixes: 1e51764a ("UBIFS: add new flash file system")
      Reported-by: default avatarSilvio Cesare <silvio.cesare@gmail.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1bc1f0f7
    • Richard Weinberger's avatar
      Revert "UBIFS: Fix potential integer overflow in allocation" · 48e11484
      Richard Weinberger authored
      commit 08acbdd6 upstream.
      
      This reverts commit 353748a3.
      It bypassed the linux-mtd review process and fixes the issue not as it
      should.
      
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Silvio Cesare <silvio.cesare@gmail.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      48e11484
    • Richard Weinberger's avatar
      ubifs: Fix memory leak in lprobs self-check · 0d1694b1
      Richard Weinberger authored
      commit eef19816 upstream.
      
      Allocate the buffer after we return early.
      Otherwise memory is being leaked.
      
      Cc: <stable@vger.kernel.org>
      Fixes: 1e51764a ("UBIFS: add new flash file system")
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0d1694b1
    • Jann Horn's avatar
      userns: move user access out of the mutex · a56a1543
      Jann Horn authored
      commit 5820f140 upstream.
      
      The old code would hold the userns_state_mutex indefinitely if
      memdup_user_nul stalled due to e.g. a userfault region. Prevent that by
      moving the memdup_user_nul in front of the mutex_lock().
      
      Note: This changes the error precedence of invalid buf/count/*ppos vs
      map already written / capabilities missing.
      
      Fixes: 22d917d8 ("userns: Rework the user_namespace adding uid/gid...")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Acked-by: default avatarChristian Brauner <christian@brauner.io>
      Acked-by: default avatarSerge Hallyn <serge@hallyn.com>
      Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a56a1543
    • Jann Horn's avatar
      sys: don't hold uts_sem while accessing userspace memory · 55463c60
      Jann Horn authored
      commit 42a0cc34 upstream.
      
      Holding uts_sem as a writer while accessing userspace memory allows a
      namespace admin to stall all processes that attempt to take uts_sem.
      Instead, move data through stack buffers and don't access userspace memory
      while uts_sem is held.
      
      Cc: stable@vger.kernel.org
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      55463c60
    • Al Viro's avatar
      osf_getdomainname(): use copy_to_user() · d2f96e17
      Al Viro authored
      commit 9ba3eb51 upstream.
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d2f96e17
    • Jacob Pan's avatar
      iommu/vt-d: Fix dev iotlb pfsid use · b68377cb
      Jacob Pan authored
      commit 1c48db44 upstream.
      
      PFSID should be used in the invalidation descriptor for flushing
      device IOTLBs on SRIOV VFs.
      Signed-off-by: default avatarJacob Pan <jacob.jun.pan@linux.intel.com>
      Cc: stable@vger.kernel.org
      Cc: "Ashok Raj" <ashok.raj@intel.com>
      Cc: "Lu Baolu" <baolu.lu@linux.intel.com>
      Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b68377cb
    • Jacob Pan's avatar
      iommu/vt-d: Add definitions for PFSID · eada1b22
      Jacob Pan authored
      commit 0f725561 upstream.
      
      When SRIOV VF device IOTLB is invalidated, we need to provide
      the PF source ID such that IOMMU hardware can gauge the depth
      of invalidation queue which is shared among VFs. This is needed
      when device invalidation throttle (DIT) capability is supported.
      
      This patch adds bit definitions for checking and tracking PFSID.
      Signed-off-by: default avatarJacob Pan <jacob.jun.pan@linux.intel.com>
      Cc: stable@vger.kernel.org
      Cc: "Ashok Raj" <ashok.raj@intel.com>
      Cc: "Lu Baolu" <baolu.lu@linux.intel.com>
      Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      eada1b22
    • Peter Zijlstra's avatar
      mm/tlb: Remove tlb_remove_table() non-concurrent condition · 04d1d58c
      Peter Zijlstra authored
      commit a6f57208 upstream.
      
      Will noted that only checking mm_users is incorrect; we should also
      check mm_count in order to cover CPUs that have a lazy reference to
      this mm (and could do speculative TLB operations).
      
      If removing this turns out to be a performance issue, we can
      re-instate a more complete check, but in tlb_table_flush() eliding the
      call_rcu_sched().
      
      Fixes: 26723911 ("mm, powerpc: move the RCU page-table freeing into generic code")
      Reported-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: default avatarRik van Riel <riel@surriel.com>
      Acked-by: default avatarWill Deacon <will.deacon@arm.com>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: David Miller <davem@davemloft.net>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: stable@kernel.org
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      04d1d58c
    • Yannik Sembritzki's avatar
      Fix kexec forbidding kernels signed with keys in the secondary keyring to boot · 7c439bc2
      Yannik Sembritzki authored
      commit ea93102f upstream.
      
      The split of .system_keyring into .builtin_trusted_keys and
      .secondary_trusted_keys broke kexec, thereby preventing kernels signed by
      keys which are now in the secondary keyring from being kexec'd.
      
      Fix this by passing VERIFY_USE_SECONDARY_KEYRING to
      verify_pefile_signature().
      
      Fixes: d3bfe841 ("certs: Add a secondary system keyring that can be added to dynamically")
      Signed-off-by: default avatarYannik Sembritzki <yannik@sembritzki.me>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Cc: kexec@lists.infradead.org
      Cc: keyrings@vger.kernel.org
      Cc: linux-security-module@vger.kernel.org
      Cc: stable@kernel.org
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7c439bc2
    • Yannik Sembritzki's avatar
      Replace magic for trusting the secondary keyring with #define · 40b08cda
      Yannik Sembritzki authored
      commit 817aef26 upstream.
      
      Replace the use of a magic number that indicates that verify_*_signature()
      should use the secondary keyring with a symbol.
      Signed-off-by: default avatarYannik Sembritzki <yannik@sembritzki.me>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Cc: keyrings@vger.kernel.org
      Cc: linux-security-module@vger.kernel.org
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      40b08cda
    • Jon Hunter's avatar
      ARM: tegra: Fix Tegra30 Cardhu PCA954x reset · ba99ff79
      Jon Hunter authored
      commit 6e181190 upstream.
      
      On all versions of Tegra30 Cardhu, the reset signal to the NXP PCA9546
      I2C mux is connected to the Tegra GPIO BB0. Currently, this pin on the
      Tegra is not configured as a GPIO but as a special-function IO (SFIO)
      that is multiplexing the pin to an I2S controller. On exiting system
      suspend, I2C commands sent to the PCA9546 are failing because there is
      no ACK. Although it is not possible to see exactly what is happening
      to the reset during suspend, by ensuring it is configured as a GPIO
      and driven high, to de-assert the reset, the failures are no longer
      seen.
      
      Please note that this GPIO is also used to drive the reset signal
      going to the camera connector on the board. However, given that there
      is no camera support currently for Cardhu, this should not have any
      impact.
      
      Fixes: 40431d16 ("ARM: tegra: enable PCA9546 on Cardhu")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ba99ff79
    • Bill Baker's avatar
      NFSv4 client live hangs after live data migration recovery · b5bc39d4
      Bill Baker authored
      commit 0f90be13 upstream.
      
      After a live data migration event at the NFS server, the client may send
      I/O requests to the wrong server, causing a live hang due to repeated
      recovery events.  On the wire, this will appear as an I/O request failing
      with NFS4ERR_BADSESSION, followed by successful CREATE_SESSION, repeatedly.
      NFS4ERR_BADSSESSION is returned because the session ID being used was
      issued by the other server and is not valid at the old server.
      
      The failure is caused by async worker threads having cached the transport
      (xprt) in the rpc_task structure.  After the migration recovery completes,
      the task is redispatched and the task resends the request to the wrong
      server based on the old value still present in tk_xprt.
      
      The solution is to recompute the tk_xprt field of the rpc_task structure
      so that the request goes to the correct server.
      Signed-off-by: default avatarBill Baker <bill.baker@oracle.com>
      Reviewed-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Tested-by: default avatarHelen Chao <helen.chao@oracle.com>
      Fixes: fb43d172 ("SUNRPC: Use the multipath iterator to assign a ...")
      Cc: stable@vger.kernel.org # v4.9+
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b5bc39d4
    • Dan Carpenter's avatar
      pnfs/blocklayout: off by one in bl_map_stripe() · 9ba1a9ea
      Dan Carpenter authored
      commit 0914bb96 upstream.
      
      "dev->nr_children" is the number of children which were parsed
      successfully in bl_parse_stripe().  It could be all of them and then, in
      that case, it is equal to v->stripe.volumes_count.  Either way, the >
      should be >= so that we don't go beyond the end of what we're supposed
      to.
      
      Fixes: 5c83746a ("pnfs/blocklayout: in-kernel GETDEVICEINFO XDR parsing")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Cc: stable@vger.kernel.org # 3.17+
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9ba1a9ea
    • Max Filippov's avatar
      xtensa: increase ranges in ___invalidate_{i,d}cache_all · 7f2163b5
      Max Filippov authored
      commit fec3259c upstream.
      
      Cache invalidation macros use cache line size to iterate over
      invalidated cache lines, assuming that all cache ways are invalidated by
      single instruction, but xtensa ISA recommends to not assume that for
      future compatibility:
        In some implementations all ways at index Addry-1..z are invalidated
        regardless of the specified way, but for future compatibility this
        behavior should not be assumed.
      
      Iterate over all cache ways in ___invalidate_icache_all and
      ___invalidate_dcache_all.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7f2163b5
    • Max Filippov's avatar
      xtensa: limit offsets in __loop_cache_{all,page} · e996a24d
      Max Filippov authored
      commit be75de25 upstream.
      
      When building kernel for xtensa cores with big cache lines (e.g. 128
      bytes or more) __loop_cache_all and __loop_cache_page may generate
      assembly instructions with immediate fields that are too big. This
      results in the following build errors:
      
        arch/xtensa/mm/misc.S: Assembler messages:
        arch/xtensa/mm/misc.S:464: Error: operand 2 of 'diwbi' has invalid value '256'
        arch/xtensa/mm/misc.S:464: Error: operand 2 of 'diwbi' has invalid value '384'
        arch/xtensa/kernel/head.S: Assembler messages:
        arch/xtensa/kernel/head.S:172: Error: operand 2 of 'diu' has invalid value '256'
        arch/xtensa/kernel/head.S:172: Error: operand 2 of 'diu' has invalid value '384'
        arch/xtensa/kernel/head.S:176: Error: operand 2 of 'iiu' has invalid value '256'
        arch/xtensa/kernel/head.S:176: Error: operand 2 of 'iiu' has invalid value '384'
        arch/xtensa/kernel/head.S:255: Error: operand 2 of 'diwb' has invalid value '256'
        arch/xtensa/kernel/head.S:255: Error: operand 2 of 'diwb' has invalid value '384'
      
      Add parameter max_immed to these macros and use it to limit values of
      immediate operands. Extract common code of these macros into the new
      macro __loop_cache_unroll.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e996a24d
    • Paolo Bonzini's avatar
      KVM: VMX: fixes for vmentry_l1d_flush module parameter · 8729412c
      Paolo Bonzini authored
      commit 0027ff2a upstream.
      
      Two bug fixes:
      
      1) missing entries in the l1d_param array; this can cause a host crash
      if an access attempts to reach the missing entry. Future-proof the get
      function against any overflows as well.  However, the two entries
      VMENTER_L1D_FLUSH_EPT_DISABLED and VMENTER_L1D_FLUSH_NOT_REQUIRED must
      not be accepted by the parse function, so disable them there.
      
      2) invalid values must be rejected even if the CPU does not have the
      bug, so test for them before checking boot_cpu_has(X86_BUG_L1TF)
      
      ... and a small refactoring, since the .cmd field is redundant with
      the index in the array.
      Reported-by: default avatarBandan Das <bsd@redhat.com>
      Cc: stable@vger.kernel.org
      Fixes: a7b9020bSigned-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8729412c
    • zhangyi (F)'s avatar
      PM / sleep: wakeup: Fix build error caused by missing SRCU support · 18c5d285
      zhangyi (F) authored
      commit 3df6f61f upstream.
      
      Commit ea0212f4 (power: auto select CONFIG_SRCU) made the code in
      drivers/base/power/wakeup.c use SRCU instead of RCU, but it forgot to
      select CONFIG_SRCU in Kconfig, which leads to the following build
      error if CONFIG_SRCU is not selected somewhere else:
      
      drivers/built-in.o: In function `wakeup_source_remove':
      (.text+0x3c6fc): undefined reference to `synchronize_srcu'
      drivers/built-in.o: In function `pm_print_active_wakeup_sources':
      (.text+0x3c7a8): undefined reference to `__srcu_read_lock'
      drivers/built-in.o: In function `pm_print_active_wakeup_sources':
      (.text+0x3c84c): undefined reference to `__srcu_read_unlock'
      drivers/built-in.o: In function `device_wakeup_arm_wake_irqs':
      (.text+0x3d1d8): undefined reference to `__srcu_read_lock'
      drivers/built-in.o: In function `device_wakeup_arm_wake_irqs':
      (.text+0x3d228): undefined reference to `__srcu_read_unlock'
      drivers/built-in.o: In function `device_wakeup_disarm_wake_irqs':
      (.text+0x3d24c): undefined reference to `__srcu_read_lock'
      drivers/built-in.o: In function `device_wakeup_disarm_wake_irqs':
      (.text+0x3d29c): undefined reference to `__srcu_read_unlock'
      drivers/built-in.o:(.data+0x4158): undefined reference to `process_srcu'
      
      Fix this error by selecting CONFIG_SRCU when PM_SLEEP is enabled.
      
      Fixes: ea0212f4 (power: auto select CONFIG_SRCU)
      Cc: 4.2+ <stable@vger.kernel.org> # 4.2+
      Signed-off-by: default avatarzhangyi (F) <yi.zhang@huawei.com>
      [ rjw: Minor subject/changelog fixups ]
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      18c5d285
    • Tomas Bortoli's avatar
      9p: fix multiple NULL-pointer-dereferences · 3ac733eb
      Tomas Bortoli authored
      commit 10aa1452 upstream.
      
      Added checks to prevent GPFs from raising.
      
      Link: http://lkml.kernel.org/r/20180727110558.5479-1-tomasbortoli@gmail.comSigned-off-by: default avatarTomas Bortoli <tomasbortoli@gmail.com>
      Reported-by: syzbot+1a262da37d3bead15c39@syzkaller.appspotmail.com
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarDominique Martinet <dominique.martinet@cea.fr>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3ac733eb
    • Rafael David Tinoco's avatar
      mfd: hi655x: Fix regmap area declared size for hi655x · 262f38fa
      Rafael David Tinoco authored
      commit 6afebb70 upstream.
      
      Fixes https://bugs.linaro.org/show_bug.cgi?id=3903
      
      LTP Functional tests have caused a bad paging request when triggering
      the regmap_read_debugfs() logic of the device PMIC Hi6553 (reading
      regmap/f8000000.pmic/registers file during read_all test):
      
      Unable to handle kernel paging request at virtual address ffff0
      [ffff00000984e000] pgd=0000000077ffe803, pud=0000000077ffd803,0
      Internal error: Oops: 96000007 [#1] SMP
      ...
      Hardware name: HiKey Development Board (DT)
      ...
      Call trace:
       regmap_mmio_read8+0x24/0x40
       regmap_mmio_read+0x48/0x70
       _regmap_bus_reg_read+0x38/0x48
       _regmap_read+0x68/0x170
       regmap_read+0x50/0x78
       regmap_read_debugfs+0x1a0/0x308
       regmap_map_read_file+0x48/0x58
       full_proxy_read+0x68/0x98
       __vfs_read+0x48/0x80
       vfs_read+0x94/0x150
       SyS_read+0x6c/0xd8
       el0_svc_naked+0x30/0x34
      Code: aa1e03e0 d503201f f9400280 8b334000 (39400000)
      
      Investigations have showed that, when triggered by debugfs read()
      handler, the mmio regmap logic was reading a bigger (16k) register area
      than the one mapped by devm_ioremap_resource() during hi655x-pmic probe
      time (4k).
      
      This commit changes hi655x's max register, according to HW specs, to be
      the same as the one declared in the pmic device in hi6220's dts, fixing
      the issue.
      
      Cc: <stable@vger.kernel.org> #v4.9 #v4.14 #v4.16 #v4.17
      Signed-off-by: default avatarRafael David Tinoco <rafael.tinoco@linaro.org>
      Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      262f38fa
    • Steven Rostedt (VMware)'s avatar
      uprobes: Use synchronize_rcu() not synchronize_sched() · 0ef60632
      Steven Rostedt (VMware) authored
      commit 016f8ffc upstream.
      
      While debugging another bug, I was looking at all the synchronize*()
      functions being used in kernel/trace, and noticed that trace_uprobes was
      using synchronize_sched(), with a comment to synchronize with
      {u,ret}_probe_trace_func(). When looking at those functions, the data is
      protected with "rcu_read_lock()" and not with "rcu_read_lock_sched()". This
      is using the wrong synchronize_*() function.
      
      Link: http://lkml.kernel.org/r/20180809160553.469e1e32@gandalf.local.home
      
      Cc: stable@vger.kernel.org
      Fixes: 70ed91c6 ("tracing/uprobes: Support ftrace_event_file base multibuffer")
      Acked-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0ef60632
    • Steven Rostedt (VMware)'s avatar
      tracing/blktrace: Fix to allow setting same value · 941ca8db
      Steven Rostedt (VMware) authored
      commit 757d9140 upstream.
      
      Masami Hiramatsu reported:
      
        Current trace-enable attribute in sysfs returns an error
        if user writes the same setting value as current one,
        e.g.
      
          # cat /sys/block/sda/trace/enable
          0
          # echo 0 > /sys/block/sda/trace/enable
          bash: echo: write error: Invalid argument
          # echo 1 > /sys/block/sda/trace/enable
          # echo 1 > /sys/block/sda/trace/enable
          bash: echo: write error: Device or resource busy
      
        But this is not a preferred behavior, it should ignore
        if new setting is same as current one. This fixes the
        problem as below.
      
          # cat /sys/block/sda/trace/enable
          0
          # echo 0 > /sys/block/sda/trace/enable
          # echo 1 > /sys/block/sda/trace/enable
          # echo 1 > /sys/block/sda/trace/enable
      
      Link: http://lkml.kernel.org/r/20180816103802.08678002@gandalf.local.home
      
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: linux-block@vger.kernel.org
      Cc: stable@vger.kernel.org
      Fixes: cd649b8b ("blktrace: remove sysfs_blk_trace_enable_show/store()")
      Reported-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      941ca8db
    • Steven Rostedt (VMware)'s avatar
      tracing: Do not call start/stop() functions when tracing_on does not change · dc697314
      Steven Rostedt (VMware) authored
      commit f143641b upstream.
      
      Currently, when one echo's in 1 into tracing_on, the current tracer's
      "start()" function is executed, even if tracing_on was already one. This can
      lead to strange side effects. One being that if the hwlat tracer is enabled,
      and someone does "echo 1 > tracing_on" into tracing_on, the hwlat tracer's
      start() function is called again which will recreate another kernel thread,
      and make it unable to remove the old one.
      
      Link: http://lkml.kernel.org/r/1533120354-22923-1-git-send-email-erica.bugden@linutronix.de
      
      Cc: stable@vger.kernel.org
      Fixes: 2df8f8a6 ("tracing: Fix regression with irqsoff tracer and tracing_on file")
      Reported-by: default avatarErica Bugden <erica.bugden@linutronix.de>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dc697314
    • Johan Hovold's avatar
      rtc: omap: fix potential crash on power off · 4e935c2e
      Johan Hovold authored
      commit 5c8b84f4 upstream.
      
      Do not set the system power-off callback and omap power-off rtc pointer
      until we're done setting up our device to avoid leaving stale pointers
      around after a late probe error.
      
      Fixes: 97ea1906 ("rtc: omap: Support ext_wakeup configuration")
      Cc: stable <stable@vger.kernel.org>     # 4.9
      Cc: Marcin Niestroj <m.niestroj@grinn-global.com>
      Cc: Tony Lindgren <tony@atomide.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Acked-by: default avatarTony Lindgren <tony@atomide.com>
      Reviewed-by: default avatarMarcin Niestroj <m.niestroj@grinn-global.com>
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e935c2e
    • Nadav Amit's avatar
      vmw_balloon: fix VMCI use when balloon built into kernel · 604c8018
      Nadav Amit authored
      commit c3cc1b0f upstream.
      
      Currently, when all modules, including VMCI and VMware balloon are built
      into the kernel, the initialization of the balloon happens before the
      VMCI is probed. As a result, the balloon fails to initialize the VMCI
      doorbell, which it uses to get asynchronous requests for balloon size
      changes.
      
      The problem can be seen in the logs, in the form of the following
      message:
      	"vmw_balloon: failed to initialize vmci doorbell"
      
      The driver would work correctly but slightly less efficiently, probing
      for requests periodically. This patch changes the balloon to be
      initialized using late_initcall() instead of module_init() to address
      this issue. It does not address a situation in which VMCI is built as a
      module and the balloon is built into the kernel.
      
      Fixes: 48e3d668 ("VMware balloon: Enable notification via VMCI")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarXavier Deguillard <xdeguillard@vmware.com>
      Signed-off-by: default avatarNadav Amit <namit@vmware.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      604c8018
    • Nadav Amit's avatar
      vmw_balloon: VMCI_DOORBELL_SET does not check status · 1893974d
      Nadav Amit authored
      commit ce664331 upstream.
      
      When vmballoon_vmci_init() sets a doorbell using VMCI_DOORBELL_SET, for
      some reason it does not consider the status and looks at the result.
      However, the hypervisor does not update the result - it updates the
      status. This might cause VMCI doorbell not to be enabled, resulting in
      degraded performance.
      
      Fixes: 48e3d668 ("VMware balloon: Enable notification via VMCI")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarXavier Deguillard <xdeguillard@vmware.com>
      Signed-off-by: default avatarNadav Amit <namit@vmware.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1893974d
    • Nadav Amit's avatar
      vmw_balloon: do not use 2MB without batching · fa51177b
      Nadav Amit authored
      commit 5081efd1 upstream.
      
      If the hypervisor sets 2MB batching is on, while batching is cleared,
      the balloon code breaks. In this case the legacy mechanism is used with
      2MB page. The VM would report a 2MB page is ballooned, and the
      hypervisor would only take the first 4KB.
      
      While the hypervisor should not report such settings, make the code more
      robust by not enabling 2MB support without batching.
      
      Fixes: 365bd7ef ("VMware balloon: Support 2m page ballooning.")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarXavier Deguillard <xdeguillard@vmware.com>
      Signed-off-by: default avatarNadav Amit <nadav.amit@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fa51177b
    • Nadav Amit's avatar
      vmw_balloon: fix inflation of 64-bit GFNs · 0e0dd1a2
      Nadav Amit authored
      commit 09755690 upstream.
      
      When balloon batching is not supported by the hypervisor, the guest
      frame number (GFN) must fit in 32-bit. However, due to a bug, this check
      was mistakenly ignored. In practice, when total RAM is greater than
      16TB, the balloon does not work currently, making this bug unlikely to
      happen.
      
      Fixes: ef0f8f11 ("VMware balloon: partially inline vmballoon_reserve_page.")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarXavier Deguillard <xdeguillard@vmware.com>
      Signed-off-by: default avatarNadav Amit <namit@vmware.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0e0dd1a2
    • Lars-Peter Clausen's avatar
      iio: ad9523: Fix return value for ad952x_store() · d4e5a9ed
      Lars-Peter Clausen authored
      commit 9a5094ca upstream.
      
      A sysfs write callback function needs to either return the number of
      consumed characters or an error.
      
      The ad952x_store() function currently returns 0 if the input value was "0",
      this will signal that no characters have been consumed and the function
      will be called repeatedly in a loop indefinitely. Fix this by returning
      number of supplied characters to indicate that the whole input string has
      been consumed.
      Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
      Fixes: cd1678f9 ("iio: frequency: New driver for AD9523 SPI Low Jitter Clock Generator")
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d4e5a9ed
    • Lars-Peter Clausen's avatar
      iio: ad9523: Fix displayed phase · 4e834c73
      Lars-Peter Clausen authored
      commit 5a4e33c1 upstream.
      
      Fix the displayed phase for the ad9523 driver. Currently the most
      significant decimal place is dropped and all other digits are shifted one
      to the left. This is due to a multiplication by 10, which is not necessary,
      so remove it.
      Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
      Fixes: cd1678f9 ("iio: frequency: New driver for AD9523 SPI Low Jitter Clock Generator")
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e834c73
    • Tycho Andersen's avatar
      uart: fix race between uart_put_char() and uart_shutdown() · e5147bbf
      Tycho Andersen authored
      commit a5ba1d95 upstream.
      
      We have reports of the following crash:
      
          PID: 7 TASK: ffff88085c6d61c0 CPU: 1 COMMAND: "kworker/u25:0"
          #0 [ffff88085c6db710] machine_kexec at ffffffff81046239
          #1 [ffff88085c6db760] crash_kexec at ffffffff810fc248
          #2 [ffff88085c6db830] oops_end at ffffffff81008ae7
          #3 [ffff88085c6db860] no_context at ffffffff81050b8f
          #4 [ffff88085c6db8b0] __bad_area_nosemaphore at ffffffff81050d75
          #5 [ffff88085c6db900] bad_area_nosemaphore at ffffffff81050e83
          #6 [ffff88085c6db910] __do_page_fault at ffffffff8105132e
          #7 [ffff88085c6db9b0] do_page_fault at ffffffff8105152c
          #8 [ffff88085c6db9c0] page_fault at ffffffff81a3f122
          [exception RIP: uart_put_char+149]
          RIP: ffffffff814b67b5 RSP: ffff88085c6dba78 RFLAGS: 00010006
          RAX: 0000000000000292 RBX: ffffffff827c5120 RCX: 0000000000000081
          RDX: 0000000000000000 RSI: 000000000000005f RDI: ffffffff827c5120
          RBP: ffff88085c6dba98 R8: 000000000000012c R9: ffffffff822ea320
          R10: ffff88085fe4db04 R11: 0000000000000001 R12: ffff881059f9c000
          R13: 0000000000000001 R14: 000000000000005f R15: 0000000000000fba
          ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018
          #9 [ffff88085c6dbaa0] tty_put_char at ffffffff81497544
          #10 [ffff88085c6dbac0] do_output_char at ffffffff8149c91c
          #11 [ffff88085c6dbae0] __process_echoes at ffffffff8149cb8b
          #12 [ffff88085c6dbb30] commit_echoes at ffffffff8149cdc2
          #13 [ffff88085c6dbb60] n_tty_receive_buf_fast at ffffffff8149e49b
          #14 [ffff88085c6dbbc0] __receive_buf at ffffffff8149ef5a
          #15 [ffff88085c6dbc20] n_tty_receive_buf_common at ffffffff8149f016
          #16 [ffff88085c6dbca0] n_tty_receive_buf2 at ffffffff8149f194
          #17 [ffff88085c6dbcb0] flush_to_ldisc at ffffffff814a238a
          #18 [ffff88085c6dbd50] process_one_work at ffffffff81090be2
          #19 [ffff88085c6dbe20] worker_thread at ffffffff81091b4d
          #20 [ffff88085c6dbeb0] kthread at ffffffff81096384
          #21 [ffff88085c6dbf50] ret_from_fork at ffffffff81a3d69f​
      
      after slogging through some dissasembly:
      
      ffffffff814b6720 <uart_put_char>:
      ffffffff814b6720:	55                   	push   %rbp
      ffffffff814b6721:	48 89 e5             	mov    %rsp,%rbp
      ffffffff814b6724:	48 83 ec 20          	sub    $0x20,%rsp
      ffffffff814b6728:	48 89 1c 24          	mov    %rbx,(%rsp)
      ffffffff814b672c:	4c 89 64 24 08       	mov    %r12,0x8(%rsp)
      ffffffff814b6731:	4c 89 6c 24 10       	mov    %r13,0x10(%rsp)
      ffffffff814b6736:	4c 89 74 24 18       	mov    %r14,0x18(%rsp)
      ffffffff814b673b:	e8 b0 8e 58 00       	callq  ffffffff81a3f5f0 <mcount>
      ffffffff814b6740:	4c 8b a7 88 02 00 00 	mov    0x288(%rdi),%r12
      ffffffff814b6747:	45 31 ed             	xor    %r13d,%r13d
      ffffffff814b674a:	41 89 f6             	mov    %esi,%r14d
      ffffffff814b674d:	49 83 bc 24 70 01 00 	cmpq   $0x0,0x170(%r12)
      ffffffff814b6754:	00 00
      ffffffff814b6756:	49 8b 9c 24 80 01 00 	mov    0x180(%r12),%rbx
      ffffffff814b675d:	00
      ffffffff814b675e:	74 2f                	je     ffffffff814b678f <uart_put_char+0x6f>
      ffffffff814b6760:	48 89 df             	mov    %rbx,%rdi
      ffffffff814b6763:	e8 a8 67 58 00       	callq  ffffffff81a3cf10 <_raw_spin_lock_irqsave>
      ffffffff814b6768:	41 8b 8c 24 78 01 00 	mov    0x178(%r12),%ecx
      ffffffff814b676f:	00
      ffffffff814b6770:	89 ca                	mov    %ecx,%edx
      ffffffff814b6772:	f7 d2                	not    %edx
      ffffffff814b6774:	41 03 94 24 7c 01 00 	add    0x17c(%r12),%edx
      ffffffff814b677b:	00
      ffffffff814b677c:	81 e2 ff 0f 00 00    	and    $0xfff,%edx
      ffffffff814b6782:	75 23                	jne    ffffffff814b67a7 <uart_put_char+0x87>
      ffffffff814b6784:	48 89 c6             	mov    %rax,%rsi
      ffffffff814b6787:	48 89 df             	mov    %rbx,%rdi
      ffffffff814b678a:	e8 e1 64 58 00       	callq  ffffffff81a3cc70 <_raw_spin_unlock_irqrestore>
      ffffffff814b678f:	44 89 e8             	mov    %r13d,%eax
      ffffffff814b6792:	48 8b 1c 24          	mov    (%rsp),%rbx
      ffffffff814b6796:	4c 8b 64 24 08       	mov    0x8(%rsp),%r12
      ffffffff814b679b:	4c 8b 6c 24 10       	mov    0x10(%rsp),%r13
      ffffffff814b67a0:	4c 8b 74 24 18       	mov    0x18(%rsp),%r14
      ffffffff814b67a5:	c9                   	leaveq
      ffffffff814b67a6:	c3                   	retq
      ffffffff814b67a7:	49 8b 94 24 70 01 00 	mov    0x170(%r12),%rdx
      ffffffff814b67ae:	00
      ffffffff814b67af:	48 63 c9             	movslq %ecx,%rcx
      ffffffff814b67b2:	41 b5 01             	mov    $0x1,%r13b
      ffffffff814b67b5:	44 88 34 0a          	mov    %r14b,(%rdx,%rcx,1)
      ffffffff814b67b9:	41 8b 94 24 78 01 00 	mov    0x178(%r12),%edx
      ffffffff814b67c0:	00
      ffffffff814b67c1:	83 c2 01             	add    $0x1,%edx
      ffffffff814b67c4:	81 e2 ff 0f 00 00    	and    $0xfff,%edx
      ffffffff814b67ca:	41 89 94 24 78 01 00 	mov    %edx,0x178(%r12)
      ffffffff814b67d1:	00
      ffffffff814b67d2:	eb b0                	jmp    ffffffff814b6784 <uart_put_char+0x64>
      ffffffff814b67d4:	66 66 66 2e 0f 1f 84 	data32 data32 nopw %cs:0x0(%rax,%rax,1)
      ffffffff814b67db:	00 00 00 00 00
      
      for our build, this is crashing at:
      
          circ->buf[circ->head] = c;
      
      Looking in uart_port_startup(), it seems that circ->buf (state->xmit.buf)
      protected by the "per-port mutex", which based on uart_port_check() is
      state->port.mutex. Indeed, the lock acquired in uart_put_char() is
      uport->lock, i.e. not the same lock.
      
      Anyway, since the lock is not acquired, if uart_shutdown() is called, the
      last chunk of that function may release state->xmit.buf before its assigned
      to null, and cause the race above.
      
      To fix it, let's lock uport->lock when allocating/deallocating
      state->xmit.buf in addition to the per-port mutex.
      
      v2: switch to locking uport->lock on allocation/deallocation instead of
          locking the per-port mutex in uart_put_char. Note that since
          uport->lock is a spin lock, we have to switch the allocation to
          GFP_ATOMIC.
      v3: move the allocation outside the lock, so we can switch back to
          GFP_KERNEL
      Signed-off-by: default avatarTycho Andersen <tycho@tycho.ws>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e5147bbf
    • Mike Snitzer's avatar
      dm cache metadata: save in-core policy_hint_size to on-disk superblock · d08b58b5
      Mike Snitzer authored
      commit fd2fa954 upstream.
      
      policy_hint_size starts as 0 during __write_initial_superblock().  It
      isn't until the policy is loaded that policy_hint_size is set in-core
      (cmd->policy_hint_size).  But it never got recorded in the on-disk
      superblock because __commit_transaction() didn't deal with transfering
      the in-core cmd->policy_hint_size to the on-disk superblock.
      
      The in-core cmd->policy_hint_size gets initialized by metadata_open()'s
      __begin_transaction_flags() which re-reads all superblock fields.
      Because the superblock's policy_hint_size was never properly stored, when
      the cache was created, hints_array_available() would always return false
      when re-activating a previously created cache.  This means
      __load_mappings() always considered the hints invalid and never made use
      of the hints (these hints served to optimize).
      
      Another detremental side-effect of this oversight is the cache_check
      utility would fail with: "invalid hint width: 0"
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d08b58b5