From patchwork Thu Mar 9 22:37:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 6383 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp562528wrd; Thu, 9 Mar 2023 14:51:14 -0800 (PST) X-Google-Smtp-Source: AK7set8oKIzeC3BkjrVF9z2rvc6XGaPhPwdYL7PPgbp4ga5jkNtUIF2uwdQrriHOqG7Gkobt0V2y X-Received: by 2002:a17:90b:1b45:b0:234:b6f5:7ddf with SMTP id nv5-20020a17090b1b4500b00234b6f57ddfmr23128958pjb.44.1678402273724; Thu, 09 Mar 2023 14:51:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678402273; cv=none; d=google.com; s=arc-20160816; b=tfRqMsB/ckGAEYXVvzcgwwlLOxqm9pMn+jHX0RYJxLdImqUYoe/9/RvgODGMPS7dvD who25vrfrap6fb9WFQZzBnqEPYEpjop9AAma1r+t4fQenBoDASpsXe+WNAepWrZNgQ/R aiV6IDNRRHhrn2zh7jezDLHuAjeEvehPq98AKySvEdm3oRx8xv+H4teC+YJDcDyzh/S2 FqB3FtWUZWP9v7Kt3h29GnVowmj4K4t+BKaUO/8tFhwXeoWG9w5Q/Bqk4IBpdPsi+yYB jO3cmSPH8fml8OoItNpydKZ29f6QADilLGB4VK/F7RaIFb1VxBR81hMSVUKVNNu+k5GZ GJ9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=KDlNY98zejjvKZ/14cSb+fv+AsQvq/yadRcmqDsBLIE=; b=jjheZxvqt4iQaSTNApuFFae4dwv/r10F+laEUdPaeS+c1Sg7qVP2VlBu4uTRRXSXt1 a0Vkj7eFvrjEJLugLeIy/hamZi+8jYB9XcyppDfMRT9Bk80FhDj22oFHZ7QLsxlbh99j HkdEMdo6xevj53TB0n3WiNFdAfdO4lOKorKPMGkS9QQLvcjflvbExYtPQoqs+AVf7Iei zsoyrmnoOklDfZh+5KbCEusWCQmjaWibhE30d+F73QEvMaDJSWZecmCj9AuH7PxNvXGV oSKd6z/TBKsQSzdgcSswGeI3HdAYKfc/zB2I4Rf5r9zC0H+azMNb7XcQPbY/6WPkqz1+ rMnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DzyMGrXD; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a17090abc0400b0022c09c603bdsi904902pjr.118.2023.03.09.14.51.01; Thu, 09 Mar 2023 14:51:13 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=DzyMGrXD; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231258AbjCIWiC (ORCPT + 99 others); Thu, 9 Mar 2023 17:38:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbjCIWh7 (ORCPT ); Thu, 9 Mar 2023 17:37:59 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D34E9FAEDC for ; Thu, 9 Mar 2023 14:37:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678401435; 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=KDlNY98zejjvKZ/14cSb+fv+AsQvq/yadRcmqDsBLIE=; b=DzyMGrXDHSYgREdJdCH/XYOFlFLbqH4svGr/NNVrPJ6ramQU3t4aQpmt/ODGIwEWomNn4b 1o7VEvkmn9pncdXwnLuDGO1v1o9I0/kG8kSkuylbt9ft2YNkwPw0B68o0LgSOMx0YpbVhR DEDaj7paqMU/kIE1AeimfeBJVgjl9q0= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-336-2rz4MP4rNnK994skoXiNnw-1; Thu, 09 Mar 2023 17:37:14 -0500 X-MC-Unique: 2rz4MP4rNnK994skoXiNnw-1 Received: by mail-qk1-f198.google.com with SMTP id 8-20020a370508000000b00724fd33cb3eso2048257qkf.14 for ; Thu, 09 Mar 2023 14:37:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678401434; 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=KDlNY98zejjvKZ/14cSb+fv+AsQvq/yadRcmqDsBLIE=; b=Kk67WnNEjDg0JZnmY570Io1rhRh04kN7qGv94GQ9az/DCALyootQ8BDUeKgyetOlOd CtcY0Lkxvwa8yDiG06JpDHXXTEoo8i8KRQqRw09oe+wEk7HDtdN9ON8lhc5doQ1F4ZFQ 3dgZjMactt+dwh4CAT2WLSWIWhPHEAyMtIRUMUD2F7hW142O2CAvB3CicQR8wO81m7zj X/X1DzfPFwBFJp3K1cgfexj6QJbYNzkOtGjE83yx0f+UuV/zf0W0kGgLM5zLPt21zSP/ HX3J+JQhCQtk5vaZompqeMZ6u4Tv1dPMLtHqy9Jd2LhiqgQ4vEintL2Ei6e/T7qsarYo WUTQ== X-Gm-Message-State: AO0yUKWREsHfv6eqpjJJNOTQzrgUuiBK2vBqlWOGaP0IxyaoR/RaRZ7m 4BigPNzGnm09Awx2y3ZjvcrokTv45yTOX8dNMLK7u29JXNVgZTgKnebldKzAh/rlPMFllBR+FNe j6JtXFRoBJt+yZw6MKXyAgcU2 X-Received: by 2002:ac8:574a:0:b0:3bf:da3a:4e0f with SMTP id 10-20020ac8574a000000b003bfda3a4e0fmr1802883qtx.0.1678401434084; Thu, 09 Mar 2023 14:37:14 -0800 (PST) X-Received: by 2002:ac8:574a:0:b0:3bf:da3a:4e0f with SMTP id 10-20020ac8574a000000b003bfda3a4e0fmr1802858qtx.0.1678401433663; Thu, 09 Mar 2023 14:37:13 -0800 (PST) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-56-70-30-145-63.dsl.bell.ca. [70.30.145.63]) by smtp.gmail.com with ESMTPSA id c26-20020ac84e1a000000b003b8484fdfccsm172215qtw.42.2023.03.09.14.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 14:37:13 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit , Axel Rasmussen , Paul Gofman , Muhammad Usama Anjum , David Hildenbrand , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Andrew Morton Subject: [PATCH v4 0/2] mm/uffd: Add feature bit UFFD_FEATURE_WP_UNPOPULATED Date: Thu, 9 Mar 2023 17:37:09 -0500 Message-Id: <20230309223711.823547-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759932342417314677?= X-GMAIL-MSGID: =?utf-8?q?1759932342417314677?= v1: https://lore.kernel.org/r/20230215210257.224243-1-peterx@redhat.com v2: https://lore.kernel.org/r/20230227230044.1596744-1-peterx@redhat.com v3: https://lore.kernel.org/r/20230306213925.617814-1-peterx@redhat.com v4: - s/handle_pte_missing/do_pte_missing/, fix spellings, etc. [David] - Add a helper userfaultfd_wp_use_markers() [David] - Update userfaultfd.rst describing the new feature bit The new feature bit will make anonymous memory acts the same like file memory on userfaultfd-wp in that it'll also wr-protect none ptes. It can be useful in two cases: (1) Uffd-wp app that needs to wr-protect none ptes like QEMU snapshot, so pre-fault can be replaced by enabling this flag and speed up protections (2) It helps to implement async uffd-wp mode that Muhammad is working on [1] It's debateable whether this is the most ideal solution because with the new feature bit set, wr-protect none pte needs to pre-populate the pgtables to the last level (PAGE_SIZE). But it seems fine so far to service either purpose above, so we can leave optimizations for later. The series brings pte markers to anonymous memory too. There's some change in the common mm code path in the 1st patch, great to have some eye looking at it, but hopefully they're still relatively straightforward. Thanks, [1] https://lore.kernel.org/all/Y+v2HJ8+3i%2FKzDBu@x1n/ Peter Xu (2): mm/uffd: UFFD_FEATURE_WP_UNPOPULATED selftests/mm: Smoke test UFFD_FEATURE_WP_UNPOPULATED Documentation/admin-guide/mm/userfaultfd.rst | 17 ++++++ fs/userfaultfd.c | 16 ++++++ include/linux/mm_inline.h | 6 +++ include/linux/userfaultfd_k.h | 23 ++++++++ include/uapi/linux/userfaultfd.h | 10 +++- mm/memory.c | 56 +++++++++++++++----- mm/mprotect.c | 51 ++++++++++++++---- tools/testing/selftests/mm/userfaultfd.c | 45 +++++++++++++++- 8 files changed, 197 insertions(+), 27 deletions(-)