Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1180700rwb; Thu, 8 Dec 2022 07:38:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf5GGlzVwwiMm9JMMW5p0efyvkBPPNZ7GzVODKpAiO14SAD9Uvzeq9YVn21+MX1inwhngLBM X-Received: by 2002:a05:6402:14:b0:461:deed:6d20 with SMTP id d20-20020a056402001400b00461deed6d20mr86890954edu.55.1670513881031; Thu, 08 Dec 2022 07:38:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670513881; cv=none; d=google.com; s=arc-20160816; b=IVRGXT76KSCGGzIvaYpYXh/UqUTBrkYoLpBfl7H8uVHLYFB5mcTiUThgVSo0dpZc8T tqPNrKf67ZEdsazSojGx45h29AZdPlM597IRIispR0zQV74t9QKOnrAVlWaG2l3DHVcy ld50axVUQ1rrd8RVuseUAQEnkLAXxk3/FNPMKRWQQmvVd+80kFUiowbXjwd+ZYSv8GJI XmsDtawHzMXxUdGhvjrw/Ydq2A3lafqDTxDUfp0urO0KjcgoaEJa5+tWRUCPtQ6RMmyf ZYytC0Ouop1zfnXyLc6PEUvGWCKy+HkvOEJoZLc7Ydn/xyX0kiDQpU4GT4/F0lH5KsVd pfog== 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=1TCrGY30xtqKhvpkZ91gzI+bfZZQwx6XMMEYmjyVbA4=; b=AZKBDTtHpMlWPnIay+I5pfIvQN2NaDWoBDPDPxvJLcFg+lygCuSQBJmW+6vJFcHGP4 yB8QVxX/0hG987Lh6daRGeNs2WASj1zTbl94Wb+74gDyC9+PQmeg93xqHUI4FAgFyrsi +LPsksl163yFgqZ8wcoCJKRIJqEUg4q/gu0I1TYCh37mFgWYoV35gzMmxjMVhnEGCKgV X4a8aQ+G3YbeDjJI+3s+MaxRttC1dI7D6e8ObtmN2L+KbQLITG/vAIhCSqukJ6+C8/Cr qCu3/6tMXKsYnmtkwAGx8MSxDxM6fai8sBwevHlc+L6cKtv4zL79GmwaXy8XxCDDTBAs +s2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dq/kYMa/"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf36-20020a1709077f2400b007c0aa685133si19568105ejc.34.2022.12.08.07.37.34; Thu, 08 Dec 2022 07:38:01 -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=@redhat.com header.s=mimecast20190719 header.b="dq/kYMa/"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230354AbiLHPVP (ORCPT + 72 others); Thu, 8 Dec 2022 10:21:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230221AbiLHPUx (ORCPT ); Thu, 8 Dec 2022 10:20:53 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B4E2103A for ; Thu, 8 Dec 2022 07:17:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670512654; 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=1TCrGY30xtqKhvpkZ91gzI+bfZZQwx6XMMEYmjyVbA4=; b=dq/kYMa/1WGdfpbLqQzOSgi6B6ru0vxm//Fs9hzPfbsyYaY37E4u6PFnoEozehskTSjXqF eWkdl/7eRBcEMz3c4enK8JiGMdC6FCqreUe7HhroMEMrGN8dJVn+vhJsNKagixxniS6r9w ofSFBrkvvoRhNFfZMHwYoNMlrlJqhj8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-306-USx6dQuyMN2vpuwmh3jfLA-1; Thu, 08 Dec 2022 10:17:32 -0500 X-MC-Unique: USx6dQuyMN2vpuwmh3jfLA-1 Received: by mail-qt1-f200.google.com with SMTP id m8-20020ac807c8000000b003a7f82f0da7so1642723qth.11 for ; Thu, 08 Dec 2022 07:17:31 -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=1TCrGY30xtqKhvpkZ91gzI+bfZZQwx6XMMEYmjyVbA4=; b=5js4h7pY1dVM+y1c9Y7JEnRsxhEtmWskh6n3p8IJ1AMOOQVYzI2HrUiUqb7SH1i5Fv clRGQC5AWSMWLytIT4EX98ykuwXaQ8Xm7PxfJ5eQkniLBLRnEPeL44h5SJGTHJW4pahI 1HhV8Lrel6YjFSbtwWFtreridt0hzoi5ZVBg0vFj26fiVzI3mNRclyJkIbe8oEfgq9HD 5IR3RXe6kAqwLNxbJ2YwB/wn4OokZloh5OVg9vuNEXBuOVHo11+lzIMADwxQCH2+LxbR 1kDejYCgfuNSfmzhuvH0dIRQviZxJcjXTcgZZXQFptFKfvjj5RUSm8gbV5DHwaKWKI8B K54Q== X-Gm-Message-State: ANoB5pnTnPGX/qaZvcYkOUP3ae6Zdk+3DGTox2Gec5l5L4zuFDN9DSwh uvOwXmlLIBY0hOPNb42mPTsX0dMmeyBQeWUMFlIuEFxlDEnmxlU7X7C62zhsaprIzd9VkNZ64ji qzjLpKnLNFecOnZgHl9mwNCLL X-Received: by 2002:a05:622a:4a17:b0:3a5:3c5e:7b67 with SMTP id fv23-20020a05622a4a1700b003a53c5e7b67mr3659177qtb.37.1670512651093; Thu, 08 Dec 2022 07:17:31 -0800 (PST) X-Received: by 2002:a05:622a:4a17:b0:3a5:3c5e:7b67 with SMTP id fv23-20020a05622a4a1700b003a53c5e7b67mr3659149qtb.37.1670512650788; Thu, 08 Dec 2022 07:17:30 -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 c4-20020a05620a268400b006ec62032d3dsm19471430qkp.30.2022.12.08.07.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 07:17:29 -0800 (PST) Date: Thu, 8 Dec 2022 10:17:28 -0500 From: Peter Xu To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ives van Hoorne , stable@vger.kernel.org, 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> <5a626d30-ccc9-6be3-29f7-78f83afbe5c4@redhat.com> <53e52007-e556-332d-ec4d-5fe48a90e9b0@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <53e52007-e556-332d-ec4d-5fe48a90e9b0@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 Wed, Dec 07, 2022 at 09:10:41PM +0100, David Hildenbrand wrote: > Now, my 2 cents on the whole topic regarding "supported", "not supported" > etc: > > (1) If something is not supported we should bail out or at least warn > the user. I'm pretty sure there are other uffd-wp dummy users like > me. Skimming over the man userfaultfd page nothing in particular > regarding PROT_WRITE, mprotect(), ... maybe I looked at the wrong > page. > (2) If something is easy to support, support it instead of having all > these surprises for users and having to document them and warn the > user. Makes all these discussions regarding what's supported, what's > a valid use case, etc ... much easier. > (3) Inconsistency confuses users. If something used to work for anon, > in an ideal world, we make shmem behave in a similar, non-surprising > way. > (4) There are much smarter people like me with much more advanced > magical hats. I'm pretty sure they will come up with use cases that > I am not even able to anticipate right now. > (5) Users will make any imaginable mistake possible and point at the > doc, that nothing speaks against it and that the system didn't bail > out. > > Again, just my 2 cents. Maybe the dos and don'ts of userfaultfd-wp are > properly documented already and we just don't bail out. I just don't know how to properly document it with all the information. If things missing we can always work on top, but again I hope we don't go too far from what will become useful. Note that I never said mprotect is not supported... AFAIR there is a use case where one can (with non-cooperative mode) use uffd-wp to track a process who does mprotect. For anon uffd-wp it should work already, now this also reminded me maybe yes with the vm_page_prot patch for shmem from you it'll also work with shmem and it's still good to have that. In that case IIUC we'll just notify uffd-wp first then with SIGBUS. Said that, it's still unclear how these things are used altogether in an intended way. Let me give some examples. - What if uffd-wp is registered with SIGBUS mode? How it'll work with mprotect(RO) too which also use SIGBUS? - What if uffd-wp tracks a process that also use uffd-wp? Now nest cannot work, but do we need to document it explicitly, or should we just implemented nesting of uffd-wp? - Even if uffd-wp seems to work well with mprotect(RO), what about all the rest modes combined? Uffd has missing and minor mode, mprotect can do more than RO. One thing we used to discuss but a slight different case: what happens if one registers with uffd missing and also mprotect(NONE)? When the page accessed IIUC we will notify SIGBUS first instead of uffd because IIRC we'll check vma flags earlier. Is this the behavior we wanted? What's the expected behavior? This will also be a different order we notify comparing to the case of "uffd-wp with mprotect(RO)" because in that case we notify uffd-wp before SIGBUS. Should we revert the order there just to align with everything? Sorry to dump these examples. What I wanted to say is to me there're just so many things to consider and that's just a start. I am not sure whether it'll be even worth it to decide which should be the right order and make everything very much defined, even if I still think 99% of the people will not even care, when someone cares as a start from 1% then 0.99% of them will find that they can actually do it cleaner with other approaches with the same kernel facilities. What about the last 0.01%? They're the driven force to enhance the kernel, that's always my understanding. They'll either start to ask: "hey I have a use case that want to use uffd with mprotect() in this way, and that cannot be done by existing infras. Would it make sense to allow it to happen?". Or they come with patches. That's how things evolve to me. These may be seen as excuses of not having proper documentation, personally sometimes it's not easy for me to draw the line myself on which should be properly documented and which may not be needed. What I worry is over engineer and we spend time on things that may not as important or more priority than something else. Going back - the solo request I was asking to not use a mprotect example is mprotect is really not the one that the majority should use for using uffd-wp. It's not easy to help people understand the problem at all. That's all for that. Thanks, -- Peter Xu