Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8449185ybi; Tue, 23 Jul 2019 08:44:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYXhPsfWO5pxbEF7rpr/E3XlJx4Vql/2hern2BzoeAqpBpLhMOzO2lQ3XnFbjNCYgGuYtY X-Received: by 2002:a17:902:b70c:: with SMTP id d12mr78172495pls.314.1563896688986; Tue, 23 Jul 2019 08:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563896688; cv=none; d=google.com; s=arc-20160816; b=jCQyNV11z/7xsrakYnrKZVRGIFmIgQSbvYpZYwfbFRWzpUorCNO0obQuRG0eSb46jq XVe8ZQG4F4S707ZGEmvnL/C8tb9Xh24AU6IUPT/nFFq3PAPbbTR52NMc4w+5O1YQf/oL ddu6CedMr1Y+igkf+jZc1f1aNj72sv5/ZExnjBl9zdopdnTx+FfLxXIJt7NE14VSoItU L3pqaO0s0r4RqMNAN8WUN/CU4vEM/z1t44hE9dn91Cp5LbGtgKT8cFUfGlbRXtYLF4QD 6RznXnl50V1kQNCpRV8dwis2dDUixbMzUhs8FSKkT5tOKEoPdlHLOZnK95eLb6/t+AW+ RM4g== 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=ChqCczgPPMAdZGIJfk/xI6N8p5HZAKgav0uSZ0NSoxc=; b=fZW8l3GHGLjiDXMJr9TDiSTHvp/M671Z0ekZ1TkP4RJr2I50qfsEtcIzQctI0+fgII s63qDK7bxsAVJ1hbkzLbTk2BvWHvZXWpDOsUMBu1gnL7gaznPgV4JVZ6CenOEH6XZIik Yybug+7fRNLkkx83Z3lTQwJlkMsof523etV1denz4K88rei+GSrEadxYcgX1mzQbOX0t fggBSKRAthCYwkcD2h7l/JBIfJ5QJZp1qB/VbxzLjmXHApoAEGAxtE3/fhPPsoZmfgl+ Ks3WqIgm0RiAWKTZ3jy8ygc0R1K6OId1wYTIM+tx+ErJ1LWYk6peobYU85GTaLVKf68I YUDw== 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 u38si11609882pgl.507.2019.07.23.08.44.32; Tue, 23 Jul 2019 08:44:48 -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 S1732495AbfGWJ5y (ORCPT + 99 others); Tue, 23 Jul 2019 05:57:54 -0400 Received: from foss.arm.com ([217.140.110.172]:52008 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731566AbfGWJ5x (ORCPT ); Tue, 23 Jul 2019 05:57:53 -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 D39B8337; Tue, 23 Jul 2019 02:57:52 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 639E93F71A; Tue, 23 Jul 2019 02:57:50 -0700 (PDT) Date: Tue, 23 Jul 2019 10:57:48 +0100 From: Mark Rutland To: Steven Price Cc: linux-mm@kvack.org, Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Dave Hansen , Ingo Molnar , James Morse , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Peter Zijlstra , Thomas Gleixner , Will Deacon , x86@kernel.org, "H. Peter Anvin" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Liang, Kan" , Andrew Morton Subject: Re: [PATCH v9 19/21] mm: Add generic ptdump Message-ID: <20190723095747.GB8085@lakrids.cambridge.arm.com> References: <20190722154210.42799-1-steven.price@arm.com> <20190722154210.42799-20-steven.price@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190722154210.42799-20-steven.price@arm.com> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 22, 2019 at 04:42:08PM +0100, Steven Price wrote: > Add a generic version of page table dumping that architectures can > opt-in to > > Signed-off-by: Steven Price [...] > +#ifdef CONFIG_KASAN > +/* > + * This is an optimization for KASAN=y case. Since all kasan page tables > + * eventually point to the kasan_early_shadow_page we could call note_page() > + * right away without walking through lower level page tables. This saves > + * us dozens of seconds (minutes for 5-level config) while checking for > + * W+X mapping or reading kernel_page_tables debugfs file. > + */ > +static inline bool kasan_page_table(struct ptdump_state *st, void *pt, > + unsigned long addr) > +{ > + if (__pa(pt) == __pa(kasan_early_shadow_pmd) || > +#ifdef CONFIG_X86 > + (pgtable_l5_enabled() && > + __pa(pt) == __pa(kasan_early_shadow_p4d)) || > +#endif > + __pa(pt) == __pa(kasan_early_shadow_pud)) { > + st->note_page(st, addr, 5, pte_val(kasan_early_shadow_pte[0])); > + return true; > + } > + return false; Having you tried this with CONFIG_DEBUG_VIRTUAL? The kasan_early_shadow_pmd is a kernel object rather than a linear map object, so you should use __pa_symbol for that. It's a bit horrid to have to test multiple levels in one function; can't we check the relevant level inline in each of the test_p?d funcs? They're optional anyway, so they only need to be defined for CONFIG_KASAN. Thanks, Mark. > +} > +#else > +static inline bool kasan_page_table(struct ptdump_state *st, void *pt, > + unsigned long addr) > +{ > + return false; > +} > +#endif > + > +static int ptdump_test_p4d(unsigned long addr, unsigned long next, > + p4d_t *p4d, struct mm_walk *walk) > +{ > + struct ptdump_state *st = walk->private; > + > + if (kasan_page_table(st, p4d, addr)) > + return 1; > + return 0; > +} > +static int ptdump_test_pud(unsigned long addr, unsigned long next, > + pud_t *pud, struct mm_walk *walk) > +{ > + struct ptdump_state *st = walk->private; > + > + if (kasan_page_table(st, pud, addr)) > + return 1; > + return 0; > +} > + > +static int ptdump_test_pmd(unsigned long addr, unsigned long next, > + pmd_t *pmd, struct mm_walk *walk) > +{ > + struct ptdump_state *st = walk->private; > + > + if (kasan_page_table(st, pmd, addr)) > + return 1; > + return 0; > +} > + > +static int ptdump_hole(unsigned long addr, unsigned long next, > + struct mm_walk *walk) > +{ > + struct ptdump_state *st = walk->private; > + > + st->note_page(st, addr, -1, 0); > + > + return 0; > +} > + > +void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm) > +{ > + struct mm_walk walk = { > + .mm = mm, > + .pgd_entry = ptdump_pgd_entry, > + .p4d_entry = ptdump_p4d_entry, > + .pud_entry = ptdump_pud_entry, > + .pmd_entry = ptdump_pmd_entry, > + .pte_entry = ptdump_pte_entry, > + .test_p4d = ptdump_test_p4d, > + .test_pud = ptdump_test_pud, > + .test_pmd = ptdump_test_pmd, > + .pte_hole = ptdump_hole, > + .private = st > + }; > + const struct ptdump_range *range = st->range; > + > + down_read(&mm->mmap_sem); > + while (range->start != range->end) { > + walk_page_range(range->start, range->end, &walk); > + range++; > + } > + up_read(&mm->mmap_sem); > + > + /* Flush out the last page */ > + st->note_page(st, 0, 0, 0); > +} > -- > 2.20.1 >