Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2588856lqp; Mon, 25 Mar 2024 03:44:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVygjo7/+dgcgmHDxjRlzT1dmy2qwsIAABZbmdDSmJFbWvpgrX2IYS1gaGrRBSfWGkxFe+E5g06rv0IL+KI923gTVn9qXU2uyck70Tgbw== X-Google-Smtp-Source: AGHT+IHHAUmdHzRBoVCXwIdXrs+I5OSjcRgcqa2EM2r7Nrdf/DLWd54mO4WWr9kBRyTjKdGdXpk6 X-Received: by 2002:a17:90a:f285:b0:2a0:390e:f072 with SMTP id fs5-20020a17090af28500b002a0390ef072mr4464931pjb.40.1711363452885; Mon, 25 Mar 2024 03:44:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711363452; cv=pass; d=google.com; s=arc-20160816; b=SlcbGGKCFH6sdSnPmboTw3syR/gxQ+PXm1r8FaxdISRPAuuVevZG/Me2Fe18WnMpJb E9tImxs7tD1k/S2S+LvhQ7flafuNB7Pia57/IZdha0k13nJpAL+JTiS4Cy1aYRahs2Ft cotrvzKIJz398K9pK+pS0IlQWUx+5kJlxd9aTSZ4gSky+DFVrfSWi0nak+p8IIlXLKWI A2GiF5UGpGgNkutFjPtU9eOTgJbkNXiGX96h8kiyXpRp+cJ5BkBbFnp684xjgfmf5l7w xZ/EuFibmsrFoiE8MHBwF/8tzP8lE3/WITLj4D9RhbkrfoU2zkOrLweg8jZrZt6flqbO 5xBg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=F/9diwuYUmeBQ0YxpO3Ranw6jn67XBevO2cR6FUz6v0=; fh=bewSQvuA0/GMLNkXZCY6BVvXowY1LyW/Ro23JMfVQ8s=; b=c2ihwwHE6WBp1WdYM2Iru2NFw2w1e8BAwYYIdmeu7leUs947a3IMfTvj0dA5d1wlgE INweWNBLDc9IoONUx1if7+Zb0KIMHi/07tJjnmAL+loea1UAIUCvtKP6SVnO0QNpI93P /Qsc967wDGxuNg7SOUUfNVA9fam6sYP7Qw84KDERVlRRFbKP2m63eqksqjyj2JRkkKuR 29ziKsGLQCEUfyik4aiiy6odkEaK+fIpFFIUnzuKXmXh7CIADc1Ul7VmyK8ws7LF8kPv 69cQg/+eCzRSkgomXLh1wZxFbh+ypIa/jLRBorFnSVSuwmnNk0/wxN7zlSO/eC+3B8KW 9hdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jXGaNuht; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116409-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116409-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id nv17-20020a17090b1b5100b0029c7a551127si11845616pjb.99.2024.03.25.03.44.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:44:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116409-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jXGaNuht; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116409-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116409-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9FA61B39BB0 for ; Mon, 25 Mar 2024 08:51:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BCA7147C78; Mon, 25 Mar 2024 05:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jXGaNuht" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 46EB5155380 for ; Mon, 25 Mar 2024 02:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711333084; cv=none; b=TOnKeX4gp0R/La9jmPPAu1GuGYm7x1wv9VSGd30gRYoycKKaVCNqyrCPOXWoVqW/XSppBVd+ZMa4gY53qi47JstAj+kBSlWF2qowXmO5VUYdfR/BGB2Oe+kKE6oblz5kiaP9hGNevS4EEq2r2Bq+B2l95Gh/Vr7J+WkI2GnVfCM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711333084; c=relaxed/simple; bh=NoQ/9ZnQSMX+2qUfsoDT6WHWT7bNrCxUqTCcoTOjF7I=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=kTC8wkqoBhwxoTDTK8CrMMMuTe+/eL4exR8z13/OJ50rsEzP/kEEimRIr0lyPnjDGJyjaUXlbOeNG4ry9QQOfGO104mW1Hfq3DXHYc6fOQQ6GWp04T29kxU/BohieG3O0v1bizA9kCgE5fNXy4dmly1/e9LwHPClkdK2l2c5/Pk= 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=jXGaNuht; arc=none smtp.client-ip=192.198.163.13 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711333082; x=1742869082; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=NoQ/9ZnQSMX+2qUfsoDT6WHWT7bNrCxUqTCcoTOjF7I=; b=jXGaNuhtIwxuHc6OPE4usGi46q8kyhk7MIgQ5sktGbgcjSVIe02wNTOS jHy5dtOdo3dGcY8LVMyoer1IuWVmyL1BdmyfQ1ur8yVliCWXhPXZ7OWND +ly+9py+SZ6eZLO3GG6Glv9d1skenwpKeGTPC8o+tUaxh+k8FWo2Edb3X 3F0PszUx6DTaP2Firh/t9hufBMSVcERj+y3oUO/Q+2zINUuSgf8PnCZmT 2WsvQVEmzVVleQ5ZmPrzFANK7WRH1a0wmdAuPgrCJGN1cl5oluudl2edM smA4Nm5wi1x58iR+xS7Fz1vBgQlpv2U2B2DEj8d75yQwDqojrdLfTgB2W Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="9271305" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="9271305" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2024 19:18:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="15353886" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa010.jf.intel.com with ESMTP; 24 Mar 2024 19:17:57 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Jason Gunthorpe Cc: Tina Zhang , Yi Liu , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 00/12] Consolidate domain cache invalidation Date: Mon, 25 Mar 2024 10:16:53 +0800 Message-Id: <20240325021705.249769-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The IOMMU hardware cache needs to be invalidated whenever the mappings in the domain are changed. Currently, domain cache invalidation is scattered across different places, causing several issues: - IOMMU IOTLB Invalidation: This is done by iterating through the domain IDs of each domain using the following code: xa_for_each(&dmar_domain->iommu_array, i, info) iommu_flush_iotlb_psi(info->iommu, dmar_domain, start_pfn, nrpages, list_empty(&gather->freelist), 0); This code could theoretically cause a use-after-free problem because there's no lock to protect the "info" pointer within the loop. - Inconsistent Invalidation Methods: Different domain types implement their own cache invalidation methods, making the code difficult to maintain. For example, the DMA domain, SVA domain, and nested domain have similar cache invalidation code scattered across different files. - SVA Domain Inconsistency: The SVA domain implementation uses a completely different data structure to track attached devices compared to other domains. This creates unnecessary differences and, even worse, leads to duplicate IOTLB invalidation when an SVA domain is attached to devices belonging to different IOMMU domains. - Nested Domain Dependency: The special overlap between a nested domain and its parent domain requires a dedicated parent_domain_flush() helper function to be called everywhere the parent domain's mapping changes. - Limited Debugging Support: There are currently no debugging aids available for domain cache invalidation. By consolidating domain cache invalidation into a common location, we can address the issues mentioned above and improve the code's maintainability and debuggability. Jason Gunthorpe (1): iommu: Add ops->domain_alloc_sva() Lu Baolu (11): iommu/vt-d: Add cache tag assignment interface iommu/vt-d: Add cache tag invalidation helpers iommu/vt-d: Add trace events for cache tag interface iommu/vt-d: Use cache_tag_flush_all() in flush_iotlb_all iommu/vt-d: Use cache_tag_flush_range() in tlb_sync iommu/vt-d: Use cache_tag_flush_cm_range() in iotlb_sync_map iommu/vt-d: Cleanup use of iommu_flush_iotlb_psi() iommu/vt-d: Use cache_tag_flush_range() in cache_invalidate_user iommu/vt-d: Use cache helpers in arch_invalidate_secondary_tlbs iommu/vt-d: Retire intel_svm_dev iommu/vt-d: Retire struct intel_svm include/linux/iommu.h | 3 + drivers/iommu/intel/iommu.h | 66 +++--- drivers/iommu/intel/trace.h | 97 +++++++++ drivers/iommu/intel/cache.c | 389 +++++++++++++++++++++++++++++++++++ drivers/iommu/intel/iommu.c | 294 ++++---------------------- drivers/iommu/intel/nested.c | 71 ++----- drivers/iommu/intel/svm.c | 279 ++++++------------------- drivers/iommu/iommu-sva.c | 16 +- drivers/iommu/intel/Makefile | 2 +- 9 files changed, 660 insertions(+), 557 deletions(-) create mode 100644 drivers/iommu/intel/cache.c -- 2.34.1