commit 4143d798313fffa39f05bf24dd560ace42225c26
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Wed Jan 6 14:45:02 2021 +0100

    Linux 4.19.165
    
    Tested-by: Pavel Machek (CIP) <pavel@denx.de>
    Tested-by: Jon Hunter <jonathanh@nvidia.com>
    Tested-by: Guenter Roeck <linux@roeck-us.net>
    Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
    Tested-by: Shuah Khan <skhan@linuxfoundation.org>
    Link: https://lore.kernel.org/r/20210105090818.518271884@linuxfoundation.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 63d881957e59dde38f38100631ae138d5c0cee88
Author: Hyeongseok Kim <hyeongseok@gmail.com>
Date:   Thu Dec 3 09:46:59 2020 +0900

    dm verity: skip verity work if I/O error when system is shutting down
    
    [ Upstream commit 252bd1256396cebc6fc3526127fdb0b317601318 ]
    
    If emergency system shutdown is called, like by thermal shutdown,
    a dm device could be alive when the block device couldn't process
    I/O requests anymore. In this state, the handling of I/O errors
    by new dm I/O requests or by those already in-flight can lead to
    a verity corruption state, which is a misjudgment.
    
    So, skip verity work in response to I/O error when system is shutting
    down.
    
    Signed-off-by: Hyeongseok Kim <hyeongseok@gmail.com>
    Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
    Signed-off-by: Mike Snitzer <snitzer@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 5ec9c5d260adc6d6b599aa4df5358f6ad25c3fcc
Author: Takashi Iwai <tiwai@suse.de>
Date:   Fri Dec 18 15:56:25 2020 +0100

    ALSA: pcm: Clear the full allocated memory at hw_params
    
    [ Upstream commit 618de0f4ef11acd8cf26902e65493d46cc20cc89 ]
    
    The PCM hw_params core function tries to clear up the PCM buffer
    before actually using for avoiding the information leak from the
    previous usages or the usage before a new allocation.  It performs the
    memset() with runtime->dma_bytes, but this might still leave some
    remaining bytes untouched; namely, the PCM buffer size is aligned in
    page size for mmap, hence runtime->dma_bytes doesn't necessarily cover
    all PCM buffer pages, and the remaining bytes are exposed via mmap.
    
    This patch changes the memory clearance to cover the all buffer pages
    if the stream is supposed to be mmap-ready (that guarantees that the
    buffer size is aligned in page size).
    
    Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
    Link: https://lore.kernel.org/r/20201218145625.2045-3-tiwai@suse.de
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 74925430503eccee4ddf20f3b46a580ca6a72bab
Author: Jessica Yu <jeyu@kernel.org>
Date:   Fri Nov 27 10:09:39 2020 +0100

    module: delay kobject uevent until after module init call
    
    [ Upstream commit 38dc717e97153e46375ee21797aa54777e5498f3 ]
    
    Apparently there has been a longstanding race between udev/systemd and
    the module loader. Currently, the module loader sends a uevent right
    after sysfs initialization, but before the module calls its init
    function. However, some udev rules expect that the module has
    initialized already upon receiving the uevent.
    
    This race has been triggered recently (see link in references) in some
    systemd mount unit files. For instance, the configfs module creates the
    /sys/kernel/config mount point in its init function, however the module
    loader issues the uevent before this happens. sys-kernel-config.mount
    expects to be able to mount /sys/kernel/config upon receipt of the
    module loading uevent, but if the configfs module has not called its
    init function yet, then this directory will not exist and the mount unit
    fails. A similar situation exists for sys-fs-fuse-connections.mount, as
    the fuse sysfs mount point is created during the fuse module's init
    function. If udev is faster than module initialization then the mount
    unit would fail in a similar fashion.
    
    To fix this race, delay the module KOBJ_ADD uevent until after the
    module has finished calling its init routine.
    
    References: https://github.com/systemd/systemd/issues/17586
    Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Tested-By: Nicolas Morey-Chaisemartin <nmoreychaisemartin@suse.com>
    Signed-off-by: Jessica Yu <jeyu@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 05a0aec6787885a335a9d3cec7e1cfffee253b84
Author: Trond Myklebust <trond.myklebust@hammerspace.com>
Date:   Wed Nov 25 12:06:14 2020 -0500

    NFSv4: Fix a pNFS layout related use-after-free race when freeing the inode
    
    [ Upstream commit b6d49ecd1081740b6e632366428b960461f8158b ]
    
    When returning the layout in nfs4_evict_inode(), we need to ensure that
    the layout is actually done being freed before we can proceed to free the
    inode itself.
    
    Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit f2dc273475894b50841647c1ee180834c2836c9e
Author: Qinglang Miao <miaoqinglang@huawei.com>
Date:   Wed Oct 28 17:15:51 2020 +0800

    powerpc: sysdev: add missing iounmap() on error in mpic_msgr_probe()
    
    [ Upstream commit ffa1797040c5da391859a9556be7b735acbe1242 ]
    
    I noticed that iounmap() of msgr_block_addr before return from
    mpic_msgr_probe() in the error handling case is missing. So use
    devm_ioremap() instead of just ioremap() when remapping the message
    register block, so the mapping will be automatically released on
    probe failure.
    
    Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://lore.kernel.org/r/20201028091551.136400-1-miaoqinglang@huawei.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 75f1bd7955f17cf15412165d25f03df7d659568e
Author: Jan Kara <jack@suse.cz>
Date:   Mon Nov 2 16:32:10 2020 +0100

    quota: Don't overflow quota file offsets
    
    [ Upstream commit 10f04d40a9fa29785206c619f80d8beedb778837 ]
    
    The on-disk quota format supports quota files with upto 2^32 blocks. Be
    careful when computing quota file offsets in the quota files from block
    numbers as they can overflow 32-bit types. Since quota files larger than
    4GB would require ~26 millions of quota users, this is mostly a
    theoretical concern now but better be careful, fuzzers would find the
    problem sooner or later anyway...
    
    Reviewed-by: Andreas Dilger <adilger@dilger.ca>
    Signed-off-by: Jan Kara <jack@suse.cz>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit bea7f4d1ffa33ced2801947eb70e400387b07575
Author: Miroslav Benes <mbenes@suse.cz>
Date:   Tue Oct 27 15:03:36 2020 +0100

    module: set MODULE_STATE_GOING state when a module fails to load
    
    [ Upstream commit 5e8ed280dab9eeabc1ba0b2db5dbe9fe6debb6b5 ]
    
    If a module fails to load due to an error in prepare_coming_module(),
    the following error handling in load_module() runs with
    MODULE_STATE_COMING in module's state. Fix it by correctly setting
    MODULE_STATE_GOING under "bug_cleanup" label.
    
    Signed-off-by: Miroslav Benes <mbenes@suse.cz>
    Signed-off-by: Jessica Yu <jeyu@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 4cb33d97b067682e4e3c398a57426e4c7e493a3d
Author: Dinghao Liu <dinghao.liu@zju.edu.cn>
Date:   Tue Oct 20 14:12:26 2020 +0800

    rtc: sun6i: Fix memleak in sun6i_rtc_clk_init
    
    [ Upstream commit 28d211919e422f58c1e6c900e5810eee4f1ce4c8 ]
    
    When clk_hw_register_fixed_rate_with_accuracy() fails,
    clk_data should be freed. It's the same for the subsequent
    two error paths, but we should also unregister the already
    registered clocks in them.
    
    Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
    Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
    Link: https://lore.kernel.org/r/20201020061226.6572-1-dinghao.liu@zju.edu.cn
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 8e63266b0d42a2dc233cfc468636889b5b3ba1cf
Author: Boqun Feng <boqun.feng@gmail.com>
Date:   Thu Nov 5 14:23:51 2020 +0800

    fcntl: Fix potential deadlock in send_sig{io, urg}()
    
    commit 8d1ddb5e79374fb277985a6b3faa2ed8631c5b4c upstream.
    
    Syzbot reports a potential deadlock found by the newly added recursive
    read deadlock detection in lockdep:
    
    [...] ========================================================
    [...] WARNING: possible irq lock inversion dependency detected
    [...] 5.9.0-rc2-syzkaller #0 Not tainted
    [...] --------------------------------------------------------
    [...] syz-executor.1/10214 just changed the state of lock:
    [...] ffff88811f506338 (&f->f_owner.lock){.+..}-{2:2}, at: send_sigurg+0x1d/0x200
    [...] but this lock was taken by another, HARDIRQ-safe lock in the past:
    [...]  (&dev->event_lock){-...}-{2:2}
    [...]
    [...]
    [...] and interrupts could create inverse lock ordering between them.
    [...]
    [...]
    [...] other info that might help us debug this:
    [...] Chain exists of:
    [...]   &dev->event_lock --> &new->fa_lock --> &f->f_owner.lock
    [...]
    [...]  Possible interrupt unsafe locking scenario:
    [...]
    [...]        CPU0                    CPU1
    [...]        ----                    ----
    [...]   lock(&f->f_owner.lock);
    [...]                                local_irq_disable();
    [...]                                lock(&dev->event_lock);
    [...]                                lock(&new->fa_lock);
    [...]   <Interrupt>
    [...]     lock(&dev->event_lock);
    [...]
    [...]  *** DEADLOCK ***
    
    The corresponding deadlock case is as followed:
    
            CPU 0           CPU 1           CPU 2
            read_lock(&fown->lock);
                            spin_lock_irqsave(&dev->event_lock, ...)
                                            write_lock_irq(&filp->f_owner.lock); // wait for the lock
                            read_lock(&fown-lock); // have to wait until the writer release
                                                   // due to the fairness
            <interrupted>
            spin_lock_irqsave(&dev->event_lock); // wait for the lock
    
    The lock dependency on CPU 1 happens if there exists a call sequence:
    
            input_inject_event():
              spin_lock_irqsave(&dev->event_lock,...);
              input_handle_event():
                input_pass_values():
                  input_to_handler():
                    handler->event(): // evdev_event()
                      evdev_pass_values():
                        spin_lock(&client->buffer_lock);
                        __pass_event():
                          kill_fasync():
                            kill_fasync_rcu():
                              read_lock(&fa->fa_lock);
                              send_sigio():
                                read_lock(&fown->lock);
    
    To fix this, make the reader in send_sigurg() and send_sigio() use
    read_lock_irqsave() and read_lock_irqrestore().
    
    Reported-by: syzbot+22e87cdf94021b984aa6@syzkaller.appspotmail.com
    Reported-by: syzbot+c5e32344981ad9f33750@syzkaller.appspotmail.com
    Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
    Signed-off-by: Jeff Layton <jlayton@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 64b2a977e116835dbe184a2f44d90b61c84fb5e8
Author: Takashi Iwai <tiwai@suse.de>
Date:   Sun Dec 6 09:35:27 2020 +0100

    ALSA: rawmidi: Access runtime->avail always in spinlock
    
    commit 88a06d6fd6b369d88cec46c62db3e2604a2f50d5 upstream.
    
    The runtime->avail field may be accessed concurrently while some
    places refer to it without taking the runtime->lock spinlock, as
    detected by KCSAN.  Usually this isn't a big problem, but for
    consistency and safety, we should take the spinlock at each place
    referencing this field.
    
    Reported-by: syzbot+a23a6f1215c84756577c@syzkaller.appspotmail.com
    Reported-by: syzbot+3d367d1df1d2b67f5c19@syzkaller.appspotmail.com
    Link: https://lore.kernel.org/r/20201206083527.21163-1-tiwai@suse.de
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 2c8ccc3052d83f84729b0173863677ce4066d151
Author: Takashi Iwai <tiwai@suse.de>
Date:   Sun Dec 6 09:34:56 2020 +0100

    ALSA: seq: Use bool for snd_seq_queue internal flags
    
    commit 4ebd47037027c4beae99680bff3b20fdee5d7c1e upstream.
    
    The snd_seq_queue struct contains various flags in the bit fields.
    Those are categorized to two different use cases, both of which are
    protected by different spinlocks.  That implies that there are still
    potential risks of the bad operations for bit fields by concurrent
    accesses.
    
    For addressing the problem, this patch rearranges those flags to be
    a standard bool instead of a bit field.
    
    Reported-by: syzbot+63cbe31877bb80ef58f5@syzkaller.appspotmail.com
    Link: https://lore.kernel.org/r/20201206083456.21110-1-tiwai@suse.de
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit fd4f2a5151e6c6294169d983303c485beade5b37
Author: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Date:   Fri Nov 27 07:40:21 2020 +0100

    media: gp8psk: initialize stats at power control logic
    
    commit d0ac1a26ed5943127cb0156148735f5f52a07075 upstream.
    
    As reported on:
            https://lore.kernel.org/linux-media/20190627222020.45909-1-willemdebruijn.kernel@gmail.com/
    
    if gp8psk_usb_in_op() returns an error, the status var is not
    initialized. Yet, this var is used later on, in order to
    identify:
            - if the device was already started;
            - if firmware has loaded;
            - if the LNBf was powered on.
    
    Using status = 0 seems to ensure that everything will be
    properly powered up.
    
    So, instead of the proposed solution, let's just set
    status = 0.
    
    Reported-by: syzbot <syzkaller@googlegroups.com>
    Reported-by: Willem de Bruijn <willemb@google.com>
    Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 074b61ff2127ed1e408f39783b32d1936d6aa3ac
Author: Anant Thazhemadam <anant.thazhemadam@gmail.com>
Date:   Mon Nov 23 04:15:34 2020 +0530

    misc: vmw_vmci: fix kernel info-leak by initializing dbells in vmci_ctx_get_chkpt_doorbells()
    
    commit 31dcb6c30a26d32650ce134820f27de3c675a45a upstream.
    
    A kernel-infoleak was reported by syzbot, which was caused because
    dbells was left uninitialized.
    Using kzalloc() instead of kmalloc() fixes this issue.
    
    Reported-by: syzbot+a79e17c39564bedf0930@syzkaller.appspotmail.com
    Tested-by: syzbot+a79e17c39564bedf0930@syzkaller.appspotmail.com
    Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
    Link: https://lore.kernel.org/r/20201122224534.333471-1-anant.thazhemadam@gmail.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit b8590c82b3ccf9fb4d9f0b0b097be10736869333
Author: Rustam Kovhaev <rkovhaev@gmail.com>
Date:   Sun Nov 1 06:09:58 2020 -0800

    reiserfs: add check for an invalid ih_entry_count
    
    commit d24396c5290ba8ab04ba505176874c4e04a2d53c upstream.
    
    when directory item has an invalid value set for ih_entry_count it might
    trigger use-after-free or out-of-bounds read in bin_search_in_dir_item()
    
    ih_entry_count * IH_SIZE for directory item should not be larger than
    ih_item_len
    
    Link: https://lore.kernel.org/r/20201101140958.3650143-1-rkovhaev@gmail.com
    Reported-and-tested-by: syzbot+83b6f7cf9922cae5c4d7@syzkaller.appspotmail.com
    Link: https://syzkaller.appspot.com/bug?extid=83b6f7cf9922cae5c4d7
    Signed-off-by: Rustam Kovhaev <rkovhaev@gmail.com>
    Signed-off-by: Jan Kara <jack@suse.cz>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 88520a207121c3f7c513ac69a7392da89ed0955f
Author: Anant Thazhemadam <anant.thazhemadam@gmail.com>
Date:   Wed Sep 30 00:28:15 2020 +0530

    Bluetooth: hci_h5: close serdev device and free hu in h5_close
    
    commit 70f259a3f4276b71db365b1d6ff1eab805ea6ec3 upstream.
    
    When h5_close() gets called, the memory allocated for the hu gets
    freed only if hu->serdev doesn't exist. This leads to a memory leak.
    So when h5_close() is requested, close the serdev device instance and
    free the memory allocated to the hu entirely instead.
    
    Fixes: https://syzkaller.appspot.com/bug?extid=6ce141c55b2f7aafd1c4
    Reported-by: syzbot+6ce141c55b2f7aafd1c4@syzkaller.appspotmail.com
    Tested-by: syzbot+6ce141c55b2f7aafd1c4@syzkaller.appspotmail.com
    Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
    Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 2f6668bfe30a952f29f12499ad5c038cb1f6653c
Author: Johan Hovold <johan@kernel.org>
Date:   Mon Nov 23 11:23:12 2020 +0100

    of: fix linker-section match-table corruption
    
    commit 5812b32e01c6d86ba7a84110702b46d8a8531fe9 upstream.
    
    Specify type alignment when declaring linker-section match-table entries
    to prevent gcc from increasing alignment and corrupting the various
    tables with padding (e.g. timers, irqchips, clocks, reserved memory).
    
    This is specifically needed on x86 where gcc (typically) aligns larger
    objects like struct of_device_id with static extent on 32-byte
    boundaries which at best prevents matching on anything but the first
    entry. Specifying alignment when declaring variables suppresses this
    optimisation.
    
    Here's a 64-bit example where all entries are corrupt as 16 bytes of
    padding has been inserted before the first entry:
    
            ffffffff8266b4b0 D __clk_of_table
            ffffffff8266b4c0 d __of_table_fixed_factor_clk
            ffffffff8266b5a0 d __of_table_fixed_clk
            ffffffff8266b680 d __clk_of_table_sentinel
    
    And here's a 32-bit example where the 8-byte-aligned table happens to be
    placed on a 32-byte boundary so that all but the first entry are corrupt
    due to the 28 bytes of padding inserted between entries:
    
            812b3ec0 D __irqchip_of_table
            812b3ec0 d __of_table_irqchip1
            812b3fa0 d __of_table_irqchip2
            812b4080 d __of_table_irqchip3
            812b4160 d irqchip_of_match_end
    
    Verified on x86 using gcc-9.3 and gcc-4.9 (which uses 64-byte
    alignment), and on arm using gcc-7.2.
    
    Note that there are no in-tree users of these tables on x86 currently
    (even if they are included in the image).
    
    Fixes: 54196ccbe0ba ("of: consolidate linker section OF match table declarations")
    Fixes: f6e916b82022 ("irqchip: add basic infrastructure")
    Cc: stable <stable@vger.kernel.org>     # 3.9
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Link: https://lore.kernel.org/r/20201123102319.8090-2-johan@kernel.org
    [ johan: adjust context to 5.4 ]
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 1344c5564d84ce01fdf844a6c77fa4be92b8039a
Author: Damien Le Moal <damien.lemoal@wdc.com>
Date:   Fri Nov 20 10:55:11 2020 +0900

    null_blk: Fix zone size initialization
    
    commit 0ebcdd702f49aeb0ad2e2d894f8c124a0acc6e23 upstream.
    
    For a null_blk device with zoned mode enabled is currently initialized
    with a number of zones equal to the device capacity divided by the zone
    size, without considering if the device capacity is a multiple of the
    zone size. If the zone size is not a divisor of the capacity, the zones
    end up not covering the entire capacity, potentially resulting is out
    of bounds accesses to the zone array.
    
    Fix this by adding one last smaller zone with a size equal to the
    remainder of the disk capacity divided by the zone size if the capacity
    is not a multiple of the zone size. For such smaller last zone, the zone
    capacity is also checked so that it does not exceed the smaller zone
    size.
    
    Reported-by: Naohiro Aota <naohiro.aota@wdc.com>
    Fixes: ca4b2a011948 ("null_blk: add zone support")
    Cc: stable@vger.kernel.org
    Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit e622fafb4a80d3477ef22961e513bdfc79fa1687
Author: Souptick Joarder <jrdr.linux@gmail.com>
Date:   Sun Sep 6 12:21:53 2020 +0530

    xen/gntdev.c: Mark pages as dirty
    
    commit 779055842da5b2e508f3ccf9a8153cb1f704f566 upstream.
    
    There seems to be a bug in the original code when gntdev_get_page()
    is called with writeable=true then the page needs to be marked dirty
    before being put.
    
    To address this, a bool writeable is added in gnt_dev_copy_batch, set
    it in gntdev_grant_copy_seg() (and drop `writeable` argument to
    gntdev_get_page()) and then, based on batch->writeable, use
    set_page_dirty_lock().
    
    Fixes: a4cdb556cae0 (xen/gntdev: add ioctl for grant copy)
    Suggested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
    Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
    Cc: John Hubbard <jhubbard@nvidia.com>
    Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
    Cc: Juergen Gross <jgross@suse.com>
    Cc: David Vrabel <david.vrabel@citrix.com>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/1599375114-32360-1-git-send-email-jrdr.linux@gmail.com
    Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
    Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
    [jinoh: backport accounting for missing
      commit 73b0140bf0fe ("mm/gup: change GUP fast to use flags rather than a write 'bool'")]
    Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 663fdcecced4c63b4ae1018db4927df198b19865
Author: Christophe Leroy <christophe.leroy@csgroup.eu>
Date:   Thu Oct 22 14:05:46 2020 +0000

    powerpc/bitops: Fix possible undefined behaviour with fls() and fls64()
    
    [ Upstream commit 1891ef21d92c4801ea082ee8ed478e304ddc6749 ]
    
    fls() and fls64() are using __builtin_ctz() and _builtin_ctzll().
    On powerpc, those builtins trivially use ctlzw and ctlzd power
    instructions.
    
    Allthough those instructions provide the expected result with
    input argument 0, __builtin_ctz() and __builtin_ctzll() are
    documented as undefined for value 0.
    
    The easiest fix would be to use fls() and fls64() functions
    defined in include/asm-generic/bitops/builtin-fls.h and
    include/asm-generic/bitops/fls64.h, but GCC output is not optimal:
    
    00000388 <testfls>:
     388:   2c 03 00 00     cmpwi   r3,0
     38c:   41 82 00 10     beq     39c <testfls+0x14>
     390:   7c 63 00 34     cntlzw  r3,r3
     394:   20 63 00 20     subfic  r3,r3,32
     398:   4e 80 00 20     blr
     39c:   38 60 00 00     li      r3,0
     3a0:   4e 80 00 20     blr
    
    000003b0 <testfls64>:
     3b0:   2c 03 00 00     cmpwi   r3,0
     3b4:   40 82 00 1c     bne     3d0 <testfls64+0x20>
     3b8:   2f 84 00 00     cmpwi   cr7,r4,0
     3bc:   38 60 00 00     li      r3,0
     3c0:   4d 9e 00 20     beqlr   cr7
     3c4:   7c 83 00 34     cntlzw  r3,r4
     3c8:   20 63 00 20     subfic  r3,r3,32
     3cc:   4e 80 00 20     blr
     3d0:   7c 63 00 34     cntlzw  r3,r3
     3d4:   20 63 00 40     subfic  r3,r3,64
     3d8:   4e 80 00 20     blr
    
    When the input of fls(x) is a constant, just check x for nullity and
    return either 0 or __builtin_clz(x). Otherwise, use cntlzw instruction
    directly.
    
    For fls64() on PPC64, do the same but with __builtin_clzll() and
    cntlzd instruction. On PPC32, lets take the generic fls64() which
    will use our fls(). The result is as expected:
    
    00000388 <testfls>:
     388:   7c 63 00 34     cntlzw  r3,r3
     38c:   20 63 00 20     subfic  r3,r3,32
     390:   4e 80 00 20     blr
    
    000003a0 <testfls64>:
     3a0:   2c 03 00 00     cmpwi   r3,0
     3a4:   40 82 00 10     bne     3b4 <testfls64+0x14>
     3a8:   7c 83 00 34     cntlzw  r3,r4
     3ac:   20 63 00 20     subfic  r3,r3,32
     3b0:   4e 80 00 20     blr
     3b4:   7c 63 00 34     cntlzw  r3,r3
     3b8:   20 63 00 40     subfic  r3,r3,64
     3bc:   4e 80 00 20     blr
    
    Fixes: 2fcff790dcb4 ("powerpc: Use builtin functions for fls()/__fls()/fls64()")
    Cc: stable@vger.kernel.org
    Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
    Acked-by: Segher Boessenkool <segher@kernel.crashing.org>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://lore.kernel.org/r/348c2d3f19ffcff8abe50d52513f989c4581d000.1603375524.git.christophe.leroy@csgroup.eu
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit a37ec98270486828123face45fa811a6b85a0980
Author: Paolo Bonzini <pbonzini@redhat.com>
Date:   Thu Dec 3 09:40:15 2020 -0500

    KVM: x86: reinstate vendor-agnostic check on SPEC_CTRL cpuid bits
    
    [ Upstream commit 39485ed95d6b83b62fa75c06c2c4d33992e0d971 ]
    
    Until commit e7c587da1252 ("x86/speculation: Use synthetic bits for
    IBRS/IBPB/STIBP"), KVM was testing both Intel and AMD CPUID bits before
    allowing the guest to write MSR_IA32_SPEC_CTRL and MSR_IA32_PRED_CMD.
    Testing only Intel bits on VMX processors, or only AMD bits on SVM
    processors, fails if the guests are created with the "opposite" vendor
    as the host.
    
    While at it, also tweak the host CPU check to use the vendor-agnostic
    feature bit X86_FEATURE_IBPB, since we only care about the availability
    of the MSR on the host here and not about specific CPUID bits.
    
    Fixes: e7c587da1252 ("x86/speculation: Use synthetic bits for IBRS/IBPB/STIBP")
    Cc: stable@vger.kernel.org
    Reported-by: Denis V. Lunev <den@openvz.org>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 88464279c03ce05b56abeed7c38c4064dd054ab9
Author: Paolo Bonzini <pbonzini@redhat.com>
Date:   Wed Feb 5 16:10:52 2020 +0100

    KVM: SVM: relax conditions for allowing MSR_IA32_SPEC_CTRL accesses
    
    [ Upstream commit df7e8818926eb4712b67421442acf7d568fe2645 ]
    
    Userspace that does not know about the AMD_IBRS bit might still
    allow the guest to protect itself with MSR_IA32_SPEC_CTRL using
    the Intel SPEC_CTRL bit.  However, svm.c disallows this and will
    cause a #GP in the guest when writing to the MSR.  Fix this by
    loosening the test and allowing the Intel CPUID bit, and in fact
    allow the AMD_STIBP bit as well since it allows writing to
    MSR_IA32_SPEC_CTRL too.
    
    Reported-by: Zhiyi Guo <zhguo@redhat.com>
    Analyzed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
    Analyzed-by: Laszlo Ersek <lersek@redhat.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit c1f49fb15943656d5e1a3bd696853ab3a954babb
Author: Petr Vorel <petr.vorel@gmail.com>
Date:   Mon Dec 14 19:03:21 2020 -0800

    uapi: move constants from <linux/kernel.h> to <linux/const.h>
    
    commit a85cbe6159ffc973e5702f70a3bd5185f8f3c38d upstream.
    
    and include <linux/const.h> in UAPI headers instead of <linux/kernel.h>.
    
    The reason is to avoid indirect <linux/sysinfo.h> include when using
    some network headers: <linux/netlink.h> or others -> <linux/kernel.h>
    -> <linux/sysinfo.h>.
    
    This indirect include causes on MUSL redefinition of struct sysinfo when
    included both <sys/sysinfo.h> and some of UAPI headers:
    
        In file included from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/kernel.h:5,
                         from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/netlink.h:5,
                         from ../include/tst_netlink.h:14,
                         from tst_crypto.c:13:
        x86_64-buildroot-linux-musl/sysroot/usr/include/linux/sysinfo.h:8:8: error: redefinition of `struct sysinfo'
         struct sysinfo {
                ^~~~~~~
        In file included from ../include/tst_safe_macros.h:15,
                         from ../include/tst_test.h:93,
                         from tst_crypto.c:11:
        x86_64-buildroot-linux-musl/sysroot/usr/include/sys/sysinfo.h:10:8: note: originally defined here
    
    Link: https://lkml.kernel.org/r/20201015190013.8901-1-petr.vorel@gmail.com
    Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
    Suggested-by: Rich Felker <dalias@aerifal.cx>
    Acked-by: Rich Felker <dalias@libc.org>
    Cc: Peter Korsgaard <peter@korsgaard.com>
    Cc: Baruch Siach <baruch@tkos.co.il>
    Cc: Florian Weimer <fweimer@redhat.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 81629230815ff27439a61d675ad9873e93190204
Author: Jan Kara <jack@suse.cz>
Date:   Fri Nov 27 12:33:54 2020 +0100

    ext4: don't remount read-only with errors=continue on reboot
    
    [ Upstream commit b08070eca9e247f60ab39d79b2c25d274750441f ]
    
    ext4_handle_error() with errors=continue mount option can accidentally
    remount the filesystem read-only when the system is rebooting. Fix that.
    
    Fixes: 1dc1097ff60e ("ext4: avoid panic during forced reboot")
    Signed-off-by: Jan Kara <jack@suse.cz>
    Reviewed-by: Andreas Dilger <adilger@dilger.ca>
    Cc: stable@kernel.org
    Link: https://lore.kernel.org/r/20201127113405.26867-2-jack@suse.cz
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 706a63e840d0ab86ecba189277f22f82e5356c63
Author: Eric Auger <eric.auger@redhat.com>
Date:   Fri Nov 13 18:52:02 2020 +0100

    vfio/pci: Move dummy_resources_list init in vfio_pci_probe()
    
    [ Upstream commit 16b8fe4caf499ae8e12d2ab1b1324497e36a7b83 ]
    
    In case an error occurs in vfio_pci_enable() before the call to
    vfio_pci_probe_mmaps(), vfio_pci_disable() will  try to iterate
    on an uninitialized list and cause a kernel panic.
    
    Lets move to the initialization to vfio_pci_probe() to fix the
    issue.
    
    Signed-off-by: Eric Auger <eric.auger@redhat.com>
    Fixes: 05f0c03fbac1 ("vfio-pci: Allow to mmap sub-page MMIO BARs if the mmio page is exclusive")
    CC: Stable <stable@vger.kernel.org> # v4.7+
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 5664f1cb0855ff4e1855d358ed68e494ceb451d5
Author: Eric Biggers <ebiggers@google.com>
Date:   Mon Dec 28 11:12:11 2020 -0800

    ubifs: prevent creating duplicate encrypted filenames
    
    commit 76786a0f083473de31678bdb259a3d4167cf756d upstream.
    
    As described in "fscrypt: add fscrypt_is_nokey_name()", it's possible to
    create a duplicate filename in an encrypted directory by creating a file
    concurrently with adding the directory's encryption key.
    
    Fix this bug on ubifs by rejecting no-key dentries in ubifs_create(),
    ubifs_mkdir(), ubifs_mknod(), and ubifs_symlink().
    
    Note that ubifs doesn't actually report the duplicate filenames from
    readdir, but rather it seems to replace the original dentry with a new
    one (which is still wrong, just a different effect from ext4).
    
    On ubifs, this fixes xfstest generic/595 as well as the new xfstest I
    wrote specifically for this bug.
    
    Fixes: f4f61d2cc6d8 ("ubifs: Implement encrypted filenames")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20201118075609.120337-5-ebiggers@kernel.org
    Signed-off-by: Eric Biggers <ebiggers@google.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 218cf245fc6a3aacb0ebe143a4f4a88121104559
Author: Eric Biggers <ebiggers@google.com>
Date:   Mon Dec 28 11:12:10 2020 -0800

    f2fs: prevent creating duplicate encrypted filenames
    
    commit bfc2b7e8518999003a61f91c1deb5e88ed77b07d upstream.
    
    As described in "fscrypt: add fscrypt_is_nokey_name()", it's possible to
    create a duplicate filename in an encrypted directory by creating a file
    concurrently with adding the directory's encryption key.
    
    Fix this bug on f2fs by rejecting no-key dentries in f2fs_add_link().
    
    Note that the weird check for the current task in f2fs_do_add_link()
    seems to make this bug difficult to reproduce on f2fs.
    
    Fixes: 9ea97163c6da ("f2fs crypto: add filename encryption for f2fs_add_link")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20201118075609.120337-4-ebiggers@kernel.org
    Signed-off-by: Eric Biggers <ebiggers@google.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit abd561e51a2a36eca2f1858b95ccaa613637d162
Author: Eric Biggers <ebiggers@google.com>
Date:   Mon Dec 28 11:12:09 2020 -0800

    ext4: prevent creating duplicate encrypted filenames
    
    commit 75d18cd1868c2aee43553723872c35d7908f240f upstream.
    
    As described in "fscrypt: add fscrypt_is_nokey_name()", it's possible to
    create a duplicate filename in an encrypted directory by creating a file
    concurrently with adding the directory's encryption key.
    
    Fix this bug on ext4 by rejecting no-key dentries in ext4_add_entry().
    
    Note that the duplicate check in ext4_find_dest_de() sometimes prevented
    this bug.  However in many cases it didn't, since ext4_find_dest_de()
    doesn't examine every dentry.
    
    Fixes: 4461471107b7 ("ext4 crypto: enable filename encryption")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20201118075609.120337-3-ebiggers@kernel.org
    Signed-off-by: Eric Biggers <ebiggers@google.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 1227ffc9d73d78e036f6f166fbdaf7dfe4c7b88b
Author: Eric Biggers <ebiggers@google.com>
Date:   Mon Dec 28 11:12:08 2020 -0800

    fscrypt: add fscrypt_is_nokey_name()
    
    commit 159e1de201b6fca10bfec50405a3b53a561096a8 upstream.
    
    It's possible to create a duplicate filename in an encrypted directory
    by creating a file concurrently with adding the encryption key.
    
    Specifically, sys_open(O_CREAT) (or sys_mkdir(), sys_mknod(), or
    sys_symlink()) can lookup the target filename while the directory's
    encryption key hasn't been added yet, resulting in a negative no-key
    dentry.  The VFS then calls ->create() (or ->mkdir(), ->mknod(), or
    ->symlink()) because the dentry is negative.  Normally, ->create() would
    return -ENOKEY due to the directory's key being unavailable.  However,
    if the key was added between the dentry lookup and ->create(), then the
    filesystem will go ahead and try to create the file.
    
    If the target filename happens to already exist as a normal name (not a
    no-key name), a duplicate filename may be added to the directory.
    
    In order to fix this, we need to fix the filesystems to prevent
    ->create(), ->mkdir(), ->mknod(), and ->symlink() on no-key names.
    (->rename() and ->link() need it too, but those are already handled
    correctly by fscrypt_prepare_rename() and fscrypt_prepare_link().)
    
    In preparation for this, add a helper function fscrypt_is_nokey_name()
    that filesystems can use to do this check.  Use this helper function for
    the existing checks that fs/crypto/ does for rename and link.
    
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20201118075609.120337-2-ebiggers@kernel.org
    Signed-off-by: Eric Biggers <ebiggers@google.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit f8bd479859c9431bf0e951948f76c75e8953d6bd
Author: Kevin Vigor <kvigor@gmail.com>
Date:   Fri Nov 6 14:20:34 2020 -0800

    md/raid10: initialize r10_bio->read_slot before use.
    
    commit 93decc563637c4288380912eac0eb42fb246cc04 upstream.
    
    In __make_request() a new r10bio is allocated and passed to
    raid10_read_request(). The read_slot member of the bio is not
    initialized, and the raid10_read_request() uses it to index an
    array. This leads to occasional panics.
    
    Fix by initializing the field to invalid value and checking for
    valid value in raid10_read_request().
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Kevin Vigor <kvigor@gmail.com>
    Signed-off-by: Song Liu <songliubraving@fb.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>