20 Jan, 2021

40 commits

  • [ Upstream commit 9bba03d4473df0b707224d4d2067b62d1e1e2a77 ]

    Linux 5.10 is out. Remove the 'kvmconfig' and 'xenconfig' shorthands
    as previously announced.

    Signed-off-by: Masahiro Yamada
    Signed-off-by: Sasha Levin

    Masahiro Yamada
     
  • [ Upstream commit 0c36d88cff4d72149f94809303c5180b6f716d39 ]

    Older versions of BSD awk are fussy about the order of '-v' and '-f'
    flags, and require a space after the flag name. This causes build
    failures on platforms with an old awk, such as macOS and NetBSD.

    Since GNU awk and modern versions of BSD awk (distributed with
    FreeBSD/OpenBSD) are fine with either form, the definition of
    'cmd_unroll' can be trivially tweaked to let the lib/raid6 Makefile
    work with both old and new awk flag dialects.

    Signed-off-by: John Millikin
    Signed-off-by: Masahiro Yamada
    Signed-off-by: Sasha Levin

    John Millikin
     
  • [ Upstream commit 1eda52334e6d13eb1a85f713ce06dd39342b5020 ]

    With MAX_PWM being defined to 255 the code

    unsigned long period;
    ...
    period = ctx->pwm->args.period;
    state.duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM);

    calculates a too small value for duty_cycle if the configured period is
    big (either by discarding the 64 bit value ctx->pwm->args.period or by
    overflowing the multiplication). As this results in a too slow fan and
    so maybe an overheating machine better be safe than sorry and error out
    in .probe.

    Signed-off-by: Uwe Kleine-König
    Link: https://lore.kernel.org/r/20201215092031.152243-1-u.kleine-koenig@pengutronix.de
    Signed-off-by: Guenter Roeck
    Signed-off-by: Sasha Levin

    Uwe Kleine-König
     
  • [ Upstream commit b000700d6db50c933ce8b661154e26cf4ad06dba ]

    When kzalloc() fails, we should execute hl_mmu_fini()
    to release the MMU module. It's the same when
    hl_ctx_init() fails.

    Signed-off-by: Dinghao Liu
    Reviewed-by: Oded Gabbay
    Signed-off-by: Oded Gabbay
    Signed-off-by: Sasha Levin

    Dinghao Liu
     
  • [ Upstream commit ede090f5a438e97d0586f64067bbb956e30a2a31 ]

    This patch fixes the return value for altera_spi_txrx. It should return
    1 for interrupt transfer mode, and return 0 for polling transfer mode.

    The altera_spi_txrx() implements the spi_controller.transfer_one
    callback. According to the spi-summary.rst, the transfer_one should
    return 0 when transfer is finished, return 1 when transfer is still in
    progress.

    Signed-off-by: Xu Yilun
    Link: https://lore.kernel.org/r/1609219662-27057-2-git-send-email-yilun.xu@intel.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Xu Yilun
     
  • [ Upstream commit 12b38ea040b3bb2a30eb9cd488376df5be7ea81f ]

    IN the probe function, if an error occurs after calling
    'spmi_controller_alloc()', it must be undone by a corresponding
    'spmi_controller_put() call.

    In the remove function, use 'spmi_controller_put(ctrl)' instead of
    'kfree(ctrl)'.

    While a it fix an error message
    (s/spmi_add_controller/spmi_controller_add/)

    Signed-off-by: Christophe JAILLET
    Link: https://lore.kernel.org/r/20201213151105.137731-1-christophe.jaillet@wanadoo.fr
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Sasha Levin

    Christophe JAILLET
     
  • [ Upstream commit fcaebc7354188b0d708c79df4390fbabd4d9799d ]

    We need to make sure our device is idle when rebooting a virtual
    machine. This is done in the driver level.

    The firmware will later handle FLR but we want to be extra safe and
    stop the devices until the FLR is handled.

    Signed-off-by: Oded Gabbay
    Signed-off-by: Sasha Levin

    Oded Gabbay
     
  • [ Upstream commit 98e8781f008372057bd5cb059ca6b507371e473d ]

    If loading the firmware file for the TPC f/w was interrupted, try
    to do it again, up to 5 times.

    Signed-off-by: Oded Gabbay
    Signed-off-by: Sasha Levin

    Oded Gabbay
     
  • [ Upstream commit 377182a3cc5ae6cc17fb04d06864c975f9f71c18 ]

    When the firmware security is enabled, the pcie_aux_dbi_reg_addr
    register in the PCI controller is blocked. Therefore, ignore
    the result of writing to this register and assume it worked. Also
    remove the prints on errors in the internal ELBI write function.

    If the security is enabled, the firmware is responsible for setting
    this register correctly so we won't have any problem.

    If the security is disabled, the write will work (unless something
    is totally broken at the PCI level and then the whole sequence
    will fail).

    In addition, remove a write to register pcie_aux_dbi_reg_addr+4,
    which was never actually needed.

    Moreover, PCIE_DBI registers are blocked to access from host when
    firmware security is enabled. Use a different register to flush the
    writes.

    Signed-off-by: Oded Gabbay
    Signed-off-by: Sasha Levin

    Oded Gabbay
     
  • [ Upstream commit 7887cc89d5851cbdec49219e9614beec776af150 ]

    A too high brightness by default (default is max) makes the
    screen go blank. Set this to 15 as in the Vendor tree.

    Signed-off-by: Linus Walleij
    Cc: Stephan Gerhold
    Link: https://lore.kernel.org/r/20201214223413.253893-1-linus.walleij@linaro.org'
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Sasha Levin

    Linus Walleij
     
  • [ Upstream commit 887078de2a23689e29d6fa1b75d7cbc544c280be ]

    Table 8-53 in the QUICC Engine Reference manual shows definitions of
    fields up to a size of 192 bytes, not just 128. But in table 8-111,
    one does find the text

    Base Address of the Global Transmitter Parameter RAM Page. [...]
    The user needs to allocate 128 bytes for this page. The address must
    be aligned to the page size.

    I've checked both rev. 7 (11/2015) and rev. 9 (05/2018) of the manual;
    they both have this inconsistency (and the table numbers are the
    same).

    Adding a bit of debug printing, on my board the struct
    ucc_geth_tx_global_pram is allocated at offset 0x880, while
    the (opaque) ucc_geth_thread_data_tx gets allocated immediately
    afterwards, at 0x900. So whatever the engine writes into the thread
    data overlaps with the tail of the global tx pram (and devmem says
    that something does get written during a simple ping).

    I haven't observed any failure that could be attributed to this, but
    it seems to be the kind of thing that would be extremely hard to
    debug. So extend the struct definition so that we do allocate 192
    bytes.

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Jakub Kicinski
    Signed-off-by: Sasha Levin

    Rasmus Villemoes
     
  • [ Upstream commit 3b66e4a8e58a85af3212c7117d7a29c9ef6679a2 ]

    Use the typical startup times from the data sheet so boards get a
    reasonable default. Not setting any enable time can lead to board hangs
    when e.g. clocks are enabled too soon afterwards.

    This fixes gpu power domain resume on the Librem 5.

    [Moved #defines into driver, seems to be general agreement and avoids any
    cross tree issues -- broonie]

    Signed-off-by: Guido Günther
    Reviewed-by: Matti Vaittinen
    Link: https://lore.kernel.org/r/41fb2ed19f584f138336344e2297ae7301f72b75.1608316658.git.agx@sigxcpu.org
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Guido Günther
     
  • [ Upstream commit cb13eea3b49055bd78e6ddf39defd6340f7379fc ]

    If we remount a filesystem in RO mode while the qgroup rescan worker is
    running, we can end up having it still running after the remount is done,
    and at unmount time we may end up with an open transaction that ends up
    never getting committed. If that happens we end up with several memory
    leaks and can crash when hardware acceleration is unavailable for crc32c.
    Possibly it can lead to other nasty surprises too, due to use-after-free
    issues.

    The following steps explain how the problem happens.

    1) We have a filesystem mounted in RW mode and the qgroup rescan worker is
    running;

    2) We remount the filesystem in RO mode, and never stop/pause the rescan
    worker, so after the remount the rescan worker is still running. The
    important detail here is that the rescan task is still running after
    the remount operation committed any ongoing transaction through its
    call to btrfs_commit_super();

    3) The rescan is still running, and after the remount completed, the
    rescan worker started a transaction, after it finished iterating all
    leaves of the extent tree, to update the qgroup status item in the
    quotas tree. It does not commit the transaction, it only releases its
    handle on the transaction;

    4) A filesystem unmount operation starts shortly after;

    5) The unmount task, at close_ctree(), stops the transaction kthread,
    which had not had a chance to commit the open transaction since it was
    sleeping and the commit interval (default of 30 seconds) has not yet
    elapsed since the last time it committed a transaction;

    6) So after stopping the transaction kthread we still have the transaction
    used to update the qgroup status item open. At close_ctree(), when the
    filesystem is in RO mode and no transaction abort happened (or the
    filesystem is in error mode), we do not expect to have any transaction
    open, so we do not call btrfs_commit_super();

    7) We then proceed to destroy the work queues, free the roots and block
    groups, etc. After that we drop the last reference on the btree inode
    by calling iput() on it. Since there are dirty pages for the btree
    inode, corresponding to the COWed extent buffer for the quotas btree,
    btree_write_cache_pages() is invoked to flush those dirty pages. This
    results in creating a bio and submitting it, which makes us end up at
    btrfs_submit_metadata_bio();

    8) At btrfs_submit_metadata_bio() we end up at the if-then-else branch
    that calls btrfs_wq_submit_bio(), because check_async_write() returned
    a value of 1. This value of 1 is because we did not have hardware
    acceleration available for crc32c, so BTRFS_FS_CSUM_IMPL_FAST was not
    set in fs_info->flags;

    9) Then at btrfs_wq_submit_bio() we call btrfs_queue_work() against the
    workqueue at fs_info->workers, which was already freed before by the
    call to btrfs_stop_all_workers() at close_ctree(). This results in an
    invalid memory access due to a use-after-free, leading to a crash.

    When this happens, before the crash there are several warnings triggered,
    since we have reserved metadata space in a block group, the delayed refs
    reservation, etc:

    ------------[ cut here ]------------
    WARNING: CPU: 4 PID: 1729896 at fs/btrfs/block-group.c:125 btrfs_put_block_group+0x63/0xa0 [btrfs]
    Modules linked in: btrfs dm_snapshot dm_thin_pool (...)
    CPU: 4 PID: 1729896 Comm: umount Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    RIP: 0010:btrfs_put_block_group+0x63/0xa0 [btrfs]
    Code: f0 01 00 00 48 39 c2 75 (...)
    RSP: 0018:ffffb270826bbdd8 EFLAGS: 00010206
    RAX: 0000000000000001 RBX: ffff947ed73e4000 RCX: ffff947ebc8b29c8
    RDX: 0000000000000001 RSI: ffffffffc0b150a0 RDI: ffff947ebc8b2800
    RBP: ffff947ebc8b2800 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000001 R12: ffff947ed73e4110
    R13: ffff947ed73e4160 R14: ffff947ebc8b2988 R15: dead000000000100
    FS: 00007f15edfea840(0000) GS:ffff9481ad600000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00007f37e2893320 CR3: 0000000138f68001 CR4: 00000000003706e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
    btrfs_free_block_groups+0x17f/0x2f0 [btrfs]
    close_ctree+0x2ba/0x2fa [btrfs]
    generic_shutdown_super+0x6c/0x100
    kill_anon_super+0x14/0x30
    btrfs_kill_super+0x12/0x20 [btrfs]
    deactivate_locked_super+0x31/0x70
    cleanup_mnt+0x100/0x160
    task_work_run+0x68/0xb0
    exit_to_user_mode_prepare+0x1bb/0x1c0
    syscall_exit_to_user_mode+0x4b/0x260
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f15ee221ee7
    Code: ff 0b 00 f7 d8 64 89 01 48 (...)
    RSP: 002b:00007ffe9470f0f8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
    RAX: 0000000000000000 RBX: 00007f15ee347264 RCX: 00007f15ee221ee7
    RDX: ffffffffffffff78 RSI: 0000000000000000 RDI: 000056169701d000
    RBP: 0000561697018a30 R08: 0000000000000000 R09: 00007f15ee2e2be0
    R10: 000056169701efe0 R11: 0000000000000246 R12: 0000000000000000
    R13: 000056169701d000 R14: 0000561697018b40 R15: 0000561697018c60
    irq event stamp: 0
    hardirqs last enabled at (0): [] 0x0
    hardirqs last disabled at (0): [] copy_process+0x8a0/0x1d70
    softirqs last enabled at (0): [] copy_process+0x8a0/0x1d70
    softirqs last disabled at (0): [] 0x0
    ---[ end trace dd74718fef1ed5c6 ]---
    ------------[ cut here ]------------
    WARNING: CPU: 2 PID: 1729896 at fs/btrfs/block-rsv.c:459 btrfs_release_global_block_rsv+0x70/0xc0 [btrfs]
    Modules linked in: btrfs dm_snapshot dm_thin_pool (...)
    CPU: 2 PID: 1729896 Comm: umount Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    RIP: 0010:btrfs_release_global_block_rsv+0x70/0xc0 [btrfs]
    Code: 48 83 bb b0 03 00 00 00 (...)
    RSP: 0018:ffffb270826bbdd8 EFLAGS: 00010206
    RAX: 000000000033c000 RBX: ffff947ed73e4000 RCX: 0000000000000000
    RDX: 0000000000000001 RSI: ffffffffc0b0d8c1 RDI: 00000000ffffffff
    RBP: ffff947ebc8b7000 R08: 0000000000000001 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000001 R12: ffff947ed73e4110
    R13: ffff947ed73e5278 R14: dead000000000122 R15: dead000000000100
    FS: 00007f15edfea840(0000) GS:ffff9481aca00000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 0000561a79f76e20 CR3: 0000000138f68006 CR4: 00000000003706e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
    btrfs_free_block_groups+0x24c/0x2f0 [btrfs]
    close_ctree+0x2ba/0x2fa [btrfs]
    generic_shutdown_super+0x6c/0x100
    kill_anon_super+0x14/0x30
    btrfs_kill_super+0x12/0x20 [btrfs]
    deactivate_locked_super+0x31/0x70
    cleanup_mnt+0x100/0x160
    task_work_run+0x68/0xb0
    exit_to_user_mode_prepare+0x1bb/0x1c0
    syscall_exit_to_user_mode+0x4b/0x260
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f15ee221ee7
    Code: ff 0b 00 f7 d8 64 89 01 (...)
    RSP: 002b:00007ffe9470f0f8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
    RAX: 0000000000000000 RBX: 00007f15ee347264 RCX: 00007f15ee221ee7
    RDX: ffffffffffffff78 RSI: 0000000000000000 RDI: 000056169701d000
    RBP: 0000561697018a30 R08: 0000000000000000 R09: 00007f15ee2e2be0
    R10: 000056169701efe0 R11: 0000000000000246 R12: 0000000000000000
    R13: 000056169701d000 R14: 0000561697018b40 R15: 0000561697018c60
    irq event stamp: 0
    hardirqs last enabled at (0): [] 0x0
    hardirqs last disabled at (0): [] copy_process+0x8a0/0x1d70
    softirqs last enabled at (0): [] copy_process+0x8a0/0x1d70
    softirqs last disabled at (0): [] 0x0
    ---[ end trace dd74718fef1ed5c7 ]---
    ------------[ cut here ]------------
    WARNING: CPU: 2 PID: 1729896 at fs/btrfs/block-group.c:3377 btrfs_free_block_groups+0x25d/0x2f0 [btrfs]
    Modules linked in: btrfs dm_snapshot dm_thin_pool (...)
    CPU: 5 PID: 1729896 Comm: umount Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    RIP: 0010:btrfs_free_block_groups+0x25d/0x2f0 [btrfs]
    Code: ad de 49 be 22 01 00 (...)
    RSP: 0018:ffffb270826bbde8 EFLAGS: 00010206
    RAX: ffff947ebeae1d08 RBX: ffff947ed73e4000 RCX: 0000000000000000
    RDX: 0000000000000001 RSI: ffff947e9d823ae8 RDI: 0000000000000246
    RBP: ffff947ebeae1d08 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000001 R12: ffff947ebeae1c00
    R13: ffff947ed73e5278 R14: dead000000000122 R15: dead000000000100
    FS: 00007f15edfea840(0000) GS:ffff9481ad200000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00007f1475d98ea8 CR3: 0000000138f68005 CR4: 00000000003706e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
    close_ctree+0x2ba/0x2fa [btrfs]
    generic_shutdown_super+0x6c/0x100
    kill_anon_super+0x14/0x30
    btrfs_kill_super+0x12/0x20 [btrfs]
    deactivate_locked_super+0x31/0x70
    cleanup_mnt+0x100/0x160
    task_work_run+0x68/0xb0
    exit_to_user_mode_prepare+0x1bb/0x1c0
    syscall_exit_to_user_mode+0x4b/0x260
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f15ee221ee7
    Code: ff 0b 00 f7 d8 64 89 (...)
    RSP: 002b:00007ffe9470f0f8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
    RAX: 0000000000000000 RBX: 00007f15ee347264 RCX: 00007f15ee221ee7
    RDX: ffffffffffffff78 RSI: 0000000000000000 RDI: 000056169701d000
    RBP: 0000561697018a30 R08: 0000000000000000 R09: 00007f15ee2e2be0
    R10: 000056169701efe0 R11: 0000000000000246 R12: 0000000000000000
    R13: 000056169701d000 R14: 0000561697018b40 R15: 0000561697018c60
    irq event stamp: 0
    hardirqs last enabled at (0): [] 0x0
    hardirqs last disabled at (0): [] copy_process+0x8a0/0x1d70
    softirqs last enabled at (0): [] copy_process+0x8a0/0x1d70
    softirqs last disabled at (0): [] 0x0
    ---[ end trace dd74718fef1ed5c8 ]---
    BTRFS info (device sdc): space_info 4 has 268238848 free, is not full
    BTRFS info (device sdc): space_info total=268435456, used=114688, pinned=0, reserved=16384, may_use=0, readonly=65536
    BTRFS info (device sdc): global_block_rsv: size 0 reserved 0
    BTRFS info (device sdc): trans_block_rsv: size 0 reserved 0
    BTRFS info (device sdc): chunk_block_rsv: size 0 reserved 0
    BTRFS info (device sdc): delayed_block_rsv: size 0 reserved 0
    BTRFS info (device sdc): delayed_refs_rsv: size 524288 reserved 0

    And the crash, which only happens when we do not have crc32c hardware
    acceleration, produces the following trace immediately after those
    warnings:

    stack segment: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC PTI
    CPU: 2 PID: 1749129 Comm: umount Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    RIP: 0010:btrfs_queue_work+0x36/0x190 [btrfs]
    Code: 54 55 53 48 89 f3 (...)
    RSP: 0018:ffffb27082443ae8 EFLAGS: 00010282
    RAX: 0000000000000004 RBX: ffff94810ee9ad90 RCX: 0000000000000000
    RDX: 0000000000000001 RSI: ffff94810ee9ad90 RDI: ffff947ed8ee75a0
    RBP: a56b6b6b6b6b6b6b R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000007 R11: 0000000000000001 R12: ffff947fa9b435a8
    R13: ffff94810ee9ad90 R14: 0000000000000000 R15: ffff947e93dc0000
    FS: 00007f3cfe974840(0000) GS:ffff9481ac600000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00007f1b42995a70 CR3: 0000000127638003 CR4: 00000000003706e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
    btrfs_wq_submit_bio+0xb3/0xd0 [btrfs]
    btrfs_submit_metadata_bio+0x44/0xc0 [btrfs]
    submit_one_bio+0x61/0x70 [btrfs]
    btree_write_cache_pages+0x414/0x450 [btrfs]
    ? kobject_put+0x9a/0x1d0
    ? trace_hardirqs_on+0x1b/0xf0
    ? _raw_spin_unlock_irqrestore+0x3c/0x60
    ? free_debug_processing+0x1e1/0x2b0
    do_writepages+0x43/0xe0
    ? lock_acquired+0x199/0x490
    __writeback_single_inode+0x59/0x650
    writeback_single_inode+0xaf/0x120
    write_inode_now+0x94/0xd0
    iput+0x187/0x2b0
    close_ctree+0x2c6/0x2fa [btrfs]
    generic_shutdown_super+0x6c/0x100
    kill_anon_super+0x14/0x30
    btrfs_kill_super+0x12/0x20 [btrfs]
    deactivate_locked_super+0x31/0x70
    cleanup_mnt+0x100/0x160
    task_work_run+0x68/0xb0
    exit_to_user_mode_prepare+0x1bb/0x1c0
    syscall_exit_to_user_mode+0x4b/0x260
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f3cfebabee7
    Code: ff 0b 00 f7 d8 64 89 01 (...)
    RSP: 002b:00007ffc9c9a05f8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
    RAX: 0000000000000000 RBX: 00007f3cfecd1264 RCX: 00007f3cfebabee7
    RDX: ffffffffffffff78 RSI: 0000000000000000 RDI: 0000562b6b478000
    RBP: 0000562b6b473a30 R08: 0000000000000000 R09: 00007f3cfec6cbe0
    R10: 0000562b6b479fe0 R11: 0000000000000246 R12: 0000000000000000
    R13: 0000562b6b478000 R14: 0000562b6b473b40 R15: 0000562b6b473c60
    Modules linked in: btrfs dm_snapshot dm_thin_pool (...)
    ---[ end trace dd74718fef1ed5cc ]---

    Finally when we remove the btrfs module (rmmod btrfs), there are several
    warnings about objects that were allocated from our slabs but were never
    freed, consequence of the transaction that was never committed and got
    leaked:

    =============================================================================
    BUG btrfs_delayed_ref_head (Tainted: G B W ): Objects remaining in btrfs_delayed_ref_head on __kmem_cache_shutdown()
    -----------------------------------------------------------------------------

    INFO: Slab 0x0000000094c2ae56 objects=24 used=2 fp=0x000000002bfa2521 flags=0x17fffc000010200
    CPU: 5 PID: 1729921 Comm: rmmod Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    Call Trace:
    dump_stack+0x8d/0xb5
    slab_err+0xb7/0xdc
    ? lock_acquired+0x199/0x490
    __kmem_cache_shutdown+0x1ac/0x3c0
    ? lock_release+0x20e/0x4c0
    kmem_cache_destroy+0x55/0x120
    btrfs_delayed_ref_exit+0x11/0x35 [btrfs]
    exit_btrfs_fs+0xa/0x59 [btrfs]
    __x64_sys_delete_module+0x194/0x260
    ? fpregs_assert_state_consistent+0x1e/0x40
    ? exit_to_user_mode_prepare+0x55/0x1c0
    ? trace_hardirqs_on+0x1b/0xf0
    do_syscall_64+0x33/0x80
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f693e305897
    Code: 73 01 c3 48 8b 0d f9 f5 (...)
    RSP: 002b:00007ffcf73eb508 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
    RAX: ffffffffffffffda RBX: 0000559df504f760 RCX: 00007f693e305897
    RDX: 000000000000000a RSI: 0000000000000800 RDI: 0000559df504f7c8
    RBP: 00007ffcf73eb568 R08: 0000000000000000 R09: 0000000000000000
    R10: 00007f693e378ac0 R11: 0000000000000206 R12: 00007ffcf73eb740
    R13: 00007ffcf73ec5a6 R14: 0000559df504f2a0 R15: 0000559df504f760
    INFO: Object 0x0000000050cbdd61 @offset=12104
    INFO: Allocated in btrfs_add_delayed_tree_ref+0xbb/0x480 [btrfs] age=1894 cpu=6 pid=1729873
    __slab_alloc.isra.0+0x109/0x1c0
    kmem_cache_alloc+0x7bb/0x830
    btrfs_add_delayed_tree_ref+0xbb/0x480 [btrfs]
    btrfs_free_tree_block+0x128/0x360 [btrfs]
    __btrfs_cow_block+0x489/0x5f0 [btrfs]
    btrfs_cow_block+0xf7/0x220 [btrfs]
    btrfs_search_slot+0x62a/0xc40 [btrfs]
    btrfs_del_orphan_item+0x65/0xd0 [btrfs]
    btrfs_find_orphan_roots+0x1bf/0x200 [btrfs]
    open_ctree+0x125a/0x18a0 [btrfs]
    btrfs_mount_root.cold+0x13/0xed [btrfs]
    legacy_get_tree+0x30/0x60
    vfs_get_tree+0x28/0xe0
    fc_mount+0xe/0x40
    vfs_kern_mount.part.0+0x71/0x90
    btrfs_mount+0x13b/0x3e0 [btrfs]
    INFO: Freed in __btrfs_run_delayed_refs+0x1117/0x1290 [btrfs] age=4292 cpu=2 pid=1729526
    kmem_cache_free+0x34c/0x3c0
    __btrfs_run_delayed_refs+0x1117/0x1290 [btrfs]
    btrfs_run_delayed_refs+0x81/0x210 [btrfs]
    commit_cowonly_roots+0xfb/0x300 [btrfs]
    btrfs_commit_transaction+0x367/0xc40 [btrfs]
    sync_filesystem+0x74/0x90
    generic_shutdown_super+0x22/0x100
    kill_anon_super+0x14/0x30
    btrfs_kill_super+0x12/0x20 [btrfs]
    deactivate_locked_super+0x31/0x70
    cleanup_mnt+0x100/0x160
    task_work_run+0x68/0xb0
    exit_to_user_mode_prepare+0x1bb/0x1c0
    syscall_exit_to_user_mode+0x4b/0x260
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    INFO: Object 0x0000000086e9b0ff @offset=12776
    INFO: Allocated in btrfs_add_delayed_tree_ref+0xbb/0x480 [btrfs] age=1900 cpu=6 pid=1729873
    __slab_alloc.isra.0+0x109/0x1c0
    kmem_cache_alloc+0x7bb/0x830
    btrfs_add_delayed_tree_ref+0xbb/0x480 [btrfs]
    btrfs_alloc_tree_block+0x2bf/0x360 [btrfs]
    alloc_tree_block_no_bg_flush+0x4f/0x60 [btrfs]
    __btrfs_cow_block+0x12d/0x5f0 [btrfs]
    btrfs_cow_block+0xf7/0x220 [btrfs]
    btrfs_search_slot+0x62a/0xc40 [btrfs]
    btrfs_del_orphan_item+0x65/0xd0 [btrfs]
    btrfs_find_orphan_roots+0x1bf/0x200 [btrfs]
    open_ctree+0x125a/0x18a0 [btrfs]
    btrfs_mount_root.cold+0x13/0xed [btrfs]
    legacy_get_tree+0x30/0x60
    vfs_get_tree+0x28/0xe0
    fc_mount+0xe/0x40
    vfs_kern_mount.part.0+0x71/0x90
    INFO: Freed in __btrfs_run_delayed_refs+0x1117/0x1290 [btrfs] age=3141 cpu=6 pid=1729803
    kmem_cache_free+0x34c/0x3c0
    __btrfs_run_delayed_refs+0x1117/0x1290 [btrfs]
    btrfs_run_delayed_refs+0x81/0x210 [btrfs]
    btrfs_write_dirty_block_groups+0x17d/0x3d0 [btrfs]
    commit_cowonly_roots+0x248/0x300 [btrfs]
    btrfs_commit_transaction+0x367/0xc40 [btrfs]
    close_ctree+0x113/0x2fa [btrfs]
    generic_shutdown_super+0x6c/0x100
    kill_anon_super+0x14/0x30
    btrfs_kill_super+0x12/0x20 [btrfs]
    deactivate_locked_super+0x31/0x70
    cleanup_mnt+0x100/0x160
    task_work_run+0x68/0xb0
    exit_to_user_mode_prepare+0x1bb/0x1c0
    syscall_exit_to_user_mode+0x4b/0x260
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    kmem_cache_destroy btrfs_delayed_ref_head: Slab cache still has objects
    CPU: 5 PID: 1729921 Comm: rmmod Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    Call Trace:
    dump_stack+0x8d/0xb5
    kmem_cache_destroy+0x119/0x120
    btrfs_delayed_ref_exit+0x11/0x35 [btrfs]
    exit_btrfs_fs+0xa/0x59 [btrfs]
    __x64_sys_delete_module+0x194/0x260
    ? fpregs_assert_state_consistent+0x1e/0x40
    ? exit_to_user_mode_prepare+0x55/0x1c0
    ? trace_hardirqs_on+0x1b/0xf0
    do_syscall_64+0x33/0x80
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f693e305897
    Code: 73 01 c3 48 8b 0d f9 f5 0b (...)
    RSP: 002b:00007ffcf73eb508 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
    RAX: ffffffffffffffda RBX: 0000559df504f760 RCX: 00007f693e305897
    RDX: 000000000000000a RSI: 0000000000000800 RDI: 0000559df504f7c8
    RBP: 00007ffcf73eb568 R08: 0000000000000000 R09: 0000000000000000
    R10: 00007f693e378ac0 R11: 0000000000000206 R12: 00007ffcf73eb740
    R13: 00007ffcf73ec5a6 R14: 0000559df504f2a0 R15: 0000559df504f760
    =============================================================================
    BUG btrfs_delayed_tree_ref (Tainted: G B W ): Objects remaining in btrfs_delayed_tree_ref on __kmem_cache_shutdown()
    -----------------------------------------------------------------------------

    INFO: Slab 0x0000000011f78dc0 objects=37 used=2 fp=0x0000000032d55d91 flags=0x17fffc000010200
    CPU: 3 PID: 1729921 Comm: rmmod Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    Call Trace:
    dump_stack+0x8d/0xb5
    slab_err+0xb7/0xdc
    ? lock_acquired+0x199/0x490
    __kmem_cache_shutdown+0x1ac/0x3c0
    ? lock_release+0x20e/0x4c0
    kmem_cache_destroy+0x55/0x120
    btrfs_delayed_ref_exit+0x1d/0x35 [btrfs]
    exit_btrfs_fs+0xa/0x59 [btrfs]
    __x64_sys_delete_module+0x194/0x260
    ? fpregs_assert_state_consistent+0x1e/0x40
    ? exit_to_user_mode_prepare+0x55/0x1c0
    ? trace_hardirqs_on+0x1b/0xf0
    do_syscall_64+0x33/0x80
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f693e305897
    Code: 73 01 c3 48 8b 0d f9 f5 (...)
    RSP: 002b:00007ffcf73eb508 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
    RAX: ffffffffffffffda RBX: 0000559df504f760 RCX: 00007f693e305897
    RDX: 000000000000000a RSI: 0000000000000800 RDI: 0000559df504f7c8
    RBP: 00007ffcf73eb568 R08: 0000000000000000 R09: 0000000000000000
    R10: 00007f693e378ac0 R11: 0000000000000206 R12: 00007ffcf73eb740
    R13: 00007ffcf73ec5a6 R14: 0000559df504f2a0 R15: 0000559df504f760
    INFO: Object 0x000000001a340018 @offset=4408
    INFO: Allocated in btrfs_add_delayed_tree_ref+0x9e/0x480 [btrfs] age=1917 cpu=6 pid=1729873
    __slab_alloc.isra.0+0x109/0x1c0
    kmem_cache_alloc+0x7bb/0x830
    btrfs_add_delayed_tree_ref+0x9e/0x480 [btrfs]
    btrfs_free_tree_block+0x128/0x360 [btrfs]
    __btrfs_cow_block+0x489/0x5f0 [btrfs]
    btrfs_cow_block+0xf7/0x220 [btrfs]
    btrfs_search_slot+0x62a/0xc40 [btrfs]
    btrfs_del_orphan_item+0x65/0xd0 [btrfs]
    btrfs_find_orphan_roots+0x1bf/0x200 [btrfs]
    open_ctree+0x125a/0x18a0 [btrfs]
    btrfs_mount_root.cold+0x13/0xed [btrfs]
    legacy_get_tree+0x30/0x60
    vfs_get_tree+0x28/0xe0
    fc_mount+0xe/0x40
    vfs_kern_mount.part.0+0x71/0x90
    btrfs_mount+0x13b/0x3e0 [btrfs]
    INFO: Freed in __btrfs_run_delayed_refs+0x63d/0x1290 [btrfs] age=4167 cpu=4 pid=1729795
    kmem_cache_free+0x34c/0x3c0
    __btrfs_run_delayed_refs+0x63d/0x1290 [btrfs]
    btrfs_run_delayed_refs+0x81/0x210 [btrfs]
    btrfs_commit_transaction+0x60/0xc40 [btrfs]
    create_subvol+0x56a/0x990 [btrfs]
    btrfs_mksubvol+0x3fb/0x4a0 [btrfs]
    __btrfs_ioctl_snap_create+0x119/0x1a0 [btrfs]
    btrfs_ioctl_snap_create+0x58/0x80 [btrfs]
    btrfs_ioctl+0x1a92/0x36f0 [btrfs]
    __x64_sys_ioctl+0x83/0xb0
    do_syscall_64+0x33/0x80
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    INFO: Object 0x000000002b46292a @offset=13648
    INFO: Allocated in btrfs_add_delayed_tree_ref+0x9e/0x480 [btrfs] age=1923 cpu=6 pid=1729873
    __slab_alloc.isra.0+0x109/0x1c0
    kmem_cache_alloc+0x7bb/0x830
    btrfs_add_delayed_tree_ref+0x9e/0x480 [btrfs]
    btrfs_alloc_tree_block+0x2bf/0x360 [btrfs]
    alloc_tree_block_no_bg_flush+0x4f/0x60 [btrfs]
    __btrfs_cow_block+0x12d/0x5f0 [btrfs]
    btrfs_cow_block+0xf7/0x220 [btrfs]
    btrfs_search_slot+0x62a/0xc40 [btrfs]
    btrfs_del_orphan_item+0x65/0xd0 [btrfs]
    btrfs_find_orphan_roots+0x1bf/0x200 [btrfs]
    open_ctree+0x125a/0x18a0 [btrfs]
    btrfs_mount_root.cold+0x13/0xed [btrfs]
    legacy_get_tree+0x30/0x60
    vfs_get_tree+0x28/0xe0
    fc_mount+0xe/0x40
    vfs_kern_mount.part.0+0x71/0x90
    INFO: Freed in __btrfs_run_delayed_refs+0x63d/0x1290 [btrfs] age=3164 cpu=6 pid=1729803
    kmem_cache_free+0x34c/0x3c0
    __btrfs_run_delayed_refs+0x63d/0x1290 [btrfs]
    btrfs_run_delayed_refs+0x81/0x210 [btrfs]
    commit_cowonly_roots+0xfb/0x300 [btrfs]
    btrfs_commit_transaction+0x367/0xc40 [btrfs]
    close_ctree+0x113/0x2fa [btrfs]
    generic_shutdown_super+0x6c/0x100
    kill_anon_super+0x14/0x30
    btrfs_kill_super+0x12/0x20 [btrfs]
    deactivate_locked_super+0x31/0x70
    cleanup_mnt+0x100/0x160
    task_work_run+0x68/0xb0
    exit_to_user_mode_prepare+0x1bb/0x1c0
    syscall_exit_to_user_mode+0x4b/0x260
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    kmem_cache_destroy btrfs_delayed_tree_ref: Slab cache still has objects
    CPU: 5 PID: 1729921 Comm: rmmod Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    Call Trace:
    dump_stack+0x8d/0xb5
    kmem_cache_destroy+0x119/0x120
    btrfs_delayed_ref_exit+0x1d/0x35 [btrfs]
    exit_btrfs_fs+0xa/0x59 [btrfs]
    __x64_sys_delete_module+0x194/0x260
    ? fpregs_assert_state_consistent+0x1e/0x40
    ? exit_to_user_mode_prepare+0x55/0x1c0
    ? trace_hardirqs_on+0x1b/0xf0
    do_syscall_64+0x33/0x80
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f693e305897
    Code: 73 01 c3 48 8b 0d f9 f5 (...)
    RSP: 002b:00007ffcf73eb508 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
    RAX: ffffffffffffffda RBX: 0000559df504f760 RCX: 00007f693e305897
    RDX: 000000000000000a RSI: 0000000000000800 RDI: 0000559df504f7c8
    RBP: 00007ffcf73eb568 R08: 0000000000000000 R09: 0000000000000000
    R10: 00007f693e378ac0 R11: 0000000000000206 R12: 00007ffcf73eb740
    R13: 00007ffcf73ec5a6 R14: 0000559df504f2a0 R15: 0000559df504f760
    =============================================================================
    BUG btrfs_delayed_extent_op (Tainted: G B W ): Objects remaining in btrfs_delayed_extent_op on __kmem_cache_shutdown()
    -----------------------------------------------------------------------------

    INFO: Slab 0x00000000f145ce2f objects=22 used=1 fp=0x00000000af0f92cf flags=0x17fffc000010200
    CPU: 5 PID: 1729921 Comm: rmmod Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    Call Trace:
    dump_stack+0x8d/0xb5
    slab_err+0xb7/0xdc
    ? lock_acquired+0x199/0x490
    __kmem_cache_shutdown+0x1ac/0x3c0
    ? __mutex_unlock_slowpath+0x45/0x2a0
    kmem_cache_destroy+0x55/0x120
    exit_btrfs_fs+0xa/0x59 [btrfs]
    __x64_sys_delete_module+0x194/0x260
    ? fpregs_assert_state_consistent+0x1e/0x40
    ? exit_to_user_mode_prepare+0x55/0x1c0
    ? trace_hardirqs_on+0x1b/0xf0
    do_syscall_64+0x33/0x80
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f693e305897
    Code: 73 01 c3 48 8b 0d f9 f5 (...)
    RSP: 002b:00007ffcf73eb508 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
    RAX: ffffffffffffffda RBX: 0000559df504f760 RCX: 00007f693e305897
    RDX: 000000000000000a RSI: 0000000000000800 RDI: 0000559df504f7c8
    RBP: 00007ffcf73eb568 R08: 0000000000000000 R09: 0000000000000000
    R10: 00007f693e378ac0 R11: 0000000000000206 R12: 00007ffcf73eb740
    R13: 00007ffcf73ec5a6 R14: 0000559df504f2a0 R15: 0000559df504f760
    INFO: Object 0x000000004cf95ea8 @offset=6264
    INFO: Allocated in btrfs_alloc_tree_block+0x1e0/0x360 [btrfs] age=1931 cpu=6 pid=1729873
    __slab_alloc.isra.0+0x109/0x1c0
    kmem_cache_alloc+0x7bb/0x830
    btrfs_alloc_tree_block+0x1e0/0x360 [btrfs]
    alloc_tree_block_no_bg_flush+0x4f/0x60 [btrfs]
    __btrfs_cow_block+0x12d/0x5f0 [btrfs]
    btrfs_cow_block+0xf7/0x220 [btrfs]
    btrfs_search_slot+0x62a/0xc40 [btrfs]
    btrfs_del_orphan_item+0x65/0xd0 [btrfs]
    btrfs_find_orphan_roots+0x1bf/0x200 [btrfs]
    open_ctree+0x125a/0x18a0 [btrfs]
    btrfs_mount_root.cold+0x13/0xed [btrfs]
    legacy_get_tree+0x30/0x60
    vfs_get_tree+0x28/0xe0
    fc_mount+0xe/0x40
    vfs_kern_mount.part.0+0x71/0x90
    btrfs_mount+0x13b/0x3e0 [btrfs]
    INFO: Freed in __btrfs_run_delayed_refs+0xabd/0x1290 [btrfs] age=3173 cpu=6 pid=1729803
    kmem_cache_free+0x34c/0x3c0
    __btrfs_run_delayed_refs+0xabd/0x1290 [btrfs]
    btrfs_run_delayed_refs+0x81/0x210 [btrfs]
    commit_cowonly_roots+0xfb/0x300 [btrfs]
    btrfs_commit_transaction+0x367/0xc40 [btrfs]
    close_ctree+0x113/0x2fa [btrfs]
    generic_shutdown_super+0x6c/0x100
    kill_anon_super+0x14/0x30
    btrfs_kill_super+0x12/0x20 [btrfs]
    deactivate_locked_super+0x31/0x70
    cleanup_mnt+0x100/0x160
    task_work_run+0x68/0xb0
    exit_to_user_mode_prepare+0x1bb/0x1c0
    syscall_exit_to_user_mode+0x4b/0x260
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    kmem_cache_destroy btrfs_delayed_extent_op: Slab cache still has objects
    CPU: 3 PID: 1729921 Comm: rmmod Tainted: G B W 5.10.0-rc4-btrfs-next-73 #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014
    Call Trace:
    dump_stack+0x8d/0xb5
    kmem_cache_destroy+0x119/0x120
    exit_btrfs_fs+0xa/0x59 [btrfs]
    __x64_sys_delete_module+0x194/0x260
    ? fpregs_assert_state_consistent+0x1e/0x40
    ? exit_to_user_mode_prepare+0x55/0x1c0
    ? trace_hardirqs_on+0x1b/0xf0
    do_syscall_64+0x33/0x80
    entry_SYSCALL_64_after_hwframe+0x44/0xa9
    RIP: 0033:0x7f693e305897
    Code: 73 01 c3 48 8b 0d f9 (...)
    RSP: 002b:00007ffcf73eb508 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
    RAX: ffffffffffffffda RBX: 0000559df504f760 RCX: 00007f693e305897
    RDX: 000000000000000a RSI: 0000000000000800 RDI: 0000559df504f7c8
    RBP: 00007ffcf73eb568 R08: 0000000000000000 R09: 0000000000000000
    R10: 00007f693e378ac0 R11: 0000000000000206 R12: 00007ffcf73eb740
    R13: 00007ffcf73ec5a6 R14: 0000559df504f2a0 R15: 0000559df504f760
    BTRFS: state leak: start 30408704 end 30425087 state 1 in tree 1 refs 1

    Fix this issue by having the remount path stop the qgroup rescan worker
    when we are remounting RO and teach the rescan worker to stop when a
    remount is in progress. If later a remount in RW mode happens, we are
    already resuming the qgroup rescan worker through the call to
    btrfs_qgroup_rescan_resume(), so we do not need to worry about that.

    Tested-by: Fabian Vogt
    Reviewed-by: Josef Bacik
    Signed-off-by: Filipe Manana
    Reviewed-by: David Sterba
    Signed-off-by: David Sterba
    Signed-off-by: Sasha Levin

    Filipe Manana
     
  • [ Upstream commit 8fc058597a283e9a37720abb0e8d68e342b9387d ]

    btrfs_discard_workfn() drops discard_ctl->lock just to take it again in
    a moment in btrfs_discard_schedule_work(). Avoid that and also reuse
    ktime.

    Reviewed-by: Josef Bacik
    Signed-off-by: Pavel Begunkov
    Reviewed-by: David Sterba
    Signed-off-by: David Sterba
    Signed-off-by: Sasha Levin

    Pavel Begunkov
     
  • [ Upstream commit ea9ed87c73e87e044b2c58d658eb4ba5216bc488 ]

    Might happen that bg->discard_eligible_time was changed without
    rescheduling, so btrfs_discard_workfn() wakes up earlier than that new
    time, peek_discard_list() returns NULL, and all work halts and goes to
    sleep without further rescheduling even there are block groups to
    discard.

    It happens pretty often, but not so visible from the userspace because
    after some time it usually will be kicked off anyway by someone else
    calling btrfs_discard_reschedule_work().

    Fix it by continue rescheduling if block group discard lists are not
    empty.

    Reviewed-by: Josef Bacik
    Signed-off-by: Pavel Begunkov
    Signed-off-by: David Sterba
    Signed-off-by: Sasha Levin

    Pavel Begunkov
     
  • [ Upstream commit f6f92968e1e5a7a9d211faaebefc26ebe408dad7 ]

    Not all firmware versions support allocating DMA memory in smaller blocks so
    first try to allocate big block of DMA memory for QMI. If the allocation fails,
    let firmware request multiple blocks of DMA memory with smaller size.

    This also fixes an unnecessary error message seen during ath11k probe on
    QCA6390:

    ath11k_pci 0000:06:00.0: Respond mem req failed, result: 1, err: 0
    ath11k_pci 0000:06:00.0: qmi failed to respond fw mem req:-22

    Tested-on: QCA6390 hw2.0 PCI WLAN.HST.1.0.1-01740-QCAHSTSWPLZ_V2_TO_X86-1

    Signed-off-by: Carl Huang
    Signed-off-by: Kalle Valo
    Link: https://lore.kernel.org/r/1608127593-15192-1-git-send-email-kvalo@codeaurora.org
    Signed-off-by: Sasha Levin

    Carl Huang
     
  • [ Upstream commit 2b33d6ffa9e38f344418976b06057e2fc2aa9e2a ]

    currently mtype_resize() can cause oops

    t = ip_set_alloc(htable_size(htable_bits));
    if (!t) {
    ret = -ENOMEM;
    goto out;
    }
    t->hregion = ip_set_alloc(ahash_sizeof_regions(htable_bits));

    Increased htable_bits can force htable_size() to return 0.
    In own turn ip_set_alloc(0) returns not 0 but ZERO_SIZE_PTR,
    so follwoing access to t->hregion should trigger an OOPS.

    Signed-off-by: Vasily Averin
    Acked-by: Jozsef Kadlecsik
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Vasily Averin
     
  • [ Upstream commit 3597010630d0aa96f5778901e691c6068bb86318 ]

    During connect and disconnect stress test, crashed happened
    because ar->rx_channel is NULL. Fix it by checking whether
    ar->rx_channel is NULL.

    Crash stack is as below:
    RIP: 0010:ath11k_dp_rx_h_ppdu+0x110/0x230 [ath11k]
    [ 5028.808963] ath11k_dp_rx_wbm_err+0x14a/0x360 [ath11k]
    [ 5028.808970] ath11k_dp_rx_process_wbm_err+0x41c/0x520 [ath11k]
    [ 5028.808978] ath11k_dp_service_srng+0x25e/0x2d0 [ath11k]
    [ 5028.808982] ath11k_pci_ext_grp_napi_poll+0x23/0x80 [ath11k_pci]
    [ 5028.808986] net_rx_action+0x27e/0x400
    [ 5028.808990] __do_softirq+0xfd/0x2bb
    [ 5028.808993] irq_exit+0xa6/0xb0
    [ 5028.808995] do_IRQ+0x56/0xe0
    [ 5028.808997] common_interrupt+0xf/0xf

    Tested-on: QCA6390 hw2.0 PCI WLAN.HST.1.0.1-01740-QCAHSTSWPLZ_V2_TO_X86-1

    Signed-off-by: Carl Huang
    Signed-off-by: Kalle Valo
    Link: https://lore.kernel.org/r/20201211055613.9310-1-cjhuang@codeaurora.org
    Signed-off-by: Sasha Levin

    Carl Huang
     
  • [ Upstream commit c0bc969c176b10598b31d5d1a5edf9a5261f0a9f ]

    xt875 comes up with a iva voltage of 1375000 and android runs at this too. fix
    maximum voltage to be consistent with this.

    Signed-off-by: Carl Philipp Klemm
    Signed-off-by: Tony Lindgren
    Signed-off-by: Sasha Levin

    Carl Philipp Klemm
     
  • [ Upstream commit c5e6ae563c802c4d828d42e134af64004db2e58c ]

    If you run 'make uImage uImage.gz' with the parallel option, uImage.gz
    will be created by two threads simultaneously.

    This is because arch/arc/Makefile does not specify the dependency
    between uImage and uImage.gz. Hence, GNU Make assumes they can be
    built in parallel. One thread descends into arch/arc/boot/ to create
    uImage, and another to create uImage.gz.

    Please notice the same log is displayed twice in the following steps:

    $ export CROSS_COMPILE=
    $ make -s ARCH=arc defconfig
    $ make -j$(nproc) ARCH=arc uImage uImage.gz
    [ snip ]
    LD vmlinux
    SORTTAB vmlinux
    SYSMAP System.map
    OBJCOPY arch/arc/boot/vmlinux.bin
    OBJCOPY arch/arc/boot/vmlinux.bin
    GZIP arch/arc/boot/vmlinux.bin.gz
    GZIP arch/arc/boot/vmlinux.bin.gz
    UIMAGE arch/arc/boot/uImage.gz
    UIMAGE arch/arc/boot/uImage.gz
    Image Name: Linux-5.10.0-rc4-00003-g62f23044
    Created: Sun Nov 22 02:52:26 2020
    Image Type: ARC Linux Kernel Image (gzip compressed)
    Data Size: 2109376 Bytes = 2059.94 KiB = 2.01 MiB
    Load Address: 80000000
    Entry Point: 80004000
    Image arch/arc/boot/uImage is ready
    Image Name: Linux-5.10.0-rc4-00003-g62f23044
    Created: Sun Nov 22 02:52:26 2020
    Image Type: ARC Linux Kernel Image (gzip compressed)
    Data Size: 2815455 Bytes = 2749.47 KiB = 2.69 MiB
    Load Address: 80000000
    Entry Point: 80004000

    This is a race between the two threads trying to write to the same file
    arch/arc/boot/uImage.gz. This is a potential problem that can generate
    a broken file.

    I fixed a similar problem for ARM by commit 3939f3345050 ("ARM: 8418/1:
    add boot image dependencies to not generate invalid images").

    I highly recommend to avoid such build rules that cause a race condition.

    Move the uImage rule to arch/arc/Makefile.

    Another strangeness is that arch/arc/boot/Makefile compares the
    timestamps between $(obj)/uImage and $(obj)/uImage.*:

    $(obj)/uImage: $(obj)/uImage.$(suffix-y)
    @ln -sf $(notdir $
    Signed-off-by: Vineet Gupta
    Signed-off-by: Sasha Levin

    Masahiro Yamada
     
  • [ Upstream commit 0cfccb3c04934cdef42ae26042139f16e805b5f7 ]

    The top-level boot_targets (uImage and uImage.*) should be phony
    targets. They just let Kbuild descend into arch/arc/boot/ and create
    files there.

    If a file exists in the top directory with the same name, the boot
    image will not be created.

    You can confirm it by the following steps:

    $ export CROSS_COMPILE=
    $ make -s ARCH=arc defconfig all # vmlinux will be built
    $ touch uImage.gz
    $ make ARCH=arc uImage.gz
    CALL scripts/atomic/check-atomics.sh
    CALL scripts/checksyscalls.sh
    CHK include/generated/compile.h
    # arch/arc/boot/uImage.gz is not created

    Specify the targets as PHONY to fix this.

    Signed-off-by: Masahiro Yamada
    Signed-off-by: Vineet Gupta
    Signed-off-by: Sasha Levin

    Masahiro Yamada
     
  • [ Upstream commit f2712ec76a5433e5ec9def2bd52a95df1f96d050 ]

    arch/arc/boot/Makefile supports uImage.lzma, but you cannot do
    'make uImage.lzma' because the corresponding target is missing
    in arch/arc/Makefile. Add it.

    I also changed the assignment operator '+=' to ':=' since this is the
    only place where we expect this variable to be set.

    Signed-off-by: Masahiro Yamada
    Signed-off-by: Vineet Gupta
    Signed-off-by: Sasha Levin

    Masahiro Yamada
     
  • [ Upstream commit 9836720911cfec25d3fbdead1c438bf87e0f2841 ]

    The deb-pkg builds for ARCH=arc fail.

    $ export CROSS_COMPILE=
    $ make -s ARCH=arc defconfig
    $ make ARCH=arc bindeb-pkg
    SORTTAB vmlinux
    SYSMAP System.map
    MODPOST Module.symvers
    make KERNELRELEASE=5.10.0-rc4 ARCH=arc KBUILD_BUILD_VERSION=2 -f ./Makefile intdeb-pkg
    sh ./scripts/package/builddeb
    cp: cannot stat 'arch/arc/boot/bootpImage': No such file or directory
    make[4]: *** [scripts/Makefile.package:87: intdeb-pkg] Error 1
    make[3]: *** [Makefile:1527: intdeb-pkg] Error 2
    make[2]: *** [debian/rules:13: binary-arch] Error 2
    dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
    make[1]: *** [scripts/Makefile.package:83: bindeb-pkg] Error 2
    make: *** [Makefile:1527: bindeb-pkg] Error 2

    The reason is obvious; arch/arc/Makefile sets $(boot)/bootpImage as
    the default image, but there is no rule to build it.

    Remove the meaningless KBUILD_IMAGE assignment so it will fallback
    to the default vmlinux. With this change, you can build the deb package.

    I removed the 'bootpImage' target as well. At best, it provides
    'make bootpImage' as an alias of 'make vmlinux', but I do not see
    much sense in doing so.

    Signed-off-by: Masahiro Yamada
    Signed-off-by: Vineet Gupta
    Signed-off-by: Sasha Levin

    Masahiro Yamada
     
  • [ Upstream commit d434ab6db524ab1efd0afad4ffa1ee65ca6ac097 ]

    __io_req_task_submit() run by task_work can set mm and files, but
    io_sq_thread() in some cases, and because __io_sq_thread_acquire_mm()
    and __io_sq_thread_acquire_files() do a simple current->mm/files check
    it may end up submitting IO with mm/files of another task.

    We also need to drop it after in the end to drop potentially grabbed
    references to them.

    Cc: stable@vger.kernel.org # 5.9+
    Signed-off-by: Pavel Begunkov
    Signed-off-by: Jens Axboe
    Signed-off-by: Sasha Levin

    Pavel Begunkov
     
  • [ Upstream commit 621fadc22365f3cf307bcd9048e3372e9ee9cdcc ]

    In rare cases a task may be exiting while io_ring_exit_work() trying to
    cancel/wait its requests. It's ok for __io_sq_thread_acquire_mm()
    because of SQPOLL check, but is not for __io_sq_thread_acquire_files().
    Play safe and fail for both of them.

    Cc: stable@vger.kernel.org # 5.5+
    Signed-off-by: Pavel Begunkov
    Signed-off-by: Jens Axboe
    Signed-off-by: Sasha Levin

    Pavel Begunkov
     
  • [ Upstream commit 5a3b590d4b2db187faa6f06adc9a53d6199fb1f9 ]

    When the first file is opened, ext4 samples the mountpoint of the
    filesystem in 64 bytes of the super block. It does so using
    strlcpy(), this means that the remaining bytes in the super block
    string buffer are untouched. If the mount point before had a longer
    path than the current one, it can be reconstructed.

    Consider the case where the fs was mounted to "/media/johnjdeveloper"
    and later to "/". The super block buffer then contains
    "/\x00edia/johnjdeveloper".

    This case was seen in the wild and caused confusion how the name
    of a developer ands up on the super block of a filesystem used
    in production...

    Fix this by using strncpy() instead of strlcpy(). The superblock
    field is defined to be a fixed-size char array, and it is already
    marked using __nonstring in fs/ext4/ext4.h. The consumer of the field
    in e2fsprogs already assumes that in the case of a 64+ byte mount
    path, that s_last_mounted will not be NUL terminated.

    Link: https://lore.kernel.org/r/X9ujIOJG/HqMr88R@mit.edu
    Reported-by: Richard Weinberger
    Signed-off-by: Theodore Ts'o
    Cc: stable@kernel.org
    Signed-off-by: Sasha Levin

    Theodore Ts'o
     
  • [ Upstream commit 347fb0cfc9bab5195c6701e62eda488310d7938f ]

    While mounting a crafted image provided by user, kernel panics due to
    the invalid chunk item whose end is less than start.

    [66.387422] loop: module loaded
    [66.389773] loop0: detected capacity change from 262144 to 0
    [66.427708] BTRFS: device fsid a62e00e8-e94e-4200-8217-12444de93c2e devid 1 transid 12 /dev/loop0 scanned by mount (613)
    [66.431061] BTRFS info (device loop0): disk space caching is enabled
    [66.431078] BTRFS info (device loop0): has skinny extents
    [66.437101] BTRFS error: insert state: end < start 29360127 37748736
    [66.437136] ------------[ cut here ]------------
    [66.437140] WARNING: CPU: 16 PID: 613 at fs/btrfs/extent_io.c:557 insert_state.cold+0x1a/0x46 [btrfs]
    [66.437369] CPU: 16 PID: 613 Comm: mount Tainted: G O 5.11.0-rc1-custom #45
    [66.437374] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ArchLinux 1.14.0-1 04/01/2014
    [66.437378] RIP: 0010:insert_state.cold+0x1a/0x46 [btrfs]
    [66.437420] RSP: 0018:ffff93e5414c3908 EFLAGS: 00010286
    [66.437427] RAX: 0000000000000000 RBX: 0000000001bfffff RCX: 0000000000000000
    [66.437431] RDX: 0000000000000000 RSI: ffffffffb90d4660 RDI: 00000000ffffffff
    [66.437434] RBP: ffff93e5414c3938 R08: 0000000000000001 R09: 0000000000000001
    [66.437438] R10: ffff93e5414c3658 R11: 0000000000000000 R12: ffff8ec782d72aa0
    [66.437441] R13: ffff8ec78bc71628 R14: 0000000000000000 R15: 0000000002400000
    [66.437447] FS: 00007f01386a8580(0000) GS:ffff8ec809000000(0000) knlGS:0000000000000000
    [66.437451] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    [66.437455] CR2: 00007f01382fa000 CR3: 0000000109a34000 CR4: 0000000000750ee0
    [66.437460] PKRU: 55555554
    [66.437464] Call Trace:
    [66.437475] set_extent_bit+0x652/0x740 [btrfs]
    [66.437539] set_extent_bits_nowait+0x1d/0x20 [btrfs]
    [66.437576] add_extent_mapping+0x1e0/0x2f0 [btrfs]
    [66.437621] read_one_chunk+0x33c/0x420 [btrfs]
    [66.437674] btrfs_read_chunk_tree+0x6a4/0x870 [btrfs]
    [66.437708] ? kvm_sched_clock_read+0x18/0x40
    [66.437739] open_ctree+0xb32/0x1734 [btrfs]
    [66.437781] ? bdi_register_va+0x1b/0x20
    [66.437788] ? super_setup_bdi_name+0x79/0xd0
    [66.437810] btrfs_mount_root.cold+0x12/0xeb [btrfs]
    [66.437854] ? __kmalloc_track_caller+0x217/0x3b0
    [66.437873] legacy_get_tree+0x34/0x60
    [66.437880] vfs_get_tree+0x2d/0xc0
    [66.437888] vfs_kern_mount.part.0+0x78/0xc0
    [66.437897] vfs_kern_mount+0x13/0x20
    [66.437902] btrfs_mount+0x11f/0x3c0 [btrfs]
    [66.437940] ? kfree+0x5ff/0x670
    [66.437944] ? __kmalloc_track_caller+0x217/0x3b0
    [66.437962] legacy_get_tree+0x34/0x60
    [66.437974] vfs_get_tree+0x2d/0xc0
    [66.437983] path_mount+0x48c/0xd30
    [66.437998] __x64_sys_mount+0x108/0x140
    [66.438011] do_syscall_64+0x38/0x50
    [66.438018] entry_SYSCALL_64_after_hwframe+0x44/0xa9
    [66.438023] RIP: 0033:0x7f0138827f6e
    [66.438033] RSP: 002b:00007ffecd79edf8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
    [66.438040] RAX: ffffffffffffffda RBX: 00007f013894c264 RCX: 00007f0138827f6e
    [66.438044] RDX: 00005593a4a41360 RSI: 00005593a4a33690 RDI: 00005593a4a3a6c0
    [66.438047] RBP: 00005593a4a33440 R08: 0000000000000000 R09: 0000000000000001
    [66.438050] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
    [66.438054] R13: 00005593a4a3a6c0 R14: 00005593a4a41360 R15: 00005593a4a33440
    [66.438078] irq event stamp: 18169
    [66.438082] hardirqs last enabled at (18175): [] console_unlock+0x4ff/0x5f0
    [66.438088] hardirqs last disabled at (18180): [] console_unlock+0x467/0x5f0
    [66.438092] softirqs last enabled at (16910): [] asm_call_irq_on_stack+0x12/0x20
    [66.438097] softirqs last disabled at (16905): [] asm_call_irq_on_stack+0x12/0x20
    [66.438103] ---[ end trace e114b111db64298b ]---
    [66.438107] BTRFS error: found node 12582912 29360127 on insert of 37748736 29360127
    [66.438127] BTRFS critical: panic in extent_io_tree_panic:679: locking error: extent tree was modified by another thread while locked (errno=-17 Object already exists)
    [66.441069] ------------[ cut here ]------------
    [66.441072] kernel BUG at fs/btrfs/extent_io.c:679!
    [66.442064] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI
    [66.443018] CPU: 16 PID: 613 Comm: mount Tainted: G W O 5.11.0-rc1-custom #45
    [66.444538] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ArchLinux 1.14.0-1 04/01/2014
    [66.446223] RIP: 0010:extent_io_tree_panic.isra.0+0x23/0x25 [btrfs]
    [66.450878] RSP: 0018:ffff93e5414c3948 EFLAGS: 00010246
    [66.451840] RAX: 0000000000000000 RBX: 0000000001bfffff RCX: 0000000000000000
    [66.453141] RDX: 0000000000000000 RSI: ffffffffb90d4660 RDI: 00000000ffffffff
    [66.454445] RBP: ffff93e5414c3948 R08: 0000000000000001 R09: 0000000000000001
    [66.455743] R10: ffff93e5414c3658 R11: 0000000000000000 R12: ffff8ec782d728c0
    [66.457055] R13: ffff8ec78bc71628 R14: ffff8ec782d72aa0 R15: 0000000002400000
    [66.458356] FS: 00007f01386a8580(0000) GS:ffff8ec809000000(0000) knlGS:0000000000000000
    [66.459841] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    [66.460895] CR2: 00007f01382fa000 CR3: 0000000109a34000 CR4: 0000000000750ee0
    [66.462196] PKRU: 55555554
    [66.462692] Call Trace:
    [66.463139] set_extent_bit.cold+0x30/0x98 [btrfs]
    [66.464049] set_extent_bits_nowait+0x1d/0x20 [btrfs]
    [66.490466] add_extent_mapping+0x1e0/0x2f0 [btrfs]
    [66.514097] read_one_chunk+0x33c/0x420 [btrfs]
    [66.534976] btrfs_read_chunk_tree+0x6a4/0x870 [btrfs]
    [66.555718] ? kvm_sched_clock_read+0x18/0x40
    [66.575758] open_ctree+0xb32/0x1734 [btrfs]
    [66.595272] ? bdi_register_va+0x1b/0x20
    [66.614638] ? super_setup_bdi_name+0x79/0xd0
    [66.633809] btrfs_mount_root.cold+0x12/0xeb [btrfs]
    [66.652938] ? __kmalloc_track_caller+0x217/0x3b0
    [66.671925] legacy_get_tree+0x34/0x60
    [66.690300] vfs_get_tree+0x2d/0xc0
    [66.708221] vfs_kern_mount.part.0+0x78/0xc0
    [66.725808] vfs_kern_mount+0x13/0x20
    [66.742730] btrfs_mount+0x11f/0x3c0 [btrfs]
    [66.759350] ? kfree+0x5ff/0x670
    [66.775441] ? __kmalloc_track_caller+0x217/0x3b0
    [66.791750] legacy_get_tree+0x34/0x60
    [66.807494] vfs_get_tree+0x2d/0xc0
    [66.823349] path_mount+0x48c/0xd30
    [66.838753] __x64_sys_mount+0x108/0x140
    [66.854412] do_syscall_64+0x38/0x50
    [66.869673] entry_SYSCALL_64_after_hwframe+0x44/0xa9
    [66.885093] RIP: 0033:0x7f0138827f6e
    [66.945613] RSP: 002b:00007ffecd79edf8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
    [66.977214] RAX: ffffffffffffffda RBX: 00007f013894c264 RCX: 00007f0138827f6e
    [66.994266] RDX: 00005593a4a41360 RSI: 00005593a4a33690 RDI: 00005593a4a3a6c0
    [67.011544] RBP: 00005593a4a33440 R08: 0000000000000000 R09: 0000000000000001
    [67.028836] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
    [67.045812] R13: 00005593a4a3a6c0 R14: 00005593a4a41360 R15: 00005593a4a33440
    [67.216138] ---[ end trace e114b111db64298c ]---
    [67.237089] RIP: 0010:extent_io_tree_panic.isra.0+0x23/0x25 [btrfs]
    [67.325317] RSP: 0018:ffff93e5414c3948 EFLAGS: 00010246
    [67.347946] RAX: 0000000000000000 RBX: 0000000001bfffff RCX: 0000000000000000
    [67.371343] RDX: 0000000000000000 RSI: ffffffffb90d4660 RDI: 00000000ffffffff
    [67.394757] RBP: ffff93e5414c3948 R08: 0000000000000001 R09: 0000000000000001
    [67.418409] R10: ffff93e5414c3658 R11: 0000000000000000 R12: ffff8ec782d728c0
    [67.441906] R13: ffff8ec78bc71628 R14: ffff8ec782d72aa0 R15: 0000000002400000
    [67.465436] FS: 00007f01386a8580(0000) GS:ffff8ec809000000(0000) knlGS:0000000000000000
    [67.511660] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    [67.535047] CR2: 00007f01382fa000 CR3: 0000000109a34000 CR4: 0000000000750ee0
    [67.558449] PKRU: 55555554
    [67.581146] note: mount[613] exited with preempt_count 2

    The image has a chunk item which has a logical start 37748736 and length
    18446744073701163008 (-8M). The calculated end 29360127 overflows.
    EEXIST was caught by insert_state() because of the duplicate end and
    extent_io_tree_panic() was called.

    Add overflow check of chunk item end to tree checker so it can be
    detected early at mount time.

    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=208929
    CC: stable@vger.kernel.org # 4.19+
    Reviewed-by: Anand Jain
    Signed-off-by: Su Yue
    Reviewed-by: David Sterba
    Signed-off-by: David Sterba
    Signed-off-by: Sasha Levin

    Su Yue
     
  • commit cb82a54904a99df9e8f9e9d282046055dae5a730 upstream.

    This USB-C Hub (17ef:721e) based on the Realtek RTL8153B chip used to
    use the cdc_ether driver. However, using this driver, with the system
    suspended the device constantly sends pause-frames as soon as the
    receive buffer fills up. This causes issues with other devices, where
    some Ethernet switches stop forwarding packets altogether.

    Using the Realtek driver (r8152) fixes this issue. Pause frames are no
    longer sent while the host system is suspended.

    Signed-off-by: Leon Schuermann
    Tested-by: Leon Schuermann
    Link: https://lore.kernel.org/r/20210111190312.12589-2-leon@is.currently.online
    Signed-off-by: Jakub Kicinski
    Signed-off-by: Greg Kroah-Hartman

    Leon Schuermann
     
  • commit bff6f1db91e330d7fba56f815cdbc412c75fe163 upstream.

    Set all EHL/TGL phy_addr to -1 so that the driver will automatically
    detect it at run-time by probing all the possible 32 addresses.

    Signed-off-by: Voon Weifeng
    Signed-off-by: Wong Vee Khee
    Link: https://lore.kernel.org/r/20201106094341.4241-1-vee.khee.wong@intel.com
    Signed-off-by: Jakub Kicinski
    Signed-off-by: Greg Kroah-Hartman

    Voon Weifeng
     
  • commit c87a95dc28b1431c7e77e2c0c983cf37698089d2 upstream.

    On some specific hardware on early boot we occasionally get:

    [ 1193.920255][ T0] BUG: sleeping function called from invalid context at mm/mempool.c:381
    [ 1193.936616][ T0] in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 0, name: swapper/69
    [ 1193.953233][ T0] no locks held by swapper/69/0.
    [ 1193.965871][ T0] irq event stamp: 575062
    [ 1193.977724][ T0] hardirqs last enabled at (575061): [] tick_nohz_idle_exit+0xe2/0x3e0
    [ 1194.002762][ T0] hardirqs last disabled at (575062): [] flush_smp_call_function_from_idle+0x4f/0x80
    [ 1194.029035][ T0] softirqs last enabled at (575050): [] asm_call_irq_on_stack+0x12/0x20
    [ 1194.054227][ T0] softirqs last disabled at (575043): [] asm_call_irq_on_stack+0x12/0x20
    [ 1194.079389][ T0] CPU: 69 PID: 0 Comm: swapper/69 Not tainted 5.10.6-cloudflare-kasan-2021.1.4-dev #1
    [ 1194.104103][ T0] Hardware name: NULL R162-Z12-CD/MZ12-HD4-CD, BIOS R10 06/04/2020
    [ 1194.119591][ T0] Call Trace:
    [ 1194.130233][ T0] dump_stack+0x9a/0xcc
    [ 1194.141617][ T0] ___might_sleep.cold+0x180/0x1b0
    [ 1194.153825][ T0] mempool_alloc+0x16b/0x300
    [ 1194.165313][ T0] ? remove_element+0x160/0x160
    [ 1194.176961][ T0] ? blk_mq_end_request+0x4b/0x490
    [ 1194.188778][ T0] crypt_convert+0x27f6/0x45f0 [dm_crypt]
    [ 1194.201024][ T0] ? rcu_read_lock_sched_held+0x3f/0x70
    [ 1194.212906][ T0] ? module_assert_mutex_or_preempt+0x3e/0x70
    [ 1194.225318][ T0] ? __module_address.part.0+0x1b/0x3a0
    [ 1194.237212][ T0] ? is_kernel_percpu_address+0x5b/0x190
    [ 1194.249238][ T0] ? crypt_iv_tcw_ctr+0x4a0/0x4a0 [dm_crypt]
    [ 1194.261593][ T0] ? is_module_address+0x25/0x40
    [ 1194.272905][ T0] ? static_obj+0x8a/0xc0
    [ 1194.283582][ T0] ? lockdep_init_map_waits+0x26a/0x700
    [ 1194.295570][ T0] ? __raw_spin_lock_init+0x39/0x110
    [ 1194.307330][ T0] kcryptd_crypt_read_convert+0x31c/0x560 [dm_crypt]
    [ 1194.320496][ T0] ? kcryptd_queue_crypt+0x1be/0x380 [dm_crypt]
    [ 1194.333203][ T0] blk_update_request+0x6d7/0x1500
    [ 1194.344841][ T0] ? blk_mq_trigger_softirq+0x190/0x190
    [ 1194.356831][ T0] blk_mq_end_request+0x4b/0x490
    [ 1194.367994][ T0] ? blk_mq_trigger_softirq+0x190/0x190
    [ 1194.379693][ T0] flush_smp_call_function_queue+0x24b/0x560
    [ 1194.391847][ T0] flush_smp_call_function_from_idle+0x59/0x80
    [ 1194.403969][ T0] do_idle+0x287/0x450
    [ 1194.413891][ T0] ? arch_cpu_idle_exit+0x40/0x40
    [ 1194.424716][ T0] ? lockdep_hardirqs_on_prepare+0x286/0x3f0
    [ 1194.436399][ T0] ? _raw_spin_unlock_irqrestore+0x39/0x40
    [ 1194.447759][ T0] cpu_startup_entry+0x19/0x20
    [ 1194.458038][ T0] secondary_startup_64_no_verify+0xb0/0xbb

    IO completion can be queued to a different CPU by the block subsystem as a "call
    single function/data". The CPU may run these routines from the idle task, but it
    does so with interrupts disabled.

    It is not a good idea to do decryption with irqs disabled even in an idle task
    context, so just defer it to a tasklet (as is done with requests from hard irqs).

    Fixes: 39d42fa96ba1 ("dm crypt: add flags to optionally bypass kcryptd workqueues")
    Cc: stable@vger.kernel.org # v5.9+
    Signed-off-by: Ignat Korchagin
    Signed-off-by: Mike Snitzer
    Signed-off-by: Greg Kroah-Hartman

    Ignat Korchagin
     
  • commit 8e14f610159d524cd7aac37982826d3ef75c09e8 upstream.

    Sometimes, when dm-crypt executes decryption in a tasklet, we may get
    "BUG: KASAN: use-after-free in tasklet_action_common.constprop..."
    with a kasan-enabled kernel.

    When the decryption fully completes in the tasklet, dm-crypt will call
    bio_endio(), which in turn will call clone_endio() from dm.c core code. That
    function frees the resources associated with the bio, including per bio private
    structures. For dm-crypt it will free the current struct dm_crypt_io, which
    contains our tasklet object, causing use-after-free, when the tasklet is being
    dequeued by the kernel.

    To avoid this, do not call bio_endio() from the current tasklet context, but
    delay its execution to the dm-crypt IO workqueue.

    Fixes: 39d42fa96ba1 ("dm crypt: add flags to optionally bypass kcryptd workqueues")
    Cc: # v5.9+
    Signed-off-by: Ignat Korchagin
    Signed-off-by: Mike Snitzer
    Signed-off-by: Greg Kroah-Hartman

    Ignat Korchagin
     
  • commit 8abec36d1274bbd5ae8f36f3658b9abb3db56c31 upstream.

    Commit 39d42fa96ba1 ("dm crypt: add flags to optionally bypass kcryptd
    workqueues") made it possible for some code paths in dm-crypt to be
    executed in softirq context, when the underlying driver processes IO
    requests in interrupt/softirq context.

    When Crypto API backlogs a crypto request, dm-crypt uses
    wait_for_completion to avoid sending further requests to an already
    overloaded crypto driver. However, if the code is executing in softirq
    context, we might get the following stacktrace:

    [ 210.235213][ C0] BUG: scheduling while atomic: fio/2602/0x00000102
    [ 210.236701][ C0] Modules linked in:
    [ 210.237566][ C0] CPU: 0 PID: 2602 Comm: fio Tainted: G W 5.10.0+ #50
    [ 210.239292][ C0] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015
    [ 210.241233][ C0] Call Trace:
    [ 210.241946][ C0]
    [ 210.242561][ C0] dump_stack+0x7d/0xa3
    [ 210.243466][ C0] __schedule_bug.cold+0xb3/0xc2
    [ 210.244539][ C0] __schedule+0x156f/0x20d0
    [ 210.245518][ C0] ? io_schedule_timeout+0x140/0x140
    [ 210.246660][ C0] schedule+0xd0/0x270
    [ 210.247541][ C0] schedule_timeout+0x1fb/0x280
    [ 210.248586][ C0] ? usleep_range+0x150/0x150
    [ 210.249624][ C0] ? unpoison_range+0x3a/0x60
    [ 210.250632][ C0] ? ____kasan_kmalloc.constprop.0+0x82/0xa0
    [ 210.251949][ C0] ? unpoison_range+0x3a/0x60
    [ 210.252958][ C0] ? __prepare_to_swait+0xa7/0x190
    [ 210.254067][ C0] do_wait_for_common+0x2ab/0x370
    [ 210.255158][ C0] ? usleep_range+0x150/0x150
    [ 210.256192][ C0] ? bit_wait_io_timeout+0x160/0x160
    [ 210.257358][ C0] ? blk_update_request+0x757/0x1150
    [ 210.258582][ C0] ? _raw_spin_lock_irq+0x82/0xd0
    [ 210.259674][ C0] ? _raw_read_unlock_irqrestore+0x30/0x30
    [ 210.260917][ C0] wait_for_completion+0x4c/0x90
    [ 210.261971][ C0] crypt_convert+0x19a6/0x4c00
    [ 210.263033][ C0] ? _raw_spin_lock_irqsave+0x87/0xe0
    [ 210.264193][ C0] ? kasan_set_track+0x1c/0x30
    [ 210.265191][ C0] ? crypt_iv_tcw_ctr+0x4a0/0x4a0
    [ 210.266283][ C0] ? kmem_cache_free+0x104/0x470
    [ 210.267363][ C0] ? crypt_endio+0x91/0x180
    [ 210.268327][ C0] kcryptd_crypt_read_convert+0x30e/0x420
    [ 210.269565][ C0] blk_update_request+0x757/0x1150
    [ 210.270563][ C0] blk_mq_end_request+0x4b/0x480
    [ 210.271680][ C0] blk_done_softirq+0x21d/0x340
    [ 210.272775][ C0] ? _raw_spin_lock+0x81/0xd0
    [ 210.273847][ C0] ? blk_mq_stop_hw_queue+0x30/0x30
    [ 210.275031][ C0] ? _raw_read_lock_irq+0x40/0x40
    [ 210.276182][ C0] __do_softirq+0x190/0x611
    [ 210.277203][ C0] ? handle_edge_irq+0x221/0xb60
    [ 210.278340][ C0] asm_call_irq_on_stack+0x12/0x20
    [ 210.279514][ C0]
    [ 210.280164][ C0] do_softirq_own_stack+0x37/0x40
    [ 210.281281][ C0] irq_exit_rcu+0x110/0x1b0
    [ 210.282286][ C0] common_interrupt+0x74/0x120
    [ 210.283376][ C0] asm_common_interrupt+0x1e/0x40
    [ 210.284496][ C0] RIP: 0010:_aesni_enc1+0x65/0xb0

    Fix this by making crypt_convert function reentrant from the point of
    a single bio and make dm-crypt defer further bio processing to a
    workqueue, if Crypto API backlogs a request in interrupt context.

    Fixes: 39d42fa96ba1 ("dm crypt: add flags to optionally bypass kcryptd workqueues")
    Cc: stable@vger.kernel.org # v5.9+
    Signed-off-by: Ignat Korchagin
    Acked-by: Mikulas Patocka
    Signed-off-by: Mike Snitzer
    Signed-off-by: Greg Kroah-Hartman

    Ignat Korchagin
     
  • commit d68b29584c25dbacd01ed44a3e45abb35353f1de upstream.

    Commit 39d42fa96ba1 ("dm crypt: add flags to optionally bypass kcryptd
    workqueues") made it possible for some code paths in dm-crypt to be
    executed in softirq context, when the underlying driver processes IO
    requests in interrupt/softirq context.

    In this case sometimes when allocating a new crypto request we may get
    a stacktrace like below:

    [ 210.103008][ C0] BUG: sleeping function called from invalid context at mm/mempool.c:381
    [ 210.104746][ C0] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 2602, name: fio
    [ 210.106599][ C0] CPU: 0 PID: 2602 Comm: fio Tainted: G W 5.10.0+ #50
    [ 210.108331][ C0] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015
    [ 210.110212][ C0] Call Trace:
    [ 210.110921][ C0]
    [ 210.111527][ C0] dump_stack+0x7d/0xa3
    [ 210.112411][ C0] ___might_sleep.cold+0x122/0x151
    [ 210.113527][ C0] mempool_alloc+0x16b/0x2f0
    [ 210.114524][ C0] ? __queue_work+0x515/0xde0
    [ 210.115553][ C0] ? mempool_resize+0x700/0x700
    [ 210.116586][ C0] ? crypt_endio+0x91/0x180
    [ 210.117479][ C0] ? blk_update_request+0x757/0x1150
    [ 210.118513][ C0] ? blk_mq_end_request+0x4b/0x480
    [ 210.119572][ C0] ? blk_done_softirq+0x21d/0x340
    [ 210.120628][ C0] ? __do_softirq+0x190/0x611
    [ 210.121626][ C0] crypt_convert+0x29f9/0x4c00
    [ 210.122668][ C0] ? _raw_spin_lock_irqsave+0x87/0xe0
    [ 210.123824][ C0] ? kasan_set_track+0x1c/0x30
    [ 210.124858][ C0] ? crypt_iv_tcw_ctr+0x4a0/0x4a0
    [ 210.125930][ C0] ? kmem_cache_free+0x104/0x470
    [ 210.126973][ C0] ? crypt_endio+0x91/0x180
    [ 210.127947][ C0] kcryptd_crypt_read_convert+0x30e/0x420
    [ 210.129165][ C0] blk_update_request+0x757/0x1150
    [ 210.130231][ C0] blk_mq_end_request+0x4b/0x480
    [ 210.131294][ C0] blk_done_softirq+0x21d/0x340
    [ 210.132332][ C0] ? _raw_spin_lock+0x81/0xd0
    [ 210.133289][ C0] ? blk_mq_stop_hw_queue+0x30/0x30
    [ 210.134399][ C0] ? _raw_read_lock_irq+0x40/0x40
    [ 210.135458][ C0] __do_softirq+0x190/0x611
    [ 210.136409][ C0] ? handle_edge_irq+0x221/0xb60
    [ 210.137447][ C0] asm_call_irq_on_stack+0x12/0x20
    [ 210.138507][ C0]
    [ 210.139118][ C0] do_softirq_own_stack+0x37/0x40
    [ 210.140191][ C0] irq_exit_rcu+0x110/0x1b0
    [ 210.141151][ C0] common_interrupt+0x74/0x120
    [ 210.142171][ C0] asm_common_interrupt+0x1e/0x40

    Fix this by allocating crypto requests with GFP_ATOMIC mask in
    interrupt context.

    Fixes: 39d42fa96ba1 ("dm crypt: add flags to optionally bypass kcryptd workqueues")
    Cc: stable@vger.kernel.org # v5.9+
    Reported-by: Maciej S. Szmigiero
    Signed-off-by: Ignat Korchagin
    Acked-by: Mikulas Patocka
    Signed-off-by: Mike Snitzer
    Signed-off-by: Greg Kroah-Hartman

    Ignat Korchagin
     
  • commit 17ffc193cdc6dc7a613d00d8ad47fc1f801b9bf0 upstream.

    Advance the maximum number of arguments from 9 to 15 to account for
    all potential feature flags that may be supplied.

    Linux 4.19 added "meta_device"
    (356d9d52e1221ba0c9f10b8b38652f78a5298329) and "recalculate"
    (a3fcf7253139609bf9ff901fbf955fba047e75dd) flags.

    Commit 468dfca38b1a6fbdccd195d875599cb7c8875cd9 added
    "sectors_per_bit" and "bitmap_flush_interval".

    Commit 84597a44a9d86ac949900441cea7da0af0f2f473 added
    "allow_discards".

    And the commit d537858ac8aaf4311b51240893add2fc62003b97 added
    "fix_padding".

    Signed-off-by: Mikulas Patocka
    Cc: stable@vger.kernel.org # v4.19+
    Signed-off-by: Mike Snitzer
    Signed-off-by: Greg Kroah-Hartman

    Mikulas Patocka
     
  • commit 9b5948267adc9e689da609eb61cf7ed49cae5fa8 upstream.

    With external metadata device, flush requests are not passed down to the
    data device.

    Fix this by submitting the flush request in dm_integrity_flush_buffers. In
    order to not degrade performance, we overlap the data device flush with
    the metadata device flush.

    Reported-by: Lukas Straub
    Signed-off-by: Mikulas Patocka
    Cc: stable@vger.kernel.org
    Signed-off-by: Mike Snitzer
    Signed-off-by: Greg Kroah-Hartman

    Mikulas Patocka
     
  • commit fcc42338375a1e67b8568dbb558f8b784d0f3b01 upstream.

    If the origin device has a volatile write-back cache and the following
    events occur:

    1: After finishing merge operation of one set of exceptions,
    merge_callback() is invoked.
    2: Update the metadata in COW device tracking the merge completion.
    This update to COW device is flushed cleanly.
    3: System crashes and the origin device's cache where the recent
    merge was completed has not been flushed.

    During the next cycle when we read the metadata from the COW device,
    we will skip reading those metadata whose merge was completed in
    step (1). This will lead to data loss/corruption.

    To address this, flush the origin device post merge IO before
    updating the metadata.

    Cc: stable@vger.kernel.org
    Signed-off-by: Akilesh Kailash
    Signed-off-by: Mike Snitzer
    Signed-off-by: Greg Kroah-Hartman

    Akilesh Kailash
     
  • commit cc07d72bf350b77faeffee1c37bc52197171473f upstream.

    Block core warned that discard_granularity was 0 for dm-raid with
    personality of raid1. Reason is that raid_io_hints() was incorrectly
    special-casing raid1 rather than raid0.

    Fix raid_io_hints() by removing discard limits settings for
    raid1. Check for raid0 instead.

    Fixes: 61697a6abd24a ("dm: eliminate 'split_discard_bios' flag from DM target interface")
    Cc: stable@vger.kernel.org
    Reported-by: Zdenek Kabelac
    Reported-by: Mikulas Patocka
    Reported-by: Stephan Bärwolf
    Signed-off-by: Mike Snitzer
    Signed-off-by: Greg Kroah-Hartman

    Mike Snitzer
     
  • commit eb351d75ce1e75b4f793d609efac08426ca50acd upstream.

    Fix the build error:

    mm/process_vm_access.c:277:5: error: implicit declaration of function 'in_compat_syscall'; did you mean 'in_ia32_syscall'? [-Werror=implicit-function-declaration]

    Fixes: 38dc5079da7081e "Fix compat regression in process_vm_rw()"
    Reported-by: syzbot+5b0d0de84d6c65b8dd2b@syzkaller.appspotmail.com
    Cc: Kyle Huey
    Cc: Jens Axboe
    Cc: Al Viro
    Cc: Christoph Hellwig
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Andrew Morton
     
  • commit 0eb98f1588c2cc7a79816d84ab18a55d254f481c upstream.

    The huge page size is encoded for VM_FAULT_HWPOISON errors only. So if
    we return VM_FAULT_HWPOISON, huge page size would just be ignored.

    Link: https://lkml.kernel.org/r/20210107123449.38481-1-linmiaohe@huawei.com
    Fixes: aa50d3a7aa81 ("Encode huge page size for VM_FAULT_HWPOISON errors")
    Signed-off-by: Miaohe Lin
    Reviewed-by: Mike Kravetz
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Miaohe Lin
     
  • commit c22ee5284cf58017fa8c6d21d8f8c68159b6faab upstream.

    In VM_MAP_PUT_PAGES case, we should put pages and free array in vfree.
    But we missed to set area->nr_pages in vmap(). So we would fail to put
    pages in __vunmap() because area->nr_pages = 0.

    Link: https://lkml.kernel.org/r/20210107123541.39206-1-linmiaohe@huawei.com
    Fixes: b944afc9d64d ("mm: add a VM_MAP_PUT_PAGES flag for vmap")
    Signed-off-by: Shijie Luo
    Signed-off-by: Miaohe Lin
    Reviewed-by: Uladzislau Rezki (Sony)
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Miaohe Lin