Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2704825ybi; Mon, 17 Jun 2019 09:14:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOmDn7jsv2rJg5nPwCKCwtye7lglEtTb5EaYtir6BIGGeyUG6ok3jd7R+daebPYBYnYHLN X-Received: by 2002:a63:3008:: with SMTP id w8mr50449513pgw.11.1560788040682; Mon, 17 Jun 2019 09:14:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560788040; cv=none; d=google.com; s=arc-20160816; b=WwQZpF5M32VuY9iq6M0+41r2PAWyP6g2j9HfG2bUwDXV+WHkTYSuVSo1uP2bGU84Qe DNAdqPlOgpAESjsTw+ZctH7cMxaV6RUv23CfTvpAMo+h42n74P6lt957pQAD5Z7inLbs +bAJQNIqBB2FrCQvOwnBSXuO4XK2dO7SBobgUfMSKrUaPzgft31fd0Gn+lm52yJeQh9Y +/6asz2WdRCNKnQUYevaquac7WDC6HHQ4LZB8SS2brL6Aw+cQp/oFYD+Mb5j9KuciOAr ykyMRagod7e+IYpVXBBDuFQz9wEW1gKpdxiUqnCxw2Hx1aHqtrNXYb84mVsUjgXympXs NZQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=ZrjkUwXGjx0IKNanz9otizHcydIMik7sTY8s4o5Mthw=; b=YHCXqE7b7qH7KWtsJEJrewqQM02bP9jEjvVcr161LJBRZya/e8ElMlYW9gHYEr3/3M PPJWuQuqLWAM16ILaYI6V0sqwZbqb2aYW2AXCOhm5NQoEa76B1uaJafLsiaiCbY1gT/L odQctwpbYBxAQkeXAnGIb0MxIvpi4ydYyTKR5KOHC2PpdxO2B+izzfIRY0jWQI43C57o Q3OX8FyF806RuL+7XTAdQEEQ31d+BShrRxYbJ6EKupK2vQOHFVxDj5892UXG9IkaEuEP Io/YvJpVRFPJBqxTVdS8jzFeuJzrsS3slLpojIu/WNBufog2Si4vlIQA/YSHX4oyscHN LPBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=esXlFkxz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n34si10333618pld.202.2019.06.17.09.13.44; Mon, 17 Jun 2019 09:14:00 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=esXlFkxz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbfFQQNT (ORCPT + 99 others); Mon, 17 Jun 2019 12:13:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:52950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726005AbfFQQNT (ORCPT ); Mon, 17 Jun 2019 12:13:19 -0400 Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A8C43208C0; Mon, 17 Jun 2019 16:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560787998; bh=WA5c9iulOrWKZC8nW/LSFI3RRwdwSMrmm9TPJb30RtA=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=esXlFkxzVe8OeQHrYcltCZb0SHCfcXUzCjMFDK71KIBrBw3fcKKyw2awU7xkaBWXi P5Cb/zukHo9q+8f0j6PjgLmzy+ue2MPDNoYGSY07b+AfBWMs3q8jtU1/STDRzL1f9Q s1Ucv1S7DZW1BS21uQS90ptCfj9qWOGZzb5QSKLE= Date: Mon, 17 Jun 2019 09:13:16 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Arnd Bergmann cc: Christoph Hellwig , Marek Szyprowski , Jesper Dangaard Brouer , Konrad Rzeszutek Wilk , Boris Ostrovsky , Juergen Gross , 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: Re: [PATCH] swiotlb: fix phys_addr_t overflow warning In-Reply-To: <20190617132946.2817440-1-arnd@arndb.de> Message-ID: References: <20190617132946.2817440-1-arnd@arndb.de> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 17 Jun 2019, Arnd Bergmann wrote: > On architectures that have a larger dma_addr_t than phys_addr_t, > the swiotlb_tbl_map_single() function truncates its return code > in the failure path, making it impossible to identify the error > later, as we compare to the original value: > > kernel/dma/swiotlb.c:551:9: error: implicit conversion from 'dma_addr_t' (aka 'unsigned long long') to 'phys_addr_t' (aka 'unsigned int') changes value from 18446744073709551615 to 4294967295 [-Werror,-Wconstant-conversion] > return DMA_MAPPING_ERROR; > > Use an explicit typecast here to convert it to the narrower type, > and use the same expression in the error handling later. > > Fixes: b907e20508d0 ("swiotlb: remove SWIOTLB_MAP_ERROR") > Signed-off-by: Arnd Bergmann Acked-by: Stefano Stabellini > --- > I still think that reverting the original commit would have > provided clearer semantics for this corner case, but at least > this patch restores the correct behavior. > --- > drivers/xen/swiotlb-xen.c | 2 +- > kernel/dma/swiotlb.c | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index d53f3493a6b9..cfbe46785a3b 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -402,7 +402,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 == (phys_addr_t)DMA_MAPPING_ERROR) > return DMA_MAPPING_ERROR; > > dev_addr = xen_phys_to_bus(map); > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > index e906ef2e6315..a3be651973ad 100644 > --- a/kernel/dma/swiotlb.c > +++ b/kernel/dma/swiotlb.c > @@ -548,7 +548,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, > if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) > dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes), total %lu (slots), used %lu (slots)\n", > size, io_tlb_nslabs, tmp_io_tlb_used); > - return DMA_MAPPING_ERROR; > + return (phys_addr_t)DMA_MAPPING_ERROR; > found: > io_tlb_used += nslots; > spin_unlock_irqrestore(&io_tlb_lock, flags); > @@ -666,7 +666,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 == (phys_addr_t)DMA_MAPPING_ERROR) > return false; > > /* Ensure that the address returned is DMA'ble */ > -- > 2.20.0 >