From patchwork Thu May 23 13:21:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13671840 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 C9DE0C25B75 for ; Thu, 23 May 2024 13:21:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AFFD6B0085; Thu, 23 May 2024 09:21:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25F926B0088; Thu, 23 May 2024 09:21:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 127046B0089; Thu, 23 May 2024 09:21:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E6EE46B0085 for ; Thu, 23 May 2024 09:21:48 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 94A7A1A05E7 for ; Thu, 23 May 2024 13:21:48 +0000 (UTC) X-FDA: 82149723096.15.8903EAF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 955FD40014 for ; Thu, 23 May 2024 13:21:45 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716470505; 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:content-transfer-encoding:in-reply-to: references; bh=VsbXcm1sxFBR27e0f5ft9IivKoeATBdnB7W0mM8QHqU=; b=ydbQyIKkJddbmiMIJ44Y2V0AlXq2VL+9bQE2OlTEuc/BrJ4M4JHs4Ci37rCITU5sTSyGhO WS6jUTgXuCGzUgKKJSVv9GAJlQHwpubvvdVusb5s1LYZ7sH0yiHdLcX8VElNSAuxxaIrh4 37A89hSSAE7daCrWkQk1A0tn3bVlLN8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716470505; a=rsa-sha256; cv=none; b=YUvQUNbsVdudkPnb6ymXBiarN0PtBGQxkmL/waRPXYGALpKJ8vAYkhVm0EUk/hY4pCuRrI g2EdCyVBZY91fWm/GY0kjaw9wr0t8F27p5xAb7ua52dzE99U6BOismWmxGSse3idq6cYf5 C7c67QsJkRWpj90Dg3E8gHeFH6mnLEA= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-K1YaVxAWPVm9eZa0GEhK8Q-1; Thu, 23 May 2024 09:21:43 -0400 X-MC-Unique: K1YaVxAWPVm9eZa0GEhK8Q-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6ab89f69cd8so459246d6.0 for ; Thu, 23 May 2024 06:21:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716470502; x=1717075302; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VsbXcm1sxFBR27e0f5ft9IivKoeATBdnB7W0mM8QHqU=; b=q/eCLCgmSlF3Sx+oifbYSgBOiuX626uOAJDQzQCVZL14aKFcg1Gq//uj/u9viy+OfU mQpW7Brt0pZ9N1oWIYPPOfTddxVOC2ZjWxGXC0WvTGZf8nNyp0kD/NcOk2HsBoo1Qe5A Nz5Jm59x7DM5Xg6zjPpJabRRKGbBUYm96vfeBYuJhqm/vKvbxteHHNz61ZJjdYF6dPxv OPzvbEvkpbX6zGSelLZ3BL1zqots0UyVIPggDTMFM/w4UygjcfmXJ+4ua3IP2uoha/ox CRrzR41htwpJ7hYAXLCFNG6kFS/boNgQLFZ47l5fwMAKZKmYSHe8mGi3fFfWvjPOZzdW cSeA== X-Forwarded-Encrypted: i=1; AJvYcCVduE+pJA70tv5b6Xmat7Eei1fTr/2hgiWlqQBXIarMKQ1ednoY9I1SaUT6+NKY5w/jhmSV2ci7sM/gnYGfinB+YeI= X-Gm-Message-State: AOJu0Yw53RSZxl88bI5E3KyZAGGtwZMLhUECXJ7PTl6ZnuUaQmDqpLFT iteCzEjW1qaIJecSJu6h6w33HzH+pTuzdW3J25Tml+3bmGXhsKVllRWzD5cjYQyNsGKqZE1cLaU 3OeApOsMJTjgWfJLbtY+ZNfyeTHXEvR9BB7SCAbCqtaqUe7ny X-Received: by 2002:a05:6214:20ca:b0:6a0:cd60:cd3b with SMTP id 6a1803df08f44-6ab808f7119mr50152986d6.3.1716470502382; Thu, 23 May 2024 06:21:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7NO9vVltJj/+QkjBYp5MEJF3IkhEATQaB+o8Vu0R5dHDKGWSJnhD6+0WyJTsI/P7Ex3Q1fg== X-Received: by 2002:a05:6214:20ca:b0:6a0:cd60:cd3b with SMTP id 6a1803df08f44-6ab808f7119mr50152616d6.3.1716470501696; Thu, 23 May 2024 06:21:41 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab873f7108sm13713156d6.125.2024.05.23.06.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 06:21:41 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , peterx@redhat.com, David Hildenbrand , Pavel Tatashin , "Aneesh Kumar K . V" , Gavin Shan , Anshuman Khandual , Mikhail Gavrilov Subject: [PATCH] mm/debug_vm_pgtable: Drop RANDOM_ORVALUE trick Date: Thu, 23 May 2024 09:21:39 -0400 Message-ID: <20240523132139.289719-1-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 955FD40014 X-Stat-Signature: mm3f84kn9zf4ti1aoj746xw7p3wpcbpu X-HE-Tag: 1716470505-94779 X-HE-Meta: U2FsdGVkX18x6ILMmYvf6j1NoW1HyPwPzKvuwXORt7OIHaZS5vREzWjjrWq4uvRKqsw3pFIkS7bdvz2EAjvaupSmmWjUPIyF2bulPtutT3xnw8LiuhNovkCCvHfOSQwG+B9QDfHryZqfZmEnmKZXpIA1aHAJ0o08wydAD72HTD/G6HPb+dqCAP8tHQWx8eRurrb8h3qUzTmvj3bZHdN8vYv/epiaO3kD4IX+IPIb9clvvwRoh55qcsqkTb69bIBvnytFSU6YmtqhM2ABMs5Ne5E0z0rKB7Fvt14t/hVf+3UyLpPtan5QCDX/fWo48ppKkMqeyB7xQoGYblDg25+tiHLnYZsLqxJC5cJYIbV5n+qn4/A95bk9NH3zdcllNV6YS0RSlZv+JO0whiC0CJ2N/7Rc/HGR5b+Z42XH9jew5YRozrp8w3bY3Rk4LrlWR6IjTI7Vjo0ld6MruJJK2PgALHY8qK3JcFk6niSooyJcRQLmkqZ9Z/D6TAZldm/jAPPZvSoz9fW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Sy4nXC7AtSAhrjm4bzxKK8Yj4aibWYKpR6d6Pl0sDJ7qIGZ+VpqI6c/+Z30GocOTYHY6veyhcGeFwPIRTYirH9x9LTKoA4AA6Q== 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: List-Subscribe: List-Unsubscribe: Macro RANDOM_ORVALUE was used to make sure the pgtable entry will be populated with !none data in clear tests. The RANDOM_ORVALUE tried to cover mostly all the bits in a pgtable entry, even if there's no discussion on whether all the bits will be vaild. Both S390 and PPC64 have their own masks to avoid touching some bits. Now it's the turn for x86_64. The issue is there's a recent report from Mikhail Gavrilov showing that this can cause a warning with the newly added pte set check in commit 8430557fc5 on writable v.s. userfaultfd-wp bit, even though the check itself was valid, the random pte is not. We can choose to mask more bits out. However the need to have such random bits setup is questionable, as now it's already guaranteed to be true on below: - For pte level, the pgtable entry will be installed with value from pfn_pte(), where pfn points to a valid page. Hence the pte will be !none already if populated with pfn_pte(). - For upper-than-pte level, the pgtable entry should contain a directory entry always, which is also !none. All the cases look like good enough to test a pxx_clear() helper. Instead of extending the bitmask, drop the "set random bits" trick completely. Add some warning guards to make sure the entries will be !none before clear(). Cc: David Hildenbrand Cc: Pavel Tatashin Cc: Aneesh Kumar K.V Cc: Gavin Shan Cc: Anshuman Khandual Reported-by: Mikhail Gavrilov Tested-by: Mikhail Gavrilov Link: https://lore.kernel.org/r/CABXGCsMB9A8-X+Np_Q+fWLURYL_0t3Y-MdoNabDM-Lzk58-DGA@mail.gmail.com Signed-off-by: Peter Xu Acked-by: David Hildenbrand Reviewed-by: Pasha Tatashin --- mm/debug_vm_pgtable.c | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index f1c9a2c5abc0..866eddb6cfda 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -40,22 +40,7 @@ * Please refer Documentation/mm/arch_pgtable_helpers.rst for the semantics * expectations that are being validated here. All future changes in here * or the documentation need to be in sync. - * - * On s390 platform, the lower 4 bits are used to identify given page table - * entry type. But these bits might affect the ability to clear entries with - * pxx_clear() because of how dynamic page table folding works on s390. So - * while loading up the entries do not change the lower 4 bits. It does not - * have affect any other platform. Also avoid the 62nd bit on ppc64 that is - * used to mark a pte entry. */ -#define S390_SKIP_MASK GENMASK(3, 0) -#if __BITS_PER_LONG == 64 -#define PPC64_SKIP_MASK GENMASK(62, 62) -#else -#define PPC64_SKIP_MASK 0x0 -#endif -#define ARCH_SKIP_MASK (S390_SKIP_MASK | PPC64_SKIP_MASK) -#define RANDOM_ORVALUE (GENMASK(BITS_PER_LONG - 1, 0) & ~ARCH_SKIP_MASK) #define RANDOM_NZVALUE GENMASK(7, 0) struct pgtable_debug_args { @@ -511,8 +496,7 @@ static void __init pud_clear_tests(struct pgtable_debug_args *args) return; pr_debug("Validating PUD clear\n"); - pud = __pud(pud_val(pud) | RANDOM_ORVALUE); - WRITE_ONCE(*args->pudp, pud); + WARN_ON(pud_none(pud)); pud_clear(args->pudp); pud = READ_ONCE(*args->pudp); WARN_ON(!pud_none(pud)); @@ -548,8 +532,7 @@ static void __init p4d_clear_tests(struct pgtable_debug_args *args) return; pr_debug("Validating P4D clear\n"); - p4d = __p4d(p4d_val(p4d) | RANDOM_ORVALUE); - WRITE_ONCE(*args->p4dp, p4d); + WARN_ON(p4d_none(p4d)); p4d_clear(args->p4dp); p4d = READ_ONCE(*args->p4dp); WARN_ON(!p4d_none(p4d)); @@ -582,8 +565,7 @@ static void __init pgd_clear_tests(struct pgtable_debug_args *args) return; pr_debug("Validating PGD clear\n"); - pgd = __pgd(pgd_val(pgd) | RANDOM_ORVALUE); - WRITE_ONCE(*args->pgdp, pgd); + WARN_ON(pgd_none(pgd)); pgd_clear(args->pgdp); pgd = READ_ONCE(*args->pgdp); WARN_ON(!pgd_none(pgd)); @@ -634,10 +616,8 @@ static void __init pte_clear_tests(struct pgtable_debug_args *args) if (WARN_ON(!args->ptep)) return; -#ifndef CONFIG_RISCV - pte = __pte(pte_val(pte) | RANDOM_ORVALUE); -#endif set_pte_at(args->mm, args->vaddr, args->ptep, pte); + WARN_ON(pte_none(pte)); flush_dcache_page(page); barrier(); ptep_clear(args->mm, args->vaddr, args->ptep); @@ -650,8 +630,7 @@ static void __init pmd_clear_tests(struct pgtable_debug_args *args) pmd_t pmd = READ_ONCE(*args->pmdp); pr_debug("Validating PMD clear\n"); - pmd = __pmd(pmd_val(pmd) | RANDOM_ORVALUE); - WRITE_ONCE(*args->pmdp, pmd); + WARN_ON(pmd_none(pmd)); pmd_clear(args->pmdp); pmd = READ_ONCE(*args->pmdp); WARN_ON(!pmd_none(pmd));