Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2392901pxb; Tue, 13 Apr 2021 00:19:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhQKhUBn0AdWutWBNeq26trwveoriXt5PYX0jHPHvxTizc0DHY7uZEBS3N6JF9Lll7KeXS X-Received: by 2002:a05:6402:10c9:: with SMTP id p9mr33734686edu.268.1618298344618; Tue, 13 Apr 2021 00:19:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618298344; cv=none; d=google.com; s=arc-20160816; b=ipc1oJFHXEiOhSsLtXkYod4dDK3h6PpPXBpUzCeWnBuPBtYXiKStEUXFSGQgwbjMwv XvXOJWOeFQ4irP0VRks9QJiU/FnIldtpZc+Zzj3sFZ3sednKBzTC96KRn5bOf4rh3qzN BKGoCflFSuhj411JVVdz2blFaO0cdli0pjNn/vRnN7zbEBsoTCxXo88cnNn35W6pzQmp QmK64rRVbeYWtl9uTcOqH3SwEotlUEmrBbRMUpIK5qZ4n2St6tev459AA4yqspiSy+Gr ix8IGI3YpBIPoBH+JqY77AwMO1xKq+Yi0zQ1LpBHYgu29PjDbnqxaAXq+6jxptOlVQxl hkNw== 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=rSg/4g7S1VAs0BEe21c6JFZm2CbvqXRaPJMkscjjUzQ=; b=vgOMxj/M9fwHqiizYRs6kF0FAKTMHVk/5HOP8prBd87Mlkeg4i2QrFG1vbVnGUV3/+ s3l0giB5VqiRN9gpsMLuvWzE9jYGVMeuC5X7PH9QMUifsbZebEm1DlRj1RaNR7ldQgFr Ytoa7FwLTHN+XogR/0+gtkVXGQk+lcArBJV4tqmAwnmeMHOZ9oOtQ4ZnIVPp8t89l88F 9sbzKbdpiOU4NM1jMwrwobqsp0hPZdy7KKM4Ek1Qi9wffLP4HfPjG9U8lMxgZsKhDTHe gHq2chJSd4hRpBQmu1mZ/f9fNpkMEQPGAuoesYtBXEwbRjsMG3UwuOvpGLTbJ0FglY3T 3wbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=inutjazr; 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 p3si9724727eds.157.2021.04.13.00.18.41; Tue, 13 Apr 2021 00:19:04 -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=inutjazr; 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 S237700AbhDLVzD (ORCPT + 99 others); Mon, 12 Apr 2021 17:55:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37037 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238235AbhDLVzC (ORCPT ); Mon, 12 Apr 2021 17:55:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618264484; 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=rSg/4g7S1VAs0BEe21c6JFZm2CbvqXRaPJMkscjjUzQ=; b=inutjazrEeRzr033gJXnuAEJuuW9F61w88eB6QP+2TNHEt0tFFDArPcZj3U8M1YpVdk7JW BfRB9Knk9OA2v5Oh3C41ky1mfC5O3GivqYUDNjomj4KBEATTIuEIIH23XIlgKaM6L0eDY2 K/Z+AJoaP01Cy69B1xAfDUia4djdYkY= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-209-PljpxEpRNSGXJmng-yk5vw-1; Mon, 12 Apr 2021 17:54:42 -0400 X-MC-Unique: PljpxEpRNSGXJmng-yk5vw-1 Received: by mail-qv1-f71.google.com with SMTP id n3so8887612qvr.8 for ; Mon, 12 Apr 2021 14:54:42 -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=rSg/4g7S1VAs0BEe21c6JFZm2CbvqXRaPJMkscjjUzQ=; b=LAVxXbFLqXilOp6IVRZtAHFgPi2rU0Te2MVbdnp+lt0rabNECW6uMAUyO67y7BWIC7 1jp5ymzcgIRxx9bo5kFqWgo+kFcRj337jFY4/1XvxPum7KWMks6PmQqGq/HndPyEB1rH RLohiUXl1ELiVSIYnM/oveJHzzVnjXRK220zxiYWZx3mDn6q4IwZ2bP+GhOKUKIwJZT6 gv9q4gRFXnzUBlW94A7Q0IG2HT6SlbNMGAMbr2zn9EhPyjQaRRlB7KcSYcUV2na+pnE1 VRQMqIZmE3e68UiBiDm5/7GnHC3yoXjuP6coag/6Bg65FzgKGUfT9OHc4CtKxUt8EanV 1tqw== X-Gm-Message-State: AOAM531fmjwyiUViyvHrqhzOKV0WybUMSnYVI/XA99KxveukFbbAjFMq r6kQ9atapPA7ibVO+zvw9a0y6wBr9QIYrzgDmYHqUR8jm7LIAeRGaGfdKCOPAg43qzdSWJP9UfW uN0DpQtEf0cSNlaaA/3fL87pr X-Received: by 2002:a05:6214:14b4:: with SMTP id bo20mr4943799qvb.20.1618264482036; Mon, 12 Apr 2021 14:54:42 -0700 (PDT) X-Received: by 2002:a05:6214:14b4:: with SMTP id bo20mr4943769qvb.20.1618264481785; Mon, 12 Apr 2021 14:54:41 -0700 (PDT) Received: from xz-x1 (bras-base-toroon474qw-grc-88-174-93-75-154.dsl.bell.ca. [174.93.75.154]) by smtp.gmail.com with ESMTPSA id z18sm3501170qkg.42.2021.04.12.14.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 14:54:40 -0700 (PDT) Date: Mon, 12 Apr 2021 17:54:37 -0400 From: Peter Xu To: Hugh Dickins Cc: Axel Rasmussen , Alexander Viro , Andrea Arcangeli , Andrew Morton , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Rapoport , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Brian Geffon , Cannon Matthews , "Dr . David Alan Gilbert" , David Rientjes , Michel Lespinasse , Mina Almasry , Oliver Upton Subject: Re: [PATCH v4] userfaultfd/shmem: fix MCOPY_ATOMIC_CONTINUE behavior Message-ID: <20210412215437.GA1001332@xz-x1> References: <20210401183701.1774159-1-axelrasmussen@google.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, Hugh, On Tue, Apr 06, 2021 at 11:14:30PM -0700, Hugh Dickins wrote: > > +static int mcopy_atomic_install_ptes(struct mm_struct *dst_mm, pmd_t *dst_pmd, > > + struct vm_area_struct *dst_vma, > > + unsigned long dst_addr, struct page *page, > > + enum mcopy_atomic_mode mode, bool wp_copy) > > +{ [...] > > + if (writable) { > > + _dst_pte = pte_mkdirty(_dst_pte); > > + if (wp_copy) > > + _dst_pte = pte_mkuffd_wp(_dst_pte); > > + else > > + _dst_pte = pte_mkwrite(_dst_pte); > > + } else if (vm_shared) { > > + /* > > + * Since we didn't pte_mkdirty(), mark the page dirty or it > > + * could be freed from under us. We could do this > > + * unconditionally, but doing it only if !writable is faster. > > + */ > > + set_page_dirty(page); > > I do not remember why Andrea or I preferred set_page_dirty() here to > pte_mkdirty(); but I suppose there might somewhere be a BUG_ON(pte_dirty) > which this would avoid. Risky to change it, though it does look odd. Is any of the possible BUG_ON(pte_dirty) going to trigger because the pte has write bit cleared? That's one question I was not very sure, e.g., whether one pte is allowed to be "dirty" if it's not writable. To me it's okay, it's actually very suitable for UFFDIO_COPY case, where it is definitely dirty data (so we must never drop it) even if it's installed as RO, however to achieve that we can still set the dirty on the page rather than the pte as what we do here. It's just a bit awkward as you said. Meanwhile today I just noticed this in arm64 code: static inline pte_t pte_wrprotect(pte_t pte) { /* * If hardware-dirty (PTE_WRITE/DBM bit set and PTE_RDONLY * clear), set the PTE_DIRTY bit. */ if (pte_hw_dirty(pte)) pte = pte_mkdirty(pte); pte = clear_pte_bit(pte, __pgprot(PTE_WRITE)); pte = set_pte_bit(pte, __pgprot(PTE_RDONLY)); return pte; } So arm64 will explicitly set the dirty bit (from the HW dirty bit) when wr-protect. It seems to prove that at least for arm64 it's very valid to have !write && dirty pte. Thanks, -- Peter Xu