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 6721DC433DB for ; Wed, 23 Dec 2020 00:23:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ECC7422AAC for ; Wed, 23 Dec 2020 00:23:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ECC7422AAC 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 0B45F6B0068; Tue, 22 Dec 2020 19:23:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 04E706B00A1; Tue, 22 Dec 2020 19:23:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7F486B00A2; Tue, 22 Dec 2020 19:23:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id CF9086B009F for ; Tue, 22 Dec 2020 19:23:45 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8E78D180AD830 for ; Wed, 23 Dec 2020 00:23:45 +0000 (UTC) X-FDA: 77622648810.13.water92_27025ad27464 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 7064318140B7B for ; Wed, 23 Dec 2020 00:23:45 +0000 (UTC) X-HE-Tag: water92_27025ad27464 X-Filterd-Recvd-Size: 5326 Received: from mail-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.171]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Dec 2020 00:23:44 +0000 (UTC) Received: by mail-il1-f171.google.com with SMTP id g1so13567465ilk.7 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=hsUfv/hNxcQYqnE0DegRXXG0bh9Cas9lTG0q6d8pox+/RX6oGGhyjmwb3cg9Nu1GVJ quO5L7D4oe+eWQKd3jX18hNj82+dpT3DZsEKGZIL+kIEaOE16KB3gdOjRQKi6y2yKV4j tBIz7rf6Wzuf7PPkS4nTIuQI6hhEPSEAerxX9nNUX/6H3HXHKQ6X1xpCUNDMrLsbJwfA 56awpHFJrwpCnanqszY/4ivYf0QvWVXwckwSuNGddBzyq3S+t4r63nvZUarRL+e+DYW/ Irh3yhfDbYD4HPYXPKtQQF7AqrsvYe9bC9aku6OhLvXit4qDZinJnG0s7GexCLFAayNr Uslg== X-Gm-Message-State: AOAM533gb9EW8vuTvzSY4mYWAFaei/30MFS6umH34TV6DpafH/5n7k93 aiMj1OREk42VyrFzPwsy/RLiUQ== 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: 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 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.