Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1071164pxb; Wed, 1 Sep 2021 16:50:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPw0fQ/+RjQMHR2evCxT+7DDUOX/LGt9KQtLDoEGkJimASo7u3gu6KrIsUDmFHpZrPsR1U X-Received: by 2002:a5e:c70c:: with SMTP id f12mr345709iop.166.1630540225536; Wed, 01 Sep 2021 16:50:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630540225; cv=none; d=google.com; s=arc-20160816; b=yijrCWO5wDOEsIfg8vYuf2dmjRIfRs1glRuWcmPGBVmIkBWbKsGbPPNT+lLXU6lYr3 JcwSfB0A6ZF1n02eppXvQXEckTPdkZQyDXmfPhWkOaePs/4J1gZs62GrzJTveMFvlcJx zErZIQ4UxmzVQSZ7Fpzr1Vtx0x4CYCa0/fs9HLhGk3Hi39JEvaXM+L0rt0Zt1XZ431mD PrCdQsjQdFUmiPuQPlGDZvJ9ip4vu7MQpQXZOBYBqG8VDk5EPXYFyMs25fCuoe6ALaIq ov45Cetdv25VCtOru6bj+giRQ/iR66N0h94OqRivJt5mbdk0DC5tQa/tBVveN9jx+0SW 3f+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=560IcZXSiBf9qDG9Tl/mVQRipFa5V94OKcciALLHTxI=; b=ucuhTlg1QJbG+j1uiuDiyl4S0t0YZsc9fuuqVCK1vKnkKsXzyaDDvzYz5uXdSLOsAu CABbZFxww6CYB/Eqe8qWqycdlnAXrAg/SkcDVn05byITwfh+IoIDyaQyct2A0AJSlQ7J nPA4EbhzAUsvXjo9trZ+NjFeJRBiiczW/YgXQ89BIKZZxYFZPOCF2oMeNQ7lCGAKi84/ EFSNj5rzCd7uM7wFDHQ2BqIMlYRi0F96mtAaOIWIzcic9vOepC1CpNhhSSML9BtBQnhS F9khQl768nt639oV4QxKG37BSVjzFS9rIeRb8qGjwJKNFNdo1UmNzjumb2OSPgyA4YOw W89A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dRdKgF0P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o29si74432jac.75.2021.09.01.16.50.14; Wed, 01 Sep 2021 16:50:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dRdKgF0P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1345063AbhIAXBI (ORCPT + 99 others); Wed, 1 Sep 2021 19:01:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54408 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344583AbhIAXBH (ORCPT ); Wed, 1 Sep 2021 19:01:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630537210; 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: in-reply-to:in-reply-to:references:references; bh=560IcZXSiBf9qDG9Tl/mVQRipFa5V94OKcciALLHTxI=; b=dRdKgF0PXr2n9Yo+wUzC5EZzHndWxZ24tnom2u1oZLGHSrr4AiAphQfOqIHrEuKUmFvva6 Yg7GWzORTP4D5Vzj8zG07sL5xWohXI4+oZCve0puAUyFmT6w3SVylGrxXL/xer0F1dEFVG /vIX+OvMlcx5jh36egVoDJxn3YNyE6k= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-549-OJPd9Zv5M-anyc8r0mPoBA-1; Wed, 01 Sep 2021 19:00:09 -0400 X-MC-Unique: OJPd9Zv5M-anyc8r0mPoBA-1 Received: by mail-qk1-f199.google.com with SMTP id 62-20020a3706410000b02903d2cdd9acf0so7054qkg.21 for ; Wed, 01 Sep 2021 16:00:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=560IcZXSiBf9qDG9Tl/mVQRipFa5V94OKcciALLHTxI=; b=KsgbRUSaSbX8RXXqFf98Hk4kNvIyCxMQMeO7T+cF8nuVnFw1pspJt5MXDFCDwGRshh /omGX0quP4Rc3y152iX6fM/JQGo9vNXuAJWswqJTzaF43t+rAbwQoXt8LV1Y32wbVkib CAcNN2wHzcsyI4PYxekV7mcSp7r2XrW/k0ZyMX6ooMtd04t09m0oKDqGHGCe0cWEM+Xf Oexd4uw1cna/GUU1CMuub0cnAruYFbxJxiNsDKXQU+qknSSsRIoC2Kr/GboZgMfvFKMJ 5Qwb4d/sTGfB66/mLJHTP/xefb32dFv1IDw5TUVfe2XgGx+36RKnuCk1huzX0IGFomsV HH1A== X-Gm-Message-State: AOAM531T8j1kaD+RN883mCDqA0aowrLOJQopUah7cdmG4Yhn9NzB/A7t QuopYI9d4KKRUC7Gxw81V+eQQvyqNQ+8bi+hkzAKSVIh8kpPpRO0cBjGfYW7VzscMPzlAkb1DDQ 2u5t2JvSTDe2mKq6NHLxdoacE X-Received: by 2002:ac8:6ec9:: with SMTP id f9mr202357qtv.2.1630537208441; Wed, 01 Sep 2021 16:00:08 -0700 (PDT) X-Received: by 2002:ac8:6ec9:: with SMTP id f9mr202327qtv.2.1630537208115; Wed, 01 Sep 2021 16:00:08 -0700 (PDT) Received: from t490s ([2607:fea8:56a3:500::ad7f]) by smtp.gmail.com with ESMTPSA id g8sm74883qkm.25.2021.09.01.16.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 16:00:07 -0700 (PDT) Date: Wed, 1 Sep 2021 19:00:05 -0400 From: Peter Xu To: Axel Rasmussen Cc: LKML , Linux MM , Andrea Arcangeli , Mike Rapoport , Jerome Glisse , Alistair Popple , Yang Shi , Andrew Morton , David Hildenbrand , Miaohe Lin , "Kirill A . Shutemov" , Matthew Wilcox , Hugh Dickins Subject: Re: [PATCH 1/5] mm/shmem: Unconditionally set pte dirty in mfill_atomic_install_pte Message-ID: References: <20210901205622.6935-1-peterx@redhat.com> <20210901205622.6935-2-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Axel, On Wed, Sep 01, 2021 at 02:48:53PM -0700, Axel Rasmussen wrote: > On Wed, Sep 1, 2021 at 1:56 PM Peter Xu wrote: > > > > 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/ > > Thanks for the cleanup Peter! No problem. Obviously that special handling of SetPageDirty is still too tricky to me and I'd love to remove it. > > I think the discussion of whether or not the data can be marked dirty > below is correct, and the code change looks good as well. But, I think > we're missing an explanation why Hugh's concern is indeed not a > problem? > > Specifically, this question: > > "Haha: I think Andrea is referring to exactly the dirty_accountable > code in change_pte_protection() which worried me above. Now, I think > that will turn out okay (shmem does not have a page_mkwrite(), and > does not participate in dirty accounting), but you will have to do > some work to assure us all of that, before sending in a cleanup > patch." > > Do we have more evidence that this is indeed fine, vs. what we had > when discussing this before? If so, we should talk about it explicitly > in this commit message, I think. > > (Sorry if you've covered this and it's just going over my head. ;) ) Thanks for looking into this. I thought Hugh's explanation should mostly have covered that. The previous worry is we may have mprotect() applying write bit errornously if we have some read-only pte marked dirty. But I don't think that'll happen just like Hugh stated in the thread I attached, as the dirty accountable flag is only set if vma_wants_writenotify() returns true. Take the first example within that helper: if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED))) return 0; So firstly it never applies to vma that doesn't have VM_WRITE|VM_SHARED. So far it even doesn't work for anonymous, but logically it may, like: https://github.com/aagit/aa/commit/05dc2c56ef79b3836c75fcf68c5b19b08f4e4c58 Peter Collingbourne originated that patch, due to some reason it didn't land which I forgot, however I still think it's doable even for anonymous. Sorry to have gone off-topic; let me go back to it. It also checks for e.g. page_mkwrite() needs, soft dirty tracking and so on to make sure it's okay to grant write bit when possible. Hugh mentioned "do some work to assure us all of that" - I did firstly went throught the code carefully myself so I'm more certain it's doing the right thing to me, secondly I did run quite some tests on the patch (actually on the whole uffd-wp shmem+hugetlbfs branch). Even if I'm going to switch the uffd-wp series to the pte marker format, this patch won't change. I also analysized three callers that may be affected by this change below, and explaining why it's okay. I hope that can also be counted as part of the "some work" that Hugh asked. Besides all these, I'm pretty happy too if anyone would help me to tell otherwise on whether there's still things missing so we can't do this. That's the "code review" part for every single patch, including this one, isn't it? :) Thanks, > > > > > > > > > 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. -- Peter Xu