From patchwork Fri Apr 19 07:43:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13635744 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98D1EC04FF6 for ; Fri, 19 Apr 2024 07:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=V/Np1w1LrphiZ1vn/uw0BlxmCy1sv3YiPdli/JBZlZk=; b=2CgrsGBOvpJ0V3 VH3B9UOiI0rYgHz1r4erENwjUPP+LcywjxLoiYajzTJRjLmKUa0uv1ZNW0ukfeF8fAv/6tgSBMRCh 2hSLkoE0MTXmKYtED8tQDwZQa/sgD69iNtj9zQ/H6Lu9K7dapeoZ1ZsfYsTKuZwROXMMD188QZbrz jXv5lVs8hOexj0KU8Bxu2RSdjyHizSWpib08fqvn+IzC8tHSiXejDr/PrF49eNbQMpbJU02BSW7sT 7a9/poHoAnXAyvu8SvuIBxeNe2HOgRcSeMI+OUeRAwgaGJv0ZdAw1KH5/yXlr2U+Jb2ZtH2eLaKmf BXT5rf9JEEHWxtwH3VZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxiuh-00000004ovD-3ie4; Fri, 19 Apr 2024 07:44:03 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxiud-00000004os3-3DEk for linux-arm-kernel@lists.infradead.org; Fri, 19 Apr 2024 07:44:01 +0000 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 E48F62F; Fri, 19 Apr 2024 00:44:23 -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 93E4A3F792; Fri, 19 Apr 2024 00:43:53 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Andrew Morton , Shuah Khan , Joey Gouly , Ard Biesheuvel , Mark Rutland , Anshuman Khandual , David Hildenbrand , Shivansh Vij Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 0/5] arm64/mm: uffd write-protect and soft-dirty tracking Date: Fri, 19 Apr 2024 08:43:39 +0100 Message-Id: <20240419074344.2643212-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240419_004359_924646_6B3BBCA5 X-CRM114-Status: GOOD ( 18.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi All, This series adds uffd write-protect and soft-dirty tracking support for arm64. I consider the soft-dirty support (patches 3 and 4) as RFC - see rationale below. Previous attempts to add these features have failed because of a perceived lack of available PTE SW bits. However it actually turns out that there are 2 available but they are hidden. PTE_PROT_NONE was previously occupying a SW bit, but it only applies when PTE_VALID is clear, so this is moved to overlay PTE_UXN in patch 1, freeing up the SW bit. Bit 63 is marked as "IGNORED" in the Arm ARM, but it does not currently indicate "reserved for SW use" like it does for the other SW bits. I've confirmed with the spec owner that this is an oversight; the bit is intended to be reserved for SW use and the spec will clarify this in a future update. So we have our two bits; patch 2 enables uffd-wp, patch 3 enables soft-dirty and patches 4 and 5 sort out the selftests so that the soft-dirty tests are compiled for, and run on arm64. That said, these are the last 2 SW bits and we may want to keep 1 bit in reserve for future use. soft-dirty is only used for CRIU to my knowledge, and it is thought that their use case could be solved with the more generic uffd-wp. So unless somebody makes a clear case for the inclusion of soft-dirty support, we are probably better off dropping patches 3 and 4 and keeping bit 63 for future use. Although note that the most recent attempt to add soft-dirty for arm64 was last month [1] so I'd like to give Shivansh Vij the opportunity to make the case. ---8<--- As an appendix, I've also experimented with adding an "extended SW bits" region linked by the `struct ptdesc` (which you can always find from the `pte_t *`). If demonstrated to work, this would act as an insurance policy in case we ever need more SW bits in future, giving us confidence to merge soft-dirty now. Unfortunately this approach suffers from 2 problems; 1) its slow; my fork() microbenchmark takes 40% longer in the worst case. 2) it is not possible to read the HW pte and the extended SW bits atomically so it is impossible to implement ptep_get_lockess() in its current form. So I've abandoned this experiment. (I can provide more details if there is interest). ---8<--- [1] https://lore.kernel.org/linux-arm-kernel/MW4PR12MB687563EFB56373E8D55DDEABB92B2@MW4PR12MB6875.namprd12.prod.outlook.com/ Thanks, Ryan Ryan Roberts (5): arm64/mm: Move PTE_PROT_NONE and PMD_PRESENT_INVALID arm64/mm: Add uffd write-protect support arm64/mm: Add soft-dirty page tracking support selftests/mm: Enable soft-dirty tests on arm64 selftests/mm: soft-dirty should fail if a testcase fails arch/arm64/Kconfig | 2 + arch/arm64/include/asm/pgtable-prot.h | 20 +++- arch/arm64/include/asm/pgtable.h | 118 +++++++++++++++++++-- arch/arm64/mm/contpte.c | 6 +- arch/arm64/mm/fault.c | 3 +- arch/arm64/mm/hugetlbpage.c | 6 +- tools/testing/selftests/mm/Makefile | 5 +- tools/testing/selftests/mm/madv_populate.c | 26 +---- tools/testing/selftests/mm/run_vmtests.sh | 5 +- tools/testing/selftests/mm/soft-dirty.c | 2 +- 10 files changed, 141 insertions(+), 52 deletions(-) --- 2.25.1