Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp337518rwe; Fri, 26 Aug 2022 06:05:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5yNbzq/2rjcZ2LZQDOkujvMMpoLJZGCrV/TTAvlgQZ12jTrrQae9xYbvBjnH5MpGlBhrbO X-Received: by 2002:a17:90b:4f82:b0:1fb:2bc6:abd5 with SMTP id qe2-20020a17090b4f8200b001fb2bc6abd5mr4294066pjb.63.1661519148340; Fri, 26 Aug 2022 06:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661519148; cv=none; d=google.com; s=arc-20160816; b=AiMeTlGUqYgs2m0MmacDtTFrDfXVDyJMqclEUTbD6vrDq64DFDC9jiExhraqUWLoWF S5jNT0PZK7Y9tMvFcx+7gy4CoGjhVY0Fi2flwF6N9lSGaHntpYJk5bGNNJj7xeTJe5jo I4FYhpKllorwx1Qr4TNF4swZBrs5dThlhXSbdsbjqNtsrOJm9h44IvwNc7H/mY//K3a+ +H7ROS5NhzZV4vnCKa2YS6Jk+ZY9lrNdCgGw2L3Uz8O6oiXX4njIDGhgbUHU3f/84qNK YBuSV7x9RHzI9Ljg7xljWZp8H5U2ns+Gnd4bLKDsF1Tv6f0FakEa/oXOyARqRGdiJAJ3 dl5w== 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=H/bNH655H8YHHwIjvFkZYhLVtg/VxBfiOgo+I1RKmvo=; b=M7nfc6wUnlyk2yd6St57f3R1gmc+oETWvNC014T52rpU1YMdYuK9T85Stu+QOWdP0N rbT++kq4rjWvQglM9cXKRa26j8HyyrOaZuexVSLUWa7KRQN4elN1STgd9mPo3lGnnJrZ 5n/aViajOd6SIY0J7B7h4r0SNsLGmpAmZwpsuuN0iQdawJm2vhefwqAphChS/7msuZtR oF2tz4Q83HQHz3+K/htiX3zIjCrzABkte4hQh33aNm2Ti9I8pwXgkm+2MJq+5pZGfzGZ 921El9PpO5H9jZ/vtUmPc4zF9xrKmec0VcVtMkJ8uGb7w0VNEN4tMrzed00GYHW6tSp7 WnEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kgBErDC6; 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 r84-20020a632b57000000b0042a0df51028si1592799pgr.797.2022.08.26.06.05.36; Fri, 26 Aug 2022 06:05:48 -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=kgBErDC6; 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 S1343514AbiHZMRb (ORCPT + 99 others); Fri, 26 Aug 2022 08:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbiHZMRZ (ORCPT ); Fri, 26 Aug 2022 08:17:25 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50587D6BAF; Fri, 26 Aug 2022 05:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661516243; x=1693052243; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xJb2ujLWIghxWSKF4394g+Zts6PWE+8ivyph6c5ThSc=; b=kgBErDC6Zg1Vp3HSLS1a3JKI2+fC+XhWLb2jUtmnG1YTYlp9rrWyp5A2 pHdtYE6rQnzRm//x+pW40P0SI6SyDspUVv17IaHKxNHO9YunQch8FSFdu 73SsZF+lvf4p0ecYVSxFq4yqGgDY+wAnEgWjNcY/Ck0xPaLKaxDFpN9AF inTMaQ8jBmmyYrPbBFQLOqPCDIGbArPoydVqFN0sAP582Buh8SovH7zfc /ySDL66zCX1lfGuACB9BRGPE+ThnPMQ7VObyymIMrw5x5P2gE13oKEORy wTIjoxa3bBpJot9F05ZSh/ri79p3kajISSoBPgN86DxH4KRK071W6KAp2 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="293234173" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="293234173" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 05:17:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="606747466" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 26 Aug 2022 05:17:18 -0700 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Bjorn Helgaas , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Fenghua Yu , Vinod Koul Cc: Eric Auger , Liu Yi L , Jacob jun Pan , Zhangfei Gao , Zhu Tony , iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu , Jean-Philippe Brucker Subject: [PATCH v12 01/17] iommu: Add max_pasids field in struct iommu_device Date: Fri, 26 Aug 2022 20:11:25 +0800 Message-Id: <20220826121141.50743-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220826121141.50743-1-baolu.lu@linux.intel.com> References: <20220826121141.50743-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 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 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 Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Reviewed-by: Yi Liu Tested-by: Zhangfei Gao Tested-by: Tony Zhu --- include/linux/iommu.h | 2 ++ drivers/iommu/intel/iommu.h | 4 ++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 + drivers/iommu/intel/dmar.c | 7 +++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ea30f00dc145..ed172cbdabf2 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -322,12 +322,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/intel/iommu.h b/drivers/iommu/intel/iommu.h index 74b0e19e23ee..c4831d2bee93 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -478,8 +478,6 @@ enum { #define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1) #define VTD_FLAG_SVM_CAPABLE (1 << 2) -extern int intel_iommu_sm; - #define sm_supported(iommu) (intel_iommu_sm && ecap_smts((iommu)->ecap)) #define pasid_supported(iommu) (sm_supported(iommu) && \ ecap_pasid((iommu)->ecap)) @@ -794,6 +792,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; @@ -809,6 +808,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/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index d32b02336411..f88541be8213 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3521,6 +3521,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 5a8f780e7ffd..3528058d253e 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -1104,6 +1104,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