Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7905142rwb; Tue, 6 Dec 2022 11:18:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf6LekhePLKsl1YUIy35Np5/t+V1Bn0g8PJbRpEWa8EISCUe9Zd979Sgx/a8LRuCn2cS8Okb X-Received: by 2002:aa7:d556:0:b0:45c:6467:94e2 with SMTP id u22-20020aa7d556000000b0045c646794e2mr78044184edr.295.1670354300338; Tue, 06 Dec 2022 11:18:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670354300; cv=none; d=google.com; s=arc-20160816; b=Zjd3brpeg2PoUhVQw7pdCzplzIfcE1AYx8fjjxV6a88bVRN5yTwvazV4vQteG0MzwP p30UROaM1wsne5lWTf07XMWo7B/L8w2w6Jxh3YB+xs9SMIN38bCgTEDofvPDdZZHR7zk UaBMEu1UJgdknOCavBtojxves9z+RD+8Q8+n7lfnD02tZmF00M94OhuPrhZweAeJSLo7 orEt83IDlBMnCulOUc2TXDY+2lC520kP9a29UXL4RVg6oHuslEST2drBXpz3pWMvk5GW hj8+a+TaV51/GUQHaILk5uTSgYlsq7BgaCPApyEpubgnHrFxlrqw+oS/fYeh84nGnniY PAkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=BdEVe1fkQEKVdGERRafaR9y25MuuPSNdqysHtrFxhBc=; b=IigqOhdx5CUwtMlo8/KhMq3pPhY1zxWba0V5XwswlT0nE/Qp/PcknGuYQyFKGwCEw3 GnzJAFiX+PqANOZ39GnTXDmTxmbHIbf8kUYJ5b4zASjZqgPUulAEyWF1GAFwe+2s3Lns 4FxwLIiGpe0FaEEZUrmdmiTn78Uw9piM4p4EpNUz2eLcN2GcAGSxD60mEQaxwBE3zmrm MU6RYgktEFw24//W9sIgG0nTiIiTre8UPCcvL2b7mSX6iwhfl7OOgK5pk5N8qDiOcIIz a7rJPUgwf5f/HSHKaw/YoT5gHdY43hVQDv/teNT2ieiYbB82jI/fiyoh50iIwsheIkpA Qw+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NzZ9GEK2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf34-20020a1709077f2200b0070fc7c9d71dsi15764582ejc.989.2022.12.06.11.18.01; Tue, 06 Dec 2022 11:18:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NzZ9GEK2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229462AbiLFTJ7 (ORCPT + 77 others); Tue, 6 Dec 2022 14:09:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbiLFTJv (ORCPT ); Tue, 6 Dec 2022 14:09:51 -0500 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDBF632B83 for ; Tue, 6 Dec 2022 11:09:50 -0800 (PST) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-144bd860fdbso5441649fac.0 for ; Tue, 06 Dec 2022 11:09:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=BdEVe1fkQEKVdGERRafaR9y25MuuPSNdqysHtrFxhBc=; b=NzZ9GEK2anazrjrWt8gm6BsL3RX9wGBqD0SD/nVRp+4i5wDcqbnK1HBEoEcik3nw/0 KxgQWAtwcx7Az+bFJU0ZTKREJjSD1QfLbCoIBQ6J37UVPFymYsEBYQd+0WhtmCHG4R8m V1U95jTzB29gWmrrKg63QSTm5R30jjoCL9muHVq5BAPI5uGHnO/oQ3kLfpXU6zO8Hrot oO00ki8ruN9BAFZKQ/5TB9s8cAv/Hyg7DZxPymRHn27d1PcDKlZUNbisAcFJPAfwqi2E 5uB19jFuR1j5dzyvpwyW7Fk2mdioyp28NpuTgHB5vDjQnVfvuCuMU0iKsd7aGjYXzPAa xcDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BdEVe1fkQEKVdGERRafaR9y25MuuPSNdqysHtrFxhBc=; b=tH6UW8EdwRdWtupn2bC/c0AEYzPMpBzD0aQ7rPp3ZEeBEGVyp+YHClLU6diBzCNUo7 tPPB6/0R6AC4tKdweg6vlC7P7nmHnO3bLND3cko22R7XyRdYKTquZXcjntksfGMBD4Qs R8uknmi57G9BjjI5wpCFXCNeV76nEYGEAeua9uIG4I+v15wkJEkKvJTtu4e6LinAZ4Lr W07KqkA9oR4EBbfrpV+4A3H6112Vpo/lNoxrJuFjQ7Lcm3J91tnHEsH+v1FV82QgbD0M 6V/wQTuDPmU4lSRX+WvhN+ZnDgZFvHM3azu9W7uP1/j4llMCX6Fo2Sk2nFNrQNi0CKhn a2OA== X-Gm-Message-State: ANoB5pknPT3YEWES6xxAQyLSmbDvoz9egefTKkBZ8u7nUC6dYFIWMDF4 5USFdgRMo170TID8yoXnSkso0A== X-Received: by 2002:a05:6870:c8c:b0:143:b006:7be9 with SMTP id mn12-20020a0568700c8c00b00143b0067be9mr22835025oab.69.1670353789957; Tue, 06 Dec 2022 11:09:49 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id r16-20020a05687080d000b00142d7f2fd4fsm11141637oab.48.2022.12.06.11.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 11:09:49 -0800 (PST) Date: Tue, 6 Dec 2022 11:09:40 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Peter Xu 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 In-Reply-To: <92173bad-caa3-6b43-9d1e-9a471fdbc184@redhat.com> Message-ID: <22d8e8ac-d75-a66-2650-b4d59f89855e@google.com> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 6 Dec 2022, David Hildenbrand wrote: ... > > We never had to remove write permissions so far from the vma->vm_page_prot > default. We always only added permissions. > > > Now, uffd-wp on shmem as of now violates these semantics. vma->vm_page_prot > cannot always be used as a safe default, because we might have to wrprotect > individual PTEs. Note that for uffd-wp on anonymous memory this was not an > issue, because we default to !write in vma->vm_page_prot. > > > The two possible ways to approach this for uffd-wp on shmem are: > > (1) Obey existing vma->vm_page_prot semantics. Default to !write and > optimize the relevant cases to *add* the write bit. This is > essentially what this patch does, minus > can_change_pte_writable() optimizations on relevant code paths where > we'd want to maintain the write bit. For example, when removing > uffd-wp protection we might want to restore the write bit directly. > > (2) Default to write permissions and check each and every code location > where we remap for uffd-wp ptes, to manuall wrprotect -- *remove* > the write bit. Alternatively, as you said, always wrprotect when > setting the PTE bit, which might work as well. > > > My claim is that (1) is less error prone, because in the worst case we forget > to optimize one code location -- instead to resulting in a BUG if we forget to > wrprotect (what we have now). But I am not going to fight for it, because I > can see that (2) can be made to work as well, as you outline in your patch. > > You seem to have decided on (2). Fair enough, you know uffd-wp best. We just > have to fix it properly and make the logic consistent whenever we remap a > page. > ... > > But I'm not going to argue about whats valid and whats not as long as it's > documented ;). I primarily wanted to showcase that the same logic based on > vma->vm_page_prot is used elsewhere, and that migration PTE restoration is not > particularly special. 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. 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. Hugh