From patchwork Mon Apr 17 19:53:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13214487 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 DE4A8C77B72 for ; Mon, 17 Apr 2023 19:53:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48ABC6B0074; Mon, 17 Apr 2023 15:53:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 43AD78E0002; Mon, 17 Apr 2023 15:53:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 302998E0001; Mon, 17 Apr 2023 15:53:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 224536B0074 for ; Mon, 17 Apr 2023 15:53:25 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CA31AAC148 for ; Mon, 17 Apr 2023 19:53:24 +0000 (UTC) X-FDA: 80691932328.11.743A702 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 745C2C001B for ; Mon, 17 Apr 2023 19:53:22 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=g7hbyqLN; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681761202; 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=ebFG+472EPgV/DQISB+I4k3P3R91wLCZUBIgWp1pKI8=; b=aC8EMqCZp4IH4dR4fDMVLN0fru53WhrRrs6n6F2RTXOfqI1a2R/Fwp+tCNRTnm0ALkkLWd mNnI6uQT9m3bMRsa7lRjcjOvPGKwDS8jkaVqD79CQgY7VG6rM7yEGPDEOUKhPgLNztOwVs pSkigoqQDQ0nRqqfF9y7mYWqEXGZZ60= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=g7hbyqLN; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681761202; a=rsa-sha256; cv=none; b=JZTKg4ENStSnuAhkhdt4udEqt/mP5RAzHczrPlOj+j59nZe0boJtQeq67kE741CiOqcHMK 3QSvDvfYIXLT690Ol3RL29WWVyWzLPODgZNxCRquRf7I1is2DSFSSlGnLkay0r+HXpQEnr IgNKEMOS4kS8YFSoPySSSb+fhB/HTDU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681761201; 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=ebFG+472EPgV/DQISB+I4k3P3R91wLCZUBIgWp1pKI8=; b=g7hbyqLN6u4DcsM9jqMsaaXg0FehDqYTHDOXiM0gWPgoo1YBaHDOntEgjA7L3t3LmoUFFI ynqfZhRBD5L5HHt70HNVtd+qGAE95VjMBpjBX9p/d7fKKH1vzuvVf+dIG31WHd/nUJ1WXn uXwoAIpNl4cxQcEqySXEJ6a+CdU2Vp8= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-ZfXBbOHNNViF_zIvEg7sbQ-1; Mon, 17 Apr 2023 15:53:20 -0400 X-MC-Unique: ZfXBbOHNNViF_zIvEg7sbQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3e9956069e5so6033261cf.0 for ; Mon, 17 Apr 2023 12:53:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681761200; x=1684353200; 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=ebFG+472EPgV/DQISB+I4k3P3R91wLCZUBIgWp1pKI8=; b=O9Ht4tssufDb4fuBx0b8mr5u/U8+RG/6rfFW5tPKr7DP04+KK44+R071bJr00eroBE XRk/CP05EP0mTUKPVCYIGNrN21uvmDE+40G+LBq3UWvVRxbtjtBZyM3Y52BUc1aphFV3 xIIicYY2ymmWmv/JyHTdM85p6YmXVfNb/WCcJMwCuwVRBFzTN0xMbOFjID9s//iOFqVR 4f9Ct57/pbklz6IOwRntYgF++D358myphdjTC2l5u1GGVlNYBvDLhaeNO17kjHwB0ahl 8fKazLQ3LDicN53EW3yePHQGxSJybcMiGpg+Aiz3vNy8PGMqMBV8Brj50sRNucnk37W7 K1HA== X-Gm-Message-State: AAQBX9fNDum6ktILY8HMcEFOBWcqviy6nXK5nwI9YCiMusTU32ifLHAv Zaj8N6iP3X00RrmdaI6Ugfh17f57rATYQiTsinKa8zNLZCOoqZWhIhI7nSaYjT1U2RkfLu8CuWp /vfEQmwwHB/o= X-Received: by 2002:ac8:5e0b:0:b0:3ee:5637:29be with SMTP id h11-20020ac85e0b000000b003ee563729bemr9983912qtx.5.1681761199964; Mon, 17 Apr 2023 12:53:19 -0700 (PDT) X-Google-Smtp-Source: AKy350Y7FmrLa3ajN6sxzqw5IZyM7aQ1g+z9cTCpvCk6Tr9Ciuz7Fh5tTLjRr0XS17ftu31HbsFXKA== X-Received: by 2002:ac8:5e0b:0:b0:3ee:5637:29be with SMTP id h11-20020ac85e0b000000b003ee563729bemr9983891qtx.5.1681761199702; Mon, 17 Apr 2023 12:53:19 -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 r17-20020ac87ef1000000b003edfb5d7637sm1731278qtc.73.2023.04.17.12.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 12:53:19 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Andrea Arcangeli , =?utf-8?q?Mika_Penttil=C3=A4?= , Andrew Morton , peterx@redhat.com, Axel Rasmussen , Nadav Amit , David Hildenbrand Subject: [PATCH v2 0/6] mm/hugetlb: More fixes around uffd-wp vs fork() / RO pins Date: Mon, 17 Apr 2023 15:53:11 -0400 Message-Id: <20230417195317.898696-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: 745C2C001B X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: fmm3wajwznqa1iy6ny6sr1gx589f4b6w X-HE-Tag: 1681761202-338184 X-HE-Meta: U2FsdGVkX1/hb6s2DUYXoOJuOJ6oN6hsb1OQfZvhTB5KZI8qewnyRDw5a0zq8fDlEWqU9IVT1Tz3Hsydx3HlYD72z1k2jilk+xp2EOVsglduDG3swKBDQAlSwqmt7gZJ5s4CuVTHbukNubM2X9bg9STyTtUCggIbOS1fa4tBK7UH5+UK2dxct3Gi/XF0Q35kcL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01x9gzgEAZypT9zDVi/xFcVsRKxglHKVk8RDctNnpKFsC7hmY2rR55GOxjoxgYo8PYfkdcC71exOlNfZB0yGj69DigCVT8b5eXniS8v8dnLJ0ucK1WOtvovc7aJ8OH7FwdIr68bZ6FOvB/15v2Wp7AVGZ4D0bXwc8PwvIK/zQYEil55nET0bjIrJ8hrOno1Pg/Qg0F2dajOCUh7SXnEDt+G4tjcDEHmAdYmi 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: v2: - Added R-bs - Fix patch 1 issue on hugetlb swap entry [Mika] 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 | 31 +- 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, 314 insertions(+), 47 deletions(-)