Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp799539pxb; Mon, 16 Aug 2021 18:42:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTGTCPCqOwMnXIdsprgd1H1rpQsXHOpAHxWV9Im9ezo8/kyx1uNZv3McQcSFET9L5hsvs8 X-Received: by 2002:a92:dd82:: with SMTP id g2mr644722iln.279.1629164523448; Mon, 16 Aug 2021 18:42:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629164523; cv=none; d=google.com; s=arc-20160816; b=J576Mal37Q8dE7cIgiWx5qMgPN2zH3Lnd2fw6g7daXolAIdpEhMBXMoKVhGxX9lRh3 +j91FOtcNs1iYCxNCAYMWdirU07mqhC8cdQL63GEczw1fnhqJwSRH5LzOqZvxR9OoO7b Lbm7sEnylyZyeHlOODNgxZDGKpZEtz0VVUidokMd0GadZK6koM0aSL5qaW5SWu6JNJEf vdieutCj779N4cCkgSStUJWG57C6IwqaVvKDK8KnLgH1DdASWuspDx1TvfWjFwEDKb/9 6TDcYPWwMWbo8lAZVIVJci+eQLdz3+7Z62BJ5Of++rYAYmT4pJmzKaiN5aEk59vl4q+P FnUQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bH6cLE0zMhAQVWMm2D0O+HHUiSj+wLXXMwuwnh6v2/4=; b=ckZGNv8Hd4tzLxlbRp96kW80HOk8PU70mLSBJRt+mpMBYtMIQWNbmbKszsRdH9yRsV J4SIaw/tRyp7uFsk76Zl/upwHfYKt9zRzq1j8o6+rLEOzPgVWJjJHxKH5laF8PtPmvca R0VMSWQegvVHBzV3bt3yGEkXlH+tMEuLHwIIGbly+CCnSt3TEkYzGoffHxR0Cja7jL+3 KR+Bw4hGnHHK5kRhgTxDUA6xPJ5YKeaJ6Y94HFQppt8Cs8mqKv0rTNSVINaiEKl/4x24 TLMdKkAihyhTe3EDaeTjQy4KEAMWwUOVA7Rnc88wUf4osvD1yWvyAnT0BTL0rOLhU5ct 0e4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iyWks8Hh; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si687850ilo.4.2021.08.16.18.41.52; Mon, 16 Aug 2021 18:42:03 -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=@chromium.org header.s=google header.b=iyWks8Hh; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236332AbhHQBkL (ORCPT + 99 others); Mon, 16 Aug 2021 21:40:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236280AbhHQBkH (ORCPT ); Mon, 16 Aug 2021 21:40:07 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C3C7C061292 for ; Mon, 16 Aug 2021 18:39:34 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id c17so17557464plz.2 for ; Mon, 16 Aug 2021 18:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bH6cLE0zMhAQVWMm2D0O+HHUiSj+wLXXMwuwnh6v2/4=; b=iyWks8HhsOysI2qXvnHO59zz/9NNMj+xLZHMy7ZrsqUapbiN8qrPSpd3JkR/19bH32 LN09eA3oCQSijRywugAepz4cGiCVfsm6Lwbj2xZmy/GokTWxnA/cKD564RUppL/77U/L 4RTw03/keaOEiWBDqE0NHHZJj/NuN3be1CnKw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bH6cLE0zMhAQVWMm2D0O+HHUiSj+wLXXMwuwnh6v2/4=; b=ksjAh7Vn0DKo4y3AvnCtZENyYag5Phdf4INfC94EUjSSzFccEiIhwktG6LoSEhbGxF NsGoQBH16OJBqRZLYCEBT59AKXEUDdWeexeOf6732KE06+2qzgWdI7A9KBnkqPck0y9z VJwpBWAEbIj7CH5OvovEZcbssWg6dr34bl8IjHpfpPdQmvlTqqdfNh3xXH+M/1C9h96S TTQp7EshGV4lb58qSLcgtNfyr6iNigPRjxQNNelVXv0qvQwSFXNjVWXda68O4aTEw5Mx Z5M5YpPCy5vlc3zAsZHlaifflpc8ISBZLbDx6B57B7ZLk88LtZ6QVfSa3vtrSXPQzOWe 3Gcw== X-Gm-Message-State: AOAM533A7b3MJNrZ2n++jV/9u7CwbWMjT5D02K0Ug9VXNHKEsoOoM4Gc 9PONT5KzIoqPNYBW7C+q+it1iA== X-Received: by 2002:a05:6a00:2171:b029:3ab:eca3:af59 with SMTP id r17-20020a056a002171b02903abeca3af59mr1049865pff.46.1629164373910; Mon, 16 Aug 2021 18:39:33 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:6864:767c:2ff8:749d]) by smtp.gmail.com with UTF8SMTPSA id j68sm475347pgc.44.2021.08.16.18.39.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Aug 2021 18:39:33 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: Robin Murphy , Christoph Hellwig Cc: Joerg Roedel , Will Deacon , Lu Baolu , Tom Murphy , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, David Stevens Subject: [PATCH v6 5/7] dma-iommu: Check CONFIG_SWIOTLB more broadly Date: Tue, 17 Aug 2021 10:38:50 +0900 Message-Id: <20210817013852.3222824-6-stevensd@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210817013852.3222824-1-stevensd@google.com> References: <20210817013852.3222824-1-stevensd@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Stevens Introduce a new dev_use_swiotlb function to guard swiotlb code, instead of overloading dev_is_untrusted. This allows CONFIG_SWIOTLB to be checked more broadly, so the swiotlb related code can be removed more aggressively. Signed-off-by: David Stevens Reviewed-by: Robin Murphy Reviewed-by: Christoph Hellwig --- drivers/iommu/dma-iommu.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 8152efada8b2..49a0d4de5f6c 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -317,6 +317,11 @@ static bool dev_is_untrusted(struct device *dev) return dev_is_pci(dev) && to_pci_dev(dev)->untrusted; } +static bool dev_use_swiotlb(struct device *dev) +{ + return IS_ENABLED(CONFIG_SWIOTLB) && dev_is_untrusted(dev); +} + /** * iommu_dma_init_domain - Initialise a DMA mapping domain * @domain: IOMMU domain previously prepared by iommu_get_dma_cookie() @@ -713,7 +718,7 @@ static void iommu_dma_sync_single_for_cpu(struct device *dev, { phys_addr_t phys; - if (dev_is_dma_coherent(dev) && !dev_is_untrusted(dev)) + if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev)) return; phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle); @@ -729,7 +734,7 @@ static void iommu_dma_sync_single_for_device(struct device *dev, { phys_addr_t phys; - if (dev_is_dma_coherent(dev) && !dev_is_untrusted(dev)) + if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev)) return; phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle); @@ -747,7 +752,7 @@ static void iommu_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg; int i; - if (dev_is_untrusted(dev)) + if (dev_use_swiotlb(dev)) for_each_sg(sgl, sg, nelems, i) iommu_dma_sync_single_for_cpu(dev, sg_dma_address(sg), sg->length, dir); @@ -763,7 +768,7 @@ static void iommu_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg; int i; - if (dev_is_untrusted(dev)) + if (dev_use_swiotlb(dev)) for_each_sg(sgl, sg, nelems, i) iommu_dma_sync_single_for_device(dev, sg_dma_address(sg), @@ -790,8 +795,7 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, * If both the physical buffer start address and size are * page aligned, we don't need to use a bounce page. */ - if (IS_ENABLED(CONFIG_SWIOTLB) && dev_is_untrusted(dev) && - iova_offset(iovad, phys | size)) { + if (dev_use_swiotlb(dev) && iova_offset(iovad, phys | size)) { void *padding_start; size_t padding_size; @@ -974,7 +978,7 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, iommu_deferred_attach(dev, domain)) return 0; - if (dev_is_untrusted(dev)) + if (dev_use_swiotlb(dev)) return iommu_dma_map_sg_swiotlb(dev, sg, nents, dir, attrs); if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) @@ -1046,7 +1050,7 @@ static void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, struct scatterlist *tmp; int i; - if (dev_is_untrusted(dev)) { + if (dev_use_swiotlb(dev)) { iommu_dma_unmap_sg_swiotlb(dev, sg, nents, dir, attrs); return; } -- 2.33.0.rc1.237.g0d66db33f3-goog