Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7343117rwb; Tue, 15 Nov 2022 10:48:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf4vw0roY610dzBPNmGqXiwITFHWyrRNZPntzEPjjxo/8KgeD8nVqImlZNATgN5pnCjVZdqE X-Received: by 2002:a63:d4f:0:b0:470:7b17:2215 with SMTP id 15-20020a630d4f000000b004707b172215mr17322166pgn.94.1668538101599; Tue, 15 Nov 2022 10:48:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668538101; cv=none; d=google.com; s=arc-20160816; b=yVP8T6YYh4df4RFVWXqS0t3l7zYCsKWwnKE5MakXoj435LXErTVUAAsYlw3161L4zw FtJsRIfclLR3waw0fP+hrT/KNFJy/PQc+49FD0CTlAiLMc2KixXW4EywlI7YiBcERW2L Xct4UjJoK5yR0SjVxBlQahW6wAiEYQjnEbdQ4ilelzFCuIKixAJANPHSqvTH5rdkokKP 8YSYxfDfVaHfuTEUf+FwJU8tblM4sryy4tTCRmKNtYrdkFFF1OdgM+uod70Eo8mCG6fD /MtfdMCNC0PQdVixrtKwRsUrzWfkRVQY/dX4SqL6T48V4w1YkItANvGFTPuOq/5brgFa dZMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=zM9NVAiHgjBvRccxutMAlz4UOKHMx1Iq+kM6b0m0gaI=; b=nhMq4/cmEhsGo+W8552CjcsNGoQInZKcpnPZFlKyo6bSpm8TV7szNFdJJHX8fMMwxP ZpHfs6oTLPT/9pvlkpxJQQG7wxfvpsZfj4AJJSlUyxqSySCckKYB0TkxfKcjZqSkHtzj Dn2vrAOhD1r30c3+TcDNn+v81vlN0N+bQRGVpzFBpvOnoAWMP+ZEQPyEXRBQvEOlTAum 58j49tkmiJNlD7IQZJxwkpHOE1JKC9oYSLz5fwN43jbHSi2yuvPOJ6dtho2un3CweluP afCivnLsbJ0t/fhPg0LohjwYtt5OF/S0ZuE4EwQJbvWDNWvGCLfZ2PEjkI0qXJzXLgN1 +5HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b7i+rRpK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j18-20020a632312000000b0046f51cbaf53si12814163pgj.529.2022.11.15.10.48.09; Tue, 15 Nov 2022 10:48:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b7i+rRpK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231268AbiKOSSp (ORCPT + 90 others); Tue, 15 Nov 2022 13:18:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbiKOSSn (ORCPT ); Tue, 15 Nov 2022 13:18:43 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F8B92FC25 for ; Tue, 15 Nov 2022 10:17:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668536267; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zM9NVAiHgjBvRccxutMAlz4UOKHMx1Iq+kM6b0m0gaI=; b=b7i+rRpK0fHQOs4humFDMLHL75Js0Ex2cCe8140CvarSn4q4XyMRCXmceLGCesFI+uh0M1 nQuS2QLtOHbAVwGlseupPGcaN+i2jm8YDxM+W2GiS+IiY77p3/sdn+apLU3eoKzPIYeeID K//La77kciverlKmP2nfrICzUl9SUAY= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-527-Xe-okTiRNR-nclKXrxPJZQ-1; Tue, 15 Nov 2022 13:17:46 -0500 X-MC-Unique: Xe-okTiRNR-nclKXrxPJZQ-1 Received: by mail-wm1-f69.google.com with SMTP id az40-20020a05600c602800b003cfa26c40easo1031284wmb.1 for ; Tue, 15 Nov 2022 10:17:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zM9NVAiHgjBvRccxutMAlz4UOKHMx1Iq+kM6b0m0gaI=; b=T6b7UTQnm393EyyjLf+Ptiq/+vnB352aXq6waA5PAX73NC1MuSIB73sJhU3nFu8O0U iUh4/Dbz9eBoZ+vnbjH7AQL0+Xj93yzzpSGhYG4V5i5ceQ3FazPtEzi5TuTPD2sTQC6k 13uGGFB4HsAtlkB+T8L0pbwfMdUg0aKBDRhhGco9nhbE3Y6xEwcmJqAvglbDmhl7Xf8r WdJ3T3aM/6g3lfBGA1nwGG6njv7mlikYRsJCcwP0eV7g6cjodhaWNfXvH7gKRfou7Zxs qQrPal2S64DzCOup9+TwpHlHuXU4nWXB14JV3CMnz5iFn2k0jzkPevfFimONQUsKLnYf Ph5w== X-Gm-Message-State: ANoB5pk/gi+s4cKe4L3ZlmAvtJAKx/kDaZl7RncUTU/j2+ib3NTJwakW 081zMKOKPjUiADmfu/xS3IrFxgzgIAum7Ega6trpNjcOKXvKJ+gy2SoiguLF+9V8wuRfg3nAY00 ZgyKcP8dYYnFFD0/o+5JVEjn1 X-Received: by 2002:a05:600c:4f06:b0:3cf:a323:bfe6 with SMTP id l6-20020a05600c4f0600b003cfa323bfe6mr2434587wmq.86.1668536265078; Tue, 15 Nov 2022 10:17:45 -0800 (PST) X-Received: by 2002:a05:600c:4f06:b0:3cf:a323:bfe6 with SMTP id l6-20020a05600c4f0600b003cfa323bfe6mr2434558wmq.86.1668536264756; Tue, 15 Nov 2022 10:17:44 -0800 (PST) Received: from ?IPV6:2003:cb:c707:9d00:9303:90ce:6dcb:2bc9? (p200300cbc7079d00930390ce6dcb2bc9.dip0.t-ipconnect.de. [2003:cb:c707:9d00:9303:90ce:6dcb:2bc9]) by smtp.gmail.com with ESMTPSA id x11-20020a5d54cb000000b002415dd45320sm12973262wrv.112.2022.11.15.10.17.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 10:17:44 -0800 (PST) Message-ID: <5ddf1310-b49f-6e66-a22a-6de361602558@redhat.com> Date: Tue, 15 Nov 2022 19:17:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH v3 1/2] mm/migrate: Fix read-only page got writable when recover pte Content-Language: en-US To: Peter Xu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Rapoport , Nadav Amit , Andrew Morton , Andrea Arcangeli , Ives van Hoorne , Axel Rasmussen , Alistair Popple , stable@vger.kernel.org References: <20221114000447.1681003-1-peterx@redhat.com> <20221114000447.1681003-2-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20221114000447.1681003-2-peterx@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14.11.22 01:04, Peter Xu wrote: > Ives van Hoorne from codesandbox.io reported an issue regarding possible > data loss of uffd-wp when applied to memfds on heavily loaded systems. The > symptom is some read page got data mismatch from the snapshot child VMs. > > Here I can also reproduce with a Rust reproducer that was provided by Ives > that keeps taking snapshot of a 256MB VM, on a 32G system when I initiate > 80 instances I can trigger the issues in ten minutes. > > It turns out that we got some pages write-through even if uffd-wp is > applied to the pte. > > The problem is, when removing migration entries, we didn't really worry > about write bit as long as we know it's not a write migration entry. That > may not be true, for some memory types (e.g. writable shmem) mk_pte can > return a pte with write bit set, then to recover the migration entry to its > original state we need to explicit wr-protect the pte or it'll has the > write bit set if it's a read migration entry. For uffd it can cause > write-through. > > The relevant code on uffd was introduced in the anon support, which is > commit f45ec5ff16a7 ("userfaultfd: wp: support swap and page migration", > 2020-04-07). However anon shouldn't suffer from this problem because anon > should already have the write bit cleared always, so that may not be a > proper Fixes target, while I'm adding the Fixes to be uffd shmem support. > > Cc: Andrea Arcangeli > Cc: stable@vger.kernel.org > Fixes: b1f9e876862d ("mm/uffd: enable write protection for shmem & hugetlbfs") > Reported-by: Ives van Hoorne > Reviewed-by: Alistair Popple > Tested-by: Ives van Hoorne > Signed-off-by: Peter Xu > --- > mm/migrate.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index dff333593a8a..8b6351c08c78 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -213,8 +213,14 @@ static bool remove_migration_pte(struct folio *folio, > pte = pte_mkdirty(pte); > if (is_writable_migration_entry(entry)) > pte = maybe_mkwrite(pte, vma); > - else if (pte_swp_uffd_wp(*pvmw.pte)) > + else > + /* NOTE: mk_pte can have write bit set */ > + pte = pte_wrprotect(pte); > + > + if (pte_swp_uffd_wp(*pvmw.pte)) { > + WARN_ON_ONCE(pte_write(pte)); > pte = pte_mkuffd_wp(pte); > + } > > if (folio_test_anon(folio) && !is_readable_migration_entry(entry)) > rmap_flags |= RMAP_EXCLUSIVE; As raised, I don't agree to this generic non-uffd-wp change without further, clear justification. I won't nack it, but I won't ack it either. -- Thanks, David / dhildenb