From patchwork Thu Apr 13 23:11:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13210717 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 5607FC77B61 for ; Thu, 13 Apr 2023 23:11:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81C83900003; Thu, 13 Apr 2023 19:11:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CC266B0078; Thu, 13 Apr 2023 19:11:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66C98900003; Thu, 13 Apr 2023 19:11:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5730A6B0075 for ; Thu, 13 Apr 2023 19:11:29 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 360671C614C for ; Thu, 13 Apr 2023 23:11:29 +0000 (UTC) X-FDA: 80677916298.28.256C035 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id BFC12A0002 for ; Thu, 13 Apr 2023 23:11:26 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gxlYokI3; spf=pass (imf15.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=1681427487; 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=Sy2ZMNXqMN2EgcAsVUaOWzVqOHhPBbCxJILj4M5ud0k=; b=wieM3iBVZCbm64mavBJTXNBUB0GO+Z0slkwv1SaFSEsFUiIEPRcljj2uzc/baMyH4KN8Ty VQbR6XN1yyQQY8inlWWB9lgOgr1F4pL+wnrXO2n8TQ2bxj7HR9QGr1ghk+769bpx77g666 EwzYhq4vO0XYmi4V9Brz4WchBEoSJ4o= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gxlYokI3; spf=pass (imf15.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=1681427487; a=rsa-sha256; cv=none; b=5lData1+vb/Ejfqh8sIhZz86O+UxrvohNQzSMdASYEjKQ+x8C9zFGkOlEZWn+kcpocXgi0 lw4z9bpmDDbH4jKFq5cGAesmOPsxfrsB90eFJHOvZJy4mZq3WMMIiRC3NpHBDFUWpe0Lil ohehHCKgsbwTlfZ0wJJ+WQzUdI3+a5o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681427486; 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=Sy2ZMNXqMN2EgcAsVUaOWzVqOHhPBbCxJILj4M5ud0k=; b=gxlYokI3PdjpIdxcky/71gVBTVTWJlPxzXPyQTf022Pe/1GUhT9YKKVpsgIpSw3nBZ8nUu +iLnVw8yaZ9P95h/rGrx9Y0HPvo1PBV+f6vNJBBA/bGK3kUyWcnII6HGCM7il+NU8D4C4j 3bkQzxcJ98HEvN5RPbjUghD8mQ9g1nA= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-0AeKPDdWOD-9gmcgmVeuzA-1; Thu, 13 Apr 2023 19:11:23 -0400 X-MC-Unique: 0AeKPDdWOD-9gmcgmVeuzA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3e947d81d7dso3391231cf.1 for ; Thu, 13 Apr 2023 16:11:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681427482; x=1684019482; 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=Sy2ZMNXqMN2EgcAsVUaOWzVqOHhPBbCxJILj4M5ud0k=; b=dB/64YggrWtf+y3gTY96uVtCgnrO0jCM8WKfvZZ4XY7XDDNKsh/2TsH1UY6hip/VLl s7i0/hHSDAUtvhN6JFfUm7fOWyKiB7TkJA5sOaxjNzWaZ3oxs2X9gApPbMe0ctY11k0M Ez6iD6oUu392k/MRDgFPd7z5pel7i2ybHgtBbZADrzbOCfBXFwfo8YKLcfvVRHfs0uPA lbAXdPj8Sh5fA1LlcJgJsnz7K31sqZNVzgKvYoxnLHHoXmtl3TEc6LeHqi0VMAi4OlIR pxOzl340z4G2uNv84L1xVe1cs1+2PiMSuJL92WMVQa2G+bvg3ZBCgsG5Kj+C2vptBqsI N+/A== X-Gm-Message-State: AAQBX9dbSQDefN3UvfeGbYrbHqG7w07e1tWoT2N3oT5J8bBUmVhctwO7 ntF4hKt4ujD0XYHkavmZSIj2tYoTfZWMX0C3l7u6R+05Ow3/o0B3ClqijzVOKnaKYIi7/gEnJdi f711hKLk+75A= X-Received: by 2002:ac8:4e43:0:b0:3bf:cf77:a861 with SMTP id e3-20020ac84e43000000b003bfcf77a861mr1053260qtw.4.1681427482617; Thu, 13 Apr 2023 16:11:22 -0700 (PDT) X-Google-Smtp-Source: AKy350azXW2VkXEejL7kciZXzwV2PnzHHS8mVYaL63ffO4fmArHm00rq3T8DL3wm/yhANxmPuDYiEQ== X-Received: by 2002:ac8:4e43:0:b0:3bf:cf77:a861 with SMTP id e3-20020ac84e43000000b003bfcf77a861mr1053215qtw.4.1681427482308; Thu, 13 Apr 2023 16:11:22 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id g3-20020ac81243000000b003ea1b97acfasm612446qtj.49.2023.04.13.16.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 16:11:21 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , Andrew Morton , David Hildenbrand , peterx@redhat.com, Mike Kravetz , Nadav Amit , Andrea Arcangeli Subject: [PATCH 0/6] mm/hugetlb: More fixes around uffd-wp vs fork() / RO pins Date: Thu, 13 Apr 2023 19:11:14 -0400 Message-Id: <20230413231120.544685-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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: aho198zx385o7kmoirax4g57f8tfuuz7 X-Rspamd-Queue-Id: BFC12A0002 X-HE-Tag: 1681427486-708516 X-HE-Meta: U2FsdGVkX1+DT5EBQpi5sdppz0MVcPvxRrcyBho0KnrfcePuHg2LxQ8FeZfsq/ZJyt1Dja6tHIfuOWDCA0w6VpSs3I+sMYwI5nsQEdWJYZbocD1dCemwht0ZDe3yQlYSpjnL9oIw7fajzDHNnVbeVM+G8nAFQ6Vcl7h+QfKOeGDieLGda8gwslDBpRKhb95+WSnb1k/0U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ch9IGOyS09seoWyIDqsdJH6ux23sNu1elnThwr25NfsZFBjuomcieX3n3z+jWz8zV3EcKYqkYqvd4VNS2tqwx4gJ8HyHD72fS0hs6jA71q36we0YZtN0ObHAvbx+BqUtsuNP4FpH445fIAI8Ezn/XWy6mxqigUSTQogCs/vMK5Lf3xfJGwjVQuAGVdFzMhsmqovQDa+S9oX01ofDcJgzj0 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 a follow up of previous discussion here: https://lore.kernel.org/r/20230324222707.GA3046@monkey There, Mike correctly pointed out that uffd-wp bit can get lost too when Copy-On-Read triggers. Last time we didn't have a reproducer, I finally wrote a reproducer and attached as the last patch. When at it, I decided to also add some more uffd-wp tests against fork(), and I found more bugs. None of them were reported by anyone probably because none of us cares, but since they're still bugs and can be reproduced by the unit test I fixed them too in another patch. The initial patch 1-2 are fixes to bugs, copied stable. The rest patches 3-6 introduces unit tests to verify (based on the recent rework on uffd unit test). Note that not all the bugfixes in patch 1 is verified (e.g. on changes to hugetlb hwpoison / migration entries), but I assume they can be reviewed with careful eyes. Thanks, Peter Xu (6): mm/hugetlb: Fix uffd-wp during fork() mm/hugetlb: Fix uffd-wp bit lost when unsharing happens selftests/mm: Add a few options for uffd-unit-test selftests/mm: Extend and rename uffd pagemap test selftests/mm: Rename COW_EXTRA_LIBS to IOURING_EXTRA_LIBS selftests/mm: Add tests for RO pinning vs fork() mm/hugetlb.c | 33 +- tools/testing/selftests/mm/Makefile | 8 +- tools/testing/selftests/mm/check_config.sh | 4 +- tools/testing/selftests/mm/uffd-unit-tests.c | 318 +++++++++++++++++-- 4 files changed, 315 insertions(+), 48 deletions(-)