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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5338C4332F for ; Tue, 28 Sep 2021 13:35:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AEFBB60FC0 for ; Tue, 28 Sep 2021 13:35:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240933AbhI1Nhc (ORCPT ); Tue, 28 Sep 2021 09:37:32 -0400 Received: from mga04.intel.com ([192.55.52.120]:37605 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240971AbhI1NhW (ORCPT ); Tue, 28 Sep 2021 09:37:22 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10120"; a="222803124" X-IronPort-AV: E=Sophos;i="5.85,329,1624345200"; d="scan'208";a="222803124" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 06:35:14 -0700 X-IronPort-AV: E=Sophos;i="5.85,329,1624345200"; d="scan'208";a="553993941" Received: from blu2-mobl3.ccr.corp.intel.com (HELO [10.254.212.203]) ([10.254.212.203]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 06:35:08 -0700 Cc: baolu.lu@linux.intel.com, "Liu, Yi L" , "alex.williamson@redhat.com" , "hch@lst.de" , "jasowang@redhat.com" , "joro@8bytes.org" , "jean-philippe@linaro.org" , "parav@mellanox.com" , "lkml@metux.net" , "pbonzini@redhat.com" , "lushenming@huawei.com" , "eric.auger@redhat.com" , "corbet@lwn.net" , "Raj, Ashok" , "yi.l.liu@linux.intel.com" , "Tian, Jun J" , "Wu, Hao" , "Jiang, Dave" , "jacob.jun.pan@linux.intel.com" , "kwankhede@nvidia.com" , "robin.murphy@arm.com" , "kvm@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "dwmw2@infradead.org" , "linux-kernel@vger.kernel.org" , "david@gibson.dropbear.id.au" , "nicolinc@nvidia.com" To: Jason Gunthorpe , "Tian, Kevin" References: <20210919063848.1476776-1-yi.l.liu@intel.com> <20210919063848.1476776-7-yi.l.liu@intel.com> <20210921170943.GS327412@nvidia.com> <20210922123931.GI327412@nvidia.com> <20210927150928.GA1517957@nvidia.com> <20210928115751.GK964074@nvidia.com> From: Lu Baolu Subject: Re: [RFC 06/20] iommu: Add iommu_device_init[exit]_user_dma interfaces Message-ID: <9a314095-3db9-30fc-2ed9-4e46d385036d@linux.intel.com> Date: Tue, 28 Sep 2021 21:35:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20210928115751.GK964074@nvidia.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jason, On 2021/9/28 19:57, Jason Gunthorpe wrote: > On Tue, Sep 28, 2021 at 07:30:41AM +0000, Tian, Kevin wrote: > >>> Also, don't call it "hint", there is nothing hinty about this, it has >>> definitive functional impacts. >> >> possibly dma_mode (too broad?) or dma_usage > > You just need a flag to specify if the driver manages DMA ownership > itself, or if it requires the driver core to setup kernel ownership > > DMA_OWNER_KERNEL > DMA_OWNER_DRIVER_CONTROLLED > > ? > > There is a bool 'suprress_bind_attrs' already so it could be done like > this: > > bool suppress_bind_attrs:1; > > /* If set the driver must call iommu_XX as the first action in probe() */ > bool suppress_dma_owner:1; > > Which is pretty low cost. Yes. Pretty low cost to fix the BUG_ON() issue. Any kernel-DMA driver binding is blocked if the device's iommu group has been put into user- dma mode. Another issue is, when putting a device into user-dma mode, all devices belonging to the same iommu group shouldn't be bound with a kernel-dma driver. Kevin's prototype checks this by READ_ONCE(dev->driver). This is not lock safe as discussed below, https://lore.kernel.org/linux-iommu/20210927130935.GZ964074@nvidia.com/ Any guidance on this? Best regards, baolu 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EA93C433EF for ; Tue, 28 Sep 2021 13:35:19 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1AEE560F9D for ; Tue, 28 Sep 2021 13:35:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1AEE560F9D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id D705C40701; Tue, 28 Sep 2021 13:35:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cLkO1AJ6fG3n; Tue, 28 Sep 2021 13:35:18 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 80C464070E; Tue, 28 Sep 2021 13:35:17 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 38C04C001C; Tue, 28 Sep 2021 13:35:17 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 08675C000F for ; Tue, 28 Sep 2021 13:35:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id F1A3740222 for ; Tue, 28 Sep 2021 13:35:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qFQ9Km4HNDqq for ; Tue, 28 Sep 2021 13:35:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by smtp2.osuosl.org (Postfix) with ESMTPS id C57EF40567 for ; Tue, 28 Sep 2021 13:35:14 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10120"; a="204185002" X-IronPort-AV: E=Sophos;i="5.85,329,1624345200"; d="scan'208";a="204185002" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 06:35:14 -0700 X-IronPort-AV: E=Sophos;i="5.85,329,1624345200"; d="scan'208";a="553993941" Received: from blu2-mobl3.ccr.corp.intel.com (HELO [10.254.212.203]) ([10.254.212.203]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 06:35:08 -0700 To: Jason Gunthorpe , "Tian, Kevin" References: <20210919063848.1476776-1-yi.l.liu@intel.com> <20210919063848.1476776-7-yi.l.liu@intel.com> <20210921170943.GS327412@nvidia.com> <20210922123931.GI327412@nvidia.com> <20210927150928.GA1517957@nvidia.com> <20210928115751.GK964074@nvidia.com> From: Lu Baolu Subject: Re: [RFC 06/20] iommu: Add iommu_device_init[exit]_user_dma interfaces Message-ID: <9a314095-3db9-30fc-2ed9-4e46d385036d@linux.intel.com> Date: Tue, 28 Sep 2021 21:35:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20210928115751.GK964074@nvidia.com> Content-Language: en-US Cc: "kvm@vger.kernel.org" , "jasowang@redhat.com" , "kwankhede@nvidia.com" , "hch@lst.de" , "jean-philippe@linaro.org" , "Jiang, Dave" , "Raj, Ashok" , "corbet@lwn.net" , "parav@mellanox.com" , "alex.williamson@redhat.com" , "lkml@metux.net" , "david@gibson.dropbear.id.au" , "dwmw2@infradead.org" , "Tian, Jun J" , "linux-kernel@vger.kernel.org" , "lushenming@huawei.com" , "iommu@lists.linux-foundation.org" , "pbonzini@redhat.com" , "robin.murphy@arm.com" X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" Hi Jason, On 2021/9/28 19:57, Jason Gunthorpe wrote: > On Tue, Sep 28, 2021 at 07:30:41AM +0000, Tian, Kevin wrote: > >>> Also, don't call it "hint", there is nothing hinty about this, it has >>> definitive functional impacts. >> >> possibly dma_mode (too broad?) or dma_usage > > You just need a flag to specify if the driver manages DMA ownership > itself, or if it requires the driver core to setup kernel ownership > > DMA_OWNER_KERNEL > DMA_OWNER_DRIVER_CONTROLLED > > ? > > There is a bool 'suprress_bind_attrs' already so it could be done like > this: > > bool suppress_bind_attrs:1; > > /* If set the driver must call iommu_XX as the first action in probe() */ > bool suppress_dma_owner:1; > > Which is pretty low cost. Yes. Pretty low cost to fix the BUG_ON() issue. Any kernel-DMA driver binding is blocked if the device's iommu group has been put into user- dma mode. Another issue is, when putting a device into user-dma mode, all devices belonging to the same iommu group shouldn't be bound with a kernel-dma driver. Kevin's prototype checks this by READ_ONCE(dev->driver). This is not lock safe as discussed below, https://lore.kernel.org/linux-iommu/20210927130935.GZ964074@nvidia.com/ Any guidance on this? Best regards, baolu _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu