From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54BA9C433DB for ; Wed, 10 Mar 2021 22:23:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0740A64FB9 for ; Wed, 10 Mar 2021 22:23:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0740A64FB9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F02318D0245; Wed, 10 Mar 2021 17:23:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EDA888D0243; Wed, 10 Mar 2021 17:23:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB91A8D0245; Wed, 10 Mar 2021 17:23:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id 9EC028D0243 for ; Wed, 10 Mar 2021 17:23:10 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5B09C8249980 for ; Wed, 10 Mar 2021 22:23:10 +0000 (UTC) X-FDA: 77905391340.29.F1196E9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 4B023407F8FE for ; Wed, 10 Mar 2021 22:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615414989; 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: in-reply-to:in-reply-to:references:references; bh=ZFzDXRjRCL3c0mZFRAdKQ2jZRyOr3oCuno8J4ucW1ys=; b=X9x/mWwNmpveV+iR6WzWYWMe25fOvxTvEEFi7awAB8IspBoJogbI4zo3qk9kwRAeh9MRuZ dKdMvrYnNLX9jDPqiGajiBE+cExel1GStAGkXSSO8WN20m8pD7/BG42X3nllbItX0Btest DW8t4wrYTq2rTw9QxxCCdDj+Yw84u9A= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-106-HP1RbQkCPGiO5W8G-L1XEA-1; Wed, 10 Mar 2021 17:23:07 -0500 X-MC-Unique: HP1RbQkCPGiO5W8G-L1XEA-1 Received: by mail-qv1-f70.google.com with SMTP id j3so13821803qvo.1 for ; Wed, 10 Mar 2021 14:23:07 -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=ZFzDXRjRCL3c0mZFRAdKQ2jZRyOr3oCuno8J4ucW1ys=; b=hzyoAviprkG+Q4u6jL3V9uB+QXv9MbO5Cod+yHseJdlEHgd2weHTxdtu0Jz7rPVC9K N0nsr8OGIJJR2m4b+uKMdylhLxYb7/D55gfD8r89rcqbYfXVKZCQ9YWm5YX6dGZyWU40 24cnP6Ia6qQYtYnFZLQr3tBPrqUlY7yaqbuFfPdpUDT5j6ORj9G33qwvQp5DC11S+tXO wUCRpaMqiWoI0DOMwb7g0H7H/cH5XNcrtTbMEndIiMUMss8T2sXPwkYuwrGL6gr4UYDm JsEwcBRxfIU7K8tX9HrSyYm+7jCvEIshn9pCJj3npmxV8+21NA8RembLmAB7tAcU/+n5 zG2w== X-Gm-Message-State: AOAM532z5lowqfLSLGBdnhbwVVC3hiAFv9KsxnINS5Ag06U+B5MDndvu mxxZkWx5E9K4MSG6X5gGXEvyQdUaKYDS4PI7i86c2Da+bnC3gW0PptaOUvneqEJiVQea7SoiRA5 2sbxvN7SgeRQ= X-Received: by 2002:ac8:66d6:: with SMTP id m22mr4889759qtp.56.1615414987203; Wed, 10 Mar 2021 14:23:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0t3Sv/WtT2KXEpJpvdRgG/DJ9qTaCC0wpr6ZtX+MfqYxr2PjwtYccR5Z4rx16/S25TA6Rzg== X-Received: by 2002:ac8:66d6:: with SMTP id m22mr4889741qtp.56.1615414986928; Wed, 10 Mar 2021 14:23:06 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.89.138]) by smtp.gmail.com with ESMTPSA id e18sm451364qtr.52.2021.03.10.14.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 14:23:06 -0800 (PST) From: Peter Xu To: linux-man@vger.kernel.org Cc: Andrea Arcangeli , Michael Kerrisk , Axel Rasmussen , linux-kernel@vger.kernel.org, peterx@redhat.com, Linux MM Mailing List , Andrew Morton , Alejandro Colomar , Nadav Amit , Mike Rapoport Subject: [PATCH v3 4/4] ioctl_userfaultfd.2: Add write-protect mode docs Date: Wed, 10 Mar 2021 17:23:00 -0500 Message-Id: <20210310222300.200054-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310222300.200054-1-peterx@redhat.com> References: <20210310222300.200054-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII" X-Stat-Signature: w76xueizkinwy8qok5fe4d7rzriy8bke X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4B023407F8FE Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615414987-653929 Content-Transfer-Encoding: quoted-printable 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: Userfaultfd write-protect mode is supported starting from Linux 5.7. Signed-off-by: Peter Xu --- man2/ioctl_userfaultfd.2 | 81 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index d4a8375b8..d8380896a 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,13 @@ 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 +Copy the page with read-only permission. +This allows the user to trap the next write to the page, which will bloc= k and +generate another write-protect userfault message. +This is only used in conjunction with write-protect mode when both missi= ng and +write-protect modes are enabled. .PP The .I copy @@ -654,6 +663,72 @@ 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) +Write-protect or write-unprotect an userfaultfd registered memory range +registered 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 mode bits 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 u= pon the +memory range specified by +.IR range . +Otherwise it'll be a write-unprotect operation upon the specified range,= which +can be used to resolve an userfaultfd write-protect page fault. +.TP +.B UFFDIO_WRITEPROTECT_MODE_DONTWAKE +When this mode bit is set, do not wake up any thread that waits for page= -fault +resolution after the operation. +This could only be specified if +.B UFFDIO_WRITEPROTECT_MODE_WP +is not specified. +.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. +For example, 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 --=20 2.26.2