Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1336439pxb; Sun, 17 Jan 2021 05:27:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJcbS3idHi3M83bCdGUYYWs1bOKokk1tFhXnzHQbpa9h0rjFxqSZybZHvmWf2DNAT8fOFE X-Received: by 2002:a17:906:a284:: with SMTP id i4mr9113894ejz.124.1610890055043; Sun, 17 Jan 2021 05:27:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610890055; cv=none; d=google.com; s=arc-20160816; b=0LiEnjpKW8ZXAWVgdgBY6994qFZLOLl0IIfznf+MXbfDyHECFqaI5cuElxw6PC08Wz KJtr2Et05QigWAdpzmUyJfqiadxMlZ121aM1oKom7JQe/M9hg25YY+Y84JSDx/psKSQY FOENFQfdYQToFsgbwxHPNZmlLMDcdrj8Gi/ugQ1uSRH1awGHwVYf64D6fFQqSTQgEhgZ 8clkJcLElZZfcO7QcSsIun89MUOwAIkwV5N5i/PQ+N7d7mDs9pVHAcxLyIgE1M8461r/ RtlBilSAVLU4kfekT1UejeZWoRf4Kp54zZzkzDoS0v0LUF8u1u56TyjCD9NC7uKzppvk wmog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kxU60hmCV0BG/dYwkJYi98vgvN0YL1wIQa10nT9yhFo=; b=H58wFpzXo87kLJ64hJIRhSvr4OXKYYMdsfq/sdOnvm3OLLcJPMoMqD74ZlKwZgLPaS xjMmG9k1HZCRfkdLn4iZOy/+rp+olJFgGUnqNVEEnSX847za+PKpNfz4wJ7hFoDnHFmp aBY1BfKybYzw1uFp8gCRppedYqiHBD+/ES0yTel1GhLFSP92rYlmt4G5oITR+mAK3emG bB/nX6+RH0XNIRF36xSCBlKO0wuJS+//aZekrGLnmw/SR0p95zbt5UacySaeuBhBrEZU MZNvVhOfSaLj+1VaBEmAwjAHci4UIttbrnKht9whEcprX0uoJNfDShuEDOLvpt8qCI2a 2lwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UoqMHdLR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g16si276399edv.364.2021.01.17.05.27.11; Sun, 17 Jan 2021 05:27:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UoqMHdLR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728552AbhAQMyv (ORCPT + 99 others); Sun, 17 Jan 2021 07:54:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:44480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726209AbhAQMyu (ORCPT ); Sun, 17 Jan 2021 07:54:50 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 435CC2076A; Sun, 17 Jan 2021 12:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610888049; bh=OXM4XbMJ6QQVz8VYx4+SysOclFuL8aP8ZUCK9YtR55M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UoqMHdLR2pouvFP/08J8Xb8te1Iq+jy+o6sqiPO59kzUrIdzIQanw1YGuwERRGi7t Qh5KhTXbzRr5ovnzvKfOhN4es6HgQWDcz0evqpcqsD87IH5Tjb7g0QjWJ/3dRwYBop hDBn/sS+ZTTEE5KKxU6mglJqsA2nWKNikWa8h4cg= Date: Sun, 17 Jan 2021 13:54:07 +0100 From: Greg Kroah-Hartman To: Nathan Chancellor Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Douglas Anderson , Stephen Boyd , Mark Brown Subject: Re: [PATCH 5.4 40/62] spi: spi-geni-qcom: Fix geni_spi_isr() NULL dereference in timeout case Message-ID: References: <20210115121958.391610178@linuxfoundation.org> <20210115122000.333323971@linuxfoundation.org> <20210116184851.GA2491015@ubuntu-m3-large-x86> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210116184851.GA2491015@ubuntu-m3-large-x86> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 16, 2021 at 11:48:51AM -0700, Nathan Chancellor wrote: > On Fri, Jan 15, 2021 at 01:28:02PM +0100, Greg Kroah-Hartman wrote: > > From: Douglas Anderson > > > > 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() > > > > > > > > ... > > 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 > > Reviewed-by: Stephen Boyd > > Link: https://lore.kernel.org/r/20201217142842.v3.1.I99ee04f0cb823415df59bd4f550d6ff5756e43d6@changeid > > Signed-off-by: Mark Brown > > Signed-off-by: Greg Kroah-Hartman > > > > --- > > 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. Argh, I thought I had dropped this before, but no. Good catch, I've dropped it now. And yes, that might be a good patch to backport (the gcc one), I'll queue that up next round, thanks. greg k-h