Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9103954imu; Tue, 4 Dec 2018 21:50:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/WrosryDa3pVEf5V9mCqvYkzVcsxfcU/bGL4UBq8YCshP6C54EOhFwPEIcuIlpzeCPiYkvC X-Received: by 2002:a65:4049:: with SMTP id h9mr19066830pgp.304.1543989013562; Tue, 04 Dec 2018 21:50:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543989013; cv=none; d=google.com; s=arc-20160816; b=yqe/0mr/PZ6WnUOyigDy0kbN69cBqf6hpvyOwsy33xaWJnXjPzddqTD4EjUAHz6KuM J1FfsaL0y8YtvCRDrLMxiNJGhEwW4L3ea/P/iBKxJodtQtedZ4U91Fp2MbjXjCTC0vss 916yunn6mBWrlfb9fb/471tfipKCnI+tLV5AwJxQ3ZWMd8dZQ74C/y/VqfWv4xDaDoUA bE7JrvqUU232w7gqPVvvRL6u1Y2DnsPN40vfntozWL8lUE/gZe4jpqhyBsy4wrnVCr4M 3g4E3Bi7RlIWcgzFUDtUzkgu01tokLdGZnfbmnqRiJjfFd+Rnd4z8pvbfZ7SV2CSoTdD s3NQ== 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=vWhAhLkOVslUb8AGYpRlcTEDGRqYlnK33vbjofTVSKg=; b=sXHps5GKPxj8MasFuBg2dMb5lYuIOhnGGQHUjdKep/bWFcunF5GnxzgpFLN8+RQ7cm XyBnn3h0N0IUmu4LLRYFMHZ6Tt0MDwJ6kzzCxhTjdebMnIgnvHCjLE6OGiT5OkJOwFNV TU+f7UTb4c/lFFtwp/gA1EI+Fxf7KR//9rU6PF6b6gJXhM8rkMl3yXbZLZd3AldJALP7 Neb820PRhIf7k/DAoWm3rN2yprJDVeYm8SFA9dBoNl/V9/ENXd3vXbgDB5NPU9TXQ/xy JQirha7eGMZuK1qvPY7cN5DWMqrvkI37JAoDYGOVy0BUIQNxOSjMaMqHumcXvE7n/Z1D UQCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ghvx7Srz; 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 d5si14800945pla.361.2018.12.04.21.49.58; Tue, 04 Dec 2018 21:50:13 -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=Ghvx7Srz; 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 S1727074AbeLEFs7 (ORCPT + 99 others); Wed, 5 Dec 2018 00:48:59 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:36582 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726092AbeLEFs6 (ORCPT ); Wed, 5 Dec 2018 00:48:58 -0500 Received: by mail-pl1-f193.google.com with SMTP id g9so9523694plo.3 for ; Tue, 04 Dec 2018 21:48:58 -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=vWhAhLkOVslUb8AGYpRlcTEDGRqYlnK33vbjofTVSKg=; b=Ghvx7SrzrvOWt9iw9+n5jZ87Tl7UOaD02HoAC3peGH3KyiLo3niR48nxltOOoNpikP AXmdTlvLOzKrhtYVVs6NFLm5qNAqhe/Pw0Xcp6dwMzbyvMW5RPBAcWGEnKb508AfoBlt iwIXiQWvM4l59LTcMGKwE6VDaNtnpp7RulPmg= 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=vWhAhLkOVslUb8AGYpRlcTEDGRqYlnK33vbjofTVSKg=; b=FYYr90GUDAVM8unaqO1SDPZqmECFRPAaRgFHW9/9E+EPDldY5ByTZ2PYCLuB75VD9F Ovu4qw954Kwyoj5XPbsX1+i9L2XS8VToisFVC7FsJMNZMPY2MHdx/QldIXTejooItabl Bge/EidRJm92rJv8pLZmV+SL+nGS2yoUGKJV6eC7Dk9KG9Tf5xGhyoTUIogNPA5sB8Yw L8wTLhdc1QtuDSZg2XcqtSoliVDL9nZzVbtHnuVfso1pCkBzShLvuSfiIYFGTfhzLIen u8PwafYKHmhDaVgslw3lRAxGrCdWnAaT3g4pkZyXnXGGQvzTo4sL+hU/uIn0wqXxVz0b uGbw== X-Gm-Message-State: AA+aEWb0y3VzB1phJkVeUdzBpw3KmSx0XHLwUtFJ78mIwyxdjEXKLbiw aquajq54Tvl1IQcAOXL2wTsX8g== X-Received: by 2002:a17:902:2468:: with SMTP id m37mr4041699plg.314.1543988938116; Tue, 04 Dec 2018 21:48:58 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:f659:7f17:ea11:4e8e]) by smtp.gmail.com with ESMTPSA id 4sm30806513pfq.10.2018.12.04.21.48.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 21:48:57 -0800 (PST) From: Nicolas Boichat To: Will Deacon Cc: Robin Murphy , 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, hch@infradead.org, Matthew Wilcox Subject: [PATCH v4 3/3] iommu/io-pgtable-arm-v7s: Request DMA32 memory, and improve debugging Date: Wed, 5 Dec 2018 13:48:28 +0800 Message-Id: <20181205054828.183476-4-drinkcat@chromium.org> X-Mailer: git-send-email 2.20.0.rc1.387.gf8505762e3-goog In-Reply-To: <20181205054828.183476-1-drinkcat@chromium.org> References: <20181205054828.183476-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 IOMMUs using ARMv7 short-descriptor format require page tables (level 1 and 2) to be allocated within the first 4GB of RAM, even on 64-bit systems. 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 v2: - Commit message (v3 used the page_frag approach) 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.20.0.rc1.387.gf8505762e3-goog