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 B03F8C433DB for ; Mon, 22 Mar 2021 22:09:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 579D261879 for ; Mon, 22 Mar 2021 22:09:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 579D261879 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 E22AB6B011C; Mon, 22 Mar 2021 18:09:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DAA606B011E; Mon, 22 Mar 2021 18:09:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD6036B011F; Mon, 22 Mar 2021 18:09:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 9D8246B011C for ; Mon, 22 Mar 2021 18:09:22 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5DDA5180AD83E for ; Mon, 22 Mar 2021 22:09:22 +0000 (UTC) X-FDA: 77948902164.27.D7DDBFD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 5022D200025F for ; Mon, 22 Mar 2021 22:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616450940; 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=Kl3kFp9hTUBjJOfw0aybm+GM5kudzpR7W9bPcAyBKfY=; b=Z6GueklmOiNCehzKiT6ILQM0UP5W8SfomthfK2NMthFjrwi6A1sHje5h53QrrAxd64PRUT pPYMoK6NAZC1WFVtkxIyOJzvsYZuOWmNisqZVSOyq0tJJw6kodS51oAsQ/4RaHMG+09qps qshl/EFz32AWFLH4Q2TA8pcUdGeeCH8= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-29-lI6Zg6rAMkiI1tQ3nyL9BQ-1; Mon, 22 Mar 2021 18:08:58 -0400 X-MC-Unique: lI6Zg6rAMkiI1tQ3nyL9BQ-1 Received: by mail-qt1-f197.google.com with SMTP id c20so231222qtw.9 for ; Mon, 22 Mar 2021 15:08:58 -0700 (PDT) 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=Kl3kFp9hTUBjJOfw0aybm+GM5kudzpR7W9bPcAyBKfY=; b=QDzq75bUjxLNp01vdhVOVc1pVAyc4fIvRLNefrAttpVLcmOZ0ts2A0A8KWVFu0Yctv DDOEYJ5do3Uzx2S8iqvxAkKdAMqsVkWcge73aI952tgQTyws9NZRtt8NsNkkCHiz8cew qJAiOX5C6iyw2qhA/fnC4J2lH/pGQOGyvOgcXhEO9/w0gkFeK11XPaUnDGBrbRrK8IHk 6m2UWP1H2r7d+u6WbBGc9HxSQc6xyj/cWzk3uPe77I3CALthn7axYEP6ckFEtTTpJWWV l1JBExfOnihz5Xy2xt3P/8Wg7fAALO5+XR7vNPyTDGkx4o0CUf4y8BwuApWnu5dBKe4S MTZg== X-Gm-Message-State: AOAM532i22fry26DFr5aBNsZ/oq15YAthKwG2KckQWgMJk2fmqE3gWn0 E+Lder2o2me9Q+c3pCEM/pMk8C7wNuEgbp7sp/Sp7WlqJRwyLqIdMwGxdPtDwx+mERO6pb1+JkY 3/Kb+mL5Wf3Q= X-Received: by 2002:a05:620a:218e:: with SMTP id g14mr2318822qka.111.1616450937655; Mon, 22 Mar 2021 15:08:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXQkjDlpEzfKxL2gVD4fm1+ph4tlOJXa1UzW5utW+yxjYVJwWLncDAwiuahCmShRLGbvdPJw== X-Received: by 2002:a05:620a:218e:: with SMTP id g14mr2318803qka.111.1616450937365; Mon, 22 Mar 2021 15:08:57 -0700 (PDT) Received: from xz-x1.redhat.com (bras-base-toroon474qw-grc-82-174-91-135-175.dsl.bell.ca. [174.91.135.175]) by smtp.gmail.com with ESMTPSA id x1sm9627850qtr.97.2021.03.22.15.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 15:08:56 -0700 (PDT) From: Peter Xu To: linux-man@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrea Arcangeli , Mike Rapoport , Axel Rasmussen , Alejandro Colomar , peterx@redhat.com, Michael Kerrisk , Nadav Amit , Andrew Morton Subject: [PATCH v4 4/4] ioctl_userfaultfd.2: Add write-protect mode docs Date: Mon, 22 Mar 2021 18:08:48 -0400 Message-Id: <20210322220848.52162-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210322220848.52162-1-peterx@redhat.com> References: <20210322220848.52162-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-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5022D200025F X-Stat-Signature: jigwjmo386fq7ct1m3e5u41ychazmcf5 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616450941-830728 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 | 84 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index d4a8375b8..5419687a6 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,16 @@ 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 block and generate another write-protect userfault message. +This is only used when both +.B UFFDIO_REGISTER_MODE_MISSING +and +.B UFFDIO_REGISTER_MODE_WP +modes are enabled for the registered range. .PP The .I copy @@ -654,6 +666,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