From nobody Tue Nov 26 05:58:23 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC9661E25F2 for ; Mon, 21 Oct 2024 08:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500985; cv=none; b=W2TqovG/Yoq+t6vwXC/7bUnNHmQcqaMQVNDX73wQO1HjsRa8YSNQk7lFTriHFDpc5SCyPU9wXGwtC0nBJRPeK7yAmR2XmWzg9UyIX7u6bUWrL+PGR7z0MMDdL0/6d/okwHZUKDPrJrj99pVIySdgbtZGVKbzxXt7+I5clAiXLfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500985; c=relaxed/simple; bh=Rpe2Bmi9GBIWmSjY0Uca0kWikIc6QccAZcI5FDF+nls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LFQcfSqZh7F/IGjV4XMJvjrtnU062F3x5eyZofB0eqUiXKSa/xtid8UASNEnJvQxLcQ/Oh7uOpq74ermbBPUv2cC9YcbwzjpCqp4AkCTbDIh49qVfVvKVCZmNhWd30k/KlnhHEjybuYuzdo9Vm2YcW/YWjYLQbwFTYakIwljqiM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Qnyoc3SF; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Qnyoc3SF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729500984; x=1761036984; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rpe2Bmi9GBIWmSjY0Uca0kWikIc6QccAZcI5FDF+nls=; b=Qnyoc3SFtx1CJQP7aVdtdOTI4V4vVhgFGuKZD1C9fhUjqEKS5bPhCl7a g5YZeBbvN9s4oBPZl28GQhczb/RoWPuVWkCaocPTrLjjEEyPgKv6RRxK/ 41QhwldOnrhN6CeLcvNjuPocLzlNAFr0eU2RTWiiyLSR1GHfLoadzUHJf lkdCwHHVbDamZtnWsJnefypYGS8nmwChEeiwgunC+YNsaHhEdArbeYEFm AkR/n6a8IbRc2CJYHMAiHp99iPthLAWTCse1nFXx7ihHTmR2LOJzBGM6D Rf2CF6YvK8/kYp+u/pQex+FmoZlc4l3byOG4oV0Nlnhl/EG/A6YZjCfUK A==; X-CSE-ConnectionGUID: hE8LIe4MS32h0NBwnQ7wrg== X-CSE-MsgGUID: QqLR/hotQp2q3EQ8dkLCvA== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="32780319" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="32780319" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:56:24 -0700 X-CSE-ConnectionGUID: U55vAQldT4m5jUcRESMe8A== X-CSE-MsgGUID: R3A7XOy1SKKyFW/wYJ6iWQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="79812712" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa010.fm.intel.com with ESMTP; 21 Oct 2024 01:56:21 -0700 From: Lu Baolu To: iommu@lists.linux.dev Cc: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Yi Liu , Vasant Hegde , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 1/7] iommu/vt-d: Add domain_alloc_paging support Date: Mon, 21 Oct 2024 16:51:18 +0800 Message-ID: <20241021085125.192333-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021085125.192333-1-baolu.lu@linux.intel.com> References: <20241021085125.192333-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the domain_alloc_paging callback for domain allocation using the iommu_paging_domain_alloc() interface. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 9f6b0780f2ef..4803e0cb8279 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4590,6 +4590,19 @@ static struct iommu_domain identity_domain =3D { }, }; =20 +static struct iommu_domain *intel_iommu_domain_alloc_paging(struct device = *dev) +{ + struct dmar_domain *dmar_domain; + bool first_stage; + + first_stage =3D first_level_by_default(0); + dmar_domain =3D paging_domain_alloc(dev, first_stage); + if (IS_ERR(dmar_domain)) + return ERR_CAST(dmar_domain); + + return &dmar_domain->domain; +} + const struct iommu_ops intel_iommu_ops =3D { .blocked_domain =3D &blocking_domain, .release_domain =3D &blocking_domain, @@ -4599,6 +4612,7 @@ const struct iommu_ops intel_iommu_ops =3D { .domain_alloc =3D intel_iommu_domain_alloc, .domain_alloc_user =3D intel_iommu_domain_alloc_user, .domain_alloc_sva =3D intel_svm_domain_alloc, + .domain_alloc_paging =3D intel_iommu_domain_alloc_paging, .probe_device =3D intel_iommu_probe_device, .release_device =3D intel_iommu_release_device, .get_resv_regions =3D intel_iommu_get_resv_regions, --=20 2.43.0 From nobody Tue Nov 26 05:58:23 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8971E1E32AC for ; Mon, 21 Oct 2024 08:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500988; cv=none; b=hY4f8oBNbNk0lt58sDbwWVd0PsbFHDZMnncu+MZxjYUqrjPvIg+iMshnoPLp4AOzuumOQm3YqjwvWROpZDJY4sEVSGDYTcK/YP0/5ZrJX8i63kvWPtidzDs7BEk5zuSxg3jEZL1pD5shW21bUFJ6y6j/xBipX1dmj7rbBXkuFck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500988; c=relaxed/simple; bh=Ipggo0JmfDpQ0wdjbffP3UNsOLeRkPCrGAoJRWLXKUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p/EagiemHFOHa69SA2CivB6eoPj9iXy1R/5NvvQQfWxInf6CquGdUd1SXyu1VSm9UymvRVF26r6NUj6vphAkz/ttL+td3wQesYeByLDCrAVkerUFCEmhTwxMe8L6DM3EB/lhQ3rwM8RUXC+yGxqvZw8Wq3SaLoPWxV4tHEugBhg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=b/M/0isH; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="b/M/0isH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729500987; x=1761036987; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ipggo0JmfDpQ0wdjbffP3UNsOLeRkPCrGAoJRWLXKUk=; b=b/M/0isHHI1FdqtWziiFYaGRzgmGYzpxnUqEVRncFUOa3DjjHuQdTVYP NROWAqfZJMFA7gGmtPJPY5iCbmQlxpROMYUAmf4fHUTIGQzRqtr1oFV7s m1oslmFbXUAnjs3eXf6mGJY/KFWQO6wlU0/jfOl6wGwA6Qe+1BNofX9Fy nzx0OZyTiCMURXaFy6KaCTVkEW2NdGxp/HC1SOy5plqCRZbAaHaffTnSR voC0UQzitM1AQGurZoVpW4IQTlEzey20wqqd16Ls4sX+SaClacVovBs8D Ok6RDQcp2pjHAT2sVVjiO5XecwE6C2lgFOdX+A40Dl900q/XEUWJJUjv5 A==; X-CSE-ConnectionGUID: 7KXabY7QQTivOBAJ5elaEg== X-CSE-MsgGUID: GcuJxG7kQQCRdtBC3YZ5fA== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="32780330" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="32780330" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:56:27 -0700 X-CSE-ConnectionGUID: mKwt2/uCTVKYmg5oXIn4AA== X-CSE-MsgGUID: B7UPBxjfT9SU2iFko+CULw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="79812720" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa010.fm.intel.com with ESMTP; 21 Oct 2024 01:56:24 -0700 From: Lu Baolu To: iommu@lists.linux.dev Cc: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Yi Liu , Vasant Hegde , linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v2 2/7] iommu/vt-d: Remove unused domain_alloc callback Date: Mon, 21 Oct 2024 16:51:19 +0800 Message-ID: <20241021085125.192333-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021085125.192333-1-baolu.lu@linux.intel.com> References: <20241021085125.192333-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With domain_alloc_paging callback supported, the legacy domain_alloc callback will never be used anymore. Remove it to avoid dead code. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 90 ------------------------------------- 1 file changed, 90 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 4803e0cb8279..dd158ff5fd45 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1454,27 +1454,6 @@ static bool first_level_by_default(unsigned int type) return type !=3D IOMMU_DOMAIN_UNMANAGED; } =20 -static struct dmar_domain *alloc_domain(unsigned int type) -{ - struct dmar_domain *domain; - - domain =3D kzalloc(sizeof(*domain), GFP_KERNEL); - if (!domain) - return NULL; - - domain->nid =3D NUMA_NO_NODE; - if (first_level_by_default(type)) - domain->use_first_level =3D true; - INIT_LIST_HEAD(&domain->devices); - INIT_LIST_HEAD(&domain->dev_pasids); - INIT_LIST_HEAD(&domain->cache_tags); - spin_lock_init(&domain->lock); - spin_lock_init(&domain->cache_lock); - xa_init(&domain->iommu_array); - - return domain; -} - int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *io= mmu) { struct iommu_domain_info *info, *curr; @@ -1546,20 +1525,6 @@ void domain_detach_iommu(struct dmar_domain *domain,= struct intel_iommu *iommu) spin_unlock(&iommu->lock); } =20 -static int guestwidth_to_adjustwidth(int gaw) -{ - int agaw; - int r =3D (gaw - 12) % 9; - - if (r =3D=3D 0) - agaw =3D gaw; - else - agaw =3D gaw + 9 - r; - if (agaw > 64) - agaw =3D 64; - return agaw; -} - static void domain_exit(struct dmar_domain *domain) { if (domain->pgd) { @@ -3379,27 +3344,6 @@ void device_block_translation(struct device *dev) info->domain =3D NULL; } =20 -static int md_domain_init(struct dmar_domain *domain, int guest_width) -{ - int adjust_width; - - /* calculate AGAW */ - domain->gaw =3D guest_width; - adjust_width =3D guestwidth_to_adjustwidth(guest_width); - domain->agaw =3D width_to_agaw(adjust_width); - - domain->iommu_coherency =3D false; - domain->iommu_superpage =3D 0; - domain->max_addr =3D 0; - - /* always allocate the top pgd */ - domain->pgd =3D iommu_alloc_page_node(domain->nid, GFP_ATOMIC); - if (!domain->pgd) - return -ENOMEM; - domain_flush_cache(domain, domain->pgd, PAGE_SIZE); - return 0; -} - static int blocking_domain_attach_dev(struct iommu_domain *domain, struct device *dev) { @@ -3486,39 +3430,6 @@ static struct dmar_domain *paging_domain_alloc(struc= t device *dev, bool first_st return domain; } =20 -static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) -{ - struct dmar_domain *dmar_domain; - struct iommu_domain *domain; - - switch (type) { - case IOMMU_DOMAIN_DMA: - case IOMMU_DOMAIN_UNMANAGED: - dmar_domain =3D alloc_domain(type); - if (!dmar_domain) { - pr_err("Can't allocate dmar_domain\n"); - return NULL; - } - if (md_domain_init(dmar_domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) { - pr_err("Domain initialization failed\n"); - domain_exit(dmar_domain); - return NULL; - } - - domain =3D &dmar_domain->domain; - domain->geometry.aperture_start =3D 0; - domain->geometry.aperture_end =3D - __DOMAIN_MAX_ADDR(dmar_domain->gaw); - domain->geometry.force_aperture =3D true; - - return domain; - default: - return NULL; - } - - return NULL; -} - static struct iommu_domain * intel_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, @@ -4609,7 +4520,6 @@ const struct iommu_ops intel_iommu_ops =3D { .identity_domain =3D &identity_domain, .capable =3D intel_iommu_capable, .hw_info =3D intel_iommu_hw_info, - .domain_alloc =3D intel_iommu_domain_alloc, .domain_alloc_user =3D intel_iommu_domain_alloc_user, .domain_alloc_sva =3D intel_svm_domain_alloc, .domain_alloc_paging =3D intel_iommu_domain_alloc_paging, --=20 2.43.0 From nobody Tue Nov 26 05:58:23 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B89A1E32D8 for ; Mon, 21 Oct 2024 08:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500991; cv=none; b=kcXS8pmj3rl+zQ9N+tf9717owMJIsAjrgyGQSC8KNjIf79erLTH3Q1EyGlInSdqhTK8KxJSkX84Shn84xvX3k2ATBEcz6Xxd7SrYw1LW7KRUrTOMKxu3wFT6RCeWy9GTnEvaGD+Kw10Nuse2v/opLlWqz36tRrN+OGxhLmUkNXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500991; c=relaxed/simple; bh=D5wGzEolDIU8tajHaJtTcRPC2Wk1mIqzyCZK/uJgEIs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rwuGlkp9wdBc2hG4eOm54ok/sqX0w5dXvTJ4GTXyCfMLR5bo2ZgMBjs88GRLFzrrpMSAMEqEcmuaRYo8Ld+Te27tW1zN0DxcRGVdLhRlUMu5sK0/cHYFfc4tmd9yM5v/x9jg8SEewk3YZnS8PSypPPJSwCB45CfFbdP+9324Oq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=oGXLLUIm; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="oGXLLUIm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729500990; x=1761036990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D5wGzEolDIU8tajHaJtTcRPC2Wk1mIqzyCZK/uJgEIs=; b=oGXLLUImZrjlQgdOIh2WE12twPgueiCma1aIxRBKfEGjIZFN4i5T29fT /wom4vFv+oBIX8e/Ot04e+3d2Y9F/I+PSSqwaK9WteW1pD4ixIrAn8mfp B97x4gnPsPkGt1OJJFr6DyhCC4mLy2ufqBShV95sTdyedIYR4FlJgJZDN qcpI1k4X5dLHANIb51VB1m3pCdRNdg6b2ZJkXwdSSTI/1YLXrTGIeRils 3aXrIxK/brCjeIwckNzSoQve0d6056xilf0zWFDMacOcw4tqENilGgfCH vt72QggiOJtPMH2XPLfBqGMj8KB/pWkGT+Gec3GSgoAb+6DN+xucNJKcA w==; X-CSE-ConnectionGUID: lznkUQonT2i5U7ySr7E93Q== X-CSE-MsgGUID: +HFtctEjQ2222LMYAaJs/A== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="32780342" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="32780342" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:56:30 -0700 X-CSE-ConnectionGUID: duPlw1HnQ+y1DJqu6olLvA== X-CSE-MsgGUID: Moi1wAnuRJCDVzmWrlJMzw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="79812737" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa010.fm.intel.com with ESMTP; 21 Oct 2024 01:56:26 -0700 From: Lu Baolu To: iommu@lists.linux.dev Cc: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Yi Liu , Vasant Hegde , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 3/7] iommu/vt-d: Enhance compatibility check for paging domain attach Date: Mon, 21 Oct 2024 16:51:20 +0800 Message-ID: <20241021085125.192333-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021085125.192333-1-baolu.lu@linux.intel.com> References: <20241021085125.192333-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The driver now supports domain_alloc_paging, ensuring that a valid device pointer is provided whenever a paging domain is allocated. Additionally, the dmar_domain attributes are set up at the time of allocation. Consistent with the established semantics in the IOMMU core, if a domain is attached to a device and found to be incompatible with the IOMMU hardware capabilities, the operation will return an -EINVAL error. This implicitly advises the caller to allocate a new domain for the device and attempt the domain attachment again. Rename prepare_domain_attach_device() to a more meaningful name. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.h | 3 +- drivers/iommu/intel/iommu.c | 70 ++++++++++++------------------------ drivers/iommu/intel/nested.c | 2 +- drivers/iommu/intel/pasid.c | 28 +-------------- 4 files changed, 26 insertions(+), 77 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 1497f3112b12..b1928ca3aaa8 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1230,8 +1230,7 @@ void __iommu_flush_iotlb(struct intel_iommu *iommu, u= 16 did, u64 addr, int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *io= mmu); void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *i= ommu); void device_block_translation(struct device *dev); -int prepare_domain_attach_device(struct iommu_domain *domain, - struct device *dev); +int paging_domain_compatible(struct iommu_domain *domain, struct device *d= ev); void domain_update_iommu_cap(struct dmar_domain *domain); =20 int dmar_ir_support(void); diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index dd158ff5fd45..eeb341aafe3e 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1606,7 +1606,7 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, int translation =3D CONTEXT_TT_MULTI_LEVEL; struct dma_pte *pgd =3D domain->pgd; struct context_entry *context; - int agaw, ret; + int ret; =20 pr_debug("Set context mapping for %02x:%02x.%d\n", bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); @@ -1623,27 +1623,15 @@ static int domain_context_mapping_one(struct dmar_d= omain *domain, =20 copied_context_tear_down(iommu, context, bus, devfn); context_clear_entry(context); - context_set_domain_id(context, did); =20 - /* - * Skip top levels of page tables for iommu which has - * less agaw than default. Unnecessary for PT mode. - */ - for (agaw =3D domain->agaw; agaw > iommu->agaw; agaw--) { - ret =3D -ENOMEM; - pgd =3D phys_to_virt(dma_pte_addr(pgd)); - if (!dma_pte_present(pgd)) - goto out_unlock; - } - if (info && info->ats_supported) translation =3D CONTEXT_TT_DEV_IOTLB; else translation =3D CONTEXT_TT_MULTI_LEVEL; =20 context_set_address_root(context, virt_to_phys(pgd)); - context_set_address_width(context, agaw); + context_set_address_width(context, domain->agaw); context_set_translation_type(context, translation); context_set_fault_enable(context); context_set_present(context); @@ -1876,20 +1864,9 @@ static int domain_setup_first_level(struct intel_iom= mu *iommu, u32 pasid) { struct dma_pte *pgd =3D domain->pgd; - int agaw, level; - int flags =3D 0; + int level, flags =3D 0; =20 - /* - * Skip top levels of page tables for iommu which has - * less agaw than default. Unnecessary for PT mode. - */ - for (agaw =3D domain->agaw; agaw > iommu->agaw; agaw--) { - pgd =3D phys_to_virt(dma_pte_addr(pgd)); - if (!dma_pte_present(pgd)) - return -ENOMEM; - } - - level =3D agaw_to_level(agaw); + level =3D agaw_to_level(domain->agaw); if (level !=3D 4 && level !=3D 5) return -EINVAL; =20 @@ -3492,42 +3469,41 @@ static void intel_iommu_domain_free(struct iommu_do= main *domain) domain_exit(dmar_domain); } =20 -int prepare_domain_attach_device(struct iommu_domain *domain, - struct device *dev) +int paging_domain_compatible(struct iommu_domain *domain, struct device *d= ev) { struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct dmar_domain *dmar_domain =3D to_dmar_domain(domain); struct intel_iommu *iommu =3D info->iommu; int addr_width; =20 + if (WARN_ON_ONCE(!(domain->type & __IOMMU_DOMAIN_PAGING))) + return -EPERM; + if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap)) return -EINVAL; =20 if (domain->dirty_ops && !ssads_supported(iommu)) return -EINVAL; =20 + if (dmar_domain->iommu_coherency !=3D + iommu_paging_structure_coherency(iommu)) + return -EINVAL; + + if (dmar_domain->iommu_superpage !=3D + iommu_superpage_capability(iommu, dmar_domain->use_first_level)) + return -EINVAL; + + if (dmar_domain->use_first_level && + (!sm_supported(iommu) || !ecap_flts(iommu->ecap))) + return -EINVAL; + /* check if this iommu agaw is sufficient for max mapped address */ addr_width =3D agaw_to_width(iommu->agaw); if (addr_width > cap_mgaw(iommu->cap)) addr_width =3D cap_mgaw(iommu->cap); =20 - if (dmar_domain->max_addr > (1LL << addr_width)) + if (dmar_domain->gaw > addr_width || dmar_domain->agaw > iommu->agaw) return -EINVAL; - dmar_domain->gaw =3D addr_width; - - /* - * Knock out extra levels of page tables if necessary - */ - while (iommu->agaw < dmar_domain->agaw) { - struct dma_pte *pte; - - pte =3D dmar_domain->pgd; - if (dma_pte_present(pte)) { - dmar_domain->pgd =3D phys_to_virt(dma_pte_addr(pte)); - iommu_free_page(pte); - } - dmar_domain->agaw--; - } =20 if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev) && context_copied(iommu, info->bus, info->devfn)) @@ -3543,7 +3519,7 @@ static int intel_iommu_attach_device(struct iommu_dom= ain *domain, =20 device_block_translation(dev); =20 - ret =3D prepare_domain_attach_device(domain, dev); + ret =3D paging_domain_compatible(domain, dev); if (ret) return ret; =20 @@ -4214,7 +4190,7 @@ static int intel_iommu_set_dev_pasid(struct iommu_dom= ain *domain, if (context_copied(iommu, info->bus, info->devfn)) return -EBUSY; =20 - ret =3D prepare_domain_attach_device(domain, dev); + ret =3D paging_domain_compatible(domain, dev); if (ret) return ret; =20 diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index 433c58944401..96016bc40f94 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -40,7 +40,7 @@ static int intel_nested_attach_dev(struct iommu_domain *d= omain, * The s2_domain will be used in nested translation, hence needs * to ensure the s2_domain is compatible with this IOMMU. */ - ret =3D prepare_domain_attach_device(&dmar_domain->s2_domain->domain, dev= ); + ret =3D paging_domain_compatible(&dmar_domain->s2_domain->domain, dev); if (ret) { dev_err_ratelimited(dev, "s2 domain is not compatible\n"); return ret; diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 2e5fa0a23299..53157e1194f4 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -345,25 +345,6 @@ int intel_pasid_setup_first_level(struct intel_iommu *= iommu, return 0; } =20 -/* - * Skip top levels of page tables for iommu which has less agaw - * than default. Unnecessary for PT mode. - */ -static int iommu_skip_agaw(struct dmar_domain *domain, - struct intel_iommu *iommu, - struct dma_pte **pgd) -{ - int agaw; - - for (agaw =3D domain->agaw; agaw > iommu->agaw; agaw--) { - *pgd =3D phys_to_virt(dma_pte_addr(*pgd)); - if (!dma_pte_present(*pgd)) - return -EINVAL; - } - - return agaw; -} - /* * Set up the scalable mode pasid entry for second only translation type. */ @@ -374,7 +355,6 @@ int intel_pasid_setup_second_level(struct intel_iommu *= iommu, struct pasid_entry *pte; struct dma_pte *pgd; u64 pgd_val; - int agaw; u16 did; =20 /* @@ -388,12 +368,6 @@ int intel_pasid_setup_second_level(struct intel_iommu = *iommu, } =20 pgd =3D domain->pgd; - agaw =3D iommu_skip_agaw(domain, iommu, &pgd); - if (agaw < 0) { - dev_err(dev, "Invalid domain page table\n"); - return -EINVAL; - } - pgd_val =3D virt_to_phys(pgd); did =3D domain_id_iommu(domain, iommu); =20 @@ -412,7 +386,7 @@ int intel_pasid_setup_second_level(struct intel_iommu *= iommu, pasid_clear_entry(pte); pasid_set_domain_id(pte, did); pasid_set_slptr(pte, pgd_val); - pasid_set_address_width(pte, agaw); + pasid_set_address_width(pte, domain->agaw); pasid_set_translation_type(pte, PASID_ENTRY_PGTT_SL_ONLY); pasid_set_fault_enable(pte); pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); --=20 2.43.0 From nobody Tue Nov 26 05:58:23 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E9791E32AC for ; Mon, 21 Oct 2024 08:56:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500993; cv=none; b=EIHZpwJZtAKKhN6PXF7E83iKKkyykhkkkUiF3u71ovIpNGAWcpNlpt3GfkvFtv60mQg9zWsxxqWN5D0Ril8HTYVvgxT8Qx6y8MGSpbHG0W6iVEbcckF/N8aMbnrkFBxFjwrFnDinJ9CUQqImWYtgyv72gFvOJcqyXPh4uuSAsac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500993; c=relaxed/simple; bh=OKL6Mu2G37CcLVl+q2h1WjYfHr6Z7zwPi0qJcVTBkT0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RtT84dJOAajo9yHGJ/KiUzTVmDdn8aU5NoSlAGFDbjqCh1KfaURZlCpUGv+4UXPtyBcSJ797K0t2h0aZ4G7kyZtaBG7SV7qIl3Zo37Ho9Z/8UivPKd4/bYME8w3FUY8iCmKJh0g8+nb6+7xBULxDxoX3xR2HG7mpOBGGTRIODTw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YxiKEyhE; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YxiKEyhE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729500993; x=1761036993; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OKL6Mu2G37CcLVl+q2h1WjYfHr6Z7zwPi0qJcVTBkT0=; b=YxiKEyhEnIGtdrPH3vr9CGFK5+Efp63cBJqmHIB3E0UBWEcKC9OAl1Id vabJtOsav7SmUPvgtpu0c7sI7L1RNMzVttizRt5WcAcfxQEZzPFkZTOtL Snvy9VhPLlq3a/nX/RNj0D7jptoznqI5KTcw0oadEcflVcRBhn0ruIZws V0YGAlSeX8O5CX0+VXKPUlivs7dOxu1QCZlGv/yqBY0/O4gzCrO17xw+F coLrkalxnfJbmJijb44Gh6d+WK0nANEQ4gvRUrXXQEQ0VTGK4dYS+MXFS X5YpUNI4NogFsWsv48hcqwm1w0LQ01+/xt73s0ZuettvV/ur1HKcu5e57 Q==; X-CSE-ConnectionGUID: 282IiWSNTkmL7Xm09E/euQ== X-CSE-MsgGUID: TJ6T1vLrRRSNaCk4rT8+vg== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="32780355" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="32780355" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:56:33 -0700 X-CSE-ConnectionGUID: QOQ2Z1/aRlqNvFMtrdsYRQ== X-CSE-MsgGUID: iuLtr2iKQYGPQQQfBlfw7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="79812754" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa010.fm.intel.com with ESMTP; 21 Oct 2024 01:56:29 -0700 From: Lu Baolu To: iommu@lists.linux.dev Cc: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Yi Liu , Vasant Hegde , linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v2 4/7] iommu/vt-d: Remove domain_update_iommu_cap() Date: Mon, 21 Oct 2024 16:51:21 +0800 Message-ID: <20241021085125.192333-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021085125.192333-1-baolu.lu@linux.intel.com> References: <20241021085125.192333-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The attributes of a paging domain are initialized during the allocation process, and any attempt to attach a domain that is not compatible will result in a failure. Therefore, there is no need to update the domain attributes at the time of domain attachment. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/iommu.c | 83 ------------------------------------- 2 files changed, 84 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index b1928ca3aaa8..f9fba9a26dac 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1231,7 +1231,6 @@ int domain_attach_iommu(struct dmar_domain *domain, s= truct intel_iommu *iommu); void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *i= ommu); void device_block_translation(struct device *dev); int paging_domain_compatible(struct iommu_domain *domain, struct device *d= ev); -void domain_update_iommu_cap(struct dmar_domain *domain); =20 int dmar_ir_support(void); =20 diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index eeb341aafe3e..756caa24008f 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -352,36 +352,6 @@ static bool iommu_paging_structure_coherency(struct in= tel_iommu *iommu) ecap_smpwc(iommu->ecap) : ecap_coherent(iommu->ecap); } =20 -static void domain_update_iommu_coherency(struct dmar_domain *domain) -{ - struct iommu_domain_info *info; - struct dmar_drhd_unit *drhd; - struct intel_iommu *iommu; - bool found =3D false; - unsigned long i; - - domain->iommu_coherency =3D true; - xa_for_each(&domain->iommu_array, i, info) { - found =3D true; - if (!iommu_paging_structure_coherency(info->iommu)) { - domain->iommu_coherency =3D false; - break; - } - } - if (found) - return; - - /* No hardware attached; use lowest common denominator */ - rcu_read_lock(); - for_each_active_iommu(iommu, drhd) { - if (!iommu_paging_structure_coherency(iommu)) { - domain->iommu_coherency =3D false; - break; - } - } - rcu_read_unlock(); -} - static int domain_update_iommu_superpage(struct dmar_domain *domain, struct intel_iommu *skip) { @@ -412,29 +382,6 @@ static int domain_update_iommu_superpage(struct dmar_d= omain *domain, return fls(mask); } =20 -static int domain_update_device_node(struct dmar_domain *domain) -{ - struct device_domain_info *info; - int nid =3D NUMA_NO_NODE; - unsigned long flags; - - spin_lock_irqsave(&domain->lock, flags); - list_for_each_entry(info, &domain->devices, link) { - /* - * There could possibly be multiple device numa nodes as devices - * within the same domain may sit behind different IOMMUs. There - * isn't perfect answer in such situation, so we select first - * come first served policy. - */ - nid =3D dev_to_node(info->dev); - if (nid !=3D NUMA_NO_NODE) - break; - } - spin_unlock_irqrestore(&domain->lock, flags); - - return nid; -} - /* Return the super pagesize bitmap if supported. */ static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain) { @@ -452,34 +399,6 @@ static unsigned long domain_super_pgsize_bitmap(struct= dmar_domain *domain) return bitmap; } =20 -/* Some capabilities may be different across iommus */ -void domain_update_iommu_cap(struct dmar_domain *domain) -{ - domain_update_iommu_coherency(domain); - domain->iommu_superpage =3D domain_update_iommu_superpage(domain, NULL); - - /* - * If RHSA is missing, we should default to the device numa domain - * as fall back. - */ - if (domain->nid =3D=3D NUMA_NO_NODE) - domain->nid =3D domain_update_device_node(domain); - - /* - * First-level translation restricts the input-address to a - * canonical address (i.e., address bits 63:N have the same - * value as address bit [N-1], where N is 48-bits with 4-level - * paging and 57-bits with 5-level paging). Hence, skip bit - * [N-1]. - */ - if (domain->use_first_level) - domain->domain.geometry.aperture_end =3D __DOMAIN_MAX_ADDR(domain->gaw -= 1); - else - domain->domain.geometry.aperture_end =3D __DOMAIN_MAX_ADDR(domain->gaw); - - domain->domain.pgsize_bitmap |=3D domain_super_pgsize_bitmap(domain); -} - struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus, u8 devfn, int alloc) { @@ -1493,7 +1412,6 @@ int domain_attach_iommu(struct dmar_domain *domain, s= truct intel_iommu *iommu) ret =3D xa_err(curr) ? : -EBUSY; goto err_clear; } - domain_update_iommu_cap(domain); =20 spin_unlock(&iommu->lock); return 0; @@ -1519,7 +1437,6 @@ void domain_detach_iommu(struct dmar_domain *domain, = struct intel_iommu *iommu) clear_bit(info->did, iommu->domain_ids); xa_erase(&domain->iommu_array, iommu->seq_id); domain->nid =3D NUMA_NO_NODE; - domain_update_iommu_cap(domain); kfree(info); } spin_unlock(&iommu->lock); --=20 2.43.0 From nobody Tue Nov 26 05:58:23 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5EBD1E3DC8 for ; Mon, 21 Oct 2024 08:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500996; cv=none; b=YtWsew6Hj1lifkVSVi+QI06sKUZQ//Q9fHwNrrAi5hOCYrvdHKZjmVMl6ApNsprzRps0VFh97lzMyNfkvwC1IeqAfCjIzpHEUQNWOUIe2lAmHQtwGhkP0r87T/W7j/Poxr4ofV9Bd4W92fhdudz/XDMEcKRcVarwnl2bAh47EZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500996; c=relaxed/simple; bh=fcfNrVyM1/xmJ1Udun6SiMd4PW9ryvb/sEJVuLPTZ9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NSfOQmskQqU/zLUgjcN1PhxQyhGReghWvT9PzgVxT9jYNfO543jp+znAh0hY7kUC3vALKf53ZuscZLrLOi/C6AcA7Sqj/i3YH+GEEzKbcJxTYtvrBB55CJd0tU6MP/8jxeuePpjYUdPNxeIUjXOFgv6FIFCt39cQRwdCdV/w7tg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BQTtye2O; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BQTtye2O" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729500995; x=1761036995; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fcfNrVyM1/xmJ1Udun6SiMd4PW9ryvb/sEJVuLPTZ9I=; b=BQTtye2OCZ4j7i2CHEUvDvTZ+XOL5Aggk2sZPKnIfQDhbTj8brQ/gPNj aIONLCGbA3lvDfAwkXGttwTRqd0WjTEV+eeSNrcQg3RMEhxWnfcMTYCiL 2WwY0u6cgeRRlw/J1Iu7KXONJv3HKOdHUKkXYjPUlQtiwI5v8jJE4dhDd TGeqlL4T0eHZ3ioZKhu5tfL9+3O8zz3hbgLPViqQoEgOP0NWTmmsJeMhU +daiBEsftgIaefn/D5LmDP/5GSfogp2y6fANV02Sr8+1Zs+EOoa1liRRJ Fc2q3kPyMeeKyWQU+CeYRRP9tMC9c9B4bKYCdXfyxbsWAbAOSpw7QcvMG g==; X-CSE-ConnectionGUID: 3L+5B8RBT7aW2IMF0OX2LA== X-CSE-MsgGUID: jLqi9DLFRvOLjZ24tqMjGA== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="32780371" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="32780371" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:56:35 -0700 X-CSE-ConnectionGUID: /xsBfnSGTEeeT+KjF8pecg== X-CSE-MsgGUID: dMUKqwkDTbiUmePtmya2qw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="79812762" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa010.fm.intel.com with ESMTP; 21 Oct 2024 01:56:32 -0700 From: Lu Baolu To: iommu@lists.linux.dev Cc: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Yi Liu , Vasant Hegde , linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v2 5/7] iommu/vt-d: Remove domain_update_iommu_superpage() Date: Mon, 21 Oct 2024 16:51:22 +0800 Message-ID: <20241021085125.192333-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021085125.192333-1-baolu.lu@linux.intel.com> References: <20241021085125.192333-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The requirement for consistent super page support across all the IOMMU hardware in the system has been removed. In the past, if a new IOMMU was hot-added and lacked consistent super page capability, the hot-add process would be aborted. However, with the updated attachment semantics, it is now permissible for the super page capability to vary among different IOMMU hardware units. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 39 +------------------------------------ 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 756caa24008f..36854b683b11 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -352,36 +352,6 @@ static bool iommu_paging_structure_coherency(struct in= tel_iommu *iommu) ecap_smpwc(iommu->ecap) : ecap_coherent(iommu->ecap); } =20 -static int domain_update_iommu_superpage(struct dmar_domain *domain, - struct intel_iommu *skip) -{ - struct dmar_drhd_unit *drhd; - struct intel_iommu *iommu; - int mask =3D 0x3; - - if (!intel_iommu_superpage) - return 0; - - /* set iommu_superpage to the smallest common denominator */ - rcu_read_lock(); - for_each_active_iommu(iommu, drhd) { - if (iommu !=3D skip) { - if (domain && domain->use_first_level) { - if (!cap_fl1gp_support(iommu->cap)) - mask =3D 0x1; - } else { - mask &=3D cap_super_page_val(iommu->cap); - } - - if (!mask) - break; - } - } - rcu_read_unlock(); - - return fls(mask); -} - /* Return the super pagesize bitmap if supported. */ static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain) { @@ -2605,20 +2575,13 @@ int dmar_parse_one_satc(struct acpi_dmar_header *hd= r, void *arg) =20 static int intel_iommu_add(struct dmar_drhd_unit *dmaru) { - int sp, ret; struct intel_iommu *iommu =3D dmaru->iommu; + int ret; =20 ret =3D intel_cap_audit(CAP_AUDIT_HOTPLUG_DMAR, iommu); if (ret) goto out; =20 - sp =3D domain_update_iommu_superpage(NULL, iommu) - 1; - if (sp >=3D 0 && !(cap_super_page_val(iommu->cap) & (1 << sp))) { - pr_warn("%s: Doesn't support large page.\n", - iommu->name); - return -ENXIO; - } - /* * Disable translation if already enabled prior to OS handover. */ --=20 2.43.0 From nobody Tue Nov 26 05:58:23 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5A3F1E3DEC for ; Mon, 21 Oct 2024 08:56:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500999; cv=none; b=EmhumUKybrKCQ5MEu0QY+mVs3oKXzyZlsoFg7XqLc3FanD4UFQ6lKiCpEPyiZZ5QafPIW2NPqjyRYJNNNODT3GO2ozMwyfyXDiVeTdDdLvE1CY92FphkY8Lr8GoVW/9l9zEkxQfBoSTJ8A8AZHsNoBZ06gb73UO3A+AeJppVgxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500999; c=relaxed/simple; bh=kqJ81w2X5hak4sjUBjP1L0SagSpWOgRvgVPYFi3njhc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PtNVav3e4Gw1kKZr4z5XaUkDQigKTMsoSzJd3hngWEe4UtWzr5sJmSssVZRx0RD8LH13A8qmfaBLxE5gkWSL7RRJs7HShUnjNk+KnVXeiajnZQhxnZyVPHuOYNT7QPhOIILOTxA0gfwK9dwso0xo3lLEnBv534CR9Tb9HBsTZSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BhVKW6tG; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BhVKW6tG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729500998; x=1761036998; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kqJ81w2X5hak4sjUBjP1L0SagSpWOgRvgVPYFi3njhc=; b=BhVKW6tGEsgwqp0aXoMyCXCVUNhefBwIHypxFLEMtdSS4fClnBlzX5TG JV7g88E8VHLVh+lYElKWb/x/1dxxUyF1Lv2mvTw6NBJ/lDpvz8huFiVAA 1uQPGJQvHoCH5Xns2fYQIyHTawt0VxqubuiFW6YWJMtqRsAz1dfYwHKdG jIF811ifAi74u4RkNy9LwWw/G2h3BmhYJ2JbvPXV0Whb3dzailFd9VgV3 uGtx8w1oyALUXE8SL3Njk0BIklQcFLj4ty7F+wu2m4nAzl8/N+mGawJZz S4D7mv7/cipQ84Qj0Chda1OoDCd/gfalseVaqfAeWqWscgaGEe1xkrXuM g==; X-CSE-ConnectionGUID: R2F2/b4FQSy3KPiFbfMQQw== X-CSE-MsgGUID: gDNF1XXHT6G1p3v6NoWHoA== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="32780380" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="32780380" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:56:38 -0700 X-CSE-ConnectionGUID: ni7yTVQpSxeKmHIGG23Zhw== X-CSE-MsgGUID: +dy3oQjkTnabhFoJXYluqw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="79812784" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa010.fm.intel.com with ESMTP; 21 Oct 2024 01:56:35 -0700 From: Lu Baolu To: iommu@lists.linux.dev Cc: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Yi Liu , Vasant Hegde , linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v2 6/7] iommu/vt-d: Refactor first_level_by_default() Date: Mon, 21 Oct 2024 16:51:23 +0800 Message-ID: <20241021085125.192333-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021085125.192333-1-baolu.lu@linux.intel.com> References: <20241021085125.192333-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The first stage page table is compatible across host and guest kernels. Therefore, this driver uses the first stage page table as the default for paging domains. The helper first_level_by_default() determines the feasibility of using the first stage page table based on a global policy. This policy requires consistency in scalable mode and first stage translation capability among all iommu units. However, this is unnecessary as domain allocation, attachment, and removal operations are performed on a per-device basis. The domain type (IOMMU_DOMAIN_DMA vs. IOMMU_DOMAIN_UNMANAGED) should not be a factor in determining the first stage page table usage. Both types are for paging domains, and there's no fundamental difference between them. The driver should not be aware of this distinction unless the core specifies allocation flags that require special handling. Convert first_level_by_default() from global to per-iommu and remove the 'type' input. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 36854b683b11..bad9593f2464 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1329,18 +1329,17 @@ static void free_dmar_iommu(struct intel_iommu *iom= mu) * Check and return whether first level is used by default for * DMA translation. */ -static bool first_level_by_default(unsigned int type) +static bool first_level_by_default(struct intel_iommu *iommu) { /* Only SL is available in legacy mode */ - if (!scalable_mode_support()) + if (!sm_supported(iommu)) return false; =20 /* Only level (either FL or SL) is available, just use it */ - if (intel_cap_flts_sanity() ^ intel_cap_slts_sanity()) - return intel_cap_flts_sanity(); + if (ecap_flts(iommu->ecap) ^ ecap_slts(iommu->ecap)) + return ecap_flts(iommu->ecap); =20 - /* Both levels are available, decide it based on domain type */ - return type !=3D IOMMU_DOMAIN_UNMANAGED; + return true; } =20 int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *io= mmu) @@ -3110,7 +3109,7 @@ int __init intel_iommu_init(void) * the virtual and physical IOMMU page-tables. */ if (cap_caching_mode(iommu->cap) && - !first_level_by_default(IOMMU_DOMAIN_DMA)) { + !first_level_by_default(iommu)) { pr_info_once("IOMMU batching disallowed due to virtualization\n"); iommu_set_dma_strict(); } @@ -4359,10 +4358,12 @@ static struct iommu_domain identity_domain =3D { =20 static struct iommu_domain *intel_iommu_domain_alloc_paging(struct device = *dev) { + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct intel_iommu *iommu =3D info->iommu; struct dmar_domain *dmar_domain; bool first_stage; =20 - first_stage =3D first_level_by_default(0); + first_stage =3D first_level_by_default(iommu); dmar_domain =3D paging_domain_alloc(dev, first_stage); if (IS_ERR(dmar_domain)) return ERR_CAST(dmar_domain); --=20 2.43.0 From nobody Tue Nov 26 05:58:23 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5226A1E4106 for ; Mon, 21 Oct 2024 08:56:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729501002; cv=none; b=L/WTe76McsMCpBDBCozGQAW+SXM8iox4VFKa9d+8TVPn2u+ZdwDl5tfZIY56tjmPo92l0nFi+jWQjH+Ytl4CmitzSZH0Feb25OStFEOdUKLl2sQomUS5XeTfOWO2HPXfC9wZ/H1ksH/btOzcNckwF2izv+hxmhFAK0KQRbXdybE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729501002; c=relaxed/simple; bh=Tbzk8V51fVW+LwkB30xCPUlXehhiTd4lUy3vVxrhRKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vDoFp2i6LJpxLHCJGIZIFstWEUR1ND1fDwlTpM5tcctVDRVLFU6nLqZg9jpjynoWrV/u2idgjzXR2HWRHIqJALnJVpSWAiuIiicRW2Tr7SzfBxVLhMtcW3l5o7rzz4DE4wAMF7/KVPNV8EoUInT9NVG0O7MPMX1Gn7WPHJaXR8o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AjEkMnPO; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AjEkMnPO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729501001; x=1761037001; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tbzk8V51fVW+LwkB30xCPUlXehhiTd4lUy3vVxrhRKw=; b=AjEkMnPOD/N7fCTnNVwVdnijLKl6KgOk5Asti1FNaS1JaTQY+bKyPsup Y82gxdElsOoHEU3nEGeZ/4Zt0u9LVoGJHnSGV2FhzIVh3TpX4cCjokKdE iq2SRcDkXWkttxVtiYccEbRiyMcAOynArnKLhhEvgjX4cmjVaIN/raQtl ujs/RoILaYu88KJ+9allZDpTpVVXVtj7Pm3rJtwlpStZxNII5g4+moVEV 320Elmr1bOuYPNUZcCf5ES5pqloSaOxjvw+JF4rRtFyx2H+LNGicvdsdp AciXXBmleUiPVqtsrdyIvQSxHn4FUtSWip7MKXIK48wrE2VlwYA3GVaRx g==; X-CSE-ConnectionGUID: WeWT50xbSBez0ev6Q83A1A== X-CSE-MsgGUID: nwmZJqfIQliAe0GJOuNJlg== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="32780390" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="32780390" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:56:41 -0700 X-CSE-ConnectionGUID: ZdfzkpVEQTKMlDCFIOscXw== X-CSE-MsgGUID: NzmZKRbdTgC9gNuCVrvutA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="79812794" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa010.fm.intel.com with ESMTP; 21 Oct 2024 01:56:38 -0700 From: Lu Baolu To: iommu@lists.linux.dev Cc: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Yi Liu , Vasant Hegde , linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v2 7/7] iommu/vt-d: Refine intel_iommu_domain_alloc_user() Date: Mon, 21 Oct 2024 16:51:24 +0800 Message-ID: <20241021085125.192333-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021085125.192333-1-baolu.lu@linux.intel.com> References: <20241021085125.192333-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The domain_alloc_user ops should always allocate a guest-compatible page table unless specific allocation flags are specified. Currently, IOMMU_HWPT_ALLOC_NEST_PARENT and IOMMU_HWPT_ALLOC_DIRTY_TRACKING require special handling, as both require hardware support for scalable mode and second-stage translation. In such cases, the driver should select a second-stage page table for the paging domain. Suggested-by: Jason Gunthorpe Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index bad9593f2464..2b5027dd0c96 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3297,6 +3297,7 @@ intel_iommu_domain_alloc_user(struct device *dev, u32= flags, struct intel_iommu *iommu =3D info->iommu; struct dmar_domain *dmar_domain; struct iommu_domain *domain; + bool first_stage; =20 /* Must be NESTING domain */ if (parent) { @@ -3313,8 +3314,20 @@ intel_iommu_domain_alloc_user(struct device *dev, u3= 2 flags, if (user_data || (dirty_tracking && !ssads_supported(iommu))) return ERR_PTR(-EOPNOTSUPP); =20 - /* Do not use first stage for user domain translation. */ - dmar_domain =3D paging_domain_alloc(dev, false); + /* + * Always allocate the guest compatible page table unless + * IOMMU_HWPT_ALLOC_NEST_PARENT or IOMMU_HWPT_ALLOC_DIRTY_TRACKING + * is specified. + */ + if (nested_parent || dirty_tracking) { + if (!sm_supported(iommu) || !ecap_slts(iommu->ecap)) + return ERR_PTR(-EOPNOTSUPP); + first_stage =3D false; + } else { + first_stage =3D first_level_by_default(iommu); + } + + dmar_domain =3D paging_domain_alloc(dev, first_stage); if (IS_ERR(dmar_domain)) return ERR_CAST(dmar_domain); domain =3D &dmar_domain->domain; --=20 2.43.0