Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1831733lqm; Fri, 3 May 2024 07:47:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLBsKaFXWCI+9AY1+34DTZPmy7EROdsXQ9DXkI5xqFHAq25DvDn6iEhoi1DJXnz6sG35hYvt6q/cQpkAl0RFYir5uw4uQpeoum1sdgoA== X-Google-Smtp-Source: AGHT+IH3Yw6+whCNZIdngXNfNBk9UR2b144IMEaripEotFUboK4Hz6jkxTV/5OrUi9DGJXgNgqXk X-Received: by 2002:a05:6358:29b:b0:17f:7206:fd81 with SMTP id w27-20020a056358029b00b0017f7206fd81mr2985342rwj.20.1714747623684; Fri, 03 May 2024 07:47:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714747623; cv=pass; d=google.com; s=arc-20160816; b=UbIaoj+efxRhSkNDxYWgW34aISm77XFSvKoXEofRP/uE4z6rzv9ZXEpFy5qLLKzGAg AinIYkl9gypgSBdMNh1BCS3rCzLiD6NuFrg7vHmgPX5+75NcH3ABvbyyBvH524tkqVd6 By6HAMb3dGZIXMUsyJJcMxxTk3g+pEt9vhyM4D+w+mCiJtmDZIvffiW4CEvJ2KSut8KM E0FHIjqShQrrXDRlAuVpNk0IBeoslWJAhLkziV++oydW+5yjV3sOseMZEb7DhctzzA3t bdmNbSfSxdp9nQv1XQDdmpSlVPKtH0osKJleBRgqeG/JgTWzo5joWadzAcG8RuEpNa3h 6PGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=tHcZvpA5XpqNIgVW9IkYChfWhAq+rf6Viv8Umc5AgaU=; fh=fe/psXtJsA7ttHWiPsXFqy2SSORxnVTmpkXPMijV0n8=; b=eSmWjMYdsvbpm3swu/sXfA9RhF8lZEXG/YDTucJa4FdsoQ+ij16WUxrk/G0ui0gp7A 8k7mjLQEuddStlBIgMOP82dfEOkYr8MKWwpHuPeDKDWGnSKW9vXowk67LN8tCCAfztN5 XtOEQKLOXdmt3jQFO2mGpNyCDdN06i0xubdGXDLf1fe4h4712weNuIY5Dtrk3pI2wwYn po22dn4rDWyrkpZB5Fv5D2Vkgtt0VfgxW2+Lx1r9hiKEHEmnfNK1O/SqTYqh8rHmUX4u QQ7xIxI4HCO9fPVzstpROnQGyVDYpvKC4mI9voBHs7l1Sx9pfmKVEiVfCgL6r8VxUakQ 6yMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-167787-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167787-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c23-20020a6566d7000000b0061d08a4b972si1377787pgw.420.2024.05.03.07.47.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 07:47:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167787-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-167787-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167787-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B92CAB21332 for ; Fri, 3 May 2024 14:46:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AC754AEFD; Fri, 3 May 2024 14:46:23 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E27A14643A for ; Fri, 3 May 2024 14:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714747582; cv=none; b=sIbHephJlcPmWanBZxoVupukCz8sv0KSf6wlPaQG4m+U7R2+1/07HzWEC5ja9P2VS2lvrshGlPjkKKRMHfr0WyGnemtXWQxPT7n0mvOk6Ua0pGYXToOGN5Z5+teZ+iSZ4tpXkfP2e/bGOkXBN2s1xIlnFgRs5kiC6vgFzznZ3K0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714747582; c=relaxed/simple; bh=dNT48mwrRLOK5MSIcUNVw6Bch5bQp2NytgNpxypW/Sk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dvaCAw7+UKUbmrcu+wZRR41nDmWVRTyEpyMfCBf7mc9yHMBmAloZX/c9IlIHlpGzEWbumWz4a31HtyVv3CN8vrPjej5wniDN5/J02UkQ37RMABnJym1z8S0kiP35FqP4aPzXPVrLT6aW4pKC4SpekEiLitMkC1OEa2xenwEJnvo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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 580D813D5; Fri, 3 May 2024 07:46:45 -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 3E60B3F73F; Fri, 3 May 2024 07:46:18 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Joey Gouly , Ard Biesheuvel , Mark Rutland , Anshuman Khandual , David Hildenbrand , Peter Xu , Mike Rapoport , Shivansh Vij Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 0/4] arm64/mm: Enable userfaultfd write-protect Date: Fri, 3 May 2024 15:45:58 +0100 Message-ID: <20240503144604.151095-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi All, This series adds uffd write-protect support for arm64. Previous attempts to add uffd-wp (and soft-dirty) 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 can be moved, 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 now we have two spare bits; patch 4 enables uffd-wp on arm64, using the SW bit freed up by moving PTE_PROT_NONE. This leaves bit 63 spare for future use (e.g. soft-dirty - see RFC at [4] - or some other usage). --- This applies on top of v6.9-rc5. All mm selftests involving uffd-wp now run. However, this work exposed a bug in core-mm that was leading to some test uffd-wp failures in the pagemap_ioctl test. The fix for that is posted at [5], and is in mm-hotfixes-unstable. With the fix applied, all the uffd-wp tests pass and no other selftest regressions are observed. Changes since v3 [3] ==================== patch 1 & 2 (was patch 1): - Split into 2 patches (per Anshuman): - patch 1: generalizes PMD_PRESENT_INVALID - patch 2: removes PTE_PROT_NONE - Re-aded comment for PTE_PRESENT_INVALID (per Anshuman) Changes since v2 [2] ==================== patch 1: - Renamed PTE_INVALID -> PTE_PRESENT_INVALID, pte_invalid() -> pte_present_invalid() (per Catalin) - Added comment explaining test in pte_protnone() (per Will) - Added R-b (thanks to Catalin) patch 2: - Move PTE_PRESENT_INVALID to PTE_NG instead of PTE_NS (per Will) - Added R-b (thanks to Catalin) patch 3: - Added R-b (thanks to Catalin, David) Changes since v1 [1] ==================== patch 1 & 2 (was patch 1): - generalized PMD_PRESENT_INVALID into PTE_INVALID - removed explicit PTE_PROT_NONE bit patch 3 (was patch 2): - collected R-b/A-b from Peter and Catalin - thanks! [1] https://lore.kernel.org/linux-arm-kernel/20240424111017.3160195-1-ryan.roberts@arm.com/ [2] https://lore.kernel.org/linux-arm-kernel/20240429140208.238056-1-ryan.roberts@arm.com/ [3] https://lore.kernel.org/linux-arm-kernel/20240501145419.1390363-1-ryan.roberts@arm.com/ [4] https://lore.kernel.org/all/20240419074344.2643212-1-ryan.roberts@arm.com/ [5] https://lore.kernel.org/all/20240429114104.182890-1-ryan.roberts@arm.com/ Thanks, Ryan Ryan Roberts (4): arm64/mm: generalize PMD_PRESENT_INVALID for all levels arm64/mm: Remove PTE_PROT_NONE bit arm64/mm: Move PTE_PRESENT_INVALID to overlay PTE_NG arm64/mm: Add uffd write-protect support arch/arm64/Kconfig | 1 + arch/arm64/include/asm/pgtable-prot.h | 19 +++-- arch/arm64/include/asm/pgtable.h | 104 +++++++++++++++++++------- 3 files changed, 91 insertions(+), 33 deletions(-) -- 2.43.0