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 9736EC433E6 for ; Tue, 5 Jan 2021 18:41:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1562F22D04 for ; Tue, 5 Jan 2021 18:41:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1562F22D04 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 5A22F8D0097; Tue, 5 Jan 2021 13:41:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 52AA88D0095; Tue, 5 Jan 2021 13:41:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41B268D0097; Tue, 5 Jan 2021 13:41:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 266D88D0095 for ; Tue, 5 Jan 2021 13:41:42 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D091D181AEF09 for ; Tue, 5 Jan 2021 18:41:41 +0000 (UTC) X-FDA: 77672590002.09.roof21_3f0aac3274db Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id C6D49180AD80F for ; Tue, 5 Jan 2021 18:41:40 +0000 (UTC) X-HE-Tag: roof21_3f0aac3274db X-Filterd-Recvd-Size: 5695 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 5 Jan 2021 18:41:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609872099; 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=EwI51oteB1zNcM5usbv0yXWNl7lwzAeC8ISFtsCGyIc=; b=MLteRMHXSEZiPmJ6pun3hqTxqD8yonyL5u9W05ZMTenFWhjCCK7VrUzoYQSh8oc0GN748d 45wpXkGngX+CTQoFB+hgtmWbC2suyUC3QYbEgND1iC1R3Z7yZ4lOYthGXxEobeob9Ubjft RblfbXG1m5jonXRHfuXWQo6cr0HbRSk= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-156-QFNAlCB9NlSAN4QVNDP2Aw-1; Tue, 05 Jan 2021 13:41:37 -0500 X-MC-Unique: QFNAlCB9NlSAN4QVNDP2Aw-1 Received: by mail-qk1-f197.google.com with SMTP id i82so523156qke.19 for ; Tue, 05 Jan 2021 10:41:37 -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=EwI51oteB1zNcM5usbv0yXWNl7lwzAeC8ISFtsCGyIc=; b=H2/D2Xl2u4ws71OpNlad/NWOYVwAjIj3ncbsACbBOaS9dgPyreuxGHSFr+QuzrZcE0 qq9nlVVoh0+5C6t+bEWjSMy+FQrSr73eT6rbj7SZiqE4a4cWpxJyGMwK63SpCGJTPou0 maodIWJ6GcYcT3w8derdTUTV7Jfy2hx/Uc89EJT5naayccr9gf7KiL2eVQJkJ/O8Mim8 PFu7XwVGn0et0rA2wAkOOfO30mJ8orfrbxWlrBrGXDYOJ+Ynk+C3wSwI+2d7wtXthrE+ W7XlwRbZ4Q4qJOEfaHp3euLSfNFGeST8+O9eVFdgq8oTJgXjZram9sGYNgrqcPaJVuXD dyyQ== X-Gm-Message-State: AOAM531ve/yPgYhIExdl5HSfEyh5x7/d4vbIqUP9fhe5+L7ZnSOuIa5i IK8tplaeH2ymfsjkOyRRGdTvusmjSljp0AkvR6zuLt66UYzdp6k2TWP1l+P8MfkLyQtbj08zbOH /zBf+BKQ0+YM= X-Received: by 2002:ac8:5b82:: with SMTP id a2mr788422qta.215.1609872096993; Tue, 05 Jan 2021 10:41:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9YFOrmm19T6QEMieBtVD2lNz6D99wYK0l0XUh/rbEAdM+XNbc0QrqMNjgU4em6as+taSqqw== X-Received: by 2002:ac8:5b82:: with SMTP id a2mr788401qta.215.1609872096643; Tue, 05 Jan 2021 10:41:36 -0800 (PST) Received: from xz-x1 ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id d2sm365817qtp.71.2021.01.05.10.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 10:41:35 -0800 (PST) Date: Tue, 5 Jan 2021 13:41:34 -0500 From: Peter Xu To: Andrea Arcangeli Cc: Nadav Amit , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nadav Amit , 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: <20210105184134.GD149908@xz-x1> References: <20201225092529.3228466-1-namit@vmware.com> <20201225092529.3228466-2-namit@vmware.com> <20210105150813.GB149908@xz-x1> MIME-Version: 1.0 In-Reply-To: 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 01:08:48PM -0500, Andrea Arcangeli wrote: > On Tue, Jan 05, 2021 at 10:08:13AM -0500, 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; > > I posted the exact same code before seeing the above so I take it as a good > sign :). I'd suggest to add the reverse check to the uffd_wp too. Agreed. I didn't mention uffd_wp check (which I actually mentioned in the reply to v1 patchset) here only because the uffd_wp check is pure optimization; while the uffd_wp_resolve check is more critical because it is potentially a fix of similar tlb flushing issue where we could have demoted the pte without being noticed, so I think it's indeed more important as Nadav wanted to fix in the same patch. It would be even nicer if we have both covered (all of them can be in unlikely() as Andrea suggested in the other email), then maybe nicer as a standalone patch, then mention about the difference of the two in the commit log (majorly, the resolving change will be more than optimization). Thanks, -- Peter Xu