Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4623987pxj; Wed, 12 May 2021 09:28:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU4Qt6iFgD4o+w1n63w6drbfuFH653vYJU6Dhnpgi7ApMg5WCHtrlvKMieJ51PSuhmtZ2M X-Received: by 2002:a17:906:d9ce:: with SMTP id qk14mr38058964ejb.411.1620836909086; Wed, 12 May 2021 09:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836909; cv=none; d=google.com; s=arc-20160816; b=d7WpePuRoRkDIEsXd2nKSIcUdLE96qWdJ2xSRmH9M4WtlQIyMKjMmmLQRPwzxhAC+j GM8Ur01q7o28TfPJGpqiVYDxr+3FEL75ITGEGpnvQpaKg7Zf6/AnRnzU5erOBTaE8mKq MR2PKe1T2fq/s08emU9qV19NYKhGl89yY+6V6pg99mv+JUkPFxWSv0KmSQhqXGVobe/y wHIVydyJrOjfHHb+qVLXiQE3nmB+ZKzw9MmBDY0YzNLFowNiJYe+lvNdXWVix1+yLaX9 FeSrVBLw4KGYn3EyA7WS8D9fKEVeBFU39g5KSHKcyRhC2SktFmkupRSvSW0y953PcSOF sRTQ== 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=ZCvx+7+SR8/g99WvuNEdsE+bGMNbFEZmZejSrN0M9kA=; b=OUpubkWpHkyg6A51ZKJlJIX3X22o01U5rC7uq3T/nKs03pg2ZL5hsBEnWqfTok+ZkW cviLNm2QhbcblCe5Tu7Q8XuMuzwYVTHf57oktUgbU1nMUNJ4Tg4O9ZPpm3Ax8CkgCBwq A9CHsbHobn+wUjQMG8l4Xr1269JYXD0o2Lg3YEuFI8KCtBI51/nxCd9DRMoMygcZhO7h b8atBqgcqX1N3sNHNZfTh9ccKZuKdBqJQVXLgtCTtflPn91NOTb3frKP5PyMSU583fYb eUbs6eNPpqb2XLkv0pkbimdmkrl837mDcfjmPyR40eJ2t9dKr+jmAQiO3htkzCmC5iSN g7rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XBvHAsJz; 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 hd36si385435ejc.151.2021.05.12.09.28.03; Wed, 12 May 2021 09:28:29 -0700 (PDT) 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=XBvHAsJz; 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 S240941AbhELQ0H (ORCPT + 99 others); Wed, 12 May 2021 12:26:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:54422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236156AbhELPhK (ORCPT ); Wed, 12 May 2021 11:37:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D8A2561C4E; Wed, 12 May 2021 15:18:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832712; bh=Yf8qw+FhU0gn+AhqcJV42bubC8diNGShU7v2phVauxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XBvHAsJzVNQoBlwDApJgZZKu4BvPPpNc/SARuepv9Bp7LYwmSpDPabUUIBLhhhT6h y+ThPynbheSpqDq4192a+1VdiE38gJGUiw44wqvhNxo0sUL1rYRb7k0YZtsZJvsM17 DkCMFnIp5M5zAfQ8IFYkeUFEfbt6WnXhpAmgguiM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ashok Raj , Lu Baolu , Joerg Roedel , Sasha Levin Subject: [PATCH 5.10 392/530] iommu/vt-d: Preset Access/Dirty bits for IOVA over FL Date: Wed, 12 May 2021 16:48:22 +0200 Message-Id: <20210512144832.660153884@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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: Lu Baolu [ Upstream commit a8ce9ebbecdfda3322bbcece6b3b25888217f8e3 ] The Access/Dirty bits in the first level page table entry will be set whenever a page table entry was used for address translation or write permission was successfully translated. This is always true when using the first-level page table for kernel IOVA. Instead of wasting hardware cycles to update the certain bits, it's better to set them up at the beginning. Suggested-by: Ashok Raj Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20210115004202.953965-1-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/intel/iommu.c | 17 ++++++++++++----- include/linux/intel-iommu.h | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 3295e5e162a4..8010c3895f8c 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1028,8 +1028,11 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain, domain_flush_cache(domain, tmp_page, VTD_PAGE_SIZE); pteval = ((uint64_t)virt_to_dma_pfn(tmp_page) << VTD_PAGE_SHIFT) | DMA_PTE_READ | DMA_PTE_WRITE; - if (domain_use_first_level(domain)) + if (domain_use_first_level(domain)) { pteval |= DMA_FL_PTE_XD | DMA_FL_PTE_US; + if (domain->domain.type == IOMMU_DOMAIN_DMA) + pteval |= DMA_FL_PTE_ACCESS; + } if (cmpxchg64(&pte->val, 0ULL, pteval)) /* Someone else set it while we were thinking; use theirs. */ free_pgtable_page(tmp_page); @@ -2354,14 +2357,18 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, return -EINVAL; attr = prot & (DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP); - if (domain_use_first_level(domain)) + if (domain_use_first_level(domain)) { attr |= DMA_FL_PTE_PRESENT | DMA_FL_PTE_XD | DMA_FL_PTE_US; - if (!sg) { - sg_res = nr_pages; - pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | attr; + if (domain->domain.type == IOMMU_DOMAIN_DMA) { + attr |= DMA_FL_PTE_ACCESS; + if (prot & DMA_PTE_WRITE) + attr |= DMA_FL_PTE_DIRTY; + } } + pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | attr; + while (nr_pages > 0) { uint64_t tmp; diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 94522685a0d9..ccaa057faf8c 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -42,6 +42,8 @@ #define DMA_FL_PTE_PRESENT BIT_ULL(0) #define DMA_FL_PTE_US BIT_ULL(2) +#define DMA_FL_PTE_ACCESS BIT_ULL(5) +#define DMA_FL_PTE_DIRTY BIT_ULL(6) #define DMA_FL_PTE_XD BIT_ULL(63) #define ADDR_WIDTH_5LEVEL (57) -- 2.30.2