From patchwork Mon Sep 26 15:26:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 12988974 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 BB650C6FA82 for ; Mon, 26 Sep 2022 15:26:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51E3F6B00FD; Mon, 26 Sep 2022 11:26:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F6246B00FE; Mon, 26 Sep 2022 11:26:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 396DC8E0066; Mon, 26 Sep 2022 11:26:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2A4DD6B00FD for ; Mon, 26 Sep 2022 11:26:34 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EE033160481 for ; Mon, 26 Sep 2022 15:26:33 +0000 (UTC) X-FDA: 79954613466.08.C9730D2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 874E740008 for ; Mon, 26 Sep 2022 15:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664205993; 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=wUjpPVfNq3g+nZuxz52N7YaNroA0tr6QoNT1fN2tuhM=; b=gECoolekUcxUDeRb1r8E1DljEV7leR6Gg9j7D4VADe65KcsBz14E0PvBiaMpFTOGhHu+vR 1HvR3obUWAyWsygwmW93pTrEqlfJ3Rall7KbVI3sIpvVTYZJXufKmynHd6BxVw8l+9nt2k TtoH9kuZmgVcdgd2z4iatdz73cPnyYw= 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-400-2yZt-JntMraBHgXMowr4YQ-1; Mon, 26 Sep 2022 11:26:29 -0400 X-MC-Unique: 2yZt-JntMraBHgXMowr4YQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5FA4B3801F4C; Mon, 26 Sep 2022 15:26:27 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 280DEC15BA5; Mon, 26 Sep 2022 15:26:23 +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 RFC 1/5] mm/mprotect: allow clean exclusive anon pages to be writable Date: Mon, 26 Sep 2022 17:26:14 +0200 Message-Id: <20220926152618.194810-2-david@redhat.com> In-Reply-To: <20220926152618.194810-1-david@redhat.com> References: <20220926152618.194810-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664205993; a=rsa-sha256; cv=none; b=RthDWMeC6eCvjBQH3uRoBJnIw46RE0Abbgob+wLXFg1m1Krn9676YIYZKMAZxr4zDENNrV 2ziWzuECIcW5fl385pN3h7Ut3G8KhQmSLQ8BRjkeM5bhh8gfAgq7ojOYJFcEr/PR8PiOV5 xpTfno06ty4O5fb4iIslINN18LZRVjQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gECoolek; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664205993; 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:in-reply-to:references:references:dkim-signature; bh=wUjpPVfNq3g+nZuxz52N7YaNroA0tr6QoNT1fN2tuhM=; b=KX3zClqGJMssy5juvpjZ5/j0AnqJKY/dqEQNX4qM6dtCNA7GBlu/lDTvyHRvljFrPem8XN IqOz34nhGR8ItDL9BDoBlgjhjusA1WkZ/5KG/sRWvWLPiaYnbF+W0Qz24/RM8a9DOQEKc1 BQWWKWheI0mGATXwWNu/oFpLF3/+7aQ= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gECoolek; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 874E740008 X-Stat-Signature: tdxakz1ba8m7m4nysbnzj4s84zfr86c7 X-Rspam-User: X-HE-Tag: 1664205993-886800 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: 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 [ comment for dirty/clean handling; return directly; update description ] Signed-off-by: David Hildenbrand --- mm/mprotect.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index ed013f836b4a..c6c13a0a4bcc 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -45,7 +45,7 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma, VM_BUG_ON(!(vma->vm_flags & VM_WRITE) || pte_write(pte)); - if (pte_protnone(pte) || !pte_dirty(pte)) + if (pte_protnone(pte)) return false; /* Do we need write faults for softdirty tracking? */ @@ -64,11 +64,15 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma, * the PT lock. */ page = vm_normal_page(vma, addr, pte); - if (!page || !PageAnon(page) || !PageAnonExclusive(page)) - return false; + return page && PageAnon(page) && PageAnonExclusive(page); } - return true; + /* + * Shared mapping: "clean" might indicate that the FS still has to be + * notified via a write fault once first -- see vma_wants_writenotify(). + * If "dirty", the assumtion is that there already was a write fault. + */ + return pte_dirty(pte); } static unsigned long change_pte_range(struct mmu_gather *tlb,