Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4141370pxb; Mon, 8 Feb 2021 08:53:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhIduZNMuWeRHMuW2pTQiC655OFfPwjyR46wTB3sqIFP+TdUtx05IrUfkeC3oe45uF3v7A X-Received: by 2002:a05:6402:4ce:: with SMTP id n14mr17939623edw.309.1612803233538; Mon, 08 Feb 2021 08:53:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612803233; cv=none; d=google.com; s=arc-20160816; b=ktTLM2zsG9w45C3Hmvi8AcL+pm2xxZCox0lGQrfB1w/E3auZrKO8fqRM8vsaCTg2LK Fb0JpQyxQwG/WDJHqo+P4AxIeYqo/YqegwWmOejm1kYclTsGnVtA+CLgxg94sdVoKXWC XGRhAdoBp45sDP9VKTGMIsJZ1eR+vmMuG3AEMSX4vq58MtH7l1GnWXG5X5C3LnFBH+G5 wJ/fc/YtJIUTUkfs01wdoC2I9vr3bEsPrnZJQKJNg7fi1Fi8ANCh8Yxr7/gIfTRpbQMW OYeHCiCZNA+JYtiJDPAcV50S8uhO3P7UcEB2Ltu4lpC6ikvORpNobvVYlrsD+uwL1dTs pitA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pUsx0m9WljuQlsC47zNOvYLQFlcF2VEWPBqrmsm0A18=; b=rep3+eoeX8mCdTbTUKxJ3Dz9+0A9vzb0mLpgEl4QcRWyKsjfDVJGTY5k1m/sWUEI8L LGmpqgft6zb9xf5X1LytPGvMCzqGFiVAzZFDY/c5qvgQfBxqhIytlkY/PJwnNL69rbJC hpgxvJNp+nUeAAH3fXnd0g0/XoW2nCWuNt6oKM+k5xshiVcTWg2lEZOVwz7rDpqQnCH2 XKvwMZsFjBpK4WMUjrWwnZUaukivL/DhpVc56Y5nu9tc3Ft2I05NYntDb2C+DvOxAVRp pY6iq5ezGUhvxPI+xGAp1luHn4VjUDEmHpL7ZSgBm6ZsHaqqP24dv7qcsQSlX4ICK6Ho mdyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="vTPr1/cQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 22si10709886ejc.181.2021.02.08.08.53.29; Mon, 08 Feb 2021 08:53:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="vTPr1/cQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232230AbhBHQuK (ORCPT + 99 others); Mon, 8 Feb 2021 11:50:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:33694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233353AbhBHPRa (ORCPT ); Mon, 8 Feb 2021 10:17:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BE37660238; Mon, 8 Feb 2021 15:11:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797097; bh=5SrLtI23WZIAEPavMoaVnodJN3n6Bm4RlGll8JcCVYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vTPr1/cQcsfNjQjP6UbtomkghqP0QOSHbP0C1+Daw8A0rPlcnn0u8Zn5wO7wAf4iO oPwV4a5jmODaJvDAcGaGaHoT7bH78ThtUdfBjktB7FiE69UeP16FiRN0Uwv/I+b8Ms sOQWWOUVzC+iVq5TYZcgPIhD0/Wo3xTdTPDw3Nlw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nadav Amit , David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Joerg Roedel Subject: [PATCH 5.4 58/65] iommu/vt-d: Do not use flush-queue when caching-mode is on Date: Mon, 8 Feb 2021 16:01:30 +0100 Message-Id: <20210208145812.475560556@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145810.230485165@linuxfoundation.org> References: <20210208145810.230485165@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nadav Amit commit 29b32839725f8c89a41cb6ee054c85f3116ea8b5 upstream. When an Intel IOMMU is virtualized, and a physical device is passed-through to the VM, changes of the virtual IOMMU need to be propagated to the physical IOMMU. The hypervisor therefore needs to monitor PTE mappings in the IOMMU page-tables. Intel specifications provide "caching-mode" capability that a virtual IOMMU uses to report that the IOMMU is virtualized and a TLB flush is needed after mapping to allow the hypervisor to propagate virtual IOMMU mappings to the physical IOMMU. To the best of my knowledge no real physical IOMMU reports "caching-mode" as turned on. Synchronizing the virtual and the physical IOMMU tables is expensive if the hypervisor is unaware which PTEs have changed, as the hypervisor is required to walk all the virtualized tables and look for changes. Consequently, domain flushes are much more expensive than page-specific flushes on virtualized IOMMUs with passthrough devices. The kernel therefore exploited the "caching-mode" indication to avoid domain flushing and use page-specific flushing in virtualized environments. See commit 78d5f0f500e6 ("intel-iommu: Avoid global flushes with caching mode.") This behavior changed after commit 13cf01744608 ("iommu/vt-d: Make use of iova deferred flushing"). Now, when batched TLB flushing is used (the default), full TLB domain flushes are performed frequently, requiring the hypervisor to perform expensive synchronization between the virtual TLB and the physical one. Getting batched TLB flushes to use page-specific invalidations again in such circumstances is not easy, since the TLB invalidation scheme assumes that "full" domain TLB flushes are performed for scalability. Disable batched TLB flushes when caching-mode is on, as the performance benefit from using batched TLB invalidations is likely to be much smaller than the overhead of the virtual-to-physical IOMMU page-tables synchronization. Fixes: 13cf01744608 ("iommu/vt-d: Make use of iova deferred flushing") Signed-off-by: Nadav Amit Cc: David Woodhouse Cc: Lu Baolu Cc: Joerg Roedel Cc: Will Deacon Cc: stable@vger.kernel.org Acked-by: Lu Baolu Link: https://lore.kernel.org/r/20210127175317.1600473-1-namit@vmware.com Signed-off-by: Joerg Roedel Signed-off-by: Nadav Amit Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/intel-iommu.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -3285,6 +3285,12 @@ static int __init init_dmars(void) if (!ecap_pass_through(iommu->ecap)) hw_pass_through = 0; + + if (!intel_iommu_strict && cap_caching_mode(iommu->cap)) { + pr_info("Disable batched IOTLB flush due to virtualization"); + intel_iommu_strict = 1; + } + #ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_supported(iommu)) intel_svm_init(iommu);