From nobody Thu Oct 30 22:49:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1760519629; cv=none; d=zohomail.com; s=zohoarc; b=Ibm8BdsEtGhd/7L9ZjftEDGC3pE4RBNOUhdS5LtwBA+zcNtW4HTfaEKAbBdPU97XdcNMoUTuxPW5zL+9fVofGpMTpSjML5y7o6HLiTSFy9mOxqkMyMuNbZNOkGcKNkCM17gsU81rR/fKrpApbyMQJNmiWLlhy/qT3ZQdB6cK5B8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760519629; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UkOLY0bMOAegRX2PLwNVc1xekduhJqcvNYaejGV6Jnk=; b=VAVIQNqYmGD+/tNdVodZlzNUGujSFO/rW2Ph/j4+Lf5UUxu/xgPVx6FXgvG1Uj7ZYGeG9ORQxma4/cEqOrD5KaMuDm1ZNnYZ+N/9pM7zkbm+sUmInNcFKka4+2bwlUWFwfOSEJ6dVbXOrgkCr7012UzSrJ2qvyeBSeYzI8z6KIM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 176051962985241.346909012153674; Wed, 15 Oct 2025 02:13:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1143387.1477140 (Exim 4.92) (envelope-from ) id 1v8xZV-0003lM-Nw; Wed, 15 Oct 2025 09:13:25 +0000 Received: by outflank-mailman (output) from mailman id 1143387.1477140; Wed, 15 Oct 2025 09:13:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v8xZV-0003lF-Kr; Wed, 15 Oct 2025 09:13:25 +0000 Received: by outflank-mailman (input) for mailman id 1143387; Wed, 15 Oct 2025 09:13:25 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v8xZV-0002lR-4x for xen-devel@lists.xenproject.org; Wed, 15 Oct 2025 09:13:25 +0000 Received: from sea.source.kernel.org (sea.source.kernel.org [2600:3c0a:e001:78e:0:1991:8:25]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 333ee8c7-a9a7-11f0-9d15-b5c5bf9af7f9; Wed, 15 Oct 2025 11:13:24 +0200 (CEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id EFF4940246; Wed, 15 Oct 2025 09:13:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27DE5C19421; Wed, 15 Oct 2025 09:13:22 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 333ee8c7-a9a7-11f0-9d15-b5c5bf9af7f9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760519602; bh=VnMG1AI6BvgRLCN60ENFie/apQCA7LYrL0xFWoo7RpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qIrMBqnuHuFqyNXyGEUvjAWSrGuP7BHKNjv3W6RybkmzvAtE/8s4IA/VJ9GgZGWEB 7bm6DuwWphduE+9B2nQ+hsAaoABhi1mvrnEwifkp0w0oOcXl5GDl8SFAl/4Hsn2XU3 qHwmOdQ7pqCuYsn/djnTr4K19DmpdZaqVnSDdvaMvNqskBH0ZJwkuOQDubU0sCtpq5 W+VFnqQwdlPVM8EnzBLjjI3VgMDfGi1EtCEG8d7wYwOwwWXwNpe/pcGzB9IKEGu2uL HHQzw8zSVXRKXjzRor9TvOjzpRxPPnksJzz0TpmzYizTMT+05dps2oNMrK/FjdOH2y mqyatvpalS22Q== From: Leon Romanovsky To: Marek Szyprowski , Robin Murphy , Russell King , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Richard Henderson , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Geoff Levand , "David S. Miller" , Andreas Larsson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, xen-devel@lists.xenproject.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, Jason Gunthorpe , Jason Gunthorpe Subject: [PATCH v5 05/14] xen: swiotlb: Switch to physical address mapping callbacks Date: Wed, 15 Oct 2025 12:12:51 +0300 Message-ID: <20251015-remove-map-page-v5-5-3bbfe3a25cdf@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251015-remove-map-page-v5-0-3bbfe3a25cdf@kernel.org> References: <20251015-remove-map-page-v5-0-3bbfe3a25cdf@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.15-dev Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1760519631806154100 From: Leon Romanovsky Combine resource and page mappings routines to one function and remove .map_resource/.unmap_resource callbacks completely. Reviewed-by: Jason Gunthorpe Signed-off-by: Leon Romanovsky --- drivers/xen/swiotlb-xen.c | 63 ++++++++++++++++++++++---------------------= ---- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index dd7747a2de87..ccf25027bec1 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -200,17 +200,32 @@ xen_swiotlb_free_coherent(struct device *dev, size_t = size, void *vaddr, * physical address to use is returned. * * Once the device is given the dma address, the device owns this memory u= ntil - * either xen_swiotlb_unmap_page or xen_swiotlb_dma_sync_single is perform= ed. + * either xen_swiotlb_unmap_phys or xen_swiotlb_dma_sync_single is perform= ed. */ -static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *pa= ge, - unsigned long offset, size_t size, - enum dma_data_direction dir, +static dma_addr_t xen_swiotlb_map_phys(struct device *dev, phys_addr_t phy= s, + size_t size, enum dma_data_direction dir, unsigned long attrs) { - phys_addr_t map, phys =3D page_to_phys(page) + offset; - dma_addr_t dev_addr =3D xen_phys_to_dma(dev, phys); + dma_addr_t dev_addr; + phys_addr_t map; =20 BUG_ON(dir =3D=3D DMA_NONE); + + if (attrs & DMA_ATTR_MMIO) { + if (unlikely(!dma_capable(dev, phys, size, false))) { + dev_err_once( + dev, + "DMA addr %pa+%zu overflow (mask %llx, bus limit %llx).\n", + &phys, size, *dev->dma_mask, + dev->bus_dma_limit); + WARN_ON_ONCE(1); + return DMA_MAPPING_ERROR; + } + return phys; + } + + dev_addr =3D xen_phys_to_dma(dev, phys); + /* * If the address happens to be in the device's DMA window, * we can safely return the device addr and not worry about bounce @@ -257,13 +272,13 @@ static dma_addr_t xen_swiotlb_map_page(struct device = *dev, struct page *page, =20 /* * Unmap a single streaming mode DMA translation. The dma_addr and size m= ust - * match what was provided for in a previous xen_swiotlb_map_page call. A= ll + * match what was provided for in a previous xen_swiotlb_map_phys call. A= ll * other usages are undefined. * * After this call, reads by the cpu to the buffer are guaranteed to see * whatever the device wrote there. */ -static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_ad= dr, +static void xen_swiotlb_unmap_phys(struct device *hwdev, dma_addr_t dev_ad= dr, size_t size, enum dma_data_direction dir, unsigned long attrs) { phys_addr_t paddr =3D xen_dma_to_phys(hwdev, dev_addr); @@ -325,7 +340,7 @@ xen_swiotlb_sync_single_for_device(struct device *dev, = dma_addr_t dma_addr, =20 /* * Unmap a set of streaming mode DMA translations. Again, cpu read rules - * concerning calls here are the same as for swiotlb_unmap_page() above. + * concerning calls here are the same as for swiotlb_unmap_phys() above. */ static void xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int ne= lems, @@ -337,7 +352,7 @@ xen_swiotlb_unmap_sg(struct device *hwdev, struct scatt= erlist *sgl, int nelems, BUG_ON(dir =3D=3D DMA_NONE); =20 for_each_sg(sgl, sg, nelems, i) - xen_swiotlb_unmap_page(hwdev, sg->dma_address, sg_dma_len(sg), + xen_swiotlb_unmap_phys(hwdev, sg->dma_address, sg_dma_len(sg), dir, attrs); =20 } @@ -352,8 +367,8 @@ xen_swiotlb_map_sg(struct device *dev, struct scatterli= st *sgl, int nelems, BUG_ON(dir =3D=3D DMA_NONE); =20 for_each_sg(sgl, sg, nelems, i) { - sg->dma_address =3D xen_swiotlb_map_page(dev, sg_page(sg), - sg->offset, sg->length, dir, attrs); + sg->dma_address =3D xen_swiotlb_map_phys(dev, sg_phys(sg), + sg->length, dir, attrs); if (sg->dma_address =3D=3D DMA_MAPPING_ERROR) goto out_unmap; sg_dma_len(sg) =3D sg->length; @@ -392,25 +407,6 @@ xen_swiotlb_sync_sg_for_device(struct device *dev, str= uct scatterlist *sgl, } } =20 -static dma_addr_t xen_swiotlb_direct_map_resource(struct device *dev, - phys_addr_t paddr, - size_t size, - enum dma_data_direction dir, - unsigned long attrs) -{ - dma_addr_t dma_addr =3D paddr; - - if (unlikely(!dma_capable(dev, dma_addr, size, false))) { - dev_err_once(dev, - "DMA addr %pad+%zu overflow (mask %llx, bus limit %llx).\n", - &dma_addr, size, *dev->dma_mask, dev->bus_dma_limit); - WARN_ON_ONCE(1); - return DMA_MAPPING_ERROR; - } - - return dma_addr; -} - /* * Return whether the given device DMA address mask can be supported * properly. For example, if your device can only drive the low 24-bits @@ -437,13 +433,12 @@ const struct dma_map_ops xen_swiotlb_dma_ops =3D { .sync_sg_for_device =3D xen_swiotlb_sync_sg_for_device, .map_sg =3D xen_swiotlb_map_sg, .unmap_sg =3D xen_swiotlb_unmap_sg, - .map_page =3D xen_swiotlb_map_page, - .unmap_page =3D xen_swiotlb_unmap_page, + .map_phys =3D xen_swiotlb_map_phys, + .unmap_phys =3D xen_swiotlb_unmap_phys, .dma_supported =3D xen_swiotlb_dma_supported, .mmap =3D dma_common_mmap, .get_sgtable =3D dma_common_get_sgtable, .alloc_pages_op =3D dma_common_alloc_pages, .free_pages =3D dma_common_free_pages, .max_mapping_size =3D swiotlb_max_mapping_size, - .map_resource =3D xen_swiotlb_direct_map_resource, }; --=20 2.51.0