Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp650379imu; Fri, 9 Nov 2018 03:58:52 -0800 (PST) X-Google-Smtp-Source: AJdET5eByGDXHmK/9RB/uaQKYiXomN/c9VS5evmKzHRIciyeKqGHM1+OnecL2qvmPt4jKsoi7DL7 X-Received: by 2002:a65:664e:: with SMTP id z14-v6mr6906693pgv.347.1541764732051; Fri, 09 Nov 2018 03:58:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541764732; cv=none; d=google.com; s=arc-20160816; b=GLdtKdRo9VCkTl8DzCY3R2SDHZL5ytzwh9wv58YgDj5DRaMJAaagw6dW7Fccg0sJpI WvLOpm8mjqgDj0bKfvK4TTu6P3Rodmwv0tnFLKVUq9gk1lN4gg1/1rWafL6VtH3bGZyr rWTA9l9lPEQ5fyEscPM8oPFlmKKMN9gne+xpFYjXhLbtlkE9vfInU7ddVEb+2FvAm1qC RmUOxy1m1xUXmbCPPdJ9Wh8DVuAep+xkI6xcKVl9nDZWy5A6H866KZcqc4XHWzXBCrhm J7G4zULpKaBe8emTYmhlN3QRpvT2t4BJXB4gQLC12m5JK+34WerT/MwgLbni5AAuJB8u pI7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oj0qv3KwGcTOa1sp7yqXD7mcastYXWlmJMO9yoT5yBg=; b=TtizBlJQZnoYTjN6D0hoIWe+aj+hLhLJEey+m+4NJmtYxsTNfNKFjI7wOUjQLaRpNW NYCO6QRQCo2eNIAFGIvwaB+5qxU2alON2vK0F9fOy3bS00CJLHPMVeAh4wqFihYe2+B1 PtL3RgskpLs2mf1fauU7n+kiL5q/9YBNuSLPqF3GlOd9t41izbQbBXcQz3yZj1ovrlTB bTdHsYExb2GHSg1yoL1fk15LfhYdJZBqsGcEczfOtAUt2QvJiWFpqg8t7QDU36EM5Rek wR3JeBwjTKh7vlEgxBiAG0owjSo9NSFC8jwapP+FyL7V5v1b30NmFd+fXyqUso1K/WBu kp6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mKQeO+1V; 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 l4-v6si8247819plb.258.2018.11.09.03.58.36; Fri, 09 Nov 2018 03:58:52 -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=mKQeO+1V; 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 S1728402AbeKIViW (ORCPT + 99 others); Fri, 9 Nov 2018 16:38:22 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33119 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727560AbeKIViW (ORCPT ); Fri, 9 Nov 2018 16:38:22 -0500 Received: by mail-pg1-f194.google.com with SMTP id q5-v6so781758pgv.0 for ; Fri, 09 Nov 2018 03:58:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oj0qv3KwGcTOa1sp7yqXD7mcastYXWlmJMO9yoT5yBg=; b=mKQeO+1VwBJSyA3ZwMybJc9inoblqXuxzryQ3DP0yj3ClE3ppXhRhMEJSSymn65OJ2 kr1cNXCvonXdZXeGkrxZ8S+9weqisvigKiIEdCl6sxjHa6bZ9IZtKxozYgJvsJU202GX zcke2SzDNP8ty/58D6TFKva8x4LdfFJYHe6BU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oj0qv3KwGcTOa1sp7yqXD7mcastYXWlmJMO9yoT5yBg=; b=ZVtJk3cJlXFwPowhkV/OyZjnVRu+it3tOh2gEXaZb9yRTsIzBb9Pntpn26VwYMuH0b 5U6UkP6DZG/DwxQGPwCSiu6nA9acmtl+50T9hcOIl+KGGqFGZrmZ7reNnpidmQmPwzgb /lh/agmlEtFQbRxzgeJZhpurl9VzhI+R9IfO6oEKDCd2XltBTT24i7A9wNpvwNdIvinK eTfMFXGz1TxcQh/mHbfT1Ea/YpNYske5mXj2oGtRjoZ7SVMg+Q4LgjmLaF09YZqXk7ve HpshUNKVHzotsQSplgKVeI95GDLKqSuLcwJa5djBNjUpOWxrmC/cWrndfoBgPywTguzm iF5Q== X-Gm-Message-State: AGRZ1gIxGhfqZnisYc0lgUXxunyhtmJ9UK+tHujG8F6ZiVXng3VsgFm0 nQZ81MDD0IWYcP9+SblMuU7j7rP2fO5P3ltZJiNK/A== X-Received: by 2002:a62:4251:: with SMTP id p78-v6mr8737695pfa.72.1541764683280; Fri, 09 Nov 2018 03:58:03 -0800 (PST) MIME-Version: 1.0 References: <20181109082448.150302-1-drinkcat@chromium.org> <20181109082448.150302-2-drinkcat@chromium.org> <00afe803-22dd-5a75-70aa-dda0c7752470@suse.cz> In-Reply-To: <00afe803-22dd-5a75-70aa-dda0c7752470@suse.cz> From: Nicolas Boichat Date: Fri, 9 Nov 2018 19:57:50 +0800 Message-ID: Subject: Re: [PATCH RFC 1/3] mm: When CONFIG_ZONE_DMA32 is set, use DMA32 for SLAB_CACHE_DMA To: vbabka@suse.cz Cc: robin.murphy@arm.com, will.deacon@arm.com, joro@8bytes.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, Joonsoo Kim , Andrew Morton , mhocko@suse.com, mgorman@techsingularity.net, yehs1@lenovo.com, rppt@linux.vnet.ibm.com, linux-arm Mailing List , iommu@lists.linux-foundation.org, lkml , linux-mm@kvack.org, yong.wu@mediatek.com, Matthias Brugger , tfiga@google.com, yingjoe.chen@mediatek.com, Alexander.Levin@microsoft.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 9, 2018 at 6:43 PM Vlastimil Babka wrote: > > On 11/9/18 9:24 AM, Nicolas Boichat wrote: > > Some callers, namely iommu/io-pgtable-arm-v7s, expect the physical > > address returned by kmem_cache_alloc with GFP_DMA parameter to be > > a 32-bit address. > > > > Instead of adding a separate SLAB_CACHE_DMA32 (and then audit > > all the calls to check if they require memory from DMA or DMA32 > > zone), we simply allocate SLAB_CACHE_DMA cache in DMA32 region, > > if CONFIG_ZONE_DMA32 is set. > > > > Fixes: ad67f5a6545f ("arm64: replace ZONE_DMA with ZONE_DMA32") > > Signed-off-by: Nicolas Boichat > > --- > > include/linux/slab.h | 13 ++++++++++++- > > mm/slab.c | 2 +- > > mm/slub.c | 2 +- > > 3 files changed, 14 insertions(+), 3 deletions(-) > > > > diff --git a/include/linux/slab.h b/include/linux/slab.h > > index 918f374e7156f4..390afe90c5dec0 100644 > > --- a/include/linux/slab.h > > +++ b/include/linux/slab.h > > @@ -30,7 +30,7 @@ > > #define SLAB_POISON ((slab_flags_t __force)0x00000800U) > > /* Align objs on cache lines */ > > #define SLAB_HWCACHE_ALIGN ((slab_flags_t __force)0x00002000U) > > -/* Use GFP_DMA memory */ > > +/* Use GFP_DMA or GFP_DMA32 memory */ > > #define SLAB_CACHE_DMA ((slab_flags_t __force)0x00004000U) > > /* DEBUG: Store the last owner for bug hunting */ > > #define SLAB_STORE_USER ((slab_flags_t __force)0x00010000U) > > @@ -126,6 +126,17 @@ > > #define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \ > > (unsigned long)ZERO_SIZE_PTR) > > > > +/* > > + * When ZONE_DMA32 is defined, have SLAB_CACHE_DMA allocate memory with > > + * GFP_DMA32 instead of GFP_DMA, as this is what some of the callers > > + * require (instead of duplicating cache for DMA and DMA32 zones). > > + */ > > +#ifdef CONFIG_ZONE_DMA32 > > +#define SLAB_CACHE_DMA_GFP GFP_DMA32 > > +#else > > +#define SLAB_CACHE_DMA_GFP GFP_DMA > > +#endif > > AFAICS this will break e.g. x86 which can have both ZONE_DMA and > ZONE_DMA32, and now you would make kmalloc(__GFP_DMA) return objects > from ZONE_DMA32 instead of __ZONE_DMA, which can break something. Oh, I was not aware that both ZONE_DMA and ZONE_DMA32 can be defined at the same time. I guess the test should be inverted, something like this (can be simplified...): #ifdef CONFIG_ZONE_DMA #define SLAB_CACHE_DMA_GFP GFP_DMA #elif defined(CONFIG_ZONE_DMA32) #define SLAB_CACHE_DMA_GFP GFP_DMA32 #else #define SLAB_CACHE_DMA_GFP GFP_DMA // ? #endif > Also I'm probably missing the point of this all. In patch 3 you use > __get_dma32_pages() thus __get_free_pages(__GFP_DMA32), which uses > alloc_pages, thus the page allocator directly, and there's no slab > caches involved. __get_dma32_pages fixes level 1 page allocations in the patch 3. This change fixes level 2 page allocations (kmem_cache_zalloc(data->l2_tables, gfp | GFP_DMA)), by transparently remapping GFP_DMA to an underlying ZONE_DMA32. The alternative would be to create a new SLAB_CACHE_DMA32 when CONFIG_ZONE_DMA32 is defined, but then I'm concerned that the callers would need to choose between the 2 (GFP_DMA or GFP_DMA32...), and also need to use some ifdefs (but maybe that's not a valid concern?). > It makes little sense to involve slab for page table > allocations anyway, as those tend to be aligned to a page size (or > high-order page size). So what am I missing? Level 2 tables are ARM_V7S_TABLE_SIZE(2) => 1kb, so we'd waste 3kb if we allocated a full page. Thanks,