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: 11714 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2893831vqx; Thu, 6 Jul 2023 16:21:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlGCprzKSROsI3mIxIvu+H12rDwzhpHAN7Np09QbIC3x374MQBOHW2q432C0tmvrDbCokd+f X-Received: by 2002:a0d:c5c7:0:b0:576:6b83:2466 with SMTP id h190-20020a0dc5c7000000b005766b832466mr3189277ywd.25.1688685685994; Thu, 06 Jul 2023 16:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688685685; cv=none; d=google.com; s=arc-20160816; b=jqLG6covNKuBbjjqvuAuznt+0rIE88iwjsuQqN57C5w2xylEjET67/HSKgCoKsBSiJ VFP9sZ5SIsnbG7I0pIunkN0xvqwMqVHcz5ZOwjxE3J6cv/BvZiLcwkWteWXRPP/4nsCg /UOmRF0xvjIx5Gy68PC7O8lmPNNnp6MdLtVCpfXx9Kn80g3bKXu1b7q2tsi7BLnXrxqZ RqfRMfqxaC9iGRmKHHxVSpFUNkpszN2xoszoGgL4k8wXVtvdI8J0vzDBDI/qh2+Ari31 h3n6xi7C7JTBWXjLSHH95WW0hS/kjJ9ptZ0kcuTQSJYJHouHJ9UBdiXjyapcYP+p3AfF 4Lqw== 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=n8zmkhTUTSLpfAyl7/UNU2Do+ozC8p34im9h+iKQJzc=; fh=Opjbx899L+35XA6SNQJRoMm3wFpvelEj3IooMxkZLjI=; b=vFMe2mLUHVaDe/xgQXGqAq0KT08qoCUBz2lBg/PHPugARtIdY8k9dvdemD7DS6L2VX kukBhvilMEq7hAzK3n+yYAov6S/tb3IIhwMzC8OepoHzAdBO11ek7TRMSDXcmyNc3dGK gyFQYJkwqAZ7JkvVyn860kS+d3gB7L9+PyvGSuqw8wymSGeJExTGafh3fymCLyDoyNbT hhSS9HPo1pWzcpUdNvpCZy2suAnlWv+HEf/DDaaIH1M41pGy92w2VP/9RS1xwnZJVhYU JFgoc17bhIvmt8+ztVwvEjj9eUNOkFQK8oIjuAvdJhUOqQFssAgGXVYJb5iXjDiE0rlg FiTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="XNNbwIV/"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a1-20020a631a01000000b005439d1acbbcsi2204105pga.440.2023.07.06.16.21.12; Thu, 06 Jul 2023 16:21:25 -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="XNNbwIV/"; 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 S229936AbjGFWuw (ORCPT + 99 others); Thu, 6 Jul 2023 18:50:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbjGFWuv (ORCPT ); Thu, 6 Jul 2023 18:50:51 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 018ED1723 for ; Thu, 6 Jul 2023 15:50:50 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bb2a7308f21so1264577276.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=IH+S/QWodbDrFFMNXYQQFmRrVYi7u/0t445NWWgq7KCS22dyIeEmNU6DOd24xze1nU +bZtUTdyu9E6Y051UBJiPksVGjdqm1Ett1IyxzSaOZ8vPjwhN2r+E14X+BXLhw6UiAR2 v40t2fK8oGODHiyvZFQV/gIQ8m0cHIg+bE0Dz640uhrafXY8/JxtDGmULoZPu1izT6Uu LEUkA9s6ikf6M5QFKQQUGPJbeVzUUG+V5p9DKm700hqtqGeMJOoLDTyZklJn68jLC89U G3J0XPKbddpR1nMUTMswD6R0tNznLDO7NzgwsA8lAbhGCWUDxx8XUhZbpsT+EeN2VxbT NQEg== X-Gm-Message-State: ABy/qLYWPdql9TkIFhtFbcRrh3N4EVPzbFM4U5wAK2XYgbS41y0I4q0N HrhCEKTLbXr608tijPlwwq25hB65pt6TweKUkqUa 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-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=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770715282025169617?= X-GMAIL-MSGID: =?utf-8?q?1770715282025169617?= 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