Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8460271imu; Tue, 4 Dec 2018 08:42:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/UDbF//zMj/nsjIvuKCyYXJrarbEzeo4JQQ8/LIUFBArhjHV0nQ3TXAeI5Y3eZngGJGHBUM X-Received: by 2002:a17:902:4025:: with SMTP id b34mr20906281pld.181.1543941749891; Tue, 04 Dec 2018 08:42:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543941749; cv=none; d=google.com; s=arc-20160816; b=SDmHr80aeikpAX1Mw0XHpf4wMi++RhohbQl+1mwmLkvuFDRmsawcyQEa7tAbw6xLTT FH62uBEPQJDI3s4EQrnfF9tmp28Ix/jozsWJI2dDs7Au/+XL3ajSG+cMQ+9q/wuhnJK0 AsFHEpaRAoS0SNBDqjkH4Xx/vtC9zlJcsSjpXLqgA9A3/TpLQYI4bmEHVBn5X13xR8qm y0VZPhybE/wHJqcDRjst5YeEPewmOuYFApsJcuvo2SeUFdC3TzlHJWlux7GwZGcksvjZ 4mXoLFKDCKyOIjFXl/HTJnqBa8QyDqoKe5Hi5m9tNFOTDYpqcEX87EG+Y2FPlq+7y6tp gADA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=wRsuy4UYn8GDU4sGrWu3HxR4btFoW7Vng00cfkw/Dow=; b=icaHr7Xe9pwKAZSfHHq1abpOK5n7tYZkhyEBLlm4a3KOyHwtr8v9SEQnjQhn2XwvXy KgfdEVPRq3xso1Enx9JZFGHZuFxgwib9rJ9MNvOlKiz8khpBHfdPpBJIw75aKZSWuPZZ wGuAAozI6r4AND7F4Vco9L9ZLbgKToRYcf8ADnltas+PjPKcCZ+wqL4JdsWcd7tzG46Y WlMfyU8b5oby7HbcMLpX5/TlDlrfi99YQZibwoEgEEKXkVxtLlDlcmCwo4UmihTf2CWc RWp5keu5Lomc5PudGiMGGI98x5/8CF40JYGi5bYLaNKk7H+ZHoekVnRKKIhzQ4Ya02as 1MAw== 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 f61si19256927plb.51.2018.12.04.08.42.12; Tue, 04 Dec 2018 08:42:29 -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 S1726988AbeLDQlX (ORCPT + 99 others); Tue, 4 Dec 2018 11:41:23 -0500 Received: from foss.arm.com ([217.140.101.70]:36710 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726367AbeLDQlW (ORCPT ); Tue, 4 Dec 2018 11:41:22 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5A52CA78; Tue, 4 Dec 2018 08:41:22 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 28F673F614; Tue, 4 Dec 2018 08:41:22 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 862C81AE0BA0; Tue, 4 Dec 2018 16:41:42 +0000 (GMT) Date: Tue, 4 Dec 2018 16:41:42 +0000 From: Will Deacon To: Nicolas Boichat Cc: Robin Murphy , Joerg Roedel , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Christoph Lameter , Vlastimil Babka , Michal Hocko , linux-mm@kvack.org, Yong Wu , Matthias Brugger , Tomasz Figa , yingjoe.chen@mediatek.com, hch@infradead.org, Matthew Wilcox Subject: Re: [PATCH v3, RFC] iommu/io-pgtable-arm-v7s: Use page_frag to request DMA32 memory Message-ID: <20181204164142.GA8520@arm.com> References: <20181204082300.95106-1-drinkcat@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181204082300.95106-1-drinkcat@chromium.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 04, 2018 at 04:23:00PM +0800, Nicolas Boichat wrote: > 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 tables, ensure GFP_DMA32 is used if CONFIG_ZONE_DMA32 > is defined (e.g. on arm64 platforms). > > For level 2 tables (1 KB), we use page_frag to allocate these pages, > as we cannot directly use kmalloc (no slab cache for GFP_DMA32) or > kmem_cache (mm/ code treats GFP_DMA32 as an invalid flag). > > One downside is that we only free the allocated page if all the > 4 fragments (4 IOMMU L2 tables) are freed, but given that we > usually only allocate limited number of IOMMU L2 tables, this > should not have too much impact on memory usage: In the absolute > worst case (4096 L2 page tables, each on their own 4K page), > we would use 16 MB of memory for 4 MB of L2 tables. > > 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 > --- > > As an alternative to the series [1], which adds support for GFP_DMA32 > to kmem_cache in mm/. IMHO the solution in [1] is cleaner and more > efficient, as it allows freed fragments (L2 tables) to be reused, but > this approach does not require any core change. > > [1] https://patchwork.kernel.org/cover/10677529/, 3 patches > > drivers/iommu/io-pgtable-arm-v7s.c | 32 ++++++++++++++++-------------- > 1 file changed, 17 insertions(+), 15 deletions(-) > > diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c > index 445c3bde04800c..0de6a51eb6755f 100644 > --- a/drivers/iommu/io-pgtable-arm-v7s.c > +++ b/drivers/iommu/io-pgtable-arm-v7s.c > @@ -161,6 +161,12 @@ > > #define ARM_V7S_TCR_PD1 BIT(5) > > +#ifdef CONFIG_ZONE_DMA32 > +#define ARM_V7S_TABLE_GFP_DMA GFP_DMA32 > +#else > +#define ARM_V7S_TABLE_GFP_DMA GFP_DMA > +#endif We may as well include __GFP_ZERO in here too. Anyway, this looks alright to me: Acked-by: Will Deacon But it sounds like you're still on the fence about this patch, so I won't pick it up unless you ask explicitly. Will