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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B541AC4708B for ; Thu, 27 May 2021 20:19:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F2019613EB for ; Thu, 27 May 2021 20:19:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2019613EB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 528706B006E; Thu, 27 May 2021 16:19:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FD2B6B0070; Thu, 27 May 2021 16:19:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 375CD6B0071; Thu, 27 May 2021 16:19:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id F08976B0070 for ; Thu, 27 May 2021 16:19:37 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 955E68249980 for ; Thu, 27 May 2021 20:19:37 +0000 (UTC) X-FDA: 78188126394.37.158B81F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 49A97C005A3E for ; Thu, 27 May 2021 20:19:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622146776; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hhEVhq4PGqE11D2YgrHebPE630Tm9aX+8YBhc8WEcaU=; b=QoL0zb2rMTGuCQMTLYv/wm9YFpCHaeu4CRBXBzi9F7GE1sPF5d1fx/IZEtOOFeOwMie6OS PAg14k0c5GpK1cullAUhE+epQhc+yyTCPBAY88iEfxffKIo3FBrJXQ2clfBuqUoDL57MHX TxnvUaRZXZH4bis1LcxgnqPJ0APOYRo= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-18-SccHNAOgP2WXd6JRleZvlw-1; Thu, 27 May 2021 16:19:34 -0400 X-MC-Unique: SccHNAOgP2WXd6JRleZvlw-1 Received: by mail-qv1-f69.google.com with SMTP id i14-20020a0cf10e0000b02901eeced6480dso1039203qvl.4 for ; Thu, 27 May 2021 13:19:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hhEVhq4PGqE11D2YgrHebPE630Tm9aX+8YBhc8WEcaU=; b=VxRskClfXif9RW14VJ69eTvcmpLVk8BL4YJ8AwmSHdSh1IJBPE1UvSGRyiTllr5Y/x fnE1BVZIUpQ+ZOtgFm/wH0Mts2A9HiVK0SYoVv9+YAjtwwAwPl6z1ImE79dhT4MAcwkq XxYtVrtPxPYeVEjQ8kU0gDCNZYDyaU/ZXFx1Ljmy7+qCwFrd1m62VhNXVt6izWJBihU0 hkGnUPgkD856xjrlNA+zsvM5dkqgoa2ijLWgWtSFT0eZITNGiUSvUyvamn23H/etOC27 Zo2k8PgwfHvWim5nv3+zmhqbQDQaH6Vk0VXCSj2LyFOVi/oLQ1wASzW4AQryxSr+WA0e SnOQ== X-Gm-Message-State: AOAM53339y6SkWutsfIcVCh6NR5iTOJvr6SZqA2IIxHkPk2PjNCw3bRX pgyi/CJhkLL2aRsJvU5JrZDTshDy//9uMe+Zi5elcTELZAo2ZH0vsWoezFSVo2eTL00zkVkBU6Y G/WP4fWpwFNY= X-Received: by 2002:a05:620a:56a:: with SMTP id p10mr329560qkp.238.1622146774398; Thu, 27 May 2021 13:19:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhQTpN08TmWtg7+wKKOD9e8MtoWozMDaw4Mi24l38BYVLrAve1MtC/JueAUjGIQC5CxsYQeQ== X-Received: by 2002:a05:620a:56a:: with SMTP id p10mr329530qkp.238.1622146774179; Thu, 27 May 2021 13:19:34 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-72-184-145-4-219.dsl.bell.ca. [184.145.4.219]) by smtp.gmail.com with ESMTPSA id u14sm2089536qkp.80.2021.05.27.13.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 13:19:33 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , "Kirill A . Shutemov" , Hugh Dickins , Andrew Morton , Miaohe Lin , Mike Rapoport , Jerome Glisse , Andrea Arcangeli , Nadav Amit , Mike Kravetz , peterx@redhat.com, Jason Gunthorpe , Matthew Wilcox Subject: [PATCH v3 01/27] mm/shmem: Unconditionally set pte dirty in mfill_atomic_install_pte Date: Thu, 27 May 2021 16:19:01 -0400 Message-Id: <20210527201927.29586-2-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527201927.29586-1-peterx@redhat.com> References: <20210527201927.29586-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII" Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QoL0zb2r; spf=none (imf06.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 49A97C005A3E X-Stat-Signature: q8m84j7fufkcmwx8msqjkfwfqgpdg8jn X-HE-Tag: 1622146769-535047 Content-Transfer-Encoding: quoted-printable 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: It was conditionally done previously, as there's one shmem special case t= hat we use SetPageDirty() instead. However that's not necessary and it should b= e easier and cleaner to do it unconditionally in mfill_atomic_install_pte()= . The most recent discussion about this is here, where Hugh explained the h= istory of SetPageDirty() and why it's possible that it's not required at all: https://lore.kernel.org/lkml/alpine.LSU.2.11.2104121657050.1097@eggly.anv= ils/ Currently mfill_atomic_install_pte() has three callers: 1. shmem_mfill_atomic_pte 2. mcopy_atomic_pte 3. mcontinue_atomic_pte After the change: case (1) should have its SetPageDirty replaced by the d= irty bit on pte (so we unify them together, finally), case (2) should have no functional change at all as it has page_in_cache=3D=3Dfalse, case (3) may= add a dirty bit to the pte. However since case (3) is UFFDIO_CONTINUE for shme= m, it's merely 100% sure the page is dirty after all, so should not make a r= eal difference either. This should make it much easier to follow on which case will set dirty fo= r uffd, as we'll simply set it all now for all uffd related ioctls. Meanwh= ile, no special handling of SetPageDirty() if there's no need. Cc: Hugh Dickins Cc: Axel Rasmussen Cc: Andrea Arcangeli Signed-off-by: Peter Xu --- mm/shmem.c | 1 - mm/userfaultfd.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index ccce139d4e5c..4085a5cf4a13 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2449,7 +2449,6 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm= , shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); =20 - SetPageDirty(page); unlock_page(page); return 0; out_delete_from_cache: diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 9ce5a3793ad4..462fa6e25e03 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -69,10 +69,9 @@ int mfill_atomic_install_pte(struct mm_struct *dst_mm,= pmd_t *dst_pmd, pgoff_t offset, max_off; =20 _dst_pte =3D mk_pte(page, dst_vma->vm_page_prot); + _dst_pte =3D pte_mkdirty(_dst_pte); if (page_in_cache && !vm_shared) writable =3D false; - if (writable || !page_in_cache) - _dst_pte =3D pte_mkdirty(_dst_pte); if (writable) { if (wp_copy) _dst_pte =3D pte_mkuffd_wp(_dst_pte); --=20 2.31.1