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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BA58C3A5A7 for ; Tue, 6 Dec 2022 21:18:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D32628E0003; Tue, 6 Dec 2022 16:18:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE2A08E0001; Tue, 6 Dec 2022 16:18:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B82AB8E0003; Tue, 6 Dec 2022 16:18:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A71BD8E0001 for ; Tue, 6 Dec 2022 16:18:34 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6A4341A0E03 for ; Tue, 6 Dec 2022 21:18:34 +0000 (UTC) X-FDA: 80213145348.22.6F5CE7F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id B1A7440013 for ; Tue, 6 Dec 2022 21:18:33 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cfeMti6i; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670361514; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=i2YR3mOSxzpUKrezOQOiAA+KBmrgPX1bMkhWS8VXMu8=; b=VAy9HA0Axva4Dl1ZSZnH3qWC2pOZ18AnGqFquPQt8Z9B1kDSTyfPtBiEk/FS8EoDhKYiz6 HmXDdsUQMI2d+zhSxGUcy1ZnJ4gxFJ2vxrRLZNHMhP+Ng302rjqfRK47N8JIl2hpncVoBc U+p1WwS+HAb3MrO/0vH0G3RczCyhi7E= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cfeMti6i; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670361514; a=rsa-sha256; cv=none; b=U3dUgAcqf/Y467ovKoTzzXPvTCRVnm/D4F4AFH4hRjwMyvOkY9Ix558r1bLmUqPfyNMi83 OboKU3xXWvwT0F+KSSMlmC3L1OL2KoRhnrQQShRVcl472uMLwFPKz3m0oXU21U8RH65Nv1 a05DoicBkI06AnPPnMT71t9VA5m6kYM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670361513; 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=i2YR3mOSxzpUKrezOQOiAA+KBmrgPX1bMkhWS8VXMu8=; b=cfeMti6imvmmHYEybwlseU2p5W8GsaQRknif3Hc3kvd/K7ror40HHuwjkwr7EEIIJXSZgh NksY/pDr74X9eJy5D63I87k9uVzqVT+h+XzQp7uxtgXM6TgGzRjse8G3233R1zCF9mZGeC 6cZizbmxEXZ4dBbIeoTbXxqVNjoGVLo= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-152-Vr7obXY8PySsWTiR9IhtFg-1; Tue, 06 Dec 2022 16:18:32 -0500 X-MC-Unique: Vr7obXY8PySsWTiR9IhtFg-1 Received: by mail-qv1-f69.google.com with SMTP id m4-20020ad44484000000b004c78122b496so3601706qvt.7 for ; Tue, 06 Dec 2022 13:18:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i2YR3mOSxzpUKrezOQOiAA+KBmrgPX1bMkhWS8VXMu8=; b=Xw7ss4FeWWfmNZDyQjfM1RMLpeWqmC3Ij2vJx0KCfivzw/mCqYJE2kvQUApKGLGIGG Tq1ICRJxR5mx70Ad4qoTW8XecUf0c6A9jHdcrbpTL66VQp0uBbsiCHNSqkoQpg4N+X78 4qYVsGt3vIGzXC6TmYsmOPEQHVmdoOovzlky2bXAaTQFM9TsD2KjkTzJMyNbGeuC0HKs f4CUrrHQtushPFXwnuATwrimzJ+1PnLvmStUFCGfodP5RrOhe/GreDuAjBifp/R7EnqY hro5lTYk89Bx+rztLCH640Cl8rF+NoapDQQcyX2/Kn7uCUTx3TegVwy3the6uTRUnoBL TZnQ== X-Gm-Message-State: ANoB5pmioIkb+fsli6etXJlIvg7ovHJOXXGrxYyAB14FzsA3/WDDlSFc 444JvF8IfmIlAUtL+vw6qMNmfZ/j0X97ckJp7y5cISGcSu4076OdQNaw/umCHQH413jBNyZIOh8 N6Io7avBGlrY= X-Received: by 2002:ac8:1408:0:b0:3a5:c55a:47a4 with SMTP id k8-20020ac81408000000b003a5c55a47a4mr516848qtj.54.1670361511579; Tue, 06 Dec 2022 13:18:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf5lFksiah2trB/06QzRBowJVOz6+v96Eel10IKtkPR/Yr1bHJq4VqtTDKSF8LgnSXzAtoPoHg== X-Received: by 2002:ac8:1408:0:b0:3a5:c55a:47a4 with SMTP id k8-20020ac81408000000b003a5c55a47a4mr516838qtj.54.1670361511295; Tue, 06 Dec 2022 13:18:31 -0800 (PST) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id bp39-20020a05620a45a700b006cbe3be300esm15581579qkb.12.2022.12.06.13.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 13:18:30 -0800 (PST) Date: Tue, 6 Dec 2022 16:18:28 -0500 From: Peter Xu To: Hugh Dickins , David Hildenbrand Cc: David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ives van Hoorne , Andrew Morton , Hugh Dickins , Alistair Popple , Mike Rapoport , Nadav Amit , Andrea Arcangeli Subject: Re: [PATCH RFC] mm/userfaultfd: enable writenotify while userfaultfd-wp is enabled for a VMA Message-ID: References: <20221202122748.113774-1-david@redhat.com> <690afe0f-c9a0-9631-b365-d11d98fdf56f@redhat.com> <19800718-9cb6-9355-da1c-c7961b01e922@redhat.com> <92173bad-caa3-6b43-9d1e-9a471fdbc184@redhat.com> <22d8e8ac-d75-a66-2650-b4d59f89855e@google.com> MIME-Version: 1.0 In-Reply-To: <22d8e8ac-d75-a66-2650-b4d59f89855e@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B1A7440013 X-Rspam-User: X-Stat-Signature: ukx63r9izr9unjkod6skbrdxi3x5ag6b X-Spamd-Result: default: False [-0.90 / 9.00]; BAYES_HAM(-6.00)[100.00%]; SORBS_IRL_BL(3.00)[209.85.219.69:received]; SUSPICIOUS_RECIPS(1.50)[]; MID_RHS_NOT_FQDN(0.50)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; RCVD_NO_TLS_LAST(0.10)[]; DKIM_TRACE(0.00)[redhat.com:+]; RCPT_COUNT_TWELVE(0.00)[12]; FROM_EQ_ENVFROM(0.00)[]; DMARC_POLICY_ALLOW(0.00)[redhat.com,none]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; R_DKIM_ALLOW(0.00)[redhat.com:s=mimecast20190719]; ARC_NA(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:170.10.133.0/24]; TO_DN_SOME(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-HE-Tag: 1670361513-558227 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: Hi, Hugh, On Tue, Dec 06, 2022 at 11:09:40AM -0800, Hugh Dickins wrote: > I have not been following the uffd-wp work, but I believe that David's > painstaking and excellent account of vm_page_prot is correct. Peter, > please I beg you to follow his advice and go for (1) for uffd-wp. Thanks for jumping in, I will. Your input definitely matters. I think the fundamental moot point was whether vm_page_prot is the "safest" or "default" behavior of vma. I thought it was the "default" and I don't want to have VM_UFFD_WP regions to have default no-write attribute comparing to generic ones. I wanted it to behave exactly like a normal shmem vma if no one explicitly does something else. If it's "safest" and you also agree then I think indeed VM_UFFD_WP falls into that category; frankly I don't have a solid clue before. Maybe that also matches better with the recent vma_wants_manual_pte_write_upgrade(), or we start to lose write bit in do_numa_page() at least for uffd-wp protected ranges when recovering the ptes, and it'll be ugly to have: diff --git a/include/linux/mm.h b/include/linux/mm.h index 3a3d23b3dbe2..718d540b9eb4 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2086,7 +2086,7 @@ static inline bool vma_wants_manual_pte_write_upgrade(struct vm_area_struct *vma * private mappings, that's always the case when we have write * permissions as we properly have to handle COW. */ - if (vma->vm_flags & VM_SHARED) + if ((vma->vm_flags & VM_SHARED) && !userfaultfd_wp(vma)) return vma_wants_writenotify(vma, vma->vm_page_prot); return !!(vma->vm_flags & VM_WRITE); To recover the write bit. I tried to move forward with the 47ba8bcc33b2 ("mm/migrate: fix read-only page got writable when recover pte", 2022-11-25) in mm-unstable upstream because that seems pretty obvious to me and that's verified in the test beds, but I obviously failed anyway. Let's adjust the patches with the best we can have. > I do not share David's faith in "documented": documented or not, > depart from safe convention and you will be adding (at least the > opportunity for) serious bugs. Yes I agree not having the write bit is safer. That's also why I wanted to move the wrprotect into pte_mkuffd_wp. I assume from "resolving problem" pov they're the same, but I'll follow your advise. David, would you please repost a new patch for this one and copy Ives to make sure it'll work for him in his systems? I'd suggest to drop the mprotect example, I'll reply later on that to the other email but I still don't know whether it's a good example for a reader to understand the problem. No reproducer needed for numa I think - I guess Ives's test case would be far enough to verify it if possible. I also hope what Ives saw was the numa balancing issue you reported, so maybe it'll resolve all problem he has. Then with that verified and queued we can drop the mm/migrate patch. Thanks, -- Peter Xu