Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2687778pxa; Mon, 17 Aug 2020 16:42:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZQUNqqmlc3j+nQUPI26gpXJmtrNBr8UyBC2dtYPthpxveXrv1Uv7AOmAh3w1yBuoYnQ64 X-Received: by 2002:a17:906:403:: with SMTP id d3mr17248274eja.522.1597707736497; Mon, 17 Aug 2020 16:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597707736; cv=none; d=google.com; s=arc-20160816; b=IarGZHLCFJnBgOz2hyIBVBh3LPtGcpbk62n0E2Sa9OrbA4UzAtYRsjoj7AJE5ad3FY 25rq7wDkM4XASSGVNQWy9JZSn3OEpa+YHmzCN6FFd9GlFWKUXCVFCWDMIbz95YgGqn5h X0kBcVKvSG0+BA6hIs0AgmC/xzug0VwSaFNrdxKjHQNi+o+owp7I1BFZprll1j1LnInW MPlhh+HvTBDUM0vRpAuymBgFbs/4rSBmmUBx04Huu1Wj4Va1h6EftDFtUuVZncHlbpZb /31rDEXhwBM4gKqjo+rACSNuyuKOExo82GtqaTm4LN6F9dLkwRlJ3ZG0Nd+enXNA7rJ3 Dhwg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RjgwGRxdBS3CJp5E+JEkyraM8vOppBs1YDLxTK5wbyg=; b=tjVq1dHBTwBSMuxJxe3t7XY3SfWO3bVjmbYrZLF50kviW5cPLmCi0k+79VDhkD7fsm sXi9/6ygzyWr3IOoVfW0a7JVswpDzPxEpupIpoObj8MreBAaqxlPoKx1qMO77/n+ZqbZ KPbkQ8eyIGyU/N1qAkd0QZGygJcMqutLjL+Qc/QVzAjRPxalTsGkPE9iHzJLlWiUYNgE TYRekJv37FdKxyE7AUilFtQHM13pD/QH2sCG4F9aCFUHZ4oKf+rD7hZLme7WG/pEBXIn u3rfeG/N1nSI2XLSlClVoCaS8yqt2iSya0NPyBi7UJiNIEPhgti6ozpSjK3TpEYFTBGW /MZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="UxWjW/D7"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fx18si12148183ejb.235.2020.08.17.16.41.53; Mon, 17 Aug 2020 16:42:16 -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=@gmail.com header.s=20161025 header.b="UxWjW/D7"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726694AbgHQXlH (ORCPT + 99 others); Mon, 17 Aug 2020 19:41:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbgHQXk7 (ORCPT ); Mon, 17 Aug 2020 19:40:59 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 910DCC061389 for ; Mon, 17 Aug 2020 16:40:59 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id x12so13873241qtp.1 for ; Mon, 17 Aug 2020 16:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RjgwGRxdBS3CJp5E+JEkyraM8vOppBs1YDLxTK5wbyg=; b=UxWjW/D7rIwoPmW420O/n0NNF2zEDTI34NFG87JTiOdOvC5B3kQxYtmdI62uwMRemR koDJdeZn0jAMWHHk5IzB2JfCsnZZ9uJ/TWwEDbLBbMcjdGqk3ad3IJeN4VQMJ49rZhMh mY5L/jyj1WGawxCrVwsH1n+zzg5h3HPonmKBwJSYbj2nW9YtC7l0dwV8yvnZy2+PT/yf fEKOCKbyR8PbwIlwm0t3YxZyRgL/u1Sn1TE9aCCtXnnm3bgQu5Ir9Qehma05SMTIM/YV O6QAvmh+g/gmVldFeNusreKYPq3c1FlFQU62KLjYpNmtdGnlLVKq+h+UkkQA0ZVk+aPa O1Yg== 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=RjgwGRxdBS3CJp5E+JEkyraM8vOppBs1YDLxTK5wbyg=; b=MfMMkCn2Hlmn0K+0AS8ypti4zFrP0sKy/TjcQqpSwWmF05Vu8JV7HvK2kKAY4smjV7 fJIUvsAjjNw2CZIPplNA77Q3bqWtANAgKP0+wsC2EavU+IAyyZsrnuMj+cWwWOCPiGOy gYCZem+7pmvJItm3upL6ZcFs5Pkdp/kMzoIXQc7XMiVZgL/Of8XRVhSb1C5tLjMvD+b2 F5H7pSPymHRIiEb0oW6RvyDcYq+Z9dYG8Y6QUrR9kz4j1W/5x3sBU2INH4969CGNCCXS nSxvXpNe58eDwXWEVwfewI3e89e/Y3WJMTae4AUSCRCzzo62GJyd1oRpMdMmHMyZPpC5 +1uw== X-Gm-Message-State: AOAM531oaG/lQXswjGDnovkP0fZIJradKdDL12wbQKWkaP9SpL1kCpMP EgGf9lP8nBGyUsz8rSP+EUc= X-Received: by 2002:aed:36c8:: with SMTP id f66mr15680464qtb.6.1597707658747; Mon, 17 Aug 2020 16:40:58 -0700 (PDT) Received: from LeoBras.ibmuc.com ([177.35.193.93]) by smtp.gmail.com with ESMTPSA id w58sm22342868qth.95.2020.08.17.16.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 16:40:58 -0700 (PDT) From: Leonardo Bras To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alexey Kardashevskiy , Christophe Leroy , Leonardo Bras , Joel Stanley , Thiago Jung Bauermann , Ram Pai , Brian King , Murilo Fossa Vicentini , David Dai Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 02/10] powerpc/kernel/iommu: Align size for IOMMU_PAGE_SIZE on iommu_*_coherent() Date: Mon, 17 Aug 2020 20:40:25 -0300 Message-Id: <20200817234033.442511-3-leobras.c@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200817234033.442511-1-leobras.c@gmail.com> References: <20200817234033.442511-1-leobras.c@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both iommu_alloc_coherent() and iommu_free_coherent() assume that once size is aligned to PAGE_SIZE it will be aligned to IOMMU_PAGE_SIZE. Update those functions to guarantee alignment with requested size using IOMMU_PAGE_ALIGN() before doing iommu_alloc() / iommu_free(). Also, on iommu_range_alloc(), replace ALIGN(n, 1 << tbl->it_page_shift) with IOMMU_PAGE_ALIGN(n, tbl), which seems easier to read. Signed-off-by: Leonardo Bras --- arch/powerpc/kernel/iommu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index 9704f3f76e63..d7086087830f 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -237,10 +237,9 @@ static unsigned long iommu_range_alloc(struct device *dev, } if (dev) - boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1, - 1 << tbl->it_page_shift); + boundary_size = IOMMU_PAGE_ALIGN(dma_get_seg_boundary(dev) + 1, tbl); else - boundary_size = ALIGN(1UL << 32, 1 << tbl->it_page_shift); + boundary_size = IOMMU_PAGE_ALIGN(1UL << 32, tbl); /* 4GB boundary for iseries_hv_alloc and iseries_hv_map */ n = iommu_area_alloc(tbl->it_map, limit, start, npages, tbl->it_offset, @@ -858,6 +857,7 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl, unsigned int order; unsigned int nio_pages, io_order; struct page *page; + size_t size_io = size; size = PAGE_ALIGN(size); order = get_order(size); @@ -884,8 +884,9 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl, memset(ret, 0, size); /* Set up tces to cover the allocated range */ - nio_pages = size >> tbl->it_page_shift; - io_order = get_iommu_order(size, tbl); + size_io = IOMMU_PAGE_ALIGN(size_io, tbl); + nio_pages = size_io >> tbl->it_page_shift; + io_order = get_iommu_order(size_io, tbl); mapping = iommu_alloc(dev, tbl, ret, nio_pages, DMA_BIDIRECTIONAL, mask >> tbl->it_page_shift, io_order, 0); if (mapping == DMA_MAPPING_ERROR) { @@ -900,11 +901,11 @@ void iommu_free_coherent(struct iommu_table *tbl, size_t size, void *vaddr, dma_addr_t dma_handle) { if (tbl) { - unsigned int nio_pages; + size_t size_io = IOMMU_PAGE_ALIGN(size, tbl); + unsigned int nio_pages = size_io >> tbl->it_page_shift; - size = PAGE_ALIGN(size); - nio_pages = size >> tbl->it_page_shift; iommu_free(tbl, dma_handle, nio_pages); + size = PAGE_ALIGN(size); free_pages((unsigned long)vaddr, get_order(size)); } -- 2.25.4