Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp182781pxj; Tue, 15 Jun 2021 23:26:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLfRCBDIBNzvUSKTJoAuNeENarTTah9ai1yCQ5CgG9XUZ906DVGze0WS9mXvfe6eF4wHkZ X-Received: by 2002:a17:906:fcb0:: with SMTP id qw16mr3625722ejb.269.1623824788493; Tue, 15 Jun 2021 23:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623824788; cv=none; d=google.com; s=arc-20160816; b=W1WDGuZeLvSOn41KOAwBZLToy0IPJEFrh+Cld1wu8VzxF71utTmLWErteh5BDOK2l1 m1ss+ognWvqoUhlIbX11IUItMVV6XIKE+XstKVLz1FQZ0QvtGChaTXPuUJ3L/Tc5Czgh +kZ/iFiaI26USbrePCSnDmyNJCacji/gKZq+12Ba9Z9VKaEwSnyBg2x7QHdsLlM8buO4 MZICVi+CWYcvib7MYNG5VY2Mell22PeglM65EWlXUg55NhLbS212x1Kj/5qy56HgaEp/ A7dHw59qVMi1Qg7Z4vCxAVAZ0uiX+qX7lomLbsJT2SycMbepW/T8kwd/730MgCdrPSnh I03Q== 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=yx1sBUKg2SZ/J5oPuuLxuIdituaRXED8so7Vw8sLIws=; b=M7Qvox1yMznA3pEHX3VUj4Ydw8ic+W8wWPwlkc8TUpRF8r7zxOq9iTcbxhzG3HmwRz D5PfHkhGqc8XpgN2IAVzrBVQ4Gtoe/eLb0p9sFI0A32Zyy3TF2nGdl9kuHgWGp+Ym53s g1j1qZs3Iz3QWASoPDnTsnR9TE1I+pV/pZbm1UWUyl6Zvlz392cu7oCo2Q/DQZ1xZ+C9 98hpPgtzdbT5PkIFcMeFdI/kmQ7zAd+E6w4yV2Y1ZR5q4x1UONQLnatX6jRqaiRQVuxl bJ2sRycY3YTiTnpRqwOTKCglPf0S0WQuSsHzZPnvrZangL1/CC9LcSoNY+JatwYOgjT3 SHYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Q4K6eTyw; 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 ar15si1393065ejc.146.2021.06.15.23.26.06; Tue, 15 Jun 2021 23:26:28 -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=Q4K6eTyw; 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 S231460AbhFPGZH (ORCPT + 99 others); Wed, 16 Jun 2021 02:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231468AbhFPGZG (ORCPT ); Wed, 16 Jun 2021 02:25:06 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 470FEC061760 for ; Tue, 15 Jun 2021 23:23:01 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id g6so1367497pfq.1 for ; Tue, 15 Jun 2021 23:23:01 -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=yx1sBUKg2SZ/J5oPuuLxuIdituaRXED8so7Vw8sLIws=; b=Q4K6eTywavWHh5xBRTV2Sn1QN0pqm21rAHVV9HUXv/UP1w8xNe4Z5udU+NX1vgnB1+ c3YMRhLko40t5PNbJ2OEaPKxiaHUl4VjZBfqy96tFVH3Qfa8f64z0y648a814QEkXJ8w S/rgJ3x7L88xW9cuGs4qk0A1P9NST1SKpuLUA= 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=yx1sBUKg2SZ/J5oPuuLxuIdituaRXED8so7Vw8sLIws=; b=dKKS8b8V+j5TKX8QMjTGgBiCazy8Lkn9BMT+aTKQrUJPgQg+iYtKT1th79rv8PDv6K ungMulm0jAIQlCPVsYijDdkPge6e652q6xa3BWgVHs0OC/A+vI+1wQP0TiiLEhFZZe+s Uk/qTNoJbOap+CKEXfIArKRw+w4maU+OyXxbGOQTk5pAdX2R1S1P9zBF/SGTNtjYztpD 4VlTBsJQCHvxdhu+oGOOBBUuVsGrMrmsX1qlGNgt4PvNPUUkRS+7vKIgXpOC+xetre2B GVpjoJ5ySZ0CYaWviQQWAkOhL6qVGAipYiQdfJjmDx7BufJfk76ZNoV7qqdsn4CyUxLW 5CPw== X-Gm-Message-State: AOAM531xB8KSXW//ZD+Y1VPeJm8Esx6Kzy+wTWm3ztnIh3HJ5Mqq06Mm +OD5oqXYOQiKHRW3FIqSNS+gMw== X-Received: by 2002:a63:4719:: with SMTP id u25mr3506046pga.193.1623824580858; Tue, 15 Jun 2021 23:23:00 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id f18sm4233834pjq.48.2021.06.15.23.22.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23:00 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski Cc: benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS" , sstabellini@kernel.org, Robin Murphy , grant.likely@arm.com, xypron.glpk@gmx.de, Thierry Reding , mingo@kernel.org, bauerman@linux.ibm.com, peterz@infradead.org, Greg KH , Saravana Kannan , "Rafael J . Wysocki" , heikki.krogerus@linux.intel.com, Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, xen-devel@lists.xenproject.org, Nicolas Boichat , Jim Quinlan , tfiga@chromium.org, bskeggs@redhat.com, bhelgaas@google.com, chris@chris-wilson.co.uk, tientzu@chromium.org, daniel@ffwll.ch, airlied@linux.ie, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, jani.nikula@linux.intel.com, jxgao@google.com, joonas.lahtinen@linux.intel.com, linux-pci@vger.kernel.org, maarten.lankhorst@linux.intel.com, matthew.auld@intel.com, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Subject: [PATCH v12 06/12] swiotlb: Use is_swiotlb_force_bounce for swiotlb data bouncing Date: Wed, 16 Jun 2021 14:21:51 +0800 Message-Id: <20210616062157.953777-7-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-1-tientzu@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Propagate the swiotlb_force into io_tlb_default_mem->force_bounce and use it to determine whether to bounce the data or not. This will be useful later to allow for different pools. Signed-off-by: Claire Chang --- include/linux/swiotlb.h | 11 +++++++++++ kernel/dma/direct.c | 2 +- kernel/dma/direct.h | 2 +- kernel/dma/swiotlb.c | 4 ++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index dd1c30a83058..8d8855c77d9a 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -84,6 +84,7 @@ extern enum swiotlb_force swiotlb_force; * unmap calls. * @debugfs: The dentry to debugfs. * @late_alloc: %true if allocated using the page allocator + * @force_bounce: %true if swiotlb bouncing is forced */ struct io_tlb_mem { phys_addr_t start; @@ -94,6 +95,7 @@ struct io_tlb_mem { spinlock_t lock; struct dentry *debugfs; bool late_alloc; + bool force_bounce; struct io_tlb_slot { phys_addr_t orig_addr; size_t alloc_size; @@ -109,6 +111,11 @@ static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr) return mem && paddr >= mem->start && paddr < mem->end; } +static inline bool is_swiotlb_force_bounce(struct device *dev) +{ + return dev->dma_io_tlb_mem->force_bounce; +} + void __init swiotlb_exit(void); unsigned int swiotlb_max_segment(void); size_t swiotlb_max_mapping_size(struct device *dev); @@ -120,6 +127,10 @@ static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr) { return false; } +static inline bool is_swiotlb_force_bounce(struct device *dev) +{ + return false; +} static inline void swiotlb_exit(void) { } diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 7a88c34d0867..a92465b4eb12 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -496,7 +496,7 @@ size_t dma_direct_max_mapping_size(struct device *dev) { /* If SWIOTLB is active, use its maximum mapping size */ if (is_swiotlb_active(dev) && - (dma_addressing_limited(dev) || swiotlb_force == SWIOTLB_FORCE)) + (dma_addressing_limited(dev) || is_swiotlb_force_bounce(dev))) return swiotlb_max_mapping_size(dev); return SIZE_MAX; } diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h index 13e9e7158d94..4632b0f4f72e 100644 --- a/kernel/dma/direct.h +++ b/kernel/dma/direct.h @@ -87,7 +87,7 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev, phys_addr_t phys = page_to_phys(page) + offset; dma_addr_t dma_addr = phys_to_dma(dev, phys); - if (unlikely(swiotlb_force == SWIOTLB_FORCE)) + if (is_swiotlb_force_bounce(dev)) return swiotlb_map(dev, phys, size, dir, attrs); if (unlikely(!dma_capable(dev, dma_addr, size, true))) { diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 101abeb0a57d..b5a9c4c0b4db 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -179,6 +179,10 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, mem->end = mem->start + bytes; mem->index = 0; mem->late_alloc = late_alloc; + + if (swiotlb_force == SWIOTLB_FORCE) + mem->force_bounce = true; + spin_lock_init(&mem->lock); for (i = 0; i < mem->nslabs; i++) { mem->slots[i].list = IO_TLB_SEGSIZE - io_tlb_offset(i); -- 2.32.0.272.g935e593368-goog