Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3948040pxb; Tue, 10 Nov 2020 04:24:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOhPxQGVG6Cib3QyslvjhcYzM3z26yTiPGLd1MEUBFGzguuQ91xR8312nzx/Pv9dLI8O64 X-Received: by 2002:aa7:d690:: with SMTP id d16mr20439198edr.329.1605011061172; Tue, 10 Nov 2020 04:24:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605011061; cv=none; d=google.com; s=arc-20160816; b=dc2BaWfhhiaNNAPrlZvfALHkWp4vlpUhQmxUAO4Wb3E+rbBPGqNG/In6X3oUqle9G8 lPQuzdYmrt0SmytR3DtWtNWt5/P9+KAnpoUshXAH5Hn16cTNZq10x5cVZiMq6l9e6tNh SkOv8b+GQcp6hQO18ab5vkpLf/p7iO2S7rCHFofW3tobSwnqbK7ntfsHYRaBKpGrWbhr u7qHGDWwRo36IEww+3i61Q3yREa1t/xd0KyhJjOgmSJQl7r+X8jCaUaz3QOg66P3VBSh pKxEUx384zLI5+0CGtfQQyG/saH7VrxM07w6GcoFczSu7oyEQ2yeJRgVdgV4EnzSpioz fEiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:user-agent :references:in-reply-to:subject:cc:to:from:date:mime-version :dkim-signature; bh=RsKAQhsjBAFRDGDj3c5k8MVs+xkOLwwQU+TEcjoUYn8=; b=fhgPdz0Y5LnkEov6Nle4yOHKCouimmhy0lh2LVINyROtEBHoqddFVSz1ALWP356Bu6 fyZzeesg5BhobEdA4hOAzXe2MdhmQMLshZHqjLctxNC8Nz6KCaebC95Kv0N7ucuVsrJz 625m3Lu+j7kn7rpLAjwRUoNL8gqg+gB//gcmEey3OEaXRWTwDdf4cq+aFyI2WGQ6aPml vVbr8LIYrSHuKKIb0Fvo56S/shHRdbIrejdYRWTYNkdqBHfqNLMtsGcCeb3LAXf/rMUo hBicq44o3bLRtrhSZZkDbWs9OYYEj+KDRxl51Xchog7NxhL6uTFItuhWC86bScznJ0nv pE3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b="bbp/I2Ft"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 32si9370229edq.92.2020.11.10.04.23.57; Tue, 10 Nov 2020 04:24:21 -0800 (PST) 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=@agner.ch header.s=dkim header.b="bbp/I2Ft"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730291AbgKJMW3 (ORCPT + 99 others); Tue, 10 Nov 2020 07:22:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728478AbgKJMW3 (ORCPT ); Tue, 10 Nov 2020 07:22:29 -0500 Received: from mail.kmu-office.ch (mail.kmu-office.ch [IPv6:2a02:418:6a02::a2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2606BC0613CF for ; Tue, 10 Nov 2020 04:22:29 -0800 (PST) Received: from webmail.kmu-office.ch (unknown [IPv6:2a02:418:6a02::a3]) by mail.kmu-office.ch (Postfix) with ESMTPSA id AF4A95C2D98; Tue, 10 Nov 2020 13:22:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1605010940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RsKAQhsjBAFRDGDj3c5k8MVs+xkOLwwQU+TEcjoUYn8=; b=bbp/I2FtCw6mOgT0qPJOd3lzI/1lpJiWfOcaEXzLWCwaI05gsT515QaI/aTSdOsajR8w9E ZGrP/D9lcA8UxuKm/CiMj5uvOLIv+wiW86w8q4BdBELTv50eEKJGRL/EL3HJKwKTyrG6HJ FPEKZ4Wg6uBj+0JGfRYgkY8wG5eSMSU= MIME-Version: 1.0 Date: Tue, 10 Nov 2020 13:22:20 +0100 From: Stefan Agner To: Arnd Bergmann Cc: Mike Rapoport , Minchan Kim , ngupta@vflare.org, Sergey Senozhatsky , Andrew Morton , sjenning@linux.vnet.ibm.com, gregkh , Arnd Bergmann , Linux-MM , linux-kernel@vger.kernel.org, linux@armlinux.org.uk Subject: Re: [PATCH] mm/zsmalloc: include sparsemem.h for MAX_PHYSMEM_BITS In-Reply-To: References: <20201108064659.GD301837@kernel.org> <7782fb694a6b0c500e8f32ecf895b2bf@agner.ch> <20201110095806.GH301837@kernel.org> User-Agent: Roundcube Webmail/1.4.9 Message-ID: <48fdc3631bc74dd77fea1a30085c8af9@agner.ch> X-Sender: stefan@agner.ch Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [adding Russell King for ARM] On 2020-11-10 12:21, Arnd Bergmann wrote: > On Tue, Nov 10, 2020 at 10:58 AM Mike Rapoport wrote: >> > > >> > > asm/sparsemem.h is not available on some architectures. >> > > It's better to use linux/mmzone.h instead. > > Ah, I missed that, too. > >> > Hm, linux/mmzone.h only includes asm/sparsemem.h when CONFIG_SPARSEMEM >> > is enabled. However, on ARM at least I can have configurations without >> > CONFIG_SPARSEMEM and physical address extension on (e.g. >> > multi_v7_defconfig + CONFIG_LPAE + CONFIG_ZSMALLOC). >> > >> > While sparsemem seems to be a good idea with LPAE it really seems not >> > required (see also https://lore.kernel.org/patchwork/patch/567589/). >> > >> > There seem to be also other architectures which define MAX_PHYSMEM_BITS >> > only when SPARSEMEM is enabled, e.g. >> > arch/riscv/include/asm/sparsemem.h... >> > >> > Not sure how to get out of this.. Maybe make ZSMALLOC dependent on >> > SPARSEMEM? It feels a bit silly restricting ZSMALLOC selection only due >> > to a compile time define... >> >> I think we can define MAX_POSSIBLE_PHYSMEM_BITS in one of >> arch/arm/inclide/asm/pgtable-{2,3}level-*.h headers to values supported >> by !LPAE and LPAE. Hm I see mm/zsmalloc.c really only needs to know how many bits are potentially used to calculate how many bits it can use for object indexing. > > Good idea. I wonder what other architectures need the same though. > Here are some I found: > > $ git grep -l PHYS_ADDR_T_64BIT arch | grep Kconfig > arch/arc/Kconfig > arch/arm/mm/Kconfig > arch/mips/Kconfig > arch/powerpc/platforms/Kconfig.cputype > arch/x86/Kconfig > > arch/arc has a CONFIG_ARC_HAS_PAE40 option > arch/riscv has 34-bit addressing in rv32 mode > arch/mips has up to 40 bits with mips32r3 XPA, but I don't know what > supports that > > arch/powerpc has this: > config PHYS_64BIT > bool 'Large physical address support' if E500 || PPC_86xx > depends on (44x || E500 || PPC_86xx) && !PPC_83xx && !PPC_82xx > > Apparently all three (4xx, e500v2, mpc86xx/e600) do 36-bit physical > addressing, but each one has a different page table format. > > Microblaze has physical address extensions, but neither those nor > 64-bit mode have so far made it into the kernel. > > To be on the safe side, we could provoke a compile-time error > when CONFIG_PHYS_ADDR_T_64BIT is set on a 32-bit > architecture, but MAX_POSSIBLE_PHYSMEM_BITS is not set. > >> That's what x86 does: >> >> $ git grep -w MAX_POSSIBLE_PHYSMEM_BITS arch/ >> arch/x86/include/asm/pgtable-3level_types.h:#define MAX_POSSIBLE_PHYSMEM_BITS 36 > > Doesn't x86 also support a 40-bit addressing mode? I suppose > those machines that actually used it are long gone. > >> arch/x86/include/asm/pgtable_64_types.h:#define MAX_POSSIBLE_PHYSMEM_BITS 52 >> >> It seems that actual numbers would be 36 for !LPAE and 40 for LPAE, but >> I'm not sure about that. > > Close enough, yes. > > The 36-bit addressing is on !LPAE is only used for early static mappings, > so I think we can pretend it's always 32-bit. I checked the ARMv8 reference, > and it says that ARMv8-Aarch32 actually supports 40 bit physical addressing > both with non-LPAE superpages (short descriptor format) and LPAE (long > descriptor format), but Linux only does 36-bit addressing on superpages > as specified for ARMv6/ARMv7 short descriptors. Oh so, more than 4GB of memory can be supported by !LPAE systems via superpages? Wasn't aware of that. Since only ARM_LPAE selects CONFIG_PHYS_ADDR_T_64BIT it really is safe to assume 32 bits for non-LPAE systems. I guess that would mean adding a #define MAX_POSSIBLE_PHYSMEM_BITS 32 to arch/arm/include/asm/pgtable-2level.h and a MAX_POSSIBLE_PHYSMEM_BITS 40 in arch/arm/include/asm/pgtable-3level.h. Seems straight forward and would solve the problem I had. I can prepare a patch for ARM, not sure about the other architectures... -- Stefan