Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1555630ybl; Thu, 30 Jan 2020 01:52:43 -0800 (PST) X-Google-Smtp-Source: APXvYqyqoGJ/8UQpNFa9T7HGATvMBRgDbkMIaJWZd6BBs3DAFLFzZ8FoPArT6JTEXdmatXMk0ziM X-Received: by 2002:aca:a816:: with SMTP id r22mr2341314oie.1.1580377963726; Thu, 30 Jan 2020 01:52:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580377963; cv=none; d=google.com; s=arc-20160816; b=0IiyKsasjl9YyEKI4UXmbgWk5hQHNJTEWH1LmSZRbv9Itq9WYp8ANZet2n9ewirMhg Y9Qfg4rkjQ732cCV6nyUuunCZChVtEye5P7fIijlZ8HzeRs7CaKA0YeJQ30RY2Md/+wz G1wGGVSO6Ev4+IF//lBXCHS3hELMK6Cvwj2S/SG1R1vxlZSPbfJYmviLQr35jMZw6eut rSCajB8lsxg02LxtcKTCBvHES3eHyvKAEy0wPAx04tdl867yJGACVDzvPzJft52eVXpN vNy/iGGRhQLMXfso2jdadDSF6l1wCUDfOiNm9sStFAq6QxF//+SgbQJAqK3xVhmqNnNi B0UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=lZNzSqthLHYkqAf+ynA39kr/Am6N06NLfXmilmY21PI=; b=wh+3Bx0F9JBPUU+yWXqECrnNQgLtg99vwMt0p4M9NDdW5HuMC2bQmalZhpVyRAWuHn /AFN/diWB3bLCqxUEuWH6YnJpBGmob/QCRkL4Empei5x8CKnoCm3PsWfsDKpBPxTKIWI 4HGWDhSI6fFF5R/alBCgUJ/bHhm4qfmIUZuxTdpn5gkemHZUs1phSVPG/Q0taT7oKwcr XJs/74zeSxdNwr/iUIUhKnI6YdmLG3UnmTXiGhcgaU7tlqxgw1TmUKcP40ccOKDjEXax dPyvB5byZNA9VwY1evet2R4A0tLlOMWFYSRhtgIHPNxP9RRLw8s9NI88iJFBuY4eFwbB sVBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17si2771127otr.320.2020.01.30.01.52.31; Thu, 30 Jan 2020 01:52:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726996AbgA3Jvj (ORCPT + 99 others); Thu, 30 Jan 2020 04:51:39 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:44916 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726882AbgA3Jvj (ORCPT ); Thu, 30 Jan 2020 04:51:39 -0500 Received: by mail-ot1-f65.google.com with SMTP id h9so2501739otj.11; Thu, 30 Jan 2020 01:51:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lZNzSqthLHYkqAf+ynA39kr/Am6N06NLfXmilmY21PI=; b=plffaIm5S+vxOS/hjxxtl6OlTNg1cu8OmnP1JU5c2DVqdUmE5s0fdayrCkzoBmieba uGJqdKmpWZzeReAhD5WJmwm7RkBowzcD2Am7wxfNCjCuIFe6RqMMUIeRHjLa0uqt3N5X IctQ2+LIM53LVPFtG/H+Lq7uKIc2vguNjh2Zkn+X1cP9ruASTQrKG1S+zcMjbFu066g0 K9rm7uamzpshWdJmMUC47D1klhXDw+J/O8A/0KzDT9bMTzhh3KMmIwhc4jRyCDRPy5V6 7kfpj40eEx/dw8nv1hYaJ8Mvd5l5SE8qPDFSza30xZ8fFKtgjwuwgk5a4PCzWpEbq+CG T7rQ== X-Gm-Message-State: APjAAAUEBJvfNUPvNusPYsbqkSTMFfH9akCPKOIAX5VSq0DAzNBH3Nsl a27oeoKttRPgeUtE0CYDm991JNgQ6572bQSunNQ= X-Received: by 2002:a9d:146:: with SMTP id 64mr2859825otu.39.1580377898038; Thu, 30 Jan 2020 01:51:38 -0800 (PST) MIME-Version: 1.0 References: <20200117153056.31363-1-geert+renesas@glider.be> In-Reply-To: From: Geert Uytterhoeven Date: Thu, 30 Jan 2020 10:51:26 +0100 Message-ID: Subject: Re: [PATCH v2] dmaengine: Create symlinks between DMA channels and slaves To: Peter Ujfalusi Cc: Geert Uytterhoeven , Vinod Koul , Dan Williams , dmaengine@vger.kernel.org, Linux-Renesas , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, On Thu, Jan 30, 2020 at 10:42 AM Peter Ujfalusi wrote: > On 17/01/2020 17.30, Geert Uytterhoeven wrote: > > Currently it is not easy to find out which DMA channels are in use, and > > which slave devices are using which channels. > > > > Fix this by creating two symlinks between the DMA channel and the actual > > slave device when a channel is requested: > > 1. A "slave" symlink from DMA channel to slave device, > > 2. A "dma:" symlink slave device to DMA channel. > > When the channel is released, the symlinks are removed again. > > The latter requires keeping track of the slave device and the channel > > name in the dma_chan structure. > > > > Note that this is limited to channel request functions for requesting an > > exclusive slave channel that take a device pointer (dma_request_chan() > > and dma_request_slave_channel*()). > > > > Signed-off-by: Geert Uytterhoeven > > --- a/drivers/dma/dmaengine.c > > +++ b/drivers/dma/dmaengine.c > > @@ -60,6 +60,8 @@ static long dmaengine_ref_count; > > > > /* --- sysfs implementation --- */ > > > > +#define DMA_SLAVE_NAME "slave" > > + > > /** > > * dev_to_dma_chan - convert a device pointer to its sysfs container object > > * @dev - device node > > @@ -730,11 +732,11 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name) > > if (has_acpi_companion(dev) && !chan) > > chan = acpi_dma_request_slave_chan_by_name(dev, name); > > > > - if (chan) { > > - /* Valid channel found or requester needs to be deferred */ > > - if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) > > - return chan; > > - } > > + if (PTR_ERR(chan) == -EPROBE_DEFER) > > + return chan; > > + > > + if (!IS_ERR_OR_NULL(chan)) > > + goto found; > > > > /* Try to find the channel via the DMA filter map(s) */ > > mutex_lock(&dma_list_mutex); > > @@ -754,7 +756,23 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name) > > } > > mutex_unlock(&dma_list_mutex); > > > > - return chan ? chan : ERR_PTR(-EPROBE_DEFER); > > + if (!IS_ERR_OR_NULL(chan)) > > + goto found; > > + > > + return ERR_PTR(-EPROBE_DEFER); > > + > > +found: > > + chan->slave = dev; > > + chan->name = kasprintf(GFP_KERNEL, "dma:%s", name); > > + if (!chan->name) > > + return ERR_PTR(-ENOMEM); > > You will lock the channel... It is requested, but it is not released in > case of failure. True. Perhaps this error should just be ignored, cfr. below. However, if this operation fails, chances are high the system will die very soon anyway. > > + > > + if (sysfs_create_link(&chan->dev->device.kobj, &dev->kobj, > > + DMA_SLAVE_NAME)) > > + dev_err(dev, "Cannot create DMA %s symlink\n", DMA_SLAVE_NAME); > > + if (sysfs_create_link(&dev->kobj, &chan->dev->device.kobj, chan->name)) > > + dev_err(dev, "Cannot create DMA %s symlink\n", chan->name); > > It is not a problem if these fail? IMHO, a failure to create these links is not fatal for the operation of the device, and thus can be ignored. Just like for debugfs. > > + return chan; > > } > > EXPORT_SYMBOL_GPL(dma_request_chan); > > > > @@ -812,6 +830,13 @@ void dma_release_channel(struct dma_chan *chan) > > /* drop PRIVATE cap enabled by __dma_request_channel() */ > > if (--chan->device->privatecnt == 0) > > dma_cap_clear(DMA_PRIVATE, chan->device->cap_mask); > > + if (chan->slave) { > > + sysfs_remove_link(&chan->slave->kobj, chan->name); > > + kfree(chan->name); > > + chan->name = NULL; > > + chan->slave = NULL; > > + } > > + sysfs_remove_link(&chan->dev->device.kobj, DMA_SLAVE_NAME); > > If a non slave channel is released, then you remove the link you have > never created? > > What happens if the link creation fails and here you attempt to remove > the failed ones? sysfs_remove_link() should handle removing non-existent links, and just return -ENOENT. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds