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 D1889C433EF for ; Mon, 6 Dec 2021 13:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244610AbhLFNjb (ORCPT ); Mon, 6 Dec 2021 08:39:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240974AbhLFNja (ORCPT ); Mon, 6 Dec 2021 08:39:30 -0500 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 849DEC061746; Mon, 6 Dec 2021 05:36:01 -0800 (PST) Received: by theia.8bytes.org (Postfix, from userid 1000) id A88E1396; Mon, 6 Dec 2021 14:35:58 +0100 (CET) Date: Mon, 6 Dec 2021 14:35:55 +0100 From: Joerg Roedel To: Lu Baolu Cc: Greg Kroah-Hartman , 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 v3 01/18] iommu: Add device dma ownership set/release interfaces Message-ID: References: <20211206015903.88687-1-baolu.lu@linux.intel.com> <20211206015903.88687-2-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211206015903.88687-2-baolu.lu@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 06, 2021 at 09:58:46AM +0800, Lu Baolu wrote: > >From the perspective of who is initiating the device to do DMA, device > DMA could be divided into the following types: > > DMA_OWNER_DMA_API: Device DMAs are initiated by a kernel driver > through the kernel DMA API. > DMA_OWNER_PRIVATE_DOMAIN: Device DMAs are initiated by a kernel > driver with its own PRIVATE domain. > DMA_OWNER_PRIVATE_DOMAIN_USER: Device DMAs are initiated by > userspace. I have looked at the other iommu patches in this series, but I still don't quite get what the difference in the code flow is between DMA_OWNER_PRIVATE_DOMAIN and DMA_OWNER_PRIVATE_DOMAIN_USER. What are the differences in the iommu core behavior based on this setting? > int iommu_device_set_dma_owner(struct device *dev, > enum iommu_dma_owner type, void *owner_cookie); > void iommu_device_release_dma_owner(struct device *dev, > enum iommu_dma_owner type); It the owner is a group-wide setting, it should be called with the group instead of the device. I have seen the group-specific funcitons are added later, but that leaves the question why the device-specific ones are needed at all. > + enum iommu_dma_owner dma_owner; > + refcount_t owner_cnt; > + void *owner_cookie; > }; I am also not quite happy yet with calling this dma_owner, but can't come up with a better name yet. > > struct group_device { > @@ -621,6 +624,7 @@ struct iommu_group *iommu_group_alloc(void) > INIT_LIST_HEAD(&group->devices); > INIT_LIST_HEAD(&group->entry); > BLOCKING_INIT_NOTIFIER_HEAD(&group->notifier); > + group->dma_owner = DMA_OWNER_NONE; DMA_OWNER_NONE is also questionable. All devices are always in one domain, and the default domain is always the one used for DMA-API, so why isn't the initial value DMA_OWNER_DMA_API? Regards, Joerg