Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4688442pxj; Wed, 12 May 2021 10:55:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz6RqtZ5h+2HtOvd3m9s2M/SheMJKF9t5K4pwqP/FDWvjp9N8TE1BwISMrz7TaasbKO9rJ X-Received: by 2002:aa7:d507:: with SMTP id y7mr45419253edq.198.1620842045761; Wed, 12 May 2021 10:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620842045; cv=none; d=google.com; s=arc-20160816; b=qRPWA3oSyfXdYNEow+ZluWVgEo7PFEqG9JtepE3XbuV1mPWScuq6v2UkggvC1ZTC1e mlbImKD1v6i4ArqBvZxykMEXkjUc8XeQT3dkpL/oluPK1E97LgwOfY7KW/bi7/lAWVWL KHt3tjEsPcbVgLB5eaFMePSkN14e6W26DfOlfIYAIknMCVhSsj8ZLGvKabogW37LRV/e 1NL75YkQlai16d2jNQc+loYQWrRVRzIjI051dV6VjIM4S6DZF6EVBMQP7j5z6ZG3KQeu bS/MKtryPlK+PwVcY3roP7BOR+EzQffA8rztDicWV10MmlhWqaKfwcqBgwhdWpbkBp08 Nz4g== 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=yhf6gZuZYvgxaNWkVtSCcdHs0Xm+fKl/A2Oou6pLtyI=; b=A1vqk+pj2E2OLcmp8s5FnD27nxQUKnUOoqc9LfSVcUTSxG36WHBrUt7DNpn0r4CWji tJfIzkoauusbsl/Y9L6AkGu+FKPSRyo/hUQMPgFbYeVir2So/HtYmp8A2tTnea9jAAQJ 1iTQ14L/jiMiY/moLPt3oqhkeW7pM+xt2LAdBBrxpMftI00gVxmExrwZV1zE+9s8Xb9X ulmDI7Xf7ZNT3KrUmZN4XG12EjEPy5mZ7qPSEwsVAFZY5Eu5mgnYcoYPRXM20E39joGH XbYEJg6bHUfurS/d6Ul6wpTeg+WCCMETgYIx1RwJhGx40G5nLO9M9b4fMVX7VEkcgOOk N7mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gsauEHjS; 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 qo11si464792ejb.530.2021.05.12.10.53.40; Wed, 12 May 2021 10:54:05 -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=gsauEHjS; 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 S1350130AbhELRrc (ORCPT + 99 others); Wed, 12 May 2021 13:47:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:51344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240127AbhELQRO (ORCPT ); Wed, 12 May 2021 12:17:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7A33061C76; Wed, 12 May 2021 15:43:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834200; bh=knmJHBvyqqFKitxksHyy8h6XvibOlRZcIruRMKrqPb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gsauEHjStEs3Td0orOZqTTNbQK19e8EL/UMNwOBWyCrUmoEWYRympS1o0JdfsxVEs QuOf8ZCSSlYJatOjcK0R55aIHdbUa5ifmexVY8qXFKcQ9g5wX6gybuqcvNtpJjuWJU vmao6nYWESWnbvUvBEnXSoJsRHqs1oSlxyp0heKM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Murphy , Lu Baolu , John Garry , Joerg Roedel , Sasha Levin Subject: [PATCH 5.11 403/601] iommu/dma: Resurrect the "forcedac" option Date: Wed, 12 May 2021 16:48:00 +0200 Message-Id: <20210512144841.085221279@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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: Robin Murphy [ Upstream commit 3542dcb15cef66c0b9e6c3b33168eb657e0d9520 ] In converting intel-iommu over to the common IOMMU DMA ops, it quietly lost the functionality of its "forcedac" option. Since this is a handy thing both for testing and for performance optimisation on certain platforms, reimplement it under the common IOMMU parameter namespace. For the sake of fixing the inadvertent breakage of the Intel-specific parameter, remove the dmar_forcedac remnants and hook it up as an alias while documenting the transition to the new common parameter. Fixes: c588072bba6b ("iommu/vt-d: Convert intel iommu driver to the iommu ops") Signed-off-by: Robin Murphy Acked-by: Lu Baolu Reviewed-by: John Garry Link: https://lore.kernel.org/r/7eece8e0ea7bfbe2cd0e30789e0d46df573af9b0.1614961776.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- Documentation/admin-guide/kernel-parameters.txt | 15 ++++++++------- drivers/iommu/dma-iommu.c | 13 ++++++++++++- drivers/iommu/intel/iommu.c | 5 ++--- include/linux/dma-iommu.h | 2 ++ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a10b545c2070..b537a9608895 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1854,13 +1854,6 @@ bypassed by not enabling DMAR with this option. In this case, gfx device will use physical address for DMA. - forcedac [X86-64] - With this option iommu will not optimize to look - for io virtual address below 32-bit forcing dual - address cycle on pci bus for cards supporting greater - than 32-bit addressing. The default is to look - for translation below 32-bit and if not available - then look in the higher range. strict [Default Off] With this option on every unmap_single operation will result in a hardware IOTLB flush operation as opposed @@ -1949,6 +1942,14 @@ nobypass [PPC/POWERNV] Disable IOMMU bypass, using IOMMU for PCI devices. + iommu.forcedac= [ARM64, X86] Control IOVA allocation for PCI devices. + Format: { "0" | "1" } + 0 - Try to allocate a 32-bit DMA address first, before + falling back to the full range if needed. + 1 - Allocate directly from the full usable range, + forcing Dual Address Cycle for PCI cards supporting + greater than 32-bit addressing. + iommu.strict= [ARM64] Configure TLB invalidation behaviour Format: { "0" | "1" } 0 - Lazy mode. diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 07e7b2f3ba27..9d4a29796fe4 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -52,6 +52,17 @@ struct iommu_dma_cookie { }; static DEFINE_STATIC_KEY_FALSE(iommu_deferred_attach_enabled); +bool iommu_dma_forcedac __read_mostly; + +static int __init iommu_dma_forcedac_setup(char *str) +{ + int ret = kstrtobool(str, &iommu_dma_forcedac); + + if (!ret && iommu_dma_forcedac) + pr_info("Forcing DAC for PCI devices\n"); + return ret; +} +early_param("iommu.forcedac", iommu_dma_forcedac_setup); void iommu_dma_free_cpu_cached_iovas(unsigned int cpu, struct iommu_domain *domain) @@ -456,7 +467,7 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, dma_limit = min(dma_limit, (u64)domain->geometry.aperture_end); /* Try to get PCI devices a SAC address */ - if (dma_limit > DMA_BIT_MASK(32) && dev_is_pci(dev)) + if (dma_limit > DMA_BIT_MASK(32) && !iommu_dma_forcedac && dev_is_pci(dev)) iova = alloc_iova_fast(iovad, iova_len, DMA_BIT_MASK(32) >> shift, false); diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index e49a79322c53..005daf50107d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -350,7 +350,6 @@ int intel_iommu_enabled = 0; EXPORT_SYMBOL_GPL(intel_iommu_enabled); static int dmar_map_gfx = 1; -static int dmar_forcedac; static int intel_iommu_strict; static int intel_iommu_superpage = 1; static int iommu_identity_mapping; @@ -441,8 +440,8 @@ static int __init intel_iommu_setup(char *str) dmar_map_gfx = 0; pr_info("Disable GFX device mapping\n"); } else if (!strncmp(str, "forcedac", 8)) { - pr_info("Forcing DAC for PCI devices\n"); - dmar_forcedac = 1; + pr_warn("intel_iommu=forcedac deprecated; use iommu.forcedac instead\n"); + iommu_dma_forcedac = true; } else if (!strncmp(str, "strict", 6)) { pr_info("Disable batched IOTLB flush\n"); intel_iommu_strict = 1; diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index 706b68d1359b..13d1f4c14d7b 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -40,6 +40,8 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list); void iommu_dma_free_cpu_cached_iovas(unsigned int cpu, struct iommu_domain *domain); +extern bool iommu_dma_forcedac; + #else /* CONFIG_IOMMU_DMA */ struct iommu_domain; -- 2.30.2