Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3320146pxb; Sun, 29 Aug 2021 22:02:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFG9FHvNCh/ROUKvTvg9zT1VH/sa7PGv9OPoncaxA31FlTLQHb5HrfyTb5+/mNYp/jwltd X-Received: by 2002:a17:906:abc3:: with SMTP id kq3mr3665491ejb.382.1630299749399; Sun, 29 Aug 2021 22:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630299749; cv=none; d=google.com; s=arc-20160816; b=pwEYF+VR6EBa28dkL0xQwcgM3xz7+mBJNAv1j0Fc6T02/jQhuxb54TbkibQ/27Vn9I zu/7m1HBmUzmP9ENq4xX8KmVK8gvvGBnlivzfPNOYgjszgga0M8+ZPoXqiHGdB9Vxv83 i3EF2Xjlrb5LVz6dgxZnPNJScD2TgrDs0Df1+308x47tWjoXjRK0/FGBahCBNXIOr+jl +sSyl7khIBcwmfGEuoRMKcWb/QParb0gUosrLs24Ae05Xnxr4o+ukybhjtcCGixyuQmT kD65i44eukn+mjyNIpYvKcY/ksAmUfJYgRvTf5CihVuuv128ovM4a1oRFfOx/ephozBk TSJw== 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=rNro/SVWUv53bWZVvRwdq3+oqlN2MzMlKhJNAj3RBQs=; b=OSTQKJEgv7Z43SvjJv54oZwFlo+PhFajQkW/+IG7PEgR4At0sPTKaUjPOLSKIL4Vu3 R5SDuWNOlq3c8Chn0/xR4wImA5qZmukk/Sqt6iV7gSf6BkkRoMQikjEaUh6UZAKhoiwH bm/L1IZAXxeCO5iD2pn931rph7PgbKlx3wes1x7ZiuYlJhjGZ7YDIoqUveNZEa3uiYH9 wRwkpTO+oPVfyksxFanRmdNQyOs6qvQdUVCI3uqP30XXBId6HduTQGX2qIMHLo3shOPA MTwWlgo2T9rRR96k/U1HBBds16ykCgnCHsVII1rKp0rzrYinl2Tnl5+pajX6KyLzpsFL ltQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SnOOVo00; 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 x16si12128059edd.522.2021.08.29.22.02.06; Sun, 29 Aug 2021 22:02: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=@chromium.org header.s=google header.b=SnOOVo00; 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 S232099AbhH3FBc (ORCPT + 99 others); Mon, 30 Aug 2021 01:01:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232460AbhH3FB3 (ORCPT ); Mon, 30 Aug 2021 01:01:29 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93D90C0617AF for ; Sun, 29 Aug 2021 22:00:31 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id y23so12262795pgi.7 for ; Sun, 29 Aug 2021 22:00:31 -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=rNro/SVWUv53bWZVvRwdq3+oqlN2MzMlKhJNAj3RBQs=; b=SnOOVo00WQXBu7XiDSvc+pPdG7jSk8OScnrPcRaBwVE5/sJRbN0FDuqPTgR9ap3oxi DNuFV2RdyH8xhSDRtjjBNQbsWsPrC57K9ZzgCNmH+uW13+ip4QA2w1jztLoKxdW5DPAl a9wBQz9AD6DK7oSL36aKM0JeXfcWXs1u44pt0= 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=rNro/SVWUv53bWZVvRwdq3+oqlN2MzMlKhJNAj3RBQs=; b=tAUNLODyUw25FcHvpZFqRTK1tgHgguwo2LRx16m0PRvY9prryFXTmpgCXK68gqP9rL rhk1cheOWrAVtB/c5nhPezj0JXYMrG7jdPxYabPrZ4Ve2RNy15ksn/2RtoJpiYoBPkyr se/0U2W4No0ve0dS2VierJiWdKkQmYuy20tUd4AqyXGCLpTt4BTNl6GbQ5eE7mg7Swwa KNAQ9URfneby2mTpKTs8CQg7pNh6Pp3P9xXW6MJ45VNApZagdGNxDLmu4DAcwcIITW5l rhVUTGp1uKZmNTieTXyj8qQGmqvlKkFbZQrdM0MKCRpemTehCDxmgXyS80l06kiurz4g tZHA== X-Gm-Message-State: AOAM5305dFJeydHK12MhWRNg4bs1qqoJaMVSE5BgBcwKwKd4yjSKzGC7 Yre1ZeRfwjEvZrYUVl2J56lzdA== X-Received: by 2002:a05:6a00:1687:b029:3e0:eb00:108e with SMTP id k7-20020a056a001687b02903e0eb00108emr21532379pfc.16.1630299631153; Sun, 29 Aug 2021 22:00:31 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:28a5:1b9f:af1d:5542]) by smtp.gmail.com with UTF8SMTPSA id t14sm15458818pga.62.2021.08.29.22.00.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Aug 2021 22:00:30 -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 , Rajat Jain , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, David Stevens Subject: [PATCH v7 5/7] dma-iommu: Check CONFIG_SWIOTLB more broadly Date: Mon, 30 Aug 2021 13:59:23 +0900 Message-Id: <20210830045925.4163412-6-stevensd@google.com> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog In-Reply-To: <20210830045925.4163412-1-stevensd@google.com> References: <20210830045925.4163412-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 95bfa57be488..714bec7a53c2 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); +} + /* sysfs updates are serialised by the mutex of the group owning @domain */ int iommu_dma_init_fq(struct iommu_domain *domain) { @@ -730,7 +735,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); @@ -746,7 +751,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); @@ -764,7 +769,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); @@ -780,7 +785,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), @@ -807,8 +812,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; @@ -991,7 +995,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)) @@ -1063,7 +1067,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.259.gc128427fd7-goog