From patchwork Mon Feb 19 11:15:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203167 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1386245dyc; Mon, 19 Feb 2024 08:16:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXC6ktrgyewA7fxHVDV5tHj2l/c1XdGmTB4f6UrpxxT3m5pqERNGdyd9TtCgfiD11/8jBgYbiW5yEJiWtnPHkdL3ug8lQ== X-Google-Smtp-Source: AGHT+IGk2SMM3BHRpMgdtby3bSqotKwMIiSwieK0zi5uqmvWQ7+AOaaEOjCBsFMz3rXxlslMlCR0 X-Received: by 2002:a17:906:649:b0:a3e:b869:11b3 with SMTP id t9-20020a170906064900b00a3eb86911b3mr1555376ejb.55.1708359398119; Mon, 19 Feb 2024 08:16:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708359398; cv=pass; d=google.com; s=arc-20160816; b=adS3Z6nDDiV6DB7h+QXbPsQUMj1vRKO764Toh9VCmkf8XartrhnVAwxrmym6yTtP/y 7MFDbYkg+QATisUpCKsiT/RT/R+Dl25jjuqmOPcZQJBwLpbxMHsXl3AJ2IpQBaPKa3Gi yBVjeIdclPH29tLcZOOv9JiWFr3vzy+RPl7XN2sfENHSJe19qIpah8btmrpj56vWBr4V pjjhSMskcZD5Ryh2voTq7+EK2Ta024/Tk3cUq1y3dyY9Ku9ZqHuLNxON+MXF6ilcU3ij 6zol9yrqfYN1byCJWBpTUd3E8RCA4hixbeHBU4nAGgQ2VUSpEQui7nRAn+Ut3DYGAk5Z 4+Fw== 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=2lF1gepeDpJ/AkL1u02tYZKKAnLPUW9NMyGOBxIVEOY=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=hgDY86psTtgAZnL9onlAoYYTkDC6amQN8SHrrt6GMCnbBHTr8z6S7Wc5OeL5heAUEe Hqw7tpbx3WhSpco+How6w4OUFcRHU5ofZElAvTTH4rhXu23IjJggw84f9vG1eFcxkTa3 ZJB5nFfdObWDXnl53vVa12RaXhsZRVHCLrhTFJgjo0ItAc3SybMhqUKeLUtAIwGbplJG zR1KnhnPswJMGS7770k1cSwLYFYa6ZZF5Pp8QCpd5tKYDXC5MtEK1z1GO8HCM2Pn5EVo MAgRvZhZJNo/Lt5/o1zEktmtEuwm3EhKt3ZCqaj9kGD18auaBAovJsOH29HVOlL2sPgQ L+Ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QRmNCfDb; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71192-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71192-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j20-20020a170906051400b00a3ea3dbd804si819899eja.772.2024.02.19.08.16.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 08:16:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71192-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QRmNCfDb; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71192-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71192-ouuuleilei=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 53E041F23BAE for ; Mon, 19 Feb 2024 11:23:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F3DE831755; Mon, 19 Feb 2024 11:22:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QRmNCfDb" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 AF8D92E419 for ; Mon, 19 Feb 2024 11:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341730; cv=none; b=OY7TRF8vr3hQrQyE1MOMX51+ukzmVS7XdtfILLPqUPXGXrNE3c5gUj0JV55Ai2LdqVOPUyjyXCJBbW9a47KgCJb249DS3+WpZA10Tw3odR3Ta86tK7xGrslEIZrTp+fCJMOAGo93Kp8R9RITtGOj113J5QABgMaPspfGMS5Sm+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341730; c=relaxed/simple; bh=Om6H6iwWgvEutVF7JX31pE1Rc0YLY3cg+69mPyvK1B8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cKvYJIiV87hQ4m+T7mnso2diAsUSoBQqf6HVp/MimJhiQgxy+PfawwsMD8z3hVWsg1k97SEwfRszkR/HeRf31HEpqzZyLLHUnndcr5A2WDVa1IfyRx5QY3Sv2+FKXimjEiQr8wvCKKYgDeJCx9ZhoiBRXvVtfg8mRN4WWcqTcdU= 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=QRmNCfDb; arc=none smtp.client-ip=198.175.65.12 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=1708341729; x=1739877729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Om6H6iwWgvEutVF7JX31pE1Rc0YLY3cg+69mPyvK1B8=; b=QRmNCfDbtXfJHheQksjy6rvvKgAHF5N2nLjrVRt7l0KY8UkGfZnap99K ZhMPhD9xKwmrHIhqiKGS5Cmy23ir32hLka7Nijsr5ShuTUeAIUJ4nyWYa qXdWPAnSzEDxxXyCNXArKkIbt3gf2STsNpA98yRFu4gLxsb+TU6x8OUjB /4faVzYh/qpvmdZOnJEryFGuOs9LNSRdLVL81RL5RkTLxY2QAmIY11xEi //Kr/Uc3hxEO+l/ybJbBJRzAXhOsUHRIlV90HOgXUwbFQu7gfe1bKmCBU mMuTnIf2wK1f7PPeBPqnXBwhr39XVddGGcZBcwan6nF8TUKFGPKL/8uvh w==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823390" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823390" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2024 03:22:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826856" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:22:06 -0800 From: Lu Baolu To: Joerg Roedel Cc: Yi Liu , Arnd Bergmann , Kevin Tian , Joao Martins , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 07/10] iommu/vt-d: Wrap the dirty tracking loop to be a helper Date: Mon, 19 Feb 2024 19:15:58 +0800 Message-Id: <20240219111601.96405-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240219111601.96405-1-baolu.lu@linux.intel.com> References: <20240219111601.96405-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791344664492739826 X-GMAIL-MSGID: 1791344664492739826 From: Yi Liu Add device_set_dirty_tracking() to loop all the devices and set the dirty tracking per the @enable parameter. Signed-off-by: Yi Liu Reviewed-by: Kevin Tian Reviewed-by: Joao Martins Link: https://lore.kernel.org/r/20240208082307.15759-8-yi.l.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index d286b8554227..2ad8fbe6dc21 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4729,23 +4729,38 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type) return vtd; } +/* + * Set dirty tracking for the device list of a domain. The caller must + * hold the domain->lock when calling it. + */ +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: @@ -4754,10 +4769,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; }