From patchwork Tue Apr 11 14:25:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13207670 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 AF3C1C77B6F for ; Tue, 11 Apr 2023 14:25:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 419C528000A; Tue, 11 Apr 2023 10:25:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A398280001; Tue, 11 Apr 2023 10:25:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 243AC28000A; Tue, 11 Apr 2023 10:25:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1436D280001 for ; Tue, 11 Apr 2023 10:25:23 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B9448160E0F for ; Tue, 11 Apr 2023 14:25:22 +0000 (UTC) X-FDA: 80669332884.28.8284ABD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 1A488160017 for ; Tue, 11 Apr 2023 14:25:20 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TldSL37m; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1681223121; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=1ElJXvy3GrdCHxap+2OiSZHKtp+/midD3ZXDx5TNtDM=; b=lGWb/j7RtDv+9imOiE7K6Bn2ZH78cbVO4Ivj129lpeuekTg3cFLM8XTIsD0clQOBRO7YXM /JWLYQPtIEcmsh+V9JWqD7zIdIOSCUa078KAaZQPfTOoV+isucpT8loOqLrTWHQXc6FOdO Hjpcztx7EoJDppPWMy8Qky5zTXzj5lI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TldSL37m; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681223121; a=rsa-sha256; cv=none; b=M9rl5CnQShqt7qkGseho0pN1BJ5Tq8pQ7Z9VsrRxCDbog7A0ZF8GTIHmuIK6PMn3wS1fY+ EWg+PqWFY96Q/OnHeeNTTqXwlba24BsRRq/mNc0itEEgeEYIeB4bWJvyD1uVyoRJIgHyVd EcfDv2dEJth0WLjLjyXL78Piv+wK2AQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681223120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=1ElJXvy3GrdCHxap+2OiSZHKtp+/midD3ZXDx5TNtDM=; b=TldSL37mQif+k5HTAynacVan+j2GIcJ5D7cWlFywH0I+3HO0c9Td6CNK0Mw5sKKRju7OTq WjEqVoa23eQQ93RhTw5yy17Gt4RarMg6Aout178apEFcuZVarNJ3AkXpsN8FCl9cFW6OiV Bp/ksRwTzeLGKXnnmw2dFk/X1fjd+SQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-480-7XB9EyNpNM6h9LofAub74g-1; Tue, 11 Apr 2023 10:25:17 -0400 X-MC-Unique: 7XB9EyNpNM6h9LofAub74g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4100A1097B19; Tue, 11 Apr 2023 14:25:16 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC58F14171D5; Tue, 11 Apr 2023 14:25:13 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, sparclinux@vger.kernel.org, David Hildenbrand , Andrew Morton , "David S. Miller" , Peter Xu , Hugh Dickins , Shuah Khan , Sam Ravnborg , Yu Zhao , Anshuman Khandual Subject: [PATCH v1 RESEND 0/6] mm: (pte|pmd)_mkdirty() should not unconditionally allow for write access Date: Tue, 11 Apr 2023 16:25:06 +0200 Message-Id: <20230411142512.438404-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: g9nzas13fem1yk86tu5o5jkoq5gt354p X-Rspamd-Queue-Id: 1A488160017 X-HE-Tag: 1681223120-807607 X-HE-Meta: U2FsdGVkX1/kDwb+2JCE1ABzU6H/Avqg8h/vjQbKbymTxk6shK1TfsNggbXnyoE7arpWBkwOBYtkZxsSFMCllK+48c8N5esOGnDOot/Z53nUonh4vkpdo0sGrxEj7zq14RWJdcT3D+qIPQRXvVfob30/J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Zjjm5AhVFNF29QX3KlNQSs/vLHslBHdfZKxelepkSnvXtb0WNCtGZLE7m6eZ6cOU12+8d2SAoX6bpB17x+6C71ANYXf6OQr9M/I7Zb9nmXgqpZj0b1FJDsQNKdZWzXmrKXBM4EDrtxPycht+hQMkzXx3UKGFU1bvhiY2t9jxV/l0pRPsR+l2ZwYM/RFDcfRbSay5oMhECPjYmHdkqsd8mKYesxze0bnj7laVyws/D5/MzVGgIYE1W1iUfnI89QPLSTFLwNZE81E7jINwhVucGNMVdXlULjnCVqN1usxTC45KbgAfoGe3c1cex63ZJdSutA9tWSXcKVxXrpPuEU3BILyt+cPQbWSP914rM6mplia3yQdwaPnPUWcT2Y5om94P0wOd1x6GhZHWI4E= 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: This is the follow-up on [1], adding selftests (testing for known issues we added workarounds for and other issues that haven't been fixed yet), fixing sparc64, reverting the workarounds, and perform one cleanup. The patch from [1] was modified slightly (updated/extended patch description, dropped one unnecessary NOP instruction from the ASM in __pte_mkhwwrite()). Retested on x86_64 and sparc64 (sun4u in QEMU). I scanned most architectures to make sure their (pte|pmd)_mkdirty() handling is correct. To be sure, we can run the selftests and find out if other architectures are still affectes (loongarch was fixed recently as well). Based on master for now. I don't expect surprises regarding mm-tress, but I can rebase if there are any problems. [1] https://lkml.kernel.org/r/20221212130213.136267-1-david@redhat.com Cc: Andrew Morton Cc: "David S. Miller" Cc: Peter Xu Cc: Hugh Dickins Cc: Shuah Khan Cc: Sam Ravnborg Cc: Yu Zhao Cc: Anshuman Khandual David Hildenbrand (6): selftests/mm: reuse read_pmd_pagesize() in COW selftest selftests/mm: mkdirty: test behavior of (pte|pmd)_mkdirty on VMAs without write permissions sparc/mm: don't unconditionally set HW writable bit when setting PTE dirty on 64bit mm/migrate: revert "mm/migrate: fix wrongly apply write bit after mkdirty on sparc64" mm/huge_memory: revert "Partly revert "mm/thp: carry over dirty bit when thp splits on pmd"" mm/huge_memory: conditionally call maybe_mkwrite() and drop pte_wrprotect() in __split_huge_pmd_locked() arch/sparc/include/asm/pgtable_64.h | 116 +++--- mm/huge_memory.c | 16 +- mm/migrate.c | 2 - tools/testing/selftests/mm/Makefile | 2 + tools/testing/selftests/mm/cow.c | 33 +- tools/testing/selftests/mm/khugepaged.c | 4 + tools/testing/selftests/mm/mkdirty.c | 379 ++++++++++++++++++ tools/testing/selftests/mm/soft-dirty.c | 3 + .../selftests/mm/split_huge_page_test.c | 4 + tools/testing/selftests/mm/vm_util.c | 4 +- 10 files changed, 468 insertions(+), 95 deletions(-) create mode 100644 tools/testing/selftests/mm/mkdirty.c