Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760563AbcLWIxN (ORCPT ); Fri, 23 Dec 2016 03:53:13 -0500 Received: from mail-sn1nam01on0057.outbound.protection.outlook.com ([104.47.32.57]:63689 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757336AbcLWIwc (ORCPT ); Fri, 23 Dec 2016 03:52:32 -0500 Authentication-Results: spf=pass (sender IP is 149.199.60.100) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; From: Kedareswara rao Appana To: , , , , , , , , CC: , , Subject: [PATCH v2 3/3] dmaengine: xilinx_dma: Fix race condition in the driver for multiple descriptor scenario Date: Fri, 23 Dec 2016 14:22:15 +0530 Message-ID: <1482483135-14767-4-git-send-email-appanad@xilinx.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1482483135-14767-1-git-send-email-appanad@xilinx.com> References: <1482483135-14767-1-git-send-email-appanad@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.0.0.1202-22778.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.100;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(7916002)(39410400002)(39450400003)(39840400002)(39860400002)(39850400002)(2980300002)(438002)(199003)(189002)(36756003)(5003940100001)(2906002)(4326007)(6666003)(2950100002)(356003)(76176999)(50986999)(8676002)(81166006)(81156014)(8936002)(5001770100001)(36386004)(50226002)(2201001)(50466002)(5660300001)(189998001)(626004)(92566002)(48376002)(305945005)(33646002)(551934003)(90966002)(45336002)(47776003)(46386002)(63266004)(38730400001)(42186005)(52956003)(103686003)(106466001)(107986001)(2101003)(5001870100001);DIR:OUT;SFP:1101;SCL:1;SRVR:CO1PR02MB208;H:xsj-pvapsmtpgw02;FPR:;SPF:Pass;PTR:xapps1.xilinx.com,unknown-60-100.xilinx.com;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2NAM02FT004;1:qHP90DXX1uVI8HahW//qw2cHsGMXkG+5yLDJtkXEX+pRPRU8nDM2ZW2OoPm5wwYHcUHJOdE841eFY15nA1TKmwjFeeMk+9gfohNBZbNfP2UioTdUZhpUWD32Mb7H2eh5R/0lUr7LT90xW4VMIdsHZZhhClUPu8W6O8rPtE+MoJdQbSrTUgFGUOcpejrenUbTHqQi1xbPyaS96zoV69RCjxy5aofa6wgUVuXJf0k3gJYzKJR5B2nGcpa7rnd9NDsPPYlyIxZ04rPyVSiBb3eMyHCbhepIuFUtZnh9atL2YWfjWTyofv3FAi7tF3/HQHQw6TS2iWHIh7LQlgl0EqpUU0cCa2v3oQHJSKSqy8utGN02UfcYi1p54v8m8SQtZLiZPpNeFw3xUGO4Bz31eKKTAmQ3Xztsj3iO8se8jSApKKLVAZxwrZyO8f4U1y+65d0nvztKaJIPYtvpp7h3wFaHm2RpvN7rj+eCSSLsn7wyKxFjibHJLawl0EvHSWVwy/XiDu9WqYGAwVihTfzziYQ7nlFuOfoK0Qn7uunaeK6sOyuXmazlASvchk7c0Xom1A2MsBJ3b/prrbdxpkxdFSDh1xLvrMIhp+cKwcxbcmmr59g/Vk/mqWZOQL6/0keL3YeLwhHR9gFdj6yA1taGpTk9oA== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: ad18928f-7859-4b23-05c1-08d42b1106ea X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(8251501002);SRVR:CO1PR02MB208; X-Microsoft-Exchange-Diagnostics: 1;CO1PR02MB208;3:SviQSIo2QEQ7W7dmtdvRQhOhauS7PmnfrhPDGI7kacBrh5FceFetdpywa34v3MuE5wBib3/7qyV0qYZWzKdZQb2M0+W8b3I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DSdhd0HGiv0xTeNpEf82x3a3q1agfFmibc2LbY3tC5DVCbKn3sNzGty1rA1oQMVY8NV4NCgcaKR1eVI06k2A7vSnPLuAQGXXxI0hK344ZqIe87FgvvAZu1L+w= X-Microsoft-Exchange-Diagnostics: 1;CO1PR02MB208;31:XxCcGh5PtgtS5/wbO35BnZvOJmrxXCT3wY43URBNKmMqkr20h50rW9xwftuV3alkrFIrbavJCGugoQAmjvLh0ZR4ssF6Iq2Jadt9J/XALHEZo34jBvEOz89QxW60Cim20hb6n53urJspuLFjzm9YgOEVpfL8DNqX75ntxPEUp28jbMqXxMGGKpSHevzMSFcNzAVRdlvCcle2nARaGrF8kqwlEydfMpSvkREN7f6oUmRIsSfhK2GyVSRFoYy6HAizETgogN/hP5EDmJKNIWRBFQ==;20:flqKIewq5OKUnj2sgNa+yg/+hOtPfgYVtZPbyRW7PjG/vl+ASLFXLqVgsE0y1HdY2rp+mjIEnjdQj53GROnONiVd4FWRmb2R7HNW8Wwhqonau0rdALiVohu23eJF6EZRUTSrQq1+DUCBQLwOemoNozUd79pVS5YnbZxXfBTkzCR2mxOtxEVgwCg1aJyXd4rXAfOa+e6Gl3w1CaTdrk9lgPiMhFzu/sxILDq6CRyF08bzYlrqf8GHGGhUFYQWIUweRo2Rr5NFrWrwuHZuYuLuA7Tq/xUg9YBhekmoyqdqjA1UxDNkmoJqKXOPJ1suJnaFyCBu8fQlvsfziYket692qN+aqZyopfK9lONWXJow8BmfOf9i+2U81kf9vaf0Uq+cCk9q/WNVXExLUxnI4elhKoto4vBARoqP0TMUHPZbljMfuadK38ovr7LjLGf5OMVFIy4td75QPZLxG/nzUmP2On+vXhvjLWGCrR2cSyjz09EbEuriDgFUI0duw5ZehiHo X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(13017025)(13024025)(13023025)(13015025)(13018025)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123564025)(20161123562025)(20161123555025)(6072148);SRVR:CO1PR02MB208;BCL:0;PCL:0;RULEID:;SRVR:CO1PR02MB208; X-Microsoft-Exchange-Diagnostics: 1;CO1PR02MB208;4:ceHffomaL0FCiE13ergzp0HbsbSJCPQwqIGzBTKZONwWNO+3Q4hBZr95O9JpOUWT4icRH3TwWFq1+Hajdr6bi9IM2XkAU+DZBIsYQk9FOQjCD23yss/sKy8y3ed51tdrjAYOrTq+ixsGlO12gnaoUgpt8WfQgvDSy5MhWnY+1x3E+BMhWF6jVta6llpeRfX8OAoIwPPU278u0wXDGLAaVHvrXsvQs/XvofaGTDynRAkH57WuzBnQLP4uWuHB6D+J41SAO4aule4T7LHP8Cf3Ran+e1KCebGWBnRy8c45nbwcRcf+Y1RtbjKKY63lWFvaTmJs4pxTiVVldx7sFtMsJCskcoKYCj9GQfjQb7B9W31jJaUiyTHqH8iqhEjRsIFifwwPELSrFxTjOfRQ2p6YHI2JgrMZ964xFEyKN0NjVF5rCe7gk/QYiccJEkapqiGUu7AIkr1FVl7IseDUntlnFpFzbFe9ZNhch/mG1KVfYGD8HOd8m3fjs7f+wgcfYUzz2iRO/IFULKJi3nbEyeLBuejlIx8VFf3qHLIqdO23Z96lFL2TsGwaqNZ4NEAKJX/3Z3hfq6ive1mtTfhV/Iy48AUZqKrbmOiaLicidudz6GstL5yLn26i3bI3owxUi0L9kEsS3nBI3/36Md4KKAidpwWGpB4HxXAJ6RMFMG2NIhVlVCyJ01E4Ne6szkokszGjt6hKjDrNgMTqtkhJ7xLclC/K9a5dVTJDKMceEEi/hyc= X-Forefront-PRVS: 016572D96D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CO1PR02MB208;23:r94RcNPr8L/o/NyjxpzIZb4n9vBQNXLAs5fc0CD+bR?= =?us-ascii?Q?rlQBZ0hgcpi4qELIuhHIHud++F+O72oJ7eaOrikxGvL+Kkg9qpwBnnYx03Kl?= =?us-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wXb84M7kgptocdoHTWbRUY5Gc4+H3j+0jRBzRY/cjT4x5w9F7+SEWwjJv872SErX7fSI7dilRYmYUiqHXYIk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CO1PR02MB208;7:GYxkv/l3s1VH9SRGNkqpXiQTf5TeXAMeTdxDIpL7XF5bIS9ND1yBn4euzg71UKXeDd50bKf7rPhQIwDGVXpWHs3HJqtx4lAvtia22Lb3WapEANOSplf3ZKJcgYp+08MH7kwKOhIeHn32NgBXuKarRVSSHK3UsNOmNp9fPd12hZgIUq/uj197KJFSTHPusFYfu3jTUEVAfAMLV+r/hrGCw6ZStLZMEHhODU9Pr2bnDtFD6pHSaN8t4iFKBenICOgiR80DV3xxzzSxIiPZ0WNQXDDuXwNAeWbcCrOW/8TYfZH9+BjcIt++SzCba1n4O5XAigFbcSAht4Mn21DqnTXgi0PyuTxvIVcqqsFNr/gd9Q1JkBXIZFPu1ejtWfQTNNCuOw5cbgJPkXZxZ0wgC9yyJg0JPAXVGqEh1G/r6aB5Hep17Z5OCBoaygbMp0qLltcRketBuPZMjBzctEvCC4Sm+g== X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Dec 2016 08:52:29.2302 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.100];Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR02MB208 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10412 Lines: 300 When driver is handling AXI DMA SoftIP When user submits multiple descriptors back to back on the S2MM(recv) side with the current driver flow the last buffer descriptor next bd points to a invalid location resulting the invalid data or errors in the DMA engine. This patch fixes this issue by creating a BD Chain during channel allocation itself and use those BD's. Signed-off-by: Kedareswara rao Appana --- Changes for v2: ---> None. drivers/dma/xilinx/xilinx_dma.c | 133 +++++++++++++++++++++++++--------------- 1 file changed, 83 insertions(+), 50 deletions(-) diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c index cf9edd8..850de1d 100644 --- a/drivers/dma/xilinx/xilinx_dma.c +++ b/drivers/dma/xilinx/xilinx_dma.c @@ -163,6 +163,7 @@ #define XILINX_DMA_BD_SOP BIT(27) #define XILINX_DMA_BD_EOP BIT(26) #define XILINX_DMA_COALESCE_MAX 255 +#define XILINX_DMA_NUM_DESCS 255 #define XILINX_DMA_NUM_APP_WORDS 5 /* Multi-Channel DMA Descriptor offsets*/ @@ -310,6 +311,7 @@ struct xilinx_dma_tx_descriptor { * @pending_list: Descriptors waiting * @active_list: Descriptors ready to submit * @done_list: Complete descriptors + * @free_seg_list: Free descriptors * @common: DMA common channel * @desc_pool: Descriptors pool * @dev: The dma device @@ -330,7 +332,9 @@ struct xilinx_dma_tx_descriptor { * @desc_submitcount: Descriptor h/w submitted count * @residue: Residue for AXI DMA * @seg_v: Statically allocated segments base + * @seg_p: Physical allocated segments base * @cyclic_seg_v: Statically allocated segment base for cyclic transfers + * @cyclic_seg_p: Physical allocated segments base for cyclic dma * @start_transfer: Differentiate b/w DMA IP's transfer */ struct xilinx_dma_chan { @@ -341,6 +345,7 @@ struct xilinx_dma_chan { struct list_head pending_list; struct list_head active_list; struct list_head done_list; + struct list_head free_seg_list; struct dma_chan common; struct dma_pool *desc_pool; struct device *dev; @@ -361,7 +366,9 @@ struct xilinx_dma_chan { u32 desc_submitcount; u32 residue; struct xilinx_axidma_tx_segment *seg_v; + dma_addr_t seg_p; struct xilinx_axidma_tx_segment *cyclic_seg_v; + dma_addr_t cyclic_seg_p; void (*start_transfer)(struct xilinx_dma_chan *chan); u16 tdest; }; @@ -567,17 +574,31 @@ static struct xilinx_axidma_tx_segment * xilinx_axidma_alloc_tx_segment(struct xilinx_dma_chan *chan) { struct xilinx_axidma_tx_segment *segment; - dma_addr_t phys; - - segment = dma_pool_zalloc(chan->desc_pool, GFP_ATOMIC, &phys); - if (!segment) - return NULL; + unsigned long flags; - segment->phys = phys; + spin_lock_irqsave(&chan->lock, flags); + if (!list_empty(&chan->free_seg_list)) { + segment = list_first_entry(&chan->free_seg_list, + struct xilinx_axidma_tx_segment, + node); + list_del(&segment->node); + } + spin_unlock_irqrestore(&chan->lock, flags); return segment; } +static void xilinx_dma_clean_hw_desc(struct xilinx_axidma_desc_hw *hw) +{ + u32 next_desc = hw->next_desc; + u32 next_desc_msb = hw->next_desc_msb; + + memset(hw, 0, sizeof(struct xilinx_axidma_desc_hw)); + + hw->next_desc = next_desc; + hw->next_desc_msb = next_desc_msb; +} + /** * xilinx_dma_free_tx_segment - Free transaction segment * @chan: Driver specific DMA channel @@ -586,7 +607,9 @@ xilinx_axidma_alloc_tx_segment(struct xilinx_dma_chan *chan) static void xilinx_dma_free_tx_segment(struct xilinx_dma_chan *chan, struct xilinx_axidma_tx_segment *segment) { - dma_pool_free(chan->desc_pool, segment, segment->phys); + xilinx_dma_clean_hw_desc(&segment->hw); + + list_add_tail(&segment->node, &chan->free_seg_list); } /** @@ -711,16 +734,26 @@ static void xilinx_dma_free_descriptors(struct xilinx_dma_chan *chan) static void xilinx_dma_free_chan_resources(struct dma_chan *dchan) { struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); + unsigned long flags; dev_dbg(chan->dev, "Free all channel resources.\n"); xilinx_dma_free_descriptors(chan); + if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { - xilinx_dma_free_tx_segment(chan, chan->cyclic_seg_v); - xilinx_dma_free_tx_segment(chan, chan->seg_v); + spin_lock_irqsave(&chan->lock, flags); + INIT_LIST_HEAD(&chan->free_seg_list); + spin_unlock_irqrestore(&chan->lock, flags); + + /* Free Memory that is allocated for cyclic DMA Mode */ + dma_free_coherent(chan->dev, sizeof(*chan->cyclic_seg_v), + chan->cyclic_seg_v, chan->cyclic_seg_p); + } + + if (chan->xdev->dma_config->dmatype != XDMA_TYPE_AXIDMA) { + dma_pool_destroy(chan->desc_pool); + chan->desc_pool = NULL; } - dma_pool_destroy(chan->desc_pool); - chan->desc_pool = NULL; } /** @@ -803,6 +836,7 @@ static void xilinx_dma_do_tasklet(unsigned long data) static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan) { struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); + int i; /* Has this channel already been allocated? */ if (chan->desc_pool) @@ -813,11 +847,30 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan) * for meeting Xilinx VDMA specification requirement. */ if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { - chan->desc_pool = dma_pool_create("xilinx_dma_desc_pool", - chan->dev, - sizeof(struct xilinx_axidma_tx_segment), - __alignof__(struct xilinx_axidma_tx_segment), - 0); + /* Allocate the buffer descriptors. */ + chan->seg_v = dma_zalloc_coherent(chan->dev, + sizeof(*chan->seg_v) * + XILINX_DMA_NUM_DESCS, + &chan->seg_p, GFP_KERNEL); + if (!chan->seg_v) { + dev_err(chan->dev, + "unable to allocate channel %d descriptors\n", + chan->id); + return -ENOMEM; + } + + for (i = 0; i < XILINX_DMA_NUM_DESCS; i++) { + chan->seg_v[i].hw.next_desc = + lower_32_bits(chan->seg_p + sizeof(*chan->seg_v) * + ((i + 1) % XILINX_DMA_NUM_DESCS)); + chan->seg_v[i].hw.next_desc_msb = + upper_32_bits(chan->seg_p + sizeof(*chan->seg_v) * + ((i + 1) % XILINX_DMA_NUM_DESCS)); + chan->seg_v[i].phys = chan->seg_p + + sizeof(*chan->seg_v) * i; + list_add_tail(&chan->seg_v[i].node, + &chan->free_seg_list); + } } else if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) { chan->desc_pool = dma_pool_create("xilinx_cdma_desc_pool", chan->dev, @@ -832,7 +885,8 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan) 0); } - if (!chan->desc_pool) { + if (!chan->desc_pool && + (chan->xdev->dma_config->dmatype != XDMA_TYPE_AXIDMA)) { dev_err(chan->dev, "unable to allocate channel %d descriptor pool\n", chan->id); @@ -841,22 +895,20 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan) if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { /* - * For AXI DMA case after submitting a pending_list, keep - * an extra segment allocated so that the "next descriptor" - * pointer on the tail descriptor always points to a - * valid descriptor, even when paused after reaching taildesc. - * This way, it is possible to issue additional - * transfers without halting and restarting the channel. - */ - chan->seg_v = xilinx_axidma_alloc_tx_segment(chan); - - /* * For cyclic DMA mode we need to program the tail Descriptor * register with a value which is not a part of the BD chain * so allocating a desc segment during channel allocation for * programming tail descriptor. */ - chan->cyclic_seg_v = xilinx_axidma_alloc_tx_segment(chan); + chan->cyclic_seg_v = dma_zalloc_coherent(chan->dev, + sizeof(*chan->cyclic_seg_v), + &chan->cyclic_seg_p, GFP_KERNEL); + if (!chan->cyclic_seg_v) { + dev_err(chan->dev, + "unable to allocate desc segment for cyclic DMA\n"); + return -ENOMEM; + } + chan->cyclic_seg_v->phys = chan->cyclic_seg_p; } dma_cookie_init(dchan); @@ -1175,7 +1227,7 @@ static void xilinx_cdma_start_transfer(struct xilinx_dma_chan *chan) static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan) { struct xilinx_dma_tx_descriptor *head_desc, *tail_desc; - struct xilinx_axidma_tx_segment *tail_segment, *old_head, *new_head; + struct xilinx_axidma_tx_segment *tail_segment; u32 reg; if (chan->err) @@ -1194,21 +1246,6 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan) tail_segment = list_last_entry(&tail_desc->segments, struct xilinx_axidma_tx_segment, node); - if (chan->has_sg && !chan->xdev->mcdma) { - old_head = list_first_entry(&head_desc->segments, - struct xilinx_axidma_tx_segment, node); - new_head = chan->seg_v; - /* Copy Buffer Descriptor fields. */ - new_head->hw = old_head->hw; - - /* Swap and save new reserve */ - list_replace_init(&old_head->node, &new_head->node); - chan->seg_v = old_head; - - tail_segment->hw.next_desc = chan->seg_v->phys; - head_desc->async_tx.phys = new_head->phys; - } - reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR); if (chan->desc_pendingcount <= XILINX_DMA_COALESCE_MAX) { @@ -1706,7 +1743,7 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg( { struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); struct xilinx_dma_tx_descriptor *desc; - struct xilinx_axidma_tx_segment *segment = NULL, *prev = NULL; + struct xilinx_axidma_tx_segment *segment = NULL; u32 *app_w = (u32 *)context; struct scatterlist *sg; size_t copy; @@ -1757,10 +1794,6 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg( XILINX_DMA_NUM_APP_WORDS); } - if (prev) - prev->hw.next_desc = segment->phys; - - prev = segment; sg_used += copy; /* @@ -1774,7 +1807,6 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg( segment = list_first_entry(&desc->segments, struct xilinx_axidma_tx_segment, node); desc->async_tx.phys = segment->phys; - prev->hw.next_desc = segment->phys; /* For the last DMA_MEM_TO_DEV transfer, set EOP */ if (chan->direction == DMA_MEM_TO_DEV) { @@ -2318,6 +2350,7 @@ static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev, INIT_LIST_HEAD(&chan->pending_list); INIT_LIST_HEAD(&chan->done_list); INIT_LIST_HEAD(&chan->active_list); + INIT_LIST_HEAD(&chan->free_seg_list); /* Retrieve the channel properties from the device tree */ has_dre = of_property_read_bool(node, "xlnx,include-dre"); -- 2.1.2