From patchwork Thu Jan 5 21:50:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank van der Linden X-Patchwork-Id: 13090567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98345C3DA7A for ; Thu, 5 Jan 2023 21:50:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 197D98E0002; Thu, 5 Jan 2023 16:50:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16EE08E0001; Thu, 5 Jan 2023 16:50:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0378E8E0002; Thu, 5 Jan 2023 16:50:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EAAE98E0001 for ; Thu, 5 Jan 2023 16:50:42 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B2B2BAB26A for ; Thu, 5 Jan 2023 21:50:42 +0000 (UTC) X-FDA: 80322090324.13.0B9B40E Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf26.hostedemail.com (Postfix) with ESMTP id 206BD140017 for ; Thu, 5 Jan 2023 21:50:40 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=N97E5S+E; spf=pass (imf26.hostedemail.com: domain of 3L0a3YwQKCLwhxfniqqing.eqonkpwz-oomxcem.qti@flex--fvdl.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3L0a3YwQKCLwhxfniqqing.eqonkpwz-oomxcem.qti@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672955441; h=from:from:sender: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:in-reply-to: references:dkim-signature; bh=nP/z/JBqOEN3G/0yT/CVyehLx6D/Q3uxCkHEL+HhJlE=; b=m6o+NJjTf43wOYXDml43X6IhCF8sUNbqW1mVQtIILqNCzSi+sGE+LK1Q5dZa0TF+X7DKoz GInIvVh068w7AvSC24kXMUC9lF5lVBr+6cRq+YL8h017qPX6dVweyZq8GvO0WiMsslSx/4 F2eaB7RZ4P1sSxkGs5rfUKIMfYEwEJs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=N97E5S+E; spf=pass (imf26.hostedemail.com: domain of 3L0a3YwQKCLwhxfniqqing.eqonkpwz-oomxcem.qti@flex--fvdl.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3L0a3YwQKCLwhxfniqqing.eqonkpwz-oomxcem.qti@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672955441; a=rsa-sha256; cv=none; b=OsrhpN74TRWCNYm85DZYWAE4/q5KoUYZf1uebO6VaqgBJ+jk6ycfT1zxrr1iC0KAivMM6z M5wSRs1RXr30RVwM3tzR0jkYFQeK+Dh3lTnUPfpm/6AQBQOTzHJZ/pph+cT73Ifpi2Mq9U hRbd2FMdehOKjWu5EmCkeS+2dc/7Aa0= Received: by mail-pg1-f201.google.com with SMTP id a33-20020a630b61000000b00429d91cc649so17356957pgl.8 for ; Thu, 05 Jan 2023 13:50:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=nP/z/JBqOEN3G/0yT/CVyehLx6D/Q3uxCkHEL+HhJlE=; b=N97E5S+E19lrAA4AQWnVeQ1zPSI0udLcTpaNriOGvpUq9sa93S5fYLC7jcQTY3c9GH 6vOlPIQ3EasbKuKKa8f636fsORW9LNYqxshuIakJO+CZHogzqOL8B4x8iYt2zEtiWJn0 qonI8Mt6fMK2CQ0R8+0cwqIob8axzuaR+oc8vBV7mlOr1D5thgSrLP7y2GaFY4egSTMx 3Cp9uzfd/KHIarx6zebfq/1YYjdskp0Huke2ZihOHEyism7ivm16Y+Rh0nhGqpsk4Qt1 qdnJRbLFydpCaP2k6qq6+R/3uX8DusBFr/4AzavQsanSHYTtPPAAh3FoxrQduBEl81yL isGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nP/z/JBqOEN3G/0yT/CVyehLx6D/Q3uxCkHEL+HhJlE=; b=bHIiIQleoYr0CeXLdtC32EC3egiqd2eY+SCETV9EEQevE5hswKeU6Lgh0SKHjvxYio qAvDV8Hjq5uFT26UWGU8bJ0ga8OAq4LZ2hishqu/WTEE9mKBfxex90scKm1krCCPWNve qY73zEK23sTlVP9MxsV+Vj0HEDTY0KnUb4+YAdM7tT8CdHKdmxI9a6J5x2mmuYMzs9av RtzxMU8LB9jgGT8MZXN52e8Yw2xU1LbD5WsfOkNfqvwHHdPRD1yAll5PhvW94TCl2YKL Izbzy5RInvfBVmVjJjQ8LjpIVh2c7LnER6rO5L2R5f548EFoiq0CaEelcjrS0VKa+jvr PkjA== X-Gm-Message-State: AFqh2kpZvDBwpzdV9Bmmtv+d9VJnJY22JWW8/dS2hTDovvFIsHgU921s itCY7jdcqpLsPg2NsKghtLk2OAiQ X-Google-Smtp-Source: AMrXdXtbd04vr0JqtXNpUJyCgRXjnSYfhoZPRz0qxGXy+sXe88Z8h6pCRZZ5NtLAPFQ4Ah+2WdXYnDwL X-Received: from fvdl-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:46ab]) (user=fvdl job=sendgmr) by 2002:a17:902:c245:b0:192:6195:44cd with SMTP id 5-20020a170902c24500b00192619544cdmr3862181plg.126.1672955439654; Thu, 05 Jan 2023 13:50:39 -0800 (PST) Date: Thu, 5 Jan 2023 21:50:25 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105215025.422635-1-fvdl@google.com> Subject: [PATCH] mm/debug: use valid physical memory for pmd/pud tests From: Frank van der Linden To: Andrew Morton , linux-mm@kvack.org Cc: Frank van der Linden , Anshuman Khandual X-Stat-Signature: nf38drg66mzokqjmoqhdstf96hfoyqsp X-Rspam-User: X-Rspamd-Queue-Id: 206BD140017 X-Rspamd-Server: rspam06 X-HE-Tag: 1672955440-166578 X-HE-Meta: U2FsdGVkX1+wzZtvqcZRplGLay0YVh41cmhgYpYrKqoneGJLtMJ1XBJEGmJnh8yIBwwd1wGKc7L8Rd7DPxOsMaq6hb2ot1g4kh1QJaZJfh7BQ0U4nuU3H3fEM3zww6NgE2hE6yz1FSLqsN3OOS2Hh36slKLRwi45o3a1PB+1+7lQ/CUtDASltGmDDd+avp6TMY0zSFsNOqoigaU1MeFsbcYuFY1JOIwu/7hBgqN4dW5V3loHDvwOuVfC3CpZmdnImQxeX0kdf+BoRhfvFeYrR5SrXVKkU32ZMKWsDCOd5Zl+FnU1msrGhbHRiFl8ZCB/F4+vIvwewJzu+PRduwTzRtvTo+3pLVTMIN+z0a1cDrJ030vYT2cdbSaxYaihtqnghGJ5J2qfuAK6vQaH/AHnuUxVTFDY4DBbm6PtEacCfBaSkijjf90RwMoskRZLWf2SZ1tN5RGOyfeE+4Pr0oF3dQNuMyX2j1LQ17l0ugoUC/1GUK/qa/Slh954LYkLJHrJIqajOQXxVwnJ28ayKknzXGDubIpF4RkxdP3eoZCB/bVkHt/Sniu2kOxEVXxa3GuE36kEdKAAWIMyUMHZ80QEEQ9fmK0rs68PtQMbumipaXM19j67d6oNWpHwAP7IyvIoZQ+biILHGDchvdGyNZF57RsLfLxOouBg89t7vmgQUa1JCwYsaigCBRRgDPHly0SMS2F86v6fp9BGu8oTXTfZ6f2IkNNEh7nK5LVrwqt+pA7G2v2Hb0LsuujpcAfEwCihdKs1D7bWV9efuS5qvYTfWMj8l3n6gJJn2oL4zQokxPM7cGEPpUoz4/flcofknj+n3cHuwZK457sD+Lxh3w+26Sdszey9ExY4vo7+trjeSD0IRk4pFzCsSnsWuig8FYDeHzPUKPLiAQioUd96nP4H/lvK67l6Ibd06Xb28o5fWYBgBeqpl1hqC3H3FWpcM0GMh540uCVPhZDZt743jSN HSZexiZ8 0BxuDNbyn6OWtNaD/o/rSxH0pD/ZAG/3KA+Oz/ksyRoZM7yDMck3t+b+UUlnphncQQ2MTxdCs/fc7mTzaFb/FRz+9zfh1upmHL9Pzt6HdUndf43+3knxXDpDN2R55DnPznQVNpelOm1W3DZxvFNpv86FDJDgyubBxuPiNwD36RB0IeOTJ7+yc7Vr+b0KMx5dDZ5Jor/y2hBi2e2kuK320fon2i+BTibtqSU2cm4NDc7ZXMSQ2DxqeYYAagL4T7l41yJY0zUKKTbts/EVCceib2Sw5roZ0o900EXcnVXZvOzdtWWPdNpqSh9ZfySZU9xThoNIvCDF/v38KlQndubN827M+UE88Zibp9TEl X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The page table debug tests need a physical address to validate low-level page table manipulation with. The memory at this address is not actually touched, it just encoded in the page table entries at various levels during the tests only. Since the memory is not used, the code just picks the physical address of the start_kernel symbol. This value is then truncated to get a properly aligned address that is to be used for various tests. Because of the truncation, the address might not actually exist, or might not describe a complete huge page. That's not a problem for most tests, but the arch-specific code may check for attribute validity and consistency. The x86 version of {pud,pmd}_set_huge actually validates the MTRRs for the PMD/PUD range. This may fail with an address derived from start_kernel, depending on where the kernel was loaded and what the physical memory layout of the system is. This then leads to false negatives for the {pud,pmd}_set_huge tests. Avoid this by finding a properly aligned memory range that exists and is usable. If such a range is not found, skip the tests that needed it. Fixes: 399145f9eb6c ("mm/debug: add tests validating architecture page table helpers") Cc: Anshuman Khandual Signed-off-by: Frank van der Linden --- mm/debug_vm_pgtable.c | 70 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index c631ade3f1d2..e9b52600904a 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,8 @@ struct pgtable_debug_args { unsigned long pmd_pfn; unsigned long pte_pfn; + phys_addr_t fixed_alignment; + unsigned long fixed_pgd_pfn; unsigned long fixed_p4d_pfn; unsigned long fixed_pud_pfn; @@ -430,7 +433,8 @@ static void __init pmd_huge_tests(struct pgtable_debug_args *args) { pmd_t pmd; - if (!arch_vmap_pmd_supported(args->page_prot)) + if (!arch_vmap_pmd_supported(args->page_prot) || + args->fixed_alignment < PMD_SIZE) return; pr_debug("Validating PMD huge\n"); @@ -449,7 +453,8 @@ static void __init pud_huge_tests(struct pgtable_debug_args *args) { pud_t pud; - if (!arch_vmap_pud_supported(args->page_prot)) + if (!arch_vmap_pud_supported(args->page_prot) || + args->fixed_alignment < PUD_SIZE) return; pr_debug("Validating PUD huge\n"); @@ -1077,11 +1082,41 @@ debug_vm_pgtable_alloc_huge_page(struct pgtable_debug_args *args, int order) return page; } +/* + * Check if a physical memory range described by contains + * an area that is of size psize, and aligned to the same. + * + * Don't use address 0, and check for overflow. + */ +static int __init phys_align_check(phys_addr_t pstart, + phys_addr_t pend, phys_addr_t psize, phys_addr_t *physp, + phys_addr_t *alignp) +{ + phys_addr_t aligned_start, aligned_end; + + if (pstart == 0) + pstart = PAGE_SIZE; + + aligned_start = ALIGN(pstart, psize); + aligned_end = aligned_start + psize; + + if (aligned_end > aligned_start && aligned_end <= pend) { + *alignp = psize; + *physp = aligned_start; + return 1; + } + + return 0; +} + + static int __init init_args(struct pgtable_debug_args *args) { struct page *page = NULL; phys_addr_t phys; int ret = 0; + u64 idx; + phys_addr_t pstart, pend; /* * Initialize the debugging data. @@ -1161,15 +1196,32 @@ static int __init init_args(struct pgtable_debug_args *args) WARN_ON(!args->start_ptep); /* - * PFN for mapping at PTE level is determined from a standard kernel - * text symbol. But pfns for higher page table levels are derived by - * masking lower bits of this real pfn. These derived pfns might not - * exist on the platform but that does not really matter as pfn_pxx() - * helpers will still create appropriate entries for the test. This - * helps avoid large memory block allocations to be used for mapping - * at higher page table levels in some of the tests. + * Find a valid physical range, preferably aligned to PUD_SIZE. + * Return the address and the alignment. It doesn't need to be + * allocated, it just needs to exist as usable memory. The memory + * won't be touched. + * + * The alignment is recorded, and can be checked to see if we + * can run the tests that require and actual valid physical + * address range on some architectures ({pmd,pud}_huge_test + * on x86). */ + phys = __pa_symbol(&start_kernel); + args->fixed_alignment = PAGE_SIZE; + + for_each_mem_range(idx, &pstart, &pend) { + if (phys_align_check(pstart, pend, PUD_SIZE, &phys, + &args->fixed_alignment)) + break; + + if (args->fixed_alignment >= PMD_SIZE) + continue; + + (void)phys_align_check(pstart, pend, PMD_SIZE, &phys, + &args->fixed_alignment); + } + args->fixed_pgd_pfn = __phys_to_pfn(phys & PGDIR_MASK); args->fixed_p4d_pfn = __phys_to_pfn(phys & P4D_MASK); args->fixed_pud_pfn = __phys_to_pfn(phys & PUD_MASK);