Linux 6.1.84

 
ahci: asm1064: asm1166: don't limit reported ports [+ + +]
Author: Conrad Kostecki <conikost@gentoo.org>
Date:   Wed Mar 13 22:46:50 2024 +0100

    ahci: asm1064: asm1166: don't limit reported ports
    
    [ Upstream commit 6cd8adc3e18960f6e59d797285ed34ef473cc896 ]
    
    Previously, patches have been added to limit the reported count of SATA
    ports for asm1064 and asm1166 SATA controllers, as those controllers do
    report more ports than physically having.
    
    While it is allowed to report more ports than physically having in CAP.NP,
    it is not allowed to report more ports than physically having in the PI
    (Ports Implemented) register, which is what these HBAs do.
    (This is a AHCI spec violation.)
    
    Unfortunately, it seems that the PMP implementation in these ASMedia HBAs
    is also violating the AHCI and SATA-IO PMP specification.
    
    What these HBAs do is that they do not report that they support PMP
    (CAP.SPM (Supports Port Multiplier) is not set).
    
    Instead, they have decided to add extra "virtual" ports in the PI register
    that is used if a port multiplier is connected to any of the physical
    ports of the HBA.
    
    Enumerating the devices behind the PMP as specified in the AHCI and
    SATA-IO specifications, by using PMP READ and PMP WRITE commands to the
    physical ports of the HBA is not possible, you have to use the "virtual"
    ports.
    
    This is of course bad, because this gives us no way to detect the device
    and vendor ID of the PMP actually connected to the HBA, which means that
    we can not apply the proper PMP quirks for the PMP that is connected to
    the HBA.
    
    Limiting the port map will thus stop these controllers from working with
    SATA Port Multipliers.
    
    This patch reverts both patches for asm1064 and asm1166, so old behavior
    is restored and SATA PMP will work again, but it will also reintroduce the
    (minutes long) extra boot time for the ASMedia controllers that do not
    have a PMP connected (either on the PCIe card itself, or an external PMP).
    
    However, a longer boot time for some, is the lesser evil compared to some
    other users not being able to detect their drives at all.
    
    Fixes: 0077a504e1a4 ("ahci: asm1166: correct count of reported ports")
    Fixes: 9815e3961754 ("ahci: asm1064: correct count of reported ports")
    Cc: stable@vger.kernel.org
    Reported-by: Matt <cryptearth@googlemail.com>
    Signed-off-by: Conrad Kostecki <conikost@gentoo.org>
    Reviewed-by: Hans de Goede <hdegoede@redhat.com>
    [cassel: rewrote commit message]
    Signed-off-by: Niklas Cassel <cassel@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

ahci: asm1064: correct count of reported ports [+ + +]
Author: Andrey Jr. Melnikov <temnota.am@gmail.com>
Date:   Wed Feb 14 17:57:57 2024 +0100

    ahci: asm1064: correct count of reported ports
    
    [ Upstream commit 9815e39617541ef52d0dfac4be274ad378c6dc09 ]
    
    The ASM1064 SATA host controller always reports wrongly,
    that it has 24 ports. But in reality, it only has four ports.
    
    before:
    ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
    ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
    ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
    
    after:
    ahci 0000:04:00.0: ASM1064 has only four ports
    ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
    ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
    ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
    ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
    
    Signed-off-by: "Andrey Jr. Melnikov" <temnota.am@gmail.com>
    Signed-off-by: Niklas Cassel <cassel@kernel.org>
    Stable-dep-of: 6cd8adc3e189 ("ahci: asm1064: asm1166: don't limit reported ports")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
ALSA: hda/realtek - Add Headset Mic supported Acer NB platform [+ + +]
Author: Kailang Yang <kailang@realtek.com>
Date:   Fri Mar 1 15:04:02 2024 +0800

    ALSA: hda/realtek - Add Headset Mic supported Acer NB platform
    
    commit 34ab5bbc6e82214d7f7393eba26d164b303ebb4e upstream.
    
    It will be enable headset Mic for Acer NB platform.
    
    Signed-off-by: Kailang Yang <kailang@realtek.com>
    Cc: <stable@vger.kernel.org>
    Link: https://lore.kernel.org/r/fe0eb6661ca240f3b7762b5b3257710d@realtek.com
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

ALSA: hda/realtek - Fix headset Mic no show at resume back for Lenovo ALC897 platform [+ + +]
Author: Kailang Yang <kailang@realtek.com>
Date:   Fri Mar 1 15:29:50 2024 +0800

    ALSA: hda/realtek - Fix headset Mic no show at resume back for Lenovo ALC897 platform
    
    commit d397b6e56151099cf3b1f7bfccb204a6a8591720 upstream.
    
    Headset Mic will no show at resume back.
    This patch will fix this issue.
    
    Fixes: d7f32791a9fc ("ALSA: hda/realtek - Add headset Mic support for Lenovo ALC897 platform")
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Kailang Yang <kailang@realtek.com>
    Link: https://lore.kernel.org/r/4713d48a372e47f98bba0c6120fd8254@realtek.com
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

ALSA: hda/realtek: fix mute/micmute LEDs for HP EliteBook [+ + +]
Author: Andy Chi <andy.chi@canonical.com>
Date:   Mon Mar 4 21:40:32 2024 +0800

    ALSA: hda/realtek: fix mute/micmute LEDs for HP EliteBook
    
    commit a17bd44c0146b00fcaa692915789c16bd1fb2a81 upstream.
    
    The HP EliteBook using ALC236 codec which using 0x02 to
    control mute LED and 0x01 to control micmute LED.
    Therefore, add a quirk to make it works.
    
    Signed-off-by: Andy Chi <andy.chi@canonical.com>
    Cc: <stable@vger.kernel.org>
    Link: https://lore.kernel.org/r/20240304134033.773348-1-andy.chi@canonical.com
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

ALSA: sh: aica: reorder cleanup operations to avoid UAF bugs [+ + +]
Author: Duoming Zhou <duoming@zju.edu.cn>
Date:   Tue Mar 26 17:42:38 2024 +0800

    ALSA: sh: aica: reorder cleanup operations to avoid UAF bugs
    
    commit 051e0840ffa8ab25554d6b14b62c9ab9e4901457 upstream.
    
    The dreamcastcard->timer could schedule the spu_dma_work and the
    spu_dma_work could also arm the dreamcastcard->timer.
    
    When the snd_pcm_substream is closing, the aica_channel will be
    deallocated. But it could still be dereferenced in the worker
    thread. The reason is that del_timer() will return directly
    regardless of whether the timer handler is running or not and
    the worker could be rescheduled in the timer handler. As a result,
    the UAF bug will happen. The racy situation is shown below:
    
          (Thread 1)                 |      (Thread 2)
    snd_aicapcm_pcm_close()          |
     ...                             |  run_spu_dma() //worker
                                     |    mod_timer()
      flush_work()                   |
      del_timer()                    |  aica_period_elapsed() //timer
      kfree(dreamcastcard->channel)  |    schedule_work()
                                     |  run_spu_dma() //worker
      ...                            |    dreamcastcard->channel-> //USE
    
    In order to mitigate this bug and other possible corner cases,
    call mod_timer() conditionally in run_spu_dma(), then implement
    PCM sync_stop op to cancel both the timer and worker. The sync_stop
    op will be called from PCM core appropriately when needed.
    
    Fixes: 198de43d758c ("[ALSA] Add ALSA support for the SEGA Dreamcast PCM device")
    Suggested-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
    Message-ID: <20240326094238.95442-1-duoming@zju.edu.cn>
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
arm64: dts: qcom: sc7280: Add additional MSI interrupts [+ + +]
Author: Krishna chaitanya chundru <quic_krichai@quicinc.com>
Date:   Mon Dec 18 19:32:36 2023 +0530

    arm64: dts: qcom: sc7280: Add additional MSI interrupts
    
    [ Upstream commit b8ba66b40da3230a8675cb5dd5c2dea5bce24d62 ]
    
    Current MSI's mapping doesn't have all the vectors. This platform
    supports 8 vectors each vector supports 32 MSI's, so total MSI's
    supported is 256.
    
    Add all the MSI groups supported for this PCIe instance in this platform.
    
    Fixes: 92e0ee9f83b3 ("arm64: dts: qcom: sc7280: Add PCIe and PHY related nodes")
    cc: stable@vger.kernel.org
    Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
    Link: https://lore.kernel.org/r/20231218-additional_msi-v1-1-de6917392684@quicinc.com
    Signed-off-by: Bjorn Andersson <andersson@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
arm: dts: marvell: Fix maxium->maxim typo in brownstone dts [+ + +]
Author: Duje Mihanović <duje.mihanovic@skole.hr>
Date:   Thu Jan 25 19:39:32 2024 +0100

    arm: dts: marvell: Fix maxium->maxim typo in brownstone dts
    
    [ Upstream commit 831e0cd4f9ee15a4f02ae10b67e7fdc10eb2b4fc ]
    
    Fix an obvious spelling error in the PMIC compatible in the MMP2
    Brownstone DTS file.
    
    Fixes: 58f1193e6210 ("mfd: max8925: Add dts")
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Duje Mihanović <duje.mihanovic@skole.hr>
    Reported-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
    Closes: https://lore.kernel.org/linux-devicetree/1410884282-18041-1-git-send-email-k.kozlowski@samsung.com/
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Link: https://lore.kernel.org/r/20240125-brownstone-typo-fix-v2-1-45bc48a0c81c@skole.hr
    [krzysztof: Just 10 years to take a patch, not bad! Rephrased commit
     msg]
    Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
ASoC: amd: yc: Revert "Fix non-functional mic on Lenovo 21J2" [+ + +]
Author: Jiawei Wang <me@jwang.link>
Date:   Wed Mar 13 09:58:52 2024 +0800

    ASoC: amd: yc: Revert "Fix non-functional mic on Lenovo 21J2"
    
    commit 861b3415e4dee06cc00cd1754808a7827b9105bf upstream.
    
    This reverts commit ed00a6945dc32462c2d3744a3518d2316da66fcc,
    which added a quirk entry to enable the Yellow Carp (YC)
    driver for the Lenovo 21J2 laptop.
    
    Although the microphone functioned with the YC driver, it
    resulted in incorrect driver usage. The Lenovo 21J2 is not a
    Yellow Carp platform, but a Pink Sardine platform, which
    already has an upstreamed driver.
    
    The microphone on the Lenovo 21J2 operates correctly with the
    CONFIG_SND_SOC_AMD_PS flag enabled and does not require the
    quirk entry. So this patch removes the quirk entry.
    
    Thanks to Mukunda Vijendar [1] for pointing this out.
    
    Link: https://lore.kernel.org/linux-sound/023092e1-689c-4b00-b93f-4092c3724fb6@amd.com/ [1]
    
    Signed-off-by: Jiawei Wang <me@jwang.link>
    Link: https://lore.kernel.org/linux-sound/023092e1-689c-4b00-b93f-4092c3724fb6@amd.com/ [1]
    Link: https://msgid.link/r/20240313015853.3573242-2-me@jwang.link
    Signed-off-by: Mark Brown <broonie@kernel.org>
    Cc: Luca Stefani <luca.stefani.ge1@gmail.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
blk-mq: release scheduler resource when request completes [+ + +]
Author: Chengming Zhou <zhouchengming@bytedance.com>
Date:   Sun Aug 13 23:23:25 2023 +0800

    blk-mq: release scheduler resource when request completes
    
    commit e5c0ca13659e9d18f53368d651ed7e6e433ec1cf upstream.
    
    Chuck reported [1] an IO hang problem on NFS exports that reside on SATA
    devices and bisected to commit 615939a2ae73 ("blk-mq: defer to the normal
    submission path for post-flush requests").
    
    We analysed the IO hang problem, found there are two postflush requests
    waiting for each other.
    
    The first postflush request completed the REQ_FSEQ_DATA sequence, so go to
    the REQ_FSEQ_POSTFLUSH sequence and added in the flush pending list, but
    failed to blk_kick_flush() because of the second postflush request which
    is inflight waiting in scheduler queue.
    
    The second postflush waiting in scheduler queue can't be dispatched because
    the first postflush hasn't released scheduler resource even though it has
    completed by itself.
    
    Fix it by releasing scheduler resource when the first postflush request
    completed, so the second postflush can be dispatched and completed, then
    make blk_kick_flush() succeed.
    
    While at it, remove the check for e->ops.finish_request, as all
    schedulers set that. Reaffirm this requirement by adding a WARN_ON_ONCE()
    at scheduler registration time, just like we do for insert_requests and
    dispatch_request.
    
    [1] https://lore.kernel.org/all/7A57C7AE-A51A-4254-888B-FE15CA21F9E9@oracle.com/
    
    Link: https://lore.kernel.org/linux-block/20230819031206.2744005-1-chengming.zhou@linux.dev/
    Reported-by: kernel test robot <oliver.sang@intel.com>
    Closes: https://lore.kernel.org/oe-lkp/202308172100.8ce4b853-oliver.sang@intel.com
    Fixes: 615939a2ae73 ("blk-mq: defer to the normal submission path for post-flush requests")
    Reported-by: Chuck Lever <chuck.lever@oracle.com>
    Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
    Tested-by: Chuck Lever <chuck.lever@oracle.com>
    Link: https://lore.kernel.org/r/20230813152325.3017343-1-chengming.zhou@linux.dev
    [axboe: folded in incremental fix and added tags]
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    [bvanassche: changed RQF_USE_SCHED into RQF_ELVPRIV; restored the
    finish_request pointer check before calling finish_request and removed
    the new warning from the elevator code. This patch fixes an I/O hang
    when submitting a REQ_FUA request to a request queue for a zoned block
    device for which FUA has been disabled (QUEUE_FLAG_FUA is not set).]
    Signed-off-by: Bart Van Assche <bvanassche@acm.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
block: Clear zone limits for a non-zoned stacked queue [+ + +]
Author: Damien Le Moal <dlemoal@kernel.org>
Date:   Thu Feb 22 22:17:23 2024 +0900

    block: Clear zone limits for a non-zoned stacked queue
    
    [ Upstream commit c8f6f88d25929ad2f290b428efcae3b526f3eab0 ]
    
    Device mapper may create a non-zoned mapped device out of a zoned device
    (e.g., the dm-zoned target). In such case, some queue limit such as the
    max_zone_append_sectors and zone_write_granularity endup being non zero
    values for a block device that is not zoned. Avoid this by clearing
    these limits in blk_stack_limits() when the stacked zoned limit is
    false.
    
    Fixes: 3093a479727b ("block: inherit the zoned characteristics in blk_stack_limits")
    Cc: stable@vger.kernel.org
    Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
    Link: https://lore.kernel.org/r/20240222131724.1803520-1-dlemoal@kernel.org
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

block: Do not force full zone append completion in req_bio_endio() [+ + +]
Author: Damien Le Moal <dlemoal@kernel.org>
Date:   Thu Mar 28 09:43:40 2024 +0900

    block: Do not force full zone append completion in req_bio_endio()
    
    commit 55251fbdf0146c252ceff146a1bb145546f3e034 upstream.
    
    This reverts commit 748dc0b65ec2b4b7b3dbd7befcc4a54fdcac7988.
    
    Partial zone append completions cannot be supported as there is no
    guarantees that the fragmented data will be written sequentially in the
    same manner as with a full command. Commit 748dc0b65ec2 ("block: fix
    partial zone append completion handling in req_bio_endio()") changed
    req_bio_endio() to always advance a partially failed BIO by its full
    length, but this can lead to incorrect accounting. So revert this
    change and let low level device drivers handle this case by always
    failing completely zone append operations. With this revert, users will
    still see an IO error for a partially completed zone append BIO.
    
    Fixes: 748dc0b65ec2 ("block: fix partial zone append completion handling in req_bio_endio()")
    Cc: stable@vger.kernel.org
    Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Link: https://lore.kernel.org/r/20240328004409.594888-2-dlemoal@kernel.org
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

block: Fix page refcounts for unaligned buffers in __bio_release_pages() [+ + +]
Author: Tony Battersby <tonyb@cybernetics.com>
Date:   Thu Feb 29 13:08:09 2024 -0500

    block: Fix page refcounts for unaligned buffers in __bio_release_pages()
    
    commit 38b43539d64b2fa020b3b9a752a986769f87f7a6 upstream.
    
    Fix an incorrect number of pages being released for buffers that do not
    start at the beginning of a page.
    
    Fixes: 1b151e2435fc ("block: Remove special-casing of compound pages")
    Cc: stable@vger.kernel.org
    Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
    Tested-by: Greg Edwards <gedwards@ddn.com>
    Link: https://lore.kernel.org/r/86e592a9-98d4-4cff-a646-0c0084328356@cybernetics.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    [ Tony: backport to v6.1 by replacing bio_release_page() loop with
      folio_put_refs() as commits fd363244e883 and e4cc64657bec are not
      present. ]
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
Bluetooth: hci_sync: Fix not checking error on hci_cmd_sync_cancel_sync [+ + +]
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Tue Mar 26 12:43:17 2024 -0400

    Bluetooth: hci_sync: Fix not checking error on hci_cmd_sync_cancel_sync
    
    commit 1c3366abdbe884be62e5a7502b4db758aa3974c6 upstream.
    
    hci_cmd_sync_cancel_sync shall check the error passed to it since it
    will be propagated using req_result which is __u32 it needs to be
    properly set to a positive value if it was passed as negative othertise
    IS_ERR will not trigger as -(errno) would be converted to a positive
    value.
    
    Fixes: 63298d6e752f ("Bluetooth: hci_core: Cancel request on command timeout")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
    Reported-and-tested-by: Thorsten Leemhuis <linux@leemhuis.info>
    Closes: https://lore.kernel.org/all/08275279-7462-4f4a-a0ee-8aa015f829bc@leemhuis.info/
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
bounds: support non-power-of-two CONFIG_NR_CPUS [+ + +]
Author: Matthew Wilcox (Oracle) <willy@infradead.org>
Date:   Tue Oct 10 15:55:49 2023 +0100

    bounds: support non-power-of-two CONFIG_NR_CPUS
    
    [ Upstream commit f2d5dcb48f7ba9e3ff249d58fc1fa963d374e66a ]
    
    ilog2() rounds down, so for example when PowerPC 85xx sets CONFIG_NR_CPUS
    to 24, we will only allocate 4 bits to store the number of CPUs instead of
    5.  Use bits_per() instead, which rounds up.  Found by code inspection.
    The effect of this would probably be a misaccounting when doing NUMA
    balancing, so to a user, it would only be a performance penalty.  The
    effects may be more wide-spread; it's hard to tell.
    
    Link: https://lkml.kernel.org/r/20231010145549.1244748-1-willy@infradead.org
    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
    Fixes: 90572890d202 ("mm: numa: Change page last {nid,pid} into {cpu,pid}")
    Reviewed-by: Rik van Riel <riel@surriel.com>
    Acked-by: Mel Gorman <mgorman@techsingularity.net>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
btrfs: fix off-by-one chunk length calculation at contains_pending_extent() [+ + +]
Author: Filipe Manana <fdmanana@suse.com>
Date:   Thu Feb 29 10:37:04 2024 +0000

    btrfs: fix off-by-one chunk length calculation at contains_pending_extent()
    
    [ Upstream commit ae6bd7f9b46a29af52ebfac25d395757e2031d0d ]
    
    At contains_pending_extent() the value of the end offset of a chunk we
    found in the device's allocation state io tree is inclusive, so when
    we calculate the length we pass to the in_range() macro, we must sum
    1 to the expression "physical_end - physical_offset".
    
    In practice the wrong calculation should be harmless as chunks sizes
    are never 1 byte and we should never have 1 byte ranges of unallocated
    space. Nevertheless fix the wrong calculation.
    
    Reported-by: Alex Lyakas <alex.lyakas@zadara.com>
    Link: https://lore.kernel.org/linux-btrfs/CAOcd+r30e-f4R-5x-S7sV22RJPe7+pgwherA6xqN2_qe7o4XTg@mail.gmail.com/
    Fixes: 1c11b63eff2a ("btrfs: replace pending/pinned chunks lists with io tree")
    CC: stable@vger.kernel.org # 6.1+
    Reviewed-by: Josef Bacik <josef@toxicpanda.com>
    Reviewed-by: Qu Wenruo <wqu@suse.com>
    Signed-off-by: Filipe Manana <fdmanana@suse.com>
    Signed-off-by: David Sterba <dsterba@suse.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

btrfs: qgroup: always free reserved space for extent records [+ + +]
Author: Qu Wenruo <wqu@suse.com>
Date:   Fri Feb 23 18:13:38 2024 +1030

    btrfs: qgroup: always free reserved space for extent records
    
    [ Upstream commit d139ded8b9cdb897bb9539eb33311daf9a177fd2 ]
    
    [BUG]
    If qgroup is marked inconsistent (e.g. caused by operations needing full
    subtree rescan, like creating a snapshot and assign to a higher level
    qgroup), btrfs would immediately start leaking its data reserved space.
    
    The following script can easily reproduce it:
    
      mkfs.btrfs -O quota -f $dev
      mount $dev $mnt
      btrfs subvolume create $mnt/subv1
      btrfs qgroup create 1/0 $mnt
    
      # This snapshot creation would mark qgroup inconsistent,
      # as the ownership involves different higher level qgroup, thus
      # we have to rescan both source and snapshot, which can be very
      # time consuming, thus here btrfs just choose to mark qgroup
      # inconsistent, and let users to determine when to do the rescan.
      btrfs subv snapshot -i 1/0 $mnt/subv1 $mnt/snap1
    
      # Now this write would lead to qgroup rsv leak.
      xfs_io -f -c "pwrite 0 64k" $mnt/file1
    
      # And at unmount time, btrfs would report 64K DATA rsv space leaked.
      umount $mnt
    
    And we would have the following dmesg output for the unmount:
    
      BTRFS info (device dm-1): last unmount of filesystem 14a3d84e-f47b-4f72-b053-a8a36eef74d3
      BTRFS warning (device dm-1): qgroup 0/5 has unreleased space, type 0 rsv 65536
    
    [CAUSE]
    Since commit e15e9f43c7ca ("btrfs: introduce
    BTRFS_QGROUP_RUNTIME_FLAG_NO_ACCOUNTING to skip qgroup accounting"),
    we introduce a mode for btrfs qgroup to skip the timing consuming
    backref walk, if the qgroup is already inconsistent.
    
    But this skip also covered the data reserved freeing, thus the qgroup
    reserved space for each newly created data extent would not be freed,
    thus cause the leakage.
    
    [FIX]
    Make the data extent reserved space freeing mandatory.
    
    The qgroup reserved space handling is way cheaper compared to the
    backref walking part, and we always have the super sensitive leak
    detector, thus it's definitely worth to always free the qgroup
    reserved data space.
    
    Reported-by: Fabian Vogt <fvogt@suse.com>
    Fixes: e15e9f43c7ca ("btrfs: introduce BTRFS_QGROUP_RUNTIME_FLAG_NO_ACCOUNTING to skip qgroup accounting")
    CC: stable@vger.kernel.org # 6.1+
    Link: https://bugzilla.suse.com/show_bug.cgi?id=1216196
    Reviewed-by: Filipe Manana <fdmanana@suse.com>
    Signed-off-by: Qu Wenruo <wqu@suse.com>
    Signed-off-by: David Sterba <dsterba@suse.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

btrfs: zoned: don't skip block groups with 100% zone unusable [+ + +]
Author: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Date:   Wed Feb 21 07:35:52 2024 -0800

    btrfs: zoned: don't skip block groups with 100% zone unusable
    
    commit a8b70c7f8600bc77d03c0b032c0662259b9e615e upstream.
    
    Commit f4a9f219411f ("btrfs: do not delete unused block group if it may be
    used soon") changed the behaviour of deleting unused block-groups on zoned
    filesystems. Starting with this commit, we're using
    btrfs_space_info_used() to calculate the number of used bytes in a
    space_info. But btrfs_space_info_used() also accounts
    btrfs_space_info::bytes_zone_unusable as used bytes.
    
    So if a block group is 100% zone_unusable it is skipped from the deletion
    step.
    
    In order not to skip fully zone_unusable block-groups, also check if the
    block-group has bytes left that can be used on a zoned filesystem.
    
    Fixes: f4a9f219411f ("btrfs: do not delete unused block group if it may be used soon")
    CC: stable@vger.kernel.org # 6.1+
    Reviewed-by: Filipe Manana <fdmanana@suse.com>
    Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
    Reviewed-by: David Sterba <dsterba@suse.com>
    Signed-off-by: David Sterba <dsterba@suse.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

btrfs: zoned: use zone aware sb location for scrub [+ + +]
Author: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Date:   Mon Feb 26 16:39:13 2024 +0100

    btrfs: zoned: use zone aware sb location for scrub
    
    commit 74098a989b9c3370f768140b7783a7aaec2759b3 upstream.
    
    At the moment scrub_supers() doesn't grab the super block's location via
    the zoned device aware btrfs_sb_log_location() but via btrfs_sb_offset().
    
    This leads to checksum errors on 'scrub' as we're not accessing the
    correct location of the super block.
    
    So use btrfs_sb_log_location() for getting the super blocks location on
    scrub.
    
    Reported-by: WA AM <waautomata@gmail.com>
    Link: http://lore.kernel.org/linux-btrfs/CANU2Z0EvUzfYxczLgGUiREoMndE9WdQnbaawV5Fv5gNXptPUKw@mail.gmail.com
    CC: stable@vger.kernel.org # 5.15+
    Reviewed-by: Qu Wenruo <wqu@suse.com>
    Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
    Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
    Reviewed-by: David Sterba <dsterba@suse.com>
    Signed-off-by: David Sterba <dsterba@suse.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
cifs: open_cached_dir(): add FILE_READ_EA to desired access [+ + +]
Author: Eugene Korenevsky <ekorenevsky@astralinux.ru>
Date:   Fri Mar 1 17:53:44 2024 +0300

    cifs: open_cached_dir(): add FILE_READ_EA to desired access
    
    [ Upstream commit f1b8224b4e6ed59e7e6f5c548673c67410098d8d ]
    
    Since smb2_query_eas() reads EA and uses cached directory,
    open_cached_dir() should request FILE_READ_EA access.
    
    Otherwise listxattr() and getxattr() will fail with EACCES
    (0xc0000022 STATUS_ACCESS_DENIED SMB status).
    
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=218543
    Cc: stable@vger.kernel.org
    Signed-off-by: Eugene Korenevsky <ekorenevsky@astralinux.ru>
    Signed-off-by: Steve French <stfrench@microsoft.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
clk: qcom: gcc-ipq6018: fix terminating of frequency table arrays [+ + +]
Author: Gabor Juhos <j4g8y7@gmail.com>
Date:   Thu Feb 29 19:07:47 2024 +0100

    clk: qcom: gcc-ipq6018: fix terminating of frequency table arrays
    
    [ Upstream commit cdbc6e2d8108bc47895e5a901cfcaf799b00ca8d ]
    
    The frequency table arrays are supposed to be terminated with an
    empty element. Add such entry to the end of the arrays where it
    is missing in order to avoid possible out-of-bound access when
    the table is traversed by functions like qcom_find_freq() or
    qcom_find_freq_floor().
    
    Only compile tested.
    
    Fixes: d9db07f088af ("clk: qcom: Add ipq6018 Global Clock Controller support")
    Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
    Reviewed-by: Stephen Boyd <sboyd@kernel.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240229-freq-table-terminator-v1-2-074334f0905c@gmail.com
    Signed-off-by: Bjorn Andersson <andersson@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

clk: qcom: gcc-ipq8074: fix terminating of frequency table arrays [+ + +]
Author: Gabor Juhos <j4g8y7@gmail.com>
Date:   Thu Feb 29 19:07:48 2024 +0100

    clk: qcom: gcc-ipq8074: fix terminating of frequency table arrays
    
    [ Upstream commit 1040ef5ed95d6fd2628bad387d78a61633e09429 ]
    
    The frequency table arrays are supposed to be terminated with an
    empty element. Add such entry to the end of the arrays where it
    is missing in order to avoid possible out-of-bound access when
    the table is traversed by functions like qcom_find_freq() or
    qcom_find_freq_floor().
    
    Only compile tested.
    
    Fixes: 9607f6224b39 ("clk: qcom: ipq8074: add PCIE, USB and SDCC clocks")
    Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
    Reviewed-by: Stephen Boyd <sboyd@kernel.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240229-freq-table-terminator-v1-3-074334f0905c@gmail.com
    Signed-off-by: Bjorn Andersson <andersson@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

clk: qcom: gcc-sdm845: Add soft dependency on rpmhpd [+ + +]
Author: Amit Pundir <amit.pundir@linaro.org>
Date:   Tue Jan 23 11:58:14 2024 +0530

    clk: qcom: gcc-sdm845: Add soft dependency on rpmhpd
    
    [ Upstream commit 1d9054e3a4fd36e2949e616f7360bdb81bcc1921 ]
    
    With the addition of RPMh power domain to the GCC node in
    device tree, we noticed a significant delay in getting the
    UFS driver probed on AOSP which futher led to mount failures
    because Android do not support rootwait. So adding a soft
    dependency on RPMh power domain which informs modprobe to
    load rpmhpd module before gcc-sdm845.
    
    Cc: stable@vger.kernel.org # v5.4+
    Fixes: 4b6ea15c0a11 ("arm64: dts: qcom: sdm845: Add missing RPMh power domain to GCC")
    Suggested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
    Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
    Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
    Link: https://lore.kernel.org/r/20240123062814.2555649-1-amit.pundir@linaro.org
    Signed-off-by: Bjorn Andersson <andersson@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

clk: qcom: mmcc-apq8084: fix terminating of frequency table arrays [+ + +]
Author: Gabor Juhos <j4g8y7@gmail.com>
Date:   Thu Feb 29 19:07:51 2024 +0100

    clk: qcom: mmcc-apq8084: fix terminating of frequency table arrays
    
    [ Upstream commit a903cfd38d8dee7e754fb89fd1bebed99e28003d ]
    
    The frequency table arrays are supposed to be terminated with an
    empty element. Add such entry to the end of the arrays where it
    is missing in order to avoid possible out-of-bound access when
    the table is traversed by functions like qcom_find_freq() or
    qcom_find_freq_floor().
    
    Only compile tested.
    
    Fixes: 2b46cd23a5a2 ("clk: qcom: Add APQ8084 Multimedia Clock Controller (MMCC) support")
    Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
    Reviewed-by: Stephen Boyd <sboyd@kernel.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240229-freq-table-terminator-v1-6-074334f0905c@gmail.com
    Signed-off-by: Bjorn Andersson <andersson@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

clk: qcom: mmcc-msm8974: fix terminating of frequency table arrays [+ + +]
Author: Gabor Juhos <j4g8y7@gmail.com>
Date:   Thu Feb 29 19:07:52 2024 +0100

    clk: qcom: mmcc-msm8974: fix terminating of frequency table arrays
    
    [ Upstream commit e2c02a85bf53ae86d79b5fccf0a75ac0b78e0c96 ]
    
    The frequency table arrays are supposed to be terminated with an
    empty element. Add such entry to the end of the arrays where it
    is missing in order to avoid possible out-of-bound access when
    the table is traversed by functions like qcom_find_freq() or
    qcom_find_freq_floor().
    
    Only compile tested.
    
    Fixes: d8b212014e69 ("clk: qcom: Add support for MSM8974's multimedia clock controller (MMCC)")
    Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
    Reviewed-by: Stephen Boyd <sboyd@kernel.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240229-freq-table-terminator-v1-7-074334f0905c@gmail.com
    Signed-off-by: Bjorn Andersson <andersson@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
clocksource/drivers/arm_global_timer: Fix maximum prescaler value [+ + +]
Author: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Date:   Sun Feb 18 18:41:37 2024 +0100

    clocksource/drivers/arm_global_timer: Fix maximum prescaler value
    
    [ Upstream commit b34b9547cee41575a4fddf390f615570759dc999 ]
    
    The prescaler in the "Global Timer Control Register bit assignments" is
    documented to use bits [15:8], which means that the maximum prescaler
    register value is 0xff.
    
    Fixes: 171b45a4a70e ("clocksource/drivers/arm_global_timer: Implement rate compensation whenever source clock changes")
    Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
    Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
    Link: https://lore.kernel.org/r/20240218174138.1942418-2-martin.blumenstingl@googlemail.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
cpufreq: amd-pstate: Fix min_perf assignment in amd_pstate_adjust_perf() [+ + +]
Author: Tor Vic <torvic9@mailbox.org>
Date:   Fri Feb 9 16:42:26 2024 +0100

    cpufreq: amd-pstate: Fix min_perf assignment in amd_pstate_adjust_perf()
    
    [ Upstream commit b26ffbf800ae3c8d01bdf90d9cd8a37e1606ff06 ]
    
    In the function amd_pstate_adjust_perf(), the 'min_perf' variable is set
    to 'highest_perf' instead of 'lowest_perf'.
    
    Fixes: 1d215f0319c2 ("cpufreq: amd-pstate: Add fast switch function for AMD P-State")
    Reported-by: Oleksandr Natalenko <oleksandr@natalenko.name>
    Reviewed-by: Perry Yuan <Perry.Yuan@amd.com>
    Signed-off-by: Tor Vic <torvic9@mailbox.org>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Cc: 6.1+ <stable@vger.kernel.org> # 6.1+
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

cpufreq: brcmstb-avs-cpufreq: fix up "add check for cpufreq_cpu_get's return value" [+ + +]
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Wed Mar 27 15:21:45 2024 +0100

    cpufreq: brcmstb-avs-cpufreq: fix up "add check for cpufreq_cpu_get's return value"
    
    In commit e72160cb6e23 ("cpufreq: brcmstb-avs-cpufreq: add check for
    cpufreq_cpu_get's return value"), build warnings occur because a
    variable is created after some logic, resulting in:
    
    drivers/cpufreq/brcmstb-avs-cpufreq.c: In function 'brcm_avs_cpufreq_get':
    drivers/cpufreq/brcmstb-avs-cpufreq.c:486:9: error: ISO C90 forbids mixed
    declarations and code [-Werror=declaration-after-statement]
      486 |         struct private_data *priv = policy->driver_data;
          |         ^~~~~~
    cc1: all warnings being treated as errors
    make[2]: *** [scripts/Makefile.build:289:
    drivers/cpufreq/brcmstb-avs-cpufreq.o] Error 1
    make[1]: *** [scripts/Makefile.build:552: drivers/cpufreq] Error 2
    make[1]: *** Waiting for unfinished jobs....
    make: *** [Makefile:1907: drivers] Error 2
    
    Fix this up.
    
    Link: https://lore.kernel.org/r/e114d9e5-26af-42be-9baa-72c3a6ec8fe5@oracle.com
    Link: https://lore.kernel.org/stable/20240327015023.GC7502@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net/T/#m15bff0fe96986ef780e848b4fff362bf8ea03f08
    Reported-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
    Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
    Fixes: e72160cb6e23 ("cpufreq: brcmstb-avs-cpufreq: add check for cpufreq_cpu_get's return value")
    Cc: Anastasia Belova <abelova@astralinux.ru>
    Cc: Viresh Kumar <viresh.kumar@linaro.org>
    Cc: Sasha Levin <sashal@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

cpufreq: dt: always allocate zeroed cpumask [+ + +]
Author: Marek Szyprowski <m.szyprowski@samsung.com>
Date:   Thu Mar 14 13:54:57 2024 +0100

    cpufreq: dt: always allocate zeroed cpumask
    
    [ Upstream commit d2399501c2c081eac703ca9597ceb83c7875a537 ]
    
    Commit 0499a78369ad ("ARM64: Dynamically allocate cpumasks and increase
    supported CPUs to 512") changed the handling of cpumasks on ARM 64bit,
    what resulted in the strange issues and warnings during cpufreq-dt
    initialization on some big.LITTLE platforms.
    
    This was caused by mixing OPPs between big and LITTLE cores, because
    OPP-sharing information between big and LITTLE cores is computed on
    cpumask, which in turn was not zeroed on allocation. Fix this by
    switching to zalloc_cpumask_var() call.
    
    Fixes: dc279ac6e5b4 ("cpufreq: dt: Refactor initialization to handle probe deferral properly")
    CC: stable@vger.kernel.org # v5.10+
    Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
    Reviewed-by: Christoph Lameter (Ampere) <cl@linux.com>
    Reviewed-by: Dhruva Gole <d-gole@ti.com>
    Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

cpufreq: Limit resolving a frequency to policy min/max [+ + +]
Author: Shivnandan Kumar <quic_kshivnan@quicinc.com>
Date:   Tue Feb 27 14:43:51 2024 +0530

    cpufreq: Limit resolving a frequency to policy min/max
    
    [ Upstream commit d394abcb12bb1a6f309c1221fdb8e73594ecf1b4 ]
    
    Resolving a frequency to an efficient one should not transgress
    policy->max (which can be set for thermal reason) and policy->min.
    
    Currently, there is possibility where scaling_cur_freq can exceed
    scaling_max_freq when scaling_max_freq is an inefficient frequency.
    
    Add a check to ensure that resolving a frequency will respect
    policy->min/max.
    
    Cc: All applicable <stable@vger.kernel.org>
    Fixes: 1f39fa0dccff ("cpufreq: Introducing CPUFREQ_RELATION_E")
    Signed-off-by: Shivnandan Kumar <quic_kshivnan@quicinc.com>
    [ rjw: Whitespace adjustment, changelog edits ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
crypto: qat - fix double free during reset [+ + +]
Author: Svyatoslav Pankratov <svyatoslav.pankratov@intel.com>
Date:   Mon Oct 9 13:27:19 2023 +0100

    crypto: qat - fix double free during reset
    
    [ Upstream commit 01aed663e6c421aeafc9c330bda630976b50a764 ]
    
    There is no need to free the reset_data structure if the recovery is
    unsuccessful and the reset is synchronous. The function
    adf_dev_aer_schedule_reset() handles the cleanup properly. Only
    asynchronous resets require such structure to be freed inside the reset
    worker.
    
    Fixes: d8cba25d2c68 ("crypto: qat - Intel(R) QAT driver framework")
    Signed-off-by: Svyatoslav Pankratov <svyatoslav.pankratov@intel.com>
    Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
    Stable-dep-of: 7d42e097607c ("crypto: qat - resolve race condition during AER recovery")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

crypto: qat - resolve race condition during AER recovery [+ + +]
Author: Damian Muszynski <damian.muszynski@intel.com>
Date:   Fri Feb 9 13:43:42 2024 +0100

    crypto: qat - resolve race condition during AER recovery
    
    [ Upstream commit 7d42e097607c4d246d99225bf2b195b6167a210c ]
    
    During the PCI AER system's error recovery process, the kernel driver
    may encounter a race condition with freeing the reset_data structure's
    memory. If the device restart will take more than 10 seconds the function
    scheduling that restart will exit due to a timeout, and the reset_data
    structure will be freed. However, this data structure is used for
    completion notification after the restart is completed, which leads
    to a UAF bug.
    
    This results in a KFENCE bug notice.
    
      BUG: KFENCE: use-after-free read in adf_device_reset_worker+0x38/0xa0 [intel_qat]
      Use-after-free read at 0x00000000bc56fddf (in kfence-#142):
      adf_device_reset_worker+0x38/0xa0 [intel_qat]
      process_one_work+0x173/0x340
    
    To resolve this race condition, the memory associated to the container
    of the work_struct is freed on the worker if the timeout expired,
    otherwise on the function that schedules the worker.
    The timeout detection can be done by checking if the caller is
    still waiting for completion or not by using completion_done() function.
    
    Fixes: d8cba25d2c68 ("crypto: qat - Intel(R) QAT driver framework")
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Damian Muszynski <damian.muszynski@intel.com>
    Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
dm snapshot: fix lockup in dm_exception_table_exit [+ + +]
Author: Mikulas Patocka <mpatocka@redhat.com>
Date:   Wed Mar 20 18:43:11 2024 +0100

    dm snapshot: fix lockup in dm_exception_table_exit
    
    [ Upstream commit 6e7132ed3c07bd8a6ce3db4bb307ef2852b322dc ]
    
    There was reported lockup when we exit a snapshot with many exceptions.
    Fix this by adding "cond_resched" to the loop that frees the exceptions.
    
    Reported-by: John Pittman <jpittman@redhat.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
    Signed-off-by: Mike Snitzer <snitzer@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
dm-raid: fix lockdep waring in "pers->hot_add_disk" [+ + +]
Author: Yu Kuai <yukuai3@huawei.com>
Date:   Tue Mar 5 15:23:06 2024 +0800

    dm-raid: fix lockdep waring in "pers->hot_add_disk"
    
    [ Upstream commit 95009ae904b1e9dca8db6f649f2d7c18a6e42c75 ]
    
    The lockdep assert is added by commit a448af25becf ("md/raid10: remove
    rcu protection to access rdev from conf") in print_conf(). And I didn't
    notice that dm-raid is calling "pers->hot_add_disk" without holding
    'reconfig_mutex'.
    
    "pers->hot_add_disk" read and write many fields that is protected by
    'reconfig_mutex', and raid_resume() already grab the lock in other
    contex. Hence fix this problem by protecting "pers->host_add_disk"
    with the lock.
    
    Fixes: 9092c02d9435 ("DM RAID: Add ability to restore transiently failed devices on resume")
    Fixes: a448af25becf ("md/raid10: remove rcu protection to access rdev from conf")
    Cc: stable@vger.kernel.org # v6.7+
    Signed-off-by: Yu Kuai <yukuai3@huawei.com>
    Signed-off-by: Xiao Ni <xni@redhat.com>
    Acked-by: Mike Snitzer <snitzer@kernel.org>
    Signed-off-by: Song Liu <song@kernel.org>
    Link: https://lore.kernel.org/r/20240305072306.2562024-10-yukuai1@huaweicloud.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
Drivers: hv: vmbus: Calculate ring buffer size for more efficient use of memory [+ + +]
Author: Michael Kelley <mhklinux@outlook.com>
Date:   Wed Feb 28 16:45:33 2024 -0800

    Drivers: hv: vmbus: Calculate ring buffer size for more efficient use of memory
    
    commit b8209544296edbd1af186e2ea9c648642c37b18c upstream.
    
    The VMBUS_RING_SIZE macro adds space for a ring buffer header to the
    requested ring buffer size.  The header size is always 1 page, and so
    its size varies based on the PAGE_SIZE for which the kernel is built.
    If the requested ring buffer size is a large power-of-2 size and the header
    size is small, the resulting size is inefficient in its use of memory.
    For example, a 512 Kbyte ring buffer with a 4 Kbyte page size results in
    a 516 Kbyte allocation, which is rounded to up 1 Mbyte by the memory
    allocator, and wastes 508 Kbytes of memory.
    
    In such situations, the exact size of the ring buffer isn't that important,
    and it's OK to allocate the 4 Kbyte header at the beginning of the 512
    Kbytes, leaving the ring buffer itself with just 508 Kbytes. The memory
    allocation can be 512 Kbytes instead of 1 Mbyte and nothing is wasted.
    
    Update VMBUS_RING_SIZE to implement this approach for "large" ring buffer
    sizes.  "Large" is somewhat arbitrarily defined as 8 times the size of
    the ring buffer header (which is of size PAGE_SIZE).  For example, for
    4 Kbyte PAGE_SIZE, ring buffers of 32 Kbytes and larger use the first
    4 Kbytes as the ring buffer header.  For 64 Kbyte PAGE_SIZE, ring buffers
    of 512 Kbytes and larger use the first 64 Kbytes as the ring buffer
    header.  In both cases, smaller sizes add space for the header so
    the ring size isn't reduced too much by using part of the space for
    the header.  For example, with a 64 Kbyte page size, we don't want
    a 128 Kbyte ring buffer to be reduced to 64 Kbytes by allocating half
    of the space for the header.  In such a case, the memory allocation
    is less efficient, but it's the best that can be done.
    
    While the new algorithm slightly changes the amount of space allocated
    for ring buffers by drivers that use VMBUS_RING_SIZE, the devices aren't
    known to be sensitive to small changes in ring buffer size, so there
    shouldn't be any effect.
    
    Fixes: c1135c7fd0e9 ("Drivers: hv: vmbus: Introduce types of GPADL")
    Fixes: 6941f67ad37d ("hv_netvsc: Calculate correct ring size when PAGE_SIZE is not 4 Kbytes")
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218502
    Cc: stable@vger.kernel.org
    Signed-off-by: Michael Kelley <mhklinux@outlook.com>
    Reviewed-by: Saurabh Sengar <ssengar@linux.microsoft.com>
    Reviewed-by: Dexuan Cui <decui@microsoft.com>
    Tested-by: Souradeep Chakrabarti <schakrabarti@linux.microsoft.com>
    Link: https://lore.kernel.org/r/20240229004533.313662-1-mhklinux@outlook.com
    Signed-off-by: Wei Liu <wei.liu@kernel.org>
    Message-ID: <20240229004533.313662-1-mhklinux@outlook.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
drm/amd/display: Fix noise issue on HDMI AV mute [+ + +]
Author: Leo Ma <hanghong.ma@amd.com>
Date:   Fri Jul 28 08:35:07 2023 -0400

    drm/amd/display: Fix noise issue on HDMI AV mute
    
    [ Upstream commit 69e3be6893a7e668660b05a966bead82bbddb01d ]
    
    [Why]
    When mode switching is triggered there is momentary noise visible on
    some HDMI TV or displays.
    
    [How]
    Wait for 2 frames to make sure we have enough time to send out AV mute
    and sink receives a full frame.
    
    Cc: Mario Limonciello <mario.limonciello@amd.com>
    Cc: Alex Deucher <alexander.deucher@amd.com>
    Cc: stable@vger.kernel.org
    Reviewed-by: Wenjing Liu <wenjing.liu@amd.com>
    Acked-by: Wayne Lin <wayne.lin@amd.com>
    Signed-off-by: Leo Ma <hanghong.ma@amd.com>
    Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

drm/amd/display: handle range offsets in VRR ranges [+ + +]
Author: Alex Deucher <alexander.deucher@amd.com>
Date:   Wed Feb 28 15:59:22 2024 -0500

    drm/amd/display: handle range offsets in VRR ranges
    
    commit 937844d661354bf142dc1c621396fdab10ecbacc upstream.
    
    Need to check the offset bits for values greater than 255.
    
    v2: also update amdgpu_dm_connector values.
    
    Suggested-by: Mano Ségransan <mano.segransan@protonmail.com>
    Tested-by: Mano Ségransan <mano.segransan@protonmail.com>
    Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3203
    Reviewed-by: Harry Wentland <harry.wentland@amd.com>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

drm/amd/display: Return the correct HDCP error code [+ + +]
Author: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Date:   Wed Feb 14 13:29:51 2024 -0700

    drm/amd/display: Return the correct HDCP error code
    
    [ Upstream commit e64b3f55e458ce7e2087a0051f47edabf74545e7 ]
    
    [WHY & HOW]
    If the display is null when creating an HDCP session, return a proper
    error code.
    
    Cc: Mario Limonciello <mario.limonciello@amd.com>
    Cc: Alex Deucher <alexander.deucher@amd.com>
    Cc: stable@vger.kernel.org
    Acked-by: Alex Hung <alex.hung@amd.com>
    Signed-off-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
    Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
drm/amdgpu/pm: Fix the error of pwm1_enable setting [+ + +]
Author: Ma Jun <Jun.Ma2@amd.com>
Date:   Fri Mar 1 15:36:58 2024 +0800

    drm/amdgpu/pm: Fix the error of pwm1_enable setting
    
    commit 0dafaf659cc463f2db0af92003313a8bc46781cd upstream.
    
    Fix the pwm_mode value error which used for
    pwm1_enable setting
    
    Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
    Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
drm/amdgpu: amdgpu_ttm_gart_bind set gtt bound flag [+ + +]
Author: Philip Yang <Philip.Yang@amd.com>
Date:   Mon Mar 11 18:07:34 2024 -0400

    drm/amdgpu: amdgpu_ttm_gart_bind set gtt bound flag
    
    [ Upstream commit 6c6064cbe58b43533e3451ad6a8ba9736c109ac3 ]
    
    Otherwise after the GTT bo is released, the GTT and gart space is freed
    but amdgpu_ttm_backend_unbind will not clear the gart page table entry
    and leave valid mapping entry pointing to the stale system page. Then
    if GPU access the gart address mistakely, it will read undefined value
    instead page fault, harder to debug and reproduce the real issue.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Philip Yang <Philip.Yang@amd.com>
    Reviewed-by: Christian König <christian.koenig@amd.com>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
drm/amdkfd: fix TLB flush after unmap for GFX9.4.2 [+ + +]
Author: Eric Huang <jinhuieric.huang@amd.com>
Date:   Wed Mar 20 15:53:47 2024 -0400

    drm/amdkfd: fix TLB flush after unmap for GFX9.4.2
    
    commit 1210e2f1033dc56b666c9f6dfb761a2d3f9f5d6c upstream.
    
    TLB flush after unmap accidentially was removed on
    gfx9.4.2. It is to add it back.
    
    Signed-off-by: Eric Huang <jinhuieric.huang@amd.com>
    Reviewed-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
drm/etnaviv: Restore some id values [+ + +]
Author: Christian Gmeiner <cgmeiner@igalia.com>
Date:   Fri Mar 1 14:28:11 2024 +0100

    drm/etnaviv: Restore some id values
    
    [ Upstream commit b735ee173f84d5d0d0733c53946a83c12d770d05 ]
    
    The hwdb selection logic as a feature that allows it to mark some fields
    as 'don't care'. If we match with such a field we memcpy(..)
    the current etnaviv_chip_identity into ident.
    
    This step can overwrite some id values read from the GPU with the
    'don't care' value.
    
    Fix this issue by restoring the affected values after the memcpy(..).
    
    As this is crucial for user space to know when this feature works as
    expected increment the minor version too.
    
    Fixes: 4078a1186dd3 ("drm/etnaviv: update hwdb selection logic")
    Cc: stable@vger.kernel.org
    Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
    Reviewed-by: Tomeu Vizoso <tomeu@tomeuvizoso.net>
    Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
drm/exynos: do not return negative values from .get_modes() [+ + +]
Author: Jani Nikula <jani.nikula@intel.com>
Date:   Fri Mar 8 18:03:41 2024 +0200

    drm/exynos: do not return negative values from .get_modes()
    
    [ Upstream commit 13d5b040363c7ec0ac29c2de9cf661a24a8aa531 ]
    
    The .get_modes() hooks aren't supposed to return negative error
    codes. Return 0 for no modes, whatever the reason.
    
    Cc: Inki Dae <inki.dae@samsung.com>
    Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
    Cc: Kyungmin Park <kyungmin.park@samsung.com>
    Cc: stable@vger.kernel.org
    Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
    Link: https://patchwork.freedesktop.org/patch/msgid/d8665f620d9c252aa7d5a4811ff6b16e773903a2.1709913674.git.jani.nikula@intel.com
    Signed-off-by: Jani Nikula <jani.nikula@intel.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
drm/i915/bios: Tolerate devdata==NULL in intel_bios_encoder_supports_dp_dual_mode() [+ + +]
Author: Ville Syrjälä <ville.syrjala@linux.intel.com>
Date:   Tue Mar 19 11:24:42 2024 +0200

    drm/i915/bios: Tolerate devdata==NULL in intel_bios_encoder_supports_dp_dual_mode()
    
    commit 32e39bab59934bfd3f37097d4dd85ac5eb0fd549 upstream.
    
    If we have no VBT, or the VBT didn't declare the encoder
    in question, we won't have the 'devdata' for the encoder.
    Instead of oopsing just bail early.
    
    We won't be able to tell whether the port is DP++ or not,
    but so be it.
    
    Cc: stable@vger.kernel.org
    Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/10464
    Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
    Link: https://patchwork.freedesktop.org/patch/msgid/20240319092443.15769-1-ville.syrjala@linux.intel.com
    Reviewed-by: Jani Nikula <jani.nikula@intel.com>
    (cherry picked from commit 26410896206342c8a80d2b027923e9ee7d33b733)
    Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
drm/i915/gt: Reset queue_priority_hint on parking [+ + +]
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Mon Mar 18 14:58:47 2024 +0100

    drm/i915/gt: Reset queue_priority_hint on parking
    
    commit 4a3859ea5240365d21f6053ee219bb240d520895 upstream.
    
    Originally, with strict in order execution, we could complete execution
    only when the queue was empty. Preempt-to-busy allows replacement of an
    active request that may complete before the preemption is processed by
    HW. If that happens, the request is retired from the queue, but the
    queue_priority_hint remains set, preventing direct submission until
    after the next CS interrupt is processed.
    
    This preempt-to-busy race can be triggered by the heartbeat, which will
    also act as the power-management barrier and upon completion allow us to
    idle the HW. We may process the completion of the heartbeat, and begin
    parking the engine before the CS event that restores the
    queue_priority_hint, causing us to fail the assertion that it is MIN.
    
    <3>[  166.210729] __engine_park:283 GEM_BUG_ON(engine->sched_engine->queue_priority_hint != (-((int)(~0U >> 1)) - 1))
    <0>[  166.210781] Dumping ftrace buffer:
    <0>[  166.210795] ---------------------------------
    ...
    <0>[  167.302811] drm_fdin-1097      2..s1. 165741070us : trace_ports: 0000:00:02.0 rcs0: promote { ccid:20 1217:2 prio 0 }
    <0>[  167.302861] drm_fdin-1097      2d.s2. 165741072us : execlists_submission_tasklet: 0000:00:02.0 rcs0: preempting last=1217:2, prio=0, hint=2147483646
    <0>[  167.302928] drm_fdin-1097      2d.s2. 165741072us : __i915_request_unsubmit: 0000:00:02.0 rcs0: fence 1217:2, current 0
    <0>[  167.302992] drm_fdin-1097      2d.s2. 165741073us : __i915_request_submit: 0000:00:02.0 rcs0: fence 3:4660, current 4659
    <0>[  167.303044] drm_fdin-1097      2d.s1. 165741076us : execlists_submission_tasklet: 0000:00:02.0 rcs0: context:3 schedule-in, ccid:40
    <0>[  167.303095] drm_fdin-1097      2d.s1. 165741077us : trace_ports: 0000:00:02.0 rcs0: submit { ccid:40 3:4660* prio 2147483646 }
    <0>[  167.303159] kworker/-89       11..... 165741139us : i915_request_retire.part.0: 0000:00:02.0 rcs0: fence c90:2, current 2
    <0>[  167.303208] kworker/-89       11..... 165741148us : __intel_context_do_unpin: 0000:00:02.0 rcs0: context:c90 unpin
    <0>[  167.303272] kworker/-89       11..... 165741159us : i915_request_retire.part.0: 0000:00:02.0 rcs0: fence 1217:2, current 2
    <0>[  167.303321] kworker/-89       11..... 165741166us : __intel_context_do_unpin: 0000:00:02.0 rcs0: context:1217 unpin
    <0>[  167.303384] kworker/-89       11..... 165741170us : i915_request_retire.part.0: 0000:00:02.0 rcs0: fence 3:4660, current 4660
    <0>[  167.303434] kworker/-89       11d..1. 165741172us : __intel_context_retire: 0000:00:02.0 rcs0: context:1216 retire runtime: { total:56028ns, avg:56028ns }
    <0>[  167.303484] kworker/-89       11..... 165741198us : __engine_park: 0000:00:02.0 rcs0: parked
    <0>[  167.303534]   <idle>-0         5d.H3. 165741207us : execlists_irq_handler: 0000:00:02.0 rcs0: semaphore yield: 00000040
    <0>[  167.303583] kworker/-89       11..... 165741397us : __intel_context_retire: 0000:00:02.0 rcs0: context:1217 retire runtime: { total:325575ns, avg:0ns }
    <0>[  167.303756] kworker/-89       11..... 165741777us : __intel_context_retire: 0000:00:02.0 rcs0: context:c90 retire runtime: { total:0ns, avg:0ns }
    <0>[  167.303806] kworker/-89       11..... 165742017us : __engine_park: __engine_park:283 GEM_BUG_ON(engine->sched_engine->queue_priority_hint != (-((int)(~0U >> 1)) - 1))
    <0>[  167.303811] ---------------------------------
    <4>[  167.304722] ------------[ cut here ]------------
    <2>[  167.304725] kernel BUG at drivers/gpu/drm/i915/gt/intel_engine_pm.c:283!
    <4>[  167.304731] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI
    <4>[  167.304734] CPU: 11 PID: 89 Comm: kworker/11:1 Tainted: G        W          6.8.0-rc2-CI_DRM_14193-gc655e0fd2804+ #1
    <4>[  167.304736] Hardware name: Intel Corporation Rocket Lake Client Platform/RocketLake S UDIMM 6L RVP, BIOS RKLSFWI1.R00.3173.A03.2204210138 04/21/2022
    <4>[  167.304738] Workqueue: i915-unordered retire_work_handler [i915]
    <4>[  167.304839] RIP: 0010:__engine_park+0x3fd/0x680 [i915]
    <4>[  167.304937] Code: 00 48 c7 c2 b0 e5 86 a0 48 8d 3d 00 00 00 00 e8 79 48 d4 e0 bf 01 00 00 00 e8 ef 0a d4 e0 31 f6 bf 09 00 00 00 e8 03 49 c0 e0 <0f> 0b 0f 0b be 01 00 00 00 e8 f5 61 fd ff 31 c0 e9 34 fd ff ff 48
    <4>[  167.304940] RSP: 0018:ffffc9000059fce0 EFLAGS: 00010246
    <4>[  167.304942] RAX: 0000000000000200 RBX: 0000000000000000 RCX: 0000000000000006
    <4>[  167.304944] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000009
    <4>[  167.304946] RBP: ffff8881330ca1b0 R08: 0000000000000001 R09: 0000000000000001
    <4>[  167.304947] R10: 0000000000000001 R11: 0000000000000001 R12: ffff8881330ca000
    <4>[  167.304948] R13: ffff888110f02aa0 R14: ffff88812d1d0205 R15: ffff88811277d4f0
    <4>[  167.304950] FS:  0000000000000000(0000) GS:ffff88844f780000(0000) knlGS:0000000000000000
    <4>[  167.304952] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    <4>[  167.304953] CR2: 00007fc362200c40 CR3: 000000013306e003 CR4: 0000000000770ef0
    <4>[  167.304955] PKRU: 55555554
    <4>[  167.304957] Call Trace:
    <4>[  167.304958]  <TASK>
    <4>[  167.305573]  ____intel_wakeref_put_last+0x1d/0x80 [i915]
    <4>[  167.305685]  i915_request_retire.part.0+0x34f/0x600 [i915]
    <4>[  167.305800]  retire_requests+0x51/0x80 [i915]
    <4>[  167.305892]  intel_gt_retire_requests_timeout+0x27f/0x700 [i915]
    <4>[  167.305985]  process_scheduled_works+0x2db/0x530
    <4>[  167.305990]  worker_thread+0x18c/0x350
    <4>[  167.305993]  kthread+0xfe/0x130
    <4>[  167.305997]  ret_from_fork+0x2c/0x50
    <4>[  167.306001]  ret_from_fork_asm+0x1b/0x30
    <4>[  167.306004]  </TASK>
    
    It is necessary for the queue_priority_hint to be lower than the next
    request submission upon waking up, as we rely on the hint to decide when
    to kick the tasklet to submit that first request.
    
    Fixes: 22b7a426bbe1 ("drm/i915/execlists: Preempt-to-busy")
    Closes: https://gitlab.freedesktop.org/drm/intel/issues/10154
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
    Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
    Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
    Cc: <stable@vger.kernel.org> # v5.4+
    Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
    Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
    Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
    Link: https://patchwork.freedesktop.org/patch/msgid/20240318135906.716055-2-janusz.krzysztofik@linux.intel.com
    (cherry picked from commit 98850e96cf811dc2d0a7d0af491caff9f5d49c1e)
    Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
drm/i915: Check before removing mm notifier [+ + +]
Author: Nirmoy Das <nirmoy.das@intel.com>
Date:   Mon Feb 19 13:50:47 2024 +0100

    drm/i915: Check before removing mm notifier
    
    commit 01bb1ae35006e473138c90711bad1a6b614a1823 upstream.
    
    Error in mmu_interval_notifier_insert() can leave a NULL
    notifier.mm pointer. Catch that and return early.
    
    Fixes: ed29c2691188 ("drm/i915: Fix userptr so we do not have to worry about obj->mm.lock, v7.")
    Cc: <stable@vger.kernel.org> # v5.13+
    [tursulin: Added Fixes and cc stable.]
    Cc: Andi Shyti <andi.shyti@linux.intel.com>
    Cc: Shawn Lee <shawn.c.lee@intel.com>
    Signed-off-by: Nirmoy Das <nirmoy.das@intel.com>
    Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
    Link: https://patchwork.freedesktop.org/patch/msgid/20240219125047.28906-1-nirmoy.das@intel.com
    Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
    (cherry picked from commit db7bbd13f08774cde0332c705f042e327fe21e73)
    Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
drm/imx/ipuv3: do not return negative values from .get_modes() [+ + +]
Author: Jani Nikula <jani.nikula@intel.com>
Date:   Fri Mar 8 18:03:43 2024 +0200

    drm/imx/ipuv3: do not return negative values from .get_modes()
    
    [ Upstream commit c2da9ada64962fcd2e6395ed9987b9874ea032d3 ]
    
    The .get_modes() hooks aren't supposed to return negative error
    codes. Return 0 for no modes, whatever the reason.
    
    Cc: Philipp Zabel <p.zabel@pengutronix.de>
    Cc: stable@vger.kernel.org
    Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
    Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
    Link: https://patchwork.freedesktop.org/patch/msgid/311f6eec96d47949b16a670529f4d89fcd97aefa.1709913674.git.jani.nikula@intel.com
    Signed-off-by: Jani Nikula <jani.nikula@intel.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
drm/panel: do not return negative error codes from drm_panel_get_modes() [+ + +]
Author: Jani Nikula <jani.nikula@intel.com>
Date:   Fri Mar 8 18:03:40 2024 +0200

    drm/panel: do not return negative error codes from drm_panel_get_modes()
    
    [ Upstream commit fc4e97726530241d96dd7db72eb65979217422c9 ]
    
    None of the callers of drm_panel_get_modes() expect it to return
    negative error codes. Either they propagate the return value in their
    struct drm_connector_helper_funcs .get_modes() hook (which is also not
    supposed to return negative codes), or add it to other counts leading to
    bogus values.
    
    On the other hand, many of the struct drm_panel_funcs .get_modes() hooks
    do return negative error codes, so handle them gracefully instead of
    propagating further.
    
    Return 0 for no modes, whatever the reason.
    
    Cc: Neil Armstrong <neil.armstrong@linaro.org>
    Cc: Jessica Zhang <quic_jesszhan@quicinc.com>
    Cc: Sam Ravnborg <sam@ravnborg.org>
    Cc: stable@vger.kernel.org
    Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
    Reviewed-by: Jessica Zhang <quic_jesszhan@quicinc.com>
    Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
    Link: https://patchwork.freedesktop.org/patch/msgid/79f559b72d8c493940417304e222a4b04dfa19c4.1709913674.git.jani.nikula@intel.com
    Signed-off-by: Jani Nikula <jani.nikula@intel.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
drm/probe-helper: warn about negative .get_modes() [+ + +]
Author: Jani Nikula <jani.nikula@intel.com>
Date:   Fri Mar 8 18:03:39 2024 +0200

    drm/probe-helper: warn about negative .get_modes()
    
    [ Upstream commit 7af03e688792293ba33149fb8df619a8dff90e80 ]
    
    The .get_modes() callback is supposed to return the number of modes,
    never a negative error code. If a negative value is returned, it'll just
    be interpreted as a negative count, and added to previous calculations.
    
    Document the rules, but handle the negative values gracefully with an
    error message.
    
    Cc: stable@vger.kernel.org
    Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
    Link: https://patchwork.freedesktop.org/patch/msgid/50208c866facc33226a3c77b82bb96aeef8ef310.1709913674.git.jani.nikula@intel.com
    Signed-off-by: Jani Nikula <jani.nikula@intel.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
drm/vc4: hdmi: do not return negative values from .get_modes() [+ + +]
Author: Jani Nikula <jani.nikula@intel.com>
Date:   Fri Mar 8 18:03:44 2024 +0200

    drm/vc4: hdmi: do not return negative values from .get_modes()
    
    [ Upstream commit abf493988e380f25242c1023275c68bd3579c9ce ]
    
    The .get_modes() hooks aren't supposed to return negative error
    codes. Return 0 for no modes, whatever the reason.
    
    Cc: Maxime Ripard <mripard@kernel.org>
    Cc: stable@vger.kernel.org
    Acked-by: Maxime Ripard <mripard@kernel.org>
    Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
    Link: https://patchwork.freedesktop.org/patch/msgid/dcda6d4003e2c6192987916b35c7304732800e08.1709913674.git.jani.nikula@intel.com
    Signed-off-by: Jani Nikula <jani.nikula@intel.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
drm/vmwgfx: Create debugfs ttm_resource_manager entry only if needed [+ + +]
Author: Jocelyn Falempe <jfalempe@redhat.com>
Date:   Tue Mar 12 10:35:12 2024 +0100

    drm/vmwgfx: Create debugfs ttm_resource_manager entry only if needed
    
    commit 4be9075fec0a639384ed19975634b662bfab938f upstream.
    
    The driver creates /sys/kernel/debug/dri/0/mob_ttm even when the
    corresponding ttm_resource_manager is not allocated.
    This leads to a crash when trying to read from this file.
    
    Add a check to create mob_ttm, system_mob_ttm, and gmr_ttm debug file
    only when the corresponding ttm_resource_manager is allocated.
    
    crash> bt
    PID: 3133409  TASK: ffff8fe4834a5000  CPU: 3    COMMAND: "grep"
     #0 [ffffb954506b3b20] machine_kexec at ffffffffb2a6bec3
     #1 [ffffb954506b3b78] __crash_kexec at ffffffffb2bb598a
     #2 [ffffb954506b3c38] crash_kexec at ffffffffb2bb68c1
     #3 [ffffb954506b3c50] oops_end at ffffffffb2a2a9b1
     #4 [ffffb954506b3c70] no_context at ffffffffb2a7e913
     #5 [ffffb954506b3cc8] __bad_area_nosemaphore at ffffffffb2a7ec8c
     #6 [ffffb954506b3d10] do_page_fault at ffffffffb2a7f887
     #7 [ffffb954506b3d40] page_fault at ffffffffb360116e
        [exception RIP: ttm_resource_manager_debug+0x11]
        RIP: ffffffffc04afd11  RSP: ffffb954506b3df0  RFLAGS: 00010246
        RAX: ffff8fe41a6d1200  RBX: 0000000000000000  RCX: 0000000000000940
        RDX: 0000000000000000  RSI: ffffffffc04b4338  RDI: 0000000000000000
        RBP: ffffb954506b3e08   R8: ffff8fee3ffad000   R9: 0000000000000000
        R10: ffff8fe41a76a000  R11: 0000000000000001  R12: 00000000ffffffff
        R13: 0000000000000001  R14: ffff8fe5bb6f3900  R15: ffff8fe41a6d1200
        ORIG_RAX: ffffffffffffffff  CS: 0010  SS: 0018
     #8 [ffffb954506b3e00] ttm_resource_manager_show at ffffffffc04afde7 [ttm]
     #9 [ffffb954506b3e30] seq_read at ffffffffb2d8f9f3
        RIP: 00007f4c4eda8985  RSP: 00007ffdbba9e9f8  RFLAGS: 00000246
        RAX: ffffffffffffffda  RBX: 000000000037e000  RCX: 00007f4c4eda8985
        RDX: 000000000037e000  RSI: 00007f4c41573000  RDI: 0000000000000003
        RBP: 000000000037e000   R8: 0000000000000000   R9: 000000000037fe30
        R10: 0000000000000000  R11: 0000000000000246  R12: 00007f4c41573000
        R13: 0000000000000003  R14: 00007f4c41572010  R15: 0000000000000003
        ORIG_RAX: 0000000000000000  CS: 0033  SS: 002b
    
    Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
    Fixes: af4a25bbe5e7 ("drm/vmwgfx: Add debugfs entries for various ttm resource managers")
    Cc: <stable@vger.kernel.org>
    Reviewed-by: Zack Rusin <zack.rusin@broadcom.com>
    Link: https://patchwork.freedesktop.org/patch/msgid/20240312093551.196609-1-jfalempe@redhat.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

drm/vmwgfx: Fix possible null pointer derefence with invalid contexts [+ + +]
Author: Zack Rusin <zack.rusin@broadcom.com>
Date:   Wed Jan 10 15:03:05 2024 -0500

    drm/vmwgfx: Fix possible null pointer derefence with invalid contexts
    
    [ Upstream commit 517621b7060096e48e42f545fa6646fc00252eac ]
    
    vmw_context_cotable can return either an error or a null pointer and its
    usage sometimes went unchecked. Subsequent code would then try to access
    either a null pointer or an error value.
    
    The invalid dereferences were only possible with malformed userspace
    apps which never properly initialized the rendering contexts.
    
    Check the results of vmw_context_cotable to fix the invalid derefs.
    
    Thanks:
    ziming zhang(@ezrak1e) from Ant Group Light-Year Security Lab
    who was the first person to discover it.
    Niels De Graef who reported it and helped to track down the poc.
    
    Fixes: 9c079b8ce8bf ("drm/vmwgfx: Adapt execbuf to the new validation api")
    Cc: <stable@vger.kernel.org> # v4.20+
    Reported-by: Niels De Graef  <ndegraef@redhat.com>
    Signed-off-by: Zack Rusin <zack.rusin@broadcom.com>
    Cc: Martin Krastev <martin.krastev@broadcom.com>
    Cc: Maaz Mombasawala <maaz.mombasawala@broadcom.com>
    Cc: Ian Forbes <ian.forbes@broadcom.com>
    Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
    Cc: dri-devel@lists.freedesktop.org
    Reviewed-by: Maaz Mombasawala <maaz.mombasawala@broadcom.com>
    Reviewed-by: Martin Krastev <martin.krastev@broadcom.com>
    Link: https://patchwork.freedesktop.org/patch/msgid/20240110200305.94086-1-zack.rusin@broadcom.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
efi/libstub: Cast away type warning in use of max() [+ + +]
Author: Ard Biesheuvel <ardb@kernel.org>
Date:   Tue Mar 26 11:15:25 2024 +0100

    efi/libstub: Cast away type warning in use of max()
    
    commit 61d130f261a3c15ae2c4b6f3ac3517d5d5b78855 upstream.
    
    Avoid a type mismatch warning in max() by switching to max_t() and
    providing the type explicitly.
    
    Fixes: 3cb4a4827596abc82e ("efi/libstub: fix efi_random_alloc() ...")
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

efi/libstub: fix efi_random_alloc() to allocate memory at alloc_min or higher address [+ + +]
Author: KONDO KAZUMA(近藤 和真) <kazuma-kondo@nec.com>
Date:   Fri Mar 22 10:47:02 2024 +0000

    efi/libstub: fix efi_random_alloc() to allocate memory at alloc_min or higher address
    
    [ Upstream commit 3cb4a4827596abc82e55b80364f509d0fefc3051 ]
    
    Following warning is sometimes observed while booting my servers:
      [    3.594838] DMA: preallocated 4096 KiB GFP_KERNEL pool for atomic allocations
      [    3.602918] swapper/0: page allocation failure: order:10, mode:0xcc1(GFP_KERNEL|GFP_DMA), nodemask=(null),cpuset=/,mems_allowed=0-1
      ...
      [    3.851862] DMA: preallocated 1024 KiB GFP_KERNEL|GFP_DMA pool for atomic allocation
    
    If 'nokaslr' boot option is set, the warning always happens.
    
    On x86, ZONE_DMA is small zone at the first 16MB of physical address
    space. When this problem happens, most of that space seems to be used by
    decompressed kernel. Thereby, there is not enough space at DMA_ZONE to
    meet the request of DMA pool allocation.
    
    The commit 2f77465b05b1 ("x86/efistub: Avoid placing the kernel below
    LOAD_PHYSICAL_ADDR") tried to fix this problem by introducing lower
    bound of allocation.
    
    But the fix is not complete.
    
    efi_random_alloc() allocates pages by following steps.
    1. Count total available slots ('total_slots')
    2. Select a slot ('target_slot') to allocate randomly
    3. Calculate a starting address ('target') to be included target_slot
    4. Allocate pages, which starting address is 'target'
    
    In step 1, 'alloc_min' is used to offset the starting address of memory
    chunk. But in step 3 'alloc_min' is not considered at all.  As the
    result, 'target' can be miscalculated and become lower than 'alloc_min'.
    
    When KASLR is disabled, 'target_slot' is always 0 and the problem
    happens everytime if the EFI memory map of the system meets the
    condition.
    
    Fix this problem by calculating 'target' considering 'alloc_min'.
    
    Cc: linux-efi@vger.kernel.org
    Cc: Tom Englund <tomenglund26@gmail.com>
    Cc: linux-kernel@vger.kernel.org
    Fixes: 2f77465b05b1 ("x86/efistub: Avoid placing the kernel below LOAD_PHYSICAL_ADDR")
    Signed-off-by: Kazuma Kondo <kazuma-kondo@nec.com>
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
efi: fix panic in kdump kernel [+ + +]
Author: Oleksandr Tymoshenko <ovt@google.com>
Date:   Sat Mar 23 06:33:33 2024 +0000

    efi: fix panic in kdump kernel
    
    [ Upstream commit 62b71cd73d41ddac6b1760402bbe8c4932e23531 ]
    
    Check if get_next_variable() is actually valid pointer before
    calling it. In kdump kernel this method is set to NULL that causes
    panic during the kexec-ed kernel boot.
    
    Tested with QEMU and OVMF firmware.
    
    Fixes: bad267f9e18f ("efi: verify that variable services are supported")
    Signed-off-by: Oleksandr Tymoshenko <ovt@google.com>
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
entry: Respect changes to system call number by trace_sys_enter() [+ + +]
Author: André Rösti <an.roesti@gmail.com>
Date:   Mon Mar 11 21:17:04 2024 +0000

    entry: Respect changes to system call number by trace_sys_enter()
    
    [ Upstream commit fb13b11d53875e28e7fbf0c26b288e4ea676aa9f ]
    
    When a probe is registered at the trace_sys_enter() tracepoint, and that
    probe changes the system call number, the old system call still gets
    executed.  This worked correctly until commit b6ec41346103 ("core/entry:
    Report syscall correctly for trace and audit"), which removed the
    re-evaluation of the syscall number after the trace point.
    
    Restore the original semantics by re-evaluating the system call number
    after trace_sys_enter().
    
    The performance impact of this re-evaluation is minimal because it only
    takes place when a trace point is active, and compared to the actual trace
    point overhead the read from a cache hot variable is negligible.
    
    Fixes: b6ec41346103 ("core/entry: Report syscall correctly for trace and audit")
    Signed-off-by: André Rösti <an.roesti@gmail.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/r/20240311211704.7262-1-an.roesti@gmail.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
exec: Fix NOMMU linux_binprm::exec in transfer_args_to_stack() [+ + +]
Author: Max Filippov <jcmvbkbc@gmail.com>
Date:   Wed Mar 20 11:26:07 2024 -0700

    exec: Fix NOMMU linux_binprm::exec in transfer_args_to_stack()
    
    commit 2aea94ac14d1e0a8ae9e34febebe208213ba72f7 upstream.
    
    In NOMMU kernel the value of linux_binprm::p is the offset inside the
    temporary program arguments array maintained in separate pages in the
    linux_binprm::page. linux_binprm::exec being a copy of linux_binprm::p
    thus must be adjusted when that array is copied to the user stack.
    Without that adjustment the value passed by the NOMMU kernel to the ELF
    program in the AT_EXECFN entry of the aux array doesn't make any sense
    and it may break programs that try to access memory pointed to by that
    entry.
    
    Adjust linux_binprm::exec before the successful return from the
    transfer_args_to_stack().
    
    Cc: <stable@vger.kernel.org>
    Fixes: b6a2fea39318 ("mm: variable length argument support")
    Fixes: 5edc2a5123a7 ("binfmt_elf_fdpic: wire up AT_EXECFD, AT_EXECFN, AT_SECURE")
    Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
    Link: https://lore.kernel.org/r/20240320182607.1472887-1-jcmvbkbc@gmail.com
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
ext4: correct best extent lstart adjustment logic [+ + +]
Author: Baokun Li <libaokun1@huawei.com>
Date:   Thu Feb 1 22:18:45 2024 +0800

    ext4: correct best extent lstart adjustment logic
    
    [ Upstream commit 4fbf8bc733d14bceb16dda46a3f5e19c6a9621c5 ]
    
    When yangerkun review commit 93cdf49f6eca ("ext4: Fix best extent lstart
    adjustment logic in ext4_mb_new_inode_pa()"), it was found that the best
    extent did not completely cover the original request after adjusting the
    best extent lstart in ext4_mb_new_inode_pa() as follows:
    
      original request: 2/10(8)
      normalized request: 0/64(64)
      best extent: 0/9(9)
    
    When we check if best ex can be kept at start of goal, ac_o_ex.fe_logical
    is 2 less than the adjusted best extent logical end 9, so we think the
    adjustment is done. But obviously 0/9(9) doesn't cover 2/10(8), so we
    should determine here if the original request logical end is less than or
    equal to the adjusted best extent logical end.
    
    In addition, add a comment stating when adjusted best_ex will not cover
    the original request, and remove the duplicate assertion because adjusting
    lstart makes no change to b_ex.fe_len.
    
    Link: https://lore.kernel.org/r/3630fa7f-b432-7afd-5f79-781bc3b2c5ea@huawei.com
    Fixes: 93cdf49f6eca ("ext4: Fix best extent lstart adjustment logic in ext4_mb_new_inode_pa()")
    Cc:  <stable@kernel.org>
    Signed-off-by: yangerkun <yangerkun@huawei.com>
    Signed-off-by: Baokun Li <libaokun1@huawei.com>
    Reviewed-by: Jan Kara <jack@suse.cz>
    Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
    Link: https://lore.kernel.org/r/20240201141845.1879253-1-libaokun1@huawei.com
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

ext4: fix corruption during on-line resize [+ + +]
Author: Maximilian Heyne <mheyne@amazon.de>
Date:   Thu Feb 15 15:50:09 2024 +0000

    ext4: fix corruption during on-line resize
    
    [ Upstream commit a6b3bfe176e8a5b05ec4447404e412c2a3fc92cc ]
    
    We observed a corruption during on-line resize of a file system that is
    larger than 16 TiB with 4k block size. With having more then 2^32 blocks
    resize_inode is turned off by default by mke2fs. The issue can be
    reproduced on a smaller file system for convenience by explicitly
    turning off resize_inode. An on-line resize across an 8 GiB boundary (the
    size of a meta block group in this setup) then leads to a corruption:
    
      dev=/dev/<some_dev> # should be >= 16 GiB
      mkdir -p /corruption
      /sbin/mke2fs -t ext4 -b 4096 -O ^resize_inode $dev $((2 * 2**21 - 2**15))
      mount -t ext4 $dev /corruption
    
      dd if=/dev/zero bs=4096 of=/corruption/test count=$((2*2**21 - 4*2**15))
      sha1sum /corruption/test
      # 79d2658b39dcfd77274e435b0934028adafaab11  /corruption/test
    
      /sbin/resize2fs $dev $((2*2**21))
      # drop page cache to force reload the block from disk
      echo 1 > /proc/sys/vm/drop_caches
    
      sha1sum /corruption/test
      # 3c2abc63cbf1a94c9e6977e0fbd72cd832c4d5c3  /corruption/test
    
    2^21 = 2^15*2^6 equals 8 GiB whereof 2^15 is the number of blocks per
    block group and 2^6 are the number of block groups that make a meta
    block group.
    
    The last checksum might be different depending on how the file is laid
    out across the physical blocks. The actual corruption occurs at physical
    block 63*2^15 = 2064384 which would be the location of the backup of the
    meta block group's block descriptor. During the on-line resize the file
    system will be converted to meta_bg starting at s_first_meta_bg which is
    2 in the example - meaning all block groups after 16 GiB. However, in
    ext4_flex_group_add we might add block groups that are not part of the
    first meta block group yet. In the reproducer we achieved this by
    substracting the size of a whole block group from the point where the
    meta block group would start. This must be considered when updating the
    backup block group descriptors to follow the non-meta_bg layout. The fix
    is to add a test whether the group to add is already part of the meta
    block group or not.
    
    Fixes: 01f795f9e0d67 ("ext4: add online resizing support for meta_bg and 64-bit file systems")
    Cc:  <stable@vger.kernel.org>
    Signed-off-by: Maximilian Heyne <mheyne@amazon.de>
    Tested-by: Srivathsa Dara <srivathsa.d.dara@oracle.com>
    Reviewed-by: Srivathsa Dara <srivathsa.d.dara@oracle.com>
    Link: https://lore.kernel.org/r/20240215155009.94493-1-mheyne@amazon.de
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
f2fs: mark inode dirty for FI_ATOMIC_COMMITTED flag [+ + +]
Author: Sunmin Jeong <s_min.jeong@samsung.com>
Date:   Wed Mar 13 20:26:19 2024 +0900

    f2fs: mark inode dirty for FI_ATOMIC_COMMITTED flag
    
    [ Upstream commit 4bf78322346f6320313683dc9464e5423423ad5c ]
    
    In f2fs_update_inode, i_size of the atomic file isn't updated until
    FI_ATOMIC_COMMITTED flag is set. When committing atomic write right
    after the writeback of the inode, i_size of the raw inode will not be
    updated. It can cause the atomicity corruption due to a mismatch between
    old file size and new data.
    
    To prevent the problem, let's mark inode dirty for FI_ATOMIC_COMMITTED
    
    Atomic write thread                   Writeback thread
                                            __writeback_single_inode
                                              write_inode
                                                f2fs_update_inode
                                                  - skip i_size update
      f2fs_ioc_commit_atomic_write
        f2fs_commit_atomic_write
          set_inode_flag(inode, FI_ATOMIC_COMMITTED)
        f2fs_do_sync_file
          f2fs_fsync_node_pages
            - skip f2fs_update_inode since the inode is clean
    
    Fixes: 3db1de0e582c ("f2fs: change the current atomic write way")
    Cc: stable@vger.kernel.org #v5.19+
    Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
    Reviewed-by: Yeongjin Gil <youngjin.gil@samsung.com>
    Signed-off-by: Sunmin Jeong <s_min.jeong@samsung.com>
    Reviewed-by: Daeho Jeong <daehojeong@google.com>
    Reviewed-by: Chao Yu <chao@kernel.org>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

f2fs: truncate page cache before clearing flags when aborting atomic write [+ + +]
Author: Sunmin Jeong <s_min.jeong@samsung.com>
Date:   Wed Mar 13 20:26:20 2024 +0900

    f2fs: truncate page cache before clearing flags when aborting atomic write
    
    [ Upstream commit 74b0ebcbdde4c7fe23c979e4cfc2fdbf349c39a3 ]
    
    In f2fs_do_write_data_page, FI_ATOMIC_FILE flag selects the target inode
    between the original inode and COW inode. When aborting atomic write and
    writeback occur simultaneously, invalid data can be written to original
    inode if the FI_ATOMIC_FILE flag is cleared meanwhile.
    
    To prevent the problem, let's truncate all pages before clearing the flag
    
    Atomic write thread              Writeback thread
      f2fs_abort_atomic_write
        clear_inode_flag(inode, FI_ATOMIC_FILE)
                                      __writeback_single_inode
                                        do_writepages
                                          f2fs_do_write_data_page
                                            - use dn of original inode
        truncate_inode_pages_final
    
    Fixes: 3db1de0e582c ("f2fs: change the current atomic write way")
    Cc: stable@vger.kernel.org #v5.19+
    Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
    Reviewed-by: Yeongjin Gil <youngjin.gil@samsung.com>
    Signed-off-by: Sunmin Jeong <s_min.jeong@samsung.com>
    Reviewed-by: Daeho Jeong <daehojeong@google.com>
    Reviewed-by: Chao Yu <chao@kernel.org>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
fat: fix uninitialized field in nostale filehandles [+ + +]
Author: Jan Kara <jack@suse.cz>
Date:   Mon Feb 5 13:26:26 2024 +0100

    fat: fix uninitialized field in nostale filehandles
    
    [ Upstream commit fde2497d2bc3a063d8af88b258dbadc86bd7b57c ]
    
    When fat_encode_fh_nostale() encodes file handle without a parent it
    stores only first 10 bytes of the file handle. However the length of the
    file handle must be a multiple of 4 so the file handle is actually 12
    bytes long and the last two bytes remain uninitialized. This is not
    great at we potentially leak uninitialized information with the handle
    to userspace. Properly initialize the full handle length.
    
    Link: https://lkml.kernel.org/r/20240205122626.13701-1-jack@suse.cz
    Reported-by: syzbot+3ce5dea5b1539ff36769@syzkaller.appspotmail.com
    Fixes: ea3983ace6b7 ("fat: restructure export_operations")
    Signed-off-by: Jan Kara <jack@suse.cz>
    Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
    Cc: Amir Goldstein <amir73il@gmail.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
fs/aio: Check IOCB_AIO_RW before the struct aio_kiocb conversion [+ + +]
Author: Bart Van Assche <bvanassche@acm.org>
Date:   Mon Mar 4 15:57:15 2024 -0800

    fs/aio: Check IOCB_AIO_RW before the struct aio_kiocb conversion
    
    commit 961ebd120565cb60cebe21cb634fbc456022db4a upstream.
    
    The first kiocb_set_cancel_fn() argument may point at a struct kiocb
    that is not embedded inside struct aio_kiocb. With the current code,
    depending on the compiler, the req->ki_ctx read happens either before
    the IOCB_AIO_RW test or after that test. Move the req->ki_ctx read such
    that it is guaranteed that the IOCB_AIO_RW test happens first.
    
    Reported-by: Eric Biggers <ebiggers@kernel.org>
    Cc: Benjamin LaHaise <ben@communityfibre.ca>
    Cc: Eric Biggers <ebiggers@google.com>
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: Avi Kivity <avi@scylladb.com>
    Cc: Sandeep Dhavale <dhavale@google.com>
    Cc: Jens Axboe <axboe@kernel.dk>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Kent Overstreet <kent.overstreet@linux.dev>
    Cc: stable@vger.kernel.org
    Fixes: b820de741ae4 ("fs/aio: Restrict kiocb_set_cancel_fn() to I/O submitted via libaio")
    Signed-off-by: Bart Van Assche <bvanassche@acm.org>
    Link: https://lore.kernel.org/r/20240304235715.3790858-1-bvanassche@acm.org
    Reviewed-by: Jens Axboe <axboe@kernel.dk>
    Reviewed-by: Eric Biggers <ebiggers@google.com>
    Signed-off-by: Christian Brauner <brauner@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
fuse: don't unhash root [+ + +]
Author: Miklos Szeredi <mszeredi@redhat.com>
Date:   Wed Feb 28 16:50:49 2024 +0100

    fuse: don't unhash root
    
    [ Upstream commit b1fe686a765e6c0d71811d825b5a1585a202b777 ]
    
    The root inode is assumed to be always hashed.  Do not unhash the root
    inode even if it is marked BAD.
    
    Fixes: 5d069dbe8aaf ("fuse: fix bad inode")
    Cc: <stable@vger.kernel.org> # v5.11
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

fuse: fix root lookup with nonzero generation [+ + +]
Author: Miklos Szeredi <mszeredi@redhat.com>
Date:   Wed Feb 28 16:50:49 2024 +0100

    fuse: fix root lookup with nonzero generation
    
    [ Upstream commit 68ca1b49e430f6534d0774a94147a823e3b8b26e ]
    
    The root inode has a fixed nodeid and generation (1, 0).
    
    Prior to the commit 15db16837a35 ("fuse: fix illegal access to inode with
    reused nodeid") generation number on lookup was ignored.  After this commit
    lookup with the wrong generation number resulted in the inode being
    unhashed.  This is correct for non-root inodes, but replacing the root
    inode is wrong and results in weird behavior.
    
    Fix by reverting to the old behavior if ignoring the generation for the
    root inode, but issuing a warning in dmesg.
    
    Reported-by: Antonio SJ Musumeci <trapexit@spawn.link>
    Closes: https://lore.kernel.org/all/CAOQ4uxhek5ytdN8Yz2tNEOg5ea4NkBb4nk0FGPjPk_9nz-VG3g@mail.gmail.com/
    Fixes: 15db16837a35 ("fuse: fix illegal access to inode with reused nodeid")
    Cc: <stable@vger.kernel.org> # v5.14
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
hexagon: vmlinux.lds.S: handle attributes section [+ + +]
Author: Nathan Chancellor <nathan@kernel.org>
Date:   Tue Mar 19 17:37:46 2024 -0700

    hexagon: vmlinux.lds.S: handle attributes section
    
    commit 549aa9678a0b3981d4821bf244579d9937650562 upstream.
    
    After the linked LLVM change, the build fails with
    CONFIG_LD_ORPHAN_WARN_LEVEL="error", which happens with allmodconfig:
    
      ld.lld: error: vmlinux.a(init/main.o):(.hexagon.attributes) is being placed in '.hexagon.attributes'
    
    Handle the attributes section in a similar manner as arm and riscv by
    adding it after the primary ELF_DETAILS grouping in vmlinux.lds.S, which
    fixes the error.
    
    Link: https://lkml.kernel.org/r/20240319-hexagon-handle-attributes-section-vmlinux-lds-s-v1-1-59855dab8872@kernel.org
    Fixes: 113616ec5b64 ("hexagon: select ARCH_WANT_LD_ORPHAN_WARN")
    Link: https://github.com/llvm/llvm-project/commit/31f4b329c8234fab9afa59494d7f8bdaeaefeaad
    Signed-off-by: Nathan Chancellor <nathan@kernel.org>
    Reviewed-by: Brian Cain <bcain@quicinc.com>
    Cc: Bill Wendling <morbo@google.com>
    Cc: Justin Stitt <justinstitt@google.com>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
hwmon: (amc6821) add of_match table [+ + +]
Author: Josua Mayer <josua@solid-run.com>
Date:   Thu Mar 7 12:06:58 2024 +0100

    hwmon: (amc6821) add of_match table
    
    [ Upstream commit 3f003fda98a7a8d5f399057d92e6ed56b468657c ]
    
    Add of_match table for "ti,amc6821" compatible string.
    This fixes automatic driver loading by userspace when using device-tree,
    and if built as a module like major linux distributions do.
    
    While devices probe just fine with i2c_device_id table, userspace can't
    match the "ti,amc6821" compatible string from dt with the plain
    "amc6821" device id. As a result, the kernel module can not be loaded.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Josua Mayer <josua@solid-run.com>
    Link: https://lore.kernel.org/r/20240307-amc6821-of-match-v1-1-5f40464a3110@solid-run.com
    [groeck: Cleaned up patch description]
    Signed-off-by: Guenter Roeck <linux@roeck-us.net>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
i2c: i801: Avoid potential double call to gpiod_remove_lookup_table [+ + +]
Author: Heiner Kallweit <hkallweit1@gmail.com>
Date:   Mon Mar 4 21:31:06 2024 +0100

    i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
    
    commit ceb013b2d9a2946035de5e1827624edc85ae9484 upstream.
    
    If registering the platform device fails, the lookup table is
    removed in the error path. On module removal we would try to
    remove the lookup table again. Fix this by setting priv->lookup
    only if registering the platform device was successful.
    In addition free the memory allocated for the lookup table in
    the error path.
    
    Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
    Cc: stable@vger.kernel.org
    Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
    Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
    Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
    Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
iio: accel: adxl367: fix DEVID read after reset [+ + +]
Author: Cosmin Tanislav <demonsingur@gmail.com>
Date:   Wed Feb 7 05:36:50 2024 +0200

    iio: accel: adxl367: fix DEVID read after reset
    
    commit 1b926914bbe4e30cb32f268893ef7d82a85275b8 upstream.
    
    regmap_read_poll_timeout() will not sleep before reading,
    causing the first read to return -ENXIO on I2C, since the
    chip does not respond to it while it is being reset.
    
    The datasheet specifies that a soft reset operation has a
    latency of 7.5ms.
    
    Add a 15ms sleep between reset and reading the DEVID register,
    and switch to a simple regmap_read() call.
    
    Fixes: cbab791c5e2a ("iio: accel: add ADXL367 driver")
    Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com>
    Reviewed-by: Nuno Sa <nuno.sa@analog.com>
    Link: https://lore.kernel.org/r/20240207033657.206171-1-demonsingur@gmail.com
    Cc: <Stable@vger.kernel.org>
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

iio: accel: adxl367: fix I2C FIFO data register [+ + +]
Author: Cosmin Tanislav <demonsingur@gmail.com>
Date:   Wed Feb 7 05:36:51 2024 +0200

    iio: accel: adxl367: fix I2C FIFO data register
    
    commit 11dadb631007324c7a8bcb2650eda88ed2b9eed0 upstream.
    
    As specified in the datasheet, the I2C FIFO data register is
    0x18, not 0x42. 0x42 was used by mistake when adapting the
    ADXL372 driver.
    
    Fix this mistake.
    
    Fixes: cbab791c5e2a ("iio: accel: add ADXL367 driver")
    Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com>
    Reviewed-by: Nuno Sa <nuno.sa@analog.com>
    Link: https://lore.kernel.org/r/20240207033657.206171-2-demonsingur@gmail.com
    Cc: <Stable@vger.kernel.org>
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
init/Kconfig: lower GCC version check for -Warray-bounds [+ + +]
Author: Kees Cook <keescook@chromium.org>
Date:   Fri Feb 23 09:08:27 2024 -0800

    init/Kconfig: lower GCC version check for -Warray-bounds
    
    commit 3e00f5802fabf2f504070a591b14b648523ede13 upstream.
    
    We continue to see false positives from -Warray-bounds even in GCC 10,
    which is getting reported in a few places[1] still:
    
    security/security.c:811:2: warning: `memcpy' offset 32 is out of the bounds [0, 0] [-Warray-bounds]
    
    Lower the GCC version check from 11 to 10.
    
    Link: https://lkml.kernel.org/r/20240223170824.work.768-kees@kernel.org
    Reported-by: Lu Yao <yaolu@kylinos.cn>
    Closes: https://lore.kernel.org/lkml/20240117014541.8887-1-yaolu@kylinos.cn/
    Link: https://lore.kernel.org/linux-next/65d84438.620a0220.7d171.81a7@mx.google.com [1]
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Reviewed-by: Paul Moore <paul@paul-moore.com>
    Cc: Ard Biesheuvel <ardb@kernel.org>
    Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Marc Aurèle La France <tsi@tuyoix.net>
    Cc: Masahiro Yamada <masahiroy@kernel.org>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nhat Pham <nphamcs@gmail.com>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Randy Dunlap <rdunlap@infradead.org>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
init: open /initrd.image with O_LARGEFILE [+ + +]
Author: John Sperbeck <jsperbeck@google.com>
Date:   Sun Mar 17 15:15:22 2024 -0700

    init: open /initrd.image with O_LARGEFILE
    
    commit 4624b346cf67400ef46a31771011fb798dd2f999 upstream.
    
    If initrd data is larger than 2Gb, we'll eventually fail to write to the
    /initrd.image file when we hit that limit, unless O_LARGEFILE is set.
    
    Link: https://lkml.kernel.org/r/20240317221522.896040-1-jsperbeck@google.com
    Signed-off-by: John Sperbeck <jsperbeck@google.com>
    Cc: Jens Axboe <axboe@kernel.dk>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
io_uring/net: correctly handle multishot recvmsg retry setup [+ + +]
Author: Jens Axboe <axboe@kernel.dk>
Date:   Thu Mar 7 17:48:03 2024 -0700

    io_uring/net: correctly handle multishot recvmsg retry setup
    
    [ Upstream commit deaef31bc1ec7966698a427da8c161930830e1cf ]
    
    If we loop for multishot receive on the initial attempt, and then abort
    later on to wait for more, we miss a case where we should be copying the
    io_async_msghdr from the stack to stable storage. This leads to the next
    retry potentially failing, if the application had the msghdr on the
    stack.
    
    Cc: stable@vger.kernel.org
    Fixes: 9bb66906f23e ("io_uring: support multishot in recvmsg")
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
iommu/dma: Force swiotlb_max_mapping_size on an untrusted device [+ + +]
Author: Nicolin Chen <nicolinc@nvidia.com>
Date:   Fri Mar 8 15:28:28 2024 +0000

    iommu/dma: Force swiotlb_max_mapping_size on an untrusted device
    
    [ Upstream commit afc5aa46ed560f01ceda897c053c6a40c77ce5c4 ]
    
    The swiotlb does not support a mapping size > swiotlb_max_mapping_size().
    On the other hand, with a 64KB PAGE_SIZE configuration, it's observed that
    an NVME device can map a size between 300KB~512KB, which certainly failed
    the swiotlb mappings, though the default pool of swiotlb has many slots:
        systemd[1]: Started Journal Service.
     => nvme 0000:00:01.0: swiotlb buffer is full (sz: 327680 bytes), total 32768 (slots), used 32 (slots)
        note: journal-offline[392] exited with irqs disabled
        note: journal-offline[392] exited with preempt_count 1
    
    Call trace:
    [    3.099918]  swiotlb_tbl_map_single+0x214/0x240
    [    3.099921]  iommu_dma_map_page+0x218/0x328
    [    3.099928]  dma_map_page_attrs+0x2e8/0x3a0
    [    3.101985]  nvme_prep_rq.part.0+0x408/0x878 [nvme]
    [    3.102308]  nvme_queue_rqs+0xc0/0x300 [nvme]
    [    3.102313]  blk_mq_flush_plug_list.part.0+0x57c/0x600
    [    3.102321]  blk_add_rq_to_plug+0x180/0x2a0
    [    3.102323]  blk_mq_submit_bio+0x4c8/0x6b8
    [    3.103463]  __submit_bio+0x44/0x220
    [    3.103468]  submit_bio_noacct_nocheck+0x2b8/0x360
    [    3.103470]  submit_bio_noacct+0x180/0x6c8
    [    3.103471]  submit_bio+0x34/0x130
    [    3.103473]  ext4_bio_write_folio+0x5a4/0x8c8
    [    3.104766]  mpage_submit_folio+0xa0/0x100
    [    3.104769]  mpage_map_and_submit_buffers+0x1a4/0x400
    [    3.104771]  ext4_do_writepages+0x6a0/0xd78
    [    3.105615]  ext4_writepages+0x80/0x118
    [    3.105616]  do_writepages+0x90/0x1e8
    [    3.105619]  filemap_fdatawrite_wbc+0x94/0xe0
    [    3.105622]  __filemap_fdatawrite_range+0x68/0xb8
    [    3.106656]  file_write_and_wait_range+0x84/0x120
    [    3.106658]  ext4_sync_file+0x7c/0x4c0
    [    3.106660]  vfs_fsync_range+0x3c/0xa8
    [    3.106663]  do_fsync+0x44/0xc0
    
    Since untrusted devices might go down the swiotlb pathway with dma-iommu,
    these devices should not map a size larger than swiotlb_max_mapping_size.
    
    To fix this bug, add iommu_dma_max_mapping_size() for untrusted devices to
    take into account swiotlb_max_mapping_size() v.s. iova_rcache_range() from
    the iommu_dma_opt_mapping_size().
    
    Fixes: 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers")
    Link: https://lore.kernel.org/r/ee51a3a5c32cf885b18f6416171802669f4a718a.1707851466.git.nicolinc@nvidia.com
    Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
    [will: Drop redundant is_swiotlb_active(dev) check]
    Signed-off-by: Will Deacon <will@kernel.org>
    Reviewed-by: Michael Kelley <mhklinux@outlook.com>
    Acked-by: Robin Murphy <robin.murphy@arm.com>
    Tested-by: Nicolin Chen <nicolinc@nvidia.com>
    Tested-by: Michael Kelley <mhklinux@outlook.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
iommu: Avoid races around default domain allocations [+ + +]
Author: Charan Teja Kalla <quic_charante@quicinc.com>
Date:   Mon Mar 4 16:40:50 2024 +0530

    iommu: Avoid races around default domain allocations
    
    This fix is applicable for LTS kernel, 6.1.y. In latest kernels, this race
    issue is fixed by the patch series [1] and [2]. The right thing to do here
    would have been propagating these changes from latest kernel to the stable
    branch, 6.1.y. However, these changes seems too intrusive to be picked for
    stable branches. Hence, the fix proposed can be taken as an alternative
    instead of backporting the patch series.
    [1] https://lore.kernel.org/all/0-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com/
    [2] https://lore.kernel.org/all/0-v5-1b99ae392328+44574-iommu_err_unwind_jgg@nvidia.com/
    
    Issue:
    A race condition is observed when arm_smmu_device_probe and
    modprobe of client devices happens in parallel. This results
    in the allocation of a new default domain for the iommu group
    even though it was previously allocated and the respective iova
    domain(iovad) was initialized. However, for this newly allocated
    default domain, iovad will not be initialized. As a result, for
    devices requesting dma allocations, this uninitialized iovad will
    be used, thereby causing NULL pointer dereference issue.
    
    Flow:
    - During arm_smmu_device_probe, bus_iommu_probe() will be called
    as part of iommu_device_register(). This results in the device probe,
    __iommu_probe_device().
    
    - When the modprobe of the client device happens in parallel, it
    sets up the DMA configuration for the device using of_dma_configure_id(),
    which inturn calls iommu_probe_device(). Later, default domain is
    allocated and attached using iommu_alloc_default_domain() and
    __iommu_attach_device() respectively. It then ends up initializing a
    mapping domain(IOVA domain) and rcaches for the device via
    arch_setup_dma_ops()->iommu_setup_dma_ops().
    
    - Now, in the bus_iommu_probe() path, it again tries to allocate
    a default domain via probe_alloc_default_domain(). This results in
    allocating a new default domain(along with IOVA domain) via
    __iommu_domain_alloc(). However, this newly allocated IOVA domain
    will not be initialized.
    
    - Now, when the same client device tries dma allocations via
    iommu_dma_alloc(), it ends up accessing the rcaches of the newly
    allocated IOVA domain, which is not initialized. This results
    into NULL pointer dereferencing.
    
    Fix this issue by adding a check in probe_alloc_default_domain()
    to see if the iommu_group already has a default domain allocated
    and initialized.
    
    Cc: <stable@vger.kernel.org> # see patch description, fix applicable only for 6.1.y
    Signed-off-by: Charan Teja Kalla <quic_charante@quicinc.com>
    Co-developed-by: Nikhil V <quic_nprakash@quicinc.com>
    Signed-off-by: Nikhil V <quic_nprakash@quicinc.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
irqchip/renesas-rzg2l: Add macro to retrieve TITSR register offset based on register's index [+ + +]
Author: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Date:   Mon Nov 20 13:18:17 2023 +0200

    irqchip/renesas-rzg2l: Add macro to retrieve TITSR register offset based on register's index
    
    [ Upstream commit 2eca4731cc66563b3919d8753dbd74d18c39f662 ]
    
    There are 2 TITSR registers available on the IA55 interrupt controller.
    
    Add a macro that retrieves the TITSR register offset based on it's
    index. This macro is useful in when adding suspend/resume support so both
    TITSR registers can be accessed in a for loop.
    
    Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/r/20231120111820.87398-7-claudiu.beznea.uj@bp.renesas.com
    Stable-dep-of: 853a6030303f ("irqchip/renesas-rzg2l: Prevent spurious interrupts when setting trigger type")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

irqchip/renesas-rzg2l: Flush posted write in irq_eoi() [+ + +]
Author: Biju Das <biju.das.jz@bp.renesas.com>
Date:   Tue Mar 5 18:39:18 2024 +0000

    irqchip/renesas-rzg2l: Flush posted write in irq_eoi()
    
    [ Upstream commit 9eec61df55c51415409c7cc47e9a1c8de94a0522 ]
    
    The irq_eoi() callback of the RZ/G2L interrupt chip clears the relevant
    interrupt cause bit in the TSCR register by writing to it.
    
    This write is not sufficient because the write is posted and therefore not
    guaranteed to immediately clear the bit. Due to that delay the CPU can
    raise the just handled interrupt again.
    
    Prevent this by reading the register back which causes the posted write to
    be flushed to the hardware before the read completes.
    
    Fixes: 3fed09559cd8 ("irqchip: Add RZ/G2L IA55 Interrupt Controller driver")
    Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

irqchip/renesas-rzg2l: Implement restriction when writing ISCR register [+ + +]
Author: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Date:   Mon Nov 20 13:18:16 2023 +0200

    irqchip/renesas-rzg2l: Implement restriction when writing ISCR register
    
    [ Upstream commit ef88eefb1a81a8701eabb7d5ced761a66a465a49 ]
    
    The RZ/G2L manual (chapter "IRQ Status Control Register (ISCR)") describes
    the operation to clear interrupts through the ISCR register as follows:
    
    [Write operation]
    
      When "Falling-edge detection", "Rising-edge detection" or
      "Falling/Rising-edge detection" is set in IITSR:
    
        - In case ISTAT is 1
            0: IRQn interrupt detection status is cleared.
            1: Invalid to write.
        - In case ISTAT is 0
            Invalid to write.
    
      When "Low-level detection" is set in IITSR.:
            Invalid to write.
    
    Take the interrupt type into account when clearing interrupts through the
    ISCR register to avoid writing the ISCR when the interrupt type is level.
    
    Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
    Link: https://lore.kernel.org/r/20231120111820.87398-6-claudiu.beznea.uj@bp.renesas.com
    Stable-dep-of: 9eec61df55c5 ("irqchip/renesas-rzg2l: Flush posted write in irq_eoi()")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

irqchip/renesas-rzg2l: Prevent spurious interrupts when setting trigger type [+ + +]
Author: Biju Das <biju.das.jz@bp.renesas.com>
Date:   Tue Mar 5 18:39:21 2024 +0000

    irqchip/renesas-rzg2l: Prevent spurious interrupts when setting trigger type
    
    [ Upstream commit 853a6030303f8a8fa54929b68e5665d9b21aa405 ]
    
    RZ/G2L interrupt chips require that the interrupt is masked before changing
    the NMI, IRQ, TINT interrupt settings. Aside of that, after setting an edge
    trigger type it is required to clear the interrupt status register in order
    to avoid spurious interrupts.
    
    The current implementation fails to do either of that and therefore is
    prone to generate spurious interrupts when setting the trigger type.
    
    Address this by:
    
      - Ensuring that the interrupt is masked at the chip level across the
        update for the TINT chip
    
      - Clearing the interrupt status register after updating the trigger mode
        for edge type interrupts
    
    [ tglx: Massaged changelog and reverted the spin_lock_irqsave() change as
            the set_type() callback is always called with interrupts disabled. ]
    
    Fixes: 3fed09559cd8 ("irqchip: Add RZ/G2L IA55 Interrupt Controller driver")
    Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

irqchip/renesas-rzg2l: Rename rzg2l_irq_eoi() [+ + +]
Author: Biju Das <biju.das.jz@bp.renesas.com>
Date:   Tue Mar 5 18:39:20 2024 +0000

    irqchip/renesas-rzg2l: Rename rzg2l_irq_eoi()
    
    [ Upstream commit b4b5cd61a6fdd92ede0dc39f0850a182affd1323 ]
    
    Rename rzg2l_irq_eoi()->rzg2l_clear_irq_int() and simplify the code by
    removing redundant priv local variable.
    
    Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
    Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Stable-dep-of: 853a6030303f ("irqchip/renesas-rzg2l: Prevent spurious interrupts when setting trigger type")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

irqchip/renesas-rzg2l: Rename rzg2l_tint_eoi() [+ + +]
Author: Biju Das <biju.das.jz@bp.renesas.com>
Date:   Tue Mar 5 18:39:19 2024 +0000

    irqchip/renesas-rzg2l: Rename rzg2l_tint_eoi()
    
    [ Upstream commit 7cb6362c63df233172eaecddaf9ce2ce2f769112 ]
    
    Rename rzg2l_tint_eoi()->rzg2l_clear_tint_int() and simplify the code by
    removing redundant priv and hw_irq local variables.
    
    Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
    Stable-dep-of: 853a6030303f ("irqchip/renesas-rzg2l: Prevent spurious interrupts when setting trigger type")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
kasan/test: avoid gcc warning for intentional overflow [+ + +]
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Mon Feb 12 12:15:52 2024 +0100

    kasan/test: avoid gcc warning for intentional overflow
    
    [ Upstream commit e10aea105e9ed14b62a11844fec6aaa87c6935a3 ]
    
    The out-of-bounds test allocates an object that is three bytes too short
    in order to validate the bounds checking.  Starting with gcc-14, this
    causes a compile-time warning as gcc has grown smart enough to understand
    the sizeof() logic:
    
    mm/kasan/kasan_test.c: In function 'kmalloc_oob_16':
    mm/kasan/kasan_test.c:443:14: error: allocation of insufficient size '13' for type 'struct <anonymous>' with size '16' [-Werror=alloc-size]
      443 |         ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL);
          |              ^
    
    Hide the actual computation behind a RELOC_HIDE() that ensures
    the compiler misses the intentional bug.
    
    Link: https://lkml.kernel.org/r/20240212111609.869266-1-arnd@kernel.org
    Fixes: 3f15801cdc23 ("lib: add kasan test module")
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
    Cc: Alexander Potapenko <glider@google.com>
    Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Dmitry Vyukov <dvyukov@google.com>
    Cc: Marco Elver <elver@google.com>
    Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 [+ + +]
Author: Nathan Chancellor <nathan@kernel.org>
Date:   Tue Mar 5 15:12:47 2024 -0700

    kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1
    
    [ Upstream commit 75b5ab134bb5f657ef7979a59106dce0657e8d87 ]
    
    Clang enables -Wenum-enum-conversion and -Wenum-compare-conditional
    under -Wenum-conversion. A recent change in Clang strengthened these
    warnings and they appear frequently in common builds, primarily due to
    several instances in common headers but there are quite a few drivers
    that have individual instances as well.
    
      include/linux/vmstat.h:508:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
        508 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
            |                            ~~~~~~~~~~~~~~~~~~~~~ ^
        509 |                            item];
            |                            ~~~~
    
      drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c:955:24: warning: conditional expression between different enumeration types ('enum iwl_mac_beacon_flags' and 'enum iwl_mac_beacon_flags_v1') [-Wenum-compare-conditional]
        955 |                 flags |= is_new_rate ? IWL_MAC_BEACON_CCK
            |                                      ^ ~~~~~~~~~~~~~~~~~~
        956 |                           : IWL_MAC_BEACON_CCK_V1;
            |                             ~~~~~~~~~~~~~~~~~~~~~
      drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c:1120:21: warning: conditional expression between different enumeration types ('enum iwl_mac_beacon_flags' and 'enum iwl_mac_beacon_flags_v1') [-Wenum-compare-conditional]
       1120 |                                                0) > 10 ?
            |                                                        ^
       1121 |                         IWL_MAC_BEACON_FILS :
            |                         ~~~~~~~~~~~~~~~~~~~
       1122 |                         IWL_MAC_BEACON_FILS_V1;
            |                         ~~~~~~~~~~~~~~~~~~~~~~
    
    Doing arithmetic between or returning two different types of enums could
    be a bug, so each of the instance of the warning needs to be evaluated.
    Unfortunately, as mentioned above, there are many instances of this
    warning in many different configurations, which can break the build when
    CONFIG_WERROR is enabled.
    
    To avoid introducing new instances of the warnings while cleaning up the
    disruption for the majority of users, disable these warnings for the
    default build while leaving them on for W=1 builds.
    
    Cc: stable@vger.kernel.org
    Closes: https://github.com/ClangBuiltLinux/linux/issues/2002
    Link: https://github.com/llvm/llvm-project/commit/8c2ae42b3e1c6aa7c18f873edcebff7c0b45a37e
    Acked-by: Yonghong Song <yonghong.song@linux.dev>
    Signed-off-by: Nathan Chancellor <nathan@kernel.org>
    Acked-by: Arnd Bergmann <arnd@arndb.de>
    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
kprobes/x86: Use copy_from_kernel_nofault() to read from unsafe address [+ + +]
Author: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Date:   Fri Mar 15 00:17:30 2024 +0900

    kprobes/x86: Use copy_from_kernel_nofault() to read from unsafe address
    
    [ Upstream commit 4e51653d5d871f40f1bd5cf95cc7f2d8b33d063b ]
    
    Read from an unsafe address with copy_from_kernel_nofault() in
    arch_adjust_kprobe_addr() because this function is used before checking
    the address is in text or not. Syzcaller bot found a bug and reported
    the case if user specifies inaccessible data area,
    arch_adjust_kprobe_addr() will cause a kernel panic.
    
    [ mingo: Clarified the comment. ]
    
    Fixes: cc66bb914578 ("x86/ibt,kprobes: Cure sym+0 equals fentry woes")
    Reported-by: Qiang Zhang <zzqq0103.hey@gmail.com>
    Tested-by: Jinghao Jia <jinghao7@illinois.edu>
    Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/171042945004.154897.2221804961882915806.stgit@devnote2
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
ksmbd: retrieve number of blocks using vfs_getattr in set_file_allocation_info [+ + +]
Author: Marios Makassikis <mmakassikis@freebox.fr>
Date:   Thu Feb 22 10:58:21 2024 +0100

    ksmbd: retrieve number of blocks using vfs_getattr in set_file_allocation_info
    
    [ Upstream commit 34cd86b6632718b7df3999d96f51e63de41c5e4f ]
    
    Use vfs_getattr() to retrieve stat information, rather than make
    assumptions about how a filesystem fills inode structs.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
    Acked-by: Namjae Jeon <linkinjeon@kernel.org>
    Signed-off-by: Steve French <stfrench@microsoft.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
KVM: Always flush async #PF workqueue when vCPU is being destroyed [+ + +]
Author: Sean Christopherson <seanjc@google.com>
Date:   Tue Jan 9 17:15:30 2024 -0800

    KVM: Always flush async #PF workqueue when vCPU is being destroyed
    
    [ Upstream commit 3d75b8aa5c29058a512db29da7cbee8052724157 ]
    
    Always flush the per-vCPU async #PF workqueue when a vCPU is clearing its
    completion queue, e.g. when a VM and all its vCPUs is being destroyed.
    KVM must ensure that none of its workqueue callbacks is running when the
    last reference to the KVM _module_ is put.  Gifting a reference to the
    associated VM prevents the workqueue callback from dereferencing freed
    vCPU/VM memory, but does not prevent the KVM module from being unloaded
    before the callback completes.
    
    Drop the misguided VM refcount gifting, as calling kvm_put_kvm() from
    async_pf_execute() if kvm_put_kvm() flushes the async #PF workqueue will
    result in deadlock.  async_pf_execute() can't return until kvm_put_kvm()
    finishes, and kvm_put_kvm() can't return until async_pf_execute() finishes:
    
     WARNING: CPU: 8 PID: 251 at virt/kvm/kvm_main.c:1435 kvm_put_kvm+0x2d/0x320 [kvm]
     Modules linked in: vhost_net vhost vhost_iotlb tap kvm_intel kvm irqbypass
     CPU: 8 PID: 251 Comm: kworker/8:1 Tainted: G        W          6.6.0-rc1-e7af8d17224a-x86/gmem-vm #119
     Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
     Workqueue: events async_pf_execute [kvm]
     RIP: 0010:kvm_put_kvm+0x2d/0x320 [kvm]
     Call Trace:
      <TASK>
      async_pf_execute+0x198/0x260 [kvm]
      process_one_work+0x145/0x2d0
      worker_thread+0x27e/0x3a0
      kthread+0xba/0xe0
      ret_from_fork+0x2d/0x50
      ret_from_fork_asm+0x11/0x20
      </TASK>
     ---[ end trace 0000000000000000 ]---
     INFO: task kworker/8:1:251 blocked for more than 120 seconds.
           Tainted: G        W          6.6.0-rc1-e7af8d17224a-x86/gmem-vm #119
     "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
     task:kworker/8:1     state:D stack:0     pid:251   ppid:2      flags:0x00004000
     Workqueue: events async_pf_execute [kvm]
     Call Trace:
      <TASK>
      __schedule+0x33f/0xa40
      schedule+0x53/0xc0
      schedule_timeout+0x12a/0x140
      __wait_for_common+0x8d/0x1d0
      __flush_work.isra.0+0x19f/0x2c0
      kvm_clear_async_pf_completion_queue+0x129/0x190 [kvm]
      kvm_arch_destroy_vm+0x78/0x1b0 [kvm]
      kvm_put_kvm+0x1c1/0x320 [kvm]
      async_pf_execute+0x198/0x260 [kvm]
      process_one_work+0x145/0x2d0
      worker_thread+0x27e/0x3a0
      kthread+0xba/0xe0
      ret_from_fork+0x2d/0x50
      ret_from_fork_asm+0x11/0x20
      </TASK>
    
    If kvm_clear_async_pf_completion_queue() actually flushes the workqueue,
    then there's no need to gift async_pf_execute() a reference because all
    invocations of async_pf_execute() will be forced to complete before the
    vCPU and its VM are destroyed/freed.  And that in turn fixes the module
    unloading bug as __fput() won't do module_put() on the last vCPU reference
    until the vCPU has been freed, e.g. if closing the vCPU file also puts the
    last reference to the KVM module.
    
    Note that kvm_check_async_pf_completion() may also take the work item off
    the completion queue and so also needs to flush the work queue, as the
    work will not be seen by kvm_clear_async_pf_completion_queue().  Waiting
    on the workqueue could theoretically delay a vCPU due to waiting for the
    work to complete, but that's a very, very small chance, and likely a very
    small delay.  kvm_arch_async_page_present_queued() unconditionally makes a
    new request, i.e. will effectively delay entering the guest, so the
    remaining work is really just:
    
            trace_kvm_async_pf_completed(addr, cr2_or_gpa);
    
            __kvm_vcpu_wake_up(vcpu);
    
            mmput(mm);
    
    and mmput() can't drop the last reference to the page tables if the vCPU is
    still alive, i.e. the vCPU won't get stuck tearing down page tables.
    
    Add a helper to do the flushing, specifically to deal with "wakeup all"
    work items, as they aren't actually work items, i.e. are never placed in a
    workqueue.  Trying to flush a bogus workqueue entry rightly makes
    __flush_work() complain (kudos to whoever added that sanity check).
    
    Note, commit 5f6de5cbebee ("KVM: Prevent module exit until all VMs are
    freed") *tried* to fix the module refcounting issue by having VMs grab a
    reference to the module, but that only made the bug slightly harder to hit
    as it gave async_pf_execute() a bit more time to complete before the KVM
    module could be unloaded.
    
    Fixes: af585b921e5d ("KVM: Halt vcpu if page it tries to access is swapped out")
    Cc: stable@vger.kernel.org
    Cc: David Matlack <dmatlack@google.com>
    Reviewed-by: Xu Yilun <yilun.xu@intel.com>
    Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
    Link: https://lore.kernel.org/r/20240110011533.503302-2-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

KVM: SVM: Flush pages under kvm->lock to fix UAF in svm_register_enc_region() [+ + +]
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri Feb 16 17:34:30 2024 -0800

    KVM: SVM: Flush pages under kvm->lock to fix UAF in svm_register_enc_region()
    
    commit 5ef1d8c1ddbf696e47b226e11888eaf8d9e8e807 upstream.
    
    Do the cache flush of converted pages in svm_register_enc_region() before
    dropping kvm->lock to fix use-after-free issues where region and/or its
    array of pages could be freed by a different task, e.g. if userspace has
    __unregister_enc_region_locked() already queued up for the region.
    
    Note, the "obvious" alternative of using local variables doesn't fully
    resolve the bug, as region->pages is also dynamically allocated.  I.e. the
    region structure itself would be fine, but region->pages could be freed.
    
    Flushing multiple pages under kvm->lock is unfortunate, but the entire
    flow is a rare slow path, and the manual flush is only needed on CPUs that
    lack coherency for encrypted memory.
    
    Fixes: 19a23da53932 ("Fix unsynchronized access to sev members through svm_register_enc_region")
    Reported-by: Gabe Kirkpatrick <gkirkpatrick@google.com>
    Cc: Josh Eads <josheads@google.com>
    Cc: Peter Gonda <pgonda@google.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20240217013430.2079561-1-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

KVM: x86/xen: inject vCPU upcall vector when local APIC is enabled [+ + +]
Author: David Woodhouse <dwmw@amazon.co.uk>
Date:   Tue Feb 27 11:49:16 2024 +0000

    KVM: x86/xen: inject vCPU upcall vector when local APIC is enabled
    
    [ Upstream commit 8e62bf2bfa46367e14d0ffdcde5aada08759497c ]
    
    Linux guests since commit b1c3497e604d ("x86/xen: Add support for
    HVMOP_set_evtchn_upcall_vector") in v6.0 onwards will use the per-vCPU
    upcall vector when it's advertised in the Xen CPUID leaves.
    
    This upcall is injected through the guest's local APIC as an MSI, unlike
    the older system vector which was merely injected by the hypervisor any
    time the CPU was able to receive an interrupt and the upcall_pending
    flags is set in its vcpu_info.
    
    Effectively, that makes the per-CPU upcall edge triggered instead of
    level triggered, which results in the upcall being lost if the MSI is
    delivered when the local APIC is *disabled*.
    
    Xen checks the vcpu_info->evtchn_upcall_pending flag when the local APIC
    for a vCPU is software enabled (in fact, on any write to the SPIV
    register which doesn't disable the APIC). Do the same in KVM since KVM
    doesn't provide a way for userspace to intervene and trap accesses to
    the SPIV register of a local APIC emulated by KVM.
    
    Fixes: fde0451be8fb3 ("KVM: x86/xen: Support per-vCPU event channel upcall via local APIC")
    Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
    Reviewed-by: Paul Durrant <paul@xen.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240227115648.3104-3-dwmw2@infradead.org
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

KVM: x86: Advertise CPUID.(EAX=7,ECX=2):EDX[5:0] to userspace [+ + +]
Author: Jim Mattson <jmattson@google.com>
Date:   Mon Oct 23 17:16:35 2023 -0700

    KVM: x86: Advertise CPUID.(EAX=7,ECX=2):EDX[5:0] to userspace
    
    commit eefe5e6682099445f77f2d97d4c525f9ac9d9b07 upstream.
    
    The low five bits {INTEL_PSFD, IPRED_CTRL, RRSBA_CTRL, DDPD_U, BHI_CTRL}
    advertise the availability of specific bits in IA32_SPEC_CTRL. Since KVM
    dynamically determines the legal IA32_SPEC_CTRL bits for the underlying
    hardware, the hard work has already been done. Just let userspace know
    that a guest can use these IA32_SPEC_CTRL bits.
    
    The sixth bit (MCDT_NO) states that the processor does not exhibit MXCSR
    Configuration Dependent Timing (MCDT) behavior. This is an inherent
    property of the physical processor that is inherited by the virtual
    CPU. Pass that information on to userspace.
    
    Signed-off-by: Jim Mattson <jmattson@google.com>
    Reviewed-by: Chao Gao <chao.gao@intel.com>
    Link: https://lore.kernel.org/r/20231024001636.890236-1-jmattson@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

KVM: x86: Mark target gfn of emulated atomic instruction as dirty [+ + +]
Author: Sean Christopherson <seanjc@google.com>
Date:   Wed Feb 14 17:00:03 2024 -0800

    KVM: x86: Mark target gfn of emulated atomic instruction as dirty
    
    commit 910c57dfa4d113aae6571c2a8b9ae8c430975902 upstream.
    
    When emulating an atomic access on behalf of the guest, mark the target
    gfn dirty if the CMPXCHG by KVM is attempted and doesn't fault.  This
    fixes a bug where KVM effectively corrupts guest memory during live
    migration by writing to guest memory without informing userspace that the
    page is dirty.
    
    Marking the page dirty got unintentionally dropped when KVM's emulated
    CMPXCHG was converted to do a user access.  Before that, KVM explicitly
    mapped the guest page into kernel memory, and marked the page dirty during
    the unmap phase.
    
    Mark the page dirty even if the CMPXCHG fails, as the old data is written
    back on failure, i.e. the page is still written.  The value written is
    guaranteed to be the same because the operation is atomic, but KVM's ABI
    is that all writes are dirty logged regardless of the value written.  And
    more importantly, that's what KVM did before the buggy commit.
    
    Huge kudos to the folks on the Cc list (and many others), who did all the
    actual work of triaging and debugging.
    
    Fixes: 1c2361f667f3 ("KVM: x86: Use __try_cmpxchg_user() to emulate atomic accesses")
    Cc: stable@vger.kernel.org
    Cc: David Matlack <dmatlack@google.com>
    Cc: Pasha Tatashin <tatashin@google.com>
    Cc: Michael Krebs <mkrebs@google.com>
    base-commit: 6769ea8da8a93ed4630f1ce64df6aafcaabfce64
    Reviewed-by: Jim Mattson <jmattson@google.com>
    Link: https://lore.kernel.org/r/20240215010004.1456078-2-seanjc@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

KVM: x86: Update KVM-only leaf handling to allow for 100% KVM-only leafs [+ + +]
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri Nov 25 20:58:39 2022 +0800

    KVM: x86: Update KVM-only leaf handling to allow for 100% KVM-only leafs
    
    commit 047c7229906152fb85c23dc18fd25a00cd7cb4de upstream.
    
    Rename kvm_cpu_cap_init_scattered() to kvm_cpu_cap_init_kvm_defined() in
    anticipation of adding KVM-only CPUID leafs that aren't recognized by the
    kernel and thus not scattered, i.e. for leafs that are 100% KVM-defined.
    
    Adjust/add comments to kvm_only_cpuid_leafs and KVM_X86_FEATURE to
    document how to create new kvm_only_cpuid_leafs entries for scattered
    features as well as features that are entirely unknown to the kernel.
    
    No functional change intended.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20221125125845.1182922-3-jiaxi.chen@linux.intel.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

KVM: x86: Use a switch statement and macros in __feature_translate() [+ + +]
Author: Jim Mattson <jmattson@google.com>
Date:   Mon Oct 23 17:16:36 2023 -0700

    KVM: x86: Use a switch statement and macros in __feature_translate()
    
    commit 80c883db87d9ffe2d685e91ba07a087b1c246c78 upstream.
    
    Use a switch statement with macro-generated case statements to handle
    translating feature flags in order to reduce the probability of runtime
    errors due to copy+paste goofs, to make compile-time errors easier to
    debug, and to make the code more readable.
    
    E.g. the compiler won't directly generate an error for duplicate if
    statements
    
            if (x86_feature == X86_FEATURE_SGX1)
                    return KVM_X86_FEATURE_SGX1;
            else if (x86_feature == X86_FEATURE_SGX2)
                    return KVM_X86_FEATURE_SGX1;
    
    and so instead reverse_cpuid_check() will fail due to the untranslated
    entry pointing at a Linux-defined leaf, which provides practically no
    hint as to what is broken
    
      arch/x86/kvm/reverse_cpuid.h:108:2: error: call to __compiletime_assert_450 declared with 'error' attribute:
                                          BUILD_BUG_ON failed: x86_leaf == CPUID_LNX_4
              BUILD_BUG_ON(x86_leaf == CPUID_LNX_4);
              ^
    whereas duplicate case statements very explicitly point at the offending
    code:
    
      arch/x86/kvm/reverse_cpuid.h:125:2: error: duplicate case value '361'
              KVM_X86_TRANSLATE_FEATURE(SGX2);
              ^
      arch/x86/kvm/reverse_cpuid.h:124:2: error: duplicate case value '360'
              KVM_X86_TRANSLATE_FEATURE(SGX1);
              ^
    
    And without macros, the opposite type of copy+paste goof doesn't generate
    any error at compile-time, e.g. this yields no complaints:
    
            case X86_FEATURE_SGX1:
                    return KVM_X86_FEATURE_SGX1;
            case X86_FEATURE_SGX2:
                    return KVM_X86_FEATURE_SGX1;
    
    Note, __feature_translate() is forcibly inlined and the feature is known
    at compile-time, so the code generation between an if-elif sequence and a
    switch statement should be identical.
    
    Signed-off-by: Jim Mattson <jmattson@google.com>
    Link: https://lore.kernel.org/r/20231024001636.890236-2-jmattson@google.com
    [sean: use a macro, rewrite changelog]
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
landlock: Warn once if a Landlock action is requested while disabled [+ + +]
Author: Mickaël Salaün <mic@digikod.net>
Date:   Tue Feb 27 12:05:50 2024 +0100

    landlock: Warn once if a Landlock action is requested while disabled
    
    [ Upstream commit 782191c74875cc33b50263e21d76080b1411884d ]
    
    Because sandboxing can be used as an opportunistic security measure,
    user space may not log unsupported features.  Let the system
    administrator know if an application tries to use Landlock but failed
    because it isn't enabled at boot time.  This may be caused by boot
    loader configurations with outdated "lsm" kernel's command-line
    parameter.
    
    Cc: stable@vger.kernel.org
    Fixes: 265885daf3e5 ("landlock: Add syscall implementations")
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Reviewed-by: Günther Noack <gnoack3000@gmail.com>
    Link: https://lore.kernel.org/r/20240227110550.3702236-2-mic@digikod.net
    Signed-off-by: Mickaël Salaün <mic@digikod.net>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
Linux: Linux 6.1.84 [+ + +]
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Wed Apr 3 15:19:55 2024 +0200

    Linux 6.1.84
    
    Link: https://lore.kernel.org/r/20240401152530.237785232@linuxfoundation.org
    Tested-by: SeongJae Park <sj@kernel.org>
    Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
    Tested-by: Pavel Machek (CIP) <pavel@denx.de>
    Tested-by: Shuah Khan <skhan@linuxfoundation.org>
    Tested-by: Kelsey Steele <kelseysteele@linux.microsoft.com>
    Tested-by: Ron Economos <re@w6rz.net>
    Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
    Tested-by: Mark Brown <broonie@kernel.org>
    Tested-by: Mateusz Jończyk <mat.jonczyk@o2.pl>
    Tested-by: Jon Hunter <jonathanh@nvidia.com>
    Tested-by: Salvatore Bonaccorso <carnil@debian.org>
    Tested-by: Yann Sionneau <ysionneau@kalrayinc.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
LoongArch: Change __my_cpu_offset definition to avoid mis-optimization [+ + +]
Author: Huacai Chen <chenhuacai@kernel.org>
Date:   Tue Mar 19 15:50:34 2024 +0800

    LoongArch: Change __my_cpu_offset definition to avoid mis-optimization
    
    [ Upstream commit c87e12e0e8c1241410e758e181ca6bf23efa5b5b ]
    
    From GCC commit 3f13154553f8546a ("df-scan: remove ad-hoc handling of
    global regs in asms"), global registers will no longer be forced to add
    to the def-use chain. Then current_thread_info(), current_stack_pointer
    and __my_cpu_offset may be lifted out of the loop because they are no
    longer treated as "volatile variables".
    
    This optimization is still correct for the current_thread_info() and
    current_stack_pointer usages because they are associated to a thread.
    However it is wrong for __my_cpu_offset because it is associated to a
    CPU rather than a thread: if the thread migrates to a different CPU in
    the loop, __my_cpu_offset should be changed.
    
    Change __my_cpu_offset definition to treat it as a "volatile variable",
    in order to avoid such a mis-optimization.
    
    Cc: stable@vger.kernel.org
    Reported-by: Xiaotian Wu <wuxiaotian@loongson.cn>
    Reported-by: Miao Wang <shankerwangmiao@gmail.com>
    Signed-off-by: Xing Li <lixing@loongson.cn>
    Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
    Signed-off-by: Rui Wang <wangrui@loongson.cn>
    Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

LoongArch: Define the __io_aw() hook as mmiowb() [+ + +]
Author: Huacai Chen <chenhuacai@kernel.org>
Date:   Tue Mar 19 15:50:34 2024 +0800

    LoongArch: Define the __io_aw() hook as mmiowb()
    
    [ Upstream commit 9c68ece8b2a5c5ff9b2fcaea923dd73efeb174cd ]
    
    Commit fb24ea52f78e0d595852e ("drivers: Remove explicit invocations of
    mmiowb()") remove all mmiowb() in drivers, but it says:
    
    "NOTE: mmiowb() has only ever guaranteed ordering in conjunction with
    spin_unlock(). However, pairing each mmiowb() removal in this patch with
    the corresponding call to spin_unlock() is not at all trivial, so there
    is a small chance that this change may regress any drivers incorrectly
    relying on mmiowb() to order MMIO writes between CPUs using lock-free
    synchronisation."
    
    The mmio in radeon_ring_commit() is protected by a mutex rather than a
    spinlock, but in the mutex fastpath it behaves similar to spinlock. We
    can add mmiowb() calls in the radeon driver but the maintainer says he
    doesn't like such a workaround, and radeon is not the only example of
    mutex protected mmio.
    
    So we should extend the mmiowb tracking system from spinlock to mutex,
    and maybe other locking primitives. This is not easy and error prone, so
    we solve it in the architectural code, by simply defining the __io_aw()
    hook as mmiowb(). And we no longer need to override queued_spin_unlock()
    so use the generic definition.
    
    Without this, we get such an error when run 'glxgears' on weak ordering
    architectures such as LoongArch:
    
    radeon 0000:04:00.0: ring 0 stalled for more than 10324msec
    radeon 0000:04:00.0: ring 3 stalled for more than 10240msec
    radeon 0000:04:00.0: GPU lockup (current fence id 0x000000000001f412 last fence id 0x000000000001f414 on ring 3)
    radeon 0000:04:00.0: GPU lockup (current fence id 0x000000000000f940 last fence id 0x000000000000f941 on ring 0)
    radeon 0000:04:00.0: scheduling IB failed (-35).
    [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35)
    radeon 0000:04:00.0: scheduling IB failed (-35).
    [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35)
    radeon 0000:04:00.0: scheduling IB failed (-35).
    [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35)
    radeon 0000:04:00.0: scheduling IB failed (-35).
    [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35)
    radeon 0000:04:00.0: scheduling IB failed (-35).
    [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35)
    radeon 0000:04:00.0: scheduling IB failed (-35).
    [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35)
    radeon 0000:04:00.0: scheduling IB failed (-35).
    [drm:radeon_gem_va_ioctl [radeon]] *ERROR* Couldn't update BO_VA (-35)
    
    Link: https://lore.kernel.org/dri-devel/29df7e26-d7a8-4f67-b988-44353c4270ac@amd.com/T/#t
    Link: https://lore.kernel.org/linux-arch/20240301130532.3953167-1-chenhuacai@loongson.cn/T/#t
    Cc: stable@vger.kernel.org
    Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
mac802154: fix llsec key resources release in mac802154_llsec_key_del [+ + +]
Author: Fedor Pchelkin <pchelkin@ispras.ru>
Date:   Wed Feb 28 19:38:39 2024 +0300

    mac802154: fix llsec key resources release in mac802154_llsec_key_del
    
    [ Upstream commit e8a1e58345cf40b7b272e08ac7b32328b2543e40 ]
    
    mac802154_llsec_key_del() can free resources of a key directly without
    following the RCU rules for waiting before the end of a grace period. This
    may lead to use-after-free in case llsec_lookup_key() is traversing the
    list of keys in parallel with a key deletion:
    
    refcount_t: addition on 0; use-after-free.
    WARNING: CPU: 4 PID: 16000 at lib/refcount.c:25 refcount_warn_saturate+0x162/0x2a0
    Modules linked in:
    CPU: 4 PID: 16000 Comm: wpan-ping Not tainted 6.7.0 #19
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
    RIP: 0010:refcount_warn_saturate+0x162/0x2a0
    Call Trace:
     <TASK>
     llsec_lookup_key.isra.0+0x890/0x9e0
     mac802154_llsec_encrypt+0x30c/0x9c0
     ieee802154_subif_start_xmit+0x24/0x1e0
     dev_hard_start_xmit+0x13e/0x690
     sch_direct_xmit+0x2ae/0xbc0
     __dev_queue_xmit+0x11dd/0x3c20
     dgram_sendmsg+0x90b/0xd60
     __sys_sendto+0x466/0x4c0
     __x64_sys_sendto+0xe0/0x1c0
     do_syscall_64+0x45/0xf0
     entry_SYSCALL_64_after_hwframe+0x6e/0x76
    
    Also, ieee802154_llsec_key_entry structures are not freed by
    mac802154_llsec_key_del():
    
    unreferenced object 0xffff8880613b6980 (size 64):
      comm "iwpan", pid 2176, jiffies 4294761134 (age 60.475s)
      hex dump (first 32 bytes):
        78 0d 8f 18 80 88 ff ff 22 01 00 00 00 00 ad de  x.......".......
        00 00 00 00 00 00 00 00 03 00 cd ab 00 00 00 00  ................
      backtrace:
        [<ffffffff81dcfa62>] __kmem_cache_alloc_node+0x1e2/0x2d0
        [<ffffffff81c43865>] kmalloc_trace+0x25/0xc0
        [<ffffffff88968b09>] mac802154_llsec_key_add+0xac9/0xcf0
        [<ffffffff8896e41a>] ieee802154_add_llsec_key+0x5a/0x80
        [<ffffffff8892adc6>] nl802154_add_llsec_key+0x426/0x5b0
        [<ffffffff86ff293e>] genl_family_rcv_msg_doit+0x1fe/0x2f0
        [<ffffffff86ff46d1>] genl_rcv_msg+0x531/0x7d0
        [<ffffffff86fee7a9>] netlink_rcv_skb+0x169/0x440
        [<ffffffff86ff1d88>] genl_rcv+0x28/0x40
        [<ffffffff86fec15c>] netlink_unicast+0x53c/0x820
        [<ffffffff86fecd8b>] netlink_sendmsg+0x93b/0xe60
        [<ffffffff86b91b35>] ____sys_sendmsg+0xac5/0xca0
        [<ffffffff86b9c3dd>] ___sys_sendmsg+0x11d/0x1c0
        [<ffffffff86b9c65a>] __sys_sendmsg+0xfa/0x1d0
        [<ffffffff88eadbf5>] do_syscall_64+0x45/0xf0
        [<ffffffff890000ea>] entry_SYSCALL_64_after_hwframe+0x6e/0x76
    
    Handle the proper resource release in the RCU callback function
    mac802154_llsec_key_del_rcu().
    
    Note that if llsec_lookup_key() finds a key, it gets a refcount via
    llsec_key_get() and locally copies key id from key_entry (which is a
    list element). So it's safe to call llsec_key_put() and free the list
    entry after the RCU grace period elapses.
    
    Found by Linux Verification Center (linuxtesting.org).
    
    Fixes: 5d637d5aabd8 ("mac802154: add llsec structures and mutators")
    Cc: stable@vger.kernel.org
    Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
    Acked-by: Alexander Aring <aahringo@redhat.com>
    Message-ID: <20240228163840.6667-1-pchelkin@ispras.ru>
    Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
md/raid5: fix atomicity violation in raid5_cache_count [+ + +]
Author: Gui-Dong Han <2045gemini@gmail.com>
Date:   Fri Jan 12 15:10:17 2024 +0800

    md/raid5: fix atomicity violation in raid5_cache_count
    
    [ Upstream commit dfd2bf436709b2bccb78c2dda550dde93700efa7 ]
    
    In raid5_cache_count():
        if (conf->max_nr_stripes < conf->min_nr_stripes)
            return 0;
        return conf->max_nr_stripes - conf->min_nr_stripes;
    The current check is ineffective, as the values could change immediately
    after being checked.
    
    In raid5_set_cache_size():
        ...
        conf->min_nr_stripes = size;
        ...
        while (size > conf->max_nr_stripes)
            conf->min_nr_stripes = conf->max_nr_stripes;
        ...
    
    Due to intermediate value updates in raid5_set_cache_size(), concurrent
    execution of raid5_cache_count() and raid5_set_cache_size() may lead to
    inconsistent reads of conf->max_nr_stripes and conf->min_nr_stripes.
    The current checks are ineffective as values could change immediately
    after being checked, raising the risk of conf->min_nr_stripes exceeding
    conf->max_nr_stripes and potentially causing an integer overflow.
    
    This possible bug is found by an experimental static analysis tool
    developed by our team. This tool analyzes the locking APIs to extract
    function pairs that can be concurrently executed, and then analyzes the
    instructions in the paired functions to identify possible concurrency bugs
    including data races and atomicity violations. The above possible bug is
    reported when our tool analyzes the source code of Linux 6.2.
    
    To resolve this issue, it is suggested to introduce local variables
    'min_stripes' and 'max_stripes' in raid5_cache_count() to ensure the
    values remain stable throughout the check. Adding locks in
    raid5_cache_count() fails to resolve atomicity violations, as
    raid5_set_cache_size() may hold intermediate values of
    conf->min_nr_stripes while unlocked. With this patch applied, our tool no
    longer reports the bug, with the kernel configuration allyesconfig for
    x86_64. Due to the lack of associated hardware, we cannot test the patch
    in runtime testing, and just verify it according to the code logic.
    
    Fixes: edbe83ab4c27 ("md/raid5: allow the stripe_cache to grow and shrink.")
    Cc: stable@vger.kernel.org
    Signed-off-by: Gui-Dong Han <2045gemini@gmail.com>
    Reviewed-by: Yu Kuai <yukuai3@huawei.com>
    Signed-off-by: Song Liu <song@kernel.org>
    Link: https://lore.kernel.org/r/20240112071017.16313-1-2045gemini@gmail.com
    Signed-off-by: Song Liu <song@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
media: mc: Add local pad to pipeline regardless of the link state [+ + +]
Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Date:   Sun Jan 14 15:55:40 2024 +0200

    media: mc: Add local pad to pipeline regardless of the link state
    
    [ Upstream commit 78f0daa026d4c5e192d31801d1be6caf88250220 ]
    
    When building pipelines by following links, the
    media_pipeline_explore_next_link() function only traverses enabled
    links. The remote pad of a disabled link is not added to the pipeline,
    and neither is the local pad. While the former is correct as disabled
    links should not be followed, not adding the local pad breaks processing
    of the MEDIA_PAD_FL_MUST_CONNECT flag.
    
    The MEDIA_PAD_FL_MUST_CONNECT flag is checked in the
    __media_pipeline_start() function that iterates over all pads after
    populating the pipeline. If the pad is not present, the check gets
    skipped, rendering it useless.
    
    Fix this by adding the local pad of all links regardless of their state,
    only skipping the remote pad for disabled links.
    
    Cc: stable@vger.kernel.org # 6.1
    Fixes: ae219872834a ("media: mc: entity: Rewrite media_pipeline_start()")
    Reported-by: Frieder Schrempf <frieder.schrempf@kontron.de>
    Closes: https://lore.kernel.org/linux-media/7658a15a-80c5-219f-2477-2a94ba6c6ba1@kontron.de
    Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
    Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
    Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

media: mc: Add num_links flag to media_pad [+ + +]
Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Date:   Mon Jan 15 00:30:02 2024 +0200

    media: mc: Add num_links flag to media_pad
    
    [ Upstream commit baeddf94aa61879b118f2faa37ed126d772670cc ]
    
    Maintain a counter of the links connected to a pad in the media_pad
    structure. This helps checking if a pad is connected to anything, which
    will be used in the pipeline building code.
    
    Cc: stable@vger.kernel.org # 6.1
    Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
    Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
    Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

media: mc: Expand MUST_CONNECT flag to always require an enabled link [+ + +]
Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Date:   Mon Jan 15 01:04:52 2024 +0200

    media: mc: Expand MUST_CONNECT flag to always require an enabled link
    
    [ Upstream commit b3decc5ce7d778224d266423b542326ad469cb5f ]
    
    The MEDIA_PAD_FL_MUST_CONNECT flag indicates that the pad requires an
    enabled link to stream, but only if it has any link at all. This makes
    little sense, as if a pad is part of a pipeline, there are very few use
    cases for an active link to be mandatory only if links exist at all. A
    review of in-tree drivers confirms they all need an enabled link for
    pads marked with the MEDIA_PAD_FL_MUST_CONNECT flag.
    
    Expand the scope of the flag by rejecting pads that have no links at
    all. This requires modifying the pipeline build code to add those pads
    to the pipeline.
    
    Cc: stable@vger.kernel.org # 6.1
    Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
    Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
    Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

media: mc: Fix flags handling when creating pad links [+ + +]
Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Date:   Mon Jan 15 00:24:12 2024 +0200

    media: mc: Fix flags handling when creating pad links
    
    [ Upstream commit 422f7af75d03d50895938d38bc9cb8be759c440f ]
    
    The media_create_pad_link() function doesn't correctly clear reject link
    type flags, nor does it set the DATA_LINK flag. It only works because
    the MEDIA_LNK_FL_DATA_LINK flag's value is 0.
    
    Fix it by returning an error if any link type flag is set. This doesn't
    introduce any regression, as nobody calls the media_create_pad_link()
    function with link type flags (easily checked by grepping for the flag
    in the source code, there are very few hits).
    
    Set the MEDIA_LNK_FL_DATA_LINK explicitly, which is a no-op that the
    compiler will optimize out, but is still useful to make the code more
    explicit and easier to understand.
    
    Cc: stable@vger.kernel.org # 6.1
    Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
    Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
    Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

media: mc: Rename pad variable to clarify intent [+ + +]
Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Date:   Mon Jan 15 00:30:02 2024 +0200

    media: mc: Rename pad variable to clarify intent
    
    [ Upstream commit 9ec9109cf9f611e3ec9ed0355afcc7aae5e73176 ]
    
    The pad local variable in the media_pipeline_explore_next_link()
    function is used to store the pad through which the entity has been
    reached. Rename it to origin to reflect that and make the code easier to
    read. This will be even more important in subsequent commits when
    expanding the function with additional logic.
    
    Cc: stable@vger.kernel.org # 6.1
    Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
    Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
    Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

media: staging: ipu3-imgu: Set fields before media_entity_pads_init() [+ + +]
Author: Hidenori Kobayashi <hidenorik@chromium.org>
Date:   Tue Jan 9 17:09:09 2024 +0900

    media: staging: ipu3-imgu: Set fields before media_entity_pads_init()
    
    [ Upstream commit 87318b7092670d4086bfec115a0280a60c51c2dd ]
    
    The imgu driver fails to probe with the following message because it
    does not set the pad's flags before calling media_entity_pads_init().
    
    [   14.596315] ipu3-imgu 0000:00:05.0: failed initialize subdev media entity (-22)
    [   14.596322] ipu3-imgu 0000:00:05.0: failed to register subdev0 ret (-22)
    [   14.596327] ipu3-imgu 0000:00:05.0: failed to register pipes (-22)
    [   14.596331] ipu3-imgu 0000:00:05.0: failed to create V4L2 devices (-22)
    
    Fix the initialization order so that the driver probe succeeds. The ops
    initialization is also moved together for readability.
    
    Fixes: a0ca1627b450 ("media: staging/intel-ipu3: Add v4l2 driver based on media framework")
    Cc: <stable@vger.kernel.org> # 6.7
    Cc: Dan Carpenter <dan.carpenter@linaro.org>
    Signed-off-by: Hidenori Kobayashi <hidenorik@chromium.org>
    Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
    Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

media: xc4000: Fix atomicity violation in xc4000_get_frequency [+ + +]
Author: Gui-Dong Han <2045gemini@gmail.com>
Date:   Fri Dec 22 13:50:30 2023 +0800

    media: xc4000: Fix atomicity violation in xc4000_get_frequency
    
    [ Upstream commit 36d503ad547d1c75758a6fcdbec2806f1b6aeb41 ]
    
    In xc4000_get_frequency():
            *freq = priv->freq_hz + priv->freq_offset;
    The code accesses priv->freq_hz and priv->freq_offset without holding any
    lock.
    
    In xc4000_set_params():
            // Code that updates priv->freq_hz and priv->freq_offset
            ...
    
    xc4000_get_frequency() and xc4000_set_params() may execute concurrently,
    risking inconsistent reads of priv->freq_hz and priv->freq_offset. Since
    these related data may update during reading, it can result in incorrect
    frequency calculation, leading to atomicity violations.
    
    This possible bug is found by an experimental static analysis tool
    developed by our team, BassCheck[1]. This tool analyzes the locking APIs
    to extract function pairs that can be concurrently executed, and then
    analyzes the instructions in the paired functions to identify possible
    concurrency bugs including data races and atomicity violations. The above
    possible bug is reported when our tool analyzes the source code of
    Linux 6.2.
    
    To address this issue, it is proposed to add a mutex lock pair in
    xc4000_get_frequency() to ensure atomicity. With this patch applied, our
    tool no longer reports the possible bug, with the kernel configuration
    allyesconfig for x86_64. Due to the lack of associated hardware, we cannot
    test the patch in runtime testing, and just verify it according to the
    code logic.
    
    [1] https://sites.google.com/view/basscheck/
    
    Fixes: 4c07e32884ab ("[media] xc4000: Fix get_frequency()")
    Cc: stable@vger.kernel.org
    Reported-by: BassCheck <bass@buaa.edu.cn>
    Signed-off-by: Gui-Dong Han <2045gemini@gmail.com>
    Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
mei: me: add arrow lake point H DID [+ + +]
Author: Alexander Usyskin <alexander.usyskin@intel.com>
Date:   Sun Feb 11 12:39:12 2024 +0200

    mei: me: add arrow lake point H DID
    
    commit 8436f25802ec028ac7254990893f3e01926d9b79 upstream.
    
    Add Arrow Lake H device id.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
    Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
    Link: https://lore.kernel.org/r/20240211103912.117105-2-tomas.winkler@intel.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

mei: me: add arrow lake point S DID [+ + +]
Author: Alexander Usyskin <alexander.usyskin@intel.com>
Date:   Sun Feb 11 12:39:11 2024 +0200

    mei: me: add arrow lake point S DID
    
    commit 7a9b9012043e126f6d6f4683e67409312d1b707b upstream.
    
    Add Arrow Lake S device id.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
    Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
    Link: https://lore.kernel.org/r/20240211103912.117105-1-tomas.winkler@intel.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
memtest: use {READ,WRITE}_ONCE in memory scanning [+ + +]
Author: Qiang Zhang <qiang4.zhang@intel.com>
Date:   Tue Mar 12 16:04:23 2024 +0800

    memtest: use {READ,WRITE}_ONCE in memory scanning
    
    [ Upstream commit 82634d7e24271698e50a3ec811e5f50de790a65f ]
    
    memtest failed to find bad memory when compiled with clang.  So use
    {WRITE,READ}_ONCE to access memory to avoid compiler over optimization.
    
    Link: https://lkml.kernel.org/r/20240312080422.691222-1-qiang4.zhang@intel.com
    Signed-off-by: Qiang Zhang <qiang4.zhang@intel.com>
    Cc: Bill Wendling <morbo@google.com>
    Cc: Justin Stitt <justinstitt@google.com>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
minmax: add umin(a, b) and umax(a, b) [+ + +]
Author: David Laight <David.Laight@ACULAB.COM>
Date:   Mon Sep 18 08:16:30 2023 +0000

    minmax: add umin(a, b) and umax(a, b)
    
    [ Upstream commit 80fcac55385ccb710d33a20dc1caaef29bd5a921 ]
    
    Patch series "minmax: Relax type checks in min() and max()", v4.
    
    The min() (etc) functions in minmax.h require that the arguments have
    exactly the same types.
    
    However when the type check fails, rather than look at the types and fix
    the type of a variable/constant, everyone seems to jump on min_t().  In
    reality min_t() ought to be rare - when something unusual is being done,
    not normality.
    
    The orginal min() (added in 2.4.9) replaced several inline functions and
    included the type - so matched the implicit casting of the function call.
    This was renamed min_t() in 2.4.10 and the current min() added.  There is
    no actual indication that the conversion of negatve values to large
    unsigned values has ever been an actual problem.
    
    A quick grep shows 5734 min() and 4597 min_t().  Having the casts on
    almost half of the calls shows that something is clearly wrong.
    
    If the wrong type is picked (and it is far too easy to pick the type of
    the result instead of the larger input) then significant bits can get
    discarded.
    
    Pretty much the worst example is in the derived clamp_val(), consider:
            unsigned char x = 200u;
            y = clamp_val(x, 10u, 300u);
    
    I also suspect that many of the min_t(u16, ...) are actually wrong.  For
    example copy_data() in printk_ringbuffer.c contains:
    
            data_size = min_t(u16, buf_size, len);
    
    Here buf_size is 'unsigned int' and len 'u16', pass a 64k buffer (can you
    prove that doesn't happen?) and no data is returned.  Apparantly it did -
    and has since been fixed.
    
    The only reason that most of the min_t() are 'fine' is that pretty much
    all the values in the kernel are between 0 and INT_MAX.
    
    Patch 1 adds umin(), this uses integer promotions to convert both
    arguments to 'unsigned long long'.  It can be used to compare a signed
    type that is known to contain a non-negative value with an unsigned type.
    The compiler typically optimises it all away.  Added first so that it can
    be referred to in patch 2.
    
    Patch 2 replaces the 'same type' check with a 'same signedness' one.  This
    makes min(unsigned_int_var, sizeof()) be ok.  The error message is also
    improved and will contain the expanded form of both arguments (useful for
    seeing how constants are defined).
    
    Patch 3 just fixes some whitespace.
    
    Patch 4 allows comparisons of 'unsigned char' and 'unsigned short' to
    signed types.  The integer promotion rules convert them both to 'signed
    int' prior to the comparison so they can never cause a negative value be
    converted to a large positive one.
    
    Patch 5 (rewritted for v4) allows comparisons of unsigned values against
    non-negative constant integer expressions.  This makes
    min(unsigned_int_var, 4) be ok.
    
    The only common case that is still errored is the comparison of signed
    values against unsigned constant integer expressions below __INT_MAX__.
    Typcally min(int_val, sizeof (foo)), the real fix for this is casting the
    constant: min(int_var, (int)sizeof (foo)).
    
    With all the patches applied pretty much all the min_t() could be replaced
    by min(), and most of the rest by umin().  However they all need careful
    inspection due to code like:
    
            sz = min_t(unsigned char, sz - 1, LIM - 1) + 1;
    
    which converts 0 to LIM.
    
    This patch (of 6):
    
    umin() and umax() can be used when min()/max() errors a signed v unsigned
    compare when the signed value is known to be non-negative.
    
    Unlike min_t(some_unsigned_type, a, b) umin() will never mask off high
    bits if an inappropriate type is selected.
    
    The '+ 0u + 0ul + 0ull' may look strange.
    The '+ 0u' is needed for 'signed int' on 64bit systems.
    The '+ 0ul' is needed for 'signed long' on 32bit systems.
    The '+ 0ull' is needed for 'signed long long'.
    
    Link: https://lkml.kernel.org/r/b97faef60ad24922b530241c5d7c933c@AcuMS.aculab.com
    Link: https://lkml.kernel.org/r/41d93ca827a248698ec64bf57e0c05a5@AcuMS.aculab.com
    Signed-off-by: David Laight <david.laight@aculab.com>
    Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: Christoph Hellwig <hch@infradead.org>
    Cc: Jason A. Donenfeld <Jason@zx2c4.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Stable-dep-of: 51b30ecb73b4 ("swiotlb: Fix alignment checks when both allocation and DMA masks are present")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
misc: lis3lv02d_i2c: Fix regulators getting en-/dis-abled twice on suspend/resume [+ + +]
Author: Hans de Goede <hdegoede@redhat.com>
Date:   Tue Feb 20 20:00:35 2024 +0100

    misc: lis3lv02d_i2c: Fix regulators getting en-/dis-abled twice on suspend/resume
    
    commit ac3e0384073b2408d6cb0d972fee9fcc3776053d upstream.
    
    When not configured for wakeup lis3lv02d_i2c_suspend() will call
    lis3lv02d_poweroff() even if the device has already been turned off
    by the runtime-suspend handler and if configured for wakeup and
    the device is runtime-suspended at this point then it is not turned
    back on to serve as a wakeup source.
    
    Before commit b1b9f7a49440 ("misc: lis3lv02d_i2c: Add missing setting
    of the reg_ctrl callback"), lis3lv02d_poweroff() failed to disable
    the regulators which as a side effect made calling poweroff() twice ok.
    
    Now that poweroff() correctly disables the regulators, doing this twice
    triggers a WARN() in the regulator core:
    
    unbalanced disables for regulator-dummy
    WARNING: CPU: 1 PID: 92 at drivers/regulator/core.c:2999 _regulator_disable
    ...
    
    Fix lis3lv02d_i2c_suspend() to not call poweroff() a second time if
    already runtime-suspended and add a poweron() call when necessary to
    make wakeup work.
    
    lis3lv02d_i2c_resume() has similar issues, with an added weirness that
    it always powers on the device if it is runtime suspended, after which
    the first runtime-resume will call poweron() again, causing the enabled
    count for the regulator to increase by 1 every suspend/resume. These
    unbalanced regulator_enable() calls cause the regulator to never
    be turned off and trigger the following WARN() on driver unbind:
    
    WARNING: CPU: 1 PID: 1724 at drivers/regulator/core.c:2396 _regulator_put
    
    Fix this by making lis3lv02d_i2c_resume() mirror the new suspend().
    
    Fixes: b1b9f7a49440 ("misc: lis3lv02d_i2c: Add missing setting of the reg_ctrl callback")
    Reported-by: Paul Menzel <pmenzel@molgen.mpg.de>
    Closes: https://lore.kernel.org/regressions/5fc6da74-af0a-4aac-b4d5-a000b39a63a5@molgen.mpg.de/
    Cc: stable@vger.kernel.org
    Cc: regressions@lists.linux.dev
    Signed-off-by: Hans de Goede <hdegoede@redhat.com>
    Tested-by: Paul Menzel <pmenzel@molgen.mpg.de> # Dell XPS 15 7590
    Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
    Link: https://lore.kernel.org/r/20240220190035.53402-1-hdegoede@redhat.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
mm, vmscan: prevent infinite loop for costly GFP_NOIO | __GFP_RETRY_MAYFAIL allocations [+ + +]
Author: Vlastimil Babka <vbabka@suse.cz>
Date:   Wed Feb 21 12:43:58 2024 +0100

    mm, vmscan: prevent infinite loop for costly GFP_NOIO | __GFP_RETRY_MAYFAIL allocations
    
    commit 803de9000f334b771afacb6ff3e78622916668b0 upstream.
    
    Sven reports an infinite loop in __alloc_pages_slowpath() for costly order
    __GFP_RETRY_MAYFAIL allocations that are also GFP_NOIO.  Such combination
    can happen in a suspend/resume context where a GFP_KERNEL allocation can
    have __GFP_IO masked out via gfp_allowed_mask.
    
    Quoting Sven:
    
    1. try to do a "costly" allocation (order > PAGE_ALLOC_COSTLY_ORDER)
       with __GFP_RETRY_MAYFAIL set.
    
    2. page alloc's __alloc_pages_slowpath tries to get a page from the
       freelist. This fails because there is nothing free of that costly
       order.
    
    3. page alloc tries to reclaim by calling __alloc_pages_direct_reclaim,
       which bails out because a zone is ready to be compacted; it pretends
       to have made a single page of progress.
    
    4. page alloc tries to compact, but this always bails out early because
       __GFP_IO is not set (it's not passed by the snd allocator, and even
       if it were, we are suspending so the __GFP_IO flag would be cleared
       anyway).
    
    5. page alloc believes reclaim progress was made (because of the
       pretense in item 3) and so it checks whether it should retry
       compaction. The compaction retry logic thinks it should try again,
       because:
        a) reclaim is needed because of the early bail-out in item 4
        b) a zonelist is suitable for compaction
    
    6. goto 2. indefinite stall.
    
    (end quote)
    
    The immediate root cause is confusing the COMPACT_SKIPPED returned from
    __alloc_pages_direct_compact() (step 4) due to lack of __GFP_IO to be
    indicating a lack of order-0 pages, and in step 5 evaluating that in
    should_compact_retry() as a reason to retry, before incrementing and
    limiting the number of retries.  There are however other places that
    wrongly assume that compaction can happen while we lack __GFP_IO.
    
    To fix this, introduce gfp_compaction_allowed() to abstract the __GFP_IO
    evaluation and switch the open-coded test in try_to_compact_pages() to use
    it.
    
    Also use the new helper in:
    - compaction_ready(), which will make reclaim not bail out in step 3, so
      there's at least one attempt to actually reclaim, even if chances are
      small for a costly order
    - in_reclaim_compaction() which will make should_continue_reclaim()
      return false and we don't over-reclaim unnecessarily
    - in __alloc_pages_slowpath() to set a local variable can_compact,
      which is then used to avoid retrying reclaim/compaction for costly
      allocations (step 5) if we can't compact and also to skip the early
      compaction attempt that we do in some cases
    
    Link: https://lkml.kernel.org/r/20240221114357.13655-2-vbabka@suse.cz
    Fixes: 3250845d0526 ("Revert "mm, oom: prevent premature OOM killer invocation for high order request"")
    Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
    Reported-by: Sven van Ashbrook <svenva@chromium.org>
    Closes: https://lore.kernel.org/all/CAG-rBihs_xMKb3wrMO1%2B-%2Bp4fowP9oy1pa_OTkfxBzPUVOZF%2Bg@mail.gmail.com/
    Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org>
    Cc: Brian Geffon <bgeffon@google.com>
    Cc: Curtis Malainey <cujomalainey@chromium.org>
    Cc: Jaroslav Kysela <perex@perex.cz>
    Cc: Mel Gorman <mgorman@techsingularity.net>
    Cc: Michal Hocko <mhocko@kernel.org>
    Cc: Takashi Iwai <tiwai@suse.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
mm/migrate: set swap entry values of THP tail pages properly. [+ + +]
Author: Zi Yan <ziy@nvidia.com>
Date:   Wed Mar 6 10:52:17 2024 -0500

    mm/migrate: set swap entry values of THP tail pages properly.
    
    The tail pages in a THP can have swap entry information stored in their
    private field. When migrating to a new page, all tail pages of the new
    page need to update ->private to avoid future data corruption.
    
    This fix is stable-only, since after commit 07e09c483cbe ("mm/huge_memory:
    work on folio->swap instead of page->private when splitting folio"),
    subpages of a swapcached THP no longer requires the maintenance.
    
    Adding THPs to the swapcache was introduced in commit
    38d8b4e6bdc87 ("mm, THP, swap: delay splitting THP during swap out"),
    where each subpage of a THP added to the swapcache had its own swapcache
    entry and required the ->private field to point to the correct swapcache
    entry. Later, when THP migration functionality was implemented in commit
    616b8371539a6 ("mm: thp: enable thp migration in generic path"),
    it initially did not handle the subpages of swapcached THPs, failing to
    update their ->private fields or replace the subpage pointers in the
    swapcache. Subsequently, commit e71769ae5260 ("mm: enable thp migration
    for shmem thp") addressed the swapcache update aspect. This patch fixes
    the update of subpage ->private fields.
    
    Closes: https://lore.kernel.org/linux-mm/1707814102-22682-1-git-send-email-quic_charante@quicinc.com/
    Fixes: 616b8371539a ("mm: thp: enable thp migration in generic path")
    Signed-off-by: Zi Yan <ziy@nvidia.com>
    Acked-by: David Hildenbrand <david@redhat.com>
    Reported-and-tested-by: Charan Teja Kalla <quic_charante@quicinc.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
mm: swap: fix race between free_swap_and_cache() and swapoff() [+ + +]
Author: Ryan Roberts <ryan.roberts@arm.com>
Date:   Wed Mar 6 14:03:56 2024 +0000

    mm: swap: fix race between free_swap_and_cache() and swapoff()
    
    [ Upstream commit 82b1c07a0af603e3c47b906c8e991dc96f01688e ]
    
    There was previously a theoretical window where swapoff() could run and
    teardown a swap_info_struct while a call to free_swap_and_cache() was
    running in another thread.  This could cause, amongst other bad
    possibilities, swap_page_trans_huge_swapped() (called by
    free_swap_and_cache()) to access the freed memory for swap_map.
    
    This is a theoretical problem and I haven't been able to provoke it from a
    test case.  But there has been agreement based on code review that this is
    possible (see link below).
    
    Fix it by using get_swap_device()/put_swap_device(), which will stall
    swapoff().  There was an extra check in _swap_info_get() to confirm that
    the swap entry was not free.  This isn't present in get_swap_device()
    because it doesn't make sense in general due to the race between getting
    the reference and swapoff.  So I've added an equivalent check directly in
    free_swap_and_cache().
    
    Details of how to provoke one possible issue (thanks to David Hildenbrand
    for deriving this):
    
    --8<-----
    
    __swap_entry_free() might be the last user and result in
    "count == SWAP_HAS_CACHE".
    
    swapoff->try_to_unuse() will stop as soon as soon as si->inuse_pages==0.
    
    So the question is: could someone reclaim the folio and turn
    si->inuse_pages==0, before we completed swap_page_trans_huge_swapped().
    
    Imagine the following: 2 MiB folio in the swapcache. Only 2 subpages are
    still references by swap entries.
    
    Process 1 still references subpage 0 via swap entry.
    Process 2 still references subpage 1 via swap entry.
    
    Process 1 quits. Calls free_swap_and_cache().
    -> count == SWAP_HAS_CACHE
    [then, preempted in the hypervisor etc.]
    
    Process 2 quits. Calls free_swap_and_cache().
    -> count == SWAP_HAS_CACHE
    
    Process 2 goes ahead, passes swap_page_trans_huge_swapped(), and calls
    __try_to_reclaim_swap().
    
    __try_to_reclaim_swap()->folio_free_swap()->delete_from_swap_cache()->
    put_swap_folio()->free_swap_slot()->swapcache_free_entries()->
    swap_entry_free()->swap_range_free()->
    ...
    WRITE_ONCE(si->inuse_pages, si->inuse_pages - nr_entries);
    
    What stops swapoff to succeed after process 2 reclaimed the swap cache
    but before process1 finished its call to swap_page_trans_huge_swapped()?
    
    --8<-----
    
    Link: https://lkml.kernel.org/r/20240306140356.3974886-1-ryan.roberts@arm.com
    Fixes: 7c00bafee87c ("mm/swap: free swap slots in batch")
    Closes: https://lore.kernel.org/linux-mm/65a66eb9-41f8-4790-8db2-0c70ea15979f@redhat.com/
    Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: "Huang, Ying" <ying.huang@intel.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
mmc: core: Avoid negative index with array access [+ + +]
Author: Mikko Rapeli <mikko.rapeli@linaro.org>
Date:   Wed Mar 13 15:37:44 2024 +0200

    mmc: core: Avoid negative index with array access
    
    commit cf55a7acd1ed38afe43bba1c8a0935b51d1dc014 upstream.
    
    Commit 4d0c8d0aef63 ("mmc: core: Use mrq.sbc in close-ended ffu") assigns
    prev_idata = idatas[i - 1], but doesn't check that the iterator i is
    greater than zero. Let's fix this by adding a check.
    
    Fixes: 4d0c8d0aef63 ("mmc: core: Use mrq.sbc in close-ended ffu")
    Link: https://lore.kernel.org/all/20231129092535.3278-1-avri.altman@wdc.com/
    Cc: stable@vger.kernel.org
    Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
    Reviewed-by: Avri Altman <avri.altman@wdc.com>
    Tested-by: Francesco Dolcini <francesco.dolcini@toradex.com>
    Link: https://lore.kernel.org/r/20240313133744.2405325-2-mikko.rapeli@linaro.org
    Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

mmc: core: Fix switch on gp3 partition [+ + +]
Author: Dominique Martinet <dominique.martinet@atmark-techno.com>
Date:   Wed Mar 6 10:44:38 2024 +0900

    mmc: core: Fix switch on gp3 partition
    
    [ Upstream commit 4af59a8df5ea930038cd3355e822f5eedf4accc1 ]
    
    Commit e7794c14fd73 ("mmc: rpmb: fixes pause retune on all RPMB
    partitions.") added a mask check for 'part_type', but the mask used was
    wrong leading to the code intended for rpmb also being executed for GP3.
    
    On some MMCs (but not all) this would make gp3 partition inaccessible:
    armadillo:~# head -c 1 < /dev/mmcblk2gp3
    head: standard input: I/O error
    armadillo:~# dmesg -c
    [  422.976583] mmc2: running CQE recovery
    [  423.058182] mmc2: running CQE recovery
    [  423.137607] mmc2: running CQE recovery
    [  423.137802] blk_update_request: I/O error, dev mmcblk2gp3, sector 0 op 0x0:(READ) flags 0x80700 phys_seg 4 prio class 0
    [  423.237125] mmc2: running CQE recovery
    [  423.318206] mmc2: running CQE recovery
    [  423.397680] mmc2: running CQE recovery
    [  423.397837] blk_update_request: I/O error, dev mmcblk2gp3, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
    [  423.408287] Buffer I/O error on dev mmcblk2gp3, logical block 0, async page read
    
    the part_type values of interest here are defined as follow:
    main  0
    boot0 1
    boot1 2
    rpmb  3
    gp0   4
    gp1   5
    gp2   6
    gp3   7
    
    so mask with EXT_CSD_PART_CONFIG_ACC_MASK (7) to correctly identify rpmb
    
    Fixes: e7794c14fd73 ("mmc: rpmb: fixes pause retune on all RPMB partitions.")
    Cc: stable@vger.kernel.org
    Cc: Jorge Ramirez-Ortiz <jorge@foundries.io>
    Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
    Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
    Link: https://lore.kernel.org/r/20240306-mmc-partswitch-v1-1-bf116985d950@codewreck.org
    Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

mmc: core: Initialize mmc_blk_ioc_data [+ + +]
Author: Mikko Rapeli <mikko.rapeli@linaro.org>
Date:   Wed Mar 13 15:37:43 2024 +0200

    mmc: core: Initialize mmc_blk_ioc_data
    
    commit 0cdfe5b0bf295c0dee97436a8ed13336933a0211 upstream.
    
    Commit 4d0c8d0aef63 ("mmc: core: Use mrq.sbc in close-ended ffu") adds
    flags uint to struct mmc_blk_ioc_data, but it does not get initialized for
    RPMB ioctls which now fails.
    
    Let's fix this by always initializing the struct and flags to zero.
    
    Fixes: 4d0c8d0aef63 ("mmc: core: Use mrq.sbc in close-ended ffu")
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218587
    Link: https://lore.kernel.org/all/20231129092535.3278-1-avri.altman@wdc.com/
    Cc: stable@vger.kernel.org
    Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
    Reviewed-by: Avri Altman <avri.altman@wdc.com>
    Acked-by: Adrian Hunter <adrian.hunter@intel.com>
    Tested-by: Francesco Dolcini <francesco.dolcini@toradex.com>
    Link: https://lore.kernel.org/r/20240313133744.2405325-1-mikko.rapeli@linaro.org
    Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

mmc: sdhci-omap: re-tuning is needed after a pm transition to support emmc HS200 mode [+ + +]
Author: Romain Naour <romain.naour@skf.com>
Date:   Sat Mar 16 00:44:44 2024 +0100

    mmc: sdhci-omap: re-tuning is needed after a pm transition to support emmc HS200 mode
    
    commit f9e2a5b00a35f2c064dc679808bc8db5cc779ed6 upstream.
    
    "PM runtime functions" was been added in sdhci-omap driver in commit
    f433e8aac6b9 ("mmc: sdhci-omap: Implement PM runtime functions") along
    with "card power off and enable aggressive PM" in commit 3edf588e7fe0
    ("mmc: sdhci-omap: Allow SDIO card power off and enable aggressive PM").
    
    Since then, the sdhci-omap driver doesn't work using mmc-hs200 mode
    due to the tuning values being lost during a pm transition.
    
    As for the sdhci_am654 driver, request a new tuning sequence before
    suspend (sdhci_omap_runtime_suspend()), otherwise the device will
    trigger cache flush error:
    
      mmc1: cache flush error -110 (ETIMEDOUT)
      mmc1: error -110 doing aggressive suspend
    
    followed by I/O errors produced by fdisk -l /dev/mmcblk1boot1:
    
      I/O error, dev mmcblk1boot0, sector 64384 op 0x0:(READ) flags 0x80700 phys_seg 1
      prio class 2
      I/O error, dev mmcblk1boot1, sector 64384 op 0x0:(READ) flags 0x80700 phys_seg 1
      prio class 2
      I/O error, dev mmcblk1boot1, sector 64384 op 0x0:(READ) flags 0x0 phys_seg 1
      prio class 2
      Buffer I/O error on dev mmcblk1boot1, logical block 8048, async page read
      I/O error, dev mmcblk1boot0, sector 64384 op 0x0:(READ) flags 0x0 phys_seg 1
      prio class 2
      Buffer I/O error on dev mmcblk1boot0, logical block 8048, async page read
    
    Don't re-tune if auto retuning is supported in HW (when SDHCI_TUNING_MODE_3
    is available).
    
    Link: https://lore.kernel.org/all/2e5f1997-564c-44e4-b357-6343e0dae7ab@smile.fr
    Fixes: f433e8aac6b9 ("mmc: sdhci-omap: Implement PM runtime functions")
    Signed-off-by: Romain Naour <romain.naour@skf.com>
    Reviewed-by: Tony Lindgren <tony@atomide.com>
    Acked-by: Adrian Hunter <adrian.hunter@intel.com>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240315234444.816978-1-romain.naour@smile.fr
    Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

mmc: tmio: avoid concurrent runs of mmc_request_done() [+ + +]
Author: Wolfram Sang <wsa+renesas@sang-engineering.com>
Date:   Tue Mar 5 11:42:56 2024 +0100

    mmc: tmio: avoid concurrent runs of mmc_request_done()
    
    [ Upstream commit e8d1b41e69d72c62865bebe8f441163ec00b3d44 ]
    
    With the to-be-fixed commit, the reset_work handler cleared 'host->mrq'
    outside of the spinlock protected critical section. That leaves a small
    race window during execution of 'tmio_mmc_reset()' where the done_work
    handler could grab a pointer to the now invalid 'host->mrq'. Both would
    use it to call mmc_request_done() causing problems (see link below).
    
    However, 'host->mrq' cannot simply be cleared earlier inside the
    critical section. That would allow new mrqs to come in asynchronously
    while the actual reset of the controller still needs to be done. So,
    like 'tmio_mmc_set_ios()', an ERR_PTR is used to prevent new mrqs from
    coming in but still avoiding concurrency between work handlers.
    
    Reported-by: Dirk Behme <dirk.behme@de.bosch.com>
    Closes: https://lore.kernel.org/all/20240220061356.3001761-1-dirk.behme@de.bosch.com/
    Fixes: df3ef2d3c92c ("mmc: protect the tmio_mmc driver against a theoretical race")
    Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
    Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
    Reviewed-by: Dirk Behme <dirk.behme@de.bosch.com>
    Cc: stable@vger.kernel.org # 3.0+
    Link: https://lore.kernel.org/r/20240305104423.3177-2-wsa+renesas@sang-engineering.com
    Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
mtd: rawnand: meson: fix scrambling mode value in command macro [+ + +]
Author: Arseniy Krasnov <avkrasnov@salutedevices.com>
Date:   Sun Feb 11 00:45:51 2024 +0300

    mtd: rawnand: meson: fix scrambling mode value in command macro
    
    [ Upstream commit ef6f463599e16924cdd02ce5056ab52879dc008c ]
    
    Scrambling mode is enabled by value (1 << 19). NFC_CMD_SCRAMBLER_ENABLE
    is already (1 << 19), so there is no need to shift it again in CMDRWGEN
    macro.
    
    Signed-off-by: Arseniy Krasnov <avkrasnov@salutedevices.com>
    Cc: <Stable@vger.kernel.org>
    Fixes: 8fae856c5350 ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
    Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
    Link: https://lore.kernel.org/linux-mtd/20240210214551.441610-1-avkrasnov@salutedevices.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
net: hns3: tracing: fix hclgevf trace event strings [+ + +]
Author: Steven Rostedt (Google) <rostedt@goodmis.org>
Date:   Wed Mar 13 09:34:54 2024 -0400

    net: hns3: tracing: fix hclgevf trace event strings
    
    [ Upstream commit 3f9952e8d80cca2da3b47ecd5ad9ec16cfd1a649 ]
    
    The __string() and __assign_str() helper macros of the TRACE_EVENT() macro
    are going through some optimizations where only the source string of
    __string() will be used and the __assign_str() source will be ignored and
    later removed.
    
    To make sure that there's no issues, a new check is added between the
    __string() src argument and the __assign_str() src argument that does a
    strcmp() to make sure they are the same string.
    
    The hclgevf trace events have:
    
      __assign_str(devname, &hdev->nic.kinfo.netdev->name);
    
    Which triggers the warning:
    
    hclgevf_trace.h:34:39: error: passing argument 1 of ‘strcmp’ from incompatible pointer type [-Werror=incompatible-pointer-types]
       34 |                 __assign_str(devname, &hdev->nic.kinfo.netdev->name);
     [..]
    arch/x86/include/asm/string_64.h:75:24: note: expected ‘const char *’ but argument is of type ‘char (*)[16]’
       75 | int strcmp(const char *cs, const char *ct);
          |            ~~~~~~~~~~~~^~
    
    Because __assign_str() now has:
    
            WARN_ON_ONCE(__builtin_constant_p(src) ?                \
                         strcmp((src), __data_offsets.dst##_ptr_) : \
                         (src) != __data_offsets.dst##_ptr_);       \
    
    The problem is the '&' on hdev->nic.kinfo.netdev->name. That's because
    that name is:
    
            char                    name[IFNAMSIZ]
    
    Where passing an address '&' of a char array is not compatible with strcmp().
    
    The '&' is not necessary, remove it.
    
    Link: https://lore.kernel.org/linux-trace-kernel/20240313093454.3909afe7@gandalf.local.home
    
    Cc: netdev <netdev@vger.kernel.org>
    Cc: Yisen Zhuang <yisen.zhuang@huawei.com>
    Cc: Salil Mehta <salil.mehta@huawei.com>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: Eric Dumazet <edumazet@google.com>
    Cc: Jakub Kicinski <kuba@kernel.org>
    Cc: Yufeng Mo <moyufeng@huawei.com>
    Cc: Huazhong Tan <tanhuazhong@huawei.com>
    Cc: stable@vger.kernel.org
    Acked-by: Paolo Abeni <pabeni@redhat.com>
    Reviewed-by: Jijie Shao <shaojijie@huawei.com>
    Fixes: d8355240cf8fb ("net: hns3: add trace event support for PF/VF mailbox")
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

net: ll_temac: platform_get_resource replaced by wrong function [+ + +]
Author: Claus Hansen Ries <chr@terma.com>
Date:   Thu Mar 21 13:08:59 2024 +0000

    net: ll_temac: platform_get_resource replaced by wrong function
    
    commit 3a38a829c8bc27d78552c28e582eb1d885d07d11 upstream.
    
    The function platform_get_resource was replaced with
    devm_platform_ioremap_resource_byname and is called using 0 as name.
    
    This eventually ends up in platform_get_resource_byname in the call
    stack, where it causes a null pointer in strcmp.
    
            if (type == resource_type(r) && !strcmp(r->name, name))
    
    It should have been replaced with devm_platform_ioremap_resource.
    
    Fixes: bd69058f50d5 ("net: ll_temac: Use devm_platform_ioremap_resource_byname()")
    Signed-off-by: Claus Hansen Ries <chr@terma.com>
    Cc: stable@vger.kernel.org
    Reviewed-by: Simon Horman <horms@kernel.org>
    Link: https://lore.kernel.org/r/cca18f9c630a41c18487729770b492bb@terma.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

net: tls: handle backlogging of crypto requests [+ + +]
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Tue Feb 6 17:18:21 2024 -0800

    net: tls: handle backlogging of crypto requests
    
    commit 8590541473188741055d27b955db0777569438e3 upstream.
    
    Since we're setting the CRYPTO_TFM_REQ_MAY_BACKLOG flag on our
    requests to the crypto API, crypto_aead_{encrypt,decrypt} can return
     -EBUSY instead of -EINPROGRESS in valid situations. For example, when
    the cryptd queue for AESNI is full (easy to trigger with an
    artificially low cryptd.cryptd_max_cpu_qlen), requests will be enqueued
    to the backlog but still processed. In that case, the async callback
    will also be called twice: first with err == -EINPROGRESS, which it
    seems we can just ignore, then with err == 0.
    
    Compared to Sabrina's original patch this version uses the new
    tls_*crypt_async_wait() helpers and converts the EBUSY to
    EINPROGRESS to avoid having to modify all the error handling
    paths. The handling is identical.
    
    Fixes: a54667f6728c ("tls: Add support for encryption using async offload accelerator")
    Fixes: 94524d8fc965 ("net/tls: Add support for async decryption of tls records")
    Co-developed-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Link: https://lore.kernel.org/netdev/9681d1febfec295449a62300938ed2ae66983f28.1694018970.git.sd@queasysnail.net/
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Reviewed-by: Simon Horman <horms@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [Srish: v2: fixed hunk failures
            fixed merge-conflict in stable branch linux-6.1.y,
            needs to go on top of https://lore.kernel.org/stable/20240307155930.913525-1-lee@kernel.org/]
    Signed-off-by: Srish Srinivasan <srish.srinivasan@broadcom.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
netfilter: nf_tables: disallow anonymous set with timeout flag [+ + +]
Author: Pablo Neira Ayuso <pablo@netfilter.org>
Date:   Fri Mar 1 00:11:10 2024 +0100

    netfilter: nf_tables: disallow anonymous set with timeout flag
    
    commit 16603605b667b70da974bea8216c93e7db043bf1 upstream.
    
    Anonymous sets are never used with timeout from userspace, reject this.
    Exception to this rule is NFT_SET_EVAL to ensure legacy meters still work.
    
    Cc: stable@vger.kernel.org
    Fixes: 761da2935d6e ("netfilter: nf_tables: add set timeout API support")
    Reported-by: lonial con <kongln9170@gmail.com>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

netfilter: nf_tables: mark set as dead when unbinding anonymous set with timeout [+ + +]
Author: Pablo Neira Ayuso <pablo@netfilter.org>
Date:   Mon Mar 4 14:22:12 2024 +0100

    netfilter: nf_tables: mark set as dead when unbinding anonymous set with timeout
    
    commit 552705a3650bbf46a22b1adedc1b04181490fc36 upstream.
    
    While the rhashtable set gc runs asynchronously, a race allows it to
    collect elements from anonymous sets with timeouts while it is being
    released from the commit path.
    
    Mingi Cho originally reported this issue in a different path in 6.1.x
    with a pipapo set with low timeouts which is not possible upstream since
    7395dfacfff6 ("netfilter: nf_tables: use timestamp to check for set
    element timeout").
    
    Fix this by setting on the dead flag for anonymous sets to skip async gc
    in this case.
    
    According to 08e4c8c5919f ("netfilter: nf_tables: mark newset as dead on
    transaction abort"), Florian plans to accelerate abort path by releasing
    objects via workqueue, therefore, this sets on the dead flag for abort
    path too.
    
    Cc: stable@vger.kernel.org
    Fixes: 5f68718b34a5 ("netfilter: nf_tables: GC transaction API to avoid race with control plane")
    Reported-by: Mingi Cho <mgcho.minic@gmail.com>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

netfilter: nf_tables: reject constant set with timeout [+ + +]
Author: Pablo Neira Ayuso <pablo@netfilter.org>
Date:   Fri Mar 1 01:04:11 2024 +0100

    netfilter: nf_tables: reject constant set with timeout
    
    commit 5f4fc4bd5cddb4770ab120ce44f02695c4505562 upstream.
    
    This set combination is weird: it allows for elements to be
    added/deleted, but once bound to the rule it cannot be updated anymore.
    Eventually, all elements expire, leading to an empty set which cannot
    be updated anymore. Reject this flags combination.
    
    Cc: stable@vger.kernel.org
    Fixes: 761da2935d6e ("netfilter: nf_tables: add set timeout API support")
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
nfs: fix UAF in direct writes [+ + +]
Author: Josef Bacik <josef@toxicpanda.com>
Date:   Fri Mar 1 11:49:57 2024 -0500

    nfs: fix UAF in direct writes
    
    [ Upstream commit 17f46b803d4f23c66cacce81db35fef3adb8f2af ]
    
    In production we have been hitting the following warning consistently
    
    ------------[ cut here ]------------
    refcount_t: underflow; use-after-free.
    WARNING: CPU: 17 PID: 1800359 at lib/refcount.c:28 refcount_warn_saturate+0x9c/0xe0
    Workqueue: nfsiod nfs_direct_write_schedule_work [nfs]
    RIP: 0010:refcount_warn_saturate+0x9c/0xe0
    PKRU: 55555554
    Call Trace:
     <TASK>
     ? __warn+0x9f/0x130
     ? refcount_warn_saturate+0x9c/0xe0
     ? report_bug+0xcc/0x150
     ? handle_bug+0x3d/0x70
     ? exc_invalid_op+0x16/0x40
     ? asm_exc_invalid_op+0x16/0x20
     ? refcount_warn_saturate+0x9c/0xe0
     nfs_direct_write_schedule_work+0x237/0x250 [nfs]
     process_one_work+0x12f/0x4a0
     worker_thread+0x14e/0x3b0
     ? ZSTD_getCParams_internal+0x220/0x220
     kthread+0xdc/0x120
     ? __btf_name_valid+0xa0/0xa0
     ret_from_fork+0x1f/0x30
    
    This is because we're completing the nfs_direct_request twice in a row.
    
    The source of this is when we have our commit requests to submit, we
    process them and send them off, and then in the completion path for the
    commit requests we have
    
    if (nfs_commit_end(cinfo.mds))
            nfs_direct_write_complete(dreq);
    
    However since we're submitting asynchronous requests we sometimes have
    one that completes before we submit the next one, so we end up calling
    complete on the nfs_direct_request twice.
    
    The only other place we use nfs_generic_commit_list() is in
    __nfs_commit_inode, which wraps this call in a
    
    nfs_commit_begin();
    nfs_commit_end();
    
    Which is a common pattern for this style of completion handling, one
    that is also repeated in the direct code with get_dreq()/put_dreq()
    calls around where we process events as well as in the completion paths.
    
    Fix this by using the same pattern for the commit requests.
    
    Before with my 200 node rocksdb stress running this warning would pop
    every 10ish minutes.  With my patch the stress test has been running for
    several hours without popping.
    
    Signed-off-by: Josef Bacik <josef@toxicpanda.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
NFSD: Fix nfsd_clid_class use of __string_len() macro [+ + +]
Author: Steven Rostedt (Google) <rostedt@goodmis.org>
Date:   Thu Feb 22 12:28:28 2024 -0500

    NFSD: Fix nfsd_clid_class use of __string_len() macro
    
    [ Upstream commit 9388a2aa453321bcf1ad2603959debea9e6ab6d4 ]
    
    I'm working on restructuring the __string* macros so that it doesn't need
    to recalculate the string twice. That is, it will save it off when
    processing __string() and the __assign_str() will not need to do the work
    again as it currently does.
    
    Currently __string_len(item, src, len) doesn't actually use "src", but my
    changes will require src to be correct as that is where the __assign_str()
    will get its value from.
    
    The event class nfsd_clid_class has:
    
      __string_len(name, name, clp->cl_name.len)
    
    But the second "name" does not exist and causes my changes to fail to
    build. That second parameter should be: clp->cl_name.data.
    
    Link: https://lore.kernel.org/linux-trace-kernel/20240222122828.3d8d213c@gandalf.local.home
    
    Cc: Neil Brown <neilb@suse.de>
    Cc: Olga Kornievskaia <kolga@netapp.com>
    Cc: Dai Ngo <Dai.Ngo@oracle.com>
    Cc: Tom Talpey <tom@talpey.com>
    Cc: stable@vger.kernel.org
    Fixes: d27b74a8675ca ("NFSD: Use new __string_len C macros for nfsd_clid_class")
    Acked-by: Chuck Lever <chuck.lever@oracle.com>
    Acked-by: Jeff Layton <jlayton@kernel.org>
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
nilfs2: fix failure to detect DAT corruption in btree and direct mappings [+ + +]
Author: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Date:   Wed Mar 13 19:58:26 2024 +0900

    nilfs2: fix failure to detect DAT corruption in btree and direct mappings
    
    [ Upstream commit f2f26b4a84a0ef41791bd2d70861c8eac748f4ba ]
    
    Patch series "nilfs2: fix kernel bug at submit_bh_wbc()".
    
    This resolves a kernel BUG reported by syzbot.  Since there are two
    flaws involved, I've made each one a separate patch.
    
    The first patch alone resolves the syzbot-reported bug, but I think
    both fixes should be sent to stable, so I've tagged them as such.
    
    This patch (of 2):
    
    Syzbot has reported a kernel bug in submit_bh_wbc() when writing file data
    to a nilfs2 file system whose metadata is corrupted.
    
    There are two flaws involved in this issue.
    
    The first flaw is that when nilfs_get_block() locates a data block using
    btree or direct mapping, if the disk address translation routine
    nilfs_dat_translate() fails with internal code -ENOENT due to DAT metadata
    corruption, it can be passed back to nilfs_get_block().  This causes
    nilfs_get_block() to misidentify an existing block as non-existent,
    causing both data block lookup and insertion to fail inconsistently.
    
    The second flaw is that nilfs_get_block() returns a successful status in
    this inconsistent state.  This causes the caller __block_write_begin_int()
    or others to request a read even though the buffer is not mapped,
    resulting in a BUG_ON check for the BH_Mapped flag in submit_bh_wbc()
    failing.
    
    This fixes the first issue by changing the return value to code -EINVAL
    when a conversion using DAT fails with code -ENOENT, avoiding the
    conflicting condition that leads to the kernel bug described above.  Here,
    code -EINVAL indicates that metadata corruption was detected during the
    block lookup, which will be properly handled as a file system error and
    converted to -EIO when passing through the nilfs2 bmap layer.
    
    Link: https://lkml.kernel.org/r/20240313105827.5296-1-konishi.ryusuke@gmail.com
    Link: https://lkml.kernel.org/r/20240313105827.5296-2-konishi.ryusuke@gmail.com
    Fixes: c3a7abf06ce7 ("nilfs2: support contiguous lookup of blocks")
    Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
    Reported-by: syzbot+cfed5b56649bddf80d6e@syzkaller.appspotmail.com
    Closes: https://syzkaller.appspot.com/bug?extid=cfed5b56649bddf80d6e
    Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

nilfs2: prevent kernel bug at submit_bh_wbc() [+ + +]
Author: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Date:   Wed Mar 13 19:58:27 2024 +0900

    nilfs2: prevent kernel bug at submit_bh_wbc()
    
    [ Upstream commit 269cdf353b5bdd15f1a079671b0f889113865f20 ]
    
    Fix a bug where nilfs_get_block() returns a successful status when
    searching and inserting the specified block both fail inconsistently.  If
    this inconsistent behavior is not due to a previously fixed bug, then an
    unexpected race is occurring, so return a temporary error -EAGAIN instead.
    
    This prevents callers such as __block_write_begin_int() from requesting a
    read into a buffer that is not mapped, which would cause the BUG_ON check
    for the BH_Mapped flag in submit_bh_wbc() to fail.
    
    Link: https://lkml.kernel.org/r/20240313105827.5296-3-konishi.ryusuke@gmail.com
    Fixes: 1f5abe7e7dbc ("nilfs2: replace BUG_ON and BUG calls triggerable from ioctl")
    Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
nouveau/dmem: handle kcalloc() allocation failure [+ + +]
Author: Duoming Zhou <duoming@zju.edu.cn>
Date:   Wed Mar 6 13:01:04 2024 +0800

    nouveau/dmem: handle kcalloc() allocation failure
    
    commit 16e87fe23d4af6df920406494ced5c0f4354567b upstream.
    
    The kcalloc() in nouveau_dmem_evict_chunk() will return null if
    the physical memory has run out. As a result, if we dereference
    src_pfns, dst_pfns or dma_addrs, the null pointer dereference bugs
    will happen.
    
    Moreover, the GPU is going away. If the kcalloc() fails, we could not
    evict all pages mapping a chunk. So this patch adds a __GFP_NOFAIL
    flag in kcalloc().
    
    Finally, as there is no need to have physically contiguous memory,
    this patch switches kcalloc() to kvcalloc() in order to avoid
    failing allocations.
    
    CC: <stable@vger.kernel.org> # v6.1
    Fixes: 249881232e14 ("nouveau/dmem: evict device private memory during release")
    Suggested-by: Danilo Krummrich <dakr@redhat.com>
    Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
    Signed-off-by: Danilo Krummrich <dakr@redhat.com>
    Link: https://patchwork.freedesktop.org/patch/msgid/20240306050104.11259-1-duoming@zju.edu.cn
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
nvmem: meson-efuse: fix function pointer type mismatch [+ + +]
Author: Jerome Brunet <jbrunet@baylibre.com>
Date:   Sat Feb 24 11:40:23 2024 +0000

    nvmem: meson-efuse: fix function pointer type mismatch
    
    [ Upstream commit cbd38332c140829ab752ba4e727f98be5c257f18 ]
    
    clang-16 warns about casting functions to incompatible types, as is done
    here to call clk_disable_unprepare:
    
    drivers/nvmem/meson-efuse.c:78:12: error: cast from 'void (*)(struct clk *)' to 'void (*)(void *)' converts to incompatible function type [-Werror,-Wcast-function-type-strict]
       78 |                                        (void(*)(void *))clk_disable_unprepare,
    
    The pattern of getting, enabling and setting a disable callback for a
    clock can be replaced with devm_clk_get_enabled(), which also fixes
    this warning.
    
    Fixes: 611fbca1c861 ("nvmem: meson-efuse: add peripheral clock")
    Cc: Stable@vger.kernel.org
    Reported-by: Arnd Bergmann <arnd@arndb.de>
    Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
    Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
    Acked-by: Arnd Bergmann <arnd@arndb.de>
    Reviewed-by: Justin Stitt <justinstitt@google.com>
    Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
    Link: https://lore.kernel.org/r/20240224114023.85535-2-srinivas.kandagatla@linaro.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
parisc/unaligned: Rewrite 64-bit inline assembly of emulate_ldd() [+ + +]
Author: Guenter Roeck <linux@roeck-us.net>
Date:   Fri Feb 16 14:26:55 2024 +0100

    parisc/unaligned: Rewrite 64-bit inline assembly of emulate_ldd()
    
    [ Upstream commit e5db6a74571a8baf87a116ea39aab946283362ff ]
    
    Convert to use real temp variables instead of clobbering processor
    registers. This aligns the 64-bit inline assembly code with the 32-bit
    assembly code which was rewritten with commit 427c1073a2a1
    ("parisc/unaligned: Rewrite 32-bit inline assembly of emulate_ldd()").
    
    While at it, fix comment in 32-bit rewrite code. Temporary variables are
    now used for both 32-bit and 64-bit code, so move their declarations
    to the function header.
    
    No functional change intended.
    
    Signed-off-by: Guenter Roeck <linux@roeck-us.net>
    Cc: stable@vger.kernel.org # v6.0+
    Signed-off-by: Helge Deller <deller@gmx.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
parisc: Avoid clobbering the C/B bits in the PSW with tophys and tovirt macros [+ + +]
Author: John David Anglin <dave.anglin@bell.net>
Date:   Fri Feb 23 16:40:51 2024 +0100

    parisc: Avoid clobbering the C/B bits in the PSW with tophys and tovirt macros
    
    [ Upstream commit 4603fbaa76b5e703b38ac8cc718102834eb6e330 ]
    
    Use add,l to avoid clobbering the C/B bits in the PSW.
    
    Signed-off-by: John David Anglin <dave.anglin@bell.net>
    Signed-off-by: Helge Deller <deller@gmx.de>
    Cc: stable@vger.kernel.org # v5.10+
    Signed-off-by: Sasha Levin <sashal@kernel.org>

parisc: Fix csum_ipv6_magic on 32-bit systems [+ + +]
Author: Guenter Roeck <linux@roeck-us.net>
Date:   Sat Feb 10 11:15:56 2024 -0800

    parisc: Fix csum_ipv6_magic on 32-bit systems
    
    [ Upstream commit 4408ba75e4ba80c91fde7e10bccccf388f5c09be ]
    
    Calculating the IPv6 checksum on 32-bit systems missed overflows when
    adding the proto+len fields into the checksum. This results in the
    following unit test failure.
    
        # test_csum_ipv6_magic: ASSERTION FAILED at lib/checksum_kunit.c:506
        Expected ( u64)csum_result == ( u64)expected, but
            ( u64)csum_result == 46722 (0xb682)
            ( u64)expected == 46721 (0xb681)
        not ok 5 test_csum_ipv6_magic
    
    This is probably rarely seen in the real world because proto+len are
    usually small values which will rarely result in overflows when calculating
    the checksum. However, the unit test code uses large values for the length
    field, causing the test to fail.
    
    Fix the problem by adding the missing carry into the final checksum.
    
    Cc: Palmer Dabbelt <palmer@rivosinc.com>
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Cc: stable@vger.kernel.org
    Signed-off-by: Guenter Roeck <linux@roeck-us.net>
    Tested-by: Charlie Jenkins <charlie@rivosinc.com>
    Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
    Signed-off-by: Helge Deller <deller@gmx.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

parisc: Fix csum_ipv6_magic on 64-bit systems [+ + +]
Author: Guenter Roeck <linux@roeck-us.net>
Date:   Tue Feb 13 15:46:31 2024 -0800

    parisc: Fix csum_ipv6_magic on 64-bit systems
    
    [ Upstream commit 4b75b12d70506e31fc02356bbca60f8d5ca012d0 ]
    
    hppa 64-bit systems calculates the IPv6 checksum using 64-bit add
    operations. The last add folds protocol and length fields into the 64-bit
    result. While unlikely, this operation can overflow. The overflow can be
    triggered with a code sequence such as the following.
    
            /* try to trigger massive overflows */
            memset(tmp_buf, 0xff, sizeof(struct in6_addr));
            csum_result = csum_ipv6_magic((struct in6_addr *)tmp_buf,
                                          (struct in6_addr *)tmp_buf,
                                          0xffff, 0xff, 0xffffffff);
    
    Fix the problem by adding any overflows from the final add operation into
    the calculated checksum. Fortunately, we can do this without additional
    cost by replacing the add operation used to fold the checksum into 32 bit
    with "add,dc" to add in the missing carry.
    
    Cc: Palmer Dabbelt <palmer@rivosinc.com>
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Cc: stable@vger.kernel.org
    Signed-off-by: Guenter Roeck <linux@roeck-us.net>
    Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
    Tested-by: Guenter Roeck <linux@roeck-us.net>
    Signed-off-by: Helge Deller <deller@gmx.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

parisc: Fix ip_fast_csum [+ + +]
Author: Guenter Roeck <linux@roeck-us.net>
Date:   Sat Feb 10 09:55:26 2024 -0800

    parisc: Fix ip_fast_csum
    
    [ Upstream commit a2abae8f0b638c31bb9799d9dd847306e0d005bd ]
    
    IP checksum unit tests report the following error when run on hppa/hppa64.
    
        # test_ip_fast_csum: ASSERTION FAILED at lib/checksum_kunit.c:463
        Expected ( u64)csum_result == ( u64)expected, but
            ( u64)csum_result == 33754 (0x83da)
            ( u64)expected == 10946 (0x2ac2)
        not ok 4 test_ip_fast_csum
    
    0x83da is the expected result if the IP header length is 20 bytes. 0x2ac2
    is the expected result if the IP header length is 24 bytes. The test fails
    with an IP header length of 24 bytes. It appears that ip_fast_csum()
    always returns the checksum for a 20-byte header, no matter how long
    the header actually is.
    
    Code analysis shows a suspicious assembler sequence in ip_fast_csum().
    
     "      addc            %0, %3, %0\n"
     "1:    ldws,ma         4(%1), %3\n"
     "      addib,<         0, %2, 1b\n"    <---
    
    While my understanding of HPPA assembler is limited, it does not seem
    to make much sense to subtract 0 from a register and to expect the result
    to ever be negative. Subtracting 1 from the length parameter makes more
    sense. On top of that, the operation should be repeated if and only if
    the result is still > 0, so change the suspicious instruction to
     "      addib,>         -1, %2, 1b\n"
    
    The IP checksum unit test passes after this change.
    
    Cc: Palmer Dabbelt <palmer@rivosinc.com>
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Cc: stable@vger.kernel.org
    Signed-off-by: Guenter Roeck <linux@roeck-us.net>
    Tested-by: Charlie Jenkins <charlie@rivosinc.com>
    Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
    Signed-off-by: Helge Deller <deller@gmx.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

parisc: Strip upper 32 bit of sum in csum_ipv6_magic for 64-bit builds [+ + +]
Author: Guenter Roeck <linux@roeck-us.net>
Date:   Tue Feb 27 12:33:51 2024 -0800

    parisc: Strip upper 32 bit of sum in csum_ipv6_magic for 64-bit builds
    
    [ Upstream commit 0568b6f0d863643db2edcc7be31165740c89fa82 ]
    
    IPv6 checksum tests with unaligned addresses on 64-bit builds result
    in unexpected failures.
    
    Expected expected == csum_result, but
        expected == 46591 (0xb5ff)
        csum_result == 46381 (0xb52d)
    with alignment offset 1
    
    Oddly enough, the problem disappeared after adding test code into
    the beginning of csum_ipv6_magic().
    
    As it turns out, the 'sum' parameter of csum_ipv6_magic() is declared as
    __wsum, which is a 32-bit variable. However, it is treated as 64-bit
    variable in the 64-bit assembler code. Tests showed that the upper 32 bit
    of the register used to pass the variable are _not_ cleared when entering
    the function. This can result in checksum calculation errors.
    
    Clearing the upper 32 bit of 'sum' as first operation in the assembler
    code fixes the problem.
    
    Acked-by: Helge Deller <deller@gmx.de>
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Cc: stable@vger.kernel.org
    Signed-off-by: Guenter Roeck <linux@roeck-us.net>
    Signed-off-by: Helge Deller <deller@gmx.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
PCI/AER: Block runtime suspend when handling errors [+ + +]
Author: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Date:   Mon Feb 12 13:01:35 2024 +0100

    PCI/AER: Block runtime suspend when handling errors
    
    [ Upstream commit 002bf2fbc00e5c4b95fb167287e2ae7d1973281e ]
    
    PM runtime can be done simultaneously with AER error handling.  Avoid that
    by using pm_runtime_get_sync() before and pm_runtime_put() after reset in
    pcie_do_recovery() for all recovering devices.
    
    pm_runtime_get_sync() will increase dev->power.usage_count counter to
    prevent any possible future request to runtime suspend a device.  It will
    also resume a device, if it was previously in D3hot state.
    
    I tested with igc device by doing simultaneous aer_inject and rpm
    suspend/resume via /sys/bus/pci/devices/PCI_ID/power/control and can
    reproduce:
    
      igc 0000:02:00.0: not ready 65535ms after bus reset; giving up
      pcieport 0000:00:1c.2: AER: Root Port link has been reset (-25)
      pcieport 0000:00:1c.2: AER: subordinate device reset failed
      pcieport 0000:00:1c.2: AER: device recovery failed
      igc 0000:02:00.0: Unable to change power state from D3hot to D0, device inaccessible
    
    The problem disappears when this patch is applied.
    
    Link: https://lore.kernel.org/r/20240212120135.146068-1-stanislaw.gruszka@linux.intel.com
    Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
    Acked-by: Rafael J. Wysocki <rafael@kernel.org>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
PCI/DPC: Quirk PIO log size for Intel Raptor Lake Root Ports [+ + +]
Author: Paul Menzel <pmenzel@molgen.mpg.de>
Date:   Tue Mar 5 12:30:56 2024 +0100

    PCI/DPC: Quirk PIO log size for Intel Raptor Lake Root Ports
    
    [ Upstream commit 627c6db20703b5d18d928464f411d0d4ec327508 ]
    
    Commit 5459c0b70467 ("PCI/DPC: Quirk PIO log size for certain Intel Root
    Ports") and commit 3b8803494a06 ("PCI/DPC: Quirk PIO log size for Intel Ice
    Lake Root Ports") add quirks for Ice, Tiger and Alder Lake Root Ports.
    System firmware for Raptor Lake still has the bug, so Linux logs the
    warning below on several Raptor Lake systems like Dell Precision 3581 with
    Intel Raptor Lake processor (0W18NX) system firmware/BIOS version 1.10.1.
    
      pci 0000:00:07.0: [8086:a76e] type 01 class 0x060400
      pci 0000:00:07.0: DPC: RP PIO log size 0 is invalid
      pci 0000:00:07.1: [8086:a73f] type 01 class 0x060400
      pci 0000:00:07.1: DPC: RP PIO log size 0 is invalid
    
    Apply the quirk for Raptor Lake Root Ports as well.
    
    This also enables the DPC driver to dump the RP PIO Log registers when DPC
    is triggered.
    
    Link: https://lore.kernel.org/r/20240305113057.56468-1-pmenzel@molgen.mpg.de
    Reported-by: Niels van Aert <nvaert1986@hotmail.com>
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218560
    Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Cc: <stable@vger.kernel.org>
    Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
    Cc: Niels van Aert <nvaert1986@hotmail.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
PCI/PM: Drain runtime-idle callbacks before driver removal [+ + +]
Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Date:   Tue Mar 5 11:45:38 2024 +0100

    PCI/PM: Drain runtime-idle callbacks before driver removal
    
    [ Upstream commit 9d5286d4e7f68beab450deddbb6a32edd5ecf4bf ]
    
    A race condition between the .runtime_idle() callback and the .remove()
    callback in the rtsx_pcr PCI driver leads to a kernel crash due to an
    unhandled page fault [1].
    
    The problem is that rtsx_pci_runtime_idle() is not expected to be running
    after pm_runtime_get_sync() has been called, but the latter doesn't really
    guarantee that.  It only guarantees that the suspend and resume callbacks
    will not be running when it returns.
    
    However, if a .runtime_idle() callback is already running when
    pm_runtime_get_sync() is called, the latter will notice that the runtime PM
    status of the device is RPM_ACTIVE and it will return right away without
    waiting for the former to complete.  In fact, it cannot wait for
    .runtime_idle() to complete because it may be called from that callback (it
    arguably does not make much sense to do that, but it is not strictly
    prohibited).
    
    Thus in general, whoever is providing a .runtime_idle() callback needs
    to protect it from running in parallel with whatever code runs after
    pm_runtime_get_sync().  [Note that .runtime_idle() will not start after
    pm_runtime_get_sync() has returned, but it may continue running then if it
    has started earlier.]
    
    One way to address that race condition is to call pm_runtime_barrier()
    after pm_runtime_get_sync() (not before it, because a nonzero value of the
    runtime PM usage counter is necessary to prevent runtime PM callbacks from
    being invoked) to wait for the .runtime_idle() callback to complete should
    it be running at that point.  A suitable place for doing that is in
    pci_device_remove() which calls pm_runtime_get_sync() before removing the
    driver, so it may as well call pm_runtime_barrier() subsequently, which
    will prevent the race in question from occurring, not just in the rtsx_pcr
    driver, but in any PCI drivers providing .runtime_idle() callbacks.
    
    Link: https://lore.kernel.org/lkml/20240229062201.49500-1-kai.heng.feng@canonical.com/ # [1]
    Link: https://lore.kernel.org/r/5761426.DvuYhMxLoT@kreacher
    Reported-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Tested-by: Ricky Wu <ricky_wu@realtek.com>
    Acked-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
PCI: dwc: endpoint: Fix advertised resizable BAR size [+ + +]
Author: Niklas Cassel <cassel@kernel.org>
Date:   Thu Mar 7 12:15:20 2024 +0100

    PCI: dwc: endpoint: Fix advertised resizable BAR size
    
    [ Upstream commit 72e34b8593e08a0ee759b7a038e0b178418ea6f8 ]
    
    The commit message in commit fc9a77040b04 ("PCI: designware-ep: Configure
    Resizable BAR cap to advertise the smallest size") claims that it modifies
    the Resizable BAR capability to only advertise support for 1 MB size BARs.
    
    However, the commit writes all zeroes to PCI_REBAR_CAP (the register which
    contains the possible BAR sizes that a BAR be resized to).
    
    According to the spec, it is illegal to not have a bit set in
    PCI_REBAR_CAP, and 1 MB is the smallest size allowed.
    
    Set bit 4 in PCI_REBAR_CAP, so that we actually advertise support for a
    1 MB BAR size.
    
    Before:
            Capabilities: [2e8 v1] Physical Resizable BAR
                    BAR 0: current size: 1MB
                    BAR 1: current size: 1MB
                    BAR 2: current size: 1MB
                    BAR 3: current size: 1MB
                    BAR 4: current size: 1MB
                    BAR 5: current size: 1MB
    After:
            Capabilities: [2e8 v1] Physical Resizable BAR
                    BAR 0: current size: 1MB, supported: 1MB
                    BAR 1: current size: 1MB, supported: 1MB
                    BAR 2: current size: 1MB, supported: 1MB
                    BAR 3: current size: 1MB, supported: 1MB
                    BAR 4: current size: 1MB, supported: 1MB
                    BAR 5: current size: 1MB, supported: 1MB
    
    Fixes: fc9a77040b04 ("PCI: designware-ep: Configure Resizable BAR cap to advertise the smallest size")
    Link: https://lore.kernel.org/linux-pci/20240307111520.3303774-1-cassel@kernel.org
    Signed-off-by: Niklas Cassel <cassel@kernel.org>
    Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
    Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
    Cc: <stable@vger.kernel.org> # 5.2
    Signed-off-by: Sasha Levin <sashal@kernel.org>

PCI: hv: Fix ring buffer size calculation [+ + +]
Author: Michael Kelley <mhklinux@outlook.com>
Date:   Fri Feb 16 12:22:40 2024 -0800

    PCI: hv: Fix ring buffer size calculation
    
    [ Upstream commit b5ff74c1ef50fe08e384026875fec660fadfaedd ]
    
    For a physical PCI device that is passed through to a Hyper-V guest VM,
    current code specifies the VMBus ring buffer size as 4 pages.  But this
    is an inappropriate dependency, since the amount of ring buffer space
    needed is unrelated to PAGE_SIZE. For example, on x86 the ring buffer
    size ends up as 16 Kbytes, while on ARM64 with 64 Kbyte pages, the ring
    size bloats to 256 Kbytes. The ring buffer for PCI pass-thru devices
    is used for only a few messages during device setup and removal, so any
    space above a few Kbytes is wasted.
    
    Fix this by declaring the ring buffer size to be a fixed 16 Kbytes.
    Furthermore, use the VMBUS_RING_SIZE() macro so that the ring buffer
    header is properly accounted for, and so the size is rounded up to a
    page boundary, using the page size for which the kernel is built. While
    w/64 Kbyte pages this results in a 64 Kbyte ring buffer header plus a
    64 Kbyte ring buffer, that's the smallest possible with that page size.
    It's still 128 Kbytes better than the current code.
    
    Link: https://lore.kernel.org/linux-pci/20240216202240.251818-1-mhklinux@outlook.com
    Signed-off-by: Michael Kelley <mhklinux@outlook.com>
    Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
    Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
    Reviewed-by: Ilpo Jarvinen <ilpo.jarvinen@linux.intel.com>
    Reviewed-by: Long Li <longli@microsoft.com>
    Cc: <stable@vger.kernel.org> # 5.15.x
    Signed-off-by: Sasha Levin <sashal@kernel.org>

PCI: qcom: Enable BDF to SID translation properly [+ + +]
Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Date:   Thu Mar 7 16:35:15 2024 +0530

    PCI: qcom: Enable BDF to SID translation properly
    
    [ Upstream commit bf79e33cdd89db498e00a6131e937259de5f2705 ]
    
    Qcom SoCs making use of ARM SMMU require BDF to SID translation table in
    the driver to properly map the SID for the PCIe devices based on their BDF
    identifier. This is currently achieved with the help of
    qcom_pcie_config_sid_1_9_0() function for SoCs supporting the 1_9_0 config.
    
    But With newer Qcom SoCs starting from SM8450, BDF to SID translation is
    set to bypass mode by default in hardware. Due to this, the translation
    table that is set in the qcom_pcie_config_sid_1_9_0() is essentially
    unused and the default SID is used for all endpoints in SoCs starting from
    SM8450.
    
    This is a security concern and also warrants swapping the DeviceID in DT
    while using the GIC ITS to handle MSIs from endpoints. The swapping is
    currently done like below in DT when using GIC ITS:
    
          /*
            * MSIs for BDF (1:0.0) only works with Device ID 0x5980.
            * Hence, the IDs are swapped.
            */
          msi-map = <0x0 &gic_its 0x5981 0x1>,
                    <0x100 &gic_its 0x5980 0x1>;
    
    Here, swapping of the DeviceIDs ensure that the endpoint with BDF (1:0.0)
    gets the DeviceID 0x5980 which is associated with the default SID as per
    the iommu mapping in DT. So MSIs were delivered with IDs swapped so far.
    But this also means the Root Port (0:0.0) won't receive any MSIs (for PME,
    AER etc...)
    
    So let's fix these issues by clearing the BDF to SID bypass mode for all
    SoCs making use of the 1_9_0 config. This allows the PCIe devices to use
    the correct SID, thus avoiding the DeviceID swapping hack in DT and also
    achieving the isolation between devices.
    
    Fixes: 4c9398822106 ("PCI: qcom: Add support for configuring BDF to SID mapping for SM8250")
    Link: https://lore.kernel.org/linux-pci/20240307-pci-bdf-sid-fix-v1-1-9423a7e2d63c@linaro.org
    Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
    Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
    Cc: stable@vger.kernel.org # 5.11
    Signed-off-by: Sasha Levin <sashal@kernel.org>

PCI: qcom: Rename qcom_pcie_config_sid_sm8250() to reflect IP version [+ + +]
Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Date:   Thu Mar 16 13:41:12 2023 +0530

    PCI: qcom: Rename qcom_pcie_config_sid_sm8250() to reflect IP version
    
    [ Upstream commit 1f70939871b260b52e9d1941f1cad740b7295c2c ]
    
    qcom_pcie_config_sid_sm8250() function no longer applies only to SM8250.
    So let's rename it to reflect the actual IP version and also move its
    definition to keep it sorted as per IP revisions.
    
    Link: https://lore.kernel.org/r/20230316081117.14288-15-manivannan.sadhasivam@linaro.org
    Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
    Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
    Stable-dep-of: bf79e33cdd89 ("PCI: qcom: Enable BDF to SID translation properly")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
pci_iounmap(): Fix MMIO mapping leak [+ + +]
Author: Philipp Stanner <pstanner@redhat.com>
Date:   Wed Jan 31 10:00:20 2024 +0100

    pci_iounmap(): Fix MMIO mapping leak
    
    [ Upstream commit 7626913652cc786c238e2dd7d8740b17d41b2637 ]
    
    The #ifdef ARCH_HAS_GENERIC_IOPORT_MAP accidentally also guards iounmap(),
    which means MMIO mappings are leaked.
    
    Move the guard so we call iounmap() for MMIO mappings.
    
    Fixes: 316e8d79a095 ("pci_iounmap'2: Electric Boogaloo: try to make sense of it all")
    Link: https://lore.kernel.org/r/20240131090023.12331-2-pstanner@redhat.com
    Reported-by: Danilo Krummrich <dakr@redhat.com>
    Suggested-by: Arnd Bergmann <arnd@kernel.org>
    Signed-off-by: Philipp Stanner <pstanner@redhat.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Arnd Bergmann <arnd@arndb.de>
    Cc: <stable@vger.kernel.org> # v5.15+
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
phy: tegra: xusb: Add API to retrieve the port number of phy [+ + +]
Author: Wayne Chang <waynec@nvidia.com>
Date:   Thu Mar 7 11:03:27 2024 +0800

    phy: tegra: xusb: Add API to retrieve the port number of phy
    
    [ Upstream commit d843f031d9e90462253015bc0bd9e3852d206bf2 ]
    
    This patch introduces a new API, tegra_xusb_padctl_get_port_number,
    to the Tegra XUSB Pad Controller driver. This API is used to identify
    the USB port that is associated with a given PHY.
    
    The function takes a PHY pointer for either a USB2 PHY or USB3 PHY as input
    and returns the corresponding port number. If the PHY pointer is invalid,
    it returns -ENODEV.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Wayne Chang <waynec@nvidia.com>
    Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
    Tested-by: Jon Hunter <jonathanh@nvidia.com>
    Link: https://lore.kernel.org/r/20240307030328.1487748-2-waynec@nvidia.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
platform/x86: p2sb: On Goldmont only cache P2SB and SPI devfn BAR [+ + +]
Author: Hans de Goede <hdegoede@redhat.com>
Date:   Mon Mar 4 14:43:55 2024 +0100

    platform/x86: p2sb: On Goldmont only cache P2SB and SPI devfn BAR
    
    commit aec7d25b497ce4a8d044e9496de0aa433f7f8f06 upstream.
    
    On Goldmont p2sb_bar() only ever gets called for 2 devices, the actual P2SB
    devfn 13,0 and the SPI controller which is part of the P2SB, devfn 13,2.
    
    But the current p2sb code tries to cache BAR0 info for all of
    devfn 13,0 to 13,7 . This involves calling pci_scan_single_device()
    for device 13 functions 0-7 and the hw does not seem to like
    pci_scan_single_device() getting called for some of the other hidden
    devices. E.g. on an ASUS VivoBook D540NV-GQ065T this leads to continuous
    ACPI errors leading to high CPU usage.
    
    Fix this by only caching BAR0 info and thus only calling
    pci_scan_single_device() for the P2SB and the SPI controller.
    
    Fixes: 5913320eb0b3 ("platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe")
    Reported-by: Danil Rybakov <danilrybakov249@gmail.com>
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218531
    Tested-by: Danil Rybakov <danilrybakov249@gmail.com>
    Signed-off-by: Hans de Goede <hdegoede@redhat.com>
    Link: https://lore.kernel.org/r/20240304134356.305375-2-hdegoede@redhat.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
PM: sleep: wakeirq: fix wake irq warning in system suspend [+ + +]
Author: Qingliang Li <qingliang.li@mediatek.com>
Date:   Fri Mar 1 17:26:57 2024 +0800

    PM: sleep: wakeirq: fix wake irq warning in system suspend
    
    [ Upstream commit e7a7681c859643f3f2476b2a28a494877fd89442 ]
    
    When driver uses pm_runtime_force_suspend() as the system suspend callback
    function and registers the wake irq with reverse enable ordering, the wake
    irq will be re-enabled when entering system suspend, triggering an
    'Unbalanced enable for IRQ xxx' warning. In this scenario, the call
    sequence during system suspend is as follows:
      suspend_devices_and_enter()
        -> dpm_suspend_start()
          -> dpm_run_callback()
            -> pm_runtime_force_suspend()
              -> dev_pm_enable_wake_irq_check()
              -> dev_pm_enable_wake_irq_complete()
    
        -> suspend_enter()
          -> dpm_suspend_noirq()
            -> device_wakeup_arm_wake_irqs()
              -> dev_pm_arm_wake_irq()
    
    To fix this issue, complete the setting of WAKE_IRQ_DEDICATED_ENABLED flag
    in dev_pm_enable_wake_irq_complete() to avoid redundant irq enablement.
    
    Fixes: 8527beb12087 ("PM: sleep: wakeirq: fix wake irq arming")
    Reviewed-by: Dhruva Gole <d-gole@ti.com>
    Signed-off-by: Qingliang Li <qingliang.li@mediatek.com>
    Reviewed-by: Johan Hovold <johan+linaro@kernel.org>
    Cc: 5.16+ <stable@vger.kernel.org> # 5.16+
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

PM: suspend: Set mem_sleep_current during kernel command line setup [+ + +]
Author: Maulik Shah <quic_mkshah@quicinc.com>
Date:   Thu Feb 29 12:14:59 2024 +0530

    PM: suspend: Set mem_sleep_current during kernel command line setup
    
    [ Upstream commit 9bc4ffd32ef8943f5c5a42c9637cfd04771d021b ]
    
    psci_init_system_suspend() invokes suspend_set_ops() very early during
    bootup even before kernel command line for mem_sleep_default is setup.
    This leads to kernel command line mem_sleep_default=s2idle not working
    as mem_sleep_current gets changed to deep via suspend_set_ops() and never
    changes back to s2idle.
    
    Set mem_sleep_current along with mem_sleep_default during kernel command
    line setup as default suspend mode.
    
    Fixes: faf7ec4a92c0 ("drivers: firmware: psci: add system suspend support")
    CC: stable@vger.kernel.org # 5.4+
    Signed-off-by: Maulik Shah <quic_mkshah@quicinc.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
powerpc/fsl: Fix mfpmr build errors with newer binutils [+ + +]
Author: Michael Ellerman <mpe@ellerman.id.au>
Date:   Thu Feb 29 23:25:19 2024 +1100

    powerpc/fsl: Fix mfpmr build errors with newer binutils
    
    [ Upstream commit 5f491356b7149564ab22323ccce79c8d595bfd0c ]
    
    Binutils 2.38 complains about the use of mfpmr when building
    ppc6xx_defconfig:
    
        CC      arch/powerpc/kernel/pmc.o
      {standard input}: Assembler messages:
      {standard input}:45: Error: unrecognized opcode: `mfpmr'
      {standard input}:56: Error: unrecognized opcode: `mtpmr'
    
    This is because by default the kernel is built with -mcpu=powerpc, and
    the mt/mfpmr instructions are not defined.
    
    It can be avoided by enabling CONFIG_E300C3_CPU, but just adding that to
    the defconfig will leave open the possibility of randconfig failures.
    
    So add machine directives around the mt/mfpmr instructions to tell
    binutils how to assemble them.
    
    Cc: stable@vger.kernel.org
    Reported-by: Jan-Benedict Glaw <jbglaw@lug-owl.de>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://msgid.link/20240229122521.762431-3-mpe@ellerman.id.au
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
powerpc/smp: Adjust nr_cpu_ids to cover all threads of a core [+ + +]
Author: Michael Ellerman <mpe@ellerman.id.au>
Date:   Thu Feb 15 00:14:04 2024 +1100

    powerpc/smp: Adjust nr_cpu_ids to cover all threads of a core
    
    [ Upstream commit 5580e96dad5a439d561d9648ffcbccb739c2a120 ]
    
    If nr_cpu_ids is too low to include at least all the threads of a single
    core adjust nr_cpu_ids upwards. This avoids triggering odd bugs in code
    that assumes all threads of a core are available.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://msgid.link/20231229120107.2281153-1-mpe@ellerman.id.au
    Signed-off-by: Sasha Levin <sashal@kernel.org>

powerpc/smp: Increase nr_cpu_ids to include the boot CPU [+ + +]
Author: Michael Ellerman <mpe@ellerman.id.au>
Date:   Thu Feb 15 00:14:04 2024 +1100

    powerpc/smp: Increase nr_cpu_ids to include the boot CPU
    
    [ Upstream commit 777f81f0a9c780a6443bcf2c7785f0cc2e87c1ef ]
    
    If nr_cpu_ids is too low to include the boot CPU adjust nr_cpu_ids
    upward. Otherwise the kernel will BUG when trying to allocate a paca
    for the boot CPU and fail to boot.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://msgid.link/20231229120107.2281153-2-mpe@ellerman.id.au
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
powerpc: xor_vmx: Add '-mhard-float' to CFLAGS [+ + +]
Author: Nathan Chancellor <nathan@kernel.org>
Date:   Sat Jan 27 11:07:43 2024 -0700

    powerpc: xor_vmx: Add '-mhard-float' to CFLAGS
    
    [ Upstream commit 35f20786c481d5ced9283ff42de5c69b65e5ed13 ]
    
    arch/powerpc/lib/xor_vmx.o is built with '-msoft-float' (from the main
    powerpc Makefile) and '-maltivec' (from its CFLAGS), which causes an
    error when building with clang after a recent change in main:
    
      error: option '-msoft-float' cannot be specified with '-maltivec'
      make[6]: *** [scripts/Makefile.build:243: arch/powerpc/lib/xor_vmx.o] Error 1
    
    Explicitly add '-mhard-float' before '-maltivec' in xor_vmx.o's CFLAGS
    to override the previous inclusion of '-msoft-float' (as the last option
    wins), which matches how other areas of the kernel use '-maltivec', such
    as AMDGPU.
    
    Cc: stable@vger.kernel.org
    Closes: https://github.com/ClangBuiltLinux/linux/issues/1986
    Link: https://github.com/llvm/llvm-project/commit/4792f912b232141ecba4cbae538873be3c28556c
    Signed-off-by: Nathan Chancellor <nathan@kernel.org>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://msgid.link/20240127-ppc-xor_vmx-drop-msoft-float-v1-1-f24140e81376@kernel.org
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
printk: Update @console_may_schedule in console_trylock_spinning() [+ + +]
Author: John Ogness <john.ogness@linutronix.de>
Date:   Mon Feb 26 13:07:24 2024 +0106

    printk: Update @console_may_schedule in console_trylock_spinning()
    
    [ Upstream commit 8076972468584d4a21dab9aa50e388b3ea9ad8c7 ]
    
    console_trylock_spinning() may takeover the console lock from a
    schedulable context. Update @console_may_schedule to make sure it
    reflects a trylock acquire.
    
    Reported-by: Mukesh Ojha <quic_mojha@quicinc.com>
    Closes: https://lore.kernel.org/lkml/20240222090538.23017-1-quic_mojha@quicinc.com
    Fixes: dbdda842fe96 ("printk: Add console owner and waiter logic to load balance console writes")
    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Mukesh Ojha <quic_mojha@quicinc.com>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/875xybmo2z.fsf@jogness.linutronix.de
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
pwm: img: fix pwm clock lookup [+ + +]
Author: Zoltan HERPAI <wigyori@uid0.hu>
Date:   Wed Mar 20 09:36:02 2024 +0100

    pwm: img: fix pwm clock lookup
    
    [ Upstream commit 9eb05877dbee03064d3d3483cd6702f610d5a358 ]
    
    22e8e19 has introduced a regression in the imgchip->pwm_clk lookup, whereas
    the clock name has also been renamed to "imgchip". This causes the driver
    failing to load:
    
    [    0.546905] img-pwm 18101300.pwm: failed to get imgchip clock
    [    0.553418] img-pwm: probe of 18101300.pwm failed with error -2
    
    Fix this lookup by reverting the clock name back to "pwm".
    
    Signed-off-by: Zoltan HERPAI <wigyori@uid0.hu>
    Link: https://lore.kernel.org/r/20240320083602.81592-1-wigyori@uid0.hu
    Fixes: 22e8e19a46f7 ("pwm: img: Rename variable pointing to driver private data")
    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
remoteproc: virtio: Fix wdg cannot recovery remote processor [+ + +]
Author: Joakim Zhang <joakim.zhang@cixtech.com>
Date:   Sun Dec 17 13:36:59 2023 +0800

    remoteproc: virtio: Fix wdg cannot recovery remote processor
    
    [ Upstream commit b327c72753d6a78de37aed6c35756f2ef62897ee ]
    
    Recovery remote processor failed when wdg irq received:
    [    0.842574] remoteproc remoteproc0: crash detected in cix-dsp-rproc: type watchdog
    [    0.842750] remoteproc remoteproc0: handling crash #1 in cix-dsp-rproc
    [    0.842824] remoteproc remoteproc0: recovering cix-dsp-rproc
    [    0.843342] remoteproc remoteproc0: stopped remote processor cix-dsp-rproc
    [    0.847901] rproc-virtio rproc-virtio.0.auto: Failed to associate buffer
    [    0.847979] remoteproc remoteproc0: failed to probe subdevices for cix-dsp-rproc: -16
    
    The reason is that dma coherent mem would not be released when
    recovering the remote processor, due to rproc_virtio_remove()
    would not be called, where the mem released. It will fail when
    it try to allocate and associate buffer again.
    
    Releasing reserved memory from rproc_virtio_dev_release(), instead of
    rproc_virtio_remove().
    
    Fixes: 1d7b61c06dc3 ("remoteproc: virtio: Create platform device for the remoteproc_virtio")
    Signed-off-by: Joakim Zhang <joakim.zhang@cixtech.com>
    Acked-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20231217053659.3245745-1-joakim.zhang@cixtech.com
    Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
Revert "block/mq-deadline: use correct way to throttling write requests" [+ + +]
Author: Bart Van Assche <bvanassche@acm.org>
Date:   Wed Mar 13 14:42:18 2024 -0700

    Revert "block/mq-deadline: use correct way to throttling write requests"
    
    [ Upstream commit 256aab46e31683d76d45ccbedc287b4d3f3e322b ]
    
    The code "max(1U, 3 * (1U << shift)  / 4)" comes from the Kyber I/O
    scheduler. The Kyber I/O scheduler maintains one internal queue per hwq
    and hence derives its async_depth from the number of hwq tags. Using
    this approach for the mq-deadline scheduler is wrong since the
    mq-deadline scheduler maintains one internal queue for all hwqs
    combined. Hence this revert.
    
    Cc: stable@vger.kernel.org
    Cc: Damien Le Moal <dlemoal@kernel.org>
    Cc: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
    Cc: Zhiguo Niu <Zhiguo.Niu@unisoc.com>
    Fixes: d47f9717e5cf ("block/mq-deadline: use correct way to throttling write requests")
    Signed-off-by: Bart Van Assche <bvanassche@acm.org>
    Link: https://lore.kernel.org/r/20240313214218.1736147-1-bvanassche@acm.org
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
Revert "usb: phy: generic: Get the vbus supply" [+ + +]
Author: Alexander Stein <alexander.stein@ew.tq-group.com>
Date:   Thu Mar 14 10:26:27 2024 +0100

    Revert "usb: phy: generic: Get the vbus supply"
    
    commit fdada0db0b2ae2addef4ccafe50937874dbeeebe upstream.
    
    This reverts commit 75fd6485cccef269ac9eb3b71cf56753341195ef.
    This patch was applied twice by accident, causing probe failures.
    Revert the accident.
    
    Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
    Fixes: 75fd6485ccce ("usb: phy: generic: Get the vbus supply")
    Cc: stable <stable@kernel.org>
    Reviewed-by: Sean Anderson <sean.anderson@seco.com>
    Link: https://lore.kernel.org/r/20240314092628.1869414-1-alexander.stein@ew.tq-group.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
ring-buffer: Do not set shortest_full when full target is hit [+ + +]
Author: Steven Rostedt (Google) <rostedt@goodmis.org>
Date:   Tue Mar 12 11:56:41 2024 -0400

    ring-buffer: Do not set shortest_full when full target is hit
    
    [ Upstream commit 761d9473e27f0c8782895013a3e7b52a37c8bcfc ]
    
    The rb_watermark_hit() checks if the amount of data in the ring buffer is
    above the percentage level passed in by the "full" variable. If it is, it
    returns true.
    
    But it also sets the "shortest_full" field of the cpu_buffer that informs
    writers that it needs to call the irq_work if the amount of data on the
    ring buffer is above the requested amount.
    
    The rb_watermark_hit() always sets the shortest_full even if the amount in
    the ring buffer is what it wants. As it is not going to wait, because it
    has what it wants, there's no reason to set shortest_full.
    
    Link: https://lore.kernel.org/linux-trace-kernel/20240312115641.6aa8ba08@gandalf.local.home
    
    Cc: stable@vger.kernel.org
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Fixes: 42fb0a1e84ff5 ("tracing/ring-buffer: Have polling block on watermark")
    Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

ring-buffer: Fix full_waiters_pending in poll [+ + +]
Author: Steven Rostedt (Google) <rostedt@goodmis.org>
Date:   Tue Mar 12 09:19:20 2024 -0400

    ring-buffer: Fix full_waiters_pending in poll
    
    [ Upstream commit 8145f1c35fa648da662078efab299c4467b85ad5 ]
    
    If a reader of the ring buffer is doing a poll, and waiting for the ring
    buffer to hit a specific watermark, there could be a case where it gets
    into an infinite ping-pong loop.
    
    The poll code has:
    
      rbwork->full_waiters_pending = true;
      if (!cpu_buffer->shortest_full ||
          cpu_buffer->shortest_full > full)
             cpu_buffer->shortest_full = full;
    
    The writer will see full_waiters_pending and check if the ring buffer is
    filled over the percentage of the shortest_full value. If it is, it calls
    an irq_work to wake up all the waiters.
    
    But the code could get into a circular loop:
    
            CPU 0                                   CPU 1
            -----                                   -----
     [ Poll ]
       [ shortest_full = 0 ]
       rbwork->full_waiters_pending = true;
                                              if (rbwork->full_waiters_pending &&
                                                  [ buffer percent ] > shortest_full) {
                                                     rbwork->wakeup_full = true;
                                                     [ queue_irqwork ]
    
       cpu_buffer->shortest_full = full;
    
                                              [ IRQ work ]
                                              if (rbwork->wakeup_full) {
                                                    cpu_buffer->shortest_full = 0;
                                                    wakeup poll waiters;
      [woken]
       if ([ buffer percent ] > full)
          break;
       rbwork->full_waiters_pending = true;
                                              if (rbwork->full_waiters_pending &&
                                                  [ buffer percent ] > shortest_full) {
                                                     rbwork->wakeup_full = true;
                                                     [ queue_irqwork ]
    
       cpu_buffer->shortest_full = full;
    
                                              [ IRQ work ]
                                              if (rbwork->wakeup_full) {
                                                    cpu_buffer->shortest_full = 0;
                                                    wakeup poll waiters;
      [woken]
    
     [ Wash, rinse, repeat! ]
    
    In the poll, the shortest_full needs to be set before the
    full_pending_waiters, as once that is set, the writer will compare the
    current shortest_full (which is incorrect) to decide to call the irq_work,
    which will reset the shortest_full (expecting the readers to update it).
    
    Also move the setting of full_waiters_pending after the check if the ring
    buffer has the required percentage filled. There's no reason to tell the
    writer to wake up waiters if there are no waiters.
    
    Link: https://lore.kernel.org/linux-trace-kernel/20240312131952.630922155@goodmis.org
    
    Cc: stable@vger.kernel.org
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Fixes: 42fb0a1e84ff5 ("tracing/ring-buffer: Have polling block on watermark")
    Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

ring-buffer: Fix resetting of shortest_full [+ + +]
Author: Steven Rostedt (Google) <rostedt@goodmis.org>
Date:   Fri Mar 8 15:24:04 2024 -0500

    ring-buffer: Fix resetting of shortest_full
    
    [ Upstream commit 68282dd930ea38b068ce2c109d12405f40df3f93 ]
    
    The "shortest_full" variable is used to keep track of the waiter that is
    waiting for the smallest amount on the ring buffer before being woken up.
    When a tasks waits on the ring buffer, it passes in a "full" value that is
    a percentage. 0 means wake up on any data. 1-100 means wake up from 1% to
    100% full buffer.
    
    As all waiters are on the same wait queue, the wake up happens for the
    waiter with the smallest percentage.
    
    The problem is that the smallest_full on the cpu_buffer that stores the
    smallest amount doesn't get reset when all the waiters are woken up. It
    does get reset when the ring buffer is reset (echo > /sys/kernel/tracing/trace).
    
    This means that tasks may be woken up more often then when they want to
    be. Instead, have the shortest_full field get reset just before waking up
    all the tasks. If the tasks wait again, they will update the shortest_full
    before sleeping.
    
    Also add locking around setting of shortest_full in the poll logic, and
    change "work" to "rbwork" to match the variable name for rb_irq_work
    structures that are used in other places.
    
    Link: https://lore.kernel.org/linux-trace-kernel/20240308202431.948914369@goodmis.org
    
    Cc: stable@vger.kernel.org
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: linke li <lilinke99@qq.com>
    Cc: Rabin Vincent <rabin@rab.in>
    Fixes: 2c2b0a78b3739 ("ring-buffer: Add percentage of ring buffer full to wake up reader")
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Stable-dep-of: 8145f1c35fa6 ("ring-buffer: Fix full_waiters_pending in poll")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

ring-buffer: Fix waking up ring buffer readers [+ + +]
Author: Steven Rostedt (Google) <rostedt@goodmis.org>
Date:   Fri Mar 8 15:24:03 2024 -0500

    ring-buffer: Fix waking up ring buffer readers
    
    [ Upstream commit b3594573681b53316ec0365332681a30463edfd6 ]
    
    A task can wait on a ring buffer for when it fills up to a specific
    watermark. The writer will check the minimum watermark that waiters are
    waiting for and if the ring buffer is past that, it will wake up all the
    waiters.
    
    The waiters are in a wait loop, and will first check if a signal is
    pending and then check if the ring buffer is at the desired level where it
    should break out of the loop.
    
    If a file that uses a ring buffer closes, and there's threads waiting on
    the ring buffer, it needs to wake up those threads. To do this, a
    "wait_index" was used.
    
    Before entering the wait loop, the waiter will read the wait_index. On
    wakeup, it will check if the wait_index is different than when it entered
    the loop, and will exit the loop if it is. The waker will only need to
    update the wait_index before waking up the waiters.
    
    This had a couple of bugs. One trivial one and one broken by design.
    
    The trivial bug was that the waiter checked the wait_index after the
    schedule() call. It had to be checked between the prepare_to_wait() and
    the schedule() which it was not.
    
    The main bug is that the first check to set the default wait_index will
    always be outside the prepare_to_wait() and the schedule(). That's because
    the ring_buffer_wait() doesn't have enough context to know if it should
    break out of the loop.
    
    The loop itself is not needed, because all the callers to the
    ring_buffer_wait() also has their own loop, as the callers have a better
    sense of what the context is to decide whether to break out of the loop
    or not.
    
    Just have the ring_buffer_wait() block once, and if it gets woken up, exit
    the function and let the callers decide what to do next.
    
    Link: https://lore.kernel.org/all/CAHk-=whs5MdtNjzFkTyaUy=vHi=qwWgPi0JgTe6OYUYMNSRZfg@mail.gmail.com/
    Link: https://lore.kernel.org/linux-trace-kernel/20240308202431.792933613@goodmis.org
    
    Cc: stable@vger.kernel.org
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: linke li <lilinke99@qq.com>
    Cc: Rabin Vincent <rabin@rab.in>
    Fixes: e30f53aad2202 ("tracing: Do not busy wait in buffer splice")
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Stable-dep-of: 761d9473e27f ("ring-buffer: Do not set shortest_full when full target is hit")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

ring-buffer: Use wait_event_interruptible() in ring_buffer_wait() [+ + +]
Author: Steven Rostedt (Google) <rostedt@goodmis.org>
Date:   Tue Mar 12 08:15:07 2024 -0400

    ring-buffer: Use wait_event_interruptible() in ring_buffer_wait()
    
    [ Upstream commit 7af9ded0c2caac0a95f33df5cb04706b0f502588 ]
    
    Convert ring_buffer_wait() over to wait_event_interruptible(). The default
    condition is to execute the wait loop inside __wait_event() just once.
    
    This does not change the ring_buffer_wait() prototype yet, but
    restructures the code so that it can take a "cond" and "data" parameter
    and will call wait_event_interruptible() with a helper function as the
    condition.
    
    The helper function (rb_wait_cond) takes the cond function and data
    parameters. It will first check if the buffer hit the watermark defined by
    the "full" parameter and then call the passed in condition parameter. If
    either are true, it returns true.
    
    If rb_wait_cond() does not return true, it will set the appropriate
    "waiters_pending" flag and returns false.
    
    Link: https://lore.kernel.org/linux-trace-kernel/CAHk-=wgsNgewHFxZAJiAQznwPMqEtQmi1waeS2O1v6L4c_Um5A@mail.gmail.com/
    Link: https://lore.kernel.org/linux-trace-kernel/20240312121703.399598519@goodmis.org
    
    Cc: stable@vger.kernel.org
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: linke li <lilinke99@qq.com>
    Cc: Rabin Vincent <rabin@rab.in>
    Fixes: f3ddb74ad0790 ("tracing: Wake up ring buffer waiters on closing of the file")
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
s390/zcrypt: fix reference counting on zcrypt card objects [+ + +]
Author: Harald Freudenberger <freude@linux.ibm.com>
Date:   Thu Feb 29 15:20:09 2024 +0100

    s390/zcrypt: fix reference counting on zcrypt card objects
    
    [ Upstream commit 50ed48c80fecbe17218afed4f8bed005c802976c ]
    
    Tests with hot-plugging crytpo cards on KVM guests with debug
    kernel build revealed an use after free for the load field of
    the struct zcrypt_card. The reason was an incorrect reference
    handling of the zcrypt card object which could lead to a free
    of the zcrypt card object while it was still in use.
    
    This is an example of the slab message:
    
        kernel: 0x00000000885a7512-0x00000000885a7513 @offset=1298. First byte 0x68 instead of 0x6b
        kernel: Allocated in zcrypt_card_alloc+0x36/0x70 [zcrypt] age=18046 cpu=3 pid=43
        kernel:  kmalloc_trace+0x3f2/0x470
        kernel:  zcrypt_card_alloc+0x36/0x70 [zcrypt]
        kernel:  zcrypt_cex4_card_probe+0x26/0x380 [zcrypt_cex4]
        kernel:  ap_device_probe+0x15c/0x290
        kernel:  really_probe+0xd2/0x468
        kernel:  driver_probe_device+0x40/0xf0
        kernel:  __device_attach_driver+0xc0/0x140
        kernel:  bus_for_each_drv+0x8c/0xd0
        kernel:  __device_attach+0x114/0x198
        kernel:  bus_probe_device+0xb4/0xc8
        kernel:  device_add+0x4d2/0x6e0
        kernel:  ap_scan_adapter+0x3d0/0x7c0
        kernel:  ap_scan_bus+0x5a/0x3b0
        kernel:  ap_scan_bus_wq_callback+0x40/0x60
        kernel:  process_one_work+0x26e/0x620
        kernel:  worker_thread+0x21c/0x440
        kernel: Freed in zcrypt_card_put+0x54/0x80 [zcrypt] age=9024 cpu=3 pid=43
        kernel:  kfree+0x37e/0x418
        kernel:  zcrypt_card_put+0x54/0x80 [zcrypt]
        kernel:  ap_device_remove+0x4c/0xe0
        kernel:  device_release_driver_internal+0x1c4/0x270
        kernel:  bus_remove_device+0x100/0x188
        kernel:  device_del+0x164/0x3c0
        kernel:  device_unregister+0x30/0x90
        kernel:  ap_scan_adapter+0xc8/0x7c0
        kernel:  ap_scan_bus+0x5a/0x3b0
        kernel:  ap_scan_bus_wq_callback+0x40/0x60
        kernel:  process_one_work+0x26e/0x620
        kernel:  worker_thread+0x21c/0x440
        kernel:  kthread+0x150/0x168
        kernel:  __ret_from_fork+0x3c/0x58
        kernel:  ret_from_fork+0xa/0x30
        kernel: Slab 0x00000372022169c0 objects=20 used=18 fp=0x00000000885a7c88 flags=0x3ffff00000000a00(workingset|slab|node=0|zone=1|lastcpupid=0x1ffff)
        kernel: Object 0x00000000885a74b8 @offset=1208 fp=0x00000000885a7c88
        kernel: Redzone  00000000885a74b0: bb bb bb bb bb bb bb bb                          ........
        kernel: Object   00000000885a74b8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
        kernel: Object   00000000885a74c8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
        kernel: Object   00000000885a74d8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
        kernel: Object   00000000885a74e8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
        kernel: Object   00000000885a74f8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
        kernel: Object   00000000885a7508: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 68 4b 6b 6b 6b a5  kkkkkkkkkkhKkkk.
        kernel: Redzone  00000000885a7518: bb bb bb bb bb bb bb bb                          ........
        kernel: Padding  00000000885a756c: 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a              ZZZZZZZZZZZZ
        kernel: CPU: 0 PID: 387 Comm: systemd-udevd Not tainted 6.8.0-HF #2
        kernel: Hardware name: IBM 3931 A01 704 (KVM/Linux)
        kernel: Call Trace:
        kernel:  [<00000000ca5ab5b8>] dump_stack_lvl+0x90/0x120
        kernel:  [<00000000c99d78bc>] check_bytes_and_report+0x114/0x140
        kernel:  [<00000000c99d53cc>] check_object+0x334/0x3f8
        kernel:  [<00000000c99d820c>] alloc_debug_processing+0xc4/0x1f8
        kernel:  [<00000000c99d852e>] get_partial_node.part.0+0x1ee/0x3e0
        kernel:  [<00000000c99d94ec>] ___slab_alloc+0xaf4/0x13c8
        kernel:  [<00000000c99d9e38>] __slab_alloc.constprop.0+0x78/0xb8
        kernel:  [<00000000c99dc8dc>] __kmalloc+0x434/0x590
        kernel:  [<00000000c9b4c0ce>] ext4_htree_store_dirent+0x4e/0x1c0
        kernel:  [<00000000c9b908a2>] htree_dirblock_to_tree+0x17a/0x3f0
        kernel:  [<00000000c9b919dc>] ext4_htree_fill_tree+0x134/0x400
        kernel:  [<00000000c9b4b3d0>] ext4_dx_readdir+0x160/0x2f0
        kernel:  [<00000000c9b4bedc>] ext4_readdir+0x5f4/0x760
        kernel:  [<00000000c9a7efc4>] iterate_dir+0xb4/0x280
        kernel:  [<00000000c9a7f1ea>] __do_sys_getdents64+0x5a/0x120
        kernel:  [<00000000ca5d6946>] __do_syscall+0x256/0x310
        kernel:  [<00000000ca5eea10>] system_call+0x70/0x98
        kernel: INFO: lockdep is turned off.
        kernel: FIX kmalloc-96: Restoring Poison 0x00000000885a7512-0x00000000885a7513=0x6b
        kernel: FIX kmalloc-96: Marking all objects used
    
    The fix is simple: Before use of the queue not only the queue object
    but also the card object needs to increase it's reference count
    with a call to zcrypt_card_get(). Similar after use of the queue
    not only the queue but also the card object's reference count is
    decreased with zcrypt_card_put().
    
    Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
    Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
scsi: core: Fix unremoved procfs host directory regression [+ + +]
Author: Guilherme G. Piccoli <gpiccoli@igalia.com>
Date:   Wed Mar 13 08:21:20 2024 -0300

    scsi: core: Fix unremoved procfs host directory regression
    
    commit f23a4d6e07570826fe95023ca1aa96a011fa9f84 upstream.
    
    Commit fc663711b944 ("scsi: core: Remove the /proc/scsi/${proc_name}
    directory earlier") fixed a bug related to modules loading/unloading, by
    adding a call to scsi_proc_hostdir_rm() on scsi_remove_host(). But that led
    to a potential duplicate call to the hostdir_rm() routine, since it's also
    called from scsi_host_dev_release(). That triggered a regression report,
    which was then fixed by commit be03df3d4bfe ("scsi: core: Fix a procfs host
    directory removal regression"). The fix just dropped the hostdir_rm() call
    from dev_release().
    
    But it happens that this proc directory is created on scsi_host_alloc(),
    and that function "pairs" with scsi_host_dev_release(), while
    scsi_remove_host() pairs with scsi_add_host(). In other words, it seems the
    reason for removing the proc directory on dev_release() was meant to cover
    cases in which a SCSI host structure was allocated, but the call to
    scsi_add_host() didn't happen. And that pattern happens to exist in some
    error paths, for example.
    
    Syzkaller causes that by using USB raw gadget device, error'ing on
    usb-storage driver, at usb_stor_probe2(). By checking that path, we can see
    that the BadDevice label leads to a scsi_host_put() after a SCSI host
    allocation, but there's no call to scsi_add_host() in such path. That leads
    to messages like this in dmesg (and a leak of the SCSI host proc
    structure):
    
    usb-storage 4-1:87.51: USB Mass Storage device detected
    proc_dir_entry 'scsi/usb-storage' already registered
    WARNING: CPU: 1 PID: 3519 at fs/proc/generic.c:377 proc_register+0x347/0x4e0 fs/proc/generic.c:376
    
    The proper fix seems to still call scsi_proc_hostdir_rm() on dev_release(),
    but guard that with the state check for SHOST_CREATED; there is even a
    comment in scsi_host_dev_release() detailing that: such conditional is
    meant for cases where the SCSI host was allocated but there was no calls to
    {add,remove}_host(), like the usb-storage case.
    
    This is what we propose here and with that, the error path of usb-storage
    does not trigger the warning anymore.
    
    Reported-by: syzbot+c645abf505ed21f931b5@syzkaller.appspotmail.com
    Fixes: be03df3d4bfe ("scsi: core: Fix a procfs host directory removal regression")
    Cc: stable@vger.kernel.org
    Cc: Bart Van Assche <bvanassche@acm.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
    Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
    Link: https://lore.kernel.org/r/20240313113006.2834799-1-gpiccoli@igalia.com
    Reviewed-by: Bart Van Assche <bvanassche@acm.org>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: libsas: Add a helper sas_get_sas_addr_and_dev_type() [+ + +]
Author: Xingui Yang <yangxingui@huawei.com>
Date:   Thu Mar 7 14:14:12 2024 +0000

    scsi: libsas: Add a helper sas_get_sas_addr_and_dev_type()
    
    commit a57345279fd311ba679b8083feb0eec5272c7729 upstream.
    
    Add a helper to get attached_sas_addr and device type from disc_resp.
    
    Suggested-by: John Garry <john.g.garry@oracle.com>
    Signed-off-by: Xingui Yang <yangxingui@huawei.com>
    Link: https://lore.kernel.org/r/20240307141413.48049-2-yangxingui@huawei.com
    Reviewed-by: John Garry <john.g.garry@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: libsas: Fix disk not being scanned in after being removed [+ + +]
Author: Xingui Yang <yangxingui@huawei.com>
Date:   Thu Mar 7 14:14:13 2024 +0000

    scsi: libsas: Fix disk not being scanned in after being removed
    
    commit 8e68a458bcf5b5cb9c3624598bae28f08251601f upstream.
    
    As of commit d8649fc1c5e4 ("scsi: libsas: Do discovery on empty PHY to
    update PHY info"), do discovery will send a new SMP_DISCOVER and update
    phy->phy_change_count. We found that if the disk is reconnected and phy
    change_count changes at this time, the disk scanning process will not be
    triggered.
    
    Therefore, call sas_set_ex_phy() to update the PHY info with the results of
    the last query. And because the previous phy info will be used when calling
    sas_unregister_devs_sas_addr(), sas_unregister_devs_sas_addr() should be
    called before sas_set_ex_phy().
    
    Fixes: d8649fc1c5e4 ("scsi: libsas: Do discovery on empty PHY to update PHY info")
    Signed-off-by: Xingui Yang <yangxingui@huawei.com>
    Link: https://lore.kernel.org/r/20240307141413.48049-3-yangxingui@huawei.com
    Reviewed-by: John Garry <john.g.garry@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: lpfc: Correct size for cmdwqe/rspwqe for memset() [+ + +]
Author: Muhammad Usama Anjum <usama.anjum@collabora.com>
Date:   Mon Mar 4 14:11:19 2024 +0500

    scsi: lpfc: Correct size for cmdwqe/rspwqe for memset()
    
    commit 16cc2ba71b9f6440805aef7f92ba0f031f79b765 upstream.
    
    The cmdwqe and rspwqe are of type lpfc_wqe128. They should be memset() with
    the same type.
    
    Fixes: 61910d6a5243 ("scsi: lpfc: SLI path split: Refactor CT paths")
    Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
    Link: https://lore.kernel.org/r/20240304091119.847060-1-usama.anjum@collabora.com
    Reviewed-by: Justin Tee <justin.tee@broadcom.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: lpfc: Correct size for wqe for memset() [+ + +]
Author: Muhammad Usama Anjum <usama.anjum@collabora.com>
Date:   Mon Mar 4 14:06:48 2024 +0500

    scsi: lpfc: Correct size for wqe for memset()
    
    commit 28d41991182c210ec1654f8af2e140ef4cc73f20 upstream.
    
    The wqe is of type lpfc_wqe128. It should be memset with the same type.
    
    Fixes: 6c621a2229b0 ("scsi: lpfc: Separate NVMET RQ buffer posting from IO resources SGL/iocbq/context")
    Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
    Link: https://lore.kernel.org/r/20240304090649.833953-1-usama.anjum@collabora.com
    Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
    Reviewed-by: Justin Tee <justintee8345@gmail.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: qla2xxx: Change debug message during driver unload [+ + +]
Author: Saurav Kashyap <skashyap@marvell.com>
Date:   Tue Feb 27 22:11:25 2024 +0530

    scsi: qla2xxx: Change debug message during driver unload
    
    commit b5a30840727a3e41d12a336d19f6c0716b299161 upstream.
    
    Upon driver unload, purge_mbox flag is set and the heartbeat monitor thread
    detects this flag and does not send the mailbox command down to FW with a
    debug message "Error detected: purge[1] eeh[0] cmd=0x0, Exiting".  This
    being not a real error, change the debug message.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Saurav Kashyap <skashyap@marvell.com>
    Signed-off-by: Nilesh Javali <njavali@marvell.com>
    Link: https://lore.kernel.org/r/20240227164127.36465-10-njavali@marvell.com
    Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: qla2xxx: Delay I/O Abort on PCI error [+ + +]
Author: Quinn Tran <qutran@marvell.com>
Date:   Tue Feb 27 22:11:26 2024 +0530

    scsi: qla2xxx: Delay I/O Abort on PCI error
    
    commit 591c1fdf2016d118b8fbde427b796fac13f3f070 upstream.
    
    Currently when PCI error is detected, I/O is aborted manually through the
    ABORT IOCB mechanism which is not guaranteed to succeed.
    
    Instead, wait for the OS or system to notify driver to wind down I/O
    through the pci_error_handlers api.  Set eeh_busy flag to pause all traffic
    and wait for I/O to drain.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Quinn Tran <qutran@marvell.com>
    Signed-off-by: Nilesh Javali <njavali@marvell.com>
    Link: https://lore.kernel.org/r/20240227164127.36465-11-njavali@marvell.com
    Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: qla2xxx: Fix command flush on cable pull [+ + +]
Author: Quinn Tran <qutran@marvell.com>
Date:   Tue Feb 27 22:11:22 2024 +0530

    scsi: qla2xxx: Fix command flush on cable pull
    
    commit a27d4d0e7de305def8a5098a614053be208d1aa1 upstream.
    
    System crash due to command failed to flush back to SCSI layer.
    
     BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
     PGD 0 P4D 0
     Oops: 0000 [#1] SMP NOPTI
     CPU: 27 PID: 793455 Comm: kworker/u130:6 Kdump: loaded Tainted: G           OE    --------- -  - 4.18.0-372.9.1.el8.x86_64 #1
     Hardware name: HPE ProLiant DL360 Gen10/ProLiant DL360 Gen10, BIOS U32 09/03/2021
     Workqueue: nvme-wq nvme_fc_connect_ctrl_work [nvme_fc]
     RIP: 0010:__wake_up_common+0x4c/0x190
     Code: 24 10 4d 85 c9 74 0a 41 f6 01 04 0f 85 9d 00 00 00 48 8b 43 08 48 83 c3 08 4c 8d 48 e8 49 8d 41 18 48 39 c3 0f 84 f0 00 00 00 <49> 8b 41 18 89 54 24 08 31 ed 4c 8d 70 e8 45 8b 29 41 f6 c5 04 75
     RSP: 0018:ffff95f3e0cb7cd0 EFLAGS: 00010086
     RAX: 0000000000000000 RBX: ffff8b08d3b26328 RCX: 0000000000000000
     RDX: 0000000000000001 RSI: 0000000000000003 RDI: ffff8b08d3b26320
     RBP: 0000000000000001 R08: 0000000000000000 R09: ffffffffffffffe8
     R10: 0000000000000000 R11: ffff95f3e0cb7a60 R12: ffff95f3e0cb7d20
     R13: 0000000000000003 R14: 0000000000000000 R15: 0000000000000000
     FS:  0000000000000000(0000) GS:ffff8b2fdf6c0000(0000) knlGS:0000000000000000
     CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
     CR2: 0000000000000000 CR3: 0000002f1e410002 CR4: 00000000007706e0
     DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
     DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
     PKRU: 55555554
     Call Trace:
      __wake_up_common_lock+0x7c/0xc0
      qla_nvme_ls_req+0x355/0x4c0 [qla2xxx]
     qla2xxx [0000:12:00.1]-f084:3: qlt_free_session_done: se_sess 0000000000000000 / sess ffff8ae1407ca000 from port 21:32:00:02:ac:07:ee:b8 loop_id 0x02 s_id 01:02:00 logout 1 keep 0 els_logo 0
     ? __nvme_fc_send_ls_req+0x260/0x380 [nvme_fc]
     qla2xxx [0000:12:00.1]-207d:3: FCPort 21:32:00:02:ac:07:ee:b8 state transitioned from ONLINE to LOST - portid=010200.
      ? nvme_fc_send_ls_req.constprop.42+0x1a/0x45 [nvme_fc]
     qla2xxx [0000:12:00.1]-2109:3: qla2x00_schedule_rport_del 21320002ac07eeb8. rport ffff8ae598122000 roles 1
     ? nvme_fc_connect_ctrl_work.cold.63+0x1e3/0xa7d [nvme_fc]
     qla2xxx [0000:12:00.1]-f084:3: qlt_free_session_done: se_sess 0000000000000000 / sess ffff8ae14801e000 from port 21:32:01:02:ad:f7:ee:b8 loop_id 0x04 s_id 01:02:01 logout 1 keep 0 els_logo 0
      ? __switch_to+0x10c/0x450
     ? process_one_work+0x1a7/0x360
     qla2xxx [0000:12:00.1]-207d:3: FCPort 21:32:01:02:ad:f7:ee:b8 state transitioned from ONLINE to LOST - portid=010201.
      ? worker_thread+0x1ce/0x390
      ? create_worker+0x1a0/0x1a0
     qla2xxx [0000:12:00.1]-2109:3: qla2x00_schedule_rport_del 21320102adf7eeb8. rport ffff8ae3b2312800 roles 70
      ? kthread+0x10a/0x120
     qla2xxx [0000:12:00.1]-2112:3: qla_nvme_unregister_remote_port: unregister remoteport on ffff8ae14801e000 21320102adf7eeb8
      ? set_kthread_struct+0x40/0x40
     qla2xxx [0000:12:00.1]-2110:3: remoteport_delete of ffff8ae14801e000 21320102adf7eeb8 completed.
      ? ret_from_fork+0x1f/0x40
     qla2xxx [0000:12:00.1]-f086:3: qlt_free_session_done: waiting for sess ffff8ae14801e000 logout
    
    The system was under memory stress where driver was not able to allocate an
    SRB to carry out error recovery of cable pull.  The failure to flush causes
    upper layer to start modifying scsi_cmnd.  When the system frees up some
    memory, the subsequent cable pull trigger another command flush. At this
    point the driver access a null pointer when attempting to DMA unmap the
    SGL.
    
    Add a check to make sure commands are flush back on session tear down to
    prevent the null pointer access.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Quinn Tran <qutran@marvell.com>
    Signed-off-by: Nilesh Javali <njavali@marvell.com>
    Link: https://lore.kernel.org/r/20240227164127.36465-7-njavali@marvell.com
    Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: qla2xxx: Fix double free of fcport [+ + +]
Author: Saurav Kashyap <skashyap@marvell.com>
Date:   Tue Feb 27 22:11:24 2024 +0530

    scsi: qla2xxx: Fix double free of fcport
    
    commit 82f522ae0d97119a43da53e0f729275691b9c525 upstream.
    
    The server was crashing after LOGO because fcport was getting freed twice.
    
     -----------[ cut here ]-----------
     kernel BUG at mm/slub.c:371!
     invalid opcode: 0000 1 SMP PTI
     CPU: 35 PID: 4610 Comm: bash Kdump: loaded Tainted: G OE --------- - - 4.18.0-425.3.1.el8.x86_64 #1
     Hardware name: HPE ProLiant DL360 Gen10/ProLiant DL360 Gen10, BIOS U32 09/03/2021
     RIP: 0010:set_freepointer.part.57+0x0/0x10
     RSP: 0018:ffffb07107027d90 EFLAGS: 00010246
     RAX: ffff9cb7e3150000 RBX: ffff9cb7e332b9c0 RCX: ffff9cb7e3150400
     RDX: 0000000000001f37 RSI: 0000000000000000 RDI: ffff9cb7c0005500
     RBP: fffff693448c5400 R08: 0000000080000000 R09: 0000000000000009
     R10: 0000000000000000 R11: 0000000000132af0 R12: ffff9cb7c0005500
     R13: ffff9cb7e3150000 R14: ffffffffc06990e0 R15: ffff9cb7ea85ea58
     FS: 00007ff6b79c2740(0000) GS:ffff9cb8f7ec0000(0000) knlGS:0000000000000000
     CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
     CR2: 000055b426b7d700 CR3: 0000000169c18002 CR4: 00000000007706e0
     DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
     DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
     PKRU: 55555554
     Call Trace:
     kfree+0x238/0x250
     qla2x00_els_dcmd_sp_free+0x20/0x230 [qla2xxx]
     ? qla24xx_els_dcmd_iocb+0x607/0x690 [qla2xxx]
     qla2x00_issue_logo+0x28c/0x2a0 [qla2xxx]
     ? qla2x00_issue_logo+0x28c/0x2a0 [qla2xxx]
     ? kernfs_fop_write+0x11e/0x1a0
    
    Remove one of the free calls and add check for valid fcport. Also use
    function qla2x00_free_fcport() instead of kfree().
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Saurav Kashyap <skashyap@marvell.com>
    Signed-off-by: Nilesh Javali <njavali@marvell.com>
    Link: https://lore.kernel.org/r/20240227164127.36465-9-njavali@marvell.com
    Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: qla2xxx: Fix N2N stuck connection [+ + +]
Author: Quinn Tran <qutran@marvell.com>
Date:   Tue Feb 27 22:11:18 2024 +0530

    scsi: qla2xxx: Fix N2N stuck connection
    
    commit 881eb861ca3877300570db10abbf11494e48548d upstream.
    
    Disk failed to rediscover after chip reset error injection. The chip reset
    happens at the time when a PLOGI is being sent. This causes a flag to be
    left on which blocks the retry. Clear the blocking flag.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Quinn Tran <qutran@marvell.com>
    Signed-off-by: Nilesh Javali <njavali@marvell.com>
    Link: https://lore.kernel.org/r/20240227164127.36465-3-njavali@marvell.com
    Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: qla2xxx: NVME|FCP prefer flag not being honored [+ + +]
Author: Quinn Tran <qutran@marvell.com>
Date:   Tue Feb 27 22:11:21 2024 +0530

    scsi: qla2xxx: NVME|FCP prefer flag not being honored
    
    commit 69aecdd410106dc3a8f543a4f7ec6379b995b8d0 upstream.
    
    Changing of [FCP|NVME] prefer flag in flash has no effect on driver. For
    device that supports both FCP + NVMe over the same connection, driver
    continues to connect to this device using the previous successful login
    mode.
    
    On completion of flash update, adapter will be reset. Driver will
    reset the prefer flag based on setting from flash.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Quinn Tran <qutran@marvell.com>
    Signed-off-by: Nilesh Javali <njavali@marvell.com>
    Link: https://lore.kernel.org/r/20240227164127.36465-6-njavali@marvell.com
    Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: qla2xxx: Prevent command send on chip reset [+ + +]
Author: Quinn Tran <qutran@marvell.com>
Date:   Tue Feb 27 22:11:17 2024 +0530

    scsi: qla2xxx: Prevent command send on chip reset
    
    commit 4895009c4bb72f71f2e682f1e7d2c2d96e482087 upstream.
    
    Currently IOCBs are allowed to push through while chip reset could be in
    progress. During chip reset the outstanding_cmds array is cleared
    twice. Once when any command on this array is returned as failed and
    secondly when the array is initialize to zero. If a command is inserted on
    to the array between these intervals, then the command will be lost.  Check
    for chip reset before sending IOCB.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Quinn Tran <qutran@marvell.com>
    Signed-off-by: Nilesh Javali <njavali@marvell.com>
    Link: https://lore.kernel.org/r/20240227164127.36465-2-njavali@marvell.com
    Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: qla2xxx: Split FCE|EFT trace control [+ + +]
Author: Quinn Tran <qutran@marvell.com>
Date:   Tue Feb 27 22:11:19 2024 +0530

    scsi: qla2xxx: Split FCE|EFT trace control
    
    commit 76a192e1a566e15365704b9f8fb3b70825f85064 upstream.
    
    Current code combines the allocation of FCE|EFT trace buffers and enables
    the features all in 1 step.
    
    Split this step into separate steps in preparation for follow-on patch to
    allow user to have a choice to enable / disable FCE trace feature.
    
    Cc: stable@vger.kernel.org
    Reported-by: kernel test robot <lkp@intel.com>
    Signed-off-by: Quinn Tran <qutran@marvell.com>
    Signed-off-by: Nilesh Javali <njavali@marvell.com>
    Link: https://lore.kernel.org/r/20240227164127.36465-4-njavali@marvell.com
    Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: qla2xxx: Update manufacturer detail [+ + +]
Author: Bikash Hazarika <bhazarika@marvell.com>
Date:   Tue Feb 27 22:11:20 2024 +0530

    scsi: qla2xxx: Update manufacturer detail
    
    commit 688fa069fda6fce24d243cddfe0c7024428acb74 upstream.
    
    Update manufacturer detail from "Marvell Semiconductor, Inc." to
    "Marvell".
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Bikash Hazarika <bhazarika@marvell.com>
    Signed-off-by: Nilesh Javali <njavali@marvell.com>
    Link: https://lore.kernel.org/r/20240227164127.36465-5-njavali@marvell.com
    Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

scsi: sd: Fix TCG OPAL unlock on system resume [+ + +]
Author: Damien Le Moal <dlemoal@kernel.org>
Date:   Tue Mar 19 16:12:09 2024 +0900

    scsi: sd: Fix TCG OPAL unlock on system resume
    
    commit 0c76106cb97548810214def8ee22700bbbb90543 upstream.
    
    Commit 3cc2ffe5c16d ("scsi: sd: Differentiate system and runtime start/stop
    management") introduced the manage_system_start_stop scsi_device flag to
    allow libata to indicate to the SCSI disk driver that nothing should be
    done when resuming a disk on system resume. This change turned the
    execution of sd_resume() into a no-op for ATA devices on system
    resume. While this solved deadlock issues during device resume, this change
    also wrongly removed the execution of opal_unlock_from_suspend().  As a
    result, devices with TCG OPAL locking enabled remain locked and
    inaccessible after a system resume from sleep.
    
    To fix this issue, introduce the SCSI driver resume method and implement it
    with the sd_resume() function calling opal_unlock_from_suspend(). The
    former sd_resume() function is renamed to sd_resume_common() and modified
    to call the new sd_resume() function. For non-ATA devices, this result in
    no functional changes.
    
    In order for libata to explicitly execute sd_resume() when a device is
    resumed during system restart, the function scsi_resume_device() is
    introduced. libata calls this function from the revalidation work executed
    on devie resume, a state that is indicated with the new device flag
    ATA_DFLAG_RESUMING. Doing so, locked TCG OPAL enabled devices are unlocked
    on resume, allowing normal operation.
    
    Fixes: 3cc2ffe5c16d ("scsi: sd: Differentiate system and runtime start/stop management")
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=218538
    Cc: stable@vger.kernel.org
    Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
    Link: https://lore.kernel.org/r/20240319071209.1179257-1-dlemoal@kernel.org
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
selftests/mqueue: Set timeout to 180 seconds [+ + +]
Author: SeongJae Park <sj@kernel.org>
Date:   Mon Feb 19 16:08:02 2024 -0800

    selftests/mqueue: Set timeout to 180 seconds
    
    [ Upstream commit 85506aca2eb4ea41223c91c5fe25125953c19b13 ]
    
    While mq_perf_tests runs with the default kselftest timeout limit, which
    is 45 seconds, the test takes about 60 seconds to complete on i3.metal
    AWS instances.  Hence, the test always times out.  Increase the timeout
    to 180 seconds.
    
    Fixes: 852c8cbf34d3 ("selftests/kselftest/runner.sh: Add 45 second timeout per test")
    Cc: <stable@vger.kernel.org> # 5.4.x
    Signed-off-by: SeongJae Park <sj@kernel.org>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
selftests: mptcp: diag: return KSFT_FAIL not test_cnt [+ + +]
Author: Geliang Tang <tanggeliang@kylinos.cn>
Date:   Fri Mar 1 18:11:22 2024 +0100

    selftests: mptcp: diag: return KSFT_FAIL not test_cnt
    
    commit 45bcc0346561daa3f59e19a753cc7f3e08e8dff1 upstream.
    
    The test counter 'test_cnt' should not be returned in diag.sh, e.g. what
    if only the 4th test fail? Will do 'exit 4' which is 'exit ${KSFT_SKIP}',
    the whole test will be marked as skipped instead of 'failed'!
    
    So we should do ret=${KSFT_FAIL} instead.
    
    Fixes: df62f2ec3df6 ("selftests/mptcp: add diag interface tests")
    Cc: stable@vger.kernel.org
    Fixes: 42fb6cddec3b ("selftests: mptcp: more stable diag tests")
    Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
    Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
    Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
serial: Lock console when calling into driver before registration [+ + +]
Author: Peter Collingbourne <pcc@google.com>
Date:   Mon Mar 4 13:43:49 2024 -0800

    serial: Lock console when calling into driver before registration
    
    [ Upstream commit 801410b26a0e8b8a16f7915b2b55c9528b69ca87 ]
    
    During the handoff from earlycon to the real console driver, we have
    two separate drivers operating on the same device concurrently. In the
    case of the 8250 driver these concurrent accesses cause problems due
    to the driver's use of banked registers, controlled by LCR.DLAB. It is
    possible for the setup(), config_port(), pm() and set_mctrl() callbacks
    to set DLAB, which can cause the earlycon code that intends to access
    TX to instead access DLL, leading to missed output and corruption on
    the serial line due to unintended modifications to the baud rate.
    
    In particular, for setup() we have:
    
    univ8250_console_setup()
    -> serial8250_console_setup()
    -> uart_set_options()
    -> serial8250_set_termios()
    -> serial8250_do_set_termios()
    -> serial8250_do_set_divisor()
    
    For config_port() we have:
    
    serial8250_config_port()
    -> autoconfig()
    
    For pm() we have:
    
    serial8250_pm()
    -> serial8250_do_pm()
    -> serial8250_set_sleep()
    
    For set_mctrl() we have (for some devices):
    
    serial8250_set_mctrl()
    -> omap8250_set_mctrl()
    -> __omap8250_set_mctrl()
    
    To avoid such problems, let's make it so that the console is locked
    during pre-registration calls to these callbacks, which will prevent
    the earlycon driver from running concurrently.
    
    Remove the partial solution to this problem in the 8250 driver
    that locked the console only during autoconfig_irq(), as this would
    result in a deadlock with the new approach. The console continues
    to be locked during autoconfig_irq() because it can only be called
    through uart_configure_port().
    
    Although this patch introduces more locking than strictly necessary
    (and in particular it also locks during the call to rs485_config()
    which is not affected by this issue as far as I can tell), it follows
    the principle that it is the responsibility of the generic console
    code to manage the earlycon handoff by ensuring that earlycon and real
    console driver code cannot run concurrently, and not the individual
    drivers.
    
    Signed-off-by: Peter Collingbourne <pcc@google.com>
    Reviewed-by: John Ogness <john.ogness@linutronix.de>
    Link: https://linux-review.googlesource.com/id/I7cf8124dcebf8618e6b2ee543fa5b25532de55d8
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240304214350.501253-1-pcc@google.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

serial: max310x: fix NULL pointer dereference in I2C instantiation [+ + +]
Author: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Date:   Thu Jan 18 10:21:57 2024 -0500

    serial: max310x: fix NULL pointer dereference in I2C instantiation
    
    [ Upstream commit 0d27056c24efd3d63a03f3edfbcfc4827086b110 ]
    
    When trying to instantiate a max14830 device from userspace:
    
        echo max14830 0x60 > /sys/bus/i2c/devices/i2c-2/new_device
    
    we get the following error:
    
        Unable to handle kernel NULL pointer dereference at virtual address...
        ...
        Call trace:
            max310x_i2c_probe+0x48/0x170 [max310x]
            i2c_device_probe+0x150/0x2a0
        ...
    
    Add check for validity of devtype to prevent the error, and abort probe
    with a meaningful error message.
    
    Fixes: 2e1f2d9a9bdb ("serial: max310x: implement I2C support")
    Cc: stable@vger.kernel.org
    Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
    Link: https://lore.kernel.org/r/20240118152213.2644269-2-hugo@hugovil.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
slimbus: core: Remove usage of the deprecated ida_simple_xx() API [+ + +]
Author: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date:   Sat Feb 24 11:41:37 2024 +0000

    slimbus: core: Remove usage of the deprecated ida_simple_xx() API
    
    [ Upstream commit 89ffa4cccec54467446f141a79b9e36893079fb8 ]
    
    ida_alloc() and ida_free() should be preferred to the deprecated
    ida_simple_get() and ida_simple_remove().
    
    Note that the upper limit of ida_simple_get() is exclusive, but the one of
    ida_alloc_range() is inclusive. So change this change allows one more
    device. Previously address 0xFE was never used.
    
    Fixes: 46a2bb5a7f7e ("slimbus: core: Add slim controllers support")
    Cc: Stable@vger.kernel.org
    Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
    Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
    Link: https://lore.kernel.org/r/20240224114137.85781-2-srinivas.kandagatla@linaro.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
smack: Handle SMACK64TRANSMUTE in smack_inode_setsecurity() [+ + +]
Author: Roberto Sassu <roberto.sassu@huawei.com>
Date:   Thu Nov 16 10:01:22 2023 +0100

    smack: Handle SMACK64TRANSMUTE in smack_inode_setsecurity()
    
    [ Upstream commit ac02f007d64eb2769d0bde742aac4d7a5fc6e8a5 ]
    
    If the SMACK64TRANSMUTE xattr is provided, and the inode is a directory,
    update the in-memory inode flags by setting SMK_INODE_TRANSMUTE.
    
    Cc: stable@vger.kernel.org
    Fixes: 5c6d1125f8db ("Smack: Transmute labels on specified directories") # v2.6.38.x
    Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
    Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

smack: Set SMACK64TRANSMUTE only for dirs in smack_inode_setxattr() [+ + +]
Author: Roberto Sassu <roberto.sassu@huawei.com>
Date:   Thu Nov 16 10:01:21 2023 +0100

    smack: Set SMACK64TRANSMUTE only for dirs in smack_inode_setxattr()
    
    [ Upstream commit 9c82169208dde516510aaba6bbd8b13976690c5d ]
    
    Since the SMACK64TRANSMUTE xattr makes sense only for directories, enforce
    this restriction in smack_inode_setxattr().
    
    Cc: stable@vger.kernel.org
    Fixes: 5c6d1125f8db ("Smack: Transmute labels on specified directories") # v2.6.38.x
    Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
    Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
soc: fsl: qbman: Always disable interrupts when taking cgr_lock [+ + +]
Author: Sean Anderson <sean.anderson@linux.dev>
Date:   Mon Mar 11 12:38:29 2024 -0400

    soc: fsl: qbman: Always disable interrupts when taking cgr_lock
    
    [ Upstream commit 584c2a9184a33a40fceee838f856de3cffa19be3 ]
    
    smp_call_function_single disables IRQs when executing the callback. To
    prevent deadlocks, we must disable IRQs when taking cgr_lock elsewhere.
    This is already done by qman_update_cgr and qman_delete_cgr; fix the
    other lockers.
    
    Fixes: 96f413f47677 ("soc/fsl/qbman: fix issue in qman_delete_cgr_safe()")
    CC: stable@vger.kernel.org
    Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
    Reviewed-by: Camelia Groza <camelia.groza@nxp.com>
    Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

soc: fsl: qbman: Use raw spinlock for cgr_lock [+ + +]
Author: Sean Anderson <sean.anderson@linux.dev>
Date:   Mon Mar 11 12:38:30 2024 -0400

    soc: fsl: qbman: Use raw spinlock for cgr_lock
    
    [ Upstream commit fbec4e7fed89b579f2483041fabf9650fb0dd6bc ]
    
    smp_call_function always runs its callback in hard IRQ context, even on
    PREEMPT_RT, where spinlocks can sleep. So we need to use a raw spinlock
    for cgr_lock to ensure we aren't waiting on a sleeping task.
    
    Although this bug has existed for a while, it was not apparent until
    commit ef2a8d5478b9 ("net: dpaa: Adjust queue depth on rate change")
    which invokes smp_call_function_single via qman_update_cgr_safe every
    time a link goes up or down.
    
    Fixes: 96f413f47677 ("soc/fsl/qbman: fix issue in qman_delete_cgr_safe()")
    CC: stable@vger.kernel.org
    Reported-by: Vladimir Oltean <vladimir.oltean@nxp.com>
    Closes: https://lore.kernel.org/all/20230323153935.nofnjucqjqnz34ej@skbuf/
    Reported-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
    Closes: https://lore.kernel.org/linux-arm-kernel/87wmsyvclu.fsf@pengutronix.de/
    Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
    Reviewed-by: Camelia Groza <camelia.groza@nxp.com>
    Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
sparc32: Fix parport build with sparc32 [+ + +]
Author: Sam Ravnborg <sam@ravnborg.org>
Date:   Sat Feb 24 18:42:27 2024 +0100

    sparc32: Fix parport build with sparc32
    
    [ Upstream commit 91d3ff922c346d6d8cb8de5ff8d504fe0ca9e17e ]
    
    include/asm/parport.h is sparc64 specific.
    Rename it to parport_64.h and use the generic version for sparc32.
    
    This fixed all{mod,yes}config build errors like:
    
    parport_pc.c:(.text):undefined-reference-to-ebus_dma_enable
    parport_pc.c:(.text):undefined-reference-to-ebus_dma_irq_enable
    parport_pc.c:(.text):undefined-reference-to-ebus_dma_register
    
    The errors occur as the sparc32 build references sparc64 symbols.
    
    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: Andreas Larsson <andreas@gaisler.com>
    Cc: Randy Dunlap <rdunlap@infradead.org>
    Cc: Maciej W. Rozycki <macro@orcam.me.uk>
    Closes: https://lore.kernel.org/r/20230406160548.25721-1-rdunlap@infradead.org/
    Fixes: 66bcd06099bb ("parport_pc: Also enable driver for PCI systems")
    Cc: stable@vger.kernel.org # v5.18+
    Tested-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
    Reviewed-by: Andreas Larsson <andreas@gaisler.com>
    Signed-off-by: Andreas Larsson <andreas@gaisler.com>
    Link: https://lore.kernel.org/r/20240224-sam-fix-sparc32-all-builds-v2-6-1f186603c5c4@ravnborg.org
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
sparc64: NMI watchdog: fix return value of __setup handler [+ + +]
Author: Randy Dunlap <rdunlap@infradead.org>
Date:   Sat Feb 10 21:28:02 2024 -0800

    sparc64: NMI watchdog: fix return value of __setup handler
    
    [ Upstream commit 3ed7c61e49d65dacb96db798c0ab6fcd55a1f20f ]
    
    __setup() handlers should return 1 to obsolete_checksetup() in
    init/main.c to indicate that the boot option has been handled.
    A return of 0 causes the boot option/value to be listed as an Unknown
    kernel parameter and added to init's (limited) argument or environment
    strings. Also, error return codes don't mean anything to
    obsolete_checksetup() -- only non-zero (usually 1) or zero.
    So return 1 from setup_nmi_watchdog().
    
    Fixes: e5553a6d0442 ("sparc64: Implement NMI watchdog on capable cpus.")
    Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
    Reported-by: Igor Zhbanov <izh1979@gmail.com>
    Link: lore.kernel.org/r/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@omprussia.ru
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: sparclinux@vger.kernel.org
    Cc: Sam Ravnborg <sam@ravnborg.org>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: stable@vger.kernel.org
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Andreas Larsson <andreas@gaisler.com>
    Signed-off-by: Andreas Larsson <andreas@gaisler.com>
    Link: https://lore.kernel.org/r/20240211052802.22612-1-rdunlap@infradead.org
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
sparc: Explicitly include correct DT includes [+ + +]
Author: Rob Herring <robh@kernel.org>
Date:   Tue Jul 18 14:45:20 2023 -0600

    sparc: Explicitly include correct DT includes
    
    [ Upstream commit 263291fa44ff0909b5b7c43ff40babc1c43362f2 ]
    
    The DT of_device.h and of_platform.h date back to the separate
    of_platform_bus_type before it was merged into the regular platform bus.
    As part of that merge prepping Arm DT support 13 years ago, they
    "temporarily" include each other. They also include platform_device.h
    and of.h. As a result, there's a pretty much random mix of those include
    files used throughout the tree. In order to detangle these headers and
    replace the implicit includes with struct declarations, users need to
    explicitly include the correct includes.
    
    Acked-by: Sam Ravnborg <sam@ravnborg.org>
    Link: https://lore.kernel.org/all/20230718143211.1066810-1-robh@kernel.org/
    Signed-off-by: Rob Herring <robh@kernel.org>
    Stable-dep-of: 91d3ff922c34 ("sparc32: Fix parport build with sparc32")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

sparc: vDSO: fix return value of __setup handler [+ + +]
Author: Randy Dunlap <rdunlap@infradead.org>
Date:   Sat Feb 10 21:28:08 2024 -0800

    sparc: vDSO: fix return value of __setup handler
    
    [ Upstream commit 5378f00c935bebb846b1fdb0e79cb76c137c56b5 ]
    
    __setup() handlers should return 1 to obsolete_checksetup() in
    init/main.c to indicate that the boot option has been handled.
    A return of 0 causes the boot option/value to be listed as an Unknown
    kernel parameter and added to init's (limited) argument or environment
    strings. Also, error return codes don't mean anything to
    obsolete_checksetup() -- only non-zero (usually 1) or zero.
    So return 1 from vdso_setup().
    
    Fixes: 9a08862a5d2e ("vDSO for sparc")
    Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
    Reported-by: Igor Zhbanov <izh1979@gmail.com>
    Link: lore.kernel.org/r/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@omprussia.ru
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: sparclinux@vger.kernel.org
    Cc: Dan Carpenter <dan.carpenter@oracle.com>
    Cc: Nick Alcock <nick.alcock@oracle.com>
    Cc: Sam Ravnborg <sam@ravnborg.org>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: stable@vger.kernel.org
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Andreas Larsson <andreas@gaisler.com>
    Signed-off-by: Andreas Larsson <andreas@gaisler.com>
    Link: https://lore.kernel.org/r/20240211052808.22635-1-rdunlap@infradead.org
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
speakup: Fix 8bit characters from direct synth [+ + +]
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sun Feb 4 16:57:36 2024 +0100

    speakup: Fix 8bit characters from direct synth
    
    [ Upstream commit b6c8dafc9d86eb77e502bb018ec4105e8d2fbf78 ]
    
    When userland echoes 8bit characters to /dev/synth with e.g.
    
    echo -e '\xe9' > /dev/synth
    
    synth_write would get characters beyond 0x7f, and thus negative when
    char is signed.  When given to synth_buffer_add which takes a u16, this
    would sign-extend and produce a U+ffxy character rather than U+xy.
    Users thus get garbled text instead of accents in their output.
    
    Let's fix this by making sure that we read unsigned characters.
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
    Fixes: 89fc2ae80bb1 ("speakup: extend synth buffer to 16bit unicode characters")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240204155736.2oh4ot7tiaa2wpbh@begin
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
staging: vc04_services: changen strncpy() to strscpy_pad() [+ + +]
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Wed Mar 13 17:36:56 2024 +0100

    staging: vc04_services: changen strncpy() to strscpy_pad()
    
    commit ef25725b7f8aaffd7756974d3246ec44fae0a5cf upstream.
    
    gcc-14 warns about this strncpy() that results in a non-terminated
    string for an overflow:
    
    In file included from include/linux/string.h:369,
                     from drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c:20:
    In function 'strncpy',
        inlined from 'create_component' at drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c:940:2:
    include/linux/fortify-string.h:108:33: error: '__builtin_strncpy' specified bound 128 equals destination size [-Werror=stringop-truncation]
    
    Change it to strscpy_pad(), which produces a properly terminated and
    zero-padded string.
    
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
    Link: https://lore.kernel.org/r/20240313163712.224585-1-arnd@kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

staging: vc04_services: fix information leak in create_component() [+ + +]
Author: Dan Carpenter <dan.carpenter@linaro.org>
Date:   Wed Mar 13 21:07:43 2024 +0300

    staging: vc04_services: fix information leak in create_component()
    
    commit f37e76abd614b68987abc8e5c22d986013349771 upstream.
    
    The m.u.component_create.pid field is for debugging and in the mainline
    kernel it's not used anything.  However, it still needs to be set to
    something to prevent disclosing uninitialized stack data.  Set it to
    zero.
    
    Fixes: 7b3ad5abf027 ("staging: Import the BCM2835 MMAL-based V4L2 camera driver.")
    Cc: stable <stable@kernel.org>
    Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
    Link: https://lore.kernel.org/r/2d972847-9ebd-481b-b6f9-af390f5aabd3@moroto.mountain
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
swap: comments get_swap_device() with usage rule [+ + +]
Author: Huang Ying <ying.huang@intel.com>
Date:   Mon May 29 14:13:55 2023 +0800

    swap: comments get_swap_device() with usage rule
    
    [ Upstream commit a95722a047724ef75567381976a36f0e44230bd9 ]
    
    The general rule to use a swap entry is as follows.
    
    When we get a swap entry, if there aren't some other ways to prevent
    swapoff, such as the folio in swap cache is locked, page table lock is
    held, etc., the swap entry may become invalid because of swapoff.
    Then, we need to enclose all swap related functions with
    get_swap_device() and put_swap_device(), unless the swap functions
    call get/put_swap_device() by themselves.
    
    Add the rule as comments of get_swap_device().
    
    Link: https://lkml.kernel.org/r/20230529061355.125791-6-ying.huang@intel.com
    Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
    Reviewed-by: David Hildenbrand <david@redhat.com>
    Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
    Reviewed-by: Chris Li (Google) <chrisl@kernel.org>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Michal Hocko <mhocko@suse.com>
    Cc: Minchan Kim <minchan@kernel.org>
    Cc: Tim Chen <tim.c.chen@linux.intel.com>
    Cc: Yang Shi <shy828301@gmail.com>
    Cc: Yu Zhao <yuzhao@google.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Stable-dep-of: 82b1c07a0af6 ("mm: swap: fix race between free_swap_and_cache() and swapoff()")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
swiotlb: Fix alignment checks when both allocation and DMA masks are present [+ + +]
Author: Will Deacon <will@kernel.org>
Date:   Fri Mar 8 15:28:27 2024 +0000

    swiotlb: Fix alignment checks when both allocation and DMA masks are present
    
    [ Upstream commit 51b30ecb73b481d5fac6ccf2ecb4a309c9ee3310 ]
    
    Nicolin reports that swiotlb buffer allocations fail for an NVME device
    behind an IOMMU using 64KiB pages. This is because we end up with a
    minimum allocation alignment of 64KiB (for the IOMMU to map the buffer
    safely) but a minimum DMA alignment mask corresponding to a 4KiB NVME
    page (i.e. preserving the 4KiB page offset from the original allocation).
    If the original address is not 4KiB-aligned, the allocation will fail
    because swiotlb_search_pool_area() erroneously compares these unmasked
    bits with the 64KiB-aligned candidate allocation.
    
    Tweak swiotlb_search_pool_area() so that the DMA alignment mask is
    reduced based on the required alignment of the allocation.
    
    Fixes: 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers")
    Link: https://lore.kernel.org/r/cover.1707851466.git.nicolinc@nvidia.com
    Reported-by: Nicolin Chen <nicolinc@nvidia.com>
    Signed-off-by: Will Deacon <will@kernel.org>
    Reviewed-by: Michael Kelley <mhklinux@outlook.com>
    Tested-by: Nicolin Chen <nicolinc@nvidia.com>
    Tested-by: Michael Kelley <mhklinux@outlook.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
tee: optee: Fix kernel panic caused by incorrect error handling [+ + +]
Author: Sumit Garg <sumit.garg@linaro.org>
Date:   Fri Mar 1 20:07:31 2024 +0530

    tee: optee: Fix kernel panic caused by incorrect error handling
    
    commit 95915ba4b987cf2b222b0f251280228a1ff977ac upstream.
    
    The error path while failing to register devices on the TEE bus has a
    bug leading to kernel panic as follows:
    
    [   15.398930] Unable to handle kernel paging request at virtual address ffff07ed00626d7c
    [   15.406913] Mem abort info:
    [   15.409722]   ESR = 0x0000000096000005
    [   15.413490]   EC = 0x25: DABT (current EL), IL = 32 bits
    [   15.418814]   SET = 0, FnV = 0
    [   15.421878]   EA = 0, S1PTW = 0
    [   15.425031]   FSC = 0x05: level 1 translation fault
    [   15.429922] Data abort info:
    [   15.432813]   ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
    [   15.438310]   CM = 0, WnR = 0, TnD = 0, TagAccess = 0
    [   15.443372]   GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
    [   15.448697] swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000000d9e3e000
    [   15.455413] [ffff07ed00626d7c] pgd=1800000bffdf9003, p4d=1800000bffdf9003, pud=0000000000000000
    [   15.464146] Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP
    
    Commit 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
    lead to the introduction of this bug. So fix it appropriately.
    
    Reported-by: Mikko Rapeli <mikko.rapeli@linaro.org>
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218542
    Fixes: 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
    Cc: stable@vger.kernel.org
    Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
    Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
thermal: devfreq_cooling: Fix perf state when calculate dfc res_util [+ + +]
Author: Ye Zhang <ye.zhang@rock-chips.com>
Date:   Thu Mar 21 18:21:00 2024 +0800

    thermal: devfreq_cooling: Fix perf state when calculate dfc res_util
    
    commit a26de34b3c77ae3a969654d94be49e433c947e3b upstream.
    
    The issue occurs when the devfreq cooling device uses the EM power model
    and the get_real_power() callback is provided by the driver.
    
    The EM power table is sorted ascending,can't index the table by cooling
    device state,so convert cooling state to performance state by
    dfc->max_state - dfc->capped_state.
    
    Fixes: 615510fe13bd ("thermal: devfreq_cooling: remove old power model and use EM")
    Cc: 5.11+ <stable@vger.kernel.org> # 5.11+
    Signed-off-by: Ye Zhang <ye.zhang@rock-chips.com>
    Reviewed-by: Dhruva Gole <d-gole@ti.com>
    Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
timers: Rename del_timer_sync() to timer_delete_sync() [+ + +]
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Wed Nov 23 21:18:44 2022 +0100

    timers: Rename del_timer_sync() to timer_delete_sync()
    
    [ Upstream commit 9b13df3fb64ee95e2397585404e442afee2c7d4f ]
    
    The timer related functions do not have a strict timer_ prefixed namespace
    which is really annoying.
    
    Rename del_timer_sync() to timer_delete_sync() and provide del_timer_sync()
    as a wrapper. Document that del_timer_sync() is not for new code.
    
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Tested-by: Guenter Roeck <linux@roeck-us.net>
    Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
    Reviewed-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
    Link: https://lore.kernel.org/r/20221123201624.954785441@linutronix.de
    Stable-dep-of: 0f7352557a35 ("wifi: brcmfmac: Fix use-after-free bug in brcmf_cfg80211_detach")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

timers: Update kernel-doc for various functions [+ + +]
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Wed Nov 23 21:18:40 2022 +0100

    timers: Update kernel-doc for various functions
    
    [ Upstream commit 14f043f1340bf30bc60af127bff39f55889fef26 ]
    
    The kernel-doc of timer related functions is partially uncomprehensible
    word salad. Rewrite it to make it useful.
    
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Tested-by: Guenter Roeck <linux@roeck-us.net>
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
    Reviewed-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
    Link: https://lore.kernel.org/r/20221123201624.828703870@linutronix.de
    Stable-dep-of: 0f7352557a35 ("wifi: brcmfmac: Fix use-after-free bug in brcmf_cfg80211_detach")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

timers: Use del_timer_sync() even on UP [+ + +]
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Wed Nov 23 21:18:42 2022 +0100

    timers: Use del_timer_sync() even on UP
    
    [ Upstream commit 168f6b6ffbeec0b9333f3582e4cf637300858db5 ]
    
    del_timer_sync() is assumed to be pointless on uniprocessor systems and can
    be mapped to del_timer() because in theory del_timer() can never be invoked
    while the timer callback function is executed.
    
    This is not entirely true because del_timer() can be invoked from interrupt
    context and therefore hit in the middle of a running timer callback.
    
    Contrary to that del_timer_sync() is not allowed to be invoked from
    interrupt context unless the affected timer is marked with TIMER_IRQSAFE.
    del_timer_sync() has proper checks in place to detect such a situation.
    
    Give up on the UP optimization and make del_timer_sync() unconditionally
    available.
    
    Co-developed-by: Steven Rostedt <rostedt@goodmis.org>
    Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Tested-by: Guenter Roeck <linux@roeck-us.net>
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
    Reviewed-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
    Link: https://lore.kernel.org/all/20220407161745.7d6754b3@gandalf.local.home
    Link: https://lore.kernel.org/all/20221110064101.429013735@goodmis.org
    Link: https://lore.kernel.org/r/20221123201624.888306160@linutronix.de
    Stable-dep-of: 0f7352557a35 ("wifi: brcmfmac: Fix use-after-free bug in brcmf_cfg80211_detach")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
tls: fix race between tx work scheduling and socket close [+ + +]
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Tue Feb 6 17:18:20 2024 -0800

    tls: fix race between tx work scheduling and socket close
    
    commit e01e3934a1b2d122919f73bc6ddbe1cdafc4bbdb upstream.
    
    Similarly to previous commit, the submitting thread (recvmsg/sendmsg)
    may exit as soon as the async crypto handler calls complete().
    Reorder scheduling the work before calling complete().
    This seems more logical in the first place, as it's
    the inverse order of what the submitting thread will do.
    
    Reported-by: valis <sec@valis.email>
    Fixes: a42055e8d2c3 ("net/tls: Add support for async encryption of records for performance")
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Reviewed-by: Simon Horman <horms@kernel.org>
    Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    [Lee: Fixed merge-conflict in Stable branches linux-6.1.y and older]
    Signed-off-by: Lee Jones <lee@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

tls: fix use-after-free on failed backlog decryption [+ + +]
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Wed Feb 28 23:44:00 2024 +0100

    tls: fix use-after-free on failed backlog decryption
    
    commit 13114dc5543069f7b97991e3b79937b6da05f5b0 upstream.
    
    When the decrypt request goes to the backlog and crypto_aead_decrypt
    returns -EBUSY, tls_do_decryption will wait until all async
    decryptions have completed. If one of them fails, tls_do_decryption
    will return -EBADMSG and tls_decrypt_sg jumps to the error path,
    releasing all the pages. But the pages have been passed to the async
    callback, and have already been released by tls_decrypt_done.
    
    The only true async case is when crypto_aead_decrypt returns
     -EINPROGRESS. With -EBUSY, we already waited so we can tell
    tls_sw_recvmsg that the data is available for immediate copy, but we
    need to notify tls_decrypt_sg (via the new ->async_done flag) that the
    memory has already been released.
    
    Fixes: 859054147318 ("net: tls: handle backlogging of crypto requests")
    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Link: https://lore.kernel.org/r/4755dd8d9bebdefaa19ce1439b833d6199d4364c.1709132643.git.sd@queasysnail.net
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
tools/resolve_btfids: fix build with musl libc [+ + +]
Author: Natanael Copa <ncopa@alpinelinux.org>
Date:   Thu Mar 28 11:59:13 2024 +0100

    tools/resolve_btfids: fix build with musl libc
    
    commit 62248b22d01e96a4d669cde0d7005bd51ebf9e76 upstream.
    
    Include the header that defines u32.
    This fixes build of 6.6.23 and 6.1.83 kernels for Alpine Linux, which
    uses musl libc. I assume that GNU libc indirecly pulls in linux/types.h.
    
    Fixes: 9707ac4fe2f5 ("tools/resolve_btfids: Refactor set sorting with types from btf_ids.h")
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218647
    Cc: stable@vger.kernel.org
    Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
    Tested-by: Greg Thelen <gthelen@google.com>
    Link: https://lore.kernel.org/r/20240328110103.28734-1-ncopa@alpinelinux.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
tracing: Use .flush() call to wake up readers [+ + +]
Author: Steven Rostedt (Google) <rostedt@goodmis.org>
Date:   Fri Mar 8 15:24:05 2024 -0500

    tracing: Use .flush() call to wake up readers
    
    commit e5d7c1916562f0e856eb3d6f569629fcd535fed2 upstream.
    
    The .release() function does not get called until all readers of a file
    descriptor are finished.
    
    If a thread is blocked on reading a file descriptor in ring_buffer_wait(),
    and another thread closes the file descriptor, it will not wake up the
    other thread as ring_buffer_wake_waiters() is called by .release(), and
    that will not get called until the .read() is finished.
    
    The issue originally showed up in trace-cmd, but the readers are actually
    other processes with their own file descriptors. So calling close() would wake
    up the other tasks because they are blocked on another descriptor then the
    one that was closed(). But there's other wake ups that solve that issue.
    
    When a thread is blocked on a read, it can still hang even when another
    thread closed its descriptor.
    
    This is what the .flush() callback is for. Have the .flush() wake up the
    readers.
    
    Link: https://lore.kernel.org/linux-trace-kernel/20240308202432.107909457@goodmis.org
    
    Cc: stable@vger.kernel.org
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: linke li <lilinke99@qq.com>
    Cc: Rabin Vincent <rabin@rab.in>
    Fixes: f3ddb74ad0790 ("tracing: Wake up ring buffer waiters on closing of the file")
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
tty: serial: fsl_lpuart: avoid idle preamble pending if CTS is enabled [+ + +]
Author: Sherry Sun <sherry.sun@nxp.com>
Date:   Tue Mar 5 09:57:06 2024 +0800

    tty: serial: fsl_lpuart: avoid idle preamble pending if CTS is enabled
    
    commit 74cb7e0355fae9641f825afa389d3fba3b617714 upstream.
    
    If the remote uart device is not connected or not enabled after booting
    up, the CTS line is high by default. At this time, if we enable the flow
    control when opening the device(for example, using “stty -F /dev/ttyLP4
    crtscts” command), there will be a pending idle preamble(first writing 0
    and then writing 1 to UARTCTRL_TE will queue an idle preamble) that
    cannot be sent out, resulting in the uart port fail to close(waiting for
    TX empty), so the user space stty will have to wait for a long time or
    forever.
    
    This is an LPUART IP bug(idle preamble has higher priority than CTS),
    here add a workaround patch to enable TX CTS after enabling UARTCTRL_TE,
    so that the idle preamble does not get stuck due to CTS is deasserted.
    
    Fixes: 380c966c093e ("tty: serial: fsl_lpuart: add 32-bit register interface support")
    Cc: stable <stable@kernel.org>
    Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
    Reviewed-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
    Link: https://lore.kernel.org/r/20240305015706.1050769-1-sherry.sun@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

tty: serial: imx: Fix broken RS485 [+ + +]
Author: Rickard x Andersson <rickaran@axis.com>
Date:   Wed Feb 21 12:53:04 2024 +0100

    tty: serial: imx: Fix broken RS485
    
    commit 672448ccf9b6a676f96f9352cbf91f4d35f4084a upstream.
    
    When about to transmit the function imx_uart_start_tx is called and in
    some RS485 configurations this function will call imx_uart_stop_rx. The
    problem is that imx_uart_stop_rx will enable loopback in order to
    release the RS485 bus, but when loopback is enabled transmitted data
    will just be looped to RX.
    
    This patch fixes the above problem by not enabling loopback when about
    to transmit.
    
    This driver now works well when used for RS485 half duplex master
    configurations.
    
    Fixes: 79d0224f6bf2 ("tty: serial: imx: Handle RS485 DE signal active high")
    Cc: stable <stable@kernel.org>
    Signed-off-by: Rickard x Andersson <rickaran@axis.com>
    Tested-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
    Link: https://lore.kernel.org/r/20240221115304.509811-1-rickaran@axis.com
    Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
ubi: Check for too small LEB size in VTBL code [+ + +]
Author: Richard Weinberger <richard@nod.at>
Date:   Wed Jan 24 07:37:02 2024 +0100

    ubi: Check for too small LEB size in VTBL code
    
    [ Upstream commit 68a24aba7c593eafa8fd00f2f76407b9b32b47a9 ]
    
    If the LEB size is smaller than a volume table record we cannot
    have volumes.
    In this case abort attaching.
    
    Cc: Chenyuan Yang <cy54@illinois.edu>
    Cc: stable@vger.kernel.org
    Fixes: 801c135ce73d ("UBI: Unsorted Block Images")
    Reported-by: Chenyuan Yang <cy54@illinois.edu>
    Closes: https://lore.kernel.org/linux-mtd/1433EB7A-FC89-47D6-8F47-23BE41B263B3@illinois.edu/
    Signed-off-by: Richard Weinberger <richard@nod.at>
    Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

ubi: correct the calculation of fastmap size [+ + +]
Author: Zhang Yi <yi.zhang@huawei.com>
Date:   Tue Feb 20 10:49:03 2024 +0800

    ubi: correct the calculation of fastmap size
    
    [ Upstream commit 7f174ae4f39e8475adcc09d26c5a43394689ad6c ]
    
    Now that the calculation of fastmap size in ubi_calc_fm_size() is
    incorrect since it miss each user volume's ubi_fm_eba structure and the
    Internal UBI volume info. Let's correct the calculation.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
    Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
    Signed-off-by: Richard Weinberger <richard@nod.at>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
ubifs: Set page uptodate in the correct place [+ + +]
Author: Matthew Wilcox (Oracle) <willy@infradead.org>
Date:   Wed Jan 24 17:52:44 2024 +0000

    ubifs: Set page uptodate in the correct place
    
    [ Upstream commit 723012cab779eee8228376754e22c6594229bf8f ]
    
    Page cache reads are lockless, so setting the freshly allocated page
    uptodate before we've overwritten it with the data it's supposed to have
    in it will allow a simultaneous reader to see old data.  Move the call
    to SetPageUptodate into ubifs_write_end(), which is after we copied the
    new data into the page.
    
    Fixes: 1e51764a3c2a ("UBIFS: add new flash file system")
    Cc: stable@vger.kernel.org
    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
    Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
    Signed-off-by: Richard Weinberger <richard@nod.at>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
usb: cdc-wdm: close race between read and workqueue [+ + +]
Author: Oliver Neukum <oneukum@suse.com>
Date:   Thu Mar 14 12:50:48 2024 +0100

    usb: cdc-wdm: close race between read and workqueue
    
    commit 339f83612f3a569b194680768b22bf113c26a29d upstream.
    
    wdm_read() cannot race with itself. However, in
    service_outstanding_interrupt() it can race with the
    workqueue, which can be triggered by error handling.
    
    Hence we need to make sure that the WDM_RESPONDING
    flag is not just only set but tested.
    
    Fixes: afba937e540c9 ("USB: CDC WDM driver")
    Cc: stable <stable@kernel.org>
    Signed-off-by: Oliver Neukum <oneukum@suse.com>
    Link: https://lore.kernel.org/r/20240314115132.3907-1-oneukum@suse.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
USB: core: Add hub_get() and hub_put() routines [+ + +]
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Fri Mar 15 13:04:50 2024 -0400

    USB: core: Add hub_get() and hub_put() routines
    
    commit ee113b860aa169e9a4d2c167c95d0f1961c6e1b8 upstream.
    
    Create hub_get() and hub_put() routines to encapsulate the kref_get()
    and kref_put() calls in hub.c.  The new routines will be used by the
    next patch in this series.
    
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Link: https://lore.kernel.org/r/604da420-ae8a-4a9e-91a4-2d511ff404fb@rowland.harvard.edu
    Cc: stable <stable@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

USB: core: Fix deadlock in port "disable" sysfs attribute [+ + +]
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Fri Mar 15 13:06:33 2024 -0400

    USB: core: Fix deadlock in port "disable" sysfs attribute
    
    commit f4d1960764d8a70318b02f15203a1be2b2554ca1 upstream.
    
    The show and store callback routines for the "disable" sysfs attribute
    file in port.c acquire the device lock for the port's parent hub
    device.  This can cause problems if another process has locked the hub
    to remove it or change its configuration:
    
            Removing the hub or changing its configuration requires the
            hub interface to be removed, which requires the port device
            to be removed, and device_del() waits until all outstanding
            sysfs attribute callbacks for the ports have returned.  The
            lock can't be released until then.
    
            But the disable_show() or disable_store() routine can't return
            until after it has acquired the lock.
    
    The resulting deadlock can be avoided by calling
    sysfs_break_active_protection().  This will cause the sysfs core not
    to wait for the attribute's callback routine to return, allowing the
    removal to proceed.  The disadvantage is that after making this call,
    there is no guarantee that the hub structure won't be deallocated at
    any moment.  To prevent this, we have to acquire a reference to it
    first by calling hub_get().
    
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Cc: stable <stable@kernel.org>
    Link: https://lore.kernel.org/r/f7a8c135-a495-4ce6-bd49-405a45e7ea9a@rowland.harvard.edu
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

USB: core: Fix deadlock in usb_deauthorize_interface() [+ + +]
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Tue Mar 12 11:48:23 2024 -0400

    USB: core: Fix deadlock in usb_deauthorize_interface()
    
    commit 80ba43e9f799cbdd83842fc27db667289b3150f5 upstream.
    
    Among the attribute file callback routines in
    drivers/usb/core/sysfs.c, the interface_authorized_store() function is
    the only one which acquires a device lock on an ancestor device: It
    calls usb_deauthorize_interface(), which locks the interface's parent
    USB device.
    
    The will lead to deadlock if another process already owns that lock
    and tries to remove the interface, whether through a configuration
    change or because the device has been disconnected.  As part of the
    removal procedure, device_del() waits for all ongoing sysfs attribute
    callbacks to complete.  But usb_deauthorize_interface() can't complete
    until the device lock has been released, and the lock won't be
    released until the removal has finished.
    
    The mechanism provided by sysfs to prevent this kind of deadlock is
    to use the sysfs_break_active_protection() function, which tells sysfs
    not to wait for the attribute callback.
    
    Reported-and-tested by: Yue Sun <samsun1006219@gmail.com>
    Reported by: xingwei lee <xrivendell7@gmail.com>
    
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Link: https://lore.kernel.org/linux-usb/CAEkJfYO6jRVC8Tfrd_R=cjO0hguhrV31fDPrLrNOOHocDkPoAA@mail.gmail.com/#r
    Fixes: 310d2b4124c0 ("usb: interface authorization: SysFS part of USB interface authorization")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/1c37eea1-9f56-4534-b9d8-b443438dc869@rowland.harvard.edu
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
usb: dwc2: gadget: Fix exiting from clock gating [+ + +]
Author: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Date:   Wed Mar 13 09:22:01 2024 +0000

    usb: dwc2: gadget: Fix exiting from clock gating
    
    commit 31f42da31417bec88158f3cf62d19db836217f1e upstream.
    
    Added exiting from the clock gating mode on USB Reset Detect interrupt
    if core in the clock gating mode.
    Added new condition to check core in clock gating mode or no.
    
    Fixes: 9b4965d77e11 ("usb: dwc2: Add exit clock gating from session request interrupt")
    Fixes: 5d240efddc7f ("usb: dwc2: Add exit clock gating from wakeup interrupt")
    Fixes: 16c729f90bdf ("usb: dwc2: Allow exit clock gating in urb enqueue")
    Fixes: 401411bbc4e6 ("usb: dwc2: Add exit clock gating before removing driver")
    CC: stable@vger.kernel.org
    Signed-off-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
    Link: https://lore.kernel.org/r/cbcc2ccd37e89e339130797ed68ae4597db773ac.1708938774.git.Minas.Harutyunyan@synopsys.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: dwc2: gadget: LPM flow fix [+ + +]
Author: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Date:   Wed Mar 13 09:22:13 2024 +0000

    usb: dwc2: gadget: LPM flow fix
    
    commit 5d69a3b54e5a630c90d82a4c2bdce3d53dc78710 upstream.
    
    Added functionality to exit from L1 state by device initiation
    using remote wakeup signaling, in case when function driver queuing
    request while core in L1 state.
    
    Fixes: 273d576c4d41 ("usb: dwc2: gadget: Add functionality to exit from LPM L1 state")
    Fixes: 88b02f2cb1e1 ("usb: dwc2: Add core state checking")
    CC: stable@vger.kernel.org
    Signed-off-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
    Link: https://lore.kernel.org/r/b4d9de5382375dddbf7ef6049d9a82066ad87d5d.1710166393.git.Minas.Harutyunyan@synopsys.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: dwc2: host: Fix hibernation flow [+ + +]
Author: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Date:   Wed Mar 13 09:21:11 2024 +0000

    usb: dwc2: host: Fix hibernation flow
    
    commit 3c7b9856a82227db01a20171d2e24c7ce305d59b upstream.
    
    Added to backup/restore registers HFLBADDR, HCCHARi, HCSPLTi,
    HCTSIZi, HCDMAi and HCDMABi.
    
    Fixes: 58e52ff6a6c3 ("usb: dwc2: Move register save and restore functions")
    Fixes: d17ee77b3044 ("usb: dwc2: add controller hibernation support")
    CC: stable@vger.kernel.org
    Signed-off-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
    Link: https://lore.kernel.org/r/c2d10ee6098b9b009a8e94191e046004747d3bdd.1708945444.git.Minas.Harutyunyan@synopsys.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: dwc2: host: Fix ISOC flow in DDMA mode [+ + +]
Author: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Date:   Wed Mar 13 09:21:32 2024 +0000

    usb: dwc2: host: Fix ISOC flow in DDMA mode
    
    commit b258e42688501cadb1a6dd658d6f015df9f32d8f upstream.
    
    Fixed ISOC completion flow in DDMA mode. Added isoc
    descriptor actual length value and update urb's start_frame
    value.
    Fixed initialization of ISOC DMA descriptors flow.
    
    Fixes: 56f5b1cff22a ("staging: Core files for the DWC2 driver")
    Fixes: 20f2eb9c4cf8 ("staging: dwc2: add microframe scheduler from downstream Pi kernel")
    Fixes: c17b337c1ea4 ("usb: dwc2: host: program descriptor for next frame")
    Fixes: dc4c76e7b22c ("staging: HCD descriptor DMA support for the DWC2 driver")
    Fixes: 762d3a1a9cd7 ("usb: dwc2: host: process all completed urbs")
    CC: stable@vger.kernel.org
    Signed-off-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
    Link: https://lore.kernel.org/r/a8b1e1711cc6cabfb45d92ede12e35445c66f06c.1708944698.git.Minas.Harutyunyan@synopsys.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: dwc2: host: Fix remote wakeup from hibernation [+ + +]
Author: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Date:   Wed Mar 13 09:21:21 2024 +0000

    usb: dwc2: host: Fix remote wakeup from hibernation
    
    commit bae2bc73a59c200db53b6c15fb26bb758e2c6108 upstream.
    
    Starting from core v4.30a changed order of programming
    GPWRDN_PMUACTV to 0 in case of exit from hibernation on
    remote wakeup signaling from device.
    
    Fixes: c5c403dc4336 ("usb: dwc2: Add host/device hibernation functions")
    CC: stable@vger.kernel.org
    Signed-off-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
    Link: https://lore.kernel.org/r/99385ec55ce73445b6fbd0f471c9bd40eb1c9b9e.1708939799.git.Minas.Harutyunyan@synopsys.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: dwc3-am62: fix module unload/reload behavior [+ + +]
Author: Roger Quadros <rogerq@kernel.org>
Date:   Tue Feb 27 11:23:48 2024 +0200

    usb: dwc3-am62: fix module unload/reload behavior
    
    [ Upstream commit 6661befe41009c210efa2c1bcd16a5cc4cff8a06 ]
    
    As runtime PM is enabled, the module can be runtime
    suspended when .remove() is called.
    
    Do a pm_runtime_get_sync() to make sure module is active
    before doing any register operations.
    
    Doing a pm_runtime_put_sync() should disable the refclk
    so no need to disable it again.
    
    Fixes the below warning at module removel.
    
    [   39.705310] ------------[ cut here ]------------
    [   39.710004] clk:162:3 already disabled
    [   39.713941] WARNING: CPU: 0 PID: 921 at drivers/clk/clk.c:1090 clk_core_disable+0xb0/0xb8
    
    We called of_platform_populate() in .probe() so call the
    cleanup function of_platform_depopulate() in .remove().
    Get rid of the now unnnecessary dwc3_ti_remove_core().
    Without this, module re-load doesn't work properly.
    
    Fixes: e8784c0aec03 ("drivers: usb: dwc3: Add AM62 USB wrapper driver")
    Cc: stable@vger.kernel.org # v5.19+
    Signed-off-by: Roger Quadros <rogerq@kernel.org>
    Link: https://lore.kernel.org/r/20240227-for-v6-9-am62-usb-errata-3-0-v4-1-0ada8ddb0767@kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

usb: dwc3-am62: Rename private data [+ + +]
Author: Ladislav Michl <ladis@linux-mips.org>
Date:   Sat Jul 15 16:07:26 2023 +0200

    usb: dwc3-am62: Rename private data
    
    [ Upstream commit 3609699c32aa4f2710a6fe2b21afc6a9a3c66bc5 ]
    
    Rename dwc3_data to dwc3_am62 to make it consistent with other
    glue drivers, it's clearer that this is am62's specific.
    While there, do the same for data variable.
    
    Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
    Link: https://lore.kernel.org/r/ZLKoHhJvT+Y6aM+C@lenoch
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Stable-dep-of: 6661befe4100 ("usb: dwc3-am62: fix module unload/reload behavior")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

usb: gadget: ncm: Fix handling of zero block length packets [+ + +]
Author: Krishna Kurapati <quic_kriskura@quicinc.com>
Date:   Wed Feb 28 17:24:41 2024 +0530

    usb: gadget: ncm: Fix handling of zero block length packets
    
    commit f90ce1e04cbcc76639d6cba0fdbd820cd80b3c70 upstream.
    
    While connecting to a Linux host with CDC_NCM_NTB_DEF_SIZE_TX
    set to 65536, it has been observed that we receive short packets,
    which come at interval of 5-10 seconds sometimes and have block
    length zero but still contain 1-2 valid datagrams present.
    
    According to the NCM spec:
    
    "If wBlockLength = 0x0000, the block is terminated by a
    short packet. In this case, the USB transfer must still
    be shorter than dwNtbInMaxSize or dwNtbOutMaxSize. If
    exactly dwNtbInMaxSize or dwNtbOutMaxSize bytes are sent,
    and the size is a multiple of wMaxPacketSize for the
    given pipe, then no ZLP shall be sent.
    
    wBlockLength= 0x0000 must be used with extreme care, because
    of the possibility that the host and device may get out of
    sync, and because of test issues.
    
    wBlockLength = 0x0000 allows the sender to reduce latency by
    starting to send a very large NTB, and then shortening it when
    the sender discovers that there’s not sufficient data to justify
    sending a large NTB"
    
    However, there is a potential issue with the current implementation,
    as it checks for the occurrence of multiple NTBs in a single
    giveback by verifying if the leftover bytes to be processed is zero
    or not. If the block length reads zero, we would process the same
    NTB infintely because the leftover bytes is never zero and it leads
    to a crash. Fix this by bailing out if block length reads zero.
    
    Cc: stable@vger.kernel.org
    Fixes: 427694cfaafa ("usb: gadget: ncm: Handle decoding of multiple NTB's in unwrap call")
    Signed-off-by: Krishna Kurapati <quic_kriskura@quicinc.com>
    Reviewed-by: Maciej Żenczykowski <maze@google.com>
    Link: https://lore.kernel.org/r/20240228115441.2105585-1-quic_kriskura@quicinc.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: gadget: tegra-xudc: Fix USB3 PHY retrieval logic [+ + +]
Author: Wayne Chang <waynec@nvidia.com>
Date:   Thu Mar 7 11:03:28 2024 +0800

    usb: gadget: tegra-xudc: Fix USB3 PHY retrieval logic
    
    [ Upstream commit 84fa943d93c31ee978355e6c6c69592dae3c9f59 ]
    
    This commit resolves an issue in the tegra-xudc USB gadget driver that
    incorrectly fetched USB3 PHY instances. The problem stemmed from the
    assumption of a one-to-one correspondence between USB2 and USB3 PHY
    names and their association with physical USB ports in the device tree.
    
    Previously, the driver associated USB3 PHY names directly with the USB3
    instance number, leading to mismatches when mapping the physical USB
    ports. For instance, if using USB3-1 PHY, the driver expect the
    corresponding PHY name as 'usb3-1'. However, the physical USB ports in
    the device tree were designated as USB2-0 and USB3-0 as we only have
    one device controller, causing a misalignment.
    
    This commit rectifies the issue by adjusting the PHY naming logic.
    Now, the driver correctly correlates the USB2 and USB3 PHY instances,
    allowing the USB2-0 and USB3-1 PHYs to form a physical USB port pair
    while accurately reflecting their configuration in the device tree by
    naming them USB2-0 and USB3-0, respectively.
    
    The change ensures that the PHY and PHY names align appropriately,
    resolving the mismatch between physical USB ports and their associated
    names in the device tree.
    
    Fixes: b4e19931c98a ("usb: gadget: tegra-xudc: Support multiple device modes")
    Cc: stable@vger.kernel.org
    Signed-off-by: Wayne Chang <waynec@nvidia.com>
    Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
    Tested-by: Jon Hunter <jonathanh@nvidia.com>
    Link: https://lore.kernel.org/r/20240307030328.1487748-3-waynec@nvidia.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

usb: port: Don't try to peer unused USB ports based on location [+ + +]
Author: Mathias Nyman <mathias.nyman@linux.intel.com>
Date:   Fri Feb 23 01:33:43 2024 +0200

    usb: port: Don't try to peer unused USB ports based on location
    
    commit 69c63350e573367f9c8594162288cffa8a26d0d1 upstream.
    
    Unused USB ports may have bogus location data in ACPI PLD tables.
    This causes port peering failures as these unused USB2 and USB3 ports
    location may match.
    
    Due to these failures the driver prints a
    "usb: port power management may be unreliable" warning, and
    unnecessarily blocks port power off during runtime suspend.
    
    This was debugged on a couple DELL systems where the unused ports
    all returned zeroes in their location data.
    Similar bugreports exist for other systems.
    
    Don't try to peer or match ports that have connect type set to
    USB_PORT_NOT_USED.
    
    Fixes: 3bfd659baec8 ("usb: find internal hub tier mismatch via acpi")
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218465
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218486
    Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>
    Link: https://lore.kernel.org/linux-usb/5406d361-f5b7-4309-b0e6-8c94408f7d75@molgen.mpg.de
    Cc: stable@vger.kernel.org # v3.16+
    Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218490
    Link: https://lore.kernel.org/r/20240222233343.71856-1-mathias.nyman@linux.intel.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
USB: serial: add device ID for VeriFone adapter [+ + +]
Author: Cameron Williams <cang1@live.co.uk>
Date:   Tue Feb 13 21:53:29 2024 +0000

    USB: serial: add device ID for VeriFone adapter
    
    [ Upstream commit cda704809797a8a86284f9df3eef5e62ec8a3175 ]
    
    Add device ID for a (probably fake) CP2102 UART device.
    
    lsusb -v output:
    
    Device Descriptor:
      bLength                18
      bDescriptorType         1
      bcdUSB               1.10
      bDeviceClass            0 [unknown]
      bDeviceSubClass         0 [unknown]
      bDeviceProtocol         0
      bMaxPacketSize0        64
      idVendor           0x11ca VeriFone Inc
      idProduct          0x0212 Verifone USB to Printer
      bcdDevice            1.00
      iManufacturer           1 Silicon Labs
      iProduct                2 Verifone USB to Printer
      iSerial                 3 0001
      bNumConfigurations      1
      Configuration Descriptor:
        bLength                 9
        bDescriptorType         2
        wTotalLength       0x0020
        bNumInterfaces          1
        bConfigurationValue     1
        iConfiguration          0
        bmAttributes         0x80
          (Bus Powered)
        MaxPower              100mA
        Interface Descriptor:
          bLength                 9
          bDescriptorType         4
          bInterfaceNumber        0
          bAlternateSetting       0
          bNumEndpoints           2
          bInterfaceClass       255 Vendor Specific Class
          bInterfaceSubClass      0 [unknown]
          bInterfaceProtocol      0
          iInterface              2 Verifone USB to Printer
          Endpoint Descriptor:
            bLength                 7
            bDescriptorType         5
            bEndpointAddress     0x81  EP 1 IN
            bmAttributes            2
              Transfer Type            Bulk
              Synch Type               None
              Usage Type               Data
            wMaxPacketSize     0x0040  1x 64 bytes
            bInterval               0
          Endpoint Descriptor:
            bLength                 7
            bDescriptorType         5
            bEndpointAddress     0x01  EP 1 OUT
            bmAttributes            2
              Transfer Type            Bulk
              Synch Type               None
              Usage Type               Data
            wMaxPacketSize     0x0040  1x 64 bytes
            bInterval               0
    Device Status:     0x0000
      (Bus Powered)
    
    Signed-off-by: Cameron Williams <cang1@live.co.uk>
    Cc: stable@vger.kernel.org
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

USB: serial: cp210x: add ID for MGP Instruments PDS100 [+ + +]
Author: Christian Häggström <christian.haggstrom@orexplore.com>
Date:   Wed Feb 14 11:47:29 2024 +0100

    USB: serial: cp210x: add ID for MGP Instruments PDS100
    
    [ Upstream commit a0d9d868491a362d421521499d98308c8e3a0398 ]
    
    The radiation meter has the text MGP Instruments PDS-100G or PDS-100GN
    produced by Mirion Technologies. Tested by forcing the driver
    association with
    
      echo 10c4 863c > /sys/bus/usb-serial/drivers/cp210x/new_id
    
    and then setting the serial port in 115200 8N1 mode. The device
    announces ID_USB_VENDOR_ENC=Silicon\x20Labs and ID_USB_MODEL_ENC=PDS100
    
    Signed-off-by: Christian Häggström <christian.haggstrom@orexplore.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

USB: serial: cp210x: add pid/vid for TDK NC0110013M and MM0110113M [+ + +]
Author: Toru Katagiri <Toru.Katagiri@tdk.com>
Date:   Tue Mar 5 08:46:14 2024 +0900

    USB: serial: cp210x: add pid/vid for TDK NC0110013M and MM0110113M
    
    [ Upstream commit b1a8da9ff1395c4879b4bd41e55733d944f3d613 ]
    
    TDK NC0110013M and MM0110113M have custom USB IDs for CP210x,
    so we need to add them to the driver.
    
    Signed-off-by: Toru Katagiri <Toru.Katagiri@tdk.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

USB: serial: ftdi_sio: add support for GMC Z216C Adapter IR-USB [+ + +]
Author: Daniel Vogelbacher <daniel@chaospixel.com>
Date:   Sun Feb 11 15:42:46 2024 +0100

    USB: serial: ftdi_sio: add support for GMC Z216C Adapter IR-USB
    
    [ Upstream commit 3fb7bc4f3a98c48981318b87cf553c5f115fd5ca ]
    
    The GMC IR-USB adapter cable utilizes a FTDI FT232R chip.
    
    Add VID/PID for this adapter so it can be used as serial device via
    ftdi_sio.
    
    Signed-off-by: Daniel Vogelbacher <daniel@chaospixel.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

USB: serial: option: add MeiG Smart SLM320 product [+ + +]
Author: Aurélien Jacobs <aurel@gnuage.org>
Date:   Wed Jan 31 18:49:17 2024 +0100

    USB: serial: option: add MeiG Smart SLM320 product
    
    [ Upstream commit 46809c51565b83881aede6cdf3b0d25254966a41 ]
    
    Update the USB serial option driver to support MeiG Smart SLM320.
    
    ID 2dee:4d41 UNISOC UNISOC-8910
    
    T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 9 Spd=480 MxCh= 0
    D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
    P: Vendor=2dee ProdID=4d41 Rev=00.00
    S: Manufacturer=UNISOC
    S: Product=UNISOC-8910
    C: #Ifs= 8 Cfg#= 1 Atr=e0 MxPwr=400mA
    I: If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I: If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I: If#= 2 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I: If#= 3 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=84(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I: If#= 4 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I: If#= 5 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=06(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=86(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I: If#= 6 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=07(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I: If#= 7 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=08(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=88(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    
    Tested successfully a PPP LTE connection using If#= 0.
    Not sure of the purpose of every other serial interfaces.
    
    Signed-off-by: Aurélien Jacobs <aurel@gnuage.org>
    Cc: stable@vger.kernel.org
    Signed-off-by: Johan Hovold <johan@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
usb: typec: Return size of buffer if pd_set operation succeeds [+ + +]
Author: Kyle Tso <kyletso@google.com>
Date:   Tue Mar 19 15:43:09 2024 +0800

    usb: typec: Return size of buffer if pd_set operation succeeds
    
    commit 53f5094fdf5deacd99b8655df692e9278506724d upstream.
    
    The attribute writing should return the number of bytes used from the
    buffer on success.
    
    Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
    Cc: stable@vger.kernel.org
    Signed-off-by: Kyle Tso <kyletso@google.com>
    Reviewed-by: Guenter Roeck <linux@roeck-us.net>
    Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
    Link: https://lore.kernel.org/r/20240319074309.3306579-1-kyletso@google.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: typec: ucsi: Ack unsupported commands [+ + +]
Author: Christian A. Ehrhardt <lk@c--e.de>
Date:   Wed Mar 20 08:39:24 2024 +0100

    usb: typec: ucsi: Ack unsupported commands
    
    commit 6b5c85ddeea77d18c4b69e3bda60e9374a20c304 upstream.
    
    If a command completes the OPM must send an ack. This applies
    to unsupported commands, too.
    
    Send the required ACK for unsupported commands.
    
    Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
    Cc: stable <stable@kernel.org>
    Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
    Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD
    Link: https://lore.kernel.org/r/20240320073927.1641788-4-lk@c--e.de
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: typec: ucsi: Clean up UCSI_CABLE_PROP macros [+ + +]
Author: Jameson Thies <jthies@google.com>
Date:   Tue Mar 5 02:58:01 2024 +0000

    usb: typec: ucsi: Clean up UCSI_CABLE_PROP macros
    
    [ Upstream commit 4d0a5a9915793377c0fe1a8d78de6bcd92cea963 ]
    
    Clean up UCSI_CABLE_PROP macros by fixing a bitmask shifting error for
    plug type and updating the modal support macro for consistent naming.
    
    Fixes: 3cf657f07918 ("usb: typec: ucsi: Remove all bit-fields")
    Cc: stable@vger.kernel.org
    Reviewed-by: Benson Leung <bleung@chromium.org>
    Reviewed-by: Prashant Malani <pmalani@chromium.org>
    Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
    Signed-off-by: Jameson Thies <jthies@google.com>
    Link: https://lore.kernel.org/r/20240305025804.1290919-2-jthies@google.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

usb: typec: ucsi: Clear EVENT_PENDING under PPM lock [+ + +]
Author: Christian A. Ehrhardt <lk@c--e.de>
Date:   Wed Mar 20 08:39:22 2024 +0100

    usb: typec: ucsi: Clear EVENT_PENDING under PPM lock
    
    commit 15b2e71b4653b3e13df34695a29ebeee237c5af2 upstream.
    
    Suppose we sleep on the PPM lock after clearing the EVENT_PENDING
    bit because the thread for another connector is executing a command.
    In this case the command completion of the other command will still
    report the connector change for our connector.
    
    Clear the EVENT_PENDING bit under the PPM lock to avoid another
    useless call to ucsi_handle_connector_change() in this case.
    
    Fixes: c9aed03a0a68 ("usb: ucsi: Add missing ppm_lock")
    Cc: stable <stable@kernel.org>
    Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
    Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
    Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD
    Link: https://lore.kernel.org/r/20240320073927.1641788-2-lk@c--e.de
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: typec: ucsi: Clear UCSI_CCI_RESET_COMPLETE before reset [+ + +]
Author: Christian A. Ehrhardt <lk@c--e.de>
Date:   Wed Mar 20 08:39:26 2024 +0100

    usb: typec: ucsi: Clear UCSI_CCI_RESET_COMPLETE before reset
    
    commit 3de4f996a0b5412aa451729008130a488f71563e upstream.
    
    Check the UCSI_CCI_RESET_COMPLETE complete flag before starting
    another reset. Use a UCSI_SET_NOTIFICATION_ENABLE command to clear
    the flag if it is set.
    
    Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
    Cc: stable <stable@kernel.org>
    Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
    Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD
    Link: https://lore.kernel.org/r/20240320073927.1641788-6-lk@c--e.de
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

usb: typec: ucsi_acpi: Refactor and fix DELL quirk [+ + +]
Author: Christian A. Ehrhardt <lk@c--e.de>
Date:   Wed Mar 20 08:39:25 2024 +0100

    usb: typec: ucsi_acpi: Refactor and fix DELL quirk
    
    commit 6aaceb7d9cd00f3e065dc4b054ecfe52c5253b03 upstream.
    
    Some DELL systems don't like UCSI_ACK_CC_CI commands with the
    UCSI_ACK_CONNECTOR_CHANGE but not the UCSI_ACK_COMMAND_COMPLETE
    bit set. The current quirk still leaves room for races because
    it requires two consecutive ACK commands to be sent.
    
    Refactor and significantly simplify the quirk to fix this:
    Send a dummy command and bundle the connector change ack with the
    command completion ack in a single UCSI_ACK_CC_CI command.
    This removes the need to probe for the quirk.
    
    While there define flag bits for struct ucsi_acpi->flags in ucsi_acpi.c
    and don't re-use definitions from ucsi.h for struct ucsi->flags.
    
    Fixes: f3be347ea42d ("usb: ucsi_acpi: Quirk to ack a connector change ack cmd")
    Cc: stable@vger.kernel.org
    Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
    Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
    Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD
    Link: https://lore.kernel.org/r/20240320073927.1641788-5-lk@c--e.de
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
USB: UAS: return ENODEV when submit urbs fail with device not attached [+ + +]
Author: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
Date:   Thu Mar 7 02:08:14 2024 +0800

    USB: UAS: return ENODEV when submit urbs fail with device not attached
    
    commit cd5432c712351a3d5f82512908f5febfca946ca6 upstream.
    
    In the scenario of entering hibernation with udisk in the system, if the
    udisk was gone or resume fail in the thaw phase of hibernation. Its state
    will be set to NOTATTACHED. At this point, usb_hub_wq was already freezed
    and can't not handle disconnect event. Next, in the poweroff phase of
    hibernation, SYNCHRONIZE_CACHE SCSI command will be sent to this udisk
    when poweroff this scsi device, which will cause uas_submit_urbs to be
    called to submit URB for sense/data/cmd pipe. However, these URBs will
    submit fail as device was set to NOTATTACHED state. Then, uas_submit_urbs
    will return a value SCSI_MLQUEUE_DEVICE_BUSY to the caller. That will lead
    the SCSI layer go into an ugly loop and system fail to go into hibernation.
    
    On the other hand, when we specially check for -ENODEV in function
    uas_queuecommand_lck, returning DID_ERROR to SCSI layer will cause device
    poweroff fail and system shutdown instead of entering hibernation.
    
    To fix this issue, let uas_submit_urbs to return original generic error
    when submitting URB failed. At the same time, we need to translate -ENODEV
    to DID_NOT_CONNECT for the SCSI layer.
    
    Suggested-by: Oliver Neukum <oneukum@suse.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
    Link: https://lore.kernel.org/r/20240306180814.4897-1-WeitaoWang-oc@zhaoxin.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
usb: udc: remove warning when queue disabled ep [+ + +]
Author: yuan linyu <yuanlinyu@hihonor.com>
Date:   Fri Mar 15 10:01:44 2024 +0800

    usb: udc: remove warning when queue disabled ep
    
    commit 2a587a035214fa1b5ef598aea0b81848c5b72e5e upstream.
    
    It is possible trigger below warning message from mass storage function,
    
    WARNING: CPU: 6 PID: 3839 at drivers/usb/gadget/udc/core.c:294 usb_ep_queue+0x7c/0x104
    pc : usb_ep_queue+0x7c/0x104
    lr : fsg_main_thread+0x494/0x1b3c
    
    Root cause is mass storage function try to queue request from main thread,
    but other thread may already disable ep when function disable.
    
    As there is no function failure in the driver, in order to avoid effort
    to fix warning, change WARN_ON_ONCE() in usb_ep_queue() to pr_debug().
    
    Suggested-by: Alan Stern <stern@rowland.harvard.edu>
    Cc: stable@vger.kernel.org
    Signed-off-by: yuan linyu <yuanlinyu@hihonor.com>
    Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
    Link: https://lore.kernel.org/r/20240315020144.2715575-1-yuanlinyu@hihonor.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
USB: usb-storage: Prevent divide-by-0 error in isd200_ata_command [+ + +]
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Thu Feb 29 14:30:06 2024 -0500

    USB: usb-storage: Prevent divide-by-0 error in isd200_ata_command
    
    commit 014bcf41d946b36a8f0b8e9b5d9529efbb822f49 upstream.
    
    The isd200 sub-driver in usb-storage uses the HEADS and SECTORS values
    in the ATA ID information to calculate cylinder and head values when
    creating a CDB for READ or WRITE commands.  The calculation involves
    division and modulus operations, which will cause a crash if either of
    these values is 0.  While this never happens with a genuine device, it
    could happen with a flawed or subversive emulation, as reported by the
    syzbot fuzzer.
    
    Protect against this possibility by refusing to bind to the device if
    either the ATA_ID_HEADS or ATA_ID_SECTORS value in the device's ID
    information is 0.  This requires isd200_Initialization() to return a
    negative error code when initialization fails; currently it always
    returns 0 (even when there is an error).
    
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Reported-and-tested-by: syzbot+28748250ab47a8f04100@syzkaller.appspotmail.com
    Link: https://lore.kernel.org/linux-usb/0000000000003eb868061245ba7f@google.com/
    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Cc: stable@vger.kernel.org
    Reviewed-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
    Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
    Link: https://lore.kernel.org/r/b1e605ea-333f-4ac0-9511-da04f411763e@rowland.harvard.edu
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
usb: xhci: Add error handling in xhci_map_urb_for_dma [+ + +]
Author: Prashanth K <quic_prashk@quicinc.com>
Date:   Thu Feb 29 16:14:38 2024 +0200

    usb: xhci: Add error handling in xhci_map_urb_for_dma
    
    [ Upstream commit be95cc6d71dfd0cba66e3621c65413321b398052 ]
    
    Currently xhci_map_urb_for_dma() creates a temporary buffer and copies
    the SG list to the new linear buffer. But if the kzalloc_node() fails,
    then the following sg_pcopy_to_buffer() can lead to crash since it
    tries to memcpy to NULL pointer.
    
    So return -ENOMEM if kzalloc returns null pointer.
    
    Cc: stable@vger.kernel.org # 5.11
    Fixes: 2017a1e58472 ("usb: xhci: Use temporary buffer to consolidate SG")
    Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
    Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
    Link: https://lore.kernel.org/r/20240229141438.619372-10-mathias.nyman@linux.intel.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
vfio/fsl-mc: Block calling interrupt handler without trigger [+ + +]
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Fri Mar 29 15:38:54 2024 -0600

    vfio/fsl-mc: Block calling interrupt handler without trigger
    
    [ Upstream commit 7447d911af699a15f8d050dfcb7c680a86f87012 ]
    
    The eventfd_ctx trigger pointer of the vfio_fsl_mc_irq object is
    initially NULL and may become NULL if the user sets the trigger
    eventfd to -1.  The interrupt handler itself is guaranteed that
    trigger is always valid between request_irq() and free_irq(), but
    the loopback testing mechanisms to invoke the handler function
    need to test the trigger.  The triggering and setting ioctl paths
    both make use of igate and are therefore mutually exclusive.
    
    The vfio-fsl-mc driver does not make use of irqfds, nor does it
    support any sort of masking operations, therefore unlike vfio-pci
    and vfio-platform, the flow can remain essentially unchanged.
    
    Cc: Diana Craciun <diana.craciun@oss.nxp.com>
    Cc:  <stable@vger.kernel.org>
    Fixes: cc0ee20bd969 ("vfio/fsl-mc: trigger an interrupt via eventfd")
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20240308230557.805580-8-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
vfio/pci: Consolidate irq cleanup on MSI/MSI-X disable [+ + +]
Author: Reinette Chatre <reinette.chatre@intel.com>
Date:   Thu May 11 08:44:28 2023 -0700

    vfio/pci: Consolidate irq cleanup on MSI/MSI-X disable
    
    [ Upstream commit a65f35cfd504e5135540939cffd4323083190b36 ]
    
    vfio_msi_disable() releases all previously allocated state
    associated with each interrupt before disabling MSI/MSI-X.
    
    vfio_msi_disable() iterates twice over the interrupt state:
    first directly with a for loop to do virqfd cleanup, followed
    by another for loop within vfio_msi_set_block() that removes
    the interrupt handler and its associated state using
    vfio_msi_set_vector_signal().
    
    Simplify interrupt cleanup by iterating over allocated interrupts
    once.
    
    Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Acked-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/837acb8cbe86a258a50da05e56a1f17c1a19abbe.1683740667.git.reinette.chatre@intel.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Stable-dep-of: fe9a7082684e ("vfio/pci: Disable auto-enable of exclusive INTx IRQ")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

vfio/pci: Create persistent INTx handler [+ + +]
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Fri Mar 29 15:38:52 2024 -0600

    vfio/pci: Create persistent INTx handler
    
    [ Upstream commit 18c198c96a815c962adc2b9b77909eec0be7df4d ]
    
    A vulnerability exists where the eventfd for INTx signaling can be
    deconfigured, which unregisters the IRQ handler but still allows
    eventfds to be signaled with a NULL context through the SET_IRQS ioctl
    or through unmask irqfd if the device interrupt is pending.
    
    Ideally this could be solved with some additional locking; the igate
    mutex serializes the ioctl and config space accesses, and the interrupt
    handler is unregistered relative to the trigger, but the irqfd path
    runs asynchronous to those.  The igate mutex cannot be acquired from the
    atomic context of the eventfd wake function.  Disabling the irqfd
    relative to the eventfd registration is potentially incompatible with
    existing userspace.
    
    As a result, the solution implemented here moves configuration of the
    INTx interrupt handler to track the lifetime of the INTx context object
    and irq_type configuration, rather than registration of a particular
    trigger eventfd.  Synchronization is added between the ioctl path and
    eventfd_signal() wrapper such that the eventfd trigger can be
    dynamically updated relative to in-flight interrupts or irqfd callbacks.
    
    Cc:  <stable@vger.kernel.org>
    Fixes: 89e1f7d4c66d ("vfio: Add PCI device driver")
    Reported-by: Reinette Chatre <reinette.chatre@intel.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20240308230557.805580-5-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

vfio/pci: Disable auto-enable of exclusive INTx IRQ [+ + +]
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Fri Mar 29 15:38:50 2024 -0600

    vfio/pci: Disable auto-enable of exclusive INTx IRQ
    
    [ Upstream commit fe9a7082684eb059b925c535682e68c34d487d43 ]
    
    Currently for devices requiring masking at the irqchip for INTx, ie.
    devices without DisINTx support, the IRQ is enabled in request_irq()
    and subsequently disabled as necessary to align with the masked status
    flag.  This presents a window where the interrupt could fire between
    these events, resulting in the IRQ incrementing the disable depth twice.
    This would be unrecoverable for a user since the masked flag prevents
    nested enables through vfio.
    
    Instead, invert the logic using IRQF_NO_AUTOEN such that exclusive INTx
    is never auto-enabled, then unmask as required.
    
    Cc:  <stable@vger.kernel.org>
    Fixes: 89e1f7d4c66d ("vfio: Add PCI device driver")
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20240308230557.805580-2-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

vfio/pci: Lock external INTx masking ops [+ + +]
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Fri Mar 8 16:05:23 2024 -0700

    vfio/pci: Lock external INTx masking ops
    
    [ Upstream commit 810cd4bb53456d0503cc4e7934e063835152c1b7 ]
    
    Mask operations through config space changes to DisINTx may race INTx
    configuration changes via ioctl.  Create wrappers that add locking for
    paths outside of the core interrupt code.
    
    In particular, irq_type is updated holding igate, therefore testing
    is_intx() requires holding igate.  For example clearing DisINTx from
    config space can otherwise race changes of the interrupt configuration.
    
    This aligns interfaces which may trigger the INTx eventfd into two
    camps, one side serialized by igate and the other only enabled while
    INTx is configured.  A subsequent patch introduces synchronization for
    the latter flows.
    
    Cc:  <stable@vger.kernel.org>
    Fixes: 89e1f7d4c66d ("vfio: Add PCI device driver")
    Reported-by: Reinette Chatre <reinette.chatre@intel.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20240308230557.805580-3-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

vfio/pci: Remove negative check on unsigned vector [+ + +]
Author: Reinette Chatre <reinette.chatre@intel.com>
Date:   Thu May 11 08:44:29 2023 -0700

    vfio/pci: Remove negative check on unsigned vector
    
    [ Upstream commit 6578ed85c7d63693669bfede01e0237d0e24211a ]
    
    User space provides the vector as an unsigned int that is checked
    early for validity (vfio_set_irqs_validate_and_prepare()).
    
    A later negative check of the provided vector is not necessary.
    
    Remove the negative check and ensure the type used
    for the vector is consistent as an unsigned int.
    
    Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Acked-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/28521e1b0b091849952b0ecb8c118729fc8cdc4f.1683740667.git.reinette.chatre@intel.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Stable-dep-of: fe9a7082684e ("vfio/pci: Disable auto-enable of exclusive INTx IRQ")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
vfio/platform: Create persistent IRQ handlers [+ + +]
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Fri Mar 29 15:38:53 2024 -0600

    vfio/platform: Create persistent IRQ handlers
    
    [ Upstream commit 675daf435e9f8e5a5eab140a9864dfad6668b375 ]
    
    The vfio-platform SET_IRQS ioctl currently allows loopback triggering of
    an interrupt before a signaling eventfd has been configured by the user,
    which thereby allows a NULL pointer dereference.
    
    Rather than register the IRQ relative to a valid trigger, register all
    IRQs in a disabled state in the device open path.  This allows mask
    operations on the IRQ to nest within the overall enable state governed
    by a valid eventfd signal.  This decouples @masked, protected by the
    @locked spinlock from @trigger, protected via the @igate mutex.
    
    In doing so, it's guaranteed that changes to @trigger cannot race the
    IRQ handlers because the IRQ handler is synchronously disabled before
    modifying the trigger, and loopback triggering of the IRQ via ioctl is
    safe due to serialization with trigger changes via igate.
    
    For compatibility, request_irq() failures are maintained to be local to
    the SET_IRQS ioctl rather than a fatal error in the open device path.
    This allows, for example, a userspace driver with polling mode support
    to continue to work regardless of moving the request_irq() call site.
    This necessarily blocks all SET_IRQS access to the failed index.
    
    Cc: Eric Auger <eric.auger@redhat.com>
    Cc:  <stable@vger.kernel.org>
    Fixes: 57f972e2b341 ("vfio/platform: trigger an interrupt via eventfd")
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20240308230557.805580-7-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

vfio/platform: Disable virqfds on cleanup [+ + +]
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Fri Mar 8 16:05:26 2024 -0700

    vfio/platform: Disable virqfds on cleanup
    
    [ Upstream commit fcdc0d3d40bc26c105acf8467f7d9018970944ae ]
    
    irqfds for mask and unmask that are not specifically disabled by the
    user are leaked.  Remove any irqfds during cleanup
    
    Cc: Eric Auger <eric.auger@redhat.com>
    Cc:  <stable@vger.kernel.org>
    Fixes: a7fa7c77cf15 ("vfio/platform: implement IRQ masking/unmasking via an eventfd")
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20240308230557.805580-6-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
vfio: Introduce interface to flush virqfd inject workqueue [+ + +]
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Fri Mar 29 15:38:51 2024 -0600

    vfio: Introduce interface to flush virqfd inject workqueue
    
    [ Upstream commit b620ecbd17a03cacd06f014a5d3f3a11285ce053 ]
    
    In order to synchronize changes that can affect the thread callback,
    introduce an interface to force a flush of the inject workqueue.  The
    irqfd pointer is only valid under spinlock, but the workqueue cannot
    be flushed under spinlock.  Therefore the flush work for the irqfd is
    queued under spinlock.  The vfio_irqfd_cleanup_wq workqueue is re-used
    for queuing this work such that flushing the workqueue is also ordered
    relative to shutdown.
    
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
    Reviewed-by: Eric Auger <eric.auger@redhat.com>
    Link: https://lore.kernel.org/r/20240308230557.805580-4-alex.williamson@redhat.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

vfio: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations [+ + +]
Author: Jason Gunthorpe <jgg@ziepe.ca>
Date:   Sun Jan 8 17:44:24 2023 +0200

    vfio: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations
    
    [ Upstream commit 0886196ca8810c5b1f5097b71c4bc0df40b10208 ]
    
    Use GFP_KERNEL_ACCOUNT for userspace persistent allocations.
    
    The GFP_KERNEL_ACCOUNT option lets the memory allocator know that this
    is untrusted allocation triggered from userspace and should be a subject
    of kmem accounting, and as such it is controlled by the cgroup
    mechanism.
    
    The way to find the relevant allocations was for example to look at the
    close_device function and trace back all the kfrees to their
    allocations.
    
    Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
    Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
    Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/20230108154427.32609-4-yishaih@nvidia.com
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Stable-dep-of: fe9a7082684e ("vfio/pci: Disable auto-enable of exclusive INTx IRQ")
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
vt: fix unicode buffer corruption when deleting characters [+ + +]
Author: Nicolas Pitre <nico@fluxnic.net>
Date:   Thu Feb 29 17:15:27 2024 -0500

    vt: fix unicode buffer corruption when deleting characters
    
    commit 1581dafaf0d34bc9c428a794a22110d7046d186d upstream.
    
    This is the same issue that was fixed for the VGA text buffer in commit
    39cdb68c64d8 ("vt: fix memory overlapping when deleting chars in the
    buffer"). The cure is also the same i.e. replace memcpy() with memmove()
    due to the overlaping buffers.
    
    Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
    Fixes: 81732c3b2fed ("tty vt: Fix line garbage in virtual console on command line edition")
    Cc: stable <stable@kernel.org>
    Link: https://lore.kernel.org/r/sn184on2-3p0q-0qrq-0218-895349s4753o@syhkavp.arg
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
wifi: brcmfmac: Fix use-after-free bug in brcmf_cfg80211_detach [+ + +]
Author: Zheng Wang <zyytlz.wz@163.com>
Date:   Sun Jan 7 08:25:04 2024 +0100

    wifi: brcmfmac: Fix use-after-free bug in brcmf_cfg80211_detach
    
    [ Upstream commit 0f7352557a35ab7888bc7831411ec8a3cbe20d78 ]
    
    This is the candidate patch of CVE-2023-47233 :
    https://nvd.nist.gov/vuln/detail/CVE-2023-47233
    
    In brcm80211 driver,it starts with the following invoking chain
    to start init a timeout worker:
    
    ->brcmf_usb_probe
      ->brcmf_usb_probe_cb
        ->brcmf_attach
          ->brcmf_bus_started
            ->brcmf_cfg80211_attach
              ->wl_init_priv
                ->brcmf_init_escan
                  ->INIT_WORK(&cfg->escan_timeout_work,
                      brcmf_cfg80211_escan_timeout_worker);
    
    If we disconnect the USB by hotplug, it will call
    brcmf_usb_disconnect to make cleanup. The invoking chain is :
    
    brcmf_usb_disconnect
      ->brcmf_usb_disconnect_cb
        ->brcmf_detach
          ->brcmf_cfg80211_detach
            ->kfree(cfg);
    
    While the timeout woker may still be running. This will cause
    a use-after-free bug on cfg in brcmf_cfg80211_escan_timeout_worker.
    
    Fix it by deleting the timer and canceling the worker in
    brcmf_cfg80211_detach.
    
    Fixes: e756af5b30b0 ("brcmfmac: add e-scan support.")
    Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
    Cc: stable@vger.kernel.org
    [arend.vanspriel@broadcom.com: keep timer delete as is and cancel work just before free]
    Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
    Signed-off-by: Kalle Valo <kvalo@kernel.org>
    Link: https://msgid.link/20240107072504.392713-1-arend.vanspriel@broadcom.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>

wifi: iwlwifi: fw: don't always use FW dump trig [+ + +]
Author: Johannes Berg <johannes.berg@intel.com>
Date:   Tue Mar 19 10:10:20 2024 +0200

    wifi: iwlwifi: fw: don't always use FW dump trig
    
    commit 045a5b645dd59929b0e05375f493cde3a0318271 upstream.
    
    Since the dump_data (struct iwl_fwrt_dump_data) is a union,
    it's not safe to unconditionally access and use the 'trig'
    member, it might be 'desc' instead. Access it only if it's
    known to be 'trig' rather than 'desc', i.e. if ini-debug
    is present.
    
    Cc: stable@vger.kernel.org
    Fixes: 0eb50c674a1e ("iwlwifi: yoyo: send hcmd to fw after dump collection completes.")
    Signed-off-by: Johannes Berg <johannes.berg@intel.com>
    Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
    Link: https://msgid.link/20240319100755.e2976bc58b29.I72fbd6135b3623227de53d8a2bb82776066cb72b@changeid
    Signed-off-by: Johannes Berg <johannes.berg@intel.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

wifi: mac80211: check/clear fast rx for non-4addr sta VLAN changes [+ + +]
Author: Felix Fietkau <nbd@nbd.name>
Date:   Sat Mar 16 08:43:36 2024 +0100

    wifi: mac80211: check/clear fast rx for non-4addr sta VLAN changes
    
    commit 4f2bdb3c5e3189297e156b3ff84b140423d64685 upstream.
    
    When moving a station out of a VLAN and deleting the VLAN afterwards, the
    fast_rx entry still holds a pointer to the VLAN's netdev, which can cause
    use-after-free bugs. Fix this by immediately calling ieee80211_check_fast_rx
    after the VLAN change.
    
    Cc: stable@vger.kernel.org
    Reported-by: ranygh@riseup.net
    Signed-off-by: Felix Fietkau <nbd@nbd.name>
    Link: https://msgid.link/20240316074336.40442-1-nbd@nbd.name
    Signed-off-by: Johannes Berg <johannes.berg@intel.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
wireguard: netlink: access device through ctx instead of peer [+ + +]
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date:   Thu Mar 14 16:49:10 2024 -0600

    wireguard: netlink: access device through ctx instead of peer
    
    [ Upstream commit 71cbd32e3db82ea4a74e3ef9aeeaa6971969c86f ]
    
    The previous commit fixed a bug that led to a NULL peer->device being
    dereferenced. It's actually easier and faster performance-wise to
    instead get the device from ctx->wg. This semantically makes more sense
    too, since ctx->wg->peer_allowedips.seq is compared with
    ctx->allowedips_seq, basing them both in ctx. This also acts as a
    defence in depth provision against freed peers.
    
    Cc: stable@vger.kernel.org
    Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
    Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

wireguard: netlink: check for dangling peer via is_dead instead of empty list [+ + +]
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date:   Thu Mar 14 16:49:09 2024 -0600

    wireguard: netlink: check for dangling peer via is_dead instead of empty list
    
    [ Upstream commit 55b6c738673871c9b0edae05d0c97995c1ff08c4 ]
    
    If all peers are removed via wg_peer_remove_all(), rather than setting
    peer_list to empty, the peer is added to a temporary list with a head on
    the stack of wg_peer_remove_all(). If a netlink dump is resumed and the
    cursored peer is one that has been removed via wg_peer_remove_all(), it
    will iterate from that peer and then attempt to dump freed peers.
    
    Fix this by instead checking peer->is_dead, which was explictly created
    for this purpose. Also move up the device_update_lock lockdep assertion,
    since reading is_dead relies on that.
    
    It can be reproduced by a small script like:
    
        echo "Setting config..."
        ip link add dev wg0 type wireguard
        wg setconf wg0 /big-config
        (
                while true; do
                        echo "Showing config..."
                        wg showconf wg0 > /dev/null
                done
        ) &
        sleep 4
        wg setconf wg0 <(printf "[Peer]\nPublicKey=$(wg genkey)\n")
    
    Resulting in:
    
        BUG: KASAN: slab-use-after-free in __lock_acquire+0x182a/0x1b20
        Read of size 8 at addr ffff88811956ec70 by task wg/59
        CPU: 2 PID: 59 Comm: wg Not tainted 6.8.0-rc2-debug+ #5
        Call Trace:
         <TASK>
         dump_stack_lvl+0x47/0x70
         print_address_description.constprop.0+0x2c/0x380
         print_report+0xab/0x250
         kasan_report+0xba/0xf0
         __lock_acquire+0x182a/0x1b20
         lock_acquire+0x191/0x4b0
         down_read+0x80/0x440
         get_peer+0x140/0xcb0
         wg_get_device_dump+0x471/0x1130
    
    Cc: stable@vger.kernel.org
    Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
    Reported-by: Lillian Berry <lillian@star-ark.net>
    Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
    Reviewed-by: Jiri Pirko <jiri@nvidia.com>
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
x86/bugs: Use sysfs_emit() [+ + +]
Author: Borislav Petkov <bp@suse.de>
Date:   Tue Aug 9 17:32:02 2022 +0200

    x86/bugs: Use sysfs_emit()
    
    commit 1d30800c0c0ae1d086ffad2bdf0ba4403370f132 upstream.
    
    Those mitigations are very talkative; use the printing helper which pays
    attention to the buffer size.
    
    Signed-off-by: Borislav Petkov <bp@suse.de>
    Link: https://lore.kernel.org/r/20220809153419.10182-1-bp@alien8.de
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
x86/coco: Export cc_vendor [+ + +]
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Sat Mar 18 12:56:33 2023 +0100

    x86/coco: Export cc_vendor
    
    commit 3d91c537296794d5d0773f61abbe7b63f2f132d8 upstream.
    
    It will be used in different checks in future changes. Export it directly
    and provide accessor functions and stubs so this can be used in general
    code when CONFIG_ARCH_HAS_CC_PLATFORM is not set.
    
    No functional changes.
    
    [ tglx: Add accessor functions ]
    
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/r/20230318115634.9392-2-bp@alien8.de
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

x86/coco: Get rid of accessor functions [+ + +]
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Mon May 8 12:44:28 2023 +0200

    x86/coco: Get rid of accessor functions
    
    commit da86eb9611840772a459693832e54c63cbcc040a upstream.
    
    cc_vendor is __ro_after_init and thus can be used directly.
    
    No functional changes.
    
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20230508121957.32341-1-bp@alien8.de
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
x86/CPU/AMD: Update the Zenbleed microcode revisions [+ + +]
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Fri Mar 15 22:42:27 2024 +0100

    x86/CPU/AMD: Update the Zenbleed microcode revisions
    
    [ Upstream commit 5c84b051bd4e777cf37aaff983277e58c99618d5 ]
    
    Update them to the correct revision numbers.
    
    Fixes: 522b1d69219d ("x86/cpu/amd: Add a Zenbleed fix")
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Cc: <stable@kernel.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
x86/cpu: Enable STIBP on AMD if Automatic IBRS is enabled [+ + +]
Author: Kim Phillips <kim.phillips@amd.com>
Date:   Thu Jul 20 14:47:27 2023 -0500

    x86/cpu: Enable STIBP on AMD if Automatic IBRS is enabled
    
    commit fd470a8beed88440b160d690344fbae05a0b9b1b upstream.
    
    Unlike Intel's Enhanced IBRS feature, AMD's Automatic IBRS does not
    provide protection to processes running at CPL3/user mode, see section
    "Extended Feature Enable Register (EFER)" in the APM v2 at
    https://bugzilla.kernel.org/attachment.cgi?id=304652
    
    Explicitly enable STIBP to protect against cross-thread CPL3
    branch target injections on systems with Automatic IBRS enabled.
    
    Also update the relevant documentation.
    
    Fixes: e7862eda309e ("x86/cpu: Support AMD Automatic IBRS")
    Reported-by: Tom Lendacky <thomas.lendacky@amd.com>
    Signed-off-by: Kim Phillips <kim.phillips@amd.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20230720194727.67022-1-kim.phillips@amd.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

x86/cpu: Support AMD Automatic IBRS [+ + +]
Author: Kim Phillips <kim.phillips@amd.com>
Date:   Tue Jan 24 10:33:18 2023 -0600

    x86/cpu: Support AMD Automatic IBRS
    
    commit e7862eda309ecfccc36bb5558d937ed3ace07f3f upstream.
    
    The AMD Zen4 core supports a new feature called Automatic IBRS.
    
    It is a "set-and-forget" feature that means that, like Intel's Enhanced IBRS,
    h/w manages its IBRS mitigation resources automatically across CPL transitions.
    
    The feature is advertised by CPUID_Fn80000021_EAX bit 8 and is enabled by
    setting MSR C000_0080 (EFER) bit 21.
    
    Enable Automatic IBRS by default if the CPU feature is present.  It typically
    provides greater performance over the incumbent generic retpolines mitigation.
    
    Reuse the SPECTRE_V2_EIBRS spectre_v2_mitigation enum.  AMD Automatic IBRS and
    Intel Enhanced IBRS have similar enablement.  Add NO_EIBRS_PBRSB to
    cpu_vuln_whitelist, since AMD Automatic IBRS isn't affected by PBRSB-eIBRS.
    
    The kernel command line option spectre_v2=eibrs is used to select AMD Automatic
    IBRS, if available.
    
    Signed-off-by: Kim Phillips <kim.phillips@amd.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Acked-by: Sean Christopherson <seanjc@google.com>
    Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
    Link: https://lore.kernel.org/r/20230124163319.2277355-8-kim.phillips@amd.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 
x86/efistub: Add missing boot_params for mixed mode compat entry [+ + +]
Author: Ard Biesheuvel <ardb@kernel.org>
Date:   Sun Mar 24 17:10:53 2024 +0100

    x86/efistub: Add missing boot_params for mixed mode compat entry
    
    commit d21f5a59ea773826cc489acb287811d690b703cc upstream.
    
    The pure EFI stub entry point does not take a struct boot_params from
    the boot loader, but creates it from scratch, and populates only the
    fields that still have meaning in this context (command line, initrd
    base and size, etc)
    
    The original mixed mode implementation used the EFI handover protocol
    instead, where the boot loader (i.e., GRUB) populates a boot_params
    struct and passes it to a special Linux specific EFI entry point that
    takes the boot_params pointer as its third argument.
    
    When the new mixed mode implementation was introduced, using a special
    32-bit PE entrypoint in the 64-bit kernel, it adopted the pure approach,
    and relied on the EFI stub to create the struct boot_params.  This is
    preferred because it makes the bootloader side much easier to implement,
    as it does not need any x86-specific knowledge on how struct boot_params
    and struct setup_header are put together. This mixed mode implementation
    was adopted by systemd-boot version 252 and later.
    
    When commit
    
      e2ab9eab324c ("x86/boot/compressed: Move 32-bit entrypoint code into .text section")
    
    refactored this code and moved it out of head_64.S, the fact that ESI
    was populated with the address of the base of the image was overlooked,
    and to simplify the code flow, ESI is now zeroed and stored to memory
    unconditionally in shared code, so that the NULL-ness of that variable
    can still be used later to determine which mixed mode boot protocol is
    in use.
    
    With ESI pointing to the base of the image, it can serve as a struct
    boot_params pointer for startup_32(), which only accesses the init_data
    and kernel_alignment fields (and the scratch field as a temporary
    stack). Zeroing ESI means that those accesses produce garbage now, even
    though things appear to work if the first page of memory happens to be
    zeroed, and the region right before LOAD_PHYSICAL_ADDR (== 16 MiB)
    happens to be free.
    
    The solution is to pass a special, temporary struct boot_params to
    startup_32() via ESI, one that is sufficient for getting it to create
    the page tables correctly and is discarded right after. This involves
    setting a minimal alignment of 4k, only to get the statically allocated
    page tables line up correctly, and setting init_size to the executable
    image size (_end - startup_32). This ensures that the page tables are
    covered by the static footprint of the PE image.
    
    Given that EFI boot no longer calls the decompressor and no longer pads
    the image to permit the decompressor to execute in place, the same
    temporary struct boot_params should be used in the EFI handover protocol
    based mixed mode implementation as well, to prevent the page tables from
    being placed outside of allocated memory.
    
    Fixes: e2ab9eab324c ("x86/boot/compressed: Move 32-bit entrypoint code into .text section")
    Cc: <stable@kernel.org> # v6.1+
    Closes: https://lore.kernel.org/all/20240321150510.GI8211@craftyguy.net/
    Reported-by: Clayton Craft <clayton@craftyguy.net>
    Tested-by: Clayton Craft <clayton@craftyguy.net>
    Tested-by: Hans de Goede <hdegoede@redhat.com>
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

x86/efistub: Call mixed mode boot services on the firmware's stack [+ + +]
Author: Ard Biesheuvel <ardb@kernel.org>
Date:   Fri Mar 22 17:03:58 2024 +0200

    x86/efistub: Call mixed mode boot services on the firmware's stack
    
    commit cefcd4fe2e3aaf792c14c9e56dab89e3d7a65d02 upstream.
    
    Normally, the EFI stub calls into the EFI boot services using the stack
    that was live when the stub was entered. According to the UEFI spec,
    this stack needs to be at least 128k in size - this might seem large but
    all asynchronous processing and event handling in EFI runs from the same
    stack and so quite a lot of space may be used in practice.
    
    In mixed mode, the situation is a bit different: the bootloader calls
    the 32-bit EFI stub entry point, which calls the decompressor's 32-bit
    entry point, where the boot stack is set up, using a fixed allocation
    of 16k. This stack is still in use when the EFI stub is started in
    64-bit mode, and so all calls back into the EFI firmware will be using
    the decompressor's limited boot stack.
    
    Due to the placement of the boot stack right after the boot heap, any
    stack overruns have gone unnoticed. However, commit
    
      5c4feadb0011983b ("x86/decompressor: Move global symbol references to C code")
    
    moved the definition of the boot heap into C code, and now the boot
    stack is placed right at the base of BSS, where any overruns will
    corrupt the end of the .data section.
    
    While it would be possible to work around this by increasing the size of
    the boot stack, doing so would affect all x86 systems, and mixed mode
    systems are a tiny (and shrinking) fraction of the x86 installed base.
    
    So instead, record the firmware stack pointer value when entering from
    the 32-bit firmware, and switch to this stack every time a EFI boot
    service call is made.
    
    Cc: <stable@kernel.org> # v6.1+
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
x86/fpu: Keep xfd_state in sync with MSR_IA32_XFD [+ + +]
Author: Adamos Ttofari <attofari@amazon.de>
Date:   Fri Mar 22 16:04:39 2024 -0700

    x86/fpu: Keep xfd_state in sync with MSR_IA32_XFD
    
    [ Upstream commit 10e4b5166df9ff7a2d5316138ca668b42d004422 ]
    
    Commit 672365477ae8 ("x86/fpu: Update XFD state where required") and
    commit 8bf26758ca96 ("x86/fpu: Add XFD state to fpstate") introduced a
    per CPU variable xfd_state to keep the MSR_IA32_XFD value cached, in
    order to avoid unnecessary writes to the MSR.
    
    On CPU hotplug MSR_IA32_XFD is reset to the init_fpstate.xfd, which
    wipes out any stale state. But the per CPU cached xfd value is not
    reset, which brings them out of sync.
    
    As a consequence a subsequent xfd_update_state() might fail to update
    the MSR which in turn can result in XRSTOR raising a #NM in kernel
    space, which crashes the kernel.
    
    To fix this, introduce xfd_set_state() to write xfd_state together
    with MSR_IA32_XFD, and use it in all places that set MSR_IA32_XFD.
    
    Fixes: 672365477ae8 ("x86/fpu: Update XFD state where required")
    Signed-off-by: Adamos Ttofari <attofari@amazon.de>
    Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/r/20240322230439.456571-1-chang.seok.bae@intel.com
    
    Closes: https://lore.kernel.org/lkml/20230511152818.13839-1-attofari@amazon.de
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
x86/Kconfig: Remove CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT [+ + +]
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Fri Feb 2 17:29:32 2024 +0100

    x86/Kconfig: Remove CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT
    
    commit 29956748339aa8757a7e2f927a8679dd08f24bb6 upstream.
    
    It was meant well at the time but nothing's using it so get rid of it.
    
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Acked-by: Ard Biesheuvel <ardb@kernel.org>
    Link: https://lore.kernel.org/r/20240202163510.GDZb0Zvj8qOndvFOiZ@fat_crate.local
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
x86/pm: Work around false positive kmemleak report in msr_build_context() [+ + +]
Author: Anton Altaparmakov <anton@tuxera.com>
Date:   Thu Mar 14 14:26:56 2024 +0000

    x86/pm: Work around false positive kmemleak report in msr_build_context()
    
    [ Upstream commit e3f269ed0accbb22aa8f25d2daffa23c3fccd407 ]
    
    Since:
    
      7ee18d677989 ("x86/power: Make restore_processor_context() sane")
    
    kmemleak reports this issue:
    
      unreferenced object 0xf68241e0 (size 32):
        comm "swapper/0", pid 1, jiffies 4294668610 (age 68.432s)
        hex dump (first 32 bytes):
          00 cc cc cc 29 10 01 c0 00 00 00 00 00 00 00 00  ....)...........
          00 42 82 f6 cc cc cc cc cc cc cc cc cc cc cc cc  .B..............
        backtrace:
          [<461c1d50>] __kmem_cache_alloc_node+0x106/0x260
          [<ea65e13b>] __kmalloc+0x54/0x160
          [<c3858cd2>] msr_build_context.constprop.0+0x35/0x100
          [<46635aff>] pm_check_save_msr+0x63/0x80
          [<6b6bb938>] do_one_initcall+0x41/0x1f0
          [<3f3add60>] kernel_init_freeable+0x199/0x1e8
          [<3b538fde>] kernel_init+0x1a/0x110
          [<938ae2b2>] ret_from_fork+0x1c/0x28
    
    Which is a false positive.
    
    Reproducer:
    
      - Run rsync of whole kernel tree (multiple times if needed).
      - start a kmemleak scan
      - Note this is just an example: a lot of our internal tests hit these.
    
    The root cause is similar to the fix in:
    
      b0b592cf0836 x86/pm: Fix false positive kmemleak report in msr_build_context()
    
    ie. the alignment within the packed struct saved_context
    which has everything unaligned as there is only "u16 gs;" at start of
    struct where in the past there were four u16 there thus aligning
    everything afterwards.  The issue is with the fact that Kmemleak only
    searches for pointers that are aligned (see how pointers are scanned in
    kmemleak.c) so when the struct members are not aligned it doesn't see
    them.
    
    Testing:
    
    We run a lot of tests with our CI, and after applying this fix we do not
    see any kmemleak issues any more whilst without it we see hundreds of
    the above report. From a single, simple test run consisting of 416 individual test
    cases on kernel 5.10 x86 with kmemleak enabled we got 20 failures due to this,
    which is quite a lot. With this fix applied we get zero kmemleak related failures.
    
    Fixes: 7ee18d677989 ("x86/power: Make restore_processor_context() sane")
    Signed-off-by: Anton Altaparmakov <anton@tuxera.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Acked-by: "Rafael J. Wysocki" <rafael@kernel.org>
    Cc: stable@vger.kernel.org
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Link: https://lore.kernel.org/r/20240314142656.17699-1-anton@tuxera.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>

 
x86/sev: Fix position dependent variable references in startup code [+ + +]
Author: Ard Biesheuvel <ardb@kernel.org>
Date:   Sat Feb 3 13:53:06 2024 +0100

    x86/sev: Fix position dependent variable references in startup code
    
    commit 1c811d403afd73f04bde82b83b24c754011bd0e8 upstream.
    
    The early startup code executes from a 1:1 mapping of memory, which
    differs from the mapping that the code was linked and/or relocated to
    run at. The latter mapping is not active yet at this point, and so
    symbol references that rely on it will fault.
    
    Given that the core kernel is built without -fPIC, symbol references are
    typically emitted as absolute, and so any such references occuring in
    the early startup code will therefore crash the kernel.
    
    While an attempt was made to work around this for the early SEV/SME
    startup code, by forcing RIP-relative addressing for certain global
    SEV/SME variables via inline assembly (see snp_cpuid_get_table() for
    example), RIP-relative addressing must be pervasively enforced for
    SEV/SME global variables when accessed prior to page table fixups.
    
    __startup_64() already handles this issue for select non-SEV/SME global
    variables using fixup_pointer(), which adjusts the pointer relative to a
    `physaddr` argument. To avoid having to pass around this `physaddr`
    argument across all functions needing to apply pointer fixups, introduce
    a macro RIP_RELATIVE_REF() which generates a RIP-relative reference to
    a given global variable. It is used where necessary to force
    RIP-relative accesses to global variables.
    
    For backporting purposes, this patch makes no attempt at cleaning up
    other occurrences of this pattern, involving either inline asm or
    fixup_pointer(). Those will be addressed later.
    
      [ bp: Call it "rip_rel_ref" everywhere like other code shortens
        "rIP-relative reference" and make the asm wrapper __always_inline. ]
    
    Co-developed-by: Kevin Loughlin <kevinloughlin@google.com>
    Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Cc: <stable@kernel.org>
    Link: https://lore.kernel.org/all/20240130220845.1978329-1-kevinloughlin@google.com
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

x86/sev: Skip ROM range scans and validation for SEV-SNP guests [+ + +]
Author: Kevin Loughlin <kevinloughlin@google.com>
Date:   Wed Mar 13 12:15:46 2024 +0000

    x86/sev: Skip ROM range scans and validation for SEV-SNP guests
    
    commit 0f4a1e80989aca185d955fcd791d7750082044a2 upstream.
    
    SEV-SNP requires encrypted memory to be validated before access.
    Because the ROM memory range is not part of the e820 table, it is not
    pre-validated by the BIOS. Therefore, if a SEV-SNP guest kernel wishes
    to access this range, the guest must first validate the range.
    
    The current SEV-SNP code does indeed scan the ROM range during early
    boot and thus attempts to validate the ROM range in probe_roms().
    However, this behavior is neither sufficient nor necessary for the
    following reasons:
    
    * With regards to sufficiency, if EFI_CONFIG_TABLES are not enabled and
      CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK is set, the kernel will
      attempt to access the memory at SMBIOS_ENTRY_POINT_SCAN_START (which
      falls in the ROM range) prior to validation.
    
      For example, Project Oak Stage 0 provides a minimal guest firmware
      that currently meets these configuration conditions, meaning guests
      booting atop Oak Stage 0 firmware encounter a problematic call chain
      during dmi_setup() -> dmi_scan_machine() that results in a crash
      during boot if SEV-SNP is enabled.
    
    * With regards to necessity, SEV-SNP guests generally read garbage
      (which changes across boots) from the ROM range, meaning these scans
      are unnecessary. The guest reads garbage because the legacy ROM range
      is unencrypted data but is accessed via an encrypted PMD during early
      boot (where the PMD is marked as encrypted due to potentially mapping
      actually-encrypted data in other PMD-contained ranges).
    
    In one exceptional case, EISA probing treats the ROM range as
    unencrypted data, which is inconsistent with other probing.
    
    Continuing to allow SEV-SNP guests to use garbage and to inconsistently
    classify ROM range encryption status can trigger undesirable behavior.
    For instance, if garbage bytes appear to be a valid signature, memory
    may be unnecessarily reserved for the ROM range. Future code or other
    use cases may result in more problematic (arbitrary) behavior that
    should be avoided.
    
    While one solution would be to overhaul the early PMD mapping to always
    treat the ROM region of the PMD as unencrypted, SEV-SNP guests do not
    currently rely on data from the ROM region during early boot (and even
    if they did, they would be mostly relying on garbage data anyways).
    
    As a simpler solution, skip the ROM range scans (and the otherwise-
    necessary range validation) during SEV-SNP guest early boot. The
    potential SEV-SNP guest crash due to lack of ROM range validation is
    thus avoided by simply not accessing the ROM range.
    
    In most cases, skip the scans by overriding problematic x86_init
    functions during sme_early_init() to SNP-safe variants, which can be
    likened to x86_init overrides done for other platforms (ex: Xen); such
    overrides also avoid the spread of cc_platform_has() checks throughout
    the tree.
    
    In the exceptional EISA case, still use cc_platform_has() for the
    simplest change, given (1) checks for guest type (ex: Xen domain status)
    are already performed here, and (2) these checks occur in a subsys
    initcall instead of an x86_init function.
    
      [ bp: Massage commit message, remove "we"s. ]
    
    Fixes: 9704c07bf9f7 ("x86/kernel: Validate ROM memory before accessing when SEV-SNP is active")
    Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Cc: <stable@kernel.org>
    Link: https://lore.kernel.org/r/20240313121546.2964854-1-kevinloughlin@google.com
    Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 
xfrm: Avoid clang fortify warning in copy_to_user_tmpl() [+ + +]
Author: Nathan Chancellor <nathan@kernel.org>
Date:   Wed Feb 21 14:46:21 2024 -0700

    xfrm: Avoid clang fortify warning in copy_to_user_tmpl()
    
    commit 1a807e46aa93ebad1dfbed4f82dc3bf779423a6e upstream.
    
    After a couple recent changes in LLVM, there is a warning (or error with
    CONFIG_WERROR=y or W=e) from the compile time fortify source routines,
    specifically the memset() in copy_to_user_tmpl().
    
      In file included from net/xfrm/xfrm_user.c:14:
      ...
      include/linux/fortify-string.h:438:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
        438 |                         __write_overflow_field(p_size_field, size);
            |                         ^
      1 error generated.
    
    While ->xfrm_nr has been validated against XFRM_MAX_DEPTH when its value
    is first assigned in copy_templates() by calling validate_tmpl() first
    (so there should not be any issue in practice), LLVM/clang cannot really
    deduce that across the boundaries of these functions. Without that
    knowledge, it cannot assume that the loop stops before i is greater than
    XFRM_MAX_DEPTH, which would indeed result a stack buffer overflow in the
    memset().
    
    To make the bounds of ->xfrm_nr clear to the compiler and add additional
    defense in case copy_to_user_tmpl() is ever used in a path where
    ->xfrm_nr has not been properly validated against XFRM_MAX_DEPTH first,
    add an explicit bound check and early return, which clears up the
    warning.
    
    Cc: stable@vger.kernel.org
    Link: https://github.com/ClangBuiltLinux/linux/issues/1985
    Signed-off-by: Nathan Chancellor <nathan@kernel.org>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>