Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2524160pxb; Sun, 23 Jan 2022 07:24:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGolLrNMyMaoe12yLDDnkysneH9fYWx9YKVaTQTIeWGDh06VBB9WBhpX+OwEhHhlKwMEf3 X-Received: by 2002:a17:902:e750:b0:14b:4bef:a2e0 with SMTP id p16-20020a170902e75000b0014b4befa2e0mr1903037plf.2.1642951458210; Sun, 23 Jan 2022 07:24:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642951458; cv=none; d=google.com; s=arc-20160816; b=RPl7rVRtQsVm9lIv9r1I6wRHuwtKTCe+khAhAOcW1ejYU+KBz61L5LAO1ielhnW/Nv Y9/BdnFzr2ftz7QGrtYalkRTLQmOJqsOsXLRN4oZC5jPdmif60U5jVEU82T3QYAw0vYK bKYyMg4UYiuNn4lmydvIJgbYswa4M8dky8ucGKl4ps6ZSuj/dgVNBpWCGX4zUEvRGk74 5NwjOhcuSVvgsI8wX+GpcO8hFmDwLRZbg1ctE0rxUYJM6uewqU5llx0gRaqp3srgbVXa GZg/U8wOlhW9CuYMtkEjEDcozi8DcjhrWbe8E2zaPwzhEzmGNzsKvHtF3tZIuX+zIIZh Q13w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=yh82ozfSM6oapqGRh4z7IM/xoIpSwq0P7Nnmuai8gxg=; b=U1MSfq8ciA89NKhu+flrQP/i4WKmDcKJ4ba4foeTofbPzvKcvsaGasr85wrFT2WJbd RhkqZdyO7xml1Ghifj7NuayUbr1furyXeSADQ6pas8ZUllDqJgaJffqS6eY6d5McNqbX wQsvg6JFQZrAdpAuqSAuXGg03zqXcx+5T5+PlVYlaFsf7BhPARGFWARuQLYlNzuEnMuH TH+f0ksU3Kho0WNF3WFKNbxazSstVjby3Zt9Z29shzWgjBcL0LTdcmYwIANxzUUVXi1x zIEDXLbfBj41d6tSTBcvXFeSUzMLeS/whJ1GpmNZNlov6/EaT2roCxiH7cRsRKw4ls+p 4tsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CAFwyQ77; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i4si5404151pgj.317.2022.01.23.07.24.06; Sun, 23 Jan 2022 07:24:18 -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=@gmail.com header.s=20210112 header.b=CAFwyQ77; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234693AbiAVSbq (ORCPT + 99 others); Sat, 22 Jan 2022 13:31:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231531AbiAVSbo (ORCPT ); Sat, 22 Jan 2022 13:31:44 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DA5FC06173B; Sat, 22 Jan 2022 10:31:43 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id bu18so40853177lfb.5; Sat, 22 Jan 2022 10:31:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=yh82ozfSM6oapqGRh4z7IM/xoIpSwq0P7Nnmuai8gxg=; b=CAFwyQ77R2H6RYwpu0aR7vj2GXGa6gLhHNaq/FMOVKUwB9TSdOV1niGlNkrMDkuIDg WU9BqxwnUgKILKeA6hPbuOX6TW/AXfNcT9UGGpeka8FaqEHbf0el5u8kebmCg65dulz9 SqpWcsrMguDTbHPpMlMc6LxC/Ua3lNuNr2yvJxp4zma6wb9fJ8FLyt3RlR83T/OutSlb MnJPvr+8atYvWA/ohHEvKjqfV9xbcBX2NNEnYNNxjNjAa0p5rGNdjL0WHutWsnMpvSlQ q2Tlua+vE/qx8rLjxnnFcqiuextgJHNbxdfZjFp11AtHU3NWkVwIsT5hOugAe3ZUK28u G6JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=yh82ozfSM6oapqGRh4z7IM/xoIpSwq0P7Nnmuai8gxg=; b=W+90WSc3Yc2sVkNrTrvtJXAcKnDXTNsfeBByz19Yt25czIdLngbahOysq2rFCzAaEB HuAX/ZqkCl5SmanW5B5VOBQiotu4YS8ZbiIxX9dWV2NWkTyGXQMTDu6bM+6fBYLaverQ U5ieonYfE1nxfgXVjUMoeaby9EP3gmgzTIygRTsViqb+IbhNA/OR0Dm5JvolyfPW87wm BbMTqp/MGkvuAy9p3pptZJXWb8VAhs1qN6SWdhwcGsH16TNYNyAuxHrQZ2+krZ4P01dx OF+DYEUdT4EMssQa5vFf8WK9WGvbLlF5liXb50eCZPPW51WXqom/pad1LWWaJnQrLEKk MFWA== X-Gm-Message-State: AOAM532b+TxIDaYG1vB2EgP5/hAtVA4UrlojVm5VE1lcNUDukfMH4/R9 Bahua1FVh8ZWgR9ZpMfQhyY= X-Received: by 2002:a05:6512:207:: with SMTP id a7mr5440742lfo.208.1642876301886; Sat, 22 Jan 2022 10:31:41 -0800 (PST) Received: from [192.168.2.145] (109-252-139-36.dynamic.spd-mgts.ru. [109.252.139.36]) by smtp.googlemail.com with ESMTPSA id q16sm631365lfg.170.2022.01.22.10.31.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 22 Jan 2022 10:31:41 -0800 (PST) Message-ID: <31ba2627-65c7-1340-e6b9-7c328a485456@gmail.com> Date: Sat, 22 Jan 2022 21:31:39 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver Content-Language: en-US To: Akhil R , "dan.j.williams@intel.com" , "devicetree@vger.kernel.org" , "dmaengine@vger.kernel.org" , Jonathan Hunter , Krishna Yarlagadda , Laxman Dewangan , "linux-kernel@vger.kernel.org" , "linux-tegra@vger.kernel.org" , "p.zabel@pengutronix.de" , Rajesh Gumasta , "robh+dt@kernel.org" , "thierry.reding@gmail.com" , "vkoul@kernel.org" Cc: Pavan Kunapuli References: <1641830718-23650-1-git-send-email-akhilrajeev@nvidia.com> <1641830718-23650-3-git-send-email-akhilrajeev@nvidia.com> <16c73e83-b990-7d8e-ddfd-7cbbe7e407ea@gmail.com> <1db14c3d-6a96-96dd-be76-b81b3a48a2b1@gmail.com> <683a71b1-049a-bddf-280d-5d5141b59686@gmail.com> From: Dmitry Osipenko In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 21.01.2022 19:24, Akhil R пишет: >>>>>>> +static int tegra_dma_terminate_all(struct dma_chan *dc) >>>>>>> +{ >>>>>>> + struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc); >>>>>>> + unsigned long flags; >>>>>>> + LIST_HEAD(head); >>>>>>> + int err; >>>>>>> + >>>>>>> + if (tdc->dma_desc) { >>>>>> >>>>>> Needs locking protection against racing with the interrupt handler. >>>>> tegra_dma_stop_client() waits for the in-flight transfer >>>>> to complete and prevents any additional transfer to start. >>>>> Wouldn't it manage the race? Do you see any potential issue there? >>>> >>>> You should consider interrupt handler like a process running in a >>>> parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence >>>> you'll get NULL dereference in tegra_dma_stop_client(). >>> >>> Is it better if I remove the below part from tegra_dma_stop_client() so >>> that dma_desc is not accessed at all? >>> >>> + wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT); >>> + tdc->dma_desc->bytes_transferred += >>> + tdc->dma_desc->bytes_requested - (wcount * 4); >>> >>> Because I don't see a point in updating the value there. dma_desc is set >>> to NULL in the next step in terminate_all() anyway. >> >> That isn't going help you much because you also can't release DMA >> descriptor while interrupt handler still may be running and using that >> descriptor. > > Does the below functions look good to resolve the issue, provided > tegra_dma_stop_client() doesn't access dma_desc? Stop shall not race with the start. > +static int tegra_dma_terminate_all(struct dma_chan *dc) > +{ > + struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc); > + unsigned long flags; > + LIST_HEAD(head); > + int err; > + > + err = tegra_dma_stop_client(tdc); > + if (err) > + return err; > + > + tegra_dma_stop(tdc); > + > + spin_lock_irqsave(&tdc->vc.lock, flags); > + tegra_dma_sid_free(tdc); > + tdc->dma_desc = NULL; > + > + vchan_get_all_descriptors(&tdc->vc, &head); > + spin_unlock_irqrestore(&tdc->vc.lock, flags); > + > + vchan_dma_desc_free_list(&tdc->vc, &head); > + > + return 0; > +} > > +static irqreturn_t tegra_dma_isr(int irq, void *dev_id) > +{ > + struct tegra_dma_channel *tdc = dev_id; > + struct tegra_dma_desc *dma_desc = tdc->dma_desc; > + struct tegra_dma_sg_req *sg_req; > + u32 status; > + > + /* Check channel error status register */ > + status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS); > + if (status) { > + tegra_dma_chan_decode_error(tdc, status); > + tegra_dma_dump_chan_regs(tdc); > + tdc_write(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS, 0xFFFFFFFF); > + } > + > + status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_STATUS); > + if (!(status & TEGRA_GPCDMA_STATUS_ISE_EOC)) > + return IRQ_HANDLED; > + > + tdc_write(tdc, TEGRA_GPCDMA_CHAN_STATUS, > + TEGRA_GPCDMA_STATUS_ISE_EOC); > + > + spin_lock(&tdc->vc.lock); > + if (!dma_desc) All checks and assignments must be done inside of critical section. > + goto irq_done;