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=-14.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 B0DB4C433DB for ; Fri, 19 Mar 2021 22:37:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3E11361978 for ; Fri, 19 Mar 2021 22:37:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E11361978 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9A4626B0071; Fri, 19 Mar 2021 18:37:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92D8C6B0072; Fri, 19 Mar 2021 18:37:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A9036B0073; Fri, 19 Mar 2021 18:37:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id 5B23E6B0071 for ; Fri, 19 Mar 2021 18:37:24 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1C1D81827E8FF for ; Fri, 19 Mar 2021 22:37:24 +0000 (UTC) X-FDA: 77938086408.31.F95CFED Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by imf10.hostedemail.com (Postfix) with ESMTP id 977C840001DE for ; Fri, 19 Mar 2021 22:37:23 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id j18so10614865wra.2 for ; Fri, 19 Mar 2021 15:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qtPqC/b9mFCQQC954uZ+jA+CaL7CGfuo4Hx7uUK7ftE=; b=LCk5dKaSSSJ+ICXJC9857Z94TUz/98BHBUWJrvWAGFGx/IKwvt4Od5C208Bh6MPnY1 UfpLZpdlORIYXGm66kJnZeD2xfxDe752ju5/IvnsnAxvi95QKDnLcqfY+HcMgT6KM3A8 k1A/tguEU8hAMSMXtJ/DOL6XkmXIYfcxGIsfhGO+Y1LyOgp/Q+/CFlm9Et6Fi5whv68a 66UBZMnVg7swBbv9CFR9cDz+mbeEHShs50n9dUMXWstok5crAUXPP7xiJ8RUx1LyAVmx x3HS3UfMfNGgNbA1dmvtvKSBz/iLjELVOKFqfoPRr31nU7e1gvRY2Jba1TLkPMsem5ci TZuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qtPqC/b9mFCQQC954uZ+jA+CaL7CGfuo4Hx7uUK7ftE=; b=d6yJm2aebMA7e+f3Pg8vvRaD/089vfMSU7KjFTqYboL59D0Lr9rcNTqdgVhGZPNjHB yb4R6W0fJzC1q9hnSDx27iBueegp6D3/20zjwebfkfpcLS4bvDLFOs0PGwBt5QthVO/5 WYJ5Hb+of0W/L+saQd1UR9mf1nftxA7fShzm5YVqJVMV9JxBnkkp0rOJBFBhYxJZFODy cfsiYCSqVS/8MfMy81rXK8/47YvbCZSkZxuRz5dFksvHgpv8Epn77b/BinAu8NCMP3NJ yKmgI4cGpF/pdFcuLQ8IjDwIkVvyi+xQFaTs/Nbr1L5gYfKTsCybIYbLFxXduJoXaG+V Xibw== X-Gm-Message-State: AOAM531Nfhi5+/20uz/9OGfhYp51PBXIagyMj6lP2zkU6RAHsinWfaNn C7tX1eiu+/1mgf3ZkI/NGdM= X-Google-Smtp-Source: ABdhPJzxzxYKl1O4f75ovjJzZjs+rdqL87EN96yF6Hg3Lk3v6ODiAORvI/1Pyrr8Xy9aIKnqD3SGCQ== X-Received: by 2002:adf:df10:: with SMTP id y16mr6682903wrl.372.1616193442341; Fri, 19 Mar 2021 15:37:22 -0700 (PDT) Received: from [192.168.0.160] ([170.253.36.171]) by smtp.gmail.com with ESMTPSA id j4sm7499426wmo.10.2021.03.19.15.37.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Mar 2021 15:37:21 -0700 (PDT) Subject: Re: [PATCH v3 4/4] ioctl_userfaultfd.2: Add write-protect mode docs To: Peter Xu , linux-man@vger.kernel.org Cc: Andrea Arcangeli , Michael Kerrisk , Axel Rasmussen , linux-kernel@vger.kernel.org, Linux MM Mailing List , Andrew Morton , Nadav Amit , Mike Rapoport References: <20210310222300.200054-1-peterx@redhat.com> <20210310222300.200054-5-peterx@redhat.com> From: "Alejandro Colomar (man-pages)" Message-ID: <5c533ba3-f335-0681-223f-bf2202a9b72a@gmail.com> Date: Fri, 19 Mar 2021 23:37:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210310222300.200054-5-peterx@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Stat-Signature: j19xfzb6pfitjfcye5e31ppeu4h7aany X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 977C840001DE Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mail-wr1-f48.google.com; client-ip=209.85.221.48 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616193443-548684 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: Hi Peter, A few more comments below. Thanks, Alex On 3/10/21 11:23 PM, Peter Xu wrote: > 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 block and Break at the comma instead. > +generate another write-protect userfault message. > +This is only used in conjunction with write-protect mode when both missing and "when both missing" both what? > +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 upon the > +memory range specified by > +.IR range . > +Otherwise it'll be a write-unprotect operation upon the specified range, which Break at the comma instead. > +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 Break at the comma. > +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 Better break at the comma. > +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 > -- Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/