Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9796277ybi; Wed, 24 Jul 2019 10:06:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqycJdu/PWZeRFwYOgYWb/B/mkE5t/MxIB3Dv2MS6qj/uYm31OeiuORvM/PdBD2q0ASNwC+W X-Received: by 2002:a63:fd50:: with SMTP id m16mr81123413pgj.192.1563987960560; Wed, 24 Jul 2019 10:06:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563987960; cv=none; d=google.com; s=arc-20160816; b=hYsuN+fAcRS/owd8Syl3GcOt8orlnEEI5zGCeMWMbB95FcdMEB9R1+KaSp6WLvN6p1 elfgGvbOKWr+aU4MgauwkE4Yuti3yEqInIPPd9+AIVNqBfU07VzzPz3gnzdei/i2VdQK W765kKrw0p8tr73YFMPin7o7xjyp1dHctgqY1CgX4Wb390yWDZjgxbPxSRLWz4oDU9ax jDBaU8YVJh2z24iW3yyhZ1njx5iMaLl8LY4RyZ5zkPXMOi98LJEceuDlNo75e1eiMaXH z+Pe4yHnU/hbiMXWvVa5J+c7ZHnZqJ6Z6g0KYRsY1/wdPERkBobx5TCfwR3RE8v8DbqF Rl6g== 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=gIx+ceJLLqzYzF7GtNXtIq07rvlh51FQYTqoEO8IsJ0=; b=e6vl6spYh4pmzf3r2Bl9jVwlYX+Rdv2vrkZv6EW8CIPYf637wusZ5Cy4+MygeWsSfP tUd3+pnuOIBiMs2UF9IatitWRaNlsH/iea2FGUIXlO0+VkAijImLx/l7Ls/MwI2YqsMc iEKmcdPswQDwIjt3n3f608qqceSZYo/iQ9h9SAPZ1nP7dP4mBC47js4w7T+iTnyDa8Kp Cg/CQNeJS/IFw5F51E9IEd7FpGCwhqgQr6ydyfN2qstu3gLofCUu9oGSZ7zA/g5l5KX6 KFAy1G+Ih6D4Eg73Z7j40H72T18eNb+nLKqBtUM+Oz8Bnqw98yPVMfXVskMcOxCrLyBz BxFA== 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 i133si14251901pgc.109.2019.07.24.10.05.45; Wed, 24 Jul 2019 10:06:00 -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 S1727284AbfGXQgu (ORCPT + 99 others); Wed, 24 Jul 2019 12:36:50 -0400 Received: from foss.arm.com ([217.140.110.172]:43732 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726316AbfGXQgu (ORCPT ); Wed, 24 Jul 2019 12:36:50 -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 3690E28; Wed, 24 Jul 2019 09:36:49 -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 C337C3F71F; Wed, 24 Jul 2019 09:36:46 -0700 (PDT) Subject: Re: [PATCH v9 19/21] mm: Add generic ptdump To: Mark Rutland Cc: 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 , Andrew Morton , linux-arm-kernel@lists.infradead.org, "Liang, Kan" References: <20190722154210.42799-1-steven.price@arm.com> <20190722154210.42799-20-steven.price@arm.com> <20190723095747.GB8085@lakrids.cambridge.arm.com> From: Steven Price Message-ID: Date: Wed, 24 Jul 2019 17:36:45 +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: <20190723095747.GB8085@lakrids.cambridge.arm.com> 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 23/07/2019 10:57, Mark Rutland wrote: > 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. Thanks for pointing that out - it is indeed broken on arm64. This was moved from x86 where CONFIG_DEBUG_VIRTUAL doesn't seem to pick this up. There is actually a problem here that 'pt' might not be in the linear map (so __pa(pt) barfs on arm64 as well as kasan_early_shadow_p?d). It looks like having the comparisons of the form "pt == lm_alias(kasan_early_shadow_p?d)" is probably best. > 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. Good point - removing the test_p?d callbacks when !CONFIG_KASAN simplifies the code. Thanks, Steve