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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79CB0C433FE for ; Tue, 15 Nov 2022 18:17:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 040F46B0071; Tue, 15 Nov 2022 13:17:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F33E96B0072; Tue, 15 Nov 2022 13:17:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD4DC6B0073; Tue, 15 Nov 2022 13:17:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CE40F6B0071 for ; Tue, 15 Nov 2022 13:17:51 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9CB321C5F49 for ; Tue, 15 Nov 2022 18:17:51 +0000 (UTC) X-FDA: 80136485142.22.7766A52 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 2CEE34000D for ; Tue, 15 Nov 2022 18:17:47 +0000 (UTC) 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-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-299-gXJPCIfBNcu68fumUpALXg-1; Tue, 15 Nov 2022 13:17:46 -0500 X-MC-Unique: gXJPCIfBNcu68fumUpALXg-1 Received: by mail-wr1-f72.google.com with SMTP id i12-20020adfaacc000000b0023cd08e3b56so3065744wrc.12 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=DnRKkx2YtpqBdsvWdQcfuW+o3Pk5NckvstCRO1IpXupDcmxjqpLOPeepeEtoYmxctU rj+SLhybF1aveaONHnxpVRbg0Cbe3Xee9LchBjW5x7QNXrGP/+JJpETCgBxFO+efUQRb iHXNVZ7vpSKB9GyCwRKOzTgx4kGeOwnhLYL4cipDO83AOZNAFHuQ5WDudqcXVCPGmvz0 C0zK/ULfJxKaDv997aG62opNhqallBJqhQ4xr9ldZWaALTgivMWoALJZtpx97hXvvPty MXQccCGJeaH98G7MavaB0USx8em0y0+eyVBi6bpLTA0xDgZ0237+F4t4gkuNLIc1ymWe iy0g== X-Gm-Message-State: ANoB5pkQwsUpHPCP5mkk+KX+XAtC63tuVd0/fQuY2wr/3yb62dLoPH0f EDroT6GeC0QeebEoxKByhP/1lRM3FVjMJL55o5GC6UYH+66Lw91Jxo5CVDE3vQzXWt3XFXsK3rI dWuPjUpheAl8= X-Received: by 2002:a05:600c:4f06:b0:3cf:a323:bfe6 with SMTP id l6-20020a05600c4f0600b003cfa323bfe6mr2434577wmq.86.1668536265068; Tue, 15 Nov 2022 10:17:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf6FRbcS4vsa5azpDI/ImCO2GqAsz5ThBO9bUYJE/LjiknvN5Mt9qC3X8dURVYSCU/NMeS3Wdw== 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 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> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668536268; a=rsa-sha256; cv=none; b=2JOQY6FdBHydxcFC/Rn/Kh77DxZWizz97apAqo7RzBxLo6UDMSf5k6xhPE9MVyT8Y28dGR a/K+NIgXmxgiqp88v8XzF6Do+t1yGDD3NFZX4xs3IKDx3WlkTWCZgVzqKgoHGYv2xF8lFx IfPvZIThSrxZeXplvpTLh+VP0npSJXg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=b7i+rRpK; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668536268; h=from:from:sender: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:dkim-signature; bh=zM9NVAiHgjBvRccxutMAlz4UOKHMx1Iq+kM6b0m0gaI=; b=E1mXbaanGChE6oe4lCp4epknGiOkSwP8hKmwB8ow4CIJ4d4/KDnLL0tDsEU1qMIBvpbixk TgMdW4Y6+L6pKF0RRR0lKcSgNIs3uDYNotvi176MCOmtXffXxtO65N7sUNLe4+3coequ0R BZlsGyeFjjKxRD/jSPcfHm7HG4hMOSE= X-Rspam-User: X-Stat-Signature: mik4j1gxo9tf9jkrdjpn7cwusxxdka9k X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2CEE34000D Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=b7i+rRpK; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1668536267-356909 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 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