Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1005307pxj; Thu, 17 Jun 2021 19:57:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0fZ2S+/fFkKd5kAVj53bWs+AL7lHEguax1Gdofk1+18bjRD61swBcZMAWqRpxEcv9uz6b X-Received: by 2002:a17:906:b2cb:: with SMTP id cf11mr8605786ejb.448.1623985056017; Thu, 17 Jun 2021 19:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623985056; cv=none; d=google.com; s=arc-20160816; b=E6RLB5rwgXRunHn2m8jA+qaNg1qgaIPOHqG3Z6jft2B7+GpgigbQRDC0EpJMCCj6WB RSgpO9d3jY6rqEevqcGT1qweUdMztz4fs3HapqPakYxDpXTuznx1zf87LDeSZYJ3Qm5J bPBXiZNmuBXbwRP7w/3ZKxQLAb/2Y8s+RMs35WejfFwJ5KqFgDDPF3CfReY1JyIVOPlx VqbsQ7oFfqjFfBaPfaOG/11A2UhHV0Y4UA6rcK/IAmYg7fsVDt/IItqM68rOd5HajdOr bqs2Dg2opISf2svQ7LdM6rUiq2IGFGBn2z+SxST+6b7k08VR8BcauF83Ivku8ufMD8o7 f4YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=pO+yyAwxfaxa3zPHchiMm6x7dhQuZj/Ixz4cT/0My1g=; b=IBVL2Whwcc2YkhhPcEeh+b83cyzEEbWJgSopEVeuRm4CWDx159Vxo/tLqpCgClHyx+ kCgeiAQLiRTE1++AAIkStqI9x1Jk/JqbK6YnI89zVAjZBOniW0B72ai6IM7vmJbCWCWN k2svjvgajaorBDL0VHL+4dPIgwgul6GhrTGbsbej4lFKF8SPO5BZ3E90YEA1mlTWcm/W HC9lEqy9GU40oZDnG0LxJdtViqletlp/kKdZO1cZh7VxlKwMu5aQrmCwvYoQcTUmfvK4 KWXgi0u2rScYH7Pha0mudTltFR4ub4Zoi5NPKHbYsjCWo+P0EeG51R+toYo11oLK8CEQ wRpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L3nKu5Hm; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc38si1059086ejc.708.2021.06.17.19.57.13; Thu, 17 Jun 2021 19:57:36 -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=@kernel.org header.s=k20201202 header.b=L3nKu5Hm; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232695AbhFQXdB (ORCPT + 99 others); Thu, 17 Jun 2021 19:33:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:48492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232665AbhFQXdA (ORCPT ); Thu, 17 Jun 2021 19:33:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EC0DB6117A; Thu, 17 Jun 2021 23:30:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623972652; bh=zT1qdWU1gzmRyGeh30JGyHfeH/5dy6E64TCLRTPOMuQ=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=L3nKu5Hm2ncrIKOEaFTf+2fL0fh6USJhIFnbQA9qkk03x89Y1npCLAh/mGQJh5jgS pnnSruyh6mX3z3Is7HGD+08WcJ0DnFnBawbI2rFKKmajFf1FEQ37ybp7Nq3v8pjbh0 NHrvEDTsIOxk4nTYvYmiUcCNBuL4M/XxImwe4e8lhtE6D3K7hOlD4JIdGP+kIOALnw 5Scct4vYV5ZtSH09JchbACRHQNDYN1A3YXySJYHgErO3JUbn5qo9xkJbr5DFsapWSj o+frwhth6wJ1B4JrC45X+H0+WpZAVkNuIox4TsHm6lkmMwlV+YZDFHxdVI/S5CtGI5 B7G21AS9iH6ZA== Date: Thu, 17 Jun 2021 16:30:50 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Claire Chang cc: 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 , 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, 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: Re: [PATCH v13 03/12] swiotlb: Set dev->dma_io_tlb_mem to the swiotlb pool used In-Reply-To: <20210617062635.1660944-4-tientzu@chromium.org> Message-ID: References: <20210617062635.1660944-1-tientzu@chromium.org> <20210617062635.1660944-4-tientzu@chromium.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Jun 2021, Claire Chang wrote: > Always have the pointer to the swiotlb pool used in struct device. This > could help simplify the code for other pools. > > Signed-off-by: Claire Chang > Reviewed-by: Christoph Hellwig > Tested-by: Stefano Stabellini > Tested-by: Will Deacon Acked-by: Stefano Stabellini > --- > drivers/base/core.c | 4 ++++ > include/linux/device.h | 4 ++++ > kernel/dma/swiotlb.c | 8 ++++---- > 3 files changed, 12 insertions(+), 4 deletions(-) > > diff --git a/drivers/base/core.c b/drivers/base/core.c > index f29839382f81..cb3123e3954d 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -27,6 +27,7 @@ > #include > #include > #include > +#include > #include > #include /* for dma_default_coherent */ > > @@ -2736,6 +2737,9 @@ void device_initialize(struct device *dev) > defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) > dev->dma_coherent = dma_default_coherent; > #endif > +#ifdef CONFIG_SWIOTLB > + dev->dma_io_tlb_mem = io_tlb_default_mem; > +#endif > } > EXPORT_SYMBOL_GPL(device_initialize); > > diff --git a/include/linux/device.h b/include/linux/device.h > index ba660731bd25..240d652a0696 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -416,6 +416,7 @@ struct dev_links_info { > * @dma_pools: Dma pools (if dma'ble device). > * @dma_mem: Internal for coherent mem override. > * @cma_area: Contiguous memory area for dma allocations > + * @dma_io_tlb_mem: Pointer to the swiotlb pool used. Not for driver use. > * @archdata: For arch-specific additions. > * @of_node: Associated device tree node. > * @fwnode: Associated device node supplied by platform firmware. > @@ -518,6 +519,9 @@ struct device { > #ifdef CONFIG_DMA_CMA > struct cma *cma_area; /* contiguous memory area for dma > allocations */ > +#endif > +#ifdef CONFIG_SWIOTLB > + struct io_tlb_mem *dma_io_tlb_mem; > #endif > /* arch specific additions */ > struct dev_archdata archdata; > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > index 2dba659a1e73..de79e9437030 100644 > --- a/kernel/dma/swiotlb.c > +++ b/kernel/dma/swiotlb.c > @@ -340,7 +340,7 @@ void __init swiotlb_exit(void) > static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t size, > enum dma_data_direction dir) > { > - struct io_tlb_mem *mem = io_tlb_default_mem; > + struct io_tlb_mem *mem = dev->dma_io_tlb_mem; > int index = (tlb_addr - mem->start) >> IO_TLB_SHIFT; > unsigned int offset = (tlb_addr - mem->start) & (IO_TLB_SIZE - 1); > phys_addr_t orig_addr = mem->slots[index].orig_addr; > @@ -431,7 +431,7 @@ static unsigned int wrap_index(struct io_tlb_mem *mem, unsigned int index) > static int find_slots(struct device *dev, phys_addr_t orig_addr, > size_t alloc_size) > { > - struct io_tlb_mem *mem = io_tlb_default_mem; > + struct io_tlb_mem *mem = dev->dma_io_tlb_mem; > unsigned long boundary_mask = dma_get_seg_boundary(dev); > dma_addr_t tbl_dma_addr = > phys_to_dma_unencrypted(dev, mem->start) & boundary_mask; > @@ -508,7 +508,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr, > size_t mapping_size, size_t alloc_size, > enum dma_data_direction dir, unsigned long attrs) > { > - struct io_tlb_mem *mem = io_tlb_default_mem; > + struct io_tlb_mem *mem = dev->dma_io_tlb_mem; > unsigned int offset = swiotlb_align_offset(dev, orig_addr); > unsigned int i; > int index; > @@ -559,7 +559,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, > size_t mapping_size, enum dma_data_direction dir, > unsigned long attrs) > { > - struct io_tlb_mem *mem = io_tlb_default_mem; > + struct io_tlb_mem *mem = hwdev->dma_io_tlb_mem; > unsigned long flags; > unsigned int offset = swiotlb_align_offset(hwdev, tlb_addr); > int index = (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT; > -- > 2.32.0.288.g62a8d224e6-goog >