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 X-Spam-Level: X-Spam-Status: No, score=-2.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20982C433DB for ; Thu, 24 Dec 2020 03:30:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A4B00224DF for ; Thu, 24 Dec 2020 03:30:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4B00224DF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F1C008D006C; Wed, 23 Dec 2020 22:30:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECCDC8D0063; Wed, 23 Dec 2020 22:30:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBA398D006C; Wed, 23 Dec 2020 22:30:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id C56F68D0063 for ; Wed, 23 Dec 2020 22:30:44 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7D6B08249980 for ; Thu, 24 Dec 2020 03:30:44 +0000 (UTC) X-FDA: 77626748808.06.show78_3e082222746e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 5491910040121 for ; Thu, 24 Dec 2020 03:30:44 +0000 (UTC) X-HE-Tag: show78_3e082222746e X-Filterd-Recvd-Size: 5788 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Dec 2020 03:30:43 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id z12so447538pjn.1 for ; Wed, 23 Dec 2020 19:30:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tPmNTzdXNZi8m1t8uo8B9JQpXn5P/PEOVeaeX2In4ao=; b=EARqp4RXMHAwoT75eHexGYdpftgE7+/9giHbUFmJeRKxl8bb68OKXHDt2goPqlA/39 J9QHhzRKf1ftUex/JQf208YnNG0dFgqxCMqTV2xH4btVOIZw6WsyUjRrgPSklXggOn/V azX+fZcuvBONeA79UwOJAwZ/Dj6Ve6WcUeeu1DZQfgKHouvn+L9P5B8UgCC+QX9WJY+c 8ZKIMCCgawveY+u0LoWJvUQrQrppjZGThf7XAHCM9H0dyLVyNPWaRp0nZ6xkWhr4m0v0 7S1v/qrcuwCBV/MrjOrNJG502mxkBETIcfungictZMNI8/rDGBFa5QvKhxI53RBxC60a TSZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tPmNTzdXNZi8m1t8uo8B9JQpXn5P/PEOVeaeX2In4ao=; b=GRydrAyLhTbPEyvgtybWA3qPbyjiuZFJlLCmkUNvThsCr0m133EwaLNJKlVjNO9+gm vze3lHhN6UPivh5Zgy+r+3t4l3NbOnmVKKyezPy2qKwgrc/qIyfJNA5GplzteFqMTwnN w7UHRUL90wFEwP3PFMKmR2zfG4gCjLBgyVxKbcMzIH7d6bIQ8RBTN0DZyLLfJnEKuq3G EzKKKiKO2SBh9baecpuI6zk25qMVW/m7h/1QfkADHm50FlR9FNiXdR7FgLL4dEr50aIE jZpphc9tMccj0yfQe6N2G0WFMXzjYGQP/EMu3FA5r/8mNQZ7lx9uhu8cLlzOK6pbeZU5 P0zw== X-Gm-Message-State: AOAM533kXNCLOXx0qRAPyzkxO70DWSrBmel4ZR21Qw8oK/R0Yy3lTpbB Rdqlxhy+lYxd1IKfFFuHMEY= X-Google-Smtp-Source: ABdhPJxC2GB+3NzCqEB4kk72085mvlPkbxuY7NwYdlHfIXgauu/ASicfIb/rPLDHR0/qWINP/J07yQ== X-Received: by 2002:a17:902:7292:b029:dc:ac9:25b5 with SMTP id d18-20020a1709027292b02900dc0ac925b5mr28509309pll.2.1608780642620; Wed, 23 Dec 2020 19:30:42 -0800 (PST) Received: from ?IPv6:2601:647:4700:9b2:50a2:5929:401b:705e? ([2601:647:4700:9b2:50a2:5929:401b:705e]) by smtp.gmail.com with ESMTPSA id w18sm25100682pfj.120.2020.12.23.19.30.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Dec 2020 19:30:41 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: [PATCH] mm/userfaultfd: fix memory corruption due to writeprotect From: Nadav Amit In-Reply-To: <3A6A1049-24C6-4B2D-8C59-21B549F742B4@gmail.com> Date: Wed, 23 Dec 2020 19:30:39 -0800 Cc: Andy Lutomirski , Yu Zhao , Andy Lutomirski , Linus Torvalds , Peter Xu , linux-mm , lkml , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , stable , Minchan Kim , Will Deacon , Peter Zijlstra Content-Transfer-Encoding: quoted-printable Message-Id: <59E54984-DD1D-4BD2-8F22-45634B764F6A@gmail.com> References: <3A6A1049-24C6-4B2D-8C59-21B549F742B4@gmail.com> To: Andrea Arcangeli X-Mailer: Apple Mail (2.3608.120.23.2.4) 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: > On Dec 23, 2020, at 7:09 PM, Nadav Amit wrote: >=20 >> On Dec 23, 2020, at 6:00 PM, Andrea Arcangeli = wrote: >>=20 >> On Wed, Dec 23, 2020 at 05:21:43PM -0800, Andy Lutomirski wrote: >>> I don=E2=80=99t love this as a long term fix. AFAICT we can have = mm_tlb_flush_pending set for quite a while =E2=80=94 mprotect seems like = it can wait in IO while splitting a huge page, for example. That gives = us a window in which every write fault turns into a TLB flush. >>=20 >> mprotect can't run concurrently with a page fault in the first place. >>=20 >> One other near zero cost improvement easy to add if this would be "if >> (vma->vm_flags & (VM_SOFTDIRTY|VM_UFFD_WP))" and it could be made >> conditional to the two config options too. >>=20 >> Still I don't mind doing it in some other way, uffd-wp has much = easier >> time doing it in another way in fact. >>=20 >> Whatever performs better is fine, but queuing up pending invalidate >> ranges don't look very attractive since it'd be a fixed cost that = we'd >> always have to pay even when there's no fault (and there can't be any >> fault at least for mprotect). >=20 > I think there are other cases in which Andy=E2=80=99s concern is = relevant > (MADV_PAGEOUT). >=20 > Perhaps holding some small bitmap based on part of the deferred = flushed > pages (e.g., bits 12-17 of the address or some other kind of a single > hash-function bloom-filter) would be more performant to avoid (most) > unnecessary TLB flushes. It will be cleared before a TLB flush and set = while > holding the PTL. >=20 > Checking if a flush is needed, under the PTL, would require a single = memory > access (although potentially cache miss). It will however require one = atomic > operation for each page-table whose PTEs=E2=80=99 flushes are deferred = - in contrast > to the current scheme which requires two atomic operations for the = *entire* > operation. Just to finish my thought - clearing the bitmap is the tricky part, which I still did not figure out.=