Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32479970rwd; Fri, 7 Jul 2023 14:57:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlH8sDKdcJQPGTMcqGF+Fp9hfcTXyJKel3wPN+O5DhO8mR4AqvJP2is9ZygZ/6hJho/Ra6px X-Received: by 2002:aa7:d6ce:0:b0:51e:f83:6de3 with SMTP id x14-20020aa7d6ce000000b0051e0f836de3mr4654686edr.17.1688767061231; Fri, 07 Jul 2023 14:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688767061; cv=none; d=google.com; s=arc-20160816; b=MO5A8tyF+oXvTgC82MyX8zebs5FKKyNOPJIqGoVPUgXadZGlFbq1Ehluv6R3sCGBOM 40TmexsKCgUnNRAW7dapa6HLPc0jALCWBjTufW+Z4UUZOEdcnR7BiKkTS9i0pEZ2ZZxO gsUXqOjwWy9sjIx0lpZeb2oWQpXD6c4PaNsrKxFJvZCS3rXh3k0IUFQwS7DEmgTaGyXI P1ioY0jNQW7BvPKKWf4+1WhFlH7GS0FHCBiWDS6pEN1SgnOL3HtyG5gKVFW2q7a7JFCu IdgJuVwKuWtEkOqBKLSAmnriUJgXISWIuHPRD43PxGaBxzHRSDK8ibBf9stRWvYSCJkh nuYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=dxkJHri43fmKt8R5z8YjbywDBegP4t1apGGC2ZsbmRA=; fh=Opjbx899L+35XA6SNQJRoMm3wFpvelEj3IooMxkZLjI=; b=bfTlMUOXFQE/YS0DgCYZCdqXUgeyTBJQ1rSUl3+ikISt9HDkryGIE1VWGYm+Ny5Cs3 UjJIpPoUApN0L0eyRQvpa8iI8tNMmUXTZAvVo7/slkaBcOSPFvgVf6gYWv2za6G/DFJC v/mmvEJKlWuRvwq5HJHsVw/Wr6kFzBNpHab5KFaGab6C8X4Ybbo2uZoFCfiAubxXh35n WDAdeucmJ7o4ZO0KYkKxB3PPLj0wUSu9jqK2phN+S9Dhds3VFnXE2pg0Sxq0krExUbxI 5FmrhdOELs/x4hiLxgnUPIYFLl34LOM4v0be6nMz7LF6+Jpaw8BeLLbqPlDYiowN/edD I1Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=blOAXi+w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a50ed88000000b0051ddbb1e3besi2508144edr.422.2023.07.07.14.57.17; Fri, 07 Jul 2023 14:57:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=blOAXi+w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232418AbjGGVzr (ORCPT + 99 others); Fri, 7 Jul 2023 17:55:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbjGGVzp (ORCPT ); Fri, 7 Jul 2023 17:55:45 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84BF71FF6 for ; Fri, 7 Jul 2023 14:55:44 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5706641dda9so24886697b3.3 for ; Fri, 07 Jul 2023 14:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688766943; x=1691358943; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=dxkJHri43fmKt8R5z8YjbywDBegP4t1apGGC2ZsbmRA=; b=blOAXi+wOuXHyUw01h+hWReeZCVMretOsTcALUUIwdsRWTO5RZumuf0OIL3/2UIoS5 /KB9UPDpk5EKnvnsrFNLSZcVSDMGG/N2/L+3YmSDMteudF7B+lVa4lvI0xEgnEzRU7AG UoT1qT5gyo11rYW0M3GTWa4gv6Fl7mczc7rJu9iIc7DUQ/Dlgi315G22kKqEzwYd3kRN vDnVlQpo4V+cUd1aT+ZuiMzo2Te2dRviYwAkiPiQw5TQRmpX3gDOmdLHmX7XCSPv/KAg anijJmgmZqXASMSpxIDxEJHEhFt2cm1S8KTqrc3Gp9IOiRP8C6gfsQ2jHBtNGX2veILY jt/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688766943; x=1691358943; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dxkJHri43fmKt8R5z8YjbywDBegP4t1apGGC2ZsbmRA=; b=AlhltMsN/Qj8ELHwzDTDebfJDU5bERTxVToUhJfs9JPI/34JZ0JZ7QvnbStOqNt1R6 1UjqsLVJygNhex4Vm722UgYAotkHw5rpbvLjOckfTiZyJ275hGP29QG2vUw3Q6IkApiy yThN6LB4/cv6ExYtTg1XFSnRs/+XzOCo+2ya/IbQID3U0AZjQU73qv3vzhox0yzhPVEV HJG5V9J6n0PIz+o8oYLCuEwIgr8tFSlEteKoBeTF7VsAoYG8ljCAiyp/a0kuh0hKNN4J 0q14YcPJR7giUyHJeKTMNTRHv9fLxJZiPC4pT7tZVepKZgyIAOBmy+DzN/I/Ie1KyWBT 18oQ== X-Gm-Message-State: ABy/qLa6xMBVpMB/0uGTKyx/9Z42LK538FSrOJCNWfovTF4cbnjb1trp FtKTgobzkuUVt6dAeYbVJN5oc3hJUQSucRqJ9kTm X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:c201:5125:39d1:ef3f]) (user=axelrasmussen job=sendgmr) by 2002:a81:a941:0:b0:579:e07c:2798 with SMTP id g62-20020a81a941000000b00579e07c2798mr45025ywh.2.1688766943660; Fri, 07 Jul 2023 14:55:43 -0700 (PDT) Date: Fri, 7 Jul 2023 14:55:32 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230707215540.2324998-1-axelrasmussen@google.com> Subject: [PATCH v4 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: v3 -> v4: - [Peter] Rename PTE_MARKER_ERROR and helpers to PTE_MARKER_POISONED. - [Peter] Switch from calloc to memset for initializing some state in the selftest. 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 | 15 ++- 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 | 8 +- tools/testing/selftests/mm/uffd-unit-tests.c | 117 +++++++++++++++++++ 17 files changed, 379 insertions(+), 66 deletions(-) -- 2.41.0.255.g8b1d071c50-goog