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=-13.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 EC194C433E0 for ; Wed, 23 Dec 2020 00:24:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A838922A83 for ; Wed, 23 Dec 2020 00:24:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726361AbgLWAYZ (ORCPT ); Tue, 22 Dec 2020 19:24:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbgLWAYZ (ORCPT ); Tue, 22 Dec 2020 19:24:25 -0500 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06375C0613D6 for ; Tue, 22 Dec 2020 16:23:45 -0800 (PST) Received: by mail-il1-x12f.google.com with SMTP id q1so13567386ilt.6 for ; Tue, 22 Dec 2020 16:23:44 -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:in-reply-to; bh=zPVUyN0X2UaL/Rf0O3PrEWZ3gBNDq2ynrHr8/vpcWJw=; b=I5zPqBlWm/SLmDdOaoYaeHfuhH0ps9HdFKks+nISg5vlCt9Tou8OEjurUZN9h7YKqD XHTk1YJFEcHfyd3wXn7lrxj/vAcOLoKhcuFssd2zzXB8TTHdR56+2p/JzIYmUFLg+u4w nTJokCzMmzI4xioWPxVkgwJrTsJCnR7civiuosDvLxdKRomoJItfF+XkBZsM6qpp7kmO fKgphZK1yPNJqfrm4qgZfKjTG1+aqoB7xdxch5HO/4JWXbwToK4V2GxcYOyxOLONFw9/ Bs7jNsyy6e7B9caoKNZ9RqO0cJc3DBxGhk/3HOYBQEYU6ualqWblfc/XotI4GarIdtNW Z+cA== 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:in-reply-to; bh=zPVUyN0X2UaL/Rf0O3PrEWZ3gBNDq2ynrHr8/vpcWJw=; b=JAJlhTukP7JDCwoI9JAC4hgWKrDKG4RJmLJT1T4CqbU7po8NJM0X/u1ysSjTZRj1Wi 6riK5TTJuT8nZbDvOxB7xjlwH2m2VAeXhdmbjc7xIm4YXZGxgE2sOjy8gm64MPCQ4Ckz 5AA6Iv7IbNiqoniP+cUKnUQDeYzNo6ABjnYYIExOQq1E79fUOS+bIihHuN+ClEtVTK/l edFcKv8E1uX4qme9MFpIsfBSG1MnXm9S1oApnaulZep+utLl1tb45MJ7o850X3xgL4V+ gI3OJ/O21ak4tRaE0VZlrU4qujsc+HGUJQsPNDRBylfE6NLI/GTBXefqqhsinpYcml2e o1ng== X-Gm-Message-State: AOAM530LuwZknPhOgyD8luxkEboKzzYBYWZ3z28SyGbC2MulS/Cn1r/a 02DWBai973iAKGf+vEcYIqpg0w== X-Google-Smtp-Source: ABdhPJwIW6Ug/4l5H12+ASCnorvrI2VqBgDLkKUaNWjzv9o3noKby3TerJHlKeOOkng7DJkb+zL4nQ== X-Received: by 2002:a92:d8d1:: with SMTP id l17mr22668025ilo.99.1608683024177; Tue, 22 Dec 2020 16:23:44 -0800 (PST) Received: from google.com ([2620:15c:183:200:7220:84ff:fe09:2d90]) by smtp.gmail.com with ESMTPSA id c2sm16996894ila.71.2020.12.22.16.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Dec 2020 16:23:43 -0800 (PST) Date: Tue, 22 Dec 2020 17:23:39 -0700 From: Yu Zhao To: Linus Torvalds Cc: Andrea Arcangeli , Andy Lutomirski , Peter Xu , Nadav Amit , 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: <1FCC8F93-FF29-44D3-A73A-DF943D056680@gmail.com> <20201221223041.GL6640@xz-x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 22, 2020 at 04:01:45PM -0800, Linus Torvalds wrote: > On Tue, Dec 22, 2020 at 3:50 PM Linus Torvalds > wrote: > > > > See zap_pte_range() for an example of doing it right, even in the > > presence of complexities (ie that has an example of both flushing the > > TLB, and doing the actual "free the pages after flush", and it does > > the two cases separately). > > The more I look at the mprotect code, the less I like it. We seem to > be much better about the TLB flushes in other places (looking at > mremap, for example). The mprotect code seems to be very laissez-faire > about the TLB flushing. > > Does adding a TLB flush to before that > > pte_unmap_unlock(pte - 1, ptl); > > fix things for you? It definitely does. But if I had to choose, I'd go with holding mmap_lock for write because 1) it's less likely to storm other CPUs by IPI and would only have performance impact on processes that use ufd, which I guess already have high tolerance for not-so-good performance, and 2) people are spearheading multiple efforts to reduce the mmap_lock contention, which hopefully would make ufd users suffer less soon. > That's not the right fix - leaving a stale TLB entry around is fine if > the TLB entry is more strict wrt protections - but it might be worth > testing as a "does it at least close the problem" patch. Well, things get trick if we do this. I'm not sure if I could vouch such a fix for stable as confident as I do holding mmap_lock for write.