1. 28 Feb, 2020 4 commits
  2. 14 Feb, 2020 36 commits
    • Greg Kroah-Hartman's avatar
      Linux 4.9.214 · 7ce43926
      Greg Kroah-Hartman authored
      7ce43926
    • Nicolai Stange's avatar
      libertas: make lbs_ibss_join_existing() return error code on rates overflow · 9d68062d
      Nicolai Stange authored
      [ Upstream commit 1754c4f6 ]
      
      Commit e5e884b4 ("libertas: Fix two buffer overflows at parsing bss
      descriptor") introduced a bounds check on the number of supplied rates to
      lbs_ibss_join_existing() and made it to return on overflow.
      
      However, the aforementioned commit doesn't set the return value accordingly
      and thus, lbs_ibss_join_existing() would return with zero even though it
      failed.
      
      Make lbs_ibss_join_existing return -EINVAL in case the bounds check on the
      number of supplied rates fails.
      
      Fixes: e5e884b4 ("libertas: Fix two buffer overflows at parsing bss descriptor")
      Signed-off-by: default avatarNicolai Stange <nstange@suse.de>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9d68062d
    • Nicolai Stange's avatar
      libertas: don't exit from lbs_ibss_join_existing() with RCU read lock held · 88c38166
      Nicolai Stange authored
      [ Upstream commit c7bf1fb7 ]
      
      Commit e5e884b4 ("libertas: Fix two buffer overflows at parsing bss
      descriptor") introduced a bounds check on the number of supplied rates to
      lbs_ibss_join_existing().
      
      Unfortunately, it introduced a return path from within a RCU read side
      critical section without a corresponding rcu_read_unlock(). Fix this.
      
      Fixes: e5e884b4 ("libertas: Fix two buffer overflows at parsing bss descriptor")
      Signed-off-by: default avatarNicolai Stange <nstange@suse.de>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      88c38166
    • Qing Xu's avatar
      mwifiex: Fix possible buffer overflows in mwifiex_cmd_append_vsie_tlv() · 7a4d6a45
      Qing Xu authored
      [ Upstream commit b70261a2 ]
      
      mwifiex_cmd_append_vsie_tlv() calls memcpy() without checking
      the destination size may trigger a buffer overflower,
      which a local user could use to cause denial of service
      or the execution of arbitrary code.
      Fix it by putting the length check before calling memcpy().
      Signed-off-by: default avatarQing Xu <m1s5p6688@gmail.com>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7a4d6a45
    • Qing Xu's avatar
      mwifiex: Fix possible buffer overflows in mwifiex_ret_wmm_get_status() · 0a996849
      Qing Xu authored
      [ Upstream commit 3a9b153c ]
      
      mwifiex_ret_wmm_get_status() calls memcpy() without checking the
      destination size.Since the source is given from remote AP which
      contains illegal wmm elements , this may trigger a heap buffer
      overflow.
      Fix it by putting the length check before calling memcpy().
      Signed-off-by: default avatarQing Xu <m1s5p6688@gmail.com>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0a996849
    • Mike Snitzer's avatar
      dm: fix potential for q->make_request_fn NULL pointer · e68f18b0
      Mike Snitzer authored
      commit 47ace7e0 upstream.
      
      Move blk_queue_make_request() to dm.c:alloc_dev() so that
      q->make_request_fn is never NULL during the lifetime of a DM device
      (even one that is created without a DM table).
      
      Otherwise generic_make_request() will crash simply by doing:
        dmsetup create -n test
        mount /dev/dm-N /mnt
      
      While at it, move ->congested_data initialization out of
      dm.c:alloc_dev() and into the bio-based specific init method.
      Reported-by: default avatarStefan Bader <stefan.bader@canonical.com>
      BugLink: https://bugs.launchpad.net/bugs/1860231
      Fixes: ff36ab34 ("dm: remove request-based logic from make_request_fn wrapper")
      Depends-on: c12c9a3c ("dm: various cleanups to md->queue initialization code")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      [smb: adjusted for context and dm_init_md_queue() exitsting in older
            kernels, and congested_data embedded in backing_dev_info]
      Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e68f18b0
    • Anand Lodnoor's avatar
      scsi: megaraid_sas: Do not initiate OCR if controller is not in ready state · 7387c496
      Anand Lodnoor authored
      commit 6d753727 upstream.
      
      Driver initiates OCR if a DCMD command times out. But there is a deadlock
      if the driver attempts to invoke another OCR before the mutex lock
      (reset_mutex) is released from the previous session of OCR.
      
      This patch takes care of the above scenario using new flag
      MEGASAS_FUSION_OCR_NOT_POSSIBLE to indicate if OCR is possible.
      
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/1579000882-20246-9-git-send-email-anand.lodnoor@broadcom.comSigned-off-by: default avatarShivasharan S <shivasharan.srikanteshwara@broadcom.com>
      Signed-off-by: default avatarAnand Lodnoor <anand.lodnoor@broadcom.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      7387c496
    • Geert Uytterhoeven's avatar
      pinctrl: sh-pfc: r8a7778: Fix duplicate SDSELF_B and SD1_CLK_B · 029f7c4a
      Geert Uytterhoeven authored
      commit 805f6357 upstream.
      
      The FN_SDSELF_B and FN_SD1_CLK_B enum IDs are used twice, which means
      one set of users must be wrong.  Replace them by the correct enum IDs.
      
      Fixes: 87f8c988 ("sh-pfc: Add r8a7778 pinmux support")
      Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Link: https://lore.kernel.org/r/20191218194812.12741-2-geert+renesas@glider.beSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      029f7c4a
    • Alexey Kardashevskiy's avatar
      powerpc/pseries: Allow not having ibm, hypertas-functions::hcall-multi-tce for DDW · 72f7b734
      Alexey Kardashevskiy authored
      commit 7559d3d2 upstream.
      
      By default a pseries guest supports a H_PUT_TCE hypercall which maps
      a single IOMMU page in a DMA window. Additionally the hypervisor may
      support H_PUT_TCE_INDIRECT/H_STUFF_TCE which update multiple TCEs at once;
      this is advertised via the device tree /rtas/ibm,hypertas-functions
      property which Linux converts to FW_FEATURE_MULTITCE.
      
      FW_FEATURE_MULTITCE is checked when dma_iommu_ops is used; however
      the code managing the huge DMA window (DDW) ignores it and calls
      H_PUT_TCE_INDIRECT even if it is explicitly disabled via
      the "multitce=off" kernel command line parameter.
      
      This adds FW_FEATURE_MULTITCE checking to the DDW code path.
      
      This changes tce_build_pSeriesLP to take liobn and page size as
      the huge window does not have iommu_table descriptor which usually
      the place to store these numbers.
      
      Fixes: 4e8b0cf4 ("powerpc/pseries: Add support for dynamic dma windows")
      Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
      Reviewed-by: default avatarThiago Jung Bauermann <bauerman@linux.ibm.com>
      Tested-by: default avatarThiago Jung Bauermann <bauerman@linux.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20191216041924.42318-3-aik@ozlabs.ruSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      72f7b734
    • Zhengyuan Liu's avatar
      tools/power/acpi: fix compilation error · e751d1a9
      Zhengyuan Liu authored
      commit 1985f8c7 upstream.
      
      If we compile tools/acpi target in the top source directory, we'd get a
      compilation error showing as bellow:
      
      	# make tools/acpi
      	  DESCEND  power/acpi
      	  DESCEND  tools/acpidbg
      	  CC       tools/acpidbg/acpidbg.o
      	Assembler messages:
      	Fatal error: can't create /home/lzy/kernel-upstream/power/acpi/\
      			tools/acpidbg/acpidbg.o: No such file or directory
      	../../Makefile.rules:26: recipe for target '/home/lzy/kernel-upstream/\
      			power/acpi/tools/acpidbg/acpidbg.o' failed
      	make[3]: *** [/home/lzy/kernel-upstream//power/acpi/tools/acpidbg/\
      			acpidbg.o] Error 1
      	Makefile:19: recipe for target 'acpidbg' failed
      	make[2]: *** [acpidbg] Error 2
      	Makefile:54: recipe for target 'acpi' failed
      	make[1]: *** [acpi] Error 2
      	Makefile:1607: recipe for target 'tools/acpi' failed
      	make: *** [tools/acpi] Error 2
      
      Fixes: d5a4b1a5 ("tools/power/acpi: Remove direct kernel source include reference")
      Signed-off-by: default avatarZhengyuan Liu <liuzhengyuan@kylinos.cn>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e751d1a9
    • Alexandre Belloni's avatar
      ARM: dts: at91: sama5d3: define clock rate range for tcb1 · 08995c08
      Alexandre Belloni authored
      commit a7e0f3fc upstream.
      
      The clock rate range for the TCB1 clock is missing. define it in the device
      tree.
      Reported-by: default avatarKarl Rudbæk Olsen <karl@micro-technic.com>
      Fixes: d2e8190b ("ARM: at91/dt: define sama5d3 clocks")
      Link: https://lore.kernel.org/r/20200110172007.1253659-2-alexandre.belloni@bootlin.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      08995c08
    • Alexandre Belloni's avatar
      ARM: dts: at91: sama5d3: fix maximum peripheral clock rates · f08233be
      Alexandre Belloni authored
      commit ee0aa926 upstream.
      
      Currently the maximum rate for peripheral clock is calculated based on a
      typical 133MHz MCK. The maximum frequency is defined in the datasheet as a
      ratio to MCK. Some sama5d3 platforms are using a 166MHz MCK. Update the
      device trees to match the maximum rate based on 166MHz.
      Reported-by: default avatarKarl Rudbæk Olsen <karl@micro-technic.com>
      Fixes: d2e8190b ("ARM: at91/dt: define sama5d3 clocks")
      Link: https://lore.kernel.org/r/20200110172007.1253659-1-alexandre.belloni@bootlin.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f08233be
    • Jose Abreu's avatar
      ARC: [plat-axs10x]: Add missing multicast filter number to GMAC node · 31697b43
      Jose Abreu authored
      commit 7980dff3 upstream.
      
      Add a missing property to GMAC node so that multicast filtering works
      correctly.
      
      Fixes: 556cc1c5 ("ARC: [axs101] Add support for AXS101 SDP (software development platform)")
      Acked-by: default avatarAlexey Brodkin <abrodkin@synopsys.com>
      Signed-off-by: default avatarJose Abreu <Jose.Abreu@synopsys.com>
      Signed-off-by: default avatarVineet Gupta <vgupta@synopsys.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      31697b43
    • Andy Shevchenko's avatar
      rtc: cmos: Stop using shared IRQ · 1f7b5c87
      Andy Shevchenko authored
      commit b6da197a upstream.
      
      As reported by Guilherme G. Piccoli:
      
      ---8<---8<---8<---
      
      The rtc-cmos interrupt setting was changed in the commit 079062b2
      ("rtc: cmos: prevent kernel warning on IRQ flags mismatch") in order
      to allow shared interrupts; according to that commit's description,
      some machine got kernel warnings due to the interrupt line being shared
      between rtc-cmos and other hardware, and rtc-cmos didn't allow IRQ sharing
      that time.
      
      After the aforementioned commit though it was observed a huge increase
      in lost HPET interrupts in some systems, observed through the following
      kernel message:
      
      [...] hpet1: lost 35 rtc interrupts
      
      After investigation, it was narrowed down to the shared interrupts
      usage when having the kernel option "irqpoll" enabled. In this case,
      all IRQ handlers are called for non-timer interrupts, if such handlers
      are setup in shared IRQ lines. The rtc-cmos IRQ handler could be set to
      hpet_rtc_interrupt(), which will produce the kernel "lost interrupts"
      message after doing work - lots of readl/writel to HPET registers, which
      are known to be slow.
      
      Although "irqpoll" is not a default kernel option, it's used in some contexts,
      one being the kdump kernel (which is an already "impaired" kernel usually
      running with 1 CPU available), so the performance burden could be considerable.
      Also, the same issue would happen (in a shorter extent though) when using
      "irqfixup" kernel option.
      
      In a quick experiment, a virtual machine with uptime of 2 minutes produced
      >300 calls to hpet_rtc_interrupt() when "irqpoll" was set, whereas without
      sharing interrupts this number reduced to 1 interrupt. Machines with more
      hardware than a VM should generate even more unnecessary HPET interrupts
      in this scenario.
      
      ---8<---8<---8<---
      
      After looking into the rtc-cmos driver history and DSDT table from
      the Microsoft Surface 3, we may notice that Hans de Goede submitted
      a correct fix (see dependency below). Thus, we simply revert
      the culprit commit.
      
      Fixes: 079062b2 ("rtc: cmos: prevent kernel warning on IRQ flags mismatch")
      Depends-on: a1e23a42 ("rtc: cmos: Do not assume irq 8 for rtc when there are no legacy irqs")
      Reported-by: default avatarGuilherme G. Piccoli <gpiccoli@canonical.com>
      Cc: Hans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Tested-by: default avatarGuilherme G. Piccoli <gpiccoli@canonical.com>
      Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
      Link: https://lore.kernel.org/r/20200123131437.28157-1-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1f7b5c87
    • Paul Kocialkowski's avatar
      rtc: hym8563: Return -EINVAL if the time is known to be invalid · 1ae7c56f
      Paul Kocialkowski authored
      commit f236a2a2 upstream.
      
      The current code returns -EPERM when the voltage loss bit is set.
      Since the bit indicates that the time value is not valid, return
      -EINVAL instead, which is the appropriate error code for this
      situation.
      
      Fixes: dcaf0384 ("rtc: add hym8563 rtc-driver")
      Signed-off-by: default avatarPaul Kocialkowski <paul.kocialkowski@bootlin.com>
      Link: https://lore.kernel.org/r/20191212153111.966923-1-paul.kocialkowski@bootlin.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1ae7c56f
    • Robert Milkowski's avatar
      NFSv4: try lease recovery on NFS4ERR_EXPIRED · d4dc8c8b
      Robert Milkowski authored
      commit 924491f2 upstream.
      
      Currently, if an nfs server returns NFS4ERR_EXPIRED to open(),
      we return EIO to applications without even trying to recover.
      
      Fixes: 272289a3 ("NFSv4: nfs4_do_handle_exception() handle revoke/expiry of a single stateid")
      Signed-off-by: default avatarRobert Milkowski <rmilkowski@gmail.com>
      Reviewed-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d4dc8c8b
    • Geert Uytterhoeven's avatar
      nfs: NFS_SWAP should depend on SWAP · fe8f086a
      Geert Uytterhoeven authored
      commit 474c4f30 upstream.
      
      If CONFIG_SWAP=n, it does not make much sense to offer the user the
      option to enable support for swapping over NFS, as that will still fail
      at run time:
      
          # swapon /swap
          swapon: /swap: swapon failed: Function not implemented
      
      Fix this by adding a dependency on CONFIG_SWAP.
      
      Fixes: a564b8f0 ("nfs: enable swap on NFS")
      Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fe8f086a
    • Logan Gunthorpe's avatar
      PCI: Don't disable bridge BARs when assigning bus resources · 208ac813
      Logan Gunthorpe authored
      commit 9db8dc6d upstream.
      
      Some PCI bridges implement BARs in addition to bridge windows.  For
      example, here's a PLX switch:
      
        04:00.0 PCI bridge: PLX Technology, Inc. PEX 8724 24-Lane, 6-Port PCI
                  Express Gen 3 (8 GT/s) Switch, 19 x 19mm FCBGA (rev ca)
      	    (prog-if 00 [Normal decode])
            Flags: bus master, fast devsel, latency 0, IRQ 30, NUMA node 0
            Memory at 90a00000 (32-bit, non-prefetchable) [size=256K]
            Bus: primary=04, secondary=05, subordinate=0a, sec-latency=0
            I/O behind bridge: 00002000-00003fff
            Memory behind bridge: 90000000-909fffff
            Prefetchable memory behind bridge: 0000380000800000-0000380000bfffff
      
      Previously, when the kernel assigned resource addresses (with the
      pci=realloc command line parameter, for example) it could clear the struct
      resource corresponding to the BAR.  When this happened, lspci would report
      this BAR as "ignored":
      
         Region 0: Memory at <ignored> (32-bit, non-prefetchable) [size=256K]
      
      This is because the kernel reports a zero start address and zero flags
      in the corresponding sysfs resource file and in /proc/bus/pci/devices.
      Investigation with 'lspci -x', however, shows the BIOS-assigned address
      will still be programmed in the device's BAR registers.
      
      It's clearly a bug that the kernel lost track of the BAR value, but in most
      cases, this still won't result in a visible issue because nothing uses the
      memory, so nothing is affected.  However, when an IOMMU is in use, it will
      not reserve this space in the IOVA because the kernel no longer thinks the
      range is valid.  (See dmar_init_reserved_ranges() for the Intel
      implementation of this.)
      
      Without the proper reserved range, a DMA mapping may allocate an IOVA that
      matches a bridge BAR, which results in DMA accesses going to the BAR
      instead of the intended RAM.
      
      The problem was in pci_assign_unassigned_root_bus_resources().  When any
      resource from a bridge device fails to get assigned, the code set the
      resource's flags to zero.  This makes sense for bridge windows, as they
      will be re-enabled later, but for regular BARs, it makes the kernel
      permanently lose track of the fact that they decode address space.
      
      Change pci_assign_unassigned_root_bus_resources() and
      pci_assign_unassigned_bridge_resources() so they only clear "res->flags"
      for bridge *windows*, not bridge BARs.
      
      Fixes: da7822e5 ("PCI: update bridge resources to get more big ranges when allocating space (again)")
      Link: https://lore.kernel.org/r/20200108213208.4612-1-logang@deltatee.com
      [bhelgaas: commit log, check for pci_is_bridge()]
      Reported-by: default avatarKit Chow <kchow@gigaio.com>
      Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      208ac813
    • Bean Huo's avatar
      scsi: ufs: Fix ufshcd_probe_hba() reture value in case ufshcd_scsi_add_wlus() fails · 39f4ec1e
      Bean Huo authored
      commit b9fc5320 upstream.
      
      A non-zero error value likely being returned by ufshcd_scsi_add_wlus() in
      case of failure of adding the WLs, but ufshcd_probe_hba() doesn't use this
      value, and doesn't report this failure to upper caller.  This patch is to
      fix this issue.
      
      Fixes: 2a8fa600 ("ufs: manually add well known logical units")
      Link: https://lore.kernel.org/r/20200120130820.1737-2-huobean@gmail.comReviewed-by: default avatarAsutosh Das <asutoshd@codeaurora.org>
      Reviewed-by: default avatarAlim Akhtar <alim.akhtar@samsung.com>
      Reviewed-by: default avatarStanley Chu <stanley.chu@mediatek.com>
      Signed-off-by: default avatarBean Huo <beanhuo@micron.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      39f4ec1e
    • Håkon Bugge's avatar
      RDMA/netlink: Do not always generate an ACK for some netlink operations · 81828ccf
      Håkon Bugge authored
      commit a242c369 upstream.
      
      In rdma_nl_rcv_skb(), the local variable err is assigned the return value
      of the supplied callback function, which could be one of
      ib_nl_handle_resolve_resp(), ib_nl_handle_set_timeout(), or
      ib_nl_handle_ip_res_resp(). These three functions all return skb->len on
      success.
      
      rdma_nl_rcv_skb() is merely a copy of netlink_rcv_skb(). The callback
      functions used by the latter have the convention: "Returns 0 on success or
      a negative error code".
      
      In particular, the statement (equal for both functions):
      
         if (nlh->nlmsg_flags & NLM_F_ACK || err)
      
      implies that rdma_nl_rcv_skb() always will ack a message, independent of
      the NLM_F_ACK being set in nlmsg_flags or not.
      
      The fix could be to change the above statement, but it is better to keep
      the two *_rcv_skb() functions equal in this respect and instead change the
      three callback functions in the rdma subsystem to the correct convention.
      
      Fixes: 2ca546b9 ("IB/sa: Route SA pathrecord query through netlink")
      Fixes: ae43f828 ("IB/core: Add IP to GID netlink offload")
      Link: https://lore.kernel.org/r/20191216120436.3204814-1-haakon.bugge@oracle.comSuggested-by: default avatarMark Haywood <mark.haywood@oracle.com>
      Signed-off-by: default avatarHåkon Bugge <haakon.bugge@oracle.com>
      Tested-by: default avatarMark Haywood <mark.haywood@oracle.com>
      Reviewed-by: default avatarLeon Romanovsky <leonro@mellanox.com>
      Reviewed-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      81828ccf
    • Ranjani Sridharan's avatar
      ASoC: pcm: update FE/BE trigger order based on the command · 221f141c
      Ranjani Sridharan authored
      [ Upstream commit acbf2774 ]
      
      Currently, the trigger orders SND_SOC_DPCM_TRIGGER_PRE/POST
      determine the order in which FE DAI and BE DAI are triggered.
      In the case of SND_SOC_DPCM_TRIGGER_PRE, the FE DAI is
      triggered before the BE DAI and in the case of
      SND_SOC_DPCM_TRIGGER_POST, the BE DAI is triggered before
      the FE DAI. And this order remains the same irrespective of the
      trigger command.
      
      In the case of the SOF driver, during playback, the FW
      expects the BE DAI to be triggered before the FE DAI during
      the START trigger. The BE DAI trigger handles the starting of
      Link DMA and so it must be started before the FE DAI is started
      to prevent xruns during pause/release. This can be addressed
      by setting the trigger order for the FE dai link to
      SND_SOC_DPCM_TRIGGER_POST. But during the STOP trigger,
      the FW expects the FE DAI to be triggered before the BE DAI.
      Retaining the same order during the START and STOP commands,
      results in FW error as the DAI component in the FW is still
      active.
      
      The issue can be fixed by mirroring the trigger order of
      FE and BE DAI's during the START and STOP trigger. So, with the
      trigger order set to SND_SOC_DPCM_TRIGGER_PRE, the FE DAI will be
      trigger first during SNDRV_PCM_TRIGGER_START/STOP/RESUME
      and the BE DAI will be triggered first during the
      STOP/SUSPEND/PAUSE commands. Conversely, with the trigger order
      set to SND_SOC_DPCM_TRIGGER_POST, the BE DAI will be triggered
      first during the SNDRV_PCM_TRIGGER_START/STOP/RESUME commands
      and the FE DAI will be triggered first during the
      SNDRV_PCM_TRIGGER_STOP/SUSPEND/PAUSE commands.
      Signed-off-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
      Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
      Link: https://lore.kernel.org/r/20191104224812.3393-2-ranjani.sridharan@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      221f141c
    • David Howells's avatar
      rxrpc: Fix service call disconnection · 1b950f7a
      David Howells authored
      [ Upstream commit b39a934e ]
      
      The recent patch that substituted a flag on an rxrpc_call for the
      connection pointer being NULL as an indication that a call was disconnected
      puts the set_bit in the wrong place for service calls.  This is only a
      problem if a call is implicitly terminated by a new call coming in on the
      same connection channel instead of a terminating ACK packet.
      
      In such a case, rxrpc_input_implicit_end_call() calls
      __rxrpc_disconnect_call(), which is now (incorrectly) setting the
      disconnection bit, meaning that when rxrpc_release_call() is later called,
      it doesn't call rxrpc_disconnect_call() and so the call isn't removed from
      the peer's error distribution list and the list gets corrupted.
      
      KASAN finds the issue as an access after release on a call, but the
      position at which it occurs is confusing as it appears to be related to a
      different call (the call site is where the latter call is being removed
      from the error distribution list and either the next or pprev pointer
      points to a previously released call).
      
      Fix this by moving the setting of the flag from __rxrpc_disconnect_call()
      to rxrpc_disconnect_call() in the same place that the connection pointer
      was being cleared.
      
      Fixes: 5273a191 ("rxrpc: Fix NULL pointer deref due to call->conn being cleared on disconnect")
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1b950f7a
    • Song Liu's avatar
      perf/core: Fix mlock accounting in perf_mmap() · 026d9148
      Song Liu authored
      commit 00346155 upstream.
      
      Decreasing sysctl_perf_event_mlock between two consecutive perf_mmap()s of
      a perf ring buffer may lead to an integer underflow in locked memory
      accounting. This may lead to the undesired behaviors, such as failures in
      BPF map creation.
      
      Address this by adjusting the accounting logic to take into account the
      possibility that the amount of already locked memory may exceed the
      current limit.
      
      Fixes: c4b75479 ("perf/core: Make the mlock accounting simple again")
      Suggested-by: default avatarAlexander Shishkin <alexander.shishkin@linux.intel.com>
      Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Cc: <stable@vger.kernel.org>
      Acked-by: default avatarAlexander Shishkin <alexander.shishkin@linux.intel.com>
      Link: https://lkml.kernel.org/r/20200123181146.2238074-1-songliubraving@fb.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      026d9148
    • Konstantin Khlebnikov's avatar
      clocksource: Prevent double add_timer_on() for watchdog_timer · 75fc4654
      Konstantin Khlebnikov authored
      commit febac332 upstream.
      
      Kernel crashes inside QEMU/KVM are observed:
      
        kernel BUG at kernel/time/timer.c:1154!
        BUG_ON(timer_pending(timer) || !timer->function) in add_timer_on().
      
      At the same time another cpu got:
      
        general protection fault: 0000 [#1] SMP PTI of poinson pointer 0xdead000000000200 in:
      
        __hlist_del at include/linux/list.h:681
        (inlined by) detach_timer at kernel/time/timer.c:818
        (inlined by) expire_timers at kernel/time/timer.c:1355
        (inlined by) __run_timers at kernel/time/timer.c:1686
        (inlined by) run_timer_softirq at kernel/time/timer.c:1699
      
      Unfortunately kernel logs are badly scrambled, stacktraces are lost.
      
      Printing the timer->function before the BUG_ON() pointed to
      clocksource_watchdog().
      
      The execution of clocksource_watchdog() can race with a sequence of
      clocksource_stop_watchdog() .. clocksource_start_watchdog():
      
      expire_timers()
       detach_timer(timer, true);
        timer->entry.pprev = NULL;
       raw_spin_unlock_irq(&base->lock);
       call_timer_fn
        clocksource_watchdog()
      
      					clocksource_watchdog_kthread() or
      					clocksource_unbind()
      
      					spin_lock_irqsave(&watchdog_lock, flags);
      					clocksource_stop_watchdog();
      					 del_timer(&watchdog_timer);
      					 watchdog_running = 0;
      					spin_unlock_irqrestore(&watchdog_lock, flags);
      
      					spin_lock_irqsave(&watchdog_lock, flags);
      					clocksource_start_watchdog();
      					 add_timer_on(&watchdog_timer, ...);
      					 watchdog_running = 1;
      					spin_unlock_irqrestore(&watchdog_lock, flags);
      
        spin_lock(&watchdog_lock);
        add_timer_on(&watchdog_timer, ...);
         BUG_ON(timer_pending(timer) || !timer->function);
          timer_pending() -> true
          BUG()
      
      I.e. inside clocksource_watchdog() watchdog_timer could be already armed.
      
      Check timer_pending() before calling add_timer_on(). This is sufficient as
      all operations are synchronized by watchdog_lock.
      
      Fixes: 75c5158f ("timekeeping: Update clocksource with stop_machine")
      Signed-off-by: default avatarKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/158048693917.4378.13823603769948933793.stgit@buzzSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      75fc4654
    • Ronnie Sahlberg's avatar
      cifs: fail i/o on soft mounts if sessionsetup errors out · f78ba732
      Ronnie Sahlberg authored
      commit b0dd940e upstream.
      
      RHBZ: 1579050
      
      If we have a soft mount we should fail commands for session-setup
      failures (such as the password having changed/ account being deleted/ ...)
      and return an error back to the application.
      Signed-off-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      CC: Stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f78ba732
    • Miaohe Lin's avatar
      KVM: nVMX: vmread should not set rflags to specify success in case of #PF · 0b414c54
      Miaohe Lin authored
      [ Upstream commit a4d956b9 ]
      
      In case writing to vmread destination operand result in a #PF, vmread
      should not call nested_vmx_succeed() to set rflags to specify success.
      Similar to as done in VMPTRST (See handle_vmptrst()).
      Reviewed-by: default avatarLiran Alon <liran.alon@oracle.com>
      Signed-off-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0b414c54
    • Sean Christopherson's avatar
      KVM: VMX: Add non-canonical check on writes to RTIT address MSRs · bd350d09
      Sean Christopherson authored
      [ Upstream commit fe6ed369 ]
      
      Reject writes to RTIT address MSRs if the data being written is a
      non-canonical address as the MSRs are subject to canonical checks, e.g.
      KVM will trigger an unchecked #GP when loading the values to hardware
      during pt_guest_enter().
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bd350d09
    • Sean Christopherson's avatar
      KVM: x86/mmu: Apply max PA check for MMIO sptes to 32-bit KVM · fce8d95c
      Sean Christopherson authored
      [ Upstream commit e30a7d62 ]
      
      Remove the bogus 64-bit only condition from the check that disables MMIO
      spte optimization when the system supports the max PA, i.e. doesn't have
      any reserved PA bits.  32-bit KVM always uses PAE paging for the shadow
      MMU, and per Intel's SDM:
      
        PAE paging translates 32-bit linear addresses to 52-bit physical
        addresses.
      
      The kernel's restrictions on max physical addresses are limits on how
      much memory the kernel can reasonably use, not what physical addresses
      are supported by hardware.
      
      Fixes: ce88decf ("KVM: MMU: mmio page fault support")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fce8d95c
    • Josef Bacik's avatar
      btrfs: flush write bio if we loop in extent_write_cache_pages · 8dc2210c
      Josef Bacik authored
      [ Upstream commit 42ffb0bf]
      
      There exists a deadlock with range_cyclic that has existed forever.  If
      we loop around with a bio already built we could deadlock with a writer
      who has the page locked that we're attempting to write but is waiting on
      a page in our bio to be written out.  The task traces are as follows
      
        PID: 1329874  TASK: ffff889ebcdf3800  CPU: 33  COMMAND: "kworker/u113:5"
         #0 [ffffc900297bb658] __schedule at ffffffff81a4c33f
         #1 [ffffc900297bb6e0] schedule at ffffffff81a4c6e3
         #2 [ffffc900297bb6f8] io_schedule at ffffffff81a4ca42
         #3 [ffffc900297bb708] __lock_page at ffffffff811f145b
         #4 [ffffc900297bb798] __process_pages_contig at ffffffff814bc502
         #5 [ffffc900297bb8c8] lock_delalloc_pages at ffffffff814bc684
         #6 [ffffc900297bb900] find_lock_delalloc_range at ffffffff814be9ff
         #7 [ffffc900297bb9a0] writepage_delalloc at ffffffff814bebd0
         #8 [ffffc900297bba18] __extent_writepage at ffffffff814bfbf2
         #9 [ffffc900297bba98] extent_write_cache_pages at ffffffff814bffbd
      
        PID: 2167901  TASK: ffff889dc6a59c00  CPU: 14  COMMAND:
        "aio-dio-invalid"
         #0 [ffffc9003b50bb18] __schedule at ffffffff81a4c33f
         #1 [ffffc9003b50bba0] schedule at ffffffff81a4c6e3
         #2 [ffffc9003b50bbb8] io_schedule at ffffffff81a4ca42
         #3 [ffffc9003b50bbc8] wait_on_page_bit at ffffffff811f24d6
         #4 [ffffc9003b50bc60] prepare_pages at ffffffff814b05a7
         #5 [ffffc9003b50bcd8] btrfs_buffered_write at ffffffff814b1359
         #6 [ffffc9003b50bdb0] btrfs_file_write_iter at ffffffff814b5933
         #7 [ffffc9003b50be38] new_sync_write at ffffffff8128f6a8
         #8 [ffffc9003b50bec8] vfs_write at ffffffff81292b9d
         #9 [ffffc9003b50bf00] ksys_pwrite64 at ffffffff81293032
      
      I used drgn to find the respective pages we were stuck on
      
      page_entry.page 0xffffea00fbfc7500 index 8148 bit 15 pid 2167901
      page_entry.page 0xffffea00f9bb7400 index 7680 bit 0 pid 1329874
      
      As you can see the kworker is waiting for bit 0 (PG_locked) on index
      7680, and aio-dio-invalid is waiting for bit 15 (PG_writeback) on index
      8148.  aio-dio-invalid has 7680, and the kworker epd looks like the
      following
      
        crash> struct extent_page_data ffffc900297bbbb0
        struct extent_page_data {
          bio = 0xffff889f747ed830,
          tree = 0xffff889eed6ba448,
          extent_locked = 0,
          sync_io = 0
        }
      
      Probably worth mentioning as well that it waits for writeback of the
      page to complete while holding a lock on it (at prepare_pages()).
      
      Using drgn I walked the bio pages looking for page
      0xffffea00fbfc7500 which is the one we're waiting for writeback on
      
        bio = Object(prog, 'struct bio', address=0xffff889f747ed830)
        for i in range(0, bio.bi_vcnt.value_()):
            bv = bio.bi_io_vec[i]
            if bv.bv_page.value_() == 0xffffea00fbfc7500:
      	  print("FOUND IT")
      
      which validated what I suspected.
      
      The fix for this is simple, flush the epd before we loop back around to
      the beginning of the file during writeout.
      
      Fixes: b293f02e ("Btrfs: Add writepages support")
      CC: stable@vger.kernel.org # 4.4+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8dc2210c
    • Marios Pomonis's avatar
      KVM: x86: Protect pmu_intel.c from Spectre-v1/L1TF attacks · 66b85556
      Marios Pomonis authored
      [ Upstream commit 66061740 ]
      
      This fixes Spectre-v1/L1TF vulnerabilities in intel_find_fixed_event()
      and intel_rdpmc_ecx_to_pmc().
      kvm_rdpmc() (ancestor of intel_find_fixed_event()) and
      reprogram_fixed_counter() (ancestor of intel_rdpmc_ecx_to_pmc()) are
      exported symbols so KVM should treat them conservatively from a security
      perspective.
      
      Fixes: 25462f7f ("KVM: x86/vPMU: Define kvm_pmu_ops to support vPMU function dispatch")
      Signed-off-by: default avatarNick Finco <nifi@google.com>
      Signed-off-by: default avatarMarios Pomonis <pomonis@google.com>
      Reviewed-by: default avatarAndrew Honig <ahonig@google.com>
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarJim Mattson <jmattson@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      66b85556
    • Claudiu Beznea's avatar
      drm: atmel-hlcdc: enable clock before configuring timing engine · 5d6e14f3
      Claudiu Beznea authored
      [ Upstream commit 2c1fb9d8 ]
      
      Changing pixel clock source without having this clock source enabled
      will block the timing engine and the next operations after (in this case
      setting ATMEL_HLCDC_CFG(5) settings in atmel_hlcdc_crtc_mode_set_nofb()
      will fail). It is recomended (although in datasheet this is not present)
      to actually enabled pixel clock source before doing any changes on timing
      enginge (only SAM9X60 datasheet specifies that the peripheral clock and
      pixel clock must be enabled before using LCD controller).
      
      Fixes: 1a396789 ("drm: add Atmel HLCDC Display Controller support")
      Signed-off-by: default avatarClaudiu Beznea <claudiu.beznea@microchip.com>
      Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
      Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
      Cc: <stable@vger.kernel.org> # v4.0+
      Link: https://patchwork.freedesktop.org/patch/msgid/1576672109-22707-3-git-send-email-claudiu.beznea@microchip.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      5d6e14f3
    • Filipe Manana's avatar
      Btrfs: fix race between adding and putting tree mod seq elements and nodes · 24e9e6bf
      Filipe Manana authored
      [ Upstream commit 7227ff4d ]
      
      There is a race between adding and removing elements to the tree mod log
      list and rbtree that can lead to use-after-free problems.
      
      Consider the following example that explains how/why the problems happens:
      
      1) Task A has mod log element with sequence number 200. It currently is
         the only element in the mod log list;
      
      2) Task A calls btrfs_put_tree_mod_seq() because it no longer needs to
         access the tree mod log. When it enters the function, it initializes
         'min_seq' to (u64)-1. Then it acquires the lock 'tree_mod_seq_lock'
         before checking if there are other elements in the mod seq list.
         Since the list it empty, 'min_seq' remains set to (u64)-1. Then it
         unlocks the lock 'tree_mod_seq_lock';
      
      3) Before task A acquires the lock 'tree_mod_log_lock', task B adds
         itself to the mod seq list through btrfs_get_tree_mod_seq() and gets a
         sequence number of 201;
      
      4) Some other task, name it task C, modifies a btree and because there
         elements in the mod seq list, it adds a tree mod elem to the tree
         mod log rbtree. That node added to the mod log rbtree is assigned
         a sequence number of 202;
      
      5) Task B, which is doing fiemap and resolving indirect back references,
         calls btrfs get_old_root(), with 'time_seq' == 201, which in turn
         calls tree_mod_log_search() - the search returns the mod log node
         from the rbtree with sequence number 202, created by task C;
      
      6) Task A now acquires the lock 'tree_mod_log_lock', starts iterating
         the mod log rbtree and finds the node with sequence number 202. Since
         202 is less than the previously computed 'min_seq', (u64)-1, it
         removes the node and frees it;
      
      7) Task B still has a pointer to the node with sequence number 202, and
         it dereferences the pointer itself and through the call to
         __tree_mod_log_rewind(), resulting in a use-after-free problem.
      
      This issue can be triggered sporadically with the test case generic/561
      from fstests, and it happens more frequently with a higher number of
      duperemove processes. When it happens to me, it either freezes the VM or
      it produces a trace like the following before crashing:
      
        [ 1245.321140] general protection fault: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC PTI
        [ 1245.321200] CPU: 1 PID: 26997 Comm: pool Not tainted 5.5.0-rc6-btrfs-next-52 #1
        [ 1245.321235] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-0-ga698c8995f-prebuilt.qemu.org 04/01/2014
        [ 1245.321287] RIP: 0010:rb_next+0x16/0x50
        [ 1245.321307] Code: ....
        [ 1245.321372] RSP: 0018:ffffa151c4d039b0 EFLAGS: 00010202
        [ 1245.321388] RAX: 6b6b6b6b6b6b6b6b RBX: ffff8ae221363c80 RCX: 6b6b6b6b6b6b6b6b
        [ 1245.321409] RDX: 0000000000000001 RSI: 0000000000000000 RDI: ffff8ae221363c80
        [ 1245.321439] RBP: ffff8ae20fcc4688 R08: 0000000000000002 R09: 0000000000000000
        [ 1245.321475] R10: ffff8ae20b120910 R11: 00000000243f8bb1 R12: 0000000000000038
        [ 1245.321506] R13: ffff8ae221363c80 R14: 000000000000075f R15: ffff8ae223f762b8
        [ 1245.321539] FS:  00007fdee1ec7700(0000) GS:ffff8ae236c80000(0000) knlGS:0000000000000000
        [ 1245.321591] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        [ 1245.321614] CR2: 00007fded4030c48 CR3: 000000021da16003 CR4: 00000000003606e0
        [ 1245.321642] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
        [ 1245.321668] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
        [ 1245.321706] Call Trace:
        [ 1245.321798]  __tree_mod_log_rewind+0xbf/0x280 [btrfs]
        [ 1245.321841]  btrfs_search_old_slot+0x105/0xd00 [btrfs]
        [ 1245.321877]  resolve_indirect_refs+0x1eb/0xc60 [btrfs]
        [ 1245.321912]  find_parent_nodes+0x3dc/0x11b0 [btrfs]
        [ 1245.321947]  btrfs_check_shared+0x115/0x1c0 [btrfs]
        [ 1245.321980]  ? extent_fiemap+0x59d/0x6d0 [btrfs]
        [ 1245.322029]  extent_fiemap+0x59d/0x6d0 [btrfs]
        [ 1245.322066]  do_vfs_ioctl+0x45a/0x750
        [ 1245.322081]  ksys_ioctl+0x70/0x80
        [ 1245.322092]  ? trace_hardirqs_off_thunk+0x1a/0x1c
        [ 1245.322113]  __x64_sys_ioctl+0x16/0x20
        [ 1245.322126]  do_syscall_64+0x5c/0x280
        [ 1245.322139]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
        [ 1245.322155] RIP: 0033:0x7fdee3942dd7
        [ 1245.322177] Code: ....
        [ 1245.322258] RSP: 002b:00007fdee1ec6c88 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
        [ 1245.322294] RAX: ffffffffffffffda RBX: 00007fded40210d8 RCX: 00007fdee3942dd7
        [ 1245.322314] RDX: 00007fded40210d8 RSI: 00000000c020660b RDI: 0000000000000004
        [ 1245.322337] RBP: 0000562aa89e7510 R08: 0000000000000000 R09: 00007fdee1ec6d44
        [ 1245.322369] R10: 0000000000000073 R11: 0000000000000246 R12: 00007fdee1ec6d48
        [ 1245.322390] R13: 00007fdee1ec6d40 R14: 00007fded40210d0 R15: 00007fdee1ec6d50
        [ 1245.322423] Modules linked in: ....
        [ 1245.323443] ---[ end trace 01de1e9ec5dff3cd ]---
      
      Fix this by ensuring that btrfs_put_tree_mod_seq() computes the minimum
      sequence number and iterates the rbtree while holding the lock
      'tree_mod_log_lock' in write mode. Also get rid of the 'tree_mod_seq_lock'
      lock, since it is now redundant.
      
      Fixes: bd989ba3 ("Btrfs: add tree modification log functions")
      Fixes: 097b8a7c ("Btrfs: join tree mod log code with the code holding back delayed refs")
      CC: stable@vger.kernel.org # 4.4+
      Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      24e9e6bf
    • David Sterba's avatar
      btrfs: remove trivial locking wrappers of tree mod log · a71561b9
      David Sterba authored
      [ Upstream commit b1a09f1e ]
      
      The wrappers are trivial and do not bring any extra value on top of the
      plain locking primitives.
      Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a71561b9
    • Anand Jain's avatar
      btrfs: use bool argument in free_root_pointers() · fb8c8121
      Anand Jain authored
      [ Upstream commit 4273eaff ]
      
      We don't need int argument bool shall do in free_root_pointers().  And
      rename the argument as it confused two people.
      Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
      Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fb8c8121
    • Filipe Manana's avatar
      Btrfs: fix assertion failure on fsync with NO_HOLES enabled · 131d3ff8
      Filipe Manana authored
      [ Upstream commit 0ccc3876 ]
      
      Back in commit a89ca6f2 ("Btrfs: fix fsync after truncate when
      no_holes feature is enabled") I added an assertion that is triggered when
      an inline extent is found to assert that the length of the (uncompressed)
      data the extent represents is the same as the i_size of the inode, since
      that is true most of the time I couldn't find or didn't remembered about
      any exception at that time. Later on the assertion was expanded twice to
      deal with a case of a compressed inline extent representing a range that
      matches the sector size followed by an expanding truncate, and another
      case where fallocate can update the i_size of the inode without adding
      or updating existing extents (if the fallocate range falls entirely within
      the first block of the file). These two expansion/fixes of the assertion
      were done by commit 7ed586d0 ("Btrfs: fix assertion on fsync of
      regular file when using no-holes feature") and commit 6399fb5a
      ("Btrfs: fix assertion failure during fsync in no-holes mode").
      These however missed the case where an falloc expands the i_size of an
      inode to exactly the sector size and inline extent exists, for example:
      
       $ mkfs.btrfs -f -O no-holes /dev/sdc
       $ mount /dev/sdc /mnt
      
       $ xfs_io -f -c "pwrite -S 0xab 0 1096" /mnt/foobar
       wrote 1096/1096 bytes at offset 0
       1 KiB, 1 ops; 0.0002 sec (4.448 MiB/sec and 4255.3191 ops/sec)
      
       $ xfs_io -c "falloc 1096 3000" /mnt/foobar
       $ xfs_io -c "fsync" /mnt/foobar
       Segmentation fault
      
       $ dmesg
       [701253.602385] assertion failed: len == i_size || (len == fs_info->sectorsize && btrfs_file_extent_compression(leaf, extent) != BTRFS_COMPRESS_NONE) || (len < i_size && i_size < fs_info->sectorsize), file: fs/btrfs/tree-log.c, line: 4727
       [701253.602962] ------------[ cut here ]------------
       [701253.603224] kernel BUG at fs/btrfs/ctree.h:3533!
       [701253.603503] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC PTI
       [701253.603774] CPU: 2 PID: 7192 Comm: xfs_io Tainted: G        W         5.0.0-rc8-btrfs-next-45 #1
       [701253.604054] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.11.2-0-gf9626ccb91-prebuilt.qemu-project.org 04/01/2014
       [701253.604650] RIP: 0010:assfail.constprop.23+0x18/0x1a [btrfs]
       (...)
       [701253.605591] RSP: 0018:ffffbb48c186bc48 EFLAGS: 00010286
       [701253.605914] RAX: 00000000000000de RBX: ffff921d0a7afc08 RCX: 0000000000000000
       [701253.606244] RDX: 0000000000000000 RSI: ffff921d36b16868 RDI: ffff921d36b16868
       [701253.606580] RBP: ffffbb48c186bcf0 R08: 0000000000000000 R09: 0000000000000000
       [701253.606913] R10: 0000000000000003 R11: 0000000000000000 R12: ffff921d05d2de18
       [701253.607247] R13: ffff921d03b54000 R14: 0000000000000448 R15: ffff921d059ecf80
       [701253.607769] FS:  00007f14da906700(0000) GS:ffff921d36b00000(0000) knlGS:0000000000000000
       [701253.608163] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       [701253.608516] CR2: 000056087ea9f278 CR3: 00000002268e8001 CR4: 00000000003606e0
       [701253.608880] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
       [701253.609250] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
       [701253.609608] Call Trace:
       [701253.609994]  btrfs_log_inode+0xdfb/0xe40 [btrfs]
       [701253.610383]  btrfs_log_inode_parent+0x2be/0xa60 [btrfs]
       [701253.610770]  ? do_raw_spin_unlock+0x49/0xc0
       [701253.611150]  btrfs_log_dentry_safe+0x4a/0x70 [btrfs]
       [701253.611537]  btrfs_sync_file+0x3b2/0x440 [btrfs]
       [701253.612010]  ? do_sysinfo+0xb0/0xf0
       [701253.612552]  do_fsync+0x38/0x60
       [701253.612988]  __x64_sys_fsync+0x10/0x20
       [701253.613360]  do_syscall_64+0x60/0x1b0
       [701253.613733]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
       [701253.614103] RIP: 0033:0x7f14da4e66d0
       (...)
       [701253.615250] RSP: 002b:00007fffa670fdb8 EFLAGS: 00000246 ORIG_RAX: 000000000000004a
       [701253.615647] RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007f14da4e66d0
       [701253.616047] RDX: 000056087ea9c260 RSI: 000056087ea9c260 RDI: 0000000000000003
       [701253.616450] RBP: 0000000000000001 R08: 0000000000000020 R09: 0000000000000010
       [701253.616854] R10: 000000000000009b R11: 0000000000000246 R12: 000056087ea9c260
       [701253.617257] R13: 000056087ea9c240 R14: 0000000000000000 R15: 000056087ea9dd10
       (...)
       [701253.619941] ---[ end trace e088d74f132b6da5 ]---
      
      Updating the assertion again to allow for this particular case would result
      in a meaningless assertion, plus there is currently no risk of logging
      content that would result in any corruption after a log replay if the size
      of the data encoded in an inline extent is greater than the inode's i_size
      (which is not currently possibe either with or without compression),
      therefore just remove the assertion.
      
      CC: stable@vger.kernel.org # 4.4+
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      131d3ff8
    • Eric Biggers's avatar
      ext4: fix deadlock allocating crypto bounce page from mempool · e0f95d89
      Eric Biggers authored
      [ Upstream commit 547c556f ]
      
      ext4_writepages() on an encrypted file has to encrypt the data, but it
      can't modify the pagecache pages in-place, so it encrypts the data into
      bounce pages and writes those instead.  All bounce pages are allocated
      from a mempool using GFP_NOFS.
      
      This is not correct use of a mempool, and it can deadlock.  This is
      because GFP_NOFS includes __GFP_DIRECT_RECLAIM, which enables the "never
      fail" mode for mempool_alloc() where a failed allocation will fall back
      to waiting for one of the preallocated elements in the pool.
      
      But since this mode is used for all a bio's pages and not just the
      first, it can deadlock waiting for pages already in the bio to be freed.
      
      This deadlock can be reproduced by patching mempool_alloc() to pretend
      that pool->alloc() always fails (so that it always falls back to the
      preallocations), and then creating an encrypted file of size > 128 KiB.
      
      Fix it by only using GFP_NOFS for the first page in the bio.  For
      subsequent pages just use GFP_NOWAIT, and if any of those fail, just
      submit the bio and start a new one.
      
      This will need to be fixed in f2fs too, but that's less straightforward.
      
      Fixes: c9af28fd ("ext4 crypto: don't let data integrity writebacks fail with ENOMEM")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Link: https://lore.kernel.org/r/20191231181149.47619-1-ebiggers@kernel.orgSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e0f95d89