From patchwork Thu Feb 16 15:30:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13143383 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 8C960C636CC for ; Thu, 16 Feb 2023 15:31:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6C146B0071; Thu, 16 Feb 2023 10:31:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E1C176B0072; Thu, 16 Feb 2023 10:31:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBCCE6B0074; Thu, 16 Feb 2023 10:31:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B7E206B0071 for ; Thu, 16 Feb 2023 10:31:11 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8AD8E1411D3 for ; Thu, 16 Feb 2023 15:31:11 +0000 (UTC) X-FDA: 80473543542.29.79CA5BC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 6664B2003A for ; Thu, 16 Feb 2023 15:31:08 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LodzfAkR; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1676561468; 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: references:dkim-signature; bh=K37os/T782c+Ji/0fbHlVEJWHAsVkYLkQoth8fPzQm4=; b=GYvOPHY4lDItBXwKs9Bj2NmCT0TrSiJaH3CeDFEf0B7TZjIHtc01P6j3uknf9rrNLkiNEv DfdxFIr/CCIep9UvGexDPfyfFk8QX3aj6lYEvC4NLzKB+P9RN0S13Hol0oPW7A3ASAx4BR c3hs1nHwpFUNWV4g6TgmYFmcJkPBFzA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LodzfAkR; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676561468; a=rsa-sha256; cv=none; b=iOxao1FPTOqB+Pe8gXAs9YG8vEdgL87/rgIbWmsjUfBziPy4ViEuscv7IRgIyZpy5n9jcM Vj4rmZtHHh7SSVTf5OVttnn76Ldpj+0pxWdN/ctUdLuP3Nl2wgXHyFvpKhS79SnB+m3jzq uk8ONSV3enouxYbT6r7cJcam7YnDsdw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676561467; 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; bh=K37os/T782c+Ji/0fbHlVEJWHAsVkYLkQoth8fPzQm4=; b=LodzfAkRJvzdIV90hk1whRv78PX6pneor7HilAVCTvTkzh9iruwrrJoC6BH1c6jB3KsH+i +SIen/g9d2D7ERAR///roDo3+MYL3jmTWS9Ta1Pk/nSr2vxnIZZ9SD1U/a0CtwK+ckIcCC H/e3AjP3esyBopaTt9aiK/EBtboeuoU= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-617-ciJbf8uzPkeu70dmqZtRNA-1; Thu, 16 Feb 2023 10:31:06 -0500 X-MC-Unique: ciJbf8uzPkeu70dmqZtRNA-1 Received: by mail-io1-f72.google.com with SMTP id t20-20020a6b5f14000000b007404263f2faso1066336iob.21 for ; Thu, 16 Feb 2023 07:31:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=K37os/T782c+Ji/0fbHlVEJWHAsVkYLkQoth8fPzQm4=; b=Wu3DRzQjguUzZy2znMFAvvOGNU4vvffTLMnHeQ2J6k/MAYrPUsrbFFBYKoFZQadVvE g0Df+XXsBba7g5GdcFsjZ9ocvQMC+8UiK7aYedE4octvm8sjIdcZkUXy/oS0a/bQ5nx6 hRmS6wBwZl4rKFXuwUDjC6YWIBI///LJ0YJ9nTs1/p4BiSxgBvHHWIQwmR/KmfWlk8qt XpFkkL5zv8ldSZP9OwTEt8D+bR3Bzo6wVXl9YZxYFtLZkSEUS/OLgvvSY3RIR2XE7Uzo tX18UlgJrnlUPCy1EHHrJZAhGiciJYVKeCcWCbaw9HGhjN/5VRPVfuz6gBxbLLift07v 8iiA== X-Gm-Message-State: AO0yUKV5is+rPbj/jhusAcvAniuqX83OGL5C+6ruv8RxqHG9/7lA0loY kRGS1kIpqNJSZWWVZmZ66wj8Aboiu1xz7w+B1kdt8HGg6ZFFH+MshYJUaMjF7rQ1XbnwA1xqUhE w7+JGv4D/6rw= X-Received: by 2002:a05:6e02:1d0b:b0:315:29e8:6ef3 with SMTP id i11-20020a056e021d0b00b0031529e86ef3mr5031457ila.2.1676561465808; Thu, 16 Feb 2023 07:31:05 -0800 (PST) X-Google-Smtp-Source: AK7set/LlCcmK92UMfUs1F3JlPSX2iMzBZGJEL2IhKoQ8a21cfzcIzZTZ385IxNhGrfa0Mp8d7Jo9Q== X-Received: by 2002:a05:6e02:1d0b:b0:315:29e8:6ef3 with SMTP id i11-20020a056e021d0b00b0031529e86ef3mr5031443ila.2.1676561465541; Thu, 16 Feb 2023 07:31:05 -0800 (PST) Received: from x1n.redhat.com ([70.30.145.63]) by smtp.gmail.com with ESMTPSA id x11-20020a92060b000000b0031559a28169sm514793ilg.65.2023.02.16.07.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 07:31:05 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , peterx@redhat.com, regressions@leemhuis.info, Nick Bowler Subject: [PATCH] mm/migrate: Fix wrongly apply write bit after mkdirty on sparc64 Date: Thu, 16 Feb 2023 10:30:59 -0500 Message-Id: <20230216153059.256739-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 6664B2003A X-Stat-Signature: 97cngkzb8gu85uhbi4obpyides96q664 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676561468-757187 X-HE-Meta: U2FsdGVkX19TGpT91ev2hslqv6xXv0BoPVywTMqtLLiswO/frheygJa2PMEtENK95iEDGWExZUfLuDick7SZYXhriI1xLxl8DGg8+CUUOVhYoRUinflL30BE2ZiwQrNK2nzdErRirOrZ9OQueJpmAe7hh171TysvzeiLrPEcASHf8llP6MvzyJinsXLzPBlDSrRX5xIV/UtmzU9yqwcBPIdxrCXd9lu9KAsQerNuQyznpIX7fiRtKRtEFOmixApnxrOncRvV0whbjmbrwMtrIYWWix2ks+SLSSXKmnj7mDZWFsMKS7J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yEi3vsK8htMwITgTg6JHHP5JhfaMiPLUPlK8I51kn1obYSnimkVZPl+cRELy0Uzp1uoyYtPslg+AAOJruIPJOk688x+hfk0y9w/SbK46lDPHD6WgKkHSlBMyVljHDclQL74CqhzxY6+7BGl3EzNA8XTws2bUGbhsc/dU+NkjW390My+NkjUV35SQEkRpO7k3TOvBB1+OkdW0IISs2V0fnDMn/pho4X7SfsxJgAZxnY08TEyIZ7VMQo+gYyGzwf+fjQYYmv85HHSZoLsph6McsBX2NA9X1zz9YVFin/zBlZ6J0WzyOhxkmIZlYIQID86WIaOoWc7eIkIqKVCI/3t3nZJZdfNSkm4ZdElff3dYTn4iseH1oUKsoEBM+roj1JWZIiYwEHU= 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: Nick Bowler reported another sparc64 breakage after the young/dirty persistent work for page migration (per "Link:" below). That's after a similar report [2]. It turns out page migration was overlooked, and it wasn't failing before because page migration was not enabled in the initial report test environment. David proposed another way [2] to fix this from sparc64 side, but that patch didn't land somehow. Neither did I check whether there's any other arch that has similar issues. Let's fix it for now as simple as moving the write bit handling to be after dirty, like what we did before. Note: this is based on mm-unstable, because the breakage was since 6.1 and we're at a very late stage of 6.2 (-rc8), so I assume for this specific case we should target this at 6.3. [1] https://lore.kernel.org/all/20221021160603.GA23307@u164.east.ru/ [2] https://lore.kernel.org/all/20221212130213.136267-1-david@redhat.com/ Cc: regressions@leemhuis.info Fixes: 2e3468778dbe ("mm: remember young/dirty bit for page migrations") Link: https://lore.kernel.org/all/CADyTPExpEqaJiMGoV+Z6xVgL50ZoMJg49B10LcZ=8eg19u34BA@mail.gmail.com/ Reported-by: Nick Bowler Tested-by: Nick Bowler Signed-off-by: Peter Xu Acked-by: David Hildenbrand --- mm/huge_memory.c | 6 ++++-- mm/migrate.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 1343a7d88299..4fc43859e59a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3274,8 +3274,6 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new) pmde = mk_huge_pmd(new, READ_ONCE(vma->vm_page_prot)); if (pmd_swp_soft_dirty(*pvmw->pmd)) pmde = pmd_mksoft_dirty(pmde); - if (is_writable_migration_entry(entry)) - pmde = maybe_pmd_mkwrite(pmde, vma); if (pmd_swp_uffd_wp(*pvmw->pmd)) pmde = pmd_mkuffd_wp(pmde); if (!is_migration_entry_young(entry)) @@ -3283,6 +3281,10 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new) /* NOTE: this may contain setting soft-dirty on some archs */ if (PageDirty(new) && is_migration_entry_dirty(entry)) pmde = pmd_mkdirty(pmde); + if (is_writable_migration_entry(entry)) + pmde = maybe_pmd_mkwrite(pmde, vma); + else + pmde = pmd_wrprotect(pmde); if (PageAnon(new)) { rmap_t rmap_flags = RMAP_COMPOUND; diff --git a/mm/migrate.c b/mm/migrate.c index ef68a1aff35c..40c63e77e91f 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -225,6 +225,8 @@ static bool remove_migration_pte(struct folio *folio, pte = maybe_mkwrite(pte, vma); else if (pte_swp_uffd_wp(*pvmw.pte)) pte = pte_mkuffd_wp(pte); + else + pte = pte_wrprotect(pte); if (folio_test_anon(folio) && !is_readable_migration_entry(entry)) rmap_flags |= RMAP_EXCLUSIVE;