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=-3.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,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 49491C433E0 for ; Thu, 24 Dec 2020 03:34:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CCC9E224B0 for ; Thu, 24 Dec 2020 03:34:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCC9E224B0 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 59BCA8D006E; Wed, 23 Dec 2020 22:34:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 525A68D0063; Wed, 23 Dec 2020 22:34:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39DC48D006E; Wed, 23 Dec 2020 22:34:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id 1D6F18D0063 for ; Wed, 23 Dec 2020 22:34:07 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E164D1EF2 for ; Thu, 24 Dec 2020 03:34:06 +0000 (UTC) X-FDA: 77626757292.28.title37_4f10f912746e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id C02CF6D66 for ; Thu, 24 Dec 2020 03:34:06 +0000 (UTC) X-HE-Tag: title37_4f10f912746e X-Filterd-Recvd-Size: 6007 Received: from mail-il1-f181.google.com (mail-il1-f181.google.com [209.85.166.181]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Dec 2020 03:34:06 +0000 (UTC) Received: by mail-il1-f181.google.com with SMTP id k8so947596ilr.4 for ; Wed, 23 Dec 2020 19:34:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=c5fNsg2UwF5UocytYwq0XQNimIsx8M/0x2kcxXnzw6s=; b=PgNEDPhRRco6MUm+b35ScL9j7jTW2b7WyA5+rPGX4xjQrF6SUP/6+x/45YJPtKsHtG +pw2Aig8V5nQJ2pMAor1ZD3H9qsk2OPqg+BJ6NRonx+8A5Ph3TLfa+3BEvoH+W65zwHs 52a2XnIgl0IVSgJZPRgMOO/G/7vAYwyW1rBkk2Lb4b/aJuqeHYZ05wrVsjliA/IcAfoC mJ1cmIuuNuZ0I1Jx9dM1iGTfOwJU4ubp6ZkIf1Q48WGSVqulGu+na8E+JuA2Plv4CrFD MTVZlotsa8kip62TOCTXmoqLGNdIL65SxXUH1gTe9J7QfqcxmGdBBVDoXUU8FIcr45Ns sysA== 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:content-transfer-encoding :in-reply-to; bh=c5fNsg2UwF5UocytYwq0XQNimIsx8M/0x2kcxXnzw6s=; b=YMRvoJpRgXKYaAHv4G8xYhHoE/J9Skv3AGtEsJkA2Z6Q6nkA+a/MZkXOohLcIBQdEA kjDA29svPO0JzykcqdcGfNdutduEjC2GGNa5BoVvIyrERWR7/lmw1lGjQfJm8tKkOoeQ nzDpTwyzQQN/rsZ8eTSuXFY6i+Tqb7xVfbyF0zbvoN34QckGLq56ulVIPSC5cJ+CBs0j r8Sd472cPxHeeLRFXCMTFSEUfBl3+McMEPlrqi0mdDDA2m2w6h50Oz3TQuOO0pZmmXUl EwMZZl3Ehwxv4jtjCNn0/crOAy27Gi25PlLW+0kIxERIkaQYMmoDaizjbYDdUQFEscyn 64CQ== X-Gm-Message-State: AOAM531EdTw2KAR9qWin4qt254Qs3yQHO6XCFcXgxaeIo+pMrLbMJzfB DXQ/y5xZ2Azg6Mt1bBjL7JSq8Q== X-Google-Smtp-Source: ABdhPJwlSb2HJ2fXreVypNQMIQPBK3ZPIqIThkVchlUswu3+TbmFlW0XsYozNSC0nOOqS5dkRor2sg== X-Received: by 2002:a92:ca91:: with SMTP id t17mr27317300ilo.67.1608780845418; Wed, 23 Dec 2020 19:34:05 -0800 (PST) Received: from google.com ([2620:15c:183:200:7220:84ff:fe09:2d90]) by smtp.gmail.com with ESMTPSA id e9sm18039843ils.14.2020.12.23.19.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 19:34:04 -0800 (PST) Date: Wed, 23 Dec 2020 20:34:00 -0700 From: Yu Zhao To: Nadav Amit Cc: Andrea Arcangeli , Andy Lutomirski , Andy Lutomirski , Linus Torvalds , Peter Xu , linux-mm , lkml , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , stable , Minchan Kim , Will Deacon , Peter Zijlstra Subject: Re: [PATCH] mm/userfaultfd: fix memory corruption due to writeprotect Message-ID: References: <3A6A1049-24C6-4B2D-8C59-21B549F742B4@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <3A6A1049-24C6-4B2D-8C59-21B549F742B4@gmail.com> Content-Transfer-Encoding: quoted-printable 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 Wed, Dec 23, 2020 at 07:09:10PM -0800, Nadav Amit wrote: > > On Dec 23, 2020, at 6:00 PM, Andrea Arcangeli w= rote: > >=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 easie= r > > 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 releva= nt > (MADV_PAGEOUT). That patch only demonstrate a rough idea and I should have been elaborate: if we ever decide to go that direction, we only need to worry about "jumping through hoops", because the final patch (set) I have in mind would not only have the build time optimization Andrea suggested but also include runtime optimizations like skipping do_swap_page() path and (!PageAnon() || page_mapcount > 1). Rest assured, the performance impact on do_wp_page() from occasionally an additional TLB flush on top of a page copy is negligible. > 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 me= mory > access (although potentially cache miss). It will however require one a= tomic > 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 *ent= ire* > operation. >=20