Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp1393649pxy; Sun, 15 Aug 2021 20:01:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1OxdusskfORXQAi5Y1ZKyp1hIIweg0N1xNbnljiPEoeeyP/X/MSxNgYU6TQ38mIuOE5/l X-Received: by 2002:a5d:8e11:: with SMTP id e17mr11242398iod.138.1629082869955; Sun, 15 Aug 2021 20:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629082869; cv=none; d=google.com; s=arc-20160816; b=m/SoyGELRogFa646GtHawYwwsKTW/sFZaKZGFhxVxcAizYwLqU9Vt+ZFXzyen3PCFC 4TARgmOxuroptogxUXw3o8tPq1AxdJTvXewQ8YRuCSc3Zhykhi4KOlOAXKrP3iMrk0Es CJMLDgvyR+babl/X9xAjV3JZiTTp2+rl3ZQFU+UOkmVOBBoPHVOv5RCpkZ1B2kVuc77l FpkEqMEa+pHtkCwLeV8P5snEpCOWTaRxfN0FwtelcNrRveh8RFIINPqD+r3ylDL1516M IMMGOrpy+Ze7rvX8xXM7OhGGJ5vIkp4RjY7EAabqzFBYGn39k0U75fph4041OmnKcq8Y FKxg== 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=Ag8rYt4Qynkz+ZmVF3Oja3eIjKQLOppmv3Wwber6wHI=; b=C076PsbHp/2OPG7YVbAi9kRkgHhPJxzF4ooY4wpuZxfQDg6OU6Ddt3AyrfzgoP0BLC 1R8jd3tFFcwAymRt5W0jUejy37alx5w57tLMYhq14QYKR5qVCMiE2dsB+OSv/Rz2mpIV pHJa/RgX2QVQDfN1XnGHs9664MzhG4BmiHuYEMKuA9+60NHUv7Wo8lIbZhPBbDBJFnhW 1Y4l2Wh5phLkh/CnuaZ2TxF1MyYb2RTA8Ixp8YWzGoMsed+9v4ZBrtLHDJrKxgFiuJde 0OZLh90NVaqKK71BnMJ3JSQUfQ6JTLT0exgfLrQCW6SViGq8SXbI5/b5HCzldrrXGq/H HVIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QPACOrfx; 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 13si11648309jan.43.2021.08.15.20.00.58; Sun, 15 Aug 2021 20:01:09 -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=QPACOrfx; 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 S232757AbhHPDAO (ORCPT + 99 others); Sun, 15 Aug 2021 23:00:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232746AbhHPDAL (ORCPT ); Sun, 15 Aug 2021 23:00:11 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30275C0613C1 for ; Sun, 15 Aug 2021 19:59:41 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id e15so19175300plh.8 for ; Sun, 15 Aug 2021 19:59:41 -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=Ag8rYt4Qynkz+ZmVF3Oja3eIjKQLOppmv3Wwber6wHI=; b=QPACOrfxzZCuRSa07kcQvq99jKQXmFCMz6gsaRKLPXh2OqhPW10+1QF9uyS6yftWDS NWG8+N9vA7Y3xCtzk2xMft0qiFqgUNVNeFi7D43vt1aX/pwjHZTgd6YohE5Z70k5CoRC AjOlO0jkpwt9qOzioFO6cMQ3GAoXjHGxxnGaI= 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=Ag8rYt4Qynkz+ZmVF3Oja3eIjKQLOppmv3Wwber6wHI=; b=ipl0HnULMy0ifK8ChPxijJSJXbyh91HSoQw9tLA54//HSQ8zooL+0v2tQXOLpqA7XG wCdAOKkJ/ziRO/bl/od7dwSDroPiI1WSjegWgc/o2gZUn+rM+g7Z6eQ6WX8/JH6pP+G8 fn6fZsS7xa1QQT6TNShAr2LcZx04YeRpoc0gOS5CYlT3KErf0krD7d4a1savR1Yg3hSH obiCr5+bTTu8GkpTbCZ5U+S83Gm3MEl6/CjRrnNjcVpzNPv3d+4SxOkVDURvrHJcm+l+ 5WXM1E1FhmjAnqqtMESYj+MuDZAF9e/IlHMO7WWwFRNA2fNlXpX8y81PLnTttpWspxdG geoA== X-Gm-Message-State: AOAM531t7d0gEvp130fmFW2vd1cflouiGsrMYk+mmNHzxSZd8KW+qAjE laGoH4wGOlvyvaRHMGvbXH+8Bw== X-Received: by 2002:a17:902:8bc4:b029:12b:8470:e29e with SMTP id r4-20020a1709028bc4b029012b8470e29emr11693028plo.2.1629082780746; Sun, 15 Aug 2021 19:59:40 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:17b8:f07a:2a52:317a]) by smtp.gmail.com with UTF8SMTPSA id r14sm9374864pff.106.2021.08.15.19.59.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Aug 2021 19:59:40 -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 v5 5/7] dma-iommu: Check CONFIG_SWIOTLB more broadly Date: Mon, 16 Aug 2021 11:57:53 +0900 Message-Id: <20210816025755.2906695-6-stevensd@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816025755.2906695-1-stevensd@google.com> References: <20210816025755.2906695-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 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index f7da4934f7e6..bad813d63ea6 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,7 +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) && + if (IS_ENABLED(CONFIG_SWIOTLB) && dev_use_swiotlb(dev) && iova_offset(iovad, phys | size)) { void *padding_start; size_t padding_size; @@ -975,7 +980,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)) @@ -1047,7 +1052,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