Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1111193imu; Sat, 15 Dec 2018 14:42:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/X2ehN5VvZ4Gk4/0IszN7ymGGDTrJ1Q3UCt9X+TYdAJsnhjHwTpIGwioAvyxwFiPrNCbluA X-Received: by 2002:a63:e21:: with SMTP id d33mr7411760pgl.272.1544913760500; Sat, 15 Dec 2018 14:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544913760; cv=none; d=google.com; s=arc-20160816; b=HkoK59tnVFjNWfIuMuxRAqKy0TzNgARivQJxqvVkfHygTGKf2z8XqdG9thFYo0Kly2 ohLtq3B2xVKTh5XhR2e1x5z0IxHOKVdNBBKZcovFUqQRxNvhY49+SWHkQ3Eje2XDDnSt 5masta5+cF/9HcAur6fz5wUXpXhmLGJEzONBv9TxmwxTD3kjDT+DCXCq6pLBW+XzFXhl sFIdpZp6EHgeZlckmZjdHH/aBAHCvC/WykG94gVwyO4nWhBg4HxH4qLTpqWS2Jd7+5X3 gqnlL4GCuuRgMrtFyTJFYc1Z7sZ3qwALV2QH6wPsMRWPvQJgHswUW6x9baBBaNUoWBwE Sg1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=FKeQUtmcRzd2zrJjRw/m2Q8KO+K43HOZjq+SXacMevQ=; b=S7KPZ6agYzN5wDIj+4q0coLQftSbb3jyqiSNdvXqwt9RUQabQ1z9JgeJu25VdNbqEx mPzHWmgTcWhn0W5vFY21H4klekBlJ0R0ySyPFDLMoBPvFIoi3WAsnW7HV/VNzCpE4z47 I5hb3If35zzgVNxCOoCZOQ4lIpKO07nothZwm6NXxA2s2+xMHxakLJ+47ipYrE1+r4kU zLZ/p+r9qq7izj6PMmMvlurEeHbEL6vuw3qZafp95VdV73+iHOSjvGw7gFUtSDn2CII9 JiQjKVDd1xNSSY1VkoimfYOOcPCUxOdNseGcRJVriBldAbzSDzia6lsMH2WY3oESYjFz Hk/w== 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 q26si5041000pgk.162.2018.12.15.14.41.27; Sat, 15 Dec 2018 14:42:40 -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 S1729605AbeLOWib convert rfc822-to-8bit (ORCPT + 99 others); Sat, 15 Dec 2018 17:38:31 -0500 Received: from mga05.intel.com ([192.55.52.43]:35114 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727229AbeLOWia (ORCPT ); Sat, 15 Dec 2018 17:38:30 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Dec 2018 14:38:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,358,1539673200"; d="scan'208";a="126264857" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga002.fm.intel.com with ESMTP; 15 Dec 2018 14:38:29 -0800 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sat, 15 Dec 2018 14:38:29 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sat, 15 Dec 2018 14:38:29 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.203]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.201]) with mapi id 14.03.0415.000; Sun, 16 Dec 2018 06:38:27 +0800 From: "Liu, Yi L" To: Lu Baolu , Joerg Roedel , "David Woodhouse" , Alex Williamson , Kirti Wankhede CC: "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 Thread-Topic: [RFC PATCH 1/5] iommu: Add APIs for IOMMU PASID management Thread-Index: AQHUelOoaj4q5o5bw0yVukg2nF8lF6WAlpzw Date: Sat, 15 Dec 2018 22:38:26 +0000 Message-ID: References: <20181112064501.2290-1-baolu.lu@linux.intel.com> <20181112064501.2290-2-baolu.lu@linux.intel.com> In-Reply-To: <20181112064501.2290-2-baolu.lu@linux.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZjBkNWIwYmQtYWQyMS00ZGFkLTgxNzktMDFjMGRlZjM1NjliIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiSkVzWnpuU2VYNXB4dDJrYUNKT2Jydzd4bWYyeXVMdHpXWVp2eHdRdmZVWmlUQmRCTnVQYlJFQ0UwcnZ4M2l5ZSJ9 x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > 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. Thanks, Yi Liu