From patchwork Mon Mar 6 21:39:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13162418 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 F14B5C64EC4 for ; Mon, 6 Mar 2023 21:39:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7993C6B0071; Mon, 6 Mar 2023 16:39:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 74AD26B0072; Mon, 6 Mar 2023 16:39:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 610856B0073; Mon, 6 Mar 2023 16:39:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 524BD6B0071 for ; Mon, 6 Mar 2023 16:39:33 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EA35FA0C40 for ; Mon, 6 Mar 2023 21:39:32 +0000 (UTC) X-FDA: 80539790184.07.01AF047 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id BF7C6140013 for ; Mon, 6 Mar 2023 21:39:30 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KBoNvahu; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678138771; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=WDt24Uf5+E3IsPxqM3v9POMr36n8o93nXZKrGMIf14c=; b=TEUHN9t8IVhHBh68LZJnv02FmtadQ++HSxJTVTI+OSvJOS+71Mcwp6iapwjt+Qv9RUUGeJ QMN8cz4d3R/IC/Tch0kTq4pSHIkhBk7TakwDLFqfgLajhH6CYogiXwb1S4QxzxiGBGByGw oDVpOZfwm2lvqVQiDBn1EM/teFWmooM= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KBoNvahu; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678138771; a=rsa-sha256; cv=none; b=Sb2LmZuCikQxSK9MW8HHY2Mo/mFZhieCh4Cu592yR8q/C2plC57HUq7RaOIc4ZXSe482NV 9KFYUAvCs8XdtmTDPqTL3epO5NMQlcaAOcYcRopnPDpSkq7RgUqvzhiql+kjS3NvCCQM1f kHUGj8992vCaVqiBy6L+OxzIMr/jmow= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678138770; 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=WDt24Uf5+E3IsPxqM3v9POMr36n8o93nXZKrGMIf14c=; b=KBoNvahuMxCT9nTbWyh49n7B0eoaHty/+8a0igHeNttu7iRUSnpmytV3ZUwGiJbZXoEZ63 3elkohYTq2YgnIgA1RjKqILGMQk7Th2DV2ARL3AqupPraVUEJ9zU1iMXmVB04SdsPiSdxJ uKGbkDJHRkzc8oEefnUK6fOd8FchZxU= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-104-tsRmwES_PeaS1Lmy0k7hRw-1; Mon, 06 Mar 2023 16:39:28 -0500 X-MC-Unique: tsRmwES_PeaS1Lmy0k7hRw-1 Received: by mail-qt1-f197.google.com with SMTP id b7-20020ac85407000000b003bfb9cff263so5927600qtq.6 for ; Mon, 06 Mar 2023 13:39:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678138768; 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=WDt24Uf5+E3IsPxqM3v9POMr36n8o93nXZKrGMIf14c=; b=J07kpaOznwOXGEaR46YLpzujyPtmpLD10HVlsJVQ9/Hg7bu7nqywkEkIV+EmGoKa6Q +6b/HgqFsu2FnytZrPvIw+kCXCd6ASI+1xLuT6niAg0L0PmsW1LL6aiInyC8ziHKHe/W QbDouPAksCRJmAYdtjT6ZxrmF8t6/cx6xwgLRUw4TRjz7WfHpQN3UI/bn90YEoG2Z0m7 pjZQ8sE7eJdmSZmLE2RZjmmP6COpEs+b7GzzNbc3PFYLCG9a/ydEVZqtcPxcurM0Y4b4 MTdtkHYo4+ul5ThbdjrMivBj7RDo8UMn/IUhO5/TVCTnZf4X5mhkHts8Tm38JCUE9qhj 2pnQ== X-Gm-Message-State: AO0yUKXe9k4g2ZSewcx5Uumv6NqegUKRtOQWa/7tzfAbOv94eGJa2dqM KHabX0Q0VLSd3hyaujyTX1ZhQfdOjKWAUb9Yld6UVUQbfcYolmFaoqF4ZYKT7UTa9YDf4fDeKdV Jru+zCFsBBEYHaZiTRs+nG/hAgR3zmyhLBIeemFFtVaUtdtPlWjMh3i+a/4JM8GO6cJFr X-Received: by 2002:a05:622a:148:b0:3bf:c382:7abd with SMTP id v8-20020a05622a014800b003bfc3827abdmr24256428qtw.6.1678138767727; Mon, 06 Mar 2023 13:39:27 -0800 (PST) X-Google-Smtp-Source: AK7set9gvk7iwq0Oz79/PSPE5Dcre7oN76C1jvcTeDr8aO4o+8NyEmIHiqxcqTZUl5H1N2fanOy3xA== X-Received: by 2002:a05:622a:148:b0:3bf:c382:7abd with SMTP id v8-20020a05622a014800b003bfc3827abdmr24256380qtw.6.1678138767340; Mon, 06 Mar 2023 13:39:27 -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 e20-20020a05622a111400b003bfa66b7484sm8522884qty.35.2023.03.06.13.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 13:39:26 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muhammad Usama Anjum , peterx@redhat.com, Andrea Arcangeli , Axel Rasmussen , Mike Rapoport , Nadav Amit , Paul Gofman , Andrew Morton , David Hildenbrand Subject: [PATCH v3 0/2] mm/uffd: Add feature bit UFFD_FEATURE_WP_UNPOPULATED Date: Mon, 6 Mar 2023 16:39:23 -0500 Message-Id: <20230306213925.617814-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: igpsxup5iybwqm6os1puxqpruyin6brb X-Rspamd-Queue-Id: BF7C6140013 X-HE-Tag: 1678138770-584067 X-HE-Meta: U2FsdGVkX18WaNOjrMvDhV0QL05QK4/74G8jBjG/A4xEZlDi34s7RF+Q9SdiOYscyfPl39nhARjF69huOmgqEwZVUUYvqD/TJfWJ7thvgBbQ9Aa0NZxPdxovcYMoYRFGFchXpyN8jdW29fTKG7K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48bGPb4AbfypY5k59mBpVpv6Uhao51P8KVGMYJY2oyGdwZGuO8Nru6rgs5QjYz4RHa8nBtwy0Axx2+VwJA8HmA1ZuMMH7OsKcDfZ/IiT5LN/CC6f5V0sTN39x3m6wpO44BRO8W2ZG0YMDxj13P9MVg2CVHeRqvzPEU7fo1K8fpVH8pB/PAMQPdlv0jB1DjDYFCi3wYgxiONjI+d9lRPgg1qwoDoD2+wo7KhFL3US8bqksUF8j3EEjETvqZSgAQ3UsAWdqOm+88NO2XftW43qVTe/JmqnacLKGsJiYfxQMqj3naqeN/RrcTtWXPh3nulCt77ir1woiwnK2ZOtboGnDS1BT5Iz1mLz4AEATflZQgjl+iY= 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 is v3 of the patch(set). Old versions: v1: https://lore.kernel.org/r/20230215210257.224243-1-peterx@redhat.com v2: https://lore.kernel.org/r/20230227230044.1596744-1-peterx@redhat.com Comparing to v2, this fixes a bug that Muhammad reported on reading none pte failure after wr-protected with WP_UNPOPULATED. I also split the test into a separate one. 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 WP_UNPOPULATED fs/userfaultfd.c | 14 ++++++ include/linux/mm_inline.h | 6 +++ include/linux/userfaultfd_k.h | 6 +++ include/uapi/linux/userfaultfd.h | 10 +++- mm/memory.c | 56 ++++++++++++++++------ mm/mprotect.c | 59 ++++++++++++++++++++---- tools/testing/selftests/mm/userfaultfd.c | 45 +++++++++++++++++- 7 files changed, 169 insertions(+), 27 deletions(-)