Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1622985ybv; Fri, 21 Feb 2020 00:29:00 -0800 (PST) X-Google-Smtp-Source: APXvYqyWRp8AZuSoqpleABe9ZPlVWZMNtVZN4LGOpCVZBlL8RwXl7poXQmQstCwfA4s2YiKEV2Uc X-Received: by 2002:aca:acc4:: with SMTP id v187mr1064805oie.130.1582273740451; Fri, 21 Feb 2020 00:29:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273740; cv=none; d=google.com; s=arc-20160816; b=bSr5vudO3dPYmIQ2OfO24gLfkufq8FhmS+n0mshbeGhj5XhZLpmp5LS4JBo/9UhXGL I0J62+94sQK315UgvCu6fHSe49KAzwvXsy3tW7OCP0bM1r1l2VG4QtMxFGeDr15rlb6y BmY8XfsCZkVwSK/38jvDNGRIds7pXB9/rvcbWJSoWKwmjz5LyVIoIl23VqPvkIS+4CMT 7TDwTL1k0T7oes2rEEuZ+Kjv1eTFYTMbKymjzchOMPMtQejECGsCWCK1bSkBfieRAiI7 8+uhYyjtIB/4mmgWtPO/bSfSH4uGkLn946jOKfCczrKWKtdiyxVKH90f0CPMjs7OFrv/ 8W4w== 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=l7dW7UZy6RwW+3GeyCidV6yJbKWRBnTf4q/aSyNSKAc=; b=c3TgRCaD4nzcsRG7yBm5u75yCuvvvA0XDKEebjk2+2sn8wy8KyJHC0dNFN7XWWloz1 3eqUMP3C1zHb1w4NcGRcoaEleo+rAChseHWKNq90WhzljGo1D8XFksEEdWS9sJzLPDgr 9dmQIsxRfnsU3WrE6JEL6IX5Uea8BU6pFzTj1PPMXewgWZWNHrBVohyD0eKfQp5Qa8/+ xLbb2z9YwUJNaRwN2i6aQ7OJY9O35kVsOAQjBewedd+6vmk6qVran0oIK7FiWUP72jUF E9IqpGQkFfPcG3WAgvOSg5r2eez/VmlwRwTyF8IJF7V2Yn0K1TGPMqlrfWBWDa7rbRFP EGWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gzBr3+Hz; 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 69si1209948otv.190.2020.02.21.00.28.47; Fri, 21 Feb 2020 00:29:00 -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=gzBr3+Hz; 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 S2387950AbgBUIUl (ORCPT + 99 others); Fri, 21 Feb 2020 03:20:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:59576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732212AbgBUIUa (ORCPT ); Fri, 21 Feb 2020 03:20:30 -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 58DC42469E; Fri, 21 Feb 2020 08:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273229; bh=Uci4Q4URTC+pEHdpdJ5xnqKC2i/pyvKZ/JORzpyZwpI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gzBr3+HzApXL4rnzXIJ/R1EW+v+z7fboaKZLHRqjqYUlj9+ww/FXNVKKoqykTyTq1 T9AI2myiLAp3fY9ZBz7RYcsFJHH25RthnBrxeKnPrW2ZxqagNT0qDHQaUKPID6+wAb DFLHQr+j9dInj0AGgmUQ+M6mxXA1IqtiPaeMJYwU= 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 4.19 086/191] dmaengine: Store module owner in dma_device struct Date: Fri, 21 Feb 2020 08:40:59 +0100 Message-Id: <20200221072301.489640228@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@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 f1a441ab395d7..8a52a5efee4f5 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -190,7 +190,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; } /** @@ -923,6 +923,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 0647f436f88c2..50128c36f0b48 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -686,6 +686,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. @@ -749,6 +750,7 @@ struct dma_device { int dev_id; struct device *dev; + struct module *owner; u32 src_addr_widths; u32 dst_addr_widths; -- 2.20.1