From patchwork Thu Sep 2 20:17:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12472435 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 50297C433FE for ; Thu, 2 Sep 2021 20:17:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E6ECA6112F for ; Thu, 2 Sep 2021 20:17:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E6ECA6112F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8ED496B0074; Thu, 2 Sep 2021 16:17:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89BFE6B0073; Thu, 2 Sep 2021 16:17:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73BF48D0001; Thu, 2 Sep 2021 16:17:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 634BE6B0072 for ; Thu, 2 Sep 2021 16:17:30 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 113DC250A9 for ; Thu, 2 Sep 2021 20:17:30 +0000 (UTC) X-FDA: 78543743460.08.76A83D5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf10.hostedemail.com (Postfix) with ESMTP id A84FD6001989 for ; Thu, 2 Sep 2021 20:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630613849; 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=uUFjqTEK/Z5AKo1Agn+ijWYpHJREXXiYmYHdAc5BzAA=; b=Z6qEfofjm51JWDcdvlkG7yT+cluxLiNcmIbB9fjakupIWZUXhaY/pCK16i6ejV1kEPfaoh aVKksy5OtKg7M4hsAhm4Kex6n1BY8id+4RSSZDxHH6o7IOZJI8wEppn2MN8qQSTeuq+LCi 0s21ENSoxyanDNu64aSok0IkzxOkxZE= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-451-iqWFpY24OLKP9fKxaHbWxA-1; Thu, 02 Sep 2021 16:17:26 -0400 X-MC-Unique: iqWFpY24OLKP9fKxaHbWxA-1 Received: by mail-qv1-f72.google.com with SMTP id u8-20020a0cee88000000b00363b89e1c50so3420400qvr.16 for ; Thu, 02 Sep 2021 13:17:26 -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=uUFjqTEK/Z5AKo1Agn+ijWYpHJREXXiYmYHdAc5BzAA=; b=hhKXB6ZvCWL9mv9Nr77xmJwobJsvXell/npkGjlcQ0S4HfeqtZzN6M3I3S6nwZDLGo aUHXVhXfNAN9YpH2HjvFoLTRlG++MTAQU2GYD3DLCDUFABJPrJ767CCZssIWP0AnEexU /oSeWxoU3Fz2DsMYCtEraeaNCccZGMg5qWIyz2uYZGZH8/MIJvjgJk/uTYHPd6v8Szfr gKsiOUYkm8K+VLGS3n72ehp22sa0JdooAK587h1io97xASWwLRnJyqSi7NtxiXNPdxNn NGSv0I2crcV95k7uL5V5oiHJQXjR2P6k4zM94T70XpTzUGTLaFiAG4BlzpLaXZEBJG/A xl3Q== X-Gm-Message-State: AOAM5319kr0GA62jbASTIYlHb5UUgfjolzYmvaMgMd5HCvSO9IwTmS7H myv+6MnKnMgtcz+s1yQI2FHBdbTmwGzbOw7qfU95dJ/sANYY/Of9iH6Sz7FXPDoKojmmgLXadOQ 8jy6NE5uo0ek= X-Received: by 2002:ac8:4891:: with SMTP id i17mr124470qtq.321.1630613845666; Thu, 02 Sep 2021 13:17:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywigrvnlxKpAN78Q/CgPMddaGPkdQXUBfT3wFLvHKkKpWp9wEzSSYfVzG1sJzo6z/t9ArXKA== X-Received: by 2002:ac8:4891:: with SMTP id i17mr124450qtq.321.1630613845467; Thu, 02 Sep 2021 13:17:25 -0700 (PDT) Received: from t490s.redhat.com ([2607:fea8:56a3:500::ad7f]) by smtp.gmail.com with ESMTPSA id m8sm2219962qkk.130.2021.09.02.13.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 13:17:24 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , linux-mm@kvack.org Cc: Andrea Arcangeli , Yang Shi , Matthew Wilcox , peterx@redhat.com, Jerome Glisse , Mike Rapoport , "Kirill A . Shutemov" , Miaohe Lin , David Hildenbrand , Alistair Popple , Axel Rasmussen Subject: [PATCH v2 1/5] mm/shmem: Unconditionally set pte dirty in mfill_atomic_install_pte Date: Thu, 2 Sep 2021 16:17:17 -0400 Message-Id: <20210902201721.52796-2-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902201721.52796-1-peterx@redhat.com> References: <20210902201721.52796-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Z6qEfofj; spf=none (imf10.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: nr9df8ks3g69ce3mfz9yagfkhk5zsmkc X-Rspamd-Queue-Id: A84FD6001989 X-Rspamd-Server: rspam04 X-HE-Tag: 1630613849-287949 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 that we use SetPageDirty() instead. However that's not necessary and it should be easier and cleaner to do it unconditionally in mfill_atomic_install_pte(). The most recent discussion about this is here, where Hugh explained the history 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.anvils/ 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 dirty bit on pte (so we unify them together, finally), case (2) should have no functional change at all as it has page_in_cache==false, case (3) may add a dirty bit to the pte. However since case (3) is UFFDIO_CONTINUE for shmem, it's merely 100% sure the page is dirty after all, so should not make a real difference either. This should make it much easier to follow on which case will set dirty for uffd, as we'll simply set it all now for all uffd related ioctls. Meanwhile, 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 dacda7463d54..3f91c8ce4d02 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2437,7 +2437,6 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); - SetPageDirty(page); unlock_page(page); return 0; out_delete_from_cache: diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 0e2132834bc7..b30a3724c701 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; _dst_pte = mk_pte(page, dst_vma->vm_page_prot); + _dst_pte = pte_mkdirty(_dst_pte); if (page_in_cache && !vm_shared) writable = false; - if (writable || !page_in_cache) - _dst_pte = pte_mkdirty(_dst_pte); if (writable) { if (wp_copy) _dst_pte = pte_mkuffd_wp(_dst_pte);