10 Sep, 2018

9 commits

  • commit dc30b96ab6d569060741572cf30517d3179429a8 upstream.

    ondemand_readahead() checks bdi->io_pages to cap the maximum pages
    that need to be processed. This works until the readit section. If
    we would do an async only readahead (async size = sync size) and
    target is at beginning of window we expand the pages by another
    get_next_ra_size() pages. Btrace for large reads shows that kernel
    always issues a doubled size read at the beginning of processing.
    Add an additional check for io_pages in the lower part of the func.
    The fix helps devices that hard limit bio pages and rely on proper
    handling of max_hw_read_sectors (e.g. older FusionIO cards). For
    that reason it could qualify for stable.

    Fixes: 9491ae4a ("mm: don't cap request size based on read-ahead setting")
    Cc: stable@vger.kernel.org
    Signed-off-by: Markus Stockhausen stockhausen@collogia.de
    Signed-off-by: Jens Axboe
    Signed-off-by: Greg Kroah-Hartman

    Markus Stockhausen
     
  • commit 9faf870e559a710c44e747ba20383ea82d8ac5d2 upstream.

    The DM_CM_RST register actually has bits 0-31 defaulting to 1s and bits
    32-63 defaulting to 0s -- fix off-by-one in #define RST_RESERVED_BITS.

    Signed-off-by: Sergei Shtylyov
    Reviewed-by: Wolfram Sang
    Fixes: 2a68ea7896e3 ("mmc: renesas-sdhi: add support for R-Car Gen3 SDHI DMAC")
    Cc: stable@vger.kernel.org # v4.14+
    Signed-off-by: Ulf Hansson
    Signed-off-by: Greg Kroah-Hartman

    Sergei Shtylyov
     
  • commit 931c4e9a72ae91d59c5332ffb6812911a749da8e upstream.

    The path "spi: cadence: Add usleep_range() for
    cdns_spi_fill_tx_fifo()" added a usleep_range() function call,
    which cannot be used in atomic context.
    However the cdns_spi_fill_tx_fifo() function can be called during
    an interrupt which may result in a kernel panic:

    BUG: scheduling while atomic: grep/561/0x00010002
    Modules linked in:
    Preemption disabled at:
    [] wait_for_common+0x48/0x178
    CPU: 0 PID: 561 Comm: grep Not tainted 4.17.0 #1
    Hardware name: Cadence CSP (DT)
    Call trace:
    dump_backtrace+0x0/0x198
    show_stack+0x14/0x20
    dump_stack+0x8c/0xac
    __schedule_bug+0x6c/0xb8
    __schedule+0x570/0x5d8
    schedule+0x34/0x98
    schedule_hrtimeout_range_clock+0x98/0x110
    schedule_hrtimeout_range+0x10/0x18
    usleep_range+0x64/0x98
    cdns_spi_fill_tx_fifo+0x70/0xb0
    cdns_spi_irq+0xd0/0xe0
    __handle_irq_event_percpu+0x9c/0x128
    handle_irq_event_percpu+0x34/0x88
    handle_irq_event+0x48/0x78
    handle_fasteoi_irq+0xbc/0x1b0
    generic_handle_irq+0x24/0x38
    __handle_domain_irq+0x84/0xf8
    gic_handle_irq+0xc4/0x180

    This patch replaces the function call with udelay() which can be
    used in an atomic context, like an interrupt.

    Signed-off-by: Jan Kotas
    Signed-off-by: Mark Brown
    Cc: stable@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman

    Janek Kotas
     
  • commit d8ffee2f551a627ffb7b216e2da322cb9a037f77 upstream.

    Registers of DSPI should not be accessed before enabling its clock. On
    Toradex Colibri VF50 on Iris carrier board this could be seen during
    bootup as imprecise abort:

    Unhandled fault: imprecise external abort (0x1c06) at 0x00000000
    Internal error: : 1c06 [#1] ARM
    Modules linked in:
    CPU: 0 PID: 1 Comm: swapper Not tainted 4.14.39-dirty #97
    Hardware name: Freescale Vybrid VF5xx/VF6xx (Device Tree)
    Backtrace:
    [] (regmap_write) from [] (dspi_probe+0x1f0/0x8dc)
    [] (dspi_probe) from [] (platform_drv_probe+0x54/0xb8)
    [] (platform_drv_probe) from [] (driver_probe_device+0x280/0x2f8)
    [] (driver_probe_device) from [] (__driver_attach+0xc0/0xc4)
    [] (__driver_attach) from [] (bus_for_each_dev+0x70/0xa4)
    [] (bus_for_each_dev) from [] (driver_attach+0x24/0x28)
    [] (driver_attach) from [] (bus_add_driver+0x1a0/0x218)
    [] (bus_add_driver) from [] (driver_register+0x80/0x100)
    [] (driver_register) from [] (__platform_driver_register+0x48/0x50)
    [] (__platform_driver_register) from [] (fsl_dspi_driver_init+0x1c/0x20)
    [] (fsl_dspi_driver_init) from [] (do_one_initcall+0x4c/0x174)
    [] (do_one_initcall) from [] (kernel_init_freeable+0x144/0x1d8)
    [] (kernel_init_freeable) from [] (kernel_init+0x10/0x114)
    [] (kernel_init) from [] (ret_from_fork+0x14/0x2c)

    Cc:
    Fixes: 5ee67b587a2b ("spi: dspi: clear SPI_SR before enable interrupt")
    Signed-off-by: Krzysztof Kozlowski
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Krzysztof Kozlowski
     
  • commit 22d71a5097ec7059b6cbbee678a4f88484695941 upstream.

    Intel Ice Lake SPI host controller follows the Intel Cannon Lake but the
    PCI IDs are different. Add the new PCI IDs to the driver supported
    devices list.

    Signed-off-by: Mika Westerberg
    Signed-off-by: Jarkko Nikula
    Signed-off-by: Mark Brown
    Cc: stable@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • commit 563a53f3906a6b43692498e5b3ae891fac93a4af upstream.

    On non-OF systems spi->controlled_data may be NULL. This causes a NULL
    pointer derefence on dm365-evm.

    Signed-off-by: Bartosz Golaszewski
    Signed-off-by: Mark Brown
    Cc: stable@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman

    Bartosz Golaszewski
     
  • commit d28c756caee6e414d9ba367d0b92da24145af2a8 upstream.

    The zero-copy optimization when reading or writing large chunks of data
    is quite useful. However, the 9p messages created through the zero-copy
    write path have an incorrect message size: it should be the size of the
    header + size of the data being written but instead it's just the size
    of the header.

    This only works if the server ignores the size field of the message and
    otherwise breaks the framing of the protocol. Fix this by re-writing the
    message size field with the correct value.

    Tested by running `dd if=/dev/zero of=out bs=4k count=1` inside a
    virtio-9p mount.

    Link: http://lkml.kernel.org/r/20180717003529.114368-1-chirantan@chromium.org
    Signed-off-by: Chirantan Ekbote
    Reviewed-by: Greg Kurz
    Tested-by: Greg Kurz
    Cc: Dylan Reid
    Cc: Guenter Roeck
    Cc: stable@vger.kernel.org
    Signed-off-by: Dominique Martinet
    Signed-off-by: Greg Kroah-Hartman

    Chirantan Ekbote
     
  • commit f9c52831133050c6b82aa8b6831c92da2bbf2a0b upstream.

    This patch is necessary if case of AF_PACKET or other socket interface
    which I am aware of it and didn't allocated the necessary room.

    Reported-by: David Palma
    Reported-by: Rabi Narayan Sahoo
    Cc: stable@vger.kernel.org
    Signed-off-by: Alexander Aring
    Signed-off-by: Stefan Schmidt
    Signed-off-by: Greg Kroah-Hartman

    Alexander Aring
     
  • commit ac74f87c789af40936a80131c4759f3e72579c3a upstream.

    This patch fixes patch add handling to take care tail and headroom for
    single 6lowpan frames. We need to be sure we have a skb with the right
    head and tailroom for single frames. This patch do it by using
    skb_copy_expand() if head and tailroom is not enough allocated by upper
    layer.

    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195059
    Reported-by: David Palma
    Reported-by: Rabi Narayan Sahoo
    Cc: stable@vger.kernel.org
    Signed-off-by: Alexander Aring
    Signed-off-by: Stefan Schmidt
    Signed-off-by: Greg Kroah-Hartman

    Alexander Aring
     

05 Sep, 2018

31 commits

  • Greg Kroah-Hartman
     
  • commit b86729109c5fd0a480300f40608aac68764b5adf upstream.

    GCC 8 changed the order of some fields and is very picky about ordering
    in static initializers, so instead just move to dynamic initializers,
    and drop the redundant already-zero field assignments.

    Suggested-by: Valdis Kletnieks
    Signed-off-by: Kees Cook
    Cc: Lance Albertson
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     
  • commit 80d172431696482d9acd8d2c4ea78fed8956e2a1 upstream.

    GCC requires another #include to get the gcc-plugins to build cleanly.

    Signed-off-by: Valdis Kletnieks
    Signed-off-by: Kees Cook
    Cc: Lance Albertson
    Signed-off-by: Greg Kroah-Hartman

    Valdis Kletnieks
     
  • commit 8f3fafc9c2f0ece10832c25f7ffcb07c97a32ad4 upstream.

    Like d88b6d04: "cdrom: information leak in cdrom_ioctl_media_changed()"

    There is another cast from unsigned long to int which causes
    a bounds check to fail with specially crafted input. The value is
    then used as an index in the slot array in cdrom_slot_status().

    Signed-off-by: Scott Bauer
    Signed-off-by: Scott Bauer
    Cc: stable@vger.kernel.org
    Signed-off-by: Jens Axboe
    Signed-off-by: Greg Kroah-Hartman

    Scott Bauer
     
  • commit cb9d7fd51d9fbb329d182423bd7b92d0f8cb0e01 upstream.

    Some architectures need to use stop_machine() to patch functions for
    ftrace, and the assumption is that the stopped CPUs do not make function
    calls to traceable functions when they are in the stopped state.

    Commit ce4f06dcbb5d ("stop_machine: Touch_nmi_watchdog() after
    MULTI_STOP_PREPARE") added calls to the watchdog touch functions from
    the stopped CPUs and those functions lack notrace annotations. This
    leads to crashes when enabling/disabling ftrace on ARM kernels built
    with the Thumb-2 instruction set.

    Fix it by adding the necessary notrace annotations.

    Fixes: ce4f06dcbb5d ("stop_machine: Touch_nmi_watchdog() after MULTI_STOP_PREPARE")
    Signed-off-by: Vincent Whitchurch
    Signed-off-by: Thomas Gleixner
    Cc: Peter Zijlstra
    Cc: oleg@redhat.com
    Cc: tj@kernel.org
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/20180821152507.18313-1-vincent.whitchurch@axis.com
    Signed-off-by: Greg Kroah-Hartman

    Vincent Whitchurch
     
  • commit a427503edaaed9b75ed9746a654cece7e93e60a8 upstream.

    If an iio channel defines a basic property, there are duplicate entries
    in /sys/class/power/*/uevent.

    So add a check to avoid duplicates. Since all channels may be duplicates,
    we have to modify the related error check.

    Signed-off-by: H. Nikolaus Schaller
    Cc: stable@vger.kernel.org
    Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO")
    Signed-off-by: Sebastian Reichel
    Signed-off-by: Greg Kroah-Hartman

    H. Nikolaus Schaller
     
  • commit 932d47448c3caa0fa99e84d7f5bc302aa286efd8 upstream.

    We did have sporadic problems in the pinctrl framework during boot
    where a pin group name unexpectedly became NULL leading to a NULL
    dereference in strcmp.

    Detailled analysis of the failing cases did reveal that there were
    two devm allocated objects close to each other. The second one was
    the affected group_desc in pinmux and the first one was the
    psy_desc->properties buffer of the gab driver.

    Review of the gab code showed that the address calculation for
    one memcpy() is wrong. It does

    properties + sizeof(type) * index

    but C is defined to do the index multiplication already for
    pointer + integer additions. Hence the factor was applied twice
    and the memcpy() does write outside of the properties buffer.
    Sometimes it happened to be the pinctrl and triggered the strcmp(NULL).

    Anyways, it is overkill to use a memcpy() here instead of a simple
    assignment, which is easier to read and has less risk for wrong
    address calculations. So we change code to a simple assignment.

    If we initialize the index to the first free location, we can even
    remove the local variable 'properties'.

    This bug seems to exist right from the beginning in 3.7-rc1 in

    commit e60fea794e6e ("power: battery: Generic battery driver using IIO")

    Signed-off-by: H. Nikolaus Schaller
    Cc: stable@vger.kernel.org
    Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO")
    Signed-off-by: Sebastian Reichel
    Signed-off-by: Greg Kroah-Hartman

    H. Nikolaus Schaller
     
  • commit 5e2e2f9f76e157063a656351728703cb02b068f1 upstream.

    "count" needs to be signed for the error handling to work. I made "i"
    signed as well so they match.

    Fixes: 02113ba93ea4 (PM / clk: Add support for obtaining clocks from device-tree)
    Cc: 4.6+ # 4.6+
    Signed-off-by: Dan Carpenter
    Signed-off-by: Rafael J. Wysocki
    Signed-off-by: Greg Kroah-Hartman

    Dan Carpenter
     
  • commit a64ad008980c65d38e6cf6858429c78e6b740c41 upstream.

    Register, shift and mask were wrong according to datasheet.

    Fixes: 115510053e5e ("clk: rockchip: add clock controller for the RK3399")
    Cc: stable@vger.kernel.org
    Signed-off-by: Alberto Panizzo
    Signed-off-by: Anthony Brandon
    Signed-off-by: Heiko Stuebner
    Signed-off-by: Greg Kroah-Hartman

    Alberto Panizzo
     
  • commit 26abc916a898d34c5ad159315a2f683def3c5555 upstream.

    The problem is that iscsi_login_zero_tsih_s1 sets conn->sess early in
    iscsi_login_set_conn_values. If the function fails later like when we
    alloc the idr it does kfree(sess) and leaves the conn->sess pointer set.
    iscsi_login_zero_tsih_s1 then returns -Exyz and we then call
    iscsi_target_login_sess_out and access the freed memory.

    This patch has iscsi_login_zero_tsih_s1 either completely setup the
    session or completely tear it down, so later in
    iscsi_target_login_sess_out we can just check for it being set to the
    connection.

    Cc: stable@vger.kernel.org
    Fixes: 0957627a9960 ("iscsi-target: Fix sess allocation leak in...")
    Signed-off-by: Mike Christie
    Acked-by: Martin K. Petersen
    Signed-off-by: Matthew Wilcox
    Signed-off-by: Greg Kroah-Hartman

    Mike Christie
     
  • commit 0ee223b2e1f67cb2de9c0e3247c510d846e74d63 upstream.

    A long time ago the unfortunate decision was taken to add a self-deletion
    attribute to the sysfs SCSI device directory. That decision was unfortunate
    because self-deletion is really tricky. We can't drop that attribute
    because widely used user space software depends on it, namely the
    rescan-scsi-bus.sh script. Hence this patch that avoids that writing into
    that attribute triggers a deadlock. See also commit 7973cbd9fbd9 ("[PATCH]
    add sysfs attributes to scan and delete scsi_devices").

    This patch avoids that self-removal triggers the following deadlock:

    ======================================================
    WARNING: possible circular locking dependency detected
    4.18.0-rc2-dbg+ #5 Not tainted
    ------------------------------------------------------
    modprobe/6539 is trying to acquire lock:
    000000008323c4cd (kn->count#202){++++}, at: kernfs_remove_by_name_ns+0x45/0x90

    but task is already holding lock:
    00000000a6ec2c69 (&shost->scan_mutex){+.+.}, at: scsi_remove_host+0x21/0x150 [scsi_mod]

    which lock already depends on the new lock.

    the existing dependency chain (in reverse order) is:

    -> #1 (&shost->scan_mutex){+.+.}:
    __mutex_lock+0xfe/0xc70
    mutex_lock_nested+0x1b/0x20
    scsi_remove_device+0x26/0x40 [scsi_mod]
    sdev_store_delete+0x27/0x30 [scsi_mod]
    dev_attr_store+0x3e/0x50
    sysfs_kf_write+0x87/0xa0
    kernfs_fop_write+0x190/0x230
    __vfs_write+0xd2/0x3b0
    vfs_write+0x101/0x270
    ksys_write+0xab/0x120
    __x64_sys_write+0x43/0x50
    do_syscall_64+0x77/0x230
    entry_SYSCALL_64_after_hwframe+0x49/0xbe

    -> #0 (kn->count#202){++++}:
    lock_acquire+0xd2/0x260
    __kernfs_remove+0x424/0x4a0
    kernfs_remove_by_name_ns+0x45/0x90
    remove_files.isra.1+0x3a/0x90
    sysfs_remove_group+0x5c/0xc0
    sysfs_remove_groups+0x39/0x60
    device_remove_attrs+0x82/0xb0
    device_del+0x251/0x580
    __scsi_remove_device+0x19f/0x1d0 [scsi_mod]
    scsi_forget_host+0x37/0xb0 [scsi_mod]
    scsi_remove_host+0x9b/0x150 [scsi_mod]
    sdebug_driver_remove+0x4b/0x150 [scsi_debug]
    device_release_driver_internal+0x241/0x360
    device_release_driver+0x12/0x20
    bus_remove_device+0x1bc/0x290
    device_del+0x259/0x580
    device_unregister+0x1a/0x70
    sdebug_remove_adapter+0x8b/0xf0 [scsi_debug]
    scsi_debug_exit+0x76/0xe8 [scsi_debug]
    __x64_sys_delete_module+0x1c1/0x280
    do_syscall_64+0x77/0x230
    entry_SYSCALL_64_after_hwframe+0x49/0xbe

    other info that might help us debug this:

    Possible unsafe locking scenario:

    CPU0 CPU1
    ---- ----
    lock(&shost->scan_mutex);
    lock(kn->count#202);
    lock(&shost->scan_mutex);
    lock(kn->count#202);

    *** DEADLOCK ***

    2 locks held by modprobe/6539:
    #0: 00000000efaf9298 (&dev->mutex){....}, at: device_release_driver_internal+0x68/0x360
    #1: 00000000a6ec2c69 (&shost->scan_mutex){+.+.}, at: scsi_remove_host+0x21/0x150 [scsi_mod]

    stack backtrace:
    CPU: 10 PID: 6539 Comm: modprobe Not tainted 4.18.0-rc2-dbg+ #5
    Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
    Call Trace:
    dump_stack+0xa4/0xf5
    print_circular_bug.isra.34+0x213/0x221
    __lock_acquire+0x1a7e/0x1b50
    lock_acquire+0xd2/0x260
    __kernfs_remove+0x424/0x4a0
    kernfs_remove_by_name_ns+0x45/0x90
    remove_files.isra.1+0x3a/0x90
    sysfs_remove_group+0x5c/0xc0
    sysfs_remove_groups+0x39/0x60
    device_remove_attrs+0x82/0xb0
    device_del+0x251/0x580
    __scsi_remove_device+0x19f/0x1d0 [scsi_mod]
    scsi_forget_host+0x37/0xb0 [scsi_mod]
    scsi_remove_host+0x9b/0x150 [scsi_mod]
    sdebug_driver_remove+0x4b/0x150 [scsi_debug]
    device_release_driver_internal+0x241/0x360
    device_release_driver+0x12/0x20
    bus_remove_device+0x1bc/0x290
    device_del+0x259/0x580
    device_unregister+0x1a/0x70
    sdebug_remove_adapter+0x8b/0xf0 [scsi_debug]
    scsi_debug_exit+0x76/0xe8 [scsi_debug]
    __x64_sys_delete_module+0x1c1/0x280
    do_syscall_64+0x77/0x230
    entry_SYSCALL_64_after_hwframe+0x49/0xbe

    See also https://www.mail-archive.com/linux-scsi@vger.kernel.org/msg54525.html.

    Fixes: ac0ece9174ac ("scsi: use device_remove_file_self() instead of device_schedule_callback()")
    Signed-off-by: Bart Van Assche
    Cc: Greg Kroah-Hartman
    Acked-by: Tejun Heo
    Cc: Johannes Thumshirn
    Cc:
    Signed-off-by: Greg Kroah-Hartman

    Signed-off-by: Martin K. Petersen

    Bart Van Assche
     
  • commit 2afc9166f79b8f6da5f347f48515215ceee4ae37 upstream.

    Introduce these two functions and export them such that the next patch
    can add calls to these functions from the SCSI core.

    Signed-off-by: Bart Van Assche
    Acked-by: Tejun Heo
    Acked-by: Greg Kroah-Hartman
    Cc:
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Greg Kroah-Hartman

    Bart Van Assche
     
  • commit 91b7bdb2c0089cbbb817df6888ab1458c645184e upstream.

    This patch avoids that smatch complains about a double unlock on
    ioc->transport_cmds.mutex.

    Fixes: 651a01364994 ("scsi: scsi_transport_sas: switch to bsg-lib for SMP passthrough")
    Signed-off-by: Bart Van Assche
    Cc: Christoph Hellwig
    Cc: Sathya Prakash
    Cc: Chaitra P B
    Cc: Suganath Prabu Subramani
    Cc: stable@vger.kernel.org
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Greg Kroah-Hartman

    Bart Van Assche
     
  • commit 36a11029b07ee30bdc4553274d0efea645ed9d91 upstream.

    The userpace expects to read the number of bytes stated in the header.
    Returning the size of the buffer instead would be unexpected.

    Cc: stable@vger.kernel.org
    Fixes: 095531f891e6 ("tpm: return a TPM_RC_COMMAND_CODE response if command is not implemented")
    Signed-off-by: Ricardo Schwarzmeier
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen
    Signed-off-by: Greg Kroah-Hartman

    Ricardo Schwarzmeier
     
  • commit 690d9163bf4b8563a2682e619f938e6a0443947f upstream.

    Some versions of GCC suboptimally generate calls to the __multi3()
    intrinsic for MIPS64r6 builds, resulting in link failures due to the
    missing function:

    LD vmlinux.o
    MODPOST vmlinux.o
    kernel/bpf/verifier.o: In function `kmalloc_array':
    include/linux/slab.h:631: undefined reference to `__multi3'
    fs/select.o: In function `kmalloc_array':
    include/linux/slab.h:631: undefined reference to `__multi3'
    ...

    We already have a workaround for this in which we provide the
    instrinsic, but we do so selectively for GCC 7 only. Unfortunately the
    issue occurs with older GCC versions too - it has been observed with
    both GCC 5.4.0 & GCC 6.4.0.

    MIPSr6 support was introduced in GCC 5, so all major GCC versions prior
    to GCC 8 are affected and we extend our workaround accordingly to all
    MIPS64r6 builds using GCC versions older than GCC 8.

    Signed-off-by: Paul Burton
    Reported-by: Vladimir Kondratiev
    Fixes: ebabcf17bcd7 ("MIPS: Implement __multi3 for GCC7 MIPS64r6 builds")
    Patchwork: https://patchwork.linux-mips.org/patch/20297/
    Cc: James Hogan
    Cc: Ralf Baechle
    Cc: linux-mips@linux-mips.org
    Cc: stable@vger.kernel.org # 4.15+
    Signed-off-by: Greg Kroah-Hartman

    Paul Burton
     
  • commit a30718868915fbb991a9ae9e45594b059f28e9ae upstream.

    Linux expects that if a CPU modifies a memory location, then that
    modification will eventually become visible to other CPUs in the system.

    Loongson 3 CPUs include a Store Fill Buffer (SFB) which sits between a
    core & its L1 data cache, queueing memory accesses & allowing for faster
    forwarding of data from pending stores to younger loads from the core.
    Unfortunately the SFB prioritizes loads such that a continuous stream of
    loads may cause a pending write to be buffered indefinitely. This is
    problematic if we end up with 2 CPUs which each perform a store that the
    other polls for - one or both CPUs may end up with their stores buffered
    in the SFB, never reaching cache due to the continuous reads from the
    poll loop. Such a deadlock condition has been observed whilst running
    qspinlock code.

    This patch changes the definition of cpu_relax() to smp_mb() for
    Loongson-3, forcing a flush of the SFB on SMP systems which will cause
    any pending writes to make it as far as the L1 caches where they will
    become visible to other CPUs. If the kernel is not compiled for SMP
    support, this will expand to a barrier() as before.

    This workaround matches that currently implemented for ARM when
    CONFIG_ARM_ERRATA_754327=y, which was introduced by commit 534be1d5a2da
    ("ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore").

    Although the workaround is only required when the Loongson 3 SFB
    functionality is enabled, and we only began explicitly enabling that
    functionality in v4.7 with commit 1e820da3c9af ("MIPS: Loongson-3:
    Introduce CONFIG_LOONGSON3_ENHANCEMENT"), existing or future firmware
    may enable the SFB which means we may need the workaround backported to
    earlier kernels too.

    [paul.burton@mips.com:
    - Reword commit message & comment.
    - Limit stable backport to v3.15+ where we support Loongson 3 CPUs.]

    Signed-off-by: Huacai Chen
    Signed-off-by: Paul Burton
    References: 534be1d5a2da ("ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore")
    References: 1e820da3c9af ("MIPS: Loongson-3: Introduce CONFIG_LOONGSON3_ENHANCEMENT")
    Patchwork: https://patchwork.linux-mips.org/patch/19830/
    Cc: Ralf Baechle
    Cc: James Hogan
    Cc: linux-mips@linux-mips.org
    Cc: Fuxin Zhang
    Cc: Zhangjin Wu
    Cc: Huacai Chen
    Cc: stable@vger.kernel.org # v3.15+
    Signed-off-by: Greg Kroah-Hartman

    Huacai Chen
     
  • commit 344ebf09949c31bcb8818d8458b65add29f1d67b upstream.

    The VDSO Makefile filters CFLAGS to select a subset which it uses whilst
    building the VDSO ELF. One of the flags it allows through is the -march=
    flag that selects the architecture/ISA to target.

    Unfortunately in cases where CONFIG_CPU_MIPS32_R{1,2}=y and the
    toolchain defaults to building for MIPS64, the main MIPS Makefile ends
    up using the short-form - flags in cflags-y. This is because the
    calls to cc-option always fail to use the long-form -march= flag
    due to the lack of an -mabi= flag in KBUILD_CFLAGS at the point
    where the cc-option function is executed. The resulting GCC invocation
    is something like:

    $ mips64-linux-gcc -Werror -march=mips32r2 -c -x c /dev/null -o tmp
    cc1: error: '-march=mips32r2' is not compatible with the selected ABI

    These short-form - flags are dropped by the VDSO Makefile's
    filtering, and so we attempt to build the VDSO without specifying any
    architecture. This results in an attempt to build the VDSO using
    whatever the compiler's default architecture is, regardless of whether
    that is suitable for the kernel configuration.

    One encountered build failure resulting from this mismatch is a
    rejection of the sync instruction if the kernel is configured for a
    MIPS32 or MIPS64 r1 or r2 target but the toolchain defaults to an older
    architecture revision such as MIPS1 which did not include the sync
    instruction:

    CC arch/mips/vdso/gettimeofday.o
    /tmp/ccGQKoOj.s: Assembler messages:
    /tmp/ccGQKoOj.s:273: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:329: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:520: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:714: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:1009: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:1066: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:1114: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:1279: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:1334: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:1374: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:1459: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:1514: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:1814: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:2002: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    /tmp/ccGQKoOj.s:2066: Error: opcode not supported on this processor: mips1 (mips1) `sync'
    make[2]: *** [scripts/Makefile.build:318: arch/mips/vdso/gettimeofday.o] Error 1
    make[1]: *** [scripts/Makefile.build:558: arch/mips/vdso] Error 2
    make[1]: *** Waiting for unfinished jobs....

    This can be reproduced for example by attempting to build
    pistachio_defconfig using Arnd's GCC 8.1.0 mips64 toolchain from
    kernel.org:

    https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.1.0/x86_64-gcc-8.1.0-nolibc-mips64-linux.tar.xz

    Resolve this problem by using the long-form -march= in all cases,
    which makes it through the arch/mips/vdso/Makefile's filtering & is thus
    consistently used to build both the kernel proper & the VDSO.

    The use of cc-option to prefer the long-form & fall back to the
    short-form flags makes no sense since the short-form is just an
    abbreviation for the also-supported long-form in all GCC versions that
    we support building with. This means there is no case in which we have
    to use the short-form - flags, so we can simply remove them.

    The manual redefinition of _MIPS_ISA is removed naturally along with the
    use of the short-form flags that it accompanied, and whilst here we
    remove the separate assembler ISA selection. I suspect that both of
    these were only required due to the mips32 vs mips2 mismatch that was
    introduced by commit 59b3e8e9aac6 ("[MIPS] Makefile crapectomy.") and
    fixed but not cleaned up by commit 9200c0b2a07c ("[MIPS] Fix Makefile
    bugs for MIPS32/MIPS64 R1 and R2.").

    I've marked this for backport as far as v4.4 where the MIPS VDSO was
    introduced. In earlier kernels there should be no ill effect to using
    the short-form flags.

    Signed-off-by: Paul Burton
    Cc: Ralf Baechle
    Cc: linux-mips@linux-mips.org
    Cc: stable@vger.kernel.org # v4.4+
    Reviewed-by: James Hogan
    Patchwork: https://patchwork.linux-mips.org/patch/19579/
    Signed-off-by: Greg Kroah-Hartman

    Paul Burton
     
  • commit f5958b4cf4fc38ed4583ab83fb7c4cd1ab05f47b upstream.

    Use the `unsigned long' rather than `__u32' type for DSP accumulator
    registers, like with the regular MIPS multiply/divide accumulator and
    general-purpose registers, as all are 64-bit in 64-bit implementations
    and using a 32-bit data type leads to contents truncation on context
    saving.

    Update `arch_ptrace' and `compat_arch_ptrace' accordingly, removing
    casts that are similarly not used with multiply/divide accumulator or
    general-purpose register accesses.

    Signed-off-by: Maciej W. Rozycki
    Signed-off-by: Paul Burton
    Fixes: e50c0a8fa60d ("Support the MIPS32 / MIPS64 DSP ASE.")
    Patchwork: https://patchwork.linux-mips.org/patch/19329/
    Cc: Alexander Viro
    Cc: James Hogan
    Cc: Ralf Baechle
    Cc: linux-fsdevel@vger.kernel.org
    Cc: linux-mips@linux-mips.org
    Cc: linux-kernel@vger.kernel.org
    Cc: stable@vger.kernel.org # 2.6.15+
    Signed-off-by: Greg Kroah-Hartman

    Maciej W. Rozycki
     
  • commit f2a3ab36077222437b4826fc76111caa14562b7c upstream.

    Since the blacklist and list files on debugfs indicates
    a sensitive address information to reader, it should be
    restricted to the root user.

    Suggested-by: Thomas Richter
    Suggested-by: Ingo Molnar
    Signed-off-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: Arnd Bergmann
    Cc: David Howells
    Cc: David S . Miller
    Cc: Heiko Carstens
    Cc: Jon Medhurst
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Tobin C . Harding
    Cc: Will Deacon
    Cc: acme@kernel.org
    Cc: akpm@linux-foundation.org
    Cc: brueckner@linux.vnet.ibm.com
    Cc: linux-arch@vger.kernel.org
    Cc: rostedt@goodmis.org
    Cc: schwidefsky@de.ibm.com
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/lkml/152491890171.9916.5183693615601334087.stgit@devbox
    Signed-off-by: Ingo Molnar
    Signed-off-by: Greg Kroah-Hartman

    Masami Hiramatsu
     
  • commit 75b2f5f5911fe7a2fc82969b2b24dde34e8f820d upstream.

    Fix %p uses in error messages by removing it and
    using general dumper.

    Signed-off-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: Arnd Bergmann
    Cc: David Howells
    Cc: David S . Miller
    Cc: Heiko Carstens
    Cc: Jon Medhurst
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Thomas Richter
    Cc: Tobin C . Harding
    Cc: Will Deacon
    Cc: acme@kernel.org
    Cc: akpm@linux-foundation.org
    Cc: brueckner@linux.vnet.ibm.com
    Cc: linux-arch@vger.kernel.org
    Cc: rostedt@goodmis.org
    Cc: schwidefsky@de.ibm.com
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/lkml/152491905361.9916.15300852365956231645.stgit@devbox
    Signed-off-by: Ingo Molnar
    Signed-off-by: Greg Kroah-Hartman

    Masami Hiramatsu
     
  • commit 866f3576a72b2233a76dffb80290f8086dc49e17 upstream.

    During interrupt setup we allocate interrupt vectors, walk the list of msi
    descriptors, and fill in the message data. Requesting more interrupts than
    supported on s390 can lead to an out of bounds access.

    When we restrict the number of interrupts we should also stop walking the
    msi list after all supported interrupts are handled.

    Cc: stable@vger.kernel.org
    Signed-off-by: Sebastian Ott
    Signed-off-by: Heiko Carstens
    Signed-off-by: Greg Kroah-Hartman

    Sebastian Ott
     
  • commit fb7d7518b0d65955f91c7b875c36eae7694c69bd upstream.

    The numa_init_early initcall sets the node_to_cpumask_map[0] to the
    full cpu_possible_mask. Unfortunately this early_initcall is too late,
    the NUMA setup for numa=emu is done even earlier. The order of calls
    is numa_setup() -> emu_update_cpu_topology(), then the early_initcalls(),
    followed by sched_init_domains().

    Starting with git commit 051f3ca02e46432c0965e8948f00c07d8a2f09c0
    "sched/topology: Introduce NUMA identity node sched domain"
    the incorrect node_to_cpumask_map[0] really screws up the domain
    setup and the kernel panics with the follow oops:

    Cc: # v4.15+
    Signed-off-by: Martin Schwidefsky
    Signed-off-by: Greg Kroah-Hartman

    Martin Schwidefsky
     
  • commit 64e03ff72623b8c2ea89ca3cb660094e019ed4ae upstream.

    When allocating a new AOB fails, handle_outbound() is still capable of
    transmitting the selected buffer (just without async completion).

    But if a previous transfer on this queue slot used async completion, its
    sbal_state flags field is still set to QDIO_OUTBUF_STATE_FLAG_PENDING.
    So when the upper layer driver sees this stale flag, it expects an async
    completion that never happens.

    Fix this by unconditionally clearing the flags field.

    Fixes: 104ea556ee7f ("qdio: support asynchronous delivery of storage blocks")
    Cc: #v3.2+
    Signed-off-by: Julian Wiedmann
    Signed-off-by: Martin Schwidefsky
    Signed-off-by: Greg Kroah-Hartman

    Julian Wiedmann
     
  • commit 26f843848bae973817b3587780ce6b7b0200d3e4 upstream.

    For machines without the exrl instruction the BFP jit generates
    code that uses an "br %r1" instruction located in the lowcore page.
    Unfortunately there is a cut & paste error that puts an additional
    "larl %r1,.+14" instruction in the code that clobbers the branch
    target address in %r1. Remove the larl instruction.

    Cc: # v4.17+
    Fixes: de5cb6eb51 ("s390: use expoline thunks in the BPF JIT")
    Signed-off-by: Martin Schwidefsky
    Signed-off-by: Greg Kroah-Hartman

    Martin Schwidefsky
     
  • commit 37a366face294facb9c9d9fdd9f5b64a27456cbd upstream.

    Commit c9b5ad546e7d "s390/mm: tag normal pages vs pages used in page tables"
    accidentally changed the logic in arch_set_page_states(), which is used by
    the suspend/resume code. set_page_stable(page, order) was changed to
    set_page_stable_dat(page, 0). After this, only the first page of higher order
    pages will be set to stable, and a write to one of the unstable pages will
    result in an addressing exception.

    Fix this by using "order" again, instead of "0".

    Fixes: c9b5ad546e7d ("s390/mm: tag normal pages vs pages used in page tables")
    Cc: stable@vger.kernel.org # 4.14+
    Reviewed-by: Heiko Carstens
    Signed-off-by: Gerald Schaefer
    Signed-off-by: Martin Schwidefsky
    Signed-off-by: Greg Kroah-Hartman

    Gerald Schaefer
     
  • commit f12d11c5c184626b4befdee3d573ec8237405a33 upstream.

    Reset the KASAN shadow state of the task stack before rewinding RSP.
    Without this, a kernel oops will leave parts of the stack poisoned, and
    code running under do_exit() can trip over such poisoned regions and cause
    nonsensical false-positive KASAN reports about stack-out-of-bounds bugs.

    This does not wipe the exception stacks; if an oops happens on an exception
    stack, it might result in random KASAN false-positives from other tasks
    afterwards. This is probably relatively uninteresting, since if the kernel
    oopses on an exception stack, there are most likely bigger things to worry
    about. It'd be more interesting if vmapped stacks and KASAN were
    compatible, since then handle_stack_overflow() would oops from exception
    stack context.

    Fixes: 2deb4be28077 ("x86/dumpstack: When OOPSing, rewind the stack before do_exit()")
    Signed-off-by: Jann Horn
    Signed-off-by: Thomas Gleixner
    Acked-by: Andrey Ryabinin
    Cc: Andy Lutomirski
    Cc: Dmitry Vyukov
    Cc: Alexander Potapenko
    Cc: Kees Cook
    Cc: kasan-dev@googlegroups.com
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/20180828184033.93712-1-jannh@google.com
    Signed-off-by: Greg Kroah-Hartman

    Jann Horn
     
  • commit d49dbfade96d5b0863ca8a90122a805edd5ef50a upstream.

    val can be indirectly controlled by user-space, hence leading to
    a potential exploitation of the Spectre variant 1 vulnerability.

    This issue was detected with the help of Smatch:

    vers/hwmon/nct6775.c:2698 store_pwm_weight_temp_sel() warn: potential
    spectre issue 'data->temp_src' [r]

    Fix this by sanitizing val before using it to index data->temp_src

    Notice that given that speculation windows are large, the policy is
    to kill the speculation on the first load and not worry if it can be
    completed with a dependent load/store [1].

    [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2

    Cc: stable@vger.kernel.org
    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Guenter Roeck
    Signed-off-by: Greg Kroah-Hartman

    Gustavo A. R. Silva
     
  • commit cc51e5428ea54f575d49cfcede1d4cb3a72b4ec4 upstream.

    On Nehalem and newer core CPUs the CPU cache internally uses 44 bits
    physical address space. The L1TF workaround is limited by this internal
    cache address width, and needs to have one bit free there for the
    mitigation to work.

    Older client systems report only 36bit physical address space so the range
    check decides that L1TF is not mitigated for a 36bit phys/32GB system with
    some memory holes.

    But since these actually have the larger internal cache width this warning
    is bogus because it would only really be needed if the system had more than
    43bits of memory.

    Add a new internal x86_cache_bits field. Normally it is the same as the
    physical bits field reported by CPUID, but for Nehalem and newerforce it to
    be at least 44bits.

    Change the L1TF memory size warning to use the new cache_bits field to
    avoid bogus warnings and remove the bogus comment about memory size.

    Fixes: 17dbca119312 ("x86/speculation/l1tf: Add sysfs reporting for l1tf")
    Reported-by: George Anchev
    Reported-by: Christopher Snowhill
    Signed-off-by: Andi Kleen
    Signed-off-by: Thomas Gleixner
    Cc: x86@kernel.org
    Cc: linux-kernel@vger.kernel.org
    Cc: Michael Hocko
    Cc: vbabka@suse.cz
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/20180824170351.34874-1-andi@firstfloor.org
    Signed-off-by: Greg Kroah-Hartman

    Andi Kleen
     
  • commit 1ab534e85c93945f7862378d8c8adcf408205b19 upstream.

    The check for Spectre microcodes does not check for family 6, only the
    model numbers.

    Add a family 6 check to avoid ambiguity with other families.

    Fixes: a5b296636453 ("x86/cpufeature: Blacklist SPEC_CTRL/PRED_CMD on early Spectre v2 microcodes")
    Signed-off-by: Andi Kleen
    Signed-off-by: Thomas Gleixner
    Cc: x86@kernel.org
    Cc: linux-kernel@vger.kernel.org
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/20180824170351.34874-2-andi@firstfloor.org
    Signed-off-by: Greg Kroah-Hartman

    Andi Kleen
     
  • commit 1f59a4581b5ecfe9b4f049a7a2cf904d8352842d upstream.

    This should have been marked extern inline in order to pick up the out
    of line definition in arch/x86/kernel/irqflags.S.

    Fixes: 208cbb325589 ("x86/irqflags: Provide a declaration for native_save_fl")
    Reported-by: Ben Hutchings
    Signed-off-by: Nick Desaulniers
    Signed-off-by: Thomas Gleixner
    Reviewed-by: Juergen Gross
    Cc: "H. Peter Anvin"
    Cc: Boris Ostrovsky
    Cc: Greg Kroah-Hartman
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/20180827214011.55428-1-ndesaulniers@google.com
    Signed-off-by: Greg Kroah-Hartman

    Nick Desaulniers
     
  • commit 4012e77a903d114f915fc607d6d2ed54a3d6c9b1 upstream.

    A NMI can hit in the middle of context switching or in the middle of
    switch_mm_irqs_off(). In either case, CR3 might not match current->mm,
    which could cause copy_from_user_nmi() and friends to read the wrong
    memory.

    Fix it by adding a new nmi_uaccess_okay() helper and checking it in
    copy_from_user_nmi() and in __copy_from_user_nmi()'s callers.

    Signed-off-by: Andy Lutomirski
    Signed-off-by: Thomas Gleixner
    Reviewed-by: Rik van Riel
    Cc: Nadav Amit
    Cc: Borislav Petkov
    Cc: Jann Horn
    Cc: Peter Zijlstra
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/dd956eba16646fd0b15c3c0741269dfd84452dac.1535557289.git.luto@kernel.org
    Signed-off-by: Greg Kroah-Hartman

    Andy Lutomirski