Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5848323iob; Tue, 10 May 2022 05:15:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpiWLIXGDhOufnH19PW7t+xcOGQ9Jjkqw3ZwbcSZE8MTjPeSoa7mjaDUttt9zNzGZDsTH/ X-Received: by 2002:a05:6402:1c93:b0:428:1818:4fe7 with SMTP id cy19-20020a0564021c9300b0042818184fe7mr22494808edb.129.1652184901248; Tue, 10 May 2022 05:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652184901; cv=none; d=google.com; s=arc-20160816; b=ssxOMCARbV0NE6m5IXJq8j8qeDg1oioBPBHWsDQkOZOXe/h0V9Ja58a8j79qvP7QMc afe0gr5X6Y2j9zNzviVbgyaYXnPy0cH7wU8r0asCI5PBlMSLKBybrbXcts60Pq4nVaiL InG3SAib246jlFbFL1mqt3WtiZRq6e3BUuYIUOxSPwobpjufAHOY3L84t+ixRNFMQKzH qkiVjye4O2Neg+V0NuLvrz6tptxybauke+MC1Vv594uwi1Vq2pUB8RELXr3t00nu6bjH glw/TS8SnE8qD2qet9bxhBQDvBFEE30FsaGUQ/+F+bwx+cUWU2Y3rzVym9klsiXw8mpL OOVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Hl55KbujNGwC3ag6VCB5fwtbKvluQ7NBbAT+kUJzJJ0=; b=Y7z+6i6tQUyh4bQGDx0Gbo/xLRVqmzAWeTeAD7dVXAdOggwdCE3zTw5PPuBjF5NYRA JrYlIpssWF/DwOTzXN6y5PxkFsVi1cY4tspF4OBSeO8pRH3qeawwudY4yr/k76VkLgHK YUs1RQ9JeZ4O2o6nOe0AuVn/itQ1sSnvKdC5qLLwtoN0fqDwCalgX0MWd1Sn0x2ZiKE2 zmCJiOXIspUDLgsa9VpTLuaY+4iaSssjyu7tQRF8ysgBHjDGlWEaedcPqg2ReSjGFe5i NIH9PRm+v0vCv+CdmmfAM5O+4jRXW8zpHOWO3jhymroyRnCazyDt73c1es/pRgFt1nUM zBnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GzNcFKo6; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g6-20020a17090669c600b006f428fb25b5si16527899ejs.674.2022.05.10.05.14.35; Tue, 10 May 2022 05:15:01 -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=@intel.com header.s=Intel header.b=GzNcFKo6; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237068AbiEJGZX (ORCPT + 99 others); Tue, 10 May 2022 02:25:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237089AbiEJGZB (ORCPT ); Tue, 10 May 2022 02:25:01 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75CD1F62E for ; Mon, 9 May 2022 23:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652163664; x=1683699664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VjhNoKI6MtW1lOMCYZbpbYvPa5VAnC2OCUg7RydhhmI=; b=GzNcFKo69X2N/KIgKsbasrP2rtxT6Ql5GpMAGjt3usMgWGbNdoYGCrDS 0n9QkPHo6JeQzh9+SOlIWRemrKBXeIvndqD+CLMHKf9gqsKTMlyzx8rvY 3giLv0Us9FJcEQXio2J89P5hmLUR8YNpaDCH8uyOOaud8yrETo52nnW8b OqEoiUk+P/xGLK6ti1Z2WkglBmC91nB10wdDhTOzycvlspD07GCqsSwPc 66/8JgFqjEpbCeTT9H2bru3FY1Hm6xKnDD4cBQAKABMOrVKZ0Fx3WJGqo Wu9srJfpUgwSN9IMWp2PDWdDaTes7xjKPq5Gb9KV9fjcnR8J+j2AlrUUl g==; X-IronPort-AV: E=McAfee;i="6400,9594,10342"; a="332312921" X-IronPort-AV: E=Sophos;i="5.91,213,1647327600"; d="scan'208";a="332312921" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2022 23:21:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,213,1647327600"; d="scan'208";a="552636440" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga002.jf.intel.com with ESMTP; 09 May 2022 23:21:00 -0700 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Vinod Koul Cc: Eric Auger , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu , Jean-Philippe Brucker Subject: [PATCH v6 04/12] iommu/sva: Basic data structures for SVA Date: Tue, 10 May 2022 14:17:30 +0800 Message-Id: <20220510061738.2761430-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220510061738.2761430-1-baolu.lu@linux.intel.com> References: <20220510061738.2761430-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Use below data structures for SVA implementation in the IOMMU core: - 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 mm and each grabs a mm_count of the mm in order to make sure mm could only be freed after all domains have been unbound. A new mm field is added to struct iommu_domain and a helper is added to retrieve mm from a domain pointer. - struct iommu_sva (existing) 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. - struct dev_iommu::sva_bonds A pasid-indexed xarray to track the bonds happened on the device. Suggested-by: Jean-Philippe Brucker Signed-off-by: Lu Baolu --- include/linux/iommu.h | 13 +++++++++++++ drivers/iommu/iommu.c | 3 +++ 2 files changed, 16 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ab36244d4e94..2921e634491e 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -64,6 +64,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 +89,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 +100,9 @@ struct iommu_domain { void *handler_token; struct iommu_domain_geometry geometry; struct iommu_dma_cookie *iova_cookie; +#ifdef CONFIG_IOMMU_SVA + struct mm_struct *mm; +#endif }; static inline bool iommu_is_dma_domain(struct iommu_domain *domain) @@ -380,6 +388,9 @@ struct dev_iommu { struct iommu_device *iommu_dev; void *priv; unsigned int pasid_bits; +#ifdef CONFIG_IOMMU_SVA + struct xarray sva_bonds; +#endif }; int iommu_device_register(struct iommu_device *iommu, @@ -629,6 +640,8 @@ struct iommu_fwspec { */ struct iommu_sva { struct device *dev; + struct iommu_domain *domain; + refcount_t users; }; int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 16e8db2d86fc..1abff5fc9554 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -202,6 +202,9 @@ static struct dev_iommu *dev_iommu_get(struct device *dev) return NULL; mutex_init(¶m->lock); +#ifdef CONFIG_IOMMU_SVA + xa_init(¶m->sva_bonds); +#endif dev->iommu = param; return param; } -- 2.25.1