Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1627219pxb; Thu, 4 Mar 2021 16:51:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeqo/6ZGYnDbmyrG6mdfED5/bZJfygkJBKQJXKb3wi4uU+CyKEB7BiMx3DesvXFNlk2Rnt X-Received: by 2002:a5e:9709:: with SMTP id w9mr5586944ioj.29.1614905508747; Thu, 04 Mar 2021 16:51:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614905508; cv=none; d=google.com; s=arc-20160816; b=ssfLl4B87TNfiUdpugrMPk0XlgHj96CDNihhC8kn+6IonnNaaBBkYqT038GRNIMrE8 mjqksfaZucyN9mISYRKY+2a2gk74kWeHx2fMzIwthev6qArKn+icuMz3tNfJ0nTXy7kS lb31fs5SK0p5PCxiL3icuDXr6bJr5KWMA64XLU56FS/eUc2upit3HOGKBlvezVasQgmE 4KQ6srikquCQaVDIXOYd3IyBKVIgAvJ38biRZSV1tN43vvr1vsqMtkWk2k/kgNB5JHhC wjN2pf1gpaJ0wA7oyeBWfXklsKJzFZQVLD/wF2eEyXjWce++eer8NzZvCQRP6fac5pv1 Ipfw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0tDcn9g219xehBx47za8NiyX09EPm0l6AhkPUkOSCPU=; b=nJKGBUjR5OeYaEe/reV5YO4M2U3VJX5DxVHwiq657wSgrEgAHTsL76R8V+0QQhqvkk /h5+Tm8Zex6Fz1SyZWd3gV8BDcoJwU7X8DsKtv2/EpN083Fjk6YDyoKr2yaZ9aA+iU9o y8cKHt/MX5Vm9YcEX2Hh+5zbpqs60u68n9sDCorykiXGXAdpanVMNo8ZtsUiY8U3DVZ7 DyTNfX2Y3x+kHGEN5RogCU7LHeAG1w2FCLZ4DhctVXj/UfLZy6M1M6r7/oL/jXiD1sY8 +e6OVLkd820Jvkb1V4hdh8yHERCbgWO85zSL7BaLyvdnykjytVUmJULOl8EhTl8KJ/Vx wrsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A898zDCL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t12si869297iof.82.2021.03.04.16.51.36; Thu, 04 Mar 2021 16:51:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A898zDCL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237980AbhCDQdc (ORCPT + 99 others); Thu, 4 Mar 2021 11:33:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30974 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237841AbhCDQdS (ORCPT ); Thu, 4 Mar 2021 11:33:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614875513; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0tDcn9g219xehBx47za8NiyX09EPm0l6AhkPUkOSCPU=; b=A898zDCLqOknDBTPozVDFlkI/XztdoRb4w7iYfEQl6FwMvcPo96qhVe6mdCc527qaJ24H/ 5XBKDFOKpB/GqdHf3mpeRGpC8gFZymyX9jSFiuKDmueTmfD8OlJ/rgdBZcr3FITRFE9o8W dSpkcdt9o4VwGzNcM7Uo4uxJyXVBhKU= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-600-LMvORoBkPBuR9woDVQ7LRw-1; Thu, 04 Mar 2021 11:31:51 -0500 X-MC-Unique: LMvORoBkPBuR9woDVQ7LRw-1 Received: by mail-qt1-f200.google.com with SMTP id p32so13186824qtd.14 for ; Thu, 04 Mar 2021 08:31:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0tDcn9g219xehBx47za8NiyX09EPm0l6AhkPUkOSCPU=; b=YIYxXEKw+nU96YfBclgDdPPASW5JePrYxzE3jx8vYhajLEAOyAuKSCZZanSh5wYqJ7 NwMHiLuv1uy/24GSu1OxE/XupxwM1MDcCm+jcRuvGP5QwFuGctLWHz5U2dhUCqHVb5nd qOVNZ/3y25RwhUgWst4YbO6fHFd+272rm6bbiDPta3Rx8U0zMI1Kyxs0LCRE9PYoEbo8 ks3XRYxuB1vzAYAc39edqdOtJQ/Z8MN/s5k4JAiSfEp/6UhJqVm0Zqq7mNilTPJonGSa iKCpEDHLI39EQzncddXB4DgdDCzxfgReMY51N73hvfCDGtlTgxtfrOl7Kn4b2SMOnYiD CEiw== X-Gm-Message-State: AOAM533EgcCFv0/JP4M0OJEa482BtZohAHgR/ZvM6O57wASmS3QIjZpL iWnS+o1p+fo3+5ieas3CZqfi+U3YMqI7aQbYO8basj3IeStO7B1qN1FbL2zqPvk8tfKmjCgWrFI Tw6RnQMBvXT54Zhb1nTNeXewM X-Received: by 2002:a05:620a:41:: with SMTP id t1mr4784536qkt.322.1614875510981; Thu, 04 Mar 2021 08:31:50 -0800 (PST) X-Received: by 2002:a05:620a:41:: with SMTP id t1mr4784503qkt.322.1614875510658; Thu, 04 Mar 2021 08:31:50 -0800 (PST) Received: from xz-x1.redhat.com (bras-vprn-toroon474qw-lp130-25-174-95-95-253.dsl.bell.ca. [174.95.95.253]) by smtp.gmail.com with ESMTPSA id r2sm51753qti.4.2021.03.04.08.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 08:31:49 -0800 (PST) From: Peter Xu To: linux-man@vger.kernel.org Cc: Alejandro Colomar , Nadav Amit , Andrea Arcangeli , linux-kernel@vger.kernel.org, Michael Kerrisk , Mike Rapoport , Axel Rasmussen , Andrew Morton , Linux MM Mailing List , peterx@redhat.com Subject: [PATCH v2 4/4] ioctl_userfaultfd.2: Add write-protect mode docs Date: Thu, 4 Mar 2021 11:31:40 -0500 Message-Id: <20210304163140.543171-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210304163140.543171-1-peterx@redhat.com> References: <20210304163140.543171-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Userfaultfd write-protect mode is supported starting from Linux 5.7. Signed-off-by: Peter Xu --- man2/ioctl_userfaultfd.2 | 76 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index b58983fe7..7497e63c4 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -234,6 +234,11 @@ operation is supported. The .B UFFDIO_UNREGISTER operation is supported. +.TP +.B 1 << _UFFDIO_WRITEPROTECT +The +.B UFFDIO_WRITEPROTECT +operation is supported. .PP This .BR ioctl (2) @@ -322,9 +327,6 @@ Track page faults on missing pages. .B UFFDIO_REGISTER_MODE_WP Track page faults on write-protected pages. .PP -Currently, the only supported mode is -.BR UFFDIO_REGISTER_MODE_MISSING . -.PP If the operation is successful, the kernel modifies the .I ioctls bit-mask field to indicate which @@ -443,6 +445,11 @@ operation: .TP .B UFFDIO_COPY_MODE_DONTWAKE Do not wake up the thread that waits for page-fault resolution +.TP +.B UFFDIO_COPY_MODE_WP +Do not set write permission when copying the page. The next write to the page +will trigger a write fault. This can be used in conjunction with write-protect +mode so that there will be another message generated when the page is written again. .PP The .I copy @@ -654,6 +661,69 @@ field of the structure was not a multiple of the system page size; or .I len was zero; or the specified range was otherwise invalid. +.SS UFFDIO_WRITEPROTECT +(Since Linux 5.7) Do write-protect or write-unprotect for an userfaultfd +registered memory range with mode +.BR UFFDIO_REGISTER_MODE_WP . +.PP +The +.I argp +argument is a pointer to a +.I uffdio_range +structure as shown below: +.PP +.in +4n +.EX +struct uffdio_writeprotect { + struct uffdio_range range; /* Range to change write permission */ + __u64 mode; /* Mode to change write permission */ +}; +.EE +.in +There're two modes that are supported in this structure: +.TP +.B UFFDIO_WRITEPROTECT_MODE_WP +When this mode bit is set, the ioctl will be a write-protect operation upon the +memory range specified by +.IR range . +Otherwise it'll be a write-unprotect operation upon the specified range. +.TP +.B UFFDIO_WRITEPROTECT_MODE_DONTWAKE +Do not wake up the thread that waits for page-fault resolution after the +operation. This could only be specified if +.B UFFDIO_WRITEPROTECT_MODE_WP +is not specified (in a resolving stage, not protecting stage). +.PP +This +.BR ioctl (2) +operation returns 0 on success. +On error, \-1 is returned and +.I errno +is set to indicate the error. +Possible errors include: +.TP +.B EINVAL +The +.I start +or the +.I len +field of the +.I ufdio_range +structure was not a multiple of the system page size; or +.I len +was zero; or the specified range was otherwise invalid. +.TP +.B EAGAIN +The process was interrupted and need to retry. +.TP +.B ENOENT +The range specified in +.I range +is not valid. E.g., the virtual address does not exist, or not registered with +userfaultfd write-protect mode. +.TP +.B EFAULT +Encountered a generic fault during processing. .SH RETURN VALUE See descriptions of the individual operations, above. .SH ERRORS -- 2.26.2