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 AB7F8C433C1 for ; Tue, 23 Mar 2021 18:11:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C6C5F619A9 for ; Tue, 23 Mar 2021 18:11:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6C5F619A9 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 35D446B027D; Tue, 23 Mar 2021 14:11:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30D446B027F; Tue, 23 Mar 2021 14:11:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15F786B0280; Tue, 23 Mar 2021 14:11:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0186.hostedemail.com [216.40.44.186]) by kanga.kvack.org (Postfix) with ESMTP id EBE656B027D for ; Tue, 23 Mar 2021 14:11:08 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A6178180B1A7B for ; Tue, 23 Mar 2021 18:11:08 +0000 (UTC) X-FDA: 77951930616.36.181A8BC Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf29.hostedemail.com (Postfix) with ESMTP id 2217AF3 for ; Tue, 23 Mar 2021 18:11:07 +0000 (UTC) Received: by mail-wm1-f48.google.com with SMTP id d8-20020a1c1d080000b029010f15546281so11223285wmd.4 for ; Tue, 23 Mar 2021 11:11:07 -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=/3n6/hjBeKG9YY5D/RNZJFxIplip8JKuOKCUvPOqsyg=; b=To17+Rs+T5WPTHvuDG3BGBgm8g5YIPCce2xRsDeuS4+gc5INAL99XSzlDw2T8BKDBK KD15Y8sCX1q8Z/mY4s7FdHNe8AlsjQUXFRIKs3WtLdeVdqXszcryOGDEFkhkHkRZbcfM iETMdKgZ+4C5phdJzPnGkegivlmVEGM27hSRzRsfF0Xm1B80rqVksIQ7uIGqS9sKSAcB FjCF84FgZxHFv5WNidIz3iEyHrVRiNJ4Fzzr24BCj7yKRhqXqjGkgsEGD4BoFm8cdr9K kClv+wN/BqY4FNZEgNmMmJPlrdHCDxb0TlcLNpTWAx3u1J2yjhfRhxfVjyWP8S5HYysg MKLg== 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=/3n6/hjBeKG9YY5D/RNZJFxIplip8JKuOKCUvPOqsyg=; b=EI7w6BGDbYgWYiMu3Z0EffN/wiTjsfQCG6hqgDLrGiDKkKRQrmUnXxBJZ/JckZZsCF CiEFJCr5xVwlp7eN3Uiqb1VjT9LyVCtwIl0tZMosURHavLlP3KINKrnKTtdMNpjSzghR Br1H0dx109aYkgWYi+4n82JOLsClzd6g2JOlpUXPE2WXkgP/DvJt04OGC2fOXnpsjGJg vy9c6T8aUD5nbg6WS/RJ9qibplKWuDjjU++ghskzrihXy2gMMWaW4O205RuPeBeyA2Hk 9GmDel0vbZWhTOSPwrI/6a4ayqPCdBDcx/rCUagLUUgdd6UKqlKzDsqHPlAw+mP3NjTW cxWw== X-Gm-Message-State: AOAM531KHHYMMi7/iXwO6zJDZB6I6r9idJFVlxOMz4nmZ5/WwBdvrtCv MkA1ogL1ph/aa9VRbc19bnQ= X-Google-Smtp-Source: ABdhPJwbogAK01BZyOnaAQboki65TGpfbdsETa9yYXZOlcn2lwwNcqX+bzYBcjbiCHt67q5Y6O7IEg== X-Received: by 2002:a7b:c1c4:: with SMTP id a4mr4612562wmj.122.1616523066666; Tue, 23 Mar 2021 11:11:06 -0700 (PDT) Received: from [10.8.0.206] ([195.53.121.100]) by smtp.gmail.com with ESMTPSA id p12sm24239866wrx.28.2021.03.23.11.11.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Mar 2021 11:11:06 -0700 (PDT) Subject: Re: [PATCH v4 4/4] ioctl_userfaultfd.2: Add write-protect mode docs To: Peter Xu , linux-man@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mike Rapoport Cc: Andrea Arcangeli , Axel Rasmussen , Michael Kerrisk , Nadav Amit , Andrew Morton References: <20210322220848.52162-1-peterx@redhat.com> <20210322220848.52162-5-peterx@redhat.com> From: "Alejandro Colomar (man-pages)" Message-ID: Date: Tue, 23 Mar 2021 19:11:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210322220848.52162-5-peterx@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2217AF3 X-Stat-Signature: 7gzyh7gezwfmfgtjoki3xz85h963za56 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mail-wm1-f48.google.com; client-ip=209.85.128.48 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616523067-566537 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, Please see a few comments below. Thanks, Alex On 3/22/21 11:08 PM, Peter Xu wrote: > 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. s/write-protect/write-protected/ ? > +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 upon 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. Maybe: "The process was interrupted; retry this call."? I don't know what other pager say about this kind of error. > +.TP > +.B ENOENT > +The range specified in > +.I range > +is not valid. I'm not sure how this is different from the wording above in EINVAL. An "otherwise invalid range" was already giving EINVAL? > +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. What is a "generic fault"? > .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/