Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1208011imu; Sat, 15 Dec 2018 17:27:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/USmxIM3+dL/IoJw27mSM1lWWHBaSCysDzd1QG0b4kK7ymaQhf/Y9Klyorjg5DjTwOnftR4 X-Received: by 2002:a17:902:7c05:: with SMTP id x5mr7937222pll.273.1544923678315; Sat, 15 Dec 2018 17:27:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544923678; cv=none; d=google.com; s=arc-20160816; b=oqVvXomZRnSIxZwo4+pF/VMRvTFijRvZ24Z9a3nZV53Uzp2fao/FldF5Eajt1F6BB+ ut3XSNXTiOo4V3J48NO9Plc02F6iQLtGJvd4zOt2pKJjXGitzod2K5MqDAeQwj0hZUmp vlBeNwh6jxM91cwo7h/jp5/OImZBHzJ+yRnhQuRY1BwqAttAEhbGftQXapiuejbJyF5v pwfNqbd0aFjzjqujJd7qQXN0njZfVZQF7Tqkgyyp/QaYIJDCjLv6KhWxiflNK9lBc+rK mqaD9vdYNCT8/3wR/LjDf6Dxph9IA1gC+NTI7UavZPjdGGFHKys13yVvQ9CTVt+mnTuQ /4tw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:cc; bh=dJzqfamQaEwWIzW5/bUhX12cj+K5Yp5M2q8vlkvnUNg=; b=Pfh49iegoPjJDkY/Ygdve9liiycI9eyZHnWtDz/pGFMCi080kEsKV1T9zcN8qUkxOD 9w64y2VYDle8rks7tAvY3K25Xg/WfZRQFSzPKtq0RoPvM30kO7N6Cb+c41p3SxxQQkoQ lFgkncO5/c7tUpK0G6Mh4sG3BnGo3I2brTeQ6hqb5n/eb40deUT2WHVqUdjjZnO9sG8+ FGTsCaJ8bPXzl0ovS2iAUAzPR3kZH1UOUeU8SqFbZ2oKMUB/qzpcMSd6izeBR0sktkwO 9LJshJK7B1FwLh926L4gLxA7JT5LK02C38Xbm783lPRsnJrK08u+mJ8sZWZARRQ9DsoS MuiQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si8111402pfq.129.2018.12.15.17.27.03; Sat, 15 Dec 2018 17:27:58 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729069AbeLPBYT (ORCPT + 99 others); Sat, 15 Dec 2018 20:24:19 -0500 Received: from mga02.intel.com ([134.134.136.20]:32192 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727227AbeLPBYT (ORCPT ); Sat, 15 Dec 2018 20:24:19 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Dec 2018 17:24:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,359,1539673200"; d="scan'208";a="99054648" Received: from allen-box.sh.intel.com (HELO [10.239.161.122]) ([10.239.161.122]) by orsmga007.jf.intel.com with ESMTP; 15 Dec 2018 17:24:13 -0800 Cc: baolu.lu@linux.intel.com, "Raj, Ashok" , "Kumar, Sanjay K" , "Pan, Jacob jun" , "Tian, Kevin" , Jean-Philippe Brucker , "Sun, Yi Y" , "peterx@redhat.com" , "Bie, Tiwei" , "Zeng, Xin" , "iommu@lists.linux-foundation.org" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Jacob Pan Subject: Re: [RFC PATCH 1/5] iommu: Add APIs for IOMMU PASID management To: "Liu, Yi L" , Joerg Roedel , David Woodhouse , Alex Williamson , Kirti Wankhede References: <20181112064501.2290-1-baolu.lu@linux.intel.com> <20181112064501.2290-2-baolu.lu@linux.intel.com> From: Lu Baolu Message-ID: <63ba6b78-ab31-4f54-002c-4c3baf818d3e@linux.intel.com> Date: Sun, 16 Dec 2018 09:20:38 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 12/16/18 6:38 AM, Liu, Yi L wrote: >> From: Lu Baolu [mailto:baolu.lu@linux.intel.com] >> Sent: Sunday, November 11, 2018 10:45 PM >> Subject: [RFC PATCH 1/5] iommu: Add APIs for IOMMU PASID management >> >> This adds APIs for IOMMU drivers and device drivers to manage the PASIDs used for >> DMA transfer and translation. It bases on I/O ASID allocator for PASID namespace >> management and relies on vendor specific IOMMU drivers for paravirtual PASIDs. >> >> Below APIs are added: >> >> * iommu_pasid_init(pasid) >> - Initialize a PASID consumer. The vendor specific IOMMU >> drivers are able to set the PASID range imposed by IOMMU >> hardware through a callback in iommu_ops. >> >> * iommu_pasid_exit(pasid) >> - The PASID consumer stops consuming any PASID. >> >> * iommu_pasid_alloc(pasid, min, max, private, *ioasid) >> - Allocate a PASID and associate a @private data with this >> PASID. The PASID value is stored in @ioaisd if returning >> success. >> >> * iommu_pasid_free(pasid, ioasid) >> - Free a PASID to the pool so that it could be consumed by >> others. >> >> This also adds below helpers to lookup or iterate PASID items associated with a >> consumer. >> >> * iommu_pasid_for_each(pasid, func, data) >> - Iterate PASID items of the consumer identified by @pasid, >> and call @func() against each item. An error returned from >> @func() will break the iteration. >> >> * iommu_pasid_find(pasid, ioasid) >> - Retrieve the private data associated with @ioasid. >> >> Cc: Ashok Raj >> Cc: Jacob Pan >> Cc: Kevin Tian >> Cc: Jean-Philippe Brucker >> Signed-off-by: Lu Baolu >> --- >> drivers/iommu/Kconfig | 1 + >> drivers/iommu/iommu.c | 89 +++++++++++++++++++++++++++++++++++++++++++ >> include/linux/iommu.h | 73 +++++++++++++++++++++++++++++++++++ >> 3 files changed, 163 insertions(+) >> >> diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index >> d9a25715650e..39f2bb76c7b8 100644 >> --- a/drivers/iommu/Kconfig >> +++ b/drivers/iommu/Kconfig >> @@ -1,6 +1,7 @@ >> # IOMMU_API always gets selected by whoever wants it. >> config IOMMU_API >> bool >> + select IOASID >> >> menuconfig IOMMU_SUPPORT >> bool "IOMMU Hardware Support" >> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index >> 0b7c96d1425e..570b244897bb 100644 >> --- a/drivers/iommu/iommu.c >> +++ b/drivers/iommu/iommu.c >> @@ -2082,3 +2082,92 @@ void iommu_detach_device_aux(struct iommu_domain >> *domain, struct device *dev) >> } >> } >> EXPORT_SYMBOL_GPL(iommu_detach_device_aux); >> + >> +/* >> + * APIs for PASID used by IOMMU and the device drivers which depend >> + * on IOMMU. >> + */ >> +struct iommu_pasid *iommu_pasid_init(struct bus_type *bus) { > > I'm thinking about if using struct iommu_domain here is better > than struct bus_type. The major purpose is to pass iommu_ops > in it and route into iommu-sublayer. iommu_domain may be > better since some modules like vfio_iommu_type1 would use > iommu_domain more than bus type. But drivers might call this during initialization when it doesn't has any domain yet. Best regards, Lu Baolu