From nobody Thu Apr 9 07:50:10 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 533F6C433FE for ; Wed, 2 Nov 2022 19:13:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230381AbiKBTNY (ORCPT ); Wed, 2 Nov 2022 15:13:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230199AbiKBTNO (ORCPT ); Wed, 2 Nov 2022 15:13:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E996AE3B for ; Wed, 2 Nov 2022 12:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667416343; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6YPbVJPY8MtPnMTid4uTdi1CU5/wNXrXzoHJaI5QF0k=; b=KFFQXIaYwDlSjIFvvgxo7Jp7wbTncilBY/f3NnKKY9NN8/GaokhB+jLdG/aH5lUk42QRzI ScyKA+M5ei9UtZOTon6O4PW7XtETBAMBKYzGOHIVtp9g/dGn3VKxZUp+ECN4i9ngiGGFcX TD4nEKmhT/KCiWrHKLh4l9J/XmgEuAk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-542-rpR-vEwkMu-2AEpRHiq6RQ-1; Wed, 02 Nov 2022 15:12:19 -0400 X-MC-Unique: rpR-vEwkMu-2AEpRHiq6RQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3DD773804060; Wed, 2 Nov 2022 19:12:19 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.192.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E840492CA5; Wed, 2 Nov 2022 19:12:15 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, David Hildenbrand , Linus Torvalds , Andrew Morton , Mel Gorman , Dave Chinner , Nadav Amit , Peter Xu , Andrea Arcangeli , Hugh Dickins , Vlastimil Babka , Michael Ellerman , Nicholas Piggin , Mike Rapoport , Anshuman Khandual Subject: [PATCH v1 1/6] mm/mprotect: allow clean exclusive anon pages to be writable Date: Wed, 2 Nov 2022 20:12:04 +0100 Message-Id: <20221102191209.289237-2-david@redhat.com> In-Reply-To: <20221102191209.289237-1-david@redhat.com> References: <20221102191209.289237-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Nadav Amit Anonymous pages might have the dirty bit clear, but this should not prevent mprotect from making them writable if they are exclusive. Therefore, skip the test whether the page is dirty in this case. Note that there are already other ways to get a writable PTE mapping an anonymous page that is clean: for example, via MADV_FREE. In an ideal world, we'd have a different indication from the FS whether writenotify is still required. Signed-off-by: Nadav Amit [ return directly; update description ] Signed-off-by: David Hildenbrand --- mm/mprotect.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index 8d770855b591..86a28c0e190f 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -46,7 +46,7 @@ static inline bool can_change_pte_writable(struct vm_area= _struct *vma, =20 VM_BUG_ON(!(vma->vm_flags & VM_WRITE) || pte_write(pte)); =20 - if (pte_protnone(pte) || !pte_dirty(pte)) + if (pte_protnone(pte)) return false; =20 /* Do we need write faults for softdirty tracking? */ @@ -65,11 +65,10 @@ static inline bool can_change_pte_writable(struct vm_ar= ea_struct *vma, * the PT lock. */ page =3D vm_normal_page(vma, addr, pte); - if (!page || !PageAnon(page) || !PageAnonExclusive(page)) - return false; + return page && PageAnon(page) && PageAnonExclusive(page); } =20 - return true; + return pte_dirty(pte); } =20 static unsigned long change_pte_range(struct mmu_gather *tlb, --=20 2.38.1