Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: spi-zynqmp-gqspi: return -ENOMEM if dma_map_single fails

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 <quanyang.wang@windriver.com>
Link: https://lore.kernel.org/r/20210416004652.2975446-6-quanyang.wang@windriver.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Quanyang Wang and committed by
Mark Brown
126bdb60 a2c5bedb

+20 -6
+20 -6
drivers/spi/spi-zynqmp-gqspi.c
··· 733 733 * zynqmp_qspi_setuprxdma - This function sets up the RX DMA operation 734 734 * @xqspi: xqspi is a pointer to the GQSPI instance. 735 735 */ 736 - static void zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) 736 + static int zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) 737 737 { 738 738 u32 rx_bytes, rx_rem, config_reg; 739 739 dma_addr_t addr; ··· 747 747 zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, config_reg); 748 748 xqspi->mode = GQSPI_MODE_IO; 749 749 xqspi->dma_rx_bytes = 0; 750 - return; 750 + return 0; 751 751 } 752 752 753 753 rx_rem = xqspi->bytes_to_receive % 4; ··· 755 755 756 756 addr = dma_map_single(xqspi->dev, (void *)xqspi->rxbuf, 757 757 rx_bytes, DMA_FROM_DEVICE); 758 - if (dma_mapping_error(xqspi->dev, addr)) 758 + if (dma_mapping_error(xqspi->dev, addr)) { 759 759 dev_err(xqspi->dev, "ERR:rxdma:memory not mapped\n"); 760 + return -ENOMEM; 761 + } 760 762 761 763 xqspi->dma_rx_bytes = rx_bytes; 762 764 xqspi->dma_addr = addr; ··· 779 777 780 778 /* Write the number of bytes to transfer */ 781 779 zynqmp_gqspi_write(xqspi, GQSPI_QSPIDMA_DST_SIZE_OFST, rx_bytes); 780 + 781 + return 0; 782 782 } 783 783 784 784 /** ··· 817 813 * @genfifoentry: genfifoentry is pointer to the variable in which 818 814 * GENFIFO mask is returned to calling function 819 815 */ 820 - static void zynqmp_qspi_read_op(struct zynqmp_qspi *xqspi, u8 rx_nbits, 816 + static int zynqmp_qspi_read_op(struct zynqmp_qspi *xqspi, u8 rx_nbits, 821 817 u32 genfifoentry) 822 818 { 823 - zynqmp_qspi_setuprxdma(xqspi); 819 + int ret; 820 + 821 + ret = zynqmp_qspi_setuprxdma(xqspi); 822 + if (ret) 823 + return ret; 824 824 zynqmp_qspi_fillgenfifo(xqspi, rx_nbits, genfifoentry); 825 + 826 + return 0; 825 827 } 826 828 827 829 /** ··· 1041 1031 xqspi->rxbuf = (u8 *)op->data.buf.in; 1042 1032 xqspi->bytes_to_receive = op->data.nbytes; 1043 1033 xqspi->bytes_to_transfer = 0; 1044 - zynqmp_qspi_read_op(xqspi, op->data.buswidth, 1034 + err = zynqmp_qspi_read_op(xqspi, op->data.buswidth, 1045 1035 genfifoentry); 1036 + if (err) 1037 + goto return_err; 1038 + 1046 1039 zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, 1047 1040 zynqmp_gqspi_read 1048 1041 (xqspi, GQSPI_CONFIG_OFST) | ··· 1172 1159 goto clk_dis_all; 1173 1160 } 1174 1161 1162 + dma_set_mask(&pdev->dev, DMA_BIT_MASK(44)); 1175 1163 ctlr->bits_per_word_mask = SPI_BPW_MASK(8); 1176 1164 ctlr->num_chipselect = GQSPI_DEFAULT_NUM_CS; 1177 1165 ctlr->mem_ops = &zynqmp_qspi_mem_ops;