From patchwork Mon Feb 19 11:15:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1255211dyc; Mon, 19 Feb 2024 04:40:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWp9yeHtPKj1JohYCrosJ8U+8bezCoaFww4ZTIlX/8fr42DmgUvrmITbZ0nY6LJUTM1GgLZft6qYf1LmCS05tMFbKLPoA== X-Google-Smtp-Source: AGHT+IFNmZ/ozj+gg1M4M4K8ilctEwHL+8rt1H5DdW3lsA7GrUqSdysPnHe4ylTQ7cJJ6acYvXZb X-Received: by 2002:a05:620a:2194:b0:787:3311:433c with SMTP id g20-20020a05620a219400b007873311433cmr11944510qka.23.1708346434842; Mon, 19 Feb 2024 04:40:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708346434; cv=pass; d=google.com; s=arc-20160816; b=qO/jpSTxIFFvN1kc5kf1q6hkmblSTKG/eknEOavrGlcJDtu++fig3bbYG03lGp5WGp Lxc7GXHmEUVXZ4SqM7JcQagj2TDNoTHxNbNlt8asup20kK3LpJQ1Z2sJRZb3lOs5WZv8 uRZuV4p2iY3tAtNi1Fb1YK8XdhR3Y9OlZDogla2KlcDRJBuE+/4pldHDA/V51LqeFqQ3 ulcwO5ZnnV2NsD2AXCoplDFHk1THtIuOFpVTWnX/aZhv3wpkqQs2FsnQxcWgopJz6qGi UeW770H27cJ4QPJwlL9LCTRHKUPY48B2i2sEmt07ie++0N/CPIrefoLQKB+aDWRXh7ku TBhA== 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=32wSNigltmfbvj+9NBitamA2FQmGmwXd/TQ7BsQ0i8k=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=0UvXD61fLG6r17k9LewnAA5e040V+G6Ghbvhe9LXI70on2qnWhGF3RCgdE5EyU2YO/ GvGTu/c293bs5ETVSFZ9p/8dkXuQaDN6YZWOyw1tyWQm6y1Zd1WQ+KnSdQoWpYiQYcqu 5YgcMR/nZ1KdaIygsQiJTRnLm6Eknp6cTIILI7AFtFFyUde+gNlHAGIUov9ANt4N4MGV qFEO3b7a+ddONlQtIJi7n5SsLwamlGhtVQVSx7nnvpBLQc+u6gBoVw5al9wOw5h5+KjV oO39aOTl3/eR1cq2vHWskvGzjmOQn+J2exz9L/b26JajR4ULKe7U2U3I89efLgTi84Jw 983A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Ne/ohbi6"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71193-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71193-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u22-20020a05620a085600b007876fdb7bd5si594048qku.599.2024.02.19.04.40.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 04:40:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71193-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Ne/ohbi6"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71193-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71193-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 83DFD1C22C3D for ; Mon, 19 Feb 2024 11:23:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4328732C90; Mon, 19 Feb 2024 11:22:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ne/ohbi6" 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 185762E835 for ; Mon, 19 Feb 2024 11:22:11 +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=1708341732; cv=none; b=QW9CIHScMfgjBmMGmo1aRpPQIWsqsqMtdrV3gO5QSpVneWWYFV228aHLFdl0e1Z+DklNPdNRMKjB0lEzGYwwkHaOcngFaV6Gah4sBQOhNrNBZJ4xJ8maaZ83X1yw2maFBerxkrFTEHgPiPfU7rc8cWAJUPfvoMheKdZLa6m1ekY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341732; c=relaxed/simple; bh=c8ihMzuK+A3SWUIyq5JZpbhzCFh2xbpRUbw/s59zjdc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HO1km1t66Rtk3aW639SifmTNRH13gb2jUGSplrP75thqL2kmrD3PpF3YVGjwMdNE01CK6tqRzGN5QPqAH6EMJdmZm5XFKYZD0tj0ssfsKL3lAedL6QopfimCny4lFyZBJuEcLeBq54dPbqVsV02oShP+b3fCnOUVV99TfQQqpxw= 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=Ne/ohbi6; 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=1708341732; x=1739877732; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c8ihMzuK+A3SWUIyq5JZpbhzCFh2xbpRUbw/s59zjdc=; b=Ne/ohbi6h39hsp6bK49dALM3TpOcEMo5M0vgGrqxZKTho7HIz1SKfv/W Wswb+z0Vkci/ZapFLkpz1fj/Xa8EdJTvYBHHQF2pwjxmALKpI5I52RU7g BBCrXlp9bUSJA1phpTo3dAa17BlTbZmwANqUyk3jv2PrtXHwOQmhLu+VA D5nB+M4/sfoCH8ni028A5xCYka8Ha6ZtiSf2Uy4taloSWuWZnGIbkWhay D6WY1Ulf5xzVER9fI3IEh7P2RYSeRXaW9lLblJ29dWYoG82tXO7WJ/Fdx cEDRnBcVqqQ20X0fonvaQ/upC8k5FplVqeitQFEuprlmQsHS7fRfzXByG A==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823396" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823396" 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:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826865" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:22:09 -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 08/10] iommu/vt-d: Add missing dirty tracking set for parent domain Date: Mon, 19 Feb 2024 19:15:59 +0800 Message-Id: <20240219111601.96405-9-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: 1791331071347744032 X-GMAIL-MSGID: 1791331071347744032 From: Yi Liu Setting dirty tracking for a s2 domain requires to loop all the related devices and set the dirty tracking enable bit in the PASID table entry. This includes the devices that are attached to the nested domains of a s2 domain if this s2 domain is used as parent. However, the existing dirty tracking set only loops s2 domain's own devices. It will miss dirty page logs in the parent domain. Now, the parent domain tracks the nested domains, so it can loop the nested domains and the devices attached to the nested domains to ensure dirty tracking on the parent is set completely. Fixes: b41e38e22539 ("iommu/vt-d: Add nested domain allocation") Signed-off-by: Yi Sun Signed-off-by: Yi Liu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20240208082307.15759-9-yi.l.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 2ad8fbe6dc21..11652e0bcab3 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4748,6 +4748,35 @@ static int device_set_dirty_tracking(struct list_head *devices, bool enable) return ret; } +static int parent_domain_set_dirty_tracking(struct dmar_domain *domain, + bool enable) +{ + struct dmar_domain *s1_domain; + unsigned long flags; + int ret; + + spin_lock(&domain->s1_lock); + list_for_each_entry(s1_domain, &domain->s1_domains, s2_link) { + spin_lock_irqsave(&s1_domain->lock, flags); + ret = device_set_dirty_tracking(&s1_domain->devices, enable); + spin_unlock_irqrestore(&s1_domain->lock, flags); + if (ret) + goto err_unwind; + } + spin_unlock(&domain->s1_lock); + return 0; + +err_unwind: + list_for_each_entry(s1_domain, &domain->s1_domains, s2_link) { + spin_lock_irqsave(&s1_domain->lock, flags); + device_set_dirty_tracking(&s1_domain->devices, + domain->dirty_tracking); + spin_unlock_irqrestore(&s1_domain->lock, flags); + } + spin_unlock(&domain->s1_lock); + return ret; +} + static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain, bool enable) { @@ -4762,6 +4791,12 @@ static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain, if (ret) goto err_unwind; + if (dmar_domain->nested_parent) { + ret = parent_domain_set_dirty_tracking(dmar_domain, enable); + if (ret) + goto err_unwind; + } + dmar_domain->dirty_tracking = enable; out_unlock: spin_unlock(&dmar_domain->lock);