Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5430679ybh; Wed, 7 Aug 2019 06:00:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPslUNNhhn3bmBzCznmzTxlALyWiElTbL6129u/dBaurBkgJU0fIhnEtskiDyC+gRH67d9 X-Received: by 2002:a17:90a:cb87:: with SMTP id a7mr8572033pju.130.1565182803058; Wed, 07 Aug 2019 06:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565182803; cv=none; d=google.com; s=arc-20160816; b=xal5S//Apmq8hTVsZpncSCLt/A+nuC/uGkmMWkymANZuLJhTr87LsM4OAbFot7q93b 3a5EjD8+5x/cpsSMXzP6uN7d7foay3w3tyi20tRWTHAeaFoxCoM8mjxikpDUDfFJa/7y kRKiRGh0H6x+Z6JVjHUHgpWQLo4r7TTE+eO114zTq40OGsfKd7TYbe/lKipW3yTAWN35 LF5gSrypyqfZiukyXiivx0/pKhJYjZnTLc9NQbDiyfbqZ+3H/99klS+rD8UV5tIBmpy0 RSUMZcu10my7WYf7O9cMPeEsVkpbswFCJSIAGxCRaCs5xYBWIy+Kx6LaMi/HqFJ2fnT9 Nn5Q== 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=Ld9G8s52mUgVqlwLTqPePoM9iCKTubDk7WMu/oo2f+A=; b=lPtoqfuP5jH9sHBJnKdMSJ/kILIoqg2SNY1LsABksWJM42KrOxIKHUW2q2HoBtZx1O hqM7b9d0l9zLxOQ7lzGwQBKhiPZ2Sl54rAleRg3qyLjn7+OfmKirF15i+RPWWGGzl/oc DRYipe+4BuHWr7C6sXPidjamT0DBWrzAP64m5TMrppM5kco5Rs35ksHW9eWzuPNzLwwz fL4r608nwssn6b5q95SE0ov2Q+Qdh5giLgoTsqhjlTop/ltJg7Jvq2QL6M/s9g1qiNs+ fKFUksZiCVIIW1JdywXHTqKaltAuYL7PMs35jZcDpMLel9O2v8eMxh2Rnx8lMfTxZIj9 qNLQ== 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 e13si52945055pfl.279.2019.08.07.05.59.45; Wed, 07 Aug 2019 06:00:03 -0700 (PDT) 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 S2387958AbfHGM60 (ORCPT + 99 others); Wed, 7 Aug 2019 08:58:26 -0400 Received: from foss.arm.com ([217.140.110.172]:47950 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387476AbfHGM6Z (ORCPT ); Wed, 7 Aug 2019 08:58:25 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D9E2B28; Wed, 7 Aug 2019 05:58:24 -0700 (PDT) Received: from [10.1.196.133] (e112269-lin.cambridge.arm.com [10.1.196.133]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 493D93F575; Wed, 7 Aug 2019 05:58:22 -0700 (PDT) Subject: Re: [PATCH v10 20/22] x86: mm: Convert dump_pagetables to use walk_page_range To: Andrew Morton Cc: Mark Rutland , x86@kernel.org, Arnd Bergmann , Ard Biesheuvel , Peter Zijlstra , Catalin Marinas , Dave Hansen , linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , James Morse , Thomas Gleixner , Will Deacon , linux-arm-kernel@lists.infradead.org, "Liang, Kan" References: <20190731154603.41797-1-steven.price@arm.com> <20190731154603.41797-21-steven.price@arm.com> <20190806165823.3f735b45a7c4163aca20a767@linux-foundation.org> From: Steven Price Message-ID: <066fa4ca-5a46-ba86-607f-9c3e16f79cde@arm.com> Date: Wed, 7 Aug 2019 13:58:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190806165823.3f735b45a7c4163aca20a767@linux-foundation.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/08/2019 00:58, Andrew Morton wrote: > On Wed, 31 Jul 2019 16:46:01 +0100 Steven Price wrote: > >> Make use of the new functionality in walk_page_range to remove the >> arch page walking code and use the generic code to walk the page tables. >> >> The effective permissions are passed down the chain using new fields >> in struct pg_state. >> >> The KASAN optimisation is implemented by including test_p?d callbacks >> which can decide to skip an entire tree of entries >> >> ... >> >> +static const struct ptdump_range ptdump_ranges[] = { >> +#ifdef CONFIG_X86_64 >> >> -#define pgd_large(a) (pgtable_l5_enabled() ? pgd_large(a) : p4d_large(__p4d(pgd_val(a)))) >> -#define pgd_none(a) (pgtable_l5_enabled() ? pgd_none(a) : p4d_none(__p4d(pgd_val(a)))) >> +#define normalize_addr_shift (64 - (__VIRTUAL_MASK_SHIFT + 1)) >> +#define normalize_addr(u) ((signed long)(u << normalize_addr_shift) \ >> + >> normalize_addr_shift) >> >> -static inline bool is_hypervisor_range(int idx) >> -{ >> -#ifdef CONFIG_X86_64 >> - /* >> - * A hole in the beginning of kernel address space reserved >> - * for a hypervisor. >> - */ >> - return (idx >= pgd_index(GUARD_HOLE_BASE_ADDR)) && >> - (idx < pgd_index(GUARD_HOLE_END_ADDR)); >> + {0, PTRS_PER_PGD * PGD_LEVEL_MULT / 2}, >> + {normalize_addr(PTRS_PER_PGD * PGD_LEVEL_MULT / 2), ~0UL}, > > This blows up because PGD_LEVEL_MULT is sometimes not a constant. > > x86_64 allmodconfig: > > In file included from ./arch/x86/include/asm/pgtable_types.h:249:0, > from ./arch/x86/include/asm/paravirt_types.h:45, > from ./arch/x86/include/asm/ptrace.h:94, > from ./arch/x86/include/asm/math_emu.h:5, > from ./arch/x86/include/asm/processor.h:12, > from ./arch/x86/include/asm/cpufeature.h:5, > from ./arch/x86/include/asm/thread_info.h:53, > from ./include/linux/thread_info.h:38, > from ./arch/x86/include/asm/preempt.h:7, > from ./include/linux/preempt.h:78, > from ./include/linux/spinlock.h:51, > from ./include/linux/wait.h:9, > from ./include/linux/wait_bit.h:8, > from ./include/linux/fs.h:6, > from ./include/linux/debugfs.h:15, > from arch/x86/mm/dump_pagetables.c:11: > ./arch/x86/include/asm/pgtable_64_types.h:56:22: error: initializer element is not constant > #define PTRS_PER_PGD 512 > ^ This is very unhelpful of GCC - it's actually PTRS_PER_P4D which isn't constant! > arch/x86/mm/dump_pagetables.c:363:6: note: in expansion of macro ‘PTRS_PER_PGD’ > {0, PTRS_PER_PGD * PGD_LEVEL_MULT / 2}, > ^~~~~~~~~~~~ > ./arch/x86/include/asm/pgtable_64_types.h:56:22: note: (near initialization for ‘ptdump_ranges[0].end’) > #define PTRS_PER_PGD 512 > ^ > arch/x86/mm/dump_pagetables.c:363:6: note: in expansion of macro ‘PTRS_PER_PGD’ > {0, PTRS_PER_PGD * PGD_LEVEL_MULT / 2}, > ^~~~~~~~~~~~ > arch/x86/mm/dump_pagetables.c:360:27: error: initializer element is not constant > #define normalize_addr(u) ((signed long)(u << normalize_addr_shift) \ > ^ > arch/x86/mm/dump_pagetables.c:364:3: note: in expansion of macro ‘normalize_addr’ > {normalize_addr(PTRS_PER_PGD * PGD_LEVEL_MULT / 2), ~0UL}, > ^~~~~~~~~~~~~~ > arch/x86/mm/dump_pagetables.c:360:27: note: (near initialization for ‘ptdump_ranges[1].start’) > #define normalize_addr(u) ((signed long)(u << normalize_addr_shift) \ > ^ > arch/x86/mm/dump_pagetables.c:364:3: note: in expansion of macro ‘normalize_addr’ > {normalize_addr(PTRS_PER_PGD * PGD_LEVEL_MULT / 2), ~0UL}, > > I don't know what to do about this so I'll drop the series. My best solution to this is to simply make ptdump_ranges dynamic (see below). But there are other problems with this series (thanks for spotting them), so I'll send out another version later. Thanks, Steve ----8<----- diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index 998c7f46763c..8fc129ff985e 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -353,7 +353,10 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, } } -static const struct ptdump_range ptdump_ranges[] = { +static void ptdump_walk_pgd_level_core(struct seq_file *m, struct mm_struct *mm, + bool checkwx, bool dmesg) +{ + const struct ptdump_range ptdump_ranges[] = { #ifdef CONFIG_X86_64 #define normalize_addr_shift (64 - (__VIRTUAL_MASK_SHIFT + 1)) @@ -368,9 +371,6 @@ static const struct ptdump_range ptdump_ranges[] = { {0, 0} }; -static void ptdump_walk_pgd_level_core(struct seq_file *m, struct mm_struct *mm, - bool checkwx, bool dmesg) -{ struct pg_state st = { .ptdump = { .note_page = note_page,