From mboxrd@z Thu Jan 1 00:00:00 1970 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 8B153C77B70 for ; Tue, 11 Apr 2023 14:25:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 860C528000F; Tue, 11 Apr 2023 10:25:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79A2F28000A; Tue, 11 Apr 2023 10:25:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 614A928000F; Tue, 11 Apr 2023 10:25:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4CD3028000A for ; Tue, 11 Apr 2023 10:25:38 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1E259160E0C for ; Tue, 11 Apr 2023 14:25:38 +0000 (UTC) X-FDA: 80669333556.14.864BB7B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 3A548C000E for ; Tue, 11 Apr 2023 14:25:36 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EKmfHWR9; spf=pass (imf28.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=1681223136; 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=qzK4ogixuaREht4MpkiqqhFPvzGg6ALQmBRRBO9bEhw=; b=70IDSlGde4joheSaFvk6yGAtm4dj3CDFYKE2hbURH3df0z9JMEKVrND2VG31Mw67pU5Qak OdcY+AftS0nXhavK+ert0JlayKYbhJHFP3SQZXragHPWdrBXYDzv4Gu6SwusH/ZY/ROL7t PO6w7jYC5M0EcAZOv10Zj/h9xW6Gtug= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EKmfHWR9; spf=pass (imf28.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681223136; a=rsa-sha256; cv=none; b=Ng5x202dgV41480s5ah5b7wdBF4iXmLY7jkwHdnnOsb6r7poz3nKzIabgVlYFB/C9p9scB odOPbqQaevUlfaW5gEVFo1Ty/fkTjaXPWDu1A/W1nquk1hZa7lOzQD0DRA8VeXghDqPwnK eMCZtKMMHGk56zSh2YvjTvMWzxO+JP0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681223135; 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=qzK4ogixuaREht4MpkiqqhFPvzGg6ALQmBRRBO9bEhw=; b=EKmfHWR9HxArZ7X2PHCZeF6T/VlOEWW6Fblifxeh5r3JRgGJvWYaTvlJvmw/nGl+mFuJRu QPsXeOyXiELrTHHqg3qTVYrxJrl5uLUr2xtIabKyAMsUhP4BQRstgupcYcN7Pr7r7kmEEk XPEsrEfXxDf5WDNxbTh48B3kyx+2HcI= 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-333-CZ7gWNr3MiGiLm_dWDQrxw-1; Tue, 11 Apr 2023 10:25:32 -0400 X-MC-Unique: CZ7gWNr3MiGiLm_dWDQrxw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCE451C27D9C; Tue, 11 Apr 2023 14:25:31 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 826DB14171D6; Tue, 11 Apr 2023 14:25:29 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, sparclinux@vger.kernel.org, David Hildenbrand , Andrew Morton , "David S. Miller" , Peter Xu , Hugh Dickins , Shuah Khan , Sam Ravnborg , Yu Zhao , Anshuman Khandual Subject: [PATCH v1 RESEND 6/6] mm/huge_memory: conditionally call maybe_mkwrite() and drop pte_wrprotect() in __split_huge_pmd_locked() Date: Tue, 11 Apr 2023 16:25:12 +0200 Message-Id: <20230411142512.438404-7-david@redhat.com> In-Reply-To: <20230411142512.438404-1-david@redhat.com> References: <20230411142512.438404-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3A548C000E X-Stat-Signature: c831ezww6pmsjgtcjxaxzz84nbtwitkg X-HE-Tag: 1681223136-453165 X-HE-Meta: U2FsdGVkX19s1ah5qjfHliPAiXeVyMET/ecZZNXuk/892dCWH6Df9nphHxaeM2jCUChCD4Dyf2ppwQJ+vgyO3YzomOyGDNLrnUDatFnfspGtYd88O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9cav2IFxeVWZKv4/5o6finhQ= 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: No need to call maybe_mkwrite() to then wrprotect if the source PMD was not writable. It's worth nothing that this now allows for PTEs to be writable even if the source PMD was not writable: if vma->vm_page_prot includes write permissions. As documented in commit 931298e103c2 ("mm/userfaultfd: rely on vma->vm_page_prot in uffd_wp_range()"), any mechanism that intends to have pages wrprotected (COW, writenotify, mprotect, uffd-wp, softdirty, ...) has to properly adjust vma->vm_page_prot upfront, to not include write permissions. If vma->vm_page_prot includes write permissions, the PTE/PMD can be writable as default. This now mimics the handling in mm/migrate.c:remove_migration_pte() and in mm/huge_memory.c:remove_migration_pmd(), which has been in place for a long time (except that 96a9c287e25d ("mm/migrate: fix wrongly apply write bit after mkdirty on sparc64") temporarily changed it). Signed-off-by: David Hildenbrand --- mm/huge_memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 6f3af65435c8..8332e16ac97b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2235,11 +2235,10 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, entry = pte_swp_mkuffd_wp(entry); } else { entry = mk_pte(page + i, READ_ONCE(vma->vm_page_prot)); - entry = maybe_mkwrite(entry, vma); + if (write) + entry = maybe_mkwrite(entry, vma); if (anon_exclusive) SetPageAnonExclusive(page + i); - if (!write) - entry = pte_wrprotect(entry); if (!young) entry = pte_mkold(entry); /* NOTE: this may set soft-dirty too on some archs */ -- 2.39.2