Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4601985pxj; Wed, 12 May 2021 09:02:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPyqRQR3wcFeQC/MRFhlQTsdsIICM9kiRYvheiAhXtG5UWgrxLzG3BA6AVqyAvxzfLXOy1 X-Received: by 2002:aca:d610:: with SMTP id n16mr7779676oig.112.1620835372213; Wed, 12 May 2021 09:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835372; cv=none; d=google.com; s=arc-20160816; b=I4eP4cEiDjgJBJowf0NVBubbevCE31HFAm2JVuCgBRFeu+u79verSJ+UmRgs/n+HAt 0Pxb9tjQBrHEwZEg3KJZb+y8qzJTmXozVfsvnoojpk6nokYX8XB4+a90gKm/qZKiQo5g rW+OaAwo1LLaTuSQb3UswIVIe6ERGKLvYq3zNSvu5ADa5+DdLtZ1yy98Y0SqJirkye5w je8BoEu5VJMlt2890m+yKl3vBc++D/OudlB53JCJURoBV9Zy0pnjQ37gesbSeGmol8pv W3MPaulN9TIWCtNRtS83auzeEODGuT3LL6apO/dJmmhJVOE8LcceplrRNstkp08z7Co5 NEZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4HCddOtoAIsiIZvftYhFEO50ogJmhlXJj7NHhk2ta04=; b=gFzYV7o9Sgf6WEVmM+M6lq1ZyZ3LgJwdxLWbukofaXlCQfKYrDETeYscnd4FTEuQq3 6XxJlTVsUv3lOUR46q2bBouhbjgPY6wKcUgcncvJko7pzX2AaiJOXplGhUx/Ibxuzibo 1awrII/SSSrHAPkoDCQLKEzOchqltsCem/1xR0E4qDsuQsC0bq1lfaVS6MmqPkZ3PaP4 Dp2jLMwxTa/YfBcKXDv3hCt5BtDmn1aK+gqfsteZJ9tf0RBuEbkynuEk3oGh51f0tEJM 75sU/86K/qF2p45HO5zJUqigEnlhc4fyq2mekYzZNGd3sQDlAdlEE2agznHTJYdPLXm1 ZduA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C1qGDGad; 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 t17si217703oif.261.2021.05.12.09.02.37; Wed, 12 May 2021 09:02:52 -0700 (PDT) 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=C1qGDGad; 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 S234435AbhELQBo (ORCPT + 99 others); Wed, 12 May 2021 12:01:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:40904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235493AbhELP2N (ORCPT ); Wed, 12 May 2021 11:28:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1DDBC61A2D; Wed, 12 May 2021 15:13:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832400; bh=bipMomk1GdGdN94LjQeuhOQ/x+1wMLC7ZtoquWDh69U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C1qGDGadOk4VpCQ6sQ531xEVhsg4knJYX0s5YSh2IEQt6gMHR0MXcxBdZfweDVJHA FDo1eFZMrQUQtncyInVlhMhxsEsjRsAj8SxFMfLYAuIY86H+CamW392HmYvR48P4mk UeuJQom2pyclAlBsjr9QdTObe7NENsZrwb+J/kPE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Quanyang Wang , Mark Brown , Sasha Levin Subject: [PATCH 5.10 265/530] spi: spi-zynqmp-gqspi: return -ENOMEM if dma_map_single fails Date: Wed, 12 May 2021 16:46:15 +0200 Message-Id: <20210512144828.531271321@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quanyang Wang [ Upstream commit 126bdb606fd2802454e6048caef1be3e25dd121e ] The spi controller supports 44-bit address space on AXI in DMA mode, so set dma_addr_t width to 44-bit to avoid using a swiotlb mapping. In addition, if dma_map_single fails, it should return immediately instead of continuing doing the DMA operation which bases on invalid address. This fixes the following crash which occurs in reading a big block from flash: [ 123.633577] zynqmp-qspi ff0f0000.spi: swiotlb buffer is full (sz: 4194304 bytes), total 32768 (slots), used 0 (slots) [ 123.644230] zynqmp-qspi ff0f0000.spi: ERR:rxdma:memory not mapped [ 123.784625] Unable to handle kernel paging request at virtual address 00000000003fffc0 [ 123.792536] Mem abort info: [ 123.795313] ESR = 0x96000145 [ 123.798351] EC = 0x25: DABT (current EL), IL = 32 bits [ 123.803655] SET = 0, FnV = 0 [ 123.806693] EA = 0, S1PTW = 0 [ 123.809818] Data abort info: [ 123.812683] ISV = 0, ISS = 0x00000145 [ 123.816503] CM = 1, WnR = 1 [ 123.819455] user pgtable: 4k pages, 48-bit VAs, pgdp=0000000805047000 [ 123.825887] [00000000003fffc0] pgd=0000000803b45003, p4d=0000000803b45003, pud=0000000000000000 [ 123.834586] Internal error: Oops: 96000145 [#1] PREEMPT SMP Fixes: 1c26372e5aa9 ("spi: spi-zynqmp-gqspi: Update driver to use spi-mem framework") Signed-off-by: Quanyang Wang Link: https://lore.kernel.org/r/20210416004652.2975446-6-quanyang.wang@windriver.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-zynqmp-gqspi.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 2a0be16b2eb0..1dd2af9cc237 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -731,7 +731,7 @@ static irqreturn_t zynqmp_qspi_irq(int irq, void *dev_id) * zynqmp_qspi_setuprxdma - This function sets up the RX DMA operation * @xqspi: xqspi is a pointer to the GQSPI instance. */ -static void zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) +static int zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) { u32 rx_bytes, rx_rem, config_reg; dma_addr_t addr; @@ -745,7 +745,7 @@ static void zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, config_reg); xqspi->mode = GQSPI_MODE_IO; xqspi->dma_rx_bytes = 0; - return; + return 0; } rx_rem = xqspi->bytes_to_receive % 4; @@ -753,8 +753,10 @@ static void zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) addr = dma_map_single(xqspi->dev, (void *)xqspi->rxbuf, rx_bytes, DMA_FROM_DEVICE); - if (dma_mapping_error(xqspi->dev, addr)) + if (dma_mapping_error(xqspi->dev, addr)) { dev_err(xqspi->dev, "ERR:rxdma:memory not mapped\n"); + return -ENOMEM; + } xqspi->dma_rx_bytes = rx_bytes; xqspi->dma_addr = addr; @@ -775,6 +777,8 @@ static void zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) /* Write the number of bytes to transfer */ zynqmp_gqspi_write(xqspi, GQSPI_QSPIDMA_DST_SIZE_OFST, rx_bytes); + + return 0; } /** @@ -811,11 +815,17 @@ static void zynqmp_qspi_write_op(struct zynqmp_qspi *xqspi, u8 tx_nbits, * @genfifoentry: genfifoentry is pointer to the variable in which * GENFIFO mask is returned to calling function */ -static void zynqmp_qspi_read_op(struct zynqmp_qspi *xqspi, u8 rx_nbits, +static int zynqmp_qspi_read_op(struct zynqmp_qspi *xqspi, u8 rx_nbits, u32 genfifoentry) { - zynqmp_qspi_setuprxdma(xqspi); + int ret; + + ret = zynqmp_qspi_setuprxdma(xqspi); + if (ret) + return ret; zynqmp_qspi_fillgenfifo(xqspi, rx_nbits, genfifoentry); + + return 0; } /** @@ -1029,8 +1039,11 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, xqspi->rxbuf = (u8 *)op->data.buf.in; xqspi->bytes_to_receive = op->data.nbytes; xqspi->bytes_to_transfer = 0; - zynqmp_qspi_read_op(xqspi, op->data.buswidth, + err = zynqmp_qspi_read_op(xqspi, op->data.buswidth, genfifoentry); + if (err) + goto return_err; + zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, zynqmp_gqspi_read (xqspi, GQSPI_CONFIG_OFST) | @@ -1152,6 +1165,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) goto clk_dis_all; } + dma_set_mask(&pdev->dev, DMA_BIT_MASK(44)); ctlr->bits_per_word_mask = SPI_BPW_MASK(8); ctlr->num_chipselect = GQSPI_DEFAULT_NUM_CS; ctlr->mem_ops = &zynqmp_qspi_mem_ops; -- 2.30.2