From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796187554; b=h26Cuob0NoSTQNZPVdVsVMDISv1oGAIAer4KlDU/Vd1ufLadYKsj5yPxOdlfQdsz/EEQ Z4uM3c0DfMyTQ3B2EB0vji+mvcjkDBZ2DYNxLY5ewMPEB2A4VdmOdx5G8BIydvN94x23V uNA4Ut2WEcHhx0731bU2hDSJP6YHEa+4V6iI9cwgIhW+RQJ4gzCTGhUl2Yn5Tf1kJVLql l24csH1Jmo8xS0ePfeWo/qejq0AsvHKGNhtQ6mtjpaQLaWGnGsLAhAHc5qEjEfGXOOksA LvorokXxUSdhanhJG2HE+rgZrOeGwyoshfp0JSloA1uaNrBmqPtVo+RXDDPSJRWYSYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796187554; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:Message-ID:From:Subject:To:Cc:MIME-Version:Content-Type: Content-Disposition:User-Agent; bh=iFOEaCm9MEOGQ91TVVmWorwd+S5Ihy2tMx8B7TjPSw4=; b=vHW1j/+04zOIFbKL424mgWQYUavoPO8qkaHD1i/UCKCm3RADZ3Z5qn1MAPWKO9BA4+6r qMXdtiaB5z8U3qqPeKd9vJ/tc0/r7bqmvcIecQNm9tq83DXNh8l0HmJRwuyUlA+Z+lti2 CerFKs40qGRvFCRKmtzfVeyiYEbpP7sXP+dN86a3pj6xLEyxNkS5O9RQjtJ1bPilh1Ozo kA7JovbEDIVHFXcKkcyZKSPhDFHfq/6VE0uuYBm2MI3IfmcwyBh3hDuL9+fFokF8CmWRe dSKARvKMewYJU2h/kj+9r26GN+CVZX+DUmmb+yso1+leKsZOe3DArSV7f+/wy94I64Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=Ec1vkbJZ; arc=none smtp.remote-ip=209.85.128.179 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DC2D606A31A for ; Wed, 2 Dec 2026 04:59:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4DC2D606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=Ec1vkbJZ Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-8b4e18369c8so76403387b3.2 for ; Tue, 01 Dec 2026 20:59:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1796187553; x=1796792353; darn=vger.kernel.org; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:message-id:date:from:to:cc:subject:date:message-id :reply-to:content-type; bh=iFOEaCm9MEOGQ91TVVmWorwd+S5Ihy2tMx8B7TjPSw4=; b=Ec1vkbJZQUkYi6nwpdjxJvzkMGZPNqFqs8Pk+WW6gdCgEjiiHFI+v9+wUlfLxemq+2 YWZWn390mUfm9StDCkR9Q01UKus57qFSNTk9AcaXbhhMbGUVX8gt1NZoWqSE+IsvBSrF P7/Az0GBEIGIdnUQ4XFn7D8GePQIwkD82RuI0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796187553; x=1796792353; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:message-id:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=iFOEaCm9MEOGQ91TVVmWorwd+S5Ihy2tMx8B7TjPSw4=; b=t8un6/klUQ39CLfkQifqF2EZpf5sX6uOYF8FAzA3iRwQJ0xHdZQ0f5iuf1/bHKsqap ULXvgaJ5SYHrOa3epEWjwfzt/GNMtYWV45ZefkSSKMgCwSDoF7ZCqTKE0mB/D/BSRBbs 5I+kyOmlzTNSlowoEXefiDwzs8Aguf7mN8WzmuxWVYfkZ9vZDuFy1MaAJF66qrPLyogw r2cEEeaAsl/JwvSPx4PaMzZVZ3Pwq9L/irMJJ+qQEvDdgSbj/BPTBmVZx0NG2EkbhKZQ OLOUOjiFKcVaZzJKZ3/qeBUb2tp0CYVAbrwTyfXTgI2NwtO7Wn3HupKrDeGDxpHdbkpB +2DQ== X-Forwarded-Encrypted: i=1; AL+hErEMh7di+jpngse1MRZBwua0u9WUX9IAHxYmp+Fq65ngMC8olgZsTTQ0saBHAm0X7yDQou6yEuzdVDowW54=@vger.kernel.org X-Gm-Message-State: APuU4Z8Lkp8lwIeVOUXvEiMjRKsk/1DqKAtDX/g+4ScQCPHRihMmUUMU 0M7vh0CPgbUiTPZHE/AQVSXLmKYj0bWRhFYMgw/933PUMQooUT01hOi56Ejd/ZSHV54= X-Gm-Gg: AZFdTZfz1ZV7jPpCjK/QxsXauDnZmhOfm+JgagaplWzUyeLFBKgc3OWyk2TKAWGLTa0 i0+QJooM9f9NxrhnRVVVN3L9siwwbawlSMQsjQo77YmjeFANCXqBe4CTKjogyjXJMOObiNtphkg VxC3ZsmnKc8Q+gLEaarnaW+6gGoQrCsKtxd5ftWmD7UA5Peu4clEoqW+dzwsyeEE5WttX4hHa4s JbQy56wWDME/DK1jQgwg9Fx+gRxtZcQkyy3gl9xqzdEcZYK71QBKjZuiw0hXx3mQzlV9zRo5XuR WE89krMahKuw0+CtUH0JKQg3JuQpq5dExzll6cyyZJNTXOtwtxyYY3jbqtYxxuW+1xTtOOKynaA A9B9hCip2vNLfPBbv8e5KErJ85LLP+jzAK2fNvIbJfw9eLQG+WS4hyj788536qpfeYNfyArJqWy b1DtqWKJbMmmeyLmBXZF9ErdpOL1rlSj0sifwR1+R9DkvOEHmYgxJsQhH7kXUnydc8wXQFJFlBF xt0M3Psu5xKZE15GD/gsTfzsZwp4wr3NKmtOV+j1KjA7j9+hzD4C8YyR8n+QlE65xochq7+WbEc 9dCTQLRX+gGhDzLKQOXSgtDY0DIl9YOpS8weR1JL8RXqOVOay/BNaBlmq9ePWJJMVpzwFVJYMBc wZQ9M0TaEzWWyzB4/6POISTdwmEV7L9kdFMYJq+IxMrY3Sd/PJAvXvuXX76zpSaVGCOt8ColVSh 1Tv7aqWbeqXkT+PsOPbN/0NuY58D5EHIW2piT/t8aGK5YO/tidsjZMpYPHTRKC8tfl0SDSfWn5d nlH64OvmRzmPeftx+SLNvg= X-Received: by 2002:a05:690c:b99:b0:8b4:da1a:8f6e with SMTP id 00721157ae682-8b520436e71mr141332737b3.17.1796187553161; Tue, 01 Dec 2026 20:59:13 -0800 (PST) Received: from [172.20.0.3] (c-73-207-185-9.hsd1.ga.comcast.net. [73.207.185.9]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b5db89abafsm10372467b3.0.2026.12.01.20.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 20:59:12 -0800 (PST) Date: Tue, 01 Dec 2026 20:59:09 -0800 Message-ID: <1b920241d08ed3c39c2cd19a5507529bb3af95a2.1796187429.git.chris@chrisdown.name> From: Chris Down Subject: [PATCH] mm: use softleaf_migration_mkreadable() in change_protection() To: Andrew Morton Cc: Muchun Song , Oscar Salvador , David Hildenbrand , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Kiryl Shutsemau , Lorenzo Stoakes , Suren Baghdasaryan , Vlastimil Babka , Shakeel Butt , Pedro Falcato , Jann Horn , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tal Zussman X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/2.4.3 (cc9e3943) (2026-10-09) change_protection() downgrades a writable migration entry to a readable one in change_softleaf_pte(), change_non_present_huge_pmd() and hugetlb_change_protection(). Each of them open codes the same choice: the new entry is readable exclusive if the folio is anonymous, since a writable anon migration entry implies AnonExclusive, and plain readable otherwise. PAGEMAP_SCAN's write-protect path needed the same downgrade, so softleaf_migration_mkreadable() was added to leafops.h for it. Let's use it in change_protection() too. Each site still handles the soft-dirty and uffd bits itself as before. hugetlb_change_protection() only looked up the folio for this choice, so its local goes away. The other places that choose between readable exclusive and readable migration entries, such as try_to_migrate_one() and __split_huge_pmd_locked(), carry over the exclusive state of the page or of the old entry rather than downgrade a writable one, so they are left alone. No functional change intended. Suggested-by: Lorenzo Stoakes (ARM) Signed-off-by: Chris Down --- mm/huge_memory.c | 7 +------ mm/hugetlb.c | 8 +------- mm/mprotect.c | 7 +------ 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 4fc888ddfb69..ce028838bdba 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2704,16 +2704,11 @@ static void change_non_present_huge_pmd(struct mm_struct *mm, VM_WARN_ON(!pmd_is_valid_softleaf(*pmd)); if (softleaf_is_migration_write(entry)) { - const struct folio *folio = softleaf_to_folio(entry); - /* * A protection check is difficult so * just be safe and disable write */ - if (folio_test_anon(folio)) - entry = make_readable_exclusive_migration_entry(swp_offset(entry)); - else - entry = make_readable_migration_entry(swp_offset(entry)); + entry = softleaf_migration_mkreadable(entry); newpmd = softleaf_to_pmd(entry); if (pmd_swp_soft_dirty(*pmd)) newpmd = pmd_swp_mksoft_dirty(newpmd); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 367c93f851d5..f1e0ed41af09 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6831,16 +6831,10 @@ long hugetlb_change_protection(struct vm_area_struct *vma, if (unlikely(softleaf_is_hwpoison(entry))) { /* Nothing to do. */ } else if (unlikely(softleaf_is_migration(entry))) { - struct folio *folio = softleaf_to_folio(entry); pte_t newpte = pte; if (softleaf_is_migration_write(entry)) { - if (folio_test_anon(folio)) - entry = make_readable_exclusive_migration_entry( - swp_offset(entry)); - else - entry = make_readable_migration_entry( - swp_offset(entry)); + entry = softleaf_migration_mkreadable(entry); newpte = swp_entry_to_pte(entry); pages++; } diff --git a/mm/mprotect.c b/mm/mprotect.c index ef4e7188e24d..e1c4f8fca4e8 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -221,16 +221,11 @@ static long change_softleaf_pte(struct vm_area_struct *vma, pte_t newpte; if (softleaf_is_migration_write(entry)) { - const struct folio *folio = softleaf_to_folio(entry); - /* * A protection check is difficult so * just be safe and disable write */ - if (folio_test_anon(folio)) - entry = make_readable_exclusive_migration_entry(swp_offset(entry)); - else - entry = make_readable_migration_entry(swp_offset(entry)); + entry = softleaf_migration_mkreadable(entry); newpte = swp_entry_to_pte(entry); if (pte_swp_soft_dirty(oldpte)) newpte = pte_swp_mksoft_dirty(newpte); base-commit: 4bffe3da0065e60f45a0b96f7460e5e7f7d2b63a -- 2.56.1