Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp724882lqe; Sun, 7 Apr 2024 00:29:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVrwjNZdESebqrfn1/b+9i8XyvixM7rKwBs30VtdpdIqq3runBAo2lBX3s3iobN8A4wETLY1GND4q0i8VZp9Nwdb2MEX0PlBapgjkeW4A== X-Google-Smtp-Source: AGHT+IGHekZA8jNa0hpxy02Wi9aOvQTTJE6qJ8uY9oSr60F1mChGIu2+LXLx9oDu0XI2PX/HyAz0 X-Received: by 2002:a05:620a:5205:b0:78d:4fee:62b1 with SMTP id dc5-20020a05620a520500b0078d4fee62b1mr7106887qkb.4.1712474985933; Sun, 07 Apr 2024 00:29:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712474985; cv=pass; d=google.com; s=arc-20160816; b=uhU7sXJnonqr0RWMbVllUhcB/RYm1RGNsdSCokWMlSouNdadGCrwt/XvbIMsh+jm+g oF1lWXnHt2jFIgJ4MQuUdmks8E4AyBVZW+wZcEQx7in7prp1vY+elD7Jyq8TCG18f7ye q/PxnKrV/yv0OIX3y/xXlNYoXxm0+aoiKxFqddunEIbVw/1+vIymqd5qCo2I2q/EYF+b +2ToZAWwxlDFB3At6l3bQkbJf9dvLDExNFwNIXVfTVlMoMO+PAR4k/8XYs7L4IfnuvFW 4aTvOwoGx8OBb3FoqRa5bQ2TaJ4l0fhlqLHEGqojVm/MH7ZOek2sE24wZJxb6HHXcQM4 AoSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=sDq0m+eLSE7pX/83dt4ZX3UUuiiGy1wf2EdmLVTDr7Y=; fh=iR1lbYJQnHEnSnVdQKkdJhsLOas5OhplD/LHY8w7b54=; b=ako0bAMPcq1pTZLk1n0IO81C3/R0JZLblKeqCOTNIIqaA+u4NpOOkaNs8kpe3iJ4QW lJF1vNzEQQwt/L+wXlkVYDSNp+4+Z8p5HqthJI7eDdbO2f0O662hvh+Jv3AMXLkdeHk7 J666YdouLRCPdSIHJxIbnNlDMR00LyfKtbvUtVRi74IXoFzuIOW0p8be5cZCwUVwU01Q B0eEIEZ6YdNo8hBDY+/qJK2GKKpD2GThtDJgLO5V6Kv5aDhGhhgBz6/ALn72W2bN3G1D MFKWRctCr/uCCRKno9lq6o5UzQupf+4vRbG3kUUA8Ozt0DmcOy9/jvTx+TxT9RIG4Zg6 tutA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SWYtJxKr; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-134223-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134223-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t13-20020a05620a034d00b0078d617ffc19si1106654qkm.169.2024.04.07.00.29.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 00:29:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134223-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SWYtJxKr; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-134223-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134223-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 56D9D1C21F2D for ; Sun, 7 Apr 2024 07:29:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4730E11181; Sun, 7 Apr 2024 07:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SWYtJxKr" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 0928D10A23 for ; Sun, 7 Apr 2024 07:29:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712474972; cv=none; b=Liocx5fYOkq9Ghbm9J2z/xmVMMpW1Uh3N7hED/7sI+ywNA03ZERkm2XUqAvM0zN5yCUmZRUdWD3u4DsS57E1WLTgaIcw9kl2VP41cogsbKTbruHDw06xWUG4AOSj5HdUM3KjfQThtjJOyIm86Osuzuev312oWRm4B1Qzlm/AGHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712474972; c=relaxed/simple; bh=oegOZxAKMmIs+FUbmGggNTdmhPzqyGI38fezqk9NBoQ=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=JILvyw/Ad5s5U/tbP4LeJKxkeC1RSkwv0EAhoUQoo4xvxzVy9eJaQJHqKj0VvoFhGfso5uALkkz3hgTsvdzHRMzUgsXzU5bg0qEHzFy0ET/aIR2vSZolbbJKI6lrtMSPjTRD50uB0hTIDNqVJIvWR68Wdrsyta3x73xX0nAjPco= 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=SWYtJxKr; arc=none smtp.client-ip=192.198.163.7 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=1712474971; x=1744010971; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=oegOZxAKMmIs+FUbmGggNTdmhPzqyGI38fezqk9NBoQ=; b=SWYtJxKrEgIaylhP+keJqtxaAou8dciwnpBXmYUSNnC9c6olmWElkfzc Re+TiWBnPjbpYJMrH7u8pwD+PKumR82vzGv/f+gdryGoXYdNEWpFzCLsO uLv3kJHCt82dD5e5QeOygKpw6Cy1rAszt668T/CD2LUr+aLbM01XAhHr+ 57v8WnE+qSKUr6qieLDTaN9U+QQfx+mxjk6y2clSbRwkWchVNajOgSgfo 3WHnp1LYNv7FvknKwny8/9MCp2CM1jB6yZUpoYYteV9FiXwTV9R6s6CBP WJN3NpyUrNh5/jCuzsaj4lh9lcd5Yvx8M0G6tkrnC5egVjiUrVlh/zasl w==; X-CSE-ConnectionGUID: H9q20hjGS1+ccafG9BUnWw== X-CSE-MsgGUID: 2ni9JRriRRWhK8FgeYcvLQ== X-IronPort-AV: E=McAfee;i="6600,9927,11036"; a="33162970" X-IronPort-AV: E=Sophos;i="6.07,184,1708416000"; d="scan'208";a="33162970" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2024 00:29:29 -0700 X-CSE-ConnectionGUID: PHFVHD3kS7mePUJRP+UoNw== X-CSE-MsgGUID: yX/4fWnLQS2NZdh97lhW1g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,184,1708416000"; d="scan'208";a="50544993" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by orviesa002.jf.intel.com with ESMTP; 07 Apr 2024 00:29:25 -0700 Message-ID: <2256b869-d0c2-49b4-b6cc-89e59d40386f@linux.intel.com> Date: Sun, 7 Apr 2024 15:28:19 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, "Zhang, Tina" , "Liu, Yi L" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 00/12] Consolidate domain cache invalidation To: "Tian, Kevin" , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe References: <20240325021705.249769-1-baolu.lu@linux.intel.com> Content-Language: en-US From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 3/28/24 3:59 PM, Tian, Kevin wrote: >> From: Lu Baolu >> Sent: Monday, March 25, 2024 10:17 AM >> >> 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. > can you elaborate how duplicated invalidations are caused? Yes, sure. Current Intel SVA implementation keeps the bond between mm and a PASID of a device in a list of intel_svm_dev. In the mm notifier callback, it iterates all intel_svam_dev in the list and invalidates the IOTLB and device TLB sequentially. If multiple devices belong to a single IOMMU, the IOTLB will be flushed multiple times. However, since these devices share the same domain ID and PASID, a single IOTLB cache invalidation is sufficient. The additional flushes are redundant and negatively impact performance. Best regards, baolu