All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Douglas Anderson <dianders@chromium.org>,
	Stephen Boyd <swboyd@chromium.org>,
	Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH 5.4 40/62] spi: spi-geni-qcom: Fix geni_spi_isr() NULL dereference in timeout case
Date: Sat, 16 Jan 2021 11:48:51 -0700	[thread overview]
Message-ID: <20210116184851.GA2491015@ubuntu-m3-large-x86> (raw)
In-Reply-To: <20210115122000.333323971@linuxfoundation.org>

On Fri, Jan 15, 2021 at 01:28:02PM +0100, Greg Kroah-Hartman wrote:
> From: Douglas Anderson <dianders@chromium.org>
> 
> commit 4aa1464acbe3697710279a4bd65cb4801ed30425 upstream.
> 
> In commit 7ba9bdcb91f6 ("spi: spi-geni-qcom: Don't keep a local state
> variable") we changed handle_fifo_timeout() so that we set
> "mas->cur_xfer" to NULL to make absolutely sure that we don't mess
> with the buffers from the previous transfer in the timeout case.
> 
> Unfortunately, this caused the IRQ handler to dereference NULL in some
> cases.  One case:
> 
>   CPU0                           CPU1
>   ----                           ----
>                                  setup_fifo_xfer()
>                                   geni_se_setup_m_cmd()
>                                  <hardware starts transfer>
>                                  <transfer completes in hardware>
>                                  <hardware sets M_RX_FIFO_WATERMARK_EN in m_irq>
>                                  ...
>                                  handle_fifo_timeout()
>                                   spin_lock_irq(mas->lock)
>                                   mas->cur_xfer = NULL
>                                   geni_se_cancel_m_cmd()
>                                   spin_unlock_irq(mas->lock)
> 
>   geni_spi_isr()
>    spin_lock(mas->lock)
>    if (m_irq & M_RX_FIFO_WATERMARK_EN)
>     geni_spi_handle_rx()
>      mas->cur_xfer NULL dereference!
> 
> tl;dr: Seriously delayed interrupts for RX/TX can lead to timeout
> handling setting mas->cur_xfer to NULL.
> 
> Let's check for the NULL transfer in the TX and RX cases and reset the
> watermark or clear out the fifo respectively to put the hardware back
> into a sane state.
> 
> NOTE: things still could get confused if we get timeouts all the way
> through handle_fifo_timeout() and then start a new transfer because
> interrupts from the old transfer / cancel / abort could still be
> pending.  A future patch will help this corner case.
> 
> Fixes: 561de45f72bd ("spi: spi-geni-qcom: Add SPI driver support for GENI based QUP")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> Reviewed-by: Stephen Boyd <swboyd@chromium.org>
> Link: https://lore.kernel.org/r/20201217142842.v3.1.I99ee04f0cb823415df59bd4f550d6ff5756e43d6@changeid
> Signed-off-by: Mark Brown <broonie@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> ---
>  drivers/spi/spi-geni-qcom.c |   14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> --- a/drivers/spi/spi-geni-qcom.c
> +++ b/drivers/spi/spi-geni-qcom.c
> @@ -415,6 +415,12 @@ static void geni_spi_handle_tx(struct sp
>  	unsigned int bytes_per_fifo_word = geni_byte_per_fifo_word(mas);
>  	unsigned int i = 0;
>  
> +	/* Stop the watermark IRQ if nothing to send */
> +	if (!mas->cur_xfer) {
> +		writel(0, se->base + SE_GENI_TX_WATERMARK_REG);
> +		return false;
> +	}
> +
>  	max_bytes = (mas->tx_fifo_depth - mas->tx_wm) * bytes_per_fifo_word;
>  	if (mas->tx_rem_bytes < max_bytes)
>  		max_bytes = mas->tx_rem_bytes;
> @@ -454,6 +460,14 @@ static void geni_spi_handle_rx(struct sp
>  		if (rx_last_byte_valid && rx_last_byte_valid < 4)
>  			rx_bytes -= bytes_per_fifo_word - rx_last_byte_valid;
>  	}
> +
> +	/* Clear out the FIFO and bail if nowhere to put it */
> +	if (!mas->cur_xfer) {
> +		for (i = 0; i < DIV_ROUND_UP(rx_bytes, bytes_per_fifo_word); i++)
> +			readl(se->base + SE_GENI_RX_FIFOn);
> +		return;
> +	}
> +
>  	if (mas->rx_rem_bytes < rx_bytes)
>  		rx_bytes = mas->rx_rem_bytes;
>  
> 
> 

This commit breaks the build with clang:

drivers/spi/spi-geni-qcom.c:421:3: error: void function
'geni_spi_handle_tx' should not return a value [-Wreturn-type]
                return false;
                ^      ~~~~~
1 error generated.

It looks like commit 6d66507d9b55 ("spi: spi-geni-qcom: Don't wait to
start 1st transfer if transmitting") would resolve this.

It might be worth picking up commit 172aad81a882 ("kbuild: enforce
-Werror=return-type") so that GCC behaves like clang does.

Cheers,
Nathan

  reply	other threads:[~2021-01-16 18:49 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 12:27 [PATCH 5.4 00/62] 5.4.90-rc1 review Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 01/62] x86/asm/32: Add ENDs to some functions and relabel with SYM_CODE_* Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 02/62] vfio iommu: Add dma available capability Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 03/62] net: cdc_ncm: correct overhead in delayed_ndp_size Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 04/62] net: hns3: fix the number of queues actually used by ARQ Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 05/62] net: hns3: fix a phy loopback fail issue Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 06/62] net: stmmac: dwmac-sun8i: Balance internal PHY resource references Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 07/62] net: stmmac: dwmac-sun8i: Balance internal PHY power Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 08/62] net: vlan: avoid leaks on register_vlan_dev() failures Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 09/62] net/sonic: Fix some resource leaks in error handling paths Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 10/62] net: ipv6: fib: flush exceptions when purging route Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 11/62] tools: selftests: add test for changing routes with PTMU exceptions Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 12/62] net: fix pmtu check in nopmtudisc mode Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 13/62] net: ip: always refragment ip defragmented packets Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 14/62] octeontx2-af: fix memory leak of lmac and lmac->name Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 15/62] nexthop: Fix off-by-one error in error path Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 16/62] nexthop: Unlink nexthop group entry " Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 17/62] s390/qeth: fix L2 header access in qeth_l3_osa_features_check() Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 18/62] net: dsa: lantiq_gswip: Exclude RMII from modes that report 1 GbE Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 19/62] net/mlx5: Use port_num 1 instead of 0 when delete a RoCE address Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 20/62] net/mlx5e: ethtool, Fix restriction of autoneg with 56G Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 21/62] chtls: Fix hardware tid leak Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 22/62] chtls: Remove invalid set_tcb call Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 23/62] chtls: Fix panic when route to peer not configured Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 24/62] chtls: Replace skb_dequeue with skb_peek Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 25/62] chtls: Added a check to avoid NULL pointer dereference Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 26/62] chtls: Fix chtls resources release sequence Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 27/62] x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 28/62] x86/resctrl: Dont move a task to the same resource group Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 29/62] exfat: Month timestamp metadata accidentally incremented Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 30/62] vmlinux.lds.h: Add PGO and AutoFDO input sections Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 31/62] iio: imu: st_lsm6dsx: fix edge-trigger interrupts Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 32/62] HID: wacom: Fix memory leakage caused by kfifo_alloc Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 33/62] ARM: OMAP2+: omap_device: fix idling of devices during probe Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 34/62] i2c: sprd: use a specific timeout to avoid system hang up issue Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 35/62] dmaengine: dw-edma: Fix use after free in dw_edma_alloc_chunk() Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 36/62] can: tcan4x5x: fix bittiming const, use common bittiming from m_can driver Greg Kroah-Hartman
2021-01-15 12:27 ` [PATCH 5.4 37/62] can: m_can: m_can_class_unregister(): remove erroneous m_can_clk_stop() Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 38/62] can: kvaser_pciefd: select CONFIG_CRC32 Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 39/62] cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get() Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 40/62] spi: spi-geni-qcom: Fix geni_spi_isr() NULL dereference in timeout case Greg Kroah-Hartman
2021-01-16 18:48   ` Nathan Chancellor [this message]
2021-01-17 12:54     ` Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 41/62] spi: stm32: FIFO threshold level - fix align packet size Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 42/62] i2c: i801: Fix the i2c-mux gpiod_lookup_table not being properly terminated Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 43/62] dmaengine: mediatek: mtk-hsdma: Fix a resource leak in the error handling path of the probe function Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 44/62] dmaengine: xilinx_dma: check dma_async_device_register return value Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 45/62] dmaengine: xilinx_dma: fix incompatible param warning in _child_probe() Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 46/62] dmaengine: xilinx_dma: fix mixed_enum_type coverity warning Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 47/62] qed: select CONFIG_CRC32 Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 48/62] wil6210: " Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 49/62] block: rsxx: " Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 50/62] lightnvm: " Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 51/62] iommu/intel: Fix memleak in intel_irq_remapping_alloc Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 52/62] bpftool: Fix compilation failure for net.o with older glibc Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 53/62] net/mlx5e: Fix memleak in mlx5e_create_l2_table_groups Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 54/62] net/mlx5e: Fix two double free cases Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 55/62] regmap: debugfs: Fix a memory leak when calling regmap_attach_dev Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 56/62] wan: ds26522: select CONFIG_BITREVERSE Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 57/62] regulator: qcom-rpmh-regulator: correct hfsmps515 definition Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 58/62] net: mvpp2: disable force link UP during port init procedure Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 59/62] KVM: arm64: Dont access PMCR_EL0 when no PMU is available Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 60/62] block: fix use-after-free in disk_part_iter_next Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 61/62] net: drop bogus skb with CHECKSUM_PARTIAL and offset beyond end of trimmed packet Greg Kroah-Hartman
2021-01-15 12:28 ` [PATCH 5.4 62/62] regmap: debugfs: Fix a reversed if statement in regmap_debugfs_init() Greg Kroah-Hartman
2021-01-15 16:19 ` [PATCH 5.4 00/62] 5.4.90-rc1 review Jon Hunter
2021-01-15 21:13 ` Shuah Khan
2021-01-15 21:19 ` Guenter Roeck
2021-01-16  4:17 ` Naresh Kamboju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210116184851.GA2491015@ubuntu-m3-large-x86 \
    --to=natechancellor@gmail.com \
    --cc=broonie@kernel.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=swboyd@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.