Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp596247pxb; Fri, 13 Aug 2021 01:55:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+AR8J3ZcsadzNMt+0niw/r0U6BWC0tbMEoX3FbtTOpU7/LF6HWxgPDThcb5WzvPrVlH9s X-Received: by 2002:aa7:d3cf:: with SMTP id o15mr1751490edr.98.1628844943989; Fri, 13 Aug 2021 01:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628844943; cv=none; d=google.com; s=arc-20160816; b=zf/rLOxFLgQ2ZRbw6ckfYhyRHPI6Ccnze9Aqo0BleOq/90jjifB4MoERXWb4MUzLWl lpoksXzCt+SWW6aFOGSqg/E3R4UT6CHXR72pvxdm0Z7B7uVzqNP8nQMFZwFnYorEFXrE JglDNwgfmzYEIV0M+FasnWS5W2VR+3yk2PXz662LbkzLIES+UWCL/edJEryT7tp79Cb2 l5HJBzzunRnXi3dsh+mrjm2n4EteJo1iVUA2mCDkGy4PgmqF0L3KWU3lA63JbhuRsRlG AGxvy1GDvKh8C/g5n9icFr7v5eojLbfIl6rOvOu77ZVSJzLV6nyDLiX394DbEgrmKeQG w4zg== 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=39hkNmw6o7Z0mNIDijrFuXQ77XHiAZfo7UkU2TVoZZI=; b=Fh+qJoP4evQc9wSZvMEeAfAHFgHdqQE/4aBxo9eemY9PAWu3HYYKh1c+kZ4SwbRSV/ XyJnA33v5/TSLVPXKLJIjPTEsbR/8Zf2xH0/6e4un9+1wLO20yhIhfeepu7NFCJj4cif nBQtQxwHIHqDS30+qR7lyA7/R9akJjm80xOcx9qqKoJCmZ1PZkf3gGYzV0JIm49mPml8 QaOJ+EjEOYh87hkXFQ+Dm4iqlP/+GwaETXFb1fu+hCvfn96ioBaaWRACp7N/s/FVDAvZ XrkGz4ed1qnw7SF1hcwRYUspXYeUizUK7aXDPN/A2kG/VELhrzgbnYESR2HVM+GuGf5Z s02A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YfA1LumM; 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 h15si986323eja.338.2021.08.13.01.55.20; Fri, 13 Aug 2021 01:55:43 -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=YfA1LumM; 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 S239696AbhHMHqN (ORCPT + 99 others); Fri, 13 Aug 2021 03:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239042AbhHMHoA (ORCPT ); Fri, 13 Aug 2021 03:44:00 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2D3CC061224 for ; Fri, 13 Aug 2021 00:42:48 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id e19so10776935pla.10 for ; Fri, 13 Aug 2021 00:42:48 -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=39hkNmw6o7Z0mNIDijrFuXQ77XHiAZfo7UkU2TVoZZI=; b=YfA1LumMveWEilLmwpuS8MN4XSqv9UJi0P7hqJauNlaSRr4OULvU+AtHTS2Pi72Gn4 j1cwRAofyqssx4rJ3xp/bofOFanP7pUehmxPRR/JKrs94zNmuiJhjbaRgjCDsFUPjRYb A+61dBnjw+5gMT1efXHKQ7V8lcMjcUjAcUJ2Y= 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=39hkNmw6o7Z0mNIDijrFuXQ77XHiAZfo7UkU2TVoZZI=; b=q9vklRDQte1V7oYDXwxP1gtHfLwPxn5g7UUoQsjdBLgbGdPgcbl8M/BE6ww2YyiZvY O6kDU309JGFXMPl8hewGyo6IVDupsi0rKtKXgVXJHGb1UkqE/trp3L+BBuB4xUISppN1 NTPle1pPEKYtXoaL8dwNcmNmWqwuSQLHMVnKkwgEjdU31GpJrwIF+S8jwWIFfFVaYIli suiUuCtzRIcKhyF7y2IJvS1u/7KTQBjL6S14bI/eAml7HoMlWQUDUoDXWRCzJUXMNSOS NSVD0Sv/xNlrSujXV9EXwk9limMOsMUmtmsjbkFcgfUpjzUacZyOmV5ROMTVhyNEKrGd +Rng== X-Gm-Message-State: AOAM530xDSUIezn6DkAYqafLFH/H92zdFr08rCOP249Ro0WcTqh30uqv PxlzmhkhxTo07RjdaEOLrSz0Pw== X-Received: by 2002:a63:a511:: with SMTP id n17mr1217056pgf.156.1628840568515; Fri, 13 Aug 2021 00:42:48 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:cbc8:5998:527e:5f43]) by smtp.gmail.com with UTF8SMTPSA id u190sm1173679pfb.95.2021.08.13.00.42.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Aug 2021 00:42:48 -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 v4 4/6] dma-iommu: Check CONFIG_SWIOTLB more broadly Date: Fri, 13 Aug 2021 16:38:37 +0900 Message-Id: <20210813073839.1562438-5-stevensd@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210813073839.1562438-1-stevensd@google.com> References: <20210813073839.1562438-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 --- 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