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 31583C433E0 for ; Thu, 24 Dec 2020 03:09:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A7235224B1 for ; Thu, 24 Dec 2020 03:09:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7235224B1 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 D5F568D006A; Wed, 23 Dec 2020 22:09:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D10508D0063; Wed, 23 Dec 2020 22:09:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFFC08D006A; Wed, 23 Dec 2020 22:09:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id A82648D0063 for ; Wed, 23 Dec 2020 22:09:15 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 715FD8249980 for ; Thu, 24 Dec 2020 03:09:15 +0000 (UTC) X-FDA: 77626694670.05.scarf40_4a13b582746d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 5547718045E8D for ; Thu, 24 Dec 2020 03:09:15 +0000 (UTC) X-HE-Tag: scarf40_4a13b582746d X-Filterd-Recvd-Size: 5421 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Dec 2020 03:09:14 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id n25so794812pgb.0 for ; Wed, 23 Dec 2020 19:09:14 -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=9YZIn5r9a16cJmb80iAADW/k9YKcZBQhhaz7cSUNZQQ=; b=GXqTETn+JJ3Z+Wt/ra82ifel909kps/sWbceWAZcCu2eRwX2sou8hGWtU1nDtWUeAq bKo1GkOt0ps7mIKK/Xrfz4cWHR4Y2u3lZ+Lo13L3qS00yzdUvTmvIhnl60A4hG5YUQTp hEDyKPZvgoC9sm5ChGywNwtrmAwyn8eX+qKqvaHhRzZHaxJpqKVhs8vhQ2wVN7FakaRF yFm5BtvLWfkmiHpOToMEqdISmNfxH8Xt2kvFXo0q0CL+a35Kdi+MPBuVn8giFgSc+aB4 jF89vtd8BU90Oqfv3u4eW9BxpPqvpDhRmWukoESHT0JAyfWBNYHC57y0qugYf4Hbc4ZZ pb1w== 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=9YZIn5r9a16cJmb80iAADW/k9YKcZBQhhaz7cSUNZQQ=; b=I3AVLTDMKBYxLYDiekV8OWCyscPg2RntF00/NgdqPYyXuJRBa0wtZ30izwg2Jh/jGI NIVTgbQ0cxY/YaYWmWRrhsz5ymNZCri3EBLeEc8QXin/NBTduqJCLGGvdewfrJSVRaE4 Tpjq7Nm7ULQzdDTk+vZYsFMqmCo2CCAV/XMyV5j7fVCaQ6LduL/smjQRsshiB8/Sf7t9 Xy3kdcQWMdZYCZGWrUQJB4DTrtEcCEEHarqMbikwVgpGqtVg9fWSGqJ3rZJU2u3CnLSW 53lzEWrB8EFRJAzXYBkGllDylYomoO0k3YI7OAoZ/Y+Mqm99pq5ME4zlltKR7js6a3dg 234Q== X-Gm-Message-State: AOAM532ytyTOgdpQW2CyUuPkry1g4/nrpePoPYaeiESzAlkp+4m1RKmq UPkE/6B/bbvvKxbt9/Ub1XA= X-Google-Smtp-Source: ABdhPJw4q3WD3Ssxx5LcXqadho/lRYLUCDdlNnQp6VM4GiGI0ojvprpCP9WUbWiIGD9fnT2qvxf7Aw== X-Received: by 2002:a63:794:: with SMTP id 142mr26785898pgh.187.1608779353843; Wed, 23 Dec 2020 19:09:13 -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 cu4sm889005pjb.18.2020.12.23.19.09.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Dec 2020 19:09:12 -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: Date: Wed, 23 Dec 2020 19:09:10 -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: <3A6A1049-24C6-4B2D-8C59-21B549F742B4@gmail.com> References: 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 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). I think there are other cases in which Andy=E2=80=99s concern is = relevant (MADV_PAGEOUT). 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. 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.