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=-11.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 D5788C433DB for ; Tue, 5 Jan 2021 19:43:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6758D22D72 for ; Tue, 5 Jan 2021 19:43:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6758D22D72 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C3B188D00A9; Tue, 5 Jan 2021 14:43:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BEAAF8D006E; Tue, 5 Jan 2021 14:43:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B00BE8D00A9; Tue, 5 Jan 2021 14:43:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id 9BFBB8D006E for ; Tue, 5 Jan 2021 14:43:36 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 66D54181AEF10 for ; Tue, 5 Jan 2021 19:43:36 +0000 (UTC) X-FDA: 77672746032.08.kiss83_0605a97274db Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 4A4F01819E764 for ; Tue, 5 Jan 2021 19:43:36 +0000 (UTC) X-HE-Tag: kiss83_0605a97274db X-Filterd-Recvd-Size: 5978 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 5 Jan 2021 19:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609875815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JyQ8Yx6ecRcdkus2Q+iowXLy4MC41M17PpJ0LhrHNpk=; b=WpWqQeJDMXbxFrQx0/bEDz3gvNPenzltL3bACLRoCiUYPEQjgJLbem2XcWyGdNpqlwiA1/ ChfI2zcJ0ja1qI+rJbJ2YKUo9b5P6lpwD2Z1gUKoHKqw723HzXSrmLLoulCPoZDDGg+Mt7 xtTPnknwTUebxzcaVCJ2/Im/W1JDCgw= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-578-2swzZ01aMTqjswD4LJ7Yiw-1; Tue, 05 Jan 2021 14:43:33 -0500 X-MC-Unique: 2swzZ01aMTqjswD4LJ7Yiw-1 Received: by mail-qk1-f198.google.com with SMTP id g5so642292qke.22 for ; Tue, 05 Jan 2021 11:43:32 -0800 (PST) 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=JyQ8Yx6ecRcdkus2Q+iowXLy4MC41M17PpJ0LhrHNpk=; b=DRccCRY1mZa614dMACbPPGOeQAbn9CamIAJVVVkgEdl6bnQsFtyGmHVfEGiRREi5ZN Gz3O6HAXZ7TBQZhOPkqB1Z8OrwIszYthDuow7IkP8WcJHtkI7xUcWlZmQKT+OxOeycrN aUyzLEZ7wxL0E1GGTIazSO5wCDJluVFls5Uq+/lcxtbmkDm17mQs5g6RzSTtKST3DB8i sk/ymwI5NpyYzkaavGfUpN7dVO5FDs9vmFatBO/v4WZOzgT0A7AolpiXYss3207gz5OP WzdOYdK0YmXwAp97m1fnKM8vGlk62/I/jTFr1JY6VEysvqFYgsQS3YF4VZcFtgSoK0Wx 8nDw== X-Gm-Message-State: AOAM531Hs07tOm5Oa5KmbDUWgKBe1Fa4dr5fiE8I5GxjuAt3vX/UVkP+ rhgt1c8/Y+JyLTpKNe8CCy/54+MUPev3h9t5c0pbJb/V2AsNEp0WbUzjA7FagYUFa/FZD6Lsz7o +a7S44Jvbmfs= X-Received: by 2002:a05:6214:4c7:: with SMTP id ck7mr1111271qvb.7.1609875812203; Tue, 05 Jan 2021 11:43:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyekDcfWUxGQnFBPKSLKN8PBvaWikC0raWQa6ze3medUNTdPRfPM8cyuocGWhnfMQ4ih8L1zQ== X-Received: by 2002:a05:6214:4c7:: with SMTP id ck7mr1111250qvb.7.1609875811957; Tue, 05 Jan 2021 11:43:31 -0800 (PST) Received: from xz-x1 ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id w8sm36806qts.50.2021.01.05.11.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 11:43:31 -0800 (PST) Date: Tue, 5 Jan 2021 14:43:29 -0500 From: Peter Xu To: Nadav Amit Cc: linux-mm , lkml , Andrea Arcangeli , Yu Zhao , Andy Lutomirski , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , Minchan Kim , Will Deacon , Peter Zijlstra Subject: Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect Message-ID: <20210105194329.GF149908@xz-x1> References: <20201225092529.3228466-1-namit@vmware.com> <20201225092529.3228466-2-namit@vmware.com> <20210105150813.GB149908@xz-x1> <070CFD88-57A0-40FF-9614-6ED47B214301@vmware.com> MIME-Version: 1.0 In-Reply-To: <070CFD88-57A0-40FF-9614-6ED47B214301@vmware.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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, Jan 05, 2021 at 07:07:51PM +0000, Nadav Amit wrote: > > On Jan 5, 2021, at 7:08 AM, Peter Xu wrote: > > > > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > >> diff --git a/mm/mprotect.c b/mm/mprotect.c > >> index ab709023e9aa..c08c4055b051 100644 > >> --- a/mm/mprotect.c > >> +++ b/mm/mprotect.c > >> @@ -75,7 +75,8 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, > >> oldpte = *pte; > >> if (pte_present(oldpte)) { > >> pte_t ptent; > >> - bool preserve_write = prot_numa && pte_write(oldpte); > >> + bool preserve_write = (prot_numa || uffd_wp_resolve) && > >> + pte_write(oldpte); > > > > Irrelevant of the other tlb issue, this is a standalone one and I commented in > > v1 about simply ignore the change if necessary; unluckily that seems to be > > ignored.. so I'll try again - would below be slightly better? > > > > if (uffd_wp_resolve && !pte_uffd_wp(oldpte)) > > continue; > > > > Firstly, current patch is confusing at least to me, because "uffd_wp_resolve" > > means "unprotect the pte", whose write bit should mostly be cleared already > > when uffd_wp_resolve is applicable. Then "preserve_write" for that pte looks > > odd already. > > > > Meanwhile, if that really happens (when pte write bit set, but during a > > uffd_wp_resolve request) imho there is really nothing we can do, so we should > > simply avoid touching that at all, and also avoid ptep_modify_prot_start, > > pte_modify, ptep_modify_prot_commit, calls etc., which takes extra cost. > > Sorry for missing your feedback before. What you suggest makes perfect > sense. No problem. I actually appreciated a lot for all your great works on these. The strange thing is the userfaultfd kselftest seems to be working always fine locally to me (probably another reason that I mostly test uffd-wp with umapsort), so I won't be able to reproduce some issue you (and Andrea) have encountered. It's great you unveiled all these hard tlb problems and nailed them down so lives should be easier for all of us. Thanks, -- Peter Xu