From patchwork Tue Apr 11 14:15:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 81996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2617362vqo; Tue, 11 Apr 2023 07:27:10 -0700 (PDT) X-Google-Smtp-Source: AKy350bwDoRSfmf6DXZnhrwcTjW+ZB4vizPWQpFtVcTaNqX2V6zOsaz5WYcrYoEFYyCQ+IHNoxt1 X-Received: by 2002:a17:903:2886:b0:1a6:413c:4a47 with SMTP id ku6-20020a170903288600b001a6413c4a47mr6381384plb.1.1681223230533; Tue, 11 Apr 2023 07:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681223230; cv=none; d=google.com; s=arc-20160816; b=P5hbLwnq3ynVMcZFKc2vESUtBybpnwsZaTNUBjNVGz8mogk5o+6HHcPrMe5SWerbvJ ZuNJ5YHHFF0+ABSpv8cG4lGU8dOJBOYOQ4ChaWq+J6BuMIRsKW2jRdli7KBEG3WicLS6 thOmKAS2L7twQ+l/T1A9YhXlSHfmNCVBQaqizZf1L4dbswqgB+8JNJYOuD3WYyrryG04 Py1mMw8q7Zk1iW0K+VZbbGR3mr8yzg4vbZ4r3mAYU1lnCJnAA3d04Zry7+LRk0jkzu6w bboegF/Q+fBZsT08X1VkUi0J9v1V8+LSesiIjHiUdFQhiWa1m3+xbhjd6crCVWSor4x+ TXrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qzK4ogixuaREht4MpkiqqhFPvzGg6ALQmBRRBO9bEhw=; b=hB+priht4/SIzXYM6eN6LaB2M/f2bU0NmppHSL1HSycrv+QdSHuNDwz/awVMyAX4+q vaj6KmKyH4T6yeJDK0d7WtYbon4Rdk5z/nL9hynPxSV7PIgamLBMe5eemxDNPXVU7ofL lf4wLu1O4dM2Km9WyIOEfkKdyl3bkc39qE6g+pPczqCzaVb+rI67WRzmjYjzfROkimcG ZCsPc7CDE1NuGR2Y7wRX/BgbnLXirHXVNndA7ar8KrJ4hBoTBXcU5Toknq9kh6ivzwwK IRgOU+9ReOwyLK0vCAl9K7Bh022AAt/oi3l9EfN0se2tky/11Eo46qFupPXGgMGUS+wZ /1eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GNpxJ+7s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jy14-20020a17090342ce00b001a652580118si2717875plb.237.2023.04.11.07.26.57; Tue, 11 Apr 2023 07:27:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GNpxJ+7s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229988AbjDKORS (ORCPT + 99 others); Tue, 11 Apr 2023 10:17:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbjDKORO (ORCPT ); Tue, 11 Apr 2023 10:17:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62559448B for ; Tue, 11 Apr 2023 07:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681222548; 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=GNpxJ+7sI+jah3+/zAazYlQF38DN2IdKKwkWtN2oqqgUC42+irTJMuWA8pJUMNki9bOOL/ Dh5MWZvkaeCr1jYVczDlu9RiwrV/eKLYju+IuK7bovig4v4WbpGrDyCk27iGf/FKQZrRGY NqsRbuH5K/M6t7SI50irXJvOJ4Y3Efg= 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-371-Ckkwz92eO7-IkeIGQlURJg-1; Tue, 11 Apr 2023 10:15:45 -0400 X-MC-Unique: Ckkwz92eO7-IkeIGQlURJg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 17DDE1C12991; Tue, 11 Apr 2023 14:15:45 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9240D400F281; Tue, 11 Apr 2023 14:15:43 +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 Subject: [PATCH v1 6/6] mm/huge_memory: conditionally call maybe_mkwrite() and drop pte_wrprotect() in __split_huge_pmd_locked() Date: Tue, 11 Apr 2023 16:15:29 +0200 Message-Id: <20230411141529.428991-8-david@redhat.com> In-Reply-To: <20230411141529.428991-1-david@redhat.com> References: <20230411141529.428991-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762890306847760586?= X-GMAIL-MSGID: =?utf-8?q?1762890330285173466?= 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 */