From patchwork Thu Jul 6 22:50:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13304270 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 55EF1C0015E for ; Thu, 6 Jul 2023 22:50:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92F468D0001; Thu, 6 Jul 2023 18:50:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B81B6B0074; Thu, 6 Jul 2023 18:50:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 759178D0001; Thu, 6 Jul 2023 18:50:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 626866B0072 for ; Thu, 6 Jul 2023 18:50:52 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 260D81A0C96 for ; Thu, 6 Jul 2023 22:50:52 +0000 (UTC) X-FDA: 80982683544.16.8787D5E Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf19.hostedemail.com (Postfix) with ESMTP id 3CADB1A0011 for ; Thu, 6 Jul 2023 22:50:50 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="XNNbwIV/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3SUWnZA0KCJw6TAHN6OIQOOAJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--axelrasmussen.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3SUWnZA0KCJw6TAHN6OIQOOAJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--axelrasmussen.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688683850; 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:in-reply-to: references:dkim-signature; bh=n8zmkhTUTSLpfAyl7/UNU2Do+ozC8p34im9h+iKQJzc=; b=g3bl3gHn6tgB0y3VZbQ2YUG9pa2qQ3DOsC5uPqWEDfMhRyhdQ9c+6+Qffo5pbc3zg+aGI8 ORu9Wg01R8MXTZzgjF8b6OZUbiIht1mmbdQTONtCSKpWsyFPIrxIfw3vIEUAZu0pZk3Oj9 H3AFsMadJulwRxsig5vC4z3I2O2c/6M= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="XNNbwIV/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3SUWnZA0KCJw6TAHN6OIQOOAJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--axelrasmussen.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3SUWnZA0KCJw6TAHN6OIQOOAJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--axelrasmussen.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688683850; a=rsa-sha256; cv=none; b=dDKA7NAdG91vTwtBiA6llVnvjX0XDzYBwocuQ3rhrq8o53JjNC9Tj442fMdK6fGPVCyZmx S2UoYDmX3Qh07v1vCPXSi3AHuzBIYs77NjSpAQEb2k2VRKumE7/nf4mYwX0lL8vtV+72O/ f0qYZiu+Em9GzgvnZNbJSUzoj96IYmQ= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-bb2a7308f21so1264578276.2 for ; Thu, 06 Jul 2023 15:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688683849; x=1691275849; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=n8zmkhTUTSLpfAyl7/UNU2Do+ozC8p34im9h+iKQJzc=; b=XNNbwIV//0t27QtIOlhCug+a1paGkIprej7/5tHl5NNn5KUEQh78vpB8hSgjpHgtml SHVQw3iJV4o2JiJrhBDuJIcmXz3dhskaIu5jpZoYHvMoFHMN6dOyuK+gts/4KV47wAdF AVwnH9YNrhfFTLUcC8hUifJ+Wg9tetdDYhfm0QOYMEa6yqrvPsN54eNgMW652Y9t7dsn 4bBAzinND5wZDeIb6WWSVMvGD/yFFBONlGlbJzg6Yw5yde8xFCyvT/xKxlAA9Dw84boG X9157aATBdSKF3LfFE3ppzGxi+pKdgj65AAT3C9RqpCsGlIodHhiOdCG2Uk9JuBh9llq LOxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688683849; x=1691275849; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=n8zmkhTUTSLpfAyl7/UNU2Do+ozC8p34im9h+iKQJzc=; b=X4qPLnlxbNWtCD3pdcLttgswH2Dq6SakspfnbkCPTLX3/32zI046kZTncmwzlytht3 jbqbRrZ7+hPL8UpmotrMiMeFcdTl74rODSUuyEDotzIAUaC+P4ltgjzr+/FM5siYZ5iE RyUkyU3BBfHIvQax/EMV6g95ok3Kq0g4KqiB4XCdMPm5l+knxnhzObS6DS6kP9DYMrJR RjWeFSQ3DqvBZR51BWNQkqgNKWTDtDb5Kg+TkCIZMzcOFzG7bcFe72VfPYn+W//EjKEd KpOeHqr+YozzerLxLckLM78IcvRpTj85iOMVmmgDJfd37fEzYYj6SDTT1pTgB4IWyDit igLw== X-Gm-Message-State: ABy/qLYoeVW1rfMvnczi53QsH/HobGU+o4/AxuUV38MNG6Ump606J0Eo iUhTLIgwfqhiypgXIAhv9CVi4CnA0N4BVnD8Yxa2 X-Google-Smtp-Source: APBJJlFbLqWUavEdkD+jz9r/bjiqpKIWeClwQb49Ydc52jFFjwqSAI72wtmf2+hUlHqaQBcSWvtJMNcnMXeulK/4C2EZ X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:bec3:2b1c:87a:fca2]) (user=axelrasmussen job=sendgmr) by 2002:a25:3189:0:b0:c4f:43d7:7dbd with SMTP id x131-20020a253189000000b00c4f43d77dbdmr18242ybx.12.1688683849213; Thu, 06 Jul 2023 15:50:49 -0700 (PDT) Date: Thu, 6 Jul 2023 15:50:28 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230706225037.1164380-1-axelrasmussen@google.com> Subject: [PATCH v3 0/8] add UFFDIO_POISON to simulate memory poisoning with UFFD From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Brian Geffon , Christian Brauner , David Hildenbrand , Gaosheng Cui , Huang Ying , Hugh Dickins , James Houghton , "Jan Alexander Steffens (heftig)" , Jiaqi Yan , Jonathan Corbet , Kefeng Wang , "Liam R. Howlett" , Miaohe Lin , Mike Kravetz , "Mike Rapoport (IBM)" , Muchun Song , Nadav Amit , Naoya Horiguchi , Peter Xu , Ryan Roberts , Shuah Khan , Suleiman Souhlal , Suren Baghdasaryan , "T.J. Alumbaugh" , Yu Zhao , ZhangPeng Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Axel Rasmussen X-Rspam-User: X-Stat-Signature: zoq4fyhkb9cbgxomo35h1ki7hqfzo77h X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3CADB1A0011 X-HE-Tag: 1688683849-277067 X-HE-Meta: U2FsdGVkX19mb6VfBi+BM+u3b6N8XgES0oiYw7kSpzR2IGdl2qxdaKAZKVmroU8hoq2j5WlRGYGx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KVJAfYwAdc5c7tLimkmQMC3051d5x1HU4WJ3oxATWbalrTofpL4rQnJlVZpvm5xnBXaYaCLX6cofrgGHUOoQ0avdBJyOgxALvurLOfW5AMahcXl9pj97P6DRLgTRs75FnAiQPrx03qEzV+M/vk1Sbbr6R8rUfyt5gdnNTfRyLymSbZP7HHr0ypdHs48DyFSFx7+j7LagaT6SCZ7vbbWrHsAApiwJzOdGMl5873SxQEYmcc4+LK1pfATaZDBwkFAR50uNPitUbNdMnyOe0KiPZzKtoyD4qjS9KUProCnmiovgJQVpNFsqX4YyXU+2j87eVPYcUsAGZjSZdMhoP8BChxKvu772IFcMF4/bFy76eXcqGak6gM7RWOQfCnjCrJlrK0/QXw7o4beRkT4Ws6iiRnZ4O3NLkPrYvD7zfH6VbWC1vT9HXGW097qZ0eB76Wpb4LWu6RCqx18NvOniMhmmOeqnUODEeOJj4jMyKmBXCNE06uc6iwy4XWuuw292KiWb01GNtD+nvIkFeRBngW55rw== 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 series adds a new userfaultfd feature, UFFDIO_POISON. See commit 4 for a detailed description of the feature. The series is based on Linus master (partial 6.5 merge window), and structured like this: - Patches 1-3 are preparation / refactoring - Patches 4-6 implement and advertise the new feature - Patches 7-8 implement a unit test for the new feature Changelog: v2 -> v3: - Rebase onto current Linus master. - Don't overwrite existing PTE markers for non-hugetlb UFFDIO_POISON. Before, non-hugetlb would override them, but hugetlb would not. I don't think there's a use case where we *want* to override a UFFD_WP marker for example, so take the more conservative behavior for all kinds of memory. - [Peter] Drop hugetlb mfill atomic refactoring, since it isn't needed for this series (we don't touch that code directly anyway). - [Peter] Switch to re-using PTE_MARKER_SWAPIN_ERROR instead of defining new PTE_MARKER_UFFD_POISON. - [Peter] Extract start / len range overflow check into existing validate_range helper; this fixes the style issue of unnecessary braces in the UFFDIO_POISON implementation, because this code is just deleted. - [Peter] Extract file size check out into a new helper. - [Peter] Defer actually "enabling" the new feature until the last commit in the series; combine this with adding the documentation. As a consequence, move the selftest commits after this one. - [Randy] Fix typo in documentation. v1 -> v2: - [Peter] Return VM_FAULT_HWPOISON not VM_FAULT_SIGBUS, to yield the correct behavior for KVM (guest MCE). - [Peter] Rename UFFDIO_SIGBUS to UFFDIO_POISON. - [Peter] Implement hugetlbfs support for UFFDIO_POISON. Axel Rasmussen (8): mm: make PTE_MARKER_SWAPIN_ERROR more general mm: userfaultfd: check for start + len overflow in validate_range mm: userfaultfd: extract file size check out into a helper mm: userfaultfd: add new UFFDIO_POISON ioctl mm: userfaultfd: support UFFDIO_POISON for hugetlbfs mm: userfaultfd: document and enable new UFFDIO_POISON feature selftests/mm: refactor uffd_poll_thread to allow custom fault handlers selftests/mm: add uffd unit test for UFFDIO_POISON Documentation/admin-guide/mm/userfaultfd.rst | 15 +++ fs/userfaultfd.c | 73 ++++++++++-- include/linux/mm_inline.h | 19 +++ include/linux/swapops.h | 10 +- include/linux/userfaultfd_k.h | 4 + include/uapi/linux/userfaultfd.h | 25 +++- mm/hugetlb.c | 51 ++++++-- mm/madvise.c | 2 +- mm/memory.c | 15 ++- mm/mprotect.c | 4 +- mm/shmem.c | 4 +- mm/swapfile.c | 2 +- mm/userfaultfd.c | 83 ++++++++++--- tools/testing/selftests/mm/uffd-common.c | 5 +- tools/testing/selftests/mm/uffd-common.h | 3 + tools/testing/selftests/mm/uffd-stress.c | 12 +- tools/testing/selftests/mm/uffd-unit-tests.c | 117 +++++++++++++++++++ 17 files changed, 377 insertions(+), 67 deletions(-) --- 2.41.0.255.g8b1d071c50-goog