From patchwork Mon Feb 19 11:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1265771dyc; Mon, 19 Feb 2024 05:01:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXeLG1m+9JV+dDPDNCPbIZ9JUdckOtshFp6+l+fgj/vr6IRvTUiXK528EpyOESfjyPxgggSZ4H3ivLTqsDLCqkGtAMaEQ== X-Google-Smtp-Source: AGHT+IHcd3gXBEgUvqsRjt6E5MBh4Y4YEriI64VUa/NDk7ZjqTc2j7Fzk3zK/y4WX3DpTvmrg5/B X-Received: by 2002:a25:ab06:0:b0:dc2:2e01:4ff0 with SMTP id u6-20020a25ab06000000b00dc22e014ff0mr10381954ybi.45.1708347682873; Mon, 19 Feb 2024 05:01:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708347682; cv=pass; d=google.com; s=arc-20160816; b=iVIUnJCQipUgtobmQzczEx8tqpXXA5FexRlCOKh35tyVhklOdc9VdTj1HQxwMeQL8u TqhmgXYpLZ+0DU+4uqne/eE3lk/M4awiDbOjssMx3OFp17PZ9fiWzf65uZs5kY+BtAv2 od7700PHPyNhIlUkWCZFJSFSvBhd+dzc6bzc+4AGwImOVrb82g3aOSWm/zmMLaZhtExT wQvVftk92QEi1KlOfw+jc5VXl7dQ9N97m/diCA4PftHbHdSSJ77wpjbzMlIHUPEyfJ5R xGF7UbZVzaZEpwBxaowWMNvSnT+6SM7UmirYV65sLCZax5/cJ4mgIJr3KZ1Bwa2If91l gZgg== 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=pE5BXOCWCdps/MhTXNSchEKQtId/Nkr1fwNGGFapMBU=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=IfMcTS4ADXq7mN0CVLBPOybtcXkxlnUT3mpX2pDe2oYGDixV7yBiNC/9fZFxsYKyQ9 FNX/Ca0GXBs0MIDxT7A/+9CH8Pa2MUvTFM4xGWBQ0ZUGgESVA4e6TP/Yi9nb8thKzpNc uMAUr0OekwM3mL67SFFmv0SVIutt0dfEbPQNNdS3xLFPLd/3eQvJnfefdzjPFblIfM9t glRRSG2w8eOn76HoURj0fEQDJ3nvlFm3WE2F5cS4p5c9I5UBvpVYdpN9/Zlk4O9ref+G hXzzbVCOV+q2fOX2OY1OkGMsPi76sxug5HRV98EOfR8L3sBNjEasTfTwq4sF/fPVpaz2 tjxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WdZKyfKu; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71186-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71186-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 t6-20020a25f606000000b00dce3f1bc8c5si1471609ybd.671.2024.02.19.05.01.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:01:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71186-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=WdZKyfKu; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71186-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71186-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 1D1251C22357 for ; Mon, 19 Feb 2024 11:22:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D25072C848; Mon, 19 Feb 2024 11:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WdZKyfKu" 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 D07EA2C693 for ; Mon, 19 Feb 2024 11:21:54 +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=1708341716; cv=none; b=MfD2HEBJIdYwkU7fpFk1O8KWsfA2PLR6TXMkqkiCVXHUel2y2Ah2b+ibWeD+klleOsoRwsTbtQys1LjBNBexGt51oOE16V38WfLyYBPgrOOiaOVraiXxo8Rbxd72X7iuzB7mNCYh0fMXmyu5mRPw6RDOTkqQ6T1MYHnV3mcC1iw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341716; c=relaxed/simple; bh=FU4fhoGWvuGe6qI9myzpUIIpInnM2vTTQxC1ESzz82w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Tu47pkt+j/8aCXsxkgq3I5cUn6ZItjXZfBXBBdbFZ5hs6eX3ClYVFeCiDxn9TsgdkPGesgDs21PAHO9y0V2y8U6pd1kNq0sI5owP+LimxvUM52/Lro+qAcURAB5fFUFCa6nPLtK/cYzBfplf8Aagztl4aXPEnKpT66hL800hMGo= 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=WdZKyfKu; 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=1708341715; x=1739877715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FU4fhoGWvuGe6qI9myzpUIIpInnM2vTTQxC1ESzz82w=; b=WdZKyfKuTF7tRNL0utkI/BiM6S9ojPgiKh1aGLJ0Y0ksG7DWVYlHYnTl NXZXrmsKeNbAH5Pt5qEf6LymeOgE86Gj+ozOl8d9bHPdOwS2eF5S9kQ3m Ju/lhEyMvRTPzu1/p9bP/1FF4XB5kquZcmDyqnAKlU4yQLnpASHbt02A8 rdwLZSliJKEZOH/6gqgyIpJfdutlDLQK1JbxaZv3UVkLIfdgsw1jekPoD WXiyUn4Mm2Vd132VFEOzXDts26VtjDRjWIkQKukEEq2TwnDBglG02CWq1 jzNULSCucvg+/HVgjhKuXtz+67rzGV+q/pelA7FaKo1v3q1kPh4kjWGSq w==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823334" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823334" 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:21:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826784" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:21:52 -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 01/10] iommu/vt-d: Track nested domains in parent Date: Mon, 19 Feb 2024 19:15:52 +0800 Message-Id: <20240219111601.96405-2-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: 1791332380067088634 X-GMAIL-MSGID: 1791332380067088634 From: Yi Liu Today the parent domain (s2_domain) is unaware of which DID's are used by and which devices are attached to nested domains (s1_domain) nested on it. This leads to a problem that some operations (flush iotlb/devtlb and enable dirty tracking) on parent domain only apply to DID's and devices directly tracked in the parent domain hence are incomplete. This tracks the nested domains in list in parent domain. With this, operations on parent domain can loop the nested domains and refer to the devices and iommu_array to ensure the operations on parent domain take effect on all the affected devices and iommus. Signed-off-by: Yi Liu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20240208082307.15759-2-yi.l.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 6 ++++++ drivers/iommu/intel/iommu.c | 18 ++++++++++++++---- drivers/iommu/intel/nested.c | 12 +++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index d02f916d8e59..9b27edb73aa9 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -627,6 +627,10 @@ struct dmar_domain { int agaw; /* maximum mapped address */ u64 max_addr; + /* Protect the s1_domains list */ + spinlock_t s1_lock; + /* Track s1_domains nested on this domain */ + struct list_head s1_domains; }; /* Nested user domain */ @@ -637,6 +641,8 @@ struct dmar_domain { unsigned long s1_pgtbl; /* page table attributes */ struct iommu_hwpt_vtd_s1 s1_cfg; + /* link to parent domain siblings */ + struct list_head s2_link; }; }; diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 6fb5f6fceea1..e393c62776f3 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3883,6 +3883,7 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING; bool nested_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT; struct intel_iommu *iommu = info->iommu; + struct dmar_domain *dmar_domain; struct iommu_domain *domain; /* Must be NESTING domain */ @@ -3908,11 +3909,16 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, if (!domain) return ERR_PTR(-ENOMEM); - if (nested_parent) - to_dmar_domain(domain)->nested_parent = true; + dmar_domain = to_dmar_domain(domain); + + if (nested_parent) { + dmar_domain->nested_parent = true; + INIT_LIST_HEAD(&dmar_domain->s1_domains); + spin_lock_init(&dmar_domain->s1_lock); + } if (dirty_tracking) { - if (to_dmar_domain(domain)->use_first_level) { + if (dmar_domain->use_first_level) { iommu_domain_free(domain); return ERR_PTR(-EOPNOTSUPP); } @@ -3924,8 +3930,12 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, static void intel_iommu_domain_free(struct iommu_domain *domain) { + struct dmar_domain *dmar_domain = to_dmar_domain(domain); + + WARN_ON(dmar_domain->nested_parent && + !list_empty(&dmar_domain->s1_domains)); if (domain != &si_domain->domain) - domain_exit(to_dmar_domain(domain)); + domain_exit(dmar_domain); } int prepare_domain_attach_device(struct iommu_domain *domain, diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index f26c7f1c46cc..6a75f6eb18f1 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -70,7 +70,13 @@ static int intel_nested_attach_dev(struct iommu_domain *domain, static void intel_nested_domain_free(struct iommu_domain *domain) { - kfree(to_dmar_domain(domain)); + struct dmar_domain *dmar_domain = to_dmar_domain(domain); + struct dmar_domain *s2_domain = dmar_domain->s2_domain; + + spin_lock(&s2_domain->s1_lock); + list_del(&dmar_domain->s2_link); + spin_unlock(&s2_domain->s1_lock); + kfree(dmar_domain); } static void nested_flush_dev_iotlb(struct dmar_domain *domain, u64 addr, @@ -201,5 +207,9 @@ struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent, spin_lock_init(&domain->lock); xa_init(&domain->iommu_array); + spin_lock(&s2_domain->s1_lock); + list_add(&domain->s2_link, &s2_domain->s1_domains); + spin_unlock(&s2_domain->s1_lock); + return &domain->domain; } From patchwork Mon Feb 19 11:15:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1255400dyc; Mon, 19 Feb 2024 04:40:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUBP+5rGYnLVjPfiyTAVIzHDVt9jajGqbX1CfYO18I9wwNU6TP5G/57xcyZupbcdr5Kj1qw4ZogHVpVAuCmgvmkHHA+Yg== X-Google-Smtp-Source: AGHT+IHa4R9/2GRh7lCJ9w+SHHpzYo45Jhs2E38ZZpJsCYprcHO9KYR3Wkae5WHJC8Od4mYqcDYG X-Received: by 2002:a05:6214:e8d:b0:68f:88c0:784e with SMTP id hf13-20020a0562140e8d00b0068f88c0784emr303009qvb.62.1708346456583; Mon, 19 Feb 2024 04:40:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708346456; cv=pass; d=google.com; s=arc-20160816; b=G0RzqOMeqaQ9uVslpfBfm9wdxmZu7Sh6R0Rf7Opnu96oTg7Tw+8nVdqOACAw8JS3K8 WtQZ5+Eo/2p675Q/D0iosy64nBKxLvSLzkUTMVx3dUgb/C2EZKZ2560+GAlO1c3/YzKO Y8ydFFcMX4/BBY/QjeHAmGbaKSb2xQr/U3fdLlFsHpyQ7yVTsEtmmt0j+IGqtzGoC8T1 7pJfOC/HhJgjPeE5iu8uO+soqsApwBbDQI2y96beeacXOdUU3Ua2GjYbOpCaNrjh/47q p2++at7bMdwT8hVluEMLgnEXNNV6uYyN+IVzfb1+Q3Bn/oQxJxGyCJoMN9oquW8a8Fp4 /WMQ== 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=YmypyFSumgSKdb/Ew/d9XyN6Rvfb9c598YS+ZZ+7HVQ=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=FW53GVk/G5eDeS7V4VS/xbSTF5dYDAgAFiIz4cpKe49TdRRmKd/Zx39C/0Cl7LeRVN czVaqpJnwfAhhEzpmpDaglKvFkui4BZ82J+owbCiweTKKZebg4ZqeMfIGpeSGP+tgQP/ 7nqgOjBw+dej3S+7ZAEUbxt00xQMwFajJPQFFDErri4aTbCVPbpQykEk/VwQM99XJZxg 3GWemp1n64hHw0pD3WPp4pBEodl76AvILcVQkbXAoVeK4fejciJPIAm/tDG5xPQyOeSG JwtgwAQLCJGkt/KuMN04jfaeMvZ/mKy845H3HpEUXtUET7mchPvykiV1nLP4+gluN5pw tnyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cT59GSDj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71187-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71187-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 fv1-20020a056214240100b0068c4ff7f5a0si5959284qvb.323.2024.02.19.04.40.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 04:40:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71187-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=cT59GSDj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71187-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71187-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 D0D261C22521 for ; Mon, 19 Feb 2024 11:22:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8DFA2D03C; Mon, 19 Feb 2024 11:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cT59GSDj" 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 38A022C1B9 for ; Mon, 19 Feb 2024 11:21:57 +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=1708341718; cv=none; b=E+UdSRmirVWSbbJ4myD+oUA+HTauu35M3K+GdZIryFTRQ662UzW5iq+2VhlYMOq9kSgAOcEKGgJJjC5hmAXWvM8M2iPgn54JV9xlQ1YRxK6l/zYPdAtqJySL2i5E2OLEbC62AZe1keL3JnDkcVcv0+a8IaaXXih8t8i0bBVLuY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341718; c=relaxed/simple; bh=Zqh+3Mt2v/emqmQjBVUt1eEzkbGDcsPozbxTYVR4sOQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m9FeFbTjLIqFL4RtVGr7G4HozGpznxB9Y9Z5yJGM1mJYNJXIqEQr4zlZ/K4ptmu5E8WA3Ocb+6N4r0DHJ3cvTAKhj7D5YE324opnDvqdyrbQ4BdOZJIKa+51vCtcWpdYvDNcj8l3Dc1dfGzksir9yzExpXJI9QBzmD8E22V4Vhc= 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=cT59GSDj; 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=1708341718; x=1739877718; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zqh+3Mt2v/emqmQjBVUt1eEzkbGDcsPozbxTYVR4sOQ=; b=cT59GSDj9BKSYHkESZJQfxxbx549XxChlEJ0kUbCrOiKYjfGIdiAJ1KP niBA9QLCyw/ZhZOUgx3veOIhhV2/EfbAvF4LK4Th+9THqLVmff09INclS nm84AzkmaaRm+9zBFGtrDBcAL/SCAXHyuLboPlNLzsF8cz/oXLAoO3Jzt s6temF4ThxSlnuDKHiPT4VmjHAspj3lvJKG8agQDgxaZslIzDlwmwbBS/ wDGVpoxPF2+8aHwhZzJikzQ9k1n/HHDJbADTLNqW9T/v8ZS/4ambMXaFf 1kJM+69aMpgiKhQ+U1PrrBCmGj9JT9DhrQRNeGv5HidVrmmlHGJnAezJE Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823343" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823343" 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:21:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826798" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:21:55 -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 02/10] iommu/vt-d: Add __iommu_flush_iotlb_psi() Date: Mon, 19 Feb 2024 19:15:53 +0800 Message-Id: <20240219111601.96405-3-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: 1791331093948526925 X-GMAIL-MSGID: 1791331093948526925 From: Yi Liu Add __iommu_flush_iotlb_psi() to do the psi iotlb flush with a DID input rather than calculating it within the helper. This is useful when flushing cache for parent domain which reuses DIDs of its nested domains. Signed-off-by: Yi Liu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20240208082307.15759-3-yi.l.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 78 ++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index e393c62776f3..dbdb8366c42a 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1368,6 +1368,46 @@ static void domain_flush_pasid_iotlb(struct intel_iommu *iommu, spin_unlock_irqrestore(&domain->lock, flags); } +static void __iommu_flush_iotlb_psi(struct intel_iommu *iommu, u16 did, + unsigned long pfn, unsigned int pages, + int ih) +{ + unsigned int aligned_pages = __roundup_pow_of_two(pages); + unsigned long bitmask = aligned_pages - 1; + unsigned int mask = ilog2(aligned_pages); + u64 addr = (u64)pfn << VTD_PAGE_SHIFT; + + /* + * PSI masks the low order bits of the base address. If the + * address isn't aligned to the mask, then compute a mask value + * needed to ensure the target range is flushed. + */ + if (unlikely(bitmask & pfn)) { + unsigned long end_pfn = pfn + pages - 1, shared_bits; + + /* + * Since end_pfn <= pfn + bitmask, the only way bits + * higher than bitmask can differ in pfn and end_pfn is + * by carrying. This means after masking out bitmask, + * high bits starting with the first set bit in + * shared_bits are all equal in both pfn and end_pfn. + */ + shared_bits = ~(pfn ^ end_pfn) & ~bitmask; + mask = shared_bits ? __ffs(shared_bits) : BITS_PER_LONG; + } + + /* + * Fallback to domain selective flush if no PSI support or + * the size is too big. + */ + if (!cap_pgsel_inv(iommu->cap) || mask > cap_max_amask_val(iommu->cap)) + iommu->flush.flush_iotlb(iommu, did, 0, 0, + DMA_TLB_DSI_FLUSH); + else + iommu->flush.flush_iotlb(iommu, did, addr | ih, mask, + DMA_TLB_PSI_FLUSH); +} + static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, struct dmar_domain *domain, unsigned long pfn, unsigned int pages, @@ -1384,42 +1424,10 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, if (ih) ih = 1 << 6; - if (domain->use_first_level) { + if (domain->use_first_level) domain_flush_pasid_iotlb(iommu, domain, addr, pages, ih); - } else { - unsigned long bitmask = aligned_pages - 1; - - /* - * PSI masks the low order bits of the base address. If the - * address isn't aligned to the mask, then compute a mask value - * needed to ensure the target range is flushed. - */ - if (unlikely(bitmask & pfn)) { - unsigned long end_pfn = pfn + pages - 1, shared_bits; - - /* - * Since end_pfn <= pfn + bitmask, the only way bits - * higher than bitmask can differ in pfn and end_pfn is - * by carrying. This means after masking out bitmask, - * high bits starting with the first set bit in - * shared_bits are all equal in both pfn and end_pfn. - */ - shared_bits = ~(pfn ^ end_pfn) & ~bitmask; - mask = shared_bits ? __ffs(shared_bits) : BITS_PER_LONG; - } - - /* - * Fallback to domain selective flush if no PSI support or - * the size is too big. - */ - if (!cap_pgsel_inv(iommu->cap) || - mask > cap_max_amask_val(iommu->cap)) - iommu->flush.flush_iotlb(iommu, did, 0, 0, - DMA_TLB_DSI_FLUSH); - else - iommu->flush.flush_iotlb(iommu, did, addr | ih, mask, - DMA_TLB_PSI_FLUSH); - } + else + __iommu_flush_iotlb_psi(iommu, did, pfn, pages, ih); /* * In caching mode, changes of pages from non-present to present require From patchwork Mon Feb 19 11:15:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203076 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1284874dyc; Mon, 19 Feb 2024 05:33:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZLZ/cOu810NQh2WYJ9p4CVFkwVQKBgvXJbtKZ1T6KzzSsMYfIMuvNjjh9g+Lxd+dSeZzE3QihjnHZD93eTECX37E76w== X-Google-Smtp-Source: AGHT+IHBpfg4AqxzuG1NT3fd8eymqIT0/K9Z5yykbKYP5Lr6/fMLLICKLqKSsThq/QZGNualGlRs X-Received: by 2002:a17:90a:f992:b0:299:388f:5a29 with SMTP id cq18-20020a17090af99200b00299388f5a29mr10412899pjb.24.1708349587105; Mon, 19 Feb 2024 05:33:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708349587; cv=pass; d=google.com; s=arc-20160816; b=UJchhUXoG+ou9k7GaP75wytxw7/E1odhg61DloKRF2yLfg+QqWRKTNtcsgCnkaQNqa NbEbj4BCZIwGPHzMDxjEITqvaYXxmLB4fqEug6KIBoKhvGCo/2wSS8gjjsOFAYUZc8Aj vUDbxFsqu72YRfTKy19Lhm1UYSXCjfUp/WQQ3OqK+xXyFEvP21OgvdLOaH+JcnGw8D0F ABif0VCsyOeLtfZ37aH93d3xNiTzZcm6hmUWf8Jq2B/uNqjAt/7vOX2FeKMUg6533736 pUnZR1B0AQFPqV6CYAhnse5SgC/GJ+M7sCsFb/EDG+7RhvTmReRf5LCyH4gtSXUb2GWJ MXMQ== 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=ePtNSfywjEJ53hTGygLlcO8U1HNk4xnKyyeVVUbP1hE=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=XIZGPrYLIwtvYCHneC9ZW9/VA/y41G1NR/Mkn9x1lFxYiquQWKUO8yVAmyCotmLFfI gptbYXrYzO+QL+tYm67kaCGOiqrjXQo1zO3vTTrWQAB8evE446WscQy+edrjGvZrNyUM jSi5/2iOhZPtNlvddowCY6BbtKwCHQCD6XR/nK+zkpasGyCNPu5XjJfmJhjY7n4luwl3 CztpROn9GIF2GI7kHLLSmDnl/29ptsPSvppBTMtMzUqwGenT0UOp6doFRgjfMQQhqif4 QP5iDYXBz1DlsfXGUFyd+ZKrRKCDQW3C37Pjj1iraFbUsdTk+MpgUUQ6Js7uDX5703uL 1DAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PIu7a43C; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71188-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71188-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x64-20020a638643000000b005ce0474353csi4311545pgd.238.2024.02.19.05.33.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:33:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71188-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PIu7a43C; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71188-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71188-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 47703B2279E for ; Mon, 19 Feb 2024 11:22:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE2B32D03B; Mon, 19 Feb 2024 11:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PIu7a43C" 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 8E1412C6B9 for ; Mon, 19 Feb 2024 11:21:59 +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=1708341721; cv=none; b=oubcB5nt/dVEBrSoMmkwVLWuDxNU9hVPvtcXb3w7+f7sOzlT1m90EoINcQJ0iy+1rJrj33/Ujtiix5KZfROukw2zcNVcQCiyv63WfHU0kG1IKlT0VN8//gDzrK3aQqM9l6ZNUvRn82/wQ0unWsVXM1yfO5/Dzk5BYeSWeaY9KHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341721; c=relaxed/simple; bh=wdo4y+teNsTSHhgxPZRjHIAgdvEhP4G9F49w7xcQvdM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z/LFRmW41T776k4ib7jrNGFPjGiZ3dDgHwjKf5Ajrxz6txfbpSVC3OzFqCaU1aaEFMvlDnVoNIlD9rHaVLAORpIBaNMSrmRH9RlJWzTD9vaYK8sbrMu49eaOVScYSOsu7aQYcQk7Tbysd8N1jZ+8Uw+UF8H7yvJaGRfdKbYlebc= 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=PIu7a43C; 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=1708341720; x=1739877720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wdo4y+teNsTSHhgxPZRjHIAgdvEhP4G9F49w7xcQvdM=; b=PIu7a43CJOCZ6dAIk+AiUTwncLe19Yc7UxTY+0EvcNnR6Br7I0I3TztU I4hZRHXgHzaSgnFKttlH5iRDRKTI+m67vqbKMUGmD7aV5oaUaTCoNLxYZ WEjqyUfPrVMxv56V8IUwcQ9YuSdckwydaLhvJkB1hJv3rzzykfxb3Zc04 N/nRJQ2pWmVUpqIkxvf9/Dfi2oecRxl/0jbLrfBLSu33rGjCHkLylqz9J K3kBNVdg8n380Q73eeKj/G/dvehD0ZSls6o27dNUEG5zi/g5lkxHf0y7J FRtylH1+MFOzce4JKoyn0kPmx3iFed+2+vFLxJKu+D5nV5CaZQk/DFiuY w==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823353" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823353" 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:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826813" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:21:57 -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 03/10] iommu/vt-d: Add missing iotlb flush for parent domain Date: Mon, 19 Feb 2024 19:15:54 +0800 Message-Id: <20240219111601.96405-4-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: 1791334376749455738 X-GMAIL-MSGID: 1791334376749455738 From: Yi Liu If a domain is used as the parent in nested translation its mappings might be cached using DID of the nested domain. But the existing code ignores this fact to only invalidate the iotlb entries tagged by the domain's own DID. Loop the s1_domains list, if any, to invalidate all iotlb entries related to the target s2 address range. According to VT-d spec there is no need for software to explicitly flush the affected s1 cache. It's implicitly done by HW when s2 cache is invalidated. Fixes: b41e38e22539 ("iommu/vt-d: Add nested domain allocation") Signed-off-by: Yi Liu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20240208082307.15759-4-yi.l.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index dbdb8366c42a..e3dbcae95975 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1451,6 +1451,28 @@ static void __mapping_notify_one(struct intel_iommu *iommu, struct dmar_domain * iommu_flush_write_buffer(iommu); } +/* + * Flush the relevant caches in nested translation if the domain + * also serves as a parent + */ +static void parent_domain_flush(struct dmar_domain *domain, + unsigned long pfn, + unsigned long pages, int ih) +{ + struct dmar_domain *s1_domain; + + spin_lock(&domain->s1_lock); + list_for_each_entry(s1_domain, &domain->s1_domains, s2_link) { + struct iommu_domain_info *info; + unsigned long i; + + xa_for_each(&s1_domain->iommu_array, i, info) + __iommu_flush_iotlb_psi(info->iommu, info->did, + pfn, pages, ih); + } + spin_unlock(&domain->s1_lock); +} + static void intel_flush_iotlb_all(struct iommu_domain *domain) { struct dmar_domain *dmar_domain = to_dmar_domain(domain); @@ -1470,6 +1492,9 @@ static void intel_flush_iotlb_all(struct iommu_domain *domain) if (!cap_caching_mode(iommu->cap)) iommu_flush_dev_iotlb(dmar_domain, 0, MAX_AGAW_PFN_WIDTH); } + + if (dmar_domain->nested_parent) + parent_domain_flush(dmar_domain, 0, -1, 0); } static void iommu_disable_protect_mem_regions(struct intel_iommu *iommu) @@ -1993,6 +2018,9 @@ static void switch_to_super_page(struct dmar_domain *domain, iommu_flush_iotlb_psi(info->iommu, domain, start_pfn, lvl_pages, 0, 0); + if (domain->nested_parent) + parent_domain_flush(domain, start_pfn, + lvl_pages, 0); } pte++; @@ -4125,6 +4153,9 @@ static void intel_iommu_tlb_sync(struct iommu_domain *domain, start_pfn, nrpages, list_empty(&gather->freelist), 0); + if (dmar_domain->nested_parent) + parent_domain_flush(dmar_domain, start_pfn, nrpages, + list_empty(&gather->freelist)); put_pages_list(&gather->freelist); } From patchwork Mon Feb 19 11:15:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1344957dyc; Mon, 19 Feb 2024 07:10:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU8frwS8JkCy4K6+0AZgFi1MEMJa9qPnQgm2FtvMYEhOoo3uKPNuccyefopeGyaOejSEINiwQ1sbE7v0LHnDHkJQgyZwQ== X-Google-Smtp-Source: AGHT+IF0svkK8ISQTW6E+6f1BiQVyzdvvMDv3zhtKLhG1t0WjcdTf8gX98CtNbO0BdMw2ab1lAFG X-Received: by 2002:a05:622a:1101:b0:42c:66ce:bbe1 with SMTP id e1-20020a05622a110100b0042c66cebbe1mr16330505qty.53.1708355413437; Mon, 19 Feb 2024 07:10:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708355413; cv=pass; d=google.com; s=arc-20160816; b=VarTwjiZxkxnZbSUB+1Xaq/KYbgpfFavYPNtAsvG288X2QbhU4HbhFRHDBrycibTJW 9r8cTWdLUhKpRkh/EzgHqazSCE+PVcwHPLyqSq7EiVr696CA87VD6V4w/Zzmm2Zin6RT xArd9dJ6maycoQK1ndtmnZ9cZ51y5S4BvX5R/WZvSh6LjXw2ZG6FnTuJw0aXp29Bpgrt JNd9AvSvalGFQmXXOcEutl4f71PKW7VT77gR5o2MFLOmtXg69656ZGRS7S1hrF9HFtEH v6dFaixp4ZXIdgqSjCYEJ4c+ZcZ98KQ2CY5Jp4YZuCUqW7mWR7z16tdpKAQ26aaOXjl3 qHzQ== 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=NuIXXs9QkboYfRArjwEFl130Y7wclw2WuUSuaCvvTBM=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=sTG2qoFod1BSK1etaozOUytRPCkD61gSGA3dI41o7IhSGKHLZr3LMrD6VbwZEwQz8j m+kMyMm46Nc5SbwKdjRBX/L6aINgmeilK4xXS1XZhbZLywKqVYXWmDIOAv+dZQng/i3m Dvo9PnWicCVQTQNMxdFvOGHFFUSmN1n6RydgZgI2oMCGot0NKKc9nTVLk62xcH6rkzEF ECmZENkt9NAshPcBV0ABDUAuJSC0zzU1nhDg6btBrjPSXGn08fMRq/kU8vaNw5K+Bx3W j5lXziGVA2knvUCHOVrvhlsgKwEy5hNyX0Js/LO48eeGMM6W1eNNQmekm0l+Dg4QEwqY 6grw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GPl5sCRQ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71189-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71189-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 w4-20020a05622a134400b0042aaa53f36dsi6990136qtk.573.2024.02.19.07.10.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 07:10:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71189-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=GPl5sCRQ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71189-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71189-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 CC85D1C22775 for ; Mon, 19 Feb 2024 11:22:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 155AD2E3EF; Mon, 19 Feb 2024 11:22:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GPl5sCRQ" 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 C4E962C192 for ; Mon, 19 Feb 2024 11:22:01 +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=1708341724; cv=none; b=XmQ4QZRdz414eSJzrXRyRyWZkdMqUyxiCpUaD7/fqGjIvxyVvv3HzG+8BGdfUziEltKHYiOUcs8VQaF+m1Tjkwa62yo5dgMPgiG1KH2eips4SZLA2YhzuYqgWehbGwsax0SgLe+rDcyoRxMYiuU9344CMc8KpbNanu9VFVJilvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341724; c=relaxed/simple; bh=MrZgKSOW1tjC5BJ1Aj4vy1HeG1IeCVgQtjxOHw/lyVA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Up0FeZIxzkAG6YBOmL17aFbCUJHClGBKnfMFJpnXD1FeIV+gRJfMXtj3E4MKPxihnSjsLnoY9GmmgaNCNdGBkcE6aolCRak+qlUL+4FocxnTB4FKBodDjdY+bOorDdgrfDkA3emCnwaAznQUJSCbPMWJ6kPOruV2PQVWDZXoqN8= 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=GPl5sCRQ; 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=1708341722; x=1739877722; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MrZgKSOW1tjC5BJ1Aj4vy1HeG1IeCVgQtjxOHw/lyVA=; b=GPl5sCRQpuehZoDDCMa03BX4lisoJBZ8YFQm1h4UZQCfCKbTNMHO+8iF gnG09ZOT0prQTNC3WAYWOuEQrDVfcukkTZ/5sU7LrNnO3PE6F7SSjAld+ XOE4TmsL73mhwZ5YtwCkfVQLIThPlpYbFZT77ij93Qmivgtud1zu2aG2Z w07J0tjwC77Q0cezWXrgKAXOX3t0TXltFSzNORvKedRugwgll6vtWsVCI zOI+uPfkNmgmheN6Lb/YV0+V3KcCs36pa0ak8ZSqlMyoifExPrbuxd9Vp tBDih3+6yGlZJMBnyMhtM8rKOAr0cynigS4fgSp8/8Fsp6wvCBC1k2Q2e A==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823359" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823359" 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:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826822" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:22:00 -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 04/10] iommu/vt-d: Update iotlb in nested domain attach Date: Mon, 19 Feb 2024 19:15:55 +0800 Message-Id: <20240219111601.96405-5-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: 1791340485608871032 X-GMAIL-MSGID: 1791340485608871032 From: Yi Liu Should call domain_update_iotlb() to update the has_iotlb_device flag of the domain after attaching device to nested domain. Without it, this flag is not set properly and would result in missing device TLB flush. Fixes: 9838f2bb6b6b ("iommu/vt-d: Set the nested domain to a device") Signed-off-by: Yi Liu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20240208082307.15759-5-yi.l.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 + drivers/iommu/intel/iommu.c | 4 +--- drivers/iommu/intel/nested.c | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 9b27edb73aa9..4145c04cb1c6 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1066,6 +1066,7 @@ int qi_submit_sync(struct intel_iommu *iommu, struct qi_desc *desc, */ #define QI_OPT_WAIT_DRAIN BIT(0) +void domain_update_iotlb(struct dmar_domain *domain); int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu); void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu); void device_block_translation(struct device *dev); diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index e3dbcae95975..711c3e3fe095 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -396,8 +396,6 @@ static int domain_update_device_node(struct dmar_domain *domain) return nid; } -static void domain_update_iotlb(struct dmar_domain *domain); - /* Return the super pagesize bitmap if supported. */ static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain) { @@ -1218,7 +1216,7 @@ domain_lookup_dev_info(struct dmar_domain *domain, return NULL; } -static void domain_update_iotlb(struct dmar_domain *domain) +void domain_update_iotlb(struct dmar_domain *domain) { struct dev_pasid_info *dev_pasid; struct device_domain_info *info; diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index 6a75f6eb18f1..d5af5925a31c 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -65,6 +65,8 @@ static int intel_nested_attach_dev(struct iommu_domain *domain, list_add(&info->link, &dmar_domain->devices); spin_unlock_irqrestore(&dmar_domain->lock, flags); + domain_update_iotlb(dmar_domain); + return 0; } From patchwork Mon Feb 19 11:15:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1340901dyc; Mon, 19 Feb 2024 07:05:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXSOw/r9WETWFusxLOnKNKmejhEsJvgmc/e/CJ5lCgj/WkM+MPjljbd9QAgUugpWAfEecQR+OwlU/vUQO+itvuwUuhfuQ== X-Google-Smtp-Source: AGHT+IFoNwhGTyecvW08/vqJGt+B/1EnOAwHyl14/0EfiWzfPP0lRqP5GlyKxQuE3B7xFECFYcID X-Received: by 2002:a1f:ea04:0:b0:4c8:90e5:6790 with SMTP id i4-20020a1fea04000000b004c890e56790mr3337499vkh.5.1708355120313; Mon, 19 Feb 2024 07:05:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708355120; cv=pass; d=google.com; s=arc-20160816; b=c+EnLYVcErOJxmiDf3mSGJFD67xXDB0vt7HJ73A+xIrLwVedebtw7Lf+fLdwdrA33d TOVtjzs/QNP6c+cEMLDCiuTgd2kYm1OPmt9OtIFWTa+F/JNVzaRhQxGMkhMEb40n40QJ HUigapxkMFObA0TPpE4CuDpS2AZqsXOIbPHHtmdZtsvbytzsQcQgffpZ7hoVRI59eP5A ik5JioBgAVEFAkCDPAOR0FGEJxrTJ5D742UlYyOPvdubGkGgVL7HNQD+irFabmBANkGz GqxomifRVu+cBh0XJXyxSjByWRDjDoDum4s8+S9fwQhVQru/S/oLsWhIS9qjJCh2uC4T 2erQ== 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=rzeEvL5e7JPQZsHBflEDGAuDdLExwDEd/C7u3fr/WU0=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=TTccvJtDi+WQ9EPlKhZaBVy2P/u7cEA2tpEOoJq36BDlymCbWC6n9KmII/d/exSeHc FR+HWLer0O06mNXddo+N8AdlFiO1vbTGfsPE/TqEbDxBa+IqqqaQhHK2h31avgO4+BKK aKgU6lGO4KY5Ife2gd7WzXWyp4jA21towXeqFZ3G6fhrbWExJ3OjC1IuUUo2udxy6G80 1sJVZyoZ57IVCMjvuZGarxPLk7gIUq7VBlqPm64hL2wyKY9fy9DH6sr+L1Rblw2CqvyS dQq0VhTdWW7eNCsGqKR6QpbQKyAxUhuhS0gnauT297pcfYF+z7IpKUhtWyydhswT1VyP kViQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nQXPKWNL; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71190-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71190-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 i7-20020a056122208700b004cb774f4083si344809vkd.9.2024.02.19.07.05.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 07:05:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71190-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=nQXPKWNL; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71190-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71190-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 148EF1C228FB for ; Mon, 19 Feb 2024 11:23:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A72402E416; Mon, 19 Feb 2024 11:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nQXPKWNL" 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 5C6DA2D606 for ; Mon, 19 Feb 2024 11:22:04 +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=1708341726; cv=none; b=Y6JdPpW4HbSp5d+B0kuDG37QvLGnLklcxTfJLhZPIySGD8no4qMBxbu4GwEdMBeRpotRHtZ8v2YFAJ77yoG91Xdm+gqBixJl6b2K6Y5660dVBmXZvjbgSCv0L/W3HtGUxTEiTqlRxEuRmlQLta/vsoVo2GnBPFAkChvSWOakaP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341726; c=relaxed/simple; bh=Czn+l+8Z40u8Nj0hak+E8ur277wY/U7sKfZyklmUb7M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A+P918l5te6P6JQQFC7pgiHJBtsNlcIkjMDCK2WQdoUu9ybHaI0BAcZqHWM2NLSHtz+Uc8pUoqdatFceE1+tfFqgmR6oPOutmH5N2EVY/BCXkwQgv94GOwdQAS9wQ8SIx56BYvj99kE0e190nEICOuxbIepJz2Pw3eOGLW1/yps= 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=nQXPKWNL; 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=1708341725; x=1739877725; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Czn+l+8Z40u8Nj0hak+E8ur277wY/U7sKfZyklmUb7M=; b=nQXPKWNLOVgJ/MROYRudmVFp+/96fl0cG5lawf8NFo/ScaqOOVzlpssm 3yA7ZrpVAMLSbeCFMDNsC5ERqPwXxmrsEMYKfIw/v/8JQCYcWRSIsWH6n IbPJbEdeqgUTyccT0jfxU/p1DgmWtDehDIr6e5RUn9TVEfrIZTwRjsCFO Cw3wY7yRymXj/kxVmcd1+WuWpu2iu/7hUpXrbMM6kA3sOFy+nc7fSjVef t3aOhSgF1DiilPcxf/kfkZncLCQVPgTonkvgvDoFru7PVTEAC27xllJ3e DRfyQyO3zSZwA+lLZnYJx/RqntZJTQSI4ZpRmmeRcDrw283PwmL/dTB8m g==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823369" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823369" 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:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826834" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:22:02 -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 05/10] iommu/vt-d: Add missing device iotlb flush for parent domain Date: Mon, 19 Feb 2024 19:15:56 +0800 Message-Id: <20240219111601.96405-6-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: 1791340177760475690 X-GMAIL-MSGID: 1791340177760475690 From: Yi Liu ATS-capable devices cache the result of nested translation. This result relies on the mappings in s2 domain (a.k.a. parent). When there are modifications in the s2 domain, the related nested translation caches on the device should be flushed. This includes the devices that are attached to the s1 domain. However, the existing code ignores this fact to only loops its own devices. As there is no easy way to identify the exact set of nested translations affected by the change of s2 domain. So, this just flushes the entire device iotlb on the device. As above, driver loops the s2 domain's s1_domains list and loops the devices list of each s1_domain to flush the entire device iotlb on the devices. Fixes: b41e38e22539 ("iommu/vt-d: Add nested domain allocation") Signed-off-by: Yi Liu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20240208082307.15759-6-yi.l.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 711c3e3fe095..2eee83b5441b 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1461,12 +1461,30 @@ static void parent_domain_flush(struct dmar_domain *domain, spin_lock(&domain->s1_lock); list_for_each_entry(s1_domain, &domain->s1_domains, s2_link) { + struct device_domain_info *device_info; struct iommu_domain_info *info; + unsigned long flags; unsigned long i; xa_for_each(&s1_domain->iommu_array, i, info) __iommu_flush_iotlb_psi(info->iommu, info->did, pfn, pages, ih); + + if (!s1_domain->has_iotlb_device) + continue; + + spin_lock_irqsave(&s1_domain->lock, flags); + list_for_each_entry(device_info, &s1_domain->devices, link) + /* + * Address translation cache in device side caches the + * result of nested translation. There is no easy way + * to identify the exact set of nested translations + * affected by a change in S2. So just flush the entire + * device cache. + */ + __iommu_flush_dev_iotlb(device_info, 0, + MAX_AGAW_PFN_WIDTH); + spin_unlock_irqrestore(&s1_domain->lock, flags); } spin_unlock(&domain->s1_lock); } From patchwork Mon Feb 19 11:15:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203089 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1293275dyc; Mon, 19 Feb 2024 05:50:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXNWX+2at5aQ8FHuZmbz/VuK7mwmbBih1hLheVjCmYgErZB8a3PxtBJDORGn1c9yzP1HsiV+qm5UjBjVtwlbeLQK7V6EA== X-Google-Smtp-Source: AGHT+IE2++UNAtWOI+hg+8PycAxcXGBvBZAHceVW//ajnyMtgBDuRB2w0ogn9OWe3uOW73o06aHG X-Received: by 2002:a05:6808:4498:b0:3c1:4526:7533 with SMTP id eq24-20020a056808449800b003c145267533mr11586304oib.14.1708350621662; Mon, 19 Feb 2024 05:50:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350621; cv=pass; d=google.com; s=arc-20160816; b=0l/KmHH4Bz7gbZOxQhbmo6nx2ApRc0fLwuKDc9JdZiMyhcdIoH2wWglunKGtBmdzBN 1TludTZcjoqPNc5GgtjY54xyXO1p8UsUT6RNv97ocETVpfv7ATrgqN7bwPNiQoWWKJud ydvUZg6Ih1Ds96TK1yEJ3G0tCn/mUq5eMgagLGern/KiMrLNFyhbZTtNglbO2F5akY0w 1muJckUb2D0qTTY6W3uy9EJJi47i+fhUDTnVvHyNtWV+uZ6wTMfQ0UE+rjYoktuXF4nm TH6CtHzRh9eAJD3PVAemvNL8cfppSrw4+e2V5+pJ2p/Mw2ollvFEJ895iRDhKHcXttoJ O21Q== 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=wWFC9TurdDn/7osXd//evfrghlK0nPLXsFUJmVdsgMg=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=nFeKbKkYNv0MdZfWCqJ/v7JGNimvuetlZbQf+avlWhr+x2a1uX31CV93gL8uNe6qNI QJtPUQ8ODVpm4aA58cx0mOhppP2EVy460a0+xceL6xFvvooKVkNPovmRUfIi+ZSCEKno Jsd2oRzdr09UNgHdPhcbBVtBmv4DNQEjAIaBugpqMC0w7x0GUpm7sEbMdr6qWXan2sJL FHSKS0vVLAeF/0yI+4etWIELixUAkvJvDSHF1KSfIlydFzKVGFJH/okQfgUa/1wbvvTv l7/iJeMZKh0YZneneNQO/u8IX1LZCnpYdP3YMBW98AsiHvSfaFb4pw5Dmv93GtFp+/Qb LiWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lIvOZoyL; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71191-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71191-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. [147.75.199.223]) by mx.google.com with ESMTPS id gu11-20020a056214260b00b0068f359a8975si6359586qvb.59.2024.02.19.05.50.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:50:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71191-ouuuleilei=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=lIvOZoyL; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71191-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71191-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 D7FCF1C22A13 for ; Mon, 19 Feb 2024 11:23:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DAE62E83C; Mon, 19 Feb 2024 11:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lIvOZoyL" 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 D8C6B2C1A6 for ; Mon, 19 Feb 2024 11:22:06 +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=1708341728; cv=none; b=sJO1mo/I7/Tf7AXwKCEB0boq3/TgrMtBT3X+LDTvNa71IwSeAy+NzDfoA/nvK3KgFr/M/r1FHy+ZBd/osaH0kEiYu0qnl8JR27peZKtfNMi3kggdqs6rdD4nnD8e4CNo2uXDcJgslRYyD/kSbF+SmcNszjcVPdf+xJJ68tmjlJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341728; c=relaxed/simple; bh=7Xq0FoTONpxLm9RWoF+B7SARgkpsA7bimB+gDd+Xbq0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RYydErpbGEsjh4SvceS/A/8EOGf2EEptQeoRPjY4lruZmHJUguCpbvqVHmj3H9KJgLZdP2LuNfaZ/ZkM4Od4/IdRNlK1BjXMJLNBsBi/Yge0AgnDEEdqtDyirqLvkWPNfBsQHfJXaywjbzS6Uu7IwNyOXB5TdhdjPT2W38lQb7w= 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=lIvOZoyL; 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=1708341727; x=1739877727; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7Xq0FoTONpxLm9RWoF+B7SARgkpsA7bimB+gDd+Xbq0=; b=lIvOZoyL6ChB/TMoFlm5bqWyYSueZV1nP5HtHs4AI4pc0VnpsiaHUtor mmXkG41A3j9BJjrcttTbwy9mD0YoUDg5oHVYJuUbeVh/06wIGw10ZkmTP x53CONktxkaWxfgkr1B7ApM5Z9ZBNyKjGz3dpUyJ3ZdUU3TDgJwFCnUHz sj9WNHG5J5w6q0G3iX7sslFfMpBzr7FZhIlyh5Y/05BZ0crksd5vQD6xD yzJ2wIacrqea5w3AmhvCoDo7nSR97kc9UCz0Wi6yO5lLvW65AsGyKyj4f rvmNGatCGXM6+NZKNfMtWH2q0oo9J/NIOuuT0F5jXLVPXNfcTiNH8V49s w==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823381" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823381" 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:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826846" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:22:04 -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 06/10] iommu/vt-d: Remove domain parameter for intel_pasid_setup_dirty_tracking() Date: Mon, 19 Feb 2024 19:15:57 +0800 Message-Id: <20240219111601.96405-7-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: 1791335461437475993 X-GMAIL-MSGID: 1791335461437475993 From: Yi Liu The only usage of input @domain is to get the domain id (DID) to flush cache after setting dirty tracking. However, DID can be obtained from the pasid entry. So no need to pass in domain. This can make this helper cleaner when adding the missing dirty tracking for the parent domain, which needs to use the DID of nested domain. Signed-off-by: Yi Liu Reviewed-by: Joao Martins Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20240208082307.15759-7-yi.l.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/pasid.h | 1 - drivers/iommu/intel/iommu.c | 7 +++---- drivers/iommu/intel/pasid.c | 3 +-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h index 8d40d4c66e31..487ede039bdd 100644 --- a/drivers/iommu/intel/pasid.h +++ b/drivers/iommu/intel/pasid.h @@ -307,7 +307,6 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, struct dmar_domain *domain, struct device *dev, u32 pasid); int intel_pasid_setup_dirty_tracking(struct intel_iommu *iommu, - struct dmar_domain *domain, struct device *dev, u32 pasid, bool enabled); int intel_pasid_setup_pass_through(struct intel_iommu *iommu, diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 2eee83b5441b..d286b8554227 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4741,8 +4741,7 @@ static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain, goto out_unlock; list_for_each_entry(info, &dmar_domain->devices, link) { - ret = intel_pasid_setup_dirty_tracking(info->iommu, - info->domain, info->dev, + ret = intel_pasid_setup_dirty_tracking(info->iommu, info->dev, IOMMU_NO_PASID, enable); if (ret) goto err_unwind; @@ -4756,8 +4755,8 @@ static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain, err_unwind: list_for_each_entry(info, &dmar_domain->devices, link) - intel_pasid_setup_dirty_tracking(info->iommu, dmar_domain, - info->dev, IOMMU_NO_PASID, + intel_pasid_setup_dirty_tracking(info->iommu, info->dev, + IOMMU_NO_PASID, dmar_domain->dirty_tracking); spin_unlock(&dmar_domain->lock); return ret; diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 3239cefa4c33..a32d7e509842 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -428,7 +428,6 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, * Set up dirty tracking on a second only or nested translation type. */ int intel_pasid_setup_dirty_tracking(struct intel_iommu *iommu, - struct dmar_domain *domain, struct device *dev, u32 pasid, bool enabled) { @@ -445,7 +444,7 @@ int intel_pasid_setup_dirty_tracking(struct intel_iommu *iommu, return -ENODEV; } - did = domain_id_iommu(domain, iommu); + did = pasid_get_domain_id(pte); pgtt = pasid_pte_get_pgtt(pte); if (pgtt != PASID_ENTRY_PGTT_SL_ONLY && pgtt != PASID_ENTRY_PGTT_NESTED) { 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; } 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); From patchwork Mon Feb 19 11:16:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1337878dyc; Mon, 19 Feb 2024 07:01:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW/nzmUyfRVtKAtfQY7sJzSMB2xIUgeGq6tJCivI4ZtYP8B2HSQbw1MOL7rEYdsrvbrGxQrCFjNm7LK6S+jHQrcPXEIAw== X-Google-Smtp-Source: AGHT+IHrjslxlf+LHL0ir/CtSSZlPStdrNgnpJ4tqVBmVXmd2eFrNKHPNJiCadC0lximZw+2UvnI X-Received: by 2002:a17:906:7d48:b0:a3e:39a7:b1e7 with SMTP id l8-20020a1709067d4800b00a3e39a7b1e7mr3643964ejp.10.1708354919288; Mon, 19 Feb 2024 07:01:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708354919; cv=pass; d=google.com; s=arc-20160816; b=iCxLEnw10Ay40/+Dk0S2HBGXCoZHCgfWv5ubfLiQoUCmkHmSmDhO9Fj7cWmePZEfae aivASc/N/N7eQRCUuoHuIB8QJ2fSxPUvt8GvQDZqXDPynQkRtJP9humMef4JAjpKqz51 IGUHHnBReJQojdQ+mASkoQBeOMoo49sAbcpqoUWvGMNMdePHX4sxiSutLd9NhMQJedJQ 9fFkEC+djI7y2I9tvZaiJWhB9Ge56Ggwfm9fAZnOUPQKWBa/FTroC+RwF7KIIrnWb+mR HpdiJUx0WmrTwtzXiYD7fCsB/zaq1NnjoLUckuLhXlpt8YKv5mgOdm72dN0wUCihXDkG CVqQ== 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=e/MZKjCq3h6+VDQ8o1GpLcuIiGyRUvcuUDITCRMc6n8=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=W8xwxLf1dlR3bpNfbGbpisxGaFJ4xf+vNgb3qMF1xOEp6sNl/A3Dl8m1Zb5ibR15Ws GuI+xgS4NszhcANy9TCQNtQ4B3L0GheWK+yzq9ugJhD09VnsBlBYXIoAHdrtCH3ePJn6 uYo9gMxK4CwglqS2DQVLrDLtczWvrD2sIJrZO38qPL1Nsm58B/sR1utYPTxRUUI1CsvA I3s7DcyHbq2WLxI2fxedDx6Hcbrm7Hm66E15qOsHzGq17fsZ8Dt2VOGGK8ehHp4zCqjU aGGYhy/6AhxMXvHzv8Fb1i81+SpSYQB/bCNYJb+LIi3s4/WdwAMrgqX43uHQRZXghBQj 3JLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EBdJxPIP; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71194-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71194-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 o2-20020a1709061b0200b00a3e848b80a5si1017622ejg.1055.2024.02.19.07.01.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 07:01:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71194-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=EBdJxPIP; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71194-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71194-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 125551F23EC1 for ; Mon, 19 Feb 2024 11:24:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2FB8D33CC9; Mon, 19 Feb 2024 11:22:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EBdJxPIP" 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 1A5C52E84D for ; Mon, 19 Feb 2024 11:22:13 +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=1708341734; cv=none; b=eRdyQLl1c8MqC1TNLs6eLQTxolCeAG6fUQpZLp0GgWbYUAO7XEUxC2b94om8j1UArCOKnQ7B4K/FBIplV3UOa2/f6XSrEJLbr6VCA9wwNk6yNvIXVlJypwfwFRsKjuRRksVJIXwr0QFRMBXnXbiz6QavRD3Gw7mdyWUrrAQZQ6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341734; c=relaxed/simple; bh=SU6KvDmjdOLfKEuiZcMfCTvca3+Q7A/X/vy1dY8kqnw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LcaJe2B+PLJKBufBwb9jOcCuUN7CEf1rgDDeP5UqLSgI2ALRQKi6FyjRt67OoNKvUThCLS9U2xz/t85fTSliCvB0yx4RDb4Zhr+meopjHc6B4JuSjXLR0CUaINOLaaV8OSNe/xcEHW6vyowQ58+fcta77w+dKBAPUqn36JG3CQo= 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=EBdJxPIP; 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=1708341734; x=1739877734; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SU6KvDmjdOLfKEuiZcMfCTvca3+Q7A/X/vy1dY8kqnw=; b=EBdJxPIPo4sTDzacUdw5qr/UfWMp8L2qPPd9XtT08rek0PjqODxZzYL3 7/vLaUPkWXkgRbECXrUSn1Szlvr6yfQ1fh+THVGNFPF2oolA/sJTc/jw3 hvik2zTyU6v5OdHi9yVSGsoOLu53d5j2WIqVmfdKPW6dqKS58LaL+wVa0 VIZJ7MvCzs1h/soVYw8ZcER1HmzBYYQcGzWAOwUE23mwEKLtGe1gAl0Ff 0Z3oge1y3dDjSygKdPkaAaiiwe5cFUEdK6JVcoiuJCc4oKoa4C54CMkgM RLD4gTqegpMaAJJaZKTWC73lEV9PTkFPSj6ZHVF4stAhYoYRBfPfv9ZW0 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823406" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823406" 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:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826883" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:22:11 -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 09/10] iommu/vt-d: Set SSADE when attaching to a parent with dirty tracking Date: Mon, 19 Feb 2024 19:16:00 +0800 Message-Id: <20240219111601.96405-10-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: 1791339967577889321 X-GMAIL-MSGID: 1791339967577889321 From: Yi Liu Should set the SSADE (Second Stage Access/Dirty bit Enable) bit of the pasid entry when attaching a device to a nested domain if its parent has already enabled dirty tracking. Fixes: 111bf85c68f6 ("iommu/vt-d: Add helper to setup pasid nested translation") Signed-off-by: Yi Liu Reviewed-by: Joao Martins Link: https://lore.kernel.org/r/20240208091414.28133-1-yi.l.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/pasid.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index a32d7e509842..108158e2b907 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -657,6 +657,8 @@ int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev, pasid_set_domain_id(pte, did); pasid_set_address_width(pte, s2_domain->agaw); pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); + if (s2_domain->dirty_tracking) + pasid_set_ssade(pte); pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED); pasid_set_present(pte); spin_unlock(&iommu->lock); From patchwork Mon Feb 19 11:16:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 203140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1337940dyc; Mon, 19 Feb 2024 07:02:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVxJwTodEDYyC3zYllSRxeWrj0tzP208u1eIybGroNVb80MLpi3kPD1aFqaPzdVAaK3eTyzHNV9kYa8Op4gxWu/NzNEQg== X-Google-Smtp-Source: AGHT+IEkOTSSLa1Ab1vBBdQfjzU+aeHKeuxIIEfel+5GyT+BmQOFv/Y3lI44ypheKv+YwhEtxSTc X-Received: by 2002:a17:906:abc9:b0:a3c:a770:748 with SMTP id kq9-20020a170906abc900b00a3ca7700748mr9690984ejb.58.1708354923851; Mon, 19 Feb 2024 07:02:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708354923; cv=pass; d=google.com; s=arc-20160816; b=rOrhGFyR46Nca9X8vp2pOMhXYvgzdwaGIFRHeAF2tUFxvzu18Gq/5XaIAQ+TA1M6QN 8Mkr9CM+A4kqRz5nQqtEWbBqRGARbI7eFE0z9RPLymC4pjq7KIpYFVnlpF1tj2Pie83Y I6rKaK/KaqHbeGYEH59OJamxjoPju1g1iMIgu4it3OiLuyDGIdY4F4m2ceBaQ5txc/Zg UZgE6RhW644LQu3cyJWqtd+OTF0Da1yexXTZ50s1CwsphJ0TEHBuPYherEPe0uLCCNPI bQoymlMdlMWomf83xayBpe12U2ouENduNJ9IF/eGOkXjdM758tKanfwm2ZoPB0nOSX3H jzxg== 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=w8M34L7wyti/wp5kMtwa9WC/3cabRsJvt4mcFv4VoiA=; fh=xIXrYyuim0+qQ0OPX7PXG3ceqpJb0Om6wEk3bRGARVs=; b=SF4VIZDmbLVVZd6ILL9U2PR+1kH+mh2rrc9BojM4ck9rY2T/Lw7ctj5nbNysnXwvrk 4gkSn48PHlR2ZIvTHgSJltaUqPvwSUWUyE0HBxXdsicPb/1YEyES8Ttocse796KPJXdk MHAvA7/m//n+Z0AF/g4FxzNTcEOm6oCaKiGOg0buDJMSdh6KdSjMTJyWCeYvi7xDR4YF NPpYAuz/he7sRprZGTzQd6gpb67rhBdHToUd3LapzUquoml7cCxNJw5gFj0v3cCHEIWP MONMyzXZHHJ5r6iKAgEhlxmrw7xvQ0jmjixxRMnA+SVx2NjLc2R+g4c7GUGDaSQ1vGmR pdtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q9rUbu3l; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71195-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71195-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. [147.75.80.249]) by mx.google.com with ESMTPS id hr12-20020a1709073f8c00b00a3e9fec0241si836359ejc.848.2024.02.19.07.02.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 07:02:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71195-ouuuleilei=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=Q9rUbu3l; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-71195-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71195-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 3CB591F23FAB for ; Mon, 19 Feb 2024 11:24:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6661633CC7; Mon, 19 Feb 2024 11:22:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Q9rUbu3l" 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 6BEFB3306B for ; Mon, 19 Feb 2024 11:22:15 +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=1708341736; cv=none; b=qtVIT0LTQB9WHd0k2e5S7LUGluQK/DmKr7X3XzfGFfuhoe9OyBmbrYhU8uBJeUr5Y+TnO9C0zyaohq0DcAryKOlYsu3xWS9Hzkv4TJslVKJ/1Cjrj+CNa0G3+ytcQOBTSfV1HQz1Nh1VX4aoOdpRyXDJ9CA4qT+9CjhsWH/QZzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708341736; c=relaxed/simple; bh=fCI8ry2QwMgfpyT/VHftog8+K3+UurzhRMpjSws+ROQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oAgKo7yPd9pmWqs8kPY/V5/hm2AyB3x9hN/2zqpqb+tgrGwYA38fkzaZyvp+5GPnmOtBRVmqnzB+oMKmFeH0jJ7GNjbTxDaltp2pV3PVf53cp7pU7m3x4jyL7cV9cqb+VqmLt5kCMR7MWN9DcB4deqnpIJUAGln6FPzu5kemoZQ= 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=Q9rUbu3l; 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=1708341736; x=1739877736; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fCI8ry2QwMgfpyT/VHftog8+K3+UurzhRMpjSws+ROQ=; b=Q9rUbu3lKPUu0eElfh1wn1CmDlNipsWIkyeJe8yH204Y6lcOZbcR8Bn9 wS3SbaZ5/JkuZEeyUkaBHiRtUzStRuEEhoZw90O2+/T1WtBY8oISp9Y3F Ky68iGUfEUaJnPCAmVnTi3v0Xi81xC4PS7N0q0s7Joef+0FndxVFAEcf/ Y/OqJJCDTuoNuHskNHkN7JAmODSffOqNLB8c6O8mxCaj8u5OQrOYOTT2I Ac/rAulWhgNIo4pM4u2Z7mMdwjQv2csDPbxBpj6g4OSbRD//r8/7EvA8o f01UnuzGSlXimKTI+nfpi7y3nbiIxbFofERcF2M1KjEEMhksuQdWnp8J9 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="13823413" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="13823413" 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:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="4826892" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa006.jf.intel.com with ESMTP; 19 Feb 2024 03:22:13 -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 10/10] iommu/vt-d: Fix constant-out-of-range warning Date: Mon, 19 Feb 2024 19:16:01 +0800 Message-Id: <20240219111601.96405-11-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: 1791339972391832148 X-GMAIL-MSGID: 1791339972391832148 From: Arnd Bergmann On 32-bit builds, the vt-d driver causes a warning with clang: drivers/iommu/intel/nested.c:112:13: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned long' is always false [-Werror,-Wtautological-constant-out-of-range-compare] 112 | if (npages == U64_MAX) | ~~~~~~ ^ ~~~~~~~ Make the variable a 64-bit type, which matches both the caller and the use anyway. Fixes: f6f3721244a8 ("iommu/vt-d: Add iotlb flush for nested domain") Signed-off-by: Arnd Bergmann Link: https://lore.kernel.org/r/20240213095832.455245-1-arnd@kernel.org Signed-off-by: Lu Baolu --- drivers/iommu/intel/nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index d5af5925a31c..a7d68f3d518a 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -103,7 +103,7 @@ static void nested_flush_dev_iotlb(struct dmar_domain *domain, u64 addr, } static void intel_nested_flush_cache(struct dmar_domain *domain, u64 addr, - unsigned long npages, bool ih) + u64 npages, bool ih) { struct iommu_domain_info *info; unsigned int mask;