From patchwork Wed Sep 15 18:14:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12497123 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 8F7E6C433F5 for ; Wed, 15 Sep 2021 18:15:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0DD37600D4 for ; Wed, 15 Sep 2021 18:15:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0DD37600D4 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 A331C6B0072; Wed, 15 Sep 2021 14:15:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 993E76B0073; Wed, 15 Sep 2021 14:15:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80D796B0074; Wed, 15 Sep 2021 14:15:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 70C516B0072 for ; Wed, 15 Sep 2021 14:15:04 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1686530C89 for ; Wed, 15 Sep 2021 18:15:04 +0000 (UTC) X-FDA: 78590609328.25.FCE4DDB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id B96B7E001987 for ; Wed, 15 Sep 2021 18:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631729703; 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=/JtLLJZ1Bt4HNZ1/rns47BurBkMZGMTII6QW5YE/blU=; b=cKOlx5KAZ7I96NCCJVjLiIpPIq0Q2CI1rZbCgo67elHTFXQ3A/runrEHX6te5rNN3Un8jk 7fIHaKtHAUzHYpDpBijhkW1cZq9toTx+HR5PSwAJ4esUajslAQHT2MDaysriS34RTlHDEF CqP6sbt5y2Ao3rVTO02kxvKNhbuozLs= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-_DGx4e--PS-RIEvr4UNZUQ-1; Wed, 15 Sep 2021 14:15:02 -0400 X-MC-Unique: _DGx4e--PS-RIEvr4UNZUQ-1 Received: by mail-qt1-f199.google.com with SMTP id q19-20020ac87353000000b0029a09eca2afso5496188qtp.21 for ; Wed, 15 Sep 2021 11:15:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/JtLLJZ1Bt4HNZ1/rns47BurBkMZGMTII6QW5YE/blU=; b=SOxIY4KT48xQMPrvAcR9rmJsG1YFL+Ejwg/0IcCa0cQLgT85pwtrVbpGsdzpnDooFa 3Es3juqhduiSilTWbE2ynuRGMzhcK9MpP4A2X3TRvJ7Z7B2F9sOlXY6Uc4FhV3Arm9fz mL+Wkoqkj2CPwJbuDQgCLu4Pr+d5x32+JjaoIwY2Ri63aJos7KxALW5FtX/bIhOBwXz7 tfO/y7dobFXKyiD1LA6/k0Dmo3MSALr+I7YDwlc8TZalz8StUJg18BJrF07vEC+/XH5M WByZbT1/3dVpVJwOn9yEo0+6i2kbF/lD5S9eiyjT6X56NcqtqnCleQ3L1kB7zeI+QB6j gFEA== X-Gm-Message-State: AOAM530h+6qXDWKtM9w9J+mlFcNEoOOqGL2VBdB6k68nWotiecbQ65Ur 0kkvM2OFUzcnxvygiP3+dnNaxOnxy7R63r2/K5Vqui4oxiZDzJIrhgva0Z+pBxzXBNh+ZfIckDL ME96U5svL9Ks= X-Received: by 2002:a37:9445:: with SMTP id w66mr1329162qkd.410.1631729700630; Wed, 15 Sep 2021 11:15:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUlP/bFYTOYGW/AZ/geeOWP7U0B/+waHTXzFWcNOT4AybXR2GPW/I4aEVdSb5hzua//G11kw== X-Received: by 2002:a37:9445:: with SMTP id w66mr1329128qkd.410.1631729700388; Wed, 15 Sep 2021 11:15:00 -0700 (PDT) Received: from t490s.redhat.com ([2607:fea8:56a2:9100::d35a]) by smtp.gmail.com with ESMTPSA id n18sm578663qkn.63.2021.09.15.11.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 11:14:59 -0700 (PDT) From: Peter Xu To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Andrea Arcangeli , Liam Howlett , Hugh Dickins , Mike Rapoport , Yang Shi , David Hildenbrand , "Kirill A . Shutemov" , Jerome Glisse , Alistair Popple , Miaohe Lin , Matthew Wilcox , Axel Rasmussen Subject: [PATCH v4 1/4] mm/shmem: Unconditionally set pte dirty in mfill_atomic_install_pte Date: Wed, 15 Sep 2021 14:14:53 -0400 Message-Id: <20210915181456.10739-2-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210915181456.10739-1-peterx@redhat.com> References: <20210915181456.10739-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cKOlx5KA; spf=none (imf30.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: rspam06 X-Rspamd-Queue-Id: B96B7E001987 X-Stat-Signature: pjjeu138j5kbc89dm156ujwcztmn1kxx X-HE-Tag: 1631729703-285733 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 because UFFDIO_CONTINUE normally requires another process to modify the page cache and kick the faulted thread, 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 Reviewed-by: Axel Rasmussen 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 88742953532c..96ccf6e941aa 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2424,7 +2424,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 7a9008415534..caf6dfff2a60 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);