From patchwork Tue Jul 20 15:56:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12388737 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=-15.2 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,URIBL_BLOCKED, USER_AGENT_GIT 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 35DA6C636C8 for ; Tue, 20 Jul 2021 15:57:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA1A96113B for ; Tue, 20 Jul 2021 15:57:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA1A96113B 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 CBC8C6B0036; Tue, 20 Jul 2021 11:57:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C89466B005D; Tue, 20 Jul 2021 11:57:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B29F56B006C; Tue, 20 Jul 2021 11:57:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id 8DEFE6B0036 for ; Tue, 20 Jul 2021 11:57:07 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1FBAB22BF0 for ; Tue, 20 Jul 2021 15:57:06 +0000 (UTC) X-FDA: 78383420052.08.F9B9828 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 9E80B70009F2 for ; Tue, 20 Jul 2021 15:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626796625; 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=RrmE2OcblZLr/e4Eexjc5JVjcsj9lLbrbn7aAaKUXPI=; b=Y1NrJQERl9eRBg6zJuTKC5RbXp9R1dPvewhoNa9EIb8mBVRYCOs6YhdjG3dFNqAODPTQlw UDl6mre+83cgzdQwVDtzj39h0Mb/jSWW57nqHDpbzAxCiBLfKEOLMgWrf3MnIcfUchSm5T L6jXxzF2+aP73sO503CI+BsgdFg/J+o= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-534-jC1T9yMYOzeUGQLg9PbuaA-1; Tue, 20 Jul 2021 11:57:01 -0400 X-MC-Unique: jC1T9yMYOzeUGQLg9PbuaA-1 Received: by mail-qt1-f199.google.com with SMTP id j16-20020ac855100000b029025bf786be09so12726020qtq.20 for ; Tue, 20 Jul 2021 08:57:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Lwb/S+J+gslC2Y28b3P4zMlQmindrrr+LZzI9LinPc=; b=tMxFFQvrUVOMN9zyTW5Cj9MegcCjAOaBXTsrU3UqxUSt37EvM6z7e0r3MHddfm+KsR +kAu8Y+EGfxSCWUgoPlSLtob6xcXjXS+nbum3sSS4acf7U2p7Htl+1GIV7g5aqruLmNH w0NWA3eP6T8v7xknwmfnFQcxqD2sQxCm3/aAYmY2nCNTUikVEFYS1mflEBUZXW6i+G0q bBuDzA/vYf9TrR2wbLNcFBhDzDha1xhHE03nTuYNRpQvgDor3wugOZ55rsbI02bpLpc1 f2dx4OmbmxYu18g2KMJ/hUryPVypGe0s2NloNngEXTaSCk1fYhYR8ERCQ15X/Bcc1f9o FQcw== X-Gm-Message-State: AOAM5306tu+wiv/fddyEUtWWa0AsR31skzsPuEneGRAA7xWJpRU2aEW9 4Cys8nKS1o/fwcRHyxhGAvU/hcchrW/3FhpSnaqug0rTpsRc+jkURxN+JyQTC7LAtWlVCXNWgzn 2vy2tQm2Igmo= X-Received: by 2002:ac8:5ac3:: with SMTP id d3mr27100965qtd.257.1626796621454; Tue, 20 Jul 2021 08:57:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE0JZxI8C6H+JP4haDAXSMgAMN5qTlpp01szfWOjLU+DL8S7l+xGlXl6hHUCHSo3cqzozHRQ== X-Received: by 2002:ac8:5ac3:: with SMTP id d3mr27100943qtd.257.1626796621218; Tue, 20 Jul 2021 08:57:01 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id 74sm5298585qkh.42.2021.07.20.08.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 08:57:00 -0700 (PDT) From: Peter Xu To: stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Igor Raits , peterx@redhat.com, Hillf Danton , Axel Rasmussen , Hugh Dickins , Andrew Morton Subject: [PATCH stable 5.10.y 0/2] mm/thp: Fix uffd-wp with fork(); crash on pmd migration entry on fork Date: Tue, 20 Jul 2021 11:56:55 -0400 Message-Id: <20210720155657.499127-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <796cbb7-5a1c-1ba0-dde5-479aba8224f2@google.com> References: <796cbb7-5a1c-1ba0-dde5-479aba8224f2@google.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9E80B70009F2 X-Stat-Signature: ke8cgf518wtmgy6chggfij1ypm1bricy Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y1NrJQER; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf27.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-HE-Tag: 1626796625-884942 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000602, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In summary, this series should be needed for 5.10/5.12/5.13. This is the 5.10.y backport of the series. Patch 1 is a dependency of patch 2, while patch 2 should be the real fix. There's a minor conflict on patch 2 when cherry pick due to not having the new helper called page_needs_cow_for_dma(). It's also mentioned at the entry of patch 2. This series should be able to fix a rare race that mentioned in thread: https://lore.kernel.org/linux-mm/796cbb7-5a1c-1ba0-dde5-479aba8224f2@google.com/ This fact wasn't discovered when the fix got proposed and merged, because the fix was originally about uffd-wp and its fork event. However it turns out that the problematic commit b569a1760782f3d is also causing crashing on fork() of pmd migration entries which is even more severe than the original uffd-wp problem. Stable kernels at least on 5.12.y has the crash reproduced, and it's possible 5.13.y and 5.10.y could hit it due to having the problematic commit b569a1760782f3d but lacking of the uffd-wp fix patch (8f34f1eac382, which is also patch 2 of this series). The pmd entry crash problem was reported by Igor Raits and debugged by Hugh Dickins . Please review, thanks. Peter Xu (2): mm/thp: simplify copying of huge zero page pmd when fork mm/userfaultfd: fix uffd-wp special cases for fork() include/linux/huge_mm.h | 2 +- include/linux/swapops.h | 2 ++ mm/huge_memory.c | 36 +++++++++++++++++------------------- mm/memory.c | 25 +++++++++++++------------ 4 files changed, 33 insertions(+), 32 deletions(-)