From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C590DC433F5 for ; Mon, 14 Feb 2022 10:49:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348939AbiBNKtl (ORCPT ); Mon, 14 Feb 2022 05:49:41 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349119AbiBNKtR (ORCPT ); Mon, 14 Feb 2022 05:49:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28AADBF94E; Mon, 14 Feb 2022 02:12:22 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B937961027; Mon, 14 Feb 2022 10:12:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66D3CC340E9; Mon, 14 Feb 2022 10:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644833541; bh=4e6jacegMudm5QOO5r4b8aXUbKWQ/KZagciGyXk0tFQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dWgOCaq9LwmLUWtMT7HPrs1K+hIb25M6y5lmPLlGADQIWn+ktjprZPDD4AHsRsFdP 22C5wQvlEiUCP2TIBNNZG0gJ+dQ4/5WAaA8UbkTfOuU3UVef1Kj4DZOkHgKPZU6q51 6mKzlynGQpisdWw3qFqtDq7e6e382gjSAm2McVts= Date: Mon, 14 Feb 2022 10:59:50 +0100 From: Greg Kroah-Hartman To: Lu Baolu Cc: Joerg Roedel , Alex Williamson , Bjorn Helgaas , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 04/14] driver core: platform: Add driver dma ownership management Message-ID: References: <20220104015644.2294354-1-baolu.lu@linux.intel.com> <20220104015644.2294354-5-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220104015644.2294354-5-baolu.lu@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Tue, Jan 04, 2022 at 09:56:34AM +0800, Lu Baolu wrote: > Multiple platform devices may be placed in the same IOMMU group because > they cannot be isolated from each other. These devices must either be > entirely under kernel control or userspace control, never a mixture. This > checks and sets DMA ownership during driver binding, and release the > ownership during driver unbinding. > > The device driver may set a new flag (no_kernel_api_dma) to skip calling > iommu_device_use_dma_api() during the binding process. For instance, the > userspace framework drivers (vfio etc.) which need to manually claim > their own dma ownership when assigning the device to userspace. > > Signed-off-by: Lu Baolu > --- > include/linux/platform_device.h | 1 + > drivers/base/platform.c | 20 ++++++++++++++++++++ > 2 files changed, 21 insertions(+) > > diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h > index 17fde717df68..8f0eaafcef47 100644 > --- a/include/linux/platform_device.h > +++ b/include/linux/platform_device.h > @@ -210,6 +210,7 @@ struct platform_driver { > struct device_driver driver; > const struct platform_device_id *id_table; > bool prevent_deferred_probe; > + bool no_kernel_api_dma; > }; > > #define to_platform_driver(drv) (container_of((drv), struct platform_driver, \ > diff --git a/drivers/base/platform.c b/drivers/base/platform.c > index b4d36b46ab2e..d5171e44d903 100644 > --- a/drivers/base/platform.c > +++ b/drivers/base/platform.c > @@ -30,6 +30,7 @@ > #include > #include > #include > +#include > > #include "base.h" > #include "power/power.h" > @@ -1451,9 +1452,16 @@ static void platform_shutdown(struct device *_dev) > > static int platform_dma_configure(struct device *dev) > { > + struct platform_driver *drv = to_platform_driver(dev->driver); > enum dev_dma_attr attr; > int ret = 0; > > + if (!drv->no_kernel_api_dma) { > + ret = iommu_device_use_dma_api(dev); > + if (ret) > + return ret; > + } > + > if (dev->of_node) { > ret = of_dma_configure(dev, dev->of_node, true); > } else if (has_acpi_companion(dev)) { > @@ -1461,9 +1469,20 @@ static int platform_dma_configure(struct device *dev) > ret = acpi_dma_configure(dev, attr); > } > > + if (ret && !drv->no_kernel_api_dma) > + iommu_device_unuse_dma_api(dev); So you are now going to call this for every platform driver _unless_ they set this flag? And having "negative" flags is rough to parse at times. Yes, we have "prevent_deferred_probe" already here, so maybe keep this in the same nameing scheme and use "prevent_dma_api"? And it would be good to document this somewhere as to what this means. thanks, greg k-h