Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp310373iob; Tue, 3 May 2022 18:18:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLT0WOXpem+dbquIazNIbx7flB9oXboe6tOZdck4GwPDt6f2553RHxv3czITq+V20bSycb X-Received: by 2002:a17:903:32c9:b0:15e:c1cc:2409 with SMTP id i9-20020a17090332c900b0015ec1cc2409mr2276956plr.2.1651627121042; Tue, 03 May 2022 18:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651627121; cv=none; d=google.com; s=arc-20160816; b=H5AXqD/7uppfoaBC/zmjJ2ln7c4u2FEXyn7Q6cZuz7OU0CMOkgxWh2x+42wqQe9Jki xSlhZQMLgSQqbUaMxlNWR/t6PlMhjjlDVs6Mclw8v8zN/d79PAWDPgPmcN0xzr58D4lC yIyPWhKGDKuf9d40im7JYESEdtOmSVZwILMoOzhZsDOB6i10lGcQYKoCmrjYaYf3D+B/ u9ZAgMXOpnIPKdU+xtEDuQ0gus1AyhaAQHMcr5UPSVnib6/A3nBq2UzK959+brNY1NaH 2xvSjlcT+vwrOSZd5tyCSWJ1QPabrp4vMWoZOibnUb6minRg5bQNQ1vZAD5EtFeMr7mj uoZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9gjEyY8o65rJfUi2R/5q726th223KCfR89ZxIyy7Kvw=; b=r7P4CPwatlUVWKPpN/gxSxVUxhNSKSQqbeF6/ai9GuUEjchEQezLBo8O6Div3Mw/jR Wu/NiACTtF6UjuvZ5v55IVz4x0Q4QE55PH0DI4gBnBbXtHwg+w0k7oTLbFGrExwBLA3j 70MKKUAEd7gxA3aTalVnlPusd5TA1ZufpF78GksrPym5TDVeeELI3Z7kvmQwUwjBZQGn vhhoUQtAu0DMIXRnswIr47kv5cJ2+HXIuOgBNqjn30SVPES3fIlvrjwegNh4hGgdDfFE W4xJa/+FizOpdcMX+A6NsimFakapRWO5Ht5SWGSG31Mq0WlLfwy/pLfv323fL1lqPXlB f9lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZNqaq/uE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d12-20020a170902cecc00b00153b2d16545si5814132plg.333.2022.05.03.18.18.24; Tue, 03 May 2022 18:18:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZNqaq/uE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241072AbiECSN0 (ORCPT + 99 others); Tue, 3 May 2022 14:13:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241062AbiECSNW (ORCPT ); Tue, 3 May 2022 14:13:22 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1B923EBB9 for ; Tue, 3 May 2022 11:09:48 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id dk23so34955406ejb.8 for ; Tue, 03 May 2022 11:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9gjEyY8o65rJfUi2R/5q726th223KCfR89ZxIyy7Kvw=; b=ZNqaq/uE1FvHcpZ723NGH4mJuGNVsmIWAFT1HzkYo+YbUPOssbd8ZiZtdVi99Hsm+D ftZ0CpOSqPqAmBbDjy5WSC8rKUrwO/pDLOzEPkMG9MBpWKlCDLE+9eiBnOswGbhRYPO7 k4Ec6IWtjWfqKNpTKPBJ+bgZkFotwJSXkFohEHaZdGkeKCbRuFmG1RDCtEtOPzdqO7Tz 2z8wJ3hQgSS6Hna69kwpTbOTtAd1dOXSkBI9ApHUuummyXmXKYoiZ+EiHj6TTfe7G0y/ b86duNQGCx1bfFEPhDi+0RqyNIm+SdQ9dpA/VzRzj7pnDVf4/ddErdeYhQrO0h8WQoxe 0R+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9gjEyY8o65rJfUi2R/5q726th223KCfR89ZxIyy7Kvw=; b=1JQnpAy2cY11PSzXuLQTXsp2yvgKSmT+mmr9McHvdVw8HQrAEToNM0m69jPES9oVgV MSwZl8LeoCm23YpX1TuoGDCcaaT77YuILKjeTEjYlP0CLaxoDABycEFty6VnKtrbcLyf tdioagkIc7E6mrokf7IWv9tJsZocrn/64ANwgjPtELF7N4nAW66wY965RlGWqTYgCS5/ Dm3jHEv+iVxVrzn7Lakk5jQ9WZLull5bTwcVpmyBw8JIgj8OcOrWLlyrwhhBIvd0bjov oWSUjb0ckAZyBQ0QvHqc+CZfMgg68ar2y97kl7DmPFNkvylLVqcAQw/RV/yQiBhjSJVg PK2A== X-Gm-Message-State: AOAM531wCOxcYQlRhVRRMC92lK2VZD/UwnhLdL5dbIVkrRv0kGrua25C xoJSxMGiVVswOC+FFEQeFL4Yiw== X-Received: by 2002:a17:906:a08b:b0:6b9:2e20:f139 with SMTP id q11-20020a170906a08b00b006b92e20f139mr17550173ejy.463.1651601387539; Tue, 03 May 2022 11:09:47 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id s8-20020aa7cb08000000b0042617ba638csm8058733edt.22.2022.05.03.11.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 11:09:46 -0700 (PDT) Date: Tue, 3 May 2022 19:09:22 +0100 From: Jean-Philippe Brucker To: Lu Baolu Cc: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Vinod Koul , Eric Auger , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 04/12] iommu/sva: Basic data structures for SVA Message-ID: References: <20220502014842.991097-1-baolu.lu@linux.intel.com> <20220502014842.991097-5-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220502014842.991097-5-baolu.lu@linux.intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 02, 2022 at 09:48:34AM +0800, Lu Baolu wrote: > Use below data structures for SVA implementation in the IOMMU core: > > - struct iommu_sva_ioas > Represent the I/O address space shared with an application CPU address > space. This structure has a 1:1 relationship with an mm_struct. It > grabs a "mm->mm_count" refcount during creation and drop it on release. Do we actually need this structure? At the moment it only keeps track of bonds, which we can move to struct dev_iommu. Replacing it by a mm pointer in struct iommu_domain simplifies the driver and seems to work Thanks, Jean > > - struct iommu_domain (IOMMU_DOMAIN_SVA type) > Represent a hardware pagetable that the IOMMU hardware could use for > SVA translation. Multiple iommu domains could be bound with an SVA ioas > and each grabs a refcount from ioas in order to make sure ioas could > only be freed after all domains have been unbound. > > - struct iommu_sva > Represent a bond relationship between an SVA ioas and an iommu domain. > If a bond already exists, it's reused and a reference is taken. > > Signed-off-by: Lu Baolu > --- > include/linux/iommu.h | 14 +++++++++++++- > drivers/iommu/iommu-sva-lib.h | 1 + > drivers/iommu/iommu-sva-lib.c | 18 ++++++++++++++++++ > 3 files changed, 32 insertions(+), 1 deletion(-) > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index ab36244d4e94..f582f434c513 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -42,6 +42,7 @@ struct notifier_block; > struct iommu_sva; > struct iommu_fault_event; > struct iommu_dma_cookie; > +struct iommu_sva_ioas; > > /* iommu fault flags */ > #define IOMMU_FAULT_READ 0x0 > @@ -64,6 +65,9 @@ struct iommu_domain_geometry { > #define __IOMMU_DOMAIN_PT (1U << 2) /* Domain is identity mapped */ > #define __IOMMU_DOMAIN_DMA_FQ (1U << 3) /* DMA-API uses flush queue */ > > +#define __IOMMU_DOMAIN_SHARED (1U << 4) /* Page table shared from CPU */ > +#define __IOMMU_DOMAIN_HOST_VA (1U << 5) /* Host CPU virtual address */ > + > /* > * This are the possible domain-types > * > @@ -86,6 +90,8 @@ struct iommu_domain_geometry { > #define IOMMU_DOMAIN_DMA_FQ (__IOMMU_DOMAIN_PAGING | \ > __IOMMU_DOMAIN_DMA_API | \ > __IOMMU_DOMAIN_DMA_FQ) > +#define IOMMU_DOMAIN_SVA (__IOMMU_DOMAIN_SHARED | \ > + __IOMMU_DOMAIN_HOST_VA) > > struct iommu_domain { > unsigned type; > @@ -95,6 +101,7 @@ struct iommu_domain { > void *handler_token; > struct iommu_domain_geometry geometry; > struct iommu_dma_cookie *iova_cookie; > + struct iommu_sva_ioas *sva_ioas; > }; > > static inline bool iommu_is_dma_domain(struct iommu_domain *domain) > @@ -628,7 +635,12 @@ struct iommu_fwspec { > * struct iommu_sva - handle to a device-mm bond > */ > struct iommu_sva { > - struct device *dev; > + struct device *dev; > + struct iommu_sva_ioas *sva_ioas; > + struct iommu_domain *domain; > + /* Link to sva ioas's bonds list */ > + struct list_head node; > + refcount_t users; > }; > > int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, > diff --git a/drivers/iommu/iommu-sva-lib.h b/drivers/iommu/iommu-sva-lib.h > index 8909ea1094e3..9c5e108e2c8a 100644 > --- a/drivers/iommu/iommu-sva-lib.h > +++ b/drivers/iommu/iommu-sva-lib.h > @@ -10,6 +10,7 @@ > > int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max); > struct mm_struct *iommu_sva_find(ioasid_t pasid); > +struct mm_struct *iommu_sva_domain_mm(struct iommu_domain *domain); > > /* I/O Page fault */ > struct device; > diff --git a/drivers/iommu/iommu-sva-lib.c b/drivers/iommu/iommu-sva-lib.c > index 106506143896..d524a402be3b 100644 > --- a/drivers/iommu/iommu-sva-lib.c > +++ b/drivers/iommu/iommu-sva-lib.c > @@ -3,6 +3,8 @@ > * Helpers for IOMMU drivers implementing SVA > */ > #include > +#include > +#include > #include > > #include "iommu-sva-lib.h" > @@ -10,6 +12,22 @@ > static DEFINE_MUTEX(iommu_sva_lock); > static DECLARE_IOASID_SET(iommu_sva_pasid); > > +struct iommu_sva_ioas { > + struct mm_struct *mm; > + ioasid_t pasid; > + > + /* Counter of domains attached to this ioas. */ > + refcount_t users; > + > + /* All bindings are linked here. */ > + struct list_head bonds; > +}; > + > +struct mm_struct *iommu_sva_domain_mm(struct iommu_domain *domain) > +{ > + return domain->sva_ioas->mm; > +} > + > /** > * iommu_sva_alloc_pasid - Allocate a PASID for the mm > * @mm: the mm > -- > 2.25.1 >