From patchwork Fri Jan 13 17:10:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13101194 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 B2309C54EBD for ; Fri, 13 Jan 2023 17:10:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B0E48E0003; Fri, 13 Jan 2023 12:10:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2607F8E0001; Fri, 13 Jan 2023 12:10:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 128628E0003; Fri, 13 Jan 2023 12:10:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 062A28E0001 for ; Fri, 13 Jan 2023 12:10:59 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CB70F1C6060 for ; Fri, 13 Jan 2023 17:10:58 +0000 (UTC) X-FDA: 80350415796.26.2AC17D7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 4AA29C000D for ; Fri, 13 Jan 2023 17:10:57 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MzzgZFn9; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673629857; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rXiyu4T9E3cHd7BmjOKGfZSf96+T1UTdr6M/Zzcd1iA=; b=73jaaOxXGkgZsUe97qsmXHFdSkL9Uag1OBWF3q4x9+I5MDUb9ezi3kby62PVgUPaEzsupf JBXKnrVxFx9VL8H5cSUECnLFxO9l5sgPyL5K3/bMxxtbd6jpKgFMS21r1tB49pm05HxP3s TyrQRcxrwohrw5UKTK4q38Q8AHkY7MM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MzzgZFn9; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673629857; a=rsa-sha256; cv=none; b=y2QzSvRlmTzxDPquV3SBE0HC/6u0AOXD2uVSwsWiyMTQv4rTFe3aFErmOPnK5AWtQh6wdT 56IldLYMR6GkYlAT1W0Lj2JYQhlh3l0yoW+mlpMtiUHio6YjqTtj3Y5FnMthr8Lm9DFTD/ u8wHfU6UBLjTEm3tWGxJjSx9nrPZVEg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673629856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rXiyu4T9E3cHd7BmjOKGfZSf96+T1UTdr6M/Zzcd1iA=; b=MzzgZFn9sHvvvkJqpOIAgVaumGdbHCkIhUchZCBwdusCm2cqP3dPZoZ6vERhF29yKcf5i1 YgrmL1xiHJ9jiTy+IN5O+2TjsnhIsFo/DhCO2/2YKEpssRLsN3SSfgQ0EStUmiGh6UR3Vw boNELFaA2aE0/DAMStEV7AvNX0/52nc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-131-UP7pYWA7N8-Lxng6Qfiptg-1; Fri, 13 Jan 2023 12:10:53 -0500 X-MC-Unique: UP7pYWA7N8-Lxng6Qfiptg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E39ED3C0D195; Fri, 13 Jan 2023 17:10:51 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8457040C2064; Fri, 13 Jan 2023 17:10:44 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Hugh Dickins , John Hubbard , Jason Gunthorpe , Mike Rapoport , Yang Shi , Vlastimil Babka , Nadav Amit , Andrea Arcangeli , Peter Xu , linux-mm@kvack.org, x86@kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-xtensa@linux-xtensa.org, David Hildenbrand Subject: [PATCH mm-unstable v1 01/26] mm/debug_vm_pgtable: more pte_swp_exclusive() sanity checks Date: Fri, 13 Jan 2023 18:10:01 +0100 Message-Id: <20230113171026.582290-2-david@redhat.com> In-Reply-To: <20230113171026.582290-1-david@redhat.com> References: <20230113171026.582290-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4AA29C000D X-Stat-Signature: yo1985y3tbjpze8o76fj9g87tqh6bj9y X-HE-Tag: 1673629857-305043 X-HE-Meta: U2FsdGVkX19Z+uZ2Stsz3apXPjTBY8udGsW5d12XbnGMbTFF1LsL2ezaZFDE6YzsuIJSUYtdpOQyetDWqnvC5/loSW1AVDMrsXCQkyyr++SufBEtTcIqZlPvS6MLwIU/LirRDtXX/G6hP2AHmwUZNwLeVt5P5HcLyMzBKWQ7EPsUbzjCJQpgY915m9CwPzSgbAFJulr5IjuguoFqyiP3wqgxU0Q8kJECNN1LiMP2VwHq9VvGHzbMF4UhAeiXtbL5BUmjraPhVEo5B/J+xtiVY0GvwXALvRBCFTxpqUyciL5JgdlSlP8gkh0RIAySDr4K0hG/yhD7m3Sy6mseQ2ki5e/ZVbjb6/Evi/BlDOSi16fxTb7yPJBoMkKFqaDXwJ1tsYNRadOqZ/0z7MAxGw3HTnNwLPorVki+VwMv5V7VZITq8eObPQDeNhlt6LEzp4dsLrfRBY673Sxog0cWsMHY2cPty09McQIvb8xCaSRkpMBcEh45iwud0pZw5H6kQcFv7RbjwCHoVRijoOqvGlryvdrtLTp3GAO+4Y0lpmmrb8/sayfBJrZqvru/ajZLlphpHiLKawC/FLQWdBW4yBEock+nG1HomGVF8tKSjjoHk/rNbDs8mJCWSY8WzXetSqFDZ+OfqKb6WuS7ZFya8DtXSsu1B2cJ6hW/C+7DNjZQNa7DoQF/1Px1WFkAbRZS654e3bjUAClvvYAJb5pWLkWSV4t1YOLIY8//aQ/EZcgMt98HK1z5ocCWaSVyW2L4uGqkRtIuYH8Bo7RWaStOMCa7vbD16LT2iddZbxol+hWdYIdi9W5+Nsvd8mWvCgUMYkaI0ZNszY93Q7MzBvrQWZ+hdWFW0zrzW549sLNN2/6Dp0K05QMdwUYX5Zp+niYyM8NN1PPgQADBF/xxQAlUKiwEygZITYlg+XJrxfDHwA8OxJLMWz66M08pTllUQ+c4Ilg63kQwigcFGAU++BvB4Bh C5HaN1Uy MczjRt+j1b0zNKhyc02UAfTo6QvnI7i1AcjEO 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: We want to implement __HAVE_ARCH_PTE_SWP_EXCLUSIVE on all architectures. Let's extend our sanity checks, especially testing that our PTE bit does not affect: * is_swap_pte() -> pte_present() and pte_none() * the swap entry + type * pte_swp_soft_dirty() Especially, the pfn_pte() is dodgy when the swap PTE layout differs heavily from ordinary PTEs. Let's properly construct a swap PTE from swap type+offset. Signed-off-by: David Hildenbrand Reported-by: kernel test robot Signed-off-by: David Hildenbrand --- mm/debug_vm_pgtable.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index bb3328f46126..a0730beffd78 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -811,13 +811,34 @@ static void __init pmd_swap_soft_dirty_tests(struct pgtable_debug_args *args) { static void __init pte_swap_exclusive_tests(struct pgtable_debug_args *args) { #ifdef __HAVE_ARCH_PTE_SWP_EXCLUSIVE - pte_t pte = pfn_pte(args->fixed_pte_pfn, args->page_prot); + unsigned long max_swapfile_size = generic_max_swapfile_size(); + swp_entry_t entry, entry2; + pte_t pte; pr_debug("Validating PTE swap exclusive\n"); + + /* Create a swp entry with all possible bits set */ + entry = swp_entry((1 << MAX_SWAPFILES_SHIFT) - 1, + max_swapfile_size - 1); + + pte = swp_entry_to_pte(entry); + WARN_ON(pte_swp_exclusive(pte)); + WARN_ON(!is_swap_pte(pte)); + entry2 = pte_to_swp_entry(pte); + WARN_ON(memcmp(&entry, &entry2, sizeof(entry))); + pte = pte_swp_mkexclusive(pte); WARN_ON(!pte_swp_exclusive(pte)); + WARN_ON(!is_swap_pte(pte)); + WARN_ON(pte_swp_soft_dirty(pte)); + entry2 = pte_to_swp_entry(pte); + WARN_ON(memcmp(&entry, &entry2, sizeof(entry))); + pte = pte_swp_clear_exclusive(pte); WARN_ON(pte_swp_exclusive(pte)); + WARN_ON(!is_swap_pte(pte)); + entry2 = pte_to_swp_entry(pte); + WARN_ON(memcmp(&entry, &entry2, sizeof(entry))); #endif /* __HAVE_ARCH_PTE_SWP_EXCLUSIVE */ }