From patchwork Tue Nov 8 17:46:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13036631 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 D602EC4332F for ; Tue, 8 Nov 2022 17:47:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59C176B0072; Tue, 8 Nov 2022 12:47:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 54B5C6B0073; Tue, 8 Nov 2022 12:47:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 414618E0001; Tue, 8 Nov 2022 12:47:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 349676B0072 for ; Tue, 8 Nov 2022 12:47:08 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 11CB6A018D for ; Tue, 8 Nov 2022 17:47:08 +0000 (UTC) X-FDA: 80111006136.09.E9EBD63 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 94D3B2000B for ; Tue, 8 Nov 2022 17:47:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667929625; 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=WGbV1U2aDxfQ1lc1pr50AmTwCrCIAULruAnB9rz2fY54yekU4F2zf772pV/T196a/XQGzG yTEDOL8KMkSKtkBO7aGPLeLM+QEByu3wLopnwbvkjRWur7Ww6oXWnGQ6Xs/+QB5t+IePgk JgBYU8OdOgwTNbuAllRcoUVfemFNM/0= 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-589-5U-PXS9XOe-k_dUPBm89IA-1; Tue, 08 Nov 2022 12:47:02 -0500 X-MC-Unique: 5U-PXS9XOe-k_dUPBm89IA-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 8FB033806738; Tue, 8 Nov 2022 17:47:01 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5E20C15BB5; Tue, 8 Nov 2022 17:46:57 +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 v2 1/7] mm/mprotect: allow clean exclusive anon pages to be writable Date: Tue, 8 Nov 2022 18:46:46 +0100 Message-Id: <20221108174652.198904-2-david@redhat.com> In-Reply-To: <20221108174652.198904-1-david@redhat.com> References: <20221108174652.198904-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=1667929626; a=rsa-sha256; cv=none; b=qdcU7tUmeoCW+jUh6BnsFCVw8sY6xSReLMoXDUV8E/R9NkTKrHHBqsLqufm6Qr4IM7lg/p lNTnEUByx/fi8ghAl1OxPYCujtP4VXVshUspD2+4dx36hY6U1W4GOWcz6l3nrxR2iN2Rj7 6EMJSdqg3hQd9kjy8IMuG9zTJGbiyXo= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WGbV1U2a; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667929626; 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=6YPbVJPY8MtPnMTid4uTdi1CU5/wNXrXzoHJaI5QF0k=; b=P/Q789OsKPV+6OeOBnlx1BgkzDNBuhCBWraYpLXZa3ZJwLzlgqJr0PhSVRuLDU3Xm4gosD Ki25ZPCJnKVXqBf9xmwMfPsMTgrLtsu5Bnt41rnLkh3/II2uPJ4RXmqKhNdU+HQs9hBH45 Y6w2Iklvwf7z1QZPbuvzk+GDuI7v+WE= Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WGbV1U2a; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: f6xzxetehgh18mwhnhxir4wyt41erg5k X-Rspamd-Queue-Id: 94D3B2000B X-HE-Tag: 1667929626-945163 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 [ 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, 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? */ @@ -65,11 +65,10 @@ 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; + return pte_dirty(pte); } static unsigned long change_pte_range(struct mmu_gather *tlb,