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: 699936 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22407EB64DD for ; Thu, 6 Jul 2023 22:50:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230017AbjGFWuw (ORCPT ); Thu, 6 Jul 2023 18:50:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbjGFWuv (ORCPT ); Thu, 6 Jul 2023 18:50:51 -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 0246D1992 for ; Thu, 6 Jul 2023 15:50:50 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5704970148dso13015867b3.3 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=dBWs/FI6fsUFyNiLagplTRurfqAtWAodWoL5OHu49L9vOS2VGSNQP+rPLXIk31gS3N RInr0GUwqoQLetGk8cebaNBz1vfwttCqASI6i4JrBE5ncdNRtausiQDi1uHe2xGOCsao 2RyXIh2JPIP5XSeod6h+31lWrch6CjXleCshNN3iJVzl+OV545i4/jFBMV39P7yoFmlN ku5DX3hJL9Q664s6AOmzRr1NBgnOtTzVnvbN4eE2vme2++/FfBAmwkJ8GKBtNwOvIWRU L8FkoVRGqxOhH7TFQchVyvgi58Z2NdDL7+dwwugqs9zlWtCa3dsOAGoBLVYSXqJ0scQY Rp6Q== X-Gm-Message-State: ABy/qLZCS3RDpJPGRUH8+RfN9bivLIDFU5mo65gqWoDoBuq4YqPgWvzP 4f3oOEMSc/qY3vBRzkzKDgcbo4zXxosBZMovJ/Q3 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@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: 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(-) Reviewed-by: Peter Xu Acked-by: Peter Xu --- 2.41.0.255.g8b1d071c50-goog