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]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D38CC5B543 for ; Fri, 30 May 2025 14:05:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD3DC6B0127; Fri, 30 May 2025 10:05:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D84026B0128; Fri, 30 May 2025 10:05:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C736E6B0129; Fri, 30 May 2025 10:05:08 -0400 (EDT) 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 A54CE6B0127 for ; Fri, 30 May 2025 10:05:08 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 496B9C0943 for ; Fri, 30 May 2025 14:05:08 +0000 (UTC) X-FDA: 83499745896.23.34C4C9C Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 4E186180013 for ; Fri, 30 May 2025 14:05:06 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf06.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1748613906; 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=m/1XyZhkINgjqjL6rNsMcBMnKJ0gfD5AmRtZg+RBhuk=; b=b8e5oR+c4rmIFqv0hNvIIYfRtPoQJS87NRfnqv55qXTbdVggr8dd6dDmGkKNG1r4ziGasr jV97xmPsLdyOJLsiDiUU2QWagdq2rY3SX08OR9lhhXQpv+jLRXbrbyq27ZTU7xBZN/Sf/N p18o0LwDVoCKnhF4AUmusAFjKfBP84s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1748613906; a=rsa-sha256; cv=none; b=J6wpSqrrOTcEbvMYxotnLlPQAIWXTAWzY1zuyhtQaovMnBT9rQY/Ym5F9fQBLTukGrh8EX J9n6pAwhvDwxdzyfKlWSRfslMbDUt+VbDZXYK53ImuT8yWgNO0Mpj/MjjpxGA1/9A4p4bL 7p1YGBdkGPpKIx9jKE0HSDfC4wsZE/o= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf06.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com 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 82C55169C; Fri, 30 May 2025 07:04:48 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D6E5D3F673; Fri, 30 May 2025 07:04:59 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "David S. Miller" , Andreas Larsson , Juergen Gross , Ajay Kaher , Alexey Makhalov , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Boris Ostrovsky , "Aneesh Kumar K.V" , Andrew Morton , Peter Zijlstra , Arnd Bergmann , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Alexei Starovoitov , Andrey Ryabinin Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, virtualization@lists.linux.dev, xen-devel@lists.xenproject.org, linux-mm@kvack.org Subject: [RFC PATCH v1 0/6] Lazy mmu mode fixes and improvements Date: Fri, 30 May 2025 15:04:38 +0100 Message-ID: <20250530140446.2387131-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4E186180013 X-Stat-Signature: 7jqr48yrt8y1knb74hzsdwyy8mo5mjmh X-Rspam-User: X-HE-Tag: 1748613906-274831 X-HE-Meta: U2FsdGVkX1/mxZcs760O8q4q42Usjp5lcNvQmVlVXB/5NBW4o7GXl89kjcRl6gOYBH4c9Q3gu+DNYUJhsb9uC1Jk4UF2ZaOWvcgt8/AQ12v+eFWT6R0wLwy6Fxqb1fJTnUJ9aL4Va5PD3lMFuBda+kMAmjVxN5rzYmv51k3xhONA0o3/2js30B8xwjHzrFi076nJupanBg6rl3+ceMW+yEizDeSJyYCtW3lgiOIo94rBIx4mBEt1pBQ3VLW4+EAZza6csCE88aF4uSoDs+doynz07ZSvC7p2tuoCH6jBOVX8Ios2/JIQJcPLu67GBGQswCTIDPWjXc+rLL8qKL23cU1xHOzQeYvudCSxx3+MKx4p5+Tm6bOLLRpuqtSaHM2/SnuefVqXDP5+R9l/WNxw0KlfToS0isuhjC0/Q7+JIc/ml5WVy8SPQ8uslbCnfWEq+ekRLsifDqQ5CNEc4w1eR/ib2Y2R8R+l/fkCsyYwuSRW+I6cWMjNm99043T2a/aJ6ekiwQUgGdpudD+z7NdkLN04SAgC/vkrBQcx4fR3EV4G/lI8Wq16OXKytYYK9gm7LucWNiLQNHDdksEFY2jGld4BaC0b3HV4auWT36dRJrd5hs+/DuDyfttR4WOLgrJeKpml/GqrPFpGoXz3CQWrzYITTsaPZsQ+EGmyJ7lZLGYTEbCO/7T5u0tsatQ9yUszm6vMkOrae8I7lC0ZKo70QLXZH6UxG2Az6Mt+R6u1I1d59EuK4DTDnEIZpCnDHrGGqV5HkZjFRthvzcAN7dC/265ImoSU54/KYphishY9hcAVmG0DA2O2T7O3XdC8Qjy4m+tQVk5xyM/ALFnsvDrcbdtZhEmL6uunZIUW/zjGn2R2ztB7ucnxlPXthloh2Lx9LDsL1z1qY8bn8Loh1cN7DnIVALjDoeKLyP5kYSt8TGwviGbXBlO7eaNgp7f8WcGDdLOYddYVcS12Yl6qRIU r4JL4LBm DEkXrIL5na55NVuHdxZrSkXMq6M4vdDCY8aNusB/ToTNHHTJ8EtsGca+t2zSJZgJy4WASxvvWnaDTCjQIEdxEse8PEADtE51ePNM0zYlXDunIATfrrW9UJlg8Sg+ATlWhUo89hboqnDd+rUEtIyssS+Hh5gHaUn3DgLX8 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: Hi All, I recently added support for lazy mmu mode on arm64. The series is now in Linus's tree so should be in v6.16-rc1. But during testing in linux-next we found some ugly corners (unexpected nesting). I was able to fix those issues by making the arm64 implementation more permissive (like the other arches). But this is quite fragile IMHO. So I'd rather fix the root cause and ensure that lazy mmu mode never nests, and more importantly, that code never makes pgtable modifications expecting them to be immediate, not knowing that it's actually in lazy mmu mode so the changes get deferred. The first 2 patches are unrelated, very obvious bug fixes. They don't affect arm64 because arm64 only uses lazy mmu for kernel mappings. But I noticed them during code review and think they should be fixed. The next 3 patches are aimed at solving the nesting issue. And the final patch is reverting the "permissive" fix I did for arm64, which is no longer needed after the previous 3 patches. I've labelled this RFC for now because it depends on the arm64 lazy mmu patches in Linus's master, so it won't apply to mm-unstable. But I'm keen to get review and siince I'm touching various arches and modifying some core mm stuff, I thought that might take a while so thought I'd beat the rush and get a first version out early. I've build-tested all the affected arches. And I've run mm selftests for the arm64 build, with no issues (with DEBUG_PAGEALLOC and KFENCE enabled). Applies against Linus's master branch (f66bc387efbe). Thanks, Ryan Ryan Roberts (6): fs/proc/task_mmu: Fix pte update and tlb maintenance ordering in pagemap_scan_pmd_entry() mm: Fix pte update and tlb maintenance ordering in migrate_vma_collect_pmd() mm: Avoid calling page allocator from apply_to_page_range() mm: Introduce arch_in_lazy_mmu_mode() mm: Avoid calling page allocator while in lazy mmu mode Revert "arm64/mm: Permit lazy_mmu_mode to be nested" arch/arm64/include/asm/pgtable.h | 22 ++++---- .../include/asm/book3s/64/tlbflush-hash.h | 15 ++++++ arch/sparc/include/asm/tlbflush_64.h | 1 + arch/sparc/mm/tlb.c | 12 +++++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 1 + arch/x86/kernel/paravirt.c | 6 +++ arch/x86/xen/mmu_pv.c | 6 +++ fs/proc/task_mmu.c | 3 +- include/asm-generic/tlb.h | 2 + include/linux/mm.h | 6 +++ include/linux/pgtable.h | 1 + kernel/bpf/arena.c | 6 +-- mm/kasan/shadow.c | 2 +- mm/memory.c | 54 ++++++++++++++----- mm/migrate_device.c | 3 +- mm/mmu_gather.c | 15 ++++++ 17 files changed, 128 insertions(+), 32 deletions(-) -- 2.43.0