Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp121056rdb; Thu, 8 Feb 2024 00:25:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWtv5sndGCvR/KzGEinR03jEOMTzzZjm/AZCuxDQwuiDipOsY/gFhmYGFNcZyqZw8knRl2Ce8IliHw64DfpKnn3nPH6oGmEABsh6TC2mw== X-Google-Smtp-Source: AGHT+IEf0RKwdvn23Yz7HFpu3Ras+yoMU5rxvcAZyQjJCHjvq453AeRLIdszL4KakQNq68hOAx+x X-Received: by 2002:a2e:978b:0:b0:2d0:c546:b08e with SMTP id y11-20020a2e978b000000b002d0c546b08emr4528370lji.9.1707380748814; Thu, 08 Feb 2024 00:25:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707380748; cv=pass; d=google.com; s=arc-20160816; b=Dzcd+id9W5zzqPcc8lelvV35wfatzd8csM/IvKDQOrrNWy3Fvr8p1QZgatDJ0ZlIKy ptQh8Of0GQU+nQUTgSisfjAgckoOwNScNk4sJwsBz/IgBlpqnrNw+tZyQD08cBg7pREx SZof6lLfCtc2hvG/2NZcEb7Er8SfDxzM/tx+ePg+B1TQ1ASXyyT1pCQVJ9CUPiUhbysQ g3wlq6vnI4SKA5wHQjcHusKbHnD7PUAkh1D3tuzk0yOhLC3MqQvREjSygdM2lhFOQouF f6/RQFCFdHKq5BQNe1CVqgMJ35q3SGuhzWA8Wa8OfQo7u6oF188kvwRs3mbeTGd4rLF/ ocTA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Leo6OjFF7cTvTWH9Ij/WGHRlmsf3xAf3sM/zNznugKM=; fh=qIPQbXli90gIrFnx/4Hcq9NyIGVQbG7fg5+wdTixNoQ=; b=RJcrpCnihmY+OBmyYJ13RQKw9ysH3KjMlwWGiLc3wvGU23kQmTd1AXPrO0UW/gmI4g FlTcsIp9QheFGimi04b3kPL/PCeZ2X4wOMOklrUaHb7XF9T+e7pdzv6ISqeg/O5ooxhz OXNHSdn91DxpaRKX8hB5cvunptJbpBfw8xjafTfiPcyfrceiBuQX/W4LXum4uUaQBU/Q ao/25IwjJpv/BTm48zsNIIt5BKREcwODUcAoRaD7YfR8lgkiCDubHKSLOKq8LXf9vDDc OZveKQSJ4O9BxEhajOsSyPb7CtvQNTkmSHIdL+hbIBN2DflPwo6vuaQKq510HQA+9O5p MCJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ctn59+PP; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57611-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57611-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCX54WUFHrHxhJ+LfyWxb0PzcpqAyQot8FAxEULzD0vgjCTRFrYM73VSflMlNVDV7vd+QChlMLRowI96wagU9ocQvV+2J9ziCIonKVqcOQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gy3-20020a0564025bc300b00560c7c3bdf8si667516edb.342.2024.02.08.00.25.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:25:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57611-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ctn59+PP; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57611-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57611-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 895841F246A8 for ; Thu, 8 Feb 2024 08:25:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E526E6E2CF; Thu, 8 Feb 2024 08:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ctn59+PP" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 20EAE6BB55; Thu, 8 Feb 2024 08:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380597; cv=none; b=am7v7zPJ22t5Boj59vYhII8NqGMEkFKvt/CoOQX6TOmeUlmocOpm1dHa0sp+yIHONV/riKHyQgIX4lWko6oEgzq8SjR4T6nrQypZ7El21ByruOKaDzzxvrn1GBBmEAN8HD2M1qn29GgAHSusgX3xLYu0RK8wAU22VGSd75FGnWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380597; c=relaxed/simple; bh=E5vqPNymMiBaUwgno+gdspERLQZxZHNPzxdUdl6DYtw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rqNP4LDMlwIpz9WQ1yO2Y9Tny9fMVEVqwc8VLobDiHyh7PGsYdZofs/wgrw1Qf073ZyeXhaKorrrg30O2u8XzrTebuCZg9k3TBzKu7YFyAdW0ZP87Log4zRRUUc5s5lTsqwPadnKyhkrzoGVABw0lQ5T88rZGhm+Q5hhKNQycZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ctn59+PP; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707380597; x=1738916597; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E5vqPNymMiBaUwgno+gdspERLQZxZHNPzxdUdl6DYtw=; b=Ctn59+PPCl7yPs/4fKewQM9CkYzA2CNXLP2QIapjy/uGeWvLL1FbZTap /tUkPRNFzhxtnZiA+4skETRApuFEsiswvQUwxtlrUG+mB1GX00pCBOxov ygwUxSVJjtt9BsyJGot2pk6HpuKGpbHNvxBzv4tHLWicCHekpxvsbrFpg l6SAaNEmPXWgNlF+DKz9/+ZmLkhe5Pt5Wa6hHCCRF/xqSKwpZ8V7umcIx Hd/ZPlT29n2kNT4+YrgvVNE1XVy1TW3GBEAVo+SRdWxT3pwDXrLUibrqq joXTrZkep0RBt4fekhCmWEeumtdnnjKgGEsEDU3p3ar5Eja6AUXNTz16X g==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="5036353" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="5036353" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 00:23:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="6252137" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa003.jf.intel.com with ESMTP; 08 Feb 2024 00:23:15 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH rc 7/8] iommu/vt-d: Wrap the dirty tracking loop to be a helper Date: Thu, 8 Feb 2024 00:23:06 -0800 Message-Id: <20240208082307.15759-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208082307.15759-1-yi.l.liu@intel.com> References: <20240208082307.15759-1-yi.l.liu@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: 8bit Add device_set_dirty_tracking() to loop all the devices and set the dirty tracking per the @enable parameter. Signed-off-by: Yi Liu --- drivers/iommu/intel/iommu.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index dae20991e036..7636d3f03905 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4730,23 +4730,35 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type) return vtd; } +static int +device_set_dirty_tracking(struct list_head *devices, bool enable) +{ + struct device_domain_info *info; + int ret = 0; + + list_for_each_entry(info, devices, link) { + ret = intel_pasid_setup_dirty_tracking(info->iommu, info->dev, + IOMMU_NO_PASID, enable); + if (ret) + break; + } + + return ret; +} + static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain, bool enable) { struct dmar_domain *dmar_domain = to_dmar_domain(domain); - struct device_domain_info *info; int ret; spin_lock(&dmar_domain->lock); if (dmar_domain->dirty_tracking == enable) goto out_unlock; - list_for_each_entry(info, &dmar_domain->devices, link) { - ret = intel_pasid_setup_dirty_tracking(info->iommu, info->dev, - IOMMU_NO_PASID, enable); - if (ret) - goto err_unwind; - } + ret = device_set_dirty_tracking(&dmar_domain->devices, enable); + if (ret) + goto err_unwind; dmar_domain->dirty_tracking = enable; out_unlock: @@ -4755,10 +4767,8 @@ static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain, return 0; err_unwind: - list_for_each_entry(info, &dmar_domain->devices, link) - intel_pasid_setup_dirty_tracking(info->iommu, info->dev, - IOMMU_NO_PASID, - dmar_domain->dirty_tracking); + device_set_dirty_tracking(&dmar_domain->devices, + dmar_domain->dirty_tracking); spin_unlock(&dmar_domain->lock); return ret; } -- 2.34.1