From mboxrd@z Thu Jan 1 00:00:00 1970 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE47ECA1016 for ; Mon, 8 Sep 2025 07:40:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B2C48E000C; Mon, 8 Sep 2025 03:40:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 164468E0001; Mon, 8 Sep 2025 03:40:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 051DE8E000C; Mon, 8 Sep 2025 03:40:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DFAFE8E0001 for ; Mon, 8 Sep 2025 03:40:36 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7C0DCBC821 for ; Mon, 8 Sep 2025 07:40:36 +0000 (UTC) X-FDA: 83865285672.15.F98ED35 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf05.hostedemail.com (Postfix) with ESMTP id DB1F3100007 for ; Mon, 8 Sep 2025 07:40:34 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf05.hostedemail.com: domain of kevin.brodsky@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=kevin.brodsky@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1757317235; 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; bh=MFkkO1F/ehQm5F1fclNMPZMJvYctYpk2C79PJc5Is3I=; b=xKUwtW57evwCDcA5ejWESNbumMosWT0NK7DrdgOE7Gp+pYuq8GmmtweG/R+eWwF5aLQzc2 9AcE3p/bw9t2HpbGmgH50Ezg/LSk6C9X8QbGUpOA3ynD9GMY+lFrDWotM0vSPCAC65J1pU 2XF8kCu2VewoYrPHEQ4hSAsH0CEZ9X0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf05.hostedemail.com: domain of kevin.brodsky@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=kevin.brodsky@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1757317235; a=rsa-sha256; cv=none; b=WjM7y9pHNtiawBBQ8troddHqWIOaCZafAKPO1MdIxy+LCG9JyPox4zm1+tHNvoG0JHdYYc cv6fJT0kkH0vvanTYQKV1/M0tVYF/vdTwEz0lAXcF/vZ42ZBPiulGlWLGiKP/kAR3rGPZA OhavBTnW/lcOodipzeJultYIu0/ZTXg= 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 7E6E91692; Mon, 8 Sep 2025 00:40:25 -0700 (PDT) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 23BFF3F63F; Mon, 8 Sep 2025 00:40:29 -0700 (PDT) From: Kevin Brodsky To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Alexander Gordeev , Andreas Larsson , Andrew Morton , Boris Ostrovsky , Borislav Petkov , Catalin Marinas , Christophe Leroy , Dave Hansen , David Hildenbrand , "David S. Miller" , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Juergen Gross , "Liam R. Howlett" , Lorenzo Stoakes , Madhavan Srinivasan , Michael Ellerman , Michal Hocko , Mike Rapoport , Nicholas Piggin , Peter Zijlstra , Ryan Roberts , Suren Baghdasaryan , Thomas Gleixner , Vlastimil Babka , Will Deacon , Yeoreum Yun , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH v2 0/7] Nesting support for lazy MMU mode Date: Mon, 8 Sep 2025 08:39:24 +0100 Message-ID: <20250908073931.4159362-1-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: 7183y8jje6spozhkg6opf6sjgz7u6qwm X-Rspam-User: X-Rspamd-Queue-Id: DB1F3100007 X-Rspamd-Server: rspam01 X-HE-Tag: 1757317234-240228 X-HE-Meta: U2FsdGVkX1+9cyHQlDu4yIOyUF+HWiJA6GQOgX/jsrIAwt5N+W3a70OyCBlbDNsXfo3PzTl9Ta3e4nmZTkW4rtfYl+75eNIRWfMX5zAv7MZgq4ZMo8i4QzwnHG+Z/17QpC/u2n2ROepaXu0oTBCCXwuh0eLdzUAFyPenC/ynIwtvBvU7zr5AsGnzoKdHtg+aBFNnbAnNxYu9FTmlCJgxQW4tlNgelIbKieGM/zqjglCVfmo1XSskSgD4e/68eXqiCjI/hwxySFqxDLIcEhlOAueRBbqu01MECBrV9oCXQNC6+TP5ab4LmH/gMeuyPCafQTa1fk8W/poUuEQPdJWv2moB7Iw4yJyPJaj7Lm3q8N0Ive6ZqHoPwJ6CVHSnJfUCIhOHGd98BRaPaDb1zgWybJMuUaQST+GBEqClpTHbrV6NjV55QLl6gJVoqz91gH06/tE0X0XB97BqlkwC3MReAyzD/7rF2S5zekJXjNztd6iEGwsnFEf4Ewxo9dbp69kb0DvNKo4wtfPmucYWTaXixZ9XqciGiYpXsRi04wIOuMJ5f/xvrBP2xqASkbQuL+1XoQpT8ektS0fO8mq6228UDx7Y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YOoCSVQu+KGT3fxJd0qzQ5+8sTVDhfb6rpqVYZyHxA0opkzHahp0dmdxzdOJGPtfGeQO27QWVCkKXlnRYgboxx8LcS6YoJuU4eWnYq62h1llD1t/Z+YvtYNjALwRiPtqZ3aTZLWx32Zh3v/+4gzty2vH0C4lz6pjrX6WSO6LOTFyz 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: When the lazy MMU mode was introduced eons ago, it wasn't made clear whether such a sequence was legal: arch_enter_lazy_mmu_mode() ... arch_enter_lazy_mmu_mode() ... arch_leave_lazy_mmu_mode() ... arch_leave_lazy_mmu_mode() It seems fair to say that nested calls to arch_{enter,leave}_lazy_mmu_mode() were not expected, and most architectures never explicitly supported it. Ryan Roberts' series from March [1] attempted to prevent nesting from ever occurring, and mostly succeeded. Unfortunately, a corner case (DEBUG_PAGEALLOC) may still cause nesting to occur on arm64. Ryan proposed [2] to address that corner case at the generic level but this approach received pushback; [3] then attempted to solve the issue on arm64 only, but it was deemed too fragile. It feels generally fragile to rely on lazy_mmu sections not to nest, because callers of various standard mm functions do not know if the function uses lazy_mmu itself. This series therefore performs a U-turn and adds support for nested lazy_mmu sections, on all architectures. The main change enabling nesting is patch 2, following the approach suggested by Catalin Marinas [4]: have enter() return some state and the matching leave() take that state. In this series, the state is only used to handle nesting, but it could be used for other purposes such as restoring context modified by enter(); the proposed kpkeys framework would be an immediate user [5]. Patch overview: * Patch 1: general cleanup - not directly related, but avoids any doubt regarding the expected behaviour of arch_flush_lazy_mmu_mode() outside x86 * Patch 2: main API change, no functional change * Patch 3-6: nesting support for all architectures that support lazy_mmu * Patch 7: clarification that nesting is supported in the documentation Patch 4-6 are technically not required at this stage since nesting is only observed on arm64, but they ensure future correctness in case nesting is (re)introduced in generic paths. For instance, it could be beneficial in some configurations to enter lazy_mmu set_ptes() once again. This series has been tested by running the mm kselfetsts on arm64 with DEBUG_PAGEALLOC and KFENCE. It was also build-tested on other architectures (with and without XEN_PV on x86). - Kevin [1] https://lore.kernel.org/all/20250303141542.3371656-1-ryan.roberts@arm.com/ [2] https://lore.kernel.org/all/20250530140446.2387131-1-ryan.roberts@arm.com/ [3] https://lore.kernel.org/all/20250606135654.178300-1-ryan.roberts@arm.com/ [4] https://lore.kernel.org/all/aEhKSq0zVaUJkomX@arm.com/ [5] https://lore.kernel.org/linux-hardening/20250815085512.2182322-19-kevin.brodsky@arm.com/ --- Changelog v1..v2: - Rebased on mm-unstable. - Patch 2: handled new calls to enter()/leave(), clarified how the "flush" pattern (leave() followed by enter()) is handled. - Patch 5,6: removed unnecessary local variable [Alexander Gordeev's suggestion]. - Added Mike Rapoport's Acked-by. v1: https://lore.kernel.org/all/20250904125736.3918646-1-kevin.brodsky@arm.com/ --- Cc: Alexander Gordeev Cc: Andreas Larsson Cc: Andrew Morton Cc: Boris Ostrovsky Cc: Borislav Petkov Cc: Catalin Marinas Cc: Christophe Leroy Cc: Dave Hansen Cc: David Hildenbrand Cc: "David S. Miller" Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Jann Horn Cc: Juergen Gross Cc: "Liam R. Howlett" Cc: Lorenzo Stoakes Cc: Madhavan Srinivasan Cc: Michael Ellerman Cc: Michal Hocko Cc: Mike Rapoport Cc: Nicholas Piggin Cc: Peter Zijlstra Cc: Ryan Roberts Cc: Suren Baghdasaryan Cc: Thomas Gleixner Cc: Vlastimil Babka Cc: Will Deacon Cc: Yeoreum Yun Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: sparclinux@vger.kernel.org Cc: xen-devel@lists.xenproject.org --- Kevin Brodsky (7): mm: remove arch_flush_lazy_mmu_mode() mm: introduce local state for lazy_mmu sections arm64: mm: fully support nested lazy_mmu sections x86/xen: support nested lazy_mmu sections (again) powerpc/mm: support nested lazy_mmu sections sparc/mm: support nested lazy_mmu sections mm: update lazy_mmu documentation arch/arm64/include/asm/pgtable.h | 34 ++++++------------- .../include/asm/book3s/64/tlbflush-hash.h | 22 ++++++++---- arch/powerpc/mm/book3s64/hash_tlb.c | 10 +++--- arch/powerpc/mm/book3s64/subpage_prot.c | 5 +-- arch/sparc/include/asm/tlbflush_64.h | 6 ++-- arch/sparc/mm/tlb.c | 17 +++++++--- arch/x86/include/asm/paravirt.h | 8 ++--- arch/x86/include/asm/paravirt_types.h | 6 ++-- arch/x86/include/asm/pgtable.h | 3 +- arch/x86/xen/enlighten_pv.c | 2 +- arch/x86/xen/mmu_pv.c | 13 ++++--- fs/proc/task_mmu.c | 5 +-- include/linux/mm_types.h | 3 ++ include/linux/pgtable.h | 21 +++++++++--- mm/kasan/shadow.c | 4 +-- mm/madvise.c | 20 ++++++----- mm/memory.c | 20 ++++++----- mm/migrate_device.c | 5 +-- mm/mprotect.c | 5 +-- mm/mremap.c | 5 +-- mm/userfaultfd.c | 5 +-- mm/vmalloc.c | 15 ++++---- mm/vmscan.c | 15 ++++---- 23 files changed, 148 insertions(+), 101 deletions(-) base-commit: b024763926d2726978dff6588b81877d000159c1 -- 2.47.0