Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp559525img; Thu, 28 Feb 2019 04:17:27 -0800 (PST) X-Google-Smtp-Source: AHgI3IZHeEeYm+NIChgfsOuuUdViHJeGO6iJu7gkyl7PI2apJi7+OAqJ23JUrQC6EhKjJOpCfRwQ X-Received: by 2002:a17:902:24e1:: with SMTP id l30mr7600393plg.141.1551356247073; Thu, 28 Feb 2019 04:17:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551356247; cv=none; d=google.com; s=arc-20160816; b=Iq4xTTrSGYfTFHe6XXGnlPf6I+qVKGMNoNqbncFuA76xgH2ymKleY3thqNqMZzOEoZ ToRMHgkbcwQdu2dA8haekFHw7bi7Y6yV+ZzPVM0xQBZyIlKRbjGHi/UtcYliiPvZG9rj J49g2URol6emB+5zLsvBHZKn++IL8RJgmrWQjFdL9b9MplD4UzhiUToGmDVKn+qjbmbq 86Mp3x9a3H8oEv09DD7CbFegCbhdHNGwykyWeUIbz+AujgjJ8YfVyg7GgS/xwRfF46H8 Va81WOaMdbKjO6qYQn/vzdAJrtwswIE4ZLQFYic+dfWMWe33QBy8hrgjEfHgkpe3EcC8 SYVw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=rHny8Epa2KX8nVY4IJ8/IgPBrNfjhgZOct1JiTErilk=; b=LAaIu+70ydicvf0gT2NZhHO986XZ56TcCBAR0eE6Xal8/jM2b86IaVhRj9SHV0A3OV bF4cEe9/kuqPMAGFcWDvB0O9y31qs2JFAcB1j/uzYmlnCvNEeO1jBRPft971b69ePOJ8 ZnzSTRtYH0wZPA0FFwDTiZfz2sfSDiwF5keWqprlWbwMa2dlNY0pzLtPpp8itBv7GE/F l5D+odAgk0/lJO6czX55UDHPAjImmEFAyL9zI/spJN0U0Ej6iqRF6iXurpqF1xmiONCB JMj2dKCaJY5RR1tzbXNdFU2k0HE+lzHsQV0vKHu+tdJ/blqQQa6P5u35mFj1HhLbox+H CEqw== 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 cs19si19817986plb.431.2019.02.28.04.17.12; Thu, 28 Feb 2019 04:17:27 -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 S1732543AbfB1L2H (ORCPT + 99 others); Thu, 28 Feb 2019 06:28:07 -0500 Received: from foss.arm.com ([217.140.101.70]:45990 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbfB1L2H (ORCPT ); Thu, 28 Feb 2019 06:28:07 -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 8A9D9EBD; Thu, 28 Feb 2019 03:28:06 -0800 (PST) Received: from [10.1.196.69] (e112269-lin.cambridge.arm.com [10.1.196.69]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6AABA3F738; Thu, 28 Feb 2019 03:28:03 -0800 (PST) Subject: Re: [PATCH v3 27/34] mm: pagewalk: Add 'depth' parameter to pte_hole To: Dave Hansen , linux-mm@kvack.org Cc: Mark Rutland , x86@kernel.org, Arnd Bergmann , Ard Biesheuvel , Peter Zijlstra , Catalin Marinas , Dave Hansen , Will Deacon , linux-kernel@vger.kernel.org, =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , James Morse , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, "Liang, Kan" References: <20190227170608.27963-1-steven.price@arm.com> <20190227170608.27963-28-steven.price@arm.com> From: Steven Price Message-ID: <02b9ec67-75c5-4a36-9110-cc4ba6ee4f94@arm.com> Date: Thu, 28 Feb 2019 11:28:01 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27/02/2019 17:38, Dave Hansen wrote: > On 2/27/19 9:06 AM, Steven Price wrote: >> #ifdef CONFIG_SHMEM >> static int smaps_pte_hole(unsigned long addr, unsigned long end, >> - struct mm_walk *walk) >> + __always_unused int depth, struct mm_walk *walk) >> { > > I think this 'depth' argument is a mistake. It's synthetic and it's > surely going to be a source of bugs. > > The page table dumpers seem to be using this to dump out the "name" of a > hole which seems a bit bogus in the first place. I'd much rather teach > the dumpers about the length of the hole, "the hole is 0x12340000 bytes > long", rather than "there's a hole at this level". I originally started by trying to calculate the 'depth' from (end - addr), e.g. for arm64: level = 4 - (ilog2(end - addr) - PAGE_SHIFT) / (PAGE_SHIFT - 3) However there are two issues that I encountered: * walk_page_range() takes a range of addresses to walk. This means that holes at the beginning/end of the range are clamped to the address range. This particularly shows up at the end of the range as I use ~0ULL as the end which leads to (~0ULL - addr) which is 1 byte short of the desired size. Obviously that particular corner-case is easy to work round, but it seemed fragile. * The above definition for arm64 isn't correct in all cases. You need to account for things like CONFIG_PGTABLE_LEVELS. Other architectures also have various quirks in their page tables. I guess I could try something like: static int get_level(unsigned long addr, unsigned long end) { /* Add 1 to account for ~0ULL */ unsigned long size = (end - addr) + 1; if (size < PMD_SIZE) return 4; else if (size < PUD_SIZE) return 3; else if (size < P4D_SIZE) return 2; else if (size < PGD_SIZE) return 1; return 0; } There are two immediate problems with that: * The "+1" to deal with ~0ULL is fragile * PGD_SIZE isn't what you might expect, it's not defined for most architectures and arm64/x86 use it as the size of the PGD table. Although that's easy enough to fix up. Do you think a function like above would be preferable? The other option would of course be to just drop the information from the debugfs file about at which level the holes are. But it can be useful information to see whether there are empty levels in the page table structure. Although this is an area where x86 and arm64 differ currently (x86 explicitly shows the gaps, arm64 doesn't), so if x86 doesn't mind losing that functionality that would certainly simplify things! Thanks, Steve