Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2806482imu; Sun, 11 Nov 2018 01:06:44 -0800 (PST) X-Google-Smtp-Source: AJdET5e3sh7MHz4lpVCHZnE2z0tFOmxT8Ld2CKMSXqjo3nD6+00IpN2tCmzoACy+jPChkLu4GL3Y X-Received: by 2002:a17:902:6b82:: with SMTP id p2-v6mr15708797plk.50.1541927204481; Sun, 11 Nov 2018 01:06:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541927204; cv=none; d=google.com; s=arc-20160816; b=y979DuknqFMmEYH31Eq6ASiWTErcmE4Y9aXA0aqEBiqFX69MWoN5JwPl8w+pbf1EoB zl267XiwQjsPRpA1Fe8DW4UQiKVZ3rgFtWJiZWFo0x0fNcq/wINRTGgeUbp38cf0eVvj F/C1WGrFSkTo9zil5LCn3DrVM69stG6VokP7YVhUyjxuwcH/SD6lU1ia6jQ2bbm+fXGO NHjdP1iLnHn7K3FLvimC4u+TEM9/sOG2Wr3n8ub+vla4Xbyxvxx+ramp8QIc5t6QA+Hh R37Vc+Jwdv7/5jrO5gp4z0Dh2W8HqbHILT7n2dtWbeA0gVeKASTOsj1wZ8U4Zua27YTJ mWJA== 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=J3drSXNEQad/j7zI+ID7YdbI6KhfStGY6vScO313iR4=; b=KKQqWF3N1X4DJWQ+e3QCtxeHwbichWkZsAWR3Hu/grAbFnknjLeoRnk4klaoULcMok ML1PhvAlhTueCBI4ThSRi6qY1o1bG+mqwELSxwqlP5CWThUBbCcW1FjOrgoznLZX3ZJa 4TRAnE/5sPC9GI9ZMXCTFLJ9zw9uQECGGBXUsXpdGnVJ3+3vV10sJdpJd/ffP9OYa/Fo 0SHY6lj3EftX72k7LR3b2JnEF7iDqtzPAqEH2Tco2NPRsv5rUgmTGtMuH3WC7eaOaMNX lpvxAACUaUumN4wbjLRHCsqfCkOswnDEeY/rJ+m1XLh063vNzcd20CPlYf+steOj1pjr +PJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DcjG9kTD; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o14-v6si11972237pgi.52.2018.11.11.01.06.29; Sun, 11 Nov 2018 01:06:44 -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; dkim=pass header.i=@chromium.org header.s=google header.b=DcjG9kTD; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727727AbeKKSwP (ORCPT + 99 others); Sun, 11 Nov 2018 13:52:15 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38083 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727334AbeKKSwO (ORCPT ); Sun, 11 Nov 2018 13:52:14 -0500 Received: by mail-pg1-f194.google.com with SMTP id f8-v6so2696670pgq.5 for ; Sun, 11 Nov 2018 01:04:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J3drSXNEQad/j7zI+ID7YdbI6KhfStGY6vScO313iR4=; b=DcjG9kTDXB4SQ7VqcCMrX/L11oHaZNfPg9bG1SMflAXtx7Sdu1dqaoGyXOCoJ27tqZ TXk+rgHoUJbj9EsRYITf58Qh9ZhpgwOmxbxRHsI9hfkN3Wuw3up8qbfLy+xDMg7VZc+c e1b6fwI4rwon3DJdb6ZCA5AYTpsyukkQJdy20= 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=J3drSXNEQad/j7zI+ID7YdbI6KhfStGY6vScO313iR4=; b=NBXhWAPfawWEYRXJ64AYWU/WFbZVhth/1cxra6vZlf3ru/9t6lBebsYgRHIj0Schcz r+MfmYCaLdMCgTiEneLIz9dEPMPrcY3x13cKv5Wx47yoDvWAUvh50dxS36NMVINi/FAU 8qeM7FcShrEvT/TVI6N10p9d9CzTpLawlaCBGzGv6NTxeyAxjD9b9NNzE5AHwN6ID7Hv CYJ9gt2k/NxrvOcgGaiswb1k8kv4C2MxK9SgmQJx1MJhQYrAHaVIciLj8j3QjBlJHuXf UzxVyl8erUZ7+sAglFHBXJE628fstSwEbEX91zJJnWJiT/3uZjGSW/sMbEzw0Pjx+/qD oBNw== X-Gm-Message-State: AGRZ1gL+bKNxpdOI8muwnni4HU5c6wLIHwTducY+7Ky7q5Z0dAo9CEPy 08gEjvSkUHPQlvK5NEUs6tZdwg== X-Received: by 2002:a63:f141:: with SMTP id o1mr13637587pgk.134.1541927054240; Sun, 11 Nov 2018 01:04:14 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:f659:7f17:ea11:4e8e]) by smtp.gmail.com with ESMTPSA id 69sm8107956pgg.86.2018.11.11.01.04.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Nov 2018 01:04:13 -0800 (PST) From: Nicolas Boichat To: Robin Murphy Cc: Will Deacon , Joerg Roedel , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Michal Hocko , Mel Gorman , Levin Alexander , Huaisheng Ye , Mike Rapoport , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yong Wu , Matthias Brugger , Tomasz Figa , yingjoe.chen@mediatek.com Subject: [PATCH v2 3/3] iommu/io-pgtable-arm-v7s: Request DMA32 memory, and improve debugging Date: Sun, 11 Nov 2018 17:03:41 +0800 Message-Id: <20181111090341.120786-4-drinkcat@chromium.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181111090341.120786-1-drinkcat@chromium.org> References: <20181111090341.120786-1-drinkcat@chromium.org> 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 For level 1/2 pages, ensure GFP_DMA32 is used if CONFIG_ZONE_DMA32 is defined (e.g. on arm64 platforms). For level 2 pages, allocate a slab cache in SLAB_CACHE_DMA32. Also, print an error when the physical address does not fit in 32-bit, to make debugging easier in the future. Fixes: ad67f5a6545f ("arm64: replace ZONE_DMA with ZONE_DMA32") Signed-off-by: Nicolas Boichat --- Changes since v1: - Changed approach to use SLAB_CACHE_DMA32 added by the previous commit. - Use DMA or DMA32 depending on the architecture (DMA for arm, DMA32 for arm64). drivers/iommu/io-pgtable-arm-v7s.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index 445c3bde04800c..996f7b6d00b44a 100644 --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -161,6 +161,14 @@ #define ARM_V7S_TCR_PD1 BIT(5) +#ifdef CONFIG_ZONE_DMA32 +#define ARM_V7S_TABLE_GFP_DMA GFP_DMA32 +#define ARM_V7S_TABLE_SLAB_CACHE SLAB_CACHE_DMA32 +#else +#define ARM_V7S_TABLE_GFP_DMA GFP_DMA +#define ARM_V7S_TABLE_SLAB_CACHE SLAB_CACHE_DMA +#endif + typedef u32 arm_v7s_iopte; static bool selftest_running; @@ -198,13 +206,17 @@ static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp, void *table = NULL; if (lvl == 1) - table = (void *)__get_dma_pages(__GFP_ZERO, get_order(size)); + table = (void *)__get_free_pages( + __GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size)); else if (lvl == 2) - table = kmem_cache_zalloc(data->l2_tables, gfp | GFP_DMA); + table = kmem_cache_zalloc(data->l2_tables, + gfp | ARM_V7S_TABLE_GFP_DMA); phys = virt_to_phys(table); - if (phys != (arm_v7s_iopte)phys) + if (phys != (arm_v7s_iopte)phys) { /* Doesn't fit in PTE */ + dev_err(dev, "Page table does not fit in PTE: %pa", &phys); goto out_free; + } if (table && !(cfg->quirks & IO_PGTABLE_QUIRK_NO_DMA)) { dma = dma_map_single(dev, table, size, DMA_TO_DEVICE); if (dma_mapping_error(dev, dma)) @@ -737,7 +749,7 @@ static struct io_pgtable *arm_v7s_alloc_pgtable(struct io_pgtable_cfg *cfg, data->l2_tables = kmem_cache_create("io-pgtable_armv7s_l2", ARM_V7S_TABLE_SIZE(2), ARM_V7S_TABLE_SIZE(2), - SLAB_CACHE_DMA, NULL); + ARM_V7S_TABLE_SLAB_CACHE, NULL); if (!data->l2_tables) goto out_free_data; -- 2.19.1.930.g4563a0d9d0-goog