Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3903160iog; Tue, 21 Jun 2022 08:10:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1seKbCAmNo8ByCRJPtR+swevsMq3GgPdBAsg+AH+e65cTnD3DLpxAf8xI8Hx8irXvQaUYTG X-Received: by 2002:a05:6402:22b9:b0:435:750f:b4c9 with SMTP id cx25-20020a05640222b900b00435750fb4c9mr18350766edb.181.1655824220734; Tue, 21 Jun 2022 08:10:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655824220; cv=none; d=google.com; s=arc-20160816; b=pMZqv5PxQpc7UE0Rozj2U993gG3kVemTgiyLaNMkSjn0Il92W/sVjGboDkkOfBSKFv CZjbLRhAhRCInKCRUboSrc2DiJKSjHzHwAq/N0rCTybWK1CQNf4MvrYOL+pJx/McqVUD oI+veH6mRzd4i+Tv3uURWaJ04cgyti8wWxewPPj83ZDRCLAU7vZy5h2+EbYTvDLBGLWq sRSVifb58DBDaU2lgK30jjv6YaywbLdArK61A/68Hixxr2KsyooTD+6Ccklj7hx9YqW0 5xLWQeOUxdFxv6cBMIrefuAUe/cC/TLxlRaXC+lREzdwhM84pJ1YxAGGCJ8DhJZaqqHm R29w== 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=/NrJbAr+zW8j8rACb9s9pFFtUwb17+OG6vVFceFtkcI=; b=IBSD7Nf7VnlJvCc5Q8RCpJjVQsgxAL/xyYkYnhjwX5IA1kR/lCMxAFVud1LwIY5zDe ueo9qqFoIXY4YHQPc23kzWGrK3HxFtvGsTaGAHWwLwCBnHhnsc3jqj8fSLNqBCMCp1k4 AYZqUT8344tUx/ECRtZfBuesX9+CQE0qu5tF+QgTiYRFAxQw9lyRaqNBKrNoxHM2iK59 LwUfFUO3sd4KmAte9p74VWXIyCGfy1ywQ7naZl6bm8A4ENN8OuzkQlF4YbeEWAH9jnG0 4vuhVWgc7SxpKUtNivpyHuacXsqdV8DNpNQ+eqkn6E8UHFhAAznLvRD4VWLrFwfC3fEB 2LUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LqWZj4Er; 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 30-20020a170906209e00b006ff03a0cdf6si13475128ejq.951.2022.06.21.08.09.54; Tue, 21 Jun 2022 08:10:20 -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=LqWZj4Er; 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 S1351829AbiFUOsM (ORCPT + 99 others); Tue, 21 Jun 2022 10:48:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351755AbiFUOsJ (ORCPT ); Tue, 21 Jun 2022 10:48:09 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D43705FAF for ; Tue, 21 Jun 2022 07:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655822888; x=1687358888; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l0D5qDTDDoZyMPFxm4NouluQhQY8c+kpOZ5I1wmIeCE=; b=LqWZj4ErDDw2yjXjvPDAQf1FEb+k9XVqeQ/HwyHhr7XKpfHaPL1L/Da2 a3exBPqDL666K6pjwD7pP+sdSn242ewzAgJscpJ7S3PKrrT+QmYfLjw4c VZdy8gkBoqLBbRS/arLHYhZzQF9kdxCGcEjFNyejPF9VPGMKLPLvLBfUH 1L9ZTf0aDnZOFA/e96BRcT8JKytwPGbkKbGyq0Zs4dJstTEbT7xTwvXGq 5m16lNTLvyeodhmZHpzR8TeeoRWqNat1ZYiOY/uXMQPnIs2EyDqzLGHkD 7wHfW5Piw7GhIMdYUShuWKnP6bYaMTPCtHqpqG1PmBfylJ3jvauLscDTV g==; X-IronPort-AV: E=McAfee;i="6400,9594,10384"; a="305579715" X-IronPort-AV: E=Sophos;i="5.92,209,1650956400"; d="scan'208";a="305579715" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2022 07:48:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,209,1650956400"; d="scan'208";a="643659208" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga008.fm.intel.com with ESMTP; 21 Jun 2022 07:48:05 -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, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , Jean-Philippe Brucker Subject: [PATCH v9 01/11] iommu: Add max_pasids field in struct iommu_device Date: Tue, 21 Jun 2022 22:43:43 +0800 Message-Id: <20220621144353.17547-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220621144353.17547-1-baolu.lu@linux.intel.com> References: <20220621144353.17547-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 Use this field to keep the number of supported PASIDs that an IOMMU hardware is able to support. This is a generic attribute of an IOMMU and lifting it into the per-IOMMU device structure makes it possible to allocate a PASID for device without calls into the IOMMU drivers. Any iommu driver that supports PASID related features should set this field before enabling them on the devices. In the Intel IOMMU driver, intel_iommu_sm is moved to CONFIG_INTEL_IOMMU enclave so that the pasid_supported() helper could be used in dmar.c without compilation errors. Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker --- include/linux/intel-iommu.h | 3 ++- include/linux/iommu.h | 2 ++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 + drivers/iommu/intel/dmar.c | 7 +++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 4f29139bbfc3..e065cbe3c857 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -479,7 +479,6 @@ enum { #define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1) #define VTD_FLAG_SVM_CAPABLE (1 << 2) -extern int intel_iommu_sm; extern spinlock_t device_domain_lock; #define sm_supported(iommu) (intel_iommu_sm && ecap_smts((iommu)->ecap)) @@ -786,6 +785,7 @@ struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus, extern const struct iommu_ops intel_iommu_ops; #ifdef CONFIG_INTEL_IOMMU +extern int intel_iommu_sm; extern int iommu_calculate_agaw(struct intel_iommu *iommu); extern int iommu_calculate_max_sagaw(struct intel_iommu *iommu); extern int dmar_disabled; @@ -802,6 +802,7 @@ static inline int iommu_calculate_max_sagaw(struct intel_iommu *iommu) } #define dmar_disabled (1) #define intel_iommu_enabled (0) +#define intel_iommu_sm (0) #endif static inline const char *decode_prq_descriptor(char *str, size_t size, diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 5e1afe169549..03fbb1b71536 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -318,12 +318,14 @@ struct iommu_domain_ops { * @list: Used by the iommu-core to keep a list of registered iommus * @ops: iommu-ops for talking to this iommu * @dev: struct device for sysfs handling + * @max_pasids: number of supported PASIDs */ struct iommu_device { struct list_head list; const struct iommu_ops *ops; struct fwnode_handle *fwnode; struct device *dev; + u32 max_pasids; }; /** diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 88817a3376ef..ae8ec8df47c1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3546,6 +3546,7 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) /* SID/SSID sizes */ smmu->ssid_bits = FIELD_GET(IDR1_SSIDSIZE, reg); smmu->sid_bits = FIELD_GET(IDR1_SIDSIZE, reg); + smmu->iommu.max_pasids = 1UL << smmu->ssid_bits; /* * If the SMMU supports fewer bits than would fill a single L2 stream diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 592c1e1a5d4b..6c338888061a 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -1123,6 +1123,13 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) raw_spin_lock_init(&iommu->register_lock); + /* + * A value of N in PSS field of eCap register indicates hardware + * supports PASID field of N+1 bits. + */ + if (pasid_supported(iommu)) + iommu->iommu.max_pasids = 2UL << ecap_pss(iommu->ecap); + /* * This is only for hotplug; at boot time intel_iommu_enabled won't * be set yet. When intel_iommu_init() runs, it registers the units -- 2.25.1