From patchwork Fri Jun 28 14:35:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13716241 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 843DDC2BD09 for ; Fri, 28 Jun 2024 14:35:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEC296B0088; Fri, 28 Jun 2024 10:35:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9BC26B008A; Fri, 28 Jun 2024 10:35:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9642E6B008C; Fri, 28 Jun 2024 10:35:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 792AA6B0088 for ; Fri, 28 Jun 2024 10:35:39 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1E52014039E for ; Fri, 28 Jun 2024 14:35:39 +0000 (UTC) X-FDA: 82280545998.01.3535944 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by imf21.hostedemail.com (Postfix) with ESMTP id 4131B1C0029 for ; Fri, 28 Jun 2024 14:35:36 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bSN3GA9X; spf=pass (imf21.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719585323; 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:references:dkim-signature; bh=/0NwxkLlbP9jgFl/TCIElmahbD3Db/e8/WdXfIoQlZs=; b=77RXBlYiZ7o07NZZCehvV6M+xbjiAJn576tdT26hae0QqWuOrnt2gJ8Btq+Tia7xeZsZkX EzXnHiFe4yTCetnwlSNaZ1JbApCtpVTNofNzrolK7vu8N3geLLVxEtz8ozKNJI1dBrlGMe potQ6ulLhfmPdW6xIPRw9G4kaoO/EA4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bSN3GA9X; spf=pass (imf21.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719585323; a=rsa-sha256; cv=none; b=DMs7lVYXRoE6d/DA72EGXInWZOdrNQDMPtnGWl13XdawjW4pEn70gPUJ5jyulbN2bdlsu9 gDCH9tU5XHi7CkHsYUsHDtqwfLanZ1dLdr/ZveVec8qIl+jA8yDnPUiYpoAnjG5bOM084p spYBN8WI5W5HNMaJ+TnIoPXTlfNWON4= Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4217c7eb6b4so5799875e9.2 for ; Fri, 28 Jun 2024 07:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719585335; x=1720190135; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/0NwxkLlbP9jgFl/TCIElmahbD3Db/e8/WdXfIoQlZs=; b=bSN3GA9X9SGDnDGNoMdh9vARP3G14+jVxnsYU8XTjfSWfkE9FERdK3ODk40QvJpiK4 oyDeKixup95tOSyejj7PEjtGifoQtq0sfpHI0BH0/hM/OQ3hg8MccFT9LFDy58Xt9fKG yL6VH/RI+FIxT6RsbBKWjJxVH1GNFPP72pILiGsD2gQfEABfqcfg0GsHFZ4XhsjN9vqt Fej53+J3UqeWTJo82lSj+NM6kbl5s/tiKhbh+4hmOdAIl6X5XByYixpYrr8k+54u2Ktd bbLfQp4LrfDzLezDZEyLBQZui5g9izixWbnJ6rWFQ/vrSvaph29noBnWoTl59CZcAHQl J3/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719585335; x=1720190135; 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=/0NwxkLlbP9jgFl/TCIElmahbD3Db/e8/WdXfIoQlZs=; b=My7sLc3DxXLpSdo+Cxke5DzZfTgS5tu+9pdreOENINiR6dMctS6hB4ykyzl1R++0l5 j/1J9VZcRoPu7rusivw/doXHyPo+7TLEbeZ0v21HqVTk+4x41d/bPsWkm3YkAVCkSWHZ 2b8DtMCtnETGWOOI1T5JCagIwy8FHDA8Xuv0BAH7mi2CqFUXcqi4XuPl3PnEMIEGk6CA fWA7Ek3+TtTdlAuXGTYkQM5oUdD0XR0PTCPEihtgYhYgYM0kqnW9lN5PS+m+PSnsB4VZ /0F4Qkl5Hw36p015g908Q3ub4Y3DKqREHcJkvfFFbzj+uZEraOgeSQ2Od2tzjum8bAvH j2nw== X-Forwarded-Encrypted: i=1; AJvYcCUSSDjZLWxenGI4av/2sfjnplZ3yq/VI/1HComgB9Che6p148dRgCIsBsEzcBkNGifihxv2Y2bTqOz+6mXBgd0esK0= X-Gm-Message-State: AOJu0Yzcw97wHpG9atyQAQ50m6Bn5+pfDwkuAS9M9Gr/66Kzahs33IDb oZSLKWoKn74OA+NbOzDtf0g8clV+mBzCu6QDuLR9Jbw9O8olFcaG X-Google-Smtp-Source: AGHT+IFnUVHgnwtaOakrbDqmh5eSI+bbvM1Nnux4SzQbNuyj7GLBzZnPk6NITvp02lKAV3Zib0BtvA== X-Received: by 2002:a05:600c:2212:b0:424:a2d9:67c5 with SMTP id 5b1f17b1804b1-424a2d96a8emr74770535e9.16.1719585335320; Fri, 28 Jun 2024 07:35:35 -0700 (PDT) Received: from lucifer.home ([2a00:23cc:d20f:ba01:bb66:f8b2:a0e8:6447]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4256af37828sm38985485e9.9.2024.06.28.07.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 07:35:34 -0700 (PDT) From: Lorenzo Stoakes To: Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Liam R . Howlett" , Vlastimil Babka , Matthew Wilcox , Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook , Suren Baghdasaryan , Lorenzo Stoakes Subject: [RFC PATCH v2 0/7] Make core VMA operations internal and testable Date: Fri, 28 Jun 2024 15:35:21 +0100 Message-ID: X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 X-Stat-Signature: z8i9og4i4owrsxhnzkidf6ydet6xrccd X-Rspam-User: X-Rspamd-Queue-Id: 4131B1C0029 X-Rspamd-Server: rspam02 X-HE-Tag: 1719585336-481565 X-HE-Meta: U2FsdGVkX18VoYlRAVa1FsvwDISOF72cn4F9LFpuoMwQO44Idkc5yQRA+qNj6X8XWTiiC2u4z3k1q1ol8acAa8M59W/nWbb5rHdQQoqg+4FImRRxci94onWh5xPBuu7fnez5RhAHFApWzH2l1Z9uSyZw3ifhNsSRt9oFv6YA8Ev+zm3Sljr3L33ZA53oH/0Rs/5wSsxyyyv6w/FuJd6iCb5taRESD4+WGkEpootbXIfyCq/RAcCZCnaNTIRt+LSGVwWfuRsvubBzL/UbC7R5lbvk+IHqPdscRHisEDWdjZsV5O8k+abKuY7LRzGgdeoMARzpi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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: There are a number of "core" VMA manipulation functions implemented in mm/mmap.c, notably those concerning VMA merging, splitting, modifying, expanding and shrinking, which logically don't belong there. More importantly this functionality represents an internal implementation detail of memory management and should not be exposed outside of mm/ itself. This patch series isolates core VMA manipulation functionality into its own file, mm/vma.c, and provides an API to the rest of the mm code in mm/vma.h. Importantly, it also carefully implements mm/vma_internal.h, which specifies which headers need to be imported by vma.c, leading to the very useful property that vma.c depends only on mm/vma.h and mm/vma_internal.h. This is useful, because we can then re-implement vma_internal.h in userland, stubbing out and adding shims for kernel mechanisms as required, and then can directly and very easily unit test internal VMA functionality. This patch series takes advantage of existing shim logic and full userland maple tree support contained in tools/testing/radix-tree/ and tools/include/linux/, separating out shared components of the radix tree implementation to provide this testing. Kernel functionality is stubbed and shimmed as needed in tools/testing/vma/ which contains a fully functional userland vma_internal.h file and which imports mm/vma.c and mm/vma.h to be directly tested from userland. A simple, skeleton testing implementation is provided in tools/testing/vma/vma.c as a proof-of-concept, asserting that simple VMA merge, modify (testing split), expand and shrink functionality work correctly. v2: * Reword commit messages. * Replace vma_expand() / vma_shrink() wrappers with relocate_vma(). * Make move_page_tables() internal too. * Have internal.h import vma.h. * Use header guards to more cleanly implement userland testing code. * Rename main.c to vma.c. * Update mm/vma_internal.h to have fewer superfluous comments. * Rework testing logic so we count test failures, and output test results. * Correct some SPDX license prefixes. * Make VM_xxx_ON() debug asserts forward to xxx_ON() macros. * Update VMA tests to correctly free memory, and re-enable ASAN leak detection. v1: https://lore.kernel.org/all/cover.1719481836.git.lstoakes@gmail.com/ Lorenzo Stoakes (7): userfaultfd: move core VMA manipulation logic to mm/userfaultfd.c mm: move vma_modify() and helpers to internal header mm: move vma_shrink(), vma_expand() to internal header mm: move internal core VMA manipulation functions to own file MAINTAINERS: Add entry for new VMA files tools: separate out shared radix-tree components tools: add skeleton code for userland testing of VMA logic MAINTAINERS | 14 + fs/exec.c | 68 +- fs/userfaultfd.c | 160 +- include/linux/atomic.h | 2 +- include/linux/mm.h | 112 +- include/linux/mmzone.h | 3 +- include/linux/userfaultfd_k.h | 19 + mm/Makefile | 2 +- mm/internal.h | 167 +- mm/mmap.c | 2070 ++--------------- mm/mmu_notifier.c | 2 + mm/userfaultfd.c | 168 ++ mm/vma.c | 1766 ++++++++++++++ mm/vma.h | 362 +++ mm/vma_internal.h | 52 + tools/testing/radix-tree/Makefile | 68 +- tools/testing/radix-tree/maple.c | 14 +- tools/testing/radix-tree/xarray.c | 9 +- tools/testing/shared/autoconf.h | 2 + tools/testing/{radix-tree => shared}/bitmap.c | 0 tools/testing/{radix-tree => shared}/linux.c | 0 .../{radix-tree => shared}/linux/bug.h | 0 .../{radix-tree => shared}/linux/cpu.h | 0 .../{radix-tree => shared}/linux/idr.h | 0 .../{radix-tree => shared}/linux/init.h | 0 .../{radix-tree => shared}/linux/kconfig.h | 0 .../{radix-tree => shared}/linux/kernel.h | 0 .../{radix-tree => shared}/linux/kmemleak.h | 0 .../{radix-tree => shared}/linux/local_lock.h | 0 .../{radix-tree => shared}/linux/lockdep.h | 0 .../{radix-tree => shared}/linux/maple_tree.h | 0 .../{radix-tree => shared}/linux/percpu.h | 0 .../{radix-tree => shared}/linux/preempt.h | 0 .../{radix-tree => shared}/linux/radix-tree.h | 0 .../{radix-tree => shared}/linux/rcupdate.h | 0 .../{radix-tree => shared}/linux/xarray.h | 0 tools/testing/shared/maple-shared.h | 9 + tools/testing/shared/maple-shim.c | 7 + tools/testing/shared/shared.h | 34 + tools/testing/shared/shared.mk | 68 + .../testing/shared/trace/events/maple_tree.h | 5 + tools/testing/shared/xarray-shared.c | 5 + tools/testing/shared/xarray-shared.h | 4 + tools/testing/vma/.gitignore | 6 + tools/testing/vma/Makefile | 15 + tools/testing/vma/errors.txt | 0 tools/testing/vma/generated/autoconf.h | 2 + tools/testing/vma/linux/atomic.h | 12 + tools/testing/vma/linux/mmzone.h | 38 + tools/testing/vma/vma.c | 207 ++ tools/testing/vma/vma_internal.h | 882 +++++++ 51 files changed, 3910 insertions(+), 2444 deletions(-) create mode 100644 mm/vma.c create mode 100644 mm/vma.h create mode 100644 mm/vma_internal.h create mode 100644 tools/testing/shared/autoconf.h rename tools/testing/{radix-tree => shared}/bitmap.c (100%) rename tools/testing/{radix-tree => shared}/linux.c (100%) rename tools/testing/{radix-tree => shared}/linux/bug.h (100%) rename tools/testing/{radix-tree => shared}/linux/cpu.h (100%) rename tools/testing/{radix-tree => shared}/linux/idr.h (100%) rename tools/testing/{radix-tree => shared}/linux/init.h (100%) rename tools/testing/{radix-tree => shared}/linux/kconfig.h (100%) rename tools/testing/{radix-tree => shared}/linux/kernel.h (100%) rename tools/testing/{radix-tree => shared}/linux/kmemleak.h (100%) rename tools/testing/{radix-tree => shared}/linux/local_lock.h (100%) rename tools/testing/{radix-tree => shared}/linux/lockdep.h (100%) rename tools/testing/{radix-tree => shared}/linux/maple_tree.h (100%) rename tools/testing/{radix-tree => shared}/linux/percpu.h (100%) rename tools/testing/{radix-tree => shared}/linux/preempt.h (100%) rename tools/testing/{radix-tree => shared}/linux/radix-tree.h (100%) rename tools/testing/{radix-tree => shared}/linux/rcupdate.h (100%) rename tools/testing/{radix-tree => shared}/linux/xarray.h (100%) create mode 100644 tools/testing/shared/maple-shared.h create mode 100644 tools/testing/shared/maple-shim.c create mode 100644 tools/testing/shared/shared.h create mode 100644 tools/testing/shared/shared.mk create mode 100644 tools/testing/shared/trace/events/maple_tree.h create mode 100644 tools/testing/shared/xarray-shared.c create mode 100644 tools/testing/shared/xarray-shared.h create mode 100644 tools/testing/vma/.gitignore create mode 100644 tools/testing/vma/Makefile create mode 100644 tools/testing/vma/errors.txt create mode 100644 tools/testing/vma/generated/autoconf.h create mode 100644 tools/testing/vma/linux/atomic.h create mode 100644 tools/testing/vma/linux/mmzone.h create mode 100644 tools/testing/vma/vma.c create mode 100644 tools/testing/vma/vma_internal.h --- 2.45.1