From patchwork Thu Feb 8 08:23:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 198205 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp24609dyd; Thu, 8 Feb 2024 00:35:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWO3YCtzTsco0tS/n0dtwHa86DWcSV1bI1a1lYkszKKpDc9Qx+aZZcCG/Zogt85hM/u5FYsKnBug7yZhXn+cX8QWdljaw== X-Google-Smtp-Source: AGHT+IECtupEPGRpk+2MLIo6P5Da7SDLuQA2hbnSE0m5TZa7kzwZoZ8sHCgaOSVL1CZAI43rk20W X-Received: by 2002:a05:6a21:3d88:b0:19c:6f20:599 with SMTP id bj8-20020a056a213d8800b0019c6f200599mr7528690pzc.26.1707381320758; Thu, 08 Feb 2024 00:35:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707381320; cv=pass; d=google.com; s=arc-20160816; b=yUu+3r5VWsiqfa5Mnfa2gHgKkAtzvT3Sml/8Y0HVyy5Pt78XjOPdDnquWUizY8s1K5 zB0ovAQSDcb95CmUUZOc3ElGh/n36bi2moVtTGHEsa0JDfs0J87wPoFvXJf1RHIQTL6a T0MrrSGN4GAAEaO8MbQiwBGxBdV7p4nmEDbJe5GrbaBjkfW5cxf/w/Ig3XAfGe9TSh8g 6uvtMbCAtbWdotnNs707Ke/k378R4qYcACcqEDk/zfLRrIhETnn7RtEdIh2IaIWmSTHL rdxr5V1cDIkr65nQecUZSmoHRbLF9HLpPQ212RZdmXslgDN7ctBfO6DW2in0OtyBt+4J 4dtw== 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=hEB1CXROg93Lt3NNA5HTA5yY8ekY1dwbxNXlaCIMRsI=; fh=Am9LoEjxl6cwcp1TZaHvNW4XNuu0sIei1D0nUGc5nCY=; b=AMSZlNkFov9Y3EG5Q2WiZJJqvSveICSwyDjkfskOMmlfnVNhw208SULRGytSbhb4MC 8rLEj4BroKy5wQUmg/dOYuG9IYnc6cMD29q5GORUY/3+x3glvA1yuQFXoggi82qh+uI1 hGWciA7t2OwAU1KFBT7+6BZhAFWNEEzmnswTRlKPqncyVicqC4sebOovWqPzurOGDo/S KdNymYgOqqbSVqvpGulXQYQRV4zYoE4GQGvmba/PlsnTt3U31qqcUYcb/FnQEDOI/btS YPj3x0BT8lZWD8NIdKSsMUEaq1v7hWI4ZfsvWef8nJn3780I6UfkBNNCDgDgA74+iiXp ORRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=czmkOdku; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57605-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57605-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCUWCpilvR1VujhRcfDiG7hWPiGgZaCRROMdAZesDYZtLdr7+6qReuv+yH3IKh6Y/AoUebzBOwmLwsiNxOXCs+Eow9IuRg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o22-20020a637e56000000b005897813624fsi3316284pgn.476.2024.02.08.00.35.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:35:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57605-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=czmkOdku; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57605-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57605-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BA394288C6B for ; Thu, 8 Feb 2024 08:24:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 263E26BFD4; Thu, 8 Feb 2024 08:23:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="czmkOdku" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D24536A329; Thu, 8 Feb 2024 08:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380593; cv=none; b=t78vCwJRujQK0ncVkreRYH79zZhg1MiJiCOaZbAXzL3/RSxpBkv1qgNRxB3BU2f+Eh4K3GH+hbhRTMOsh9P0k3rxnoE3UsQcdUpKPUiirkYjoKzJIJ3/mIXcYNqwcIlAuCMTuiXO86V/ueEt7rcAoxfOqKC7ZOdbE8REyTZTejs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380593; c=relaxed/simple; bh=/GnRCRW90B1W9TXPxSmAiTyrVQIgkymW5d5jQqKtU2w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HRx2Y4TbT8jB79v3oAGqg4Ch19yy2V4X8uXAhYw841vajyGNyIPyQcLIifZUrh/u6mDhXSZS/uIoUj24UelqHwwKvO+MClJethb2ZdLFZPLUBBr/LIVzMqr41SMK2Kid5xDHaXpHNjdPjtX4ClaodAOaaBoVCtzhf3+hZVd8Zbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=czmkOdku; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707380593; x=1738916593; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/GnRCRW90B1W9TXPxSmAiTyrVQIgkymW5d5jQqKtU2w=; b=czmkOdku5B648SBN8BjBHOuxZhgu1ZiA1HUu/x8u9y/s/N+zTb3PxDrN pQUcxuPzBHy36k2Ptd4Jgm0YQs4QzxIVoXmauGv/fHGWsO4MgzJVVi8+Z VrpEzfC3POufnPRZ2tOLU91jWZNViBzi12i+NE6oQGHTEMOVZpqIzOAlK Y6pujMSOq2i523/u93Dx6JUnlo7mUjxJPW+UiTltAC5N9ILp3P48bl3it HsqVvgpdfk8JyLfP3IC6+hBts37wuVcZr6R1SpLpsdXtl1ajOUk9z5de/ L9Drd+TgQKwW8VbiaQounN1BQFAiUJpslnb06/I0VLD71zyOtC9Oei9LN g==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="5036302" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="5036302" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 00:23:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="6252090" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa003.jf.intel.com with ESMTP; 08 Feb 2024 00:23:10 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH rc 1/8] iommu/vt-d: Track nested domains in parent Date: Thu, 8 Feb 2024 00:23:00 -0800 Message-Id: <20240208082307.15759-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208082307.15759-1-yi.l.liu@intel.com> References: <20240208082307.15759-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790318856205575807 X-GMAIL-MSGID: 1790319075835758477 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 --- drivers/iommu/intel/iommu.c | 18 ++++++++++++++---- drivers/iommu/intel/iommu.h | 6 ++++++ drivers/iommu/intel/nested.c | 10 ++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) 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/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/nested.c b/drivers/iommu/intel/nested.c index f26c7f1c46cc..42d4d222e70f 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -70,6 +70,12 @@ static int intel_nested_attach_dev(struct iommu_domain *domain, static void intel_nested_domain_free(struct iommu_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(to_dmar_domain(domain)); } @@ -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 Thu Feb 8 08:23:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 198197 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp20902dyd; Thu, 8 Feb 2024 00:25:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFg/dT5Iv6lMyQDA/BDZMHtllc+fuzkXw13mvqqg356wFVGKnF5hIxeqkopekPr8KcuMMY7 X-Received: by 2002:a05:620a:4d3:b0:785:60d6:36f7 with SMTP id 19-20020a05620a04d300b0078560d636f7mr8430617qks.69.1707380701133; Thu, 08 Feb 2024 00:25:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707380701; cv=pass; d=google.com; s=arc-20160816; b=XFcZZe8ugPjpgKLyhK4HQpDl1miLwu6mWIVza5l2BCfsNbZgcBQQrbIoAcSYiXmof3 WQxo8Og72+yU3G3kC7jxehvHKIdUodltoUR4M22Uhg2KeyFD5oC1tFEDrcwT0pW0s2+F DzBPAwo4QHIR+4/KcSuYFcoPD+3Pvx9TXXgRa9Iap3yHRbWUgnbQ9S1h/z/3xw2v2dYs 5YUDif4dOCuPKOQ9+oR8u+MZZu1zsBDuMGDXw2/Jt/ftOnAK+0NwKJWFvypAfG99BYp8 wcbVybmUrvbfz5O9HzsbxY8kG/HoP3OznPTgeKgc48/qbO3ZxeNtW8AqZJqGsvl/kpjG 0siw== 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=6/LgyhAnm/AlEvoUCvBe12XiB0hNFdsiQwexWD2KdEs=; fh=hiEZnwfx7vxWJgL7k1+Ngd60SNEz/U6PtwNBJLokJ/A=; b=A5QNmC9cT3j/hpuT2t3AHiLF68uGlJBo546zZdOv4MXWTNudIznPlYVdiPpdGiH332 812S8ioB6RspuaszTPLOKYrBhLPlH+7B/MSA9CGkUSVzTVEvVjmFYNZGalicT68u5mbw bSh9HMDZdtVInx66pegr9iXSbJiG/2nRaoQyE64aYUDhUvewuRCJPeLxlf2Xif9a0cjW A5UXqH3KQzdeswUoJyB0se7MTljE5plM2Yl7+Z7+WKr8HFtFapLmdJN8OSHqDp6XFRYi 5siu9GVyWxt4L9HLJOf6ZXfRNvDWgKdkl4zatm/RtcDJR3tUwiOGBgItg/uaxkm/RN3N 4HLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q8tpHErF; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57606-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57606-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVVR4CJiJYpeF1pkbwmSHeJ1saOzq2GxdMsGZifJKWFTD6V6drQR3H/e+s2jhDkKrU8PYdfn6KEJZ0uXRg78CIrUNmHAg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d19-20020a05620a241300b00785a3e5283fsi1500420qkn.225.2024.02.08.00.25.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:25:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57606-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=Q8tpHErF; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57606-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57606-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 E76AB1C25B14 for ; Thu, 8 Feb 2024 08:25:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 89EAD6D1B8; Thu, 8 Feb 2024 08:23:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Q8tpHErF" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 598956A331; Thu, 8 Feb 2024 08:23:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380594; cv=none; b=BJKfRkuUMd0km4SbYYJpTJn909q35QzJ99OaMGgLDOIffnN8Goa5Pp8TgNWG7zbIlTOrYyHX65Km08z+AP5eOlEeOQT5e1oMEuaHTIwo7ynOTNwOjGsGTpwlm76hVXdPVYeKimnFPrdGPeZwPDT8pUvGJ8deIraNKK+HrqFWUVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380594; c=relaxed/simple; bh=6WL8z2aMLDo6O3Bz7gM5e9uPczPryXbWDTbbIrVy8k8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L5VSc7Kd8p9EIrHJqkWRQrL90nXOoDu8eefuhIQLi/cjyc82obJsrO8mjCsnkVcwj1AzsMbvL+myXCfdDuPu6BBuLAHaqUjjCDoEdBQekapmjBlZ+9qyLczGNuRCvHeV6ndGOyLAURlwjJndKsiuRX3LMA92rSR1Lqkx9gas+2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Q8tpHErF; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707380593; x=1738916593; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6WL8z2aMLDo6O3Bz7gM5e9uPczPryXbWDTbbIrVy8k8=; b=Q8tpHErFodD8JZMW6uM6wIveJD9cvhJNGXn/E1xOy/IAYd2Uwgu4WVRl DrFZDDHOb5TKjzcjNHRupQ8tS2Ka+butHNCEwfZu/Xk3FjI1R0iZ+mZ7h 4Ugzw3d95EophpDnXjLhu6edGgfLfhhRUHN//YO9Y1/W/cI/Pq72my6Qw /OghZ+/TJlJvPzwFQ93ShU9dLSropVv9xprixjeE/hdhsKJhH4TGDBC5z 2noIkNIHdvUciMkOqRojjeCP76D2Aa2jWmrcmFiK3o3InOSbdBtpvDbfh LhbJvgvtsZkquIQhH2bJTZH1M2+4ThhnOnWarokefyMXafs0keF+iO6VX w==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="5036309" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="5036309" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 00:23:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="6252102" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa003.jf.intel.com with ESMTP; 08 Feb 2024 00:23:11 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH rc 2/8] iommu/vt-d: Add __iommu_flush_iotlb_psi() Date: Thu, 8 Feb 2024 00:23:01 -0800 Message-Id: <20240208082307.15759-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208082307.15759-1-yi.l.liu@intel.com> References: <20240208082307.15759-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790318425767086735 X-GMAIL-MSGID: 1790318425767086735 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 --- drivers/iommu/intel/iommu.c | 79 +++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index e393c62776f3..eef6a187b651 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1368,6 +1368,47 @@ 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 int mask = ilog2(aligned_pages); + uint64_t addr = (uint64_t)pfn << VTD_PAGE_SHIFT; + 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); +} + static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, struct dmar_domain *domain, unsigned long pfn, unsigned int pages, @@ -1384,42 +1425,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 Thu Feb 8 08:23:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 198203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp22060dyd; Thu, 8 Feb 2024 00:28:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXljzwv8IOJJA5zVEsdeZa69x2/vNs28p+yYbJF4LV4DHc6WAcIG0YDMJF08/LfuA3lMcklqvEfq68Dxmcu1MoBqiswlg== X-Google-Smtp-Source: AGHT+IGdhpqaP6QbD6wpj+FxWWrHWvMaqVF+mqqaW9R7vE1jKMmEP1j0Hhpw2t2Pbjr9VUAIvT5s X-Received: by 2002:a05:6870:be8c:b0:218:9e23:6826 with SMTP id nx12-20020a056870be8c00b002189e236826mr10783960oab.3.1707380909791; Thu, 08 Feb 2024 00:28:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707380909; cv=pass; d=google.com; s=arc-20160816; b=JPCnwLE9dKM+me92JyBP4l3NSGD91+C2fZ94a25DdwDkEVYVYRM8ttH5dtapolTJvD gLkLQfq+A4dvoSeScz/uE/mxLWf3TVdUy2saC/aEHEYKEqtvckh+rW+XaSDJTWr1OXZA hQLgG+g1TuXCgeIX+cWZsrpB3kQVHRGn1+LmFNfJHTZI5BT8lqx20tZwNuUBp/Tn0qp2 RJIv28Kvncl7nilI85SkYFGEFKT3A+1PSdDV4Q6Lrge1hW9q+zDA7M6U/hgGdsVHqo1w +t1u9DEumPJ5S2O1NUIqmlurLXWCjKJdgiMroMo6j1H5oSowHANK5uJLxMUDuqS+LAky UFHQ== 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=ni76zA2Ft+Pri4MG8zT5PHduJlj2MCoAAvDoTxR1IX0=; fh=6S30KlT0SH32Pn7OMqG15u5Tz8XJIjMfDz1DMnKLS+k=; b=YTaKQvjhKTIqEoYGseCxyPmdRqSK3pBAqg74LcVJQDSvcsDvcK03ouYQezoDcpap/F Vb+UbZ/tL6bh/Z2Vtp6iKOd0u8eFlDtpxTZ6vIO3R6+C35pSN24dDyAXNL4XNTsQ0E+B isHIvtTnh/Mq02AnnGPTXzpGLWbvxanlTmogEVNPXa9qQFasYkr3AemxYHthlo6nANsn ui5yW+4xCe8F0AmzeDFiNUSetTvgl80rGZbZ+Uej2T8RIlANx88BovtYqNuaGBt+GlVy p1PvzRU6aaljL1bUhH3lDfKoo12Ot4Lgszk0DQZDr8gzqRStfv0jagT6pJfQGfI3ytNj nZsg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KafITziR; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57607-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57607-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCUEeMBbGaGMNak4yCu/D18r+HRheGGYVufQfKLZY+iZdvvd4m+n40XdNKr/ylaxzzbeuUtmsGhQh3YrkJ40UkKzRrVlWQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p25-20020a639519000000b005dc1c316cf5si321665pgd.357.2024.02.08.00.28.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:28:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57607-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KafITziR; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57607-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57607-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 B5BD9B248D2 for ; Thu, 8 Feb 2024 08:25:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C9CB6DCFD; Thu, 8 Feb 2024 08:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KafITziR" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D5C36A348; Thu, 8 Feb 2024 08:23:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380595; cv=none; b=LKroM8zLWYPamuuPb34BC25eDnjc1K1dyIcceBcvq40WvjKm1eegKMALZdNST4U6aOSGyG7iBN70HHaMCuiJyv/YWXwmeR/L22mwsPoxFpSXzVZc+YLzYVcoiWnNm/jVeUpoK3TEBZs21xoIpeOyl1VaKZBzYFySCcf+zmdKT5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380595; c=relaxed/simple; bh=rkAIlr3b517pIibgb/ERZPXd9p33fw79H8+yLPYzn6Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LPTiUF10Xnf+zvdyVyhwtwAQdphtThq90e+inx+QP7E2N2b2ImjkwjP0S7vWojhIK5XKXsdNMsDENyn/rNcLlkuT2TBh1geinNTus/BJjM7Fpt0X5S5psOn6RGr7Sa4RlahJFrh6BvZh099rGgDO8QsrcufQP4idr2Mb68pM71s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KafITziR; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707380594; x=1738916594; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rkAIlr3b517pIibgb/ERZPXd9p33fw79H8+yLPYzn6Y=; b=KafITziRG6TwsCCYFb918pNXiwe4PbU7q8V/uSsZKUlEyTKwLpKn+fxH y4detufcB7WSEqmmERD6lycbwQj0V+VB58rtQMKBTa6k3FUsPjDuM/99C uaUiL3ADwAnyzyOUnrcokIKJYevOSeQIjq9hfwg6TSm0GyeRVzH+pB/rr z3aFybx91nwsYq28Okd7HHD4DNOpTmNz7kYxu2r/SYJhJQgZBrOhHTmRs 5TPEBqWxMTWolQI1rFWnEhTMi8B1X+izVkNaOVLCaftJXSPQmP1jLpkGJ pjztp/XGoWNoUrkD9kncXDZHfAZ06f49ER707SM3fHqCcO0jpwTGj2aKz g==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="5036318" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="5036318" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 00:23:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="6252111" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa003.jf.intel.com with ESMTP; 08 Feb 2024 00:23:12 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH rc 3/8] iommu/vt-d: Add missing iotlb flush for parent domain Date: Thu, 8 Feb 2024 00:23:02 -0800 Message-Id: <20240208082307.15759-4-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208082307.15759-1-yi.l.liu@intel.com> References: <20240208082307.15759-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790318644856969937 X-GMAIL-MSGID: 1790318644856969937 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 --- 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 eef6a187b651..46174ff5ae22 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1452,6 +1452,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); @@ -1471,6 +1493,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) @@ -1994,6 +2019,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++; @@ -4126,6 +4154,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 Thu Feb 8 08:23:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 198200 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp21214dyd; Thu, 8 Feb 2024 00:25:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZZaSBoZqPu7ZWcsQzjbbAaJBX63Xi85/k5259v7crLjpiOYqGwdTmMsUQKyY9ZLEMJx99 X-Received: by 2002:a05:620a:450e:b0:784:bc4:ff8f with SMTP id t14-20020a05620a450e00b007840bc4ff8fmr10631971qkp.56.1707380757425; Thu, 08 Feb 2024 00:25:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707380757; cv=pass; d=google.com; s=arc-20160816; b=v82D/0S4UsIjfkIiSod0le8mECVrZv8OLhcd0b4Qo/M6qRdHxm36JoMeUu5IMJD6Px vn+Uwgq8NLv8i9OufpJijDrDtta8veYuYvzhg8mf1c54v/KPaXb/60wSwqcoB2Ekw8EQ Q9tS//9XnEFVdIARK7XsOCAtQKWWxxi5rqeNDrolLirk5m4pwvOBndp3REjRqNv3Kc5S nPpb0VYw5gRHdoDMUc12YyrxmhS5/KNc7UHmB/DL4IInMC5ij1AjzszRRWMUg1tQYOKX ZqLmYpIKiIWzzsl8Fd718ISgcdu2ksM8ayQ6TVS/u2IQlk7modPsCsQJ6ewW2nT1tzHr oG2Q== 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=gkZScmukzMIIlZ8akkLfw2oxwV2MXTvC/ijpZdc/slU=; fh=ulASIXfObfiElgjSYTdp3b9cZLKU3DxxZmwJEYUYU7Y=; b=kL/S02/H5/Yhzf4vLppa4dhqHyqn32FSYIIjmzZ+rM58TcOO9yUvS9v0ddsXCN7KIO 5qEa8kgop8+1DfgUzUsZSKhWnRCgL2m3E9HxIK5QcHlwPZ9avU+FpHfUd6ifb284CYcP kXlADjH0jlYIQn5ai2FjOVRJq47jzDn53M7cy0dKN2Ju1LHoMJU9goXlpCcotLj2qWP8 yXzXt3XuMv4UpX0Qeh6+3llygEK/Ja86xDAhoXoLxV/1abI2hmibBkf5mnDfGr/hLbH4 vfo8NgFELyZ78HGkzNHPhO4wxoXkCroPNZGTCfmdHZbd+Eel0JMkah8bzh1qzVBo9+6G 7b4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iEoxwlqx; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57608-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57608-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWA1Tc41ruwy0jdg4T2ZemYk/pHqPxHJXREnU/FgXqxhrrM0yHE6oA0Vzj0Y2GxezzoPhds6R2rk+MUcyUb+IRa1iROmw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h12-20020a05620a13ec00b007833d053697si2752247qkl.658.2024.02.08.00.25.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:25:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57608-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=iEoxwlqx; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57608-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57608-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 F31201C214EE for ; Thu, 8 Feb 2024 08:25:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 374FA6EB44; Thu, 8 Feb 2024 08:23:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iEoxwlqx" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D357F6A35C; Thu, 8 Feb 2024 08:23:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380596; cv=none; b=JbcJEJYhZFNxA4hd/2OWs0oGYjBKCz0arwSuMcF8HtgD108RTrX4BawlGM1UZuab07xuua5bXhYJvjkajzmRmk9RQnLFgU5xd6o7oeWDFXghyD1yjcByD7p01KZ7e/sr1wwAZu4PUvJ73uNSun60W4CTjYyuju2pbE31fMti3zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380596; c=relaxed/simple; bh=WWbaez9ncxln4TMS8ZatinCzJo3/RSqN211StWyg4QA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q3FWOG1d7iy0XuJ6hWXIOB5ij6j4Tph02NsOWNXQTSvgVYWxDL2bIRRU3C0VSbICwXQvhgS3ofeJTdv1nPpfTFrI1oWXFKP9bWfDxiplr1S6fKwIF1Ah2V2aVevpiq78vp3fWKicsfoTMJ4eQ9YuhHFLtvaHdlT2BixRMGOhd58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iEoxwlqx; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707380594; x=1738916594; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WWbaez9ncxln4TMS8ZatinCzJo3/RSqN211StWyg4QA=; b=iEoxwlqxiq9sXumlxd80B1YfEd8WYzYJd6TOUgnRfiqpm6+kRDrz+u3i U6rFg1Tki/Srv3S/YlHMznA9nkb9QhLy1sRK24Fc57vfcKkYtOp4gwI2X UMolKbCBt7GkTUtWu9AoiN3DH+eRNGTLfCOOZJb6U6xNN0MaKVw1qclID enrLVWGLQfUHzncAD/gmfnnv839MhRqiUwGJ6evZJBhHQVfX//SVwxV1j gmCYDC30bcF4ZnkjI5xJJ0eC32vPMEdSGA9oZj/vXKF7/T3UJ6G0p9s8J 9DN8b7ar1Owwlab2IL9YyvFhOXSwMgUvWzMV9gpeeUiXhgKVSugsnIi4r A==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="5036327" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="5036327" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 00:23:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="6252118" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa003.jf.intel.com with ESMTP; 08 Feb 2024 00:23:13 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH rc 4/8] iommu/vt-d: Update iotlb in nested domain attach Date: Thu, 8 Feb 2024 00:23:03 -0800 Message-Id: <20240208082307.15759-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208082307.15759-1-yi.l.liu@intel.com> References: <20240208082307.15759-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790318484659723106 X-GMAIL-MSGID: 1790318484659723106 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 --- drivers/iommu/intel/iommu.c | 4 +--- drivers/iommu/intel/iommu.h | 1 + drivers/iommu/intel/nested.c | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 46174ff5ae22..b1ceebe13107 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/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/nested.c b/drivers/iommu/intel/nested.c index 42d4d222e70f..f068ecf72f5a 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 Thu Feb 8 08:23:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 198207 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp25229dyd; Thu, 8 Feb 2024 00:36:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGv9KiSbleW3tHt4xhNfGLs6+DmPR+iE1sYM7Z7PO6iFJjnh2I0da9RlUABkWZStOz+j6Kl X-Received: by 2002:a05:6a21:a59b:b0:19c:9f98:f7e2 with SMTP id gd27-20020a056a21a59b00b0019c9f98f7e2mr8018019pzc.13.1707381409231; Thu, 08 Feb 2024 00:36:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707381409; cv=pass; d=google.com; s=arc-20160816; b=yfqocX8zd8gNr0aSIvRJvNpvlGpB7ZRrDysOsc6rGFv4cCJEah99zptGtw9zAEbQsM 5GwC3rUHTrCDn4toyyWTEWNArCDD1wJBEoUhGbTcr0/LcDtsM0ctBFI4QH6KMlG3HogK XQ3zg9MmXBThSK8MZ8E2pcU6QJYCxTH5IpZH9j8IikSldARzh0gDz2zfSrX65dzo2d+E d4vpznFdbhRnzLEzvX7eUBNNoiFoU72tcXWA4McsOISyL/Q2BgtdAPafUO36GtI4VEma ojdVGMy5HSebCRczPMIaZWrvF+FBv3HBc5OunzsbogNbpYlj761XxPifZZ+LryymqUod 10lA== 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=GihjeUGVY9GT/hVBh4LI9ls36jkW26pZyqdnDgD/3J4=; fh=877E4I6q4kDNC/bQWjqgw61MbriAZLCSijro2t12hXU=; b=yRsM2yxdfAjGO8q6QdBXVxO0SJUtPGEw/lPxw17ZmBIYC2m5XDLgvxPnEK2dDgl0gR b1sIx1pK1iPRfif2Txd4zRCxqV1fd97KAea4O4pHyACSYZ6QJ8KdyJekPK8IrImjL4Se JbeGM6OWAN7KbIm/kD2Pl1oALBxGDBzTbQLZkTUv2M7lj0CQe+7kDc3cieU2TKKJW+TM rrxDn7lVFE9vzy+WJsy/puC9BjajXaOpGIXPIOSz5+cAZYJMulqsDZERxLPWiByRBH2T EWO743MntJThq/fm4xqTE0JRRfuBfpjhBpI1YIJdqkAh6cHi0Kr1trOo6tF5mMjY+cLq Aezg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qxj4rkkL; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57609-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57609-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVUigWUtUfEDEtp0vKsd6kvFdq/DkSQYi+rud7tH5sinptnpgDsdcoowuvf9cNRjQ6HOsF4l/guvAu71KRV4lSJNnaPOw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z3-20020a63ac43000000b005ce087e004esi3480848pgn.785.2024.02.08.00.36.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:36:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57609-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qxj4rkkL; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57609-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57609-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 17BE628A123 for ; Thu, 8 Feb 2024 08:25:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47AC76EB4B; Thu, 8 Feb 2024 08:23:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Qxj4rkkL" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B0156A8B2; Thu, 8 Feb 2024 08:23:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380596; cv=none; b=ICS6brqY+VWflH1ey5HMr7Co2JnatAZvwRhbQP3BTuIXgmyH8UIR5WO4n35XqE6Nu+g7czueWp0QWcjx5h9DEhQbXBNUaaGRymb2BrwUWwTFrKCoiRxi0Ml1dbn9eyzCHvgRNI0YUjnlVUfRL+NbjNBU4zFfBcCsPWXV+ApppM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380596; c=relaxed/simple; bh=PKyfNmIGpOnyrWFOlTJVA1L/Yj9yssKddjjlBkd/VSU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pe8nzB/I8Kxj7xw9wALst+RVWIxn3EtrXh1A7NgKvRnsPr+KsGRfqaF81s1Gsc3W349oCWsNkrDy/cARTgkS7VLLXo76YCnLTs0wBqS3NPocxyR4Q9hDt4pXP2+NuKpNK3iRbNesctL2NKhnnSUJUYI0+s3zGawOrqDZqqrFxEE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Qxj4rkkL; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707380595; x=1738916595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PKyfNmIGpOnyrWFOlTJVA1L/Yj9yssKddjjlBkd/VSU=; b=Qxj4rkkLBlZjeHj6hM8ny7fPKnUy/5av6ThgK0tXeKETKflcYqIaoELs UXtD8uDY9VJKogFE8MqfMUte/6QlVkI/nYCH8iVnwZjWjg1beBj1IwSJD LRbCJOtnMOQHgrEGgWJKYq2yrInOPdfiI+aWlJyvdKVt4hKEtg44jTA+7 Uz1cM0vyIGk2phlZOp0BWcIUSJw+6FEDHlqzffxsV4Ozs5qbk7M5d3Btd BV1wOoaFVLktGh94Eqgp3+xJ73m+hJprJHga0orIWrBnUGnuFScJpFm1C oUP/JNq3zZEZ+WRZFjwBFZSxBhRs8uOm8TzmOELoQnv5M7qYqvSshwQWF Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="5036337" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="5036337" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 00:23:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="6252124" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa003.jf.intel.com with ESMTP; 08 Feb 2024 00:23:13 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH rc 5/8] iommu/vt-d: Add missing device iotlb flush for parent domain Date: Thu, 8 Feb 2024 00:23:04 -0800 Message-Id: <20240208082307.15759-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208082307.15759-1-yi.l.liu@intel.com> References: <20240208082307.15759-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790319168513484396 X-GMAIL-MSGID: 1790319168513484396 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 --- 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 b1ceebe13107..c5a0275697cb 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1462,12 +1462,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 Thu Feb 8 08:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 198204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp24446dyd; Thu, 8 Feb 2024 00:34:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVluPc+Lbr/H2SC8s/5fCPJiklvYwrxPVsn4iaxr2OWYjqY4lUnAAWe7zX0V7aA8brImrtVSDucxJEE5JlLdy6Jcw1NoQ== X-Google-Smtp-Source: AGHT+IG5padCAk2rk2vrZwuykEDDGgJGMsFEyzDRERSA4bf6fsTyzgq4F/lAJMrav/idKGoj6899 X-Received: by 2002:a17:90a:db89:b0:296:fff3:cf33 with SMTP id h9-20020a17090adb8900b00296fff3cf33mr218499pjv.8.1707381290684; Thu, 08 Feb 2024 00:34:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707381290; cv=pass; d=google.com; s=arc-20160816; b=JOMVg2AnkxikhV4XCc2HhcinFYjOV2VteG6slhBj4aRDVtbYJ0G+ScbzKel8e+uZqi TkVSPY5UggoxFA6KZ4PAN6L5xpgPFB0Pb2k5Tx2Ja07JIn6laFdPwbS1Dz9krnDBCTB+ SupiEUg4BshvYgW6VQaph8ir2VuHhjJ73FZNtDwLWCImtbLV1pxYn/Vdxrq3YXALjcQ7 /3iMvR00IzR8MdUD1zJwXXDTQOujg/Pt7GSU3WtTwqhOnRbxD/64ZTdK1kHOU9W+tsg2 rwhIfYWM0szlz+ZD7b3wwY33oyl6IH9D+DPAWaCr5YRQ8yv6PnRiMuWsYqKjpMkmpT8k 9/EA== 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=3S4KR+ncWw8pz+sW66DSd9oOsEbe+BtQjhcYyBhFwSk=; fh=sir/hMlzy+eAArGOhzIhowYQwZEzPQjzmc+Nw7+TRbE=; b=AVDd8S7k6Kak/7oc0CAZe80/FVHHq3amnrUaQv4N4U7kLV6O/IeUVbCL1b1IwEJ3gY zf8vhCChfnFYbckakmf6fOJjsbq7u5cyzY4AYfx9ArhwO7K0SILdZgsDkUAKAMXF7z7N 1Zl2KaM4NiFWrEqKIceZ22gccu9+I2NKTk91PXZIDDh1o9hESf2sFtLphdYq+H7lw4Q4 gxw0nVRNqaFLk+X14rX0phQ6R3Id0I55G2+5qtXPzIUcUME6uDHC8iV4ztM+J8x75nLQ i9K+awf7Qxinlsiad8RvPBat8kRp0To4YF25OzLLCPapKkIRa1ewKnQSeRm+2Mmb62nn 1Kgw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EtlFc3wV; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57610-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57610-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWrWDw31AJcbyxMn+cWFKP3GDUVPnNDswJwOJ/J2WG9Oh61rx8LiDbeKwV4t2eOhwQvzI1+o25tHuB8ZHbTQC7N4JFOFw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u12-20020a17090ac88c00b00294731fbed3si905276pjt.146.2024.02.08.00.34.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:34:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57610-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EtlFc3wV; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57610-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57610-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9334C28A819 for ; Thu, 8 Feb 2024 08:26:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54B486F069; Thu, 8 Feb 2024 08:23:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EtlFc3wV" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CA786BB25; Thu, 8 Feb 2024 08:23:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380597; cv=none; b=Kd/DrJgHKCgVcE5+uD3IQwJMMp7WomM5kgz/D67SDrGuvnWWQpR+SIq12VI4uNQOm0f/tYGAvA0ezQRUecwu7cZ/BJzYJoYQVxN5Dn5OL0lphTZKb75IEyMUi2rNjngRF5FbdooDFjcSkkZN0e/WAw0CCFMfLj9PWdDU8XZoteU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380597; c=relaxed/simple; bh=m/RDlw1Azbc+HTUjCY0lMPLwvnpodCQbjh7vQHAUPf4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eZTEreUggIc/NzxgapRZHlTAoFtXL45DvRpMZtdG5H8dfvMm5Oejy0JWwZ46HjX4scDfb9SgaBUh/uKXyrTkoIB5bC9l1/mf/vpMbdXRsGkBglzvrUOSGlOoo80Cn0RWDdNy6qjn+PmbCWUZk2QDyIsiJZMFgUBGE3espTu2lbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=EtlFc3wV; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707380596; x=1738916596; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m/RDlw1Azbc+HTUjCY0lMPLwvnpodCQbjh7vQHAUPf4=; b=EtlFc3wVPVZva8pB2sUAjsNSoFSIT1As8GwTj/sw2K+rBQc/+i4TOYuv rqtZxe6cFvZhvSju0kD+mffzhzqNcGNsrsFkx46bGZiIr71MtsyY6rUfe blmkissZjB7IDtbnH1POAs8yM0chrzaRRh23kH3K5M8fhNUlwNk7JEyp0 BC2t+UX7gKjPy+f+1ZWhm6cOYqB3A7J5IvjP126qsth1QeKekTUVE4bhf l0m7qlk7VTGlP3snl0yNxynn0B69vFVqHJGg9wBo0uWU34qO4+nrvUKuf rRhq1hDtKnQNc571+87JH2QGhR33gyygamFx+aY9Tr7iBeVMu5tzz8UT0 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="5036345" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="5036345" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 00:23:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="6252131" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa003.jf.intel.com with ESMTP; 08 Feb 2024 00:23:14 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH rc 6/8] iommu/vt-d: Remove @domain parameter from intel_pasid_setup_dirty_tracking() Date: Thu, 8 Feb 2024 00:23:05 -0800 Message-Id: <20240208082307.15759-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208082307.15759-1-yi.l.liu@intel.com> References: <20240208082307.15759-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790319044211657095 X-GMAIL-MSGID: 1790319044211657095 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: Kevin Tian Reviewed-by: Joao Martins --- drivers/iommu/intel/iommu.c | 7 +++---- drivers/iommu/intel/pasid.c | 3 +-- drivers/iommu/intel/pasid.h | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c5a0275697cb..dae20991e036 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4742,8 +4742,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; @@ -4757,8 +4756,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) { 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, From patchwork Thu Feb 8 08:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 198208 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp25269dyd; Thu, 8 Feb 2024 00:36:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUtAriacOUV0mZs4PpcrJWzgq7w1cBNwXNeoAN0ybnG7hgc/zOLn2pOYJe2+5yOdswpkd8O7yLHGOgx6jFgTzBAGfzTvQ== X-Google-Smtp-Source: AGHT+IG2C44Gf9l5isZSjxHeWvNKjv5gQqkvwUXwG1NsZcmzbS3w2uwIZ3RQDpEDlkUI47DhXfYa X-Received: by 2002:a05:6808:1187:b0:3be:c38e:ceb0 with SMTP id j7-20020a056808118700b003bec38eceb0mr9797118oil.30.1707381415835; Thu, 08 Feb 2024 00:36:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707381415; cv=pass; d=google.com; s=arc-20160816; b=iWpIKKGEydNi1s86Skq5MYCk5hOTOc0pRwD6xU91f4TRlrY2eIzBSce9CIV2ng15wo pKeRgjxEGbKiemyC1WpdN17ZOYIrLnEKeT54pRkhS0VK/NPLEXcL/y55iNs89EYrLcOv QHb001iSIAocSdjzMBA8zeZ2DfJMBUqdqLINbcdUaH80Zk1RgVjy/0OaBxg+IEJ+2QkN wnr6ZlfSCwPpksnN5ZPAOcPSKFRUwqFGGAPXoy8ItO/htGkh2pKxDluEAFrKhZ0+UhRZ AMbTpbbQi0B4ZNBXTkdKxkIVqW8XbV+0KuruMv3pLrf3Bncb376kviWcPN7PF5dmBRT6 NzoQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Leo6OjFF7cTvTWH9Ij/WGHRlmsf3xAf3sM/zNznugKM=; fh=RkTsauflr7MdAfUpf4aa5KfNk29IlSOjFmZMX108ALs=; b=TGogoYx7WdomCFAa04rK0JW0Nu1OTUKAftXLALgZgtyLHddWgwm4tlhJSL+cjuSlwt TvGx9RMUSe7ZiuSFV8dDSApbbugfek9i6xma4Au3UpqCEi2lmZtWwZC27Y9VGm3S2f3n L6X83xNEGnuybFZL6mliQKkM5V6mYZHUhHLqC2mCOu0F6/oj2Nnx8Mnx8p9T4iOlHYHv U0RpywnM4bCrw4HQa+gkttj6SHpVfYlS/pXievEp45aF63JjW0r/9CTYRrmvmYmBUJAs atxva/79Xz6+3BgrA7sqWHogW1RwaIQgD/9ROQ2l+uUCuShs0JKXppkOVBLeFefxJz2B JqiQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ctn59+PP; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57611-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57611-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCXutI0u8JpzQmU4RPKSYtwejSvACmD5T8jOdvkspkJoBCRT4k0NzV7VrH6QnQ7vwGJCYeHErWZ/ICt3JhHEPoAsHesl1Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z3-20020a63ac43000000b005ce087e004esi3480848pgn.785.2024.02.08.00.36.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:36:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57611-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ctn59+PP; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57611-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57611-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1530328A9A9 for ; Thu, 8 Feb 2024 08:26:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5B126F07A; Thu, 8 Feb 2024 08:23:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ctn59+PP" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20EAE6BB55; Thu, 8 Feb 2024 08:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380597; cv=none; b=am7v7zPJ22t5Boj59vYhII8NqGMEkFKvt/CoOQX6TOmeUlmocOpm1dHa0sp+yIHONV/riKHyQgIX4lWko6oEgzq8SjR4T6nrQypZ7El21ByruOKaDzzxvrn1GBBmEAN8HD2M1qn29GgAHSusgX3xLYu0RK8wAU22VGSd75FGnWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380597; c=relaxed/simple; bh=E5vqPNymMiBaUwgno+gdspERLQZxZHNPzxdUdl6DYtw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rqNP4LDMlwIpz9WQ1yO2Y9Tny9fMVEVqwc8VLobDiHyh7PGsYdZofs/wgrw1Qf073ZyeXhaKorrrg30O2u8XzrTebuCZg9k3TBzKu7YFyAdW0ZP87Log4zRRUUc5s5lTsqwPadnKyhkrzoGVABw0lQ5T88rZGhm+Q5hhKNQycZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ctn59+PP; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707380597; x=1738916597; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E5vqPNymMiBaUwgno+gdspERLQZxZHNPzxdUdl6DYtw=; b=Ctn59+PPCl7yPs/4fKewQM9CkYzA2CNXLP2QIapjy/uGeWvLL1FbZTap /tUkPRNFzhxtnZiA+4skETRApuFEsiswvQUwxtlrUG+mB1GX00pCBOxov ygwUxSVJjtt9BsyJGot2pk6HpuKGpbHNvxBzv4tHLWicCHekpxvsbrFpg l6SAaNEmPXWgNlF+DKz9/+ZmLkhe5Pt5Wa6hHCCRF/xqSKwpZ8V7umcIx Hd/ZPlT29n2kNT4+YrgvVNE1XVy1TW3GBEAVo+SRdWxT3pwDXrLUibrqq joXTrZkep0RBt4fekhCmWEeumtdnnjKgGEsEDU3p3ar5Eja6AUXNTz16X g==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="5036353" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="5036353" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 00:23:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="6252137" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa003.jf.intel.com with ESMTP; 08 Feb 2024 00:23:15 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH rc 7/8] iommu/vt-d: Wrap the dirty tracking loop to be a helper Date: Thu, 8 Feb 2024 00:23:06 -0800 Message-Id: <20240208082307.15759-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208082307.15759-1-yi.l.liu@intel.com> References: <20240208082307.15759-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790319175123986921 X-GMAIL-MSGID: 1790319175123986921 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 --- drivers/iommu/intel/iommu.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index dae20991e036..7636d3f03905 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4730,23 +4730,35 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type) return vtd; } +static int +device_set_dirty_tracking(struct list_head *devices, bool enable) +{ + struct device_domain_info *info; + int ret = 0; + + list_for_each_entry(info, devices, link) { + ret = intel_pasid_setup_dirty_tracking(info->iommu, info->dev, + IOMMU_NO_PASID, enable); + if (ret) + break; + } + + return ret; +} + static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain, bool enable) { struct dmar_domain *dmar_domain = to_dmar_domain(domain); - struct device_domain_info *info; int ret; spin_lock(&dmar_domain->lock); if (dmar_domain->dirty_tracking == enable) goto out_unlock; - list_for_each_entry(info, &dmar_domain->devices, link) { - ret = intel_pasid_setup_dirty_tracking(info->iommu, info->dev, - IOMMU_NO_PASID, enable); - if (ret) - goto err_unwind; - } + ret = device_set_dirty_tracking(&dmar_domain->devices, enable); + if (ret) + goto err_unwind; dmar_domain->dirty_tracking = enable; out_unlock: @@ -4755,10 +4767,8 @@ static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain, return 0; err_unwind: - list_for_each_entry(info, &dmar_domain->devices, link) - intel_pasid_setup_dirty_tracking(info->iommu, info->dev, - IOMMU_NO_PASID, - dmar_domain->dirty_tracking); + device_set_dirty_tracking(&dmar_domain->devices, + dmar_domain->dirty_tracking); spin_unlock(&dmar_domain->lock); return ret; } From patchwork Thu Feb 8 08:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 198201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp21397dyd; Thu, 8 Feb 2024 00:26:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJx/cGZRzLtdXZx1oXxBoYgZ2pqNzQyxd9CG976nHRyn4GVfswbEiYaA0IdY9asqTbMeS8 X-Received: by 2002:a0c:f506:0:b0:68c:ba51:dde7 with SMTP id j6-20020a0cf506000000b0068cba51dde7mr4901656qvm.6.1707380786974; Thu, 08 Feb 2024 00:26:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707380786; cv=pass; d=google.com; s=arc-20160816; b=em0JO0q2HNVvz0b0OmqNHGll/+aDsOI5uiz/SzT1Zmv3Jp/07JCYnchmD8uVQVV07x aK3Zw1POIsf5ZypXB+1zEKRq4JCWDRqiElRGWb5TYtBTA54WbwpWWnp0kEMdzJyxDupu nMDDLSAbNL5swsV/R5A2AEmPPxGx+9htbVOKfIGBMjJiq0HDMvqgQrDjsxUpbPYPe0Xx krRxe7sXKkVWrV6FBBsGMjzupktmVXWTmp8sko3uU2IcBKDtMAsCtAUvP8nS94c6DuGY Do6kWUf/e7LUUw+8fhUdB/fkOVPEm/MFIcyB2FmOxJlRxo+hKsrP4fzJcbxUEZkzvHGD v+Gg== 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=Gq3mgYwKVbkAsSuQY6EtlPwvu9QrBVIHF/ufWe9J5J4=; fh=b9UeyI1ifKvbL/t5Xkgc0cySjOzs/jDSqr3eJo08rH0=; b=D9EnT2FDoBd78GjibhnCnoQ110zxHKTS7XUp1eE2mrfh357QX35TGxN7dVdbD+TJfA HI8BjZFwHoDKNa7WajCzOvoy090+pN6EyiQuLfKOXrSCsuJSUsdB6dWECSLtkPHmERJ7 Jdv4zBEIuz8gJ+894WfLGuM8TGBRHd8f7x0zVJAXDIpjxKYma8MxPTcb+zKmASL4ROVg xXkoWvx+AYDpbN2xgGlAFRoMSv1mUb0q8lrDgPVRiFNPX6BFQ+NWA7wKPlT7+oq7voRr hIRqyHkpE7pNdblE4plHiC0y75QFTtp+1peHx6AGL20IilaIFG8lFIx52xpqlb90PXew Butw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="ltPA6O/S"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57612-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57612-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVxJ6qYCy6uVWdM2sj94H0mk6GM07dhUz/Cl+Le9BdEPcRn/NAq5oLa1OP41uqjrV7g1pbi8E92NWfjZ863chCNiaZMEw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c12-20020ad4430c000000b0068cae96f029si2792398qvs.32.2024.02.08.00.26.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:26:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57612-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="ltPA6O/S"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-57612-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57612-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 A07E11C2264D for ; Thu, 8 Feb 2024 08:26:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35C486F083; Thu, 8 Feb 2024 08:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ltPA6O/S" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5122D6BFA3; Thu, 8 Feb 2024 08:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380598; cv=none; b=CWZweU2swfNSkMj3/jD9ojKm/YR1MYup0JluspCyJd+fsjONwawUaJrzWbEaAZPT1MlK6IOWKsSacM6R/+AmAX9TPPX2f1EL1eUDUquqLmOLM+7JzRHn76Q1QANLLRfPqn6lXAye2QDmltefFyEG32hfGYK36y1aO5R8KbsA/fs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707380598; c=relaxed/simple; bh=thi2b5CgZH40iDhft4tiI0ilUOViNb/SOYwiICBayms=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZTcwP2kpHgqn4PwwFBhkx8jtVO+C9TXe4Z8HJdwJrFfxzPfS22o8A93XN19k+wSA6kagGSikhBoHd5DesJIBNTVQ66gwxDsopzt+JEJuybOTDYMPiUV7OondZ942x/zfI46nMdWliDjltQKrwRlS7gggNCFM6FCOIhFHNTfX/IQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ltPA6O/S; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707380597; x=1738916597; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=thi2b5CgZH40iDhft4tiI0ilUOViNb/SOYwiICBayms=; b=ltPA6O/Sy9TUw9S9HAt2bF6AyypG9EvXnvaBlP2+rkLUw7EXFBh4TEuK DnsWmj597SvZjYjvIo6b8on0Kq+xrambj7Q5ph1dMRRiAYfn7YP5nZaE0 89Y4VMF/LnU58RpZT5jXuJASfxTnZ57kR4S8iogVA/EbEcfVFPaBYIyDr I8rIFpTUY1XecRZcKLnVGhmAHMvTyjZ4Q9QZ5VFhPh+y9g7vbM97yfK5G vnkIgUlAAShpDuUvy06wL9iI7hr8DQubTduCKvL0/yAo45YHdTIrglMF3 sISOj7f/mnfa4Tl5ollbWUz1PywV5TKkzyFDOzyL0Zn+GWiHT3JiKeCI+ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="5036360" X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="5036360" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 00:23:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,253,1701158400"; d="scan'208";a="6252142" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa003.jf.intel.com with ESMTP; 08 Feb 2024 00:23:15 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH rc 8/8] iommu/vt-d: Add missing dirty tracking set for parent domain Date: Thu, 8 Feb 2024 00:23:07 -0800 Message-Id: <20240208082307.15759-9-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208082307.15759-1-yi.l.liu@intel.com> References: <20240208082307.15759-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790318515998514641 X-GMAIL-MSGID: 1790318515998514641 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 --- drivers/iommu/intel/iommu.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 7636d3f03905..b4101712a0c3 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4746,6 +4746,36 @@ 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) { @@ -4760,6 +4790,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);