Skip to content
  1. Feb 02, 2022
    • Christophe Leroy's avatar
      powerpc/32: Fix boot failure with GCC latent entropy plugin · c894d2f9
      Christophe Leroy authored
      commit bba49665 upstream.
      
      Boot fails with GCC latent entropy plugin enabled.
      
      This is due to early boot functions trying to access 'latent_entropy'
      global data while the kernel is not relocated at its final
      destination yet.
      
      As there is no way to tell GCC to use PTRRELOC() to access it,
      disable latent entropy plugin in early_32.o and feature-fixups.o and
      code-patching.o
      
      Fixes: 38addce8
      
       ("gcc-plugins: Add latent_entropy plugin")
      Cc: stable@vger.kernel.org # v4.9+
      Reported-by: default avatarErhard Furtner <erhard_f@mailbox.org>
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=215217
      Link: https://lore.kernel.org/r/2bac55483b8daf5b1caa163a45fa5f9cdbe18be4.1640178426.git.christophe.leroy@csgroup.eu
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c894d2f9
    • Christophe Leroy's avatar
      powerpc/32s: Fix kasan_init_region() for KASAN · db37befa
      Christophe Leroy authored
      commit d37823c3 upstream.
      
      It has been reported some configuration where the kernel doesn't
      boot with KASAN enabled.
      
      This is due to wrong BAT allocation for the KASAN area:
      
      	---[ Data Block Address Translation ]---
      	0: 0xc0000000-0xcfffffff 0x00000000       256M Kernel rw      m
      	1: 0xd0000000-0xdfffffff 0x10000000       256M Kernel rw      m
      	2: 0xe0000000-0xefffffff 0x20000000       256M Kernel rw      m
      	3: 0xf8000000-0xf9ffffff 0x2a000000        32M Kernel rw      m
      	4: 0xfa000000-0xfdffffff 0x2c000000        64M Kernel rw      m
      
      A BAT must have both virtual and physical addresses alignment matching
      the size of the BAT. This is not the case for BAT 4 above.
      
      Fix kasan_init_region() by using block_size() function that is in
      book3s32/mmu.c. To be able to reuse it here, make it non static and
      change its name to bat_block_size() in order to avoid name conflict
      with block_size() defined in <linux/blkdev.h>
      
      Also reuse find_free_bat() to avoid an error message from setbat()
      when no BAT is available.
      
      And allocate memory outside of linear memory mapping to avoid
      wasting that precious space.
      
      With this change we get correct alignment for BATs and KASAN shadow
      memory is allocated outside the linear memory space.
      
      	---[ Data Block Address Translation ]---
      	0: 0xc0000000-0xcfffffff 0x00000000       256M Kernel rw
      	1: 0xd0000000-0xdfffffff 0x10000000       256M Kernel rw
      	2: 0xe0000000-0xefffffff 0x20000000       256M Kernel rw
      	3: 0xf8000000-0xfbffffff 0x7c000000        64M Kernel rw
      	4: 0xfc000000-0xfdffffff 0x7a000000        32M Kernel rw
      
      Fixes: 7974c473
      
       ("powerpc/32s: Implement dedicated kasan_init_region()")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarMaxime Bizon <mbizon@freebox.fr>
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Tested-by: default avatarMaxime Bizon <mbizon@freebox.fr>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/7a50ef902494d1325227d47d33dada01e52e5518.1641818726.git.christophe.leroy@csgroup.eu
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      db37befa
    • Christophe Leroy's avatar
      powerpc/32s: Allocate one 256k IBAT instead of two consecutives 128k IBATs · 569c81c0
      Christophe Leroy authored
      commit 37eb7ca9
      
       upstream.
      
      Today we have the following IBATs allocated:
      
      	---[ Instruction Block Address Translation ]---
      	0: 0xc0000000-0xc03fffff 0x00000000         4M Kernel   x     m
      	1: 0xc0400000-0xc05fffff 0x00400000         2M Kernel   x     m
      	2: 0xc0600000-0xc06fffff 0x00600000         1M Kernel   x     m
      	3: 0xc0700000-0xc077ffff 0x00700000       512K Kernel   x     m
      	4: 0xc0780000-0xc079ffff 0x00780000       128K Kernel   x     m
      	5: 0xc07a0000-0xc07bffff 0x007a0000       128K Kernel   x     m
      	6:         -
      	7:         -
      
      The two 128K should be a single 256K instead.
      
      When _etext is not aligned to 128Kbytes, the system will allocate
      all necessary BATs to the lower 128Kbytes boundary, then allocate
      an additional 128Kbytes BAT for the remaining block.
      
      Instead, align the top to 128Kbytes so that the function directly
      allocates a 256Kbytes last block:
      
      	---[ Instruction Block Address Translation ]---
      	0: 0xc0000000-0xc03fffff 0x00000000         4M Kernel   x     m
      	1: 0xc0400000-0xc05fffff 0x00400000         2M Kernel   x     m
      	2: 0xc0600000-0xc06fffff 0x00600000         1M Kernel   x     m
      	3: 0xc0700000-0xc077ffff 0x00700000       512K Kernel   x     m
      	4: 0xc0780000-0xc07bffff 0x00780000       256K Kernel   x     m
      	5:         -
      	6:         -
      	7:         -
      
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/ab58b296832b0ec650e2203200e060adbcb2677d.1637930421.git.christophe.leroy@csgroup.eu
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      569c81c0
    • Tony Luck's avatar
      x86/cpu: Add Xeon Icelake-D to list of CPUs that support PPIN · 190753f6
      Tony Luck authored
      commit e464121f upstream.
      
      Missed adding the Icelake-D CPU to the list. It uses the same MSRs
      to control and read the inventory number as all the other models.
      
      Fixes: dc6b025d
      
       ("x86/mce: Add Xeon Icelake to list of CPUs that support PPIN")
      Reported-by: default avatarAilin Xu <ailin.xu@intel.com>
      Signed-off-by: default avatarTony Luck <tony.luck@intel.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20220121174743.1875294-2-tony.luck@intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      190753f6
    • Yazen Ghannam's avatar
      x86/MCE/AMD: Allow thresholding interface updates after init · 98ccfec9
      Yazen Ghannam authored
      commit 1f52b0ab upstream.
      
      Changes to the AMD Thresholding sysfs code prevents sysfs writes from
      updating the underlying registers once CPU init is completed, i.e.
      "threshold_banks" is set.
      
      Allow the registers to be updated if the thresholding interface is
      already initialized or if in the init path. Use the "set_lvt_off" value
      to indicate if running in the init path, since this value is only set
      during init.
      
      Fixes: a037f3ca
      
       ("x86/mce/amd: Make threshold bank setting hotplug robust")
      Signed-off-by: default avatarYazen Ghannam <yazen.ghannam@amd.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20220117161328.19148-1-yazen.ghannam@amd.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      98ccfec9
    • Bjorn Helgaas's avatar
      PCI/sysfs: Find shadow ROM before static attribute initialization · 74e88ece
      Bjorn Helgaas authored
      commit 66d28b21 upstream.
      
      Ville reported that the sysfs "rom" file for VGA devices disappeared after
      527139d7 ("PCI/sysfs: Convert "rom" to static attribute").
      
      Prior to 527139d7, FINAL fixups, including pci_fixup_video() where we
      find shadow ROMs, were run before pci_create_sysfs_dev_files() created the
      sysfs "rom" file.
      
      After 527139d7, "rom" is a static attribute and is created before FINAL
      fixups are run, so we didn't create "rom" files for shadow ROMs:
      
        acpi_pci_root_add
          ...
            pci_scan_single_device
              pci_device_add
                pci_fixup_video                    # <-- new HEADER fixup
                device_add
                  ...
                    if (grp->is_visible())
                      pci_dev_rom_attr_is_visible  # after 527139d7
          pci_bus_add_devices
            pci_bus_add_device
              pci_fixup_device(pci_fixup_final)
                pci_fixup_video                    # <-- previous FINAL fixup
              pci_create_sysfs_dev_files
                if (pci_resource_len(pdev, PCI_ROM_RESOURCE))
                  sysfs_create_bin_file("rom")     # before 527139d7
      
      Change pci_fixup_video() to be a HEADER fixup so it runs before sysfs
      static attributes are initialized.
      
      Rename the Loongson pci_fixup_radeon() to pci_fixup_video() and make its
      dmesg logging identical to the others since it is doing the same job.
      
      Link: https://lore.kernel.org/r/YbxqIyrkv3GhZVxx@intel.com
      Fixes: 527139d7
      
       ("PCI/sysfs: Convert "rom" to static attribute")
      Link: https://lore.kernel.org/r/20220126154001.16895-1-helgaas@kernel.org
      Reported-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
      Tested-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Cc: stable@vger.kernel.org			# v5.13+
      Cc: Huacai Chen <chenhuacai@kernel.org>
      Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
      Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Krzysztof Wilczyński <kw@linux.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      74e88ece
    • Mathieu Desnoyers's avatar
      sched/membarrier: Fix membarrier-rseq fence command missing from query bitmask · cef9335c
      Mathieu Desnoyers authored
      commit 80923261 upstream.
      
      The membarrier command MEMBARRIER_CMD_QUERY allows querying the
      available membarrier commands. When the membarrier-rseq fence commands
      were added, a new MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ_BITMASK was
      introduced with the intent to expose them with the MEMBARRIER_CMD_QUERY
      command, the but it was never added to MEMBARRIER_CMD_BITMASK.
      
      The membarrier-rseq fence commands are therefore not wired up with the
      query command.
      
      Rename MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ_BITMASK to
      MEMBARRIER_PRIVATE_EXPEDITED_RSEQ_BITMASK (the bitmask is not a command
      per-se), and change the erroneous
      MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ_BITMASK (which does not
      actually exist) to MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ.
      
      Wire up MEMBARRIER_PRIVATE_EXPEDITED_RSEQ_BITMASK in
      MEMBARRIER_CMD_BITMASK. Fixing this allows discovering availability of
      the membarrier-rseq fence feature.
      
      Fixes: 2a36ab71
      
       ("rseq/membarrier: Add MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ")
      Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: <stable@vger.kernel.org> # 5.10+
      Link: https://lkml.kernel.org/r/20220117203010.30129-1-mathieu.desnoyers@efficios.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cef9335c
    • Joseph Qi's avatar
      ocfs2: fix a deadlock when commit trans · 61296272
      Joseph Qi authored
      commit ddf4b773 upstream.
      
      commit 6f1b2285 introduces a regression which can deadlock as
      follows:
      
        Task1:                              Task2:
        jbd2_journal_commit_transaction     ocfs2_test_bg_bit_allocatable
        spin_lock(&jh->b_state_lock)        jbd_lock_bh_journal_head
        __jbd2_journal_remove_checkpoint    spin_lock(&jh->b_state_lock)
        jbd2_journal_put_journal_head
        jbd_lock_bh_journal_head
      
      Task1 and Task2 lock bh->b_state and jh->b_state_lock in different
      order, which finally result in a deadlock.
      
      So use jbd2_journal_[grab|put]_journal_head instead in
      ocfs2_test_bg_bit_allocatable() to fix it.
      
      Link: https://lkml.kernel.org/r/20220121071205.100648-3-joseph.qi@linux.alibaba.com
      Fixes: 6f1b2285
      
       ("ocfs2: fix race between searching chunks and release journal_head from buffer_head")
      Signed-off-by: default avatarJoseph Qi <joseph.qi@linux.alibaba.com>
      Reported-by: default avatarGautham Ananthakrishna <gautham.ananthakrishna@oracle.com>
      Tested-by: default avatarGautham Ananthakrishna <gautham.ananthakrishna@oracle.com>
      Reported-by: default avatarSaeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
      Cc: "Theodore Ts'o" <tytso@mit.edu>
      Cc: Andreas Dilger <adilger.kernel@dilger.ca>
      Cc: Changwei Ge <gechangwei@live.cn>
      Cc: Gang He <ghe@suse.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Jun Piao <piaojun@huawei.com>
      Cc: Junxiao Bi <junxiao.bi@oracle.com>
      Cc: Mark Fasheh <mark@fasheh.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      61296272
    • Joseph Qi's avatar
      jbd2: export jbd2_journal_[grab|put]_journal_head · 9f71d68f
      Joseph Qi authored
      commit 4cd1103d
      
       upstream.
      
      Patch series "ocfs2: fix a deadlock case".
      
      This fixes a deadlock case in ocfs2.  We firstly export jbd2 symbols
      jbd2_journal_[grab|put]_journal_head as preparation and later use them
      in ocfs2 insread of jbd_[lock|unlock]_bh_journal_head to fix the
      deadlock.
      
      This patch (of 2):
      
      This exports symbols jbd2_journal_[grab|put]_journal_head, which will be
      used outside modules, e.g.  ocfs2.
      
      Link: https://lkml.kernel.org/r/20220121071205.100648-2-joseph.qi@linux.alibaba.com
      Signed-off-by: default avatarJoseph Qi <joseph.qi@linux.alibaba.com>
      Cc: Mark Fasheh <mark@fasheh.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Junxiao Bi <junxiao.bi@oracle.com>
      Cc: Changwei Ge <gechangwei@live.cn>
      Cc: Gang He <ghe@suse.com>
      Cc: Jun Piao <piaojun@huawei.com>
      Cc: Andreas Dilger <adilger.kernel@dilger.ca>
      Cc: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>
      Cc: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
      Cc: "Theodore Ts'o" <tytso@mit.edu>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9f71d68f
    • Peter Collingbourne's avatar
      mm, kasan: use compare-exchange operation to set KASAN page tag · 4ca8a0bc
      Peter Collingbourne authored
      commit 27fe7339 upstream.
      
      It has been reported that the tag setting operation on newly-allocated
      pages can cause the page flags to be corrupted when performed
      concurrently with other flag updates as a result of the use of
      non-atomic operations.
      
      Fix the problem by using a compare-exchange loop to update the tag.
      
      Link: https://lkml.kernel.org/r/20220120020148.1632253-1-pcc@google.com
      Link: https://linux-review.googlesource.com/id/I456b24a2b9067d93968d43b4bb3351c0cec63101
      Fixes: 2813b9c0
      
       ("kasan, mm, arm64: tag non slab memory allocated via pagealloc")
      Signed-off-by: default avatarPeter Collingbourne <pcc@google.com>
      Reviewed-by: default avatarAndrey Konovalov <andreyknvl@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4ca8a0bc
    • Sing-Han Chen's avatar
      ucsi_ccg: Check DEV_INT bit only when starting CCG4 · 28b34657
      Sing-Han Chen authored
      commit 82591149 upstream.
      
      CCGx clears Bit 0:Device Interrupt in the INTR_REG
      if CCGx is reset successfully. However, there might
      be a chance that other bits in INTR_REG are not
      cleared due to internal data queued in PPM. This case
      misleads the driver that CCGx reset failed.
      
      The commit checks bit 0 in INTR_REG and ignores other
      bits. The ucsi driver would reset PPM later.
      
      Fixes: 247c554a
      
       ("usb: typec: ucsi: add support for Cypress CCGx")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Signed-off-by: default avatarSing-Han Chen <singhanc@nvidia.com>
      Signed-off-by: default avatarWayne Chang <waynec@nvidia.com>
      Link: https://lore.kernel.org/r/20220112094143.628610-1-waynec@nvidia.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      28b34657
    • Badhri Jagan Sridharan's avatar
      usb: typec: tcpm: Do not disconnect when receiving VSAFE0V · 3cdaeb85
      Badhri Jagan Sridharan authored
      commit 746f96e7 upstream.
      
      With some chargers, vbus might momentarily raise above VSAFE5V and fall
      back to 0V causing VSAFE0V to be triggered. This will
      will report a VBUS off event causing TCPM to transition to
      SNK_UNATTACHED state where it should be waiting in either SNK_ATTACH_WAIT
      or SNK_DEBOUNCED state. This patch makes TCPM avoid VSAFE0V events
      while in SNK_ATTACH_WAIT or SNK_DEBOUNCED state.
      
      Stub from the spec:
          "4.5.2.2.4.2 Exiting from AttachWait.SNK State
          A Sink shall transition to Unattached.SNK when the state of both
          the CC1 and CC2 pins is SNK.Open for at least tPDDebounce.
          A DRP shall transition to Unattached.SRC when the state of both
          the CC1 and CC2 pins is SNK.Open for at least tPDDebounce."
      
      [23.194131] CC1: 0 -> 0, CC2: 0 -> 5 [state SNK_UNATTACHED, polarity 0, connected]
      [23.201777] state change SNK_UNATTACHED -> SNK_ATTACH_WAIT [rev3 NONE_AMS]
      [23.209949] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 170 ms [rev3 NONE_AMS]
      [23.300579] VBUS off
      [23.300668] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [rev3 NONE_AMS]
      [23.301014] VBUS VSAFE0V
      [23.301111] Start toggling
      
      Fixes: 28b43d3d
      
       ("usb: typec: tcpm: Introduce vsafe0v for vbus")
      Cc: stable@vger.kernel.org
      Acked-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Signed-off-by: default avatarBadhri Jagan Sridharan <badhri@google.com>
      Link: https://lore.kernel.org/r/20220122015520.332507-2-badhri@google.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3cdaeb85
    • Badhri Jagan Sridharan's avatar
      usb: typec: tcpm: Do not disconnect while receiving VBUS off · 6b71fad7
      Badhri Jagan Sridharan authored
      commit 90b8aa9f upstream.
      
      With some chargers, vbus might momentarily raise above VSAFE5V and fall
      back to 0V before tcpm gets to read port->tcpc->get_vbus. This will
      will report a VBUS off event causing TCPM to transition to
      SNK_UNATTACHED where it should be waiting in either SNK_ATTACH_WAIT
      or SNK_DEBOUNCED state. This patch makes TCPM avoid vbus off events
      while in SNK_ATTACH_WAIT or SNK_DEBOUNCED state.
      
      Stub from the spec:
          "4.5.2.2.4.2 Exiting from AttachWait.SNK State
          A Sink shall transition to Unattached.SNK when the state of both
          the CC1 and CC2 pins is SNK.Open for at least tPDDebounce.
          A DRP shall transition to Unattached.SRC when the state of both
          the CC1 and CC2 pins is SNK.Open for at least tPDDebounce."
      
      [23.194131] CC1: 0 -> 0, CC2: 0 -> 5 [state SNK_UNATTACHED, polarity 0, connected]
      [23.201777] state change SNK_UNATTACHED -> SNK_ATTACH_WAIT [rev3 NONE_AMS]
      [23.209949] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 170 ms [rev3 NONE_AMS]
      [23.300579] VBUS off
      [23.300668] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [rev3 NONE_AMS]
      [23.301014] VBUS VSAFE0V
      [23.301111] Start toggling
      
      Fixes: f0690a25
      
       ("staging: typec: USB Type-C Port Manager (tcpm)")
      Cc: stable@vger.kernel.org
      Acked-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Signed-off-by: default avatarBadhri Jagan Sridharan <badhri@google.com>
      Link: https://lore.kernel.org/r/20220122015520.332507-1-badhri@google.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6b71fad7
    • Xu Yang's avatar
      usb: typec: tcpci: don't touch CC line if it's Vconn source · a1399fe6
      Xu Yang authored
      commit 5638b0df upstream.
      
      With the AMS and Collision Avoidance, tcpm often needs to change the CC's
      termination. When one CC line is sourcing Vconn, if we still change its
      termination, the voltage of the another CC line is likely to be fluctuant
      and unstable.
      
      Therefore, we should verify whether a CC line is sourcing Vconn before
      changing its termination and only change the termination that is not
      a Vconn line. This can be done by reading the Vconn Present bit of
      POWER_ STATUS register. To determine the polarity, we can read the
      Plug Orientation bit of TCPC_CONTROL register. Since Vconn can only be
      sourced if Plug Orientation is set.
      
      Fixes: 0908c5ac
      
       ("usb: typec: tcpm: AMS and Collision Avoidance")
      cc: <stable@vger.kernel.org>
      Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Acked-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Signed-off-by: default avatarXu Yang <xu.yang_2@nxp.com>
      Link: https://lore.kernel.org/r/20220113092943.752372-1-xu.yang_2@nxp.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a1399fe6
    • Alan Stern's avatar
      USB: core: Fix hang in usb_kill_urb by adding memory barriers · 93402263
      Alan Stern authored
      commit 26fbe977
      
       upstream.
      
      The syzbot fuzzer has identified a bug in which processes hang waiting
      for usb_kill_urb() to return.  It turns out the issue is not unlinking
      the URB; that works just fine.  Rather, the problem arises when the
      wakeup notification that the URB has completed is not received.
      
      The reason is memory-access ordering on SMP systems.  In outline form,
      usb_kill_urb() and __usb_hcd_giveback_urb() operating concurrently on
      different CPUs perform the following actions:
      
      CPU 0					CPU 1
      ----------------------------		---------------------------------
      usb_kill_urb():				__usb_hcd_giveback_urb():
        ...					  ...
        atomic_inc(&urb->reject);		  atomic_dec(&urb->use_count);
        ...					  ...
        wait_event(usb_kill_urb_queue,
      	atomic_read(&urb->use_count) == 0);
      					  if (atomic_read(&urb->reject))
      						wake_up(&usb_kill_urb_queue);
      
      Confining your attention to urb->reject and urb->use_count, you can
      see that the overall pattern of accesses on CPU 0 is:
      
      	write urb->reject, then read urb->use_count;
      
      whereas the overall pattern of accesses on CPU 1 is:
      
      	write urb->use_count, then read urb->reject.
      
      This pattern is referred to in memory-model circles as SB (for "Store
      Buffering"), and it is well known that without suitable enforcement of
      the desired order of accesses -- in the form of memory barriers -- it
      is entirely possible for one or both CPUs to execute their reads ahead
      of their writes.  The end result will be that sometimes CPU 0 sees the
      old un-decremented value of urb->use_count while CPU 1 sees the old
      un-incremented value of urb->reject.  Consequently CPU 0 ends up on
      the wait queue and never gets woken up, leading to the observed hang
      in usb_kill_urb().
      
      The same pattern of accesses occurs in usb_poison_urb() and the
      failure pathway of usb_hcd_submit_urb().
      
      The problem is fixed by adding suitable memory barriers.  To provide
      proper memory-access ordering in the SB pattern, a full barrier is
      required on both CPUs.  The atomic_inc() and atomic_dec() accesses
      themselves don't provide any memory ordering, but since they are
      present, we can use the optimized smp_mb__after_atomic() memory
      barrier in the various routines to obtain the desired effect.
      
      This patch adds the necessary memory barriers.
      
      CC: <stable@vger.kernel.org>
      Reported-and-tested-by: default avatar <syzbot+76629376e06e2c2ad626@syzkaller.appspotmail.com>
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Link: https://lore.kernel.org/r/Ye8K0QYee0Q0Nna2@rowland.harvard.edu
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      93402263
    • Robert Hancock's avatar
      usb: dwc3: xilinx: Fix error handling when getting USB3 PHY · 1cd3a861
      Robert Hancock authored
      commit 2cc9b1c9 upstream.
      
      The code that looked up the USB3 PHY was ignoring all errors other than
      EPROBE_DEFER in an attempt to handle the PHY not being present. Fix and
      simplify the code by using devm_phy_optional_get and dev_err_probe so
      that a missing PHY is not treated as an error and unexpected errors
      are handled properly.
      
      Fixes: 84770f02
      
       ("usb: dwc3: Add driver for Xilinx platforms")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarRobert Hancock <robert.hancock@calian.com>
      Link: https://lore.kernel.org/r/20220126000253.1586760-3-robert.hancock@calian.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1cd3a861
    • Robert Hancock's avatar
      usb: dwc3: xilinx: Skip resets and USB3 register settings for USB2.0 mode · 72d338bc
      Robert Hancock authored
      commit 9678f336 upstream.
      
      It appears that the PIPE clock should not be selected when only USB 2.0
      is being used in the design and no USB 3.0 reference clock is used.
      Also, the core resets are not required if a USB3 PHY is not in use, and
      will break things if USB3 is actually used but the PHY entry is not
      listed in the device tree.
      
      Skip core resets and register settings that are only required for
      USB3 mode when no USB3 PHY is specified in the device tree.
      
      Fixes: 84770f02
      
       ("usb: dwc3: Add driver for Xilinx platforms")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarRobert Hancock <robert.hancock@calian.com>
      Link: https://lore.kernel.org/r/20220126000253.1586760-2-robert.hancock@calian.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      72d338bc
    • Pawel Laszczak's avatar
      usb: cdnsp: Fix segmentation fault in cdns_lost_power function · 897d462d
      Pawel Laszczak authored
      commit 79aa3e19 upstream.
      
      CDNSP driver read not initialized cdns->otg_v0_regs
      which lead to segmentation fault. Patch fixes this issue.
      
      Fixes: 2cf2581c
      
       ("usb: cdns3: add power lost support for system resume")
      cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarPawel Laszczak <pawell@cadence.com>
      Link: https://lore.kernel.org/r/20220111090737.10345-1-pawell@gli-login.cadence.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      897d462d
    • Pavankumar Kondeti's avatar
      usb: gadget: f_sourcesink: Fix isoc transfer for USB_SPEED_SUPER_PLUS · 27980463
      Pavankumar Kondeti authored
      commit 904edf8a upstream.
      
      Currently when gadget enumerates in super speed plus, the isoc
      endpoint request buffer size is not calculated correctly. Fix
      this by checking the gadget speed against USB_SPEED_SUPER_PLUS
      and update the request buffer size.
      
      Fixes: 90c4d057
      
       ("usb: fix various gadgets null ptr deref on 10gbps cabling.")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarPavankumar Kondeti <quic_pkondeti@quicinc.com>
      Link: https://lore.kernel.org/r/1642820602-20619-1-git-send-email-quic_pkondeti@quicinc.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      27980463
    • Jon Hunter's avatar
      usb: common: ulpi: Fix crash in ulpi_match() · 42865e55
      Jon Hunter authored
      commit 2e3dd4a6 upstream.
      
      Commit 7495af93 ("ARM: multi_v7_defconfig: Enable drivers for
      DragonBoard 410c") enables the CONFIG_PHY_QCOM_USB_HS for the ARM
      multi_v7_defconfig. Enabling this Kconfig is causing the kernel to crash
      on the Tegra20 Ventana platform in the ulpi_match() function.
      
      The Qualcomm USB HS PHY driver that is enabled by CONFIG_PHY_QCOM_USB_HS,
      registers a ulpi_driver but this driver does not provide an 'id_table',
      so when ulpi_match() is called on the Tegra20 Ventana platform, it
      crashes when attempting to deference the id_table pointer which is not
      valid. The Qualcomm USB HS PHY driver uses device-tree for matching the
      ULPI driver with the device and so fix this crash by using device-tree
      for matching if the id_table is not valid.
      
      Fixes: ef6a7bcf
      
       ("usb: ulpi: Support device discovery via DT")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Link: https://lore.kernel.org/r/20220117150039.44058-1-jonathanh@nvidia.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      42865e55
    • Frank Li's avatar
      usb: xhci-plat: fix crash when suspend if remote wake enable · d5755832
      Frank Li authored
      commit 9df47846 upstream.
      
      Crashed at i.mx8qm platform when suspend if enable remote wakeup
      
      Internal error: synchronous external abort: 96000210 [#1] PREEMPT SMP
      Modules linked in:
      CPU: 2 PID: 244 Comm: kworker/u12:6 Not tainted 5.15.5-dirty #12
      Hardware name: Freescale i.MX8QM MEK (DT)
      Workqueue: events_unbound async_run_entry_fn
      pstate: 600000c5 (nZCv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
      pc : xhci_disable_hub_port_wake.isra.62+0x60/0xf8
      lr : xhci_disable_hub_port_wake.isra.62+0x34/0xf8
      sp : ffff80001394bbf0
      x29: ffff80001394bbf0 x28: 0000000000000000 x27: ffff00081193b578
      x26: ffff00081193b570 x25: 0000000000000000 x24: 0000000000000000
      x23: ffff00081193a29c x22: 0000000000020001 x21: 0000000000000001
      x20: 0000000000000000 x19: ffff800014e90490 x18: 0000000000000000
      x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000
      x14: 0000000000000000 x13: 0000000000000002 x12: 0000000000000000
      x11: 0000000000000000 x10: 0000000000000960 x9 : ffff80001394baa0
      x8 : ffff0008145d1780 x7 : ffff0008f95b8e80 x6 : 000000001853b453
      x5 : 0000000000000496 x4 : 0000000000000000 x3 : ffff00081193a29c
      x2 : 0000000000000001 x1 : 0000000000000000 x0 : ffff000814591620
      Call trace:
       xhci_disable_hub_port_wake.isra.62+0x60/0xf8
       xhci_suspend+0x58/0x510
       xhci_plat_suspend+0x50/0x78
       platform_pm_suspend+0x2c/0x78
       dpm_run_callback.isra.25+0x50/0xe8
       __device_suspend+0x108/0x3c0
      
      The basic flow:
      	1. run time suspend call xhci_suspend, xhci parent devices gate the clock.
              2. echo mem >/sys/power/state, system _device_suspend call xhci_suspend
              3. xhci_suspend call xhci_disable_hub_port_wake, which access register,
      	   but clock already gated by run time suspend.
      
      This problem was hidden by power domain driver, which call run time resume before it.
      
      But the below commit remove it and make this issue happen.
      	commit c1df456d
      
       ("PM: domains: Don't runtime resume devices at genpd_prepare()")
      
      This patch call run time resume before suspend to make sure clock is on
      before access register.
      
      Reviewed-by: default avatarPeter Chen <peter.chen@kernel.org>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarFrank Li <Frank.Li@nxp.com>
      Testeb-by: default avatarAbel Vesa <abel.vesa@nxp.com>
      Link: https://lore.kernel.org/r/20220110172738.31686-1-Frank.Li@nxp.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d5755832
    • Alan Stern's avatar
      usb-storage: Add unusual-devs entry for VL817 USB-SATA bridge · a9328482
      Alan Stern authored
      commit 5b67b315
      
       upstream.
      
      Two people have reported (and mentioned numerous other reports on the
      web) that VIA's VL817 USB-SATA bridge does not work with the uas
      driver.  Typical log messages are:
      
      [ 3606.232149] sd 14:0:0:0: [sdg] tag#2 uas_zap_pending 0 uas-tag 1 inflight: CMD
      [ 3606.232154] sd 14:0:0:0: [sdg] tag#2 CDB: Write(16) 8a 00 00 00 00 00 18 0c c9 80 00 00 00 80 00 00
      [ 3606.306257] usb 4-4.4: reset SuperSpeed Plus Gen 2x1 USB device number 11 using xhci_hcd
      [ 3606.328584] scsi host14: uas_eh_device_reset_handler success
      
      Surprisingly, the devices do seem to work okay for some other people.
      The cause of the differing behaviors is not known.
      
      In the hope of getting the devices to work for the most users, even at
      the possible cost of degraded performance for some, this patch adds an
      unusual_devs entry for the VL817 to block it from binding to the uas
      driver by default.  Users will be able to override this entry by means
      of a module parameter, if they want.
      
      CC: <stable@vger.kernel.org>
      Reported-by: default avatarDocMAX <mail@vacharakis.de>
      Reported-and-tested-by: default avatarThomas Weißschuh <linux@weissschuh.net>
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Link: https://lore.kernel.org/r/Ye8IsK2sjlEv1rqU@rowland.harvard.edu
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a9328482
    • Greg Kroah-Hartman's avatar
      kbuild: remove include/linux/cyclades.h from header file check · 209a523d
      Greg Kroah-Hartman authored
      commit d1ad2721 upstream.
      
      The file now rightfully throws up a big warning that it should never be
      included, so remove it from the header_check test.
      
      Fixes: f23653fe
      
       ("tty: Partially revert the removal of the Cyclades public API")
      Cc: stable <stable@vger.kernel.org>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: "Maciej W. Rozycki" <macro@embecosm.com>
      Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Link: https://lore.kernel.org/r/20220127073304.42399-1-gregkh@linuxfoundation.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      209a523d
    • Cameron Williams's avatar
      tty: Add support for Brainboxes UC cards. · fa518035
      Cameron Williams authored
      commit 152d1afa
      
       upstream.
      
      This commit adds support for the some of the Brainboxes PCI range of
      cards, including the UC-101, UC-235/246, UC-257, UC-268, UC-275/279,
      UC-302, UC-310, UC-313, UC-320/324, UC-346, UC-357, UC-368
      and UC-420/431.
      
      Signed-off-by: default avatarCameron Williams <cang1@live.co.uk>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/AM5PR0202MB2564688493F7DD9B9C610827C45E9@AM5PR0202MB2564.eurprd02.prod.outlook.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fa518035
    • Maciej W. Rozycki's avatar
      tty: Partially revert the removal of the Cyclades public API · b51afdc7
      Maciej W. Rozycki authored
      commit f23653fe upstream.
      
      Fix a user API regression introduced with commit f76edd8f ("tty:
      cyclades, remove this orphan"), which removed a part of the API and
      caused compilation errors for user programs using said part, such as
      GCC 9 in its libsanitizer component[1]:
      
      .../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc:160:10: fatal error: linux/cyclades.h: No such file or directory
        160 | #include <linux/cyclades.h>
            |          ^~~~~~~~~~~~~~~~~~
      compilation terminated.
      make[4]: *** [Makefile:664: sanitizer_platform_limits_posix.lo] Error 1
      
      As the absolute minimum required bring `struct cyclades_monitor' and
      ioctl numbers back then so as to make the library build again.  Add a
      preprocessor warning as to the obsolescence of the features provided.
      
      References:
      
      [1] GCC PR sanitizer/100379, "cyclades.h is removed from linux kernel
          header files", <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100379>
      
      Fixes: f76edd8f
      
       ("tty: cyclades, remove this orphan")
      Cc: stable@vger.kernel.org # v5.13+
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarMaciej W. Rozycki <macro@embecosm.com>
      Link: https://lore.kernel.org/r/alpine.DEB.2.20.2201260733430.11348@tpp.orcam.me.uk
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b51afdc7
    • daniel.starke@siemens.com's avatar
      tty: n_gsm: fix SW flow control encoding/handling · ff79be50
      daniel.starke@siemens.com authored
      commit 8838b2af upstream.
      
      n_gsm is based on the 3GPP 07.010 and its newer version is the 3GPP 27.010.
      See https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516
      The changes from 07.010 to 27.010 are non-functional. Therefore, I refer to
      the newer 27.010 here. Chapter 5.2.7.3 states that DC1 (XON) and DC3 (XOFF)
      are the control characters defined in ISO/IEC 646. These shall be quoted if
      seen in the data stream to avoid interpretation as flow control characters.
      
      ISO/IEC 646 refers to the set of ISO standards described as the ISO
      7-bit coded character set for information interchange. Its final version
      is also known as ITU T.50.
      See https://www.itu.int/rec/T-REC-T.50-199209-I/en
      
      To abide the standard it is needed to quote DC1 and DC3 correctly if these
      are seen as data bytes and not as control characters. The current
      implementation already tries to enforce this but fails to catch all
      defined cases. 3GPP 27.010 chapter 5.2.7.3 clearly states that the most
      significant bit shall be ignored for DC1 and DC3 handling. The current
      implementation handles only the case with the most significant bit set 0.
      Cases in which DC1 and DC3 have the most significant bit set 1 are left
      unhandled.
      
      This patch fixes this by masking the data bytes with ISO_IEC_646_MASK (only
      the 7 least significant bits set 1) before comparing them with XON
      (a.k.a. DC1) and XOFF (a.k.a. DC3) when testing which byte values need
      quotation via byte stuffing.
      
      Fixes: e1eaea46
      
       ("tty: n_gsm line discipline")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarDaniel Starke <daniel.starke@siemens.com>
      Link: https://lore.kernel.org/r/20220120101857.2509-1-daniel.starke@siemens.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ff79be50
    • Valentin Caron's avatar
      serial: stm32: fix software flow control transfer · 775fcd69
      Valentin Caron authored
      commit 037b91ec upstream.
      
      x_char is ignored by stm32_usart_start_tx() when xmit buffer is empty.
      
      Fix start_tx condition to allow x_char to be sent.
      
      Fixes: 48a6092f
      
       ("serial: stm32-usart: Add STM32 USART Driver")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarErwan Le Ray <erwan.leray@foss.st.com>
      Signed-off-by: default avatarValentin Caron <valentin.caron@foss.st.com>
      Link: https://lore.kernel.org/r/20220111164441.6178-3-valentin.caron@foss.st.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      775fcd69
    • Robert Hancock's avatar
      serial: 8250: of: Fix mapped region size when using reg-offset property · f7990378
      Robert Hancock authored
      commit d06b1cf2 upstream.
      
      8250_of supports a reg-offset property which is intended to handle
      cases where the device registers start at an offset inside the region
      of memory allocated to the device. The Xilinx 16550 UART, for which this
      support was initially added, requires this. However, the code did not
      adjust the overall size of the mapped region accordingly, causing the
      driver to request an area of memory past the end of the device's
      allocation. For example, if the UART was allocated an address of
      0xb0130000, size of 0x10000 and reg-offset of 0x1000 in the device
      tree, the region of memory reserved was b0131000-b0140fff, which caused
      the driver for the region starting at b0140000 to fail to probe.
      
      Fix this by subtracting reg-offset from the mapped region size.
      
      Fixes: b912b5e2
      
       ([POWERPC] Xilinx: of_serial support for Xilinx uart 16550.)
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarRobert Hancock <robert.hancock@calian.com>
      Link: https://lore.kernel.org/r/20220112194214.881844-1-robert.hancock@calian.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f7990378
    • Jochen Mades's avatar
      serial: pl011: Fix incorrect rs485 RTS polarity on set_mctrl · f0cb7806
      Jochen Mades authored
      commit 62f676ff upstream.
      
      Commit 8d479237 ("serial: amba-pl011: add RS485 support") sought to
      keep RTS deasserted on set_mctrl if rs485 is enabled.  However it did so
      only if deasserted RTS polarity is high.  Fix it in case it's low.
      
      Fixes: 8d479237
      
       ("serial: amba-pl011: add RS485 support")
      Cc: stable@vger.kernel.org # v5.15+
      Cc: Lino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: default avatarJochen Mades <jochen@mades.net>
      [lukas: copyedit commit message, add stable designation]
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Link: https://lore.kernel.org/r/85fa3323ba8c307943969b7343e23f34c3e652ba.1642909284.git.lukas@wunner.de
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f0cb7806
    • Mike Snitzer's avatar
      dm: properly fix redundant bio-based IO accounting · 965bc272
      Mike Snitzer authored
      commit b879f915
      
       upstream.
      
      Record the start_time for a bio but defer the starting block core's IO
      accounting until after IO is submitted using bio_start_io_acct_time().
      
      This approach avoids the need to mess around with any of the
      individual IO stats in response to a bio_split() that follows bio
      submission.
      
      Reported-by: default avatarBud Brown <bubrown@redhat.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Cc: stable@vger.kernel.org
      Depends-on: e45c47d1
      
       ("block: add bio_start_io_acct_time() to control start_time")
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Link: https://lore.kernel.org/r/20220128155841.39644-4-snitzer@redhat.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      965bc272
    • Mike Snitzer's avatar
      block: add bio_start_io_acct_time() to control start_time · 4cca3e3e
      Mike Snitzer authored
      commit e45c47d1
      
       upstream.
      
      bio_start_io_acct_time() interface is like bio_start_io_acct() that
      allows start_time to be passed in. This gives drivers the ability to
      defer starting accounting until after IO is issued (but possibily not
      entirely due to bio splitting).
      
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Link: https://lore.kernel.org/r/20220128155841.39644-2-snitzer@redhat.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4cca3e3e
    • Mike Snitzer's avatar
      dm: revert partial fix for redundant bio-based IO accounting · 86125006
      Mike Snitzer authored
      commit f524d9c9 upstream.
      
      Reverts a1e1cb72
      
       ("dm: fix redundant IO accounting for bios that
      need splitting") because it was too narrow in scope (only addressed
      redundant 'sectors[]' accounting and not ios, nsecs[], etc).
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Link: https://lore.kernel.org/r/20220128155841.39644-3-snitzer@redhat.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      86125006
    • Nicholas Piggin's avatar
      KVM: PPC: Book3S HV Nested: Fix nested HFSCR being clobbered with multiple vCPUs · c0af639c
      Nicholas Piggin authored
      commit 22f7ff0d upstream.
      
      The L0 is storing HFSCR requested by the L1 for the L2 in struct
      kvm_nested_guest when the L1 requests a vCPU enter L2. kvm_nested_guest
      is not a per-vCPU structure. Hilarity ensues.
      
      Fix it by moving the nested hfscr into the vCPU structure together with
      the other per-vCPU nested fields.
      
      Fixes: 8b210a88
      
       ("KVM: PPC: Book3S HV Nested: Make nested HFSCR state accessible")
      Cc: stable@vger.kernel.org # v5.15+
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Reviewed-by: default avatarFabiano Rosas <farosas@linux.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20220122105530.3477250-1-npiggin@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c0af639c
    • Like Xu's avatar
      KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time · e668b527
      Like Xu authored
      commit 05a9e065 upstream.
      
      XCR0 is reset to 1 by RESET but not INIT and IA32_XSS is zeroed by
      both RESET and INIT. The kvm_set_msr_common()'s handling of MSR_IA32_XSS
      also needs to update kvm_update_cpuid_runtime(). In the above cases, the
      size in bytes of the XSAVE area containing all states enabled by XCR0 or
      (XCRO | IA32_XSS) needs to be updated.
      
      For simplicity and consistency, existing helpers are used to write values
      and call kvm_update_cpuid_runtime(), and it's not exactly a fast path.
      
      Fixes: a554d207
      
       ("KVM: X86: Processor States following Reset or INIT")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarLike Xu <likexu@tencent.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20220126172226.2298529-4-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e668b527
    • Like Xu's avatar
      KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS · 096779d4
      Like Xu authored
      commit 4c282e51 upstream.
      
      Do a runtime CPUID update for a vCPU if MSR_IA32_XSS is written, as the
      size in bytes of the XSAVE area is affected by the states enabled in XSS.
      
      Fixes: 20300099
      
       ("kvm: vmx: add MSR logic for XSAVES")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarLike Xu <likexu@tencent.com>
      [sean: split out as a separate patch, adjust Fixes tag]
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20220126172226.2298529-3-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      096779d4
    • Xiaoyao Li's avatar
      KVM: x86: Keep MSR_IA32_XSS unchanged for INIT · 5afeafcc
      Xiaoyao Li authored
      commit be4f3b3f upstream.
      
      It has been corrected from SDM version 075 that MSR_IA32_XSS is reset to
      zero on Power up and Reset but keeps unchanged on INIT.
      
      Fixes: a554d207
      
       ("KVM: X86: Processor States following Reset or INIT")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarXiaoyao Li <xiaoyao.li@intel.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20220126172226.2298529-2-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5afeafcc
    • Sean Christopherson's avatar
      KVM: x86: Forcibly leave nested virt when SMM state is toggled · e3027862
      Sean Christopherson authored
      commit f7e57078
      
       upstream.
      
      Forcibly leave nested virtualization operation if userspace toggles SMM
      state via KVM_SET_VCPU_EVENTS or KVM_SYNC_X86_EVENTS.  If userspace
      forces the vCPU out of SMM while it's post-VMXON and then injects an SMI,
      vmx_enter_smm() will overwrite vmx->nested.smm.vmxon and end up with both
      vmxon=false and smm.vmxon=false, but all other nVMX state allocated.
      
      Don't attempt to gracefully handle the transition as (a) most transitions
      are nonsencial, e.g. forcing SMM while L2 is running, (b) there isn't
      sufficient information to handle all transitions, e.g. SVM wants access
      to the SMRAM save state, and (c) KVM_SET_VCPU_EVENTS must precede
      KVM_SET_NESTED_STATE during state restore as the latter disallows putting
      the vCPU into L2 if SMM is active, and disallows tagging the vCPU as
      being post-VMXON in SMM if SMM is not active.
      
      Abuse of KVM_SET_VCPU_EVENTS manifests as a WARN and memory leak in nVMX
      due to failure to free vmcs01's shadow VMCS, but the bug goes far beyond
      just a memory leak, e.g. toggling SMM on while L2 is active puts the vCPU
      in an architecturally impossible state.
      
        WARNING: CPU: 0 PID: 3606 at free_loaded_vmcs arch/x86/kvm/vmx/vmx.c:2665 [inline]
        WARNING: CPU: 0 PID: 3606 at free_loaded_vmcs+0x158/0x1a0 arch/x86/kvm/vmx/vmx.c:2656
        Modules linked in:
        CPU: 1 PID: 3606 Comm: syz-executor725 Not tainted 5.17.0-rc1-syzkaller #0
        Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
        RIP: 0010:free_loaded_vmcs arch/x86/kvm/vmx/vmx.c:2665 [inline]
        RIP: 0010:free_loaded_vmcs+0x158/0x1a0 arch/x86/kvm/vmx/vmx.c:2656
        Code: <0f> 0b eb b3 e8 8f 4d 9f 00 e9 f7 fe ff ff 48 89 df e8 92 4d 9f 00
        Call Trace:
         <TASK>
         kvm_arch_vcpu_destroy+0x72/0x2f0 arch/x86/kvm/x86.c:11123
         kvm_vcpu_destroy arch/x86/kvm/../../../virt/kvm/kvm_main.c:441 [inline]
         kvm_destroy_vcpus+0x11f/0x290 arch/x86/kvm/../../../virt/kvm/kvm_main.c:460
         kvm_free_vcpus arch/x86/kvm/x86.c:11564 [inline]
         kvm_arch_destroy_vm+0x2e8/0x470 arch/x86/kvm/x86.c:11676
         kvm_destroy_vm arch/x86/kvm/../../../virt/kvm/kvm_main.c:1217 [inline]
         kvm_put_kvm+0x4fa/0xb00 arch/x86/kvm/../../../virt/kvm/kvm_main.c:1250
         kvm_vm_release+0x3f/0x50 arch/x86/kvm/../../../virt/kvm/kvm_main.c:1273
         __fput+0x286/0x9f0 fs/file_table.c:311
         task_work_run+0xdd/0x1a0 kernel/task_work.c:164
         exit_task_work include/linux/task_work.h:32 [inline]
         do_exit+0xb29/0x2a30 kernel/exit.c:806
         do_group_exit+0xd2/0x2f0 kernel/exit.c:935
         get_signal+0x4b0/0x28c0 kernel/signal.c:2862
         arch_do_signal_or_restart+0x2a9/0x1c40 arch/x86/kernel/signal.c:868
         handle_signal_work kernel/entry/common.c:148 [inline]
         exit_to_user_mode_loop kernel/entry/common.c:172 [inline]
         exit_to_user_mode_prepare+0x17d/0x290 kernel/entry/common.c:207
         __syscall_exit_to_user_mode_work kernel/entry/common.c:289 [inline]
         syscall_exit_to_user_mode+0x19/0x60 kernel/entry/common.c:300
         do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86
         entry_SYSCALL_64_after_hwframe+0x44/0xae
         </TASK>
      
      Cc: stable@vger.kernel.org
      Reported-by: default avatar <syzbot+8112db3ab20e70d50c31@syzkaller.appspotmail.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20220125220358.2091737-1-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e3027862
    • Denis Valeev's avatar
      KVM: x86: nSVM: skip eax alignment check for non-SVM instructions · 6f3e157e
      Denis Valeev authored
      commit 47c28d43 upstream.
      
      The bug occurs on #GP triggered by VMware backdoor when eax value is
      unaligned. eax alignment check should not be applied to non-SVM
      instructions because it leads to incorrect omission of the instructions
      emulation.
      Apply the alignment check only to SVM instructions to fix.
      
      Fixes: d1cba6c9
      
       ("KVM: x86: nSVM: test eax for 4K alignment for GP errata workaround")
      Signed-off-by: default avatarDenis Valeev <lemniscattaden@gmail.com>
      Message-Id: <Yexlhaoe1Fscm59u@q>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6f3e157e
    • Sean Christopherson's avatar
      KVM: SVM: Don't intercept #GP for SEV guests · 57565656
      Sean Christopherson authored
      commit 0b0be065
      
       upstream.
      
      Never intercept #GP for SEV guests as reading SEV guest private memory
      will return cyphertext, i.e. emulating on #GP can't work as intended.
      
      Cc: stable@vger.kernel.org
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Reviewed-by: default avatarLiam Merwick <liam.merwick@oracle.com>
      Message-Id: <20220120010719.711476-4-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      57565656
    • Sean Christopherson's avatar
      KVM: SVM: Never reject emulation due to SMAP errata for !SEV guests · 3470722f
      Sean Christopherson authored
      commit 55467fcd upstream.
      
      Always signal that emulation is possible for !SEV guests regardless of
      whether or not the CPU provided a valid instruction byte stream.  KVM can
      read all guest state (memory and registers) for !SEV guests, i.e. can
      fetch the code stream from memory even if the CPU failed to do so because
      of the SMAP errata.
      
      Fixes: 05d5a486
      
       ("KVM: SVM: Workaround errata#1096 (insn_len maybe zero on SMAP violation)")
      Cc: stable@vger.kernel.org
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Reviewed-by: default avatarLiam Merwick <liam.merwick@oracle.com>
      Message-Id: <20220120010719.711476-2-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3470722f