Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4508896pxb; Mon, 21 Feb 2022 23:41:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdVh80vlpttBr2YiHbqCjAMxdOcGlPDBfEWxt2yIjscRRq3+9k7QaL9qaCxX11aC1Fo/HX X-Received: by 2002:a05:6a00:88e:b0:4d2:4829:156c with SMTP id q14-20020a056a00088e00b004d24829156cmr23934004pfj.47.1645515664756; Mon, 21 Feb 2022 23:41:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645515664; cv=none; d=google.com; s=arc-20160816; b=KS21LgbKuvTawuxrFbogac+8ZhZnLP55OJOl91NGEuTmOY3un8F8d8j/SCdVPeQoYl FchT78+i6rPsDNeNtBBVyvL4FEPvz5WCkvj11u9d6iEc6KHNLcsuQweZNltotCl1T9BQ 300iqoRaJc9bv7nEt16FXAstPH2fAMBWO1g4nYOSp4BscEinJy0BBi4DeZRUGaK4vQiK 55oFqpjN06I9VBn2zER2Z+UV3mr7/MTJk1DWkH7lZM4ZJ6SdRQtEa+KvwIPuYCXuQzOV 1z4LyxXbaef9fOpxsEMzC0bivn72sIuP/ZFV2CuLYsjk8Zh0WX5cMvj7sVLwwCt6YK8s KFIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=0ooHQvVaoHoZ/AAmEKBM5jMTMLgD5OkgUo1CPL2j36g=; b=AOG/hDi+u0dxsuRWU4noaxvaEn+ksrOMLMB/bcgHTDLagDx7njXw6H0yj87a47XO8S X3wqpLtSdO64taLWpRL6PS/P+m47fiaIdbtjYQ+qFKMIv/l8epUpORsAoAlQWLZNLCAY CRRsvdOoZeAh+ifzV+XI/H7ycSRrrGSXz0ugwEvl2v9acgWmEmxH6qJyVjqzszZWZwZ2 Bay474HHyAUdVJ28AH3/QqqKPKXSOQL455/x+FIA78I+A1n9hO/vrWZlHV1LSYBiZ6Rc RZaapBRe1cfyMqbhDCx5lup6Oq0m3Ce8gaCuvaLPy3wVhtHpB08BQFUFzVKqd5zl/uNL SxOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qwOMP8C9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b12-20020a17090a488c00b001b98e640f6asi1271983pjh.40.2022.02.21.23.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 23:41:04 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qwOMP8C9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AEBAD1285BF; Mon, 21 Feb 2022 23:41:02 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbiBVHlR (ORCPT + 99 others); Tue, 22 Feb 2022 02:41:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbiBVHlO (ORCPT ); Tue, 22 Feb 2022 02:41:14 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EFD2128589 for ; Mon, 21 Feb 2022 23:40:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 57F05CE12FE for ; Tue, 22 Feb 2022 07:40:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 440B9C340E8; Tue, 22 Feb 2022 07:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645515645; bh=W2j8A9jc87ifeEDwebVUMF/iX4lmFyZxax0K5tYjNFo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qwOMP8C9Yl/c0BR6UKgAJY3K0w4qpyyt6OP7KB24Jsyt7yWSoi6jOhkUboKMNciqx Ha38MZheNrSAuJAyvIGwjNlKdvmZbydzySt3iKZG/qkwhV7DCsOoXzF0MtFqMwF5rd f0nlNzmoLPXYypP0UhJrJ4P5CxdI3TEEPZDtWTLY= Date: Tue, 22 Feb 2022 08:40:42 +0100 From: Greg Kroah-Hartman To: Rob Herring Cc: =?iso-8859-1?Q?M=E5rten?= Lindahl , "Rafael J. Wysocki" , kernel , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] driver core: Free DMA range map when device is released Message-ID: References: <20220216094128.4025861-1-marten.lindahl@axis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 16, 2022 at 09:45:09AM -0600, Rob Herring wrote: > On Wed, Feb 16, 2022 at 3:42 AM M?rten Lindahl wrote: > > > > When unbinding/binding a driver with DMA mapped memory, the DMA map is > > not freed before the driver is reloaded. This leads to a memory leak > > when the DMA map is overwritten when reprobing the driver. > > > > This can be reproduced with a platform driver having a dma-range: > > > > dummy { > > ... > > #address-cells = <0x2>; > > #size-cells = <0x2>; > > ranges; > > dma-ranges = <...>; > > ... > > }; > > > > and then unbinding/binding it: > > > > ~# echo soc:dummy >/sys/bus/platform/drivers//unbind > > > > DMA map object 0xffffff800b0ae540 still being held by &pdev->dev > > > > ~# echo soc:dummy >/sys/bus/platform/drivers//bind > > ~# echo scan > /sys/kernel/debug/kmemleak > > ~# cat /sys/kernel/debug/kmemleak > > unreferenced object 0xffffff800b0ae540 (size 64): > > comm "sh", pid 833, jiffies 4295174550 (age 2535.352s) > > hex dump (first 32 bytes): > > 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 ................ > > 00 00 00 80 00 00 00 00 00 00 00 80 00 00 00 00 ................ > > backtrace: > > [] create_object.isra.0+0x108/0x344 > > [] kmemleak_alloc+0x8c/0xd0 > > [] __kmalloc+0x440/0x6f0 > > [] of_dma_get_range+0x124/0x220 > > [] of_dma_configure_id+0x40/0x2d0 > > [] platform_dma_configure+0x5c/0xa4 > > [] really_probe+0x8c/0x514 > > [] __driver_probe_device+0x9c/0x19c > > [] device_driver_attach+0x54/0xbc > > [] bind_store+0xc4/0x120 > > [] drv_attr_store+0x30/0x44 > > [] sysfs_kf_write+0x50/0x60 > > [] kernfs_fop_write_iter+0x124/0x1b4 > > [] new_sync_write+0xdc/0x160 > > [] vfs_write+0x23c/0x2a0 > > [] ksys_write+0x64/0xec > > > > To prevent this we should free the dma_range_map when the device is > > released. > > > > Signed-off-by: M?rten Lindahl > > Suggested-by: Rob Herring > Fixes: e0d072782c73 ("dma-mapping: introduce DMA range map, > supplanting dma_pfn_offset") > Reviewed-by: Rob Herring > > I've got a follow-up patch to refactor the 3 occurrences of this same > deinit code. Now queued up, so feel free to send the follow-up patch too. thanks, greg k-h