From patchwork Mon Mar 4 19:59:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 159585 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp4154356jad; Mon, 4 Mar 2019 12:00:56 -0800 (PST) X-Google-Smtp-Source: APXvYqwYx6txx6UOBWjRpJi53gdapO/8wT43pnSpTqLgGwLhaKArZgbWyqG+JcWLTUI5YhU7hFLO X-Received: by 2002:a17:902:7798:: with SMTP id o24mr22181471pll.212.1551729655963; Mon, 04 Mar 2019 12:00:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551729655; cv=none; d=google.com; s=arc-20160816; b=amL6VA9Ni2LYL+DexszL9IEVqcMayU6Esb/itxED9EmNDYtbimA8cbLXAu2l4rFPsA jY8UtkWNjWEVu+Aja29LiQVC8l9TrHSShMGq4sR2grYgcqroBT0lhPPiP3WLnldfmrXa WRdcO8YopuJoAzqDN91/G+0gt2IsdU6ClamuPba8ZBdtE1y/p+9diSvepBNcssUtHeM1 zEVEJfjtTMYqasuouiz+BuwXmY3quIY3dXRFaTYbrBvjV4BNmieEY23Pojs4yGQ035+M LjzxEWelvGI9JaN9/CPI5kkMT46a0rBzWM+mzr3F8fmi4bWEQPTbZP+4rA3XucI46O5u IlLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=bXo2AvEDqbBywJ2/r+gNj4T9yt6bBhoUGZYJVd+LgFs=; b=guI+txb+3DIV7oalrDI0yuZsn4kSTwHKF26EnpVKtaWDJWpJv7r8d1qnuY5qD/xwUq IRsi5BfiksqLGGDTfUYLfHfWqwK5zqADLp3aXZljdMmoapYWlgOW5qm6aISsWU9gmjfG A/npar1RZDTOGYuUwrEr8ZxSlYiMQu8w2P7G6LE/HrUwQmUoSX5wuaUfigN+VCoXWgNu QfE/zU2nRZEHoHG8enauqbIvmZHuw89rRw0K7XEC5SqIuTMMq2lq1belRsKseaXhrTeB ugDw5muZ5X+PNLRb5EXqNX6c/g9QcfNxjk1AIhi0+lsD69AwXxmMaKg4wW0J+yloMPeb IP2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h7si6061107pll.172.2019.03.04.12.00.55; Mon, 04 Mar 2019 12:00:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726436AbfCDUAy (ORCPT + 31 others); Mon, 4 Mar 2019 15:00:54 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:47069 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726038AbfCDUAx (ORCPT ); Mon, 4 Mar 2019 15:00:53 -0500 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.129]) with ESMTPA (Nemesis) id 1M2OEw-1gy9vZ29nS-003r1z; Mon, 04 Mar 2019 20:59:55 +0100 From: Arnd Bergmann To: Konrad Rzeszutek Wilk , Boris Ostrovsky , Juergen Gross , Christoph Hellwig , Marek Szyprowski Cc: Arnd Bergmann , Stefano Stabellini , Robin Murphy , Mike Rapoport , Andrew Morton , Joerg Roedel , xen-devel@lists.xenproject.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH] Revert "swiotlb: remove SWIOTLB_MAP_ERROR" Date: Mon, 4 Mar 2019 20:59:03 +0100 Message-Id: <20190304195951.1118807-1-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:oKzDNU8DH2UnV62YSntTNjreQfXMO+Px9S/SDQxFFaCgzjoour3 T1Ymdle+3p1Re9yaMA3kI7vy6LYlUiZ7aG67KLdH98LCm0w4HZPF86gWg02Q18xWTO4KCLW NcYjWfX6l0ZHbC9vqs2nzrCW3/ZktwED6vOFrdmh9uO3vHWSE9srEJ8aKaB1bNLsq/dQR4N myGSYE5Ke2sEeku88MNfg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:pEc3eJfWFzI=:ZoKfOofzlwVpnLTyG7fwsJ Iifc2JeswfHJuEMwo6pX2jP2DgVfTgGOfBb8uqYtLupfau8l1sgNzLVCiAsJhIKdeAwfG8mze jtqB+Vnvfxwh+UX1EKqfEh8SG+vAlaZg7BnvDsg96NEPjwabYn6hZRB97+RGYbU0QF5cBzLqP gOwOCff/bHLi9YX/0nlydknS6SR1/216+aetb9Vj16zk44IzHpr0qgsvQVfhcejeReirGKzKD Luw1/nV0lEXoX7uDj6hSsp6MpbOA7ALoyy42Wiokzt0HcX5CToWKXJCY+lnfuvcecCgR0B7iO 1E78EUlgphhHpTf7QO2ttWuPH8qftjpavm94X32wArj0U5l5rV0TNVriP4WYsbt3ABQwvp+Jk H/oiPB7UNeN6ypXcXLQ4CCM0bVYHBmfkYfRz3Zuuq02GPIj+7CFc1rNdl8JCrHnjkD+Bo2FFZ t74+vNMNy0vSONsHHTKzM1h0HijyXsCb048QiBr9uS7HgGGhGF1uZtPHfWTRNO3nvhDYEGt08 /WXPBzTe2eZpTFzE4Mq3wDniECT8kJnWQWOR/Zzj/C/oEImlUJQoPipKp7NhEKib29PWSwPH8 KaVOtiNzHmXfjHd7Z0oAXsDgkEjwz9aVfqgnV4Hq6F7Bu86xCDSdbUJ837UPmxuCcPWWQ+PHm MgP/9uBlBBJ0noUlR6oC+nBzlJrsar904VPdn6vHsnW0fhVXz9W7iqhdNJpmFrrul49TGAc8V mzbntpGlGoFQmxKln4ft1+6s7mDsw8TW5dej+Q== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This reverts commit b907e20508d0 ("swiotlb: remove SWIOTLB_MAP_ERROR"), which introduced an overflow warning in configurations that have a larger dma_addr_t than phys_addr_t: In file included from include/linux/dma-direct.h:5, from kernel/dma/swiotlb.c:23: kernel/dma/swiotlb.c: In function 'swiotlb_tbl_map_single': include/linux/dma-mapping.h:136:28: error: conversion from 'long long unsigned int' to 'phys_addr_t' {aka 'unsigned int'} changes value from '18446744073709551615' to '4294967295' [-Werror=overflow] #define DMA_MAPPING_ERROR (~(dma_addr_t)0) ^ kernel/dma/swiotlb.c:544:9: note: in expansion of macro 'DMA_MAPPING_ERROR' return DMA_MAPPING_ERROR; The configuration that caused this is on 32-bit ARM, where the DMA address space depends on the enabled hardware platforms, while the physical address space depends on the type of MMU chosen (classic vs LPAE). I tried a couple of alternative approaches, but the previous version seems as good as any other, so I went back to that. Fixes: b907e20508d0 ("swiotlb: remove SWIOTLB_MAP_ERROR") Signed-off-by: Arnd Bergmann --- drivers/xen/swiotlb-xen.c | 4 ++-- include/linux/swiotlb.h | 3 +++ kernel/dma/swiotlb.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) -- 2.20.0 diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 877baf2a94f4..57a98279bf4f 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -406,7 +406,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, map = swiotlb_tbl_map_single(dev, start_dma_addr, phys, size, dir, attrs); - if (map == DMA_MAPPING_ERROR) + if (map == SWIOTLB_MAP_ERROR) return DMA_MAPPING_ERROR; dev_addr = xen_phys_to_bus(map); @@ -557,7 +557,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, sg_phys(sg), sg->length, dir, attrs); - if (map == DMA_MAPPING_ERROR) { + if (map == SWIOTLB_MAP_ERROR) { dev_warn(hwdev, "swiotlb buffer is full\n"); /* Don't panic here, we expect map_sg users to do proper error handling. */ diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 361f62bb4a8e..a65a36551f58 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -44,6 +44,9 @@ enum dma_sync_target { SYNC_FOR_DEVICE = 1, }; +/* define the last possible byte of physical address space as a mapping error */ +#define SWIOTLB_MAP_ERROR (~(phys_addr_t)0x0) + extern phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, dma_addr_t tbl_dma_addr, phys_addr_t phys, size_t size, diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 12059b78b631..922880b84387 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -541,7 +541,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, spin_unlock_irqrestore(&io_tlb_lock, flags); if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes)\n", size); - return DMA_MAPPING_ERROR; + return SWIOTLB_MAP_ERROR; found: io_tlb_used += nslots; spin_unlock_irqrestore(&io_tlb_lock, flags); @@ -659,7 +659,7 @@ bool swiotlb_map(struct device *dev, phys_addr_t *phys, dma_addr_t *dma_addr, /* Oh well, have to allocate and map a bounce buffer. */ *phys = swiotlb_tbl_map_single(dev, __phys_to_dma(dev, io_tlb_start), *phys, size, dir, attrs); - if (*phys == DMA_MAPPING_ERROR) + if (*phys == SWIOTLB_MAP_ERROR) return false; /* Ensure that the address returned is DMA'ble */