Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1589795ybv; Thu, 20 Feb 2020 23:51:44 -0800 (PST) X-Google-Smtp-Source: APXvYqz1Q1NCodE9EUUTZn1OO+mCrq82TflQCBOHC3mjSnUehzn/kdJbHJTohdQmmy8BX6cQbWIi X-Received: by 2002:a9d:138:: with SMTP id 53mr27869149otu.334.1582271504848; Thu, 20 Feb 2020 23:51:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582271504; cv=none; d=google.com; s=arc-20160816; b=NWd98S58WImtJQrOUWkgXnyqfpgRdusCVlSEeAla2b/OE4zbw+Z6WbTpOfsXjE3gTE z7j3nnNpf1u6V+jJe160pPS6iWB1y0D8yogj220z6XSCUhaRvRtpFIT/zstMcJzn871Z VBWZhBELqUmJuEvVh2UC8bs9oaAGMu/sXhgiwdAaNiazDRU9tedu4Yi3CMBBA8i4G4Xz QavhB4t0STUXizjUT/vvSC2yl65uuHZi8GPMLh01wUUzK+f5WPU11ejfobc26bLthpij i5Jqn/MTjc2NYwqP+mFvtqCi+Eqrlpiufy4w+U/1G1Far5FJGDS1xdXmoppmchrDc7wm BYBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dGRxot4V5FvdIo1DMCppfJvyLSG4IkBGN83ANw9ZQd0=; b=CS35vxXeEuRn0pZ/ULUMQgDgyxcXX4HsR3izWxXfB4qbBfq7eJXAYVIoaG0PMdzKQh j5uPnE7ygvXdeIfYIxDBlmbd6hpcq1WEvN6ZVu0eHcrshnmYf2HGLhllm7yModn3QCud /0HrRW6zTTtzsXKFStKIt+4honfgudi6Xa8PiTiUEDryzhv9WpgZG8i/QSIziFrZiaAH 7+0shuKwwi0G3a/m4G2OaxzIpLPM9sNKK+J3SMSCJcc1i3T4ZbPr8cghPWLjYqp27gia miIm1M8cuBaCxAIefqmt3mmCgASVPkpzMvAFtRRBw6wSTxgHzf/PI55rHvyGrGmMGtAo N71Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YYpUMrDE; 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 y22si1014778oti.269.2020.02.20.23.51.32; Thu, 20 Feb 2020 23:51:44 -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; dkim=pass header.i=@kernel.org header.s=default header.b=YYpUMrDE; 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 S1729757AbgBUHva (ORCPT + 99 others); Fri, 21 Feb 2020 02:51:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:48750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729314AbgBUHv1 (ORCPT ); Fri, 21 Feb 2020 02:51:27 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AAAF720578; Fri, 21 Feb 2020 07:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271486; bh=Aa4LQc/fQ6MQQpm24YQGRNw2rQxRYku0iwSvM44nrAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YYpUMrDE2XvihKxoPexK6blB9K5e+pBoW7akfydQz5SELmmj3P4J+MeR9ncAWq/tF gBU+0ob1O5lYKcHeWKtYf/fO2v8K3JXS0QGivcZkKgEf3Mft8keG8RXAdI2TcZCjPF tqTJCz9HyKtR7nfKYZ8J6Zm8B6fy+7VZ1Xo6BTS8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Logan Gunthorpe , Vinod Koul , Sasha Levin Subject: [PATCH 5.5 183/399] dmaengine: Store module owner in dma_device struct Date: Fri, 21 Feb 2020 08:38:28 +0100 Message-Id: <20200221072420.576010551@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Logan Gunthorpe [ Upstream commit dae7a589c18a4d979d5f14b09374e871b995ceb1 ] dma_chan_to_owner() dereferences the driver from the struct device to obtain the owner and call module_[get|put](). However, if the backing device is unbound before the dma_device is unregistered, the driver will be cleared and this will cause a NULL pointer dereference. Instead, store a pointer to the owner module in the dma_device struct so the module reference can be properly put when the channel is put, even if the backing device was destroyed first. This change helps to support a safer unbind of DMA engines. If the dma_device is unregistered in the driver's remove function, there's no guarantee that there are no existing clients and a users action may trigger the WARN_ONCE in dma_async_device_unregister() which is unlikely to leave the system in a consistent state. Instead, a better approach is to allow the backing driver to go away and fail any subsequent requests to it. Signed-off-by: Logan Gunthorpe Link: https://lore.kernel.org/r/20191216190120.21374-2-logang@deltatee.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/dmaengine.c | 4 +++- include/linux/dmaengine.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 03ac4b96117cd..4b604086b1b3a 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -179,7 +179,7 @@ __dma_device_satisfies_mask(struct dma_device *device, static struct module *dma_chan_to_owner(struct dma_chan *chan) { - return chan->device->dev->driver->owner; + return chan->device->owner; } /** @@ -919,6 +919,8 @@ int dma_async_device_register(struct dma_device *device) return -EIO; } + device->owner = device->dev->driver->owner; + if (dma_has_cap(DMA_MEMCPY, device->cap_mask) && !device->device_prep_dma_memcpy) { dev_err(device->dev, "Device claims capability %s, but op is not defined\n", diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index dad4a68fa0094..8013562751a50 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -674,6 +674,7 @@ struct dma_filter { * @fill_align: alignment shift for memset operations * @dev_id: unique device ID * @dev: struct device reference for dma mapping api + * @owner: owner module (automatically set based on the provided dev) * @src_addr_widths: bit mask of src addr widths the device supports * Width is specified in bytes, e.g. for a device supporting * a width of 4 the mask should have BIT(4) set. @@ -737,6 +738,7 @@ struct dma_device { int dev_id; struct device *dev; + struct module *owner; u32 src_addr_widths; u32 dst_addr_widths; -- 2.20.1